9 | */
10 |
11 | if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
12 | if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13 | require_once(DOKU_PLUGIN.'syntax.php');
14 |
15 | // maintain a global count of the number of folded elements in the page,
16 | // this allows each to be uniquely identified
17 | global $plugin_folded_count;
18 | if (!isset($plugin_folded_count)) $plugin_folded_count = 0;
19 |
20 | // global used to indicate that the localised folder link title tooltips
21 | // strings have been written out
22 | global $plugin_folded_strings_set;
23 | if (!isset($plugin_folded_string_set)) $plugin_folded_string_set = false;
24 |
25 | /**
26 | * All DokuWiki plugins to extend the parser/rendering mechanism
27 | * need to inherit from this class
28 | */
29 | class syntax_plugin_folded_div extends DokuWiki_Syntax_Plugin {
30 |
31 | function getType(){ return 'container'; }
32 | function getPType() { return 'stack'; }
33 | function getAllowedTypes() { return array('container','substition','protected','disabled','paragraphs','formatting'); }
34 | function getSort(){ return 404; }
35 | function connectTo($mode) { $this->Lexer->addEntryPattern('\+\+\+\+.*?\|(?=.*\+\+\+\+)',$mode,'plugin_folded_div'); }
36 | function postConnect() { $this->Lexer->addExitPattern('\+\+\+\+','plugin_folded_div'); }
37 |
38 | /**
39 | * Handle the match
40 | */
41 | function handle($match, $state, $pos, Doku_Handler $handler){
42 | if ($state == DOKU_LEXER_ENTER){
43 | $match = trim(substr($match,4,-1)); // strip markup
44 | } else if ($state == DOKU_LEXER_UNMATCHED) {
45 | $handler->_addCall('cdata',array($match), $pos);
46 | return false;
47 | }
48 | return array($state, $match);
49 | }
50 |
51 | /**
52 | * Create output
53 | */
54 | function render($mode, Doku_Renderer $renderer, $data) {
55 | global $plugin_folded_count;
56 |
57 | if (empty($data)) return false;
58 | list($state, $cdata) = $data;
59 |
60 | if($mode == 'xhtml') {
61 | switch ($state){
62 | case DOKU_LEXER_ENTER:
63 | $plugin_folded_count++;
64 | $renderer->doc .= '';
65 |
66 | if ($cdata)
67 | $renderer->doc .= ' '.$renderer->cdata($cdata);
68 |
69 | $renderer->doc .= '
';
70 | break;
71 |
72 | case DOKU_LEXER_UNMATCHED: // defensive, shouldn't occur
73 | $renderer->cdata($cdata);
74 | break;
75 |
76 | case DOKU_LEXER_EXIT:
77 | $renderer->doc .= '
';
78 | break;
79 | }
80 | return true;
81 | } else {
82 | // handle unknown formats generically - by calling standard render methods
83 | switch ( $state ) {
84 | case DOKU_LEXER_ENTER:
85 | $renderer->p_open();
86 | $renderer->cdata($cdata);
87 | $renderer->p_close();
88 | break;
89 | case DOKU_LEXER_UNMATCHED: // defensive, shouldn't occur
90 | $renderer->cdata($cdata);
91 | break;
92 | case DOKU_LEXER_EXIT:
93 | break;
94 | }
95 | }
96 | return false;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------