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']);
29 $this->_jsdefault = "";
32 function Head($name='edit[content]') {
34 foreach (array("Wikiwyg.js","Wikiwyg/Toolbar.js","Wikiwyg/Preview.js","Wikiwyg/Wikitext.js",
35 "Wikiwyg/Wysiwyg.js","Wikiwyg/Phpwiki.js","Wikiwyg/HTML.js",
36 "Wikiwyg/Toolbar.js") as $js) {
37 $WikiTheme->addMoreHeaders
38 (Javascript('', array('src' => $this->BasePath . '/' . $js,
39 'language' => 'JavaScript')));
41 $doubleClickToEdit = ($GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT)
43 if ($GLOBALS['request']->getArg('mode') && $GLOBALS['request']->getArg('mode') == 'wysiwyg'){
44 return JavaScript($this->_jsdefault . "
45 window.onload = function() {
46 var wikiwyg = new Wikiwyg.Phpwiki();
48 doubleClickToEdit: $doubleClickToEdit,
49 javascriptLocation: data_path+'/themes/default/Wikiwyg/',
51 imagesLocation: data_path+'/themes/default/Wikiwyg/images/',
53 'save','preview','save_button','|',
56 'bold', 'italic', '|',
61 'ordered', 'unordered','hr','|',
66 'label', 'p', 'h2', 'h3', 'h4', 'pre'
69 save: '"._("Apply changes")."',
70 cancel: '"._("Exit toolbar")."',
71 h2: '"._("Title 1")."',
72 h3: '"._("Title 2")."',
73 h4: '"._("Title 3")."',
74 verbatim: '"._("Verbatim")."',
75 toc: '"._("Table of Contents")."',
76 wikitext: '"._("Insert Wikitext section")."',
79 preview: '"._("Preview")."',
80 save_button:'"._("Save")."'
87 supportCamelCaseLinks: true
90 var div = document.getElementById(\"" . $this->_htmltextid . "\");
91 wikiwyg.createWikiwygArea(div, config);
92 wikiwyg_divs.push(wikiwyg);
98 function Textarea ($textarea, $wikitext, $name='edit[content]') {
101 $htmltextid = $this->_htmltextid;
102 $textarea->SetAttr('id', $htmltextid);
103 $iframe0 = new RawXml('<iframe id="iframe0" src="blank.htm" height="0" width="0" frameborder="0"></iframe>');
104 if ($request->getArg('mode') and $request->getArg('mode') == 'wysiwyg'){
105 $out = HTML(HTML::div(array('class' => 'hint'),
106 _("Warning: This Wikiwyg editor has only Beta quality!")),
111 $out = HTML($textarea, $iframe0, "\n");
117 * Handler to convert the Wiki Markup to HTML before editing.
118 * This will be converted back by WysiwygEdit_ConvertAfter if required.
119 * *text* => '<b>text<b>'
121 function ConvertBefore($text) {
126 * No special PHP HTML->Wikitext conversion needed. This is done in js thanksfully.
127 * Avoided in editpage.php: PageEditor->getContent
129 function ConvertAfter($text) {
130 return TransformInline($text);
135 function WikiToHtml ($wikitext, &$request) {
136 $this->_wikitext = $wikitext;
137 $this->_request =& $request;
139 $this->html_content = "";
144 echo $this->html_content;
148 require_once 'lib/BlockParser.php';
149 $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename'));
150 $this->_html = $xmlcontent->AsXML();
152 $this->replace_inside_html();
155 function replace_inside_html() {
158 $this->clean_links();
159 $this->clean_plugin_name();
160 $this->replace_known_plugins();
161 $this->replace_unknown_plugins();
162 // $this->replace_tags();
163 $this->clean_plugin();
165 if ($charset != 'utf-8') {
166 if ($charset == 'iso-8959-1') {
167 $this->_html = utf8_decode($this->_html);
169 // check for iconv support
170 loadPhpExtension("iconv");
171 $this->_html = iconv("UTF-8", $charset, $this->_html);
174 $this->html_content = $this->_html;
177 // Draft function to replace RichTable
179 // Works only on one plugin for the moment
180 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() {
191 $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi';
193 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
194 <br> \1 <br>}</div><br></p>';
196 $this->_html = preg_replace($pattern,
201 // Clean links to keep only <a href="link">name</a>
202 function clean_links() {
204 // FIXME: use VIRTUAL_PATH
205 $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi';
206 $replace_string = '<a href="\1">';
207 $this->_html = preg_replace($pattern,
210 // Non existing links
211 $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi';
212 $replace_string = '<a href="\1">';
214 $this->_html = preg_replace($pattern,
219 $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi';
221 '<span>\2" style="color:blue;">\1</a></span>';
223 $this->_html = preg_replace($pattern,
228 // Put unknown tags in Wikitext {}
229 function replace_tags() {
230 // Replace old table format ( non plugin )
231 $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms';
233 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
234 <br> \1 <br>}</div><br></p>';
236 $this->_html = preg_replace($pattern,
241 // Replace \n by <br> only in
242 // <?plugin ? > tag to keep formatting
243 function clean_plugin() {
244 $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei';
245 $replace_string = 'preg_replace("/\n/Ums","<br>","\1")';
247 $this->_html = preg_replace($pattern,
253 function clean_plugin_name() {
254 // Remove plugin name converted in a link
255 $pattern = '/(\<\;\?plugin\s)\<span.*\>\<span\>\<a href=.*\>(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi';
256 $replace_string = '\1 \2 \3';
257 $this->_html = preg_replace($pattern,
263 // This is called to replace the RichTable plugin by an html table
264 // $matched contains html <p> tags so
265 // they are deleted before the conversion.
266 function replace_rich_table($matched) {
267 $plugin = $matched[1];
269 $unknown_options = "/colspan|rowspan|width|height/";
271 // if the plugin contains one of the options bellow
272 // it won't be converted
273 if (preg_match($unknown_options,$plugin))
274 return $matched[0]."\n";
276 //Replace unused <p...>
277 $pattern = '/\<p.*\>/Umsi';
278 $replace_string = "";
280 $plugin = preg_replace($pattern,
284 //replace unused </p> by \n
285 $pattern = '/\<\/p\>/Umsi';
286 $replace_string = "\n";
288 $plugin = preg_replace($pattern,
292 $plugin = "<?plugin RichTable ".$plugin." ?>";
294 require_once 'lib/BlockParser.php';
295 $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename'));
296 return $xmlcontent->AsXML();
304 // c-hanging-comment-ender-p: nil
305 // indent-tabs-mode: nil