1<?php
2
3/**
4 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
5   *
6   * class       plugin_ckgdoku_specials
7   * @author     Myron Turner <turnermm02@shaw.ca>
8*/
9
10// must be run within Dokuwiki
11if(!defined('DOKU_INC')) die();
12
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14require_once(DOKU_PLUGIN.'syntax.php');
15//define ('CKGEDIT_IMAGES', DOKU_URL . 'lib/plugins/ckgdoku/images/');
16//define ('CK_IMG_PATH',DOKU_INC . 'lib/plugins/ckgdoku/images/');
17if(!defined('DOKU_LF')) define ('DOKU_LF',"\n");
18if(!defined('DOKU_TAB')) define ('DOKU_TAB',"\t");
19
20/**
21 * All DokuWiki plugins to extend the parser/rendering mechanism
22 * need to inherit from this class
23 */
24class syntax_plugin_ckgdoku_specials extends DokuWiki_Syntax_Plugin {
25
26
27    /**
28     * What kind of syntax are we?
29     */
30    function getType(){
31        return 'substition';
32    }
33
34    /**
35     * What about paragraphs?
36     */
37
38    function getPType(){
39       //  return 'stack';
40       return 'block';
41    }
42
43    /**
44     * Where to sort in?
45     */
46    function getSort(){
47        return 155;
48    }
49
50
51    /**
52     * Connect pattern to lexer
53     */
54    function connectTo($mode) {
55
56          $this->Lexer->addSpecialPattern('~~MULTI_PLUGIN_OPEN~~',$mode,'plugin_ckgdoku_specials');
57          $this->Lexer->addSpecialPattern('~~MULTI_PLUGIN_CLOSE~~',$mode,'plugin_ckgdoku_specials');
58          $this->Lexer->addSpecialPattern('~~COMPLEX_TABLES~~',$mode,'plugin_ckgdoku_specials');
59          $this->Lexer->addSpecialPattern('~~NO_STYLING~~',$mode,'plugin_ckgdoku_specials');
60          $this->Lexer->addSpecialPattern('~~AUTO_INTERNAL_LINKS~~',$mode,'plugin_ckgdoku_specials');
61
62          $this->Lexer->addEntryPattern('~~START_HTML_BLOCK~~(?=.*?~~CLOSE_HTML_BLOCK~~)',$mode,'plugin_ckgdoku_specials');
63
64
65    }
66     function postConnect() { $this->Lexer->addExitPattern('~~CLOSE_HTML_BLOCK~~','plugin_ckgdoku_specials'); }
67
68    /**
69     * Handle the match
70     */
71    function handle($match, $state, $pos, Doku_Handler $handler){
72
73        $class = "";
74        $xhtml = "";
75        switch($state) {
76            case DOKU_LEXER_SPECIAL:
77        if(preg_match('/OPEN/', $match)) {
78           return array($state, "<span class='multi_p_open'></span>" );
79        }
80        elseif(preg_match('/CLOSE/', $match)) {
81              return array($state, "<span class='multi_p_close'></span>" );
82        }
83        elseif(preg_match('/(TABLES|STYLING|AUTO_INTERNAL)/', $match)) {
84              return array($state, "" );
85        }
86          case DOKU_LEXER_ENTER :  return array($state, '');
87          case DOKU_LEXER_UNMATCHED :
88              $match = str_replace('<div class="table">',"",$match);
89              $match = preg_replace('/<\/?code>/ms',"",$match);
90              return array($state, $match);
91          case DOKU_LEXER_EXIT :       return array($state, '');
92       }
93         return array($state, "" );
94
95    }
96
97    /**
98     * Create output
99     */
100    function render($mode, Doku_Renderer $renderer, $data) {
101        if($mode == 'xhtml'){
102            list($state, $xhtml) = $data;
103            switch ($state) {
104                case DOKU_LEXER_SPECIAL:
105            $renderer->doc .=  DOKU_LF . $xhtml . DOKU_LF;
106            return true;
107                case DOKU_LEXER_ENTER :  $renderer->doc .= ""; break;
108                case DOKU_LEXER_UNMATCHED :
109                $renderer->doc .= $xhtml; break;
110                case DOKU_LEXER_EXIT :       $renderer->doc .= ""; break;
111        }
112           return true;
113        }
114        return false;
115    }
116
117  function write_debug($what) {
118     $handle = fopen("blog_pats.txt", "a");
119     fwrite($handle,"$what\n");
120     fclose($handle);
121  }
122}
123
124
125