1<?php
2
3/**
4 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
5   *
6   * class       plugin_ckgedit_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/ckgedit/images/');
16//define ('CK_IMG_PATH',DOKU_INC . 'lib/plugins/ckgedit/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_ckgedit_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_ckgedit_specials');
57          $this->Lexer->addSpecialPattern('~~MULTI_PLUGIN_CLOSE~~',$mode,'plugin_ckgedit_specials');
58          $this->Lexer->addSpecialPattern('~~COMPLEX_TABLES~~',$mode,'plugin_ckgedit_specials');
59          $this->Lexer->addSpecialPattern('~~NO_STYLING~~',$mode,'plugin_ckgedit_specials');
60          $this->Lexer->addEntryPattern('~~START_HTML_BLOCK~~(?=.*?~~CLOSE_HTML_BLOCK~~)',$mode,'plugin_ckgedit_specials');
61         $this->Lexer->addSpecialPattern('~~AUTO_INTERNAL_LINKS~~',$mode,'plugin_ckgedit_specials');
62
63
64    }
65     function postConnect() { $this->Lexer->addExitPattern('~~CLOSE_HTML_BLOCK~~','plugin_ckgedit_specials'); }
66
67    /**
68     * Handle the match
69     */
70    function handle($match, $state, $pos, Doku_Handler $handler){
71
72        $class = "";
73        $xhtml = "";
74        switch($state) {
75            case DOKU_LEXER_SPECIAL:
76        if(preg_match('/OPEN/', $match)) {
77           return array($state, "<span class='multi_p_open'></span>" );
78        }
79        elseif(preg_match('/CLOSE/', $match)) {
80              return array($state, "<span class='multi_p_close'></span>" );
81        }
82        elseif(preg_match('/(TABLES|STYLING|AUTO_INTERNAL)/', $match)) {
83              return array($state, "" );
84        }
85          case DOKU_LEXER_ENTER :  return array($state, '');
86          case DOKU_LEXER_UNMATCHED :
87              $match = str_replace('<div class="table">',"",$match);
88              $match = preg_replace('/<\/?code>/ms',"",$match);
89              return array($state, $match);
90          case DOKU_LEXER_EXIT :       return array($state, '');
91       }
92         return array($state, "" );
93
94    }
95
96    /**
97     * Create output
98     */
99    function render($mode, Doku_Renderer $renderer, $data) {
100        if($mode == 'xhtml'){
101            list($state, $xhtml) = $data;
102            switch ($state) {
103                case DOKU_LEXER_SPECIAL:
104            $renderer->doc .=  DOKU_LF . $xhtml . DOKU_LF;
105            return true;
106                case DOKU_LEXER_ENTER :  $renderer->doc .= ""; break;
107                case DOKU_LEXER_UNMATCHED :
108                $renderer->doc .= $xhtml; break;
109                case DOKU_LEXER_EXIT :       $renderer->doc .= ""; break;
110        }
111           return true;
112        }
113        return false;
114    }
115
116  function write_debug($what) {
117     $handle = fopen("blog_pats.txt", "a");
118     fwrite($handle,"$what\n");
119     fclose($handle);
120  }
121}
122
123
124