Elgg  Version 2.3
Request.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Http;
3 
4 use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
6 
12 class Request extends SymfonyRequest {
13 
21  public function getUrlSegments($raw = false) {
22  $path = trim($this->query->get(Application::GET_PATH_KEY), '/');
23  if (!$raw) {
24  $path = htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
25  }
26  if (!$path) {
27  return array();
28  }
29 
30  return explode('/', $path);
31  }
32 
40  public function setUrlSegments(array $segments) {
41  $query = $this->query->all();
42  $query[Application::GET_PATH_KEY] = '/' . implode('/', $segments);
43  return $this->duplicate($query);
44  }
45 
53  public function getFirstUrlSegment() {
54  $segments = $this->getUrlSegments();
55  if ($segments) {
56  return array_shift($segments);
57  } else {
58  return '';
59  }
60  }
61 
65  public function getClientIp() {
66  $ip = parent::getClientIp();
67 
68  if ($ip == $this->server->get('REMOTE_ADDR')) {
69  // try one more
70  $ip_addresses = $this->server->get('HTTP_X_REAL_IP');
71  if ($ip_addresses) {
72  $ip_addresses = explode(',', $ip_addresses);
73  return array_pop($ip_addresses);
74  }
75  }
76 
77  return $ip;
78  }
79 
83  public function isXmlHttpRequest() {
84  return (strtolower($this->headers->get('X-Requested-With')) === 'xmlhttprequest'
85  || $this->query->get('X-Requested-With') === 'XMLHttpRequest'
86  || $this->request->get('X-Requested-With') === 'XMLHttpRequest');
87  // GET/POST check is necessary for jQuery.form and other iframe-based "ajax". #8735
88  }
89 }
Elgg HTTP request.
Definition: Request.php:12
getFirstUrlSegment()
Get first Elgg URL segment.
Definition: Request.php:53
$path
Definition: details.php:88
getUrlSegments($raw=false)
Get the Elgg URL segments.
Definition: Request.php:21
setUrlSegments(array $segments)
Get a cloned request with new Elgg URL segments.
Definition: Request.php:40
isXmlHttpRequest()
{}
Definition: Request.php:83
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:5