1 <?php
2 /**
3  * @license    http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
4  * @author     Francois Merciol <dokuplugin@merciol.fr>
5  *
6  * INSEE city: code database
7  */
8 
9 if (!defined ('DOKU_INC'))
10     define ('DOKU_INC', realpath (__DIR__.'/../../../').'/');
11 if (!defined ('DOKU_PLUGIN'))
12     define ('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
13 require_once(DOKU_PLUGIN.'syntax.php');
14 
15 // ============================================================
16 class syntax_plugin_ol3 extends DokuWiki_Syntax_Plugin {
17 
18     // ============================================================
19     function getType () { return 'substition'; }
20     function getPType () { return 'block'; }
21     function getSort () { return 299; }
22     function connectTo ($mode) {
23         $this->Lexer->addSpecialPattern ('\{\{ol3[^}]*\}\}', $mode, 'plugin_ol3');
24     }
25 
26     // ============================================================
27     function handle ($match, $state, $pos, Doku_Handler $handler) {
28         switch ($state) {
29         case DOKU_LEXER_SPECIAL :
30             return array ($state, trim (substr ($match, 5, -2))); // "{{ol3" => 5 "}}" => 2
31         }
32         return false;
33     }
34 
35     // ============================================================
36     function render ($mode, Doku_Renderer $renderer, $indata) {
37         $dumy = "";
38         if (empty($indata))
39             return false;
40         if ($mode != 'xhtml')
41             return false;
42         list ($instr, $data) = $indata;
43         switch ($instr) {
44         case DOKU_LEXER_SPECIAL :
45             $args = " ".$data." ";
46             if (preg_match_all ("#(\"[^\"]*\")* help (\"[^\"]*\")*#", strtolower ($args), $dumy) > 0) {
47                 $renderer->doc .= $this->ol3Help ();
48                 return true;
49             }
50             if (preg_match_all ("#(\"[^\"]*\")* test (\"[^\"]*\")*#", strtolower ($args), $dumy) > 0) {
51                 $renderer->doc .= $this->ol3Test ();
52                 return true;
53             }
54         }
55         return true;
56     }
57 
58     // ============================================================
59     function ol3Help () {
60         $url = "http://admin.parlenet.org/plugins/ol3/";
61         return
62             '<h1>Help OL3</h1>'.NL.
63             '<ul>'.NL.
64             ' <li><b>{{ol3</b> help <b>}}</b></li>'.NL.
65             ' <li><b>{{ol3</b> test <b>}}</b></li>'.NL.
66             '</ul>'.NL.
67             '<p><a class="urlextern" rel="nofollow" title="'.$url.'" href="'.$url.'">'.$url.'</a></p>'.NL;
68     }
69 
70     // ============================================================
71     function ol3Test () {
72         return
73             '<script type="text/javascript" src="/lib/plugins/ol3/test.js" defer="defer" charset="utf-8"></script>'.NL.
74             '<div id="map" class="map" style="width:200px;height:200px;"></div>'.NL;
75     }
76 
77     // ============================================================
78 }
79