slitaz-doc-wiki-data view plugins/note/syntax.php @ rev 140

Add TazPanel to en:handbook:networkconf
author Christian Mesh meshca@clarkson.edu
date Mon Mar 19 21:55:06 2012 +0000 (2012-03-19)
parents
children
line source
1 <?php
2 /**
3 * Add Note capability to dokuwiki
4 *
5 * <note>This is note</note>
6 * <note classic>This is note</note>
7 * <note important>This is an important note</note>
8 * <note warning>This is a big warning</note>
9 * <note tip>This is a tip</note>
10 *
11 * by Olivier Cortès <olive@deep-ocean.net>
12 * under the terms of the GNU GPL v2.
13 *
14 * Originaly derived from the work of :
15 * Stephane Chamberland <stephane.chamberland@ec.gc.ca> (Side Notes PlugIn)
16 * Carl-Christian Salvesen <calle@ioslo.net> (Graphviz plugin)
17 *
18 * Contributions by Eric Hameleers <alien [at] slackware [dot] com> :
19 * use <div> instead of <table>,
20 * contain the images and stylesheet inside the plugin,
21 * permit nesting of notes,
22 *
23 * Contributed by Christopher Smith <chris [at] jalakai [dot] co [dot] uk>
24 * fix some parsing problems and a security hole.
25 * make note types case independent
26 * simplify code reading
27 * modernise the plugin for changes/fixes/improvements to the underlying Dokuwiki plugin class,
28 * improve efficiency.
29 *
30 * Contributed by Aurélien Bompard <aurelien [at] bompard [dot] org>
31 * support for the ODT output format.
32 *
33 * @license GNU_GPL_v2
34 * @author Olivier Cortes <olive@deep-ocean.net>
35 */
37 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
38 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
39 require_once(DOKU_PLUGIN.'syntax.php');
42 class syntax_plugin_note extends DokuWiki_Syntax_Plugin {
44 var $notes = array(
45 'noteimportant' => array('important', 'importante'),
46 'notewarning' => array('warning','bloquante','critique'),
47 'notetip' => array('tip','tuyau','idée'),
48 'noteclassic' => array('','classic','classique')
49 );
51 var $default = 'noteclassic';
53 function getInfo(){
54 return confToHash(dirname(__FILE__).'/info.txt');
55 }
58 function getType(){ return 'container'; }
59 function getPType(){ return 'normal'; }
60 function getAllowedTypes() {
61 return array('container','substition','protected','disabled','formatting','paragraphs');
62 }
63 function getSort(){ return 195; }
65 // override default accepts() method to allow nesting
66 // - ie, to get the plugin accepts its own entry syntax
67 function accepts($mode) {
68 if ($mode == substr(get_class($this), 7)) return true;
69 return parent::accepts($mode);
70 }
72 function connectTo($mode) {
73 $this->Lexer->addEntryPattern('<note.*?>(?=.*?</note>)',$mode,'plugin_note');
74 }
75 function postConnect() {
76 $this->Lexer->addExitPattern('</note>','plugin_note');
77 }
79 function handle($match, $state, $pos, &$handler){
81 switch ($state) {
83 case DOKU_LEXER_ENTER :
84 $note = strtolower(trim(substr($match,5,-1)));
86 foreach( $this->notes as $class => $names ) {
87 if (in_array($note, $names))
88 return array($state, $class);
89 }
91 return array($state, $this->default);
93 case DOKU_LEXER_UNMATCHED :
94 return array($state, $match);
96 default:
97 return array($state);
98 }
99 }
101 function render($mode, &$renderer, $indata) {
103 if($mode == 'xhtml'){
105 list($state, $data) = $indata;
107 switch ($state) {
108 case DOKU_LEXER_ENTER :
109 $renderer->doc .= '<p><div class="'.$data.'">';
110 break;
112 case DOKU_LEXER_UNMATCHED :
113 $renderer->doc .= $renderer->_xmlEntities($data);
114 break;
116 case DOKU_LEXER_EXIT :
117 $renderer->doc .= "\n</div></p>";
118 break;
119 }
120 return true;
122 } elseif ($mode == 'odt'){
124 list($state, $data) = $indata;
126 switch ($state) {
127 case DOKU_LEXER_ENTER :
128 $type = substr($data, 4);
129 if ($type == "classic") {
130 $type = "note"; // the icon for classic notes is named note.png
131 }
132 $colors = array("note"=>"#eeffff", "warning"=>"#ffdddd", "important"=>"#ffffcc", "tip"=>"#ddffdd");
133 $renderer->autostyles["pluginnote"] = '
134 <style:style style:name="pluginnote" style:family="table">
135 <style:table-properties style:width="15cm" table:align="center" style:shadow="#808080 0.18cm 0.18cm"/>
136 </style:style>';
137 $renderer->autostyles["pluginnote.A"] = '
138 <style:style style:name="pluginnote.A" style:family="table-column">
139 <style:table-column-properties style:column-width="1.5cm"/>
140 </style:style>';
141 $renderer->autostyles["pluginnote.B"] = '
142 <style:style style:name="pluginnote.B" style:family="table-column">
143 <style:table-column-properties style:column-width="13.5cm"/>
144 </style:style>';
145 $renderer->autostyles["pluginnote".$type.".A1"] = '
146 <style:style style:name="pluginnote'.$type.'.A1" style:family="table-cell">
147 <style:table-cell-properties style:vertical-align="middle" fo:padding="0.1cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000" fo:background-color="'.$colors[$type].'"/>
148 </style:style>';
149 $renderer->autostyles["pluginnote".$type.".B1"] = '
150 <style:style style:name="pluginnote'.$type.'.B1" style:family="table-cell">
151 <style:table-cell-properties style:vertical-align="middle" fo:padding="0.3cm" fo:border-left="none" fo:border-right="0.002cm solid #000000" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000" fo:background-color="'.$colors[$type].'"/>
152 </style:style>';
153 // Content
154 $renderer->p_close();
155 $renderer->doc .= '<table:table table:name="" table:style-name="pluginnote">';
156 $renderer->doc .= '<table:table-column table:style-name="pluginnote.A"/>';
157 $renderer->doc .= '<table:table-column table:style-name="pluginnote.B"/>';
158 $renderer->doc .= '<table:table-row>';
159 $renderer->doc .= '<table:table-cell table:style-name="pluginnote'.$type.'.A1" office:value-type="string">';
160 // Don't use p_open, as it's not the same style-name
161 $renderer->doc .= '<text:p text:style-name="Table_20_Contents">';
162 $src = DOKU_PLUGIN."note/images/".$type.".png";
163 $renderer->_odtAddImage($src);
164 $renderer->doc .= '</text:p>';
165 $renderer->doc .= '</table:table-cell>';
166 $renderer->doc .= '<table:table-cell table:style-name="pluginnote'.$type.'.B1" office:value-type="string">';
167 $renderer->p_open();
168 break;
170 case DOKU_LEXER_UNMATCHED :
171 $renderer->cdata($data);
172 break;
174 case DOKU_LEXER_EXIT :
175 $renderer->p_close();
176 $renderer->doc .= '</table:table-cell>';
177 $renderer->doc .= '</table:table-row>';
178 $renderer->doc .= '</table:table>';
179 $renderer->p_open();
180 break;
181 }
182 return true;
183 }
185 // unsupported $mode
186 return false;
187 }
188 }
190 //Setup VIM: ex: et ts=4 enc=utf-8 :
191 ?>