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