ILIAS  Release_4_1_x_branch Revision 61804
 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 
34 {
35  protected $value;
36  protected $cols;
37  protected $rows;
38  protected $usert;
39  protected $rtetags;
40  protected $plugins;
41  protected $removeplugins;
42  protected $buttons;
43  protected $rtesupport;
44  protected $use_tags_for_rte_only = true;
45 
54  protected $disabled_buttons = array();
55 
64  protected $usePurifier = false;
65 
74  protected $Purifier = null;
75 
83  protected $root_block_element = null;
84 
85  protected $rte_tag_set = array(
86  "standard" => array ("strong", "em", "u", "ol", "li", "ul", "p", "div",
87  "i", "b", "code", "sup", "sub", "pre", "strike", "gap"),
88  "extended" => array (
89  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
90  "h4","h5","h6","hr","li","ol","p",
91  "pre","span","strike","strong","sub","sup","u","ul",
92  "i", "b", "gap"),
93  "extended_img" => array (
94  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
95  "h4","h5","h6","hr","img","li","ol","p",
96  "pre","span","strike","strong","sub","sup","u","ul",
97  "i", "b", "gap"),
98  "extended_table" => array (
99  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
100  "h4","h5","h6","hr","li","ol","p",
101  "pre","span","strike","strong","sub","sup","table","td",
102  "tr","u","ul", "i", "b", "gap"),
103  "extended_table_img" => array (
104  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
105  "h4","h5","h6","hr","img","li","ol","p",
106  "pre","span","strike","strong","sub","sup","table","td",
107  "tr","u","ul", "i", "b", "gap"),
108  "full" => array (
109  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
110  "h4","h5","h6","hr","img","li","ol","p",
111  "pre","span","strike","strong","sub","sup","table","td",
112  "tr","u","ul","ruby","rbc","rtc","rb","rt","rp", "i", "b", "gap"));
113 
114 
121  function __construct($a_title = "", $a_postvar = "")
122  {
123  parent::__construct($a_title, $a_postvar);
124  $this->setType("textarea");
125  $this->setRteTagSet("standard");
126  $this->plugins = array();
127  $this->removeplugins = array();
128  $this->buttons = array();
129  $this->rteSupport = array();
130  }
131 
137  function setValue($a_value)
138  {
139  $this->value = $a_value;
140  }
141 
147  function getValue()
148  {
149  return $this->value;
150  }
151 
157  function setCols($a_cols)
158  {
159  $this->cols = $a_cols;
160  }
161 
167  function getCols()
168  {
169  return $this->cols;
170  }
171 
177  function setRows($a_rows)
178  {
179  $this->rows = $a_rows;
180  }
181 
187  function getRows()
188  {
189  return $this->rows;
190  }
191 
197  function setUseRte($a_usert)
198  {
199  $this->usert = $a_usert;
200  }
201 
207  function getUseRte()
208  {
209  return $this->usert;
210  }
211 
217  function addPlugin($a_plugin)
218  {
219  $this->plugins[$a_plugin] = $a_plugin;
220  }
221 
227  function removePlugin($a_plugin)
228  {
229  $this->removeplugins[$a_plugin] = $a_plugin;
230  }
231 
237  function addButton($a_button)
238  {
239  $this->buttons[$a_button] = $a_button;
240  }
241 
247  function removeButton($a_button)
248  {
249  unset($this->buttons[$a_button]);
250  }
251 
259  function setRTESupport($obj_id, $obj_type, $module, $cfg_template = null, $hide_switch = false, $version = null)
260  {
261  $this->rteSupport = array("obj_id" => $obj_id, "obj_type" => $obj_type, "module" => $module, 'cfg_template' => $cfg_template, 'hide_switch' => $hide_switch, 'version' => $version);
262  }
263 
267  function removeRTESupport()
268  {
269  $this->rteSupport = array();
270  }
271 
277  function setRteTags($a_rtetags)
278  {
279  $this->rtetags = $a_rtetags;
280  }
281 
287  function getRteTags()
288  {
289  return $this->rtetags;
290  }
291 
298  function setRteTagSet($a_set_name)
299  {
300  $this->setRteTags($this->rte_tag_set[$a_set_name]);
301  }
302 
309  function getRteTagSet($a_set_name)
310  {
311  return $this->rte_tag_set[$a_set_name];
312  }
313 
314 
318  function getRteTagString()
319  {
320  $result = "";
321  foreach ($this->getRteTags() as $tag)
322  {
323  $result .= "<$tag>";
324  }
325  return $result;
326  }
327 
333  function setUseTagsForRteOnly($a_val)
334  {
335  $this->use_tags_for_rte_only = $a_val;
336  }
337 
344  {
346  }
347 
353  function setValueByArray($a_values)
354  {
355  $this->setValue($a_values[$this->getPostVar()]);
356  }
357 
363  function checkInput()
364  {
365  global $lng;
366  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
367 
368  if($this->usePurifier() && $this->getPurifier())
369  {
371  $_POST[$this->getPostVar()] = $this->getPurifier()->purify($_POST[$this->getPostVar()]);
372  }
373  else
374  {
375  $allowed = $this->getRteTagString();
376  if ($this->plugins["latex"] == "latex" && !is_int(strpos($allowed, "<span>")))
377  {
378  $allowed.= "<span>";
379  }
380  $_POST[$this->getPostVar()] = ($this->getUseRte() || !$this->getUseTagsForRteOnly())
381  ? ilUtil::stripSlashes($_POST[$this->getPostVar()], true, $allowed)
383  }
384 
385  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
386  {
387  $this->setAlert($lng->txt("msg_input_is_required"));
388 
389  return false;
390  }
391  return $this->checkSubItemsInput();
392  }
393 
399  function insert(&$a_tpl)
400  {
401  $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
402 
403  // disabled rte
404  if ($this->getUseRte() && $this->getDisabled())
405  {
406  $ttpl->setCurrentBlock("disabled_rte");
407  $ttpl->setVariable("DR_VAL", $this->getValue());
408  $ttpl->parseCurrentBlock();
409  }
410  else
411  {
412  if ($this->getUseRte())
413  {
414  include_once "./Services/RTE/classes/class.ilRTE.php";
415  $rtestring = ilRTE::_getRTEClassname();
416  include_once "./Services/RTE/classes/class.$rtestring.php";
417  $rte = new $rtestring($this->rteSupport['version']);
418 
419  // @todo: Check this.
420  $rte->addPlugin("emotions");
421  foreach ($this->plugins as $plugin)
422  {
423  if (strlen($plugin))
424  {
425  $rte->addPlugin($plugin);
426  }
427  }
428  foreach ($this->removeplugins as $plugin)
429  {
430  if (strlen($plugin))
431  {
432  $rte->removePlugin($plugin);
433  }
434  }
435 
436  foreach ($this->buttons as $button)
437  {
438  if (strlen($button))
439  {
440  $rte->addButton($button);
441  }
442  }
443 
444  $rte->disableButtons($this->getDisabledButtons());
445 
446  if($this->getRTERootBlockElement() !== null)
447  {
448  $rte->setRTERootBlockElement($this->getRTERootBlockElement());
449  }
450 
451  if (count($this->rteSupport) >= 3)
452  {
453  $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template'], $this->rteSupport['hide_switch']);
454  }
455  else
456  {
457  $rte->addCustomRTESupport(0, "", $this->getRteTags());
458  }
459 
460  $ttpl->touchBlock("prop_ta_w");
461  $ttpl->setCurrentBlock("prop_textarea");
462  $ttpl->setVariable("ROWS", $this->getRows());
463  }
464  else
465  {
466  $ttpl->touchBlock("no_rteditor");
467 
468  if ($this->getCols() > 5)
469  {
470  $ttpl->setCurrentBlock("prop_ta_c");
471  $ttpl->setVariable("COLS", $this->getCols());
472  $ttpl->parseCurrentBlock();
473  }
474  else
475  {
476  $ttpl->touchBlock("prop_ta_w");
477  }
478 
479  $ttpl->setCurrentBlock("prop_textarea");
480  $ttpl->setVariable("ROWS", $this->getRows());
481  }
482  if (!$this->getDisabled())
483  {
484  $ttpl->setVariable("POST_VAR",
485  $this->getPostVar());
486  }
487  $ttpl->setVariable("ID", $this->getFieldId());
488  if ($this->getDisabled())
489  {
490  $ttpl->setVariable('DISABLED','disabled="disabled" ');
491  }
492  $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
493  $ttpl->parseCurrentBlock();
494  }
495 
496  if ($this->getDisabled())
497  {
498  $ttpl->setVariable("HIDDEN_INPUT",
499  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
500  }
501 
502 
503  $a_tpl->setCurrentBlock("prop_generic");
504  $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
505  $a_tpl->parseCurrentBlock();
506 
507  }
508 
516  public function usePurifier($a_flag = null)
517  {
518  if(null === $a_flag)
519  {
520  return $this->usePurifier;
521  }
522 
523  $this->usePurifier = $a_flag;
524  return $this;
525  }
526 
535  {
536  $this->Purifier = $Purifier;
537  return $this;
538  }
539 
546  public function getPurifier()
547  {
548  return $this->Purifier;
549  }
550 
558  public function setRTERootBlockElement($a_root_block_element)
559  {
560  $this->root_block_element = $a_root_block_element;
561  return $this;
562  }
563 
570  public function getRTERootBlockElement()
571  {
573  }
574 
583  public function disableButtons($a_button)
584  {
585  if(is_array($a_button))
586  {
587  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
588  }
589  else
590  {
591  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
592  }
593 
594  return $this;
595  }
596 
605  public function getDisabledButtons($as_array = true)
606  {
607  if(!$as_array)
608  {
609  return implode(',', $this->disabled_buttons);
610  }
611  else
612  {
614  }
615  }
616 }