ILIAS  release_4-3 Revision
 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 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 
55  protected $disabled_buttons = array();
56 
65  protected $usePurifier = false;
66 
75  protected $Purifier = null;
76 
84  protected $root_block_element = null;
85 
86  protected $rte_tag_set = array(
87  "standard" => array ("strong", "em", "u", "ol", "li", "ul", "p", "div",
88  "i", "b", "code", "sup", "sub", "pre", "strike", "gap"),
89  "extended" => array (
90  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
91  "h4","h5","h6","hr","li","ol","p",
92  "pre","span","strike","strong","sub","sup","u","ul",
93  "i", "b", "gap"),
94  "extended_img" => array (
95  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
96  "h4","h5","h6","hr","img","li","ol","p",
97  "pre","span","strike","strong","sub","sup","u","ul",
98  "i", "b", "gap"),
99  "extended_table" => array (
100  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
101  "h4","h5","h6","hr","li","ol","p",
102  "pre","span","strike","strong","sub","sup","table","td",
103  "tr","u","ul", "i", "b", "gap"),
104  "extended_table_img" => array (
105  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
106  "h4","h5","h6","hr","img","li","ol","p",
107  "pre","span","strike","strong","sub","sup","table","td",
108  "tr","u","ul", "i", "b", "gap"),
109  "full" => array (
110  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
111  "h4","h5","h6","hr","img","li","ol","p",
112  "pre","span","strike","strong","sub","sup","table","td",
113  "tr","u","ul","ruby","rbc","rtc","rb","rt","rp", "i", "b", "gap"));
114 
115 
122  function __construct($a_title = "", $a_postvar = "")
123  {
124  parent::__construct($a_title, $a_postvar);
125  $this->setType("textarea");
126  $this->setRteTagSet("standard");
127  $this->plugins = array();
128  $this->removeplugins = array();
129  $this->buttons = array();
130  $this->rteSupport = array();
131  }
132 
138  function setValue($a_value)
139  {
140  $this->value = $a_value;
141  }
142 
148  function getValue()
149  {
150  return $this->value;
151  }
152 
158  function setCols($a_cols)
159  {
160  $this->cols = $a_cols;
161  }
162 
168  function getCols()
169  {
170  return $this->cols;
171  }
172 
178  function setRows($a_rows)
179  {
180  $this->rows = $a_rows;
181  }
182 
188  function getRows()
189  {
190  return $this->rows;
191  }
192 
199  public function setUseRte($a_usert, $version = '')
200  {
201  $this->usert = $a_usert;
202 
203  if(strlen($version))
204  {
205  $this->rteSupport['version'] = $version;
206  }
207  }
208 
214  function getUseRte()
215  {
216  return $this->usert;
217  }
218 
224  function addPlugin($a_plugin)
225  {
226  $this->plugins[$a_plugin] = $a_plugin;
227  }
228 
234  function removePlugin($a_plugin)
235  {
236  $this->removeplugins[$a_plugin] = $a_plugin;
237  }
238 
244  function addButton($a_button)
245  {
246  $this->buttons[$a_button] = $a_button;
247  }
248 
254  function removeButton($a_button)
255  {
256  unset($this->buttons[$a_button]);
257  }
258 
266  function setRTESupport($obj_id, $obj_type, $module, $cfg_template = null, $hide_switch = false, $version = null)
267  {
268  $this->rteSupport = array("obj_id" => $obj_id, "obj_type" => $obj_type, "module" => $module, 'cfg_template' => $cfg_template, 'hide_switch' => $hide_switch, 'version' => $version);
269  }
270 
274  function removeRTESupport()
275  {
276  $this->rteSupport = array();
277  }
278 
284  function setRteTags($a_rtetags)
285  {
286  $this->rtetags = $a_rtetags;
287  }
288 
294  function getRteTags()
295  {
296  return $this->rtetags;
297  }
298 
305  function setRteTagSet($a_set_name)
306  {
307  $this->setRteTags($this->rte_tag_set[$a_set_name]);
308  }
309 
316  function getRteTagSet($a_set_name)
317  {
318  return $this->rte_tag_set[$a_set_name];
319  }
320 
321 
325  function getRteTagString()
326  {
327  $result = "";
328  foreach ($this->getRteTags() as $tag)
329  {
330  $result .= "<$tag>";
331  }
332  return $result;
333  }
334 
340  function setUseTagsForRteOnly($a_val)
341  {
342  $this->use_tags_for_rte_only = $a_val;
343  }
344 
351  {
353  }
354 
360  function setValueByArray($a_values)
361  {
362  $this->setValue($a_values[$this->getPostVar()]);
363 
364  foreach($this->getSubItems() as $item)
365  {
366  $item->setValueByArray($a_values);
367  }
368  }
369 
375  function checkInput()
376  {
377  global $lng;
378  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
379 
380  if($this->usePurifier() && $this->getPurifier())
381  {
383  $_POST[$this->getPostVar()] = $this->getPurifier()->purify($_POST[$this->getPostVar()]);
384  }
385  else
386  {
387  $allowed = $this->getRteTagString();
388  if ($this->plugins["latex"] == "latex" && !is_int(strpos($allowed, "<span>")))
389  {
390  $allowed.= "<span>";
391  }
392  $_POST[$this->getPostVar()] = ($this->getUseRte() || !$this->getUseTagsForRteOnly())
393  ? ilUtil::stripSlashes($_POST[$this->getPostVar()], true, $allowed)
395  }
396 
397  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
398  {
399  $this->setAlert($lng->txt("msg_input_is_required"));
400 
401  return false;
402  }
403  return $this->checkSubItemsInput();
404  }
405 
411  function insert(&$a_tpl)
412  {
413  $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
414 
415  // disabled rte
416  if ($this->getUseRte() && $this->getDisabled())
417  {
418  $ttpl->setCurrentBlock("disabled_rte");
419  $ttpl->setVariable("DR_VAL", $this->getValue());
420  $ttpl->parseCurrentBlock();
421  }
422  else
423  {
424  if ($this->getUseRte())
425  {
426  $rtestring = ilRTE::_getRTEClassname();
427  include_once "./Services/RTE/classes/class.$rtestring.php";
428  $rte = new $rtestring($this->rteSupport['version']);
429 
430  // @todo: Check this.
431  $rte->addPlugin("emotions");
432  foreach ($this->plugins as $plugin)
433  {
434  if (strlen($plugin))
435  {
436  $rte->addPlugin($plugin);
437  }
438  }
439  foreach ($this->removeplugins as $plugin)
440  {
441  if (strlen($plugin))
442  {
443  $rte->removePlugin($plugin);
444  }
445  }
446 
447  foreach ($this->buttons as $button)
448  {
449  if (strlen($button))
450  {
451  $rte->addButton($button);
452  }
453  }
454 
455  $rte->disableButtons($this->getDisabledButtons());
456 
457  if($this->getRTERootBlockElement() !== null)
458  {
459  $rte->setRTERootBlockElement($this->getRTERootBlockElement());
460  }
461 
462  if (count($this->rteSupport) >= 3)
463  {
464  $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template'], $this->rteSupport['hide_switch']);
465  }
466  else
467  {
468  $rte->addCustomRTESupport(0, "", $this->getRteTags());
469  }
470 
471  $ttpl->touchBlock("prop_ta_w");
472  $ttpl->setCurrentBlock("prop_textarea");
473  $ttpl->setVariable("ROWS", $this->getRows());
474  }
475  else
476  {
477  $ttpl->touchBlock("no_rteditor");
478 
479  if ($this->getCols() > 5)
480  {
481  $ttpl->setCurrentBlock("prop_ta_c");
482  $ttpl->setVariable("COLS", $this->getCols());
483  $ttpl->parseCurrentBlock();
484  }
485  else
486  {
487  $ttpl->touchBlock("prop_ta_w");
488  }
489 
490  $ttpl->setCurrentBlock("prop_textarea");
491  $ttpl->setVariable("ROWS", $this->getRows());
492  }
493  if (!$this->getDisabled())
494  {
495  $ttpl->setVariable("POST_VAR",
496  $this->getPostVar());
497  }
498  $ttpl->setVariable("ID", $this->getFieldId());
499  if ($this->getDisabled())
500  {
501  $ttpl->setVariable('DISABLED','disabled="disabled" ');
502  }
503  $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
504  $ttpl->parseCurrentBlock();
505  }
506 
507  if ($this->getDisabled())
508  {
509  $ttpl->setVariable("HIDDEN_INPUT",
510  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
511  }
512 
513 
514  $a_tpl->setCurrentBlock("prop_generic");
515  $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
516  $a_tpl->parseCurrentBlock();
517 
518  }
519 
527  public function usePurifier($a_flag = null)
528  {
529  if(null === $a_flag)
530  {
531  return $this->usePurifier;
532  }
533 
534  $this->usePurifier = $a_flag;
535  return $this;
536  }
537 
546  {
547  $this->Purifier = $Purifier;
548  return $this;
549  }
550 
557  public function getPurifier()
558  {
559  return $this->Purifier;
560  }
561 
569  public function setRTERootBlockElement($a_root_block_element)
570  {
571  $this->root_block_element = $a_root_block_element;
572  return $this;
573  }
574 
581  public function getRTERootBlockElement()
582  {
584  }
585 
594  public function disableButtons($a_button)
595  {
596  if(is_array($a_button))
597  {
598  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
599  }
600  else
601  {
602  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
603  }
604 
605  return $this;
606  }
607 
616  public function getDisabledButtons($as_array = true)
617  {
618  if(!$as_array)
619  {
620  return implode(',', $this->disabled_buttons);
621  }
622  else
623  {
625  }
626  }
627 }