ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
EmbeddedApplication.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Data\URI;
30 
35 {
36  private const WOPI_SRC = 'WOPISrc';
37  private int $ttl = 3600;
39  private string $token;
40 
41  public function __construct(
42  protected ResourceIdentification $identification,
43  protected Action $action,
44  protected ResourceStakeholder $stakeholder,
45  protected URI $back_target,
46  protected bool $inline = false,
47  protected ?bool $edit = null,
48  ?URI $ilias_base_url = null
49  ) {
50  global $DIC;
52  $data_signer = $DIC['file_delivery.data_signer'];
53 
54  $payload = [
55  'resource_id' => $this->identification->serialize(),
56  'user_id' => $DIC->user()->getId(),
57  'stakeholder' => $this->stakeholder::class,
58  'editable' => $edit ?? ($this->action->getName() === ActionTarget::EDIT->value)
59  ];
60  $this->token = $data_signer->sign($payload, 'wopi', new \DateTimeImmutable("now + $this->ttl seconds"));
61  $this->ilias_base_url = $ilias_base_url ?? new URI(ILIAS_HTTP_PATH);
62  }
63 
64  public function getToken(): string
65  {
66  return $this->token;
67  }
68 
69  public function getTTL(): int
70  {
71  return $this->ttl;
72  }
73 
74  public function getBackTarget(): URI
75  {
76  return $this->back_target;
77  }
78 
79  public function isInline(): bool
80  {
81  return $this->inline;
82  }
83 
84  public function getActionLauncherURL(): ?URI
85  {
86  if ($this->action === null) {
87  return null;
88  }
89 
90  $appendices = $this->getAppendices();
91 
92  $url = rtrim((string) $this->action->getLauncherUrl(), '/?#')
93  . '?'
94  . self::WOPI_SRC
95  . '='
96  . urlencode(rtrim((string) $this->ilias_base_url, '/')
99  . '/'
100  . $this->identification->serialize());
101 
102  if ($appendices !== []) {
103  $url .= '&' . implode('&', $appendices);
104  }
105 
106  return new URI($url);
107  }
108 
112  protected function getAppendices(): array
113  {
114  // appendix sanitizer
115  $appendix = $this->action->getUrlAppendix();
116  $appendices = [];
117  try {
118  if ($appendix !== null) {
119  preg_match_all('/([^<]*)=([^>&]*)/m', $appendix, $appendices, PREG_SET_ORDER, 0);
120 
121  $appendices = array_filter($appendices, static function ($appendix) {
122  return isset($appendix[1], $appendix[2]);
123  });
124 
125  // we set the wopisrc ourselves
126  $appendices = array_filter($appendices, static function ($appendix) {
127  return strtolower($appendix[1]) !== 'wopisrc';
128  });
129 
130  // we remove all those placeholders
131  $appendices = array_filter($appendices, static function ($appendix) {
132  return !preg_match('/([A-Z\_]*)/m', $appendix[2]);
133  });
134 
135  $appendices = array_map(static function ($appendix) {
136  return $appendix[1] . '=' . $appendix[2];
137  }, $appendices);
138  }
139  } catch (\Throwable $t) {
140  return $appendices;
141  }
142 
143  return $appendices;
144  }
145 }
if(count($parts) !=3) $payload
Definition: ltitoken.php:70
global $DIC
Definition: feed.php:28
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:18
$url
Definition: ltiregstart.php:35
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...