ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  {
99  $lng = $this->lng;
100  $tree = $this->tree;
101  $ctrl = $this->ctrl;
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  {
196  return $this->set_link_script;
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  {
230  $ctrl = $this->ctrl;
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  {
263  $ilUser = $this->user;
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 
297  $select_ltype = ilLegacyFormElementsUtil::formSelect(
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("standard/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("standard/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  if ($ilCtrl->isAsynch()) {
664  echo $tpl->get();
665  exit;
666  }
667 
668  exit;
669  }
670 
674  public function getFileLinkHTML(): string
675  {
676  $lng = $this->lng;
677  $ilCtrl = $this->ctrl;
678 
679  $tpl = new ilTemplate("tpl.link_file.html", true, true, "Services/Link");
680  if (!is_object($this->uploaded_file)) {
681  $tpl->setCurrentBlock("form");
682  $tpl->setVariable(
683  "FORM_ACTION",
684  $ilCtrl->getFormAction($this, "saveFileLink", "", true)
685  );
686  $tpl->setVariable("TXT_SELECT_FILE", $lng->txt("cont_select_file"));
687  $tpl->setVariable("TXT_SAVE_LINK", $lng->txt("cont_create_link"));
688  $tpl->setVariable("CMD_SAVE_LINK", "saveFileLink");
689  $fi = new ilFileInputGUI("", "link_file");
690  $fi->setSize(15);
691  $tpl->setVariable("INPUT", $fi->getToolbarHTML());
692  $tpl->parseCurrentBlock();
693  } else {
694  $tpl->setCurrentBlock("link_js");
695  // $tpl->setVariable("LINK_FILE",
696  // $this->prepareJavascriptOutput("[iln dfile=\"".$this->uploaded_file->getId()."\"] [/iln]")
697  // );
698  $tpl->setVariable(
699  "TAG_B",
700  '[iln dfile=\x22' . $this->uploaded_file->getId() . '\x22]'
701  );
702  $tpl->setVariable(
703  "TAG_E",
704  "[/iln]"
705  );
706  $tpl->setVariable(
707  "TXT_FILE",
708  $this->uploaded_file->getTitle()
709  );
710  // $tpl->parseCurrentBlock();
711  }
712  return $tpl->get();
713  }
714 
718  public function saveFileLink(): void
719  {
720  if ($_FILES["link_file"]["name"] != "") {
721  $fileObj = new ilObjFile();
722  $fileObj->setType("file");
723  $fileObj->setTitle($_FILES["link_file"]["name"]);
724  $fileObj->setDescription("");
725  $fileObj->setFileName($_FILES["link_file"]["name"]);
726  $fileObj->setMode("filelist");
727  $fileObj->create();
728  // upload file to filesystem
729  $fileObj->getUploadFile(
730  $_FILES["link_file"]["tmp_name"],
731  $_FILES["link_file"]["name"]
732  );
733  $this->uploaded_file = $fileObj;
734  }
735  $this->showLinkHelp();
736  }
737 
741  public function outputThumbnail(
742  ilGlobalTemplate $tpl,
743  int $a_id,
744  string $a_mode = ""
745  ): void {
746  // output thumbnail
747  $mob = new ilObjMediaObject($a_id);
748  $med = $mob->getMediaItem("Standard");
749  $target = $med->getThumbnailTarget("small");
750  $suff = "";
751  if ($this->getSetLinkTargetScript() !== "") {
752  $tpl->setCurrentBlock("thumbnail_link");
753  $suff = "_link";
754  } else {
755  $tpl->setCurrentBlock("thumbnail_js");
756  $suff = "_js";
757  }
758 
759  if ($target !== "") {
760  $tpl->setCurrentBlock("thumb" . $suff);
761  $tpl->setVariable("SRC_THUMB", $target);
762  $tpl->parseCurrentBlock();
763  } else {
764  $tpl->setVariable("NO_THUMB", "&nbsp;");
765  }
766 
767  if ($this->getSetLinkTargetScript() !== "") {
768  $tpl->setCurrentBlock("thumbnail_link");
769  } else {
770  $tpl->setCurrentBlock("thumbnail_js");
771  }
772  $tpl->parseCurrentBlock();
773  }
774 
775  public function changeLinkType(): void
776  {
777  $ctrl = $this->ctrl;
778 
779  $ctrl->setParameter($this, "link_type", $this->request->getLinkType());
780  $base_type = explode("_", $this->request->getLinkType())[0];
781  if ($this->parent_type[$base_type] !== ilObject::_lookupType($this->parent_ref_id, true)) {
782  $ctrl->setParameter($this, "link_par_ref_id", 0);
783  $ctrl->setParameter($this, "link_par_obj_id", 0);
784  }
785 
786  $ctrl->redirect($this, "showLinkHelp", "", true);
787  }
788 
792  public function setMedPoolFolder(): void
793  {
794  $ctrl = $this->ctrl;
795  $ctrl->setParameter($this, "link_par_fold_id", $this->request->getMediaPoolFolder());
796  $ctrl->redirect($this, "showLinkHelp", "", true);
797  }
798 
802  public function getTargetExplorer(): string
803  {
804  //$ilCtrl->setParameter($this, "target_type", $a_type);
805  $exp = new ilLinkTargetObjectExplorerGUI($this, "getTargetExplorer", $this->link_type);
806 
807  $a_type = $this->parent_type[$this->base_link_type] ?? "";
808 
809  $white = array("root", "cat", "crs", "fold", "grp");
810 
811  $white[] = $a_type;
812  $exp->setClickableType($a_type);
813  if ($a_type === "prtf") {
814  $white[] = "prtt";
815  $exp->setClickableType("prtt");
816  }
817 
818  $exp->setTypeWhiteList($white);
819 
820 
821  if (!$exp->handleCommand()) {
822  return $exp->getHTML();
823  }
824  return "";
825  }
826 
830  public function changeTargetObject(
831  string $a_type = ""
832  ): void {
833  $ilCtrl = $this->ctrl;
834 
835  $ilCtrl->setParameter($this, "link_par_fold_id", "");
836  if ($this->request->getDo() === "set") {
837  $ilCtrl->setParameter($this, "link_par_ref_id", $this->request->getSelectedId());
838  $ilCtrl->redirect($this, "showLinkHelp", "", true);
839  return;
840  }
841 
842  $ilCtrl->setParameter($this, "link_type", $this->link_type);
843 
844  $tpl = new ilTemplate("tpl.link_help_explorer.html", true, true, "Services/Link");
845 
846  $output = $this->getTargetExplorer();
847 
848  $tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_choose_" . ($this->parent_type[$this->base_link_type] ?? "")));
849 
850  $tpl->setVariable("EXPLORER", $output);
851  $tpl->setVariable("ACTION", $this->ctrl->getFormAction($this, "resetLinkList", "", true));
852  $tpl->setVariable("BTN_RESET", "resetLinkList");
853  $tpl->setVariable("TXT_RESET", $this->lng->txt("back"));
854 
855  if (($this->parent_type[$this->base_link_type] ?? "") === "mep") {
856  $tpl->setCurrentBlock("sel_clipboard");
857  $this->ctrl->setParameter($this, "do", "set");
858  if ($ilCtrl->isAsynch()) {
859  $tpl->setVariable("LINK_CLIPBOARD", "#");
860  $tpl->setVariable(
861  "CLIPBOARD_ONCLICK",
862  " onclick=\"return il.IntLink.selectLinkTargetObject('mep', 0, '" . $this->link_type . "');\" "
863  );
864  } else {
865  $tpl->setVariable("LINK_CLIPBOARD", $this->ctrl->getLinkTarget($this, "changeTargetObject"));
866  }
867  $tpl->setVariable("TXT_PERS_CLIPBOARD", $this->lng->txt("clipboard"));
868  $tpl->parseCurrentBlock();
869  }
870 
871  $tpl->parseCurrentBlock();
872 
873  echo $tpl->get();
874  exit;
875  }
876 
877 
881  public function selectRepositoryItem(): string
882  {
883  $ilCtrl = $this->ctrl;
884 
885  $ilCtrl->setParameter($this, "link_par_fold_id", "");
886 
887  $exp = new ilIntLinkRepItemExplorerGUI($this, "selectRepositoryItem");
888  $exp->setSetLinkTargetScript($this->getSetLinkTargetScript());
889 
890  if (!$exp->handleCommand()) {
891  return $exp->getHTML();
892  }
893  return "";
894  }
895 
899  public function refreshRepositorySelector(): void
900  {
901  $output = $this->selectRepositoryItem();
902  echo $output;
903  exit;
904  }
905 
906  public static function getOnloadCode(string $a_url): string
907  {
908  return "il.Util.addOnLoad(function() {il.IntLink.init({url: '$a_url'});});";
909  }
910 
914  public static function getInitHTML(string $a_url): string
915  {
916  global $DIC;
917 
918  $lng = $DIC->language();
919  $tpl = $DIC["tpl"];
920 
921  $tpl->addOnLoadCode(
922  self::getOnloadCode($a_url)
923  );
924 
925  $lng->loadLanguageModule("link");
926 
927  $tpl->addJavaScript("./Services/UIComponent/Explorer/js/ilExplorer.js");
929 
930  $tpl->addJavascript("./Services/Link/js/ilIntLink.js");
931  // #18721
932  $tpl->addJavaScript("Services/Form/js/Form.js");
933 
934  $modal = ilModalGUI::getInstance();
935  $modal->setHeading($lng->txt("link_link"));
936  $modal->setId("ilIntLinkModal");
937  $modal->setBody("<div id='ilIntLinkModalContent'></div>");
938 
939  return $modal->getHTML();
940  }
941 
945  public function renderLink(
946  ilGlobalTemplate $tpl,
947  string $a_title,
948  int $a_obj_id,
949  string $a_type,
950  string $a_type_short,
951  string $a_bb_type,
952  array $a_anchors = array(),
953  string $a_link_content = ""
954  ): void {
955  $chapterRowBlock = "chapter_row_js";
956  $anchor_row_block = "anchor_link_js";
957 
958  $target_str = ($this->link_target === "")
959  ? ""
960  : " target=\"" . $this->link_target . "\"";
961 
962  if (count($a_anchors) > 0) {
963  foreach ($a_anchors as $anchor) {
964  if ($this->getSetLinkTargetScript() !== "") {
965  // not implemented yet (anchors that work with map areas)
966 
967  /*$tpl->setCurrentBlock("anchor_link");
968  $tpl->setVariable("ALINK",
969  ilUtil::appendUrlParameterString($this->getSetLinkTargetScript(),
970  "linktype=".$a_type.
971  "&linktarget=il__".$a_type_short."_".$a_obj_id.
972  "&linktargetframe=".$this->link_target).
973  "&linkanchor=".$anchor);
974  $tpl->setVariable("TXT_ALINK", "#" . $anchor);
975  $tpl->parseCurrentBlock();*/
976  } else {
977  $tpl->setCurrentBlock($anchor_row_block);
978  $tpl->setVariable(
979  "ALINK_BEGIN",
980  $this->prepareJavascriptOutput("[iln " . $a_bb_type . "=\"" . $a_obj_id . "\"" . $target_str . " anchor=\"$anchor\"]")
981  );
982  $tpl->setVariable("ALINK_END", "[/iln]");
983  $tpl->setVariable("TXT_LINK", "#" . $anchor);
984  $tpl->parseCurrentBlock();
985  }
986  }
987  }
988 
989  if ($this->getSetLinkTargetScript() !== "") {
991  if ($a_type === "MediaObject") {
992  $this->outputThumbnail($tpl, $a_obj_id);
993  }
994  $tpl->setCurrentBlock("link_row");
995  $tpl->setVariable("TXT_CHAPTER", $a_title);
996  $tpl->setVariable(
997  "LINK",
999  $this->getSetLinkTargetScript(),
1000  "linktype=" . $a_type .
1001  "&linktarget=il__" . $a_type_short . "_" . $a_obj_id .
1002  "&linktargetframe=" . $this->link_target
1003  )
1004  );
1005  } else {
1006  $tpl->setCurrentBlock($chapterRowBlock);
1007  if ($a_type === "MediaObject") {
1008  $this->outputThumbnail($tpl, $a_obj_id);
1009  $tpl->setCurrentBlock($chapterRowBlock);
1010  }
1011  $tpl->setVariable("TXT_CHAPTER", $a_title);
1012  if ($a_type === "MediaObject" && empty($target_str)) {
1013  $tpl->setVariable(
1014  "LINK_BEGIN",
1015  $this->prepareJavascriptOutput("[iln " . $a_bb_type . "=\"" . $a_obj_id . "\"/]")
1016  );
1017  $tpl->setVariable("LINK_END", "");
1018  } else {
1019  $tpl->setVariable(
1020  "LINK_BEGIN",
1021  $this->prepareJavascriptOutput("[iln " . $a_bb_type . "=\"" . $a_obj_id . "\"" . $target_str . "]")
1022  );
1023  $tpl->setVariable("LINK_CONTENT", $a_link_content);
1024  $tpl->setVariable("LINK_END", "[/iln]");
1025  }
1026  }
1027  $tpl->parseCurrentBlock();
1028 
1029  $tpl->setCurrentBlock("row");
1030  $tpl->parseCurrentBlock();
1031  }
1032 
1036  public function addUser(): string
1037  {
1038  $form = $this->initUserSearchForm();
1039  return $form->getHTML() . $this->getUserSearchResult();
1040  }
1041 
1046  {
1047  $form = new ilPropertyFormGUI();
1048  $form->setId("link_user_search_form");
1049 
1050  // user search
1051  $ti = new ilTextInputGUI($this->lng->txt("obj_user"), "usr_search_str");
1052  $ti->setValue($this->request->getUserSearchStr());
1053  $form->addItem($ti);
1054 
1055  $form->addCommandButton("searchUser", $this->lng->txt("search"));
1056 
1057  return $form;
1058  }
1059 
1063  public function getUserSearchResult(): string
1064  {
1065  global $DIC;
1066 
1067  $lng = $DIC->language();
1068 
1069  if (strlen($this->request->getUserSearchStr()) < 3) {
1070  if (strlen($this->request->getUserSearchStr()) > 0) {
1071  $lng->loadLanguageModule("search");
1072  return ilUtil::getSystemMessageHTML($lng->txt("search_minimum_three"), "info");
1073  }
1074 
1075  return "";
1076  }
1077 
1078  $form = $this->initUserSearchForm();
1079  $form->checkInput();
1080 
1081  $users = ilInternalLink::searchUsers($form->getInput("usr_search_str"));
1082  if (count($users) === 0) {
1083  return ilUtil::getSystemMessageHTML($lng->txt("cont_user_search_did_not_match"), "info");
1084  }
1085 
1086  $f = $DIC->ui()->factory();
1087  $r = $DIC->ui()->renderer();
1088  $lng = $DIC->language();
1089  $cards = array();
1090  foreach ($users as $user) {
1091  $b = $f->button()->standard($lng->txt("insert"), "#")
1092  ->withOnLoadCode(function ($id) use ($user) {
1093  return
1094  '$("#' . $id . "\").click(function(ev) { il.IntLink.addInternalLink('[iln user=\"" .
1095  ilObjUser::_lookupLogin($user) . "\"/]', '', ev); return false;});";
1096  });
1097  $name = ilUserUtil::getNamePresentation($user);
1098  $cards[] = $f->card()->standard($name, $f->image()->responsive(ilObjUser::_getPersonalPicturePath($user, "small"), $name))
1099  ->withSections(array($b));
1100  }
1101  $deck = $f->deck($cards)->withLargeCardsSize();
1102 
1103  return $r->renderAsync($deck);
1104  }
1105 }
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
static getInitHTML(string $a_url)
Get initialisation HTML to use internal link editing.
exit
Definition: login.php:29
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
special template class to simplify handling of ITX/PEAR
static _readAnchors(string $a_parent_type, int $a_page_id, string $a_page_lang="-")
Read anchors of a page.
getUserSearchResult()
Search user.
setReturn(string $a_return)
This class represents a file property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupForeignId(int $a_id)
changeTargetObject(string $a_type="")
Cange target object.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
isInTree(?int $a_node_id)
get all information of a node.
parseCurrentBlock(string $part=self::DEFAULT_BLOCK)
outputThumbnail(ilGlobalTemplate $tpl, int $a_id, string $a_mode="")
output thumbnail
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.
static getOnloadCode(string $a_url)
getFileLinkHTML()
Get HTML for file link.
loadLanguageModule(string $a_module)
Load language module.
Internal link selector.
showLinkHelp()
Show link help list.
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
filterLinkType(string $a_link_type)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
__construct(string $a_default_link_type, int $a_default_parent_id, bool $a_is_ref=true)
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 _lookupTitle(int $obj_id)
getTargetExplorer()
Cange target object.
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.
Class ilObjFile.
static redirect(string $a_script)
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 getInstance()
setMedPoolFolder()
select media pool folder
static _recoverParameters()
Recover parameters from session variables (static)
setFilterWhiteList(bool $a_white_list)
Set filter list as white list (per detault it is a black list)
prepareJavascriptOutput(string $str)
Prepare output for JS enabled editing.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getPageList(int $lm_id)
initUserSearchForm()
Init user search form.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
saveFileLink()
Save file link.
static init(ilGlobalTemplateInterface $a_main_tpl=null)
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
selectRepositoryItem()
select repository item explorer
StandardGUIRequest $request
static getAllWikiPages(int $a_wiki_id, string $lang="-")
static _lookupType(int $id, bool $reference=false)
setSetLinkTargetScript(string $a_script)
$r
refreshRepositorySelector()
Refresh Repository Selector.
static _lookupLogin(int $a_user_id)