1 <?php
2   /**
3    * @license    http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
4    * @author     Francois <webmestre@fsl56.org>
5    *
6    * Plugin showSamples: display sample from plugins
7    */
8 
9 if (!defined ('DOKU_INC'))
10   die ();
11 if (!defined ('DOKU_PLUGIN'))
12   define ('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
13 require_once (DOKU_PLUGIN.'syntax.php');
14 
15 class syntax_plugin_showSamples extends DokuWiki_Syntax_Plugin {
16 
17   // ============================================================
18   // function getInfo () {
19   //   return confToHash (dirname (__FILE__).'/INFO.txt');
20   // }
21   function getType () { return 'substition'; }
22   function getPType () { return 'block'; }
23   function getSort () { return 299; }
24   function getAllowedTypes() { return array ('container', 'baseonly', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); }
25   function connectTo ($mode) {
26     $this->Lexer->addEntryPattern ('<showSamples[^>]*>', $mode, 'plugin_showsamples');
27   }
28   function postConnect() {
29     $this->Lexer->addExitPattern ('</showSamples>', 'plugin_showsamples');
30   }
31 
32   // ============================================================
33   function handle ($match, $state, $pos, Doku_Handler $handler){
34     switch ($state) {
35     case DOKU_LEXER_ENTER:
36       return array($state, trim (substr ($match, 12, -1))); // "<showSamples" => 12 ">" => 1
37     case DOKU_LEXER_UNMATCHED:
38       return array($state, $match);
39     case DOKU_LEXER_EXIT:
40       return array($state);
41     }
42     return false;
43   }
44 
45   // ============================================================
46   function render ($mode, Doku_Renderer $renderer, $indata) {
47     if ($mode != 'xhtml')
48       return false;
49     if (empty ($indata))
50       return false;
51     list ($instr, $data) = $indata;
52     //$data = " ".$data." ";
53     $renderer->info['cache'] = FALSE;
54     switch ($instr) {
55     case DOKU_LEXER_ENTER :
56       if (preg_match_all ("#(\"[^\"]*\")*help(\"[^\"]*\")*#", strtolower ($data), $dumy) > 0) {
57 	$this->help ($renderer);
58 	return true;
59       }
60       $imgDir = DOKU_REL.'lib/plugins/showsamples/images/';
61       $renderer->doc .=
62 	'<div class="showSamples">'.NL.
63 	' <div class="navi">'.NL.
64 	'  <a onClick="showCarouselLeft()"><img src="'.$imgDir.'left.png" style="display:none;" class="leftside"/></a>'.NL.
65 	'  <a onClick="showCarouselRight()"><img src="'.$imgDir.'right.png" class="rightside"/></a>'.NL.
66 	' </div>'.NL.
67 	' <div class="slide">';
68       break;
69     case DOKU_LEXER_EXIT :
70       $renderer->doc .=
71 	' </div>'.NL.
72 	'</div>';
73       break;
74     case DOKU_LEXER_UNMATCHED:
75       $renderer->doc .= $renderer->_xmlEntities($data);
76       break;
77     }
78     return true;
79   }
80 
81   // ============================================================
82   function help (&$renderer) {
83     $url = "http://fsl56.org/admin/plugins/showSamples/";
84     $renderer->doc .=
85       '      <h1>Help showSamples V1.0</h1>'.NL.
86       '      <ul>'.NL.
87       '        <li><b>{{showSamples [help] <b>}}</b></li>'.NL.
88       '      </ul>'.NL.
89       '      <p><a class="urlextern" rel="nofollow" title="'.$url.'" href="'.$url.'">'.$url.'</a></p>'.NL;
90   }
91 
92   // ============================================================
93 } // syntax_plugin_showSamples
94 ?>
95