ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilPageContentGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/COPage/classes/class.ilPageContent.php");
5 
15 {
17  var $ilias;
18  var $tpl;
19  var $lng;
20  var $ctrl;
21  var $pg_obj;
22  var $hier_id;
23  var $dom;
24  var $updated;
27  var $page_config = null;
28 
32  protected $log;
33 
34  static $style_selector_reset = "margin-top:2px; margin-bottom:2px; text-indent:0px; position:static; float:none; width: auto;";
35 
36  // common bb buttons (special ones are iln and wln)
37  protected static $common_bb_buttons = array(
38  "str" => "Strong", "emp" => "Emph", "imp" => "Important",
39  "sup" => "Sup", "sub" => "Sub",
40  "com" => "Comment",
41  "quot" => "Quotation", "acc" => "Accent", "code" => "Code", "tex" => "Tex",
42  "fn" => "Footnote", "xln" => "ExternalLink"
43  );
44 
49  function ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id = 0, $a_pc_id = "")
50  {
51  global $ilias, $tpl, $lng, $ilCtrl;
52 
53  $this->log = ilLoggerFactory::getLogger('copg');
54 
55  $this->ilias = $ilias;
56  $this->tpl = $tpl;
57  $this->lng = $lng;
58  $this->pg_obj = $a_pg_obj;
59  $this->ctrl = $ilCtrl;
60  $this->content_obj = $a_content_obj;
61 
62  if($a_hier_id !== 0)
63  {
64  $this->hier_id = $a_hier_id;
65  $this->pc_id = $a_pc_id;
66 //echo "-".$this->pc_id."-";
67  $this->dom = $a_pg_obj->getDom();
68  }
69  }
70 
76  function setContentObject($a_val)
77  {
78  $this->content_obj = $a_val;
79  }
80 
86  function getContentObject()
87  {
88  return $this->content_obj;
89  }
90 
96  function setPage($a_val)
97  {
98  $this->pg_obj = $a_val;
99  }
100 
106  function getPage()
107  {
108  return $this->pg_obj;
109  }
110 
116  function setPageConfig($a_val)
117  {
118  $this->page_config = $a_val;
119  }
120 
126  function getPageConfig()
127  {
128  return $this->page_config;
129  }
130 
134  static function _getCommonBBButtons()
135  {
136  return self::$common_bb_buttons;
137  }
138 
139  // scorm2004-start
145  function setStyleId($a_styleid)
146  {
147  $this->styleid = $a_styleid;
148  }
149 
155  function getStyleId()
156  {
157  return $this->styleid;
158  }
159 
163  function getStyle()
164  {
165  if ((!is_object($this->style) || $this->getStyleId() != $this->style->getId()) && $this->getStyleId() > 0)
166  {
167  if (ilObject::_lookupType($this->getStyleId()) == "sty")
168  {
169  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
170  $this->style = new ilObjStyleSheet($this->getStyleId());
171  }
172  }
173 
174  return $this->style;
175  }
176 
180  protected function getCharacteristicsOfCurrentStyle($a_type)
181  {
182  if ($this->getStyleId() > 0 &&
183  ilObject::_lookupType($this->getStyleId()) == "sty")
184  {
185  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
186  $style = new ilObjStyleSheet($this->getStyleId());
187  $chars = array();
188  if (!is_array($a_type))
189  {
190  $a_type = array($a_type);
191  }
192  foreach ($a_type as $at)
193  {
194  $chars = array_merge($chars, $style->getCharacteristics($at, true));
195  }
196  $new_chars = array();
197  if (is_array($chars))
198  {
199  foreach ($chars as $char)
200  {
201  if ($this->chars[$char] != "") // keep lang vars for standard chars
202  {
203  $new_chars[$char] = $this->chars[$char];
204  }
205  else
206  {
207  $new_chars[$char] = $char;
208  }
209  asort($new_chars);
210  }
211  }
212  $this->setCharacteristics($new_chars);
213  }
214  }
215 
219  function setCharacteristics($a_chars)
220  {
221  $this->chars = $a_chars;
222  }
223 
228  {
229  return $this->chars ? $this->chars : array();
230  }
231  // scorm2004-end
232 
233 
237  function getHierId()
238  {
239  return $this->hier_id;
240  }
241 
245  function setHierId($a_hier_id)
246  {
247  $this->hier_id = $a_hier_id;
248  }
249 
253  function getBBMenu($a_ta_name = "par_content")
254  {
255  global $lng, $ilCtrl;
256 
257  include_once("./Services/COPage/classes/class.ilPageEditorSettings.php");
258 
259  $btpl = new ilTemplate("tpl.bb_menu.html", true, true, "Services/COPage");
260 
261  // not nice, should be set by context per method
262  //if ($this->pg_obj->getParentType() == "gdf" ||
263  // $this->pg_obj->getParentType() == "lm" ||
264  // $this->pg_obj->getParentType() == "dbk")
265  if ($this->getPageConfig()->getEnableInternalLinks())
266  {
267  $btpl->setCurrentBlock("bb_ilink_button");
268  $btpl->setVariable("BB_LINK_ILINK",
269  $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
270  $btpl->parseCurrentBlock();
271 
272  // add int link parts
273  include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
274  $btpl->setCurrentBlock("int_link_prep");
275  $btpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
276  $ilCtrl->getLinkTargetByClass(array("ilpageeditorgui", "ilinternallinkgui"),
277  "", false, true, false), true));
278  $btpl->parseCurrentBlock();
279 
280  }
281 
282  if ($this->getPageConfig()->getEnableKeywords())
283  {
284  $btpl->touchBlock("bb_kw_button");
285  $btpl->setVariable("TXT_KW", $this->lng->txt("cont_text_keyword"));
286  }
287  if ($this->pg_obj->getParentType() == "wpg")
288  {
289  $btpl->setCurrentBlock("bb_wikilink_button2");
290  $btpl->setVariable("TXT_WIKI_BUTTON2", $lng->txt("obj_wiki"));
291  $btpl->setVariable("WIKI_BUTTON2_URL", $ilCtrl->getLinkTargetByClass("ilwikipagegui", ""));
292  $btpl->parseCurrentBlock();
293 
294  $btpl->setCurrentBlock("bb_wikilink_button");
295  $btpl->setVariable("TXT_WLN2", $lng->txt("wiki_wiki_page"));
296  $btpl->parseCurrentBlock();
297  }
298  $mathJaxSetting = new ilSetting("MathJax");
299  $style = $this->getStyle();
300 //echo URL_TO_LATEX;
301  foreach (self::$common_bb_buttons as $c => $st)
302  {
303  if (ilPageEditorSettings::lookupSettingByParentType($this->pg_obj->getParentType(), "active_".$c, true))
304  {
305  if ($c != "tex" || $mathJaxSetting->get("enable") || defined("URL_TO_LATEX"))
306  {
307  $btpl->touchBlock("bb_".$c."_button");
308  $btpl->setVariable("TXT_".strtoupper($c), $this->lng->txt("cont_text_".$c));
309  }
310  }
311  }
312 
313  if ($this->getPageConfig()->getEnableAnchors())
314  {
315  $btpl->touchBlock("bb_anc_button");
316  $btpl->setVariable("TXT_ANC", $lng->txt("cont_anchor").":");
317  }
318 
319  // footnote
320 // $btpl->setVariable("TXT_FN", $this->lng->txt("cont_text_fn"));
321 
322 // $btpl->setVariable("TXT_CODE", $this->lng->txt("cont_text_code"));
323  $btpl->setVariable("TXT_ILN", $this->lng->txt("cont_text_iln"));
324 // $btpl->setVariable("TXT_XLN", $this->lng->txt("cont_text_xln"));
325 // $btpl->setVariable("TXT_TEX", $this->lng->txt("cont_text_tex"));
326  $btpl->setVariable("TXT_BB_TIP", $this->lng->txt("cont_bb_tip"));
327  $btpl->setVariable("TXT_WLN", $lng->txt("wiki_wiki_page"));
328 
329  $btpl->setVariable("PAR_TA_NAME", $a_ta_name);
330 
331  return $btpl->get();
332  }
333 
337  function delete()
338  {
339  $updated = $this->pg_obj->deleteContent($this->hier_id);
340  if($updated !== true)
341  {
342  $_SESSION["il_pg_error"] = $updated;
343  }
344  else
345  {
346  unset($_SESSION["il_pg_error"]);
347  }
348  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
349  }
350 
354  function moveAfter()
355  {
356  // check if a target is selected
357  if(!isset($_POST["target"]))
358  {
359  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
360  }
361 
362  // check if only one target is selected
363  if(count($_POST["target"]) > 1)
364  {
365  $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
366  }
367 
368  $a_hid = explode(":", $_POST["target"][0]);
369 //echo "-".$a_hid[0]."-".$a_hid[1]."-";
370 
371  // check if target is within source
372  if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
373  {
374  $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
375  }
376 
377  // check whether target is allowed
378  $curr_node =& $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
379  if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
380  {
381  $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
382  }
383 
384  // strip "c" "r" of table ids from hierarchical id
385  $first_hier_character = substr($a_hid[0], 0, 1);
386  if ($first_hier_character == "c" ||
387  $first_hier_character == "r" ||
388  $first_hier_character == "i")
389  {
390  $a_hid[0] = substr($a_hid[0], 1);
391  }
392 
393  // move
394  $updated = $this->pg_obj->moveContentAfter($this->hier_id, $a_hid[0],
395  $this->content_obj->getPcId(), $a_hid[1]);
396  if($updated !== true)
397  {
398  $_SESSION["il_pg_error"] = $updated;
399  }
400  else
401  {
402  unset($_SESSION["il_pg_error"]);
403  }
404 
405  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
406  }
407 
411  function moveBefore()
412  {
413  // check if a target is selected
414  if(!isset($_POST["target"]))
415  {
416  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
417  }
418 
419  // check if target is within source
420  if(count($_POST["target"]) > 1)
421  {
422  $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
423  }
424 
425  $a_hid = explode(":", $_POST["target"][0]);
426 
427  // check if target is within source
428  if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
429  {
430  $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
431  }
432 
433  // check whether target is allowed
434  $curr_node =& $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
435  if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
436  {
437  $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
438  }
439 
440  // strip "c" "r" of table ids from hierarchical id
441  $first_hier_character = substr($a_hid[0], 0, 1);
442  if ($first_hier_character == "c" ||
443  $first_hier_character == "r" ||
444  $first_hier_character == "i")
445  {
446  $a_hid[0] = substr($a_hid[0], 1);
447  }
448 
449  // move
450  $updated = $this->pg_obj->moveContentBefore($this->hier_id, $a_hid[0],
451  $this->content_obj->getPcId(), $a_hid[1]);
452  if($updated !== true)
453  {
454  $_SESSION["il_pg_error"] = $updated;
455  }
456  else
457  {
458  unset($_SESSION["il_pg_error"]);
459  }
460  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
461  }
462 
463 
467  function splitPage()
468  {
469  global $ilErr;
470 
471  if ($this->pg_obj->getParentType() != "lm" &&
472  $this->pg_obj->getParentType() != "dbk")
473  {
474  $ilErr->raiseError("Split method called for wrong parent type (".
475  $this->pg_obj->getParentType().")", $ilErr->FATAL);
476  }
477  else
478  {
479  $lm_page =& ilLMPageObject::_splitPage($this->pg_obj->getId(),
480  $this->pg_obj->getParentType(), $this->hier_id);
481 
482  // jump to new page
483  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $lm_page->getId());
484  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
485  }
486 
487  $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
488  }
489 
493  function splitPageNext()
494  {
495  global $ilErr;
496 
497  if ($this->pg_obj->getParentType() != "lm" &&
498  $this->pg_obj->getParentType() != "dbk")
499  {
500  $ilErr->raiseError("Split method called for wrong parent type (".
501  $this->pg_obj->getParentType().")", $ilErr->FATAL);
502  }
503  else
504  {
505  $succ_id = ilLMPageObject::_splitPageNext($this->pg_obj->getId(),
506  $this->pg_obj->getParentType(), $this->hier_id);
507 
508  // jump to successor page
509  if ($succ_id > 0)
510  {
511  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $succ_id);
512  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
513  }
514 
515  }
516  $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
517  }
518 
523  {
524  if(is_array($this->updated))
525  {
526  $error_str = "<b>Error(s):</b><br>";
527  foreach ($this->updated as $error)
528  {
529  $err_mess = implode($error, " - ");
530  if (!is_int(strpos($err_mess, ":0:")))
531  {
532  $error_str .= htmlentities($err_mess)."<br />";
533  }
534  }
535  ilUtil::sendFailure($error_str);
536  }
537  else if($this->updated != "" && $this->updated !== true)
538  {
539  ilUtil::sendFailure("<b>Error(s):</b><br />".
540  $this->updated);
541  }
542  }
543 
547  function cancelCreate()
548  {
549  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
550  }
551 
555  function cancelUpdate()
556  {
557  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
558  }
559 
563  function cancel()
564  {
565  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
566  }
567 
572  function deactivate()
573  {
574  $obj = & $this->content_obj;
575 
576  if ($obj->isEnabled ())
577  $obj->disable ();
578  else
579  $obj->enable ();
580 
581  $updated = $this->pg_obj->update($this->hier_id);
582  if($updated !== true)
583  {
584  $_SESSION["il_pg_error"] = $updated;
585  }
586  else
587  {
588  unset($_SESSION["il_pg_error"]);
589  }
590 
591  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
592  }
593 
597  function cut()
598  {
599  global $lng;
600 
601  $obj = $this->content_obj;
602 
603  $updated = $this->pg_obj->cutContents(array($this->hier_id.":".$this->pc_id));
604  if($updated !== true)
605  {
606  $_SESSION["il_pg_error"] = $updated;
607  }
608  else
609  {
610  unset($_SESSION["il_pg_error"]);
611  }
612 
613  ilUtil::sendSuccess($lng->txt("cont_sel_el_cut_use_paste"), true);
614  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
615  }
616 
620  function copy()
621  {
622  global $lng;
623 
624  $obj = $this->content_obj;
625 
626  ilUtil::sendSuccess($lng->txt("cont_sel_el_copied_use_paste"), true);
627  $this->pg_obj->copyContents(array($this->hier_id.":".$this->pc_id));
628 
629  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
630  }
631 
632 
636  function getTemplateOptions($a_type)
637  {
638  $style = $this->getStyle();
639 
640  if (is_object($style))
641  {
642  $ts = $style->getTemplates($a_type);
643  $options = array();
644  foreach ($ts as $t)
645  {
646  $options["t:".$t["id"].":".$t["name"]] = $t["name"];
647  }
648  return $options;
649  }
650  return array();
651  }
652 
653 }
654 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
setContentObject($a_val)
Set content object.
ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id=0, $a_pc_id="")
Constructor public.
ILIAS Setting Class.
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
$style
Definition: example_012.php:70
deactivate()
gui function set enabled if is not enabled and vice versa
$_POST['username']
Definition: cron.php:12
$_SESSION["AccountId"]
splitPage()
split page to new page at specified position
if(strpos($jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:34
getStyle()
Get style object.
getHierId()
get hierarchical id in dom object
"color:#CC0000 style
Definition: example_001.php:92
setPageConfig($a_val)
Set Page Config.
getTemplateOptions($a_type)
Get table templates.
getPageConfig()
Get Page Config.
cancelCreate()
cancel creating page content
cancelUpdate()
cancel update
splitPageNext()
split page to next page at specified position
getContentObject()
Get content object.
global $ilCtrl
Definition: ilias.php:18
_splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
split page to next page at hierarchical id
setCharacteristics($a_chars)
Set Characteristics.
getBBMenu($a_ta_name="par_content")
Get the bb menu incl.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
setPage($a_val)
Set page.
if(!is_array($argv)) $options
moveAfter()
move content element after another element
special template class to simplify handling of ITX/PEAR
displayValidationError()
display validation errors
getStyleId()
Get Style Id.
moveBefore()
move content element before another element
redirection script todo: (a better solution should control the processing via a xml file) ...
getCharacteristics()
Get characteristics.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static lookupSettingByParentType($a_par_type, $a_name, $a_default=false)
Lookup setting by parent type.
static _getCommonBBButtons()
Get common bb buttons.
Class ilObjStyleSheet.
static getLogger($a_component_id)
Get component logger.
setStyleId($a_styleid)
Set Style Id.
copy()
Copy single element.
getInitHTML($a_url, $a_move_to_body=false)
Get initialisation HTML to use interna link editing.
_splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
split page at hierarchical id
setHierId($a_hier_id)
get hierarchical id in dom object
cut()
Cut single element.