Completed
Branch BUG-10381-asset-loading (189bf4)
by
unknown
13:54
created

EE_Request::cookie_params()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
    exit('No direct script access allowed');
3
}
4
5
6
7
/**
8
 * class EE_Request
9
 *
10
 * @package         Event Espresso
11
 * @subpackage      /core/
12
 * @author          Brent Christensen
13
 *                  ------------------------------------------------------------------------
14
 */
15
class EE_Request
16
{
17
18
    /**
19
     * @access private
20
     * @var    array $_get $_GET parameters
21
     */
22
    private $_get = array();
23
24
    /**
25
     * @access private
26
     * @var    array $_post $_POST parameters
27
     */
28
    private $_post = array();
29
30
    /**
31
     * @access private
32
     * @var    array $_cookie $_COOKIE parameters
33
     */
34
    private $_cookie = array();
35
36
    /**
37
     * @access private
38
     * @var    array $_params $_REQUEST parameters
39
     */
40
    private $_params = array();
41
42
    /**
43
     * whether current request is via AJAX
44
     *
45
     * @var    boolean
46
     * @access public
47
     */
48
    public $ajax = false;
49
50
    /**
51
     * whether current request is via AJAX from the frontend of the site
52
     *
53
     * @var    boolean
54
     * @access public
55
     */
56
    public $front_ajax = false;
57
58
    /**
59
     * IP address for request
60
     *
61
     * @var string $_ip_address
62
     */
63
    private $_ip_address = '';
64
65
66
67
    /**
68
     * class constructor
69
     *
70
     * @access    public
71
     * @param array $get
72
     * @param array $post
73
     * @param array $cookie
74
     */
75
    public function __construct($get, $post, $cookie)
76
    {
77
        // grab request vars
78
        $this->_get = (array)$get;
79
        $this->_post = (array)$post;
80
        $this->_cookie = (array)$cookie;
81
        $this->_params = array_merge($this->_get, $this->_post);
82
        // AJAX ???
83
        $this->ajax = defined('DOING_AJAX') ? true : false;
84
        $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1;
85
        // grab user IP
86
        $this->_ip_address = $this->_visitor_ip();
87
    }
88
89
90
91
    /**
92
     * @return array
93
     */
94
    public function get_params()
95
    {
96
        return $this->_get;
97
    }
98
99
100
101
    /**
102
     * @return array
103
     */
104
    public function post_params()
105
    {
106
        return $this->_post;
107
    }
108
109
110
111
    /**
112
     * @return array
113
     */
114
    public function cookie_params()
115
    {
116
        return $this->_cookie;
117
    }
118
119
120
121
    /**
122
     * returns contents of $_REQUEST
123
     *
124
     * @return array
125
     */
126
    public function params()
127
    {
128
        return $this->_params;
129
    }
130
131
132
133
    /**
134
     *    setter
135
     *
136
     * @access    public
137
     * @param      $key
138
     * @param      $value
139
     * @param bool $override_ee
140
     * @return    void
141
     */
142 View Code Duplication
    public function set($key, $value, $override_ee = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
    {
144
        // don't allow "ee" to be overwritten unless explicitly instructed to do so
145
        if (
146
            $key !== 'ee'
147
            || ($key === 'ee' && empty($this->_params['ee']))
148
            || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
149
        ) {
150
            $this->_params[$key] = $value;
151
        }
152
    }
153
154
155
156
    /**
157
     *    getter
158
     *
159
     * @access    public
160
     * @param      $key
161
     * @param null $default
162
     * @return    mixed
163
     */
164
    public function get($key, $default = null)
165
    {
166
        return isset($this->_params[$key]) ? $this->_params[$key] : $default;
167
    }
168
169
170
171
    /**
172
     *    check if param exists
173
     *
174
     * @access    public
175
     * @param $key
176
     * @return    boolean
177
     */
178
    public function is_set($key)
179
    {
180
        return isset($this->_params[$key]) ? true : false;
181
    }
182
183
184
185
    /**
186
     *    remove param
187
     *
188
     * @access    public
189
     * @param      $key
190
     * @param bool $unset_from_global_too
191
     */
192
    public function un_set($key, $unset_from_global_too = false)
193
    {
194
        unset($this->_params[$key]);
195
        if ($unset_from_global_too) {
196
            unset($_REQUEST[$key]);
197
        }
198
    }
199
200
201
202
    /**
203
     * @return string
204
     */
205
    public function ip_address()
206
    {
207
        return $this->_ip_address;
208
    }
209
210
211
212
    /**
213
     * _visitor_ip
214
     *    attempt to get IP address of current visitor from server
215
     * plz see: http://stackoverflow.com/a/2031935/1475279
216
     *
217
     * @access public
218
     * @return string
219
     */
220 View Code Duplication
    private function _visitor_ip()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
221
    {
222
        $visitor_ip = '0.0.0.0';
223
        $server_keys = array(
224
            'HTTP_CLIENT_IP',
225
            'HTTP_X_FORWARDED_FOR',
226
            'HTTP_X_FORWARDED',
227
            'HTTP_X_CLUSTER_CLIENT_IP',
228
            'HTTP_FORWARDED_FOR',
229
            'HTTP_FORWARDED',
230
            'REMOTE_ADDR',
231
        );
232
        foreach ($server_keys as $key) {
233
            if (isset($_SERVER[$key])) {
234
                foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
235
                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
236
                        $visitor_ip = $ip;
237
                    }
238
                }
239
            }
240
        }
241
        return $visitor_ip;
242
    }
243
244
245
246
}
247
// End of file EE_Request.core.php
248
// Location: /core/request_stack/EE_Request.core.php