2 rcs_id('$Id: Wikiwyg.php,v 1.11 2007-07-17 14:38:40 labbenes Exp $');
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']);
30 var base_url = '".DATA_PATH."';
31 var data_url = '$this->BasePath';
32 var script_url = '$script_url';
33 var pagename = '".$request->getArg('pagename')."';
37 function Head($name='edit[content]') {
39 foreach (array("Wikiwyg.js","Wikiwyg/Toolbar.js","Wikiwyg/Preview.js","Wikiwyg/Wikitext.js",
40 "Wikiwyg/Wysiwyg.js","Wikiwyg/Phpwiki.js","Wikiwyg/HTML.js",
41 "Wikiwyg/Toolbar.js") as $js) {
42 $WikiTheme->addMoreHeaders
43 (Javascript('', array('src' => $this->BasePath . '/' . $js,
44 'language' => 'JavaScript')));
46 $doubleClickToEdit = ($GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT)
48 if ($GLOBALS['request']->getArg('mode') && $GLOBALS['request']->getArg('mode') == 'wysiwyg'){
49 return JavaScript($this->_jsdefault . "
50 window.onload = function() {
51 var wikiwyg = new Wikiwyg.Phpwiki();
53 doubleClickToEdit: $doubleClickToEdit,
54 javascriptLocation: base_url+'/themes/default/Wikiwyg/',
56 imagesLocation: base_url+'/themes/default/Wikiwyg/images/',
58 'save','preview','save_button','|',
61 'bold', 'italic', '|',
66 'ordered', 'unordered','hr','|',
71 'label', 'p', 'h2', 'h3', 'h4', 'pre'
74 save: '"._("Apply changes")."',
75 cancel: '"._("Exit toolbar")."',
76 h2: '"._("Title 1")."',
77 h3: '"._("Title 2")."',
78 h4: '"._("Title 3")."',
79 verbatim: '"._("Verbatim")."',
80 toc: '"._("Table of content")."',
81 wikitext: '"._("Insert Wikitext section")."',
84 preview: '"._("Preview")."',
85 save_button:'"._("Save")."'
92 supportCamelCaseLinks: true
95 var div = document.getElementById(\"" . $this->_htmltextid . "\");
96 wikiwyg.createWikiwygArea(div, config);
97 wikiwyg_divs.push(wikiwyg);
103 function Textarea ($textarea, $wikitext, $name='edit[content]') {
106 $htmltextid = $this->_htmltextid;
107 $textarea->SetAttr('id', $htmltextid);
108 $iframe0 = new RawXml('<iframe id="iframe0" height="0" width="0" frameborder="0"></iframe>');
109 if ($request->getArg('mode') and $request->getArg('mode') == 'wysiwyg'){
110 $out = HTML(HTML::div(array('class' => 'hint'),
111 _("Warning: This Wikiwyg editor has only Beta quality!")),
116 $out = HTML($textarea, $iframe0, "\n");
122 * Handler to convert the Wiki Markup to HTML before editing.
123 * This will be converted back by WysiwygEdit_ConvertAfter if required.
124 * *text* => '<b>text<b>'
126 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) {
135 return TransformInline($text);
140 function WikiToHtml ($wikitext, &$request) {
141 $this->_wikitext = $wikitext;
142 $this->_request =& $request;
144 $this->html_content = "";
149 echo $this->html_content;
153 require_once("lib/BlockParser.php");
154 $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename'));
155 $this->_html = $xmlcontent->AsXML();
157 $this->replace_inside_html();
160 function replace_inside_html() {
163 $this->clean_links();
164 $this->clean_plugin_name();
165 $this->replace_known_plugins();
166 $this->replace_unknown_plugins();
167 // $this->replace_tags();
168 $this->clean_plugin();
170 if ($charset != 'utf-8') {
171 if ($charset == 'iso-8959-1') {
172 $this->_html = utf8_decode($this->_html);
174 // check for iconv support
175 loadPhpExtension("iconv");
176 $this->_html = iconv("UTF-8", $charset, $this->_html);
179 $this->html_content = $this->_html;
182 // Draft function to replace RichTable
184 // Works only on one plugin for the moment
185 function replace_known_plugins() {
187 $pattern = '/\<\;\?plugin\s+RichTable(.*)\?\>\;/Umsi';
188 $replace_string = "replace_rich_table";
189 $this->_html = preg_replace_callback($pattern,
194 // Replace unknown plugins by keyword Wikitext { tag }
195 function replace_unknown_plugins() {
196 $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi';
198 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
199 <br> \1 <br>}</div><br></p>';
201 $this->_html = preg_replace($pattern,
206 // Clean links to keep only <a href="link">name</a>
207 function clean_links() {
209 // FIXME: use VIRTUAL_PATH
210 $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi';
211 $replace_string = '<a href="\1">';
212 $this->_html = preg_replace($pattern,
215 // Non existing links
216 $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi';
217 $replace_string = '<a href="\1">';
219 $this->_html = preg_replace($pattern,
224 $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi';
226 '<span>\2" style="color:blue;">\1</a></span>';
228 $this->_html = preg_replace($pattern,
233 // Put unknown tags in Wikitext {}
234 function replace_tags() {
235 // Replace old table format ( non plugin )
236 $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms';
238 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
239 <br> \1 <br>}</div><br></p>';
241 $this->_html = preg_replace($pattern,
246 // Replace \n by <br> only in
247 // <?plugin ? > tag to keep formatting
248 function clean_plugin() {
249 $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei';
250 $replace_string = 'preg_replace("/\n/Ums","<br>","\1")';
252 $this->_html = preg_replace($pattern,
258 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) {
272 $plugin = $matched[1];
274 $unknown_options = "/colspan|rowspan|width|height/";
276 // if the plugin contains one of the options bellow
277 // it won't be converted
278 if (preg_match($unknown_options,$plugin))
279 return $matched[0]."\n";
281 //Replace unused <p...>
282 $pattern = '/\<p.*\>/Umsi';
283 $replace_string = "";
285 $plugin = preg_replace($pattern,
289 //replace unused </p> by \n
290 $pattern = '/\<\/p\>/Umsi';
291 $replace_string = "\n";
293 $plugin = preg_replace($pattern,
297 $plugin = "<?plugin RichTable ".$plugin." ?>";
299 require_once("lib/BlockParser.php");
300 $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename'));
301 return $xmlcontent->AsXML();
306 $Log: not supported by cvs2svn $
307 Revision 1.9 2007/01/07 18:44:00 rurban
308 Improve id: edit: to edit-
310 Revision 1.8 2007/01/02 13:20:57 rurban
311 use the new _DEBUG_REMOTE flag. simplify default utf-8 charset conversion, not requiring iconv
313 Revision 1.7 2006/12/22 16:53:38 rurban
314 Try to dl() load the iconv extension, if not already loaded
316 Revision 1.6 2006/08/25 22:42:51 rurban
317 warn user about beta quality, not to save wrong edits
319 Revision 1.5 2006/06/28 14:28:14 jeannicolas
320 Add preview and save button on the toolbar.
321 Fix an IE issue in wikitext mode.
323 Revision 1.4 2006/06/19 17:33:06 jeannicolas
324 Add button to insert table of content plugin
325 Add button to insert wikitext section in wysiwyg mode
327 Fix internet explorer issue in wikitext mode. The toolbar in this mode didn't work.
329 Revision 1.3 2006/05/31 19:59:57 jeannicolas
330 Added wysiwyg_editor 1.1b
332 Revision 1.2 2006/05/14 17:52:20 rurban
333 fix syntax error. delete a left-over attempt to add CSS links also.
334 We did put everything into phpwiki.css for browser compatibility.
336 Revision 1.1 2006/05/13 19:59:55 rurban
337 added wysiwyg_editor-1.3a feature by Jean-Nicolas GEREONE <jean-nicolas.gereone@st.com>
338 converted wysiwyg_editor-1.3a js to WysiwygEdit framework
339 changed default ENABLE_WYSIWYG = true and added WYSIWYG_BACKEND = Wikiwyg
348 // c-hanging-comment-ender-p: nil
349 // indent-tabs-mode: nil