1<?php
2/**
3* Documentation Includer: Includes documentation pages for templates (template:doc) into the "Documentation" template.
4* Syntax: @DOC@
5* Note that this extension was developed specifically for Lemming DokuWiki.
6* @author     Harommel Rabbid
7*/
8
9
10/**
11 * All DokuWiki plugins to extend the parser/rendering mechanism
12 * need to inherit from this class
13 */
14if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/');
15require_once(DOKU_INC.'inc/init.php');
16
17class syntax_plugin_docincluder extends DokuWiki_Syntax_Plugin {
18
19
20
21   /**
22    * Get the type of syntax this plugin defines.
23    *
24    * @param none
25    * @return String <tt>'substition'</tt> (i.e. 'substitution').
26    * @public
27    * @static
28    */
29    function getType(){
30        return 'substition';
31    }
32
33    /**
34     * What kind of syntax do we allow (optional)
35     */
36//    function getAllowedTypes() {
37//        return array();
38//    }
39
40   /**
41    * Define how this plugin is handled regarding paragraphs.
42    *
43    * <p>
44    * This method is important for correct XHTML nesting. It returns
45    * one of the following values:
46    * </p>
47    * <dl>
48    * <dt>normal</dt><dd>The plugin can be used inside paragraphs.</dd>
49    * <dt>block</dt><dd>Open paragraphs need to be closed before
50    * plugin output.</dd>
51    * <dt>stack</dt><dd>Special case: Plugin wraps other paragraphs.</dd>
52    * </dl>
53    * @param none
54    * @return String <tt>'block'</tt>.
55    * @public
56    * @static
57    */
58//    function getPType(){
59//        return 'normal';
60//    }
61
62   /**
63    * Where to sort in?
64    *
65    * @param none
66    * @return Integer <tt>6</tt>.
67    * @public
68    * @static
69    */
70    function getSort(){
71        return 999;
72    }
73
74
75   /**
76    * Connect lookup pattern to lexer.
77    *
78    * @param $aMode String The desired rendermode.
79    * @return none
80    * @public
81    * @see render()
82    */
83    function connectTo($mode) {
84      $this->Lexer->addSpecialPattern('~~DOC~~',$mode,'plugin_docincluder');
85//      $this->Lexer->addEntryPattern('<TEST>',$mode,'plugin_test');
86    }
87
88//    function postConnect() {
89//      $this->Lexer->addExitPattern('</TEST>','plugin_test');
90//    }
91
92
93   /**
94    * Handler to prepare matched data for the rendering process.
95    *
96    * <p>
97    * The <tt>$aState</tt> parameter gives the type of pattern
98    * which triggered the call to this method:
99    * </p>
100    * <dl>
101    * <dt>DOKU_LEXER_ENTER</dt>
102    * <dd>a pattern set by <tt>addEntryPattern()</tt></dd>
103    * <dt>DOKU_LEXER_MATCHED</dt>
104    * <dd>a pattern set by <tt>addPattern()</tt></dd>
105    * <dt>DOKU_LEXER_EXIT</dt>
106    * <dd> a pattern set by <tt>addExitPattern()</tt></dd>
107    * <dt>DOKU_LEXER_SPECIAL</dt>
108    * <dd>a pattern set by <tt>addSpecialPattern()</tt></dd>
109    * <dt>DOKU_LEXER_UNMATCHED</dt>
110    * <dd>ordinary text encountered within the plugin's syntax mode
111    * which doesn't match any pattern.</dd>
112    * </dl>
113    * @param $aMatch String The text matched by the patterns.
114    * @param $aState Integer The lexer state for the match.
115    * @param $aPos Integer The character position of the matched text.
116    * @param $aHandler Object Reference to the Doku_Handler object.
117    * @return Integer The current lexer state for the match.
118    * @public
119    * @see render()
120    * @static
121    */
122    function handle($match, $state, $pos, Doku_Handler $handler){
123        switch ($state) {
124          case DOKU_LEXER_ENTER :
125            break;
126          case DOKU_LEXER_MATCHED :
127            break;
128          case DOKU_LEXER_UNMATCHED :
129            break;
130          case DOKU_LEXER_EXIT :
131            break;
132          case DOKU_LEXER_SPECIAL :
133            break;
134        }
135        return array();
136    }
137
138   /**
139    * Handle the actual output creation.
140    *
141    * <p>
142    * The method checks for the given <tt>$aFormat</tt> and returns
143    * <tt>FALSE</tt> when a format isn't supported. <tt>$aRenderer</tt>
144    * contains a reference to the renderer object which is currently
145    * handling the rendering. The contents of <tt>$aData</tt> is the
146    * return value of the <tt>handle()</tt> method.
147    * </p>
148    * @param $aFormat String The output format to generate.
149    * @param $aRenderer Object A reference to the renderer object.
150    * @param $aData Array The data created by the <tt>handle()</tt>
151    * method.
152    * @return Boolean <tt>TRUE</tt> if rendered successfully, or
153    * <tt>FALSE</tt> otherwise.
154    * @public
155    * @see handle()
156    */
157function render($mode, Doku_Renderer $renderer, $data) {
158        if($mode == 'xhtml'){
159            $ID = cleanID(getID());
160            $text = strtr(noNS($ID),'_',' ');
161            $text2 = "template:doc:{$text}";
162            if (rawWiki($text2) == '') {
163                $renderer->doc .= $renderer->render_text($this->getLang('no_doc'), 'xhtml');
164            }
165            else {
166                $renderer->doc .= $renderer->render_text(rawWiki($text2), 'xhtml');
167            }
168            return true;
169        }
170        return false;
171    }
172}
173