2 rcs_id('$Id: WikiToHtml.php,v 1.3 2006-06-19 17:33:06 jeannicolas Exp $');
4 * Copyright(c) STMicroelectronics, 2006
6 * Originally written by Jean-Nicolas GEREONE, STMicroelectronics, 2006.
8 This file is part of PhpWiki.
10 PhpWiki is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 PhpWiki is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with PhpWiki; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 function WikiToHtml ($wikitext, &$request) {
27 $this->_wikitext = $wikitext;
28 $this->_request =& $request;
30 $this->html_content = "";
35 echo $this->html_content;
39 require_once("lib/BlockParser.php");
40 $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename'));
41 $this->_html = $xmlcontent->AsXML();
43 $this->replace_inside_html();
46 function replace_inside_html() {
48 $this->clean_plugin_name();
49 $this->replace_known_plugins();
50 $this->replace_unknown_plugins();
51 // $this->replace_tags();
52 $this->clean_plugin();
54 $this->html_content = $this->_html;
57 // Draft function to replace RichTable
59 // Works only on one plugin for the moment
60 function replace_known_plugins() {
62 $pattern = '/\<\;\?plugin\s+RichTable(.*)\?\>\;/Umsi';
63 $replace_string = "replace_rich_table";
64 $this->_html = preg_replace_callback($pattern,
69 // Replace unknown plugins by keyword Wikitext { tag }
70 function replace_unknown_plugins() {
71 $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi';
73 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
74 <br> \1 <br>}</div><br></p>';
76 $this->_html = preg_replace($pattern,
81 // Clean links to keep only <a href="link">name</a>
82 function clean_links() {
84 $pattern = '/\<a href\=\"index.php\?pagename\=(\w+)\"([^>])*\>/Umsi';
85 $replace_string = '<a href="\1">';
86 $this->_html = preg_replace($pattern,
90 $pattern = '/\<a href\=\"index.php\?pagename\=([^"]*)(&action){1}([^>])*\>/Umsi';
91 $replace_string = '<a href="\1">';
93 $this->_html = preg_replace($pattern,
98 $pattern = '/\<u\>(.*)\<\/u\>(\<a href="(.*))[?"]{1}.*\>.*\<\/a\>/Umsi';
100 '<span>\2" style="color:blue;">\1</a></span>';
102 $this->_html = preg_replace($pattern,
107 // Put unknown tags in Wikitext {}
108 function replace_tags() {
109 // Replace old table format ( non plugin )
110 $pattern = '/(\ {0,4}(?:\S.*)?\|\S+\s*$.*?\<\/p\>)/ms';
112 '<p><div style="background-color:#D3D3D3;font-size:smaller;">Wikitext {
113 <br> \1 <br>}</div><br></p>';
115 $this->_html = preg_replace($pattern,
121 // Replace \n by <br> only in
122 // <?plugin ? > tag to keep formatting
123 function clean_plugin() {
124 $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei';
125 $replace_string = 'preg_replace("/\n/Ums","<br>","\1")';
127 $this->_html = preg_replace($pattern,
133 function clean_plugin_name() {
134 // Remove plugin name converted in a link
135 $pattern = '/(\<\;\?plugin\s)\<span.*\>\<span\>\<a href=.*\>(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi';
136 $replace_string = '\1 \2 \3';
137 $this->_html = preg_replace($pattern,
143 // This is called to replace the RichTable plugin by an html table
144 // $matched contains html <p> tags so
145 // they are deleted before the conversion.
146 function replace_rich_table($matched) {
147 $plugin = $matched[1];
149 $unknown_options = "/colspan|rowspan|width|height/";
151 // if the plugin contains one of the options bellow
152 // it won't be converted
153 if (preg_match($unknown_options,$plugin))
154 return $matched[0]."\n";
156 //Replace unused <p...>
157 $pattern = '/\<p.*\>/Umsi';
158 $replace_string = "";
160 $plugin = preg_replace($pattern,
164 //replace unused </p> by \n
165 $pattern = '/\<\/p\>/Umsi';
166 $replace_string = "\n";
168 $plugin = preg_replace($pattern,
172 $plugin = "<?plugin RichTable ".$plugin." ?>";
174 require_once("lib/BlockParser.php");
175 $xmlcontent = TransformText($plugin, 2.0, $GLOBALS['request']->getArg('pagename'));
176 return $xmlcontent->AsXML();
180 // $Log: not supported by cvs2svn $
181 // Revision 1.2 2006/06/05 08:10:19 rurban
182 // stylistic fixup: clarify request argument