XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
formdhtmltextarea.php
Go to the documentation of this file.
1 <?php
22 defined('XOOPS_ROOT_PATH') or die('Restricted access');
23 
24 
29 
34 class XoopsFormDhtmlTextArea extends XoopsFormTextArea
35 {
56  var $htmlEditor = array();
57 
65 
66  var $skipPreview = false;
67  var $doHtml = false;
68  var $js = '';
69 
81  function XoopsFormDhtmlTextArea($caption, $name, $value = "", $rows = 5, $cols = 50, $hiddentext = "xoopsHiddenText", $options = array())
82  {
83  global $xoopsConfig;
84  static $inLoop = 0;
85 
86  $inLoop ++;
87  // Second loop, invalid, return directly
88  if ($inLoop > 2) {
89  return;
90  }
91  // Else, initialize
92  $this->XoopsFormTextArea($caption, $name, $value, $rows, $cols);
93  $this->_hiddenText = $hiddentext;
94 
95  if ($inLoop > 1) {
96  return;
97  }
98  if (!isset($options['editor'])) {
99  if (isset($xoopsConfig['editor']))
100  $options['editor'] = $xoopsConfig['editor'];
101  }
102 
103  if (! empty($this->htmlEditor) || ! empty($options['editor'])) {
104  $options['name'] = $this->getName();
105  $options['value'] = $this->getValue();
106  if (! empty($options['editor'])) {
107  $this->htmlEditor = is_array($options['editor']) ? $options['editor'] : array($options['editor']);
108  }
109 
110  if (count($this->htmlEditor) == 1) {
111  xoops_load('XoopsEditorHandler');
112  $editor_handler = &XoopsEditorHandler::getInstance();
113  $this->htmlEditor = $editor_handler->get($this->htmlEditor[0], $options);
114  if ($inLoop > 1) {
115  $this->htmlEditor = null;
116  }
117  } else {
118  list ($class, $path) = $this->htmlEditor;
119  include_once XOOPS_ROOT_PATH . $path;
120  if (class_exists($class)) {
121  $this->htmlEditor = new $class($options);
122  }
123  if ($inLoop > 1) {
124  $this->htmlEditor = null;
125  }
126  }
127  }
128 
129  $inLoop = 0;
130  }
131 
137  function render()
138  {
139  if ($this->htmlEditor && is_object($this->htmlEditor)) {
140  if (! isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) {
141  return $this->htmlEditor->render();
142  }
143  }
144  static $js_loaded;
145 
146  xoops_loadLanguage('formdhtmltextarea');
147  $ret = "";
148  // actions
149  $ret .= $this->codeIcon() . "<br />\n";
150  // fonts
151  $ret .= $this->fontArray();
152  // length checker
153  $ret .= "<input type='button' onclick=\"XoopsCheckLength('" . $this->getName() . "', '" . @$this->configs['maxlength'] . "', '" . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" value=' ? ' title='" . _XOOPS_FORM_ALT_CHECKLENGTH . "' />";
154  $ret .= "<br />\n";
155  // the textarea box
156  $ret .= "<textarea id='" . $this->getName() . "' name='" . $this->getName() . "' title='". $this->getTitle() . "' onselect=\"xoopsSavePosition('" . $this->getName() . "');\" onclick=\"xoopsSavePosition('" . $this->getName() . "');\" onkeyup=\"xoopsSavePosition('" . $this->getName() . "');\" cols='" . $this->getCols() . "' rows='" . $this->getRows() . "'" . $this->getExtra() . ">" . $this->getValue() . "</textarea><br />\n";
157 
158  if (empty($this->skipPreview)) {
159  if (empty($GLOBALS['xoTheme'])) {
160  $this->js .= implode("", file(XOOPS_ROOT_PATH . "/class/textsanitizer/image/image.js"));
161  } else {
162  $GLOBALS['xoTheme']->addScript('/class/textsanitizer/image/image.js', array('type' => 'text/javascript'));
163  }
164  $button = // "<br />" .
165 "<input " . " id='" . $this->getName() . "_preview_button'" . " type='button' " . " value='" . _PREVIEW . "' " . " onclick=\"form_instantPreview('" . XOOPS_URL . "', '" . $this->getName() . "','" . XOOPS_URL . "/images', " . intval($this->doHtml) . ", '" . $GLOBALS['xoopsSecurity']->createToken() . "')\"" . " />";
166  $ret .= "<br />" . "<div id='" . $this->getName() . "_hidden' style='display: block;'> " . " <fieldset>" . " <legend>" . $button . "</legend>" . " <div id='" . $this->getName() . "_hidden_data'>" . _XOOPS_FORM_PREVIEW_CONTENT . "</div>" . " </fieldset>" . "</div>";
167  }
168  // Load javascript
169  if (empty($js_loaded)) {
170  $javascript = (($this->js) ? '<script language="JavaScript" type="text/javascript">' . $this->js . '</script>' : '') . '<script language="JavaScript" type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>';
171  $ret = $javascript . $ret;
172  $js_loaded = true;
173  }
174  return $ret;
175  }
176 
182  function codeIcon()
183  {
184  $textarea_id = $this->getName();
185  $code = "<a name='moresmiley'></a>" . "<img src='" . XOOPS_URL . "/images/url.gif' alt='" . _XOOPS_FORM_ALT_URL . "' title='" . _XOOPS_FORM_ALT_URL . "' onclick='xoopsCodeUrl(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERURL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;" . "<img src='" . XOOPS_URL . "/images/email.gif' alt='" . _XOOPS_FORM_ALT_EMAIL . "' title='" . _XOOPS_FORM_ALT_EMAIL . "' onclick='xoopsCodeEmail(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTEREMAIL, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;" . "<img src='" . XOOPS_URL . "/images/imgsrc.gif' alt='" . _XOOPS_FORM_ALT_IMG . "' title='" . _XOOPS_FORM_ALT_IMG . "' onclick='xoopsCodeImg(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERIMGURL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES) . "\", \"" . htmlspecialchars(_IMGPOSRORL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES) . "\", \"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;" . "<img src='" . XOOPS_URL . "/images/image.gif' alt='" . _XOOPS_FORM_ALT_IMAGE . "' title='" . _XOOPS_FORM_ALT_IMAGE . "' onclick='openWithSelfMain(\"" . XOOPS_URL . "/imagemanager.php?target={$textarea_id}\",\"imgmanager\",400,430);' onmouseover='style.cursor=\"hand\"'/>&nbsp;" . "<img src='" . XOOPS_URL . "/images/smiley.gif' alt='" . _XOOPS_FORM_ALT_SMILEY . "' title='" . _XOOPS_FORM_ALT_SMILEY . "' onclick='openWithSelfMain(\"" . XOOPS_URL . "/misc.php?action=showpopups&amp;type=smilies&amp;target={$textarea_id}\",\"smilies\",300,475);' onmouseover='style.cursor=\"hand\"'/>&nbsp;";
187 
188  $extensions = array_filter($myts->config['extensions']);
189  foreach(array_keys($extensions) as $key) {
190  $extension = $myts->loadExtension($key);
191  @list ($encode, $js) = $extension->encode($textarea_id);
192  if (empty($encode))
193  continue;
194  $code .= $encode;
195  if (! empty($js)) {
196  $this->js .= $js;
197  }
198  }
199  $code .= "<img src='" . XOOPS_URL . "/images/code.gif' alt='" . _XOOPS_FORM_ALT_CODE . "' title='" . _XOOPS_FORM_ALT_CODE . "' onclick='xoopsCodeCode(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERCODE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;" . "<img src='" . XOOPS_URL . "/images/quote.gif' alt='" . _XOOPS_FORM_ALT_QUOTE . "' title='" . _XOOPS_FORM_ALT_QUOTE . "' onclick='xoopsCodeQuote(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERQUOTE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>";
200 
202  $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
203  return $code;
204  }
205 
211  function fontArray()
212  {
213  $textarea_id = $this->getName();
214  $hiddentext = $this->_hiddenText;
215 
216  $fontStr = "<script type=\"text/javascript\" language=\"JavaScript\">" . "var _editor_dialog = ''" . "+ '<select id=\'{$textarea_id}Size\' onchange=\'xoopsSetElementAttribute(\"size\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'" . "+ '<option value=\'SIZE\'>" . _SIZE . "</option>'";
217  foreach($GLOBALS["formtextdhtml_sizes"] as $_val => $_name) {
218  $fontStr .= " + '<option value=\'{$_val}\'>{$_name}</option>'";
219  }
220  ;
221  $fontStr .= " + '</select> '";
222  $fontStr .= "+ '<select id=\'{$textarea_id}Font\' onchange=\'xoopsSetElementAttribute(\"font\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'" . "+ '<option value=\'FONT\'>" . _FONT . "</option>'";
223  $fontarray = ! empty($GLOBALS["formtextdhtml_fonts"]) ? $GLOBALS["formtextdhtml_fonts"] : array("Arial" , "Courier" , "Georgia" , "Helvetica" , "Impact" , "Verdana" , "Haettenschweiler");
224  foreach($fontarray as $font) {
225  $fontStr .= " + '<option value=\'{$font}\'>{$font}</option>'";
226  }
227  ;
228  $fontStr .= " + '</select> '";
229  $fontStr .= "+ '<select id=\'{$textarea_id}Color\' onchange=\'xoopsSetElementAttribute(\"color\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'" . "+ '<option value=\'COLOR\'>" . _COLOR . "</option>';" . "var _color_array = new Array('00', '33', '66', '99', 'CC', 'FF');
230  for(var i = 0; i < _color_array.length; i ++) {
231  for(var j = 0; j < _color_array.length; j ++) {
232  for(var k = 0; k < _color_array.length; k ++) {
233  var _color_ele = _color_array[i] + _color_array[j] + _color_array[k];
234  _editor_dialog += '<option value=\''+_color_ele+'\' style=\'background-color:#'+_color_ele+';color:#'+_color_ele+';\'>#'+_color_ele+'</option>';
235  }
236  }
237  }
238  _editor_dialog += '</select>';";
239 
240  $fontStr .= "document.write(_editor_dialog); </script>";
241 
242  $styleStr = "<img src='" . XOOPS_URL . "/images/bold.gif' alt='" . _XOOPS_FORM_ALT_BOLD . "' title='" . _XOOPS_FORM_ALT_BOLD . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeBold(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
243  $styleStr .= "<img src='" . XOOPS_URL . "/images/italic.gif' alt='" . _XOOPS_FORM_ALT_ITALIC . "' title='" . _XOOPS_FORM_ALT_ITALIC . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeItalic(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
244  $styleStr .= "<img src='" . XOOPS_URL . "/images/underline.gif' alt='" . _XOOPS_FORM_ALT_UNDERLINE . "' title='" . _XOOPS_FORM_ALT_UNDERLINE . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeUnderline(\"{$hiddentext}\", \"{$textarea_id}\");'/>&nbsp;";
245  $styleStr .= "<img src='" . XOOPS_URL . "/images/linethrough.gif' alt='" . _XOOPS_FORM_ALT_LINETHROUGH . "' title='" . _XOOPS_FORM_ALT_LINETHROUGH . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeLineThrough(\"{$hiddentext}\", \"{$textarea_id}\");' /></a>&nbsp;";
246 
247  $alignStr = "<img src='" . XOOPS_URL . "/images/alignleft.gif' alt='" . _XOOPS_FORM_ALT_LEFT . "' title='" . _XOOPS_FORM_ALT_LEFT . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeLeft(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
248  $alignStr .= "<img src='" . XOOPS_URL . "/images/aligncenter.gif' alt='" . _XOOPS_FORM_ALT_CENTER . "' title='" . _XOOPS_FORM_ALT_CENTER . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeCenter(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
249  $alignStr .= "<img src='" . XOOPS_URL . "/images/alignright.gif' alt='" . _XOOPS_FORM_ALT_RIGHT . "' title='" . _XOOPS_FORM_ALT_RIGHT . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeRight(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
250  $fontStr = $fontStr . "<br />\n{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
251  return $fontStr;
252  }
253 
259  function renderValidationJS()
260  {
261  if ($this->htmlEditor && is_object($this->htmlEditor) && method_exists($this->htmlEditor, 'renderValidationJS')) {
262  if (! isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) {
263  return $this->htmlEditor->renderValidationJS();
264  }
265  }
266  return parent::renderValidationJS();
267  }
268 }
269 
270 ?>