ILIAS  eassessment Revision 61809
 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 
53  protected $disabled_buttons = array();
54 
63  protected $usePurifier = false;
64 
73  protected $Purifier = null;
74 
82  protected $root_block_element = null;
83 
84  protected $rte_tag_set = array(
85  "standard" => array ("strong", "em", "u", "ol", "li", "ul", "p", "div",
86  "i", "b", "code", "sup", "sub", "pre", "strike", "gap"),
87  "extended" => array (
88  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
89  "h4","h5","h6","hr","li","ol","p",
90  "pre","span","strike","strong","sub","sup","u","ul",
91  "i", "b", "gap"),
92  "extended_img" => array (
93  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
94  "h4","h5","h6","hr","img","li","ol","p",
95  "pre","span","strike","strong","sub","sup","u","ul",
96  "i", "b", "gap"),
97  "extended_table" => 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","table","td",
101  "tr","u","ul", "i", "b", "gap"),
102  "extended_table_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","table","td",
106  "tr","u","ul", "i", "b", "gap"),
107  "full" => array (
108  "a","blockquote","br","cite","code","div","em","h1","h2","h3",
109  "h4","h5","h6","hr","img","li","ol","p",
110  "pre","span","strike","strong","sub","sup","table","td",
111  "tr","u","ul","ruby","rbc","rtc","rb","rt","rp", "i", "b", "gap"));
112 
113 
120  function __construct($a_title = "", $a_postvar = "")
121  {
122  parent::__construct($a_title, $a_postvar);
123  $this->setType("textarea");
124  $this->setRteTagSet("standard");
125  $this->plugins = array();
126  $this->removeplugins = array();
127  $this->buttons = array();
128  $this->rteSupport = array();
129  }
130 
136  function setValue($a_value)
137  {
138  $this->value = $a_value;
139  }
140 
146  function getValue()
147  {
148  return $this->value;
149  }
150 
156  function setCols($a_cols)
157  {
158  $this->cols = $a_cols;
159  }
160 
166  function getCols()
167  {
168  return $this->cols;
169  }
170 
176  function setRows($a_rows)
177  {
178  $this->rows = $a_rows;
179  }
180 
186  function getRows()
187  {
188  return $this->rows;
189  }
190 
196  function setUseRte($a_usert)
197  {
198  $this->usert = $a_usert;
199  }
200 
206  function getUseRte()
207  {
208  return $this->usert;
209  }
210 
216  function addPlugin($a_plugin)
217  {
218  $this->plugins[$a_plugin] = $a_plugin;
219  }
220 
226  function removePlugin($a_plugin)
227  {
228  $this->removeplugins[$a_plugin] = $a_plugin;
229  }
230 
236  function addButton($a_button)
237  {
238  $this->buttons[$a_button] = $a_button;
239  }
240 
246  function removeButton($a_button)
247  {
248  unset($this->buttons[$a_button]);
249  }
250 
258  function setRTESupport($obj_id, $obj_type, $module, $cfg_template = null)
259  {
260  $this->rteSupport = array("obj_id" => $obj_id, "obj_type" => $obj_type, "module" => $module, 'cfg_template' => $cfg_template);
261  }
262 
266  function removeRTESupport()
267  {
268  $this->rteSupport = array();
269  }
270 
276  function setRteTags($a_rtetags)
277  {
278  $this->rtetags = $a_rtetags;
279  }
280 
286  function getRteTags()
287  {
288  return $this->rtetags;
289  }
290 
297  function setRteTagSet($a_set_name)
298  {
299  $this->setRteTags($this->rte_tag_set[$a_set_name]);
300  }
301 
308  function getRteTagSet($a_set_name)
309  {
310  return $this->rte_tag_set[$a_set_name];
311  }
312 
313 
317  function getRteTagString()
318  {
319  $result = "";
320  foreach ($this->getRteTags() as $tag)
321  {
322  $result .= "<$tag>";
323  }
324  return $result;
325  }
326 
332  function setValueByArray($a_values)
333  {
334  $this->setValue($a_values[$this->getPostVar()]);
335  }
336 
342  function checkInput()
343  {
344  global $lng;
345  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
346 
347  if($this->usePurifier() && $this->getPurifier())
348  {
350  $_POST[$this->getPostVar()] = $this->getPurifier()->purify($_POST[$this->getPostVar()]);
351  }
352  else
353  {
354  $allowed = $this->getRteTagString();
355  if ($this->plugins["latex"] == "latex" && !is_int(strpos($allowed, "<span>")))
356  {
357  $allowed.= "<span>";
358  }
359  $_POST[$this->getPostVar()] = ($this->getUseRte())
360  ? ilUtil::stripSlashes($_POST[$this->getPostVar()], true, $allowed)
362  }
363 
364  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
365  {
366  $this->setAlert($lng->txt("msg_input_is_required"));
367 
368  return false;
369  }
370  return $this->checkSubItemsInput();
371  }
372 
378  function insert(&$a_tpl)
379  {
380  $ttpl = new ilTemplate("tpl.prop_textarea.html", true, true, "Services/Form");
381 
382  // disabled rte
383  if ($this->getUseRte() && $this->getDisabled())
384  {
385  $ttpl->setCurrentBlock("disabled_rte");
386  $ttpl->setVariable("DR_VAL", $this->getValue());
387  $ttpl->parseCurrentBlock();
388  }
389  else
390  {
391  if ($this->getUseRte())
392  {
393  include_once "./Services/RTE/classes/class.ilRTE.php";
394  $rtestring = ilRTE::_getRTEClassname();
395  include_once "./Services/RTE/classes/class.$rtestring.php";
396  $rte = new $rtestring();
397 
398  // @todo: Check this.
399  $rte->addPlugin("emotions");
400  foreach ($this->plugins as $plugin)
401  {
402  if (strlen($plugin))
403  {
404  $rte->addPlugin($plugin);
405  }
406  }
407  foreach ($this->removeplugins as $plugin)
408  {
409  if (strlen($plugin))
410  {
411  $rte->removePlugin($plugin);
412  }
413  }
414 
415  foreach ($this->buttons as $button)
416  {
417  if (strlen($button))
418  {
419  $rte->addButton($button);
420  }
421  }
422 
423  $rte->disableButtons($this->getDisabledButtons());
424 
425  if($this->getRTERootBlockElement() !== null)
426  {
427  $rte->setRTERootBlockElement($this->getRTERootBlockElement());
428  }
429 
430  if (count($this->rteSupport) >= 3)
431  {
432  $rte->addRTESupport($this->rteSupport["obj_id"], $this->rteSupport["obj_type"], $this->rteSupport["module"], false, $this->rteSupport['cfg_template']);
433  }
434  else
435  {
436  $rte->addCustomRTESupport(0, "", $this->getRteTags());
437  }
438 
439  $ttpl->touchBlock("prop_ta_w");
440  $ttpl->setCurrentBlock("prop_textarea");
441  $ttpl->setVariable("ROWS", $this->getRows());
442  }
443  else
444  {
445  $ttpl->touchBlock("no_rteditor");
446 
447  if ($this->getCols() > 5)
448  {
449  $ttpl->setCurrentBlock("prop_ta_c");
450  $ttpl->setVariable("COLS", $this->getCols());
451  $ttpl->parseCurrentBlock();
452  }
453  else
454  {
455  $ttpl->touchBlock("prop_ta_w");
456  }
457 
458  $ttpl->setCurrentBlock("prop_textarea");
459  $ttpl->setVariable("ROWS", $this->getRows());
460  }
461  if (!$this->getDisabled())
462  {
463  $ttpl->setVariable("POST_VAR",
464  $this->getPostVar());
465  }
466  $ttpl->setVariable("ID", $this->getFieldId());
467  if ($this->getDisabled())
468  {
469  $ttpl->setVariable('DISABLED','disabled="disabled" ');
470  }
471  $ttpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
472  $ttpl->parseCurrentBlock();
473  }
474 
475  if ($this->getDisabled())
476  {
477  $ttpl->setVariable("HIDDEN_INPUT",
478  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
479  }
480 
481 
482  $a_tpl->setCurrentBlock("prop_generic");
483  $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
484  $a_tpl->parseCurrentBlock();
485 
486  }
487 
495  public function usePurifier($a_flag = null)
496  {
497  if(null === $a_flag)
498  {
499  return $this->usePurifier;
500  }
501 
502  $this->usePurifier = $a_flag;
503  return $this;
504  }
505 
514  {
515  $this->Purifier = $Purifier;
516  return $this;
517  }
518 
525  public function getPurifier()
526  {
527  return $this->Purifier;
528  }
529 
537  public function setRTERootBlockElement($a_root_block_element)
538  {
539  $this->root_block_element = $a_root_block_element;
540  return $this;
541  }
542 
549  public function getRTERootBlockElement()
550  {
552  }
553 
562  public function disableButtons($a_button)
563  {
564  if(is_array($a_button))
565  {
566  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
567  }
568  else
569  {
570  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
571  }
572 
573  return $this;
574  }
575 
584  public function getDisabledButtons($as_array = true)
585  {
586  if(!$as_array)
587  {
588  return implode(',', $this->disabled_buttons);
589  }
590  else
591  {
593  }
594  }
595 }