@@ -15,289 +15,289 @@ |
||
15 | 15 | class EE_Request implements InterminableInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * $_GET parameters |
|
20 | - * |
|
21 | - * @var array $_get |
|
22 | - */ |
|
23 | - private $_get; |
|
24 | - |
|
25 | - /** |
|
26 | - * $_POST parameters |
|
27 | - * |
|
28 | - * @var array $_post |
|
29 | - */ |
|
30 | - private $_post; |
|
31 | - |
|
32 | - /** |
|
33 | - * $_COOKIE parameters |
|
34 | - * |
|
35 | - * @var array $_cookie |
|
36 | - */ |
|
37 | - private $_cookie; |
|
38 | - |
|
39 | - /** |
|
40 | - * $_REQUEST parameters |
|
41 | - * |
|
42 | - * @var array $_params |
|
43 | - */ |
|
44 | - private $_params; |
|
45 | - |
|
46 | - /** |
|
47 | - * whether current request is via AJAX |
|
48 | - * |
|
49 | - * @access public |
|
50 | - */ |
|
51 | - public $ajax = false; |
|
52 | - |
|
53 | - /** |
|
54 | - * whether current request is via AJAX from the frontend of the site |
|
55 | - * |
|
56 | - * @access public |
|
57 | - */ |
|
58 | - public $front_ajax = false; |
|
59 | - |
|
60 | - /** |
|
61 | - * IP address for request |
|
62 | - * |
|
63 | - * @var string $_ip_address |
|
64 | - */ |
|
65 | - private $_ip_address; |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * class constructor |
|
71 | - * |
|
72 | - * @access public |
|
73 | - * @param array $get |
|
74 | - * @param array $post |
|
75 | - * @param array $cookie |
|
76 | - */ |
|
77 | - public function __construct(array $get, array $post, array $cookie) |
|
78 | - { |
|
79 | - // grab request vars |
|
80 | - $this->_get = (array)$get; |
|
81 | - $this->_post = (array)$post; |
|
82 | - $this->_cookie = (array)$cookie; |
|
83 | - $this->_params = array_merge($this->_get, $this->_post); |
|
84 | - // AJAX ??? |
|
85 | - $this->ajax = defined('DOING_AJAX') ? true : false; |
|
86 | - $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1; |
|
87 | - // grab user IP |
|
88 | - $this->_ip_address = $this->_visitor_ip(); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function get_params() |
|
97 | - { |
|
98 | - return $this->_get; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return array |
|
105 | - */ |
|
106 | - public function post_params() |
|
107 | - { |
|
108 | - return $this->_post; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - public function cookie_params() |
|
117 | - { |
|
118 | - return $this->_cookie; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * returns contents of $_REQUEST |
|
125 | - * |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public function params() |
|
129 | - { |
|
130 | - return $this->_params; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param $key |
|
137 | - * @param $value |
|
138 | - * @param bool $override_ee |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - public function set($key, $value, $override_ee = false) |
|
142 | - { |
|
143 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
144 | - if ( |
|
145 | - $key !== 'ee' |
|
146 | - || ($key === 'ee' && empty($this->_params['ee'])) |
|
147 | - || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee) |
|
148 | - ) { |
|
149 | - $this->_params[$key] = $value; |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * returns the value for a request param if the given key exists |
|
157 | - * |
|
158 | - * @param $key |
|
159 | - * @param null $default |
|
160 | - * @return mixed |
|
161 | - */ |
|
162 | - public function get($key, $default = null) |
|
163 | - { |
|
164 | - return $this->request_parameter_drill_down($key, $default, 'get'); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * check if param exists |
|
171 | - * @param $key |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function is_set($key) |
|
175 | - { |
|
176 | - return $this->request_parameter_drill_down($key); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
183 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
184 | - * by using square brackets to surround keys for deeper array elements. |
|
185 | - * For example : |
|
186 | - * if the supplied $key was: "first[second][third]" |
|
187 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
188 | - * Given the following request parameters: |
|
189 | - * array( |
|
190 | - * 'first' => array( |
|
191 | - * 'second' => array( |
|
192 | - * 'third' => 'has a value' |
|
193 | - * ) |
|
194 | - * ) |
|
195 | - * ) |
|
196 | - * would return true |
|
197 | - * |
|
198 | - * @param string $is_set_or_get |
|
199 | - * @param $key |
|
200 | - * @param null $default |
|
201 | - * @param array $request_params |
|
202 | - * @return bool|mixed|null |
|
203 | - */ |
|
204 | - private function request_parameter_drill_down( |
|
205 | - $key, |
|
206 | - $default = null, |
|
207 | - $is_set_or_get = 'is_set', |
|
208 | - array $request_params = array() |
|
209 | - ) { |
|
210 | - $request_params = ! empty($request_params) |
|
211 | - ? $request_params |
|
212 | - : $this->_params; |
|
213 | - // does incoming key represent an array like 'first[second][third]' ? |
|
214 | - if (strpos($key, '[') !== false) { |
|
215 | - // turn it into an actual array |
|
216 | - $key = str_replace(']', '', $key); |
|
217 | - $keys = explode('[', $key); |
|
218 | - $key = array_shift($keys); |
|
219 | - // check if top level key exists |
|
220 | - if (isset($request_params[$key])) { |
|
221 | - // build a new key to pass along like: 'second[third]' |
|
222 | - // or just 'second' depending on depth of keys |
|
223 | - $key_string = array_shift($keys); |
|
224 | - if (! empty($keys)) { |
|
225 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
226 | - } |
|
227 | - return $this->request_parameter_drill_down( |
|
228 | - $key_string, |
|
229 | - $default, |
|
230 | - $is_set_or_get, |
|
231 | - $request_params[$key] |
|
232 | - ); |
|
233 | - } |
|
234 | - } |
|
235 | - if ($is_set_or_get === 'is_set') { |
|
236 | - return isset($request_params[$key]); |
|
237 | - } |
|
238 | - return isset($request_params[$key]) |
|
239 | - ? $request_params[$key] |
|
240 | - : $default; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * remove param |
|
247 | - * @param $key |
|
248 | - * @param bool $unset_from_global_too |
|
249 | - */ |
|
250 | - public function un_set($key, $unset_from_global_too = false) |
|
251 | - { |
|
252 | - unset($this->_params[$key]); |
|
253 | - if ($unset_from_global_too) { |
|
254 | - unset($_REQUEST[$key]); |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function ip_address() |
|
264 | - { |
|
265 | - return $this->_ip_address; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * _visitor_ip |
|
272 | - * attempt to get IP address of current visitor from server |
|
273 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
274 | - * |
|
275 | - * @access public |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - private function _visitor_ip() |
|
279 | - { |
|
280 | - $visitor_ip = '0.0.0.0'; |
|
281 | - $server_keys = array( |
|
282 | - 'HTTP_CLIENT_IP', |
|
283 | - 'HTTP_X_FORWARDED_FOR', |
|
284 | - 'HTTP_X_FORWARDED', |
|
285 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
286 | - 'HTTP_FORWARDED_FOR', |
|
287 | - 'HTTP_FORWARDED', |
|
288 | - 'REMOTE_ADDR', |
|
289 | - ); |
|
290 | - foreach ($server_keys as $key) { |
|
291 | - if (isset($_SERVER[$key])) { |
|
292 | - foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
293 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
294 | - $visitor_ip = $ip; |
|
295 | - } |
|
296 | - } |
|
297 | - } |
|
298 | - } |
|
299 | - return $visitor_ip; |
|
300 | - } |
|
18 | + /** |
|
19 | + * $_GET parameters |
|
20 | + * |
|
21 | + * @var array $_get |
|
22 | + */ |
|
23 | + private $_get; |
|
24 | + |
|
25 | + /** |
|
26 | + * $_POST parameters |
|
27 | + * |
|
28 | + * @var array $_post |
|
29 | + */ |
|
30 | + private $_post; |
|
31 | + |
|
32 | + /** |
|
33 | + * $_COOKIE parameters |
|
34 | + * |
|
35 | + * @var array $_cookie |
|
36 | + */ |
|
37 | + private $_cookie; |
|
38 | + |
|
39 | + /** |
|
40 | + * $_REQUEST parameters |
|
41 | + * |
|
42 | + * @var array $_params |
|
43 | + */ |
|
44 | + private $_params; |
|
45 | + |
|
46 | + /** |
|
47 | + * whether current request is via AJAX |
|
48 | + * |
|
49 | + * @access public |
|
50 | + */ |
|
51 | + public $ajax = false; |
|
52 | + |
|
53 | + /** |
|
54 | + * whether current request is via AJAX from the frontend of the site |
|
55 | + * |
|
56 | + * @access public |
|
57 | + */ |
|
58 | + public $front_ajax = false; |
|
59 | + |
|
60 | + /** |
|
61 | + * IP address for request |
|
62 | + * |
|
63 | + * @var string $_ip_address |
|
64 | + */ |
|
65 | + private $_ip_address; |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * class constructor |
|
71 | + * |
|
72 | + * @access public |
|
73 | + * @param array $get |
|
74 | + * @param array $post |
|
75 | + * @param array $cookie |
|
76 | + */ |
|
77 | + public function __construct(array $get, array $post, array $cookie) |
|
78 | + { |
|
79 | + // grab request vars |
|
80 | + $this->_get = (array)$get; |
|
81 | + $this->_post = (array)$post; |
|
82 | + $this->_cookie = (array)$cookie; |
|
83 | + $this->_params = array_merge($this->_get, $this->_post); |
|
84 | + // AJAX ??? |
|
85 | + $this->ajax = defined('DOING_AJAX') ? true : false; |
|
86 | + $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1; |
|
87 | + // grab user IP |
|
88 | + $this->_ip_address = $this->_visitor_ip(); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function get_params() |
|
97 | + { |
|
98 | + return $this->_get; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return array |
|
105 | + */ |
|
106 | + public function post_params() |
|
107 | + { |
|
108 | + return $this->_post; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + public function cookie_params() |
|
117 | + { |
|
118 | + return $this->_cookie; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * returns contents of $_REQUEST |
|
125 | + * |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public function params() |
|
129 | + { |
|
130 | + return $this->_params; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param $key |
|
137 | + * @param $value |
|
138 | + * @param bool $override_ee |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + public function set($key, $value, $override_ee = false) |
|
142 | + { |
|
143 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
144 | + if ( |
|
145 | + $key !== 'ee' |
|
146 | + || ($key === 'ee' && empty($this->_params['ee'])) |
|
147 | + || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee) |
|
148 | + ) { |
|
149 | + $this->_params[$key] = $value; |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * returns the value for a request param if the given key exists |
|
157 | + * |
|
158 | + * @param $key |
|
159 | + * @param null $default |
|
160 | + * @return mixed |
|
161 | + */ |
|
162 | + public function get($key, $default = null) |
|
163 | + { |
|
164 | + return $this->request_parameter_drill_down($key, $default, 'get'); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * check if param exists |
|
171 | + * @param $key |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function is_set($key) |
|
175 | + { |
|
176 | + return $this->request_parameter_drill_down($key); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
183 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
184 | + * by using square brackets to surround keys for deeper array elements. |
|
185 | + * For example : |
|
186 | + * if the supplied $key was: "first[second][third]" |
|
187 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
188 | + * Given the following request parameters: |
|
189 | + * array( |
|
190 | + * 'first' => array( |
|
191 | + * 'second' => array( |
|
192 | + * 'third' => 'has a value' |
|
193 | + * ) |
|
194 | + * ) |
|
195 | + * ) |
|
196 | + * would return true |
|
197 | + * |
|
198 | + * @param string $is_set_or_get |
|
199 | + * @param $key |
|
200 | + * @param null $default |
|
201 | + * @param array $request_params |
|
202 | + * @return bool|mixed|null |
|
203 | + */ |
|
204 | + private function request_parameter_drill_down( |
|
205 | + $key, |
|
206 | + $default = null, |
|
207 | + $is_set_or_get = 'is_set', |
|
208 | + array $request_params = array() |
|
209 | + ) { |
|
210 | + $request_params = ! empty($request_params) |
|
211 | + ? $request_params |
|
212 | + : $this->_params; |
|
213 | + // does incoming key represent an array like 'first[second][third]' ? |
|
214 | + if (strpos($key, '[') !== false) { |
|
215 | + // turn it into an actual array |
|
216 | + $key = str_replace(']', '', $key); |
|
217 | + $keys = explode('[', $key); |
|
218 | + $key = array_shift($keys); |
|
219 | + // check if top level key exists |
|
220 | + if (isset($request_params[$key])) { |
|
221 | + // build a new key to pass along like: 'second[third]' |
|
222 | + // or just 'second' depending on depth of keys |
|
223 | + $key_string = array_shift($keys); |
|
224 | + if (! empty($keys)) { |
|
225 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
226 | + } |
|
227 | + return $this->request_parameter_drill_down( |
|
228 | + $key_string, |
|
229 | + $default, |
|
230 | + $is_set_or_get, |
|
231 | + $request_params[$key] |
|
232 | + ); |
|
233 | + } |
|
234 | + } |
|
235 | + if ($is_set_or_get === 'is_set') { |
|
236 | + return isset($request_params[$key]); |
|
237 | + } |
|
238 | + return isset($request_params[$key]) |
|
239 | + ? $request_params[$key] |
|
240 | + : $default; |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * remove param |
|
247 | + * @param $key |
|
248 | + * @param bool $unset_from_global_too |
|
249 | + */ |
|
250 | + public function un_set($key, $unset_from_global_too = false) |
|
251 | + { |
|
252 | + unset($this->_params[$key]); |
|
253 | + if ($unset_from_global_too) { |
|
254 | + unset($_REQUEST[$key]); |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function ip_address() |
|
264 | + { |
|
265 | + return $this->_ip_address; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * _visitor_ip |
|
272 | + * attempt to get IP address of current visitor from server |
|
273 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
274 | + * |
|
275 | + * @access public |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + private function _visitor_ip() |
|
279 | + { |
|
280 | + $visitor_ip = '0.0.0.0'; |
|
281 | + $server_keys = array( |
|
282 | + 'HTTP_CLIENT_IP', |
|
283 | + 'HTTP_X_FORWARDED_FOR', |
|
284 | + 'HTTP_X_FORWARDED', |
|
285 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
286 | + 'HTTP_FORWARDED_FOR', |
|
287 | + 'HTTP_FORWARDED', |
|
288 | + 'REMOTE_ADDR', |
|
289 | + ); |
|
290 | + foreach ($server_keys as $key) { |
|
291 | + if (isset($_SERVER[$key])) { |
|
292 | + foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
293 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
294 | + $visitor_ip = $ip; |
|
295 | + } |
|
296 | + } |
|
297 | + } |
|
298 | + } |
|
299 | + return $visitor_ip; |
|
300 | + } |
|
301 | 301 | |
302 | 302 | |
303 | 303 |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | public function __construct(array $get, array $post, array $cookie) |
78 | 78 | { |
79 | 79 | // grab request vars |
80 | - $this->_get = (array)$get; |
|
81 | - $this->_post = (array)$post; |
|
82 | - $this->_cookie = (array)$cookie; |
|
80 | + $this->_get = (array) $get; |
|
81 | + $this->_post = (array) $post; |
|
82 | + $this->_cookie = (array) $cookie; |
|
83 | 83 | $this->_params = array_merge($this->_get, $this->_post); |
84 | 84 | // AJAX ??? |
85 | 85 | $this->ajax = defined('DOING_AJAX') ? true : false; |
86 | - $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1; |
|
86 | + $this->front_ajax = $this->is_set('ee_front_ajax') && (int) $this->get('ee_front_ajax') === 1; |
|
87 | 87 | // grab user IP |
88 | 88 | $this->_ip_address = $this->_visitor_ip(); |
89 | 89 | } |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | // build a new key to pass along like: 'second[third]' |
222 | 222 | // or just 'second' depending on depth of keys |
223 | 223 | $key_string = array_shift($keys); |
224 | - if (! empty($keys)) { |
|
225 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
224 | + if ( ! empty($keys)) { |
|
225 | + $key_string .= '['.implode('][', $keys).']'; |
|
226 | 226 | } |
227 | 227 | return $this->request_parameter_drill_down( |
228 | 228 | $key_string, |
@@ -18,305 +18,305 @@ |
||
18 | 18 | class DatetimeOffsetFix extends JobHandler |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Key for the option used to track which models have been processed when doing the batches. |
|
23 | - */ |
|
24 | - const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix'; |
|
25 | - |
|
26 | - |
|
27 | - const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Key for the option used to track what the current offset is that will be applied when this tool is executed. |
|
31 | - */ |
|
32 | - const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply'; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * String labelling the datetime offset fix type for change-log entries. |
|
37 | - */ |
|
38 | - const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix'; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * String labelling a datetime offset fix error for change-log entries. |
|
43 | - */ |
|
44 | - const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error'; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var EEM_Base[] |
|
48 | - */ |
|
49 | - protected $models_with_datetime_fields = array(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Performs any necessary setup for starting the job. This is also a good |
|
54 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
55 | - * when continue_job will be called |
|
56 | - * |
|
57 | - * @param JobParameters $job_parameters |
|
58 | - * @throws BatchRequestException |
|
59 | - * @return JobStepResponse |
|
60 | - */ |
|
61 | - public function create_job(JobParameters $job_parameters) |
|
62 | - { |
|
63 | - $models_with_datetime_fields = $this->getModelsWithDatetimeFields(); |
|
64 | - //we'll be doing each model as a batch. |
|
65 | - $job_parameters->set_job_size(count($models_with_datetime_fields)); |
|
66 | - return new JobStepResponse( |
|
67 | - $job_parameters, |
|
68 | - esc_html__('Starting Datetime Offset Fix', 'event_espresso') |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Performs another step of the job |
|
74 | - * |
|
75 | - * @param JobParameters $job_parameters |
|
76 | - * @param int $batch_size |
|
77 | - * @return JobStepResponse |
|
78 | - * @throws \EE_Error |
|
79 | - */ |
|
80 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
81 | - { |
|
82 | - $models_to_process = $this->getModelsWithDatetimeFields(); |
|
83 | - //let's pop off the a model and do the query to apply the offset. |
|
84 | - $model_to_process = array_pop($models_to_process); |
|
85 | - //update our record |
|
86 | - $this->setModelsToProcess($models_to_process); |
|
87 | - $this->processModel($model_to_process); |
|
88 | - $this->updateCountOfModelsProcessed(); |
|
89 | - $job_parameters->set_units_processed($this->getCountOfModelsProcessed()); |
|
90 | - if (count($models_to_process) > 0) { |
|
91 | - $job_parameters->set_status(JobParameters::status_continue); |
|
92 | - } else { |
|
93 | - $job_parameters->set_status(JobParameters::status_complete); |
|
94 | - } |
|
95 | - return new JobStepResponse( |
|
96 | - $job_parameters, |
|
97 | - sprintf( |
|
98 | - esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'), |
|
99 | - $model_to_process |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Performs any clean-up logic when we know the job is completed |
|
106 | - * |
|
107 | - * @param JobParameters $job_parameters |
|
108 | - * @return JobStepResponse |
|
109 | - * @throws BatchRequestException |
|
110 | - */ |
|
111 | - public function cleanup_job(JobParameters $job_parameters) |
|
112 | - { |
|
113 | - //delete important saved options. |
|
114 | - delete_option(self::MODELS_TO_PROCESS_OPTION_KEY); |
|
115 | - delete_option(self::COUNT_OF_MODELS_PROCESSED); |
|
116 | - return new JobStepResponse($job_parameters, esc_html__( |
|
117 | - 'Offset has been applied to all affected fields.', |
|
118 | - 'event_espresso' |
|
119 | - )); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Contains the logic for processing a model and applying the datetime offset to affected fields on that model. |
|
125 | - * @param string $model_class_name |
|
126 | - * @throws \EE_Error |
|
127 | - */ |
|
128 | - protected function processModel($model_class_name) |
|
129 | - { |
|
130 | - global $wpdb; |
|
131 | - /** @var EEM_Base $model */ |
|
132 | - $model = $model_class_name::instance(); |
|
133 | - $original_offset = self::getOffset(); |
|
134 | - $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB'; |
|
135 | - $offset = abs($original_offset) * 60; |
|
136 | - //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
|
137 | - foreach ($model->get_tables() as $table) { |
|
138 | - $query = 'UPDATE ' . $table->get_table_name(); |
|
139 | - $fields_affected = array(); |
|
140 | - $inner_query = array(); |
|
141 | - foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
|
142 | - if ($model_field instanceof EE_Datetime_Field) { |
|
143 | - $inner_query[] = $model_field->get_table_column() . ' = ' |
|
144 | - . $sql_date_function . '(' |
|
145 | - . $model_field->get_table_column() |
|
146 | - . ", INTERVAL $offset MINUTE)"; |
|
147 | - $fields_affected[] = $model_field; |
|
148 | - } |
|
149 | - } |
|
150 | - if (! $fields_affected) { |
|
151 | - continue; |
|
152 | - } |
|
153 | - //k convert innerquery to string |
|
154 | - $query .= ' SET ' . implode(',', $inner_query); |
|
155 | - //execute query |
|
156 | - $result = $wpdb->query($query); |
|
157 | - //record log |
|
158 | - if ($result !== false) { |
|
159 | - $this->recordChangeLog($model, $original_offset, $table, $fields_affected); |
|
160 | - } else { |
|
161 | - //record error. |
|
162 | - $error_message = $wpdb->last_error; |
|
163 | - //handle the edgecases where last_error might be empty. |
|
164 | - if (! $error_message) { |
|
165 | - $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
|
166 | - } |
|
167 | - $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Records a changelog entry using the given information. |
|
175 | - * |
|
176 | - * @param EEM_Base $model |
|
177 | - * @param float $offset |
|
178 | - * @param EE_Table_Base $table |
|
179 | - * @param EE_Model_Field_Base[] $model_fields_affected |
|
180 | - * @param string $error_message If present then there was an error so let's record that instead. |
|
181 | - * @throws \EE_Error |
|
182 | - */ |
|
183 | - private function recordChangeLog( |
|
184 | - EEM_Base $model, |
|
185 | - $offset, |
|
186 | - EE_Table_Base $table, |
|
187 | - $model_fields_affected, |
|
188 | - $error_message = '' |
|
189 | - ) { |
|
190 | - //setup $fields list. |
|
191 | - $fields = array(); |
|
192 | - /** @var EE_Datetime_Field $model_field */ |
|
193 | - foreach ($model_fields_affected as $model_field) { |
|
194 | - if (! $model_field instanceof EE_Datetime_Field) { |
|
195 | - continue; |
|
196 | - } |
|
197 | - $fields[] = $model_field->get_name(); |
|
198 | - } |
|
199 | - //setup the message for the changelog entry. |
|
200 | - $message = $error_message |
|
201 | - ? sprintf( |
|
202 | - esc_html__( |
|
203 | - 'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s', |
|
204 | - 'event_espresso' |
|
205 | - ), |
|
206 | - $table->get_table_name(), |
|
207 | - $model->get_this_model_name(), |
|
208 | - $offset, |
|
209 | - implode(',', $fields), |
|
210 | - $error_message |
|
211 | - ) |
|
212 | - : sprintf( |
|
213 | - esc_html__( |
|
214 | - 'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s', |
|
215 | - 'event_espresso' |
|
216 | - ), |
|
217 | - $table->get_table_name(), |
|
218 | - $model->get_this_model_name(), |
|
219 | - $offset, |
|
220 | - implode(',', $fields) |
|
221 | - ); |
|
222 | - //write to the log |
|
223 | - $changelog = EE_Change_Log::new_instance(array( |
|
224 | - 'LOG_type' => $error_message |
|
225 | - ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE |
|
226 | - : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE, |
|
227 | - 'LOG_message' => $message |
|
228 | - )); |
|
229 | - $changelog->save(); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * Returns an array of models that have datetime fields. |
|
235 | - * This array is added to a short lived transient cache to keep having to build this list to a minimum. |
|
236 | - * @return array an array of model class names. |
|
237 | - */ |
|
238 | - private function getModelsWithDatetimeFields() |
|
239 | - { |
|
240 | - $this->getModelsToProcess(); |
|
241 | - if (! empty($this->models_with_datetime_fields)) { |
|
242 | - return $this->models_with_datetime_fields; |
|
243 | - } |
|
244 | - |
|
245 | - $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models; |
|
246 | - foreach ($all_non_abstract_models as $non_abstract_model) { |
|
247 | - //get model instance |
|
248 | - /** @var EEM_Base $non_abstract_model */ |
|
249 | - $non_abstract_model = $non_abstract_model::instance(); |
|
250 | - if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) { |
|
251 | - $this->models_with_datetime_fields[] = get_class($non_abstract_model); |
|
252 | - } |
|
253 | - } |
|
254 | - $this->setModelsToProcess($this->models_with_datetime_fields); |
|
255 | - return $this->models_with_datetime_fields; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * This simply records the models that have been processed with our tracking option. |
|
261 | - * @param array $models_to_set array of model class names. |
|
262 | - */ |
|
263 | - private function setModelsToProcess($models_to_set) |
|
264 | - { |
|
265 | - update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * Used to keep track of how many models have been processed for the batch |
|
271 | - * @param $count |
|
272 | - */ |
|
273 | - private function updateCountOfModelsProcessed($count = 1) |
|
274 | - { |
|
275 | - $count = $this->getCountOfModelsProcessed() + (int) $count; |
|
276 | - update_option(self::COUNT_OF_MODELS_PROCESSED, $count); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Retrieve the tracked number of models processed between requests. |
|
282 | - * @return int |
|
283 | - */ |
|
284 | - private function getCountOfModelsProcessed() |
|
285 | - { |
|
286 | - return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Returns the models that are left to process. |
|
292 | - * @return array an array of model class names. |
|
293 | - */ |
|
294 | - private function getModelsToProcess() |
|
295 | - { |
|
296 | - if (empty($this->models_with_datetime_fields)) { |
|
297 | - $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array()); |
|
298 | - } |
|
299 | - return $this->models_with_datetime_fields; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
305 | - * @param float $offset |
|
306 | - */ |
|
307 | - public static function updateOffset($offset) |
|
308 | - { |
|
309 | - update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
315 | - * |
|
316 | - * @return float |
|
317 | - */ |
|
318 | - public static function getOffset() |
|
319 | - { |
|
320 | - return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0); |
|
321 | - } |
|
21 | + /** |
|
22 | + * Key for the option used to track which models have been processed when doing the batches. |
|
23 | + */ |
|
24 | + const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix'; |
|
25 | + |
|
26 | + |
|
27 | + const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Key for the option used to track what the current offset is that will be applied when this tool is executed. |
|
31 | + */ |
|
32 | + const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply'; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * String labelling the datetime offset fix type for change-log entries. |
|
37 | + */ |
|
38 | + const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix'; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * String labelling a datetime offset fix error for change-log entries. |
|
43 | + */ |
|
44 | + const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error'; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var EEM_Base[] |
|
48 | + */ |
|
49 | + protected $models_with_datetime_fields = array(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Performs any necessary setup for starting the job. This is also a good |
|
54 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
55 | + * when continue_job will be called |
|
56 | + * |
|
57 | + * @param JobParameters $job_parameters |
|
58 | + * @throws BatchRequestException |
|
59 | + * @return JobStepResponse |
|
60 | + */ |
|
61 | + public function create_job(JobParameters $job_parameters) |
|
62 | + { |
|
63 | + $models_with_datetime_fields = $this->getModelsWithDatetimeFields(); |
|
64 | + //we'll be doing each model as a batch. |
|
65 | + $job_parameters->set_job_size(count($models_with_datetime_fields)); |
|
66 | + return new JobStepResponse( |
|
67 | + $job_parameters, |
|
68 | + esc_html__('Starting Datetime Offset Fix', 'event_espresso') |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Performs another step of the job |
|
74 | + * |
|
75 | + * @param JobParameters $job_parameters |
|
76 | + * @param int $batch_size |
|
77 | + * @return JobStepResponse |
|
78 | + * @throws \EE_Error |
|
79 | + */ |
|
80 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
81 | + { |
|
82 | + $models_to_process = $this->getModelsWithDatetimeFields(); |
|
83 | + //let's pop off the a model and do the query to apply the offset. |
|
84 | + $model_to_process = array_pop($models_to_process); |
|
85 | + //update our record |
|
86 | + $this->setModelsToProcess($models_to_process); |
|
87 | + $this->processModel($model_to_process); |
|
88 | + $this->updateCountOfModelsProcessed(); |
|
89 | + $job_parameters->set_units_processed($this->getCountOfModelsProcessed()); |
|
90 | + if (count($models_to_process) > 0) { |
|
91 | + $job_parameters->set_status(JobParameters::status_continue); |
|
92 | + } else { |
|
93 | + $job_parameters->set_status(JobParameters::status_complete); |
|
94 | + } |
|
95 | + return new JobStepResponse( |
|
96 | + $job_parameters, |
|
97 | + sprintf( |
|
98 | + esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'), |
|
99 | + $model_to_process |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Performs any clean-up logic when we know the job is completed |
|
106 | + * |
|
107 | + * @param JobParameters $job_parameters |
|
108 | + * @return JobStepResponse |
|
109 | + * @throws BatchRequestException |
|
110 | + */ |
|
111 | + public function cleanup_job(JobParameters $job_parameters) |
|
112 | + { |
|
113 | + //delete important saved options. |
|
114 | + delete_option(self::MODELS_TO_PROCESS_OPTION_KEY); |
|
115 | + delete_option(self::COUNT_OF_MODELS_PROCESSED); |
|
116 | + return new JobStepResponse($job_parameters, esc_html__( |
|
117 | + 'Offset has been applied to all affected fields.', |
|
118 | + 'event_espresso' |
|
119 | + )); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Contains the logic for processing a model and applying the datetime offset to affected fields on that model. |
|
125 | + * @param string $model_class_name |
|
126 | + * @throws \EE_Error |
|
127 | + */ |
|
128 | + protected function processModel($model_class_name) |
|
129 | + { |
|
130 | + global $wpdb; |
|
131 | + /** @var EEM_Base $model */ |
|
132 | + $model = $model_class_name::instance(); |
|
133 | + $original_offset = self::getOffset(); |
|
134 | + $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB'; |
|
135 | + $offset = abs($original_offset) * 60; |
|
136 | + //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
|
137 | + foreach ($model->get_tables() as $table) { |
|
138 | + $query = 'UPDATE ' . $table->get_table_name(); |
|
139 | + $fields_affected = array(); |
|
140 | + $inner_query = array(); |
|
141 | + foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
|
142 | + if ($model_field instanceof EE_Datetime_Field) { |
|
143 | + $inner_query[] = $model_field->get_table_column() . ' = ' |
|
144 | + . $sql_date_function . '(' |
|
145 | + . $model_field->get_table_column() |
|
146 | + . ", INTERVAL $offset MINUTE)"; |
|
147 | + $fields_affected[] = $model_field; |
|
148 | + } |
|
149 | + } |
|
150 | + if (! $fields_affected) { |
|
151 | + continue; |
|
152 | + } |
|
153 | + //k convert innerquery to string |
|
154 | + $query .= ' SET ' . implode(',', $inner_query); |
|
155 | + //execute query |
|
156 | + $result = $wpdb->query($query); |
|
157 | + //record log |
|
158 | + if ($result !== false) { |
|
159 | + $this->recordChangeLog($model, $original_offset, $table, $fields_affected); |
|
160 | + } else { |
|
161 | + //record error. |
|
162 | + $error_message = $wpdb->last_error; |
|
163 | + //handle the edgecases where last_error might be empty. |
|
164 | + if (! $error_message) { |
|
165 | + $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
|
166 | + } |
|
167 | + $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Records a changelog entry using the given information. |
|
175 | + * |
|
176 | + * @param EEM_Base $model |
|
177 | + * @param float $offset |
|
178 | + * @param EE_Table_Base $table |
|
179 | + * @param EE_Model_Field_Base[] $model_fields_affected |
|
180 | + * @param string $error_message If present then there was an error so let's record that instead. |
|
181 | + * @throws \EE_Error |
|
182 | + */ |
|
183 | + private function recordChangeLog( |
|
184 | + EEM_Base $model, |
|
185 | + $offset, |
|
186 | + EE_Table_Base $table, |
|
187 | + $model_fields_affected, |
|
188 | + $error_message = '' |
|
189 | + ) { |
|
190 | + //setup $fields list. |
|
191 | + $fields = array(); |
|
192 | + /** @var EE_Datetime_Field $model_field */ |
|
193 | + foreach ($model_fields_affected as $model_field) { |
|
194 | + if (! $model_field instanceof EE_Datetime_Field) { |
|
195 | + continue; |
|
196 | + } |
|
197 | + $fields[] = $model_field->get_name(); |
|
198 | + } |
|
199 | + //setup the message for the changelog entry. |
|
200 | + $message = $error_message |
|
201 | + ? sprintf( |
|
202 | + esc_html__( |
|
203 | + 'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s', |
|
204 | + 'event_espresso' |
|
205 | + ), |
|
206 | + $table->get_table_name(), |
|
207 | + $model->get_this_model_name(), |
|
208 | + $offset, |
|
209 | + implode(',', $fields), |
|
210 | + $error_message |
|
211 | + ) |
|
212 | + : sprintf( |
|
213 | + esc_html__( |
|
214 | + 'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s', |
|
215 | + 'event_espresso' |
|
216 | + ), |
|
217 | + $table->get_table_name(), |
|
218 | + $model->get_this_model_name(), |
|
219 | + $offset, |
|
220 | + implode(',', $fields) |
|
221 | + ); |
|
222 | + //write to the log |
|
223 | + $changelog = EE_Change_Log::new_instance(array( |
|
224 | + 'LOG_type' => $error_message |
|
225 | + ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE |
|
226 | + : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE, |
|
227 | + 'LOG_message' => $message |
|
228 | + )); |
|
229 | + $changelog->save(); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * Returns an array of models that have datetime fields. |
|
235 | + * This array is added to a short lived transient cache to keep having to build this list to a minimum. |
|
236 | + * @return array an array of model class names. |
|
237 | + */ |
|
238 | + private function getModelsWithDatetimeFields() |
|
239 | + { |
|
240 | + $this->getModelsToProcess(); |
|
241 | + if (! empty($this->models_with_datetime_fields)) { |
|
242 | + return $this->models_with_datetime_fields; |
|
243 | + } |
|
244 | + |
|
245 | + $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models; |
|
246 | + foreach ($all_non_abstract_models as $non_abstract_model) { |
|
247 | + //get model instance |
|
248 | + /** @var EEM_Base $non_abstract_model */ |
|
249 | + $non_abstract_model = $non_abstract_model::instance(); |
|
250 | + if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) { |
|
251 | + $this->models_with_datetime_fields[] = get_class($non_abstract_model); |
|
252 | + } |
|
253 | + } |
|
254 | + $this->setModelsToProcess($this->models_with_datetime_fields); |
|
255 | + return $this->models_with_datetime_fields; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * This simply records the models that have been processed with our tracking option. |
|
261 | + * @param array $models_to_set array of model class names. |
|
262 | + */ |
|
263 | + private function setModelsToProcess($models_to_set) |
|
264 | + { |
|
265 | + update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * Used to keep track of how many models have been processed for the batch |
|
271 | + * @param $count |
|
272 | + */ |
|
273 | + private function updateCountOfModelsProcessed($count = 1) |
|
274 | + { |
|
275 | + $count = $this->getCountOfModelsProcessed() + (int) $count; |
|
276 | + update_option(self::COUNT_OF_MODELS_PROCESSED, $count); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Retrieve the tracked number of models processed between requests. |
|
282 | + * @return int |
|
283 | + */ |
|
284 | + private function getCountOfModelsProcessed() |
|
285 | + { |
|
286 | + return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Returns the models that are left to process. |
|
292 | + * @return array an array of model class names. |
|
293 | + */ |
|
294 | + private function getModelsToProcess() |
|
295 | + { |
|
296 | + if (empty($this->models_with_datetime_fields)) { |
|
297 | + $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array()); |
|
298 | + } |
|
299 | + return $this->models_with_datetime_fields; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
305 | + * @param float $offset |
|
306 | + */ |
|
307 | + public static function updateOffset($offset) |
|
308 | + { |
|
309 | + update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
315 | + * |
|
316 | + * @return float |
|
317 | + */ |
|
318 | + public static function getOffset() |
|
319 | + { |
|
320 | + return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0); |
|
321 | + } |
|
322 | 322 | } |
@@ -135,23 +135,23 @@ discard block |
||
135 | 135 | $offset = abs($original_offset) * 60; |
136 | 136 | //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
137 | 137 | foreach ($model->get_tables() as $table) { |
138 | - $query = 'UPDATE ' . $table->get_table_name(); |
|
138 | + $query = 'UPDATE '.$table->get_table_name(); |
|
139 | 139 | $fields_affected = array(); |
140 | 140 | $inner_query = array(); |
141 | 141 | foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
142 | 142 | if ($model_field instanceof EE_Datetime_Field) { |
143 | - $inner_query[] = $model_field->get_table_column() . ' = ' |
|
144 | - . $sql_date_function . '(' |
|
143 | + $inner_query[] = $model_field->get_table_column().' = ' |
|
144 | + . $sql_date_function.'(' |
|
145 | 145 | . $model_field->get_table_column() |
146 | 146 | . ", INTERVAL $offset MINUTE)"; |
147 | 147 | $fields_affected[] = $model_field; |
148 | 148 | } |
149 | 149 | } |
150 | - if (! $fields_affected) { |
|
150 | + if ( ! $fields_affected) { |
|
151 | 151 | continue; |
152 | 152 | } |
153 | 153 | //k convert innerquery to string |
154 | - $query .= ' SET ' . implode(',', $inner_query); |
|
154 | + $query .= ' SET '.implode(',', $inner_query); |
|
155 | 155 | //execute query |
156 | 156 | $result = $wpdb->query($query); |
157 | 157 | //record log |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | //record error. |
162 | 162 | $error_message = $wpdb->last_error; |
163 | 163 | //handle the edgecases where last_error might be empty. |
164 | - if (! $error_message) { |
|
164 | + if ( ! $error_message) { |
|
165 | 165 | $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
166 | 166 | } |
167 | 167 | $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $fields = array(); |
192 | 192 | /** @var EE_Datetime_Field $model_field */ |
193 | 193 | foreach ($model_fields_affected as $model_field) { |
194 | - if (! $model_field instanceof EE_Datetime_Field) { |
|
194 | + if ( ! $model_field instanceof EE_Datetime_Field) { |
|
195 | 195 | continue; |
196 | 196 | } |
197 | 197 | $fields[] = $model_field->get_name(); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | private function getModelsWithDatetimeFields() |
239 | 239 | { |
240 | 240 | $this->getModelsToProcess(); |
241 | - if (! empty($this->models_with_datetime_fields)) { |
|
241 | + if ( ! empty($this->models_with_datetime_fields)) { |
|
242 | 242 | return $this->models_with_datetime_fields; |
243 | 243 | } |
244 | 244 |
@@ -62,7 +62,6 @@ |
||
62 | 62 | * Checking via GET because HEAD requests are blocked on some server configurations. |
63 | 63 | * |
64 | 64 | * @param string $url |
65 | - * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly |
|
66 | 65 | * @return boolean |
67 | 66 | */ |
68 | 67 | public static function remote_file_exists($url, $args = array()) |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -14,234 +14,234 @@ discard block |
||
14 | 14 | class EEH_URL |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * _add_query_arg |
|
19 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
20 | - * |
|
21 | - * @access public |
|
22 | - * @param array $args |
|
23 | - * @param string $url |
|
24 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
28 | - { |
|
29 | - if (empty($url)) { |
|
30 | - $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
31 | - 'event_espresso'); |
|
32 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
33 | - __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', |
|
34 | - 'event_espresso'), |
|
35 | - __CLASS__ |
|
36 | - ); |
|
37 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
38 | - } |
|
39 | - // check that an action exists and add nonce |
|
40 | - if (! $exclude_nonce) { |
|
41 | - if (isset($args['action']) && ! empty($args['action'])) { |
|
42 | - $args = array_merge($args, |
|
43 | - array($args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce'))); |
|
44 | - } else { |
|
45 | - $args = array_merge($args, |
|
46 | - array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce'))); |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - //finally, let's always add a return address (if present) :) |
|
51 | - $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
52 | - ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
53 | - : $args; |
|
54 | - |
|
55 | - return add_query_arg($args, $url); |
|
56 | - |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Returns whether not the remote file exists. |
|
62 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
63 | - * |
|
64 | - * @param string $url |
|
65 | - * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public static function remote_file_exists($url, $args = array()) |
|
69 | - { |
|
70 | - $results = wp_remote_request($url, array_merge(array( |
|
71 | - 'method' => 'GET', |
|
72 | - 'redirection' => 1, |
|
73 | - ), $args)); |
|
74 | - if (! $results instanceof WP_Error && |
|
75 | - isset($results['response']) && |
|
76 | - isset($results['response']['code']) && |
|
77 | - $results['response']['code'] == '200') { |
|
78 | - return true; |
|
79 | - } else { |
|
80 | - return false; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * refactor_url |
|
87 | - * primarily used for removing the query string from a URL |
|
88 | - * |
|
89 | - * @param string $url |
|
90 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
91 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
95 | - { |
|
96 | - // break apart incoming URL |
|
97 | - $url_bits = parse_url($url); |
|
98 | - // HTTP or HTTPS ? |
|
99 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
100 | - // domain |
|
101 | - $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
102 | - // if only the base URL is requested, then return that now |
|
103 | - if ($base_url_only) { |
|
104 | - return $scheme . $host; |
|
105 | - } |
|
106 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
107 | - $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
108 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
109 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
110 | - $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
111 | - // if the query string is not required, then return what we have so far |
|
112 | - if ($remove_query) { |
|
113 | - return $scheme . $user . $pass . $host . $port . $path; |
|
114 | - } |
|
115 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
116 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
117 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * get_query_string |
|
123 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
124 | - * |
|
125 | - * @param string $url |
|
126 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
127 | - * simply return the query string |
|
128 | - * @return string|array |
|
129 | - */ |
|
130 | - public static function get_query_string($url = '', $as_array = true) |
|
131 | - { |
|
132 | - // decode, then break apart incoming URL |
|
133 | - $url_bits = parse_url(html_entity_decode($url)); |
|
134 | - // grab query string from URL |
|
135 | - $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
136 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
137 | - if (! $as_array) { |
|
138 | - return $query; |
|
139 | - } |
|
140 | - // if no query string exists then just return an empty array now |
|
141 | - if (empty($query)) { |
|
142 | - return array(); |
|
143 | - } |
|
144 | - // empty array to hold results |
|
145 | - $query_params = array(); |
|
146 | - // now break apart the query string into separate params |
|
147 | - $query = explode('&', $query); |
|
148 | - // loop thru our query params |
|
149 | - foreach ($query as $query_args) { |
|
150 | - // break apart the key value pairs |
|
151 | - $query_args = explode('=', $query_args); |
|
152 | - // and add to our results array |
|
153 | - $query_params[$query_args[0]] = $query_args[1]; |
|
154 | - } |
|
155 | - return $query_params; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * prevent_prefetching |
|
161 | - * |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - public static function prevent_prefetching() |
|
165 | - { |
|
166 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
167 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * This generates a unique site-specific string. |
|
173 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
174 | - * urls. |
|
175 | - * |
|
176 | - * @param string $prefix Use this to prefix the string with something. |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public static function generate_unique_token($prefix = '') |
|
180 | - { |
|
181 | - $token = md5(uniqid() . mt_rand()); |
|
182 | - return $prefix ? $prefix . '_' . $token : $token; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * add_nocache_headers |
|
188 | - * |
|
189 | - * @return void |
|
190 | - */ |
|
191 | - public static function add_nocache_headers() |
|
192 | - { |
|
193 | - // add no cache headers |
|
17 | + /** |
|
18 | + * _add_query_arg |
|
19 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
20 | + * |
|
21 | + * @access public |
|
22 | + * @param array $args |
|
23 | + * @param string $url |
|
24 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
28 | + { |
|
29 | + if (empty($url)) { |
|
30 | + $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
31 | + 'event_espresso'); |
|
32 | + $dev_msg = $user_msg . "\n" . sprintf( |
|
33 | + __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', |
|
34 | + 'event_espresso'), |
|
35 | + __CLASS__ |
|
36 | + ); |
|
37 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
38 | + } |
|
39 | + // check that an action exists and add nonce |
|
40 | + if (! $exclude_nonce) { |
|
41 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
42 | + $args = array_merge($args, |
|
43 | + array($args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce'))); |
|
44 | + } else { |
|
45 | + $args = array_merge($args, |
|
46 | + array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce'))); |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + //finally, let's always add a return address (if present) :) |
|
51 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
52 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
53 | + : $args; |
|
54 | + |
|
55 | + return add_query_arg($args, $url); |
|
56 | + |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Returns whether not the remote file exists. |
|
62 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
63 | + * |
|
64 | + * @param string $url |
|
65 | + * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public static function remote_file_exists($url, $args = array()) |
|
69 | + { |
|
70 | + $results = wp_remote_request($url, array_merge(array( |
|
71 | + 'method' => 'GET', |
|
72 | + 'redirection' => 1, |
|
73 | + ), $args)); |
|
74 | + if (! $results instanceof WP_Error && |
|
75 | + isset($results['response']) && |
|
76 | + isset($results['response']['code']) && |
|
77 | + $results['response']['code'] == '200') { |
|
78 | + return true; |
|
79 | + } else { |
|
80 | + return false; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * refactor_url |
|
87 | + * primarily used for removing the query string from a URL |
|
88 | + * |
|
89 | + * @param string $url |
|
90 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
91 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
95 | + { |
|
96 | + // break apart incoming URL |
|
97 | + $url_bits = parse_url($url); |
|
98 | + // HTTP or HTTPS ? |
|
99 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
100 | + // domain |
|
101 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
102 | + // if only the base URL is requested, then return that now |
|
103 | + if ($base_url_only) { |
|
104 | + return $scheme . $host; |
|
105 | + } |
|
106 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
107 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
108 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
109 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
110 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
111 | + // if the query string is not required, then return what we have so far |
|
112 | + if ($remove_query) { |
|
113 | + return $scheme . $user . $pass . $host . $port . $path; |
|
114 | + } |
|
115 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
116 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
117 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * get_query_string |
|
123 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
124 | + * |
|
125 | + * @param string $url |
|
126 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
127 | + * simply return the query string |
|
128 | + * @return string|array |
|
129 | + */ |
|
130 | + public static function get_query_string($url = '', $as_array = true) |
|
131 | + { |
|
132 | + // decode, then break apart incoming URL |
|
133 | + $url_bits = parse_url(html_entity_decode($url)); |
|
134 | + // grab query string from URL |
|
135 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
136 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
137 | + if (! $as_array) { |
|
138 | + return $query; |
|
139 | + } |
|
140 | + // if no query string exists then just return an empty array now |
|
141 | + if (empty($query)) { |
|
142 | + return array(); |
|
143 | + } |
|
144 | + // empty array to hold results |
|
145 | + $query_params = array(); |
|
146 | + // now break apart the query string into separate params |
|
147 | + $query = explode('&', $query); |
|
148 | + // loop thru our query params |
|
149 | + foreach ($query as $query_args) { |
|
150 | + // break apart the key value pairs |
|
151 | + $query_args = explode('=', $query_args); |
|
152 | + // and add to our results array |
|
153 | + $query_params[$query_args[0]] = $query_args[1]; |
|
154 | + } |
|
155 | + return $query_params; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * prevent_prefetching |
|
161 | + * |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + public static function prevent_prefetching() |
|
165 | + { |
|
166 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
167 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * This generates a unique site-specific string. |
|
173 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
174 | + * urls. |
|
175 | + * |
|
176 | + * @param string $prefix Use this to prefix the string with something. |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public static function generate_unique_token($prefix = '') |
|
180 | + { |
|
181 | + $token = md5(uniqid() . mt_rand()); |
|
182 | + return $prefix ? $prefix . '_' . $token : $token; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * add_nocache_headers |
|
188 | + * |
|
189 | + * @return void |
|
190 | + */ |
|
191 | + public static function add_nocache_headers() |
|
192 | + { |
|
193 | + // add no cache headers |
|
194 | 194 | // add_action( 'wp_head' , array( 'EED_Single_Page_Checkout', 'nocache_headers' ), 10 ); |
195 | - // plus a little extra for nginx |
|
195 | + // plus a little extra for nginx |
|
196 | 196 | // add_filter( 'nocache_headers' , array( 'EED_Single_Page_Checkout', 'nocache_headers_nginx' ), 10, 1 ); |
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * filter_input_server_url |
|
202 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
203 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
204 | - * |
|
205 | - * @param string $server_variable |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
209 | - { |
|
210 | - $URL = ''; |
|
211 | - $server_variables = array( |
|
212 | - 'REQUEST_URI' => 1, |
|
213 | - 'HTTP_HOST' => 1, |
|
214 | - 'PHP_SELF' => 1, |
|
215 | - ); |
|
216 | - $server_variable = strtoupper($server_variable); |
|
217 | - // whitelist INPUT_SERVER var |
|
218 | - if (isset($server_variables[$server_variable])) { |
|
219 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
220 | - if (empty($URL)) { |
|
221 | - // fallback sanitization if the above fails |
|
222 | - $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
223 | - } |
|
224 | - } |
|
225 | - return $URL; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Gets the current page's full URL |
|
231 | - * |
|
232 | - * @return string |
|
233 | - */ |
|
234 | - public static function current_url() |
|
235 | - { |
|
236 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
237 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
238 | - $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
239 | - $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
240 | - } else { |
|
241 | - $url = 'unknown'; |
|
242 | - } |
|
243 | - return $url; |
|
244 | - } |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * filter_input_server_url |
|
202 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
203 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
204 | + * |
|
205 | + * @param string $server_variable |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
209 | + { |
|
210 | + $URL = ''; |
|
211 | + $server_variables = array( |
|
212 | + 'REQUEST_URI' => 1, |
|
213 | + 'HTTP_HOST' => 1, |
|
214 | + 'PHP_SELF' => 1, |
|
215 | + ); |
|
216 | + $server_variable = strtoupper($server_variable); |
|
217 | + // whitelist INPUT_SERVER var |
|
218 | + if (isset($server_variables[$server_variable])) { |
|
219 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
220 | + if (empty($URL)) { |
|
221 | + // fallback sanitization if the above fails |
|
222 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
223 | + } |
|
224 | + } |
|
225 | + return $URL; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Gets the current page's full URL |
|
231 | + * |
|
232 | + * @return string |
|
233 | + */ |
|
234 | + public static function current_url() |
|
235 | + { |
|
236 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
237 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
238 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
239 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
240 | + } else { |
|
241 | + $url = 'unknown'; |
|
242 | + } |
|
243 | + return $url; |
|
244 | + } |
|
245 | 245 | |
246 | 246 | |
247 | 247 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -29,18 +29,18 @@ discard block |
||
29 | 29 | if (empty($url)) { |
30 | 30 | $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
31 | 31 | 'event_espresso'); |
32 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
32 | + $dev_msg = $user_msg."\n".sprintf( |
|
33 | 33 | __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', |
34 | 34 | 'event_espresso'), |
35 | 35 | __CLASS__ |
36 | 36 | ); |
37 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
37 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
38 | 38 | } |
39 | 39 | // check that an action exists and add nonce |
40 | - if (! $exclude_nonce) { |
|
40 | + if ( ! $exclude_nonce) { |
|
41 | 41 | if (isset($args['action']) && ! empty($args['action'])) { |
42 | 42 | $args = array_merge($args, |
43 | - array($args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce'))); |
|
43 | + array($args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce'))); |
|
44 | 44 | } else { |
45 | 45 | $args = array_merge($args, |
46 | 46 | array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce'))); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | 'method' => 'GET', |
72 | 72 | 'redirection' => 1, |
73 | 73 | ), $args)); |
74 | - if (! $results instanceof WP_Error && |
|
74 | + if ( ! $results instanceof WP_Error && |
|
75 | 75 | isset($results['response']) && |
76 | 76 | isset($results['response']['code']) && |
77 | 77 | $results['response']['code'] == '200') { |
@@ -96,25 +96,25 @@ discard block |
||
96 | 96 | // break apart incoming URL |
97 | 97 | $url_bits = parse_url($url); |
98 | 98 | // HTTP or HTTPS ? |
99 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
99 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
100 | 100 | // domain |
101 | 101 | $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
102 | 102 | // if only the base URL is requested, then return that now |
103 | 103 | if ($base_url_only) { |
104 | - return $scheme . $host; |
|
104 | + return $scheme.$host; |
|
105 | 105 | } |
106 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
106 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
107 | 107 | $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
108 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
109 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
108 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
109 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
110 | 110 | $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
111 | 111 | // if the query string is not required, then return what we have so far |
112 | 112 | if ($remove_query) { |
113 | - return $scheme . $user . $pass . $host . $port . $path; |
|
113 | + return $scheme.$user.$pass.$host.$port.$path; |
|
114 | 114 | } |
115 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
116 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
117 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
115 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
116 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
117 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | // grab query string from URL |
135 | 135 | $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
136 | 136 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
137 | - if (! $as_array) { |
|
137 | + if ( ! $as_array) { |
|
138 | 138 | return $query; |
139 | 139 | } |
140 | 140 | // if no query string exists then just return an empty array now |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public static function generate_unique_token($prefix = '') |
180 | 180 | { |
181 | - $token = md5(uniqid() . mt_rand()); |
|
182 | - return $prefix ? $prefix . '_' . $token : $token; |
|
181 | + $token = md5(uniqid().mt_rand()); |
|
182 | + return $prefix ? $prefix.'_'.$token : $token; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | 'HTTP_HOST' => 1, |
214 | 214 | 'PHP_SELF' => 1, |
215 | 215 | ); |
216 | - $server_variable = strtoupper($server_variable); |
|
216 | + $server_variable = strtoupper($server_variable); |
|
217 | 217 | // whitelist INPUT_SERVER var |
218 | 218 | if (isset($server_variables[$server_variable])) { |
219 | 219 | $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.030'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.030'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; |
6 | 6 | |
7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -22,772 +22,772 @@ discard block |
||
22 | 22 | class EE_Dependency_Map |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - /** |
|
31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | - */ |
|
33 | - const load_new_object = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | - */ |
|
39 | - const load_from_cache = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * When registering a dependency, |
|
43 | - * this indicates to keep any existing dependencies that already exist, |
|
44 | - * and simply discard any new dependencies declared in the incoming data |
|
45 | - */ |
|
46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * When registering a dependency, |
|
50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | - */ |
|
52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @type EE_Dependency_Map $_instance |
|
58 | - */ |
|
59 | - protected static $_instance; |
|
60 | - |
|
61 | - /** |
|
62 | - * @type EE_Request $request |
|
63 | - */ |
|
64 | - protected $_request; |
|
65 | - |
|
66 | - /** |
|
67 | - * @type EE_Response $response |
|
68 | - */ |
|
69 | - protected $_response; |
|
70 | - |
|
71 | - /** |
|
72 | - * @type LoaderInterface $loader |
|
73 | - */ |
|
74 | - protected $loader; |
|
75 | - |
|
76 | - /** |
|
77 | - * @type array $_dependency_map |
|
78 | - */ |
|
79 | - protected $_dependency_map = array(); |
|
80 | - |
|
81 | - /** |
|
82 | - * @type array $_class_loaders |
|
83 | - */ |
|
84 | - protected $_class_loaders = array(); |
|
85 | - |
|
86 | - /** |
|
87 | - * @type array $_aliases |
|
88 | - */ |
|
89 | - protected $_aliases = array(); |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * EE_Dependency_Map constructor. |
|
95 | - * |
|
96 | - * @param EE_Request $request |
|
97 | - * @param EE_Response $response |
|
98 | - */ |
|
99 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
100 | - { |
|
101 | - $this->_request = $request; |
|
102 | - $this->_response = $response; |
|
103 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
104 | - do_action('EE_Dependency_Map____construct'); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - * @throws InvalidInterfaceException |
|
112 | - * @throws InvalidArgumentException |
|
113 | - */ |
|
114 | - public function initialize() |
|
115 | - { |
|
116 | - $this->_register_core_dependencies(); |
|
117 | - $this->_register_core_class_loaders(); |
|
118 | - $this->_register_core_aliases(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @singleton method used to instantiate class object |
|
125 | - * @access public |
|
126 | - * @param EE_Request $request |
|
127 | - * @param EE_Response $response |
|
128 | - * @return EE_Dependency_Map |
|
129 | - */ |
|
130 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
131 | - { |
|
132 | - // check if class object is instantiated, and instantiated properly |
|
133 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
135 | - } |
|
136 | - return self::$_instance; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param LoaderInterface $loader |
|
143 | - */ |
|
144 | - public function setLoader(LoaderInterface $loader) |
|
145 | - { |
|
146 | - $this->loader = $loader; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $class |
|
153 | - * @param array $dependencies |
|
154 | - * @param int $overwrite |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public static function register_dependencies( |
|
158 | - $class, |
|
159 | - array $dependencies, |
|
160 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
161 | - ) { |
|
162 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
169 | - * to the class specified by the first parameter. |
|
170 | - * IMPORTANT !!! |
|
171 | - * The order of elements in the incoming $dependencies array MUST match |
|
172 | - * the order of the constructor parameters for the class in question. |
|
173 | - * This is especially important when overriding any existing dependencies that are registered. |
|
174 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
175 | - * |
|
176 | - * @param string $class |
|
177 | - * @param array $dependencies |
|
178 | - * @param int $overwrite |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function registerDependencies( |
|
182 | - $class, |
|
183 | - array $dependencies, |
|
184 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
185 | - ) { |
|
186 | - $class = trim($class, '\\'); |
|
187 | - $registered = false; |
|
188 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
190 | - } |
|
191 | - // we need to make sure that any aliases used when registering a dependency |
|
192 | - // get resolved to the correct class name |
|
193 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
194 | - $alias = self::$_instance->get_alias($dependency); |
|
195 | - if ( |
|
196 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
198 | - ) { |
|
199 | - unset($dependencies[$dependency]); |
|
200 | - $dependencies[$alias] = $load_source; |
|
201 | - $registered = true; |
|
202 | - } |
|
203 | - } |
|
204 | - // now add our two lists of dependencies together. |
|
205 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
206 | - // so $dependencies is NOT overwritten because it is listed first |
|
207 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
208 | - // Union is way faster than array_merge() but should be used with caution... |
|
209 | - // especially with numerically indexed arrays |
|
210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
211 | - // now we need to ensure that the resulting dependencies |
|
212 | - // array only has the entries that are required for the class |
|
213 | - // so first count how many dependencies were originally registered for the class |
|
214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
215 | - // if that count is non-zero (meaning dependencies were already registered) |
|
216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
217 | - // then truncate the final array to match that count |
|
218 | - ? array_slice($dependencies, 0, $dependency_count) |
|
219 | - // otherwise just take the incoming array because nothing previously existed |
|
220 | - : $dependencies; |
|
221 | - return $registered; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * @param string $class_name |
|
228 | - * @param string $loader |
|
229 | - * @return bool |
|
230 | - * @throws DomainException |
|
231 | - */ |
|
232 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
233 | - { |
|
234 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | - throw new DomainException( |
|
236 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
237 | - ); |
|
238 | - } |
|
239 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
240 | - if ( |
|
241 | - ! is_callable($loader) |
|
242 | - && ( |
|
243 | - strpos($loader, 'load_') !== 0 |
|
244 | - || ! method_exists('EE_Registry', $loader) |
|
245 | - ) |
|
246 | - ) { |
|
247 | - throw new DomainException( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $loader |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - $class_name = self::$_instance->get_alias($class_name); |
|
258 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
260 | - return true; |
|
261 | - } |
|
262 | - return false; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @return array |
|
269 | - */ |
|
270 | - public function dependency_map() |
|
271 | - { |
|
272 | - return $this->_dependency_map; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
279 | - * |
|
280 | - * @param string $class_name |
|
281 | - * @return boolean |
|
282 | - */ |
|
283 | - public function has($class_name = '') |
|
284 | - { |
|
285 | - // all legacy models have the same dependencies |
|
286 | - if (strpos($class_name, 'EEM_') === 0) { |
|
287 | - $class_name = 'LEGACY_MODELS'; |
|
288 | - } |
|
289 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
296 | - * |
|
297 | - * @param string $class_name |
|
298 | - * @param string $dependency |
|
299 | - * @return bool |
|
300 | - */ |
|
301 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
302 | - { |
|
303 | - // all legacy models have the same dependencies |
|
304 | - if (strpos($class_name, 'EEM_') === 0) { |
|
305 | - $class_name = 'LEGACY_MODELS'; |
|
306 | - } |
|
307 | - $dependency = $this->get_alias($dependency); |
|
308 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
309 | - ? true |
|
310 | - : false; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
317 | - * |
|
318 | - * @param string $class_name |
|
319 | - * @param string $dependency |
|
320 | - * @return int |
|
321 | - */ |
|
322 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
323 | - { |
|
324 | - // all legacy models have the same dependencies |
|
325 | - if (strpos($class_name, 'EEM_') === 0) { |
|
326 | - $class_name = 'LEGACY_MODELS'; |
|
327 | - } |
|
328 | - $dependency = $this->get_alias($dependency); |
|
329 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
330 | - ? $this->_dependency_map[$class_name][$dependency] |
|
331 | - : EE_Dependency_Map::not_registered; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param string $class_name |
|
338 | - * @return string | Closure |
|
339 | - */ |
|
340 | - public function class_loader($class_name) |
|
341 | - { |
|
342 | - // all legacy models use load_model() |
|
343 | - if(strpos($class_name, 'EEM_') === 0){ |
|
344 | - return 'load_model'; |
|
345 | - } |
|
346 | - $class_name = $this->get_alias($class_name); |
|
347 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * @return array |
|
354 | - */ |
|
355 | - public function class_loaders() |
|
356 | - { |
|
357 | - return $this->_class_loaders; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * adds an alias for a classname |
|
364 | - * |
|
365 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
366 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
367 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
368 | - */ |
|
369 | - public function add_alias($class_name, $alias, $for_class = '') |
|
370 | - { |
|
371 | - if ($for_class !== '') { |
|
372 | - if (! isset($this->_aliases[$for_class])) { |
|
373 | - $this->_aliases[$for_class] = array(); |
|
374 | - } |
|
375 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
376 | - } |
|
377 | - $this->_aliases[$class_name] = $alias; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * returns TRUE if the provided class name has an alias |
|
384 | - * |
|
385 | - * @param string $class_name |
|
386 | - * @param string $for_class |
|
387 | - * @return bool |
|
388 | - */ |
|
389 | - public function has_alias($class_name = '', $for_class = '') |
|
390 | - { |
|
391 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
392 | - || ( |
|
393 | - isset($this->_aliases[$class_name]) |
|
394 | - && ! is_array($this->_aliases[$class_name]) |
|
395 | - ); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
402 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
403 | - * for example: |
|
404 | - * if the following two entries were added to the _aliases array: |
|
405 | - * array( |
|
406 | - * 'interface_alias' => 'some\namespace\interface' |
|
407 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
408 | - * ) |
|
409 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
410 | - * to load an instance of 'some\namespace\classname' |
|
411 | - * |
|
412 | - * @param string $class_name |
|
413 | - * @param string $for_class |
|
414 | - * @return string |
|
415 | - */ |
|
416 | - public function get_alias($class_name = '', $for_class = '') |
|
417 | - { |
|
418 | - if (! $this->has_alias($class_name, $for_class)) { |
|
419 | - return $class_name; |
|
420 | - } |
|
421 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
422 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
423 | - } |
|
424 | - return $this->get_alias($this->_aliases[$class_name]); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | - * This is done by using the following class constants: |
|
433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | - */ |
|
436 | - protected function _register_core_dependencies() |
|
437 | - { |
|
438 | - $this->_dependency_map = array( |
|
439 | - 'EE_Request_Handler' => array( |
|
440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | - ), |
|
442 | - 'EE_System' => array( |
|
443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | - ), |
|
445 | - 'EE_Session' => array( |
|
446 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
447 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_Cart' => array( |
|
450 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
451 | - ), |
|
452 | - 'EE_Front_Controller' => array( |
|
453 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
454 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
455 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
456 | - ), |
|
457 | - 'EE_Messenger_Collection_Loader' => array( |
|
458 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
459 | - ), |
|
460 | - 'EE_Message_Type_Collection_Loader' => array( |
|
461 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
462 | - ), |
|
463 | - 'EE_Message_Resource_Manager' => array( |
|
464 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
465 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
466 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
467 | - ), |
|
468 | - 'EE_Message_Factory' => array( |
|
469 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
470 | - ), |
|
471 | - 'EE_messages' => array( |
|
472 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
473 | - ), |
|
474 | - 'EE_Messages_Generator' => array( |
|
475 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
476 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
477 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
478 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EE_Messages_Processor' => array( |
|
481 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
482 | - ), |
|
483 | - 'EE_Messages_Queue' => array( |
|
484 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
485 | - ), |
|
486 | - 'EE_Messages_Template_Defaults' => array( |
|
487 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
488 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
489 | - ), |
|
490 | - 'EE_Message_To_Generate_From_Request' => array( |
|
491 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
492 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
493 | - ), |
|
494 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
495 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
496 | - ), |
|
497 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
498 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
499 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
502 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
503 | - ), |
|
504 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
505 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
506 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
509 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
510 | - ), |
|
511 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
512 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
515 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
518 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
519 | - ), |
|
520 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
521 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
522 | - ), |
|
523 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
524 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
525 | - ), |
|
526 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
527 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
528 | - ), |
|
529 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
530 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
531 | - ), |
|
532 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
533 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
534 | - ), |
|
535 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
536 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
537 | - ), |
|
538 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
539 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
540 | - ), |
|
541 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
542 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
543 | - ), |
|
544 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
545 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
546 | - ), |
|
547 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
548 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
549 | - ), |
|
550 | - 'EE_Data_Migration_Class_Base' => array( |
|
551 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
552 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EE_DMS_Core_4_1_0' => array( |
|
555 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
556 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
557 | - ), |
|
558 | - 'EE_DMS_Core_4_2_0' => array( |
|
559 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
560 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
561 | - ), |
|
562 | - 'EE_DMS_Core_4_3_0' => array( |
|
563 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
564 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
565 | - ), |
|
566 | - 'EE_DMS_Core_4_4_0' => array( |
|
567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | - ), |
|
570 | - 'EE_DMS_Core_4_5_0' => array( |
|
571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | - ), |
|
574 | - 'EE_DMS_Core_4_6_0' => array( |
|
575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | - ), |
|
578 | - 'EE_DMS_Core_4_7_0' => array( |
|
579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | - ), |
|
582 | - 'EE_DMS_Core_4_8_0' => array( |
|
583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | - ), |
|
586 | - 'EE_DMS_Core_4_9_0' => array( |
|
587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
591 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
592 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
593 | - ), |
|
594 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
595 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
596 | - ), |
|
597 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
598 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
599 | - ), |
|
600 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
601 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
602 | - ), |
|
603 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
604 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
605 | - ), |
|
606 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
607 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
608 | - ), |
|
609 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
610 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
611 | - ), |
|
612 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
613 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
614 | - ), |
|
615 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
616 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
617 | - ), |
|
618 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
619 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
620 | - ), |
|
621 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
622 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
623 | - ), |
|
624 | - 'LEGACY_MODELS' => array( |
|
625 | - null, |
|
626 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
627 | - ), |
|
628 | - 'EE_Module_Request_Router' => array( |
|
629 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - ); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * Registers how core classes are loaded. |
|
638 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
639 | - * 'EE_Request_Handler' => 'load_core' |
|
640 | - * 'EE_Messages_Queue' => 'load_lib' |
|
641 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
642 | - * or, if greater control is required, by providing a custom closure. For example: |
|
643 | - * 'Some_Class' => function () { |
|
644 | - * return new Some_Class(); |
|
645 | - * }, |
|
646 | - * This is required for instantiating dependencies |
|
647 | - * where an interface has been type hinted in a class constructor. For example: |
|
648 | - * 'Required_Interface' => function () { |
|
649 | - * return new A_Class_That_Implements_Required_Interface(); |
|
650 | - * }, |
|
651 | - * |
|
652 | - * @throws InvalidInterfaceException |
|
653 | - * @throws InvalidDataTypeException |
|
654 | - * @throws InvalidArgumentException |
|
655 | - */ |
|
656 | - protected function _register_core_class_loaders() |
|
657 | - { |
|
658 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
659 | - //be used in a closure. |
|
660 | - $request = &$this->_request; |
|
661 | - $response = &$this->_response; |
|
662 | - $loader = &$this->loader; |
|
663 | - $this->_class_loaders = array( |
|
664 | - //load_core |
|
665 | - 'EE_Capabilities' => 'load_core', |
|
666 | - 'EE_Encryption' => 'load_core', |
|
667 | - 'EE_Front_Controller' => 'load_core', |
|
668 | - 'EE_Module_Request_Router' => 'load_core', |
|
669 | - 'EE_Registry' => 'load_core', |
|
670 | - 'EE_Request' => function () use (&$request) { |
|
671 | - return $request; |
|
672 | - }, |
|
673 | - 'EE_Response' => function () use (&$response) { |
|
674 | - return $response; |
|
675 | - }, |
|
676 | - 'EE_Request_Handler' => 'load_core', |
|
677 | - 'EE_Session' => 'load_core', |
|
678 | - 'EE_Cron_Tasks' => 'load_core', |
|
679 | - //load_lib |
|
680 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
681 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
682 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
683 | - 'EE_Messenger_Collection' => 'load_lib', |
|
684 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
685 | - 'EE_Messages_Processor' => 'load_lib', |
|
686 | - 'EE_Message_Repository' => 'load_lib', |
|
687 | - 'EE_Messages_Queue' => 'load_lib', |
|
688 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
689 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
690 | - 'EE_Messages_Generator' => function () { |
|
691 | - return EE_Registry::instance()->load_lib( |
|
692 | - 'Messages_Generator', |
|
693 | - array(), |
|
694 | - false, |
|
695 | - false |
|
696 | - ); |
|
697 | - }, |
|
698 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
699 | - return EE_Registry::instance()->load_lib( |
|
700 | - 'Messages_Template_Defaults', |
|
701 | - $arguments, |
|
702 | - false, |
|
703 | - false |
|
704 | - ); |
|
705 | - }, |
|
706 | - //load_model |
|
707 | - // 'EEM_Attendee' => 'load_model', |
|
708 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
709 | - // 'EEM_Message_Template' => 'load_model', |
|
710 | - //load_helper |
|
711 | - 'EEH_Parse_Shortcodes' => function () { |
|
712 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
713 | - return new EEH_Parse_Shortcodes(); |
|
714 | - } |
|
715 | - return null; |
|
716 | - }, |
|
717 | - 'EE_Template_Config' => function () { |
|
718 | - return EE_Config::instance()->template_settings; |
|
719 | - }, |
|
720 | - 'EE_Currency_Config' => function () { |
|
721 | - return EE_Config::instance()->currency; |
|
722 | - }, |
|
723 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
724 | - return $loader; |
|
725 | - }, |
|
726 | - ); |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * can be used for supplying alternate names for classes, |
|
733 | - * or for connecting interface names to instantiable classes |
|
734 | - */ |
|
735 | - protected function _register_core_aliases() |
|
736 | - { |
|
737 | - $this->_aliases = array( |
|
738 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
739 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
740 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
741 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
742 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
743 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
744 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
745 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
746 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
747 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
748 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
749 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
750 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
751 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
752 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
753 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
754 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
755 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
756 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
757 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
758 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
759 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
760 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
761 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
762 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
763 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
764 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
765 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
766 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
767 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
768 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
769 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
770 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
771 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
772 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
773 | - ); |
|
774 | - } |
|
775 | - |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
780 | - * request Primarily used by unit tests. |
|
781 | - * |
|
782 | - * @throws InvalidDataTypeException |
|
783 | - * @throws InvalidInterfaceException |
|
784 | - * @throws InvalidArgumentException |
|
785 | - */ |
|
786 | - public function reset() |
|
787 | - { |
|
788 | - $this->_register_core_class_loaders(); |
|
789 | - $this->_register_core_dependencies(); |
|
790 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + /** |
|
31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | + */ |
|
33 | + const load_new_object = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | + */ |
|
39 | + const load_from_cache = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * When registering a dependency, |
|
43 | + * this indicates to keep any existing dependencies that already exist, |
|
44 | + * and simply discard any new dependencies declared in the incoming data |
|
45 | + */ |
|
46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * When registering a dependency, |
|
50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | + */ |
|
52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @type EE_Dependency_Map $_instance |
|
58 | + */ |
|
59 | + protected static $_instance; |
|
60 | + |
|
61 | + /** |
|
62 | + * @type EE_Request $request |
|
63 | + */ |
|
64 | + protected $_request; |
|
65 | + |
|
66 | + /** |
|
67 | + * @type EE_Response $response |
|
68 | + */ |
|
69 | + protected $_response; |
|
70 | + |
|
71 | + /** |
|
72 | + * @type LoaderInterface $loader |
|
73 | + */ |
|
74 | + protected $loader; |
|
75 | + |
|
76 | + /** |
|
77 | + * @type array $_dependency_map |
|
78 | + */ |
|
79 | + protected $_dependency_map = array(); |
|
80 | + |
|
81 | + /** |
|
82 | + * @type array $_class_loaders |
|
83 | + */ |
|
84 | + protected $_class_loaders = array(); |
|
85 | + |
|
86 | + /** |
|
87 | + * @type array $_aliases |
|
88 | + */ |
|
89 | + protected $_aliases = array(); |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * EE_Dependency_Map constructor. |
|
95 | + * |
|
96 | + * @param EE_Request $request |
|
97 | + * @param EE_Response $response |
|
98 | + */ |
|
99 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
100 | + { |
|
101 | + $this->_request = $request; |
|
102 | + $this->_response = $response; |
|
103 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
104 | + do_action('EE_Dependency_Map____construct'); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + * @throws InvalidInterfaceException |
|
112 | + * @throws InvalidArgumentException |
|
113 | + */ |
|
114 | + public function initialize() |
|
115 | + { |
|
116 | + $this->_register_core_dependencies(); |
|
117 | + $this->_register_core_class_loaders(); |
|
118 | + $this->_register_core_aliases(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @singleton method used to instantiate class object |
|
125 | + * @access public |
|
126 | + * @param EE_Request $request |
|
127 | + * @param EE_Response $response |
|
128 | + * @return EE_Dependency_Map |
|
129 | + */ |
|
130 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
131 | + { |
|
132 | + // check if class object is instantiated, and instantiated properly |
|
133 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
135 | + } |
|
136 | + return self::$_instance; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param LoaderInterface $loader |
|
143 | + */ |
|
144 | + public function setLoader(LoaderInterface $loader) |
|
145 | + { |
|
146 | + $this->loader = $loader; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $class |
|
153 | + * @param array $dependencies |
|
154 | + * @param int $overwrite |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public static function register_dependencies( |
|
158 | + $class, |
|
159 | + array $dependencies, |
|
160 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
161 | + ) { |
|
162 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
169 | + * to the class specified by the first parameter. |
|
170 | + * IMPORTANT !!! |
|
171 | + * The order of elements in the incoming $dependencies array MUST match |
|
172 | + * the order of the constructor parameters for the class in question. |
|
173 | + * This is especially important when overriding any existing dependencies that are registered. |
|
174 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
175 | + * |
|
176 | + * @param string $class |
|
177 | + * @param array $dependencies |
|
178 | + * @param int $overwrite |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function registerDependencies( |
|
182 | + $class, |
|
183 | + array $dependencies, |
|
184 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
185 | + ) { |
|
186 | + $class = trim($class, '\\'); |
|
187 | + $registered = false; |
|
188 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
190 | + } |
|
191 | + // we need to make sure that any aliases used when registering a dependency |
|
192 | + // get resolved to the correct class name |
|
193 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
194 | + $alias = self::$_instance->get_alias($dependency); |
|
195 | + if ( |
|
196 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
197 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
198 | + ) { |
|
199 | + unset($dependencies[$dependency]); |
|
200 | + $dependencies[$alias] = $load_source; |
|
201 | + $registered = true; |
|
202 | + } |
|
203 | + } |
|
204 | + // now add our two lists of dependencies together. |
|
205 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
206 | + // so $dependencies is NOT overwritten because it is listed first |
|
207 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
208 | + // Union is way faster than array_merge() but should be used with caution... |
|
209 | + // especially with numerically indexed arrays |
|
210 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
211 | + // now we need to ensure that the resulting dependencies |
|
212 | + // array only has the entries that are required for the class |
|
213 | + // so first count how many dependencies were originally registered for the class |
|
214 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
215 | + // if that count is non-zero (meaning dependencies were already registered) |
|
216 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
217 | + // then truncate the final array to match that count |
|
218 | + ? array_slice($dependencies, 0, $dependency_count) |
|
219 | + // otherwise just take the incoming array because nothing previously existed |
|
220 | + : $dependencies; |
|
221 | + return $registered; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * @param string $class_name |
|
228 | + * @param string $loader |
|
229 | + * @return bool |
|
230 | + * @throws DomainException |
|
231 | + */ |
|
232 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
233 | + { |
|
234 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | + throw new DomainException( |
|
236 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
237 | + ); |
|
238 | + } |
|
239 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
240 | + if ( |
|
241 | + ! is_callable($loader) |
|
242 | + && ( |
|
243 | + strpos($loader, 'load_') !== 0 |
|
244 | + || ! method_exists('EE_Registry', $loader) |
|
245 | + ) |
|
246 | + ) { |
|
247 | + throw new DomainException( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $loader |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + $class_name = self::$_instance->get_alias($class_name); |
|
258 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
260 | + return true; |
|
261 | + } |
|
262 | + return false; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @return array |
|
269 | + */ |
|
270 | + public function dependency_map() |
|
271 | + { |
|
272 | + return $this->_dependency_map; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
279 | + * |
|
280 | + * @param string $class_name |
|
281 | + * @return boolean |
|
282 | + */ |
|
283 | + public function has($class_name = '') |
|
284 | + { |
|
285 | + // all legacy models have the same dependencies |
|
286 | + if (strpos($class_name, 'EEM_') === 0) { |
|
287 | + $class_name = 'LEGACY_MODELS'; |
|
288 | + } |
|
289 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
296 | + * |
|
297 | + * @param string $class_name |
|
298 | + * @param string $dependency |
|
299 | + * @return bool |
|
300 | + */ |
|
301 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
302 | + { |
|
303 | + // all legacy models have the same dependencies |
|
304 | + if (strpos($class_name, 'EEM_') === 0) { |
|
305 | + $class_name = 'LEGACY_MODELS'; |
|
306 | + } |
|
307 | + $dependency = $this->get_alias($dependency); |
|
308 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
309 | + ? true |
|
310 | + : false; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
317 | + * |
|
318 | + * @param string $class_name |
|
319 | + * @param string $dependency |
|
320 | + * @return int |
|
321 | + */ |
|
322 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
323 | + { |
|
324 | + // all legacy models have the same dependencies |
|
325 | + if (strpos($class_name, 'EEM_') === 0) { |
|
326 | + $class_name = 'LEGACY_MODELS'; |
|
327 | + } |
|
328 | + $dependency = $this->get_alias($dependency); |
|
329 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
330 | + ? $this->_dependency_map[$class_name][$dependency] |
|
331 | + : EE_Dependency_Map::not_registered; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param string $class_name |
|
338 | + * @return string | Closure |
|
339 | + */ |
|
340 | + public function class_loader($class_name) |
|
341 | + { |
|
342 | + // all legacy models use load_model() |
|
343 | + if(strpos($class_name, 'EEM_') === 0){ |
|
344 | + return 'load_model'; |
|
345 | + } |
|
346 | + $class_name = $this->get_alias($class_name); |
|
347 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * @return array |
|
354 | + */ |
|
355 | + public function class_loaders() |
|
356 | + { |
|
357 | + return $this->_class_loaders; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * adds an alias for a classname |
|
364 | + * |
|
365 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
366 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
367 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
368 | + */ |
|
369 | + public function add_alias($class_name, $alias, $for_class = '') |
|
370 | + { |
|
371 | + if ($for_class !== '') { |
|
372 | + if (! isset($this->_aliases[$for_class])) { |
|
373 | + $this->_aliases[$for_class] = array(); |
|
374 | + } |
|
375 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
376 | + } |
|
377 | + $this->_aliases[$class_name] = $alias; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * returns TRUE if the provided class name has an alias |
|
384 | + * |
|
385 | + * @param string $class_name |
|
386 | + * @param string $for_class |
|
387 | + * @return bool |
|
388 | + */ |
|
389 | + public function has_alias($class_name = '', $for_class = '') |
|
390 | + { |
|
391 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
392 | + || ( |
|
393 | + isset($this->_aliases[$class_name]) |
|
394 | + && ! is_array($this->_aliases[$class_name]) |
|
395 | + ); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
402 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
403 | + * for example: |
|
404 | + * if the following two entries were added to the _aliases array: |
|
405 | + * array( |
|
406 | + * 'interface_alias' => 'some\namespace\interface' |
|
407 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
408 | + * ) |
|
409 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
410 | + * to load an instance of 'some\namespace\classname' |
|
411 | + * |
|
412 | + * @param string $class_name |
|
413 | + * @param string $for_class |
|
414 | + * @return string |
|
415 | + */ |
|
416 | + public function get_alias($class_name = '', $for_class = '') |
|
417 | + { |
|
418 | + if (! $this->has_alias($class_name, $for_class)) { |
|
419 | + return $class_name; |
|
420 | + } |
|
421 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
422 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
423 | + } |
|
424 | + return $this->get_alias($this->_aliases[$class_name]); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | + * This is done by using the following class constants: |
|
433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | + */ |
|
436 | + protected function _register_core_dependencies() |
|
437 | + { |
|
438 | + $this->_dependency_map = array( |
|
439 | + 'EE_Request_Handler' => array( |
|
440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | + ), |
|
442 | + 'EE_System' => array( |
|
443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | + ), |
|
445 | + 'EE_Session' => array( |
|
446 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
447 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_Cart' => array( |
|
450 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
451 | + ), |
|
452 | + 'EE_Front_Controller' => array( |
|
453 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
454 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
455 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
456 | + ), |
|
457 | + 'EE_Messenger_Collection_Loader' => array( |
|
458 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
459 | + ), |
|
460 | + 'EE_Message_Type_Collection_Loader' => array( |
|
461 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
462 | + ), |
|
463 | + 'EE_Message_Resource_Manager' => array( |
|
464 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
465 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
466 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
467 | + ), |
|
468 | + 'EE_Message_Factory' => array( |
|
469 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
470 | + ), |
|
471 | + 'EE_messages' => array( |
|
472 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
473 | + ), |
|
474 | + 'EE_Messages_Generator' => array( |
|
475 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
476 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
477 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
478 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EE_Messages_Processor' => array( |
|
481 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
482 | + ), |
|
483 | + 'EE_Messages_Queue' => array( |
|
484 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
485 | + ), |
|
486 | + 'EE_Messages_Template_Defaults' => array( |
|
487 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
488 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
489 | + ), |
|
490 | + 'EE_Message_To_Generate_From_Request' => array( |
|
491 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
492 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
493 | + ), |
|
494 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
495 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
496 | + ), |
|
497 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
498 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
499 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
502 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
503 | + ), |
|
504 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
505 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
506 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
509 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
510 | + ), |
|
511 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
512 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
515 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
518 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
519 | + ), |
|
520 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
521 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
522 | + ), |
|
523 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
524 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
525 | + ), |
|
526 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
527 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
528 | + ), |
|
529 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
530 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
531 | + ), |
|
532 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
533 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
534 | + ), |
|
535 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
536 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
537 | + ), |
|
538 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
539 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
540 | + ), |
|
541 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
542 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
543 | + ), |
|
544 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
545 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
546 | + ), |
|
547 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
548 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
549 | + ), |
|
550 | + 'EE_Data_Migration_Class_Base' => array( |
|
551 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
552 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EE_DMS_Core_4_1_0' => array( |
|
555 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
556 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
557 | + ), |
|
558 | + 'EE_DMS_Core_4_2_0' => array( |
|
559 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
560 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
561 | + ), |
|
562 | + 'EE_DMS_Core_4_3_0' => array( |
|
563 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
564 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
565 | + ), |
|
566 | + 'EE_DMS_Core_4_4_0' => array( |
|
567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | + ), |
|
570 | + 'EE_DMS_Core_4_5_0' => array( |
|
571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | + ), |
|
574 | + 'EE_DMS_Core_4_6_0' => array( |
|
575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | + ), |
|
578 | + 'EE_DMS_Core_4_7_0' => array( |
|
579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | + ), |
|
582 | + 'EE_DMS_Core_4_8_0' => array( |
|
583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | + ), |
|
586 | + 'EE_DMS_Core_4_9_0' => array( |
|
587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
591 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
592 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
593 | + ), |
|
594 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
595 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
596 | + ), |
|
597 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
598 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
599 | + ), |
|
600 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
601 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
602 | + ), |
|
603 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
604 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
605 | + ), |
|
606 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
607 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
608 | + ), |
|
609 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
610 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
611 | + ), |
|
612 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
613 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
614 | + ), |
|
615 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
616 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
617 | + ), |
|
618 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
619 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
620 | + ), |
|
621 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
622 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
623 | + ), |
|
624 | + 'LEGACY_MODELS' => array( |
|
625 | + null, |
|
626 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
627 | + ), |
|
628 | + 'EE_Module_Request_Router' => array( |
|
629 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + ); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * Registers how core classes are loaded. |
|
638 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
639 | + * 'EE_Request_Handler' => 'load_core' |
|
640 | + * 'EE_Messages_Queue' => 'load_lib' |
|
641 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
642 | + * or, if greater control is required, by providing a custom closure. For example: |
|
643 | + * 'Some_Class' => function () { |
|
644 | + * return new Some_Class(); |
|
645 | + * }, |
|
646 | + * This is required for instantiating dependencies |
|
647 | + * where an interface has been type hinted in a class constructor. For example: |
|
648 | + * 'Required_Interface' => function () { |
|
649 | + * return new A_Class_That_Implements_Required_Interface(); |
|
650 | + * }, |
|
651 | + * |
|
652 | + * @throws InvalidInterfaceException |
|
653 | + * @throws InvalidDataTypeException |
|
654 | + * @throws InvalidArgumentException |
|
655 | + */ |
|
656 | + protected function _register_core_class_loaders() |
|
657 | + { |
|
658 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
659 | + //be used in a closure. |
|
660 | + $request = &$this->_request; |
|
661 | + $response = &$this->_response; |
|
662 | + $loader = &$this->loader; |
|
663 | + $this->_class_loaders = array( |
|
664 | + //load_core |
|
665 | + 'EE_Capabilities' => 'load_core', |
|
666 | + 'EE_Encryption' => 'load_core', |
|
667 | + 'EE_Front_Controller' => 'load_core', |
|
668 | + 'EE_Module_Request_Router' => 'load_core', |
|
669 | + 'EE_Registry' => 'load_core', |
|
670 | + 'EE_Request' => function () use (&$request) { |
|
671 | + return $request; |
|
672 | + }, |
|
673 | + 'EE_Response' => function () use (&$response) { |
|
674 | + return $response; |
|
675 | + }, |
|
676 | + 'EE_Request_Handler' => 'load_core', |
|
677 | + 'EE_Session' => 'load_core', |
|
678 | + 'EE_Cron_Tasks' => 'load_core', |
|
679 | + //load_lib |
|
680 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
681 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
682 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
683 | + 'EE_Messenger_Collection' => 'load_lib', |
|
684 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
685 | + 'EE_Messages_Processor' => 'load_lib', |
|
686 | + 'EE_Message_Repository' => 'load_lib', |
|
687 | + 'EE_Messages_Queue' => 'load_lib', |
|
688 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
689 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
690 | + 'EE_Messages_Generator' => function () { |
|
691 | + return EE_Registry::instance()->load_lib( |
|
692 | + 'Messages_Generator', |
|
693 | + array(), |
|
694 | + false, |
|
695 | + false |
|
696 | + ); |
|
697 | + }, |
|
698 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
699 | + return EE_Registry::instance()->load_lib( |
|
700 | + 'Messages_Template_Defaults', |
|
701 | + $arguments, |
|
702 | + false, |
|
703 | + false |
|
704 | + ); |
|
705 | + }, |
|
706 | + //load_model |
|
707 | + // 'EEM_Attendee' => 'load_model', |
|
708 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
709 | + // 'EEM_Message_Template' => 'load_model', |
|
710 | + //load_helper |
|
711 | + 'EEH_Parse_Shortcodes' => function () { |
|
712 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
713 | + return new EEH_Parse_Shortcodes(); |
|
714 | + } |
|
715 | + return null; |
|
716 | + }, |
|
717 | + 'EE_Template_Config' => function () { |
|
718 | + return EE_Config::instance()->template_settings; |
|
719 | + }, |
|
720 | + 'EE_Currency_Config' => function () { |
|
721 | + return EE_Config::instance()->currency; |
|
722 | + }, |
|
723 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
724 | + return $loader; |
|
725 | + }, |
|
726 | + ); |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * can be used for supplying alternate names for classes, |
|
733 | + * or for connecting interface names to instantiable classes |
|
734 | + */ |
|
735 | + protected function _register_core_aliases() |
|
736 | + { |
|
737 | + $this->_aliases = array( |
|
738 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
739 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
740 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
741 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
742 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
743 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
744 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
745 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
746 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
747 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
748 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
749 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
750 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
751 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
752 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
753 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
754 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
755 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
756 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
757 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
758 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
759 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
760 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
761 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
762 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
763 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
764 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
765 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
766 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
767 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
768 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
769 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
770 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
771 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
772 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
773 | + ); |
|
774 | + } |
|
775 | + |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
780 | + * request Primarily used by unit tests. |
|
781 | + * |
|
782 | + * @throws InvalidDataTypeException |
|
783 | + * @throws InvalidInterfaceException |
|
784 | + * @throws InvalidArgumentException |
|
785 | + */ |
|
786 | + public function reset() |
|
787 | + { |
|
788 | + $this->_register_core_class_loaders(); |
|
789 | + $this->_register_core_dependencies(); |
|
790 | + } |
|
791 | 791 | |
792 | 792 | |
793 | 793 | } |