ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
17 var $ilias;
18 var $tpl;
19 var $lng;
20
24 var $ctrl;
27 var $dom;
31 var $page_config = null;
32
36 protected $log;
37
38 static $style_selector_reset = "margin-top:2px; margin-bottom:2px; text-indent:0px; position:static; float:none; width: auto;";
39
40 // common bb buttons (special ones are iln and wln)
41 protected static $common_bb_buttons = array(
42 "str" => "Strong", "emp" => "Emph", "imp" => "Important",
43 "sup" => "Sup", "sub" => "Sub",
44 "com" => "Comment",
45 "quot" => "Quotation", "acc" => "Accent", "code" => "Code", "tex" => "Tex",
46 "fn" => "Footnote", "xln" => "ExternalLink"
47 );
48
53 function __construct($a_pg_obj, $a_content_obj, $a_hier_id = 0, $a_pc_id = "")
54 {
55 global $ilias, $tpl, $lng, $ilCtrl;
56
57 $this->log = ilLoggerFactory::getLogger('copg');
58
59 $this->ilias = $ilias;
60 $this->tpl = $tpl;
61 $this->lng = $lng;
62 $this->pg_obj = $a_pg_obj;
63 $this->ctrl = $ilCtrl;
64 $this->content_obj = $a_content_obj;
65
66 if($a_hier_id !== 0)
67 {
68 $this->hier_id = $a_hier_id;
69 $this->pc_id = $a_pc_id;
70//echo "-".$this->pc_id."-";
71 $this->dom = $a_pg_obj->getDom();
72 }
73 }
74
80 function setContentObject($a_val)
81 {
82 $this->content_obj = $a_val;
83 }
84
91 {
92 return $this->content_obj;
93 }
94
100 function setPage($a_val)
101 {
102 $this->pg_obj = $a_val;
103 }
104
110 function getPage()
111 {
112 return $this->pg_obj;
113 }
114
120 function setPageConfig($a_val)
121 {
122 $this->page_config = $a_val;
123 }
124
130 function getPageConfig()
131 {
132 return $this->page_config;
133 }
134
138 static function _getCommonBBButtons()
139 {
141 }
142
143 // scorm2004-start
149 function setStyleId($a_styleid)
150 {
151 $this->styleid = $a_styleid;
152 }
153
159 function getStyleId()
160 {
161 return $this->styleid;
162 }
163
167 function getStyle()
168 {
169 if ((!is_object($this->style) || $this->getStyleId() != $this->style->getId()) && $this->getStyleId() > 0)
170 {
171 if (ilObject::_lookupType($this->getStyleId()) == "sty")
172 {
173 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
174 $this->style = new ilObjStyleSheet($this->getStyleId());
175 }
176 }
177
178 return $this->style;
179 }
180
185 {
186 if ($this->getStyleId() > 0 &&
187 ilObject::_lookupType($this->getStyleId()) == "sty")
188 {
189 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
190 $style = new ilObjStyleSheet($this->getStyleId());
191 $chars = array();
192 if (!is_array($a_type))
193 {
194 $a_type = array($a_type);
195 }
196 foreach ($a_type as $at)
197 {
198 $chars = array_merge($chars, $style->getCharacteristics($at, true));
199 }
200 $new_chars = array();
201 if (is_array($chars))
202 {
203 foreach ($chars as $char)
204 {
205 if ($this->chars[$char] != "") // keep lang vars for standard chars
206 {
207 $new_chars[$char] = $this->chars[$char];
208 }
209 else
210 {
211 $new_chars[$char] = $char;
212 }
213 asort($new_chars);
214 }
215 }
216 $this->setCharacteristics($new_chars);
217 }
218 }
219
223 function setCharacteristics($a_chars)
224 {
225 $this->chars = $a_chars;
226 }
227
232 {
233 return $this->chars ? $this->chars : array();
234 }
235 // scorm2004-end
236
237
241 function getHierId()
242 {
243 return $this->hier_id;
244 }
245
249 function setHierId($a_hier_id)
250 {
251 $this->hier_id = $a_hier_id;
252 }
253
257 function getBBMenu($a_ta_name = "par_content")
258 {
259 global $lng, $ilCtrl;
260
261 include_once("./Services/COPage/classes/class.ilPageEditorSettings.php");
262
263 $btpl = new ilTemplate("tpl.bb_menu.html", true, true, "Services/COPage");
264
265 // not nice, should be set by context per method
266 if ($this->getPageConfig()->getEnableInternalLinks())
267 {
268 $btpl->setCurrentBlock("bb_ilink_button");
269 $btpl->setVariable("BB_LINK_ILINK",
270 $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
271 $btpl->parseCurrentBlock();
272
273 // add int link parts
274 include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
275 $btpl->setCurrentBlock("int_link_prep");
276 $btpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
277 $ilCtrl->getLinkTargetByClass(array("ilpageeditorgui", "ilinternallinkgui"),
278 "", false, true, false), true));
279 $btpl->parseCurrentBlock();
280
281 }
282
283 if ($this->getPageConfig()->getEnableKeywords())
284 {
285 $btpl->touchBlock("bb_kw_button");
286 $btpl->setVariable("TXT_KW", $this->lng->txt("cont_text_keyword"));
287 }
288 if ($this->pg_obj->getParentType() == "wpg")
289 {
290 $btpl->setCurrentBlock("bb_wikilink_button2");
291 $btpl->setVariable("TXT_WIKI_BUTTON2", $lng->txt("obj_wiki"));
292 $btpl->setVariable("WIKI_BUTTON2_URL", $ilCtrl->getLinkTargetByClass("ilwikipagegui", ""));
293 $btpl->parseCurrentBlock();
294
295 $btpl->setCurrentBlock("bb_wikilink_button");
296 $btpl->setVariable("TXT_WLN2", $lng->txt("wiki_wiki_page"));
297 $btpl->parseCurrentBlock();
298 }
299 $mathJaxSetting = new ilSetting("MathJax");
300 $style = $this->getStyle();
301//echo URL_TO_LATEX;
302 foreach (self::$common_bb_buttons as $c => $st)
303 {
304 if (ilPageEditorSettings::lookupSettingByParentType($this->pg_obj->getParentType(), "active_".$c, true))
305 {
306 if ($c != "tex" || $mathJaxSetting->get("enable") || defined("URL_TO_LATEX"))
307 {
308 if (!in_array($c, array("acc", "com", "quot", "code")))
309 {
310 $btpl->touchBlock("bb_" . $c . "_button");
311 $btpl->setVariable("TXT_" . strtoupper($c), $this->lng->txt("cont_text_" . $c));
312 $lng->toJS("cont_text_" . $c);
313 }
314 }
315 }
316 }
317
318 if ($this->getPageConfig()->getEnableAnchors())
319 {
320 $btpl->touchBlock("bb_anc_button");
321 $btpl->setVariable("TXT_ANC", $lng->txt("cont_anchor").":");
322 $lng->toJS("cont_anchor");
323 }
324
325 include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
326 $btpl->setVariable("CHAR_STYLE_SELECT", ilPCParagraphGUI::getCharStyleSelector($this->pg_obj->getParentType(), true, $this->getStyleId()));
327
328 // footnote
329// $btpl->setVariable("TXT_FN", $this->lng->txt("cont_text_fn"));
330
331// $btpl->setVariable("TXT_CODE", $this->lng->txt("cont_text_code"));
332 $btpl->setVariable("TXT_ILN", $this->lng->txt("cont_text_iln"));
333 $lng->toJS("cont_text_iln");
334// $btpl->setVariable("TXT_XLN", $this->lng->txt("cont_text_xln"));
335// $btpl->setVariable("TXT_TEX", $this->lng->txt("cont_text_tex"));
336 $btpl->setVariable("TXT_BB_TIP", $this->lng->txt("cont_bb_tip"));
337 $btpl->setVariable("TXT_WLN", $lng->txt("wiki_wiki_page"));
338 $lng->toJS("wiki_wiki_page");
339
340 $btpl->setVariable("PAR_TA_NAME", $a_ta_name);
341
342 return $btpl->get();
343 }
344
348 function delete()
349 {
350 $updated = $this->pg_obj->deleteContent($this->hier_id);
351 if($updated !== true)
352 {
353 $_SESSION["il_pg_error"] = $updated;
354 }
355 else
356 {
357 unset($_SESSION["il_pg_error"]);
358 }
359 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
360 }
361
365 function moveAfter()
366 {
367 // check if a target is selected
368 if(!isset($_POST["target"]))
369 {
370 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
371 }
372
373 // check if only one target is selected
374 if(count($_POST["target"]) > 1)
375 {
376 $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
377 }
378
379 $a_hid = explode(":", $_POST["target"][0]);
380//echo "-".$a_hid[0]."-".$a_hid[1]."-";
381
382 // check if target is within source
383 if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
384 {
385 $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
386 }
387
388 // check whether target is allowed
389 $curr_node = $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
390 if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
391 {
392 $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
393 }
394
395 // strip "c" "r" of table ids from hierarchical id
396 $first_hier_character = substr($a_hid[0], 0, 1);
397 if ($first_hier_character == "c" ||
398 $first_hier_character == "r" ||
399 $first_hier_character == "i")
400 {
401 $a_hid[0] = substr($a_hid[0], 1);
402 }
403
404 // move
405 $updated = $this->pg_obj->moveContentAfter($this->hier_id, $a_hid[0],
406 $this->content_obj->getPcId(), $a_hid[1]);
407 if($updated !== true)
408 {
409 $_SESSION["il_pg_error"] = $updated;
410 }
411 else
412 {
413 unset($_SESSION["il_pg_error"]);
414 }
415
416 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
417 }
418
422 function moveBefore()
423 {
424 // check if a target is selected
425 if(!isset($_POST["target"]))
426 {
427 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
428 }
429
430 // check if target is within source
431 if(count($_POST["target"]) > 1)
432 {
433 $this->ilias->raiseError($this->lng->txt("only_one_target"),$this->ilias->error_obj->MESSAGE);
434 }
435
436 $a_hid = explode(":", $_POST["target"][0]);
437
438 // check if target is within source
439 if($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id)))
440 {
441 $this->ilias->raiseError($this->lng->txt("cont_target_within_source"),$this->ilias->error_obj->MESSAGE);
442 }
443
444 // check whether target is allowed
445 $curr_node = $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
446 if (is_object($curr_node) && $curr_node->node_name() == "FileItem")
447 {
448 $this->ilias->raiseError($this->lng->txt("cont_operation_not_allowed"),$this->ilias->error_obj->MESSAGE);
449 }
450
451 // strip "c" "r" of table ids from hierarchical id
452 $first_hier_character = substr($a_hid[0], 0, 1);
453 if ($first_hier_character == "c" ||
454 $first_hier_character == "r" ||
455 $first_hier_character == "i")
456 {
457 $a_hid[0] = substr($a_hid[0], 1);
458 }
459
460 // move
461 $updated = $this->pg_obj->moveContentBefore($this->hier_id, $a_hid[0],
462 $this->content_obj->getPcId(), $a_hid[1]);
463 if($updated !== true)
464 {
465 $_SESSION["il_pg_error"] = $updated;
466 }
467 else
468 {
469 unset($_SESSION["il_pg_error"]);
470 }
471 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
472 }
473
474
478 function splitPage()
479 {
480 global $ilErr;
481
482 if ($this->pg_obj->getParentType() != "lm")
483 {
484 $ilErr->raiseError("Split method called for wrong parent type (".
485 $this->pg_obj->getParentType().")", $ilErr->FATAL);
486 }
487 else
488 {
489 $lm_page = ilLMPageObject::_splitPage($this->pg_obj->getId(),
490 $this->pg_obj->getParentType(), $this->hier_id);
491
492 // jump to new page
493 $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $lm_page->getId());
494 $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
495 }
496
497 $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
498 }
499
503 function splitPageNext()
504 {
505 global $ilErr;
506
507 if ($this->pg_obj->getParentType() != "lm")
508 {
509 $ilErr->raiseError("Split method called for wrong parent type (".
510 $this->pg_obj->getParentType().")", $ilErr->FATAL);
511 }
512 else
513 {
514 $succ_id = ilLMPageObject::_splitPageNext($this->pg_obj->getId(),
515 $this->pg_obj->getParentType(), $this->hier_id);
516
517 // jump to successor page
518 if ($succ_id > 0)
519 {
520 $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $succ_id);
521 $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
522 }
523
524 }
525 $this->ctrl->returnToParent($this, "jump".($this->hier_id - 1));
526 }
527
532 {
533 if(is_array($this->updated))
534 {
535 $error_str = "<b>Error(s):</b><br>";
536 foreach ($this->updated as $error)
537 {
538 $err_mess = implode($error, " - ");
539 if (!is_int(strpos($err_mess, ":0:")))
540 {
541 $error_str .= htmlentities($err_mess)."<br />";
542 }
543 }
544 ilUtil::sendFailure($error_str);
545 }
546 else if($this->updated != "" && $this->updated !== true)
547 {
548 ilUtil::sendFailure("<b>Error(s):</b><br />".
549 $this->updated);
550 }
551 }
552
556 function cancelCreate()
557 {
558 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
559 }
560
564 function cancelUpdate()
565 {
566 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
567 }
568
572 function cancel()
573 {
574 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
575 }
576
581 function deactivate()
582 {
583 $obj = & $this->content_obj;
584
585 if ($obj->isEnabled ())
586 $obj->disable ();
587 else
588 $obj->enable ();
589
590 $updated = $this->pg_obj->update($this->hier_id);
591 if($updated !== true)
592 {
593 $_SESSION["il_pg_error"] = $updated;
594 }
595 else
596 {
597 unset($_SESSION["il_pg_error"]);
598 }
599
600 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
601 }
602
606 function cut()
607 {
608 global $lng;
609
610 $obj = $this->content_obj;
611
612 $updated = $this->pg_obj->cutContents(array($this->hier_id.":".$this->pc_id));
613 if($updated !== true)
614 {
615 $_SESSION["il_pg_error"] = $updated;
616 }
617 else
618 {
619 unset($_SESSION["il_pg_error"]);
620 }
621
622 ilUtil::sendSuccess($lng->txt("cont_sel_el_cut_use_paste"), true);
623 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
624 }
625
629 function copy()
630 {
631 global $lng;
632
633 $obj = $this->content_obj;
634
635 ilUtil::sendSuccess($lng->txt("cont_sel_el_copied_use_paste"), true);
636 $this->pg_obj->copyContents(array($this->hier_id.":".$this->pc_id));
637
638 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
639 }
640
641
646 {
647 $style = $this->getStyle();
648
649 if (is_object($style))
650 {
651 $ts = $style->getTemplates($a_type);
652 $options = array();
653 foreach ($ts as $t)
654 {
655 $options["t:".$t["id"].":".$t["name"]] = $t["name"];
656 }
657 return $options;
658 }
659 return array();
660 }
661
662}
663?>
$error
Definition: Error.php:17
if(strpos( $jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:36
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
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
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$style
Definition: example_012.php:70
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
global $ilErr
Definition: raiseError.php:16
if(!is_array($argv)) $options
$a_type
Definition: workflow.php:93