1<?php
2/**
3 * Include plugin (footer component)
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author  Michael Klier <chi@chimeric.de>
7 */
8
9class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin {
10
11    function getType() {
12        return 'formatting';
13    }
14
15    function getSort() {
16        return 300;
17    }
18
19    function handle($match, $state, $pos, Doku_Handler $handler) {
20        // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
21    }
22
23    /**
24     * Renders a permalink header.
25     *
26     * Code heavily copied from the header renderer from inc/parser/xhtml.php, just
27     * added an href parameter to the anchor tag linking to the wikilink.
28     */
29    function render($mode, Doku_Renderer $renderer, $data) {
30
31        list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data;
32
33        if ($mode == 'xhtml') {
34            $renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer);
35	        return true;
36        }
37        return false;
38    }
39
40    /**
41     * Returns the meta line below the included page
42     * @param $renderer Doku_Renderer_xhtml The (xhtml) renderer
43     * @return string The HTML code of the footer
44     */
45    function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) {
46        global $conf, $ID;
47
48        if(!$flags['footer']) return '';
49
50        $meta  = p_get_metadata($page);
51        $exists = page_exists($page);
52        $xhtml = array();
53        // permalink
54        if ($flags['permalink']) {
55            $class = ($exists ? 'wikilink1' : 'wikilink2');
56            $url   = ($sect) ? wl($page) . '#' . $sect : wl($page);
57            $name  = ($sect) ? $sect_title : $page;
58            $title = ($sect) ? $page . '#' . $sect : $page;
59            if (!$title) $title = str_replace('_', ' ', noNS($page));
60            $link = array(
61                    'url'    => $url,
62                    'title'  => $title,
63                    'name'   => $name,
64                    'target' => $conf['target']['wiki'],
65                    'class'  => $class . ' permalink',
66                    'more'   => 'rel="bookmark"',
67                    );
68            $xhtml[] = $renderer->_formatLink($link);
69        }
70
71        // date
72        if ($flags['date'] && $exists) {
73            $date = $meta['date']['created'];
74            if ($date) {
75                $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $date).'">'
76                       . strftime($conf['dformat'], $date)
77                       . '</abbr>';
78            }
79        }
80
81        // modified date
82        if ($flags['mdate'] && $exists) {
83            $mdate = $meta['date']['modified'];
84            if ($mdate) {
85                $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $mdate).'">'
86                       . strftime($conf['dformat'], $mdate)
87                       . '</abbr>';
88            }
89        }
90
91        // author
92        if ($flags['user'] && $exists) {
93            $author   = $meta['user'];
94            if ($author) {
95                if (function_exists('userlink')) {
96                    $xhtml[] = '<span class="vcard author">' . userlink($author) . '</span>';
97                } else { // DokuWiki versions < 2014-05-05 doesn't have userlink support, fall back to not providing a link
98                    $xhtml[] = '<span class="vcard author">' . editorinfo($author) . '</span>';
99                }
100            }
101        }
102
103        // comments - let Discussion Plugin do the work for us
104        if (empty($sect) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion = plugin_load('helper', 'discussion'))) {
105            $disc = $discussion->td($page);
106            if ($disc) $xhtml[] = '<span class="comment">' . $disc . '</span>';
107        }
108
109        // linkbacks - let Linkback Plugin do the work for us
110        if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback = plugin_load('helper', 'linkback'))) {
111            $link = $linkback->td($page);
112            if ($link) $xhtml[] = '<span class="linkback">' . $link . '</span>';
113        }
114
115        $xhtml = implode(DOKU_LF . DOKU_TAB . '&middot; ', $xhtml);
116
117        // tags - let Tag Plugin do the work for us
118        if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag = plugin_load('helper', 'tag'))) {
119            $tags = $tag->td($page);
120            if($tags) {
121                $xhtml .= '<div class="tags"><span>' . DOKU_LF
122                              . DOKU_TAB . $tags . DOKU_LF
123                              . DOKU_TAB . '</span></div>' . DOKU_LF;
124            }
125        }
126
127        if (!$xhtml) $xhtml = '&nbsp;';
128        $class = 'inclmeta';
129        $class .= ' level' . $footer_lvl;
130        return '<div class="' . $class . '">' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '</div>' . DOKU_LF;
131    }
132}
133// vim:ts=4:sw=4:et:
134