ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailFormCall.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  public const SESSION_KEY = 'mail_transport';
30  public const REFERER_KEY = 'r';
31  public const SIGNATURE_KEY = 'sig';
32  public const CONTEXT_PREFIX = 'ctx';
33  public const CONTEXT_KEY = 'ctx_template';
34 
43  public static function getLinkTarget(
44  $gui,
45  string $cmd,
46  array $gui_params = [],
47  array $mail_params = [],
48  array $context_params = []
49  ): string {
50  return self::getTargetUrl('&', $gui, $cmd, $gui_params, $mail_params, $context_params);
51  }
52 
61  public static function getRedirectTarget(
62  $gui,
63  string $cmd,
64  array $gui_params = [],
65  array $mail_params = [],
66  array $context_params = []
67  ): string {
68  return self::getTargetUrl('&', $gui, $cmd, $gui_params, $mail_params, $context_params);
69  }
70 
80  protected static function getTargetUrl(
81  string $argument_separator,
82  $gui,
83  string $cmd,
84  array $gui_params = [],
85  array $mail_params = [],
86  array $context_params = []
87  ): string {
88  global $DIC;
89 
90  $mparams = '';
91  $referer = '';
92 
93  foreach ($mail_params as $key => $value) {
94  $mparams .= $argument_separator . $key . '=' . urlencode((string) $value);
95  }
96 
97  foreach ($context_params as $key => $value) {
98  if ($key === self::CONTEXT_KEY) {
99  $mparams .= $argument_separator . $key . '=' . urlencode((string) $value);
100  } else {
101  $mparams .= $argument_separator . self::CONTEXT_PREFIX . '_' . $key . '=' . urlencode((string) $value);
102  }
103  }
104 
105  if (is_object($gui)) {
106  $ilCtrlTmp = clone $DIC->ctrl();
107  foreach ($gui_params as $key => $value) {
108  $ilCtrlTmp->setParameter($gui, $key, $value);
109  }
110  $referer = $ilCtrlTmp->getLinkTarget($gui, $cmd, '');
111  } elseif (is_string($gui)) {
112  $referer = $gui;
113  }
114 
115  $referer = $argument_separator . self::REFERER_KEY . '=' . rawurlencode(base64_encode($referer));
116 
117  return 'ilias.php?baseClass=ilMailGUI' . $referer . $mparams;
118  }
119 
123  public static function storeReferer(array $queryParameters): void
124  {
125  $session = ilSession::get(self::SESSION_KEY);
126 
127  if (isset($queryParameters[self::REFERER_KEY])) {
128  $session[self::REFERER_KEY] = base64_decode(rawurldecode($queryParameters[self::REFERER_KEY]));
129  $session[self::SIGNATURE_KEY] = base64_decode(
130  rawurldecode(
131  $queryParameters[self::SIGNATURE_KEY] ?? ''
132  )
133  );
134 
135  $contextParameters = [];
136  foreach ($queryParameters as $key => $value) {
137  $prefix = substr($key, 0, strlen(self::CONTEXT_PREFIX));
138  if ($prefix === self::CONTEXT_PREFIX) {
139  if ($key === self::CONTEXT_KEY) {
140  $contextParameters[$key] = $value;
141  } else {
142  $contextParameters[substr($key, strlen(self::CONTEXT_PREFIX . '_'))] = $value;
143  }
144  }
145  }
146  $session[self::CONTEXT_PREFIX] = $contextParameters;
147  } else {
148  if (isset($session[self::REFERER_KEY])) {
149  unset($session[self::REFERER_KEY]);
150  }
151  if (isset($session[self::SIGNATURE_KEY])) {
152  unset($session[self::SIGNATURE_KEY]);
153  }
154  if (isset($session[self::CONTEXT_PREFIX])) {
155  unset($session[self::CONTEXT_PREFIX]);
156  }
157  }
158 
159  ilSession::set(self::SESSION_KEY, $session);
160  }
161 
162  public static function getSignature(): string
163  {
164  $sig = '';
165  $session = ilSession::get(self::SESSION_KEY);
166 
167  if (isset($session[self::SIGNATURE_KEY])) {
168  $sig = $session[self::SIGNATURE_KEY];
169 
170  unset($session[self::SIGNATURE_KEY]);
171  ilSession::set(self::SESSION_KEY, $session);
172  }
173 
174  return $sig;
175  }
176 
177  public static function getRefererRedirectUrl(): string
178  {
179  $url = '';
180  $session = ilSession::get(self::SESSION_KEY);
181 
182  if (isset($session[self::REFERER_KEY])) {
183  $url = $session[self::REFERER_KEY];
184  if (is_string($url) && $url !== '') {
185  $parts = parse_url($url);
186  if (isset($parts['query']) && $parts['query'] !== '') {
187  $url .= '&returned_from_mail=1';
188  } else {
189  $url .= '?returned_from_mail=1';
190  }
191 
192  $ilias_url_parts = parse_url(ilUtil::_getHttpPath());
193  if (isset($parts['host']) && $ilias_url_parts['host'] !== $parts['host']) {
194  $url = 'ilias.php?baseClass=ilMailGUI';
195  }
196  }
197 
198  unset($session[self::REFERER_KEY]);
199  ilSession::set(self::SESSION_KEY, $session);
200  }
201 
202  return $url;
203  }
204 
205  public static function isRefererStored(): bool
206  {
207  $session = ilSession::get(self::SESSION_KEY);
208 
209  return (
210  isset($session[self::REFERER_KEY]) &&
211  is_string($session[self::REFERER_KEY]) &&
212  $session[self::REFERER_KEY] !== ''
213  );
214  }
215 
216  public static function getContextId(): ?string
217  {
218  $session = ilSession::get(self::SESSION_KEY);
219  return (
220  isset($session[self::CONTEXT_PREFIX][self::CONTEXT_KEY]) &&
221  is_string($session[self::CONTEXT_PREFIX][self::CONTEXT_KEY]) ?
222  $session[self::CONTEXT_PREFIX][self::CONTEXT_KEY] : null
223  );
224  }
225 
226  public static function setContextId(?string $id): void
227  {
228  $session = ilSession::get(self::SESSION_KEY);
229  $session[self::CONTEXT_KEY] = $id;
230  ilSession::set(self::SESSION_KEY, $session);
231  }
232 
233  public static function getContextParameters(): array
234  {
235  $session = ilSession::get(self::SESSION_KEY);
236  if (isset($session[self::CONTEXT_PREFIX]) && is_array($session[self::CONTEXT_PREFIX])) {
237  return $session[self::CONTEXT_PREFIX];
238  }
239 
240  return [];
241  }
242 
243  public static function setContextParameters(array $parameters): void
244  {
245  $session = ilSession::get(self::SESSION_KEY);
246  $session[self::CONTEXT_PREFIX] = $parameters;
247  ilSession::set(self::SESSION_KEY, $session);
248  }
249 
253  public static function setRecipients(array $recipients, string $type = 'to'): void
254  {
255  $session = ilSession::get(self::SESSION_KEY) ?? [];
256  $session['rcp_' . $type] = array_map('strval', array_values($recipients));
257  ilSession::set(self::SESSION_KEY, $session);
258  }
259 
263  public static function getRecipients(string $type = 'to'): array
264  {
265  $session = ilSession::get(self::SESSION_KEY) ?? [];
266  $key = 'rcp_' . $type;
267  if (isset($session[$key]) && is_array($session[$key])) {
268  return array_map('strval', array_values($session[$key]));
269  }
270 
271  return [];
272  }
273 }
static get(string $a_var)
$type
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
static storeReferer(array $queryParameters)
$session
static getLinkTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
Statically used helper class for generating links to the mail form user interface.
static getTargetUrl(string $argument_separator, $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
global $DIC
Definition: feed.php:28
string $key
Consumer key/client ID value.
Definition: System.php:193
static setContextParameters(array $parameters)
static getRecipients(string $type='to')
static setRecipients(array $recipients, string $type='to')
static _getHttpPath()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
static setContextId(?string $id)
$url
static set(string $a_var, $a_val)
Set a value.