19 declare(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();
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;
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];
195 if (is_null($lm_type_lookup)) {
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(
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,
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);
379 $source_node = $node;
380 $new_node = $source_node->cloneNode(
true);
382 $childs = $new_node->child_nodes();
383 foreach ($new_node->childNodes as $child) {
385 $source_node->parentNode->insertBefore($child, $source_node);
387 $source_node->parentNode->removeChild($source_node);
394 $ilias_url = parse_url(ILIAS_HTTP_PATH);
396 $nodes = $this->dom_util->path($dom,
$path);
397 foreach ($nodes as $node) {
398 $href = $node->getAttribute(
"Href");
400 $this->log->debug(
"Href: " . $href);
401 $ref_id = $ext_link_mapper->getRefId($href);
402 $this->log->debug(
"Ref Id: " .
$ref_id);
405 $new_href = $ext_link_mapper->getNewHref(
$ref_id);
406 $this->log->debug(
"New ref id: " . $new_href);
407 if ($new_href !==
"") {
408 $node->setAttribute(
"Href", $new_href);
412 if ($node->parentNode->nodeName ==
"MapArea") {
413 $parent = $node->parentNode;
414 $parent->parentNode->removeChild($parent);
416 $source_node = $node;
417 $new_node = $source_node->cloneNode(
true);
419 foreach ($new_node->childNodes as $child) {
421 $source_node->parentNode->insertBefore($child, $source_node);
423 $source_node->parentNode->removeChild($source_node);
456 $xpath = new \DOMXPath($a_domdoc);
457 $nodes = $xpath->query(
'//IntLink');
458 foreach ($nodes as $node) {
459 $link_type = $node->getAttribute(
"Type");
461 switch ($link_type) {
462 case "StructureObject":
478 case "RepositoryItem":
490 case "PortfolioPage":
499 $target = $node->getAttribute(
"Target");
500 $target_arr = explode(
"_", $target);
501 $t_id = (
int) $target_arr[count($target_arr) - 1];
504 if (is_int(strpos($target,
"__"))) {
507 $t_inst = (
int) ($target_arr[1] ?? 0);
static _removeInstFromTarget(string $a_target)
Removes installation id from target string.
static _extractObjIdOfTarget(string $a_target)
Extract object id out of target.
resolveIntLinks(\DOMDocument $dom, ?array $a_link_map=null)
Resolves all internal link targets of the page, if targets are available (after import) ...
getDefaultLMTypeLookuper()
extractFileFromLinkId(string $file_link_id)
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
isGrandChild(int $a_startnode_id, int $a_querynode_id)
checks if a node is in the path of an other node
static _extractInstOfTarget(string $a_target)
Extract installation id out of target.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ilObjectDefinition $obj_definition
deleteInternalLinks(\ilPageObject $page)
Delete internal links.
static _deleteAllLinksOfSource(string $a_source_type, int $a_source_id, string $a_lang="-")
Delete all links of a given source.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
static _getIdForImportId(string $a_type, string $a_target)
Get current id for an import id.
getDefaultMediaCollector()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static _lookupType(int $a_obj_id, int $a_lm_id=0)
handleRepositoryLinksOnCopy(\DOMDocument $dom, array $a_mapping, int $a_source_ref_id, \ilTree $tree)
Handle repository links on copy process.
Component logger with individual log levels by component id.
getInternalLinks(\DOMDocument $dom, ?\Closure $media_collector=null)
ILIAS COPage Dom DomUtil $dom_util
saveInternalLinks(\ilPageObject $page, \DOMDocument $a_domdoc,)
save internal links of page
containsFileLinkId(\DOMDocument $dom, string $file_link_id)
static _exists(string $a_type, string $a_target)
Check if internal link refers to a valid target.
moveIntLinks(\DOMDocument $dom, array $a_from_to, ?\Closure $lm_type_lookup=null)
Move internal links from one destination to another.