Elgg  Version 1.11
Request.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Http;
3 
4 use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
5 use Symfony\Component\HttpFoundation\ParameterBag;
6 use Symfony\Component\HttpFoundation\FileBag;
7 use Symfony\Component\HttpFoundation\ServerBag;
8 use Symfony\Component\HttpFoundation\HeaderBag;
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 
76  public function getUrlSegments() {
77  $path = trim($this->query->get('__elgg_uri'), '/');
78  if (!$path) {
79  return array();
80  }
81 
82  return explode('/', $path);
83  }
84 
92  public function getFirstUrlSegment() {
93  $segments = $this->getUrlSegments();
94  if ($segments) {
95  return array_shift($segments);
96  } else {
97  return '';
98  }
99  }
100 
104  public function getClientIp() {
105  $ip = parent::getClientIp();
106 
107  if ($ip == $this->server->get('REMOTE_ADDR')) {
108  // try one more
109  $ip_addresses = $this->server->get('HTTP_X_REAL_IP');
110  if ($ip_addresses) {
111  return array_pop(explode(',', $ip_addresses));
112  }
113  }
114 
115  return $ip;
116  }
117 
124  protected function stripSlashesIfMagicQuotes($data) {
125  if (get_magic_quotes_gpc()) {
127  } else {
128  return $data;
129  }
130  }
131 }
$content
Set robots.txt action.
Definition: set_robots.php:6
$files
Definition: crop.php:36
$attributes
Definition: ajax_loader.php:13
stripSlashesIfMagicQuotes($data)
Strip slashes if magic quotes is on.
Definition: Request.php:124
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
getFirstUrlSegment()
Get first URL segment from the path info.
Definition: Request.php:92
getUrlSegments()
Get URL segments from the path info.
Definition: Request.php:76
_elgg_stripslashes_deep($value)
Strip slashes.
Definition: input.php:428
$path
Definition: invalid.php:17
elgg widget content
Definition: modules.php:171
$data
Definition: opendd.php:13
$request