ILIAS  release_8 Revision v8.24
class.ilPageLinker.php
Go to the documentation of this file.
1<?php
2
24{
25 protected bool $offline;
26 protected string $profile_back_url = "";
27 protected ilCtrl $ctrl;
28 protected string $cmd_gui;
29
30 public function __construct(
31 string $cmd_gui_class,
32 bool $offline = false,
33 string $profile_back_url = "",
34 ilCtrl $ctrl = null
35 ) {
36 global $DIC;
37
38 $this->offline = $offline;
39 $this->profile_back_url = $profile_back_url;
40 $this->cmd_gui = $cmd_gui_class;
41
42 $this->ctrl = (is_null($ctrl))
43 ? $DIC->ctrl()
44 : $ctrl;
45 }
46
47 public function setOffline(bool $offline = true): void
48 {
49 $this->offline = $offline;
50 }
51
52 public function setProfileBackUrl(string $url): void
53 {
54 $this->profile_back_url = $url;
55 }
56
57
58 public function getLayoutLinkTargets(): array
59 {
60 $targets = [];
61 return $targets;
62 }
63
64 public function getLinkTargetsXML(): string
65 {
66 $layoutLinkTargets = $this->getLayoutLinkTargets();
67
68 if (0 === count($layoutLinkTargets)) {
69 return '';
70 }
71
72 $link_info = "<LinkTargets>";
73 foreach ($layoutLinkTargets as $k => $t) {
74 $link_info .= "<LinkTarget TargetFrame=\"" . $t["Type"] . "\" LinkTarget=\"" . $t["Frame"] . "\" OnClick=\"" . $t["OnClick"] . "\" />";
75 }
76 $link_info .= "</LinkTargets>";
77 return $link_info;
78 }
79
80 public function getLinkXML(array $int_links): string
81 {
82 $ilCtrl = $this->ctrl;
83 $link_info = "<IntLinkInfos>";
84 foreach ($int_links as $int_link) {
85 $target = $int_link["Target"];
86 if (substr($target, 0, 4) == "il__") {
87 $target_arr = explode("_", $target);
89 $type = $int_link["Type"];
90
91 $targetframe = ($int_link["TargetFrame"] != "")
92 ? $int_link["TargetFrame"]
93 : "None";
94
95 $ltarget = "_top";
96 if ($targetframe != "None") {
97 $ltarget = "_blank";
98 }
99
100 // anchor
101 $anc = $anc_add = "";
102 if (($int_link["Anchor"] ?? "") != "") {
103 $anc = $int_link["Anchor"];
104 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
105 }
106
107 $href = "";
108 $lcontent = "";
109 switch ($type) {
110 case "PageObject":
111 case "StructureObject":
113 if ($type == "PageObject") {
114 $href = "./goto.php?target=pg_" . $target_id . $anc_add;
115 } else {
116 $href = "./goto.php?target=st_" . $target_id;
117 }
118 if ($lm_id == "") {
119 $href = "";
120 }
121 break;
122
123 case "GlossaryItem":
124 if ($targetframe == "Glossary") {
125 $ltarget = "";
126 }
127 $href = "./goto.php?target=git_" . $target_id;
128 break;
129
130 case "MediaObject":
131 if ($this->offline) {
132 $href = "media_" . $target_id . ".html";
133 } else {
134 $this->ctrl->setParameterByClass($this->cmd_gui, "mob_id", $target_id);
135 $href = $this->ctrl->getLinkTargetByClass(
136 $this->cmd_gui,
137 "displayMedia",
138 "",
139 false,
140 true
141 );
142 $this->ctrl->setParameterByClass($this->cmd_gui, "mob_id", "");
143 }
144 break;
145
146 case "WikiPage":
147 $wiki_anc = "";
148 if (($int_link["Anchor"] ?? "") != "") {
149 $wiki_anc = "#" . rawurlencode("copganc_" . $int_link["Anchor"]);
150 }
152 break;
153
154 case "PortfolioPage":
156 break;
157
158 case "RepositoryItem":
159 $obj_type = ilObject::_lookupType((int) $target_id, true);
160 $obj_id = ilObject::_lookupObjId((int) $target_id);
161 $href = "./goto.php?target=" . $obj_type . "_" . $target_id;
162 break;
163
164 case "File":
165 if (!$this->offline) {
166 $href = "#";
167 }
168 break;
169
170 case "User":
171 $obj_type = ilObject::_lookupType((int) $target_id);
172 if ($obj_type == "usr") {
174 //var_dump($back); exit;
175 $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $target_id);
176 if (strlen($back)) {
177 $this->ctrl->setParameterByClass(
178 "ilpublicuserprofilegui",
179 "back_url",
180 rawurlencode($back)
181 );
182 }
183 $href = "";
185 $href = $this->ctrl->getLinkTargetByClass(
186 ["ilpublicuserprofilegui"],
187 "getHTML",
188 "",
189 false,
190 true
191 );
192 }
193 $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", "");
194 $lcontent = ilUserUtil::getNamePresentation($target_id, false, false);
195 $lcontent = str_replace("&", "&amp;", htmlentities($lcontent));
196 }
197 break;
198
199 }
200 if ($href != "") {
201 $anc_par = 'Anchor="' . $anc . '"';
202 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " . $anc_par . " " .
203 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" LinkContent=\"$lcontent\" />";
204 }
205 }
206 }
207 $link_info .= "</IntLinkInfos>";
208 $link_info .= $this->getLinkTargetsXML();
209 return $link_info;
210 }
211
212 public function getFullscreenLink(): string
213 {
214 if ($this->offline) {
215 return "fullscreen.html";
216 }
217
218 return $this->ctrl->getLinkTargetByClass($this->cmd_gui, "fullscreen", "", false, false);
219 }
220}
Class ilCtrl provides processing control methods.
static _lookupContObjID(int $a_id)
get learning module id for lm object
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLinkXML(array $int_links)
__construct(string $cmd_gui_class, bool $offline=false, string $profile_back_url="", ilCtrl $ctrl=null)
setOffline(bool $offline=true)
setProfileBackUrl(string $url)
static getGotoForPortfolioPageTarget(int $a_target, bool $a_offline=false)
Get goto href for portfolio page id.
static hasPublicProfile(int $a_user_id)
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 getGotoForWikiPageTarget(string $a_target, bool $a_offline=false)
global $DIC
Definition: feed.php:28
$target_id
Definition: goto.php:52
$target_arr
Definition: goto.php:50
$type
$url