ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
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
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
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 $_POST[$this->getPostVar()] = $this->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 $ttpl->parseCurrentBlock();
531 }
532
533 if ($this->getDisabled())
534 {
535 $ttpl->setVariable("HIDDEN_INPUT",
536 $this->getHiddenTag($this->getPostVar(), $this->getValue()));
537 }
538
539
540 $a_tpl->setCurrentBlock("prop_generic");
541 $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
542 $a_tpl->parseCurrentBlock();
543
544 }
545
553 public function usePurifier($a_flag = null)
554 {
555 if(null === $a_flag)
556 {
557 return $this->usePurifier;
558 }
559
560 $this->usePurifier = $a_flag;
561 return $this;
562 }
563
572 {
573 $this->Purifier = $Purifier;
574 return $this;
575 }
576
583 public function getPurifier()
584 {
585 return $this->Purifier;
586 }
587
595 public function setRTERootBlockElement($a_root_block_element)
596 {
597 $this->root_block_element = $a_root_block_element;
598 return $this;
599 }
600
607 public function getRTERootBlockElement()
608 {
610 }
611
620 public function disableButtons($a_button)
621 {
622 if(is_array($a_button))
623 {
624 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
625 }
626 else
627 {
628 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
629 }
630
631 return $this;
632 }
633
642 public function getDisabledButtons($as_array = true)
643 {
644 if(!$as_array)
645 {
646 return implode(',', $this->disabled_buttons);
647 }
648 else
649 {
651 }
652 }
653
657 public function getInitialRteWidth()
658 {
660 }
661
666 {
667 $this->initial_rte_width = $initial_rte_width;
668 }
669}
$result
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.
getFieldId()
Get Post Variable.
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727.
removeProhibitedCharacters($a_text)
Remove prohibited characters see #19159.
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.
setInitialRteWidth($initial_rte_width)
addButton($a_button)
Add RTE button.
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.
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.
getRteTagString()
RTE Tag string.
setValueByArray($a_values)
Set value by array.
insert(&$a_tpl)
Insert property html.
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
$_POST['username']
Definition: cron.php:12
Interface for html sanitizing functionality.
global $lng
Definition: privfeed.php:40