ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4require_once("./Services/COPage/classes/class.ilPageContent.php");
5
15{
19 protected $error;
20
22 public $tpl;
23 public $lng;
24
28 public $ctrl;
29 public $pg_obj;
30 public $hier_id;
31 public $dom;
32 public $updated;
35 public $page_config = null;
36
40 protected $log;
41
42 public static $style_selector_reset = "margin-top:2px; margin-bottom:2px; text-indent:0px; position:static; float:none; width: auto;";
43
44 // common bb buttons (special ones are iln and wln)
45 protected static $common_bb_buttons = array(
46 "str" => "Strong", "emp" => "Emph", "imp" => "Important",
47 "sup" => "Sup", "sub" => "Sub",
48 "com" => "Comment",
49 "quot" => "Quotation", "acc" => "Accent", "code" => "Code", "tex" => "Tex",
50 "fn" => "Footnote", "xln" => "ExternalLink"
51 );
52
57 public function __construct($a_pg_obj, $a_content_obj, $a_hier_id = 0, $a_pc_id = "")
58 {
59 global $DIC;
60
61 $this->error = $DIC["ilErr"];
62 $tpl = $DIC["tpl"];
63 $lng = $DIC->language();
64 $ilCtrl = $DIC->ctrl();
65
66 $this->log = ilLoggerFactory::getLogger('copg');
67
68 $this->tpl = $tpl;
69 $this->lng = $lng;
70 $this->pg_obj = $a_pg_obj;
71 $this->ctrl = $ilCtrl;
72 $this->content_obj = $a_content_obj;
73
74 if ($a_hier_id !== 0) {
75 $this->hier_id = $a_hier_id;
76 $this->pc_id = $a_pc_id;
77 //echo "-".$this->pc_id."-";
78 $this->dom = $a_pg_obj->getDom();
79 }
80 }
81
87 public function setContentObject($a_val)
88 {
89 $this->content_obj = $a_val;
90 }
91
97 public function getContentObject()
98 {
99 return $this->content_obj;
100 }
101
107 public function setPage($a_val)
108 {
109 $this->pg_obj = $a_val;
110 }
111
117 public function getPage()
118 {
119 return $this->pg_obj;
120 }
121
127 public function setPageConfig($a_val)
128 {
129 $this->page_config = $a_val;
130 }
131
137 public function getPageConfig()
138 {
139 return $this->page_config;
140 }
141
145 public static function _getCommonBBButtons()
146 {
148 }
149
150 // scorm2004-start
156 public function setStyleId($a_styleid)
157 {
158 $this->styleid = $a_styleid;
159 }
160
166 public function getStyleId()
167 {
168 return $this->styleid;
169 }
170
174 public function getStyle()
175 {
176 if ((!is_object($this->style) || $this->getStyleId() != $this->style->getId()) && $this->getStyleId() > 0) {
177 if (ilObject::_lookupType($this->getStyleId()) == "sty") {
178 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
179 $this->style = new ilObjStyleSheet($this->getStyleId());
180 }
181 }
182
183 return $this->style;
184 }
185
189 public function getCharacteristicsOfCurrentStyle($a_type)
190 {
191 if ($this->getStyleId() > 0 &&
192 ilObject::_lookupType($this->getStyleId()) == "sty") {
193 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
194 $style = new ilObjStyleSheet($this->getStyleId());
195 $chars = array();
196 if (!is_array($a_type)) {
197 $a_type = array($a_type);
198 }
199 foreach ($a_type as $at) {
200 $chars = array_merge($chars, $style->getCharacteristics($at, true));
201 }
202 $new_chars = array();
203 if (is_array($chars)) {
204 foreach ($chars as $char) {
205 if ($this->chars[$char] != "") { // keep lang vars for standard chars
206 $new_chars[$char] = $this->chars[$char];
207 } else {
208 $new_chars[$char] = $char;
209 }
210 asort($new_chars);
211 }
212 }
213 $this->setCharacteristics($new_chars);
214 }
215 }
216
220 public function setCharacteristics($a_chars)
221 {
222 $this->chars = $a_chars;
223 }
224
228 public function getCharacteristics()
229 {
230 return $this->chars ? $this->chars : array();
231 }
232 // scorm2004-end
233
234
238 public function getHierId()
239 {
240 return $this->hier_id;
241 }
242
246 public function setHierId($a_hier_id)
247 {
248 $this->hier_id = $a_hier_id;
249 }
250
254 public function getBBMenu($a_ta_name = "par_content")
255 {
257 $ilCtrl = $this->ctrl;
258
259 include_once("./Services/COPage/classes/class.ilPageEditorSettings.php");
260
261 $btpl = new ilTemplate("tpl.bb_menu.html", true, true, "Services/COPage");
262
263 // not nice, should be set by context per method
264 if ($this->getPageConfig()->getEnableInternalLinks()) {
265 $btpl->setCurrentBlock("bb_ilink_button");
266 $btpl->setVariable(
267 "BB_LINK_ILINK",
268 $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp")
269 );
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(
277 array("ilpageeditorgui", "ilinternallinkgui"),
278 "",
279 false,
280 true,
281 false
282 ),
283 true
284 ));
285 $btpl->parseCurrentBlock();
286 }
287
288 if ($this->getPageConfig()->getEnableKeywords()) {
289 $btpl->touchBlock("bb_kw_button");
290 $btpl->setVariable("TXT_KW", $this->lng->txt("cont_text_keyword"));
291 }
292 if ($this->pg_obj->getParentType() == "wpg") {
293 $btpl->setCurrentBlock("bb_wikilink_button2");
294 $btpl->setVariable("TXT_WIKI_BUTTON2", $lng->txt("obj_wiki"));
295 $btpl->setVariable("WIKI_BUTTON2_URL", $ilCtrl->getLinkTargetByClass("ilwikipagegui", ""));
296 $btpl->parseCurrentBlock();
297
298 $btpl->setCurrentBlock("bb_wikilink_button");
299 $btpl->setVariable("TXT_WLN2", $lng->txt("wiki_wiki_page"));
300 $btpl->parseCurrentBlock();
301 }
302 $mathJaxSetting = new ilSetting("MathJax");
303 $style = $this->getStyle();
304 //echo URL_TO_LATEX;
305 foreach (self::$common_bb_buttons as $c => $st) {
306 if (ilPageEditorSettings::lookupSettingByParentType($this->pg_obj->getParentType(), "active_" . $c, true)) {
307 if ($c != "tex" || $mathJaxSetting->get("enable") || defined("URL_TO_LATEX")) {
308 if (!in_array($c, array("acc", "com", "quot", "code"))) {
309 $btpl->touchBlock("bb_" . $c . "_button");
310 $btpl->setVariable("TXT_" . strtoupper($c), $this->lng->txt("cont_text_" . $c));
311 $lng->toJS("cont_text_" . $c);
312 }
313 }
314 }
315 }
316
317 if ($this->getPageConfig()->getEnableAnchors()) {
318 $btpl->touchBlock("bb_anc_button");
319 $btpl->setVariable("TXT_ANC", $lng->txt("cont_anchor") . ":");
320 $lng->toJS("cont_anchor");
321 }
322
323 include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
324 $btpl->setVariable("CHAR_STYLE_SELECT", ilPCParagraphGUI::getCharStyleSelector($this->pg_obj->getParentType(), "il.COPageBB.setCharacterClass", $this->getStyleId()));
325
326 // footnote
327 // $btpl->setVariable("TXT_FN", $this->lng->txt("cont_text_fn"));
328
329 // $btpl->setVariable("TXT_CODE", $this->lng->txt("cont_text_code"));
330 $btpl->setVariable("TXT_ILN", $this->lng->txt("cont_text_iln_link"));
331 $lng->toJS("cont_text_iln");
332 // $btpl->setVariable("TXT_XLN", $this->lng->txt("cont_text_xln"));
333 // $btpl->setVariable("TXT_TEX", $this->lng->txt("cont_text_tex"));
334 $btpl->setVariable("TXT_BB_TIP", $this->lng->txt("cont_bb_tip"));
335 $btpl->setVariable("TXT_WLN", $lng->txt("wiki_wiki_page"));
336 $lng->toJS("wiki_wiki_page");
337
338 $btpl->setVariable("PAR_TA_NAME", $a_ta_name);
339
340 return $btpl->get();
341 }
342
346 public function delete()
347 {
348 $updated = $this->pg_obj->deleteContent($this->hier_id);
349 if ($updated !== true) {
350 $_SESSION["il_pg_error"] = $updated;
351 } else {
352 unset($_SESSION["il_pg_error"]);
353 }
354 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
355 }
356
360 public function moveAfter()
361 {
363
364 // check if a target is selected
365 if (!isset($_POST["target"])) {
366 $ilErr->raiseError($this->lng->txt("no_checkbox"), $ilErr->MESSAGE);
367 }
368
369 // check if only one target is selected
370 if (count($_POST["target"]) > 1) {
371 $ilErr->raiseError($this->lng->txt("only_one_target"), $ilErr->MESSAGE);
372 }
373
374 $a_hid = explode(":", $_POST["target"][0]);
375 //echo "-".$a_hid[0]."-".$a_hid[1]."-";
376
377 // check if target is within source
378 if ($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id))) {
379 $ilErr->raiseError($this->lng->txt("cont_target_within_source"), $ilErr->MESSAGE);
380 }
381
382 // check whether target is allowed
383 $curr_node = $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
384 if (is_object($curr_node) && $curr_node->node_name() == "FileItem") {
385 $ilErr->raiseError($this->lng->txt("cont_operation_not_allowed"), $ilErr->MESSAGE);
386 }
387
388 // strip "c" "r" of table ids from hierarchical id
389 $first_hier_character = substr($a_hid[0], 0, 1);
390 if ($first_hier_character == "c" ||
391 $first_hier_character == "r" ||
392 $first_hier_character == "i") {
393 $a_hid[0] = substr($a_hid[0], 1);
394 }
395
396 // move
397 $updated = $this->pg_obj->moveContentAfter(
398 $this->hier_id,
399 $a_hid[0],
400 $this->content_obj->getPcId(),
401 $a_hid[1]
402 );
403 if ($updated !== true) {
404 $_SESSION["il_pg_error"] = $updated;
405 } else {
406 unset($_SESSION["il_pg_error"]);
407 }
408 $this->log->debug("return to parent jump" . $this->hier_id);
409 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
410 }
411
415 public function moveBefore()
416 {
418
419 // check if a target is selected
420 if (!isset($_POST["target"])) {
421 $ilErr->raiseError($this->lng->txt("no_checkbox"), $ilErr->MESSAGE);
422 }
423
424 // check if target is within source
425 if (count($_POST["target"]) > 1) {
426 $ilErr->raiseError($this->lng->txt("only_one_target"), $ilErr->MESSAGE);
427 }
428
429 $a_hid = explode(":", $_POST["target"][0]);
430
431 // check if target is within source
432 if ($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id))) {
433 $ilErr->raiseError($this->lng->txt("cont_target_within_source"), $ilErr->MESSAGE);
434 }
435
436 // check whether target is allowed
437 $curr_node = $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
438 if (is_object($curr_node) && $curr_node->node_name() == "FileItem") {
439 $ilErr->raiseError($this->lng->txt("cont_operation_not_allowed"), $ilErr->MESSAGE);
440 }
441
442 // strip "c" "r" of table ids from hierarchical id
443 $first_hier_character = substr($a_hid[0], 0, 1);
444 if ($first_hier_character == "c" ||
445 $first_hier_character == "r" ||
446 $first_hier_character == "i") {
447 $a_hid[0] = substr($a_hid[0], 1);
448 }
449
450 // move
451 $updated = $this->pg_obj->moveContentBefore(
452 $this->hier_id,
453 $a_hid[0],
454 $this->content_obj->getPcId(),
455 $a_hid[1]
456 );
457 if ($updated !== true) {
458 $_SESSION["il_pg_error"] = $updated;
459 } else {
460 unset($_SESSION["il_pg_error"]);
461 }
462 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
463 }
464
465
469 public function splitPage()
470 {
472
473 if ($this->pg_obj->getParentType() != "lm") {
474 $ilErr->raiseError("Split method called for wrong parent type (" .
475 $this->pg_obj->getParentType() . ")", $ilErr->FATAL);
476 } else {
478 $this->pg_obj->getId(),
479 $this->pg_obj->getParentType(),
480 $this->hier_id
481 );
482
483 // jump to new page
484 $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $lm_page->getId());
485 $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
486 }
487
488 $this->ctrl->returnToParent($this, "jump" . ($this->hier_id - 1));
489 }
490
494 public function splitPageNext()
495 {
497
498 if ($this->pg_obj->getParentType() != "lm") {
499 $ilErr->raiseError("Split method called for wrong parent type (" .
500 $this->pg_obj->getParentType() . ")", $ilErr->FATAL);
501 } else {
503 $this->pg_obj->getId(),
504 $this->pg_obj->getParentType(),
505 $this->hier_id
506 );
507
508 // jump to successor page
509 if ($succ_id > 0) {
510 $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $succ_id);
511 $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
512 }
513 }
514 $this->ctrl->returnToParent($this, "jump" . ($this->hier_id - 1));
515 }
516
520 public function displayValidationError()
521 {
522 if (is_array($this->updated)) {
523 $error_str = "<b>Error(s):</b><br>";
524 foreach ($this->updated as $error) {
525 $err_mess = implode(" - ", $error);
526 if (!is_int(strpos($err_mess, ":0:"))) {
527 $error_str .= htmlentities($err_mess) . "<br />";
528 }
529 }
530 ilUtil::sendFailure($error_str);
531 } elseif ($this->updated != "" && $this->updated !== true) {
532 ilUtil::sendFailure("<b>Error(s):</b><br />" .
533 $this->updated);
534 }
535 }
536
540 public function cancelCreate()
541 {
542 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
543 }
544
548 public function cancelUpdate()
549 {
550 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
551 }
552
556 public function cancel()
557 {
558 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
559 }
560
565 public function deactivate()
566 {
567 $obj = &$this->content_obj;
568
569 if ($obj->isEnabled()) {
570 $obj->disable();
571 } else {
572 $obj->enable();
573 }
574
575 $updated = $this->pg_obj->update($this->hier_id);
576 if ($updated !== true) {
577 $_SESSION["il_pg_error"] = $updated;
578 } else {
579 unset($_SESSION["il_pg_error"]);
580 }
581
582 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
583 }
584
588 public function cut()
589 {
591
592 $obj = $this->content_obj;
593
594 $updated = $this->pg_obj->cutContents(array($this->hier_id . ":" . $this->pc_id));
595 if ($updated !== true) {
596 $_SESSION["il_pg_error"] = $updated;
597 } else {
598 unset($_SESSION["il_pg_error"]);
599 }
600
601 //ilUtil::sendSuccess($lng->txt("cont_sel_el_cut_use_paste"), true);
602 $this->log->debug("return to parent jump" . $this->hier_id);
603 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
604 }
605
609 public function copy()
610 {
612
613 $obj = $this->content_obj;
614
615 //ilUtil::sendSuccess($lng->txt("cont_sel_el_copied_use_paste"), true);
616 $this->pg_obj->copyContents(array($this->hier_id . ":" . $this->pc_id));
617
618 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
619 }
620
621
625 public function getTemplateOptions($a_type)
626 {
627 $style = $this->getStyle();
628
629 if (is_object($style)) {
630 $ts = $style->getTemplates($a_type);
631 $options = array();
632 foreach ($ts as $t) {
633 $options["t:" . $t["id"] . ":" . $t["name"]] = $t["name"];
634 }
635 return $options;
636 }
637 return array();
638 }
639
644 protected function redirectToParent($hier_id = "")
645 {
646 $ilCtrl = $this->ctrl;
647 if ($hier_id == "") {
649 }
650 $pcid = $this->pg_obj->getPCIdForHierId($hier_id);
651 $ilCtrl->returnToParent($this, "add" . $pcid);
652 }
653
654 protected function getParentReturn($hier_id = "")
655 {
656 if ($hier_id == "") {
658 }
659 $ilCtrl = $this->ctrl;
660 $pcid = $this->pg_obj->getPCIdForHierId($hier_id);
661 return $ilCtrl->getParentReturn($this) . "#add" . $pcid;
662 }
663}
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
static getInitHTML($a_url)
Get initialisation HTML to use interna link editing.
static _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
split page to next page at hierarchical id
static _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
split page at hierarchical id
static getLogger($a_component_id)
Get component logger.
Class ilObjStyleSheet.
static _lookupType($a_id, $a_reference=false)
lookup object type
static getCharStyleSelector($a_par_type, $a_use_callback=true, $a_style_id=0)
Get character style selector.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getHierId()
get hierarchical id in dom object
setPageConfig($a_val)
Set Page Config.
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
deactivate()
gui function set enabled if is not enabled and vice versa
getPageConfig()
Get Page Config.
getTemplateOptions($a_type)
Get table templates.
displayValidationError()
display validation errors
static _getCommonBBButtons()
Get common bb buttons.
getCharacteristics()
Get characteristics.
setPage($a_val)
Set page.
moveAfter()
move content element after another element
splitPageNext()
split page to next page at specified position
redirectToParent($hier_id="")
Redirect to parent.
cut()
Cut single element.
setStyleId($a_styleid)
Set Style Id.
splitPage()
split page to new page at specified position
getContentObject()
Get content object.
__construct($a_pg_obj, $a_content_obj, $a_hier_id=0, $a_pc_id="")
Constructor @access public.
moveBefore()
move content element before another element
setContentObject($a_val)
Set content object.
cancelCreate()
cancel creating page content
getStyle()
Get style object.
getBBMenu($a_ta_name="par_content")
Get the bb menu incl.
setCharacteristics($a_chars)
Set Characteristics.
copy()
Copy single element.
setHierId($a_hier_id)
get hierarchical id in dom object
static lookupSettingByParentType($a_par_type, $a_name, $a_default=false)
Lookup setting by parent type.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$c
Definition: cli.php:37
global $DIC
Definition: goto.php:24
if(strpos( $jquery_path, './')===0) elseif(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:54
$ilErr
Definition: raiseError.php:18