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