ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWOPIEmbeddedApplicationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
27
32{
33 public const CMD_EDIT = 'edit';
34 public const CMD_VIEW = 'view';
35 public const CMD_RETURN = 'return';
36 public const P_RETURN_TO = 'return_to';
37 public const DATA_SIGNER_SALT = 'wopi_return';
57 private \ILIAS\UI\Renderer $ui_renderer;
75
76 public function __construct(
77 private EmbeddedApplication $application,
78 ) {
79 global $DIC;
80 $this->main_tpl = $DIC->ui()->mainTemplate();
81 $this->tabs = $DIC->tabs();
82 $this->global_screen = $DIC->globalScreen();
83 $this->global_screen->layout()->meta()->addJs('./assets/js/wopi.min.js');
84 $this->global_screen->layout()->meta()->addOnloadCode('il.WOPI.init();');
85 $this->renderer = new Renderer($this->application);
86 $this->ui_renderer = $DIC->ui()->renderer();
87 $this->http = $DIC->http()->wrapper()->query();
88 $this->refinery = $DIC->refinery();
89 $this->ctrl = $DIC->ctrl();
90 $this->lng = $DIC->language();
91 $this->lng->loadLanguageModule('wopi');
92 $this->data_signer = $DIC['file_delivery.data_signer'];
93 }
94
95 public function executeCommand(): void
96 {
97 if (!$this->application->isInline()) {
98 $this->tabs->clearTargets();
99 }
100 $this->global_screen->tool()->context()->current()->addAdditionalData(
101 EmbeddedApplicationGSProvider::EMBEDDED_APPLICATION,
102 $this->application
103 );
104 $a_value = $this->sign((string) $this->application->getBackTarget());
105 $this->ctrl->setParameter($this, self::P_RETURN_TO, $a_value);
106
107 match ($this->ctrl->getCmd()) {
108 default => $this->edit(),
109 self::CMD_EDIT => $this->edit(),
110 self::CMD_VIEW => $this->view(),
111 self::CMD_RETURN => $this->return(),
112 };
113 }
114
115 private function view(): void
116 {
117 $this->main_tpl->setContent(
118 $this->ui_renderer->render($this->renderer->getComponent())
119 );
120 }
121
122 private function edit(): void
123 {
124 $this->main_tpl->setContent(
125 $this->ui_renderer->render($this->renderer->getComponent())
126 );
127 }
128
129 private function return(): void
130 {
131 $return_to = $this->http->has(self::P_RETURN_TO)
132 ? $this->verify((string) $this->http->retrieve(self::P_RETURN_TO, $this->refinery->kindlyTo()->string()))
133 : null;
134
135 if ($return_to === null) {
136 $return_to = (string) $this->application->getBackTarget();
137 }
138
139 $this->main_tpl->setOnScreenMessage(
140 'info',
141 $this->lng->txt('close_wopi_editor_info'),
142 true
143 );
144
145 $this->ctrl->redirectToURL($return_to);
146 }
147
148 private function sign(string $back_target): string
149 {
150 return $this->data_signer->sign(['t' => $back_target], self::DATA_SIGNER_SALT);
151 }
152
153 private function verify(string $back_target_token): ?string
154 {
155 return $this->data_signer->verify($back_target_token, self::DATA_SIGNER_SALT)['t'] ?? null;
156 }
157}
renderer()
Builds data types.
Definition: Factory.php:36
return true
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ArrayBasedRequestWrapper $http
@readonly
ilGlobalTemplateInterface $main_tpl
@readonly
__construct(private EmbeddedApplication $application,)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26