19declare(strict_types=1);
36 $this->dom_util =
$DIC->copage()->internal()->domain()->domUtil();
37 $this->obj_definition =
$DIC[
"objDefinition"];
38 $this->log =
$DIC->copage()->internal()->domain()->log();
48 ?\Closure $media_collector =
null
50 if (is_null($media_collector)) {
57 $nodes = $this->dom_util->path($dom,
$path);
58 foreach ($nodes as $node) {
59 $target = $node->getAttribute(
"Target");
60 $type = $node->getAttribute(
"Type");
61 $targetframe = $node->getAttribute(
"TargetFrame");
62 $anchor = $node->getAttribute(
"Anchor");
63 $links[$target .
":" . $type .
":" . $targetframe .
":" . $anchor] =
64 array(
"Target" => $target,
66 "TargetFrame" => $targetframe,
71 if ($type ==
"MediaObject" && $targetframe ==
"") {
72 if (substr($target, 0, 4) ==
"il__") {
73 $id_arr = explode(
"_", $target);
74 $id = $id_arr[count($id_arr) - 1];
76 $med_links = $media_collector((
int)
$id);
78 foreach ($med_links as $key => $med_link) {
79 $links[$key] = $med_link;
86 $path =
"//MediaAlias";
87 $nodes = $this->dom_util->path($dom,
$path);
88 foreach ($nodes as $node) {
89 $oid = $node->getAttribute(
"OriginId");
90 if (substr($oid, 0, 4) ==
"il__") {
91 $id_arr = explode(
"_", $oid);
92 $id = $id_arr[count($id_arr) - 1];
94 $med_links = $media_collector((
int)
$id);
95 foreach ($med_links as $key => $med_link) {
96 $links[$key] = $med_link;
107 $int_links = $this->getInternalLinks(
109 function (
int $id): array {
113 foreach ($int_links as $il) {
114 if ($il[
"Target"] == str_replace(
"_file_",
"_dfile_", $file_link_id)) {
123 $file = explode(
"_", $file_link_id);
124 return (
int) $file[count($file) - 1];
133 ?array $a_link_map =
null
138 $nodes = $this->dom_util->path($dom,
$path);
139 foreach ($nodes as $node) {
140 $target = $node->getAttribute(
"Target");
141 $type = $node->getAttribute(
"Type");
143 if ($a_link_map ===
null) {
147 $nt = explode(
"_", $a_link_map[$target] ??
"");
150 $new_target =
"il__" . $nt[2] .
"_" . $nt[3];
154 if ($new_target !==
false && !is_null($new_target)) {
155 $node->setAttribute(
"Target", $new_target);
159 IL_INST_ID > 0 && $type !=
"RepositoryItem") {
162 $node->setAttribute(
"Target", $new_target);
170 $path =
"//MediaAlias";
171 $nodes = $this->dom_util->path($dom,
$path);
172 foreach ($nodes as $node) {
173 $orig_id = $node->getAttribute(
"OriginId");
174 $id_arr = explode(
"_", $orig_id);
175 $mob_id = $id_arr[count($id_arr) - 1];
193 ?\Closure $lm_type_lookup =
null
195 if (is_null($lm_type_lookup)) {
196 $lm_type_lookup = $this->getDefaultLMTypeLookuper();
203 $nodes = $this->dom_util->path($dom,
$path);
204 foreach ($nodes as $node) {
205 $target = $node->getAttribute(
"Target");
206 $type = $node->getAttribute(
"Type");
208 if (($a_from_to[$obj_id] ?? 0) > 0 && is_int(strpos($target,
"__"))) {
209 if ($type ==
"PageObject" && $lm_type_lookup($a_from_to[$obj_id]) ==
"pg") {
210 $node->setAttribute(
"Target",
"il__pg_" . $a_from_to[$obj_id]);
213 if ($type ==
"StructureObject" && $lm_type_lookup($a_from_to[$obj_id]) ==
"st") {
214 $node->setAttribute(
"Target",
"il__st_" . $a_from_to[$obj_id]);
217 if ($type ==
"PortfolioPage") {
218 $node->setAttribute(
"Target",
"il__ppage_" . $a_from_to[$obj_id]);
221 if ($type ==
"WikiPage") {
222 $node->setAttribute(
"Target",
"il__wpage_" . $a_from_to[$obj_id]);
229 $path =
"//MediaAlias";
230 $nodes = $this->dom_util->path($dom,
$path);
231 foreach ($nodes as $node) {
232 $media_object_node = $node->parentNode;
233 $page_content_node = $media_object_node->parentNode;
234 $c_hier_id = $page_content_node->getAttribute(
"HierId");
237 $std_alias_item = new \ilMediaAliasItem(
242 $areas = $std_alias_item->getMapAreas();
243 $correction_needed =
false;
244 if (count($areas) > 0) {
246 foreach ($areas as $area) {
247 if (($area[
"Type"] ??
"") ==
"PageObject" ||
248 ($area[
"Type"] ??
"") ==
"StructureObject") {
249 $t = $area[
"Target"] ??
"";
251 if ($a_from_to[$tid] > 0) {
252 $correction_needed =
true;
261 $oid = $node->getAttribute(
"OriginId");
262 if (substr($oid, 0, 4) ==
"il__") {
263 $id_arr = explode(
"_", $oid);
264 $id = $id_arr[count($id_arr) - 1];
266 $mob = new \ilObjMediaObject((
int)
$id);
267 $med_item = $mob->getMediaItem(
"Standard");
268 $med_areas = $med_item->getMapAreas();
270 foreach ($med_areas as $area) {
271 $link_type = ($area->getLinkType() ==
"int")
276 "Nr" => $area->getNr(),
277 "Shape" => $area->getShape(),
278 "Coords" => $area->getCoords(),
280 "LinkType" => $link_type,
281 "Href" => $area->getHref(),
282 "Title" => $area->getTitle(),
283 "Target" => $area->getTarget(),
284 "Type" => $area->getType(),
285 "TargetFrame" => $area->getTargetFrame()
289 if ($area->getType() ==
"PageObject" ||
290 $area->getType() ==
"StructureObject") {
291 $t = $area->getTarget();
293 if ($a_from_to[$tid] > 0) {
294 $correction_needed =
true;
303 if ($correction_needed) {
305 $std_alias_item->deleteAllMapAreas();
306 foreach ($areas as $area) {
307 if (($area[
"Link"][
"LinkType"] ??
"") ==
"IntLink") {
308 $target = $area[
"Link"][
"Target"] ??
"";
309 $type = $area[
"Link"][
"Type"] ??
"";
311 if ($a_from_to[$obj_id] > 0) {
312 if ($type ==
"PageObject" && $lm_type_lookup($a_from_to[$obj_id]) ==
"pg") {
313 $area[
"Link"][
"Target"] =
"il__pg_" . $a_from_to[$obj_id];
315 if ($type ==
"StructureObject" && $lm_type_lookup($a_from_to[$obj_id]) ==
"st") {
316 $area[
"Link"][
"Target"] =
"il__st_" . $a_from_to[$obj_id];
321 $std_alias_item->addMapArea(
322 $area[
"Shape"] ??
"",
323 $area[
"Coords"] ??
"",
324 $area[
"Link"][
"Title"] ??
"",
325 array(
"Type" => $area[
"Link"][
"Type"] ??
"",
326 "TargetFrame" => $area[
"Link"][
"TargetFrame"] ??
"",
327 "Target" => $area[
"Link"][
"Target"] ??
"",
328 "Href" => $area[
"Link"][
"Href"] ??
"",
329 "LinkType" => $area[
"Link"][
"LinkType"] ??
"",
344 int $a_source_ref_id,
348 $objDefinition = $this->obj_definition;
350 $this->obj_definition,
358 $nodes = $this->dom_util->path($dom,
$path);
359 foreach ($nodes as $node) {
360 $target = $node->getAttribute(
"Target");
361 $type = $node->getAttribute(
"Type");
363 $t = explode(
"_", $target);
364 if ($type ==
"RepositoryItem" && ((
int) $t[1] == 0 || (
int) $t[1] ==
IL_INST_ID)) {
365 if (isset($a_mapping[$t[3]])) {
370 "il__obj_" . $a_mapping[$t[3]]
372 } elseif ($tree->
isGrandChild($a_source_ref_id, (
int) $t[3])) {
375 if ($node->parentNode->nodeName ===
"MapArea") {
376 $parent = $node->parentNode;
377 $parent->parentNode->removeChild($parent);
381 $source_node = $node;
382 while ($source_node->firstChild) {
383 $source_node->parentNode->insertBefore($source_node->firstChild, $source_node);
385 $source_node->parentNode->removeChild($source_node);
402 $ilias_url = parse_url(ILIAS_HTTP_PATH);
404 $nodes = $this->dom_util->path($dom,
$path);
405 foreach ($nodes as $node) {
406 $href = $node->getAttribute(
"Href");
408 $this->log->debug(
"Href: " . $href);
409 $ref_id = $ext_link_mapper->getRefId($href);
410 $this->log->debug(
"Ref Id: " .
$ref_id);
413 $new_href = $ext_link_mapper->getNewHref(
$ref_id);
414 $this->log->debug(
"New ref id: " . $new_href);
415 if ($new_href !==
"") {
416 $node->setAttribute(
"Href", $new_href);
420 if ($node->parentNode->nodeName ==
"MapArea") {
421 $parent = $node->parentNode;
422 $parent->parentNode->removeChild($parent);
424 $source_node = $node;
425 $new_node = $source_node->cloneNode(
true);
427 foreach ($new_node->childNodes as $child) {
429 $source_node->parentNode->insertBefore($child, $source_node);
431 $source_node->parentNode->removeChild($source_node);
445 $page->getParentType() .
":pg",
457 \DOMDocument $a_domdoc,
459 $this->deleteInternalLinks(
464 $xpath = new \DOMXPath($a_domdoc);
465 $nodes = $xpath->query(
'//IntLink');
466 foreach ($nodes as $node) {
467 $link_type = $node->getAttribute(
"Type");
469 switch ($link_type) {
470 case "StructureObject":
486 case "RepositoryItem":
498 case "PortfolioPage":
507 $target = $node->getAttribute(
"Target");
508 $target_arr = explode(
"_", $target);
509 $t_id = (
int) $target_arr[count($target_arr) - 1];
512 if (is_int(strpos($target,
"__"))) {
515 $t_inst = (
int) ($target_arr[1] ?? 0);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
containsFileLinkId(\DOMDocument $dom, string $file_link_id)
resolveIntLinks(\DOMDocument $dom, ?array $a_link_map=null)
Resolves all internal link targets of the page, if targets are available (after import)
getDefaultLMTypeLookuper()
handleRepositoryLinksOnCopy(\DOMDocument $dom, array $a_mapping, int $a_source_ref_id, \ilTree $tree)
Handle repository links on copy process.
extractFileFromLinkId(string $file_link_id)
getDefaultMediaCollector()
ILIAS COPage Dom DomUtil $dom_util
saveInternalLinks(\ilPageObject $page, \DOMDocument $a_domdoc,)
save internal links of page
deleteInternalLinks(\ilPageObject $page)
Delete internal links.
ilObjectDefinition $obj_definition
getInternalLinks(\DOMDocument $dom, ?\Closure $media_collector=null)
moveIntLinks(\DOMDocument $dom, array $a_from_to, ?\Closure $lm_type_lookup=null)
Move internal links from one destination to another.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists(string $a_type, string $a_target)
Check if internal link refers to a valid target.
static _removeInstFromTarget(string $a_target)
Removes installation id from target string.
static _extractInstOfTarget(string $a_target)
Extract installation id out of target.
static _getIdForImportId(string $a_type, string $a_target)
Get current id for an import id.
static _extractObjIdOfTarget(string $a_target)
Extract object id out of target.
static _saveLink(string $a_source_type, int $a_source_id, string $a_target_type, int $a_target_id, int $a_target_inst=0, string $a_source_lang="-")
save internal link information
static _lookupType(int $a_obj_id, int $a_lm_id=0)
Component logger with individual log levels by component id.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
isGrandChild(int $a_startnode_id, int $a_querynode_id)
checks if a node is in the path of an other node
if(!file_exists('../ilias.ini.php'))