ILIAS  Release_4_4_x_branch Revision 61816
 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 include_once "./Services/RTE/classes/class.ilRTE.php";
26 
35 {
36  protected $value;
37  protected $cols;
38  protected $rows;
39  protected $usert;
40  protected $rtetags;
41  protected $plugins;
42  protected $removeplugins;
43  protected $buttons;
44  protected $rtesupport;
45  protected $use_tags_for_rte_only = true;
46 
55  protected $disabled_buttons = array();
56 
65  protected $usePurifier = false;
66 
75  protected $Purifier = null;
76 
84  protected $root_block_element = null;
85 
86  protected $rte_tag_set = array(
87  "mini" => array("strong", "em", "u", "ol", "li", "ul", "blockquote", "a", "p", "span"), // #13286
88  "standard" => array ("strong", "em", "u", "ol", "li", "ul", "p", "div",
89  "i", "b", "code", "sup", "sub", "pre", "strike", "gap"),
90  "extended" => array (
91  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
92  "h4","h5","h6","hr","li","ol","p",
93  "pre","span","strike","strong","sub","sup","u","ul",
94  "i", "b", "gap"),
95  "extended_img" => array (
96  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
97  "h4","h5","h6","hr","img","li","ol","p",
98  "pre","span","strike","strong","sub","sup","u","ul",
99  "i", "b", "gap"),
100  "extended_table" => array (
101  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
102  "h4","h5","h6","hr","li","ol","p",
103  "pre","span","strike","strong","sub","sup","table","td",
104  "tr","u","ul", "i", "b", "gap"),
105  "extended_table_img" => array (
106  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
107  "h4","h5","h6","hr","img","li","ol","p",
108  "pre","span","strike","strong","sub","sup","table","td",
109  "tr","u","ul", "i", "b", "gap"),
110  "full" => array (
111  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
112  "h4","h5","h6","hr","img","li","ol","p",
113  "pre","span","strike","strong","sub","sup","table","td",
114  "tr","u","ul","ruby","rbc","rtc","rb","rt","rp", "i", "b", "gap"));
115 
116 
123  function __construct($a_title = "", $a_postvar = "")
124  {
125  parent::__construct($a_title, $a_postvar);
126  $this->setType("textarea");
127  $this->setRteTagSet("standard");
128  $this->plugins = array();
129  $this->removeplugins = array();
130  $this->buttons = array();
131  $this->rteSupport = array();
132  }
133 
139  function setValue($a_value)
140  {
141  $this->value = $a_value;
142  }
143 
149  function getValue()
150  {
151  return $this->value;
152  }
153 
159  function setCols($a_cols)
160  {
161  $this->cols = $a_cols;
162  }
163 
169  function getCols()
170  {
171  return $this->cols;
172  }
173 
179  function setRows($a_rows)
180  {
181  $this->rows = $a_rows;
182  }
183 
189  function getRows()
190  {
191  return $this->rows;
192  }
193 
200  public function setUseRte($a_usert, $version = '')
201  {
202  $this->usert = $a_usert;
203 
204  if(strlen($version))
205  {
206  $this->rteSupport['version'] = $version;
207  }
208  }
209 
215  function getUseRte()
216  {
217  return $this->usert;
218  }
219 
225  function addPlugin($a_plugin)
226  {
227  $this->plugins[$a_plugin] = $a_plugin;
228  }
229 
235  function removePlugin($a_plugin)
236  {
237  $this->removeplugins[$a_plugin] = $a_plugin;
238  }
239 
245  function addButton($a_button)
246  {
247  $this->buttons[$a_button] = $a_button;
248  }
249 
255  function removeButton($a_button)
256  {
257  unset($this->buttons[$a_button]);
258  }
259 
267  function setRTESupport($obj_id, $obj_type, $module, $cfg_template = null, $hide_switch = false, $version = null)
268  {
269  $this->rteSupport = array("obj_id" => $obj_id, "obj_type" => $obj_type, "module" => $module, 'cfg_template' => $cfg_template, 'hide_switch' => $hide_switch, 'version' => $version);
270  }
271 
275  function removeRTESupport()
276  {
277  $this->rteSupport = array();
278  }
279 
285  function setRteTags($a_rtetags)
286  {
287  $this->rtetags = $a_rtetags;
288  }
289 
295  function getRteTags()
296  {
297  return $this->rtetags;
298  }
299 
306  function setRteTagSet($a_set_name)
307  {
308  $this->setRteTags($this->rte_tag_set[$a_set_name]);
309  }
310 
317  function getRteTagSet($a_set_name)
318  {
319  return $this->rte_tag_set[$a_set_name];
320  }
321 
322 
326  function getRteTagString()
327  {
328  $result = "";
329  foreach ($this->getRteTags() as $tag)
330  {
331  $result .= "<$tag>";
332  }
333  return $result;
334  }
335 
341  function setUseTagsForRteOnly($a_val)
342  {
343  $this->use_tags_for_rte_only = $a_val;
344  }
345 
352  {
354  }
355 
361  function setValueByArray($a_values)
362  {
363  $this->setValue($a_values[$this->getPostVar()]);
364 
365  foreach($this->getSubItems() as $item)
366  {
367  $item->setValueByArray($a_values);
368  }
369  }
370 
376  function checkInput()
377  {
378  global $lng;
379  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
380 
381  if($this->usePurifier() && $this->getPurifier())
382  {
384  $_POST[$this->getPostVar()] = $this->getPurifier()->purify($_POST[$this->getPostVar()]);
385  }
386  else
387  {
388  $allowed = $this->getRteTagString();
389  if ($this->plugins["latex"] == "latex" && !is_int(strpos($allowed, "<span>")))
390  {
391  $allowed.= "<span>";
392  }
393  $_POST[$this->getPostVar()] = ($this->getUseRte() || !$this->getUseTagsForRteOnly())
394  ? ilUtil::stripSlashes($_POST[$this->getPostVar()], true, $allowed)
396  }
397 
398  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
399  {
400  $this->setAlert($lng->txt("msg_input_is_required"));
401 
402  return false;
403  }
404  return $this->checkSubItemsInput();
405  }
406 
412  function insert(&$a_tpl)
413  {
414  $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
415 
416  // disabled rte
417  if ($this->getUseRte() && $this->getDisabled())
418  {
419  $ttpl->setCurrentBlock("disabled_rte");
420  $ttpl->setVariable("DR_VAL", $this->getValue());
421  $ttpl->parseCurrentBlock();
422  }
423  else
424  {
425  if ($this->getUseRte())
426  {
427  $rtestring = ilRTE::_getRTEClassname();
428  include_once "./Services/RTE/classes/class.$rtestring.php";
429  $rte = new $rtestring($this->rteSupport['version']);
430 
431  // @todo: Check this.
432  $rte->addPlugin("emotions");
433  foreach ($this->plugins as $plugin)
434  {
435  if (strlen($plugin))
436  {
437  $rte->addPlugin($plugin);
438  }
439  }
440  foreach ($this->removeplugins as $plugin)
441  {
442  if (strlen($plugin))
443  {
444  $rte->removePlugin($plugin);
445  }
446  }
447 
448  foreach ($this->buttons as $button)
449  {
450  if (strlen($button))
451  {
452  $rte->addButton($button);
453  }
454  }
455 
456  $rte->disableButtons($this->getDisabledButtons());
457 
458  if($this->getRTERootBlockElement() !== null)
459  {
460  $rte->setRTERootBlockElement($this->getRTERootBlockElement());
461  }
462 
463  if (count($this->rteSupport) >= 3)
464  {
465  $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template'], $this->rteSupport['hide_switch']);
466  }
467  else
468  {
469  // disable all plugins for mini-tagset
470  if(!array_diff($this->getRteTags(), $this->getRteTagSet("mini")))
471  {
472  $rte->removeAllPlugins();
473 
474  // #13603 - "paste from word" is essential
475  $rte->addPlugin("paste");
476 
477  // #11980 - p-tag is mandatory but we do not want the icons it comes with
478  $rte->disableButtons(array("anchor", "justifyleft", "justifycenter",
479  "justifyright", "justifyfull", "formatselect", "removeformat",
480  "cut", "copy", "paste", "pastetext")); // JF, 2013-12-09
481  }
482 
483  $rte->addCustomRTESupport(0, "", $this->getRteTags());
484  }
485 
486  $ttpl->touchBlock("prop_ta_w");
487  $ttpl->setCurrentBlock("prop_textarea");
488  $ttpl->setVariable("ROWS", $this->getRows());
489  }
490  else
491  {
492  $ttpl->touchBlock("no_rteditor");
493 
494  if ($this->getCols() > 5)
495  {
496  $ttpl->setCurrentBlock("prop_ta_c");
497  $ttpl->setVariable("COLS", $this->getCols());
498  $ttpl->parseCurrentBlock();
499  }
500  else
501  {
502  $ttpl->touchBlock("prop_ta_w");
503  }
504 
505  $ttpl->setCurrentBlock("prop_textarea");
506  $ttpl->setVariable("ROWS", $this->getRows());
507  }
508  if (!$this->getDisabled())
509  {
510  $ttpl->setVariable("POST_VAR",
511  $this->getPostVar());
512  }
513  $ttpl->setVariable("ID", $this->getFieldId());
514  if ($this->getDisabled())
515  {
516  $ttpl->setVariable('DISABLED','disabled="disabled" ');
517  }
518  $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
519  $ttpl->parseCurrentBlock();
520  }
521 
522  if ($this->getDisabled())
523  {
524  $ttpl->setVariable("HIDDEN_INPUT",
525  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
526  }
527 
528 
529  $a_tpl->setCurrentBlock("prop_generic");
530  $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
531  $a_tpl->parseCurrentBlock();
532 
533  }
534 
542  public function usePurifier($a_flag = null)
543  {
544  if(null === $a_flag)
545  {
546  return $this->usePurifier;
547  }
548 
549  $this->usePurifier = $a_flag;
550  return $this;
551  }
552 
561  {
562  $this->Purifier = $Purifier;
563  return $this;
564  }
565 
572  public function getPurifier()
573  {
574  return $this->Purifier;
575  }
576 
584  public function setRTERootBlockElement($a_root_block_element)
585  {
586  $this->root_block_element = $a_root_block_element;
587  return $this;
588  }
589 
596  public function getRTERootBlockElement()
597  {
599  }
600 
609  public function disableButtons($a_button)
610  {
611  if(is_array($a_button))
612  {
613  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
614  }
615  else
616  {
617  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
618  }
619 
620  return $this;
621  }
622 
631  public function getDisabledButtons($as_array = true)
632  {
633  if(!$as_array)
634  {
635  return implode(',', $this->disabled_buttons);
636  }
637  else
638  {
640  }
641  }
642 }