xref: /plugin/include/syntax/footer.php (revision 2ce032a785758436b78479066d4ecd9aa14cc355)
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        $exists = page_exists($page);
56        $xhtml = array();
57        // permalink
58        if ($flags['permalink']) {
59            $class = ($exists ? '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'] && $exists) {
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        // modified date
86        if ($flags['mdate'] && $exists) {
87            $mdate = $meta['date']['modified'];
88            if ($mdate) {
89                $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $mdate).'">'
90                       . strftime($conf['dformat'], $mdate)
91                       . '</abbr>';
92            }
93        }
94
95        // author
96        if ($flags['user'] && $exists) {
97            $author   = $meta['creator'];
98            if ($author) {
99                $userpage = cleanID($this->getConf('usernamespace').':'.$author);
100                resolve_pageid(getNS($ID), $userpage, $exists);
101                $class = ($exists ? 'wikilink1' : 'wikilink2');
102                $link = array(
103                        'url'    => wl($userpage),
104                        'title'  => $userpage,
105                        'name'   => hsc($author),
106                        'target' => $conf['target']['wiki'],
107                        'class'  => $class.' url fn',
108                        'pre'    => '<span class="vcard author">',
109                        'suf'    => '</span>',
110                        );
111                $xhtml[]    = $renderer->_formatLink($link);
112            }
113        }
114
115        // comments - let Discussion Plugin do the work for us
116        if (empty($sect) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion =& plugin_load('helper', 'discussion'))) {
117            $disc = $discussion->td($page);
118            if ($disc) $xhtml[] = '<span class="comment">' . $disc . '</span>';
119        }
120
121        // linkbacks - let Linkback Plugin do the work for us
122        if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback =& plugin_load('helper', 'linkback'))) {
123            $link = $linkback->td($page);
124            if ($link) $xhtml[] = '<span class="linkback">' . $link . '</span>';
125        }
126
127        $xhtml = implode(DOKU_LF . DOKU_TAB . '&middot; ', $xhtml);
128
129        // tags - let Tag Plugin do the work for us
130        if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag =& plugin_load('helper', 'tag'))) {
131            $tags = $tag->td($page);
132            if($tags) {
133                $xhtml .= '<div class="tags"><span>' . DOKU_LF
134                              . DOKU_TAB . $tags . DOKU_LF
135                              . DOKU_TAB . '</span></div>' . DOKU_LF;
136            }
137        }
138
139        if (!$xhtml) $xhtml = '&nbsp;';
140        $class = 'inclmeta';
141        $class .= ' level' . $footer_lvl;
142        return '<div class="' . $class . '">' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '</div>' . DOKU_LF;
143    }
144}
145// vim:ts=4:sw=4:et:
146