ILIAS  release_7 Revision v7.30-3-g800a261c036
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
24include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
25include_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 protected $max_num_chars;
47 protected $min_num_chars;
48
52 protected $initial_rte_width = 795;
53
62 protected $disabled_buttons = array();
63
72 protected $usePurifier = false;
73
82 protected $Purifier = null;
83
91 protected $root_block_element = null;
92
93 protected $rte_tag_set = array(
94 "mini" => array("strong", "em", "u", "ol", "li", "ul", "blockquote", "a", "p", "span", "br"), // #13286/#17981
95 "standard" => array("strong", "em", "u", "ol", "li", "ul", "p", "div",
96 "i", "b", "code", "sup", "sub", "pre", "strike", "gap"),
97 "extended" => array(
98 "a","blockquote","br","cite","code","div","em","h1","h2","h3",
99 "h4","h5","h6","hr","li","ol","p",
100 "pre","span","strike","strong","sub","sup","u","ul",
101 "i", "b", "gap"),
102 "extended_img" => array(
103 "a","blockquote","br","cite","code","div","em","h1","h2","h3",
104 "h4","h5","h6","hr","img","li","ol","p",
105 "pre","span","strike","strong","sub","sup","u","ul",
106 "i", "b", "gap"),
107 "extended_table" => array(
108 "a","blockquote","br","cite","code","div","em","h1","h2","h3",
109 "h4","h5","h6","hr","li","ol","p",
110 "pre","span","strike","strong","sub","sup","table","td",
111 "tr","u","ul", "i", "b", "gap"),
112 "extended_table_img" => array(
113 "a","blockquote","br","cite","code","div","em","h1","h2","h3",
114 "h4","h5","h6","hr","img","li","ol","p",
115 "pre","span","strike","strong","sub","sup","table","td",
116 "tr","u","ul", "i", "b", "gap"),
117 "full" => array(
118 "a","blockquote","br","cite","code","div","em","h1","h2","h3",
119 "h4","h5","h6","hr","img","li","ol","p",
120 "pre","span","strike","strong","sub","sup","table","td",
121 "tr","u","ul","ruby","rbc","rtc","rb","rt","rp", "i", "b", "gap"));
122
123
130 public function __construct($a_title = "", $a_postvar = "")
131 {
132 global $DIC;
133
134 $this->lng = $DIC->language();
135 parent::__construct($a_title, $a_postvar);
136 $this->setType("textarea");
137 $this->setRteTagSet("standard");
138 $this->plugins = array();
139 $this->removeplugins = array();
140 $this->buttons = array();
141 $this->rteSupport = array();
142 }
143
149 public function setValue($a_value)
150 {
151 $this->value = $a_value;
152 }
153
159 public function getValue()
160 {
161 return $this->value;
162 }
163
170 public function setCols($a_cols)
171 {
172 // obsolete because of bootstrap
173 $this->cols = $a_cols;
174 }
175
181 public function getCols()
182 {
183 return $this->cols;
184 }
185
191 public function setRows($a_rows)
192 {
193 $this->rows = $a_rows;
194 }
195
201 public function getRows()
202 {
203 return $this->rows;
204 }
205
211 public function setMaxNumOfChars($a_number)
212 {
213 $this->max_num_chars = $a_number;
214 }
215
219 public function getMaxNumOfChars()
220 {
222 }
223
229 public function setMinNumOfChars($a_number)
230 {
231 $this->min_num_chars = $a_number;
232 }
233
237 public function getMinNumOfChars()
238 {
240 }
241
248 public function setUseRte($a_usert, $version = '')
249 {
250 $this->usert = $a_usert;
251
252 if (strlen($version)) {
253 $this->rteSupport['version'] = $version;
254 }
255 }
256
262 public function getUseRte()
263 {
264 return $this->usert;
265 }
266
272 public function addPlugin($a_plugin)
273 {
274 $this->plugins[$a_plugin] = $a_plugin;
275 }
276
282 public function removePlugin($a_plugin)
283 {
284 $this->removeplugins[$a_plugin] = $a_plugin;
285 }
286
292 public function addButton($a_button)
293 {
294 $this->buttons[$a_button] = $a_button;
295 }
296
302 public function removeButton($a_button)
303 {
304 unset($this->buttons[$a_button]);
305 }
306
314 public function setRTESupport($obj_id, $obj_type, $module, $cfg_template = null, $hide_switch = false, $version = null)
315 {
316 $this->rteSupport = array("obj_id" => $obj_id, "obj_type" => $obj_type, "module" => $module, 'cfg_template' => $cfg_template, 'hide_switch' => $hide_switch, 'version' => $version);
317 }
318
322 public function removeRTESupport()
323 {
324 $this->rteSupport = array();
325 }
326
332 public function setRteTags($a_rtetags)
333 {
334 $this->rtetags = $a_rtetags;
335 }
336
342 public function getRteTags()
343 {
344 return $this->rtetags;
345 }
346
353 public function setRteTagSet($a_set_name)
354 {
355 $this->setRteTags($this->rte_tag_set[$a_set_name]);
356 }
357
364 public function getRteTagSet($a_set_name)
365 {
366 return $this->rte_tag_set[$a_set_name];
367 }
368
369
373 public function getRteTagString()
374 {
375 $result = "";
376 foreach ($this->getRteTags() as $tag) {
377 $result .= "<$tag>";
378 }
379 return $result;
380 }
381
387 public function setUseTagsForRteOnly($a_val)
388 {
389 $this->use_tags_for_rte_only = $a_val;
390 }
391
397 public function getUseTagsForRteOnly()
398 {
400 }
401
407 public function setValueByArray($a_values)
408 {
409 $this->setValue($a_values[$this->getPostVar()]);
410
411 foreach ($this->getSubItems() as $item) {
412 $item->setValueByArray($a_values);
413 }
414 }
415
421 public function checkInput()
422 {
424 include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
425
426 if ($this->usePurifier() && $this->getPurifier()) {
428 $_POST[$this->getPostVar()] = $this->getPurifier()->purify($_POST[$this->getPostVar()]);
429 } else {
430 $allowed = $this->getRteTagString();
431 if ($this->plugins["latex"] == "latex" && !is_int(strpos($allowed, "<span>"))) {
432 $allowed .= "<span>";
433 }
434 $_POST[$this->getPostVar()] = ($this->getUseRte() || !$this->getUseTagsForRteOnly())
435 ? ilUtil::stripSlashes($_POST[$this->getPostVar()], true, $allowed)
437 }
438
440
441 if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") {
442 $this->setAlert($lng->txt("msg_input_is_required"));
443
444 return false;
445 }
446
447 if ($this->isCharLimited()) {
448 //avoid whitespace surprises. #20630, #20674
449 $ascii_whitespaces = chr(194) . chr(160);
450 $ascii_breaklines = chr(13) . chr(10);
451
452 $to_replace = array($ascii_whitespaces, $ascii_breaklines, "&lt;", "&gt;", "&amp;");
453 $replace_to = array(' ', '', "_", "_", "_");
454
455 #20630 mbstring extension is mandatory for 5.4
456 $chars_entered = mb_strlen(strip_tags(str_replace($to_replace, $replace_to, $_POST[$this->getPostVar()])));
457
458 if ($this->getMaxNumOfChars() && ($chars_entered > $this->getMaxNumOfChars())) {
459 $this->setAlert($lng->txt("msg_input_char_limit_max"));
460
461 return false;
462 } elseif ($this->getMinNumOfChars() && ($chars_entered < $this->getMinNumOfChars())) {
463 $this->setAlert($lng->txt("msg_input_char_limit_min"));
464
465 return false;
466 }
467 }
468
469 return $this->checkSubItemsInput();
470 }
471
477 public function insert($a_tpl)
478 {
480
481 $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
482
483 // disabled rte
484 if ($this->getUseRte() && $this->getDisabled()) {
485 $ttpl->setCurrentBlock("disabled_rte");
486 $ttpl->setVariable("DR_VAL", $this->getValue());
487 $ttpl->parseCurrentBlock();
488 } else {
489 if ($this->getUseRte()) {
490 $rtestring = ilRTE::_getRTEClassname();
491 include_once "./Services/RTE/classes/class.$rtestring.php";
492 $rte = new $rtestring($this->rteSupport['version']);
493
494 $rte->setInitialWidth($this->getInitialRteWidth());
495
496 // @todo: Check this.
497 $rte->addPlugin("emoticons");
498 foreach ($this->plugins as $plugin) {
499 if (strlen($plugin)) {
500 $rte->addPlugin($plugin);
501 }
502 }
503 foreach ($this->removeplugins as $plugin) {
504 if (strlen($plugin)) {
505 $rte->removePlugin($plugin);
506 }
507 }
508
509 foreach ($this->buttons as $button) {
510 if (strlen($button)) {
511 $rte->addButton($button);
512 }
513 }
514
515 $rte->disableButtons($this->getDisabledButtons());
516
517 if ($this->getRTERootBlockElement() !== null) {
518 $rte->setRTERootBlockElement($this->getRTERootBlockElement());
519 }
520
521 if (count($this->rteSupport) >= 3) {
522 $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template'], $this->rteSupport['hide_switch']);
523 } else {
524 // disable all plugins for mini-tagset
525 if (!array_diff($this->getRteTags(), $this->getRteTagSet("mini"))) {
526 $rte->removeAllPlugins();
527
528 // #13603 - "paste from word" is essential
529 $rte->addPlugin("paste");
530 //Add plugins 'lists', 'code' and 'link': in tinymce 3 it wasnt necessary to configure these plugins
531 $rte->addPlugin("lists");
532 $rte->addPlugin("link");
533 $rte->addPlugin("code");
534
535 if (method_exists($rte, 'removeAllContextMenuItems')) {
536 $rte->removeAllContextMenuItems(); //https://github.com/ILIAS-eLearning/ILIAS/pull/3088#issuecomment-805830050
537 }
538
539 // #11980 - p-tag is mandatory but we do not want the icons it comes with
540 $rte->disableButtons(array("anchor", "alignleft", "aligncenter",
541 "alignright", "alignjustify", "formatselect", "removeformat",
542 "cut", "copy", "paste", "pastetext")); // JF, 2013-12-09
543 }
544 $rte->addCustomRTESupport(0, "", $this->getRteTags());
545 }
546
547 $ttpl->touchBlock("prop_ta_w");
548 $ttpl->setCurrentBlock("prop_textarea");
549 $ttpl->setVariable("ROWS", $this->getRows());
550 } else {
551 $ttpl->touchBlock("no_rteditor");
552
553 if ($this->getCols() > 5) {
554 $ttpl->setCurrentBlock("prop_ta_c");
555 $ttpl->setVariable("COLS", $this->getCols());
556 $ttpl->parseCurrentBlock();
557 } else {
558 $ttpl->touchBlock("prop_ta_w");
559 }
560
561 $ttpl->setCurrentBlock("prop_textarea");
562 $ttpl->setVariable("ROWS", $this->getRows());
563 }
564
565 $ttpl->setVariable("POST_VAR", $this->getPostVar());
566 $ttpl->setVariable("ID", $this->getFieldId());
567 if ($this->getDisabled()) {
568 $ttpl->setVariable('DISABLED', 'disabled="disabled" ');
569 }
570 $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
571
572 if ($this->getRequired()) {
573 $ttpl->setVariable("REQUIRED", "required=\"required\"");
574 }
575
576 if ($this->isCharLimited()) {
577 $ttpl->setVariable("MAXCHARS", $this->getMaxNumOfChars());
578 $ttpl->setVariable("MINCHARS", $this->getMinNumOfChars());
579
580 $lng->toJS("form_chars_remaining");
581 }
582
583 $ttpl->parseCurrentBlock();
584 }
585
586 if ($this->isCharLimited()) {
587 $ttpl->setVariable("FEEDBACK_MAX_LIMIT", $this->getMaxNumOfChars());
588 $ttpl->setVariable("FEEDBACK_ID", $this->getFieldId());
589 $ttpl->setVariable("CHARS_REMAINING", $lng->txt("form_chars_remaining"));
590 }
591
592 if ($this->getDisabled()) {
593 $ttpl->setVariable(
594 "HIDDEN_INPUT",
595 $this->getHiddenTag($this->getPostVar(), $this->getValue())
596 );
597 }
598 $a_tpl->setCurrentBlock("prop_generic");
599 $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
600 $a_tpl->parseCurrentBlock();
601 }
602
610 public function usePurifier($a_flag = null)
611 {
612 if (null === $a_flag) {
613 return $this->usePurifier;
614 }
615
616 $this->usePurifier = $a_flag;
617 return $this;
618 }
619
628 {
629 $this->Purifier = $Purifier;
630 return $this;
631 }
632
639 public function getPurifier()
640 {
641 return $this->Purifier;
642 }
643
651 public function setRTERootBlockElement($a_root_block_element)
652 {
653 $this->root_block_element = $a_root_block_element;
654 return $this;
655 }
656
663 public function getRTERootBlockElement()
664 {
666 }
667
676 public function disableButtons($a_button)
677 {
678 if (is_array($a_button)) {
679 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
680 } else {
681 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
682 }
683
684 return $this;
685 }
686
695 public function getDisabledButtons($as_array = true)
696 {
697 if (!$as_array) {
698 return implode(',', $this->disabled_buttons);
699 } else {
701 }
702 }
703
707 public function getInitialRteWidth()
708 {
710 }
711
716 {
717 $this->initial_rte_width = $initial_rte_width;
718 }
719
720 public function isCharLimited()
721 {
722 if ($this->getMaxNumOfChars() || $this->getMinNumOfChars()) {
723 return true;
724 }
725
726 return false;
727 }
728}
$result
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
getHiddenTag($a_post_var, $a_value)
Get hidden tag (used for disabled properties)
setAlert($a_alert)
Set Alert Text.
static removeProhibitedCharacters($a_text)
Remove prohibited characters see #19159.
getFieldId()
Get Post Variable.
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727.
static _getRTEClassname()
This class represents a property that may include a sub form.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
setMinNumOfChars($a_number)
Set Minimum number of characters allowed.
setInitialRteWidth($initial_rte_width)
addButton($a_button)
Add RTE button.
setMaxNumOfChars($a_number)
Set Maximum number of characters allowed.
setUseRte($a_usert, $version='')
Set Use Rich Text Editing.
setRteTagSet($a_set_name)
Set Set of Valid RTE Tags.
setRTESupport($obj_id, $obj_type, $module, $cfg_template=null, $hide_switch=false, $version=null)
Set RTE support for a special module.
removeRTESupport()
Remove RTE support for a special module.
disableButtons($a_button)
Sets buttons which should be disabled in TinyMCE.
getUseTagsForRteOnly()
Get use tags for RTE only (default is true)
setPurifier(ilHtmlPurifierInterface $Purifier)
Setter for the html purifier.
setValue($a_value)
Set Value.
insert($a_tpl)
Insert property html.
getRteTagSet($a_set_name)
Get Set of Valid RTE Tags.
getPurifier()
Getter for the html purifier.
setRTERootBlockElement($a_root_block_element)
Setter for the TinyMCE root block element.
removePlugin($a_plugin)
Remove RTE plugin.
getRTERootBlockElement()
Getter for the TinyMCE root block element.
getMinNumOfChars()
Get Minimum number of characters allowed.
getRteTagString()
RTE Tag string.
getMaxNumOfChars()
Get Maximum number of characters allowed.
setValueByArray($a_values)
Set value by array.
removeButton($a_button)
Remove RTE button.
usePurifier($a_flag=null)
Setter/Getter for the html purifier usage.
getDisabledButtons($as_array=true)
Returns the disabled TinyMCE buttons.
setRteTags($a_rtetags)
Set Valid RTE Tags.
setUseTagsForRteOnly($a_val)
Set use tags for RTE only (default is true)
addPlugin($a_plugin)
Add RTE plugin.
checkInput()
Check input, strip slashes etc.
__construct($a_title="", $a_postvar="")
Constructor.
getUseRte()
Get Use Rich Text Editing.
getRteTags()
Get Valid RTE Tags.
static stripOnlySlashes($a_str)
strip slashes if magic qoutes is enabled
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
global $DIC
Definition: goto.php:24
Interface for html sanitizing functionality.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc