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