Elgg  Version master
RedirectService.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
8 
9  protected bool $is_xhr;
10 
11  protected string $site_url;
12 
13  protected string $current_url;
14 
22  public function __construct(
23  protected \ElggSession $session,
24  \Elgg\Http\Request $request,
26  ) {
27  $this->is_xhr = $request->isXmlHttpRequest();
28  $this->site_url = $config->wwwroot;
29  $this->current_url = $request->getCurrentURL();
30  }
31 
37  public function setLastForwardFrom() {
38  if ($this->is_xhr) {
39  return;
40  }
41 
42  if (elgg_strpos($this->current_url, $this->site_url) !== 0) {
43  return;
44  }
45 
46  $path = elgg_substr($this->current_url, elgg_strlen($this->site_url));
47 
48  $patterns = [
49  '~^action/~',
50  '~^cache/~',
51  '~^serve-file/~',
52  ];
53  foreach ($patterns as $pattern) {
54  if (preg_match($pattern, $path)) {
55  return;
56  }
57  }
58 
59  $this->session->set('last_forward_from', $this->current_url);
60  }
61 }
__construct(protected\ElggSession $session,\Elgg\Http\Request $request,\Elgg\Config $config)
Constructor.
$request
Definition: livesearch.php:12
setLastForwardFrom()
Capture the URL the user requested when they were redirected.
Elgg Session Management.
Definition: ElggSession.php:19
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:53
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
$path
Definition: details.php:70
Handles common tasks when redirecting a request.
elgg_strpos()
Wrapper function for mb_strpos().
Definition: mb_wrapper.php:71
elgg_substr()
Wrapper function for mb_substr().
Definition: mb_wrapper.php:194
if(isset($_COOKIE['elggperm'])) $session
Definition: login_as.php:29
Request container.
Definition: Request.php:12