1<?php
2/*
3 http://qrcode.kaywa.com/
4 http://de.wikipedia.org/wiki/QR_Code
5 Und hier der Code:
6 URL:
7 <img src="http://qrcode.kaywa.com/img.php?s=6&d=http%3A%2F%2Fwww.ich-bin-am-wandern-gewesen.de%2F" alt="qrcode"  />
8 Tel:
9 <img src="http://qrcode.kaywa.com/img.php?s=6&d=TEL%3A%2B491632575970" alt="qrcode"  />
10 Text:
11 <img src="http://qrcode.kaywa.com/img.php?s=6&d=DuDa" alt="qrcode"  />
12 SMS:
13 <img src="http://qrcode.kaywa.com/img.php?s=6&d=SMSTO%3A%2B491632575970%3ADuDa" alt="qrcode"  />
14 Groessen:
15 s=5 : S
16 s=6 : M
17 s=8 : L
18 s=12 : XL
19 */
20
21/**
22 * Plugin qrcode: 2D-Barcode Implementation
23 *
24 * @license    GNU
25 * @author     Juergen A.Lamers <jaloma.ac@googlemail.com>
26 */
27
28if (!defined('DOKU_INC'))
29define('DOKU_INC', realpath(dirname( __FILE__ ).'/../../../').'/');
30if (!defined('DOKU_PLUGIN'))
31define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
32require_once (DOKU_PLUGIN.'syntax.php');
33
34/**
35 * All DokuWiki plugins to extend the parser/rendering mechanism
36 * need to inherit from this class
37 */
38
39class syntax_plugin_qrcode_qrcode extends DokuWiki_Syntax_Plugin
40{
41
42    /**
43     * return some info
44     */
45    function getInfo()
46    {
47        return array (
48        'author'=>'Juergen A.Lamers',
49        'email'=>'jaloma.ac@googlemail.com',
50        'date'=>@file_get_contents(DOKU_PLUGIN . 'qrcode/VERSION'),
51        'name'=>'qrcode -- 2D-Barcode Plugin',
52        'desc'=>'2D-Barcode Plugin using http://qrcode.kaywa.com/ ~~QRCODE~text~~',
53        'url'=>'http://wiki.splitbrain.org/plugin:qrcode',
54        );
55    }
56
57    /**
58     * What kind of syntax are we?
59     */
60    function getType()
61    {
62        return 'substition';
63    }
64
65    /**
66     * What about paragraphs? (optional)
67     */
68    function getPType()
69    {
70        return 'inline';
71    }
72
73    /**
74     * Where to sort in?
75     */
76    function getSort()
77    {
78        return 999;
79    }
80
81    /**
82     * Connect pattern to lexer
83     */
84    function connectTo($mode)
85    {
86        $this->Lexer->addSpecialPattern('~~QRCODE.*?~~', $mode, 'plugin_qrcode_qrcode');
87    }
88
89    /**
90     * Handle the match
91     */
92    function handle($match, $state, $pos, & $handler)
93    {
94        global $conf;
95        $resultStr = '';
96        $paramsArr = explode('~', $match);
97        $align = "";//"middle";
98        $last = count($paramsArr);
99        for ($i = 0; $i < $last; $i++)
100        {
101            $currentParam = $paramsArr[$i];
102            if ($i == 3 && $currentParam[0] == ' ')
103            {
104                $align = 'align="left"';//"top";
105                $currentParam = substr($currentParam, 1);
106            } elseif ($currentParam[strlen($currentParam)-1] == ' ' && $i == ($last-3))
107            {
108                // Habe ich schon am Anfang ein ' ' gehabt, schalte ich jetzt auf 'center' um
109                if ($align == 'align="left"')
110                {
111                    $align = 'align="center"';
112                } else
113                {
114                    $align = 'align="right"';//"bottom";
115                }
116                $currentParam = substr($currentParam, 1, sizeof($currentParam)-1);
117            }
118            $paramPairArr = explode('=', $currentParam);
119            switch($paramPairArr[0])
120            {
121                case 'QRCODE':
122                    break;
123                case '':
124                    break;
125                case 'size':
126                    $size = $paramPairArr[1];
127                    /*
128                     s=5 : S
129                     s=6 : M
130                     s=8 : L
131                     s=12 : XL
132                     */
133                    switch($size)
134                    {
135                        case 'S':
136                            $resultStr .= '&amp;s=5';
137                            break;
138                        case 'M':
139                            $resultStr .= '&amp;s=6';
140                            break;
141                        case 'L':
142                            $resultStr .= '&amp;s=8';
143                            break;
144                        case 'XL':
145                            $resultStr .= '&amp;s=12';
146                            break;
147                        default:
148                            $resultStr .= '&amp;s=15';
149                            break;
150
151                }
152            case 'url':
153                /*
154                 URL:
155                 <img src="http://qrcode.kaywa.com/img.php?s=6&d=http%3A%2F%2Fwww.ich-bin-am-wandern-gewesen.de%2F" alt="qrcode"  />
156                 */
157                $resultStr .= '&amp;d=http%3A%2F%2F'.htmlspecialchars($paramPairArr[1], ENT_QUOTES, 'UTF-8');
158                break;
159            case 'tel':
160                /*
161                 Tel:
162                 <img src="http://qrcode.kaywa.com/img.php?s=6&d=TEL%3A%2B491632575970" alt="qrcode"  />
163                 */
164                $resultStr .= '&amp;d=TEL'.htmlspecialchars($paramPairArr[1], ENT_QUOTES, 'UTF-8');
165                break;
166            case 'text':
167                /*
168                 Text:
169                 <img src="http://qrcode.kaywa.com/img.php?s=6&d=DuDa" alt="qrcode"  />
170                 */
171                $resultStr .= '&amp;d='.htmlspecialchars($paramPairArr[1], ENT_QUOTES, 'UTF-8');
172                break;
173            case 'sms':
174                /*
175                 SMS:
176                 <img src="http://qrcode.kaywa.com/img.php?s=6&d=SMSTO%3A%2B491632575970%3ADuDa" alt="qrcode"  />
177                 */
178                $resultStr .= '&amp;d=SMSTO'.htmlspecialchars($paramPairArr[1], ENT_QUOTES, 'UTF-8');
179                break;
180
181            default:
182                //					$resultStr .= ' ' . $paramPairArr[0] . '="' . $paramPairArr[1] . '"';
183                break;
184        }
185    }
186    /*
187     Don't have barcode reader ? click here http://www.freewarepocketpc.net/ppc-tag-barcode.html
188     QRcode generated by Tec-it http://www.tec-it.com/online-demos/tbarcode/barcode-generator.aspx
189     qrcode.kaywa.com
190     <a href="http://www.freewarepocketpc.net/ppc-download-i-nigma-barcode-reader-v1-4.html">Download i-nigma barcode reader v1.40</a>
191     */
192    return '<img src="http://qrcode.kaywa.com/img.php?'.$resultStr.'" '.$align.' style="valign:top;" alt="qrcode" />';
193}
194
195
196/**
197 * Create output
198 */
199function render($mode, & $renderer, $data)
200{
201    if ($mode == 'xhtml')
202    {
203        $renderer->doc .= $data;
204        if ($this->getConf('qrcodeshowfooter'))
205        {
206            $txt = 'Dont have barcode reader ? click here http://www.freewarepocketpc.net/ppc-tag-barcode.html
207QRcode generated by Tec-it http://www.tec-it.com/online-demos/tbarcode/barcode-generator.aspx
208qrcode.kaywa.com
209
210<a href="http://www.freewarepocketpc.net/ppc-download-i-nigma-barcode-reader-v1-4.html">Download i-nigma barcode reader v1.40</a>
211';
212            $renderer->doc .= $txt;
213        }
214        return true;
215    }
216    return false;
217}
218} // Class
219
220
221//Setup VIM: ex: et ts=4 enc=utf-8 :
222