ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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", "br"), // #13286/#17981
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)
402  : $this->stripSlashesAddSpaceFallback($_POST[$this->getPostVar()]);
403  }
404 
405  $_POST[$this->getPostVar()] = self::removeProhibitedCharacters($_POST[$this->getPostVar()]);
406 
407  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
408  {
409  $this->setAlert($lng->txt("msg_input_is_required"));
410 
411  return false;
412  }
413  return $this->checkSubItemsInput();
414  }
415 
421  function insert($a_tpl)
422  {
423  $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
424 
425  // disabled rte
426  if ($this->getUseRte() && $this->getDisabled())
427  {
428  $ttpl->setCurrentBlock("disabled_rte");
429  $ttpl->setVariable("DR_VAL", $this->getValue());
430  $ttpl->parseCurrentBlock();
431  }
432  else
433  {
434  if ($this->getUseRte())
435  {
436  $rtestring = ilRTE::_getRTEClassname();
437  include_once "./Services/RTE/classes/class.$rtestring.php";
438  $rte = new $rtestring($this->rteSupport['version']);
439 
440  $rte->setInitialWidth($this->getInitialRteWidth());
441 
442  // @todo: Check this.
443  $rte->addPlugin("emotions");
444  foreach ($this->plugins as $plugin)
445  {
446  if (strlen($plugin))
447  {
448  $rte->addPlugin($plugin);
449  }
450  }
451  foreach ($this->removeplugins as $plugin)
452  {
453  if (strlen($plugin))
454  {
455  $rte->removePlugin($plugin);
456  }
457  }
458 
459  foreach ($this->buttons as $button)
460  {
461  if (strlen($button))
462  {
463  $rte->addButton($button);
464  }
465  }
466 
467  $rte->disableButtons($this->getDisabledButtons());
468 
469  if($this->getRTERootBlockElement() !== null)
470  {
471  $rte->setRTERootBlockElement($this->getRTERootBlockElement());
472  }
473 
474  if (count($this->rteSupport) >= 3)
475  {
476  $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template'], $this->rteSupport['hide_switch']);
477  }
478  else
479  {
480  // disable all plugins for mini-tagset
481  if(!array_diff($this->getRteTags(), $this->getRteTagSet("mini")))
482  {
483  $rte->removeAllPlugins();
484 
485  // #13603 - "paste from word" is essential
486  $rte->addPlugin("paste");
487 
488  // #11980 - p-tag is mandatory but we do not want the icons it comes with
489  $rte->disableButtons(array("anchor", "justifyleft", "justifycenter",
490  "justifyright", "justifyfull", "formatselect", "removeformat",
491  "cut", "copy", "paste", "pastetext")); // JF, 2013-12-09
492  }
493 
494  $rte->addCustomRTESupport(0, "", $this->getRteTags());
495  }
496 
497  $ttpl->touchBlock("prop_ta_w");
498  $ttpl->setCurrentBlock("prop_textarea");
499  $ttpl->setVariable("ROWS", $this->getRows());
500  }
501  else
502  {
503  $ttpl->touchBlock("no_rteditor");
504 
505  if ($this->getCols() > 5)
506  {
507  $ttpl->setCurrentBlock("prop_ta_c");
508  $ttpl->setVariable("COLS", $this->getCols());
509  $ttpl->parseCurrentBlock();
510  }
511  else
512  {
513  $ttpl->touchBlock("prop_ta_w");
514  }
515 
516  $ttpl->setCurrentBlock("prop_textarea");
517  $ttpl->setVariable("ROWS", $this->getRows());
518  }
519  if (!$this->getDisabled())
520  {
521  $ttpl->setVariable("POST_VAR",
522  $this->getPostVar());
523  }
524  $ttpl->setVariable("ID", $this->getFieldId());
525  if ($this->getDisabled())
526  {
527  $ttpl->setVariable('DISABLED','disabled="disabled" ');
528  }
529  $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
530 
531  if($this->getRequired())
532  {
533  $ttpl->setVariable("REQUIRED", "required=\"required\"");
534  }
535 
536  $ttpl->parseCurrentBlock();
537  }
538 
539  if ($this->getDisabled())
540  {
541  $ttpl->setVariable("HIDDEN_INPUT",
542  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
543  }
544  $a_tpl->setCurrentBlock("prop_generic");
545  $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
546  $a_tpl->parseCurrentBlock();
547 
548  }
549 
557  public function usePurifier($a_flag = null)
558  {
559  if(null === $a_flag)
560  {
561  return $this->usePurifier;
562  }
563 
564  $this->usePurifier = $a_flag;
565  return $this;
566  }
567 
576  {
577  $this->Purifier = $Purifier;
578  return $this;
579  }
580 
587  public function getPurifier()
588  {
589  return $this->Purifier;
590  }
591 
599  public function setRTERootBlockElement($a_root_block_element)
600  {
601  $this->root_block_element = $a_root_block_element;
602  return $this;
603  }
604 
611  public function getRTERootBlockElement()
612  {
614  }
615 
624  public function disableButtons($a_button)
625  {
626  if(is_array($a_button))
627  {
628  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
629  }
630  else
631  {
632  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
633  }
634 
635  return $this;
636  }
637 
646  public function getDisabledButtons($as_array = true)
647  {
648  if(!$as_array)
649  {
650  return implode(',', $this->disabled_buttons);
651  }
652  else
653  {
655  }
656  }
657 
661  public function getInitialRteWidth()
662  {
664  }
665 
670  {
671  $this->initial_rte_width = $initial_rte_width;
672  }
673 }
static _getRTEClassname()
setRTESupport($obj_id, $obj_type, $module, $cfg_template=null, $hide_switch=false, $version=null)
Set RTE support for a special module.
setValueByArray($a_values)
Set value by array.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getHiddenTag($a_post_var, $a_value)
Get hidden tag (used for disabled properties)
$result
setRteTagSet($a_set_name)
Set Set of Valid RTE Tags.
getPostVar()
Get Post Variable.
setUseRte($a_usert, $version='')
Set Use Rich Text Editing.
setValue($a_value)
Set Value.
setUseTagsForRteOnly($a_val)
Set use tags for RTE only (default is true)
removePlugin($a_plugin)
Remove RTE plugin.
setAlert($a_alert)
Set Alert Text.
setRteTags($a_rtetags)
Set Valid RTE Tags.
static stripOnlySlashes($a_str)
strip slashes if magic qoutes is enabled
setType($a_type)
Set Type.
setRTERootBlockElement($a_root_block_element)
Setter for the TinyMCE root block element.
removeButton($a_button)
Remove RTE button.
removeRTESupport()
Remove RTE support for a special module.
__construct($a_title="", $a_postvar="")
Constructor.
getRteTags()
Get Valid RTE Tags.
getRteTagString()
RTE Tag string.
Interface for html sanitizing functionality.
disableButtons($a_button)
Sets buttons which should be disabled in TinyMCE.
getRTERootBlockElement()
Getter for the TinyMCE root block element.
getRteTagSet($a_set_name)
Get Set of Valid RTE Tags.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
getUseRte()
Get Use Rich Text Editing.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
setInitialRteWidth($initial_rte_width)
Remove unnecessary rows
usePurifier($a_flag=null)
Setter/Getter for the html purifier usage.
addButton($a_button)
Add RTE button.
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727.
This class represents a property that may include a sub form.
global $lng
Definition: privfeed.php:17
This class represents a text area property in a property form.
addPlugin($a_plugin)
Add RTE plugin.
setPurifier(ilHtmlPurifierInterface $Purifier)
Setter for the html purifier.
getUseTagsForRteOnly()
Get use tags for RTE only (default is true)
checkInput()
Check input, strip slashes etc.
$_POST["username"]
insert($a_tpl)
Insert property html.
getDisabledButtons($as_array=true)
Returns the disabled TinyMCE buttons.
getPurifier()
Getter for the html purifier.