_transformer_tags = false; $this->BasePath = DATA_PATH . '/themes/default/Wikiwyg'; $this->_htmltextid = "edit-content"; $this->_wikitextid = "editareawiki"; $script_url = deduce_script_name(); if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug'])) $script_url .= ("?start_debug=" . $_GET['start_debug']); $this->_jsdefault = ""; } function Head($name = 'edit[content]') { global $WikiTheme; foreach (array("Wikiwyg.js", "Wikiwyg/Toolbar.js", "Wikiwyg/Preview.js", "Wikiwyg/Wikitext.js", "Wikiwyg/Wysiwyg.js", "Wikiwyg/Phpwiki.js", "Wikiwyg/HTML.js", "Wikiwyg/Toolbar.js") as $js) { $WikiTheme->addMoreHeaders (Javascript('', array('src' => $this->BasePath . '/' . $js, 'language' => 'JavaScript'))); } $doubleClickToEdit = ($GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT) ? 'true' : 'false'; if ($GLOBALS['request']->getArg('mode') && $GLOBALS['request']->getArg('mode') == 'wysiwyg') { return JavaScript($this->_jsdefault . " window.onload = function() { var wikiwyg = new Wikiwyg.Phpwiki(); var config = { doubleClickToEdit: $doubleClickToEdit, javascriptLocation: data_path+'/themes/default/Wikiwyg/', toolbar: { imagesLocation: data_path+'/themes/default/Wikiwyg/images/', controlLayout: [ 'save','preview','save_button','|', 'p','|', 'h2', 'h3', 'h4','|', 'bold', 'italic', '|', 'sup', 'sub', '|', 'toc', 'wikitext','|', 'pre','|', 'ordered', 'unordered','hr','|', 'link','|', 'table' ], styleSelector: [ 'label', 'p', 'h2', 'h3', 'h4', 'pre' ], controlLabels: { save: '" . _("Apply changes") . "', cancel: '" . _("Exit toolbar") . "', h2: '" . _("Title 1") . "', h3: '" . _("Title 2") . "', h4: '" . _("Title 3") . "', verbatim: '" . _("Verbatim") . "', toc: '" . _("Table of Contents") . "', wikitext: '" . _("Insert Wikitext section") . "', sup: '" . _("Sup") . "', sub: '" . _("Sub") . "', preview: '" . _("Preview") . "', save_button:'" . _("Save") . "' } }, wysiwyg: { iframeId: 'iframe0' }, wikitext: { supportCamelCaseLinks: true } }; var div = document.getElementById(\"" . $this->_htmltextid . "\"); wikiwyg.createWikiwygArea(div, config); wikiwyg_divs.push(wikiwyg); wikiwyg.editMode();}" ); } } function Textarea($textarea, $wikitext, $name = 'edit[content]') { global $request; $htmltextid = $this->_htmltextid; $textarea->SetAttr('id', $htmltextid); $iframe0 = new RawXml(''); if ($request->getArg('mode') and $request->getArg('mode') == 'wysiwyg') { $out = HTML(HTML::div(array('class' => 'hint'), _("Warning: This Wikiwyg editor has only Beta quality!")), $textarea, $iframe0, "\n"); } else { $out = HTML($textarea, $iframe0, "\n"); } return $out; } /** * Handler to convert the Wiki Markup to HTML before editing. * This will be converted back by WysiwygEdit_ConvertAfter if required. * *text* => 'text' */ function ConvertBefore($text) { return $text; } /* * No special PHP HTML->Wikitext conversion needed. This is done in js thanksfully. * Avoided in editpage.php: PageEditor->getContent */ function ConvertAfter($text) { return TransformInline($text); } } class WikiToHtml { function WikiToHtml($wikitext, &$request) { $this->_wikitext = $wikitext; $this->_request =& $request; $this->_html = ""; $this->html_content = ""; } function send() { $this->convert(); echo $this->html_content; } function convert() { require_once 'lib/BlockParser.php'; $xmlcontent = TransformText($this->_wikitext, $this->_request->getArg('pagename')); $this->_html = $xmlcontent->AsXML(); $this->replace_inside_html(); } function replace_inside_html() { $this->clean_links(); $this->clean_plugin_name(); $this->replace_known_plugins(); $this->replace_unknown_plugins(); // $this->replace_tags(); $this->clean_plugin(); $this->html_content = $this->_html; } // Draft function to replace RichTable // by a html table // Works only on one plugin for the moment function replace_known_plugins() { // If match a plugin $pattern = '/\<\;\?plugin\s+RichTable(.*)\?\>\;/Umsi'; $replace_string = "replace_rich_table"; $this->_html = preg_replace_callback($pattern, $replace_string, $this->_html); } // Replace unknown plugins by keyword Wikitext { tag } function replace_unknown_plugins() { $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi'; $replace_string = '

Wikitext {
\1
}

'; $this->_html = preg_replace($pattern, $replace_string, $this->_html); } // Clean links to keep only name function clean_links() { // Existing links // FIXME: use VIRTUAL_PATH $pattern = '/\])*\>/Umsi'; $replace_string = ''; $this->_html = preg_replace($pattern, $replace_string, $this->_html); // Non existing links $pattern = '/\])*\>/Umsi'; $replace_string = ''; $this->_html = preg_replace($pattern, $replace_string, $this->_html); // Clean underline $pattern = '/\(.*)\<\/u\>(\.*\<\/a\>/Umsi'; $replace_string = '\2" style="color:blue;">\1'; $this->_html = preg_replace($pattern, $replace_string, $this->_html); } // Put unknown tags in Wikitext {} function replace_tags() { // Replace old table format ( non plugin ) $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms'; $replace_string = '

Wikitext {
\1
}

'; $this->_html = preg_replace($pattern, $replace_string, $this->_html); } // Replace \n by
only in // tag to keep formatting function clean_plugin() { $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei'; $replace_string = 'preg_replace("/\n/Ums","
","\1")'; $this->_html = preg_replace($pattern, $replace_string, $this->_html); } function clean_plugin_name() { // Remove plugin name converted in a link $pattern = '/(\<\;\?plugin\s)\\\(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi'; $replace_string = '\1 \2 \3'; $this->_html = preg_replace($pattern, $replace_string, $this->_html); } } // This is called to replace the RichTable plugin by an html table // $matched contains html

tags so // they are deleted before the conversion. function replace_rich_table($matched) { $plugin = $matched[1]; $unknown_options = "/colspan|rowspan|width|height/"; // if the plugin contains one of the options bellow // it won't be converted if (preg_match($unknown_options, $plugin)) return $matched[0] . "\n"; else { //Replace unused $pattern = '/\/Umsi'; $replace_string = ""; $plugin = preg_replace($pattern, $replace_string, $plugin); //replace unused

by \n $pattern = '/\<\/p\>/Umsi'; $replace_string = "\n"; $plugin = preg_replace($pattern, $replace_string, $plugin); $plugin = ""; require_once 'lib/BlockParser.php'; $xmlcontent = TransformText($plugin, $GLOBALS['request']->getArg('pagename')); return $xmlcontent->AsXML(); } } // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: