From: Reini U. <ru...@us...> - 2006-12-22 16:53:39
|
Update of /cvsroot/phpwiki/phpwiki/lib/WysiwygEdit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23303/WysiwygEdit Modified Files: Wikiwyg.php Log Message: Try to dl() load the iconv extension, if not already loaded Index: Wikiwyg.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/WysiwygEdit/Wikiwyg.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -2 -b -p -d -r1.6 -r1.7 --- Wikiwyg.php 25 Aug 2006 22:42:51 -0000 1.6 +++ Wikiwyg.php 22 Dec 2006 16:53:38 -0000 1.7 @@ -11,4 +11,5 @@ rcs_id('$Id$'); * @package WysiwygEdit * @author Reini Urban, based on a patch by Jean-Nicolas GEREONE, STMicroelectronics, 2006 + * Current maintainer: Sabri LABBENE, STMicroelectronics, 2006 */ @@ -27,4 +28,5 @@ var base_url = '".DATA_PATH."'; var data_url = '$this->BasePath'; var script_url = '".deduce_script_name()."'; +var pagename = '".$GLOBALS['request']->getArg('pagename')."'; "; } @@ -50,5 +52,5 @@ window.onload = function() { imagesLocation: base_url+'/themes/default/Wikiwyg/images/', controlLayout: [ - 'save','preview','|','save_button','|', + 'save','preview','save_button','|', 'mode_selector', '/', 'p','|', @@ -125,18 +127,178 @@ window.onload = function() { } +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, 2.0, $this->_request->getArg('pagename')); + $this->_html = $xmlcontent->AsXML(); + + $this->replace_inside_html(); + } + + function replace_inside_html() { + global $charset; + + $this->clean_links(); + $this->clean_plugin_name(); + $this->replace_known_plugins(); + $this->replace_unknown_plugins(); + // $this->replace_tags(); + $this->clean_plugin(); + + if ($charset != 'utf-8') { + // check for iconv support + loadPhpExtension("iconv"); + $this->_html = iconv("UTF-8", $charset, $this->_html); + } + $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 = + '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext { + <br> \1 <br>}</div><br></p>'; + + $this->_html = preg_replace($pattern, + $replace_string, + $this->_html); + } + + // Clean links to keep only <a href="link">name</a> + function clean_links() { + // Existing links + $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi'; + $replace_string = '<a href="\1">'; + $this->_html = preg_replace($pattern, + $replace_string, + $this->_html) ; + // Non existing links + $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi'; + $replace_string = '<a href="\1">'; + + $this->_html = preg_replace($pattern, + $replace_string, + $this->_html) ; + + // Clean underline + $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi'; + $replace_string = + '<span>\2" style="color:blue;">\1</a></span>'; + + $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 = + '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext { + <br> \1 <br>}</div><br></p>'; + + $this->_html = preg_replace($pattern, + $replace_string, + $this->_html); +} + + // Replace \n by <br> only in + // <?plugin ? > tag to keep formatting + function clean_plugin() { + $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei'; + $replace_string = 'preg_replace("/\n/Ums","<br>","\1")'; + + $this->_html = preg_replace($pattern, + $replace_string, + $this->_html) ; + + } + + function clean_plugin_name() { + // Remove plugin name converted in a link + $pattern = '/(\<\;\?plugin\s)\<span.*\>\<span\>\<a href=.*\>(\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 <p> 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 <p...> + $pattern = '/\<p.*\>/Umsi'; + $replace_string = ""; + + $plugin = preg_replace($pattern, + $replace_string, + $plugin) ; + + //replace unused </p> by \n + $pattern = '/\<\/p\>/Umsi'; + $replace_string = "\n"; + + $plugin = preg_replace($pattern, + $replace_string, + $plugin) ; + + $plugin = "<?plugin RichTable ".$plugin." ?>"; + + require_once("lib/BlockParser.php"); + $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename')); + return $xmlcontent->AsXML(); + } +} /* $Log$ + Revision 1.7 2006/12/22 16:53:38 rurban + Try to dl() load the iconv extension, if not already loaded + Revision 1.6 2006/08/25 22:42:51 rurban warn user about beta quality, not to save wrong edits Revision 1.5 2006/06/28 14:28:14 jeannicolas - - Add preview and save button on the toolbar. Fix an IE issue in wikitext mode. Revision 1.4 2006/06/19 17:33:06 jeannicolas - Add button to insert table of content plugin Add button to insert wikitext section in wysiwyg mode @@ -145,10 +307,9 @@ window.onload = function() { Revision 1.3 2006/05/31 19:59:57 jeannicolas - - Added wysiwyg_editor 1.1b Revision 1.2 2006/05/14 17:52:20 rurban - fix syntax error. delete a left-over attempt to add CSS links also. We did put everything into phpwiki.css for browser compatibility. + fix syntax error. delete a left-over attempt to add CSS links also. + We did put everything into phpwiki.css for browser compatibility. Revision 1.1 2006/05/13 19:59:55 rurban |