2 rcs_id('$Id: Wikiwyg.php,v 1.7 2006-12-22 16:53:38 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() {
22 $this->_transformer_tags = false;
23 $this->BasePath = DATA_PATH.'/themes/default/Wikiwyg';
24 $this->_htmltextid = "edit:content";
25 $this->_wikitextid = "editareawiki";
27 var base_url = '".DATA_PATH."';
28 var data_url = '$this->BasePath';
29 var script_url = '".deduce_script_name()."';
30 var pagename = '".$GLOBALS['request']->getArg('pagename')."';
34 function Head($name='edit[content]') {
36 foreach (array("Wikiwyg.js","Wikiwyg/Toolbar.js","Wikiwyg/Preview.js","Wikiwyg/Wikitext.js",
37 "Wikiwyg/Wysiwyg.js","Wikiwyg/Phpwiki.js","Wikiwyg/HTML.js",
38 "Wikiwyg/Toolbar.js") as $js) {
39 $WikiTheme->addMoreHeaders
40 (Javascript('', array('src' => $this->BasePath . '/' . $js,
41 'language' => 'JavaScript')));
43 $doubleClickToEdit = ($GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT)
45 return JavaScript($this->_jsdefault . "
46 window.onload = function() {
47 var wikiwyg = new Wikiwyg.Phpwiki();
49 doubleClickToEdit: $doubleClickToEdit,
50 javascriptLocation: base_url+'/themes/default/Wikiwyg/',
52 imagesLocation: base_url+'/themes/default/Wikiwyg/images/',
54 'save','preview','save_button','|',
58 'bold', 'italic', '|',
63 'ordered', 'unordered','hr','|',
68 'label', 'p', 'h2', 'h3', 'h4', 'pre'
71 save: '"._("Apply changes")."',
72 cancel: '"._("Exit toolbar")."',
73 h2: '"._("Title 1")."',
74 h3: '"._("Title 2")."',
75 h4: '"._("Title 3")."',
76 verbatim: '"._("Verbatim")."',
77 toc: '"._("Table of content")."',
78 wikitext: '"._("Insert Wikitext section")."',
81 preview: '"._("Preview")."',
82 save_button:'"._("Save")."'
89 supportCamelCaseLinks: true
92 var div = document.getElementById(\"" . $this->_htmltextid . "\");
93 wikiwyg.createWikiwygArea(div, config);
94 wikiwyg_divs.push(wikiwyg);
99 function Textarea ($textarea, $wikitext, $name='edit[content]') {
100 $htmltextid = $this->_htmltextid;
101 $textarea->SetAttr('id', $htmltextid);
102 $iframe0 = new RawXml('<iframe id="iframe0" height="0" width="0" frameborder="0"></iframe>');
103 $out = HTML(HTML::div(array('class' => 'hint'),
104 _("Warning: This Wikiwyg editor has only Beta quality!")),
112 * Handler to convert the Wiki Markup to HTML before editing.
113 * This will be converted back by WysiwygEdit_ConvertAfter if required.
114 * *text* => '<b>text<b>'
116 function ConvertBefore($text) {
121 * No special PHP HTML->Wikitext conversion needed. This is done in js thanksfully.
122 * Avoided in editpage.php: PageEditor->getContent
124 function ConvertAfter($text) {
125 return TransformInline($text);
130 function WikiToHtml ($wikitext, &$request) {
131 $this->_wikitext = $wikitext;
132 $this->_request =& $request;
134 $this->html_content = "";
139 echo $this->html_content;
143 require_once("lib/BlockParser.php");
144 $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename'));
145 $this->_html = $xmlcontent->AsXML();
147 $this->replace_inside_html();
150 function replace_inside_html() {
153 $this->clean_links();
154 $this->clean_plugin_name();
155 $this->replace_known_plugins();
156 $this->replace_unknown_plugins();
157 // $this->replace_tags();
158 $this->clean_plugin();
160 if ($charset != 'utf-8') {
161 // check for iconv support
162 loadPhpExtension("iconv");
163 $this->_html = iconv("UTF-8", $charset, $this->_html);
165 $this->html_content = $this->_html;
168 // Draft function to replace RichTable
170 // Works only on one plugin for the moment
171 function replace_known_plugins() {
173 $pattern = '/\<\;\?plugin\s+RichTable(.*)\?\>\;/Umsi';
174 $replace_string = "replace_rich_table";
175 $this->_html = preg_replace_callback($pattern,
180 // Replace unknown plugins by keyword Wikitext { tag }
181 function replace_unknown_plugins() {
182 $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi';
184 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
185 <br> \1 <br>}</div><br></p>';
187 $this->_html = preg_replace($pattern,
192 // Clean links to keep only <a href="link">name</a>
193 function clean_links() {
195 $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi';
196 $replace_string = '<a href="\1">';
197 $this->_html = preg_replace($pattern,
200 // Non existing links
201 $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi';
202 $replace_string = '<a href="\1">';
204 $this->_html = preg_replace($pattern,
209 $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi';
211 '<span>\2" style="color:blue;">\1</a></span>';
213 $this->_html = preg_replace($pattern,
218 // Put unknown tags in Wikitext {}
219 function replace_tags() {
220 // Replace old table format ( non plugin )
221 $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms';
223 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
224 <br> \1 <br>}</div><br></p>';
226 $this->_html = preg_replace($pattern,
231 // Replace \n by <br> only in
232 // <?plugin ? > tag to keep formatting
233 function clean_plugin() {
234 $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei';
235 $replace_string = 'preg_replace("/\n/Ums","<br>","\1")';
237 $this->_html = preg_replace($pattern,
243 function clean_plugin_name() {
244 // Remove plugin name converted in a link
245 $pattern = '/(\<\;\?plugin\s)\<span.*\>\<span\>\<a href=.*\>(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi';
246 $replace_string = '\1 \2 \3';
247 $this->_html = preg_replace($pattern,
253 // This is called to replace the RichTable plugin by an html table
254 // $matched contains html <p> tags so
255 // they are deleted before the conversion.
256 function replace_rich_table($matched) {
257 $plugin = $matched[1];
259 $unknown_options = "/colspan|rowspan|width|height/";
261 // if the plugin contains one of the options bellow
262 // it won't be converted
263 if (preg_match($unknown_options,$plugin))
264 return $matched[0]."\n";
266 //Replace unused <p...>
267 $pattern = '/\<p.*\>/Umsi';
268 $replace_string = "";
270 $plugin = preg_replace($pattern,
274 //replace unused </p> by \n
275 $pattern = '/\<\/p\>/Umsi';
276 $replace_string = "\n";
278 $plugin = preg_replace($pattern,
282 $plugin = "<?plugin RichTable ".$plugin." ?>";
284 require_once("lib/BlockParser.php");
285 $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename'));
286 return $xmlcontent->AsXML();
291 $Log: not supported by cvs2svn $
292 Revision 1.6 2006/08/25 22:42:51 rurban
293 warn user about beta quality, not to save wrong edits
295 Revision 1.5 2006/06/28 14:28:14 jeannicolas
296 Add preview and save button on the toolbar.
297 Fix an IE issue in wikitext mode.
299 Revision 1.4 2006/06/19 17:33:06 jeannicolas
300 Add button to insert table of content plugin
301 Add button to insert wikitext section in wysiwyg mode
303 Fix internet explorer issue in wikitext mode. The toolbar in this mode didn't work.
305 Revision 1.3 2006/05/31 19:59:57 jeannicolas
306 Added wysiwyg_editor 1.1b
308 Revision 1.2 2006/05/14 17:52:20 rurban
309 fix syntax error. delete a left-over attempt to add CSS links also.
310 We did put everything into phpwiki.css for browser compatibility.
312 Revision 1.1 2006/05/13 19:59:55 rurban
313 added wysiwyg_editor-1.3a feature by Jean-Nicolas GEREONE <jean-nicolas.gereone@st.com>
314 converted wysiwyg_editor-1.3a js to WysiwygEdit framework
315 changed default ENABLE_WYSIWYG = true and added WYSIWYG_BACKEND = Wikiwyg
324 // c-hanging-comment-ender-p: nil
325 // indent-tabs-mode: nil