1<?php
2/**
3 * Display quotations
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 * @author     Trailjeep <trailjeep@gmil.com>
8 */
9
10
11class syntax_plugin_jquotes extends DokuWiki_Syntax_Plugin {
12
13    /**
14     * What kind of syntax are we?
15     */
16    function getType() {
17        return 'substition';
18    }
19
20    /**
21     * What about paragraphs?
22     */
23    function getPType() {
24        return 'block';
25    }
26
27    /**
28     * Where to sort in?
29     */
30    function getSort() {
31        return 302;
32    }
33
34    /**
35     * Connect pattern to lexer
36     */
37    function connectTo($mode) {
38        $this->Lexer->addSpecialPattern('\{\{jquotes>[^}]*\}\}', $mode, 'plugin_jquotes');
39    }
40
41    /**
42     * Handle the match
43     */
44    function handle($match, $state, $pos, Doku_Handler $handler) {
45        $match = substr($match, 11, -2); //strip markup from start and end
46
47        $data = array();
48
49        //handle params
50        list($cookie, $params) = explode('?', $match, 2);
51
52        // quotes file
53        $data['cookie'] = cleanID($cookie);
54
55        //time interval for changing cookies
56        $data['time'] = 30;
57        if(preg_match('/\b(\d+)\b/i', $params, $match)) {
58            $data['time'] = (int) $match[1];
59        }
60
61        //no hammering please!
62        if($data['time'] < 5) $data['time'] = 5;
63
64        return $data;
65    }
66
67    /**
68     * Create output
69     */
70    function render($mode, Doku_Renderer $renderer, $data) {
71        if($mode != 'xhtml') return false;
72
73        $attr = array(
74            'class' => 'plugin_jquotes',
75            'data-time' => $data['time'],
76            'data-cookie' => $data['cookie']
77        );
78
79        $full = explode('|', helper_plugin_jquotes::getCookieHTML($data['cookie']));
80        $quote = $full[0];
81        $cite = $full[1];
82
83        $renderer->doc .= '<figure '.buildAttributes($attr).' onClick="copy_quote()">';
84        $renderer->doc .= "<blockquote><p>$quote</p></blockquote>";
85        $renderer->doc .= "<figcaption>$cite</figcaption>";
86        $renderer->doc .= '</figure>';
87
88        return true;
89    }
90
91}
92
93//Setup VIM: ex: et ts=4 enc=utf-8 :
94