xref: /plugin/include/syntax/footer.php (revision 2524d4070dd2d3a04a927b4ad11e6ee8599a434b)
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, &$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, &$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     */
49    function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) {
50        global $conf, $ID;
51
52        if(!$flags['footer']) return '';
53
54        $meta  = p_get_metadata($page);
55        $xhtml = array();
56
57        // permalink
58        if ($flags['permalink']) {
59            $class = (page_exists($page) ? 'wikilink1' : 'wikilink2');
60            $url   = ($sect) ? wl($page) . '#' . $sect : wl($page);
61            $name  = ($sect) ? $sect_title : $page;
62            $title = ($sect) ? $page . '#' . $sect : $page;
63            if (!$title) $title = str_replace('_', ' ', noNS($page));
64            $link = array(
65                    'url'    => $url,
66                    'title'  => $title,
67                    'name'   => $name,
68                    'target' => $conf['target']['wiki'],
69                    'class'  => $class . ' permalink',
70                    'more'   => 'rel="bookmark"',
71                    );
72            $xhtml[] = $renderer->_formatLink($link);
73        }
74
75        // date
76        if ($flags['date']) {
77            $date = $meta['date']['created'];
78            if ($date) {
79                $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $date).'">'
80                       . strftime($conf['dformat'], $date)
81                       . '</abbr>';
82            }
83        }
84
85        // author
86        if ($flags['user']) {
87            $author   = $meta['creator'];
88            if ($author) {
89                $userpage = cleanID($this->getConf('usernamespace').':'.$author);
90                resolve_pageid(getNS($ID), $userpage, $exists);
91                $class = ($exists ? 'wikilink1' : 'wikilink2');
92                $link = array(
93                        'url'    => wl($userpage),
94                        'title'  => $userpage,
95                        'name'   => hsc($author),
96                        'target' => $conf['target']['wiki'],
97                        'class'  => $class.' url fn',
98                        'pre'    => '<span class="vcard author">',
99                        'suf'    => '</span>',
100                        );
101                $xhtml[]    = $renderer->_formatLink($link);
102            }
103        }
104
105        // comments - let Discussion Plugin do the work for us
106        if (empty($sect) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion =& plugin_load('helper', 'discussion'))) {
107            $disc = $discussion->td($page);
108            if ($disc) $xhtml[] = '<span class="comment">' . $disc . '</span>';
109        }
110
111        // linkbacks - let Linkback Plugin do the work for us
112        if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback =& plugin_load('helper', 'linkback'))) {
113            $link = $linkback->td($page);
114            if ($link) $xhtml[] = '<span class="linkback">' . $link . '</span>';
115        }
116
117        $xhtml = implode(DOKU_LF . DOKU_TAB . '&middot; ', $xhtml);
118
119        // tags - let Tag Plugin do the work for us
120        if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag =& plugin_load('helper', 'tag'))) {
121            $tags = $tag->td($page);
122            if($tags) {
123                $xhtml .= '<div class="tags"><span>' . DOKU_LF
124                              . DOKU_TAB . $tags . DOKU_LF
125                              . DOKU_TAB . '</span></div>' . DOKU_LF;
126            }
127        }
128
129        if (!$xhtml) $xhtml = '&nbsp;';
130        $class = 'inclmeta';
131        $class .= ' level' . $footer_lvl;
132        return '<div class="' . $class . '">' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '</div>' . DOKU_LF;
133    }
134}
135// vim:ts=4:sw=4:et:
136