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