1<?php
2/**
3 * DokuWiki Plugin miniblog
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Esther Brunner <wikidesign@gmail.com> (upstream)
7 * @author  Michael Klier <chi@chimeric.de> (upstrema)
8 * @author  Gina Haeussge <osd@foosel.net> (upstream)
9 * @author  lainme <lainme993@gmail.com>
10 */
11
12// must be run within Dokuwiki
13if (!defined('DOKU_INC')) die();
14
15class helper_plugin_miniblog_entry extends DokuWiki_Plugin {
16    public function entry_list($ns) {
17        global $conf;
18
19        // pages to display
20        search($pages, $conf['datadir'], 'search_pagename', array('query'=>'.txt'), $ns);
21
22        // sort
23        $entries = array();
24        foreach ((array)$pages as $page) {
25            $date = p_get_metadata($page['id'], 'date created', METADATA_DONT_RENDER);
26            $user = p_get_metadata($page['id'], 'user', METADATA_DONT_RENDER);
27
28            $entries[$date] = array(
29                'id' => $page['id'],
30                'date' => $date,
31                'user' => $user,
32            );
33        }
34        krsort($entries);
35
36        return $entries;
37    }
38
39    public function entry_content($id, $canonical=false) {
40        global $conf;
41
42        $ins = p_cached_instructions(wikiFN($id), false, $id);
43
44        // delete heading, resolve internal links and remove comment
45        $head = false;
46        for ($i=0; $i<count($ins); $i++) {
47            switch ($ins[$i][0]) {
48                case 'header':
49                    if ($head === false) {
50                        $head = $ins[$i][1][0];
51                        unset($ins[$i]);
52                    }
53                    break;
54                case 'internallink':
55                    resolve_pageid(getNS($id), $ins[$i][1][0], $exists);
56                    break;
57                case 'internalmedia':
58                    resolve_mediaid(getNS($id), $ins[$i][1][0], $exists);
59                    break;
60                case 'plugin':
61                    if ($ins[$i][1][0] == 'miniblog_comment') unset($ins[$i]);
62                    break;
63            }
64        }
65
66        $html = p_render('xhtml', $ins, $info);
67        if (!$conf['canonical'] && $canonical) {
68            $base = preg_quote(DOKU_REL, '/');
69            $html = preg_replace('/(<a href|<img src)="('.$base.')/s', '$1="'.DOKU_URL, $html);
70        }
71        return array($head, $html);
72    }
73}
74