ILIAS  Release_5_0_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 
50  protected $initial_rte_width = 795;
51 
60  protected $disabled_buttons = array();
61 
70  protected $usePurifier = false;
71 
80  protected $Purifier = null;
81 
89  protected $root_block_element = null;
90 
91  protected $rte_tag_set = array(
92  "mini" => array("strong", "em", "u", "ol", "li", "ul", "blockquote", "a", "p", "span"), // #13286
93  "standard" => array ("strong", "em", "u", "ol", "li", "ul", "p", "div",
94  "i", "b", "code", "sup", "sub", "pre", "strike", "gap"),
95  "extended" => array (
96  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
97  "h4","h5","h6","hr","li","ol","p",
98  "pre","span","strike","strong","sub","sup","u","ul",
99  "i", "b", "gap"),
100  "extended_img" => array (
101  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
102  "h4","h5","h6","hr","img","li","ol","p",
103  "pre","span","strike","strong","sub","sup","u","ul",
104  "i", "b", "gap"),
105  "extended_table" => array (
106  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
107  "h4","h5","h6","hr","li","ol","p",
108  "pre","span","strike","strong","sub","sup","table","td",
109  "tr","u","ul", "i", "b", "gap"),
110  "extended_table_img" => 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", "i", "b", "gap"),
115  "full" => array (
116  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
117  "h4","h5","h6","hr","img","li","ol","p",
118  "pre","span","strike","strong","sub","sup","table","td",
119  "tr","u","ul","ruby","rbc","rtc","rb","rt","rp", "i", "b", "gap"));
120 
121 
128  function __construct($a_title = "", $a_postvar = "")
129  {
130  parent::__construct($a_title, $a_postvar);
131  $this->setType("textarea");
132  $this->setRteTagSet("standard");
133  $this->plugins = array();
134  $this->removeplugins = array();
135  $this->buttons = array();
136  $this->rteSupport = array();
137  }
138 
144  function setValue($a_value)
145  {
146  $this->value = $a_value;
147  }
148 
154  function getValue()
155  {
156  return $this->value;
157  }
158 
165  function setCols($a_cols)
166  {
167  // obsolete because of bootstrap
168  $this->cols = $a_cols;
169  }
170 
176  function getCols()
177  {
178  return $this->cols;
179  }
180 
186  function setRows($a_rows)
187  {
188  $this->rows = $a_rows;
189  }
190 
196  function getRows()
197  {
198  return $this->rows;
199  }
200 
207  public function setUseRte($a_usert, $version = '')
208  {
209  $this->usert = $a_usert;
210 
211  if(strlen($version))
212  {
213  $this->rteSupport['version'] = $version;
214  }
215  }
216 
222  function getUseRte()
223  {
224  return $this->usert;
225  }
226 
232  function addPlugin($a_plugin)
233  {
234  $this->plugins[$a_plugin] = $a_plugin;
235  }
236 
242  function removePlugin($a_plugin)
243  {
244  $this->removeplugins[$a_plugin] = $a_plugin;
245  }
246 
252  function addButton($a_button)
253  {
254  $this->buttons[$a_button] = $a_button;
255  }
256 
262  function removeButton($a_button)
263  {
264  unset($this->buttons[$a_button]);
265  }
266 
274  function setRTESupport($obj_id, $obj_type, $module, $cfg_template = null, $hide_switch = false, $version = null)
275  {
276  $this->rteSupport = array("obj_id" => $obj_id, "obj_type" => $obj_type, "module" => $module, 'cfg_template' => $cfg_template, 'hide_switch' => $hide_switch, 'version' => $version);
277  }
278 
282  function removeRTESupport()
283  {
284  $this->rteSupport = array();
285  }
286 
292  function setRteTags($a_rtetags)
293  {
294  $this->rtetags = $a_rtetags;
295  }
296 
302  function getRteTags()
303  {
304  return $this->rtetags;
305  }
306 
313  function setRteTagSet($a_set_name)
314  {
315  $this->setRteTags($this->rte_tag_set[$a_set_name]);
316  }
317 
324  function getRteTagSet($a_set_name)
325  {
326  return $this->rte_tag_set[$a_set_name];
327  }
328 
329 
333  function getRteTagString()
334  {
335  $result = "";
336  foreach ($this->getRteTags() as $tag)
337  {
338  $result .= "<$tag>";
339  }
340  return $result;
341  }
342 
348  function setUseTagsForRteOnly($a_val)
349  {
350  $this->use_tags_for_rte_only = $a_val;
351  }
352 
359  {
361  }
362 
368  function setValueByArray($a_values)
369  {
370  $this->setValue($a_values[$this->getPostVar()]);
371 
372  foreach($this->getSubItems() as $item)
373  {
374  $item->setValueByArray($a_values);
375  }
376  }
377 
383  function checkInput()
384  {
385  global $lng;
386  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
387 
388  if($this->usePurifier() && $this->getPurifier())
389  {
391  $_POST[$this->getPostVar()] = $this->getPurifier()->purify($_POST[$this->getPostVar()]);
392  }
393  else
394  {
395  $allowed = $this->getRteTagString();
396  if ($this->plugins["latex"] == "latex" && !is_int(strpos($allowed, "<span>")))
397  {
398  $allowed.= "<span>";
399  }
400  $_POST[$this->getPostVar()] = ($this->getUseRte() || !$this->getUseTagsForRteOnly())
401  ? ilUtil::stripSlashes($_POST[$this->getPostVar()], true, $allowed)
403  }
404 
405  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
406  {
407  $this->setAlert($lng->txt("msg_input_is_required"));
408 
409  return false;
410  }
411  return $this->checkSubItemsInput();
412  }
413 
419  function insert(&$a_tpl)
420  {
421  $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
422 
423  // disabled rte
424  if ($this->getUseRte() && $this->getDisabled())
425  {
426  $ttpl->setCurrentBlock("disabled_rte");
427  $ttpl->setVariable("DR_VAL", $this->getValue());
428  $ttpl->parseCurrentBlock();
429  }
430  else
431  {
432  if ($this->getUseRte())
433  {
434  $rtestring = ilRTE::_getRTEClassname();
435  include_once "./Services/RTE/classes/class.$rtestring.php";
436  $rte = new $rtestring($this->rteSupport['version']);
437 
438  $rte->setInitialWidth($this->getInitialRteWidth());
439 
440  // @todo: Check this.
441  $rte->addPlugin("emotions");
442  foreach ($this->plugins as $plugin)
443  {
444  if (strlen($plugin))
445  {
446  $rte->addPlugin($plugin);
447  }
448  }
449  foreach ($this->removeplugins as $plugin)
450  {
451  if (strlen($plugin))
452  {
453  $rte->removePlugin($plugin);
454  }
455  }
456 
457  foreach ($this->buttons as $button)
458  {
459  if (strlen($button))
460  {
461  $rte->addButton($button);
462  }
463  }
464 
465  $rte->disableButtons($this->getDisabledButtons());
466 
467  if($this->getRTERootBlockElement() !== null)
468  {
469  $rte->setRTERootBlockElement($this->getRTERootBlockElement());
470  }
471 
472  if (count($this->rteSupport) >= 3)
473  {
474  $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template'], $this->rteSupport['hide_switch']);
475  }
476  else
477  {
478  // disable all plugins for mini-tagset
479  if(!array_diff($this->getRteTags(), $this->getRteTagSet("mini")))
480  {
481  $rte->removeAllPlugins();
482 
483  // #13603 - "paste from word" is essential
484  $rte->addPlugin("paste");
485 
486  // #11980 - p-tag is mandatory but we do not want the icons it comes with
487  $rte->disableButtons(array("anchor", "justifyleft", "justifycenter",
488  "justifyright", "justifyfull", "formatselect", "removeformat",
489  "cut", "copy", "paste", "pastetext")); // JF, 2013-12-09
490  }
491 
492  $rte->addCustomRTESupport(0, "", $this->getRteTags());
493  }
494 
495  $ttpl->touchBlock("prop_ta_w");
496  $ttpl->setCurrentBlock("prop_textarea");
497  $ttpl->setVariable("ROWS", $this->getRows());
498  }
499  else
500  {
501  $ttpl->touchBlock("no_rteditor");
502 
503  if ($this->getCols() > 5)
504  {
505  $ttpl->setCurrentBlock("prop_ta_c");
506  $ttpl->setVariable("COLS", $this->getCols());
507  $ttpl->parseCurrentBlock();
508  }
509  else
510  {
511  $ttpl->touchBlock("prop_ta_w");
512  }
513 
514  $ttpl->setCurrentBlock("prop_textarea");
515  $ttpl->setVariable("ROWS", $this->getRows());
516  }
517  if (!$this->getDisabled())
518  {
519  $ttpl->setVariable("POST_VAR",
520  $this->getPostVar());
521  }
522  $ttpl->setVariable("ID", $this->getFieldId());
523  if ($this->getDisabled())
524  {
525  $ttpl->setVariable('DISABLED','disabled="disabled" ');
526  }
527  $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
528  $ttpl->parseCurrentBlock();
529  }
530 
531  if ($this->getDisabled())
532  {
533  $ttpl->setVariable("HIDDEN_INPUT",
534  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
535  }
536 
537 
538  $a_tpl->setCurrentBlock("prop_generic");
539  $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
540  $a_tpl->parseCurrentBlock();
541 
542  }
543 
551  public function usePurifier($a_flag = null)
552  {
553  if(null === $a_flag)
554  {
555  return $this->usePurifier;
556  }
557 
558  $this->usePurifier = $a_flag;
559  return $this;
560  }
561 
570  {
571  $this->Purifier = $Purifier;
572  return $this;
573  }
574 
581  public function getPurifier()
582  {
583  return $this->Purifier;
584  }
585 
593  public function setRTERootBlockElement($a_root_block_element)
594  {
595  $this->root_block_element = $a_root_block_element;
596  return $this;
597  }
598 
605  public function getRTERootBlockElement()
606  {
608  }
609 
618  public function disableButtons($a_button)
619  {
620  if(is_array($a_button))
621  {
622  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
623  }
624  else
625  {
626  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
627  }
628 
629  return $this;
630  }
631 
640  public function getDisabledButtons($as_array = true)
641  {
642  if(!$as_array)
643  {
644  return implode(',', $this->disabled_buttons);
645  }
646  else
647  {
649  }
650  }
651 
655  public function getInitialRteWidth()
656  {
658  }
659 
664  {
665  $this->initial_rte_width = $initial_rte_width;
666  }
667 }