summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/tag/syntax/tagpage.php
blob: bec2e70c85730766d1bb510bdd1058d476a01563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
 * Tag Plugin: Display a link to the listing of all pages with a certain tag.
 *
 * Usage: {{tagpage>mytag[&dynamic][|title]}}
 *
 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author   Matthias Schulte <dokuwiki@lupo49.de>
 */

/** Tagpage syntax, allows to link to a given tag */
class syntax_plugin_tag_tagpage extends DokuWiki_Syntax_Plugin {

    /**
     * @return string Syntax type
     */
    function getType() {
        return 'substition';
    }

    /**
     * @return int Sort order
     */
    function getSort() {
        return 305;
    }

    /**
     * @return string Paragraph type
     */
    function getPType() {
        return 'normal';
    }

    /**
     * @param string $mode Parser mode
     */
    function connectTo($mode) {
        $this->Lexer->addSpecialPattern('\{\{tagpage>.*?\}\}', $mode, 'plugin_tag_tagpage');
    }

    /**
     * Handle matches of the count syntax
     *
     * @param string          $match The match of the syntax
     * @param int             $state The state of the handler
     * @param int             $pos The position in the document
     * @param Doku_Handler    $handler The handler
     * @return array Data for the renderer
     */
    function handle($match, $state, $pos, Doku_Handler $handler) {
        $params            = array();
        $dump              = trim(substr($match, 10, -2)); // get given tag
        $dump              = explode('|', $dump, 2); // split to tags, link name and options
        $params['title']   = $dump[1];
        $dump              = explode('&', $dump[0]);
        $params['dynamic'] = ($dump[1] == 'dynamic');
        $params['tag']     = trim($dump[0]);

        return $params;
    }

    /**
     * Render xhtml output
     *
     * @param string         $mode      Renderer mode (supported modes: xhtml)
     * @param Doku_Renderer  $renderer  The renderer
     * @param array          $data      The data from the handler function
     * @return bool If rendering was successful.
     */
    function render($mode, Doku_Renderer $renderer, $data) {
        if($data == false) return false;

        if($mode == "xhtml") {
            if($data['dynamic']) {
                // deactivate (renderer) cache as long as there is no proper cache handling
                // implemented for the count syntax
                $renderer->nocache();
            }

            /** @var helper_plugin_tag $my */
            if(!($my = $this->loadHelper('tag'))) return false;

            $renderer->doc .= $my->tagLink($data['tag'], $data['title'], $data['dynamic']);
            return true;
        }
        return false;
    }
}
// vim:ts=4:sw=4:et: