1<?php
2/**
3 * QRCode Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Daniel Pätzold <mailto://obel1x@web.de>
7 */
8
9
10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13require_once(DOKU_INC.'inc/search.php');
14require_once(DOKU_INC.'conf/dokuwiki.php');
15
16/**
17 * All DokuWiki plugins to extend the parser/rendering mechanism
18 * need to inherit from this class
19 */
20class syntax_plugin_qrcode2 extends DokuWiki_Syntax_Plugin {
21
22    /**
23     * What kind of syntax are we?
24     */
25    function getType(){
26        return 'substition';
27    }
28
29    /**
30     * What about paragraphs?
31     */
32    function getPType(){
33        return 'block';
34    }
35
36    /**
37     * Where to sort in?
38     */
39    function getSort(){
40        return 32;
41    }
42
43
44    /**
45     * Connect pattern to lexer
46     */
47    function connectTo($mode) {
48        $this->Lexer->addSpecialPattern('\{\{QRCODE>[^}]*\}\}',$mode,'plugin_qrcode2');
49    }
50
51
52    /**
53     * Handle the match
54     */
55    function handle($match, $state, $pos, Doku_Handler $handler){
56        $ret = urlencode(substr($match,9,-2)); //strip {{QRCODE> from start and }} from end
57        return $ret;
58    }
59
60    /**
61     * Create output
62     */
63    public function render($mode, Doku_Renderer $renderer, $data) {
64		global $conf;
65
66        // $data is what the function handle return'ed.
67        if($mode == 'xhtml'){
68            /** @var Doku_Renderer_xhtml $renderer */
69
70			if(isset($conf['userewrite']) && $conf['userewrite'] == 2) {
71				$renderer->doc .= '<img src="../lib/plugins/qrcode2/png.php?id='.$data.'" />';
72			}
73			else {
74				$renderer->doc .= '<img src="lib/plugins/qrcode2/png.php?id='.$data.'" />';
75			}
76
77            return true;
78        }
79        return false;
80    }
81}
82
83//Setup VIM: ex: et ts=4 enc=utf-8 :
84