~hexmode/+junk/main

« back to all changes in this revision

Viewing changes to install-files/apps/sqlitemanager1.2.0/spaw/spaw_control.class.php

  • Committer: Mark A. Hershberger
  • Date: 2008-01-05 19:38:56 UTC
  • Revision ID: hershberger@spawn-xp-20080105193856-6rnzgwa4nehue3qj
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php 
 
2
// ================================================
 
3
// SPAW PHP WYSIWYG editor control
 
4
// ================================================
 
5
// Main control class
 
6
// ================================================
 
7
// Developed: Alan Mendelevich, alan@solmetra.lt
 
8
// Copyright: Solmetra (c)2003 All rights reserved.
 
9
// ------------------------------------------------
 
10
//                                www.solmetra.com
 
11
// ================================================
 
12
// v.1.0, 2003-03-25
 
13
// ================================================
 
14
 
 
15
if (preg_match("/:\/\//i", $spaw_root)) die ("can't include external file");
 
16
 
 
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';
 
21
 
 
22
// instance counter (static)
 
23
$spaw_wysiwyg_instCount = 0;
 
24
 
 
25
class SPAW_Wysiwyg {
 
26
  // controls name
 
27
  var $control_name;
 
28
  // controls unmodified name
 
29
  var $original_name;   
 
30
  // value
 
31
  var $value;
 
32
  // holds control toolbar mode.
 
33
  var $mode; 
 
34
  // editor dimensions;
 
35
  var $height;
 
36
  var $width;
 
37
  // language object
 
38
  var $lang;
 
39
  // theme (skin)
 
40
  var $theme;
 
41
  // editor stylesheet
 
42
  var $css_stylesheet;
 
43
  // toolbar dropdown data
 
44
  var $dropdown_data;
 
45
  // toolbars
 
46
  var $toolbars;
 
47
  
 
48
  // constructor
 
49
  function SPAW_Wysiwyg($control_name='richeditor', $value='', $lang='', $mode = '',
 
50
              $theme='', $width='100%', $height='300px', $css_stylesheet='', $dropdown_data='', $javascript='')
 
51
  {
 
52
    global $spaw_dir;
 
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;
 
58
    
 
59
    $spaw_wysiwyg_instCount++;
 
60
    
 
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 == '')
 
68
    {
 
69
      $this->css_stylesheet = $spaw_default_css_stylesheet;
 
70
    }
 
71
    else
 
72
    {
 
73
      $this->css_stylesheet = $css_stylesheet;
 
74
    }
 
75
    $this->getLang($lang);
 
76
    if ($theme=='')
 
77
    {
 
78
      $this->theme = $spaw_default_theme;
 
79
    }
 
80
    else
 
81
    {
 
82
      $this->theme = $theme;
 
83
    }
 
84
    $this->mode = $mode;
 
85
    $this->dropdown_data = $dropdown_data;
 
86
    $this->getToolbar();
 
87
  }
 
88
 
 
89
  // sets _mode variable and fills toolbar items array
 
90
  function setMode($value) {
 
91
    $this->mode = $value;
 
92
  }
 
93
  // returns _mode value
 
94
  function getMode() {
 
95
    return($this->mode);
 
96
  }
 
97
 
 
98
  // set value/get value
 
99
  function setValue($value) {
 
100
    $this->value = $value;
 
101
  }
 
102
  function getValue() {
 
103
    return($this->value);
 
104
  }
 
105
 
 
106
  // set height/get height
 
107
  function setHeight($value) {
 
108
    $this->height = $value;
 
109
  }
 
110
  function getHeight() {
 
111
    return($this->height);
 
112
  }
 
113
 
 
114
  // set/get width
 
115
  function setWidth($value) {
 
116
    $this->width = $value;
 
117
  }
 
118
  function getWidth() {
 
119
    return($this->width);
 
120
  }
 
121
 
 
122
  // set/get css_stylesheet
 
123
  function setCssStyleSheet($value) {
 
124
    $this->css_stylesheet = $value;
 
125
  }
 
126
  function getCssStyleSheet() {
 
127
    return($this->css_stylesheet);
 
128
  }
 
129
  
 
130
  // outputs css and javascript code include
 
131
  function getCssScript($inline = false)
 
132
  {
 
133
    // static method... use only once per page
 
134
    global $spaw_dir;
 
135
    global $spaw_inline_js;
 
136
    global $spaw_root;
 
137
    global $spaw_active_toolbar;
 
138
    global $spaw_internal_link_script;
 
139
    global $spaw_img_popup_url;
 
140
 
 
141
    $buf = '';
 
142
    if ($spaw_inline_js)
 
143
    {
 
144
      // inline javascript
 
145
      echo "<script language='JavaScript'>\n";
 
146
      echo "<!--\n";
 
147
      echo "var spaw_active_toolbar = ".($spaw_active_toolbar?"true":"false").";\n";
 
148
      include($spaw_root.'class/script.js.php');
 
149
      echo "//-->\n";
 
150
      echo "</script>\n";
 
151
    }
 
152
    else
 
153
    {
 
154
      // external javascript
 
155
      $buf = "<script language='JavaScript'>\n";
 
156
      $buf .= "<!--\n";
 
157
      $buf .= "var spaw_active_toolbar = ".($spaw_active_toolbar?"true":"false").";\n";
 
158
      $buf .= "//-->\n";
 
159
      $buf .= "</script>\n";
 
160
      $buf .= '<script language="JavaScript" src="'.$spaw_dir.'spaw_script.js.php"></script>'."\n\n";
 
161
    }
 
162
    return $buf;
 
163
  }
 
164
 
 
165
  // load language data
 
166
  function getLang($lang='')
 
167
  {
 
168
    $this->lang = new SPAW_Lang($lang);
 
169
  }
 
170
  // load toolbars
 
171
  function getToolbar()
 
172
  {
 
173
   $this->toolbars = new SPAW_Toolbars($this->lang,$this->control_name,$this->mode,$this->theme,$this->dropdown_data);
 
174
  }
 
175
  
 
176
  // returns html for wysiwyg control
 
177
  function getHtml()
 
178
  {
 
179
    global $spaw_dir;
 
180
    global $spaw_wysiwyg_instCount;
 
181
    global $spaw_active_toolbar;
 
182
    
 
183
    
 
184
    $n = $this->control_name;
 
185
        $orn = $this->original_name;
 
186
    // todo: make more customizable
 
187
 
 
188
    $buf = '';
 
189
    if (SPAW_Util::checkBrowser())
 
190
    {
 
191
      if ($spaw_wysiwyg_instCount == 1)
 
192
      {
 
193
        $buf.= $this->getCssScript();
 
194
      }
 
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">';
 
198
 
 
199
      $buf.= '<table border="0" cellspacing="0" cellpadding="0" width="'.$this->getWidth().'" height="'.$this->getHeight().'">';
 
200
      $buf.= '<tr>';
 
201
 
 
202
      $buf .= '<td id="SPAW_'.$n.'_toolbar_top_design" class="SPAW_'.$this->theme.'_toolbar" colspan="3">';
 
203
      $buf.= $this->toolbars->get('top');
 
204
      $buf .= '</td>';
 
205
 
 
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');
 
208
      $buf .= '</td>';
 
209
      
 
210
      $buf .= '</tr>';
 
211
 
 
212
      $buf.= '<tr>';
 
213
 
 
214
      $buf.= '<td id="SPAW_'.$n.'_toolbar_left_design" valign="top" class="SPAW_'.$this->theme.'_toolbar" >';
 
215
      $buf.= $this->toolbars->get('left');
 
216
      $buf .= '</td>';
 
217
 
 
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');
 
220
      $buf .= '</td>';
 
221
      
 
222
      $buf .= '<td align="left" valign="top" width="100%" height="100%">';
 
223
      
 
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>';
 
226
 
 
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>';
 
230
 
 
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">';
 
235
 
 
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>';
 
237
      
 
238
      $buf.= "\n<script language=\"javascript\">\n<!--\n";
 
239
 
 
240
/*      
 
241
      $tmpstr = str_replace("\r\n","\n",$this->getValue());
 
242
      $tmpstr = str_replace("\r","\n",$tmpstr);
 
243
      $content = explode("\n",$tmpstr);
 
244
      $plus = "";
 
245
      foreach ($content as $line)
 
246
      {
 
247
        $buf.="setTimeout('document.getElementById(\"".$n."\").value ".$plus."=\"".str_replace('-->','@@END_COMMENT',str_replace('<!--','@@START_COMMENT',str_replace('"','&quot;',str_replace("'","\'",str_replace("\\","\\\\\\\\",$line)))))."\\\\n\";',0);\n";
 
248
        $plus = "+";
 
249
      }
 
250
 
 
251
      $buf.="setTimeout('document.getElementById(\"".$n."\").value = document.getElementById(\"".$n."\").value.replace(/&quot;/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";
 
254
 
 
255
//      $buf.='setTimeout("alert(document.all.'.$n.'.value);",0);'."\n";
 
256
 
 
257
//      $buf.='setTimeout("'.$n.'_rEdit.document.body.innerHTML += document.all.'.$n.'.value;",0);'."\n";
 
258
      
 
259
//  $buf.='setTimeout("SPAW_toggle_borders(\''.$n.'\',this[\''.$n.'_rEdit\'].document.body,null);",0);'."\n";
 
260
*/
 
261
      // editor init
 
262
      //$buf.='setTimeout("SPAW_editorInit(\''.$n.'\',\''.htmlspecialchars($this->getCssStyleSheet()).'\',\''.$this->lang->getDir().'\');",0);'."\n";
 
263
      
 
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";
 
270
      $buf.='}'."\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";
 
273
      
 
274
 
 
275
      $buf.= '//--></script>';
 
276
 
 
277
      $buf.= '</td>';
 
278
      
 
279
      $buf.= '<td id="SPAW_'.$n.'_toolbar_right_design" valign="top" class="SPAW_'.$this->theme.'_toolbar">';
 
280
      $buf.= $this->toolbars->get('right');
 
281
      $buf .= '</td>';
 
282
 
 
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');
 
285
      $buf .= '</td>';
 
286
      
 
287
      $buf.= '</tr>';
 
288
      $buf.= '<tr><td class="SPAW_'.$this->theme.'_toolbar"></td>';
 
289
 
 
290
      $buf .= '<td id="SPAW_'.$n.'_toolbar_bottom_design" class="SPAW_'.$this->theme.'_toolbar" width="100%">';
 
291
      $buf.= $this->toolbars->get('bottom');
 
292
      $buf .= '</td>';
 
293
 
 
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');
 
296
      $buf .= '</td>';
 
297
      
 
298
      $buf .= '<td class="SPAW_'.$this->theme.'_toolbar"></td></tr>';
 
299
      $buf.= '</table>';
 
300
    }
 
301
    else
 
302
    {
 
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>';
 
305
    }
 
306
    return $buf;
 
307
  }
 
308
 
 
309
  // outputs wysiwyg control
 
310
  function show()
 
311
  {
 
312
    echo $this->getHtml();
 
313
  }
 
314
 
 
315
}
 
316
?>