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
21 function WysiwygEdit_Wikiwyg()
23 global $request, $LANG;
24 $this->_transformer_tags = false;
25 $this->BasePath = DATA_PATH . '/themes/default/Wikiwyg';
26 $this->_htmltextid = "edit-content";
27 $this->_wikitextid = "editareawiki";
28 $script_url = deduce_script_name();
29 if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug']))
30 $script_url .= ("?start_debug=" . $_GET['start_debug']);
31 $this->_jsdefault = "";
34 function Head($name = 'edit[content]')
37 foreach (array("Wikiwyg.js", "Wikiwyg/Toolbar.js", "Wikiwyg/Preview.js", "Wikiwyg/Wikitext.js",
38 "Wikiwyg/Wysiwyg.js", "Wikiwyg/Phpwiki.js", "Wikiwyg/HTML.js",
39 "Wikiwyg/Toolbar.js") as $js) {
40 $WikiTheme->addMoreHeaders
41 (Javascript('', array('src' => $this->BasePath . '/' . $js,
42 'language' => 'JavaScript')));
44 $doubleClickToEdit = ($GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT)
46 if ($GLOBALS['request']->getArg('mode') && $GLOBALS['request']->getArg('mode') == 'wysiwyg') {
47 return JavaScript($this->_jsdefault . "
48 window.onload = function() {
49 var wikiwyg = new Wikiwyg.Phpwiki();
51 doubleClickToEdit: $doubleClickToEdit,
52 javascriptLocation: data_path+'/themes/default/Wikiwyg/',
54 imagesLocation: data_path+'/themes/default/Wikiwyg/images/',
56 'save','preview','save_button','|',
59 'bold', 'italic', '|',
64 'ordered', 'unordered','hr','|',
69 'label', 'p', 'h2', 'h3', 'h4', 'pre'
72 save: '" . _("Apply changes") . "',
73 cancel: '" . _("Exit toolbar") . "',
74 h2: '" . _("Title 1") . "',
75 h3: '" . _("Title 2") . "',
76 h4: '" . _("Title 3") . "',
77 verbatim: '" . _("Verbatim") . "',
78 toc: '" . _("Table of Contents") . "',
79 wikitext: '" . _("Insert Wikitext section") . "',
80 sup: '" . _("Sup") . "',
81 sub: '" . _("Sub") . "',
82 preview: '" . _("Preview") . "',
83 save_button:'" . _("Save") . "'
90 supportCamelCaseLinks: true
93 var div = document.getElementById(\"" . $this->_htmltextid . "\");
94 wikiwyg.createWikiwygArea(div, config);
95 wikiwyg_divs.push(wikiwyg);
101 function Textarea($textarea, $wikitext, $name = 'edit[content]')
105 $htmltextid = $this->_htmltextid;
106 $textarea->SetAttr('id', $htmltextid);
107 $iframe0 = new RawXml('<iframe id="iframe0" src="blank.htm" height="0" width="0" frameborder="0"></iframe>');
108 if ($request->getArg('mode') and $request->getArg('mode') == 'wysiwyg') {
109 $out = HTML(HTML::div(array('class' => 'hint'),
110 _("Warning: This Wikiwyg editor has only Beta quality!")),
115 $out = HTML($textarea, $iframe0, "\n");
121 * Handler to convert the Wiki Markup to HTML before editing.
122 * This will be converted back by WysiwygEdit_ConvertAfter if required.
123 * *text* => '<b>text<b>'
125 function ConvertBefore($text)
131 * No special PHP HTML->Wikitext conversion needed. This is done in js thanksfully.
132 * Avoided in editpage.php: PageEditor->getContent
134 function ConvertAfter($text)
136 return TransformInline($text);
142 function WikiToHtml($wikitext, &$request)
144 $this->_wikitext = $wikitext;
145 $this->_request =& $request;
147 $this->html_content = "";
153 echo $this->html_content;
158 require_once 'lib/BlockParser.php';
159 $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename'));
160 $this->_html = $xmlcontent->AsXML();
162 $this->replace_inside_html();
165 function replace_inside_html()
169 $this->clean_links();
170 $this->clean_plugin_name();
171 $this->replace_known_plugins();
172 $this->replace_unknown_plugins();
173 // $this->replace_tags();
174 $this->clean_plugin();
176 if ($charset != 'utf-8') {
177 if ($charset == 'iso-8959-1') {
178 $this->_html = utf8_decode($this->_html);
180 // check for iconv support
181 loadPhpExtension("iconv");
182 $this->_html = iconv("UTF-8", $charset, $this->_html);
185 $this->html_content = $this->_html;
188 // Draft function to replace RichTable
190 // Works only on one plugin for the moment
191 function replace_known_plugins()
194 $pattern = '/\<\;\?plugin\s+RichTable(.*)\?\>\;/Umsi';
195 $replace_string = "replace_rich_table";
196 $this->_html = preg_replace_callback($pattern,
201 // Replace unknown plugins by keyword Wikitext { tag }
202 function replace_unknown_plugins()
204 $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi';
206 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
207 <br> \1 <br>}</div><br></p>';
209 $this->_html = preg_replace($pattern,
214 // Clean links to keep only <a href="link">name</a>
215 function clean_links()
218 // FIXME: use VIRTUAL_PATH
219 $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi';
220 $replace_string = '<a href="\1">';
221 $this->_html = preg_replace($pattern,
224 // Non existing links
225 $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi';
226 $replace_string = '<a href="\1">';
228 $this->_html = preg_replace($pattern,
233 $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi';
235 '<span>\2" style="color:blue;">\1</a></span>';
237 $this->_html = preg_replace($pattern,
242 // Put unknown tags in Wikitext {}
243 function replace_tags()
245 // Replace old table format ( non plugin )
246 $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms';
248 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
249 <br> \1 <br>}</div><br></p>';
251 $this->_html = preg_replace($pattern,
256 // Replace \n by <br> only in
257 // <?plugin ? > tag to keep formatting
258 function clean_plugin()
260 $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei';
261 $replace_string = 'preg_replace("/\n/Ums","<br>","\1")';
263 $this->_html = preg_replace($pattern,
269 function clean_plugin_name()
271 // Remove plugin name converted in a link
272 $pattern = '/(\<\;\?plugin\s)\<span.*\>\<span\>\<a href=.*\>(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi';
273 $replace_string = '\1 \2 \3';
274 $this->_html = preg_replace($pattern,
280 // This is called to replace the RichTable plugin by an html table
281 // $matched contains html <p> tags so
282 // they are deleted before the conversion.
283 function replace_rich_table($matched)
285 $plugin = $matched[1];
287 $unknown_options = "/colspan|rowspan|width|height/";
289 // if the plugin contains one of the options bellow
290 // it won't be converted
291 if (preg_match($unknown_options, $plugin))
292 return $matched[0] . "\n";
294 //Replace unused <p...>
295 $pattern = '/\<p.*\>/Umsi';
296 $replace_string = "";
298 $plugin = preg_replace($pattern,
302 //replace unused </p> by \n
303 $pattern = '/\<\/p\>/Umsi';
304 $replace_string = "\n";
306 $plugin = preg_replace($pattern,
310 $plugin = "<?plugin RichTable " . $plugin . " ?>";
312 require_once 'lib/BlockParser.php';
313 $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename'));
314 return $xmlcontent->AsXML();
322 // c-hanging-comment-ender-p: nil
323 // indent-tabs-mode: nil