@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\widgets\EspressoWidget; |
4 | 4 | |
5 | 5 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | /** |
@@ -26,379 +26,379 @@ discard block |
||
26 | 26 | final class EE_Front_Controller |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var string $_template_path |
|
31 | - */ |
|
32 | - private $_template_path; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string $_template |
|
36 | - */ |
|
37 | - private $_template; |
|
38 | - |
|
39 | - /** |
|
40 | - * @type EE_Registry $Registry |
|
41 | - */ |
|
42 | - protected $Registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * @type EE_Request_Handler $Request_Handler |
|
46 | - */ |
|
47 | - protected $Request_Handler; |
|
48 | - |
|
49 | - /** |
|
50 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
51 | - */ |
|
52 | - protected $Module_Request_Router; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * class constructor |
|
57 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @param \EE_Registry $Registry |
|
61 | - * @param \EE_Request_Handler $Request_Handler |
|
62 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
63 | - */ |
|
64 | - public function __construct( |
|
65 | - EE_Registry $Registry, |
|
66 | - EE_Request_Handler $Request_Handler, |
|
67 | - EE_Module_Request_Router $Module_Request_Router |
|
68 | - ) { |
|
69 | - $this->Registry = $Registry; |
|
70 | - $this->Request_Handler = $Request_Handler; |
|
71 | - $this->Module_Request_Router = $Module_Request_Router; |
|
72 | - // determine how to integrate WP_Query with the EE models |
|
73 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
74 | - // load other resources and begin to actually run shortcodes and modules |
|
75 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
76 | - // analyse the incoming WP request |
|
77 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
78 | - // process request with module factory |
|
79 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
80 | - // before headers sent |
|
81 | - add_action('wp', array($this, 'wp'), 5); |
|
82 | - // after headers sent but before any markup is output, |
|
83 | - // primarily used to process any content shortcodes |
|
84 | - add_action('get_header', array($this, 'get_header')); |
|
85 | - // header |
|
86 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | - // display errors |
|
90 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | - // the content |
|
92 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | - //exclude our private cpt comments |
|
94 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | - // action hook EE |
|
98 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | - // for checking that browser cookies are enabled |
|
100 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
101 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return EE_Request_Handler |
|
108 | - */ |
|
109 | - public function Request_Handler() |
|
110 | - { |
|
111 | - return $this->Request_Handler; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return EE_Module_Request_Router |
|
117 | - */ |
|
118 | - public function Module_Request_Router() |
|
119 | - { |
|
120 | - return $this->Module_Request_Router; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return LegacyShortcodesManager |
|
127 | - */ |
|
128 | - public function getLegacyShortcodesManager() |
|
129 | - { |
|
130 | - return EE_Config::getLegacyShortcodesManager(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * filter_wp_comments |
|
143 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
144 | - * widgets/queries done on frontend |
|
145 | - * |
|
146 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
147 | - * @return array array of comment clauses with modifications. |
|
148 | - */ |
|
149 | - public function filter_wp_comments($clauses) |
|
150 | - { |
|
151 | - global $wpdb; |
|
152 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
153 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
154 | - foreach ($cpts as $cpt => $details) { |
|
155 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
156 | - } |
|
157 | - } |
|
158 | - return $clauses; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * employ_CPT_Strategy |
|
164 | - * |
|
165 | - * @access public |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function employ_CPT_Strategy() |
|
169 | - { |
|
170 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
171 | - $this->Registry->load_core('CPT_Strategy'); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
178 | - * |
|
179 | - * @param string $url incoming url |
|
180 | - * @return string final assembled url |
|
181 | - */ |
|
182 | - public function maybe_force_admin_ajax_ssl($url) |
|
183 | - { |
|
184 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
185 | - $url = str_replace('http://', 'https://', $url); |
|
186 | - } |
|
187 | - return $url; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
200 | - * default priority init phases have run |
|
201 | - * |
|
202 | - * @access public |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - public function wp_loaded() |
|
206 | - { |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
214 | - /** |
|
215 | - * _get_request |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @param WP $WP |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - public function get_request(WP $WP) |
|
222 | - { |
|
223 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
224 | - $this->Request_Handler->parse_request($WP); |
|
225 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
232 | - * |
|
233 | - * @access public |
|
234 | - * @param WP_Query $WP_Query |
|
235 | - * @return void |
|
236 | - */ |
|
237 | - public function pre_get_posts($WP_Query) |
|
238 | - { |
|
239 | - // only load Module_Request_Router if this is the main query |
|
240 | - if ( |
|
241 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
242 | - && $WP_Query->is_main_query() |
|
243 | - ) { |
|
244 | - // cycle thru module routes |
|
245 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
246 | - // determine module and method for route |
|
247 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
248 | - if ($module instanceof EED_Module) { |
|
249 | - // get registered view for route |
|
250 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
251 | - // grab module name |
|
252 | - $module_name = $module->module_name(); |
|
253 | - // map the module to the module objects |
|
254 | - $this->Registry->modules->{$module_name} = $module; |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /*********************************************** WP HOOK ***********************************************/ |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * wp - basically last chance to do stuff before headers sent |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - public function wp() |
|
274 | - { |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
280 | - |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * callback for the WP "get_header" hook point |
|
285 | - * checks sidebars for EE widgets |
|
286 | - * loads resources and assets accordingly |
|
287 | - * |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function get_header() |
|
291 | - { |
|
292 | - global $wp_query; |
|
293 | - if (empty($wp_query->posts)){ |
|
294 | - return; |
|
295 | - } |
|
296 | - // if we already know this is an espresso page, then load assets |
|
297 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
298 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
299 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
300 | - if ( $load_assets){ |
|
301 | - wp_enqueue_style('espresso_default'); |
|
302 | - wp_enqueue_style('espresso_custom_css'); |
|
303 | - wp_enqueue_script('espresso_core'); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * builds list of active widgets then scans active sidebars looking for them |
|
311 | - * returns true is an EE widget is found in an active sidebar |
|
312 | - * Please Note: this does NOT mean that the sidebar or widget |
|
313 | - * is actually in use in a given template, as that is unfortunately not known |
|
314 | - * until a sidebar and it's widgets are actually loaded |
|
315 | - * |
|
316 | - * @return boolean |
|
317 | - */ |
|
318 | - private function espresso_widgets_in_active_sidebars() |
|
319 | - { |
|
320 | - $espresso_widgets = array(); |
|
321 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
322 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
323 | - if (is_active_widget(false, false, $id_base)) { |
|
324 | - $espresso_widgets[] = $id_base; |
|
325 | - } |
|
326 | - } |
|
327 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
328 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
329 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
330 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
331 | - foreach ($espresso_widgets as $espresso_widget) { |
|
332 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
333 | - return true; |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
337 | - } |
|
338 | - } |
|
339 | - return false; |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * header_meta_tag |
|
347 | - * |
|
348 | - * @access public |
|
349 | - * @return void |
|
350 | - */ |
|
351 | - public function header_meta_tag() |
|
352 | - { |
|
353 | - print( |
|
354 | - apply_filters( |
|
355 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
356 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
357 | - ); |
|
358 | - |
|
359 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
360 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
361 | - //also exclude all critical pages from indexing |
|
362 | - if ( |
|
363 | - ( |
|
364 | - is_tax('espresso_event_type') |
|
365 | - && get_option( 'blog_public' ) !== '0' |
|
366 | - ) |
|
367 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
368 | - ) { |
|
369 | - print( |
|
370 | - apply_filters( |
|
371 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
372 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
373 | - ) |
|
374 | - ); |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * wp_print_scripts |
|
382 | - * |
|
383 | - * @return void |
|
384 | - */ |
|
385 | - public function wp_print_scripts() |
|
386 | - { |
|
387 | - global $post; |
|
388 | - if ( |
|
389 | - isset($post->EE_Event) |
|
390 | - && $post->EE_Event instanceof EE_Event |
|
391 | - && get_post_type() === 'espresso_events' |
|
392 | - && is_singular() |
|
393 | - ) { |
|
394 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - |
|
401 | - /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
29 | + /** |
|
30 | + * @var string $_template_path |
|
31 | + */ |
|
32 | + private $_template_path; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string $_template |
|
36 | + */ |
|
37 | + private $_template; |
|
38 | + |
|
39 | + /** |
|
40 | + * @type EE_Registry $Registry |
|
41 | + */ |
|
42 | + protected $Registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * @type EE_Request_Handler $Request_Handler |
|
46 | + */ |
|
47 | + protected $Request_Handler; |
|
48 | + |
|
49 | + /** |
|
50 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
51 | + */ |
|
52 | + protected $Module_Request_Router; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * class constructor |
|
57 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @param \EE_Registry $Registry |
|
61 | + * @param \EE_Request_Handler $Request_Handler |
|
62 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
63 | + */ |
|
64 | + public function __construct( |
|
65 | + EE_Registry $Registry, |
|
66 | + EE_Request_Handler $Request_Handler, |
|
67 | + EE_Module_Request_Router $Module_Request_Router |
|
68 | + ) { |
|
69 | + $this->Registry = $Registry; |
|
70 | + $this->Request_Handler = $Request_Handler; |
|
71 | + $this->Module_Request_Router = $Module_Request_Router; |
|
72 | + // determine how to integrate WP_Query with the EE models |
|
73 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
74 | + // load other resources and begin to actually run shortcodes and modules |
|
75 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
76 | + // analyse the incoming WP request |
|
77 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
78 | + // process request with module factory |
|
79 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
80 | + // before headers sent |
|
81 | + add_action('wp', array($this, 'wp'), 5); |
|
82 | + // after headers sent but before any markup is output, |
|
83 | + // primarily used to process any content shortcodes |
|
84 | + add_action('get_header', array($this, 'get_header')); |
|
85 | + // header |
|
86 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | + // display errors |
|
90 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | + // the content |
|
92 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | + //exclude our private cpt comments |
|
94 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | + // action hook EE |
|
98 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | + // for checking that browser cookies are enabled |
|
100 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
101 | + setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return EE_Request_Handler |
|
108 | + */ |
|
109 | + public function Request_Handler() |
|
110 | + { |
|
111 | + return $this->Request_Handler; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return EE_Module_Request_Router |
|
117 | + */ |
|
118 | + public function Module_Request_Router() |
|
119 | + { |
|
120 | + return $this->Module_Request_Router; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return LegacyShortcodesManager |
|
127 | + */ |
|
128 | + public function getLegacyShortcodesManager() |
|
129 | + { |
|
130 | + return EE_Config::getLegacyShortcodesManager(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * filter_wp_comments |
|
143 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
144 | + * widgets/queries done on frontend |
|
145 | + * |
|
146 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
147 | + * @return array array of comment clauses with modifications. |
|
148 | + */ |
|
149 | + public function filter_wp_comments($clauses) |
|
150 | + { |
|
151 | + global $wpdb; |
|
152 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
153 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
154 | + foreach ($cpts as $cpt => $details) { |
|
155 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
156 | + } |
|
157 | + } |
|
158 | + return $clauses; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * employ_CPT_Strategy |
|
164 | + * |
|
165 | + * @access public |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function employ_CPT_Strategy() |
|
169 | + { |
|
170 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
171 | + $this->Registry->load_core('CPT_Strategy'); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
178 | + * |
|
179 | + * @param string $url incoming url |
|
180 | + * @return string final assembled url |
|
181 | + */ |
|
182 | + public function maybe_force_admin_ajax_ssl($url) |
|
183 | + { |
|
184 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
185 | + $url = str_replace('http://', 'https://', $url); |
|
186 | + } |
|
187 | + return $url; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
200 | + * default priority init phases have run |
|
201 | + * |
|
202 | + * @access public |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + public function wp_loaded() |
|
206 | + { |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
214 | + /** |
|
215 | + * _get_request |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @param WP $WP |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + public function get_request(WP $WP) |
|
222 | + { |
|
223 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
224 | + $this->Request_Handler->parse_request($WP); |
|
225 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
232 | + * |
|
233 | + * @access public |
|
234 | + * @param WP_Query $WP_Query |
|
235 | + * @return void |
|
236 | + */ |
|
237 | + public function pre_get_posts($WP_Query) |
|
238 | + { |
|
239 | + // only load Module_Request_Router if this is the main query |
|
240 | + if ( |
|
241 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
242 | + && $WP_Query->is_main_query() |
|
243 | + ) { |
|
244 | + // cycle thru module routes |
|
245 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
246 | + // determine module and method for route |
|
247 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
248 | + if ($module instanceof EED_Module) { |
|
249 | + // get registered view for route |
|
250 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
251 | + // grab module name |
|
252 | + $module_name = $module->module_name(); |
|
253 | + // map the module to the module objects |
|
254 | + $this->Registry->modules->{$module_name} = $module; |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /*********************************************** WP HOOK ***********************************************/ |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * wp - basically last chance to do stuff before headers sent |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + public function wp() |
|
274 | + { |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
280 | + |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * callback for the WP "get_header" hook point |
|
285 | + * checks sidebars for EE widgets |
|
286 | + * loads resources and assets accordingly |
|
287 | + * |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function get_header() |
|
291 | + { |
|
292 | + global $wp_query; |
|
293 | + if (empty($wp_query->posts)){ |
|
294 | + return; |
|
295 | + } |
|
296 | + // if we already know this is an espresso page, then load assets |
|
297 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
298 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
299 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
300 | + if ( $load_assets){ |
|
301 | + wp_enqueue_style('espresso_default'); |
|
302 | + wp_enqueue_style('espresso_custom_css'); |
|
303 | + wp_enqueue_script('espresso_core'); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * builds list of active widgets then scans active sidebars looking for them |
|
311 | + * returns true is an EE widget is found in an active sidebar |
|
312 | + * Please Note: this does NOT mean that the sidebar or widget |
|
313 | + * is actually in use in a given template, as that is unfortunately not known |
|
314 | + * until a sidebar and it's widgets are actually loaded |
|
315 | + * |
|
316 | + * @return boolean |
|
317 | + */ |
|
318 | + private function espresso_widgets_in_active_sidebars() |
|
319 | + { |
|
320 | + $espresso_widgets = array(); |
|
321 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
322 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
323 | + if (is_active_widget(false, false, $id_base)) { |
|
324 | + $espresso_widgets[] = $id_base; |
|
325 | + } |
|
326 | + } |
|
327 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
328 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
329 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
330 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
331 | + foreach ($espresso_widgets as $espresso_widget) { |
|
332 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
333 | + return true; |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | + } |
|
338 | + } |
|
339 | + return false; |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * header_meta_tag |
|
347 | + * |
|
348 | + * @access public |
|
349 | + * @return void |
|
350 | + */ |
|
351 | + public function header_meta_tag() |
|
352 | + { |
|
353 | + print( |
|
354 | + apply_filters( |
|
355 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
356 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
357 | + ); |
|
358 | + |
|
359 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
360 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
361 | + //also exclude all critical pages from indexing |
|
362 | + if ( |
|
363 | + ( |
|
364 | + is_tax('espresso_event_type') |
|
365 | + && get_option( 'blog_public' ) !== '0' |
|
366 | + ) |
|
367 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
368 | + ) { |
|
369 | + print( |
|
370 | + apply_filters( |
|
371 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
372 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
373 | + ) |
|
374 | + ); |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * wp_print_scripts |
|
382 | + * |
|
383 | + * @return void |
|
384 | + */ |
|
385 | + public function wp_print_scripts() |
|
386 | + { |
|
387 | + global $post; |
|
388 | + if ( |
|
389 | + isset($post->EE_Event) |
|
390 | + && $post->EE_Event instanceof EE_Event |
|
391 | + && get_post_type() === 'espresso_events' |
|
392 | + && is_singular() |
|
393 | + ) { |
|
394 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + |
|
401 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
402 | 402 | |
403 | 403 | |
404 | 404 | |
@@ -409,99 +409,99 @@ discard block |
||
409 | 409 | // * @param $the_content |
410 | 410 | // * @return string |
411 | 411 | // */ |
412 | - // public function the_content( $the_content ) { |
|
413 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
414 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
415 | - // } |
|
416 | - // return $the_content; |
|
417 | - // } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * display_errors |
|
426 | - * |
|
427 | - * @access public |
|
428 | - * @return void |
|
429 | - */ |
|
430 | - public function display_errors() |
|
431 | - { |
|
432 | - static $shown_already = false; |
|
433 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
434 | - if ( |
|
435 | - ! $shown_already |
|
436 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
437 | - && is_main_query() |
|
438 | - && ! is_feed() |
|
439 | - && in_the_loop() |
|
440 | - && $this->Request_Handler->is_espresso_page() |
|
441 | - ) { |
|
442 | - echo EE_Error::get_notices(); |
|
443 | - $shown_already = true; |
|
444 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
445 | - } |
|
446 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - |
|
453 | - /*********************************************** UTILITIES ***********************************************/ |
|
454 | - /** |
|
455 | - * template_include |
|
456 | - * |
|
457 | - * @access public |
|
458 | - * @param string $template_include_path |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public function template_include($template_include_path = null) |
|
462 | - { |
|
463 | - if ($this->Request_Handler->is_espresso_page()) { |
|
464 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
465 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
466 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
467 | - $this->_template = basename($this->_template_path); |
|
468 | - return $this->_template_path; |
|
469 | - } |
|
470 | - return $template_include_path; |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * get_selected_template |
|
476 | - * |
|
477 | - * @access public |
|
478 | - * @param bool $with_path |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public function get_selected_template($with_path = false) |
|
482 | - { |
|
483 | - return $with_path ? $this->_template_path : $this->_template; |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * @deprecated 4.9.26 |
|
490 | - * @param string $shortcode_class |
|
491 | - * @param \WP $wp |
|
492 | - */ |
|
493 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
494 | - { |
|
495 | - \EE_Error::doing_it_wrong( |
|
496 | - __METHOD__, |
|
497 | - __( |
|
498 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
499 | - 'event_espresso' |
|
500 | - ), |
|
501 | - '4.9.26' |
|
502 | - ); |
|
503 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
504 | - } |
|
412 | + // public function the_content( $the_content ) { |
|
413 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
414 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
415 | + // } |
|
416 | + // return $the_content; |
|
417 | + // } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * display_errors |
|
426 | + * |
|
427 | + * @access public |
|
428 | + * @return void |
|
429 | + */ |
|
430 | + public function display_errors() |
|
431 | + { |
|
432 | + static $shown_already = false; |
|
433 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
434 | + if ( |
|
435 | + ! $shown_already |
|
436 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
437 | + && is_main_query() |
|
438 | + && ! is_feed() |
|
439 | + && in_the_loop() |
|
440 | + && $this->Request_Handler->is_espresso_page() |
|
441 | + ) { |
|
442 | + echo EE_Error::get_notices(); |
|
443 | + $shown_already = true; |
|
444 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
445 | + } |
|
446 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + |
|
453 | + /*********************************************** UTILITIES ***********************************************/ |
|
454 | + /** |
|
455 | + * template_include |
|
456 | + * |
|
457 | + * @access public |
|
458 | + * @param string $template_include_path |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public function template_include($template_include_path = null) |
|
462 | + { |
|
463 | + if ($this->Request_Handler->is_espresso_page()) { |
|
464 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
465 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
466 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
467 | + $this->_template = basename($this->_template_path); |
|
468 | + return $this->_template_path; |
|
469 | + } |
|
470 | + return $template_include_path; |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * get_selected_template |
|
476 | + * |
|
477 | + * @access public |
|
478 | + * @param bool $with_path |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public function get_selected_template($with_path = false) |
|
482 | + { |
|
483 | + return $with_path ? $this->_template_path : $this->_template; |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * @deprecated 4.9.26 |
|
490 | + * @param string $shortcode_class |
|
491 | + * @param \WP $wp |
|
492 | + */ |
|
493 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
494 | + { |
|
495 | + \EE_Error::doing_it_wrong( |
|
496 | + __METHOD__, |
|
497 | + __( |
|
498 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
499 | + 'event_espresso' |
|
500 | + ), |
|
501 | + '4.9.26' |
|
502 | + ); |
|
503 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
504 | + } |
|
505 | 505 | |
506 | 506 | } |
507 | 507 | // End of file EE_Front_Controller.core.php |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | do_action('AHEE__EE_Front_Controller__construct__done', $this); |
99 | 99 | // for checking that browser cookies are enabled |
100 | 100 | if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
101 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
101 | + setcookie('ee_cookie_test', uniqid('ect', true), time() + DAY_IN_SECONDS, '/'); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | public function get_header() |
291 | 291 | { |
292 | 292 | global $wp_query; |
293 | - if (empty($wp_query->posts)){ |
|
293 | + if (empty($wp_query->posts)) { |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | // if we already know this is an espresso page, then load assets |
297 | 297 | $load_assets = $this->Request_Handler->is_espresso_page(); |
298 | 298 | // if we are already loading assets then just move along, otherwise check for widgets |
299 | 299 | $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
300 | - if ( $load_assets){ |
|
300 | + if ($load_assets) { |
|
301 | 301 | wp_enqueue_style('espresso_default'); |
302 | 302 | wp_enqueue_style('espresso_custom_css'); |
303 | 303 | wp_enqueue_script('espresso_core'); |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | print( |
354 | 354 | apply_filters( |
355 | 355 | 'FHEE__EE_Front_Controller__header_meta_tag', |
356 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
356 | + '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n") |
|
357 | 357 | ); |
358 | 358 | |
359 | 359 | //let's exclude all event type taxonomy term archive pages from search engine indexing |
@@ -362,14 +362,14 @@ discard block |
||
362 | 362 | if ( |
363 | 363 | ( |
364 | 364 | is_tax('espresso_event_type') |
365 | - && get_option( 'blog_public' ) !== '0' |
|
365 | + && get_option('blog_public') !== '0' |
|
366 | 366 | ) |
367 | 367 | || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
368 | 368 | ) { |
369 | 369 | print( |
370 | 370 | apply_filters( |
371 | 371 | 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
372 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
372 | + '<meta name="robots" content="noindex,follow" />'."\n" |
|
373 | 373 | ) |
374 | 374 | ); |
375 | 375 | } |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | ) { |
442 | 442 | echo EE_Error::get_notices(); |
443 | 443 | $shown_already = true; |
444 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
444 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
445 | 445 | } |
446 | 446 | do_action('AHEE__EE_Front_Controller__display_errors__end'); |
447 | 447 | } |
@@ -16,1376 +16,1376 @@ |
||
16 | 16 | class EE_Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * EE_Registry Object |
|
21 | - * |
|
22 | - * @var EE_Registry $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var EE_Dependency_Map $_dependency_map |
|
29 | - * @access protected |
|
30 | - */ |
|
31 | - protected $_dependency_map = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array $_class_abbreviations |
|
35 | - * @access protected |
|
36 | - */ |
|
37 | - protected $_class_abbreviations = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @access public |
|
41 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | - */ |
|
43 | - public $BUS; |
|
44 | - |
|
45 | - /** |
|
46 | - * EE_Cart Object |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Cart $CART |
|
50 | - */ |
|
51 | - public $CART = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * EE_Config Object |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @var EE_Config $CFG |
|
58 | - */ |
|
59 | - public $CFG = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * EE_Network_Config Object |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @var EE_Network_Config $NET_CFG |
|
66 | - */ |
|
67 | - public $NET_CFG = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * StdClass object for storing library classes in |
|
71 | - * |
|
72 | - * @public LIB |
|
73 | - * @var StdClass $LIB |
|
74 | - */ |
|
75 | - public $LIB = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * EE_Request_Handler Object |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @var EE_Request_Handler $REQ |
|
82 | - */ |
|
83 | - public $REQ = null; |
|
84 | - |
|
85 | - /** |
|
86 | - * EE_Session Object |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @var EE_Session $SSN |
|
90 | - */ |
|
91 | - public $SSN = null; |
|
92 | - |
|
93 | - /** |
|
94 | - * holds the ee capabilities object. |
|
95 | - * |
|
96 | - * @since 4.5.0 |
|
97 | - * @var EE_Capabilities |
|
98 | - */ |
|
99 | - public $CAP = null; |
|
100 | - |
|
101 | - /** |
|
102 | - * holds the EE_Message_Resource_Manager object. |
|
103 | - * |
|
104 | - * @since 4.9.0 |
|
105 | - * @var EE_Message_Resource_Manager |
|
106 | - */ |
|
107 | - public $MRM = null; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Holds the Assets Registry instance |
|
112 | - * @var Registry |
|
113 | - */ |
|
114 | - public $AssetsRegistry = null; |
|
115 | - |
|
116 | - /** |
|
117 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Addon[] |
|
121 | - */ |
|
122 | - public $addons = null; |
|
123 | - |
|
124 | - /** |
|
125 | - * $models |
|
126 | - * @access public |
|
127 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | - */ |
|
129 | - public $models = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * $modules |
|
133 | - * @access public |
|
134 | - * @var EED_Module[] $modules |
|
135 | - */ |
|
136 | - public $modules = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * $shortcodes |
|
140 | - * @access public |
|
141 | - * @var EES_Shortcode[] $shortcodes |
|
142 | - */ |
|
143 | - public $shortcodes = null; |
|
144 | - |
|
145 | - /** |
|
146 | - * $widgets |
|
147 | - * @access public |
|
148 | - * @var WP_Widget[] $widgets |
|
149 | - */ |
|
150 | - public $widgets = null; |
|
151 | - |
|
152 | - /** |
|
153 | - * $non_abstract_db_models |
|
154 | - * @access public |
|
155 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | - * classnames (eg "EEM_Event") |
|
159 | - */ |
|
160 | - public $non_abstract_db_models = array(); |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * $i18n_js_strings - internationalization for JS strings |
|
165 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | - * in js file: var translatedString = eei18n.string_key; |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @var array |
|
170 | - */ |
|
171 | - public static $i18n_js_strings = array(); |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * $main_file - path to espresso.php |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @var array |
|
179 | - */ |
|
180 | - public $main_file; |
|
181 | - |
|
182 | - /** |
|
183 | - * array of ReflectionClass objects where the key is the class name |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @var ReflectionClass[] |
|
187 | - */ |
|
188 | - public $_reflectors; |
|
189 | - |
|
190 | - /** |
|
191 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | - * |
|
193 | - * @access protected |
|
194 | - * @var boolean $_cache_on |
|
195 | - */ |
|
196 | - protected $_cache_on = true; |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @singleton method used to instantiate class object |
|
202 | - * @access public |
|
203 | - * @param \EE_Dependency_Map $dependency_map |
|
204 | - * @return \EE_Registry instance |
|
205 | - */ |
|
206 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | - { |
|
208 | - // check if class object is instantiated |
|
209 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | - self::$_instance = new EE_Registry($dependency_map); |
|
211 | - } |
|
212 | - return self::$_instance; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - *protected constructor to prevent direct creation |
|
219 | - * |
|
220 | - * @Constructor |
|
221 | - * @access protected |
|
222 | - * @param \EE_Dependency_Map $dependency_map |
|
223 | - * @return \EE_Registry |
|
224 | - */ |
|
225 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | - { |
|
227 | - $this->_dependency_map = $dependency_map; |
|
228 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * initialize |
|
235 | - */ |
|
236 | - public function initialize() |
|
237 | - { |
|
238 | - $this->_class_abbreviations = apply_filters( |
|
239 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | - array( |
|
241 | - 'EE_Config' => 'CFG', |
|
242 | - 'EE_Session' => 'SSN', |
|
243 | - 'EE_Capabilities' => 'CAP', |
|
244 | - 'EE_Cart' => 'CART', |
|
245 | - 'EE_Network_Config' => 'NET_CFG', |
|
246 | - 'EE_Request_Handler' => 'REQ', |
|
247 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
250 | - ) |
|
251 | - ); |
|
252 | - // class library |
|
253 | - $this->LIB = new stdClass(); |
|
254 | - $this->addons = new stdClass(); |
|
255 | - $this->modules = new stdClass(); |
|
256 | - $this->shortcodes = new stdClass(); |
|
257 | - $this->widgets = new stdClass(); |
|
258 | - $this->load_core('Base', array(), true); |
|
259 | - // add our request and response objects to the cache |
|
260 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
261 | - $this->_set_cached_class( |
|
262 | - $request_loader(), |
|
263 | - 'EE_Request' |
|
264 | - ); |
|
265 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
266 | - $this->_set_cached_class( |
|
267 | - $response_loader(), |
|
268 | - 'EE_Response' |
|
269 | - ); |
|
270 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * init |
|
277 | - * |
|
278 | - * @access public |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - public function init() |
|
282 | - { |
|
283 | - // Get current page protocol |
|
284 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | - // Output admin-ajax.php URL with same protocol as current page |
|
286 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * localize_i18n_js_strings |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public static function localize_i18n_js_strings() |
|
298 | - { |
|
299 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | - foreach ($i18n_js_strings as $key => $value) { |
|
301 | - if (is_scalar($value)) { |
|
302 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | - } |
|
304 | - } |
|
305 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param mixed string | EED_Module $module |
|
312 | - */ |
|
313 | - public function add_module($module) |
|
314 | - { |
|
315 | - if ($module instanceof EED_Module) { |
|
316 | - $module_class = get_class($module); |
|
317 | - $this->modules->{$module_class} = $module; |
|
318 | - } else { |
|
319 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | - $this->load_core('Module_Request_Router'); |
|
321 | - } |
|
322 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @param string $module_name |
|
330 | - * @return mixed EED_Module | NULL |
|
331 | - */ |
|
332 | - public function get_module($module_name = '') |
|
333 | - { |
|
334 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * loads core classes - must be singletons |
|
341 | - * |
|
342 | - * @access public |
|
343 | - * @param string $class_name - simple class name ie: session |
|
344 | - * @param mixed $arguments |
|
345 | - * @param bool $load_only |
|
346 | - * @return mixed |
|
347 | - */ |
|
348 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | - { |
|
350 | - $core_paths = apply_filters( |
|
351 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | - array( |
|
353 | - EE_CORE, |
|
354 | - EE_ADMIN, |
|
355 | - EE_CPTS, |
|
356 | - EE_CORE . 'data_migration_scripts' . DS, |
|
357 | - EE_CORE . 'request_stack' . DS, |
|
358 | - EE_CORE . 'middleware' . DS, |
|
359 | - ) |
|
360 | - ); |
|
361 | - // retrieve instantiated class |
|
362 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * loads service classes |
|
369 | - * |
|
370 | - * @access public |
|
371 | - * @param string $class_name - simple class name ie: session |
|
372 | - * @param mixed $arguments |
|
373 | - * @param bool $load_only |
|
374 | - * @return mixed |
|
375 | - */ |
|
376 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | - { |
|
378 | - $service_paths = apply_filters( |
|
379 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | - array( |
|
381 | - EE_CORE . 'services' . DS, |
|
382 | - ) |
|
383 | - ); |
|
384 | - // retrieve instantiated class |
|
385 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * loads data_migration_scripts |
|
392 | - * |
|
393 | - * @access public |
|
394 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | - * @param mixed $arguments |
|
396 | - * @return EE_Data_Migration_Script_Base|mixed |
|
397 | - */ |
|
398 | - public function load_dms($class_name, $arguments = array()) |
|
399 | - { |
|
400 | - // retrieve instantiated class |
|
401 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * loads object creating classes - must be singletons |
|
408 | - * |
|
409 | - * @param string $class_name - simple class name ie: attendee |
|
410 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
413 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | - * @return EE_Base_Class | bool |
|
415 | - */ |
|
416 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | - { |
|
418 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | - EE_CORE, |
|
420 | - EE_CLASSES, |
|
421 | - EE_BUSINESS, |
|
422 | - )); |
|
423 | - // retrieve instantiated class |
|
424 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * loads helper classes - must be singletons |
|
431 | - * |
|
432 | - * @param string $class_name - simple class name ie: price |
|
433 | - * @param mixed $arguments |
|
434 | - * @param bool $load_only |
|
435 | - * @return EEH_Base | bool |
|
436 | - */ |
|
437 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | - { |
|
439 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | - // retrieve instantiated class |
|
442 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * loads core classes - must be singletons |
|
449 | - * |
|
450 | - * @access public |
|
451 | - * @param string $class_name - simple class name ie: session |
|
452 | - * @param mixed $arguments |
|
453 | - * @param bool $load_only |
|
454 | - * @param bool $cache whether to cache the object or not. |
|
455 | - * @return mixed |
|
456 | - */ |
|
457 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | - { |
|
459 | - $paths = array( |
|
460 | - EE_LIBRARIES, |
|
461 | - EE_LIBRARIES . 'messages' . DS, |
|
462 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | - EE_LIBRARIES . 'qtips' . DS, |
|
464 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | - ); |
|
466 | - // retrieve instantiated class |
|
467 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * loads model classes - must be singletons |
|
474 | - * |
|
475 | - * @param string $class_name - simple class name ie: price |
|
476 | - * @param mixed $arguments |
|
477 | - * @param bool $load_only |
|
478 | - * @return EEM_Base | bool |
|
479 | - */ |
|
480 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | - { |
|
482 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | - EE_MODELS, |
|
484 | - EE_CORE, |
|
485 | - )); |
|
486 | - // retrieve instantiated class |
|
487 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * loads model classes - must be singletons |
|
494 | - * |
|
495 | - * @param string $class_name - simple class name ie: price |
|
496 | - * @param mixed $arguments |
|
497 | - * @param bool $load_only |
|
498 | - * @return mixed | bool |
|
499 | - */ |
|
500 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | - { |
|
502 | - $paths = array( |
|
503 | - EE_MODELS . 'fields' . DS, |
|
504 | - EE_MODELS . 'helpers' . DS, |
|
505 | - EE_MODELS . 'relations' . DS, |
|
506 | - EE_MODELS . 'strategies' . DS, |
|
507 | - ); |
|
508 | - // retrieve instantiated class |
|
509 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Determines if $model_name is the name of an actual EE model. |
|
516 | - * |
|
517 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | - * @return boolean |
|
519 | - */ |
|
520 | - public function is_model_name($model_name) |
|
521 | - { |
|
522 | - return isset($this->models[$model_name]) ? true : false; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * generic class loader |
|
529 | - * |
|
530 | - * @param string $path_to_file - directory path to file location, not including filename |
|
531 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
532 | - * @param string $type - file type - core? class? helper? model? |
|
533 | - * @param mixed $arguments |
|
534 | - * @param bool $load_only |
|
535 | - * @return mixed |
|
536 | - */ |
|
537 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
538 | - { |
|
539 | - // retrieve instantiated class |
|
540 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * load_addon |
|
547 | - * |
|
548 | - * @param string $path_to_file - directory path to file location, not including filename |
|
549 | - * @param string $class_name - full class name ie: My_Class |
|
550 | - * @param string $type - file type - core? class? helper? model? |
|
551 | - * @param mixed $arguments |
|
552 | - * @param bool $load_only |
|
553 | - * @return EE_Addon |
|
554 | - */ |
|
555 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
556 | - { |
|
557 | - // retrieve instantiated class |
|
558 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * instantiates, caches, and automatically resolves dependencies |
|
565 | - * for classes that use a Fully Qualified Class Name. |
|
566 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
567 | - * then you need to use one of the existing load_*() methods |
|
568 | - * which can resolve the classname and filepath from the passed arguments |
|
569 | - * |
|
570 | - * @param bool|string $class_name Fully Qualified Class Name |
|
571 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
572 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
573 | - * @param bool $from_db some classes are instantiated from the db |
|
574 | - * and thus call a different method to instantiate |
|
575 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
576 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
577 | - * @return mixed null = failure to load or instantiate class object. |
|
578 | - * object = class loaded and instantiated successfully. |
|
579 | - * bool = fail or success when $load_only is true |
|
580 | - */ |
|
581 | - public function create( |
|
582 | - $class_name = false, |
|
583 | - $arguments = array(), |
|
584 | - $cache = false, |
|
585 | - $from_db = false, |
|
586 | - $load_only = false, |
|
587 | - $addon = false |
|
588 | - ) { |
|
589 | - $class_name = ltrim($class_name, '\\'); |
|
590 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
591 | - if ( ! class_exists($class_name)) { |
|
592 | - // maybe the class is registered with a preceding \ |
|
593 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
594 | - // still doesn't exist ? |
|
595 | - if ( ! class_exists($class_name)) { |
|
596 | - return null; |
|
597 | - } |
|
598 | - } |
|
599 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
600 | - if ($load_only) { |
|
601 | - return true; |
|
602 | - } |
|
603 | - $addon = $addon ? 'addon' : ''; |
|
604 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
605 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
606 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
607 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
608 | - // return object if it's already cached |
|
609 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
610 | - if ($cached_class !== null) { |
|
611 | - return $cached_class; |
|
612 | - } |
|
613 | - } |
|
614 | - // instantiate the requested object |
|
615 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
616 | - if ($this->_cache_on && $cache) { |
|
617 | - // save it for later... kinda like gum { : $ |
|
618 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
619 | - } |
|
620 | - $this->_cache_on = true; |
|
621 | - return $class_obj; |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * instantiates, caches, and injects dependencies for classes |
|
628 | - * |
|
629 | - * @param array $file_paths an array of paths to folders to look in |
|
630 | - * @param string $class_prefix EE or EEM or... ??? |
|
631 | - * @param bool|string $class_name $class name |
|
632 | - * @param string $type file type - core? class? helper? model? |
|
633 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
634 | - * @param bool $from_db some classes are instantiated from the db |
|
635 | - * and thus call a different method to instantiate |
|
636 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
637 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
638 | - * @return null|object|bool null = failure to load or instantiate class object. |
|
639 | - * object = class loaded and instantiated successfully. |
|
640 | - * bool = fail or success when $load_only is true |
|
641 | - */ |
|
642 | - protected function _load( |
|
643 | - $file_paths = array(), |
|
644 | - $class_prefix = 'EE_', |
|
645 | - $class_name = false, |
|
646 | - $type = 'class', |
|
647 | - $arguments = array(), |
|
648 | - $from_db = false, |
|
649 | - $cache = true, |
|
650 | - $load_only = false |
|
651 | - ) { |
|
652 | - $class_name = ltrim($class_name, '\\'); |
|
653 | - // strip php file extension |
|
654 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
655 | - // does the class have a prefix ? |
|
656 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
657 | - // make sure $class_prefix is uppercase |
|
658 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
659 | - // add class prefix ONCE!!! |
|
660 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
661 | - } |
|
662 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
663 | - $class_exists = class_exists($class_name); |
|
664 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
665 | - if ($load_only && $class_exists) { |
|
666 | - return true; |
|
667 | - } |
|
668 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
669 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
670 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
671 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
672 | - // return object if it's already cached |
|
673 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
674 | - if ($cached_class !== null) { |
|
675 | - return $cached_class; |
|
676 | - } |
|
677 | - } |
|
678 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
679 | - if ( ! $class_exists) { |
|
680 | - // get full path to file |
|
681 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
682 | - // load the file |
|
683 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
684 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
685 | - if ( ! $loaded || $load_only) { |
|
686 | - // return boolean if only loading, or null if an object was expected |
|
687 | - return $load_only ? $loaded : null; |
|
688 | - } |
|
689 | - } |
|
690 | - // instantiate the requested object |
|
691 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
692 | - if ($this->_cache_on && $cache) { |
|
693 | - // save it for later... kinda like gum { : $ |
|
694 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
695 | - } |
|
696 | - $this->_cache_on = true; |
|
697 | - return $class_obj; |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * _get_cached_class |
|
704 | - * attempts to find a cached version of the requested class |
|
705 | - * by looking in the following places: |
|
706 | - * $this->{$class_abbreviation} ie: $this->CART |
|
707 | - * $this->{$class_name} ie: $this->Some_Class |
|
708 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
709 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
710 | - * |
|
711 | - * @access protected |
|
712 | - * @param string $class_name |
|
713 | - * @param string $class_prefix |
|
714 | - * @return mixed |
|
715 | - */ |
|
716 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
717 | - { |
|
718 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
719 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
720 | - } else { |
|
721 | - // have to specify something, but not anything that will conflict |
|
722 | - $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
723 | - } |
|
724 | - // check if class has already been loaded, and return it if it has been |
|
725 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
726 | - return $this->{$class_abbreviation}; |
|
727 | - } else if (isset ($this->{$class_name})) { |
|
728 | - return $this->{$class_name}; |
|
729 | - } else if (isset ($this->LIB->{$class_name})) { |
|
730 | - return $this->LIB->{$class_name}; |
|
731 | - } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
732 | - return $this->addons->{$class_name}; |
|
733 | - } |
|
734 | - return null; |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * _resolve_path |
|
741 | - * attempts to find a full valid filepath for the requested class. |
|
742 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
743 | - * then returns that path if the target file has been found and is readable |
|
744 | - * |
|
745 | - * @access protected |
|
746 | - * @param string $class_name |
|
747 | - * @param string $type |
|
748 | - * @param array $file_paths |
|
749 | - * @return string | bool |
|
750 | - */ |
|
751 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
752 | - { |
|
753 | - // make sure $file_paths is an array |
|
754 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
755 | - // cycle thru paths |
|
756 | - foreach ($file_paths as $key => $file_path) { |
|
757 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
758 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
759 | - // prep file type |
|
760 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
761 | - // build full file path |
|
762 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
763 | - //does the file exist and can be read ? |
|
764 | - if (is_readable($file_paths[$key])) { |
|
765 | - return $file_paths[$key]; |
|
766 | - } |
|
767 | - } |
|
768 | - return false; |
|
769 | - } |
|
770 | - |
|
771 | - |
|
772 | - |
|
773 | - /** |
|
774 | - * _require_file |
|
775 | - * basically just performs a require_once() |
|
776 | - * but with some error handling |
|
777 | - * |
|
778 | - * @access protected |
|
779 | - * @param string $path |
|
780 | - * @param string $class_name |
|
781 | - * @param string $type |
|
782 | - * @param array $file_paths |
|
783 | - * @return boolean |
|
784 | - * @throws \EE_Error |
|
785 | - */ |
|
786 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
787 | - { |
|
788 | - // don't give up! you gotta... |
|
789 | - try { |
|
790 | - //does the file exist and can it be read ? |
|
791 | - if ( ! $path) { |
|
792 | - // so sorry, can't find the file |
|
793 | - throw new EE_Error ( |
|
794 | - sprintf( |
|
795 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
796 | - trim($type, '.'), |
|
797 | - $class_name, |
|
798 | - '<br />' . implode(',<br />', $file_paths) |
|
799 | - ) |
|
800 | - ); |
|
801 | - } |
|
802 | - // get the file |
|
803 | - require_once($path); |
|
804 | - // if the class isn't already declared somewhere |
|
805 | - if (class_exists($class_name, false) === false) { |
|
806 | - // so sorry, not a class |
|
807 | - throw new EE_Error( |
|
808 | - sprintf( |
|
809 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
810 | - $type, |
|
811 | - $path, |
|
812 | - $class_name |
|
813 | - ) |
|
814 | - ); |
|
815 | - } |
|
816 | - } catch (EE_Error $e) { |
|
817 | - $e->get_error(); |
|
818 | - return false; |
|
819 | - } |
|
820 | - return true; |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * _create_object |
|
827 | - * Attempts to instantiate the requested class via any of the |
|
828 | - * commonly used instantiation methods employed throughout EE. |
|
829 | - * The priority for instantiation is as follows: |
|
830 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
831 | - * - model objects via their 'new_instance_from_db' method |
|
832 | - * - model objects via their 'new_instance' method |
|
833 | - * - "singleton" classes" via their 'instance' method |
|
834 | - * - standard instantiable classes via their __constructor |
|
835 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
836 | - * then the constructor for the requested class will be examined to determine |
|
837 | - * if any dependencies exist, and if they can be injected. |
|
838 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
839 | - * |
|
840 | - * @access protected |
|
841 | - * @param string $class_name |
|
842 | - * @param array $arguments |
|
843 | - * @param string $type |
|
844 | - * @param bool $from_db |
|
845 | - * @return null | object |
|
846 | - * @throws \EE_Error |
|
847 | - */ |
|
848 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
849 | - { |
|
850 | - $class_obj = null; |
|
851 | - $instantiation_mode = '0) none'; |
|
852 | - // don't give up! you gotta... |
|
853 | - try { |
|
854 | - // create reflection |
|
855 | - $reflector = $this->get_ReflectionClass($class_name); |
|
856 | - // make sure arguments are an array |
|
857 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
858 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
859 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
860 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
861 | - ? $arguments |
|
862 | - : array($arguments); |
|
863 | - // attempt to inject dependencies ? |
|
864 | - if ($this->_dependency_map->has($class_name)) { |
|
865 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
866 | - } |
|
867 | - // instantiate the class if possible |
|
868 | - if ($reflector->isAbstract()) { |
|
869 | - // nothing to instantiate, loading file was enough |
|
870 | - // does not throw an exception so $instantiation_mode is unused |
|
871 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
872 | - $class_obj = true; |
|
873 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
874 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
875 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
876 | - $class_obj = $reflector->newInstance(); |
|
877 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
878 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
879 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
880 | - } else if (method_exists($class_name, 'new_instance')) { |
|
881 | - $instantiation_mode = "4) new_instance()"; |
|
882 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
883 | - } else if (method_exists($class_name, 'instance')) { |
|
884 | - $instantiation_mode = "5) instance()"; |
|
885 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
886 | - } else if ($reflector->isInstantiable()) { |
|
887 | - $instantiation_mode = "6) constructor"; |
|
888 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
889 | - } else { |
|
890 | - // heh ? something's not right ! |
|
891 | - throw new EE_Error( |
|
892 | - sprintf( |
|
893 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
894 | - $type, |
|
895 | - $class_name |
|
896 | - ) |
|
897 | - ); |
|
898 | - } |
|
899 | - } catch (Exception $e) { |
|
900 | - if ( ! $e instanceof EE_Error) { |
|
901 | - $e = new EE_Error( |
|
902 | - sprintf( |
|
903 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
904 | - $class_name, |
|
905 | - '<br />', |
|
906 | - $e->getMessage(), |
|
907 | - $instantiation_mode |
|
908 | - ) |
|
909 | - ); |
|
910 | - } |
|
911 | - $e->get_error(); |
|
912 | - } |
|
913 | - return $class_obj; |
|
914 | - } |
|
915 | - |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
920 | - * @param array $array |
|
921 | - * @return bool |
|
922 | - */ |
|
923 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
924 | - { |
|
925 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - |
|
930 | - /** |
|
931 | - * getReflectionClass |
|
932 | - * checks if a ReflectionClass object has already been generated for a class |
|
933 | - * and returns that instead of creating a new one |
|
934 | - * |
|
935 | - * @access public |
|
936 | - * @param string $class_name |
|
937 | - * @return ReflectionClass |
|
938 | - */ |
|
939 | - public function get_ReflectionClass($class_name) |
|
940 | - { |
|
941 | - if ( |
|
942 | - ! isset($this->_reflectors[$class_name]) |
|
943 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
944 | - ) { |
|
945 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
946 | - } |
|
947 | - return $this->_reflectors[$class_name]; |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - |
|
952 | - /** |
|
953 | - * _resolve_dependencies |
|
954 | - * examines the constructor for the requested class to determine |
|
955 | - * if any dependencies exist, and if they can be injected. |
|
956 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
957 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
958 | - * For example: |
|
959 | - * if attempting to load a class "Foo" with the following constructor: |
|
960 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
961 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
962 | - * but only IF they are NOT already present in the incoming arguments array, |
|
963 | - * and the correct classes can be loaded |
|
964 | - * |
|
965 | - * @access protected |
|
966 | - * @param ReflectionClass $reflector |
|
967 | - * @param string $class_name |
|
968 | - * @param array $arguments |
|
969 | - * @return array |
|
970 | - * @throws \ReflectionException |
|
971 | - */ |
|
972 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
973 | - { |
|
974 | - // let's examine the constructor |
|
975 | - $constructor = $reflector->getConstructor(); |
|
976 | - // whu? huh? nothing? |
|
977 | - if ( ! $constructor) { |
|
978 | - return $arguments; |
|
979 | - } |
|
980 | - // get constructor parameters |
|
981 | - $params = $constructor->getParameters(); |
|
982 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
983 | - $argument_keys = array_keys($arguments); |
|
984 | - // now loop thru all of the constructors expected parameters |
|
985 | - foreach ($params as $index => $param) { |
|
986 | - // is this a dependency for a specific class ? |
|
987 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
988 | - if ( |
|
989 | - // param is not even a class |
|
990 | - empty($param_class) |
|
991 | - // and something already exists in the incoming arguments for this param |
|
992 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
993 | - ) { |
|
994 | - // so let's skip this argument and move on to the next |
|
995 | - continue; |
|
996 | - } else if ( |
|
997 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
998 | - ! empty($param_class) |
|
999 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1000 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1001 | - ) { |
|
1002 | - // skip this argument and move on to the next |
|
1003 | - continue; |
|
1004 | - } else if ( |
|
1005 | - // parameter is type hinted as a class, and should be injected |
|
1006 | - ! empty($param_class) |
|
1007 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1008 | - ) { |
|
1009 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1010 | - } else { |
|
1011 | - try { |
|
1012 | - $arguments[$index] = $param->getDefaultValue(); |
|
1013 | - } catch (ReflectionException $e) { |
|
1014 | - throw new ReflectionException( |
|
1015 | - sprintf( |
|
1016 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1017 | - $e->getMessage(), |
|
1018 | - $param->getName() |
|
1019 | - ) |
|
1020 | - ); |
|
1021 | - } |
|
1022 | - } |
|
1023 | - } |
|
1024 | - return $arguments; |
|
1025 | - } |
|
1026 | - |
|
1027 | - |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * @access protected |
|
1031 | - * @param string $class_name |
|
1032 | - * @param string $param_class |
|
1033 | - * @param array $arguments |
|
1034 | - * @param mixed $index |
|
1035 | - * @return array |
|
1036 | - */ |
|
1037 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1038 | - { |
|
1039 | - $dependency = null; |
|
1040 | - // should dependency be loaded from cache ? |
|
1041 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1042 | - !== EE_Dependency_Map::load_new_object |
|
1043 | - ? true |
|
1044 | - : false; |
|
1045 | - // we might have a dependency... |
|
1046 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1047 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1048 | - // and grab it if it exists |
|
1049 | - if ($cached_class instanceof $param_class) { |
|
1050 | - $dependency = $cached_class; |
|
1051 | - } else if ($param_class != $class_name) { |
|
1052 | - // obtain the loader method from the dependency map |
|
1053 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1054 | - // is loader a custom closure ? |
|
1055 | - if ($loader instanceof Closure) { |
|
1056 | - $dependency = $loader(); |
|
1057 | - } else { |
|
1058 | - // set the cache on property for the recursive loading call |
|
1059 | - $this->_cache_on = $cache_on; |
|
1060 | - // if not, then let's try and load it via the registry |
|
1061 | - if (method_exists($this, $loader)) { |
|
1062 | - $dependency = $this->{$loader}($param_class); |
|
1063 | - } else { |
|
1064 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
1065 | - } |
|
1066 | - } |
|
1067 | - } |
|
1068 | - // did we successfully find the correct dependency ? |
|
1069 | - if ($dependency instanceof $param_class) { |
|
1070 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1071 | - if (isset($argument_keys[$index])) { |
|
1072 | - $arguments[$argument_keys[$index]] = $dependency; |
|
1073 | - } else { |
|
1074 | - $arguments[$index] = $dependency; |
|
1075 | - } |
|
1076 | - } |
|
1077 | - return $arguments; |
|
1078 | - } |
|
1079 | - |
|
1080 | - |
|
1081 | - |
|
1082 | - /** |
|
1083 | - * _set_cached_class |
|
1084 | - * attempts to cache the instantiated class locally |
|
1085 | - * in one of the following places, in the following order: |
|
1086 | - * $this->{class_abbreviation} ie: $this->CART |
|
1087 | - * $this->{$class_name} ie: $this->Some_Class |
|
1088 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1089 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1090 | - * |
|
1091 | - * @access protected |
|
1092 | - * @param object $class_obj |
|
1093 | - * @param string $class_name |
|
1094 | - * @param string $class_prefix |
|
1095 | - * @param bool $from_db |
|
1096 | - * @return void |
|
1097 | - */ |
|
1098 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1099 | - { |
|
1100 | - if (empty($class_obj)) { |
|
1101 | - return; |
|
1102 | - } |
|
1103 | - // return newly instantiated class |
|
1104 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
1105 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1106 | - $this->{$class_abbreviation} = $class_obj; |
|
1107 | - } else if (property_exists($this, $class_name)) { |
|
1108 | - $this->{$class_name} = $class_obj; |
|
1109 | - } else if ($class_prefix == 'addon') { |
|
1110 | - $this->addons->{$class_name} = $class_obj; |
|
1111 | - } else if ( ! $from_db) { |
|
1112 | - $this->LIB->{$class_name} = $class_obj; |
|
1113 | - } |
|
1114 | - } |
|
1115 | - |
|
1116 | - |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1120 | - * |
|
1121 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1122 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1123 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1124 | - * @param array $arguments |
|
1125 | - * @return object |
|
1126 | - */ |
|
1127 | - public static function factory($classname, $arguments = array()) |
|
1128 | - { |
|
1129 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1130 | - if ($loader instanceof Closure) { |
|
1131 | - return $loader($arguments); |
|
1132 | - } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1133 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1134 | - } |
|
1135 | - return null; |
|
1136 | - } |
|
1137 | - |
|
1138 | - |
|
1139 | - |
|
1140 | - /** |
|
1141 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1142 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
1143 | - * |
|
1144 | - * @param string $name |
|
1145 | - * @return EE_Addon |
|
1146 | - */ |
|
1147 | - public function get_addon_by_name($name) |
|
1148 | - { |
|
1149 | - foreach ($this->addons as $addon) { |
|
1150 | - if ($addon->name() == $name) { |
|
1151 | - return $addon; |
|
1152 | - } |
|
1153 | - } |
|
1154 | - return null; |
|
1155 | - } |
|
1156 | - |
|
1157 | - |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1161 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1162 | - * |
|
1163 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1164 | - */ |
|
1165 | - public function get_addons_by_name() |
|
1166 | - { |
|
1167 | - $addons = array(); |
|
1168 | - foreach ($this->addons as $addon) { |
|
1169 | - $addons[$addon->name()] = $addon; |
|
1170 | - } |
|
1171 | - return $addons; |
|
1172 | - } |
|
1173 | - |
|
1174 | - |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1178 | - * a stale copy of it around |
|
1179 | - * |
|
1180 | - * @param string $model_name |
|
1181 | - * @return \EEM_Base |
|
1182 | - * @throws \EE_Error |
|
1183 | - */ |
|
1184 | - public function reset_model($model_name) |
|
1185 | - { |
|
1186 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1187 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1188 | - return null; |
|
1189 | - } |
|
1190 | - //get that model reset it and make sure we nuke the old reference to it |
|
1191 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1192 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1193 | - } else { |
|
1194 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1195 | - } |
|
1196 | - return $this->LIB->{$model_class_name}; |
|
1197 | - } |
|
1198 | - |
|
1199 | - |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * Resets the registry. |
|
1203 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1204 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1205 | - * - $_dependency_map |
|
1206 | - * - $_class_abbreviations |
|
1207 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1208 | - * - $REQ: Still on the same request so no need to change. |
|
1209 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1210 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1211 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1212 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1213 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1214 | - * switch or on the restore. |
|
1215 | - * - $modules |
|
1216 | - * - $shortcodes |
|
1217 | - * - $widgets |
|
1218 | - * |
|
1219 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1220 | - * the Registry to its state at the beginning of the request |
|
1221 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1222 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1223 | - * currently reinstantiate the singletons at the moment) |
|
1224 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1225 | - * code instead can just change the model context to a different blog id if necessary |
|
1226 | - * @return EE_Registry |
|
1227 | - */ |
|
1228 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1229 | - { |
|
1230 | - $instance = self::instance(); |
|
1231 | - EEH_Activation::reset(); |
|
1232 | - //properties that get reset |
|
1233 | - $instance->_cache_on = true; |
|
1234 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1235 | - $instance->CART = null; |
|
1236 | - $instance->MRM = null; |
|
1237 | - $instance->AssetsRegistry = null; |
|
1238 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1239 | - //messages reset |
|
1240 | - EED_Messages::reset(); |
|
1241 | - if ($reset_models) { |
|
1242 | - foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1243 | - $instance->reset_model($model_name); |
|
1244 | - } |
|
1245 | - } |
|
1246 | - $instance->LIB = new stdClass(); |
|
1247 | - return $instance; |
|
1248 | - } |
|
1249 | - |
|
1250 | - |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * @override magic methods |
|
1254 | - * @return void |
|
1255 | - */ |
|
1256 | - public final function __destruct() |
|
1257 | - { |
|
1258 | - } |
|
1259 | - |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * @param $a |
|
1264 | - * @param $b |
|
1265 | - */ |
|
1266 | - public final function __call($a, $b) |
|
1267 | - { |
|
1268 | - } |
|
1269 | - |
|
1270 | - |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * @param $a |
|
1274 | - */ |
|
1275 | - public final function __get($a) |
|
1276 | - { |
|
1277 | - } |
|
1278 | - |
|
1279 | - |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * @param $a |
|
1283 | - * @param $b |
|
1284 | - */ |
|
1285 | - public final function __set($a, $b) |
|
1286 | - { |
|
1287 | - } |
|
1288 | - |
|
1289 | - |
|
1290 | - |
|
1291 | - /** |
|
1292 | - * @param $a |
|
1293 | - */ |
|
1294 | - public final function __isset($a) |
|
1295 | - { |
|
1296 | - } |
|
19 | + /** |
|
20 | + * EE_Registry Object |
|
21 | + * |
|
22 | + * @var EE_Registry $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var EE_Dependency_Map $_dependency_map |
|
29 | + * @access protected |
|
30 | + */ |
|
31 | + protected $_dependency_map = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array $_class_abbreviations |
|
35 | + * @access protected |
|
36 | + */ |
|
37 | + protected $_class_abbreviations = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @access public |
|
41 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | + */ |
|
43 | + public $BUS; |
|
44 | + |
|
45 | + /** |
|
46 | + * EE_Cart Object |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Cart $CART |
|
50 | + */ |
|
51 | + public $CART = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * EE_Config Object |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @var EE_Config $CFG |
|
58 | + */ |
|
59 | + public $CFG = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * EE_Network_Config Object |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @var EE_Network_Config $NET_CFG |
|
66 | + */ |
|
67 | + public $NET_CFG = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * StdClass object for storing library classes in |
|
71 | + * |
|
72 | + * @public LIB |
|
73 | + * @var StdClass $LIB |
|
74 | + */ |
|
75 | + public $LIB = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * EE_Request_Handler Object |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @var EE_Request_Handler $REQ |
|
82 | + */ |
|
83 | + public $REQ = null; |
|
84 | + |
|
85 | + /** |
|
86 | + * EE_Session Object |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @var EE_Session $SSN |
|
90 | + */ |
|
91 | + public $SSN = null; |
|
92 | + |
|
93 | + /** |
|
94 | + * holds the ee capabilities object. |
|
95 | + * |
|
96 | + * @since 4.5.0 |
|
97 | + * @var EE_Capabilities |
|
98 | + */ |
|
99 | + public $CAP = null; |
|
100 | + |
|
101 | + /** |
|
102 | + * holds the EE_Message_Resource_Manager object. |
|
103 | + * |
|
104 | + * @since 4.9.0 |
|
105 | + * @var EE_Message_Resource_Manager |
|
106 | + */ |
|
107 | + public $MRM = null; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Holds the Assets Registry instance |
|
112 | + * @var Registry |
|
113 | + */ |
|
114 | + public $AssetsRegistry = null; |
|
115 | + |
|
116 | + /** |
|
117 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Addon[] |
|
121 | + */ |
|
122 | + public $addons = null; |
|
123 | + |
|
124 | + /** |
|
125 | + * $models |
|
126 | + * @access public |
|
127 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | + */ |
|
129 | + public $models = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * $modules |
|
133 | + * @access public |
|
134 | + * @var EED_Module[] $modules |
|
135 | + */ |
|
136 | + public $modules = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * $shortcodes |
|
140 | + * @access public |
|
141 | + * @var EES_Shortcode[] $shortcodes |
|
142 | + */ |
|
143 | + public $shortcodes = null; |
|
144 | + |
|
145 | + /** |
|
146 | + * $widgets |
|
147 | + * @access public |
|
148 | + * @var WP_Widget[] $widgets |
|
149 | + */ |
|
150 | + public $widgets = null; |
|
151 | + |
|
152 | + /** |
|
153 | + * $non_abstract_db_models |
|
154 | + * @access public |
|
155 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | + * classnames (eg "EEM_Event") |
|
159 | + */ |
|
160 | + public $non_abstract_db_models = array(); |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * $i18n_js_strings - internationalization for JS strings |
|
165 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | + * in js file: var translatedString = eei18n.string_key; |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @var array |
|
170 | + */ |
|
171 | + public static $i18n_js_strings = array(); |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * $main_file - path to espresso.php |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @var array |
|
179 | + */ |
|
180 | + public $main_file; |
|
181 | + |
|
182 | + /** |
|
183 | + * array of ReflectionClass objects where the key is the class name |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @var ReflectionClass[] |
|
187 | + */ |
|
188 | + public $_reflectors; |
|
189 | + |
|
190 | + /** |
|
191 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | + * |
|
193 | + * @access protected |
|
194 | + * @var boolean $_cache_on |
|
195 | + */ |
|
196 | + protected $_cache_on = true; |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @singleton method used to instantiate class object |
|
202 | + * @access public |
|
203 | + * @param \EE_Dependency_Map $dependency_map |
|
204 | + * @return \EE_Registry instance |
|
205 | + */ |
|
206 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | + { |
|
208 | + // check if class object is instantiated |
|
209 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | + self::$_instance = new EE_Registry($dependency_map); |
|
211 | + } |
|
212 | + return self::$_instance; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + *protected constructor to prevent direct creation |
|
219 | + * |
|
220 | + * @Constructor |
|
221 | + * @access protected |
|
222 | + * @param \EE_Dependency_Map $dependency_map |
|
223 | + * @return \EE_Registry |
|
224 | + */ |
|
225 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | + { |
|
227 | + $this->_dependency_map = $dependency_map; |
|
228 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * initialize |
|
235 | + */ |
|
236 | + public function initialize() |
|
237 | + { |
|
238 | + $this->_class_abbreviations = apply_filters( |
|
239 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | + array( |
|
241 | + 'EE_Config' => 'CFG', |
|
242 | + 'EE_Session' => 'SSN', |
|
243 | + 'EE_Capabilities' => 'CAP', |
|
244 | + 'EE_Cart' => 'CART', |
|
245 | + 'EE_Network_Config' => 'NET_CFG', |
|
246 | + 'EE_Request_Handler' => 'REQ', |
|
247 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
250 | + ) |
|
251 | + ); |
|
252 | + // class library |
|
253 | + $this->LIB = new stdClass(); |
|
254 | + $this->addons = new stdClass(); |
|
255 | + $this->modules = new stdClass(); |
|
256 | + $this->shortcodes = new stdClass(); |
|
257 | + $this->widgets = new stdClass(); |
|
258 | + $this->load_core('Base', array(), true); |
|
259 | + // add our request and response objects to the cache |
|
260 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
261 | + $this->_set_cached_class( |
|
262 | + $request_loader(), |
|
263 | + 'EE_Request' |
|
264 | + ); |
|
265 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
266 | + $this->_set_cached_class( |
|
267 | + $response_loader(), |
|
268 | + 'EE_Response' |
|
269 | + ); |
|
270 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * init |
|
277 | + * |
|
278 | + * @access public |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + public function init() |
|
282 | + { |
|
283 | + // Get current page protocol |
|
284 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | + // Output admin-ajax.php URL with same protocol as current page |
|
286 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * localize_i18n_js_strings |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public static function localize_i18n_js_strings() |
|
298 | + { |
|
299 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | + foreach ($i18n_js_strings as $key => $value) { |
|
301 | + if (is_scalar($value)) { |
|
302 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | + } |
|
304 | + } |
|
305 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param mixed string | EED_Module $module |
|
312 | + */ |
|
313 | + public function add_module($module) |
|
314 | + { |
|
315 | + if ($module instanceof EED_Module) { |
|
316 | + $module_class = get_class($module); |
|
317 | + $this->modules->{$module_class} = $module; |
|
318 | + } else { |
|
319 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | + $this->load_core('Module_Request_Router'); |
|
321 | + } |
|
322 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @param string $module_name |
|
330 | + * @return mixed EED_Module | NULL |
|
331 | + */ |
|
332 | + public function get_module($module_name = '') |
|
333 | + { |
|
334 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * loads core classes - must be singletons |
|
341 | + * |
|
342 | + * @access public |
|
343 | + * @param string $class_name - simple class name ie: session |
|
344 | + * @param mixed $arguments |
|
345 | + * @param bool $load_only |
|
346 | + * @return mixed |
|
347 | + */ |
|
348 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | + { |
|
350 | + $core_paths = apply_filters( |
|
351 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | + array( |
|
353 | + EE_CORE, |
|
354 | + EE_ADMIN, |
|
355 | + EE_CPTS, |
|
356 | + EE_CORE . 'data_migration_scripts' . DS, |
|
357 | + EE_CORE . 'request_stack' . DS, |
|
358 | + EE_CORE . 'middleware' . DS, |
|
359 | + ) |
|
360 | + ); |
|
361 | + // retrieve instantiated class |
|
362 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * loads service classes |
|
369 | + * |
|
370 | + * @access public |
|
371 | + * @param string $class_name - simple class name ie: session |
|
372 | + * @param mixed $arguments |
|
373 | + * @param bool $load_only |
|
374 | + * @return mixed |
|
375 | + */ |
|
376 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | + { |
|
378 | + $service_paths = apply_filters( |
|
379 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | + array( |
|
381 | + EE_CORE . 'services' . DS, |
|
382 | + ) |
|
383 | + ); |
|
384 | + // retrieve instantiated class |
|
385 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * loads data_migration_scripts |
|
392 | + * |
|
393 | + * @access public |
|
394 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | + * @param mixed $arguments |
|
396 | + * @return EE_Data_Migration_Script_Base|mixed |
|
397 | + */ |
|
398 | + public function load_dms($class_name, $arguments = array()) |
|
399 | + { |
|
400 | + // retrieve instantiated class |
|
401 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * loads object creating classes - must be singletons |
|
408 | + * |
|
409 | + * @param string $class_name - simple class name ie: attendee |
|
410 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
413 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | + * @return EE_Base_Class | bool |
|
415 | + */ |
|
416 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | + { |
|
418 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | + EE_CORE, |
|
420 | + EE_CLASSES, |
|
421 | + EE_BUSINESS, |
|
422 | + )); |
|
423 | + // retrieve instantiated class |
|
424 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * loads helper classes - must be singletons |
|
431 | + * |
|
432 | + * @param string $class_name - simple class name ie: price |
|
433 | + * @param mixed $arguments |
|
434 | + * @param bool $load_only |
|
435 | + * @return EEH_Base | bool |
|
436 | + */ |
|
437 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | + { |
|
439 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | + // retrieve instantiated class |
|
442 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * loads core classes - must be singletons |
|
449 | + * |
|
450 | + * @access public |
|
451 | + * @param string $class_name - simple class name ie: session |
|
452 | + * @param mixed $arguments |
|
453 | + * @param bool $load_only |
|
454 | + * @param bool $cache whether to cache the object or not. |
|
455 | + * @return mixed |
|
456 | + */ |
|
457 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | + { |
|
459 | + $paths = array( |
|
460 | + EE_LIBRARIES, |
|
461 | + EE_LIBRARIES . 'messages' . DS, |
|
462 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | + EE_LIBRARIES . 'qtips' . DS, |
|
464 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | + ); |
|
466 | + // retrieve instantiated class |
|
467 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * loads model classes - must be singletons |
|
474 | + * |
|
475 | + * @param string $class_name - simple class name ie: price |
|
476 | + * @param mixed $arguments |
|
477 | + * @param bool $load_only |
|
478 | + * @return EEM_Base | bool |
|
479 | + */ |
|
480 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | + { |
|
482 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | + EE_MODELS, |
|
484 | + EE_CORE, |
|
485 | + )); |
|
486 | + // retrieve instantiated class |
|
487 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * loads model classes - must be singletons |
|
494 | + * |
|
495 | + * @param string $class_name - simple class name ie: price |
|
496 | + * @param mixed $arguments |
|
497 | + * @param bool $load_only |
|
498 | + * @return mixed | bool |
|
499 | + */ |
|
500 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | + { |
|
502 | + $paths = array( |
|
503 | + EE_MODELS . 'fields' . DS, |
|
504 | + EE_MODELS . 'helpers' . DS, |
|
505 | + EE_MODELS . 'relations' . DS, |
|
506 | + EE_MODELS . 'strategies' . DS, |
|
507 | + ); |
|
508 | + // retrieve instantiated class |
|
509 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Determines if $model_name is the name of an actual EE model. |
|
516 | + * |
|
517 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | + * @return boolean |
|
519 | + */ |
|
520 | + public function is_model_name($model_name) |
|
521 | + { |
|
522 | + return isset($this->models[$model_name]) ? true : false; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * generic class loader |
|
529 | + * |
|
530 | + * @param string $path_to_file - directory path to file location, not including filename |
|
531 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
532 | + * @param string $type - file type - core? class? helper? model? |
|
533 | + * @param mixed $arguments |
|
534 | + * @param bool $load_only |
|
535 | + * @return mixed |
|
536 | + */ |
|
537 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
538 | + { |
|
539 | + // retrieve instantiated class |
|
540 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * load_addon |
|
547 | + * |
|
548 | + * @param string $path_to_file - directory path to file location, not including filename |
|
549 | + * @param string $class_name - full class name ie: My_Class |
|
550 | + * @param string $type - file type - core? class? helper? model? |
|
551 | + * @param mixed $arguments |
|
552 | + * @param bool $load_only |
|
553 | + * @return EE_Addon |
|
554 | + */ |
|
555 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
556 | + { |
|
557 | + // retrieve instantiated class |
|
558 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * instantiates, caches, and automatically resolves dependencies |
|
565 | + * for classes that use a Fully Qualified Class Name. |
|
566 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
567 | + * then you need to use one of the existing load_*() methods |
|
568 | + * which can resolve the classname and filepath from the passed arguments |
|
569 | + * |
|
570 | + * @param bool|string $class_name Fully Qualified Class Name |
|
571 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
572 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
573 | + * @param bool $from_db some classes are instantiated from the db |
|
574 | + * and thus call a different method to instantiate |
|
575 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
576 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
577 | + * @return mixed null = failure to load or instantiate class object. |
|
578 | + * object = class loaded and instantiated successfully. |
|
579 | + * bool = fail or success when $load_only is true |
|
580 | + */ |
|
581 | + public function create( |
|
582 | + $class_name = false, |
|
583 | + $arguments = array(), |
|
584 | + $cache = false, |
|
585 | + $from_db = false, |
|
586 | + $load_only = false, |
|
587 | + $addon = false |
|
588 | + ) { |
|
589 | + $class_name = ltrim($class_name, '\\'); |
|
590 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
591 | + if ( ! class_exists($class_name)) { |
|
592 | + // maybe the class is registered with a preceding \ |
|
593 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
594 | + // still doesn't exist ? |
|
595 | + if ( ! class_exists($class_name)) { |
|
596 | + return null; |
|
597 | + } |
|
598 | + } |
|
599 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
600 | + if ($load_only) { |
|
601 | + return true; |
|
602 | + } |
|
603 | + $addon = $addon ? 'addon' : ''; |
|
604 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
605 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
606 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
607 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
608 | + // return object if it's already cached |
|
609 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
610 | + if ($cached_class !== null) { |
|
611 | + return $cached_class; |
|
612 | + } |
|
613 | + } |
|
614 | + // instantiate the requested object |
|
615 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
616 | + if ($this->_cache_on && $cache) { |
|
617 | + // save it for later... kinda like gum { : $ |
|
618 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
619 | + } |
|
620 | + $this->_cache_on = true; |
|
621 | + return $class_obj; |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * instantiates, caches, and injects dependencies for classes |
|
628 | + * |
|
629 | + * @param array $file_paths an array of paths to folders to look in |
|
630 | + * @param string $class_prefix EE or EEM or... ??? |
|
631 | + * @param bool|string $class_name $class name |
|
632 | + * @param string $type file type - core? class? helper? model? |
|
633 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
634 | + * @param bool $from_db some classes are instantiated from the db |
|
635 | + * and thus call a different method to instantiate |
|
636 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
637 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
638 | + * @return null|object|bool null = failure to load or instantiate class object. |
|
639 | + * object = class loaded and instantiated successfully. |
|
640 | + * bool = fail or success when $load_only is true |
|
641 | + */ |
|
642 | + protected function _load( |
|
643 | + $file_paths = array(), |
|
644 | + $class_prefix = 'EE_', |
|
645 | + $class_name = false, |
|
646 | + $type = 'class', |
|
647 | + $arguments = array(), |
|
648 | + $from_db = false, |
|
649 | + $cache = true, |
|
650 | + $load_only = false |
|
651 | + ) { |
|
652 | + $class_name = ltrim($class_name, '\\'); |
|
653 | + // strip php file extension |
|
654 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
655 | + // does the class have a prefix ? |
|
656 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
657 | + // make sure $class_prefix is uppercase |
|
658 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
659 | + // add class prefix ONCE!!! |
|
660 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
661 | + } |
|
662 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
663 | + $class_exists = class_exists($class_name); |
|
664 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
665 | + if ($load_only && $class_exists) { |
|
666 | + return true; |
|
667 | + } |
|
668 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
669 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
670 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
671 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
672 | + // return object if it's already cached |
|
673 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
674 | + if ($cached_class !== null) { |
|
675 | + return $cached_class; |
|
676 | + } |
|
677 | + } |
|
678 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
679 | + if ( ! $class_exists) { |
|
680 | + // get full path to file |
|
681 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
682 | + // load the file |
|
683 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
684 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
685 | + if ( ! $loaded || $load_only) { |
|
686 | + // return boolean if only loading, or null if an object was expected |
|
687 | + return $load_only ? $loaded : null; |
|
688 | + } |
|
689 | + } |
|
690 | + // instantiate the requested object |
|
691 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
692 | + if ($this->_cache_on && $cache) { |
|
693 | + // save it for later... kinda like gum { : $ |
|
694 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
695 | + } |
|
696 | + $this->_cache_on = true; |
|
697 | + return $class_obj; |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * _get_cached_class |
|
704 | + * attempts to find a cached version of the requested class |
|
705 | + * by looking in the following places: |
|
706 | + * $this->{$class_abbreviation} ie: $this->CART |
|
707 | + * $this->{$class_name} ie: $this->Some_Class |
|
708 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
709 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
710 | + * |
|
711 | + * @access protected |
|
712 | + * @param string $class_name |
|
713 | + * @param string $class_prefix |
|
714 | + * @return mixed |
|
715 | + */ |
|
716 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
717 | + { |
|
718 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
719 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
720 | + } else { |
|
721 | + // have to specify something, but not anything that will conflict |
|
722 | + $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
723 | + } |
|
724 | + // check if class has already been loaded, and return it if it has been |
|
725 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
726 | + return $this->{$class_abbreviation}; |
|
727 | + } else if (isset ($this->{$class_name})) { |
|
728 | + return $this->{$class_name}; |
|
729 | + } else if (isset ($this->LIB->{$class_name})) { |
|
730 | + return $this->LIB->{$class_name}; |
|
731 | + } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
732 | + return $this->addons->{$class_name}; |
|
733 | + } |
|
734 | + return null; |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * _resolve_path |
|
741 | + * attempts to find a full valid filepath for the requested class. |
|
742 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
743 | + * then returns that path if the target file has been found and is readable |
|
744 | + * |
|
745 | + * @access protected |
|
746 | + * @param string $class_name |
|
747 | + * @param string $type |
|
748 | + * @param array $file_paths |
|
749 | + * @return string | bool |
|
750 | + */ |
|
751 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
752 | + { |
|
753 | + // make sure $file_paths is an array |
|
754 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
755 | + // cycle thru paths |
|
756 | + foreach ($file_paths as $key => $file_path) { |
|
757 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
758 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
759 | + // prep file type |
|
760 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
761 | + // build full file path |
|
762 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
763 | + //does the file exist and can be read ? |
|
764 | + if (is_readable($file_paths[$key])) { |
|
765 | + return $file_paths[$key]; |
|
766 | + } |
|
767 | + } |
|
768 | + return false; |
|
769 | + } |
|
770 | + |
|
771 | + |
|
772 | + |
|
773 | + /** |
|
774 | + * _require_file |
|
775 | + * basically just performs a require_once() |
|
776 | + * but with some error handling |
|
777 | + * |
|
778 | + * @access protected |
|
779 | + * @param string $path |
|
780 | + * @param string $class_name |
|
781 | + * @param string $type |
|
782 | + * @param array $file_paths |
|
783 | + * @return boolean |
|
784 | + * @throws \EE_Error |
|
785 | + */ |
|
786 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
787 | + { |
|
788 | + // don't give up! you gotta... |
|
789 | + try { |
|
790 | + //does the file exist and can it be read ? |
|
791 | + if ( ! $path) { |
|
792 | + // so sorry, can't find the file |
|
793 | + throw new EE_Error ( |
|
794 | + sprintf( |
|
795 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
796 | + trim($type, '.'), |
|
797 | + $class_name, |
|
798 | + '<br />' . implode(',<br />', $file_paths) |
|
799 | + ) |
|
800 | + ); |
|
801 | + } |
|
802 | + // get the file |
|
803 | + require_once($path); |
|
804 | + // if the class isn't already declared somewhere |
|
805 | + if (class_exists($class_name, false) === false) { |
|
806 | + // so sorry, not a class |
|
807 | + throw new EE_Error( |
|
808 | + sprintf( |
|
809 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
810 | + $type, |
|
811 | + $path, |
|
812 | + $class_name |
|
813 | + ) |
|
814 | + ); |
|
815 | + } |
|
816 | + } catch (EE_Error $e) { |
|
817 | + $e->get_error(); |
|
818 | + return false; |
|
819 | + } |
|
820 | + return true; |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * _create_object |
|
827 | + * Attempts to instantiate the requested class via any of the |
|
828 | + * commonly used instantiation methods employed throughout EE. |
|
829 | + * The priority for instantiation is as follows: |
|
830 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
831 | + * - model objects via their 'new_instance_from_db' method |
|
832 | + * - model objects via their 'new_instance' method |
|
833 | + * - "singleton" classes" via their 'instance' method |
|
834 | + * - standard instantiable classes via their __constructor |
|
835 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
836 | + * then the constructor for the requested class will be examined to determine |
|
837 | + * if any dependencies exist, and if they can be injected. |
|
838 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
839 | + * |
|
840 | + * @access protected |
|
841 | + * @param string $class_name |
|
842 | + * @param array $arguments |
|
843 | + * @param string $type |
|
844 | + * @param bool $from_db |
|
845 | + * @return null | object |
|
846 | + * @throws \EE_Error |
|
847 | + */ |
|
848 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
849 | + { |
|
850 | + $class_obj = null; |
|
851 | + $instantiation_mode = '0) none'; |
|
852 | + // don't give up! you gotta... |
|
853 | + try { |
|
854 | + // create reflection |
|
855 | + $reflector = $this->get_ReflectionClass($class_name); |
|
856 | + // make sure arguments are an array |
|
857 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
858 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
859 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
860 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
861 | + ? $arguments |
|
862 | + : array($arguments); |
|
863 | + // attempt to inject dependencies ? |
|
864 | + if ($this->_dependency_map->has($class_name)) { |
|
865 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
866 | + } |
|
867 | + // instantiate the class if possible |
|
868 | + if ($reflector->isAbstract()) { |
|
869 | + // nothing to instantiate, loading file was enough |
|
870 | + // does not throw an exception so $instantiation_mode is unused |
|
871 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
872 | + $class_obj = true; |
|
873 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
874 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
875 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
876 | + $class_obj = $reflector->newInstance(); |
|
877 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
878 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
879 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
880 | + } else if (method_exists($class_name, 'new_instance')) { |
|
881 | + $instantiation_mode = "4) new_instance()"; |
|
882 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
883 | + } else if (method_exists($class_name, 'instance')) { |
|
884 | + $instantiation_mode = "5) instance()"; |
|
885 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
886 | + } else if ($reflector->isInstantiable()) { |
|
887 | + $instantiation_mode = "6) constructor"; |
|
888 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
889 | + } else { |
|
890 | + // heh ? something's not right ! |
|
891 | + throw new EE_Error( |
|
892 | + sprintf( |
|
893 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
894 | + $type, |
|
895 | + $class_name |
|
896 | + ) |
|
897 | + ); |
|
898 | + } |
|
899 | + } catch (Exception $e) { |
|
900 | + if ( ! $e instanceof EE_Error) { |
|
901 | + $e = new EE_Error( |
|
902 | + sprintf( |
|
903 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
904 | + $class_name, |
|
905 | + '<br />', |
|
906 | + $e->getMessage(), |
|
907 | + $instantiation_mode |
|
908 | + ) |
|
909 | + ); |
|
910 | + } |
|
911 | + $e->get_error(); |
|
912 | + } |
|
913 | + return $class_obj; |
|
914 | + } |
|
915 | + |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
920 | + * @param array $array |
|
921 | + * @return bool |
|
922 | + */ |
|
923 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
924 | + { |
|
925 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + |
|
930 | + /** |
|
931 | + * getReflectionClass |
|
932 | + * checks if a ReflectionClass object has already been generated for a class |
|
933 | + * and returns that instead of creating a new one |
|
934 | + * |
|
935 | + * @access public |
|
936 | + * @param string $class_name |
|
937 | + * @return ReflectionClass |
|
938 | + */ |
|
939 | + public function get_ReflectionClass($class_name) |
|
940 | + { |
|
941 | + if ( |
|
942 | + ! isset($this->_reflectors[$class_name]) |
|
943 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
944 | + ) { |
|
945 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
946 | + } |
|
947 | + return $this->_reflectors[$class_name]; |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + |
|
952 | + /** |
|
953 | + * _resolve_dependencies |
|
954 | + * examines the constructor for the requested class to determine |
|
955 | + * if any dependencies exist, and if they can be injected. |
|
956 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
957 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
958 | + * For example: |
|
959 | + * if attempting to load a class "Foo" with the following constructor: |
|
960 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
961 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
962 | + * but only IF they are NOT already present in the incoming arguments array, |
|
963 | + * and the correct classes can be loaded |
|
964 | + * |
|
965 | + * @access protected |
|
966 | + * @param ReflectionClass $reflector |
|
967 | + * @param string $class_name |
|
968 | + * @param array $arguments |
|
969 | + * @return array |
|
970 | + * @throws \ReflectionException |
|
971 | + */ |
|
972 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
973 | + { |
|
974 | + // let's examine the constructor |
|
975 | + $constructor = $reflector->getConstructor(); |
|
976 | + // whu? huh? nothing? |
|
977 | + if ( ! $constructor) { |
|
978 | + return $arguments; |
|
979 | + } |
|
980 | + // get constructor parameters |
|
981 | + $params = $constructor->getParameters(); |
|
982 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
983 | + $argument_keys = array_keys($arguments); |
|
984 | + // now loop thru all of the constructors expected parameters |
|
985 | + foreach ($params as $index => $param) { |
|
986 | + // is this a dependency for a specific class ? |
|
987 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
988 | + if ( |
|
989 | + // param is not even a class |
|
990 | + empty($param_class) |
|
991 | + // and something already exists in the incoming arguments for this param |
|
992 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
993 | + ) { |
|
994 | + // so let's skip this argument and move on to the next |
|
995 | + continue; |
|
996 | + } else if ( |
|
997 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
998 | + ! empty($param_class) |
|
999 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1000 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1001 | + ) { |
|
1002 | + // skip this argument and move on to the next |
|
1003 | + continue; |
|
1004 | + } else if ( |
|
1005 | + // parameter is type hinted as a class, and should be injected |
|
1006 | + ! empty($param_class) |
|
1007 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1008 | + ) { |
|
1009 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1010 | + } else { |
|
1011 | + try { |
|
1012 | + $arguments[$index] = $param->getDefaultValue(); |
|
1013 | + } catch (ReflectionException $e) { |
|
1014 | + throw new ReflectionException( |
|
1015 | + sprintf( |
|
1016 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1017 | + $e->getMessage(), |
|
1018 | + $param->getName() |
|
1019 | + ) |
|
1020 | + ); |
|
1021 | + } |
|
1022 | + } |
|
1023 | + } |
|
1024 | + return $arguments; |
|
1025 | + } |
|
1026 | + |
|
1027 | + |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * @access protected |
|
1031 | + * @param string $class_name |
|
1032 | + * @param string $param_class |
|
1033 | + * @param array $arguments |
|
1034 | + * @param mixed $index |
|
1035 | + * @return array |
|
1036 | + */ |
|
1037 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1038 | + { |
|
1039 | + $dependency = null; |
|
1040 | + // should dependency be loaded from cache ? |
|
1041 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1042 | + !== EE_Dependency_Map::load_new_object |
|
1043 | + ? true |
|
1044 | + : false; |
|
1045 | + // we might have a dependency... |
|
1046 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1047 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1048 | + // and grab it if it exists |
|
1049 | + if ($cached_class instanceof $param_class) { |
|
1050 | + $dependency = $cached_class; |
|
1051 | + } else if ($param_class != $class_name) { |
|
1052 | + // obtain the loader method from the dependency map |
|
1053 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1054 | + // is loader a custom closure ? |
|
1055 | + if ($loader instanceof Closure) { |
|
1056 | + $dependency = $loader(); |
|
1057 | + } else { |
|
1058 | + // set the cache on property for the recursive loading call |
|
1059 | + $this->_cache_on = $cache_on; |
|
1060 | + // if not, then let's try and load it via the registry |
|
1061 | + if (method_exists($this, $loader)) { |
|
1062 | + $dependency = $this->{$loader}($param_class); |
|
1063 | + } else { |
|
1064 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
1065 | + } |
|
1066 | + } |
|
1067 | + } |
|
1068 | + // did we successfully find the correct dependency ? |
|
1069 | + if ($dependency instanceof $param_class) { |
|
1070 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1071 | + if (isset($argument_keys[$index])) { |
|
1072 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1073 | + } else { |
|
1074 | + $arguments[$index] = $dependency; |
|
1075 | + } |
|
1076 | + } |
|
1077 | + return $arguments; |
|
1078 | + } |
|
1079 | + |
|
1080 | + |
|
1081 | + |
|
1082 | + /** |
|
1083 | + * _set_cached_class |
|
1084 | + * attempts to cache the instantiated class locally |
|
1085 | + * in one of the following places, in the following order: |
|
1086 | + * $this->{class_abbreviation} ie: $this->CART |
|
1087 | + * $this->{$class_name} ie: $this->Some_Class |
|
1088 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1089 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1090 | + * |
|
1091 | + * @access protected |
|
1092 | + * @param object $class_obj |
|
1093 | + * @param string $class_name |
|
1094 | + * @param string $class_prefix |
|
1095 | + * @param bool $from_db |
|
1096 | + * @return void |
|
1097 | + */ |
|
1098 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1099 | + { |
|
1100 | + if (empty($class_obj)) { |
|
1101 | + return; |
|
1102 | + } |
|
1103 | + // return newly instantiated class |
|
1104 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1105 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1106 | + $this->{$class_abbreviation} = $class_obj; |
|
1107 | + } else if (property_exists($this, $class_name)) { |
|
1108 | + $this->{$class_name} = $class_obj; |
|
1109 | + } else if ($class_prefix == 'addon') { |
|
1110 | + $this->addons->{$class_name} = $class_obj; |
|
1111 | + } else if ( ! $from_db) { |
|
1112 | + $this->LIB->{$class_name} = $class_obj; |
|
1113 | + } |
|
1114 | + } |
|
1115 | + |
|
1116 | + |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1120 | + * |
|
1121 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1122 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1123 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1124 | + * @param array $arguments |
|
1125 | + * @return object |
|
1126 | + */ |
|
1127 | + public static function factory($classname, $arguments = array()) |
|
1128 | + { |
|
1129 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1130 | + if ($loader instanceof Closure) { |
|
1131 | + return $loader($arguments); |
|
1132 | + } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1133 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1134 | + } |
|
1135 | + return null; |
|
1136 | + } |
|
1137 | + |
|
1138 | + |
|
1139 | + |
|
1140 | + /** |
|
1141 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1142 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
1143 | + * |
|
1144 | + * @param string $name |
|
1145 | + * @return EE_Addon |
|
1146 | + */ |
|
1147 | + public function get_addon_by_name($name) |
|
1148 | + { |
|
1149 | + foreach ($this->addons as $addon) { |
|
1150 | + if ($addon->name() == $name) { |
|
1151 | + return $addon; |
|
1152 | + } |
|
1153 | + } |
|
1154 | + return null; |
|
1155 | + } |
|
1156 | + |
|
1157 | + |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1161 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1162 | + * |
|
1163 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1164 | + */ |
|
1165 | + public function get_addons_by_name() |
|
1166 | + { |
|
1167 | + $addons = array(); |
|
1168 | + foreach ($this->addons as $addon) { |
|
1169 | + $addons[$addon->name()] = $addon; |
|
1170 | + } |
|
1171 | + return $addons; |
|
1172 | + } |
|
1173 | + |
|
1174 | + |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1178 | + * a stale copy of it around |
|
1179 | + * |
|
1180 | + * @param string $model_name |
|
1181 | + * @return \EEM_Base |
|
1182 | + * @throws \EE_Error |
|
1183 | + */ |
|
1184 | + public function reset_model($model_name) |
|
1185 | + { |
|
1186 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1187 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1188 | + return null; |
|
1189 | + } |
|
1190 | + //get that model reset it and make sure we nuke the old reference to it |
|
1191 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1192 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1193 | + } else { |
|
1194 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1195 | + } |
|
1196 | + return $this->LIB->{$model_class_name}; |
|
1197 | + } |
|
1198 | + |
|
1199 | + |
|
1200 | + |
|
1201 | + /** |
|
1202 | + * Resets the registry. |
|
1203 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1204 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1205 | + * - $_dependency_map |
|
1206 | + * - $_class_abbreviations |
|
1207 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1208 | + * - $REQ: Still on the same request so no need to change. |
|
1209 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1210 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1211 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1212 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1213 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1214 | + * switch or on the restore. |
|
1215 | + * - $modules |
|
1216 | + * - $shortcodes |
|
1217 | + * - $widgets |
|
1218 | + * |
|
1219 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1220 | + * the Registry to its state at the beginning of the request |
|
1221 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1222 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1223 | + * currently reinstantiate the singletons at the moment) |
|
1224 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1225 | + * code instead can just change the model context to a different blog id if necessary |
|
1226 | + * @return EE_Registry |
|
1227 | + */ |
|
1228 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1229 | + { |
|
1230 | + $instance = self::instance(); |
|
1231 | + EEH_Activation::reset(); |
|
1232 | + //properties that get reset |
|
1233 | + $instance->_cache_on = true; |
|
1234 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1235 | + $instance->CART = null; |
|
1236 | + $instance->MRM = null; |
|
1237 | + $instance->AssetsRegistry = null; |
|
1238 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1239 | + //messages reset |
|
1240 | + EED_Messages::reset(); |
|
1241 | + if ($reset_models) { |
|
1242 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1243 | + $instance->reset_model($model_name); |
|
1244 | + } |
|
1245 | + } |
|
1246 | + $instance->LIB = new stdClass(); |
|
1247 | + return $instance; |
|
1248 | + } |
|
1249 | + |
|
1250 | + |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * @override magic methods |
|
1254 | + * @return void |
|
1255 | + */ |
|
1256 | + public final function __destruct() |
|
1257 | + { |
|
1258 | + } |
|
1259 | + |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * @param $a |
|
1264 | + * @param $b |
|
1265 | + */ |
|
1266 | + public final function __call($a, $b) |
|
1267 | + { |
|
1268 | + } |
|
1269 | + |
|
1270 | + |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * @param $a |
|
1274 | + */ |
|
1275 | + public final function __get($a) |
|
1276 | + { |
|
1277 | + } |
|
1278 | + |
|
1279 | + |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * @param $a |
|
1283 | + * @param $b |
|
1284 | + */ |
|
1285 | + public final function __set($a, $b) |
|
1286 | + { |
|
1287 | + } |
|
1288 | + |
|
1289 | + |
|
1290 | + |
|
1291 | + /** |
|
1292 | + * @param $a |
|
1293 | + */ |
|
1294 | + public final function __isset($a) |
|
1295 | + { |
|
1296 | + } |
|
1297 | 1297 | |
1298 | 1298 | |
1299 | 1299 | |
1300 | - /** |
|
1301 | - * @param $a |
|
1302 | - */ |
|
1303 | - public final function __unset($a) |
|
1304 | - { |
|
1305 | - } |
|
1300 | + /** |
|
1301 | + * @param $a |
|
1302 | + */ |
|
1303 | + public final function __unset($a) |
|
1304 | + { |
|
1305 | + } |
|
1306 | 1306 | |
1307 | 1307 | |
1308 | 1308 | |
1309 | - /** |
|
1310 | - * @return array |
|
1311 | - */ |
|
1312 | - public final function __sleep() |
|
1313 | - { |
|
1314 | - return array(); |
|
1315 | - } |
|
1309 | + /** |
|
1310 | + * @return array |
|
1311 | + */ |
|
1312 | + public final function __sleep() |
|
1313 | + { |
|
1314 | + return array(); |
|
1315 | + } |
|
1316 | 1316 | |
1317 | 1317 | |
1318 | 1318 | |
1319 | - public final function __wakeup() |
|
1320 | - { |
|
1321 | - } |
|
1319 | + public final function __wakeup() |
|
1320 | + { |
|
1321 | + } |
|
1322 | 1322 | |
1323 | 1323 | |
1324 | 1324 | |
1325 | - /** |
|
1326 | - * @return string |
|
1327 | - */ |
|
1328 | - public final function __toString() |
|
1329 | - { |
|
1330 | - return ''; |
|
1331 | - } |
|
1325 | + /** |
|
1326 | + * @return string |
|
1327 | + */ |
|
1328 | + public final function __toString() |
|
1329 | + { |
|
1330 | + return ''; |
|
1331 | + } |
|
1332 | 1332 | |
1333 | 1333 | |
1334 | 1334 | |
1335 | - public final function __invoke() |
|
1336 | - { |
|
1337 | - } |
|
1335 | + public final function __invoke() |
|
1336 | + { |
|
1337 | + } |
|
1338 | 1338 | |
1339 | 1339 | |
1340 | 1340 | |
1341 | - public final static function __set_state($array = array()) |
|
1342 | - { |
|
1343 | - return EE_Registry::instance(); |
|
1344 | - } |
|
1341 | + public final static function __set_state($array = array()) |
|
1342 | + { |
|
1343 | + return EE_Registry::instance(); |
|
1344 | + } |
|
1345 | 1345 | |
1346 | 1346 | |
1347 | 1347 | |
1348 | - public final function __clone() |
|
1349 | - { |
|
1350 | - } |
|
1348 | + public final function __clone() |
|
1349 | + { |
|
1350 | + } |
|
1351 | 1351 | |
1352 | 1352 | |
1353 | 1353 | |
1354 | - /** |
|
1355 | - * @param $a |
|
1356 | - * @param $b |
|
1357 | - */ |
|
1358 | - public final static function __callStatic($a, $b) |
|
1359 | - { |
|
1360 | - } |
|
1354 | + /** |
|
1355 | + * @param $a |
|
1356 | + * @param $b |
|
1357 | + */ |
|
1358 | + public final static function __callStatic($a, $b) |
|
1359 | + { |
|
1360 | + } |
|
1361 | 1361 | |
1362 | 1362 | |
1363 | 1363 | |
1364 | - /** |
|
1365 | - * Gets all the custom post type models defined |
|
1366 | - * |
|
1367 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1368 | - */ |
|
1369 | - public function cpt_models() |
|
1370 | - { |
|
1371 | - $cpt_models = array(); |
|
1372 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1373 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1374 | - $cpt_models[$short_name] = $classname; |
|
1375 | - } |
|
1376 | - } |
|
1377 | - return $cpt_models; |
|
1378 | - } |
|
1364 | + /** |
|
1365 | + * Gets all the custom post type models defined |
|
1366 | + * |
|
1367 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1368 | + */ |
|
1369 | + public function cpt_models() |
|
1370 | + { |
|
1371 | + $cpt_models = array(); |
|
1372 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1373 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1374 | + $cpt_models[$short_name] = $classname; |
|
1375 | + } |
|
1376 | + } |
|
1377 | + return $cpt_models; |
|
1378 | + } |
|
1379 | 1379 | |
1380 | 1380 | |
1381 | 1381 | |
1382 | - /** |
|
1383 | - * @return \EE_Config |
|
1384 | - */ |
|
1385 | - public static function CFG() |
|
1386 | - { |
|
1387 | - return self::instance()->CFG; |
|
1388 | - } |
|
1382 | + /** |
|
1383 | + * @return \EE_Config |
|
1384 | + */ |
|
1385 | + public static function CFG() |
|
1386 | + { |
|
1387 | + return self::instance()->CFG; |
|
1388 | + } |
|
1389 | 1389 | |
1390 | 1390 | |
1391 | 1391 | } |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | |
376 | 376 | |
377 | 377 | /** |
378 | - * @param mixed $var |
|
378 | + * @param string $var |
|
379 | 379 | * @param string $var_name |
380 | 380 | * @param string $file |
381 | 381 | * @param int $line |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | |
571 | 571 | /** |
572 | 572 | * @deprecated 4.9.39.rc.034 |
573 | - * @param null $timer_name |
|
573 | + * @param string $timer_name |
|
574 | 574 | */ |
575 | 575 | public function start_timer($timer_name = null) |
576 | 576 | { |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -17,626 +17,626 @@ discard block |
||
17 | 17 | class EEH_Debug_Tools |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EEH_Autoloader object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $_memory_usage_points = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EEH_Debug_Tools |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - return self::$_instance; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * private class constructor |
|
53 | - */ |
|
54 | - private function __construct() |
|
55 | - { |
|
56 | - // load Kint PHP debugging library |
|
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | - } |
|
65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | - // } |
|
68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * show_db_name |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public static function show_db_name() |
|
82 | - { |
|
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | - . DB_NAME |
|
86 | - . '</p>'; |
|
87 | - } |
|
88 | - if (EE_DEBUG) { |
|
89 | - Benchmark::displayResults(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
97 | - * |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public function espresso_session_footer_dump() |
|
101 | - { |
|
102 | - if ( |
|
103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | - && ! defined('DOING_AJAX') |
|
105 | - && class_exists('Kint') |
|
106 | - && function_exists('wp_get_current_user') |
|
107 | - && current_user_can('update_core') |
|
108 | - && class_exists('EE_Registry') |
|
109 | - ) { |
|
110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | - $this->espresso_list_hooked_functions(); |
|
114 | - Benchmark::displayResults(); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * List All Hooked Functions |
|
122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | - * |
|
125 | - * @param string $tag |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - public function espresso_list_hooked_functions($tag = '') |
|
129 | - { |
|
130 | - global $wp_filter; |
|
131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | - if ($tag) { |
|
133 | - $hook[$tag] = $wp_filter[$tag]; |
|
134 | - if (! is_array($hook[$tag])) { |
|
135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | - return; |
|
137 | - } |
|
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | - } else { |
|
140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | - ksort($hook); |
|
142 | - } |
|
143 | - foreach ($hook as $tag_name => $priorities) { |
|
144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | - ksort($priorities); |
|
146 | - foreach ($priorities as $priority => $function) { |
|
147 | - echo $priority; |
|
148 | - foreach ($function as $name => $properties) { |
|
149 | - echo "\t$name<br />"; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * registered_filter_callbacks |
|
159 | - * |
|
160 | - * @param string $hook_name |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public static function registered_filter_callbacks($hook_name = '') |
|
164 | - { |
|
165 | - $filters = array(); |
|
166 | - global $wp_filter; |
|
167 | - if (isset($wp_filter[$hook_name])) { |
|
168 | - $filters[$hook_name] = array(); |
|
169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | - $filters[$hook_name][$priority] = array(); |
|
171 | - foreach ($callbacks as $callback) { |
|
172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - return $filters; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * captures plugin activation errors for debugging |
|
183 | - * |
|
184 | - * @return void |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public static function ee_plugin_activation_errors() |
|
188 | - { |
|
189 | - if (WP_DEBUG) { |
|
190 | - $activation_errors = ob_get_contents(); |
|
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | - } |
|
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | - if (class_exists('EEH_File')) { |
|
196 | - try { |
|
197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | - ); |
|
200 | - EEH_File::write_to_file( |
|
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | - $activation_errors |
|
203 | - ); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - EE_Error::add_error( |
|
206 | - sprintf( |
|
207 | - __( |
|
208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | - 'event_espresso' |
|
210 | - ), |
|
211 | - $e->getMessage() |
|
212 | - ), |
|
213 | - __FILE__, __FUNCTION__, __LINE__ |
|
214 | - ); |
|
215 | - } |
|
216 | - } else { |
|
217 | - // old school attempt |
|
218 | - file_put_contents( |
|
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | - $activation_errors |
|
221 | - ); |
|
222 | - } |
|
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | - * or we want to make sure they use something the right way. |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @param string $function The function that was called |
|
237 | - * @param string $message A message explaining what has been done incorrectly |
|
238 | - * @param string $version The version of Event Espresso where the error was added |
|
239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | - * but not have any notices appear until a later version. This allows developers |
|
242 | - * extra time to update their code before notices appear. |
|
243 | - * @param int $error_type |
|
244 | - * @uses trigger_error() |
|
245 | - */ |
|
246 | - public function doing_it_wrong( |
|
247 | - $function, |
|
248 | - $message, |
|
249 | - $version, |
|
250 | - $applies_when = '', |
|
251 | - $error_type = null |
|
252 | - ) { |
|
253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | - // because we swapped the parameter order around for the last two params, |
|
256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | - if (is_int($applies_when)) { |
|
258 | - $error_type = $applies_when; |
|
259 | - $applies_when = espresso_version(); |
|
260 | - } |
|
261 | - // if not displaying notices yet, then just leave |
|
262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | - return; |
|
264 | - } |
|
265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | - $version = $version === null |
|
267 | - ? '' |
|
268 | - : sprintf( |
|
269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | - $version |
|
271 | - ); |
|
272 | - $error_message = sprintf( |
|
273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | - $function, |
|
275 | - '<strong>', |
|
276 | - '</strong>', |
|
277 | - $message, |
|
278 | - $version |
|
279 | - ); |
|
280 | - // don't trigger error if doing ajax, |
|
281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | - $error_message .= ' ' . esc_html__( |
|
284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | - 'event_espresso' |
|
286 | - ); |
|
287 | - $error_message .= '<ul><li>'; |
|
288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | - $error_message .= '</ul>'; |
|
290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | - //now we set this on the transient so it shows up on the next request. |
|
292 | - EE_Error::get_notices(false, true); |
|
293 | - } else { |
|
294 | - trigger_error($error_message, $error_type); |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Logger helpers |
|
303 | - */ |
|
304 | - /** |
|
305 | - * debug |
|
306 | - * |
|
307 | - * @param string $class |
|
308 | - * @param string $func |
|
309 | - * @param string $line |
|
310 | - * @param array $info |
|
311 | - * @param bool $display_request |
|
312 | - * @param string $debug_index |
|
313 | - * @param string $debug_key |
|
314 | - * @throws EE_Error |
|
315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | - */ |
|
317 | - public static function log( |
|
318 | - $class = '', |
|
319 | - $func = '', |
|
320 | - $line = '', |
|
321 | - $info = array(), |
|
322 | - $display_request = false, |
|
323 | - $debug_index = '', |
|
324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
325 | - ) { |
|
326 | - if (WP_DEBUG) { |
|
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | - $debug_data = get_option($debug_key, array()); |
|
329 | - $default_data = array( |
|
330 | - $class => $func . '() : ' . $line, |
|
331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | - ); |
|
333 | - // don't serialize objects |
|
334 | - $info = self::strip_objects($info); |
|
335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | - if (! isset($debug_data[$index])) { |
|
337 | - $debug_data[$index] = array(); |
|
338 | - } |
|
339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | - update_option($debug_key, $debug_data); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * strip_objects |
|
348 | - * |
|
349 | - * @param array $info |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public static function strip_objects($info = array()) |
|
353 | - { |
|
354 | - foreach ($info as $key => $value) { |
|
355 | - if (is_array($value)) { |
|
356 | - $info[$key] = self::strip_objects($value); |
|
357 | - } else if (is_object($value)) { |
|
358 | - $object_class = get_class($value); |
|
359 | - $info[$object_class] = array(); |
|
360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | - if (method_exists($value, 'ID')) { |
|
362 | - $info[$object_class]['ID'] = $value->ID(); |
|
363 | - } |
|
364 | - if (method_exists($value, 'status')) { |
|
365 | - $info[$object_class]['status'] = $value->status(); |
|
366 | - } else if (method_exists($value, 'status_ID')) { |
|
367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
368 | - } |
|
369 | - unset($info[$key]); |
|
370 | - } |
|
371 | - } |
|
372 | - return (array)$info; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $var |
|
379 | - * @param string $var_name |
|
380 | - * @param string $file |
|
381 | - * @param int $line |
|
382 | - * @param int $heading_tag |
|
383 | - * @param bool $die |
|
384 | - * @param string $margin |
|
385 | - */ |
|
386 | - public static function printv( |
|
387 | - $var, |
|
388 | - $var_name = '', |
|
389 | - $file = __FILE__, |
|
390 | - $line = __LINE__, |
|
391 | - $heading_tag = 5, |
|
392 | - $die = false, |
|
393 | - $margin = '' |
|
394 | - ) { |
|
395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | - $is_method = method_exists($var_name, $var); |
|
398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
400 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
401 | - $result .= $is_method |
|
402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
404 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
405 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
406 | - if ($die) { |
|
407 | - die($result); |
|
408 | - } |
|
409 | - echo $result; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @param string $var_name |
|
416 | - * @param string $heading_tag |
|
417 | - * @param string $margin |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
421 | - { |
|
422 | - if (defined('EE_TESTS_DIR')) { |
|
423 | - return "\n\n{$var_name}"; |
|
424 | - } |
|
425 | - $margin = "25px 0 0 {$margin}"; |
|
426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @param string $heading_tag |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - protected static function headingX($heading_tag = 'h5') |
|
436 | - { |
|
437 | - if (defined('EE_TESTS_DIR')) { |
|
438 | - return "\n"; |
|
439 | - } |
|
440 | - return '</' . $heading_tag . '>'; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * @param string $content |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - protected static function grey_span($content = '') |
|
450 | - { |
|
451 | - if (defined('EE_TESTS_DIR')) { |
|
452 | - return $content; |
|
453 | - } |
|
454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * @param string $file |
|
461 | - * @param int $line |
|
462 | - * @return string |
|
463 | - */ |
|
464 | - protected static function file_and_line($file, $line) |
|
465 | - { |
|
466 | - if (defined('EE_TESTS_DIR')) { |
|
467 | - return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
468 | - } |
|
469 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
470 | - . $file |
|
471 | - . '<br />line no: ' |
|
472 | - . $line |
|
473 | - . '</span>'; |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * @param string $content |
|
480 | - * @return string |
|
481 | - */ |
|
482 | - protected static function orange_span($content = '') |
|
483 | - { |
|
484 | - if (defined('EE_TESTS_DIR')) { |
|
485 | - return $content; |
|
486 | - } |
|
487 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * @param mixed $var |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - protected static function pre_span($var) |
|
497 | - { |
|
498 | - ob_start(); |
|
499 | - var_dump($var); |
|
500 | - $var = ob_get_clean(); |
|
501 | - if (defined('EE_TESTS_DIR')) { |
|
502 | - return "\n" . $var; |
|
503 | - } |
|
504 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * @param mixed $var |
|
511 | - * @param string $var_name |
|
512 | - * @param string $file |
|
513 | - * @param int $line |
|
514 | - * @param int $heading_tag |
|
515 | - * @param bool $die |
|
516 | - */ |
|
517 | - public static function printr( |
|
518 | - $var, |
|
519 | - $var_name = '', |
|
520 | - $file = __FILE__, |
|
521 | - $line = __LINE__, |
|
522 | - $heading_tag = 5, |
|
523 | - $die = false |
|
524 | - ) { |
|
525 | - // return; |
|
526 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
527 | - $margin = is_admin() ? ' 180px' : '0'; |
|
528 | - //$print_r = false; |
|
529 | - if (is_string($var)) { |
|
530 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
531 | - return; |
|
532 | - } |
|
533 | - if (is_object($var)) { |
|
534 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
535 | - //$print_r = true; |
|
536 | - } else if (is_array($var)) { |
|
537 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
538 | - //$print_r = true; |
|
539 | - } else if (is_numeric($var)) { |
|
540 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
541 | - } else if ($var === null) { |
|
542 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
543 | - } |
|
544 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
545 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
546 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
547 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
548 | - EEH_Debug_Tools::pre_span($var) |
|
549 | - ); |
|
550 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
551 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
552 | - if ($die) { |
|
553 | - die($result); |
|
554 | - } |
|
555 | - echo $result; |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - |
|
560 | - /******************** deprecated ********************/ |
|
561 | - /** |
|
562 | - * @deprecated 4.9.39.rc.034 |
|
563 | - */ |
|
564 | - public function reset_times() |
|
565 | - { |
|
566 | - Benchmark::resetTimes(); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * @deprecated 4.9.39.rc.034 |
|
573 | - * @param null $timer_name |
|
574 | - */ |
|
575 | - public function start_timer($timer_name = null) |
|
576 | - { |
|
577 | - Benchmark::startTimer($timer_name); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * @deprecated 4.9.39.rc.034 |
|
584 | - * @param string $timer_name |
|
585 | - */ |
|
586 | - public function stop_timer($timer_name = '') |
|
587 | - { |
|
588 | - Benchmark::stopTimer($timer_name); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * @deprecated 4.9.39.rc.034 |
|
595 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
596 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
597 | - * @return void |
|
598 | - */ |
|
599 | - public function measure_memory($label, $output_now = false) |
|
600 | - { |
|
601 | - Benchmark::measureMemory($label, $output_now); |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * @deprecated 4.9.39.rc.034 |
|
608 | - * @param int $size |
|
609 | - * @return string |
|
610 | - */ |
|
611 | - public function convert($size) |
|
612 | - { |
|
613 | - return Benchmark::convert($size); |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * @deprecated 4.9.39.rc.034 |
|
620 | - * @param bool $output_now |
|
621 | - * @return string |
|
622 | - */ |
|
623 | - public function show_times($output_now = true) |
|
624 | - { |
|
625 | - return Benchmark::displayResults($output_now); |
|
626 | - } |
|
627 | - |
|
628 | - |
|
629 | - |
|
630 | - /** |
|
631 | - * @deprecated 4.9.39.rc.034 |
|
632 | - * @param string $timer_name |
|
633 | - * @param float $total_time |
|
634 | - * @return string |
|
635 | - */ |
|
636 | - public function format_time($timer_name, $total_time) |
|
637 | - { |
|
638 | - return Benchmark::formatTime($timer_name, $total_time); |
|
639 | - } |
|
20 | + /** |
|
21 | + * instance of the EEH_Autoloader object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $_memory_usage_points = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EEH_Debug_Tools |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + return self::$_instance; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * private class constructor |
|
53 | + */ |
|
54 | + private function __construct() |
|
55 | + { |
|
56 | + // load Kint PHP debugging library |
|
57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | + } |
|
65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | + // } |
|
68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * show_db_name |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public static function show_db_name() |
|
82 | + { |
|
83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | + . DB_NAME |
|
86 | + . '</p>'; |
|
87 | + } |
|
88 | + if (EE_DEBUG) { |
|
89 | + Benchmark::displayResults(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
97 | + * |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public function espresso_session_footer_dump() |
|
101 | + { |
|
102 | + if ( |
|
103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | + && ! defined('DOING_AJAX') |
|
105 | + && class_exists('Kint') |
|
106 | + && function_exists('wp_get_current_user') |
|
107 | + && current_user_can('update_core') |
|
108 | + && class_exists('EE_Registry') |
|
109 | + ) { |
|
110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | + $this->espresso_list_hooked_functions(); |
|
114 | + Benchmark::displayResults(); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * List All Hooked Functions |
|
122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | + * |
|
125 | + * @param string $tag |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + public function espresso_list_hooked_functions($tag = '') |
|
129 | + { |
|
130 | + global $wp_filter; |
|
131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | + if ($tag) { |
|
133 | + $hook[$tag] = $wp_filter[$tag]; |
|
134 | + if (! is_array($hook[$tag])) { |
|
135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | + return; |
|
137 | + } |
|
138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | + } else { |
|
140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | + ksort($hook); |
|
142 | + } |
|
143 | + foreach ($hook as $tag_name => $priorities) { |
|
144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | + ksort($priorities); |
|
146 | + foreach ($priorities as $priority => $function) { |
|
147 | + echo $priority; |
|
148 | + foreach ($function as $name => $properties) { |
|
149 | + echo "\t$name<br />"; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * registered_filter_callbacks |
|
159 | + * |
|
160 | + * @param string $hook_name |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public static function registered_filter_callbacks($hook_name = '') |
|
164 | + { |
|
165 | + $filters = array(); |
|
166 | + global $wp_filter; |
|
167 | + if (isset($wp_filter[$hook_name])) { |
|
168 | + $filters[$hook_name] = array(); |
|
169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | + $filters[$hook_name][$priority] = array(); |
|
171 | + foreach ($callbacks as $callback) { |
|
172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + return $filters; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * captures plugin activation errors for debugging |
|
183 | + * |
|
184 | + * @return void |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public static function ee_plugin_activation_errors() |
|
188 | + { |
|
189 | + if (WP_DEBUG) { |
|
190 | + $activation_errors = ob_get_contents(); |
|
191 | + if (! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | + } |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | + if (class_exists('EEH_File')) { |
|
196 | + try { |
|
197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | + ); |
|
200 | + EEH_File::write_to_file( |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | + $activation_errors |
|
203 | + ); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + EE_Error::add_error( |
|
206 | + sprintf( |
|
207 | + __( |
|
208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | + 'event_espresso' |
|
210 | + ), |
|
211 | + $e->getMessage() |
|
212 | + ), |
|
213 | + __FILE__, __FUNCTION__, __LINE__ |
|
214 | + ); |
|
215 | + } |
|
216 | + } else { |
|
217 | + // old school attempt |
|
218 | + file_put_contents( |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | + $activation_errors |
|
221 | + ); |
|
222 | + } |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | + * or we want to make sure they use something the right way. |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @param string $function The function that was called |
|
237 | + * @param string $message A message explaining what has been done incorrectly |
|
238 | + * @param string $version The version of Event Espresso where the error was added |
|
239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | + * but not have any notices appear until a later version. This allows developers |
|
242 | + * extra time to update their code before notices appear. |
|
243 | + * @param int $error_type |
|
244 | + * @uses trigger_error() |
|
245 | + */ |
|
246 | + public function doing_it_wrong( |
|
247 | + $function, |
|
248 | + $message, |
|
249 | + $version, |
|
250 | + $applies_when = '', |
|
251 | + $error_type = null |
|
252 | + ) { |
|
253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | + // because we swapped the parameter order around for the last two params, |
|
256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | + if (is_int($applies_when)) { |
|
258 | + $error_type = $applies_when; |
|
259 | + $applies_when = espresso_version(); |
|
260 | + } |
|
261 | + // if not displaying notices yet, then just leave |
|
262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | + return; |
|
264 | + } |
|
265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | + $version = $version === null |
|
267 | + ? '' |
|
268 | + : sprintf( |
|
269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | + $version |
|
271 | + ); |
|
272 | + $error_message = sprintf( |
|
273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | + $function, |
|
275 | + '<strong>', |
|
276 | + '</strong>', |
|
277 | + $message, |
|
278 | + $version |
|
279 | + ); |
|
280 | + // don't trigger error if doing ajax, |
|
281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | + $error_message .= ' ' . esc_html__( |
|
284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | + 'event_espresso' |
|
286 | + ); |
|
287 | + $error_message .= '<ul><li>'; |
|
288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | + $error_message .= '</ul>'; |
|
290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | + //now we set this on the transient so it shows up on the next request. |
|
292 | + EE_Error::get_notices(false, true); |
|
293 | + } else { |
|
294 | + trigger_error($error_message, $error_type); |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Logger helpers |
|
303 | + */ |
|
304 | + /** |
|
305 | + * debug |
|
306 | + * |
|
307 | + * @param string $class |
|
308 | + * @param string $func |
|
309 | + * @param string $line |
|
310 | + * @param array $info |
|
311 | + * @param bool $display_request |
|
312 | + * @param string $debug_index |
|
313 | + * @param string $debug_key |
|
314 | + * @throws EE_Error |
|
315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | + */ |
|
317 | + public static function log( |
|
318 | + $class = '', |
|
319 | + $func = '', |
|
320 | + $line = '', |
|
321 | + $info = array(), |
|
322 | + $display_request = false, |
|
323 | + $debug_index = '', |
|
324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
325 | + ) { |
|
326 | + if (WP_DEBUG) { |
|
327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | + $debug_data = get_option($debug_key, array()); |
|
329 | + $default_data = array( |
|
330 | + $class => $func . '() : ' . $line, |
|
331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | + ); |
|
333 | + // don't serialize objects |
|
334 | + $info = self::strip_objects($info); |
|
335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | + if (! isset($debug_data[$index])) { |
|
337 | + $debug_data[$index] = array(); |
|
338 | + } |
|
339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | + update_option($debug_key, $debug_data); |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * strip_objects |
|
348 | + * |
|
349 | + * @param array $info |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public static function strip_objects($info = array()) |
|
353 | + { |
|
354 | + foreach ($info as $key => $value) { |
|
355 | + if (is_array($value)) { |
|
356 | + $info[$key] = self::strip_objects($value); |
|
357 | + } else if (is_object($value)) { |
|
358 | + $object_class = get_class($value); |
|
359 | + $info[$object_class] = array(); |
|
360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | + if (method_exists($value, 'ID')) { |
|
362 | + $info[$object_class]['ID'] = $value->ID(); |
|
363 | + } |
|
364 | + if (method_exists($value, 'status')) { |
|
365 | + $info[$object_class]['status'] = $value->status(); |
|
366 | + } else if (method_exists($value, 'status_ID')) { |
|
367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
368 | + } |
|
369 | + unset($info[$key]); |
|
370 | + } |
|
371 | + } |
|
372 | + return (array)$info; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $var |
|
379 | + * @param string $var_name |
|
380 | + * @param string $file |
|
381 | + * @param int $line |
|
382 | + * @param int $heading_tag |
|
383 | + * @param bool $die |
|
384 | + * @param string $margin |
|
385 | + */ |
|
386 | + public static function printv( |
|
387 | + $var, |
|
388 | + $var_name = '', |
|
389 | + $file = __FILE__, |
|
390 | + $line = __LINE__, |
|
391 | + $heading_tag = 5, |
|
392 | + $die = false, |
|
393 | + $margin = '' |
|
394 | + ) { |
|
395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | + $is_method = method_exists($var_name, $var); |
|
398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
400 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
401 | + $result .= $is_method |
|
402 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
404 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
405 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
406 | + if ($die) { |
|
407 | + die($result); |
|
408 | + } |
|
409 | + echo $result; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @param string $var_name |
|
416 | + * @param string $heading_tag |
|
417 | + * @param string $margin |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
421 | + { |
|
422 | + if (defined('EE_TESTS_DIR')) { |
|
423 | + return "\n\n{$var_name}"; |
|
424 | + } |
|
425 | + $margin = "25px 0 0 {$margin}"; |
|
426 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @param string $heading_tag |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + protected static function headingX($heading_tag = 'h5') |
|
436 | + { |
|
437 | + if (defined('EE_TESTS_DIR')) { |
|
438 | + return "\n"; |
|
439 | + } |
|
440 | + return '</' . $heading_tag . '>'; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * @param string $content |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + protected static function grey_span($content = '') |
|
450 | + { |
|
451 | + if (defined('EE_TESTS_DIR')) { |
|
452 | + return $content; |
|
453 | + } |
|
454 | + return '<span style="color:#999">' . $content . '</span>'; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * @param string $file |
|
461 | + * @param int $line |
|
462 | + * @return string |
|
463 | + */ |
|
464 | + protected static function file_and_line($file, $line) |
|
465 | + { |
|
466 | + if (defined('EE_TESTS_DIR')) { |
|
467 | + return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
468 | + } |
|
469 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
470 | + . $file |
|
471 | + . '<br />line no: ' |
|
472 | + . $line |
|
473 | + . '</span>'; |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * @param string $content |
|
480 | + * @return string |
|
481 | + */ |
|
482 | + protected static function orange_span($content = '') |
|
483 | + { |
|
484 | + if (defined('EE_TESTS_DIR')) { |
|
485 | + return $content; |
|
486 | + } |
|
487 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * @param mixed $var |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + protected static function pre_span($var) |
|
497 | + { |
|
498 | + ob_start(); |
|
499 | + var_dump($var); |
|
500 | + $var = ob_get_clean(); |
|
501 | + if (defined('EE_TESTS_DIR')) { |
|
502 | + return "\n" . $var; |
|
503 | + } |
|
504 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * @param mixed $var |
|
511 | + * @param string $var_name |
|
512 | + * @param string $file |
|
513 | + * @param int $line |
|
514 | + * @param int $heading_tag |
|
515 | + * @param bool $die |
|
516 | + */ |
|
517 | + public static function printr( |
|
518 | + $var, |
|
519 | + $var_name = '', |
|
520 | + $file = __FILE__, |
|
521 | + $line = __LINE__, |
|
522 | + $heading_tag = 5, |
|
523 | + $die = false |
|
524 | + ) { |
|
525 | + // return; |
|
526 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
527 | + $margin = is_admin() ? ' 180px' : '0'; |
|
528 | + //$print_r = false; |
|
529 | + if (is_string($var)) { |
|
530 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
531 | + return; |
|
532 | + } |
|
533 | + if (is_object($var)) { |
|
534 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
535 | + //$print_r = true; |
|
536 | + } else if (is_array($var)) { |
|
537 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
538 | + //$print_r = true; |
|
539 | + } else if (is_numeric($var)) { |
|
540 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
541 | + } else if ($var === null) { |
|
542 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
543 | + } |
|
544 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
545 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
546 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
547 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
548 | + EEH_Debug_Tools::pre_span($var) |
|
549 | + ); |
|
550 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
551 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
552 | + if ($die) { |
|
553 | + die($result); |
|
554 | + } |
|
555 | + echo $result; |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + |
|
560 | + /******************** deprecated ********************/ |
|
561 | + /** |
|
562 | + * @deprecated 4.9.39.rc.034 |
|
563 | + */ |
|
564 | + public function reset_times() |
|
565 | + { |
|
566 | + Benchmark::resetTimes(); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * @deprecated 4.9.39.rc.034 |
|
573 | + * @param null $timer_name |
|
574 | + */ |
|
575 | + public function start_timer($timer_name = null) |
|
576 | + { |
|
577 | + Benchmark::startTimer($timer_name); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * @deprecated 4.9.39.rc.034 |
|
584 | + * @param string $timer_name |
|
585 | + */ |
|
586 | + public function stop_timer($timer_name = '') |
|
587 | + { |
|
588 | + Benchmark::stopTimer($timer_name); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * @deprecated 4.9.39.rc.034 |
|
595 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
596 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
597 | + * @return void |
|
598 | + */ |
|
599 | + public function measure_memory($label, $output_now = false) |
|
600 | + { |
|
601 | + Benchmark::measureMemory($label, $output_now); |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * @deprecated 4.9.39.rc.034 |
|
608 | + * @param int $size |
|
609 | + * @return string |
|
610 | + */ |
|
611 | + public function convert($size) |
|
612 | + { |
|
613 | + return Benchmark::convert($size); |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * @deprecated 4.9.39.rc.034 |
|
620 | + * @param bool $output_now |
|
621 | + * @return string |
|
622 | + */ |
|
623 | + public function show_times($output_now = true) |
|
624 | + { |
|
625 | + return Benchmark::displayResults($output_now); |
|
626 | + } |
|
627 | + |
|
628 | + |
|
629 | + |
|
630 | + /** |
|
631 | + * @deprecated 4.9.39.rc.034 |
|
632 | + * @param string $timer_name |
|
633 | + * @param float $total_time |
|
634 | + * @return string |
|
635 | + */ |
|
636 | + public function format_time($timer_name, $total_time) |
|
637 | + { |
|
638 | + return Benchmark::formatTime($timer_name, $total_time); |
|
639 | + } |
|
640 | 640 | |
641 | 641 | |
642 | 642 | |
@@ -649,31 +649,31 @@ discard block |
||
649 | 649 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
650 | 650 | */ |
651 | 651 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
652 | - function dump_wp_query() |
|
653 | - { |
|
654 | - global $wp_query; |
|
655 | - d($wp_query); |
|
656 | - } |
|
652 | + function dump_wp_query() |
|
653 | + { |
|
654 | + global $wp_query; |
|
655 | + d($wp_query); |
|
656 | + } |
|
657 | 657 | } |
658 | 658 | /** |
659 | 659 | * borrowed from Kint Debugger |
660 | 660 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
661 | 661 | */ |
662 | 662 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
663 | - function dump_wp() |
|
664 | - { |
|
665 | - global $wp; |
|
666 | - d($wp); |
|
667 | - } |
|
663 | + function dump_wp() |
|
664 | + { |
|
665 | + global $wp; |
|
666 | + d($wp); |
|
667 | + } |
|
668 | 668 | } |
669 | 669 | /** |
670 | 670 | * borrowed from Kint Debugger |
671 | 671 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
672 | 672 | */ |
673 | 673 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
674 | - function dump_post() |
|
675 | - { |
|
676 | - global $post; |
|
677 | - d($post); |
|
678 | - } |
|
674 | + function dump_post() |
|
675 | + { |
|
676 | + global $post; |
|
677 | + d($post); |
|
678 | + } |
|
679 | 679 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public static function instance() |
41 | 41 | { |
42 | 42 | // check if class object is instantiated, and instantiated properly |
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | 44 | self::$_instance = new self(); |
45 | 45 | } |
46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | private function __construct() |
55 | 55 | { |
56 | 56 | // load Kint PHP debugging library |
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
64 | 64 | } |
65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function show_db_name() |
82 | 82 | { |
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
85 | 85 | . DB_NAME |
86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
132 | 132 | if ($tag) { |
133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
134 | - if (! is_array($hook[$tag])) { |
|
134 | + if ( ! is_array($hook[$tag])) { |
|
135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
136 | 136 | return; |
137 | 137 | } |
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
139 | 139 | } else { |
140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | { |
189 | 189 | if (WP_DEBUG) { |
190 | 190 | $activation_errors = ob_get_contents(); |
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
191 | + if ( ! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
193 | 193 | } |
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
195 | 195 | if (class_exists('EEH_File')) { |
196 | 196 | try { |
197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
199 | 199 | ); |
200 | 200 | EEH_File::write_to_file( |
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
202 | 202 | $activation_errors |
203 | 203 | ); |
204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | } else { |
217 | 217 | // old school attempt |
218 | 218 | file_put_contents( |
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
220 | 220 | $activation_errors |
221 | 221 | ); |
222 | 222 | } |
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
225 | 225 | } |
226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | // don't trigger error if doing ajax, |
281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
283 | - $error_message .= ' ' . esc_html__( |
|
283 | + $error_message .= ' '.esc_html__( |
|
284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
285 | 285 | 'event_espresso' |
286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
325 | 325 | ) { |
326 | 326 | if (WP_DEBUG) { |
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
328 | 328 | $debug_data = get_option($debug_key, array()); |
329 | 329 | $default_data = array( |
330 | - $class => $func . '() : ' . $line, |
|
330 | + $class => $func.'() : '.$line, |
|
331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
332 | 332 | ); |
333 | 333 | // don't serialize objects |
334 | 334 | $info = self::strip_objects($info); |
335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
336 | - if (! isset($debug_data[$index])) { |
|
336 | + if ( ! isset($debug_data[$index])) { |
|
337 | 337 | $debug_data[$index] = array(); |
338 | 338 | } |
339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | unset($info[$key]); |
370 | 370 | } |
371 | 371 | } |
372 | - return (array)$info; |
|
372 | + return (array) $info; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
400 | 400 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
401 | 401 | $result .= $is_method |
402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
402 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
403 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
404 | 404 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
405 | 405 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
406 | 406 | if ($die) { |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | return "\n\n{$var_name}"; |
424 | 424 | } |
425 | 425 | $margin = "25px 0 0 {$margin}"; |
426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
426 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | if (defined('EE_TESTS_DIR')) { |
438 | 438 | return "\n"; |
439 | 439 | } |
440 | - return '</' . $heading_tag . '>'; |
|
440 | + return '</'.$heading_tag.'>'; |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | if (defined('EE_TESTS_DIR')) { |
452 | 452 | return $content; |
453 | 453 | } |
454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
454 | + return '<span style="color:#999">'.$content.'</span>'; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | protected static function file_and_line($file, $line) |
465 | 465 | { |
466 | 466 | if (defined('EE_TESTS_DIR')) { |
467 | - return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
467 | + return "\n (".$file.' line no: '.$line.' ) '; |
|
468 | 468 | } |
469 | 469 | return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
470 | 470 | . $file |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | if (defined('EE_TESTS_DIR')) { |
485 | 485 | return $content; |
486 | 486 | } |
487 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
487 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | |
@@ -499,9 +499,9 @@ discard block |
||
499 | 499 | var_dump($var); |
500 | 500 | $var = ob_get_clean(); |
501 | 501 | if (defined('EE_TESTS_DIR')) { |
502 | - return "\n" . $var; |
|
502 | + return "\n".$var; |
|
503 | 503 | } |
504 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
504 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
545 | 545 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
546 | 546 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
547 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
547 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
548 | 548 | EEH_Debug_Tools::pre_span($var) |
549 | 549 | ); |
550 | 550 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | { |
123 | 123 | add_action( |
124 | 124 | 'shutdown', |
125 | - function () { |
|
125 | + function() { |
|
126 | 126 | Benchmark::displayResults(); |
127 | 127 | } |
128 | 128 | ); |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | return ''; |
143 | 143 | } |
144 | 144 | $output = ''; |
145 | - if (! empty(Benchmark::$times)) { |
|
145 | + if ( ! empty(Benchmark::$times)) { |
|
146 | 146 | $total = 0; |
147 | 147 | $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'; |
148 | 148 | foreach (Benchmark::$times as $timer_name => $total_time) { |
149 | - $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />'; |
|
149 | + $output .= Benchmark::formatTime($timer_name, $total_time).'<br />'; |
|
150 | 150 | $total += $total_time; |
151 | 151 | } |
152 | 152 | $output .= '<br />'; |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
163 | 163 | $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
164 | 164 | } |
165 | - if (! empty(Benchmark::$memory_usage)) { |
|
166 | - $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage); |
|
165 | + if ( ! empty(Benchmark::$memory_usage)) { |
|
166 | + $output .= '<h5>Memory</h5>'.implode('<br />', Benchmark::$memory_usage); |
|
167 | 167 | } |
168 | 168 | if (empty($output)) { |
169 | 169 | return ''; |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | public static function convert($size) |
193 | 193 | { |
194 | 194 | $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
195 | - return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)]; |
|
195 | + return round($size / pow(1024, $i = floor(log($size, 1024))), 2).' '.$unit[absint($i)]; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 |
@@ -17,229 +17,229 @@ |
||
17 | 17 | class Benchmark |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * array containing the start time for the timers |
|
22 | - */ |
|
23 | - private static $start_times; |
|
24 | - |
|
25 | - /** |
|
26 | - * array containing all the timer'd times, which can be outputted via show_times() |
|
27 | - */ |
|
28 | - private static $times = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected static $memory_usage = array(); |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * whether to benchmark code or not |
|
39 | - */ |
|
40 | - public static function doNotRun() |
|
41 | - { |
|
42 | - return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * resetTimes |
|
49 | - */ |
|
50 | - public static function resetTimes() |
|
51 | - { |
|
52 | - Benchmark::$times = array(); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
59 | - * |
|
60 | - * @param null $timer_name |
|
61 | - */ |
|
62 | - public static function startTimer($timer_name = null) |
|
63 | - { |
|
64 | - if (Benchmark::doNotRun()) { |
|
65 | - return; |
|
66 | - } |
|
67 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
68 | - Benchmark::$start_times[$timer_name] = microtime(true); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
75 | - * |
|
76 | - * @param string $timer_name |
|
77 | - */ |
|
78 | - public static function stopTimer($timer_name = '') |
|
79 | - { |
|
80 | - if (Benchmark::doNotRun()) { |
|
81 | - return; |
|
82 | - } |
|
83 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
84 | - if (isset(Benchmark::$start_times[$timer_name])) { |
|
85 | - $start_time = Benchmark::$start_times[$timer_name]; |
|
86 | - unset(Benchmark::$start_times[$timer_name]); |
|
87 | - } else { |
|
88 | - $start_time = array_pop(Benchmark::$start_times); |
|
89 | - } |
|
90 | - Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Measure the memory usage by PHP so far. |
|
97 | - * |
|
98 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
99 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - public static function measureMemory($label, $output_now = false) |
|
103 | - { |
|
104 | - if (Benchmark::doNotRun()) { |
|
105 | - return; |
|
106 | - } |
|
107 | - $memory_used = Benchmark::convert(memory_get_peak_usage(true)); |
|
108 | - Benchmark::$memory_usage[$label] = $memory_used; |
|
109 | - if ($output_now) { |
|
110 | - echo "\r\n<br>$label : $memory_used"; |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * will display the benchmarking results at shutdown |
|
118 | - * |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - public static function displayResultsAtShutdown() |
|
122 | - { |
|
123 | - add_action( |
|
124 | - 'shutdown', |
|
125 | - function () { |
|
126 | - Benchmark::displayResults(); |
|
127 | - } |
|
128 | - ); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * displayResults |
|
135 | - * |
|
136 | - * @param bool $echo |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public static function displayResults($echo = true) |
|
140 | - { |
|
141 | - if (Benchmark::doNotRun()) { |
|
142 | - return ''; |
|
143 | - } |
|
144 | - $output = ''; |
|
145 | - if (! empty(Benchmark::$times)) { |
|
146 | - $total = 0; |
|
147 | - $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'; |
|
148 | - foreach (Benchmark::$times as $timer_name => $total_time) { |
|
149 | - $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />'; |
|
150 | - $total += $total_time; |
|
151 | - } |
|
152 | - $output .= '<br />'; |
|
153 | - $output .= '<h4>TOTAL TIME</h4>'; |
|
154 | - $output .= Benchmark::formatTime('', $total); |
|
155 | - $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
156 | - $output .= '<br />'; |
|
157 | - $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
158 | - $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
159 | - $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
160 | - $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
161 | - $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
162 | - $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
163 | - $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
164 | - } |
|
165 | - if (! empty(Benchmark::$memory_usage)) { |
|
166 | - $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage); |
|
167 | - } |
|
168 | - if (empty($output)) { |
|
169 | - return ''; |
|
170 | - } |
|
171 | - $output = '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
172 | - . (is_admin() ? ' margin:2em 2em 2em 180px;' : ' margin:2em;') |
|
173 | - . ' padding:2em;">' |
|
174 | - . '<h4>BENCHMARKING</h4>' |
|
175 | - . $output |
|
176 | - . '</div>'; |
|
177 | - if ($echo) { |
|
178 | - echo $output; |
|
179 | - return ''; |
|
180 | - } |
|
181 | - return $output; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
188 | - * |
|
189 | - * @param int $size |
|
190 | - * @return string |
|
191 | - */ |
|
192 | - public static function convert($size) |
|
193 | - { |
|
194 | - $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
195 | - return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)]; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $timer_name |
|
202 | - * @param float $total_time |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public static function formatTime($timer_name, $total_time) |
|
206 | - { |
|
207 | - $total_time *= 1000; |
|
208 | - switch ($total_time) { |
|
209 | - case $total_time > 12500 : |
|
210 | - $color = 'red'; |
|
211 | - $bold = 'bold'; |
|
212 | - break; |
|
213 | - case $total_time > 2500 : |
|
214 | - $color = 'darkorange'; |
|
215 | - $bold = 'bold'; |
|
216 | - break; |
|
217 | - case $total_time > 500 : |
|
218 | - $color = 'gold'; |
|
219 | - $bold = 'bold'; |
|
220 | - break; |
|
221 | - case $total_time > 100 : |
|
222 | - $color = 'limegreen'; |
|
223 | - $bold = 'normal'; |
|
224 | - break; |
|
225 | - case $total_time > 20 : |
|
226 | - $color = 'deepskyblue'; |
|
227 | - $bold = 'normal'; |
|
228 | - break; |
|
229 | - default : |
|
230 | - $color = 'mediumpurple'; |
|
231 | - $bold = 'normal'; |
|
232 | - break; |
|
233 | - } |
|
234 | - return '<span style="min-width: 10px; margin:0 1em; color:' |
|
235 | - . $color |
|
236 | - . '; font-weight:' |
|
237 | - . $bold |
|
238 | - . '; font-size:1.2em;">' |
|
239 | - . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
240 | - . '</span> ' |
|
241 | - . $timer_name; |
|
242 | - } |
|
20 | + /** |
|
21 | + * array containing the start time for the timers |
|
22 | + */ |
|
23 | + private static $start_times; |
|
24 | + |
|
25 | + /** |
|
26 | + * array containing all the timer'd times, which can be outputted via show_times() |
|
27 | + */ |
|
28 | + private static $times = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected static $memory_usage = array(); |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * whether to benchmark code or not |
|
39 | + */ |
|
40 | + public static function doNotRun() |
|
41 | + { |
|
42 | + return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * resetTimes |
|
49 | + */ |
|
50 | + public static function resetTimes() |
|
51 | + { |
|
52 | + Benchmark::$times = array(); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
59 | + * |
|
60 | + * @param null $timer_name |
|
61 | + */ |
|
62 | + public static function startTimer($timer_name = null) |
|
63 | + { |
|
64 | + if (Benchmark::doNotRun()) { |
|
65 | + return; |
|
66 | + } |
|
67 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
68 | + Benchmark::$start_times[$timer_name] = microtime(true); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
75 | + * |
|
76 | + * @param string $timer_name |
|
77 | + */ |
|
78 | + public static function stopTimer($timer_name = '') |
|
79 | + { |
|
80 | + if (Benchmark::doNotRun()) { |
|
81 | + return; |
|
82 | + } |
|
83 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
84 | + if (isset(Benchmark::$start_times[$timer_name])) { |
|
85 | + $start_time = Benchmark::$start_times[$timer_name]; |
|
86 | + unset(Benchmark::$start_times[$timer_name]); |
|
87 | + } else { |
|
88 | + $start_time = array_pop(Benchmark::$start_times); |
|
89 | + } |
|
90 | + Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Measure the memory usage by PHP so far. |
|
97 | + * |
|
98 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
99 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + public static function measureMemory($label, $output_now = false) |
|
103 | + { |
|
104 | + if (Benchmark::doNotRun()) { |
|
105 | + return; |
|
106 | + } |
|
107 | + $memory_used = Benchmark::convert(memory_get_peak_usage(true)); |
|
108 | + Benchmark::$memory_usage[$label] = $memory_used; |
|
109 | + if ($output_now) { |
|
110 | + echo "\r\n<br>$label : $memory_used"; |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * will display the benchmarking results at shutdown |
|
118 | + * |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + public static function displayResultsAtShutdown() |
|
122 | + { |
|
123 | + add_action( |
|
124 | + 'shutdown', |
|
125 | + function () { |
|
126 | + Benchmark::displayResults(); |
|
127 | + } |
|
128 | + ); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * displayResults |
|
135 | + * |
|
136 | + * @param bool $echo |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public static function displayResults($echo = true) |
|
140 | + { |
|
141 | + if (Benchmark::doNotRun()) { |
|
142 | + return ''; |
|
143 | + } |
|
144 | + $output = ''; |
|
145 | + if (! empty(Benchmark::$times)) { |
|
146 | + $total = 0; |
|
147 | + $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'; |
|
148 | + foreach (Benchmark::$times as $timer_name => $total_time) { |
|
149 | + $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />'; |
|
150 | + $total += $total_time; |
|
151 | + } |
|
152 | + $output .= '<br />'; |
|
153 | + $output .= '<h4>TOTAL TIME</h4>'; |
|
154 | + $output .= Benchmark::formatTime('', $total); |
|
155 | + $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
156 | + $output .= '<br />'; |
|
157 | + $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
158 | + $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
159 | + $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
160 | + $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
161 | + $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
162 | + $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
163 | + $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
164 | + } |
|
165 | + if (! empty(Benchmark::$memory_usage)) { |
|
166 | + $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage); |
|
167 | + } |
|
168 | + if (empty($output)) { |
|
169 | + return ''; |
|
170 | + } |
|
171 | + $output = '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
172 | + . (is_admin() ? ' margin:2em 2em 2em 180px;' : ' margin:2em;') |
|
173 | + . ' padding:2em;">' |
|
174 | + . '<h4>BENCHMARKING</h4>' |
|
175 | + . $output |
|
176 | + . '</div>'; |
|
177 | + if ($echo) { |
|
178 | + echo $output; |
|
179 | + return ''; |
|
180 | + } |
|
181 | + return $output; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
188 | + * |
|
189 | + * @param int $size |
|
190 | + * @return string |
|
191 | + */ |
|
192 | + public static function convert($size) |
|
193 | + { |
|
194 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
195 | + return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)]; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $timer_name |
|
202 | + * @param float $total_time |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public static function formatTime($timer_name, $total_time) |
|
206 | + { |
|
207 | + $total_time *= 1000; |
|
208 | + switch ($total_time) { |
|
209 | + case $total_time > 12500 : |
|
210 | + $color = 'red'; |
|
211 | + $bold = 'bold'; |
|
212 | + break; |
|
213 | + case $total_time > 2500 : |
|
214 | + $color = 'darkorange'; |
|
215 | + $bold = 'bold'; |
|
216 | + break; |
|
217 | + case $total_time > 500 : |
|
218 | + $color = 'gold'; |
|
219 | + $bold = 'bold'; |
|
220 | + break; |
|
221 | + case $total_time > 100 : |
|
222 | + $color = 'limegreen'; |
|
223 | + $bold = 'normal'; |
|
224 | + break; |
|
225 | + case $total_time > 20 : |
|
226 | + $color = 'deepskyblue'; |
|
227 | + $bold = 'normal'; |
|
228 | + break; |
|
229 | + default : |
|
230 | + $color = 'mediumpurple'; |
|
231 | + $bold = 'normal'; |
|
232 | + break; |
|
233 | + } |
|
234 | + return '<span style="min-width: 10px; margin:0 1em; color:' |
|
235 | + . $color |
|
236 | + . '; font-weight:' |
|
237 | + . $bold |
|
238 | + . '; font-size:1.2em;">' |
|
239 | + . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
240 | + . '</span> ' |
|
241 | + . $timer_name; |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | 245 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** |
16 | 16 | * Use to select a quantity from the first ticket for the given event (so this can be used on a event archive page). |
17 | 17 | * @param int|string $event_id |
18 | - * @param int|string $quantity |
|
18 | + * @param integer $quantity |
|
19 | 19 | */ |
20 | 20 | public function selectQuantityOfFirstTicketForEventId($event_id, $quantity = 1) |
21 | 21 | { |
@@ -12,23 +12,23 @@ |
||
12 | 12 | trait TicketSelector |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Use to select a quantity from the first ticket for the given event (so this can be used on a event archive page). |
|
17 | - * @param int|string $event_id |
|
18 | - * @param int|string $quantity |
|
19 | - */ |
|
20 | - public function selectQuantityOfFirstTicketForEventId($event_id, $quantity = 1) |
|
21 | - { |
|
22 | - $this->actor()->selectOption(TicketSelectorElements::ticketOptionByEventIdSelector($event_id), $quantity); |
|
23 | - } |
|
15 | + /** |
|
16 | + * Use to select a quantity from the first ticket for the given event (so this can be used on a event archive page). |
|
17 | + * @param int|string $event_id |
|
18 | + * @param int|string $quantity |
|
19 | + */ |
|
20 | + public function selectQuantityOfFirstTicketForEventId($event_id, $quantity = 1) |
|
21 | + { |
|
22 | + $this->actor()->selectOption(TicketSelectorElements::ticketOptionByEventIdSelector($event_id), $quantity); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Used to submit the ticket selection for the given event id (so this can be used on an event archive page). |
|
28 | - * @param int|string $event_id |
|
29 | - */ |
|
30 | - public function submitTicketSelectionsForEventId($event_id) |
|
31 | - { |
|
32 | - $this->actor()->click(TicketSelectorElements::ticketSelectionSubmitSelectorByEventId($event_id)); |
|
33 | - } |
|
26 | + /** |
|
27 | + * Used to submit the ticket selection for the given event id (so this can be used on an event archive page). |
|
28 | + * @param int|string $event_id |
|
29 | + */ |
|
30 | + public function submitTicketSelectionsForEventId($event_id) |
|
31 | + { |
|
32 | + $this->actor()->click(TicketSelectorElements::ticketSelectionSubmitSelectorByEventId($event_id)); |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -13,39 +13,39 @@ |
||
13 | 13 | */ |
14 | 14 | trait Checkout |
15 | 15 | { |
16 | - /** |
|
17 | - * @param $value |
|
18 | - * @param int $attendee_number |
|
19 | - */ |
|
20 | - public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1) |
|
21 | - { |
|
22 | - $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @param $value |
|
27 | - * @param int $attendee_number |
|
28 | - */ |
|
29 | - public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1) |
|
30 | - { |
|
31 | - $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @param $value |
|
36 | - * @param int $attendee_number |
|
37 | - */ |
|
38 | - public function fillOutEmailFieldForAttendee($value, $attendee_number = 1) |
|
39 | - { |
|
40 | - $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Clicks the next registration step button. |
|
46 | - */ |
|
47 | - public function goToNextRegistrationStep() |
|
48 | - { |
|
49 | - $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
50 | - } |
|
16 | + /** |
|
17 | + * @param $value |
|
18 | + * @param int $attendee_number |
|
19 | + */ |
|
20 | + public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1) |
|
21 | + { |
|
22 | + $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @param $value |
|
27 | + * @param int $attendee_number |
|
28 | + */ |
|
29 | + public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1) |
|
30 | + { |
|
31 | + $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @param $value |
|
36 | + * @param int $attendee_number |
|
37 | + */ |
|
38 | + public function fillOutEmailFieldForAttendee($value, $attendee_number = 1) |
|
39 | + { |
|
40 | + $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Clicks the next registration step button. |
|
46 | + */ |
|
47 | + public function goToNextRegistrationStep() |
|
48 | + { |
|
49 | + $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | \ No newline at end of file |
@@ -13,48 +13,48 @@ |
||
13 | 13 | class Checkout |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * The class selector for the next step button in the checkout. |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - const NEXT_STEP_BUTTON_SELECTOR = '.spco-next-step-btn'; |
|
21 | - |
|
22 | - /** |
|
23 | - * @param int $attendee_number |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public static function firstNameFieldSelectorForAttendeeNumber($attendee_number = 1) |
|
27 | - { |
|
28 | - return self::fieldSelectorForAttendeeNumber('fname', $attendee_number); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param int $attendee_number |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public static function lastNameFieldSelectorForAttendeeNumber($attendee_number = 1) |
|
37 | - { |
|
38 | - return self::fieldSelectorForAttendeeNumber('lname', $attendee_number); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @param int $attendee_number |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public static function emailFieldSelectorForAttendeeNumber($attendee_number = 1) |
|
47 | - { |
|
48 | - return self::fieldSelectorForAttendeeNumber('email', $attendee_number); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @param $field_name |
|
53 | - * @param int $attendee_number |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public static function fieldSelectorForAttendeeNumber($field_name, $attendee_number = 1) |
|
57 | - { |
|
58 | - return "//div[starts-with(@id, 'spco-attendee-panel-dv-$attendee_number')]//input[contains(@class, 'ee-reg-qstn-$field_name')]"; |
|
59 | - } |
|
16 | + /** |
|
17 | + * The class selector for the next step button in the checkout. |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + const NEXT_STEP_BUTTON_SELECTOR = '.spco-next-step-btn'; |
|
21 | + |
|
22 | + /** |
|
23 | + * @param int $attendee_number |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public static function firstNameFieldSelectorForAttendeeNumber($attendee_number = 1) |
|
27 | + { |
|
28 | + return self::fieldSelectorForAttendeeNumber('fname', $attendee_number); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param int $attendee_number |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public static function lastNameFieldSelectorForAttendeeNumber($attendee_number = 1) |
|
37 | + { |
|
38 | + return self::fieldSelectorForAttendeeNumber('lname', $attendee_number); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @param int $attendee_number |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public static function emailFieldSelectorForAttendeeNumber($attendee_number = 1) |
|
47 | + { |
|
48 | + return self::fieldSelectorForAttendeeNumber('email', $attendee_number); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @param $field_name |
|
53 | + * @param int $attendee_number |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public static function fieldSelectorForAttendeeNumber($field_name, $attendee_number = 1) |
|
57 | + { |
|
58 | + return "//div[starts-with(@id, 'spco-attendee-panel-dv-$attendee_number')]//input[contains(@class, 'ee-reg-qstn-$field_name')]"; |
|
59 | + } |
|
60 | 60 | } |
@@ -103,8 +103,8 @@ |
||
103 | 103 | public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
104 | 104 | { |
105 | 105 | return $context |
106 | - ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
107 | - : '.' . $message_type_slug . '-edit-link'; |
|
106 | + ? '.'.$message_type_slug.'-'.$context.'-edit-link' |
|
107 | + : '.'.$message_type_slug.'-edit-link'; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 |
@@ -12,146 +12,146 @@ |
||
12 | 12 | class MessagesAdmin extends CoreAdmin |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Context slug for the admin messages context. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - const ADMIN_CONTEXT_SLUG = 'admin'; |
|
20 | - |
|
21 | - /** |
|
22 | - * Context slug for the primary attendee messages context |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Status reference for the EEM_Message::status_sent status. |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - const MESSAGE_STATUS_SENT = 'MSN'; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Message type slug for the Payment Failed message type |
|
37 | - */ |
|
38 | - const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = '#global_messages_settings-do-messages-on-same-request'; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * This is the container where active message types for a messenger are found/dragged to. |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
65 | - * a string. |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public static function messageActivityListTableUrl($additional_params = '') |
|
69 | - { |
|
70 | - return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
76 | - * a string. |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
80 | - { |
|
81 | - return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
87 | - * a string. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public static function customMessageTemplateListTableUrl($additional_params = '') |
|
91 | - { |
|
92 | - return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public static function messageSettingsUrl() |
|
100 | - { |
|
101 | - return self::adminUrl('espresso_messages', 'settings'); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
107 | - $message_type_slug, |
|
108 | - $messenger_slug = 'email' |
|
109 | - ) { |
|
110 | - return "#$message_type_slug-messagetype-$messenger_slug"; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @param string $message_type_slug |
|
116 | - * @param string $context |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
120 | - { |
|
121 | - return $context |
|
122 | - ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
123 | - : '.' . $message_type_slug . '-edit-link'; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
129 | - * @param $field |
|
130 | - * @param $message_type_label |
|
131 | - * @param string $message_status |
|
132 | - * @param string $messenger |
|
133 | - * @param string $context |
|
134 | - * @param string $table_cell_content_for_field |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public static function messagesActivityListTableCellSelectorFor( |
|
138 | - $field, |
|
139 | - $message_type_label, |
|
140 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
141 | - $messenger = 'Email', |
|
142 | - $context = 'Event Admin', |
|
143 | - $table_cell_content_for_field = '' |
|
144 | - ) { |
|
145 | - $selector = "//tr[contains(@class, 'msg-status-$message_status')]" |
|
146 | - . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
147 | - if ($messenger) { |
|
148 | - $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
149 | - } |
|
150 | - $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
151 | - $selector .= $table_cell_content_for_field |
|
152 | - ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
153 | - : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
154 | - return $selector; |
|
155 | - } |
|
15 | + /** |
|
16 | + * Context slug for the admin messages context. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + const ADMIN_CONTEXT_SLUG = 'admin'; |
|
20 | + |
|
21 | + /** |
|
22 | + * Context slug for the primary attendee messages context |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Status reference for the EEM_Message::status_sent status. |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + const MESSAGE_STATUS_SENT = 'MSN'; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Message type slug for the Payment Failed message type |
|
37 | + */ |
|
38 | + const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = '#global_messages_settings-do-messages-on-same-request'; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * This is the container where active message types for a messenger are found/dragged to. |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
65 | + * a string. |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public static function messageActivityListTableUrl($additional_params = '') |
|
69 | + { |
|
70 | + return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
76 | + * a string. |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
80 | + { |
|
81 | + return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
87 | + * a string. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public static function customMessageTemplateListTableUrl($additional_params = '') |
|
91 | + { |
|
92 | + return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public static function messageSettingsUrl() |
|
100 | + { |
|
101 | + return self::adminUrl('espresso_messages', 'settings'); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
107 | + $message_type_slug, |
|
108 | + $messenger_slug = 'email' |
|
109 | + ) { |
|
110 | + return "#$message_type_slug-messagetype-$messenger_slug"; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @param string $message_type_slug |
|
116 | + * @param string $context |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
120 | + { |
|
121 | + return $context |
|
122 | + ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
123 | + : '.' . $message_type_slug . '-edit-link'; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
129 | + * @param $field |
|
130 | + * @param $message_type_label |
|
131 | + * @param string $message_status |
|
132 | + * @param string $messenger |
|
133 | + * @param string $context |
|
134 | + * @param string $table_cell_content_for_field |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public static function messagesActivityListTableCellSelectorFor( |
|
138 | + $field, |
|
139 | + $message_type_label, |
|
140 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
141 | + $messenger = 'Email', |
|
142 | + $context = 'Event Admin', |
|
143 | + $table_cell_content_for_field = '' |
|
144 | + ) { |
|
145 | + $selector = "//tr[contains(@class, 'msg-status-$message_status')]" |
|
146 | + . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
147 | + if ($messenger) { |
|
148 | + $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
149 | + } |
|
150 | + $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
151 | + $selector .= $table_cell_content_for_field |
|
152 | + ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
153 | + : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
154 | + return $selector; |
|
155 | + } |
|
156 | 156 | |
157 | 157 | } |
158 | 158 | \ No newline at end of file |
@@ -12,24 +12,24 @@ |
||
12 | 12 | class TicketSelector |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Return the selector for the ticket option select input for the given event id. |
|
17 | - * @param int|string $event_id |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public static function ticketOptionByEventIdSelector($event_id) |
|
21 | - { |
|
22 | - return "//select[@id='ticket-selector-tbl-qty-slct-$event_id-1']"; |
|
23 | - } |
|
15 | + /** |
|
16 | + * Return the selector for the ticket option select input for the given event id. |
|
17 | + * @param int|string $event_id |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public static function ticketOptionByEventIdSelector($event_id) |
|
21 | + { |
|
22 | + return "//select[@id='ticket-selector-tbl-qty-slct-$event_id-1']"; |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Return the selector for the submit button for the ticket selector for the given event id. |
|
28 | - * @param int|string $event_id |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public static function ticketSelectionSubmitSelectorByEventId($event_id) |
|
32 | - { |
|
33 | - return "#ticket-selector-submit-$event_id-btn"; |
|
34 | - } |
|
26 | + /** |
|
27 | + * Return the selector for the submit button for the ticket selector for the given event id. |
|
28 | + * @param int|string $event_id |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public static function ticketSelectionSubmitSelectorByEventId($event_id) |
|
32 | + { |
|
33 | + return "#ticket-selector-submit-$event_id-btn"; |
|
34 | + } |
|
35 | 35 | } |
36 | 36 | \ No newline at end of file |