xref: /plugin/include/syntax/footer.php (revision d53221c49ccfc29a83b1abfcb3757051fc53153e)
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_editButton($page, $flags, $redirect_id);
55            $renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer);
56	        return true;
57        }
58        return false;
59    }
60
61    /**
62     * Display an edit button for the included page
63     */
64    function html_editButton($page, $flags, $redirect_id) {
65        global $lang;
66
67        if($flags['editbtn']) return '';
68
69        $xhtml = '';
70        if(auth_quickaclcheck($page) >= AUTH_EDIT) {
71            $params = array('do' => 'edit');
72            if($flags['redirect']) $params['redirect_id'] = $redirect_id;
73            $xhtml = '<div class="secedit">' . DOKU_LF
74                   .  DOKU_TAB . html_btn('secedit', $page, '', $params, 'post') . DOKU_LF
75                   . '</div>' . DOKU_LF;
76            return $xhtml;
77        }
78    }
79
80    /**
81     * Returns the meta line below the included page
82     */
83    function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) {
84        global $conf, $ID;
85
86        if(!$flags['footer']) return '';
87
88        $meta  = p_get_metadata($page);
89        $xhtml = array();
90
91        // permalink
92        if ($flags['link']) {
93            $class = (page_exists($page) ? 'wikilink1' : 'wikilink2');
94            $url   = ($sect) ? wl($page) . '#' . $sect : wl($page);
95            $name  = ($sect) ? $sect_title : $page;
96            $title = ($sect) ? $page . '#' . $sect : $page;
97            if (!$title) $title = str_replace('_', ' ', noNS($page));
98            $link = array(
99                    'url'    => $url,
100                    'title'  => $title,
101                    'name'   => $name,
102                    'target' => $conf['target']['wiki'],
103                    'class'  => $class . ' permalink',
104                    'more'   => 'rel="bookmark"',
105                    );
106            $xhtml[] = $renderer->_formatLink($link);
107        }
108
109        // date
110        if ($flags['date']) {
111            $date = $meta['date']['created'];
112            if ($date) {
113                $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $date).'">'
114                       . strftime($conf['dformat'], $date)
115                       . '</abbr>';
116            }
117        }
118
119        // author
120        if ($flags['user']) {
121            $author   = $meta['creator'];
122            if ($author) {
123                $userpage = cleanID($this->getConf('usernamespace').':'.$author);
124                resolve_pageid(getNS($ID), $userpage, $exists);
125                $class = ($exists ? 'wikilink1' : 'wikilink2');
126                $link = array(
127                        'url'    => wl($userpage),
128                        'title'  => $userpage,
129                        'name'   => hsc($author),
130                        'target' => $conf['target']['wiki'],
131                        'class'  => $class.' url fn',
132                        'pre'    => '<span class="vcard author">',
133                        'suf'    => '</span>',
134                        );
135                $xhtml[]    = $renderer->_formatLink($link);
136            }
137        }
138
139        // comments - let Discussion Plugin do the work for us
140        if (empty($sec) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion =& plugin_load('helper', 'discussion'))) {
141            $disc = $discussion->td($page);
142            if ($disc) $xhtml[] = '<span class="comment">' . $disc . '</span>';
143        }
144
145        // linkbacks - let Linkback Plugin do the work for us
146        if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback =& plugin_load('helper', 'linkback'))) {
147            $link = $linkback->td($id);
148            if ($link) $xhtml[] = '<span class="linkback">' . $link . '</span>';
149        }
150
151        $xhtml = implode(DOKU_LF . DOKU_TAB . '&middot; ', $xhtml);
152
153        // tags - let Tag Plugin do the work for us
154        if (empty($sect) && $flags['showtags'] && (!plugin_isdisabled('tag')) && ($tag =& plugin_load('helper', 'tag'))) {
155            $page['tags'] = '<div class="tags"><span>' . DOKU_LF
156                          . DOKU_TAB . $tag->td($id) . DOKU_LF
157                          . DOKU_TAB . '</span></div>' . DOKU_LF;
158            $xhtml = $page['tags'] . DOKU_TAB . $xhtml;
159        }
160
161        if (!$xhtml) $xhtml = '&nbsp;';
162        $class = 'inclmeta';
163        $class .= ' level' . $footer_lvl;
164        return '<div class="' . $class . '">' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '</div>' . DOKU_LF;
165    }
166}
167// vim:ts=4:sw=4:et:enc=utf-8:
168