xref: /plugin/include/syntax/footer.php (revision 34bf25238ac065bc91fac0fc937d1e410c6b4fe2)
16f0ad9d7SMichael Klier<?php
26f0ad9d7SMichael Klier/**
3b68e5bd3SMichael Klier * Include plugin (footer component)
46f0ad9d7SMichael Klier *
56f0ad9d7SMichael Klier * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
66f0ad9d7SMichael Klier * @author  Michael Klier <chi@chimeric.de>
76f0ad9d7SMichael Klier */
86f0ad9d7SMichael Klier
96f0ad9d7SMichael Klierclass syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin {
106f0ad9d7SMichael Klier
116f0ad9d7SMichael Klier    function getType() {
126f0ad9d7SMichael Klier        return 'formatting';
136f0ad9d7SMichael Klier    }
146f0ad9d7SMichael Klier
156f0ad9d7SMichael Klier    function getSort() {
166f0ad9d7SMichael Klier        return 300;
176f0ad9d7SMichael Klier    }
186f0ad9d7SMichael Klier
194aa23dc0SGerrit Uitslag    function handle($match, $state, $pos, Doku_Handler $handler) {
206f0ad9d7SMichael Klier        // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
216f0ad9d7SMichael Klier    }
226f0ad9d7SMichael Klier
236f0ad9d7SMichael Klier    /**
246f0ad9d7SMichael Klier     * Renders a permalink header.
256f0ad9d7SMichael Klier     *
266f0ad9d7SMichael Klier     * Code heavily copied from the header renderer from inc/parser/xhtml.php, just
276f0ad9d7SMichael Klier     * added an href parameter to the anchor tag linking to the wikilink.
286f0ad9d7SMichael Klier     */
294aa23dc0SGerrit Uitslag    function render($mode, Doku_Renderer $renderer, $data) {
306f0ad9d7SMichael Klier
316f0ad9d7SMichael Klier        list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data;
326f0ad9d7SMichael Klier
336f0ad9d7SMichael Klier        if ($mode == 'xhtml') {
346f0ad9d7SMichael Klier            $renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer);
356f0ad9d7SMichael Klier	        return true;
366f0ad9d7SMichael Klier        }
376f0ad9d7SMichael Klier        return false;
386f0ad9d7SMichael Klier    }
396f0ad9d7SMichael Klier
406f0ad9d7SMichael Klier    /**
416f0ad9d7SMichael Klier     * Returns the meta line below the included page
427a086143SMichael Hamann     * @param $renderer Doku_Renderer_xhtml The (xhtml) renderer
437a086143SMichael Hamann     * @return string The HTML code of the footer
446f0ad9d7SMichael Klier     */
456f0ad9d7SMichael Klier    function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) {
466f0ad9d7SMichael Klier        global $conf, $ID;
476f0ad9d7SMichael Klier
486f0ad9d7SMichael Klier        if(!$flags['footer']) return '';
496f0ad9d7SMichael Klier
506f0ad9d7SMichael Klier        $meta  = p_get_metadata($page);
518d13979cSMichael Hamann        $exists = page_exists($page);
526f0ad9d7SMichael Klier        $xhtml = array();
536f0ad9d7SMichael Klier        // permalink
54b68e5bd3SMichael Klier        if ($flags['permalink']) {
558d13979cSMichael Hamann            $class = ($exists ? 'wikilink1' : 'wikilink2');
56d53221c4SMichael Klier            $url   = ($sect) ? wl($page) . '#' . $sect : wl($page);
57d53221c4SMichael Klier            $name  = ($sect) ? $sect_title : $page;
58d53221c4SMichael Klier            $title = ($sect) ? $page . '#' . $sect : $page;
596f0ad9d7SMichael Klier            if (!$title) $title = str_replace('_', ' ', noNS($page));
606f0ad9d7SMichael Klier            $link = array(
61d53221c4SMichael Klier                    'url'    => $url,
62d53221c4SMichael Klier                    'title'  => $title,
63d53221c4SMichael Klier                    'name'   => $name,
646f0ad9d7SMichael Klier                    'target' => $conf['target']['wiki'],
656f0ad9d7SMichael Klier                    'class'  => $class . ' permalink',
666f0ad9d7SMichael Klier                    'more'   => 'rel="bookmark"',
676f0ad9d7SMichael Klier                    );
686f0ad9d7SMichael Klier            $xhtml[] = $renderer->_formatLink($link);
696f0ad9d7SMichael Klier        }
706f0ad9d7SMichael Klier
716f0ad9d7SMichael Klier        // date
728d13979cSMichael Hamann        if ($flags['date'] && $exists) {
736f0ad9d7SMichael Klier            $date = $meta['date']['created'];
746f0ad9d7SMichael Klier            if ($date) {
75*34bf2523SAndreas Gohr                $xhtml[] = '<abbr class="published" title="'.dformat($date, '%Y-%m-%dT%H:%M:%SZ').'">'
76*34bf2523SAndreas Gohr                       . dformat($date)
776f0ad9d7SMichael Klier                       . '</abbr>';
786f0ad9d7SMichael Klier            }
796f0ad9d7SMichael Klier        }
806f0ad9d7SMichael Klier
813fca97c9Sboukeversteegh        // modified date
828d13979cSMichael Hamann        if ($flags['mdate'] && $exists) {
833fca97c9Sboukeversteegh            $mdate = $meta['date']['modified'];
843fca97c9Sboukeversteegh            if ($mdate) {
85*34bf2523SAndreas Gohr                $xhtml[] = '<abbr class="published" title="'.dformat($mdate, '%Y-%m-%dT%H:%M:%SZ').'">'
86*34bf2523SAndreas Gohr                       . dformat($mdate)
873fca97c9Sboukeversteegh                       . '</abbr>';
883fca97c9Sboukeversteegh            }
893fca97c9Sboukeversteegh        }
903fca97c9Sboukeversteegh
916f0ad9d7SMichael Klier        // author
928d13979cSMichael Hamann        if ($flags['user'] && $exists) {
937a086143SMichael Hamann            $author   = $meta['user'];
946f0ad9d7SMichael Klier            if ($author) {
957a086143SMichael Hamann                if (function_exists('userlink')) {
967a086143SMichael Hamann                    $xhtml[] = '<span class="vcard author">' . userlink($author) . '</span>';
977a086143SMichael Hamann                } else { // DokuWiki versions < 2014-05-05 doesn't have userlink support, fall back to not providing a link
987a086143SMichael Hamann                    $xhtml[] = '<span class="vcard author">' . editorinfo($author) . '</span>';
997a086143SMichael Hamann                }
1006f0ad9d7SMichael Klier            }
1016f0ad9d7SMichael Klier        }
1026f0ad9d7SMichael Klier
1036f0ad9d7SMichael Klier        // comments - let Discussion Plugin do the work for us
10462633254SMichael Hamann        if (empty($sect) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion = plugin_load('helper', 'discussion'))) {
1056f0ad9d7SMichael Klier            $disc = $discussion->td($page);
1066f0ad9d7SMichael Klier            if ($disc) $xhtml[] = '<span class="comment">' . $disc . '</span>';
1076f0ad9d7SMichael Klier        }
1086f0ad9d7SMichael Klier
1096f0ad9d7SMichael Klier        // linkbacks - let Linkback Plugin do the work for us
11062633254SMichael Hamann        if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback = plugin_load('helper', 'linkback'))) {
1117a09d26bSMichael Klier            $link = $linkback->td($page);
1126f0ad9d7SMichael Klier            if ($link) $xhtml[] = '<span class="linkback">' . $link . '</span>';
1136f0ad9d7SMichael Klier        }
1146f0ad9d7SMichael Klier
1156f0ad9d7SMichael Klier        $xhtml = implode(DOKU_LF . DOKU_TAB . '&middot; ', $xhtml);
1166f0ad9d7SMichael Klier
1176f0ad9d7SMichael Klier        // tags - let Tag Plugin do the work for us
11862633254SMichael Hamann        if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag = plugin_load('helper', 'tag'))) {
119026df011SMichael Klier            $tags = $tag->td($page);
120026df011SMichael Klier            if($tags) {
121026df011SMichael Klier                $xhtml .= '<div class="tags"><span>' . DOKU_LF
122026df011SMichael Klier                              . DOKU_TAB . $tags . DOKU_LF
1236f0ad9d7SMichael Klier                              . DOKU_TAB . '</span></div>' . DOKU_LF;
124026df011SMichael Klier            }
1256f0ad9d7SMichael Klier        }
1266f0ad9d7SMichael Klier
1276f0ad9d7SMichael Klier        if (!$xhtml) $xhtml = '&nbsp;';
1286f0ad9d7SMichael Klier        $class = 'inclmeta';
1296f0ad9d7SMichael Klier        $class .= ' level' . $footer_lvl;
1306f0ad9d7SMichael Klier        return '<div class="' . $class . '">' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '</div>' . DOKU_LF;
1316f0ad9d7SMichael Klier    }
1326f0ad9d7SMichael Klier}
1332524d407SMichael Hamann// vim:ts=4:sw=4:et:
134