Elgg  Version 1.12
Request.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Http;
3 
4 use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
9 
41 class Request extends SymfonyRequest {
42 
46  public function initialize(array $query = array(), array $request = array(), array $attributes = array(),
47  array $cookies = array(), array $files = array(), array $server = array(), $content = null) {
48  $this->request = new ParameterBag($this->stripSlashesIfMagicQuotes($request));
49  $this->query = new ParameterBag($this->stripSlashesIfMagicQuotes($query));
50  $this->attributes = new ParameterBag($attributes);
51  $this->cookies = new ParameterBag($this->stripSlashesIfMagicQuotes($cookies));
52  $this->files = new FileBag($files);
53  $this->server = new ServerBag($server);
54  $this->headers = new HeaderBag($this->server->getHeaders());
55 
56  $this->content = $content;
57  $this->languages = null;
58  $this->charsets = null;
59  $this->encodings = null;
60  $this->acceptableContentTypes = null;
61  $this->pathInfo = null;
62  $this->requestUri = null;
63  $this->baseUrl = null;
64  $this->basePath = null;
65  $this->method = null;
66  $this->format = null;
67  }
68 
78  public function getUrlSegments($raw = false) {
79  $path = trim($this->query->get('__elgg_uri'), '/');
80  if (!$raw) {
81  $path = htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
82  }
83  if (!$path) {
84  return array();
85  }
86 
87  return explode('/', $path);
88  }
89 
97  public function getFirstUrlSegment() {
98  $segments = $this->getUrlSegments();
99  if ($segments) {
100  return array_shift($segments);
101  } else {
102  return '';
103  }
104  }
105 
109  public function getClientIp() {
110  $ip = parent::getClientIp();
111 
112  if ($ip == $this->server->get('REMOTE_ADDR')) {
113  // try one more
114  $ip_addresses = $this->server->get('HTTP_X_REAL_IP');
115  if ($ip_addresses) {
116  $ip_addresses = explode(',', $ip_addresses);
117  return array_pop($ip_addresses);
118  }
119  }
120 
121  return $ip;
122  }
123 
127  public function isXmlHttpRequest() {
128  return (strtolower($this->headers->get('X-Requested-With')) === 'xmlhttprequest'
129  || $this->query->get('X-Requested-With') === 'XMLHttpRequest'
130  || $this->request->get('X-Requested-With') === 'XMLHttpRequest');
131  // GET/POST check is necessary for jQuery.form and other iframe-based "ajax". #8735
132  }
133 
140  protected function stripSlashesIfMagicQuotes($data) {
141  if (get_magic_quotes_gpc()) {
143  } else {
144  return $data;
145  }
146  }
147 }
getFirstUrlSegment()
Get first URL segment from the path info.
Definition: Request.php:97
$data
Definition: opendd.php:13
$files
Definition: crop.php:36
getUrlSegments($raw=false)
Get URL segments from the path info.
Definition: Request.php:78
isXmlHttpRequest()
{}
Definition: Request.php:127
stripSlashesIfMagicQuotes($data)
Strip slashes if magic quotes is on.
Definition: Request.php:140
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition files
Definition: LICENSE.txt:210
_elgg_stripslashes_deep($value)
Strip slashes.
Definition: input.php:427
$content
Set robots.txt action.
Definition: set_robots.php:6
elgg widget content
Definition: admin.php:1250
initialize(array $query=array(), array $request=array(), array $attributes=array(), array $cookies=array(), array $files=array(), array $server=array(), $content=null)
Definition: Request.php:46
$request
$attributes
Definition: ajax_loader.php:13
$path
Definition: invalid.php:17