1 <?php
2 /**
3  *
4  *
5  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6  * @author     Myron Turner <turnermm02@shaw.ca>
7  *
8  */
9 // must be run within Dokuwiki
10 if(!defined('DOKU_INC')) die();
11 
12 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13 define('TOCSEL_DIR', DOKU_BASE . 'lib/plugins/tocselect/');
14 require_once(DOKU_PLUGIN.'syntax.php');
15 
16 /**
17  * All DokuWiki plugins to extend the parser/rendering mechanism
18  * need to inherit from this class
19  */
20 class syntax_plugin_tocselect extends DokuWiki_Syntax_Plugin {
21 
22     function getType(){
23         return 'substition';
24     }
25 
26     /**
27      * Where to sort in?
28      */
29     function getSort(){
30         return 155;
31     }
32     function getPType() {
33         return 'block';
34     }
35 
36    function connectTo($mode) {
37         $this->Lexer->addSpecialPattern('~~SELECTTOC~~',$mode,'plugin_tocselect');
38         $this->Lexer->addSpecialPattern('~~SELECTTOC>curID~~',$mode,'plugin_tocselect');
39     }
40 
41   function handle($match, $state, $pos, Doku_Handler $handler) {
42 
43             $handler->_addCall('notoc',array(),$pos);
44            if(preg_match('/curID/', $match)) {
45                $match = 'curID';
46            }
47            else $match = 'wiki:id';
48 
49            return array($state,$match);
50   }
51 
52    function render($mode, Doku_Renderer $renderer, $data) {
53         if($mode == 'xhtml'){
54          global $lang;
55          $select = $this->getLang('select');
56          $nsroot = $this->getLang('nsroot');
57          $rootopen = $this->getLang('rootopen');
58          list($state,$wikid) = $data;
59          $renderer->doc .='<div class="tocsel_right">';
60          $renderer->doc .='<span class="clickerdir  tocselb hx1_5" id="tocsel_rootns"  title="' .  $rootopen . '" onclick="tocsel_updatetoc(\':*\');">'. $nsroot.'</span><br />';
61          $renderer->doc .=  '<DIV><FORM><input type="button" value="' . $select. '" id="selectoc_btn"  name="selectoc_btn" /> <INPUT  type="text" title="wiki:id" id="selectoc_id" name="selectoc_id" value="'.$wikid .'"></FORM></DIV>';
62          $renderer->doc .= '<div id="tocseltoggle"><img src="'  . TOCSEL_DIR. 'img/open.png"></div ><span class="tocsel_title">'  . $lang['toc'] .'</span><div id = "setctoc_out"></div>';
63          $renderer->doc .='</div>';
64          return true;
65         }
66         return false;
67    }
68 }