ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMailFormCall.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  final public const string SESSION_KEY = 'mail_transport';
24  final public const string REFERER_KEY = 'r';
25  final public const string SIGNATURE_KEY = 'sig';
26  final public const string CONTEXT_PREFIX = 'ctx';
27  final public const string CONTEXT_KEY = 'ctx_template';
28 
32  public static function getLinkTarget(
33  $gui,
34  string $cmd,
35  array $gui_params = [],
36  array $mail_params = [],
37  array $context_params = []
38  ): string {
39  return self::getTargetUrl('&', $gui, $cmd, $gui_params, $mail_params, $context_params);
40  }
41 
45  public static function getRedirectTarget(
46  $gui,
47  string $cmd,
48  array $gui_params = [],
49  array $mail_params = [],
50  array $context_params = []
51  ): string {
52  return self::getTargetUrl('&', $gui, $cmd, $gui_params, $mail_params, $context_params);
53  }
54 
58  protected static function getTargetUrl(
59  string $argument_separator,
60  $gui,
61  string $cmd,
62  array $gui_params = [],
63  array $mail_params = [],
64  array $context_params = []
65  ): string {
66  global $DIC;
67 
68  $mparams = '';
69  $referer = '';
70 
71  foreach ($mail_params as $key => $value) {
72  $mparams .= $argument_separator . $key . '=' . urlencode((string) $value);
73  }
74 
75  foreach ($context_params as $key => $value) {
76  if ($key === self::CONTEXT_KEY) {
77  $mparams .= $argument_separator . $key . '=' . urlencode((string) $value);
78  } else {
79  $mparams .= $argument_separator . self::CONTEXT_PREFIX . '_' . $key . '=' . urlencode((string) $value);
80  }
81  }
82 
83  if (is_object($gui)) {
84  $ctrl_tmp = clone $DIC->ctrl();
85  foreach ($gui_params as $key => $value) {
86  $ctrl_tmp->setParameter($gui, $key, $value);
87  }
88  $referer = $ctrl_tmp->getLinkTarget($gui, $cmd, '');
89  } elseif (is_string($gui)) {
90  $referer = $gui;
91  }
92 
93  $referer = $argument_separator . self::REFERER_KEY . '=' . rawurlencode(base64_encode((string) $referer));
94 
95  return 'ilias.php?baseClass=ilMailGUI' . $referer . $mparams;
96  }
97 
101  public static function storeReferer(array $query_parameters): void
102  {
103  $session = ilSession::get(self::SESSION_KEY);
104 
105  if (isset($query_parameters[self::REFERER_KEY])) {
106  $session[self::REFERER_KEY] = base64_decode(rawurldecode((string) $query_parameters[self::REFERER_KEY]));
107  $session[self::SIGNATURE_KEY] = base64_decode(
108  rawurldecode(
109  $query_parameters[self::SIGNATURE_KEY] ?? ''
110  )
111  );
112 
113  $context_parameters = [];
114  foreach ($query_parameters as $key => $value) {
115  $prefix = substr($key, 0, strlen(self::CONTEXT_PREFIX));
116  if ($prefix === self::CONTEXT_PREFIX) {
117  if ($key === self::CONTEXT_KEY) {
118  $context_parameters[$key] = $value;
119  } else {
120  $context_parameters[substr($key, strlen(self::CONTEXT_PREFIX . '_'))] = $value;
121  }
122  }
123  }
124  $session[self::CONTEXT_PREFIX] = $context_parameters;
125  } else {
126  if (isset($session[self::REFERER_KEY])) {
127  unset($session[self::REFERER_KEY]);
128  }
129  if (isset($session[self::SIGNATURE_KEY])) {
130  unset($session[self::SIGNATURE_KEY]);
131  }
132  if (isset($session[self::CONTEXT_PREFIX])) {
133  unset($session[self::CONTEXT_PREFIX]);
134  }
135  }
136 
137  ilSession::set(self::SESSION_KEY, $session);
138  }
139 
140  public static function getSignature(): string
141  {
142  $sig = '';
143  $session = ilSession::get(self::SESSION_KEY);
144 
145  if (isset($session[self::SIGNATURE_KEY])) {
146  $sig = $session[self::SIGNATURE_KEY];
147 
148  unset($session[self::SIGNATURE_KEY]);
149  ilSession::set(self::SESSION_KEY, $session);
150  }
151 
152  return $sig;
153  }
154 
155  public static function getRefererRedirectUrl(): string
156  {
157  $url = '';
158  $session = ilSession::get(self::SESSION_KEY);
159 
160  if (isset($session[self::REFERER_KEY])) {
161  $url = $session[self::REFERER_KEY];
162  if (is_string($url) && $url !== '') {
163  $parts = parse_url($url);
164  if (isset($parts['query']) && $parts['query'] !== '') {
165  $url .= '&returned_from_mail=1';
166  } else {
167  $url .= '?returned_from_mail=1';
168  }
169 
170  $ilias_url_parts = parse_url(ilUtil::_getHttpPath());
171  if (isset($parts['host']) && $ilias_url_parts['host'] !== $parts['host']) {
172  $url = 'ilias.php?baseClass=ilMailGUI';
173  }
174  }
175 
176  unset($session[self::REFERER_KEY]);
177  ilSession::set(self::SESSION_KEY, $session);
178  }
179 
180  return $url;
181  }
182 
183  public static function isRefererStored(): bool
184  {
185  $session = ilSession::get(self::SESSION_KEY);
186 
187  return (
188  isset($session[self::REFERER_KEY]) &&
189  is_string($session[self::REFERER_KEY]) &&
190  $session[self::REFERER_KEY] !== ''
191  );
192  }
193 
194  public static function getContextId(): ?string
195  {
196  $session = ilSession::get(self::SESSION_KEY);
197  return (
198  isset($session[self::CONTEXT_PREFIX][self::CONTEXT_KEY]) &&
199  is_string($session[self::CONTEXT_PREFIX][self::CONTEXT_KEY]) ?
200  $session[self::CONTEXT_PREFIX][self::CONTEXT_KEY] : null
201  );
202  }
203 
204  public static function setContextId(?string $id): void
205  {
206  $session = ilSession::get(self::SESSION_KEY);
207  $session[self::CONTEXT_KEY] = $id;
208  ilSession::set(self::SESSION_KEY, $session);
209  }
210 
211  public static function getContextParameters(): array
212  {
213  $session = ilSession::get(self::SESSION_KEY);
214  if (isset($session[self::CONTEXT_PREFIX]) && is_array($session[self::CONTEXT_PREFIX])) {
215  return $session[self::CONTEXT_PREFIX];
216  }
217 
218  return [];
219  }
220 
221  public static function setContextParameters(array $parameters): void
222  {
223  $session = ilSession::get(self::SESSION_KEY);
224  $session[self::CONTEXT_PREFIX] = $parameters;
225  ilSession::set(self::SESSION_KEY, $session);
226  }
227 
231  public static function setRecipients(array $recipients, string $type = 'to'): void
232  {
233  $session = ilSession::get(self::SESSION_KEY) ?? [];
234  $session['rcp_' . $type] = array_map('strval', array_values($recipients));
235  ilSession::set(self::SESSION_KEY, $session);
236  }
237 
241  public static function getRecipients(string $type = 'to'): array
242  {
243  $session = ilSession::get(self::SESSION_KEY) ?? [];
244  $key = 'rcp_' . $type;
245  if (isset($session[$key]) && is_array($session[$key])) {
246  return array_map('strval', array_values($session[$key]));
247  }
248 
249  return [];
250  }
251 }
static get(string $a_var)
final const string REFERER_KEY
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
static getLinkTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
$url
Definition: shib_logout.php:68
static getTargetUrl(string $argument_separator, $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
final const string CONTEXT_PREFIX
global $DIC
Definition: shib_login.php:26
final const string SIGNATURE_KEY
static setContextParameters(array $parameters)
static getRecipients(string $type='to')
final const string SESSION_KEY
final const string CONTEXT_KEY
static setRecipients(array $recipients, string $type='to')
static _getHttpPath()
static storeReferer(array $query_parameters)
$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)
static set(string $a_var, $a_val)
Set a value.