2 rcs_id('$Id: Wikiwyg.php,v 1.8 2007-01-02 13:20:57 rurban 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 return JavaScript($this->_jsdefault . "
49 window.onload = function() {
50 var wikiwyg = new Wikiwyg.Phpwiki();
52 doubleClickToEdit: $doubleClickToEdit,
53 javascriptLocation: base_url+'/themes/default/Wikiwyg/',
55 imagesLocation: base_url+'/themes/default/Wikiwyg/images/',
57 '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);
102 function Textarea ($textarea, $wikitext, $name='edit[content]') {
103 $htmltextid = $this->_htmltextid;
104 $textarea->SetAttr('id', $htmltextid);
105 $iframe0 = new RawXml('<iframe id="iframe0" height="0" width="0" frameborder="0"></iframe>');
106 $out = HTML(HTML::div(array('class' => 'hint'),
107 _("Warning: This Wikiwyg editor has only Beta quality!")),
115 * Handler to convert the Wiki Markup to HTML before editing.
116 * This will be converted back by WysiwygEdit_ConvertAfter if required.
117 * *text* => '<b>text<b>'
119 function ConvertBefore($text) {
124 * No special PHP HTML->Wikitext conversion needed. This is done in js thanksfully.
125 * Avoided in editpage.php: PageEditor->getContent
127 function ConvertAfter($text) {
128 return TransformInline($text);
133 function WikiToHtml ($wikitext, &$request) {
134 $this->_wikitext = $wikitext;
135 $this->_request =& $request;
137 $this->html_content = "";
142 echo $this->html_content;
146 require_once("lib/BlockParser.php");
147 $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename'));
148 $this->_html = $xmlcontent->AsXML();
150 $this->replace_inside_html();
153 function replace_inside_html() {
156 $this->clean_links();
157 $this->clean_plugin_name();
158 $this->replace_known_plugins();
159 $this->replace_unknown_plugins();
160 // $this->replace_tags();
161 $this->clean_plugin();
163 if ($charset != 'utf-8') {
164 if ($charset == 'iso-8959-1') {
165 $this->_html = utf8_decode($this->_html);
167 // check for iconv support
168 loadPhpExtension("iconv");
169 $this->_html = iconv("UTF-8", $charset, $this->_html);
172 $this->html_content = $this->_html;
175 // Draft function to replace RichTable
177 // Works only on one plugin for the moment
178 function replace_known_plugins() {
180 $pattern = '/\<\;\?plugin\s+RichTable(.*)\?\>\;/Umsi';
181 $replace_string = "replace_rich_table";
182 $this->_html = preg_replace_callback($pattern,
187 // Replace unknown plugins by keyword Wikitext { tag }
188 function replace_unknown_plugins() {
189 $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi';
191 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
192 <br> \1 <br>}</div><br></p>';
194 $this->_html = preg_replace($pattern,
199 // Clean links to keep only <a href="link">name</a>
200 function clean_links() {
202 // FIXME: use VIRTUAL_PATH
203 $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi';
204 $replace_string = '<a href="\1">';
205 $this->_html = preg_replace($pattern,
208 // Non existing links
209 $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi';
210 $replace_string = '<a href="\1">';
212 $this->_html = preg_replace($pattern,
217 $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi';
219 '<span>\2" style="color:blue;">\1</a></span>';
221 $this->_html = preg_replace($pattern,
226 // Put unknown tags in Wikitext {}
227 function replace_tags() {
228 // Replace old table format ( non plugin )
229 $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms';
231 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
232 <br> \1 <br>}</div><br></p>';
234 $this->_html = preg_replace($pattern,
239 // Replace \n by <br> only in
240 // <?plugin ? > tag to keep formatting
241 function clean_plugin() {
242 $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei';
243 $replace_string = 'preg_replace("/\n/Ums","<br>","\1")';
245 $this->_html = preg_replace($pattern,
251 function clean_plugin_name() {
252 // Remove plugin name converted in a link
253 $pattern = '/(\<\;\?plugin\s)\<span.*\>\<span\>\<a href=.*\>(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi';
254 $replace_string = '\1 \2 \3';
255 $this->_html = preg_replace($pattern,
261 // This is called to replace the RichTable plugin by an html table
262 // $matched contains html <p> tags so
263 // they are deleted before the conversion.
264 function replace_rich_table($matched) {
265 $plugin = $matched[1];
267 $unknown_options = "/colspan|rowspan|width|height/";
269 // if the plugin contains one of the options bellow
270 // it won't be converted
271 if (preg_match($unknown_options,$plugin))
272 return $matched[0]."\n";
274 //Replace unused <p...>
275 $pattern = '/\<p.*\>/Umsi';
276 $replace_string = "";
278 $plugin = preg_replace($pattern,
282 //replace unused </p> by \n
283 $pattern = '/\<\/p\>/Umsi';
284 $replace_string = "\n";
286 $plugin = preg_replace($pattern,
290 $plugin = "<?plugin RichTable ".$plugin." ?>";
292 require_once("lib/BlockParser.php");
293 $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename'));
294 return $xmlcontent->AsXML();
299 $Log: not supported by cvs2svn $
300 Revision 1.7 2006/12/22 16:53:38 rurban
301 Try to dl() load the iconv extension, if not already loaded
303 Revision 1.6 2006/08/25 22:42:51 rurban
304 warn user about beta quality, not to save wrong edits
306 Revision 1.5 2006/06/28 14:28:14 jeannicolas
307 Add preview and save button on the toolbar.
308 Fix an IE issue in wikitext mode.
310 Revision 1.4 2006/06/19 17:33:06 jeannicolas
311 Add button to insert table of content plugin
312 Add button to insert wikitext section in wysiwyg mode
314 Fix internet explorer issue in wikitext mode. The toolbar in this mode didn't work.
316 Revision 1.3 2006/05/31 19:59:57 jeannicolas
317 Added wysiwyg_editor 1.1b
319 Revision 1.2 2006/05/14 17:52:20 rurban
320 fix syntax error. delete a left-over attempt to add CSS links also.
321 We did put everything into phpwiki.css for browser compatibility.
323 Revision 1.1 2006/05/13 19:59:55 rurban
324 added wysiwyg_editor-1.3a feature by Jean-Nicolas GEREONE <jean-nicolas.gereone@st.com>
325 converted wysiwyg_editor-1.3a js to WysiwygEdit framework
326 changed default ENABLE_WYSIWYG = true and added WYSIWYG_BACKEND = Wikiwyg
335 // c-hanging-comment-ender-p: nil
336 // indent-tabs-mode: nil