ILIAS  release_8 Revision v8.24
class.ilInternalLinkGUI.php
Go to the documentation of this file.
1<?php
2
20
26{
27 protected ?ilObjFile $uploaded_file = null;
28 protected int $parent_fold_id;
29 protected string $default_parent_obj_type;
31 protected string $return;
32 protected string $default_link_type = "";
33 protected int $default_parent_ref_id = 0;
34 protected int $default_parent_obj_id = 0;
35 protected int $parent_ref_id = 0;
36 protected int $parent_obj_id = 0;
37 protected string $link_type = ""; // "PageObject_New"
38 protected string $link_target = ""; // "New"
39 protected string $base_link_type = ""; // "PageObject"
40 public string $set_link_script = "";
42 protected array $ltypes = [];
44 protected array $parent_type = [];
45 public ilCtrl $ctrl;
46 protected bool $filter_white_list = false;
48 protected array $filter_link_types = [];
49 protected ilTree $tree;
50 protected ilLanguage $lng;
51 protected ilObjUser $user;
52
53 public function __construct(
54 string $a_default_link_type,
55 int $a_default_parent_id,
56 bool $a_is_ref = true
57 ) {
58 global $DIC;
59 $this->tree = $DIC->repositoryTree();
60 $this->lng = $DIC->language();
61 $this->ctrl = $DIC->ctrl();
62 $this->user = $DIC->user();
63
64 $this->request = new StandardGUIRequest(
65 $DIC->http(),
66 $DIC->refinery()
67 );
68
69 $this->lng->loadLanguageModule("link");
70 $this->lng->loadLanguageModule("content");
71 $this->ctrl->saveParameter($this, array("linkmode", "link_par_ref_id", "link_par_obj_id",
72 "link_par_fold_id", "link_type"));
73
74 // default type and parent
75 $this->default_link_type = $a_default_link_type;
76 if ($a_is_ref) {
77 $this->default_parent_ref_id = $a_default_parent_id;
78 $this->default_parent_obj_id = ilObject::_lookupObjId($a_default_parent_id);
79 } else {
80 $this->default_parent_ref_id = 0;
81 $this->default_parent_obj_id = $a_default_parent_id;
82 }
83 $this->default_parent_obj_type = ($this->default_parent_obj_id > 0)
84 ? ilObject::_lookupType($this->default_parent_obj_id)
85 : "";
86
87 // current parent object
88 $this->parent_ref_id = $this->request->getLinkParentRefId();
89 $this->parent_fold_id = $this->request->getLinkParentFolderId(); // e.g. media pool folder
90 if ($this->parent_ref_id > 0) {
91 $this->parent_obj_id = ilObject::_lookupObjId($this->parent_ref_id);
92 } else {
93 $this->parent_obj_id = $this->request->getLinkParentObjId();
94 }
95 }
96
97 public function init(): void
98 {
102
103 if ($this->parent_ref_id > 0 && !$tree->isInTree($this->parent_ref_id)) {
104 $this->resetLinkList();
105 }
106
107 $this->parent_type = array(
108 "StructureObject" => "lm",
109 "PageObject" => "lm",
110 "GlossaryItem" => "glo",
111 "Media" => "mep",
112 "WikiPage" => "wiki",
113 "PortfolioPage" => "prtf",
114 "PortfolioTemplatePage" => "prtt",
115 "File" => "",
116 "RepositoryItem" => "",
117 "User" => ""
118 );
119
120 // filter link types
121 $this->ltypes = array(
122 "StructureObject" => $lng->txt("cont_lk_chapter"),
123 "StructureObject_New" => $lng->txt("cont_lk_chapter_new"),
124 "PageObject" => $lng->txt("cont_lk_page"),
125 "PageObject_FAQ" => $lng->txt("cont_lk_page_faq"),
126 "PageObject_New" => $lng->txt("cont_lk_page_new"),
127 "GlossaryItem" => $lng->txt("cont_lk_term"),
128 "GlossaryItem_New" => $lng->txt("cont_lk_term_new"),
129 "Media" => $lng->txt("cont_lk_media_inline"),
130 "Media_Media" => $lng->txt("cont_lk_media_media"),
131 "Media_FAQ" => $lng->txt("cont_lk_media_faq"),
132 "Media_New" => $lng->txt("cont_lk_media_new"),
133 "WikiPage" => $lng->txt("cont_wiki_page"),
134 "PortfolioPage" => $lng->txt("cont_prtf_page"),
135 "PortfolioTemplatePage" => $lng->txt("cont_prtt_page"),
136 "File" => $lng->txt("cont_lk_file"),
137 "RepositoryItem" => $lng->txt("cont_repository_item"),
138 "User" => $lng->txt("cont_user")
139 );
140 if (!$this->filter_white_list) {
141 foreach ($this->filter_link_types as $link_type) {
142 unset($this->ltypes[$link_type]);
143 }
144 } else {
145 $ltypes = array();
146 foreach ($this->ltypes as $k => $l) {
147 if (in_array($k, $this->filter_link_types, true)) {
148 $ltypes[$k] = $l;
149 }
150 }
151 $this->ltypes = $ltypes;
152 }
153 // determine link type and target
154 $this->link_type = ($this->request->getLinkType() === "")
155 ? $this->default_link_type
156 : $this->request->getLinkType();
157 $ltype_arr = explode("_", $this->link_type);
158 $this->base_link_type = $ltype_arr[0];
159 $this->link_target = $ltype_arr[1] ?? "";
160
161
162 $def_type = ilObject::_lookupType($this->default_parent_obj_id);
163
164 // determine content object id
165 switch ($this->base_link_type) {
166 case "PageObject":
167 case "StructureObject":
168 case "GlossaryItem":
169 case "Media":
170 case "WikiPage":
171 case "PortfolioPage":
172 case "PortfolioTemplatePage":
173 if ($this->parent_ref_id === 0 && $this->parent_obj_id === 0
174 && $def_type === ($this->parent_type[$this->base_link_type] ?? "")) {
175 $this->parent_ref_id = $this->default_parent_ref_id;
176 $this->parent_obj_id = $this->default_parent_obj_id;
177 $ctrl->setParameter($this, "link_par_obj_id", $this->parent_obj_id);
178 $ctrl->setParameter($this, "link_par_ref_id", $this->parent_ref_id);
179 }
180 break;
181 }
182 }
183
184 public function setSetLinkTargetScript(string $a_script): void
185 {
186 $this->set_link_script = $a_script;
187 }
188
189 public function setReturn(string $a_return): void
190 {
191 $this->return = $a_return;
192 }
193
194 public function getSetLinkTargetScript(): string
195 {
197 }
198
199 public function filterLinkType(string $a_link_type): void
200 {
201 $this->filter_link_types[] = $a_link_type;
202 }
203
207 public function setFilterWhiteList(bool $a_white_list): void
208 {
209 $this->filter_white_list = $a_white_list;
210 }
211
212
213 public function executeCommand(): string
214 {
215 $this->init();
216 $next_class = $this->ctrl->getNextClass($this);
217
218 $cmd = $this->ctrl->getCmd("showLinkHelp");
219 switch ($next_class) {
220 default:
221 $ret = $this->$cmd();
222 break;
223 }
224
225 return (string) $ret;
226 }
227
228 public function resetLinkList(): void
229 {
231
232 $ctrl->setParameter($this, "link_par_ref_id", 0);
233 $ctrl->setParameter($this, "link_par_obj_id", 0);
234 $ctrl->setParameter($this, "link_par_fold_id", 0);
235 $ctrl->setParameter($this, "link_type", "");
236
237 $ctrl->redirect($this, "showLinkHelp", "", true);
238 }
239
240 public function closeLinkHelp(): void
241 {
242 if ($this->return === "") {
243 $this->ctrl->returnToParent($this);
244 } else {
245 ilUtil::redirect($this->return);
246 }
247 }
248
252 public function prepareJavascriptOutput(string $str): string
253 {
254 return htmlspecialchars($str, ENT_QUOTES);
255 }
256
257
261 public function showLinkHelp(): void
262 {
264 $ilCtrl = $this->ctrl;
265
266
267 $parent_type = $this->parent_type[$this->base_link_type] ?? "";
268 if ((in_array($this->base_link_type, array("GlossaryItem", "WikiPage", "PageObject", "StructureObject"), true) &&
269 ($this->parent_ref_id === 0))
270 ||
271 (($this->parent_ref_id > 0) &&
272 ilObject::_lookupType($this->parent_ref_id, true) !== $parent_type)) {
273 if ($parent_type !== "") {
274 $this->changeTargetObject($parent_type);
275 }
276 }
277 if ($ilCtrl->isAsynch()) {
278 $tpl = new ilGlobalTemplate("tpl.link_help_asynch.html", true, true, "Services/Link");
279 $tpl->setVariable("NEW_LINK_URL", $this->ctrl->getLinkTarget(
280 $this,
281 "",
282 false,
283 true,
284 false
285 ));
286 } else {
287 $tpl = new ilGlobalTemplate("tpl.link_help.html", true, true, "Services/Link");
288 $tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
289 }
290
291 $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "changeLinkType", "", true));
292 $tpl->setVariable("FORMACTION2", $this->ctrl->getFormAction($this));
293 $tpl->setVariable("TXT_HELP_HEADER", $this->lng->txt("cont_link_select"));
294 $tpl->setVariable("TXT_TYPE", $this->lng->txt("cont_link_type"));
295
296
298 $this->link_type,
299 "ltype",
300 $this->ltypes,
301 false,
302 true,
303 "0",
304 "",
305 array("id" => "ilIntLinkTypeSelector")
306 );
307 $tpl->setVariable("SELECT_TYPE", $select_ltype);
308 $tpl->setVariable("CMD_CHANGETYPE", "changeLinkType");
309 $tpl->setVariable("BTN_CHANGETYPE", $this->lng->txt("cont_change_type"));
310
311 $tpl->setVariable("CMD_CLOSE", "closeLinkHelp");
312 $tpl->setVariable("BTN_CLOSE", $this->lng->txt("close"));
313
314 $chapterRowBlock = "chapter_row_js";
315
316 // switch link type
317 switch ($this->base_link_type) {
318 // page link
319 case "PageObject":
320 $cont_obj = new ilObjLearningModule($this->parent_ref_id, true);
321
322 // get all chapters
323 $ctree = $cont_obj->getLMTree();
324 $nodes = $ctree->getSubTree($ctree->getNodeData($ctree->getRootId()));
325 $tpl->setCurrentBlock("chapter_list");
326 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("obj_lm"));
327 $tpl->setVariable("TXT_CONT_TITLE", $cont_obj->getTitle());
328 $tpl->setVariable("THEAD", $this->lng->txt("pages"));
329
330
331 $tpl->setCurrentBlock("change_cont_obj");
332 $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
333 $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
334 $tpl->parseCurrentBlock();
335
336 foreach ($nodes as $node) {
337 if ($node["type"] === "st") {
338 $tpl->setCurrentBlock("header_row");
339 $tpl->setVariable("TXT_HEADER", $node["title"]);
340 $tpl->parseCurrentBlock();
341 $tpl->setCurrentBlock("row");
342 $tpl->parseCurrentBlock();
343 }
344
345 if ($node["type"] === "pg") {
346 $this->renderLink(
347 $tpl,
348 $node["title"],
349 $node["obj_id"],
350 "PageObject",
351 "pg",
352 "page",
353 ilPCParagraph::_readAnchors("lm", $node["obj_id"], "")
354 );
355 }
356 }
357
358 // get all free pages
359 $pages = ilLMPageObject::getPageList($cont_obj->getId());
360 $free_pages = array();
361 foreach ($pages as $page) {
362 if (!$ctree->isInTree($page["obj_id"])) {
363 $free_pages[] = $page;
364 }
365 }
366 if (count($free_pages) > 0) {
367 $tpl->setCurrentBlock("header_row");
368 $tpl->setVariable("TXT_HEADER", $this->lng->txt("cont_free_pages"));
369 $tpl->parseCurrentBlock();
370
371 foreach ($free_pages as $node) {
372 $this->renderLink(
373 $tpl,
374 $node["title"],
375 $node["obj_id"],
376 "PageObject",
377 "pg",
378 "page",
379 ilPCParagraph::_readAnchors("lm", $node["obj_id"], "")
380 );
381 }
382 }
383
384 $tpl->setCurrentBlock("chapter_list");
385 $tpl->parseCurrentBlock();
386
387 break;
388
389 // chapter link
390 case "StructureObject":
391
392 // check whether current object matchs to type
393 if (ilObject::_lookupType($this->parent_ref_id, true) !== "lm") {
394 $this->changeTargetObject("lm");
395 }
396
397 $cont_obj = new ilObjLearningModule($this->parent_ref_id, true);
398
399 // get all chapters
400 $ctree = $cont_obj->getLMTree();
401 $nodes = $ctree->getSubTree($ctree->getNodeData($ctree->getRootId()));
402 $tpl->setCurrentBlock("chapter_list");
403 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("obj_lm"));
404 $tpl->setVariable("TXT_CONT_TITLE", $cont_obj->getTitle());
405 $tpl->setVariable("THEAD", $this->lng->txt("link_chapters"));
406 $tpl->setCurrentBlock("change_cont_obj");
407 $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
408 $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
409 $tpl->parseCurrentBlock();
410
411 foreach ($nodes as $node) {
412 if ($node["type"] === "st") {
413 $this->renderLink(
414 $tpl,
415 $node["title"],
416 $node["obj_id"],
417 "StructureObject",
418 "st",
419 "chap"
420 );
421 }
422 }
423 $tpl->setCurrentBlock("chapter_list");
424 $tpl->parseCurrentBlock();
425 break;
426
427 // glossary item link
428 case "GlossaryItem":
429 $glossary = new ilObjGlossary($this->parent_ref_id, true);
430
431 // get all glossary items
432 $terms = $glossary->getTermList();
433 $tpl->setCurrentBlock("chapter_list");
434 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("glossary"));
435 $tpl->setVariable("TXT_CONT_TITLE", $glossary->getTitle());
436 $tpl->setVariable("THEAD", $this->lng->txt("link_terms"));
437 $tpl->setCurrentBlock("change_cont_obj");
438 $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
439 $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
440 $tpl->parseCurrentBlock();
441
442 foreach ($terms as $term) {
443 $this->renderLink(
444 $tpl,
445 $term["term"],
446 $term["id"],
447 "GlossaryItem",
448 "git",
449 "term"
450 );
451 }
452
453 $tpl->setCurrentBlock("chapter_list");
454 $tpl->parseCurrentBlock();
455 break;
456
457 // media object
458 case "Media":
459 //$tpl->setVariable("TARGET2", " target=\"content\" ");
460 // content object id = 0 --> get clipboard objects
461 if ($this->parent_ref_id === 0) {
462 $tpl->setCurrentBlock("change_cont_obj");
463 $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
464 $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
465 $tpl->parseCurrentBlock();
466 $mobjs = $ilUser->getClipboardObjects("mob");
467 // sort by name
468 $objs = array();
469 foreach ($mobjs as $obj) {
470 $objs[$obj["title"] . ":" . $obj["id"]] = $obj;
471 }
472 ksort($objs);
473 $tpl->setCurrentBlock("chapter_list");
474 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("cont_media_source"));
475 $tpl->setVariable("TXT_CONT_TITLE", $this->lng->txt("cont_personal_clipboard"));
476 $tpl->setVariable("THEAD", $this->lng->txt("link_mobs"));
477 $tpl->setVariable("COLSPAN", "2");
478
479 foreach ($objs as $obj) {
480 $this->renderLink(
481 $tpl,
482 $obj["title"],
483 $obj["id"],
484 "MediaObject",
485 "mob",
486 "media"
487 );
488 }
489 } else {
490 $med_pool = new ilObjMediaPool($this->parent_ref_id, true);
491 // get current folders
492 $fobjs = $med_pool->getChilds($this->parent_fold_id, "fold");
493 $f2objs = array();
494 foreach ($fobjs as $obj) {
495 $f2objs[$obj["title"] . ":" . $obj["child"]] = $obj;
496 }
497 ksort($f2objs);
498 // get current media objects
499 $mobjs = $med_pool->getChilds($this->parent_fold_id, "mob");
500 $m2objs = array();
501 foreach ($mobjs as $obj) {
502 $m2objs[$obj["title"] . ":" . $obj["child"]] = $obj;
503 }
504 ksort($m2objs);
505
506 // merge everything together
507 $objs = array_merge($f2objs, $m2objs);
508
509 $tpl->setCurrentBlock("chapter_list");
510 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("mep"));
511 $tpl->setVariable("TXT_CONT_TITLE", $med_pool->getTitle());
512 $tpl->setVariable("THEAD", $this->lng->txt("link_mobs"));
513 $tpl->setCurrentBlock("change_cont_obj");
514 $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
515 $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
516 $tpl->setVariable("COLSPAN", "2");
517 $tpl->parseCurrentBlock();
518 if ($parent_id = $med_pool->getParentId($this->parent_fold_id)) {
519 $tpl->setCurrentBlock("icon");
520 $tpl->setVariable("ICON_SRC", ilUtil::getImagePath("icon_fold.svg"));
521 $tpl->parseCurrentBlock();
522 $tpl->setCurrentBlock("link_row");
523 $tpl->setVariable("TXT_CHAPTER", "..");
524 $this->ctrl->setParameter($this, "mep_fold", $parent_id);
525 if ($ilCtrl->isAsynch()) {
526 $tpl->setVariable("LINK", "#");
527 $tpl->setVariable(
528 "LR_ONCLICK",
529 " onclick=\"return il.IntLink.setMepPoolFolder('" . $parent_id . "');\" "
530 );
531 } else {
532 $tpl->setVariable(
533 "LINK",
534 $this->ctrl->getLinkTarget($this, "setMedPoolFolder")
535 );
536 }
537 $tpl->parseCurrentBlock();
538 $tpl->setCurrentBlock("row");
539 $tpl->parseCurrentBlock();
540 }
541 foreach ($objs as $obj) {
542 if ($obj["type"] === "fold") {
543 $tpl->setCurrentBlock("icon");
544 $tpl->setVariable("ICON_SRC", ilUtil::getImagePath("icon_fold.svg"));
545 $tpl->parseCurrentBlock();
546 $tpl->setCurrentBlock("link_row");
547 $tpl->setVariable("TXT_CHAPTER", $obj["title"]);
548 $this->ctrl->setParameter($this, "mep_fold", $obj["child"]);
549 if ($ilCtrl->isAsynch()) {
550 $tpl->setVariable("LINK", "#");
551 $tpl->setVariable(
552 "LR_ONCLICK",
553 " onclick=\"return il.IntLink.setMepPoolFolder('" . $obj["child"] . "');\" "
554 );
555 } else {
556 $tpl->setVariable(
557 "LINK",
558 $this->ctrl->getLinkTarget($this, "setMedPoolFolder")
559 );
560 }
561 $tpl->parseCurrentBlock();
562 } else {
563 $fid = ilMediaPoolItem::lookupForeignId($obj["child"]);
564 if (ilObject::_lookupType($fid) === "mob") {
565 $this->renderLink(
566 $tpl,
567 $obj["title"],
568 $fid,
569 "MediaObject",
570 "mob",
571 "media"
572 );
573 }
574 }
575 $tpl->setCurrentBlock("row");
576 $tpl->parseCurrentBlock();
577 }
578 }
579 $tpl->setCurrentBlock("chapter_list");
580 $tpl->parseCurrentBlock();
581 break;
582
583 // wiki page link
584 case "WikiPage":
585 $wiki_id = ilObject::_lookupObjId($this->parent_ref_id);
586 $wpages = ilWikiPage::getAllWikiPages($wiki_id);
587
588 // get all glossary items
589 $tpl->setCurrentBlock("chapter_list");
590 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("obj_wiki"));
591 $tpl->setVariable("TXT_CONT_TITLE", ilObject::_lookupTitle($wiki_id));
592 $tpl->setVariable("THEAD", $this->lng->txt("link_wpages"));
593 $tpl->setCurrentBlock("change_cont_obj");
594 $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
595 $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
596 $tpl->parseCurrentBlock();
597
598 foreach ($wpages as $wpage) {
599 $this->renderLink(
600 $tpl,
601 $wpage["title"],
602 $wpage["id"],
603 "WikiPage",
604 "wpage",
605 "wpage",
606 ilPCParagraph::_readAnchors("wpg", $wpage["id"], "")
607 );
608 }
609 $tpl->setCurrentBlock("chapter_list");
610 $tpl->parseCurrentBlock();
611 break;
612
613 // Portfolio page link
614 case "PortfolioPage":
615 case "PortfolioTemplatePage":
616 $prtf_id = $this->parent_obj_id;
617 $ppages = ilPortfolioPage::getAllPortfolioPages($prtf_id);
618
619 // get all glossary items
620 $tpl->setCurrentBlock("chapter_list");
621 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("obj_" . ilObject::_lookupType($prtf_id)));
622 $tpl->setVariable("TXT_CONT_TITLE", ilObject::_lookupTitle($prtf_id));
623 $tpl->setVariable("THEAD", $this->lng->txt("pages"));
624
625 foreach ($ppages as $ppage) {
626 $this->renderLink(
627 $tpl,
628 $ppage["title"],
629 $ppage["id"],
630 "PortfolioPage",
631 "ppage",
632 "ppage",
633 array(),
634 $ppage["title"]
635 );
636 }
637
638 $tpl->setCurrentBlock("chapter_list");
639 $tpl->parseCurrentBlock();
640 break;
641
642 // repository item
643 case "RepositoryItem":
644 $tpl->setVariable("LINK_HELP_CONTENT", $this->selectRepositoryItem());
645 break;
646
647 // file download link
648 case "File":
649 if (!isset($this->uploaded_file)) {
650 $tpl->setVariable("LINK_HELP_CONTENT", $this->getFileLinkHTML());
651 } else {
652 echo $this->getFileLinkHTML();
653 exit;
654 }
655 break;
656
657 // file download link
658 case "User":
659 $tpl->setVariable("LINK_HELP_CONTENT", $this->addUser());
660 break;
661
662 }
663
664 if ($ilCtrl->isAsynch()) {
665 echo $tpl->get();
666 exit;
667 }
668
669 exit;
670 }
671
675 public function getFileLinkHTML(): string
676 {
678 $ilCtrl = $this->ctrl;
679
680 $tpl = new ilTemplate("tpl.link_file.html", true, true, "Services/Link");
681 if (!is_object($this->uploaded_file)) {
682 $tpl->setCurrentBlock("form");
683 $tpl->setVariable(
684 "FORM_ACTION",
685 $ilCtrl->getFormAction($this, "saveFileLink", "", true)
686 );
687 $tpl->setVariable("TXT_SELECT_FILE", $lng->txt("cont_select_file"));
688 $tpl->setVariable("TXT_SAVE_LINK", $lng->txt("cont_create_link"));
689 $tpl->setVariable("CMD_SAVE_LINK", "saveFileLink");
690 $fi = new ilFileInputGUI("", "link_file");
691 $fi->setSize(15);
692 $tpl->setVariable("INPUT", $fi->getToolbarHTML());
693 $tpl->parseCurrentBlock();
694 } else {
695 $tpl->setCurrentBlock("link_js");
696 // $tpl->setVariable("LINK_FILE",
697 // $this->prepareJavascriptOutput("[iln dfile=\"".$this->uploaded_file->getId()."\"] [/iln]")
698 // );
699 $tpl->setVariable(
700 "TAG_B",
701 '[iln dfile=\x22' . $this->uploaded_file->getId() . '\x22]'
702 );
703 $tpl->setVariable(
704 "TAG_E",
705 "[/iln]"
706 );
707 $tpl->setVariable(
708 "TXT_FILE",
709 $this->uploaded_file->getTitle()
710 );
711 // $tpl->parseCurrentBlock();
712 }
713 return $tpl->get();
714 }
715
719 public function saveFileLink(): void
720 {
721 if ($_FILES["link_file"]["name"] != "") {
722 $fileObj = new ilObjFile();
723 $fileObj->setType("file");
724 $fileObj->setTitle($_FILES["link_file"]["name"]);
725 $fileObj->setDescription("");
726 $fileObj->setFileName($_FILES["link_file"]["name"]);
727 $fileObj->setMode("filelist");
728 $fileObj->create();
729 // upload file to filesystem
730 $fileObj->getUploadFile(
731 $_FILES["link_file"]["tmp_name"],
732 $_FILES["link_file"]["name"]
733 );
734 $this->uploaded_file = $fileObj;
735 }
736 $this->showLinkHelp();
737 }
738
742 public function outputThumbnail(
744 int $a_id,
745 string $a_mode = ""
746 ): void {
747 // output thumbnail
748 $mob = new ilObjMediaObject($a_id);
749 $med = $mob->getMediaItem("Standard");
750 $target = $med->getThumbnailTarget("small");
751 $suff = "";
752 if ($this->getSetLinkTargetScript() !== "") {
753 $tpl->setCurrentBlock("thumbnail_link");
754 $suff = "_link";
755 } else {
756 $tpl->setCurrentBlock("thumbnail_js");
757 $suff = "_js";
758 }
759
760 if ($target !== "") {
761 $tpl->setCurrentBlock("thumb" . $suff);
762 $tpl->setVariable("SRC_THUMB", $target);
763 $tpl->parseCurrentBlock();
764 } else {
765 $tpl->setVariable("NO_THUMB", "&nbsp;");
766 }
767
768 if ($this->getSetLinkTargetScript() !== "") {
769 $tpl->setCurrentBlock("thumbnail_link");
770 } else {
771 $tpl->setCurrentBlock("thumbnail_js");
772 }
773 $tpl->parseCurrentBlock();
774 }
775
776 public function changeLinkType(): void
777 {
778 $ctrl = $this->ctrl;
779
780 $ctrl->setParameter($this, "link_type", $this->request->getLinkType());
781 $base_type = explode("_", $this->request->getLinkType())[0];
782 if ($this->parent_type[$base_type] !== ilObject::_lookupType($this->parent_ref_id, true)) {
783 $ctrl->setParameter($this, "link_par_ref_id", 0);
784 $ctrl->setParameter($this, "link_par_obj_id", 0);
785 }
786
787 $ctrl->redirect($this, "showLinkHelp", "", true);
788 }
789
793 public function setMedPoolFolder(): void
794 {
795 $ctrl = $this->ctrl;
796 $ctrl->setParameter($this, "link_par_fold_id", $this->request->getMediaPoolFolder());
797 $ctrl->redirect($this, "showLinkHelp", "", true);
798 }
799
803 public function getTargetExplorer(): string
804 {
805 //$ilCtrl->setParameter($this, "target_type", $a_type);
806 $exp = new ilLinkTargetObjectExplorerGUI($this, "getTargetExplorer", $this->link_type);
807
808 $a_type = $this->parent_type[$this->base_link_type] ?? "";
809
810 $white = array("root", "cat", "crs", "fold", "grp");
811
812 $white[] = $a_type;
813 $exp->setClickableType($a_type);
814 if ($a_type === "prtf") {
815 $white[] = "prtt";
816 $exp->setClickableType("prtt");
817 }
818
819 $exp->setTypeWhiteList($white);
820
821
822 if (!$exp->handleCommand()) {
823 return $exp->getHTML();
824 }
825 return "";
826 }
827
831 public function changeTargetObject(
832 string $a_type = ""
833 ): void {
834 $ilCtrl = $this->ctrl;
835
836 $ilCtrl->setParameter($this, "link_par_fold_id", "");
837 if ($this->request->getDo() === "set") {
838 $ilCtrl->setParameter($this, "link_par_ref_id", $this->request->getSelectedId());
839 $ilCtrl->redirect($this, "showLinkHelp", "", true);
840 return;
841 }
842
843 $ilCtrl->setParameter($this, "link_type", $this->link_type);
844
845 $tpl = new ilTemplate("tpl.link_help_explorer.html", true, true, "Services/Link");
846
847 $output = $this->getTargetExplorer();
848
849 $tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_choose_" . ($this->parent_type[$this->base_link_type] ?? "")));
850
851 $tpl->setVariable("EXPLORER", $output);
852 $tpl->setVariable("ACTION", $this->ctrl->getFormAction($this, "resetLinkList", "", true));
853 $tpl->setVariable("BTN_RESET", "resetLinkList");
854 $tpl->setVariable("TXT_RESET", $this->lng->txt("back"));
855
856 if (($this->parent_type[$this->base_link_type] ?? "") === "mep") {
857 $tpl->setCurrentBlock("sel_clipboard");
858 $this->ctrl->setParameter($this, "do", "set");
859 if ($ilCtrl->isAsynch()) {
860 $tpl->setVariable("LINK_CLIPBOARD", "#");
861 $tpl->setVariable(
862 "CLIPBOARD_ONCLICK",
863 " onclick=\"return il.IntLink.selectLinkTargetObject('mep', 0, '" . $this->link_type . "');\" "
864 );
865 } else {
866 $tpl->setVariable("LINK_CLIPBOARD", $this->ctrl->getLinkTarget($this, "changeTargetObject"));
867 }
868 $tpl->setVariable("TXT_PERS_CLIPBOARD", $this->lng->txt("clipboard"));
869 $tpl->parseCurrentBlock();
870 }
871
872 $tpl->parseCurrentBlock();
873
874 echo $tpl->get();
875 exit;
876 }
877
878
882 public function selectRepositoryItem(): string
883 {
884 $ilCtrl = $this->ctrl;
885
886 $ilCtrl->setParameter($this, "link_par_fold_id", "");
887
888 $exp = new ilIntLinkRepItemExplorerGUI($this, "selectRepositoryItem");
889 $exp->setSetLinkTargetScript($this->getSetLinkTargetScript());
890
891 if (!$exp->handleCommand()) {
892 return $exp->getHTML();
893 }
894 return "";
895 }
896
900 public function refreshRepositorySelector(): void
901 {
902 $output = $this->selectRepositoryItem();
903 echo $output;
904 exit;
905 }
906
907 public static function getOnloadCode(string $a_url): string
908 {
909 return "il.Util.addOnLoad(function() {il.IntLink.init({url: '$a_url'});});";
910 }
911
915 public static function getInitHTML(string $a_url): string
916 {
917 global $DIC;
918
919 $lng = $DIC->language();
920 $tpl = $DIC["tpl"];
921
922 $tpl->addOnLoadCode(
923 self::getOnloadCode($a_url)
924 );
925
926 $lng->loadLanguageModule("link");
927
928 $tpl->addJavaScript("./Services/UIComponent/Explorer/js/ilExplorer.js");
931
932 $tpl->addJavascript("./Services/Link/js/ilIntLink.js");
933 // #18721
934 $tpl->addJavaScript("Services/Form/js/Form.js");
935
936 $modal = ilModalGUI::getInstance();
937 $modal->setHeading($lng->txt("link_link"));
938 $modal->setId("ilIntLinkModal");
939 $modal->setBody("<div id='ilIntLinkModalContent'></div>");
940
941 return $modal->getHTML();
942 }
943
947 public function renderLink(
949 string $a_title,
950 int $a_obj_id,
951 string $a_type,
952 string $a_type_short,
953 string $a_bb_type,
954 array $a_anchors = array(),
955 string $a_link_content = ""
956 ): void {
957 $chapterRowBlock = "chapter_row_js";
958 $anchor_row_block = "anchor_link_js";
959
960 $target_str = ($this->link_target === "")
961 ? ""
962 : " target=\"" . $this->link_target . "\"";
963
964 if (count($a_anchors) > 0) {
965 foreach ($a_anchors as $anchor) {
966 if ($this->getSetLinkTargetScript() !== "") {
967 // not implemented yet (anchors that work with map areas)
968
969 /*$tpl->setCurrentBlock("anchor_link");
970 $tpl->setVariable("ALINK",
971 ilUtil::appendUrlParameterString($this->getSetLinkTargetScript(),
972 "linktype=".$a_type.
973 "&linktarget=il__".$a_type_short."_".$a_obj_id.
974 "&linktargetframe=".$this->link_target).
975 "&linkanchor=".$anchor);
976 $tpl->setVariable("TXT_ALINK", "#" . $anchor);
977 $tpl->parseCurrentBlock();*/
978 } else {
979 $tpl->setCurrentBlock($anchor_row_block);
980 $tpl->setVariable(
981 "ALINK_BEGIN",
982 $this->prepareJavascriptOutput("[iln " . $a_bb_type . "=\"" . $a_obj_id . "\"" . $target_str . " anchor=\"$anchor\"]")
983 );
984 $tpl->setVariable("ALINK_END", "[/iln]");
985 $tpl->setVariable("TXT_LINK", "#" . $anchor);
986 $tpl->parseCurrentBlock();
987 }
988 }
989 }
990
991 if ($this->getSetLinkTargetScript() !== "") {
993 if ($a_type === "MediaObject") {
994 $this->outputThumbnail($tpl, $a_obj_id);
995 }
996 $tpl->setCurrentBlock("link_row");
997 $tpl->setVariable("TXT_CHAPTER", $a_title);
998 $tpl->setVariable(
999 "LINK",
1001 $this->getSetLinkTargetScript(),
1002 "linktype=" . $a_type .
1003 "&linktarget=il__" . $a_type_short . "_" . $a_obj_id .
1004 "&linktargetframe=" . $this->link_target
1005 )
1006 );
1007 } else {
1008 $tpl->setCurrentBlock($chapterRowBlock);
1009 if ($a_type === "MediaObject") {
1010 $this->outputThumbnail($tpl, $a_obj_id);
1011 $tpl->setCurrentBlock($chapterRowBlock);
1012 }
1013 $tpl->setVariable("TXT_CHAPTER", $a_title);
1014 if ($a_type === "MediaObject" && empty($target_str)) {
1015 $tpl->setVariable(
1016 "LINK_BEGIN",
1017 $this->prepareJavascriptOutput("[iln " . $a_bb_type . "=\"" . $a_obj_id . "\"/]")
1018 );
1019 $tpl->setVariable("LINK_END", "");
1020 } else {
1021 $tpl->setVariable(
1022 "LINK_BEGIN",
1023 $this->prepareJavascriptOutput("[iln " . $a_bb_type . "=\"" . $a_obj_id . "\"" . $target_str . "]")
1024 );
1025 $tpl->setVariable("LINK_CONTENT", $a_link_content);
1026 $tpl->setVariable("LINK_END", "[/iln]");
1027 }
1028 }
1029 $tpl->parseCurrentBlock();
1030
1031 $tpl->setCurrentBlock("row");
1032 $tpl->parseCurrentBlock();
1033 }
1034
1038 public function addUser(): string
1039 {
1040 $form = $this->initUserSearchForm();
1041 return $form->getHTML() . $this->getUserSearchResult();
1042 }
1043
1048 {
1049 $form = new ilPropertyFormGUI();
1050 $form->setId("link_user_search_form");
1051
1052 // user search
1053 $ti = new ilTextInputGUI($this->lng->txt("obj_user"), "usr_search_str");
1054 $ti->setValue($this->request->getUserSearchStr());
1055 $form->addItem($ti);
1056
1057 $form->addCommandButton("searchUser", $this->lng->txt("search"));
1058
1059 return $form;
1060 }
1061
1065 public function getUserSearchResult(): string
1066 {
1067 global $DIC;
1068
1069 $lng = $DIC->language();
1070
1071 if (strlen($this->request->getUserSearchStr()) < 3) {
1072 if (strlen($this->request->getUserSearchStr()) > 0) {
1073 $lng->loadLanguageModule("search");
1074 return ilUtil::getSystemMessageHTML($lng->txt("search_minimum_three"), "info");
1075 }
1076
1077 return "";
1078 }
1079
1080 $form = $this->initUserSearchForm();
1081 $form->checkInput();
1082
1083 $users = ilInternalLink::searchUsers($form->getInput("usr_search_str"));
1084 if (count($users) === 0) {
1085 return ilUtil::getSystemMessageHTML($lng->txt("cont_user_search_did_not_match"), "info");
1086 }
1087
1088 $f = $DIC->ui()->factory();
1089 $r = $DIC->ui()->renderer();
1090 $lng = $DIC->language();
1091 $cards = array();
1092 foreach ($users as $user) {
1093 $b = $f->button()->standard($lng->txt("insert"), "#")
1094 ->withOnLoadCode(function ($id) use ($user) {
1095 return
1096 '$("#' . $id . "\").click(function(ev) { il.IntLink.addInternalLink('[iln user=\"" .
1097 ilObjUser::_lookupLogin($user) . "\"/]', '', ev); return false;});";
1098 });
1100 $cards[] = $f->card()->standard($name, $f->image()->responsive(ilObjUser::_getPersonalPicturePath($user, "small"), $name))
1101 ->withSections(array($b));
1102 }
1103 $deck = $f->deck($cards)->withLargeCardsSize();
1104
1105 return $r->renderAsync($deck);
1106 }
1107}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilCtrl provides processing control methods.
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
static init(ilGlobalTemplateInterface $a_main_tpl=null)
This class represents a file property in a property form.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
parseCurrentBlock(string $part=self::DEFAULT_BLOCK)
static _recoverParameters()
Recover parameters from session variables (static)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Internal link selector.
renderLink(ilGlobalTemplate $tpl, string $a_title, int $a_obj_id, string $a_type, string $a_type_short, string $a_bb_type, array $a_anchors=array(), string $a_link_content="")
Render internal link item.
refreshRepositorySelector()
Refresh Repository Selector.
StandardGUIRequest $request
setMedPoolFolder()
select media pool folder
getTargetExplorer()
Cange target object.
setFilterWhiteList(bool $a_white_list)
Set filter list as white list (per detault it is a black list)
saveFileLink()
Save file link.
static getOnloadCode(string $a_url)
__construct(string $a_default_link_type, int $a_default_parent_id, bool $a_is_ref=true)
setSetLinkTargetScript(string $a_script)
selectRepositoryItem()
select repository item explorer
prepareJavascriptOutput(string $str)
Prepare output for JS enabled editing.
getFileLinkHTML()
Get HTML for file link.
initUserSearchForm()
Init user search form.
filterLinkType(string $a_link_type)
changeTargetObject(string $a_type="")
Cange target object.
showLinkHelp()
Show link help list.
setReturn(string $a_return)
static getInitHTML(string $a_url)
Get initialisation HTML to use internal link editing.
outputThumbnail(ilGlobalTemplate $tpl, int $a_id, string $a_mode="")
output thumbnail
static getPageList(int $lm_id)
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupForeignId(int $a_id)
static getInstance()
Class ilObjFile.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMediaItem(string $a_purpose)
get item for media purpose
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
static _lookupLogin(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static _readAnchors(string $a_parent_type, int $a_page_id, string $a_page_lang="-")
Read anchors of a page.
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
This class represents a property form user interface.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isInTree(?int $a_node_id)
get all information of a node.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
static redirect(string $a_script)
static getAllWikiPages(int $a_wiki_id)
static initConnection(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
exit
Definition: login.php:28
if($format !==null) $name
Definition: metadata.php:247
$lng