4 * Wikiwyg is compatible with most internet browsers which
5 * include: IE 5.5+ (Windows), Firefox 1.0+, Mozilla 1.3+
8 * Download: http://openjsan.org/doc/i/in/ingy/Wikiwyg/
9 * Suggested installation into themes/default/Wikiwyg/
11 * @package WysiwygEdit
12 * @author Reini Urban, based on a patch by Jean-Nicolas GEREONE, STMicroelectronics, 2006
13 * Current maintainer: Sabri LABBENE, STMicroelectronics, 2006
16 require_once("lib/WysiwygEdit.php");
18 class WysiwygEdit_Wikiwyg extends WysiwygEdit {
20 function WysiwygEdit_Wikiwyg() {
21 global $request, $LANG;
22 $this->_transformer_tags = false;
23 $this->BasePath = DATA_PATH.'/themes/default/Wikiwyg';
24 $this->_htmltextid = "edit-content";
25 $this->_wikitextid = "editareawiki";
26 $script_url = deduce_script_name();
27 if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug']))
28 $script_url .= ("?start_debug=".$_GET['start_debug']);
29 $this->_jsdefault = "";
32 function Head($name='edit[content]') {
34 foreach (array("Wikiwyg.js","Wikiwyg/Toolbar.js","Wikiwyg/Preview.js","Wikiwyg/Wikitext.js",
35 "Wikiwyg/Wysiwyg.js","Wikiwyg/Phpwiki.js","Wikiwyg/HTML.js",
36 "Wikiwyg/Toolbar.js") as $js) {
37 $WikiTheme->addMoreHeaders
38 (Javascript('', array('src' => $this->BasePath . '/' . $js,
39 'language' => 'JavaScript')));
41 $doubleClickToEdit = ($GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT)
43 if ($GLOBALS['request']->getArg('mode') && $GLOBALS['request']->getArg('mode') == 'wysiwyg'){
44 return JavaScript($this->_jsdefault . "
45 window.onload = function() {
46 var wikiwyg = new Wikiwyg.Phpwiki();
48 doubleClickToEdit: $doubleClickToEdit,
49 javascriptLocation: data_path+'/themes/default/Wikiwyg/',
51 imagesLocation: data_path+'/themes/default/Wikiwyg/images/',
53 'save','preview','save_button','|',
56 'bold', 'italic', '|',
61 'ordered', 'unordered','hr','|',
66 'label', 'p', 'h2', 'h3', 'h4', 'pre'
69 save: '"._("Apply changes")."',
70 cancel: '"._("Exit toolbar")."',
71 h2: '"._("Title 1")."',
72 h3: '"._("Title 2")."',
73 h4: '"._("Title 3")."',
74 verbatim: '"._("Verbatim")."',
75 toc: '"._("Table of content")."',
76 wikitext: '"._("Insert Wikitext section")."',
79 preview: '"._("Preview")."',
80 save_button:'"._("Save")."'
87 supportCamelCaseLinks: true
90 var div = document.getElementById(\"" . $this->_htmltextid . "\");
91 wikiwyg.createWikiwygArea(div, config);
92 wikiwyg_divs.push(wikiwyg);
98 function Textarea ($textarea, $wikitext, $name='edit[content]') {
101 $htmltextid = $this->_htmltextid;
102 $textarea->SetAttr('id', $htmltextid);
103 $iframe0 = new RawXml('<iframe id="iframe0" src="blank.htm" height="0" width="0" frameborder="0"></iframe>');
104 if ($request->getArg('mode') and $request->getArg('mode') == 'wysiwyg'){
105 $out = HTML(HTML::div(array('class' => 'hint'),
106 _("Warning: This Wikiwyg editor has only Beta quality!")),
111 $out = HTML($textarea, $iframe0, "\n");
117 * Handler to convert the Wiki Markup to HTML before editing.
118 * This will be converted back by WysiwygEdit_ConvertAfter if required.
119 * *text* => '<b>text<b>'
121 function ConvertBefore($text) {
126 * No special PHP HTML->Wikitext conversion needed. This is done in js thanksfully.
127 * Avoided in editpage.php: PageEditor->getContent
129 function ConvertAfter($text) {
130 return TransformInline($text);
135 function WikiToHtml ($wikitext, &$request) {
136 $this->_wikitext = $wikitext;
137 $this->_request =& $request;
139 $this->html_content = "";
144 echo $this->html_content;
148 require_once("lib/BlockParser.php");
149 $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename'));
150 $this->_html = $xmlcontent->AsXML();
152 $this->replace_inside_html();
155 function replace_inside_html() {
158 $this->clean_links();
159 $this->clean_plugin_name();
160 $this->replace_known_plugins();
161 $this->replace_unknown_plugins();
162 // $this->replace_tags();
163 $this->clean_plugin();
165 if ($charset != 'utf-8') {
166 if ($charset == 'iso-8959-1') {
167 $this->_html = utf8_decode($this->_html);
169 // check for iconv support
170 loadPhpExtension("iconv");
171 $this->_html = iconv("UTF-8", $charset, $this->_html);
174 $this->html_content = $this->_html;
177 // Draft function to replace RichTable
179 // Works only on one plugin for the moment
180 function replace_known_plugins() {
182 $pattern = '/\<\;\?plugin\s+RichTable(.*)\?\>\;/Umsi';
183 $replace_string = "replace_rich_table";
184 $this->_html = preg_replace_callback($pattern,
189 // Replace unknown plugins by keyword Wikitext { tag }
190 function replace_unknown_plugins() {
191 $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi';
193 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
194 <br> \1 <br>}</div><br></p>';
196 $this->_html = preg_replace($pattern,
201 // Clean links to keep only <a href="link">name</a>
202 function clean_links() {
204 // FIXME: use VIRTUAL_PATH
205 $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi';
206 $replace_string = '<a href="\1">';
207 $this->_html = preg_replace($pattern,
210 // Non existing links
211 $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi';
212 $replace_string = '<a href="\1">';
214 $this->_html = preg_replace($pattern,
219 $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi';
221 '<span>\2" style="color:blue;">\1</a></span>';
223 $this->_html = preg_replace($pattern,
228 // Put unknown tags in Wikitext {}
229 function replace_tags() {
230 // Replace old table format ( non plugin )
231 $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms';
233 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
234 <br> \1 <br>}</div><br></p>';
236 $this->_html = preg_replace($pattern,
241 // Replace \n by <br> only in
242 // <?plugin ? > tag to keep formatting
243 function clean_plugin() {
244 $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei';
245 $replace_string = 'preg_replace("/\n/Ums","<br>","\1")';
247 $this->_html = preg_replace($pattern,
253 function clean_plugin_name() {
254 // Remove plugin name converted in a link
255 $pattern = '/(\<\;\?plugin\s)\<span.*\>\<span\>\<a href=.*\>(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi';
256 $replace_string = '\1 \2 \3';
257 $this->_html = preg_replace($pattern,
263 // This is called to replace the RichTable plugin by an html table
264 // $matched contains html <p> tags so
265 // they are deleted before the conversion.
266 function replace_rich_table($matched) {
267 $plugin = $matched[1];
269 $unknown_options = "/colspan|rowspan|width|height/";
271 // if the plugin contains one of the options bellow
272 // it won't be converted
273 if (preg_match($unknown_options,$plugin))
274 return $matched[0]."\n";
276 //Replace unused <p...>
277 $pattern = '/\<p.*\>/Umsi';
278 $replace_string = "";
280 $plugin = preg_replace($pattern,
284 //replace unused </p> by \n
285 $pattern = '/\<\/p\>/Umsi';
286 $replace_string = "\n";
288 $plugin = preg_replace($pattern,
292 $plugin = "<?plugin RichTable ".$plugin." ?>";
294 require_once("lib/BlockParser.php");
295 $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename'));
296 return $xmlcontent->AsXML();
301 $Log: not supported by cvs2svn $
302 Revision 1.13 2007/09/12 19:42:53 rurban
305 Revision 1.12 2007/07/19 09:33:41 labbenes
306 Remove Internet Explorer Security Warning about non secure contents display.
308 Revision 1.11 2007/07/17 14:38:40 labbenes
309 Remove the mode selector from wikiwyg toolbar.
311 Revision 1.9 2007/01/07 18:44:00 rurban
312 Improve id: edit: to edit-
314 Revision 1.8 2007/01/02 13:20:57 rurban
315 use the new _DEBUG_REMOTE flag. simplify default utf-8 charset conversion, not requiring iconv
317 Revision 1.7 2006/12/22 16:53:38 rurban
318 Try to dl() load the iconv extension, if not already loaded
320 Revision 1.6 2006/08/25 22:42:51 rurban
321 warn user about beta quality, not to save wrong edits
323 Revision 1.5 2006/06/28 14:28:14 jeannicolas
324 Add preview and save button on the toolbar.
325 Fix an IE issue in wikitext mode.
327 Revision 1.4 2006/06/19 17:33:06 jeannicolas
328 Add button to insert table of content plugin
329 Add button to insert wikitext section in wysiwyg mode
331 Fix internet explorer issue in wikitext mode. The toolbar in this mode didn't work.
333 Revision 1.3 2006/05/31 19:59:57 jeannicolas
334 Added wysiwyg_editor 1.1b
336 Revision 1.2 2006/05/14 17:52:20 rurban
337 fix syntax error. delete a left-over attempt to add CSS links also.
338 We did put everything into phpwiki.css for browser compatibility.
340 Revision 1.1 2006/05/13 19:59:55 rurban
341 added wysiwyg_editor-1.3a feature by Jean-Nicolas GEREONE <jean-nicolas.gereone@st.com>
342 converted wysiwyg_editor-1.3a js to WysiwygEdit framework
343 changed default ENABLE_WYSIWYG = true and added WYSIWYG_BACKEND = Wikiwyg
352 // c-hanging-comment-ender-p: nil
353 // indent-tabs-mode: nil