]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WysiwygEdit.php
include [all] Include and file path should be devided with single space. File path...
[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     function WysiwygEdit() {
29         $this->_transformer_tags = false;
30     }
31
32     function Head($name='edit[content]') {
33         trigger_error("virtual", E_USER_ERROR);
34     }
35
36     // to be called after </textarea>
37     function Textarea($textarea,$wikitext,$name='edit[content]') {
38         trigger_error("virtual", E_USER_ERROR);
39     }
40
41     /**
42      * Handler to convert the Wiki Markup to HTML before editing.
43      * This will be converted back by WysiwygEdit_ConvertAfter if required.
44      *  *text* => '<b>text<b>'
45      */
46     function ConvertBefore($text) {
47         require_once 'lib/BlockParser.php';
48         $xml = TransformText($text, 2.0, $GLOBALS['request']->getArg('pagename'));
49         return $xml->AsXML();
50     }
51
52     /**
53      * FIXME: Handler to convert the HTML formatting back to wiki formatting.
54      * Derived from InlineParser, but returning wiki text instead of HtmlElement objects.
55      * '<b>text<b>' => '<SPAN style="FONT-WEIGHT: bold">text</SPAN>' => '*text*'
56      *
57      * TODO: Switch over to HtmlParser
58      */
59     function ConvertAfter($text) {
60         static $trfm;
61         if (empty($trfm)) {
62             $trfm = new HtmlTransformer($this->_transformer_tags);
63         }
64         $markup = $trfm->parse($text); // version 2.0
65         return $markup;
66     }
67 }
68
69 // re-use these classes for the regexp's.
70 // just output strings instead of XmlObjects
71 class Markup_html_br extends Markup_linebreak {
72     function markup ($match) {
73         return $match;
74     }
75 }
76
77 class Markup_html_simple_tag extends Markup_html_emphasis {
78     function markup ($match, $body) {
79         $tag = substr($match, 1, -1);
80         switch ($tag) {
81         case 'b':
82         case 'strong':
83             return "*".$body."*";
84         case 'big':
85             return "<big>".$body."</big>";
86         case 'i':
87         case 'em':
88             return "_".$body."_";
89         }
90     }
91 }
92
93 class Markup_html_p extends BalancedMarkup
94 {
95     var $_start_regexp = "<(?:p|P)( class=\".*\")?>";
96
97     function getEndRegexp ($match) {
98         return "<\\/" . substr($match, 1);
99     }
100     function markup ($match, $body) {
101         return $body."\n";
102     }
103 }
104
105 //'<SPAN style="FONT-WEIGHT: bold">text</SPAN>' => '*text*'
106 class Markup_html_spanbold extends BalancedMarkup
107 {
108     var $_start_regexp = "<(?:span|SPAN) style=\"FONT-WEIGHT: bold\">";
109
110     function getEndRegexp ($match) {
111         return "<\\/" . substr($match, 1);
112     }
113     function markup ($match, $body) {
114         //Todo: convert style formatting to simplier nested <b><i> tags
115         return "*".$body."*";
116     }
117 }
118
119 class HtmlTransformer extends InlineTransformer
120 {
121     function HtmlTransformer ($tags = false) {
122         if (!$tags) $tags =
123             array('escape','html_br','html_spanbold','html_simple_tag',
124                   'html_p',);
125         /*
126          'html_a','html_span','html_div',
127          'html_table','html_hr','html_pre',
128          'html_blockquote',
129          'html_indent','html_ol','html_li','html_ul','html_img'
130         */
131         return $this->InlineTransformer($tags);
132     }
133 }
134
135 // Local Variables:
136 // mode: php
137 // tab-width: 8
138 // c-basic-offset: 4
139 // c-hanging-comment-ender-p: nil
140 // indent-tabs-mode: nil
141 // End: