xref: /plugin/include/syntax/footer.php (revision b95aa97629f1fc009b086cef21236235b850fa48)
1<?php
2/**
3 * Include plugin (permalink header component)
4 *
5 * Provides a header instruction which renders a permalink to the included page
6 *
7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author  Gina Haeussge <osd@foosel.net>
9 * @author  Michael Klier <chi@chimeric.de>
10 */
11
12if (!defined('DOKU_INC'))
13    define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/');
14if (!defined('DOKU_PLUGIN'))
15    define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
16require_once (DOKU_PLUGIN . 'syntax.php');
17
18class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin {
19
20    function getInfo() {
21        return array (
22            'author' => 'Gina Häußge, Michael Klier',
23            'email' => 'dokuwiki@chimeric.de',
24            'date' => @file_get_contents(DOKU_PLUGIN . 'blog/VERSION'),
25            'name' => 'Include Plugin (permalink header component)',
26            'desc' => 'Provides a header instruction which renders a permalink to the included page',
27            'url' => 'http://wiki.splitbrain.org/plugin:include',
28        );
29    }
30
31    function getType() {
32        return 'formatting';
33    }
34
35    function getSort() {
36        return 300;
37    }
38
39    function handle($match, $state, $pos, &$handler) {
40        // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
41    }
42
43    /**
44     * Renders a permalink header.
45     *
46     * Code heavily copied from the header renderer from inc/parser/xhtml.php, just
47     * added an href parameter to the anchor tag linking to the wikilink.
48     */
49    function render($mode, &$renderer, $data) {
50
51        list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data;
52
53        if ($mode == 'xhtml') {
54            $renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer);
55	        return true;
56        }
57        return false;
58    }
59
60    /**
61     * Returns the meta line below the included page
62     */
63    function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) {
64        global $conf, $ID;
65
66        if(!$flags['footer']) return '';
67
68        $meta  = p_get_metadata($page);
69        $xhtml = array();
70
71        // permalink
72        if ($flags['link']) {
73            $class = (page_exists($page) ? 'wikilink1' : 'wikilink2');
74            $url   = ($sect) ? wl($page) . '#' . $sect : wl($page);
75            $name  = ($sect) ? $sect_title : $page;
76            $title = ($sect) ? $page . '#' . $sect : $page;
77            if (!$title) $title = str_replace('_', ' ', noNS($page));
78            $link = array(
79                    'url'    => $url,
80                    'title'  => $title,
81                    'name'   => $name,
82                    'target' => $conf['target']['wiki'],
83                    'class'  => $class . ' permalink',
84                    'more'   => 'rel="bookmark"',
85                    );
86            $xhtml[] = $renderer->_formatLink($link);
87        }
88
89        // date
90        if ($flags['date']) {
91            $date = $meta['date']['created'];
92            if ($date) {
93                $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $date).'">'
94                       . strftime($conf['dformat'], $date)
95                       . '</abbr>';
96            }
97        }
98
99        // author
100        if ($flags['user']) {
101            $author   = $meta['creator'];
102            if ($author) {
103                $userpage = cleanID($this->getConf('usernamespace').':'.$author);
104                resolve_pageid(getNS($ID), $userpage, $exists);
105                $class = ($exists ? 'wikilink1' : 'wikilink2');
106                $link = array(
107                        'url'    => wl($userpage),
108                        'title'  => $userpage,
109                        'name'   => hsc($author),
110                        'target' => $conf['target']['wiki'],
111                        'class'  => $class.' url fn',
112                        'pre'    => '<span class="vcard author">',
113                        'suf'    => '</span>',
114                        );
115                $xhtml[]    = $renderer->_formatLink($link);
116            }
117        }
118
119        // comments - let Discussion Plugin do the work for us
120        if (empty($sec) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion =& plugin_load('helper', 'discussion'))) {
121            $disc = $discussion->td($page);
122            if ($disc) $xhtml[] = '<span class="comment">' . $disc . '</span>';
123        }
124
125        // linkbacks - let Linkback Plugin do the work for us
126        if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback =& plugin_load('helper', 'linkback'))) {
127            $link = $linkback->td($id);
128            if ($link) $xhtml[] = '<span class="linkback">' . $link . '</span>';
129        }
130
131        $xhtml = implode(DOKU_LF . DOKU_TAB . '&middot; ', $xhtml);
132
133        // tags - let Tag Plugin do the work for us
134        if (empty($sect) && $flags['showtags'] && (!plugin_isdisabled('tag')) && ($tag =& plugin_load('helper', 'tag'))) {
135            $page['tags'] = '<div class="tags"><span>' . DOKU_LF
136                          . DOKU_TAB . $tag->td($id) . DOKU_LF
137                          . DOKU_TAB . '</span></div>' . DOKU_LF;
138            $xhtml = $page['tags'] . DOKU_TAB . $xhtml;
139        }
140
141        if (!$xhtml) $xhtml = '&nbsp;';
142        $class = 'inclmeta';
143        $class .= ' level' . $footer_lvl;
144        return '<div class="' . $class . '">' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '</div>' . DOKU_LF;
145    }
146}
147// vim:ts=4:sw=4:et:enc=utf-8:
148