ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ExtLinkMapper.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 protected array $ilias_url;
26
27 public function __construct(
28 protected \ilObjectDefinition $object_def,
29 string $ilias_http_path,
30 protected array $mapping,
31 protected $client_id = ""
32 ) {
33 $this->ilias_url = parse_url($ilias_http_path);
34 if ($client_id === "") {
35 $this->client_id = CLIENT_ID;
36 }
37 }
38
39 public function getRefId(string $href): int
40 {
41 $url = parse_url($href);
42
43 // only handle links on same host
44 if (($url["host"] ?? "") !== "" && $url["host"] !== $this->ilias_url["host"]) {
45 return 0;
46 }
47
48 $ref_id = 0;
49
50 // get parameters
51 $par = [];
52 $type = "";
53
54 // links ending with .html, e.g. goto_client_cat_581.html
55 if (substr($href, strlen($href) - 5) === ".html") {
56 $parts = explode(
57 "_",
58 basename(
59 substr($url["path"], 0, strlen($url["path"]) - 5)
60 )
61 );
62 if (array_shift($parts) !== "goto") {
63 return 0;
64 }
65 $par["client_id"] = array_shift($parts);
66 $par["target"] = implode("_", $parts); // e.g. cat_581
67 $t = explode("_", $par["target"]);
68 $type = $t[0] ?? "";
69 $ref_id = (int) ($t[1] ?? 0);
70 } elseif (is_int($p = strpos($href, "/goto.php/"))) {
71 $parts = explode("/", substr($href, $p + 10));
72 $ref_id = (int) ($parts[1] ?? 0);
73 $type = ($parts[0] ?? "");
74 } elseif (is_int($p = strpos($href, "/go/"))) {
75 $parts = explode("/", substr($href, $p + 4));
76 $ref_id = (int) ($parts[1] ?? 0);
77 $type = ($parts[0] ?? "");
78 } else {
79 // extract all query parameter
80 foreach (explode("&", ($url["query"] ?? "")) as $p) {
81 $p = explode("=", $p);
82 if (isset($p[0]) && isset($p[1])) {
83 $par[$p[0]] = $p[1];
84 }
85 }
86 $ref_id = (int) ($par["ref_id"] ?? 0);
87 }
88
89 if ($ref_id > 0 && $type !== "" && !$this->object_def->isRBACObject($type)) {
90 $ref_id = 0;
91 }
92
93 // we have a client and it's the wrong client -> return ""
94 $target_client_id = $par["client_id"] ?? "";
95 if ($target_client_id !== "" && $target_client_id !== $this->client_id) {
96 return 0;
97 }
98 return $ref_id;
99 }
100
101 public function getNewHref(int $ref_id): string
102 {
103 if ($ref_id > 0) {
104 $new_ref_id = ($this->mapping[$ref_id] ?? 0);
105 if ($new_ref_id > 0) {
106 return \ilLink::_getLink($new_ref_id);
107 }
108 }
109 return "";
110 }
111}
string $client_id
Definition: class.ilias.php:36
parses the objects.xml it handles the xml-description of all ilias objects
const CLIENT_ID
Definition: constants.php:41
$ref_id
Definition: ltiauth.php:66
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
$url
Definition: shib_logout.php:68