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()
167 $this->clean_links();
168 $this->clean_plugin_name();
169 $this->replace_known_plugins();
170 $this->replace_unknown_plugins();
171 // $this->replace_tags();
172 $this->clean_plugin();
173 $this->html_content = $this->_html;
176 // Draft function to replace RichTable
178 // Works only on one plugin for the moment
179 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()
192 $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi';
194 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
195 <br> \1 <br>}</div><br></p>';
197 $this->_html = preg_replace($pattern,
202 // Clean links to keep only <a href="link">name</a>
203 function clean_links()
206 // FIXME: use VIRTUAL_PATH
207 $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi';
208 $replace_string = '<a href="\1">';
209 $this->_html = preg_replace($pattern,
212 // Non existing links
213 $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi';
214 $replace_string = '<a href="\1">';
216 $this->_html = preg_replace($pattern,
221 $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi';
223 '<span>\2" style="color:blue;">\1</a></span>';
225 $this->_html = preg_replace($pattern,
230 // Put unknown tags in Wikitext {}
231 function replace_tags()
233 // Replace old table format ( non plugin )
234 $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms';
236 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
237 <br> \1 <br>}</div><br></p>';
239 $this->_html = preg_replace($pattern,
244 // Replace \n by <br> only in
245 // <?plugin ? > tag to keep formatting
246 function clean_plugin()
248 $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei';
249 $replace_string = 'preg_replace("/\n/Ums","<br>","\1")';
251 $this->_html = preg_replace($pattern,
257 function clean_plugin_name()
259 // Remove plugin name converted in a link
260 $pattern = '/(\<\;\?plugin\s)\<span.*\>\<span\>\<a href=.*\>(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi';
261 $replace_string = '\1 \2 \3';
262 $this->_html = preg_replace($pattern,
268 // This is called to replace the RichTable plugin by an html table
269 // $matched contains html <p> tags so
270 // they are deleted before the conversion.
271 function replace_rich_table($matched)
273 $plugin = $matched[1];
275 $unknown_options = "/colspan|rowspan|width|height/";
277 // if the plugin contains one of the options bellow
278 // it won't be converted
279 if (preg_match($unknown_options, $plugin))
280 return $matched[0] . "\n";
282 //Replace unused <p...>
283 $pattern = '/\<p.*\>/Umsi';
284 $replace_string = "";
286 $plugin = preg_replace($pattern,
290 //replace unused </p> by \n
291 $pattern = '/\<\/p\>/Umsi';
292 $replace_string = "\n";
294 $plugin = preg_replace($pattern,
298 $plugin = "<?plugin RichTable " . $plugin . " ?>";
300 require_once 'lib/BlockParser.php';
301 $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename'));
302 return $xmlcontent->AsXML();
310 // c-hanging-comment-ender-p: nil
311 // indent-tabs-mode: nil