File: WysiwygEdit.php

package info (click to toggle)
phpwiki 1.3.14-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 15,716 kB
  • ctags: 23,548
  • sloc: php: 88,295; sql: 1,476; sh: 1,378; perl: 765; makefile: 602; awk: 28
file content (161 lines) | stat: -rwxr-xr-x 4,564 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
rcs_id('$Id: WysiwygEdit.php,v 1.4 2006/05/13 19:59:54 rurban Exp $');
/**
 * Baseclass for WysiwygEdit/*
 *
 * ENABLE_WYSIWYG - Support for some WYSIWYG_BACKEND Editors:
 *   tinymce, htmlarea3, FCKeditor, spaw, htmlarea2, Wikiwyg
 * Not yet enabled as default, since we cannot convert HTML to Wiki Markup yet.
 * (See HtmlParser.php for the ongoing efforts)
 * We might use a PageType=html, which is contra wiki, but some people 
 * might prefer HTML markup.
 *
 * TODO: Change from ENABLE_WYSIWYG constant to user preference variable 
 *       (checkbox setting or edit click as in gmail),
 *       when HtmlParser is finished.
 * Based upon htmlarea3.php and tinymce.php
 *
 * WARNING! Probably incompatible with ENABLE_XHTML_XML (TestMe)
 *
 * @package WysiwygEdit
 * @author Reini Urban
 */

require_once("lib/InlineParser.php");

class WysiwygEdit {

    function WysiwygEdit() { 
        $this->_transformer_tags = false;
    }

    function Head($name='edit[content]') {
        trigger_error("virtual", E_USER_ERROR); 
    }

    // to be called after </textarea>
    function Textarea($textarea,$wikitext,$name='edit[content]') {
        trigger_error("virtual", E_USER_ERROR); 
    }

    /**
     * Handler to convert the Wiki Markup to HTML before editing.
     * This will be converted back by WysiwygEdit_ConvertAfter if required.
     *  *text* => '<b>text<b>'
     */
    function ConvertBefore($text) {
        require_once("lib/BlockParser.php");
    	$xml = TransformText($text, 2.0, $GLOBALS['request']->getArg('pagename'));
        return $xml->AsXML();
    }
    
    /**
     * FIXME: Handler to convert the HTML formatting back to wiki formatting.
     * Derived from InlineParser, but returning wiki text instead of HtmlElement objects.
     * '<b>text<b>' => '<SPAN style="FONT-WEIGHT: bold">text</SPAN>' => '*text*'
     *
     * TODO: Switch over to HtmlParser
     */
    function ConvertAfter($text) {
        static $trfm;
        if (empty($trfm)) {
            $trfm = new HtmlTransformer($this->_transformer_tags);
        }
        $markup = $trfm->parse($text); // version 2.0
        return $markup;
    }
}

// re-use these classes for the regexp's.
// just output strings instead of XmlObjects
class Markup_html_br extends Markup_linebreak {
    function markup ($match) {
        return $match;
    }
}

class Markup_html_simple_tag extends Markup_html_emphasis {
    function markup ($match, $body) {
        $tag = substr($match, 1, -1);
        switch ($tag) {
        case 'b':
        case 'strong':
            return "*".$body."*";
        case 'big': 
            return "<big>".$body."</big>";
        case 'i':
        case 'em':
            return "_".$body."_";
        }
    }
}

class Markup_html_p extends BalancedMarkup
{
    var $_start_regexp = "<(?:p|P)( class=\".*\")?>";

    function getEndRegexp ($match) {
        return "<\\/" . substr($match, 1);
    }
    function markup ($match, $body) {
        return $body."\n";
    }
}

//'<SPAN style="FONT-WEIGHT: bold">text</SPAN>' => '*text*'
class Markup_html_spanbold extends BalancedMarkup
{
    var $_start_regexp = "<(?:span|SPAN) style=\"FONT-WEIGHT: bold\">";

    function getEndRegexp ($match) {
        return "<\\/" . substr($match, 1);
    }
    function markup ($match, $body) {
        //Todo: convert style formatting to simplier nested <b><i> tags
        return "*".$body."*";
    }
}

class HtmlTransformer extends InlineTransformer
{
    function HtmlTransformer ($tags = false) {
        if (!$tags) $tags = 
            array('escape','html_br','html_spanbold','html_simple_tag',
                  'html_p',);
        /*
         'html_a','html_span','html_div',
         'html_table','html_hr','html_pre',
         'html_blockquote',
         'html_indent','html_ol','html_li','html_ul','html_img'
        */
        return $this->InlineTransformer($tags);
    }
}

/*
 $Log: WysiwygEdit.php,v $
 Revision 1.4  2006/05/13 19:59:54  rurban
 added wysiwyg_editor-1.3a feature by Jean-Nicolas GEREONE <jean-nicolas.gereone@st.com>
 converted wysiwyg_editor-1.3a js to WysiwygEdit framework
 changed default ENABLE_WYSIWYG = true and added WYSIWYG_BACKEND = Wikiwyg

 Revision 1.3  2005/10/31 17:20:40  rurban
 fix ConvertBefore

 Revision 1.2  2005/10/31 16:46:13  rurban
 move old default transformers to baseclass

 Revision 1.1  2005/10/30 14:22:15  rurban
 refactor WysiwygEdit


*/

// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>