]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WysiwygEdit/htmlarea2.php
refactor WysiwygEdit
[SourceForge/phpwiki.git] / lib / WysiwygEdit / htmlarea2.php
1 <?php
2 /**
3  * requires installation into themes/default/htmlarea2/
4  * Output the javascript function to check for MS Internet Explorer >= 5.5 on Windows
5  * and call the real js script then, else just a nil func.
6  *   version 2: only for MSIE 5.5 and better
7  *   version 3: also Mozilla >= 1.3
8  *
9  * @package WysiwygEdit
10  * @author Reini Urban
11  */
12
13 require_once("lib/WysiwygEdit.php");
14
15 class WysiwygEdit_htmlarea2 extends WysiwygEdit {
16
17     function Head($name='edit[content]') {
18         return JavaScript("_editor_url = \"".DATA_PATH."/themes/default/htmlarea2/\";
19 var win_ie_ver = parseFloat(navigator.appVersion.split(\"MSIE\")[1]);
20 if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
21 if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
22 if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
23 if (win_ie_ver >= 5.5) {
24   document.write('<scr' + 'ipt src=\"' +_editor_url+ 'editor.js\"');
25   document.write(' language=\"Javascript1.2\"></scr' + 'ipt>');
26 } else {
27   document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); 
28 }
29  ",
30                     array('version' => 'JavaScript1.2',
31                           'type' => 'text/javascript'));
32     }
33
34     // to be called after </textarea>
35     // version 2
36     function Textarea($textarea,$wikitext,$name='edit[content]') {
37         $out = HTML($textarea);
38         // some more custom links 
39         //$out->pushContent(HTML::a(array('href'=>"javascript:editor_insertHTML('".$name."',\"<font style='background-color: yellow'>\",'</font>',1)"),_("Highlight selected text")));
40         //$out->pushContent(HTML("\n"));
41         $out->pushContent(JavaScript("editor_generate('".$name."');",
42                                      array('version' => 'JavaScript1.2',
43                                            'defer' => 1)));
44         return $out;
45         //return "\n".'<script language="JavaScript1.2" defer> editor_generate(\'CONTENT\'); </script>'."\n";
46     }
47
48     // for testing only
49     function Head_IEonly() {
50         return HTML(JavaScript("_editor_url = \"".DATA_PATH."/themes/default/htmlarea2/\""),
51                     "\n",
52                     JavaScript("",
53                                array('version' => 'JavaScript1.2',
54                                      'type' => 'text/javascript',
55                                      'src' => DATA_PATH."/themes/default/htmlarea2/editor.js")));
56     }
57
58 }
59
60 // re-use these classes for the regexp's.
61 // just output strings instead of XmlObjects
62 class Markup_html_br extends Markup_linebreak {
63     function markup ($match) {
64         return $match;
65     }
66 }
67
68 class Markup_html_simple_tag extends Markup_html_emphasis {
69     function markup ($match, $body) {
70         $tag = substr($match, 1, -1);
71         switch ($tag) {
72         case 'b':
73         case 'strong':
74             return "*".$body."*";
75         case 'big': return "<big>".$body."</big>";
76         case 'i':
77         case 'em':
78             return "_".$body."_";
79         }
80     }
81 }
82
83 //'<SPAN style="FONT-WEIGHT: bold">text</SPAN>' => '*text*'
84 class Markup_html_bold extends BalancedMarkup
85 {
86     var $_start_regexp = "<(?:span|SPAN) style=\"FONT-WEIGHT: bold\">";
87
88     function getEndRegexp ($match) {
89         return "<\\/" . substr($match, 1);
90     }
91     function markup ($match, $body) {
92         //TODO: convert style formatting to simplier nested <b><i> tags
93         return "*".$body."*";
94     }
95 }
96
97 class HtmlTransformer extends InlineTransformer
98 {
99     function HtmlTransformer () {
100         $this->InlineTransformer(array('escape',
101                                        'html_br','html_bold','html_simple_tag',
102                                        /*
103                                        'html_a','html_span','html_div',
104                                        'html_table','html_hr','html_pre',
105                                        'html_blockquote',
106                                        'html_indent','html_ol','html_li','html_ul','html_img',
107                                        */));
108     }
109 }
110
111 /*
112  $Log: not supported by cvs2svn $
113
114 */
115
116 // Local Variables:
117 // mode: php
118 // tab-width: 8
119 // c-basic-offset: 4
120 // c-hanging-comment-ender-p: nil
121 // indent-tabs-mode: nil
122 // End:
123 ?>