]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WysiwygEdit.php
Allow bold, italics or underlined for numbers
[SourceForge/phpwiki.git] / lib / WysiwygEdit.php
1 <?php
2
3 /**
4  * Baseclass for WysiwygEdit/*
5  *
6  * ENABLE_WYSIWYG - Support for some WYSIWYG_BACKEND Editors:
7  *   tinymce, htmlarea3, FCKeditor, spaw, htmlarea2, Wikiwyg
8  * Not yet enabled as default, since we cannot convert HTML to Wiki Markup yet.
9  * (See HtmlParser.php for the ongoing efforts)
10  * We might use a PageType=html, which is contra wiki, but some people
11  * might prefer HTML markup.
12  *
13  * TODO: Change from ENABLE_WYSIWYG constant to user preference variable
14  *       (checkbox setting or edit click as in gmail),
15  *       when HtmlParser is finished.
16  * Based upon htmlarea3.php and tinymce.php
17  *
18  * WARNING! Probably incompatible with ENABLE_XHTML_XML (TestMe)
19  *
20  * @package WysiwygEdit
21  * @author Reini Urban
22  */
23
24 require_once 'lib/InlineParser.php';
25
26 class WysiwygEdit
27 {
28
29     function WysiwygEdit()
30     {
31         $this->_transformer_tags = false;
32     }
33
34     function Head($name = 'edit[content]')
35     {
36         trigger_error("virtual", E_USER_ERROR);
37     }
38
39     // to be called after </textarea>
40     function Textarea($textarea, $wikitext, $name = 'edit[content]')
41     {
42         trigger_error("virtual", E_USER_ERROR);
43     }
44
45     /**
46      * Handler to convert the Wiki Markup to HTML before editing.
47      * This will be converted back by WysiwygEdit_ConvertAfter if required.
48      *  *text* => '<b>text<b>'
49      */
50     function ConvertBefore($text)
51     {
52         require_once 'lib/BlockParser.php';
53         $xml = TransformText($text, $GLOBALS['request']->getArg('pagename'));
54         return $xml->AsXML();
55     }
56
57     /**
58      * FIXME: Handler to convert the HTML formatting back to wiki formatting.
59      * Derived from InlineParser, but returning wiki text instead of HtmlElement objects.
60      * '<b>text<b>' => '<SPAN style="FONT-WEIGHT: bold">text</SPAN>' => '*text*'
61      *
62      * TODO: Switch over to HtmlParser
63      */
64     function ConvertAfter($text)
65     {
66         static $trfm;
67         if (empty($trfm)) {
68             $trfm = new HtmlTransformer($this->_transformer_tags);
69         }
70         $markup = $trfm->parse($text); // version 2.0
71         return $markup;
72     }
73 }
74
75 // re-use these classes for the regexp's.
76 // just output strings instead of XmlObjects
77 class Markup_html_br extends Markup_linebreak
78 {
79     function markup($match)
80     {
81         return $match;
82     }
83 }
84
85 class Markup_html_simple_tag extends Markup_html_emphasis
86 {
87     function markup($match, $body)
88     {
89         $tag = substr($match, 1, -1);
90         switch ($tag) {
91             case 'b':
92             case 'strong':
93                 return "*" . $body . "*";
94             case 'big':
95                 return "<big>" . $body . "</big>";
96             case 'i':
97             case 'em':
98                 return "_" . $body . "_";
99         }
100     }
101 }
102
103 class Markup_html_p extends BalancedMarkup
104 {
105     public $_start_regexp = "<(?:p|P)( class=\".*\")?>";
106
107     function getEndRegexp($match)
108     {
109         return "<\\/" . substr($match, 1);
110     }
111
112     function markup($match, $body)
113     {
114         return $body . "\n";
115     }
116 }
117
118 //'<SPAN style="FONT-WEIGHT: bold">text</SPAN>' => '*text*'
119 class Markup_html_spanbold extends BalancedMarkup
120 {
121     public $_start_regexp = "<(?:span|SPAN) style=\"FONT-WEIGHT: bold\">";
122
123     function getEndRegexp($match)
124     {
125         return "<\\/" . substr($match, 1);
126     }
127
128     function markup($match, $body)
129     {
130         //Todo: convert style formatting to simplier nested <b><i> tags
131         return "*" . $body . "*";
132     }
133 }
134
135 class HtmlTransformer extends InlineTransformer
136 {
137     function HtmlTransformer($tags = false)
138     {
139         if (!$tags) $tags =
140             array('escape', 'html_br', 'html_spanbold', 'html_simple_tag',
141                 'html_p',);
142         /*
143          'html_a','html_span','html_div',
144          'html_table','html_hr','html_pre',
145          'html_blockquote',
146          'html_indent','html_ol','html_li','html_ul','html_img'
147         */
148         return $this->InlineTransformer($tags);
149     }
150 }
151
152 // Local Variables:
153 // mode: php
154 // tab-width: 8
155 // c-basic-offset: 4
156 // c-hanging-comment-ender-p: nil
157 // indent-tabs-mode: nil
158 // End: