ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilHelpGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
16{
20 protected $ctrl;
21
25 protected $settings;
26
30 protected $lng;
31
35 protected $user;
36
37 public $help_sections = array();
38 const ID_PART_SCREEN = "screen";
39 const ID_PART_SUB_SCREEN = "sub_screen";
40 const ID_PART_COMPONENT = "component";
41 public $def_screen_id = array();
42 public $screen_id = array();
43
47 protected $ui;
48
52 protected $raw_menu_items = null;
53
57 public function __construct()
58 {
59 global $DIC;
60
61 $this->settings = $DIC->settings();
62 $this->lng = $DIC->language();
63 $this->user = $DIC->user();
64 $ilCtrl = $DIC->ctrl();
65
66 $this->ctrl = $ilCtrl;
67 $this->ui = $DIC->ui();
68 }
69
76 public function setDefaultScreenId($a_part, $a_id)
77 {
78 $this->def_screen_id[$a_part] = $a_id;
79 }
80
86 public function setScreenId($a_id)
87 {
88 $this->screen_id[self::ID_PART_SCREEN] = $a_id;
89 }
90
96 public function setSubScreenId($a_id)
97 {
98 $this->screen_id[self::ID_PART_SUB_SCREEN] = $a_id;
99 }
100
107 public function setScreenIdComponent($a_comp)
108 {
109 $this->screen_id_component = $a_comp;
110 }
111
112
119 public function getScreenId()
120 {
121 $comp = ($this->screen_id_component != "")
122 ? $this->screen_id_component
123 : $this->def_screen_id[self::ID_PART_COMPONENT];
124
125 if ($comp == "") {
126 return "";
127 }
128
129 $scr_id = ($this->screen_id[self::ID_PART_SCREEN] != "")
130 ? $this->screen_id[self::ID_PART_SCREEN]
131 : $this->def_screen_id[self::ID_PART_SCREEN];
132
133 $sub_scr_id = ($this->screen_id[self::ID_PART_SUB_SCREEN] != "")
134 ? $this->screen_id[self::ID_PART_SUB_SCREEN]
135 : $this->def_screen_id[self::ID_PART_SUB_SCREEN];
136
137 $screen_id = $comp . "/" .
138 $scr_id . "/" .
139 $sub_scr_id;
140
141 return $screen_id;
142 }
143
144
151 public function addHelpSection($a_help_id, $a_level = 1)
152 {
153 $this->help_sections[] = array("help_id" => $a_help_id, $a_level);
154 }
155
162 public function hasSections()
163 {
165
166 include_once("./Services/Help/classes/class.ilHelpMapping.php");
168 }
169
176 public function getHelpSections()
177 {
178 include_once("./Services/Help/classes/class.ilHelpMapping.php");
179 return ilHelpMapping::getHelpSectionsForId($this->getScreenId(), (int) $_GET["ref_id"]);
180 }
181
188 public function setCtrlPar()
189 {
190 $ilCtrl = $this->ctrl;
191
192 /*$h_ids = $sep = "";
193 foreach ($this->getHelpSections() as $hs)
194 {
195 $h_ids.= $sep.$hs;
196 $sep = ",";
197 }*/
198 $ilCtrl->setParameterByClass("ilhelpgui", "help_screen_id", $this->getScreenId() . "." . $_GET["ref_id"]);
199 }
200
201
205 public function executeCommand()
206 {
207 $cmd = $this->ctrl->getCmd("showHelp");
208 $next_class = $this->ctrl->getNextClass($this);
209
210 switch ($next_class) {
211 default:
212 return $this->$cmd();
213 break;
214 }
215 }
216
220 public function showHelp()
221 {
223 $lng->loadLanguageModule("help");
224 $ui = $this->ui;
225
226 if ($_GET["help_screen_id"] != "") {
227 ilSession::set("help_screen_id", $_GET["help_screen_id"]);
228 $help_screen_id = $_GET["help_screen_id"];
229 } else {
230 $help_screen_id = ilSession::get("help_screen_id");
231 }
232
233 ilSession::set("help_search_term", "");
234
235 $this->resetCurrentPage();
236
237 $id_arr = explode(".", $help_screen_id);
238 include_once("./Services/Help/classes/class.ilHelpMapping.php");
239 include_once("./Services/Help/classes/class.ilHelp.php");
240
241 $help_arr = ilHelpMapping::getHelpSectionsForId($id_arr[0], $id_arr[1]);
242 $oh_lm_id = ilHelp::getHelpLMId();
243
244 if ($oh_lm_id > 0) {
245 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
246 $acc = new ilAccordionGUI();
247 $acc->setId("oh_acc_" . $h_id);
248 $acc->setUseSessionStorage(true);
249 $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
250
251 foreach ($help_arr as $h_id) {
252 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
253 $st_id = $h_id;
254 if (!ilLMObject::_exists($st_id)) {
255 continue;
256 }
257
258 $pages = ilLMObject::getPagesOfChapter($oh_lm_id, $st_id);
259 include_once("./Services/UIComponent/GroupedList/classes/class.ilGroupedListGUI.php");
260 $grp_list = new ilGroupedListGUI();
261 foreach ($pages as $pg) {
262 $grp_list->addEntry(
263 $this->replaceMenuItemTags((string) ilLMObject::_lookupTitle($pg["child"])),
264 "#",
265 "",
266 "return il.Help.showPage(" . $pg["child"] . ");"
267 );
268 }
269
270 $acc->addItem(ilLMObject::_lookupTitle($st_id), $grp_list->getHTML());
271 }
272
273 $h_tpl = new ilTemplate("tpl.help.html", true, true, "Services/Help");
274 $h_tpl->setVariable("HEAD", $lng->txt("help"));
275
276 $h_tpl->setCurrentBlock("search");
277 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
278 $h_tpl->setVariable("GL_SEARCH", ilGlyphGUI::get(ilGlyphGUI::SEARCH));
279 $h_tpl->setVariable("HELP_SEARCH_LABEL", $this->lng->txt("help_search_label"));
280 $h_tpl->parseCurrentBlock();
281
282 if (count($help_arr) > 0) {
283 $h_tpl->setVariable("CONTENT", $acc->getHTML());
284 } else {
285 $mess = $ui->factory()->messageBox()->info($lng->txt("help_no_content"));
286 $h_tpl->setVariable("CONTENT", $ui->renderer()->render([$mess]));
287 }
288
289 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
290 $h_tpl->setVariable("CLOSE_IMG", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
291 echo $h_tpl->get();
292 }
293 exit;
294 }
295
302 public function showPage()
303 {
305 $ui = $this->ui;
306
307 $page_id = (int) $_GET["help_page"];
308
309 $h_tpl = new ilTemplate("tpl.help.html", true, true, "Services/Help");
310 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
311
312
313 if (($t = ilSession::get("help_search_term")) != "") {
314 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) use ($t) {
315 return
316 "$(\"#$id\").click(function() { return il.Help.search('" . ilUtil::prepareFormOutput($t) . "'); return false;});";
317 });
318 $h_tpl->setVariable("BACKBUTTON", $ui->renderer()->renderAsync($back_button));
319 } else {
320 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) {
321 return
322 "$(\"#$id\").click(function() { return il.Help.listHelp(event, true); return false;});";
323 });
324 $h_tpl->setVariable("BACKBUTTON", $ui->renderer()->renderAsync($back_button));
325 }
326
327 $h_tpl->setVariable(
328 "HEAD",
329 $this->replaceMenuItemTags((string) ilLMObject::_lookupTitle($page_id))
330 );
331
332 include_once("./Services/COPage/classes/class.ilPageUtil.php");
333 if (!ilPageUtil::_existsAndNotEmpty("lm", $page_id)) {
334 exit;
335 }
336 include_once("./Services/COPage/classes/class.ilPageObject.php");
337 include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
338
339 // get page object
340 include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
341 include_once("./Modules/LearningModule/classes/class.ilLMPageGUI.php");
342 $page_gui = new ilLMPageGUI($page_id);
343 $cfg = $page_gui->getPageConfig();
344 $page_gui->setPresentationTitle("");
345 $page_gui->setTemplateOutput(false);
346 $page_gui->setHeader("");
347 $page_gui->setRawPageContent(true);
348 $cfg->setEnablePCType("Map", false);
349 $cfg->setEnablePCType("Tabs", false);
350 $cfg->setEnablePCType("FileList", false);
351
352 $page_gui->getPageObject()->buildDom();
353 $int_links = $page_gui->getPageObject()->getInternalLinks();
354 $link_xml = $this->getLinkXML($int_links);
355 $link_xml .= $this->getLinkTargetsXML();
356 //echo htmlentities($link_xml);
357 $page_gui->setLinkXML($link_xml);
358
359 $ret = $this->replaceMenuItemTags((string) $page_gui->showPage());
360
361 $h_tpl->setVariable("CONTENT", $ret);
362 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
363 $h_tpl->setVariable("CLOSE_IMG", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
364
365 ilSession::set("help_pg", $page_id);
366
367 $page = $h_tpl->get();
368
369 // replace style classes
370 //$page = str_replace("ilc_text_inline_Strong", "ilHelpStrong", $page);
371
372 echo $page;
373 exit;
374 }
375
382 public function resetCurrentPage()
383 {
384 ilSession::clear("help_pg");
385 }
386
387
394 public function getTabTooltipText($a_tab_id)
395 {
397
398 include_once("./Services/Help/classes/class.ilHelp.php");
399 if ($this->screen_id_component != "") {
400 return ilHelp::getTooltipPresentationText($this->screen_id_component . "_" . $a_tab_id);
401 //return $lng->txt("help_tt_".$this->screen_id_component."_".$a_tab_id);
402 }
403 return "";
404 }
405
412 public function initHelp($a_tpl, $ajax_url)
413 {
414 global $DIC;
415
416 $ilUser = $DIC->user();
417 $ilSetting = $DIC->settings();
418 $ctrl = $DIC->ctrl();
419
421 $a_tpl->addJavascript("./Services/Help/js/ilHelp.js");
422 $a_tpl->addJavascript("./Services/Accordion/js/accordion.js");
424 $a_tpl->addJavascript("./Services/COPage/js/ilCOPagePres.js");
425
426 $this->setCtrlPar();
427 $a_tpl->addOnLoadCode(
428 "il.Help.setAjaxUrl('" .
429 $ctrl->getLinkTargetByClass("ilhelpgui", "", "", true)
430 . "');"
431 );
432
433
434 $module_id = (int) $ilSetting->get("help_module");
435
436 if ((OH_REF_ID > 0 || $module_id > 0) && $ilUser->getLanguage() == "de") {
437 if (ilSession::get("help_pg") > 0) {
438 $a_tpl->addOnLoadCode("il.Help.showCurrentPage(" . ilSession::get("help_pg") . ");", 3);
439 } else {
440 $a_tpl->addOnLoadCode("il.Help.listHelp(null);", 3);
441 }
442
443
444 if ($ilUser->getPref("hide_help_tt")) {
445 $a_tpl->addOnLoadCode("if (il && il.Help) {il.Help.switchTooltips();}", 3);
446 }
447 }
448 }
449
455 public function isHelpPageActive()
456 {
457 return (ilSession::get("help_pg") > 0);
458 }
459
466 public function deactivateTooltips()
467 {
469
470 $ilUser->writePref("hide_help_tt", "1");
471 }
472
479 public function activateTooltips()
480 {
482
483 $ilUser->writePref("hide_help_tt", "0");
484 }
485
489 public function getLinkXML($a_int_links)
490 {
491 $ilCtrl = $this->ctrl;
492
493 $link_info = "<IntLinkInfos>";
494 foreach ($a_int_links as $int_link) {
495 $target = $int_link["Target"];
496 if (substr($target, 0, 4) == "il__") {
497 $target_arr = explode("_", $target);
498 $target_id = $target_arr[count($target_arr) - 1];
499 $type = $int_link["Type"];
500 $targetframe = "None";
501
502 // anchor
503 $anc = $anc_add = "";
504 if ($int_link["Anchor"] != "") {
505 $anc = $int_link["Anchor"];
506 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
507 }
508
509 switch ($type) {
510 case "PageObject":
511 case "StructureObject":
512 if ($type == "PageObject") {
513 $href = "#pg_" . $target_id;
514 } else {
515 $href = "#";
516 }
517 break;
518
519 }
520
521 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
522 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"\" Anchor=\"\"/>";
523 }
524 }
525 $link_info .= "</IntLinkInfos>";
526
527 return $link_info;
528 }
529
533 public function getLinkTargetsXML()
534 {
535 $link_info = "<LinkTargets>";
536 $link_info .= "<LinkTarget TargetFrame=\"None\" LinkTarget=\"\" OnClick=\"return il.Help.openLink(event);\" />";
537 $link_info .= "</LinkTargets>";
538 return $link_info;
539 }
540
547 public function search()
548 {
550 $ui = $this->ui;
551
552 $term = $_GET["term"];
553
554 if ($term == "") {
555 $term = ilSession::get("help_search_term");
556 }
557
558 $this->resetCurrentPage();
559
560 $h_tpl = new ilTemplate("tpl.help.html", true, true, "Services/Help");
561 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
562
563
564 $back_button = $ui->factory()->button()->bulky($ui->factory()->symbol()->glyph()->back(), $lng->txt("back"), "#")->withOnLoadCode(function ($id) {
565 return
566 "$(\"#$id\").click(function() { return il.Help.listHelp(event, true); return false;});";
567 });
568 $h_tpl->setVariable("BACKBUTTON", $ui->renderer()->renderAsync($back_button));
569
570 $h_tpl->setVariable("HEAD", $lng->txt("help") . " - " .
571 $lng->txt("search_result"));
572
573 $h_tpl->setCurrentBlock("search");
574 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
575 $h_tpl->setVariable("GL_SEARCH", ilGlyphGUI::get(ilGlyphGUI::SEARCH));
576 $h_tpl->setVariable("HELP_SEARCH_LABEL", $this->lng->txt("help_search_label"));
577 $h_tpl->setVariable("VAL_SEARCH", ilUtil::prepareFormOutput($term));
578 $h_tpl->parseCurrentBlock();
579
580 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
581 $h_tpl->setVariable("CLOSE_IMG", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
582
583 $lm_id = ilHelp::getHelpLMId();
584 include_once("./Services/Search/classes/class.ilRepositoryObjectDetailSearch.php");
585 $s = new ilRepositoryObjectDetailSearch($lm_id);
586 $s->setQueryString($term);
587 $result = $s->performSearch();
588
589 include_once("./Services/UIComponent/GroupedList/classes/class.ilGroupedListGUI.php");
590 $grp_list = new ilGroupedListGUI();
591 foreach ($result->getResults() as $r) {
592 $grp_list->addEntry(
593 ilLMObject::_lookupTitle($r["item_id"]),
594 "#",
595 "",
596 "return il.Help.showPage(" . $r["item_id"] . ");"
597 );
598 }
599 $h_tpl->setVariable("CONTENT", $grp_list->getHTML());
600
601 ilSession::set("help_search_term", $term);
602
603 echo $h_tpl->get();
604 ;
605 exit;
606 }
607
608
609
610
618 protected function replaceMenuItemTags(string $content) : string
619 {
620 global $DIC;
621
622 $mmc = $DIC->globalScreen()->collector()->mainmenu();
623 if ($this->raw_menu_items == null) {
624 $mmc->collectOnce();
625 $this->raw_menu_items = iterator_to_array($mmc->getRawItems());
626 }
627
628 foreach ($this->raw_menu_items as $item) {
629 if ($item instanceof Item\LinkList) {
630 foreach ($item->getLinks() as $link) {
631 $content = $this->replaceItemTag($mmc, $content, $link);
632 }
633 }
634 $content = $this->replaceItemTag($mmc, $content, $item);
635 }
636 return $content;
637 }
638
645 protected function replaceItemTag($mmc, string $content, \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item)
646 {
647 global $DIC;
648 $mmc = $DIC->globalScreen()->collector()->mainmenu();
649
650 $id = $item->getProviderIdentification()->getInternalIdentifier();
651 $ws = "[ \t\r\f\v\n]*";
652
653 // menu item path
654 while (preg_match("~\[(menu" . $ws . "path$ws=$ws(\"$id\")$ws)/\]~i", $content, $found)) {
655 $path = "";
656 if ($item instanceof \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isChild) {
657 $parent = $mmc->getItemInformation()->getParent($item);
658 if ($parent !== null) {
659 $parent = $mmc->getSingleItemFromRaw($parent);
660 $path = $this->getTitleForItem($parent) . " > ";
661 }
662 }
663 $path .= $this->getTitleForItem($item);
664 $content = preg_replace(
665 '~\[' . $found[1] . '/\]~i',
666 "<strong>" . $path . "</strong>",
667 $content
668 );
669 }
670 // menu item
671 while (preg_match("~\[(menu" . $ws . "item$ws=$ws(\"$id\")$ws)/\]~i", $content, $found)) {
672 $content = preg_replace(
673 '~\[' . $found[1] . '/\]~i',
674 "<strong>" . $this->getTitleForItem($item) . "</strong>",
675 $content
676 );
677 }
678 return $content;
679 }
680
687 protected function getTitleForItem(\ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item) : string
688 {
689 global $DIC;
690 $mmc = $DIC->globalScreen()->collector()->mainmenu();
691 return $mmc->getItemInformation()->customTranslationForUser($item)->getTitle();
692 }
693}
$result
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Accordion user interface class.
static get($a_glyph, $a_text="")
Get glyph html.
Grouped list GUI class.
Help GUI class.
hasSections()
Has sections?
isHelpPageActive()
Is help page active?
addHelpSection($a_help_id, $a_level=1)
Add help section.
getLinkXML($a_int_links)
get xml for links
showHelp()
Show online help.
const ID_PART_COMPONENT
initHelp($a_tpl, $ajax_url)
Render current help page.
getHelpSections()
Get help sections.
getTabTooltipText($a_tab_id)
Get tab tooltip text.
getTitleForItem(\ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item)
Get title for item.
getLinkTargetsXML()
Get XMl for Link Targets.
setDefaultScreenId($a_part, $a_id)
Set default screen id.
__construct()
constructor
replaceItemTag($mmc, string $content, \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem $item)
Replace item tag.
setCtrlPar()
Get help section url parameter.
deactivateTooltips()
Deactivate tooltips.
executeCommand()
execute command
const ID_PART_SCREEN
const ID_PART_SUB_SCREEN
getScreenId()
Get screen id.
showPage()
Show page.
replaceMenuItemTags(string $content)
Help page post processing.
search()
Search.
resetCurrentPage()
Hide help.
setSubScreenId($a_id)
Set sub screen id.
setScreenId($a_id)
Set screen id.
activateTooltips()
Activate tooltips.
setScreenIdComponent($a_comp)
Set screen id component.
static hasScreenIdSections($a_screen_id)
Has given screen Id any sections?
static getHelpSectionsForId($a_screen_id, $a_ref_id)
Get help sections for screen id.
static getTooltipPresentationText($a_tt_id)
Get tooltip for id.
static getHelpLMId()
Get help lm id.
static getPagesOfChapter($a_lm_id, $a_chap_id)
Get pages of chapter.
static _lookupTitle($a_obj_id)
Lookup title.
static _exists($a_id)
checks wether a lm content object with specified id exists or not
Extension of ilPageObjectGUI for learning modules.
static _existsAndNotEmpty($a_parent_type, $a_id, $a_lang="-")
checks whether page exists and is not empty (may return true on some empty pages)
static set($a_var, $a_val)
Set a value.
static clear($a_var)
Unset a value.
static get($a_var)
Get a value.
special template class to simplify handling of ITX/PEAR
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static initConnection(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
static initMaphilight()
Inits and add maphilight to the general template.
global $DIC
Definition: goto.php:24
$target_id
Definition: goto.php:51
$target_arr
Definition: goto.php:49
$ilUser
Definition: imgupload.php:18
exit
Definition: login.php:29
Class ChatMainBarProvider \MainMenu\Provider.
$ret
Definition: parser.php:6
global $ilSetting
Definition: privfeed.php:17
$type
settings()
Definition: settings.php:2
ui()
Definition: ui.php:5