ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
456 if (function_exists('mb_strlen')) {
457 $chars_entered = mb_strlen(strip_tags(str_replace($to_replace, $replace_to, $_POST[$this->getPostVar()])));
458 } else {
459 $chars_entered = strlen(strip_tags(str_replace($to_replace, $replace_to, $_POST[$this->getPostVar()])));
460 }
461
462 if ($this->getMaxNumOfChars() && ($chars_entered > $this->getMaxNumOfChars())) {
463 $this->setAlert($lng->txt("msg_input_char_limit_max"));
464
465 return false;
466 } elseif ($this->getMinNumOfChars() && ($chars_entered < $this->getMinNumOfChars())) {
467 $this->setAlert($lng->txt("msg_input_char_limit_min"));
468
469 return false;
470 }
471 }
472
473 return $this->checkSubItemsInput();
474 }
475
481 public function insert($a_tpl)
482 {
484
485 $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
486
487 // disabled rte
488 if ($this->getUseRte() && $this->getDisabled()) {
489 $ttpl->setCurrentBlock("disabled_rte");
490 $ttpl->setVariable("DR_VAL", $this->getValue());
491 $ttpl->parseCurrentBlock();
492 } else {
493 if ($this->getUseRte()) {
494 $rtestring = ilRTE::_getRTEClassname();
495 include_once "./Services/RTE/classes/class.$rtestring.php";
496 $rte = new $rtestring($this->rteSupport['version']);
497
498 $rte->setInitialWidth($this->getInitialRteWidth());
499
500 // @todo: Check this.
501 $rte->addPlugin("emotions");
502 foreach ($this->plugins as $plugin) {
503 if (strlen($plugin)) {
504 $rte->addPlugin($plugin);
505 }
506 }
507 foreach ($this->removeplugins as $plugin) {
508 if (strlen($plugin)) {
509 $rte->removePlugin($plugin);
510 }
511 }
512
513 foreach ($this->buttons as $button) {
514 if (strlen($button)) {
515 $rte->addButton($button);
516 }
517 }
518
519 $rte->disableButtons($this->getDisabledButtons());
520
521 if ($this->getRTERootBlockElement() !== null) {
522 $rte->setRTERootBlockElement($this->getRTERootBlockElement());
523 }
524
525 if (count($this->rteSupport) >= 3) {
526 $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template'], $this->rteSupport['hide_switch']);
527 } else {
528 // disable all plugins for mini-tagset
529 if (!array_diff($this->getRteTags(), $this->getRteTagSet("mini"))) {
530 $rte->removeAllPlugins();
531
532 // #13603 - "paste from word" is essential
533 $rte->addPlugin("paste");
534
535 // #11980 - p-tag is mandatory but we do not want the icons it comes with
536 $rte->disableButtons(array("anchor", "justifyleft", "justifycenter",
537 "justifyright", "justifyfull", "formatselect", "removeformat",
538 "cut", "copy", "paste", "pastetext")); // JF, 2013-12-09
539 }
540
541 $rte->addCustomRTESupport(0, "", $this->getRteTags());
542 }
543
544 $ttpl->touchBlock("prop_ta_w");
545 $ttpl->setCurrentBlock("prop_textarea");
546 $ttpl->setVariable("ROWS", $this->getRows());
547 } else {
548 $ttpl->touchBlock("no_rteditor");
549
550 if ($this->getCols() > 5) {
551 $ttpl->setCurrentBlock("prop_ta_c");
552 $ttpl->setVariable("COLS", $this->getCols());
553 $ttpl->parseCurrentBlock();
554 } else {
555 $ttpl->touchBlock("prop_ta_w");
556 }
557
558 $ttpl->setCurrentBlock("prop_textarea");
559 $ttpl->setVariable("ROWS", $this->getRows());
560 }
561 if (!$this->getDisabled()) {
562 $ttpl->setVariable(
563 "POST_VAR",
564 $this->getPostVar()
565 );
566 }
567 $ttpl->setVariable("ID", $this->getFieldId());
568 if ($this->getDisabled()) {
569 $ttpl->setVariable('DISABLED', 'disabled="disabled" ');
570 }
571 $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
572
573 if ($this->getRequired()) {
574 $ttpl->setVariable("REQUIRED", "required=\"required\"");
575 }
576
577 if ($this->isCharLimited()) {
578 $ttpl->setVariable("MAXCHARS", $this->getMaxNumOfChars());
579 $ttpl->setVariable("MINCHARS", $this->getMinNumOfChars());
580
581 $lng->toJS("form_chars_remaining");
582 }
583
584 $ttpl->parseCurrentBlock();
585 }
586
587 if ($this->isCharLimited()) {
588 $ttpl->setVariable("FEEDBACK_MAX_LIMIT", $this->getMaxNumOfChars());
589 $ttpl->setVariable("FEEDBACK_ID", $this->getFieldId());
590 $ttpl->setVariable("CHARS_REMAINING", $lng->txt("form_chars_remaining"));
591 }
592
593 if ($this->getDisabled()) {
594 $ttpl->setVariable(
595 "HIDDEN_INPUT",
596 $this->getHiddenTag($this->getPostVar(), $this->getValue())
597 );
598 }
599 $a_tpl->setCurrentBlock("prop_generic");
600 $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
601 $a_tpl->parseCurrentBlock();
602 }
603
611 public function usePurifier($a_flag = null)
612 {
613 if (null === $a_flag) {
614 return $this->usePurifier;
615 }
616
617 $this->usePurifier = $a_flag;
618 return $this;
619 }
620
629 {
630 $this->Purifier = $Purifier;
631 return $this;
632 }
633
640 public function getPurifier()
641 {
642 return $this->Purifier;
643 }
644
652 public function setRTERootBlockElement($a_root_block_element)
653 {
654 $this->root_block_element = $a_root_block_element;
655 return $this;
656 }
657
664 public function getRTERootBlockElement()
665 {
667 }
668
677 public function disableButtons($a_button)
678 {
679 if (is_array($a_button)) {
680 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
681 } else {
682 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
683 }
684
685 return $this;
686 }
687
696 public function getDisabledButtons($as_array = true)
697 {
698 if (!$as_array) {
699 return implode(',', $this->disabled_buttons);
700 } else {
702 }
703 }
704
708 public function getInitialRteWidth()
709 {
711 }
712
717 {
718 $this->initial_rte_width = $initial_rte_width;
719 }
720
721 public function isCharLimited()
722 {
723 if ($this->getMaxNumOfChars() || $this->getMinNumOfChars()) {
724 return true;
725 }
726
727 return false;
728 }
729}
$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
Interface for html sanitizing functionality.
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35
if($modEnd===false) $module
Definition: module.php:59
global $DIC
Definition: saml.php:7