ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
EmbeddedApplication.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30
35{
39 private const WOPI_SRC = 'WOPISrc';
40 private const SUB_THM = 'thm';
41 private const SUB_DCHAT = 'dchat';
42 private const SUB_EMBED = 'embed';
43 private int $ttl = 3600 * 8;
44 private string $token;
45 private array $substitutions = [
46 self::SUB_THM => 1,
47 self::SUB_DCHAT => 0,
48 self::SUB_EMBED => false
49 ];
51
52 public function __construct(
53 protected ResourceIdentification $identification,
54 protected ?Action $action,
55 protected ResourceStakeholder $stakeholder,
56 protected URI $back_target,
57 protected bool $inline = false,
58 ?string $ui_language = null
59 ) {
60 global $DIC;
62 $data_signer = $DIC['file_delivery.data_signer'];
63 $this->ilias_base_url = new URI(ILIAS_HTTP_PATH);
64 $editable = $this->action?->getName() === ActionTarget::EDIT->value;
65
66 $payload = [
67 'resource_id' => $this->identification->serialize(),
68 'user_id' => $DIC->user()->getId(),
69 'stakeholder' => $this->stakeholder::class,
70 'editable' => $editable
71 ];
72
73 $ui_language ??= 'en_US';
74 $this->substitutions['lang'] = $ui_language;
75 $this->substitutions['rs'] = $ui_language;
76 $this->substitutions['ui'] = $ui_language;
77 $this->substitutions[self::SUB_EMBED] = !$editable;
78 $this->token = $data_signer->sign($payload, 'wopi', new \DateTimeImmutable("now + $this->ttl seconds"));
79 }
80
81 public function getToken(): string
82 {
83 return $this->token;
84 }
85
86 public function getTTL(): int
87 {
88 return $this->ttl;
89 }
90
91 public function getBackTarget(): URI
92 {
93 return $this->back_target;
94 }
95
96 public function isInline(): bool
97 {
98 return $this->inline;
99 }
100
101 public function getActionLauncherURL(): ?URI
102 {
103 if ($this->action === null) {
104 return null;
105 }
106
107 $appendices = $this->getAppendices();
108
109 $url = rtrim((string) $this->action->getLauncherUrl(), '/?#')
110 . '?'
111 . self::WOPI_SRC
112 . '='
113 . urlencode(
114 rtrim((string) $this->ilias_base_url, '/')
117 . '/'
118 . $this->identification->serialize()
119 );
120
121 if ($appendices !== []) {
122 $url .= '&' . implode('&', $appendices);
123 }
124
125 return new URI($url);
126 }
127
131 protected function getAppendices(): array
132 {
133 // appendix sanitizer
134 $appendix = $this->action->getUrlAppendix();
135 $appendices = [];
136 try {
137 if ($appendix !== null) {
138 preg_match_all('/([^<]*)=([^>&]*)/m', $appendix, $appendices, PREG_SET_ORDER, 0);
139
140 $appendices = array_filter($appendices, static fn(array $appendix): bool => isset($appendix[1], $appendix[2]));
141
142 // we set the wopisrc ourselves
143 $appendices = array_filter($appendices, static fn(array $appendix): bool => strtolower($appendix[1]) !== 'wopisrc');
144
145 // try substitutions
146 $appendices = array_map(function (array $appendix): array {
147 $key = strtolower($appendix[1]);
148 if (isset($this->substitutions[$key])) {
149 $appendix[2] = (string) $this->substitutions[$key];
150 }
151 return $appendix;
152 }, $appendices);
153
154 // we remove all those placeholders
155 $appendices = array_filter($appendices, static fn(array $appendix): bool => $appendix[0] !== $appendix[1] . '=' . $appendix[2]);
156
157 $here = 1;
158
159 $appendices = array_map(static fn(array $appendix): string => $appendix[1] . '=' . $appendix[2], $appendices);
160 }
161 } catch (\Throwable $t) {
162 return [];
163 }
164
165 return $appendices;
166 }
167}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
if(count($parts) !=3) $payload
Definition: ltitoken.php:67
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68