ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTextAreaInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
25 
34 {
35  protected $value;
36  protected $cols;
37  protected $rows;
38  protected $usert;
39  protected $rtetags;
40  protected $plugins;
41  protected $removeplugins;
42  protected $buttons;
43  protected $rtesupport;
44  protected $use_tags_for_rte_only = true;
45 
54  protected $disabled_buttons = array();
55 
64  protected $usePurifier = false;
65 
74  protected $Purifier = null;
75 
83  protected $root_block_element = null;
84 
85  protected $rte_tag_set = array(
86  "standard" => array ("strong", "em", "u", "ol", "li", "ul", "p", "div",
87  "i", "b", "code", "sup", "sub", "pre", "strike", "gap"),
88  "extended" => array (
89  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
90  "h4","h5","h6","hr","li","ol","p",
91  "pre","span","strike","strong","sub","sup","u","ul",
92  "i", "b", "gap"),
93  "extended_img" => array (
94  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
95  "h4","h5","h6","hr","img","li","ol","p",
96  "pre","span","strike","strong","sub","sup","u","ul",
97  "i", "b", "gap"),
98  "extended_table" => array (
99  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
100  "h4","h5","h6","hr","li","ol","p",
101  "pre","span","strike","strong","sub","sup","table","td",
102  "tr","u","ul", "i", "b", "gap"),
103  "extended_table_img" => array (
104  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
105  "h4","h5","h6","hr","img","li","ol","p",
106  "pre","span","strike","strong","sub","sup","table","td",
107  "tr","u","ul", "i", "b", "gap"),
108  "full" => array (
109  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
110  "h4","h5","h6","hr","img","li","ol","p",
111  "pre","span","strike","strong","sub","sup","table","td",
112  "tr","u","ul","ruby","rbc","rtc","rb","rt","rp", "i", "b", "gap"));
113 
114 
121  function __construct($a_title = "", $a_postvar = "")
122  {
123  parent::__construct($a_title, $a_postvar);
124  $this->setType("textarea");
125  $this->setRteTagSet("standard");
126  $this->plugins = array();
127  $this->removeplugins = array();
128  $this->buttons = array();
129  $this->rteSupport = array();
130  }
131 
137  function setValue($a_value)
138  {
139  $this->value = $a_value;
140  }
141 
147  function getValue()
148  {
149  return $this->value;
150  }
151 
157  function setCols($a_cols)
158  {
159  $this->cols = $a_cols;
160  }
161 
167  function getCols()
168  {
169  return $this->cols;
170  }
171 
177  function setRows($a_rows)
178  {
179  $this->rows = $a_rows;
180  }
181 
187  function getRows()
188  {
189  return $this->rows;
190  }
191 
197  function setUseRte($a_usert)
198  {
199  $this->usert = $a_usert;
200  }
201 
207  function getUseRte()
208  {
209  return $this->usert;
210  }
211 
217  function addPlugin($a_plugin)
218  {
219  $this->plugins[$a_plugin] = $a_plugin;
220  }
221 
227  function removePlugin($a_plugin)
228  {
229  $this->removeplugins[$a_plugin] = $a_plugin;
230  }
231 
237  function addButton($a_button)
238  {
239  $this->buttons[$a_button] = $a_button;
240  }
241 
247  function removeButton($a_button)
248  {
249  unset($this->buttons[$a_button]);
250  }
251 
259  function setRTESupport($obj_id, $obj_type, $module, $cfg_template = null, $hide_switch = false, $version = null)
260  {
261  $this->rteSupport = array("obj_id" => $obj_id, "obj_type" => $obj_type, "module" => $module, 'cfg_template' => $cfg_template, 'hide_switch' => $hide_switch, 'version' => $version);
262  }
263 
267  function removeRTESupport()
268  {
269  $this->rteSupport = array();
270  }
271 
277  function setRteTags($a_rtetags)
278  {
279  $this->rtetags = $a_rtetags;
280  }
281 
287  function getRteTags()
288  {
289  return $this->rtetags;
290  }
291 
298  function setRteTagSet($a_set_name)
299  {
300  $this->setRteTags($this->rte_tag_set[$a_set_name]);
301  }
302 
309  function getRteTagSet($a_set_name)
310  {
311  return $this->rte_tag_set[$a_set_name];
312  }
313 
314 
318  function getRteTagString()
319  {
320  $result = "";
321  foreach ($this->getRteTags() as $tag)
322  {
323  $result .= "<$tag>";
324  }
325  return $result;
326  }
327 
333  function setUseTagsForRteOnly($a_val)
334  {
335  $this->use_tags_for_rte_only = $a_val;
336  }
337 
344  {
346  }
347 
353  function setValueByArray($a_values)
354  {
355  $this->setValue($a_values[$this->getPostVar()]);
356 
357  foreach($this->getSubItems() as $item)
358  {
359  $item->setValueByArray($a_values);
360  }
361  }
362 
368  function checkInput()
369  {
370  global $lng;
371  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
372 
373  if($this->usePurifier() && $this->getPurifier())
374  {
376  $_POST[$this->getPostVar()] = $this->getPurifier()->purify($_POST[$this->getPostVar()]);
377  }
378  else
379  {
380  $allowed = $this->getRteTagString();
381  if ($this->plugins["latex"] == "latex" && !is_int(strpos($allowed, "<span>")))
382  {
383  $allowed.= "<span>";
384  }
385  $_POST[$this->getPostVar()] = ($this->getUseRte() || !$this->getUseTagsForRteOnly())
386  ? ilUtil::stripSlashes($_POST[$this->getPostVar()], true, $allowed)
388  }
389 
390  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
391  {
392  $this->setAlert($lng->txt("msg_input_is_required"));
393 
394  return false;
395  }
396  return $this->checkSubItemsInput();
397  }
398 
404  function insert(&$a_tpl)
405  {
406  $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
407 
408  // disabled rte
409  if ($this->getUseRte() && $this->getDisabled())
410  {
411  $ttpl->setCurrentBlock("disabled_rte");
412  $ttpl->setVariable("DR_VAL", $this->getValue());
413  $ttpl->parseCurrentBlock();
414  }
415  else
416  {
417  if ($this->getUseRte())
418  {
419  include_once "./Services/RTE/classes/class.ilRTE.php";
420  $rtestring = ilRTE::_getRTEClassname();
421  include_once "./Services/RTE/classes/class.$rtestring.php";
422  $rte = new $rtestring($this->rteSupport['version']);
423 
424  // @todo: Check this.
425  $rte->addPlugin("emotions");
426  foreach ($this->plugins as $plugin)
427  {
428  if (strlen($plugin))
429  {
430  $rte->addPlugin($plugin);
431  }
432  }
433  foreach ($this->removeplugins as $plugin)
434  {
435  if (strlen($plugin))
436  {
437  $rte->removePlugin($plugin);
438  }
439  }
440 
441  foreach ($this->buttons as $button)
442  {
443  if (strlen($button))
444  {
445  $rte->addButton($button);
446  }
447  }
448 
449  $rte->disableButtons($this->getDisabledButtons());
450 
451  if($this->getRTERootBlockElement() !== null)
452  {
453  $rte->setRTERootBlockElement($this->getRTERootBlockElement());
454  }
455 
456  if (count($this->rteSupport) >= 3)
457  {
458  $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template'], $this->rteSupport['hide_switch']);
459  }
460  else
461  {
462  $rte->addCustomRTESupport(0, "", $this->getRteTags());
463  }
464 
465  $ttpl->touchBlock("prop_ta_w");
466  $ttpl->setCurrentBlock("prop_textarea");
467  $ttpl->setVariable("ROWS", $this->getRows());
468  }
469  else
470  {
471  $ttpl->touchBlock("no_rteditor");
472 
473  if ($this->getCols() > 5)
474  {
475  $ttpl->setCurrentBlock("prop_ta_c");
476  $ttpl->setVariable("COLS", $this->getCols());
477  $ttpl->parseCurrentBlock();
478  }
479  else
480  {
481  $ttpl->touchBlock("prop_ta_w");
482  }
483 
484  $ttpl->setCurrentBlock("prop_textarea");
485  $ttpl->setVariable("ROWS", $this->getRows());
486  }
487  if (!$this->getDisabled())
488  {
489  $ttpl->setVariable("POST_VAR",
490  $this->getPostVar());
491  }
492  $ttpl->setVariable("ID", $this->getFieldId());
493  if ($this->getDisabled())
494  {
495  $ttpl->setVariable('DISABLED','disabled="disabled" ');
496  }
497  $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
498  $ttpl->parseCurrentBlock();
499  }
500 
501  if ($this->getDisabled())
502  {
503  $ttpl->setVariable("HIDDEN_INPUT",
504  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
505  }
506 
507 
508  $a_tpl->setCurrentBlock("prop_generic");
509  $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
510  $a_tpl->parseCurrentBlock();
511 
512  }
513 
521  public function usePurifier($a_flag = null)
522  {
523  if(null === $a_flag)
524  {
525  return $this->usePurifier;
526  }
527 
528  $this->usePurifier = $a_flag;
529  return $this;
530  }
531 
540  {
541  $this->Purifier = $Purifier;
542  return $this;
543  }
544 
551  public function getPurifier()
552  {
553  return $this->Purifier;
554  }
555 
563  public function setRTERootBlockElement($a_root_block_element)
564  {
565  $this->root_block_element = $a_root_block_element;
566  return $this;
567  }
568 
575  public function getRTERootBlockElement()
576  {
578  }
579 
588  public function disableButtons($a_button)
589  {
590  if(is_array($a_button))
591  {
592  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
593  }
594  else
595  {
596  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
597  }
598 
599  return $this;
600  }
601 
610  public function getDisabledButtons($as_array = true)
611  {
612  if(!$as_array)
613  {
614  return implode(',', $this->disabled_buttons);
615  }
616  else
617  {
619  }
620  }
621 }