2
// ================================================
3
// SPAW PHP WYSIWYG editor control
4
// ================================================
6
// ================================================
7
// Developed: Alan Mendelevich, alan@solmetra.lt
8
// Copyright: Solmetra (c)2003 All rights reserved.
9
// ------------------------------------------------
11
// ================================================
13
// ================================================
15
if (preg_match("/:\/\//i", $spaw_root)) die ("can't include external file");
17
include $spaw_root.'config/spaw_control.config.php';
18
include $spaw_root.'class/util.class.php';
19
include $spaw_root.'class/toolbars.class.php';
20
include $spaw_root.'class/lang.class.php';
22
// instance counter (static)
23
$spaw_wysiwyg_instCount = 0;
28
// controls unmodified name
32
// holds control toolbar mode.
43
// toolbar dropdown data
49
function SPAW_Wysiwyg($control_name='richeditor', $value='', $lang='', $mode = '',
50
$theme='', $width='100%', $height='300px', $css_stylesheet='', $dropdown_data='', $javascript='')
53
global $spaw_wysiwyg_instCount;
54
global $spaw_default_theme;
55
global $spaw_default_css_stylesheet;
56
global $spaw_wysiwyg_instCount;
57
global $spaw_javascript;
59
$spaw_wysiwyg_instCount++;
61
$this->original_name = $control_name;
62
$this->control_name = str_replace(']','_',str_replace('[','_',str_replace('[]','_'.$spaw_wysiwyg_instCount.'_',$control_name)));
63
$this->value = $value;
64
$this->width = $width;
65
$this->height = $height;
66
$this->spaw_javascript = $javascript;
67
if ($css_stylesheet == '')
69
$this->css_stylesheet = $spaw_default_css_stylesheet;
73
$this->css_stylesheet = $css_stylesheet;
75
$this->getLang($lang);
78
$this->theme = $spaw_default_theme;
82
$this->theme = $theme;
85
$this->dropdown_data = $dropdown_data;
89
// sets _mode variable and fills toolbar items array
90
function setMode($value) {
93
// returns _mode value
98
// set value/get value
99
function setValue($value) {
100
$this->value = $value;
102
function getValue() {
103
return($this->value);
106
// set height/get height
107
function setHeight($value) {
108
$this->height = $value;
110
function getHeight() {
111
return($this->height);
115
function setWidth($value) {
116
$this->width = $value;
118
function getWidth() {
119
return($this->width);
122
// set/get css_stylesheet
123
function setCssStyleSheet($value) {
124
$this->css_stylesheet = $value;
126
function getCssStyleSheet() {
127
return($this->css_stylesheet);
130
// outputs css and javascript code include
131
function getCssScript($inline = false)
133
// static method... use only once per page
135
global $spaw_inline_js;
137
global $spaw_active_toolbar;
138
global $spaw_internal_link_script;
139
global $spaw_img_popup_url;
145
echo "<script language='JavaScript'>\n";
147
echo "var spaw_active_toolbar = ".($spaw_active_toolbar?"true":"false").";\n";
148
include($spaw_root.'class/script.js.php');
154
// external javascript
155
$buf = "<script language='JavaScript'>\n";
157
$buf .= "var spaw_active_toolbar = ".($spaw_active_toolbar?"true":"false").";\n";
159
$buf .= "</script>\n";
160
$buf .= '<script language="JavaScript" src="'.$spaw_dir.'spaw_script.js.php"></script>'."\n\n";
165
// load language data
166
function getLang($lang='')
168
$this->lang = new SPAW_Lang($lang);
171
function getToolbar()
173
$this->toolbars = new SPAW_Toolbars($this->lang,$this->control_name,$this->mode,$this->theme,$this->dropdown_data);
176
// returns html for wysiwyg control
180
global $spaw_wysiwyg_instCount;
181
global $spaw_active_toolbar;
184
$n = $this->control_name;
185
$orn = $this->original_name;
186
// todo: make more customizable
189
if (SPAW_Util::checkBrowser())
191
if ($spaw_wysiwyg_instCount == 1)
193
$buf.= $this->getCssScript();
195
// theme based css file and javascript
196
$buf.= '<script language="JavaScript" src="'.$spaw_dir.'lib/themes/'.$this->theme.'/js/toolbar.js.php"></script>';
197
$buf.= '<link rel="stylesheet" type="text/css" href="'.$spaw_dir.'lib/themes/'.$this->theme.'/css/toolbar.css">';
199
$buf.= '<table border="0" cellspacing="0" cellpadding="0" width="'.$this->getWidth().'" height="'.$this->getHeight().'">';
202
$buf .= '<td id="SPAW_'.$n.'_toolbar_top_design" class="SPAW_'.$this->theme.'_toolbar" colspan="3">';
203
$buf.= $this->toolbars->get('top');
206
$buf .= '<td id="SPAW_'.$n.'_toolbar_top_html" class="SPAW_'.$this->theme.'_toolbar" colspan="3" style="display : none;">';
207
$buf.= $this->toolbars->get('top','html');
214
$buf.= '<td id="SPAW_'.$n.'_toolbar_left_design" valign="top" class="SPAW_'.$this->theme.'_toolbar" >';
215
$buf.= $this->toolbars->get('left');
218
$buf.= '<td id="SPAW_'.$n.'_toolbar_left_html" valign="top" class="SPAW_'.$this->theme.'_toolbar" style="display : none;">';
219
$buf.= $this->toolbars->get('left','html');
222
$buf .= '<td align="left" valign="top" width="100%" height="100%">';
224
//$buf.= '<input type="hidden" id="'.$n.'" name="'.$n.'">';
225
//$buf.= '<textarea id="'.$n.'" name="'.$orn.'" style="width:'.$this->getWidth().'; height:'.$this->getHeight().'; display:none;" class="SPAW_'.$this->theme.'_editarea"></textarea>';
227
$buf.= '<textarea id="'.$n.'" name="'.$orn.'" style="width:'.$this->getWidth().'; height:'.$this->getHeight().'; display:none;" class="SPAW_'.$this->theme.'_editarea" '.$this->spaw_javascript.'>';
228
$buf.= htmlspecialchars($this->getValue());
229
$buf.= '</textarea>';
231
$buf.= '<input type="hidden" id="SPAW_'.$n.'_editor_mode" name="SPAW_'.$n.'_editor_mode" value="design">';
232
$buf.= '<input type="hidden" id="SPAW_'.$n.'_lang" value="'.$this->lang->lang.'">';
233
$buf.= '<input type="hidden" id="SPAW_'.$n.'_theme" value="'.$this->theme.'">';
234
$buf.= '<input type="hidden" id="SPAW_'.$n.'_borders" value="on">';
236
$buf.= '<iframe id="'.$n.'_rEdit" style="width:100%; height:'.$this->getHeight().'; direction:'.$this->lang->getDir().';" class="SPAW_'.$this->theme.'_editarea" frameborder="no" src="'.$spaw_dir.'empty.html"></iframe><br>';
238
$buf.= "\n<script language=\"javascript\">\n<!--\n";
241
$tmpstr = str_replace("\r\n","\n",$this->getValue());
242
$tmpstr = str_replace("\r","\n",$tmpstr);
243
$content = explode("\n",$tmpstr);
245
foreach ($content as $line)
247
$buf.="setTimeout('document.getElementById(\"".$n."\").value ".$plus."=\"".str_replace('-->','@@END_COMMENT',str_replace('<!--','@@START_COMMENT',str_replace('"','"',str_replace("'","\'",str_replace("\\","\\\\\\\\",$line)))))."\\\\n\";',0);\n";
251
$buf.="setTimeout('document.getElementById(\"".$n."\").value = document.getElementById(\"".$n."\").value.replace(/"/g,\'\"\');',0);"."\n";
252
$buf.="setTimeout('document.getElementById(\"".$n."\").value = document.getElementById(\"".$n."\").value.replace(/@@START_COMMENT/g,\'<!--\');',0);"."\n";
253
$buf.="setTimeout('document.getElementById(\"".$n."\").value = document.getElementById(\"".$n."\").value.replace(/@@END_COMMENT/g,\'-->\');',0);"."\n";
255
// $buf.='setTimeout("alert(document.all.'.$n.'.value);",0);'."\n";
257
// $buf.='setTimeout("'.$n.'_rEdit.document.body.innerHTML += document.all.'.$n.'.value;",0);'."\n";
259
// $buf.='setTimeout("SPAW_toggle_borders(\''.$n.'\',this[\''.$n.'_rEdit\'].document.body,null);",0);'."\n";
262
//$buf.='setTimeout("SPAW_editorInit(\''.$n.'\',\''.htmlspecialchars($this->getCssStyleSheet()).'\',\''.$this->lang->getDir().'\');",0);'."\n";
264
// let's try to call init from document onload
265
$buf.='var spaw_tmpstr="";'."\n";
266
$buf.='if (window.onload != null) {'."\n";
267
$buf.=' spaw_tmpstr = window.onload.toString();'."\n";
268
$buf.=' var spaw_i = spaw_tmpstr.indexOf("{") + 2;'."\n";
269
$buf.=' spaw_tmpstr = spaw_tmpstr.substr(spaw_i,spaw_tmpstr.length-spaw_i-2);'."\n";
271
$buf.='window.onload = new Function("SPAW_editorInit(\''.$n.'\',\''.htmlspecialchars($this->getCssStyleSheet()).'\',\''.$this->lang->getDir().'\');" + spaw_tmpstr);'."\n";
272
//$buf.='alert(window.onload.toString());'."\n";
275
$buf.= '//--></script>';
279
$buf.= '<td id="SPAW_'.$n.'_toolbar_right_design" valign="top" class="SPAW_'.$this->theme.'_toolbar">';
280
$buf.= $this->toolbars->get('right');
283
$buf.= '<td id="SPAW_'.$n.'_toolbar_right_html" valign="top" class="SPAW_'.$this->theme.'_toolbar" style="display : none;">';
284
$buf.= $this->toolbars->get('right','html');
288
$buf.= '<tr><td class="SPAW_'.$this->theme.'_toolbar"></td>';
290
$buf .= '<td id="SPAW_'.$n.'_toolbar_bottom_design" class="SPAW_'.$this->theme.'_toolbar" width="100%">';
291
$buf.= $this->toolbars->get('bottom');
294
$buf .= '<td id="SPAW_'.$n.'_toolbar_bottom_html" class="SPAW_'.$this->theme.'_toolbar" width="100%" style="display : none;">';
295
$buf.= $this->toolbars->get('bottom','html');
298
$buf .= '<td class="SPAW_'.$this->theme.'_toolbar"></td></tr>';
303
// show simple text area
304
$buf = '<textarea cols="20" rows="5" name="'.$n.'" style="width:'.$this->getWidth().'; height:'.$this->getHeight().'" '.$this->spaw_javascript.'>'.htmlspecialchars($this->getValue()).'</textarea>';
309
// outputs wysiwyg control
312
echo $this->getHtml();