1<?php
2/**
3 * DokuWiki Plugin miniblog
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Gina Haeussge <osd@foosel.net> (upstream)
7 * @author  lainme <lainme993@gmail.com>
8 */
9
10// must be run within Dokuwik
11if (!defined('DOKU_INC')) die();
12
13class action_plugin_miniblog extends DokuWiki_Action_Plugin {
14    public function register(Doku_Event_Handler $controller) {
15        $controller->register_hook('FEED_MODE_UNKNOWN', 'BEFORE', $this, 'handle_mode_unknown');
16        $controller->register_hook('FEED_ITEM_ADD', 'BEFORE', $this, 'handle_item_add');
17    }
18
19    public function handle_mode_unknown(&$event, $param) {
20        if ($event->data['opt']['feed_mode'] != 'miniblog') return;
21
22        $event->preventDefault();
23        $event->data['data'] = array();
24
25        $entries = $this->loadHelper('miniblog_entry')->entry_list('blog');
26        $entries = array_slice($entries, 0, $event->data['opt']['items']);
27
28        // add entries to feed
29        foreach ($entries as $entry) {
30            $event->data['data'][] = $entry;
31        }
32    }
33
34    public function handle_item_add(&$event, $param) {
35        if ($event->data['opt']['feed_mode'] != 'miniblog') return;
36
37        // remove first heading from content
38        list($head, $content) = $this->loadHelper('miniblog_entry')->entry_content($event->data['ditem']['id'], true);
39        $event->data['item']->description = $content;
40    }
41}
42