@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | * @param \EE_Registry $Registry |
89 | 89 | * @return \EE_System |
90 | 90 | */ |
91 | - public static function instance( EE_Registry $Registry = null ) { |
|
91 | + public static function instance(EE_Registry $Registry = null) { |
|
92 | 92 | // check if class object is instantiated |
93 | - if ( ! self::$_instance instanceof EE_System ) { |
|
94 | - self::$_instance = new self( $Registry ); |
|
93 | + if ( ! self::$_instance instanceof EE_System) { |
|
94 | + self::$_instance = new self($Registry); |
|
95 | 95 | } |
96 | 96 | return self::$_instance; |
97 | 97 | } |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | * resets the instance and returns it |
102 | 102 | * @return EE_System |
103 | 103 | */ |
104 | - public static function reset(){ |
|
104 | + public static function reset() { |
|
105 | 105 | self::$_instance->_req_type = NULL; |
106 | 106 | |
107 | 107 | //make sure none of the old hooks are left hanging around |
108 | - remove_all_actions( 'AHEE__EE_System__perform_activations_upgrades_and_migrations' ); |
|
108 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
109 | 109 | |
110 | 110 | //we need to reset the migration manager in order for it to detect DMSs properly |
111 | 111 | EE_Data_Migration_Manager::reset(); |
@@ -125,28 +125,28 @@ discard block |
||
125 | 125 | * @access private |
126 | 126 | * @param \EE_Registry $Registry |
127 | 127 | */ |
128 | - private function __construct( EE_Registry $Registry ) { |
|
128 | + private function __construct(EE_Registry $Registry) { |
|
129 | 129 | $this->registry = $Registry; |
130 | - do_action( 'AHEE__EE_System__construct__begin', $this ); |
|
130 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
131 | 131 | // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
132 | - add_action( 'AHEE__EE_Bootstrap__load_espresso_addons', array( $this, 'load_espresso_addons' ) ); |
|
132 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
133 | 133 | // when an ee addon is activated, we want to call the core hook(s) again |
134 | 134 | // because the newly-activated addon didn't get a chance to run at all |
135 | - add_action( 'activate_plugin', array( $this, 'load_espresso_addons' ), 1 ); |
|
135 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
136 | 136 | // detect whether install or upgrade |
137 | - add_action( 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array( $this, 'detect_activations_or_upgrades' ), 3 ); |
|
137 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), 3); |
|
138 | 138 | // load EE_Config, EE_Textdomain, etc |
139 | - add_action( 'AHEE__EE_Bootstrap__load_core_configuration', array( $this, 'load_core_configuration' ), 5 ); |
|
139 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
140 | 140 | // load EE_Config, EE_Textdomain, etc |
141 | - add_action( 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', array( $this, 'register_shortcodes_modules_and_widgets' ), 7 ); |
|
141 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
142 | 142 | // you wanna get going? I wanna get going... let's get going! |
143 | - add_action( 'AHEE__EE_Bootstrap__brew_espresso', array( $this, 'brew_espresso' ), 9 ); |
|
143 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
144 | 144 | //other housekeeping |
145 | 145 | //exclude EE critical pages from wp_list_pages |
146 | - add_filter( 'wp_list_pages_excludes', array( $this, 'remove_pages_from_wp_list_pages' ), 10 ); |
|
146 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
147 | 147 | // ALL EE Addons should use the following hook point to attach their initial setup too |
148 | 148 | // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
149 | - do_action( 'AHEE__EE_System__construct__complete', $this ); |
|
149 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | |
@@ -166,30 +166,30 @@ discard block |
||
166 | 166 | public function load_espresso_addons() { |
167 | 167 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
168 | 168 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
169 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_LIBRARIES . 'plugin_api' ); |
|
169 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
170 | 170 | //load and setup EE_Capabilities |
171 | - $this->registry->load_core( 'Capabilities' ); |
|
171 | + $this->registry->load_core('Capabilities'); |
|
172 | 172 | //caps need to be initialized on every request so that capability maps are set. |
173 | 173 | //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
174 | 174 | $this->registry->CAP->init_caps(); |
175 | - do_action( 'AHEE__EE_System__load_espresso_addons' ); |
|
175 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
176 | 176 | //if the WP API basic auth plugin isn't already loaded, load it now. |
177 | 177 | //We want it for mobile apps. Just include the entire plugin |
178 | 178 | //also, don't load the basic auth when a plugin is getting activated, because |
179 | 179 | //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
180 | 180 | //and causes a fatal error |
181 | - if( !function_exists( 'json_basic_auth_handler' ) |
|
182 | - && ! function_exists( 'json_basic_auth_error' ) |
|
181 | + if ( ! function_exists('json_basic_auth_handler') |
|
182 | + && ! function_exists('json_basic_auth_error') |
|
183 | 183 | && ! ( |
184 | - isset( $_GET[ 'action'] ) |
|
185 | - && in_array( $_GET[ 'action' ], array( 'activate', 'activate-selected' ) ) |
|
184 | + isset($_GET['action']) |
|
185 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
186 | 186 | ) |
187 | 187 | && ! ( |
188 | - isset( $_GET['activate' ] ) |
|
189 | - && $_GET['activate' ] === 'true' |
|
188 | + isset($_GET['activate']) |
|
189 | + && $_GET['activate'] === 'true' |
|
190 | 190 | ) |
191 | 191 | ) { |
192 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
192 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | * @access public |
206 | 206 | * @return void |
207 | 207 | */ |
208 | - public function detect_activations_or_upgrades(){ |
|
208 | + public function detect_activations_or_upgrades() { |
|
209 | 209 | //first off: let's make sure to handle core |
210 | 210 | $this->detect_if_activation_or_upgrade(); |
211 | - foreach($this->registry->addons as $addon){ |
|
211 | + foreach ($this->registry->addons as $addon) { |
|
212 | 212 | //detect teh request type for that addon |
213 | 213 | $addon->detect_activation_or_upgrade(); |
214 | 214 | } |
@@ -229,41 +229,41 @@ discard block |
||
229 | 229 | do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
230 | 230 | |
231 | 231 | // load M-Mode class |
232 | - $this->registry->load_core( 'Maintenance_Mode' ); |
|
232 | + $this->registry->load_core('Maintenance_Mode'); |
|
233 | 233 | // check if db has been updated, or if its a brand-new installation |
234 | 234 | |
235 | 235 | $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
236 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
236 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
237 | 237 | //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
238 | 238 | |
239 | - switch($request_type){ |
|
239 | + switch ($request_type) { |
|
240 | 240 | case EE_System::req_type_new_activation: |
241 | - do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__new_activation' ); |
|
242 | - $this->_handle_core_version_change( $espresso_db_update ); |
|
241 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
242 | + $this->_handle_core_version_change($espresso_db_update); |
|
243 | 243 | break; |
244 | 244 | case EE_System::req_type_reactivation: |
245 | - do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__reactivation' ); |
|
246 | - $this->_handle_core_version_change( $espresso_db_update ); |
|
245 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
246 | + $this->_handle_core_version_change($espresso_db_update); |
|
247 | 247 | break; |
248 | 248 | case EE_System::req_type_upgrade: |
249 | - do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__upgrade' ); |
|
249 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
250 | 250 | //migrations may be required now that we've upgraded |
251 | 251 | EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
252 | - $this->_handle_core_version_change( $espresso_db_update ); |
|
252 | + $this->_handle_core_version_change($espresso_db_update); |
|
253 | 253 | // echo "done upgrade";die; |
254 | 254 | break; |
255 | 255 | case EE_System::req_type_downgrade: |
256 | - do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__downgrade' ); |
|
256 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
257 | 257 | //its possible migrations are no longer required |
258 | 258 | EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
259 | - $this->_handle_core_version_change( $espresso_db_update ); |
|
259 | + $this->_handle_core_version_change($espresso_db_update); |
|
260 | 260 | break; |
261 | 261 | case EE_System::req_type_normal: |
262 | 262 | default: |
263 | 263 | // $this->_maybe_redirect_to_ee_about(); |
264 | 264 | break; |
265 | 265 | } |
266 | - do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__complete' ); |
|
266 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -271,10 +271,10 @@ discard block |
||
271 | 271 | * initializing the database later during the request |
272 | 272 | * @param array $espresso_db_update |
273 | 273 | */ |
274 | - protected function _handle_core_version_change( $espresso_db_update ){ |
|
275 | - $this->update_list_of_installed_versions( $espresso_db_update ); |
|
274 | + protected function _handle_core_version_change($espresso_db_update) { |
|
275 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
276 | 276 | //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
277 | - add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' )); |
|
277 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', array($this, 'initialize_db_if_no_migrations_required')); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | |
@@ -289,44 +289,44 @@ discard block |
||
289 | 289 | * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it from the options table |
290 | 290 | * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
291 | 291 | */ |
292 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null){ |
|
293 | - do_action( 'FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update ); |
|
294 | - if( ! $espresso_db_update){ |
|
295 | - $espresso_db_update = get_option( 'espresso_db_update' ); |
|
292 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) { |
|
293 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
294 | + if ( ! $espresso_db_update) { |
|
295 | + $espresso_db_update = get_option('espresso_db_update'); |
|
296 | 296 | } |
297 | 297 | // check that option is an array |
298 | - if( ! is_array( $espresso_db_update )) { |
|
298 | + if ( ! is_array($espresso_db_update)) { |
|
299 | 299 | // if option is FALSE, then it never existed |
300 | - if ( $espresso_db_update === FALSE ) { |
|
300 | + if ($espresso_db_update === FALSE) { |
|
301 | 301 | // make $espresso_db_update an array and save option with autoload OFF |
302 | - $espresso_db_update = array(); |
|
303 | - add_option( 'espresso_db_update', $espresso_db_update, '', 'no' ); |
|
302 | + $espresso_db_update = array(); |
|
303 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
304 | 304 | } else { |
305 | 305 | // option is NOT FALSE but also is NOT an array, so make it an array and save it |
306 | - $espresso_db_update = array( $espresso_db_update=>array() ); |
|
307 | - update_option( 'espresso_db_update', $espresso_db_update ); |
|
306 | + $espresso_db_update = array($espresso_db_update=>array()); |
|
307 | + update_option('espresso_db_update', $espresso_db_update); |
|
308 | 308 | } |
309 | - }else{ |
|
309 | + } else { |
|
310 | 310 | $corrected_db_update = array(); |
311 | 311 | //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
312 | - foreach($espresso_db_update as $should_be_version_string => $should_be_array){ |
|
313 | - if(is_int($should_be_version_string) && ! is_array($should_be_array)){ |
|
312 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
313 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
314 | 314 | //the key is an int, and the value IS NOT an array |
315 | 315 | //so it must be numerically-indexed, where values are versions installed... |
316 | 316 | //fix it! |
317 | 317 | $version_string = $should_be_array; |
318 | 318 | $corrected_db_update[$version_string] = array('unknown-date'); |
319 | - }else{ |
|
319 | + } else { |
|
320 | 320 | //ok it checks out |
321 | 321 | $corrected_db_update[$should_be_version_string] = $should_be_array; |
322 | 322 | } |
323 | 323 | } |
324 | 324 | $espresso_db_update = $corrected_db_update; |
325 | - update_option( 'espresso_db_update', $espresso_db_update ); |
|
325 | + update_option('espresso_db_update', $espresso_db_update); |
|
326 | 326 | |
327 | 327 | } |
328 | 328 | |
329 | - do_action( 'FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update ); |
|
329 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
330 | 330 | return $espresso_db_update; |
331 | 331 | } |
332 | 332 | |
@@ -346,34 +346,34 @@ discard block |
||
346 | 346 | * so we prefer to only do it when necessary |
347 | 347 | * @return void |
348 | 348 | */ |
349 | - public function initialize_db_if_no_migrations_required( $initialize_addons_too = FALSE, $verify_schema = true ){ |
|
349 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = FALSE, $verify_schema = true) { |
|
350 | 350 | $request_type = $this->detect_req_type(); |
351 | 351 | //only initialize system if we're not in maintenance mode. |
352 | - if( EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ){ |
|
353 | - update_option( 'ee_flush_rewrite_rules', TRUE ); |
|
352 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
353 | + update_option('ee_flush_rewrite_rules', TRUE); |
|
354 | 354 | |
355 | - if( $verify_schema ) { |
|
355 | + if ($verify_schema) { |
|
356 | 356 | EEH_Activation::initialize_db_and_folders(); |
357 | 357 | } |
358 | 358 | EEH_Activation::initialize_db_content(); |
359 | 359 | EEH_Activation::system_initialization(); |
360 | - if( $initialize_addons_too ) { |
|
360 | + if ($initialize_addons_too) { |
|
361 | 361 | $this->initialize_addons(); |
362 | 362 | } |
363 | - }else{ |
|
364 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for( 'Core' ); |
|
363 | + } else { |
|
364 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
365 | 365 | } |
366 | - if ( $request_type == EE_System::req_type_new_activation || $request_type == EE_System::req_type_reactivation || $request_type == EE_System::req_type_upgrade ) { |
|
367 | - add_action( 'AHEE__EE_System__load_CPTs_and_session__start', array( $this, 'redirect_to_about_ee' ), 9 ); |
|
366 | + if ($request_type == EE_System::req_type_new_activation || $request_type == EE_System::req_type_reactivation || $request_type == EE_System::req_type_upgrade) { |
|
367 | + add_action('AHEE__EE_System__load_CPTs_and_session__start', array($this, 'redirect_to_about_ee'), 9); |
|
368 | 368 | } |
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
372 | 372 | * Initializes the db for all registered addons |
373 | 373 | */ |
374 | - public function initialize_addons(){ |
|
374 | + public function initialize_addons() { |
|
375 | 375 | //foreach registered addon, make sure its db is up-to-date too |
376 | - foreach($this->registry->addons as $addon){ |
|
376 | + foreach ($this->registry->addons as $addon) { |
|
377 | 377 | $addon->initialize_db_if_no_migrations_required(); |
378 | 378 | } |
379 | 379 | } |
@@ -385,16 +385,16 @@ discard block |
||
385 | 385 | * @param string $current_version_to_add version to be added to the version history |
386 | 386 | * @return boolean success as to whether or not this option was changed |
387 | 387 | */ |
388 | - public function update_list_of_installed_versions($version_history = NULL,$current_version_to_add = NULL) { |
|
389 | - if( ! $version_history ) { |
|
388 | + public function update_list_of_installed_versions($version_history = NULL, $current_version_to_add = NULL) { |
|
389 | + if ( ! $version_history) { |
|
390 | 390 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
391 | 391 | } |
392 | - if( $current_version_to_add == NULL){ |
|
392 | + if ($current_version_to_add == NULL) { |
|
393 | 393 | $current_version_to_add = espresso_version(); |
394 | 394 | } |
395 | - $version_history[ $current_version_to_add ][] = date( 'Y-m-d H:i:s',time() ); |
|
395 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
396 | 396 | // re-save |
397 | - return update_option( 'espresso_db_update', $version_history ); |
|
397 | + return update_option('espresso_db_update', $version_history); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | |
@@ -411,10 +411,10 @@ discard block |
||
411 | 411 | * but still know if this is a new install or not |
412 | 412 | * @return int one of the constants on EE_System::req_type_ |
413 | 413 | */ |
414 | - public function detect_req_type( $espresso_db_update = NULL ){ |
|
415 | - if ( $this->_req_type === NULL ){ |
|
416 | - $espresso_db_update = ! empty( $espresso_db_update ) ? $espresso_db_update : $this->fix_espresso_db_upgrade_option(); |
|
417 | - $this->_req_type = $this->detect_req_type_given_activation_history( $espresso_db_update, 'ee_espresso_activation', espresso_version() ); |
|
414 | + public function detect_req_type($espresso_db_update = NULL) { |
|
415 | + if ($this->_req_type === NULL) { |
|
416 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update : $this->fix_espresso_db_upgrade_option(); |
|
417 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, 'ee_espresso_activation', espresso_version()); |
|
418 | 418 | } |
419 | 419 | return $this->_req_type; |
420 | 420 | } |
@@ -430,39 +430,39 @@ discard block |
||
430 | 430 | * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be espresso_version()) |
431 | 431 | * @return int one of the constants on EE_System::req_type_* |
432 | 432 | */ |
433 | - public static function detect_req_type_given_activation_history( $activation_history_for_addon, $activation_indicator_option_name, $version_to_upgrade_to ){ |
|
434 | - $version_is_higher = self::_new_version_is_higher( $activation_history_for_addon, $version_to_upgrade_to ); |
|
435 | - if( $activation_history_for_addon ){ |
|
433 | + public static function detect_req_type_given_activation_history($activation_history_for_addon, $activation_indicator_option_name, $version_to_upgrade_to) { |
|
434 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
435 | + if ($activation_history_for_addon) { |
|
436 | 436 | //it exists, so this isn't a completely new install |
437 | 437 | //check if this version already in that list of previously installed versions |
438 | - if ( ! isset( $activation_history_for_addon[ $version_to_upgrade_to ] )) { |
|
438 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
439 | 439 | //it a version we haven't seen before |
440 | - if( $version_is_higher === 1 ){ |
|
440 | + if ($version_is_higher === 1) { |
|
441 | 441 | $req_type = EE_System::req_type_upgrade; |
442 | - }else{ |
|
442 | + } else { |
|
443 | 443 | $req_type = EE_System::req_type_downgrade; |
444 | 444 | } |
445 | - delete_option( $activation_indicator_option_name ); |
|
445 | + delete_option($activation_indicator_option_name); |
|
446 | 446 | } else { |
447 | 447 | // its not an update. maybe a reactivation? |
448 | - if( get_option( $activation_indicator_option_name, FALSE ) ){ |
|
449 | - if ( $version_is_higher === -1 ){ |
|
448 | + if (get_option($activation_indicator_option_name, FALSE)) { |
|
449 | + if ($version_is_higher === -1) { |
|
450 | 450 | $req_type = EE_System::req_type_downgrade; |
451 | - }elseif( $version_is_higher === 0 ){ |
|
451 | + }elseif ($version_is_higher === 0) { |
|
452 | 452 | //we've seen this version before, but it's an activation. must be a reactivation |
453 | 453 | $req_type = EE_System::req_type_reactivation; |
454 | - }else{//$version_is_higher === 1 |
|
454 | + } else {//$version_is_higher === 1 |
|
455 | 455 | $req_type = EE_System::req_type_upgrade; |
456 | 456 | } |
457 | - delete_option( $activation_indicator_option_name ); |
|
457 | + delete_option($activation_indicator_option_name); |
|
458 | 458 | } else { |
459 | 459 | //we've seen this version before and the activation indicate doesn't show it was just activated |
460 | - if ( $version_is_higher === -1 ){ |
|
460 | + if ($version_is_higher === -1) { |
|
461 | 461 | $req_type = EE_System::req_type_downgrade; |
462 | - }elseif( $version_is_higher === 0 ){ |
|
462 | + }elseif ($version_is_higher === 0) { |
|
463 | 463 | //we've seen this version before and it's not an activation. its normal request |
464 | 464 | $req_type = EE_System::req_type_normal; |
465 | - }else{//$version_is_higher === 1 |
|
465 | + } else {//$version_is_higher === 1 |
|
466 | 466 | $req_type = EE_System::req_type_upgrade; |
467 | 467 | } |
468 | 468 | } |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | } else { |
471 | 471 | //brand new install |
472 | 472 | $req_type = EE_System::req_type_new_activation; |
473 | - delete_option( $activation_indicator_option_name ); |
|
473 | + delete_option($activation_indicator_option_name); |
|
474 | 474 | } |
475 | 475 | return $req_type; |
476 | 476 | } |
@@ -488,30 +488,30 @@ discard block |
||
488 | 488 | * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
489 | 489 | * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
490 | 490 | */ |
491 | - protected static function _new_version_is_higher( $activation_history_for_addon, $version_to_upgrade_to ){ |
|
491 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) { |
|
492 | 492 | //find the most recently-activated version |
493 | 493 | $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
494 | 494 | $most_recently_active_version = '0.0.0.dev.000'; |
495 | - if( is_array( $activation_history_for_addon ) ){ |
|
496 | - foreach( $activation_history_for_addon as $version => $times_activated ){ |
|
495 | + if (is_array($activation_history_for_addon)) { |
|
496 | + foreach ($activation_history_for_addon as $version => $times_activated) { |
|
497 | 497 | //check there is a record of when this version was activated. Otherwise, |
498 | 498 | //mark it as unknown |
499 | - if( ! $times_activated ){ |
|
500 | - $times_activated = array( 'unknown-date'); |
|
499 | + if ( ! $times_activated) { |
|
500 | + $times_activated = array('unknown-date'); |
|
501 | 501 | } |
502 | - if( is_string( $times_activated ) ){ |
|
503 | - $times_activated = array( $times_activated ); |
|
502 | + if (is_string($times_activated)) { |
|
503 | + $times_activated = array($times_activated); |
|
504 | 504 | } |
505 | - foreach( $times_activated as $an_activation ){ |
|
506 | - if( $an_activation != 'unknown-date' && |
|
507 | - $an_activation > $most_recently_active_version_activation ){ |
|
505 | + foreach ($times_activated as $an_activation) { |
|
506 | + if ($an_activation != 'unknown-date' && |
|
507 | + $an_activation > $most_recently_active_version_activation) { |
|
508 | 508 | $most_recently_active_version = $version; |
509 | 509 | $most_recently_active_version_activation = $an_activation == 'unknown-date' ? '1970-01-01 00:00:00' : $an_activation; |
510 | 510 | } |
511 | 511 | } |
512 | 512 | } |
513 | 513 | } |
514 | - return version_compare( $version_to_upgrade_to, $most_recently_active_version ); |
|
514 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | |
@@ -521,24 +521,24 @@ discard block |
||
521 | 521 | * @return void |
522 | 522 | */ |
523 | 523 | public function redirect_to_about_ee() { |
524 | - $notices = EE_Error::get_notices( FALSE ); |
|
524 | + $notices = EE_Error::get_notices(FALSE); |
|
525 | 525 | //if current user is an admin and it's not an ajax request |
526 | 526 | if ( |
527 | - $this->registry->CAP->current_user_can( 'manage_options', 'espresso_about_default' ) |
|
528 | - && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
529 | - && ! isset( $notices[ 'errors' ] ) |
|
527 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
528 | + && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
529 | + && ! isset($notices['errors']) |
|
530 | 530 | ) { |
531 | - $query_params = array( 'page' => 'espresso_about' ); |
|
531 | + $query_params = array('page' => 'espresso_about'); |
|
532 | 532 | |
533 | - if ( EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation ) { |
|
533 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
534 | 534 | $query_params['new_activation'] = TRUE; |
535 | 535 | } |
536 | 536 | |
537 | - if ( EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation ) { |
|
537 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
538 | 538 | $query_params['reactivation'] = TRUE; |
539 | 539 | } |
540 | - $url = add_query_arg( $query_params, admin_url( 'admin.php' ) ); |
|
541 | - wp_safe_redirect( $url ); |
|
540 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
541 | + wp_safe_redirect($url); |
|
542 | 542 | exit(); |
543 | 543 | } |
544 | 544 | } |
@@ -552,31 +552,31 @@ discard block |
||
552 | 552 | * |
553 | 553 | * @return void |
554 | 554 | */ |
555 | - public function load_core_configuration(){ |
|
556 | - do_action( 'AHEE__EE_System__load_core_configuration__begin', $this ); |
|
557 | - $this->registry->load_core( 'EE_Load_Textdomain' ); |
|
555 | + public function load_core_configuration() { |
|
556 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
557 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
558 | 558 | //load textdomain |
559 | 559 | EE_Load_Textdomain::load_textdomain(); |
560 | 560 | // load and setup EE_Config and EE_Network_Config |
561 | - $this->registry->load_core( 'Config' ); |
|
562 | - $this->registry->load_core( 'Network_Config' ); |
|
561 | + $this->registry->load_core('Config'); |
|
562 | + $this->registry->load_core('Network_Config'); |
|
563 | 563 | // setup autoloaders |
564 | 564 | // enable logging? |
565 | - if ( $this->registry->CFG->admin->use_full_logging ) { |
|
566 | - $this->registry->load_core( 'Log' ); |
|
565 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
566 | + $this->registry->load_core('Log'); |
|
567 | 567 | } |
568 | 568 | // check for activation errors |
569 | - $activation_errors = get_option( 'ee_plugin_activation_errors', FALSE ); |
|
570 | - if ( $activation_errors ) { |
|
571 | - EE_Error::add_error( $activation_errors, __FILE__, __FUNCTION__, __LINE__ ); |
|
572 | - update_option( 'ee_plugin_activation_errors', FALSE ); |
|
569 | + $activation_errors = get_option('ee_plugin_activation_errors', FALSE); |
|
570 | + if ($activation_errors) { |
|
571 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
572 | + update_option('ee_plugin_activation_errors', FALSE); |
|
573 | 573 | } |
574 | 574 | // get model names |
575 | 575 | $this->_parse_model_names(); |
576 | 576 | |
577 | 577 | //load caf stuff a chance to play during the activation process too. |
578 | 578 | $this->_maybe_brew_regular(); |
579 | - do_action( 'AHEE__EE_System__load_core_configuration__complete', $this ); |
|
579 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | |
@@ -585,23 +585,23 @@ discard block |
||
585 | 585 | * |
586 | 586 | * @return void |
587 | 587 | */ |
588 | - private function _parse_model_names(){ |
|
588 | + private function _parse_model_names() { |
|
589 | 589 | //get all the files in the EE_MODELS folder that end in .model.php |
590 | - $models = glob( EE_MODELS.'*.model.php'); |
|
590 | + $models = glob(EE_MODELS.'*.model.php'); |
|
591 | 591 | $model_names = array(); |
592 | 592 | $non_abstract_db_models = array(); |
593 | - foreach( $models as $model ){ |
|
593 | + foreach ($models as $model) { |
|
594 | 594 | // get model classname |
595 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename( $model ); |
|
596 | - $short_name = str_replace( 'EEM_', '', $classname ); |
|
595 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
596 | + $short_name = str_replace('EEM_', '', $classname); |
|
597 | 597 | $reflectionClass = new ReflectionClass($classname); |
598 | - if( $reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()){ |
|
599 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
598 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
599 | + $non_abstract_db_models[$short_name] = $classname; |
|
600 | 600 | } |
601 | - $model_names[ $short_name ] = $classname; |
|
601 | + $model_names[$short_name] = $classname; |
|
602 | 602 | } |
603 | - $this->registry->models = apply_filters( 'FHEE__EE_System__parse_model_names', $model_names ); |
|
604 | - $this->registry->non_abstract_db_models = apply_filters( 'FHEE__EE_System__parse_implemented_model_names', $non_abstract_db_models ); |
|
603 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
604 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', $non_abstract_db_models); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | |
@@ -611,8 +611,8 @@ discard block |
||
611 | 611 | * @return void |
612 | 612 | */ |
613 | 613 | private function _maybe_brew_regular() { |
614 | - if (( ! defined( 'EE_DECAF' ) || EE_DECAF !== TRUE ) && is_readable( EE_CAFF_PATH . 'brewing_regular.php' )) { |
|
615 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
614 | + if (( ! defined('EE_DECAF') || EE_DECAF !== TRUE) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
615 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | |
@@ -629,9 +629,9 @@ discard block |
||
629 | 629 | * @return void |
630 | 630 | */ |
631 | 631 | public function register_shortcodes_modules_and_widgets() { |
632 | - do_action( 'AHEE__EE_System__register_shortcodes_modules_and_widgets' ); |
|
632 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
633 | 633 | // check for addons using old hookpoint |
634 | - if ( has_action( 'AHEE__EE_System__register_shortcodes_modules_and_addons' )) { |
|
634 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
635 | 635 | $this->_incompatible_addon_error(); |
636 | 636 | } |
637 | 637 | } |
@@ -645,19 +645,19 @@ discard block |
||
645 | 645 | */ |
646 | 646 | private function _incompatible_addon_error() { |
647 | 647 | // get array of classes hooking into here |
648 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( 'AHEE__EE_System__register_shortcodes_modules_and_addons' ); |
|
649 | - if ( ! empty( $class_names )) { |
|
650 | - $msg = __( 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', 'event_espresso' ); |
|
648 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
649 | + if ( ! empty($class_names)) { |
|
650 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', 'event_espresso'); |
|
651 | 651 | $msg .= '<ul>'; |
652 | - foreach ( $class_names as $class_name ) { |
|
653 | - $msg .= '<li><b>Event Espresso - ' . str_replace( array( 'EE_', 'EEM_', 'EED_', 'EES_', 'EEW_' ), '', $class_name ) . '</b></li>'; |
|
652 | + foreach ($class_names as $class_name) { |
|
653 | + $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', $class_name).'</b></li>'; |
|
654 | 654 | } |
655 | 655 | $msg .= '</ul>'; |
656 | - $msg .= __( 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', 'event_espresso' ); |
|
656 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', 'event_espresso'); |
|
657 | 657 | // save list of incompatible addons to wp-options for later use |
658 | - add_option( 'ee_incompatible_addons', $class_names, '', 'no' ); |
|
659 | - if ( is_admin() ) { |
|
660 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
658 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
659 | + if (is_admin()) { |
|
660 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
661 | 661 | } |
662 | 662 | } |
663 | 663 | } |
@@ -674,26 +674,26 @@ discard block |
||
674 | 674 | * |
675 | 675 | * @return void |
676 | 676 | */ |
677 | - public function brew_espresso(){ |
|
678 | - do_action( 'AHEE__EE_System__brew_espresso__begin', $this ); |
|
677 | + public function brew_espresso() { |
|
678 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
679 | 679 | // load some final core systems |
680 | - add_action( 'init', array( $this, 'set_hooks_for_core' ), 1 ); |
|
681 | - add_action( 'init', array( $this, 'perform_activations_upgrades_and_migrations' ), 3 ); |
|
682 | - add_action( 'init', array( $this, 'load_CPTs_and_session' ), 5 ); |
|
683 | - add_action( 'init', array( $this, 'load_controllers' ), 7 ); |
|
684 | - add_action( 'init', array( $this, 'core_loaded_and_ready' ), 9 ); |
|
685 | - add_action( 'init', array( $this, 'initialize' ), 10 ); |
|
686 | - add_action( 'init', array( $this, 'initialize_last' ), 100 ); |
|
687 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 25 ); |
|
688 | - add_action('admin_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 25 ); |
|
689 | - add_action( 'admin_bar_menu', array( $this, 'espresso_toolbar_items' ), 100 ); |
|
690 | - |
|
691 | - if ( is_admin() && apply_filters( 'FHEE__EE_System__brew_espresso__load_pue', TRUE ) ) { |
|
680 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
681 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
682 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
683 | + add_action('init', array($this, 'load_controllers'), 7); |
|
684 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
685 | + add_action('init', array($this, 'initialize'), 10); |
|
686 | + add_action('init', array($this, 'initialize_last'), 100); |
|
687 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25); |
|
688 | + add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25); |
|
689 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
690 | + |
|
691 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', TRUE)) { |
|
692 | 692 | // pew pew pew |
693 | - $this->registry->load_core( 'PUE' ); |
|
694 | - do_action( 'AHEE__EE_System__brew_espresso__after_pue_init' ); |
|
693 | + $this->registry->load_core('PUE'); |
|
694 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
695 | 695 | } |
696 | - do_action( 'AHEE__EE_System__brew_espresso__complete', $this ); |
|
696 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | */ |
708 | 708 | public function set_hooks_for_core() { |
709 | 709 | $this->_deactivate_incompatible_addons(); |
710 | - do_action( 'AHEE__EE_System__set_hooks_for_core' ); |
|
710 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | |
@@ -716,15 +716,15 @@ discard block |
||
716 | 716 | * Using the information gathered in EE_System::_incompatible_addon_error, |
717 | 717 | * deactivates any addons considered incompatible with the current version of EE |
718 | 718 | */ |
719 | - private function _deactivate_incompatible_addons(){ |
|
720 | - $incompatible_addons = get_option( 'ee_incompatible_addons', array() ); |
|
721 | - if ( ! empty( $incompatible_addons )) { |
|
722 | - $active_plugins = get_option( 'active_plugins', array() ); |
|
723 | - foreach ( $active_plugins as $active_plugin ) { |
|
724 | - foreach ( $incompatible_addons as $incompatible_addon ) { |
|
725 | - if ( strpos( $active_plugin, $incompatible_addon ) !== FALSE ) { |
|
726 | - unset( $_GET['activate'] ); |
|
727 | - espresso_deactivate_plugin( $active_plugin ); |
|
719 | + private function _deactivate_incompatible_addons() { |
|
720 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
721 | + if ( ! empty($incompatible_addons)) { |
|
722 | + $active_plugins = get_option('active_plugins', array()); |
|
723 | + foreach ($active_plugins as $active_plugin) { |
|
724 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
725 | + if (strpos($active_plugin, $incompatible_addon) !== FALSE) { |
|
726 | + unset($_GET['activate']); |
|
727 | + espresso_deactivate_plugin($active_plugin); |
|
728 | 728 | } |
729 | 729 | } |
730 | 730 | } |
@@ -741,10 +741,10 @@ discard block |
||
741 | 741 | */ |
742 | 742 | public function perform_activations_upgrades_and_migrations() { |
743 | 743 | //first check if we had previously attempted to setup EE's directories but failed |
744 | - if( EEH_Activation::upload_directories_incomplete() ) { |
|
744 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
745 | 745 | EEH_Activation::create_upload_directories(); |
746 | 746 | } |
747 | - do_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations' ); |
|
747 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | |
@@ -756,10 +756,10 @@ discard block |
||
756 | 756 | * @return void |
757 | 757 | */ |
758 | 758 | public function load_CPTs_and_session() { |
759 | - do_action( 'AHEE__EE_System__load_CPTs_and_session__start' ); |
|
759 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
760 | 760 | // register Custom Post Types |
761 | - $this->registry->load_core( 'Register_CPTs' ); |
|
762 | - do_action( 'AHEE__EE_System__load_CPTs_and_session__complete' ); |
|
761 | + $this->registry->load_core('Register_CPTs'); |
|
762 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | |
@@ -774,16 +774,16 @@ discard block |
||
774 | 774 | * @return void |
775 | 775 | */ |
776 | 776 | public function load_controllers() { |
777 | - do_action( 'AHEE__EE_System__load_controllers__start' ); |
|
777 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
778 | 778 | // let's get it started |
779 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level() ) { |
|
780 | - do_action( 'AHEE__EE_System__load_controllers__load_front_controllers' ); |
|
781 | - $this->registry->load_core( 'Front_Controller', array(), false, true ); |
|
782 | - } else if ( ! EE_FRONT_AJAX ) { |
|
783 | - do_action( 'AHEE__EE_System__load_controllers__load_admin_controllers' ); |
|
784 | - EE_Registry::instance()->load_core( 'Admin' ); |
|
779 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
780 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
781 | + $this->registry->load_core('Front_Controller', array(), false, true); |
|
782 | + } else if ( ! EE_FRONT_AJAX) { |
|
783 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
784 | + EE_Registry::instance()->load_core('Admin'); |
|
785 | 785 | } |
786 | - do_action( 'AHEE__EE_System__load_controllers__complete' ); |
|
786 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | |
@@ -797,9 +797,9 @@ discard block |
||
797 | 797 | * @return void |
798 | 798 | */ |
799 | 799 | public function core_loaded_and_ready() { |
800 | - do_action( 'AHEE__EE_System__core_loaded_and_ready' ); |
|
801 | - do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
802 | - $this->registry->load_core( 'Session' ); |
|
800 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
801 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
802 | + $this->registry->load_core('Session'); |
|
803 | 803 | // add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 ); |
804 | 804 | } |
805 | 805 | |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | * @return void |
815 | 815 | */ |
816 | 816 | public function initialize() { |
817 | - do_action( 'AHEE__EE_System__initialize' ); |
|
817 | + do_action('AHEE__EE_System__initialize'); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | * @return void |
829 | 829 | */ |
830 | 830 | public function initialize_last() { |
831 | - do_action( 'AHEE__EE_System__initialize_last' ); |
|
831 | + do_action('AHEE__EE_System__initialize_last'); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | |
@@ -860,21 +860,21 @@ discard block |
||
860 | 860 | */ |
861 | 861 | public static function do_not_cache() { |
862 | 862 | // set no cache constants |
863 | - if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
|
864 | - define( 'DONOTCACHEPAGE', true ); |
|
863 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
864 | + define('DONOTCACHEPAGE', true); |
|
865 | 865 | } |
866 | - if ( ! defined( 'DONOTCACHCEOBJECT' ) ) { |
|
867 | - define( 'DONOTCACHCEOBJECT', true ); |
|
866 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
867 | + define('DONOTCACHCEOBJECT', true); |
|
868 | 868 | } |
869 | - if ( ! defined( 'DONOTCACHEDB' ) ) { |
|
870 | - define( 'DONOTCACHEDB', true ); |
|
869 | + if ( ! defined('DONOTCACHEDB')) { |
|
870 | + define('DONOTCACHEDB', true); |
|
871 | 871 | } |
872 | 872 | // add no cache headers |
873 | - add_action( 'send_headers' , array( 'EE_System', 'nocache_headers' ), 10 ); |
|
873 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
874 | 874 | // plus a little extra for nginx and Google Chrome |
875 | - add_filter( 'nocache_headers', array( 'EE_System', 'extra_nocache_headers' ), 10, 1 ); |
|
875 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
876 | 876 | // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
877 | - remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); |
|
877 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | * @param $headers |
887 | 887 | * @return array |
888 | 888 | */ |
889 | - public static function extra_nocache_headers ( $headers ) { |
|
889 | + public static function extra_nocache_headers($headers) { |
|
890 | 890 | // for NGINX |
891 | 891 | $headers['X-Accel-Expires'] = 0; |
892 | 892 | // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
@@ -915,14 +915,14 @@ discard block |
||
915 | 915 | * @param WP_Admin_Bar $admin_bar |
916 | 916 | * @return void |
917 | 917 | */ |
918 | - public function espresso_toolbar_items( WP_Admin_Bar $admin_bar ) { |
|
918 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) { |
|
919 | 919 | |
920 | 920 | // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
921 | - if ( EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance || defined( 'DOING_AJAX' ) || ! $this->registry->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_top_level' )) { |
|
921 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance || defined('DOING_AJAX') || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')) { |
|
922 | 922 | return; |
923 | 923 | } |
924 | 924 | |
925 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
925 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
926 | 926 | $menu_class = 'espresso_menu_item_class'; |
927 | 927 | //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
928 | 928 | //because they're only defined in each of their respective constructors |
@@ -934,20 +934,20 @@ discard block |
||
934 | 934 | //Top Level |
935 | 935 | $admin_bar->add_menu(array( |
936 | 936 | 'id' => 'espresso-toolbar', |
937 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') . '</span>', |
|
937 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'._x('Event Espresso', 'admin bar menu group label', 'event_espresso').'</span>', |
|
938 | 938 | 'href' => $events_admin_url, |
939 | 939 | 'meta' => array( |
940 | 940 | 'title' => __('Event Espresso', 'event_espresso'), |
941 | - 'class' => $menu_class . 'first' |
|
941 | + 'class' => $menu_class.'first' |
|
942 | 942 | ), |
943 | 943 | )); |
944 | 944 | |
945 | 945 | //Events |
946 | - if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events' ) ) { |
|
946 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
947 | 947 | $admin_bar->add_menu(array( |
948 | 948 | 'id' => 'espresso-toolbar-events', |
949 | 949 | 'parent' => 'espresso-toolbar', |
950 | - 'title' => __( 'Events', 'event_espresso' ), |
|
950 | + 'title' => __('Events', 'event_espresso'), |
|
951 | 951 | 'href' => $events_admin_url, |
952 | 952 | 'meta' => array( |
953 | 953 | 'title' => __('Events', 'event_espresso'), |
@@ -958,13 +958,13 @@ discard block |
||
958 | 958 | } |
959 | 959 | |
960 | 960 | |
961 | - if ( $this->registry->CAP->current_user_can( 'ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new' ) ) { |
|
961 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
962 | 962 | //Events Add New |
963 | 963 | $admin_bar->add_menu(array( |
964 | 964 | 'id' => 'espresso-toolbar-events-new', |
965 | 965 | 'parent' => 'espresso-toolbar-events', |
966 | 966 | 'title' => __('Add New', 'event_espresso'), |
967 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'create_new' ), $events_admin_url ), |
|
967 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'create_new'), $events_admin_url), |
|
968 | 968 | 'meta' => array( |
969 | 969 | 'title' => __('Add New', 'event_espresso'), |
970 | 970 | 'target' => '', |
@@ -973,18 +973,18 @@ discard block |
||
973 | 973 | )); |
974 | 974 | } |
975 | 975 | |
976 | - if ( is_single() && ( get_post_type() == 'espresso_events' ) ) { |
|
976 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
977 | 977 | |
978 | 978 | //Current post |
979 | 979 | global $post; |
980 | 980 | |
981 | - if ( $this->registry->CAP->current_user_can( 'ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID ) ) { |
|
981 | + if ($this->registry->CAP->current_user_can('ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)) { |
|
982 | 982 | //Events Edit Current Event |
983 | 983 | $admin_bar->add_menu(array( |
984 | 984 | 'id' => 'espresso-toolbar-events-edit', |
985 | 985 | 'parent' => 'espresso-toolbar-events', |
986 | 986 | 'title' => __('Edit Event', 'event_espresso'), |
987 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$post->ID ), $events_admin_url ), |
|
987 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'edit', 'post'=>$post->ID), $events_admin_url), |
|
988 | 988 | 'meta' => array( |
989 | 989 | 'title' => __('Edit Event', 'event_espresso'), |
990 | 990 | 'target' => '', |
@@ -996,11 +996,11 @@ discard block |
||
996 | 996 | } |
997 | 997 | |
998 | 998 | //Events View |
999 | - if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-view' ) ) { |
|
999 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-view')) { |
|
1000 | 1000 | $admin_bar->add_menu(array( |
1001 | 1001 | 'id' => 'espresso-toolbar-events-view', |
1002 | 1002 | 'parent' => 'espresso-toolbar-events', |
1003 | - 'title' => __( 'View', 'event_espresso' ), |
|
1003 | + 'title' => __('View', 'event_espresso'), |
|
1004 | 1004 | 'href' => $events_admin_url, |
1005 | 1005 | 'meta' => array( |
1006 | 1006 | 'title' => __('View', 'event_espresso'), |
@@ -1010,12 +1010,12 @@ discard block |
||
1010 | 1010 | )); |
1011 | 1011 | } |
1012 | 1012 | |
1013 | - if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all' ) ) { |
|
1013 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1014 | 1014 | //Events View All |
1015 | 1015 | $admin_bar->add_menu(array( |
1016 | 1016 | 'id' => 'espresso-toolbar-events-all', |
1017 | 1017 | 'parent' => 'espresso-toolbar-events-view', |
1018 | - 'title' => __( 'All', 'event_espresso' ), |
|
1018 | + 'title' => __('All', 'event_espresso'), |
|
1019 | 1019 | 'href' => $events_admin_url, |
1020 | 1020 | 'meta' => array( |
1021 | 1021 | 'title' => __('All', 'event_espresso'), |
@@ -1026,13 +1026,13 @@ discard block |
||
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | |
1029 | - if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-today' ) ) { |
|
1029 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-today')) { |
|
1030 | 1030 | //Events View Today |
1031 | 1031 | $admin_bar->add_menu(array( |
1032 | 1032 | 'id' => 'espresso-toolbar-events-today', |
1033 | 1033 | 'parent' => 'espresso-toolbar-events-view', |
1034 | 1034 | 'title' => __('Today', 'event_espresso'), |
1035 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $events_admin_url ), |
|
1035 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'today'), $events_admin_url), |
|
1036 | 1036 | 'meta' => array( |
1037 | 1037 | 'title' => __('Today', 'event_espresso'), |
1038 | 1038 | 'target' => '', |
@@ -1042,13 +1042,13 @@ discard block |
||
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | |
1045 | - if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-month' ) ) { |
|
1045 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-month')) { |
|
1046 | 1046 | //Events View This Month |
1047 | 1047 | $admin_bar->add_menu(array( |
1048 | 1048 | 'id' => 'espresso-toolbar-events-month', |
1049 | 1049 | 'parent' => 'espresso-toolbar-events-view', |
1050 | - 'title' => __( 'This Month', 'event_espresso'), |
|
1051 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $events_admin_url ), |
|
1050 | + 'title' => __('This Month', 'event_espresso'), |
|
1051 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'month'), $events_admin_url), |
|
1052 | 1052 | 'meta' => array( |
1053 | 1053 | 'title' => __('This Month', 'event_espresso'), |
1054 | 1054 | 'target' => '', |
@@ -1058,11 +1058,11 @@ discard block |
||
1058 | 1058 | } |
1059 | 1059 | |
1060 | 1060 | //Registration Overview |
1061 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations' ) ) { |
|
1061 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations')) { |
|
1062 | 1062 | $admin_bar->add_menu(array( |
1063 | 1063 | 'id' => 'espresso-toolbar-registrations', |
1064 | 1064 | 'parent' => 'espresso-toolbar', |
1065 | - 'title' => __( 'Registrations', 'event_espresso' ), |
|
1065 | + 'title' => __('Registrations', 'event_espresso'), |
|
1066 | 1066 | 'href' => $reg_admin_url, |
1067 | 1067 | 'meta' => array( |
1068 | 1068 | 'title' => __('Registrations', 'event_espresso'), |
@@ -1073,12 +1073,12 @@ discard block |
||
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | //Registration Overview Today |
1076 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today' ) ) { |
|
1076 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today')) { |
|
1077 | 1077 | $admin_bar->add_menu(array( |
1078 | 1078 | 'id' => 'espresso-toolbar-registrations-today', |
1079 | 1079 | 'parent' => 'espresso-toolbar-registrations', |
1080 | - 'title' => __( 'Today', 'event_espresso'), |
|
1081 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $reg_admin_url ), |
|
1080 | + 'title' => __('Today', 'event_espresso'), |
|
1081 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'today'), $reg_admin_url), |
|
1082 | 1082 | 'meta' => array( |
1083 | 1083 | 'title' => __('Today', 'event_espresso'), |
1084 | 1084 | 'target' => '', |
@@ -1088,14 +1088,14 @@ discard block |
||
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | //Registration Overview Today Completed |
1091 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' ) ) { |
|
1091 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')) { |
|
1092 | 1092 | $admin_bar->add_menu(array( |
1093 | 1093 | 'id' => 'espresso-toolbar-registrations-today-approved', |
1094 | 1094 | 'parent' => 'espresso-toolbar-registrations-today', |
1095 | - 'title' => __( 'Approved', 'event_espresso' ), |
|
1096 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ), |
|
1095 | + 'title' => __('Approved', 'event_espresso'), |
|
1096 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_approved), $reg_admin_url), |
|
1097 | 1097 | 'meta' => array( |
1098 | - 'title' => __('Approved', 'event_espresso' ), |
|
1098 | + 'title' => __('Approved', 'event_espresso'), |
|
1099 | 1099 | 'target' => '', |
1100 | 1100 | 'class' => $menu_class |
1101 | 1101 | ), |
@@ -1103,14 +1103,14 @@ discard block |
||
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | //Registration Overview Today Pending\ |
1106 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' ) ) { |
|
1106 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')) { |
|
1107 | 1107 | $admin_bar->add_menu(array( |
1108 | 1108 | 'id' => 'espresso-toolbar-registrations-today-pending', |
1109 | 1109 | 'parent' => 'espresso-toolbar-registrations-today', |
1110 | - 'title' => __( 'Pending', 'event_espresso' ), |
|
1111 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', 'reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ), |
|
1110 | + 'title' => __('Pending', 'event_espresso'), |
|
1111 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'today', 'reg_status'=>EEM_Registration::status_id_pending_payment), $reg_admin_url), |
|
1112 | 1112 | 'meta' => array( |
1113 | - 'title' => __('Pending Payment', 'event_espresso' ), |
|
1113 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1114 | 1114 | 'target' => '', |
1115 | 1115 | 'class' => $menu_class |
1116 | 1116 | ), |
@@ -1118,14 +1118,14 @@ discard block |
||
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | //Registration Overview Today Incomplete |
1121 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' ) ) { |
|
1121 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')) { |
|
1122 | 1122 | $admin_bar->add_menu(array( |
1123 | 1123 | 'id' => 'espresso-toolbar-registrations-today-not-approved', |
1124 | 1124 | 'parent' => 'espresso-toolbar-registrations-today', |
1125 | - 'title' => __( 'Not Approved', 'event_espresso' ), |
|
1126 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ), |
|
1125 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1126 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_not_approved), $reg_admin_url), |
|
1127 | 1127 | 'meta' => array( |
1128 | - 'title' => __('Not Approved', 'event_espresso' ), |
|
1128 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1129 | 1129 | 'target' => '', |
1130 | 1130 | 'class' => $menu_class |
1131 | 1131 | ), |
@@ -1133,12 +1133,12 @@ discard block |
||
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | //Registration Overview Today Incomplete |
1136 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' ) ) { |
|
1136 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')) { |
|
1137 | 1137 | $admin_bar->add_menu(array( |
1138 | 1138 | 'id' => 'espresso-toolbar-registrations-today-cancelled', |
1139 | 1139 | 'parent' => 'espresso-toolbar-registrations-today', |
1140 | - 'title' => __( 'Cancelled', 'event_espresso'), |
|
1141 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ), |
|
1140 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1141 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_cancelled), $reg_admin_url), |
|
1142 | 1142 | 'meta' => array( |
1143 | 1143 | 'title' => __('Cancelled', 'event_espresso'), |
1144 | 1144 | 'target' => '', |
@@ -1148,12 +1148,12 @@ discard block |
||
1148 | 1148 | } |
1149 | 1149 | |
1150 | 1150 | //Registration Overview This Month |
1151 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month' ) ) { |
|
1151 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month')) { |
|
1152 | 1152 | $admin_bar->add_menu(array( |
1153 | 1153 | 'id' => 'espresso-toolbar-registrations-month', |
1154 | 1154 | 'parent' => 'espresso-toolbar-registrations', |
1155 | - 'title' => __( 'This Month', 'event_espresso' ), |
|
1156 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $reg_admin_url ), |
|
1155 | + 'title' => __('This Month', 'event_espresso'), |
|
1156 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'month'), $reg_admin_url), |
|
1157 | 1157 | 'meta' => array( |
1158 | 1158 | 'title' => __('This Month', 'event_espresso'), |
1159 | 1159 | 'target' => '', |
@@ -1163,12 +1163,12 @@ discard block |
||
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | //Registration Overview This Month Approved |
1166 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' ) ) { |
|
1166 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')) { |
|
1167 | 1167 | $admin_bar->add_menu(array( |
1168 | 1168 | 'id' => 'espresso-toolbar-registrations-month-approved', |
1169 | 1169 | 'parent' => 'espresso-toolbar-registrations-month', |
1170 | - 'title' => __( 'Approved', 'event_espresso' ), |
|
1171 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ), |
|
1170 | + 'title' => __('Approved', 'event_espresso'), |
|
1171 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_approved), $reg_admin_url), |
|
1172 | 1172 | 'meta' => array( |
1173 | 1173 | 'title' => __('Approved', 'event_espresso'), |
1174 | 1174 | 'target' => '', |
@@ -1178,12 +1178,12 @@ discard block |
||
1178 | 1178 | } |
1179 | 1179 | |
1180 | 1180 | //Registration Overview This Month Pending |
1181 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' ) ) { |
|
1181 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')) { |
|
1182 | 1182 | $admin_bar->add_menu(array( |
1183 | 1183 | 'id' => 'espresso-toolbar-registrations-month-pending', |
1184 | 1184 | 'parent' => 'espresso-toolbar-registrations-month', |
1185 | - 'title' => __( 'Pending', 'event_espresso'), |
|
1186 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ), |
|
1185 | + 'title' => __('Pending', 'event_espresso'), |
|
1186 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_pending_payment), $reg_admin_url), |
|
1187 | 1187 | 'meta' => array( |
1188 | 1188 | 'title' => __('Pending', 'event_espresso'), |
1189 | 1189 | 'target' => '', |
@@ -1193,14 +1193,14 @@ discard block |
||
1193 | 1193 | } |
1194 | 1194 | |
1195 | 1195 | //Registration Overview This Month Not Approved |
1196 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' ) ) { |
|
1196 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')) { |
|
1197 | 1197 | $admin_bar->add_menu(array( |
1198 | 1198 | 'id' => 'espresso-toolbar-registrations-month-not-approved', |
1199 | 1199 | 'parent' => 'espresso-toolbar-registrations-month', |
1200 | - 'title' => __( 'Not Approved', 'event_espresso'), |
|
1201 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ), |
|
1200 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1201 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_not_approved), $reg_admin_url), |
|
1202 | 1202 | 'meta' => array( |
1203 | - 'title' => __('Not Approved', 'event_espresso' ), |
|
1203 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1204 | 1204 | 'target' => '', |
1205 | 1205 | 'class' => $menu_class |
1206 | 1206 | ), |
@@ -1209,12 +1209,12 @@ discard block |
||
1209 | 1209 | |
1210 | 1210 | |
1211 | 1211 | //Registration Overview This Month Cancelled |
1212 | - if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' ) ) { |
|
1212 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')) { |
|
1213 | 1213 | $admin_bar->add_menu(array( |
1214 | 1214 | 'id' => 'espresso-toolbar-registrations-month-cancelled', |
1215 | 1215 | 'parent' => 'espresso-toolbar-registrations-month', |
1216 | 1216 | 'title' => __('Cancelled', 'event_espresso'), |
1217 | - 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ), |
|
1217 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_cancelled), $reg_admin_url), |
|
1218 | 1218 | 'meta' => array( |
1219 | 1219 | 'title' => __('Cancelled', 'event_espresso'), |
1220 | 1220 | 'target' => '', |
@@ -1224,11 +1224,11 @@ discard block |
||
1224 | 1224 | } |
1225 | 1225 | |
1226 | 1226 | //Extensions & Services |
1227 | - if ( $this->registry->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' ) ) { |
|
1227 | + if ($this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')) { |
|
1228 | 1228 | $admin_bar->add_menu(array( |
1229 | 1229 | 'id' => 'espresso-toolbar-extensions-and-services', |
1230 | 1230 | 'parent' => 'espresso-toolbar', |
1231 | - 'title' => __( 'Extensions & Services', 'event_espresso' ), |
|
1231 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1232 | 1232 | 'href' => $extensions_admin_url, |
1233 | 1233 | 'meta' => array( |
1234 | 1234 | 'title' => __('Extensions & Services', 'event_espresso'), |
@@ -1250,8 +1250,8 @@ discard block |
||
1250 | 1250 | * @param array $exclude_array any existing pages being excluded are in this array. |
1251 | 1251 | * @return array |
1252 | 1252 | */ |
1253 | - public function remove_pages_from_wp_list_pages( $exclude_array ) { |
|
1254 | - return array_merge( $exclude_array, $this->registry->CFG->core->get_critical_pages_array() ); |
|
1253 | + public function remove_pages_from_wp_list_pages($exclude_array) { |
|
1254 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | 1257 | |
@@ -1271,15 +1271,15 @@ discard block |
||
1271 | 1271 | */ |
1272 | 1272 | public function wp_enqueue_scripts() { |
1273 | 1273 | // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
1274 | - if ( apply_filters( 'FHEE_load_EE_System_scripts', TRUE ) ) { |
|
1274 | + if (apply_filters('FHEE_load_EE_System_scripts', TRUE)) { |
|
1275 | 1275 | // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
1276 | - if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) { |
|
1276 | + if (apply_filters('FHEE_load_jquery_validate', FALSE)) { |
|
1277 | 1277 | // register jQuery Validate and additional methods |
1278 | - wp_register_script( 'jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery' ), '1.15.0', TRUE ); |
|
1279 | - wp_register_script( 'jquery-validate-extra-methods', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', array( 'jquery', 'jquery-validate' ), '1.15.0', TRUE ); |
|
1278 | + wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE); |
|
1279 | + wp_register_script('jquery-validate-extra-methods', EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', array('jquery', 'jquery-validate'), '1.15.0', TRUE); |
|
1280 | 1280 | } |
1281 | - wp_register_script( 'select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true ); |
|
1282 | - wp_register_style( 'select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all' ); |
|
1281 | + wp_register_script('select2', EE_GLOBAL_ASSETS_URL.'scripts/select2.min.js', array(), '4.0.2', true); |
|
1282 | + wp_register_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
1283 | 1283 | } |
1284 | 1284 | } |
1285 | 1285 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @since EE4 |
24 | 24 | * |
25 | 25 | */ |
26 | -abstract class EEM_Base extends EE_Base{ |
|
26 | +abstract class EEM_Base extends EE_Base { |
|
27 | 27 | |
28 | 28 | //admin posty |
29 | 29 | //basic -> grants access to mine -> if they don't have it, select none |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * Flag indicating whether this model has a primary key or not |
244 | 244 | * @var boolean |
245 | 245 | */ |
246 | - protected $_has_primary_key_field=null; |
|
246 | + protected $_has_primary_key_field = null; |
|
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -305,19 +305,19 @@ discard block |
||
305 | 305 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
306 | 306 | * @var array |
307 | 307 | */ |
308 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
308 | + protected $_between_style_operators = array('BETWEEN'); |
|
309 | 309 | |
310 | 310 | /** |
311 | 311 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
312 | 312 | * @var array |
313 | 313 | */ |
314 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
314 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
315 | 315 | |
316 | 316 | /** |
317 | 317 | * Allowed values for $query_params['order'] for ordering in queries |
318 | 318 | * @var array |
319 | 319 | */ |
320 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
320 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
321 | 321 | |
322 | 322 | /** |
323 | 323 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -331,13 +331,13 @@ discard block |
||
331 | 331 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
332 | 332 | * @var array |
333 | 333 | */ |
334 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
334 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
335 | 335 | |
336 | 336 | /** |
337 | 337 | * All the data types that can be used in $wpdb->prepare statements. |
338 | 338 | * @var array |
339 | 339 | */ |
340 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
340 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
341 | 341 | |
342 | 342 | /** |
343 | 343 | * EE_Registry Object |
@@ -370,17 +370,17 @@ discard block |
||
370 | 370 | /** |
371 | 371 | * constant used to show EEM_Base has not yet verified the db on this http request |
372 | 372 | */ |
373 | - const db_verified_none = 0; |
|
373 | + const db_verified_none = 0; |
|
374 | 374 | /** |
375 | 375 | * constant used to show EEM_Base has verified the EE core db on this http request, |
376 | 376 | * but not the addons' dbs |
377 | 377 | */ |
378 | - const db_verified_core = 1; |
|
378 | + const db_verified_core = 1; |
|
379 | 379 | /** |
380 | 380 | * constant used to show EEM_Base has verified the addons' dbs (and implicitly |
381 | 381 | * the EE core db too) |
382 | 382 | */ |
383 | - const db_verified_addons = 2; |
|
383 | + const db_verified_addons = 2; |
|
384 | 384 | |
385 | 385 | /** |
386 | 386 | * indicates whether an EEM_Base child has already re-verified the DB |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | * @param null $timezone |
412 | 412 | * @throws \EE_Error |
413 | 413 | */ |
414 | - protected function __construct( $timezone = NULL ){ |
|
414 | + protected function __construct($timezone = NULL) { |
|
415 | 415 | // check that the model has not been loaded too soon |
416 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
417 | - throw new EE_Error ( |
|
416 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
417 | + throw new EE_Error( |
|
418 | 418 | sprintf( |
419 | - __( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ), |
|
420 | - get_class( $this ) |
|
419 | + __('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'), |
|
420 | + get_class($this) |
|
421 | 421 | ) |
422 | 422 | ); |
423 | 423 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | /** |
426 | 426 | * Set blogid for models to current blog. However we ONLY do this if $_model_query_blog_id is not already set. |
427 | 427 | */ |
428 | - if ( empty( EEM_Base::$_model_query_blog_id ) ) { |
|
428 | + if (empty(EEM_Base::$_model_query_blog_id)) { |
|
429 | 429 | EEM_Base::set_model_query_blog_id(); |
430 | 430 | } |
431 | 431 | |
@@ -434,11 +434,11 @@ discard block |
||
434 | 434 | * just use EE_Register_Model_Extension |
435 | 435 | * @var EE_Table_Base[] $_tables |
436 | 436 | */ |
437 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
438 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
437 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
438 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
439 | 439 | /** @var $table_obj EE_Table_Base */ |
440 | 440 | $table_obj->_construct_finalize_with_alias($table_alias); |
441 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
441 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
442 | 442 | /** @var $table_obj EE_Secondary_Table */ |
443 | 443 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
444 | 444 | } |
@@ -448,54 +448,54 @@ discard block |
||
448 | 448 | * EE_Register_Model_Extension |
449 | 449 | * @param EE_Model_Field_Base[] $_fields |
450 | 450 | */ |
451 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
451 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
452 | 452 | $this->_invalidate_field_caches(); |
453 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
454 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
455 | - throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields))); |
|
453 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
454 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
455 | + throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields))); |
|
456 | 456 | } |
457 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
457 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
458 | 458 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
459 | 459 | //primary key field base has a slightly different _construct_finalize |
460 | 460 | /** @var $field_obj EE_Model_Field_Base */ |
461 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
461 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | |
465 | 465 | // everything is related to Extra_Meta |
466 | - if( get_class($this) !== 'EEM_Extra_Meta'){ |
|
466 | + if (get_class($this) !== 'EEM_Extra_Meta') { |
|
467 | 467 | //make extra meta related to everything, but don't block deleting things just |
468 | 468 | //because they have related extra meta info. For now just orphan those extra meta |
469 | 469 | //in the future we should automatically delete them |
470 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
470 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
471 | 471 | } |
472 | 472 | //and change logs |
473 | - if( get_class( $this) !== 'EEM_Change_Log' ) { |
|
474 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
473 | + if (get_class($this) !== 'EEM_Change_Log') { |
|
474 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
475 | 475 | } |
476 | 476 | /** |
477 | 477 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
478 | 478 | * EE_Register_Model_Extension |
479 | 479 | * @param EE_Model_Relation_Base[] $_model_relations |
480 | 480 | */ |
481 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
482 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
481 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
482 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
483 | 483 | /** @var $relation_obj EE_Model_Relation_Base */ |
484 | 484 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
485 | 485 | } |
486 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
486 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
487 | 487 | /** @var $index_obj EE_Index */ |
488 | 488 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
489 | 489 | } |
490 | 490 | |
491 | 491 | $this->set_timezone($timezone); |
492 | 492 | //finalize default where condition strategy, or set default |
493 | - if( ! $this->_default_where_conditions_strategy){ |
|
493 | + if ( ! $this->_default_where_conditions_strategy) { |
|
494 | 494 | //nothing was set during child constructor, so set default |
495 | 495 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
496 | 496 | } |
497 | 497 | $this->_default_where_conditions_strategy->_finalize_construct($this); |
498 | - if( ! $this->_minimum_where_conditions_strategy){ |
|
498 | + if ( ! $this->_minimum_where_conditions_strategy) { |
|
499 | 499 | //nothing was set during child constructor, so set default |
500 | 500 | $this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions(); |
501 | 501 | } |
@@ -503,14 +503,14 @@ discard block |
||
503 | 503 | |
504 | 504 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
505 | 505 | //to indicate to NOT set it, set it to the logical default |
506 | - if( $this->_caps_slug === null ) { |
|
507 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
506 | + if ($this->_caps_slug === null) { |
|
507 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
508 | 508 | } |
509 | 509 | //initialize the standard cap restriction generators if none were specified by the child constructor |
510 | - if( $this->_cap_restriction_generators !== false ){ |
|
511 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
512 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
513 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
510 | + if ($this->_cap_restriction_generators !== false) { |
|
511 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
512 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
513 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
514 | 514 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
515 | 515 | new EE_Restriction_Generator_Protected(), |
516 | 516 | $cap_context, |
@@ -520,23 +520,23 @@ discard block |
||
520 | 520 | } |
521 | 521 | } |
522 | 522 | //if there are cap restriction generators, use them to make the default cap restrictions |
523 | - if( $this->_cap_restriction_generators !== false ){ |
|
524 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
525 | - if( ! $generator_object ){ |
|
523 | + if ($this->_cap_restriction_generators !== false) { |
|
524 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
525 | + if ( ! $generator_object) { |
|
526 | 526 | continue; |
527 | 527 | } |
528 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
528 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
529 | 529 | throw new EE_Error( |
530 | 530 | sprintf( |
531 | - __( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ), |
|
531 | + __('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'), |
|
532 | 532 | $context, |
533 | 533 | $this->get_this_model_name() |
534 | 534 | ) |
535 | 535 | ); |
536 | 536 | } |
537 | - $action = $this->cap_action_for_context( $context ); |
|
538 | - if( ! $generator_object->construction_finalized() ){ |
|
539 | - $generator_object->_construct_finalize( $this, $action ); |
|
537 | + $action = $this->cap_action_for_context($context); |
|
538 | + if ( ! $generator_object->construction_finalized()) { |
|
539 | + $generator_object->_construct_finalize($this, $action); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | } |
@@ -550,11 +550,11 @@ discard block |
||
550 | 550 | * @param string $context one of EEM_Base::valid_cap_contexts() |
551 | 551 | * @return EE_Default_Where_Conditions[] |
552 | 552 | */ |
553 | - protected function _generate_cap_restrictions( $context ){ |
|
554 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
555 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
556 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
557 | - }else{ |
|
553 | + protected function _generate_cap_restrictions($context) { |
|
554 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
555 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
556 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
557 | + } else { |
|
558 | 558 | return array(); |
559 | 559 | } |
560 | 560 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * @param int $blog_id If provided then will set the blog_id for the models to this id. If not provided then the |
567 | 567 | * value for get_current_blog_id() will be used. |
568 | 568 | */ |
569 | - public static function set_model_query_blog_id( $blog_id = 0 ) { |
|
569 | + public static function set_model_query_blog_id($blog_id = 0) { |
|
570 | 570 | EEM_Base::$_model_query_blog_id = $blog_id > 0 ? (int) $blog_id : get_current_blog_id(); |
571 | 571 | } |
572 | 572 | |
@@ -591,16 +591,16 @@ discard block |
||
591 | 591 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
592 | 592 | * @return static (as in the concrete child class) |
593 | 593 | */ |
594 | - public static function instance( $timezone = NULL ){ |
|
594 | + public static function instance($timezone = NULL) { |
|
595 | 595 | |
596 | 596 | // check if instance of Espresso_model already exists |
597 | 597 | if ( ! static::$_instance instanceof static) { |
598 | 598 | // instantiate Espresso_model |
599 | - static::$_instance = new static( $timezone ); |
|
599 | + static::$_instance = new static($timezone); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | //we might have a timezone set, let set_timezone decide what to do with it |
603 | - static::$_instance->set_timezone( $timezone ); |
|
603 | + static::$_instance->set_timezone($timezone); |
|
604 | 604 | |
605 | 605 | // Espresso_model object |
606 | 606 | return static::$_instance; |
@@ -613,11 +613,11 @@ discard block |
||
613 | 613 | * @param null | string $timezone |
614 | 614 | * @return static |
615 | 615 | */ |
616 | - public static function reset( $timezone = NULL ){ |
|
617 | - if ( ! is_null( static::$_instance ) ) { |
|
616 | + public static function reset($timezone = NULL) { |
|
617 | + if ( ! is_null(static::$_instance)) { |
|
618 | 618 | static::$_instance = null; |
619 | 619 | |
620 | - return self::instance( $timezone ); |
|
620 | + return self::instance($timezone); |
|
621 | 621 | } |
622 | 622 | return null; |
623 | 623 | } |
@@ -631,19 +631,19 @@ discard block |
||
631 | 631 | * @return array |
632 | 632 | * @throws \EE_Error |
633 | 633 | */ |
634 | - public function status_array( $translated = FALSE ) { |
|
635 | - if ( ! array_key_exists( 'Status', $this->_model_relations ) ) { |
|
634 | + public function status_array($translated = FALSE) { |
|
635 | + if ( ! array_key_exists('Status', $this->_model_relations)) { |
|
636 | 636 | return array(); |
637 | 637 | } |
638 | 638 | $model_name = $this->get_this_model_name(); |
639 | - $status_type = str_replace( ' ', '_', strtolower( str_replace( '_', ' ', $model_name ) ) ); |
|
640 | - $stati = EEM_Status::instance()->get_all( array( array( 'STS_type' => $status_type ) ) ); |
|
639 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
640 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
641 | 641 | $status_array = array(); |
642 | - foreach ( $stati as $status ) { |
|
643 | - $status_array[ $status->ID() ] = $status->get( 'STS_code' ); |
|
642 | + foreach ($stati as $status) { |
|
643 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
644 | 644 | } |
645 | 645 | return $translated |
646 | - ? EEM_Status::instance()->localized_status( $status_array, false, 'sentence' ) |
|
646 | + ? EEM_Status::instance()->localized_status($status_array, false, 'sentence') |
|
647 | 647 | : $status_array; |
648 | 648 | } |
649 | 649 | |
@@ -776,10 +776,10 @@ discard block |
||
776 | 776 | * )); |
777 | 777 | * @throws \EE_Error |
778 | 778 | */ |
779 | - public function get_all($query_params = array()){ |
|
780 | - if( isset( $query_params[ 'limit' ] ) |
|
781 | - && ! isset( $query_params[ 'group_by' ] ) ) { |
|
782 | - $query_params[ 'group_by' ] = array_keys( $this->get_combined_primary_key_fields() ); |
|
779 | + public function get_all($query_params = array()) { |
|
780 | + if (isset($query_params['limit']) |
|
781 | + && ! isset($query_params['group_by'])) { |
|
782 | + $query_params['group_by'] = array_keys($this->get_combined_primary_key_fields()); |
|
783 | 783 | } |
784 | 784 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
785 | 785 | } |
@@ -790,10 +790,10 @@ discard block |
||
790 | 790 | * @param array $query_params @see EEM_Base::get_all() |
791 | 791 | * @return array like EEM_Base::get_all |
792 | 792 | */ |
793 | - public function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
793 | + public function alter_query_params_to_only_include_mine($query_params = array()) { |
|
794 | 794 | $wp_user_field_name = $this->wp_user_field_name(); |
795 | - if( $wp_user_field_name ){ |
|
796 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
795 | + if ($wp_user_field_name) { |
|
796 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
797 | 797 | } |
798 | 798 | return $query_params; |
799 | 799 | } |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | * foreign key to the WP_User table |
807 | 807 | */ |
808 | 808 | public function wp_user_field_name() { |
809 | - try{ |
|
810 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
811 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
812 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
813 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
814 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
815 | - }else{ |
|
809 | + try { |
|
810 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
811 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
812 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
813 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
814 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
815 | + } else { |
|
816 | 816 | $model_with_fk_to_wp_users = $this; |
817 | 817 | $model_chain_to_wp_user = ''; |
818 | 818 | } |
819 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
820 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
821 | - }catch( EE_Error $e ) { |
|
819 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
820 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
821 | + } catch (EE_Error $e) { |
|
822 | 822 | return false; |
823 | 823 | } |
824 | 824 | } |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | * (or transiently-related model) |
833 | 833 | * @return string |
834 | 834 | */ |
835 | - public function model_chain_to_wp_user(){ |
|
835 | + public function model_chain_to_wp_user() { |
|
836 | 836 | return $this->_model_chain_to_wp_user; |
837 | 837 | } |
838 | 838 | |
@@ -844,13 +844,13 @@ discard block |
||
844 | 844 | * @return boolean |
845 | 845 | */ |
846 | 846 | public function is_owned() { |
847 | - if( $this->model_chain_to_wp_user() ){ |
|
847 | + if ($this->model_chain_to_wp_user()) { |
|
848 | 848 | return true; |
849 | - }else{ |
|
850 | - try{ |
|
851 | - $this->get_foreign_key_to( 'WP_User' ); |
|
849 | + } else { |
|
850 | + try { |
|
851 | + $this->get_foreign_key_to('WP_User'); |
|
852 | 852 | return true; |
853 | - }catch( EE_Error $e ){ |
|
853 | + } catch (EE_Error $e) { |
|
854 | 854 | return false; |
855 | 855 | } |
856 | 856 | } |
@@ -872,17 +872,17 @@ discard block |
||
872 | 872 | * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
873 | 873 | * @throws \EE_Error |
874 | 874 | */ |
875 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
875 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
876 | 876 | // remember the custom selections, if any, and type cast as array |
877 | 877 | // (unless $columns_to_select is an object, then just set as an empty array) |
878 | 878 | // Note: (array) 'some string' === array( 'some string' ) |
879 | - $this->_custom_selections = ! is_object( $columns_to_select ) ? (array) $columns_to_select : array(); |
|
880 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
879 | + $this->_custom_selections = ! is_object($columns_to_select) ? (array) $columns_to_select : array(); |
|
880 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
881 | 881 | $select_expressions = $columns_to_select !== null |
882 | - ? $this->_construct_select_from_input( $columns_to_select ) |
|
883 | - : $this->_construct_default_select_sql( $model_query_info ); |
|
884 | - $SQL = "SELECT $select_expressions " . $this->_construct_2nd_half_of_select_query( $model_query_info ); |
|
885 | - return $this->_do_wpdb_query( 'get_results', array( $SQL, $output ) ); |
|
882 | + ? $this->_construct_select_from_input($columns_to_select) |
|
883 | + : $this->_construct_default_select_sql($model_query_info); |
|
884 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
885 | + return $this->_do_wpdb_query('get_results', array($SQL, $output)); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | /** |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
901 | 901 | * @throws \EE_Error |
902 | 902 | */ |
903 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
903 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
904 | 904 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
905 | 905 | } |
906 | 906 | |
@@ -912,12 +912,12 @@ discard block |
||
912 | 912 | * @throws EE_Error |
913 | 913 | * @return string |
914 | 914 | */ |
915 | - private function _construct_select_from_input($columns_to_select){ |
|
916 | - if(is_array($columns_to_select)){ |
|
915 | + private function _construct_select_from_input($columns_to_select) { |
|
916 | + if (is_array($columns_to_select)) { |
|
917 | 917 | $select_sql_array = array(); |
918 | 918 | |
919 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
920 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
919 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
920 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
921 | 921 | throw new EE_Error( |
922 | 922 | sprintf( |
923 | 923 | __( |
@@ -929,24 +929,24 @@ discard block |
||
929 | 929 | ) |
930 | 930 | ); |
931 | 931 | } |
932 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
932 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
933 | 933 | throw new EE_Error( |
934 | 934 | sprintf( |
935 | 935 | __( |
936 | 936 | "Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", |
937 | 937 | "event_espresso" |
938 | 938 | ), |
939 | - $selection_and_datatype[ 1 ], |
|
940 | - $selection_and_datatype[ 0 ], |
|
939 | + $selection_and_datatype[1], |
|
940 | + $selection_and_datatype[0], |
|
941 | 941 | $alias, |
942 | - implode( ",", $this->_valid_wpdb_data_types ) |
|
942 | + implode(",", $this->_valid_wpdb_data_types) |
|
943 | 943 | ) |
944 | 944 | ); |
945 | 945 | } |
946 | 946 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
947 | 947 | } |
948 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
949 | - }else{ |
|
948 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
949 | + } else { |
|
950 | 950 | $columns_to_select_string = $columns_to_select; |
951 | 951 | } |
952 | 952 | return $columns_to_select_string; |
@@ -961,7 +961,7 @@ discard block |
||
961 | 961 | * @return string |
962 | 962 | * @throws \EE_Error |
963 | 963 | */ |
964 | - public function primary_key_name(){ |
|
964 | + public function primary_key_name() { |
|
965 | 965 | return $this->get_primary_key_field()->get_name(); |
966 | 966 | } |
967 | 967 | |
@@ -973,14 +973,14 @@ discard block |
||
973 | 973 | * @param mixed $id int or string, depending on the type of the model's primary key |
974 | 974 | * @return EE_Base_Class |
975 | 975 | */ |
976 | - public function get_one_by_ID($id){ |
|
977 | - if( $this->get_from_entity_map( $id ) ){ |
|
978 | - return $this->get_from_entity_map( $id ); |
|
976 | + public function get_one_by_ID($id) { |
|
977 | + if ($this->get_from_entity_map($id)) { |
|
978 | + return $this->get_from_entity_map($id); |
|
979 | 979 | } |
980 | 980 | return $this->get_one( |
981 | 981 | $this->alter_query_params_to_restrict_by_ID( |
982 | 982 | $id, |
983 | - array( 'default_where_conditions' => 'minimum' ) |
|
983 | + array('default_where_conditions' => 'minimum') |
|
984 | 984 | ) |
985 | 985 | ); |
986 | 986 | } |
@@ -996,15 +996,15 @@ discard block |
||
996 | 996 | * @return array of normal query params, @see EEM_Base::get_all |
997 | 997 | * @throws \EE_Error |
998 | 998 | */ |
999 | - public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) { |
|
1000 | - if( ! isset( $query_params[ 0 ] ) ) { |
|
1001 | - $query_params[ 0 ] = array(); |
|
999 | + public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) { |
|
1000 | + if ( ! isset($query_params[0])) { |
|
1001 | + $query_params[0] = array(); |
|
1002 | 1002 | } |
1003 | - if( $this->has_primary_key_field ( ) ) { |
|
1004 | - $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
|
1005 | - }else{ |
|
1003 | + if ($this->has_primary_key_field( )) { |
|
1004 | + $query_params[0][$this->primary_key_name()] = $id; |
|
1005 | + } else { |
|
1006 | 1006 | //no primary key, so the $id must be from the get_index_primary_key_string() |
1007 | - $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
|
1007 | + $query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id)); |
|
1008 | 1008 | } |
1009 | 1009 | return $query_params; |
1010 | 1010 | } |
@@ -1019,16 +1019,16 @@ discard block |
||
1019 | 1019 | * @return EE_Base_Class | NULL |
1020 | 1020 | * @throws \EE_Error |
1021 | 1021 | */ |
1022 | - public function get_one($query_params = array()){ |
|
1023 | - if( ! is_array( $query_params ) ){ |
|
1024 | - EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1022 | + public function get_one($query_params = array()) { |
|
1023 | + if ( ! is_array($query_params)) { |
|
1024 | + EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1025 | 1025 | $query_params = array(); |
1026 | 1026 | } |
1027 | 1027 | $query_params['limit'] = 1; |
1028 | 1028 | $items = $this->get_all($query_params); |
1029 | - if(empty($items)){ |
|
1029 | + if (empty($items)) { |
|
1030 | 1030 | return null; |
1031 | - }else{ |
|
1031 | + } else { |
|
1032 | 1032 | return array_shift($items); |
1033 | 1033 | } |
1034 | 1034 | } |
@@ -1051,8 +1051,8 @@ discard block |
||
1051 | 1051 | * @return EE_Base_Class[]|array |
1052 | 1052 | * @throws \EE_Error |
1053 | 1053 | */ |
1054 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1055 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1054 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1055 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | |
@@ -1073,8 +1073,8 @@ discard block |
||
1073 | 1073 | * @return EE_Base_Class[]|array |
1074 | 1074 | * @throws \EE_Error |
1075 | 1075 | */ |
1076 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1077 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1076 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1077 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | |
@@ -1095,9 +1095,9 @@ discard block |
||
1095 | 1095 | * @return EE_Base_Class|null|array() |
1096 | 1096 | * @throws \EE_Error |
1097 | 1097 | */ |
1098 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1099 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1100 | - return empty( $results ) ? null : reset( $results ); |
|
1098 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1099 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1100 | + return empty($results) ? null : reset($results); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | |
@@ -1119,9 +1119,9 @@ discard block |
||
1119 | 1119 | * @return EE_Base_Class|null|array() |
1120 | 1120 | * @throws EE_Error |
1121 | 1121 | */ |
1122 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1123 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1124 | - return empty( $results ) ? null : reset( $results ); |
|
1122 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1123 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1124 | + return empty($results) ? null : reset($results); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | |
@@ -1142,42 +1142,42 @@ discard block |
||
1142 | 1142 | * @return EE_Base_Class[]|array |
1143 | 1143 | * @throws EE_Error |
1144 | 1144 | */ |
1145 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1145 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1146 | 1146 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1147 | - if ( empty( $field_to_order_by ) ) { |
|
1148 | - if ( $this->has_primary_key_field() ) { |
|
1147 | + if (empty($field_to_order_by)) { |
|
1148 | + if ($this->has_primary_key_field()) { |
|
1149 | 1149 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1150 | 1150 | } else { |
1151 | 1151 | |
1152 | - if ( WP_DEBUG ) { |
|
1153 | - throw new EE_Error( __( 'EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso' ) ); |
|
1152 | + if (WP_DEBUG) { |
|
1153 | + throw new EE_Error(__('EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso')); |
|
1154 | 1154 | } |
1155 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1155 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1156 | 1156 | return array(); |
1157 | 1157 | } |
1158 | 1158 | } |
1159 | 1159 | |
1160 | - if( ! is_array( $query_params ) ){ |
|
1161 | - EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1160 | + if ( ! is_array($query_params)) { |
|
1161 | + EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1162 | 1162 | $query_params = array(); |
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | //let's add the where query param for consecutive look up. |
1166 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1166 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1167 | 1167 | $query_params['limit'] = $limit; |
1168 | 1168 | |
1169 | 1169 | //set direction |
1170 | - $incoming_orderby = isset( $query_params['order_by'] ) ? (array)$query_params['order_by'] : array(); |
|
1170 | + $incoming_orderby = isset($query_params['order_by']) ? (array) $query_params['order_by'] : array(); |
|
1171 | 1171 | $query_params['order_by'] = $operand === '>' |
1172 | - ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby |
|
1173 | - : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1172 | + ? array($field_to_order_by => 'ASC') + $incoming_orderby |
|
1173 | + : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1174 | 1174 | |
1175 | 1175 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1176 | - if ( empty( $columns_to_select ) ) { |
|
1177 | - return $this->get_all( $query_params ); |
|
1176 | + if (empty($columns_to_select)) { |
|
1177 | + return $this->get_all($query_params); |
|
1178 | 1178 | } else { |
1179 | 1179 | //getting just the fields |
1180 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1180 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1181 | 1181 | } |
1182 | 1182 | } |
1183 | 1183 | |
@@ -1188,18 +1188,18 @@ discard block |
||
1188 | 1188 | * This sets the _timezone property after model object has been instantiated. |
1189 | 1189 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1190 | 1190 | */ |
1191 | - public function set_timezone( $timezone ) { |
|
1192 | - if ( $timezone !== null ) { |
|
1191 | + public function set_timezone($timezone) { |
|
1192 | + if ($timezone !== null) { |
|
1193 | 1193 | $this->_timezone = $timezone; |
1194 | 1194 | } |
1195 | 1195 | //note we need to loop through relations and set the timezone on those objects as well. |
1196 | - foreach ( $this->_model_relations as $relation ) { |
|
1197 | - $relation->set_timezone( $timezone ); |
|
1196 | + foreach ($this->_model_relations as $relation) { |
|
1197 | + $relation->set_timezone($timezone); |
|
1198 | 1198 | } |
1199 | 1199 | //and finally we do the same for any datetime fields |
1200 | - foreach ( $this->_fields as $field ) { |
|
1201 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1202 | - $field->set_timezone( $timezone ); |
|
1200 | + foreach ($this->_fields as $field) { |
|
1201 | + if ($field instanceof EE_Datetime_Field) { |
|
1202 | + $field->set_timezone($timezone); |
|
1203 | 1203 | } |
1204 | 1204 | } |
1205 | 1205 | } |
@@ -1214,9 +1214,9 @@ discard block |
||
1214 | 1214 | */ |
1215 | 1215 | public function get_timezone() { |
1216 | 1216 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1217 | - if ( empty( $this->_timezone ) ) { |
|
1218 | - foreach( $this->_fields as $field ) { |
|
1219 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1217 | + if (empty($this->_timezone)) { |
|
1218 | + foreach ($this->_fields as $field) { |
|
1219 | + if ($field instanceof EE_Datetime_Field) { |
|
1220 | 1220 | $this->set_timezone($field->get_timezone()); |
1221 | 1221 | break; |
1222 | 1222 | } |
@@ -1224,8 +1224,8 @@ discard block |
||
1224 | 1224 | } |
1225 | 1225 | |
1226 | 1226 | //if timezone STILL empty then return the default timezone for the site. |
1227 | - if ( empty( $this->_timezone ) ) { |
|
1228 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1227 | + if (empty($this->_timezone)) { |
|
1228 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1229 | 1229 | } |
1230 | 1230 | return $this->_timezone; |
1231 | 1231 | } |
@@ -1243,19 +1243,19 @@ discard block |
||
1243 | 1243 | * |
1244 | 1244 | * @return array formats in an array with the date format first, and the time format last. |
1245 | 1245 | */ |
1246 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1247 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1246 | + public function get_formats_for($field_name, $pretty = false) { |
|
1247 | + $field_settings = $this->field_settings_for($field_name); |
|
1248 | 1248 | |
1249 | 1249 | //if not a valid EE_Datetime_Field then throw error |
1250 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1251 | - throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) ); |
|
1250 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1251 | + throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name)); |
|
1252 | 1252 | } |
1253 | 1253 | |
1254 | 1254 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1255 | 1255 | //the field. |
1256 | 1256 | $this->_timezone = $field_settings->get_timezone(); |
1257 | 1257 | |
1258 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1258 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | |
@@ -1279,25 +1279,25 @@ discard block |
||
1279 | 1279 | * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1280 | 1280 | * exception is triggered. |
1281 | 1281 | */ |
1282 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1283 | - $formats = $this->get_formats_for( $field_name ); |
|
1282 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1283 | + $formats = $this->get_formats_for($field_name); |
|
1284 | 1284 | |
1285 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1285 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1286 | 1286 | |
1287 | - if ( $timestamp ) { |
|
1288 | - return $DateTime->format( 'U' ); |
|
1287 | + if ($timestamp) { |
|
1288 | + return $DateTime->format('U'); |
|
1289 | 1289 | } |
1290 | 1290 | |
1291 | 1291 | //not returning timestamp, so return formatted string in timezone. |
1292 | - switch( $what ) { |
|
1292 | + switch ($what) { |
|
1293 | 1293 | case 'time' : |
1294 | - return $DateTime->format( $formats[1] ); |
|
1294 | + return $DateTime->format($formats[1]); |
|
1295 | 1295 | break; |
1296 | 1296 | case 'date' : |
1297 | - return $DateTime->format( $formats[0] ); |
|
1297 | + return $DateTime->format($formats[0]); |
|
1298 | 1298 | break; |
1299 | 1299 | default : |
1300 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1300 | + return $DateTime->format(implode(' ', $formats)); |
|
1301 | 1301 | break; |
1302 | 1302 | } |
1303 | 1303 | } |
@@ -1319,17 +1319,17 @@ discard block |
||
1319 | 1319 | * @return DateTime |
1320 | 1320 | * @throws \EE_Error |
1321 | 1321 | */ |
1322 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1322 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1323 | 1323 | |
1324 | 1324 | //just using this to ensure the timezone is set correctly internally |
1325 | - $this->get_formats_for( $field_name ); |
|
1325 | + $this->get_formats_for($field_name); |
|
1326 | 1326 | |
1327 | 1327 | //load EEH_DTT_Helper |
1328 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1328 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1329 | 1329 | |
1330 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1330 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1331 | 1331 | |
1332 | - return $incomingDateTime->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
1332 | + return $incomingDateTime->setTimezone(new DateTimeZone($this->_timezone)); |
|
1333 | 1333 | } |
1334 | 1334 | |
1335 | 1335 | |
@@ -1339,7 +1339,7 @@ discard block |
||
1339 | 1339 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1340 | 1340 | * @return EE_Table_Base[] |
1341 | 1341 | */ |
1342 | - public function get_tables(){ |
|
1342 | + public function get_tables() { |
|
1343 | 1343 | return $this->_tables; |
1344 | 1344 | } |
1345 | 1345 | |
@@ -1375,9 +1375,9 @@ discard block |
||
1375 | 1375 | * @return int how many rows got updated or FALSE if something went wrong with the query (wp returns FALSE or num rows affected which *could* include 0 which DOES NOT mean the query was bad) |
1376 | 1376 | * @throws \EE_Error |
1377 | 1377 | */ |
1378 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1379 | - if( ! is_array( $query_params ) ){ |
|
1380 | - EE_Error::doing_it_wrong('EEM_Base::update', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1378 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1379 | + if ( ! is_array($query_params)) { |
|
1380 | + EE_Error::doing_it_wrong('EEM_Base::update', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1381 | 1381 | $query_params = array(); |
1382 | 1382 | } |
1383 | 1383 | /** |
@@ -1387,7 +1387,7 @@ discard block |
||
1387 | 1387 | * @param array $fields_n_values the updated fields and their new values |
1388 | 1388 | * @param array $query_params @see EEM_Base::get_all() |
1389 | 1389 | */ |
1390 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1390 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1391 | 1391 | /** |
1392 | 1392 | * Filters the fields about to be updated given the query parameters. You can provide the |
1393 | 1393 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1395,10 +1395,10 @@ discard block |
||
1395 | 1395 | * @param EEM_Base $model the model being queried |
1396 | 1396 | * @param array $query_params see EEM_Base::get_all() |
1397 | 1397 | */ |
1398 | - $fields_n_values = (array)apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1398 | + $fields_n_values = (array) apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1399 | 1399 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1400 | 1400 | //to do that, for each table, verify that it's PK isn't null. |
1401 | - $tables= $this->get_tables(); |
|
1401 | + $tables = $this->get_tables(); |
|
1402 | 1402 | |
1403 | 1403 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1404 | 1404 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1408,29 +1408,29 @@ discard block |
||
1408 | 1408 | //we want to make sure the default_where strategy is ignored |
1409 | 1409 | $this->_ignore_where_strategy = TRUE; |
1410 | 1410 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1411 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1411 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1412 | 1412 | // type cast stdClass as array |
1413 | - $wpdb_result = (array)$wpdb_result; |
|
1413 | + $wpdb_result = (array) $wpdb_result; |
|
1414 | 1414 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1415 | - if( $this->has_primary_key_field() ){ |
|
1416 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1417 | - }else{ |
|
1415 | + if ($this->has_primary_key_field()) { |
|
1416 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1417 | + } else { |
|
1418 | 1418 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1419 | 1419 | $main_table_pk_value = null; |
1420 | 1420 | } |
1421 | 1421 | //if there are more than 1 tables, we'll want to verify that each table for this model has an entry in the other tables |
1422 | 1422 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1423 | - if(count($tables) > 1){ |
|
1423 | + if (count($tables) > 1) { |
|
1424 | 1424 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1425 | 1425 | //in that table, and so we'll want to insert one |
1426 | - foreach($tables as $table_obj){ |
|
1426 | + foreach ($tables as $table_obj) { |
|
1427 | 1427 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1428 | 1428 | //if there is no private key for this table on the results, it means there's no entry |
1429 | 1429 | //in this table, right? so insert a row in the current table, using any fields available |
1430 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1430 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1431 | 1431 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1432 | 1432 | //if we died here, report the error |
1433 | - if( ! $success ) { |
|
1433 | + if ( ! $success) { |
|
1434 | 1434 | return false; |
1435 | 1435 | } |
1436 | 1436 | } |
@@ -1450,44 +1450,44 @@ discard block |
||
1450 | 1450 | //if this wasn't called from a model object (to update itself) |
1451 | 1451 | //then we want to make sure we keep all the existing |
1452 | 1452 | //model objects in sync with the db |
1453 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1454 | - if( $this->has_primary_key_field() ){ |
|
1455 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1456 | - }else{ |
|
1453 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1454 | + if ($this->has_primary_key_field()) { |
|
1455 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1456 | + } else { |
|
1457 | 1457 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1458 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1458 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1459 | 1459 | $model_objs_affected_ids = array(); |
1460 | - foreach( $models_affected_key_columns as $row ){ |
|
1461 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1462 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1460 | + foreach ($models_affected_key_columns as $row) { |
|
1461 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1462 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1463 | 1463 | } |
1464 | 1464 | |
1465 | 1465 | } |
1466 | 1466 | |
1467 | - if( ! $model_objs_affected_ids ){ |
|
1467 | + if ( ! $model_objs_affected_ids) { |
|
1468 | 1468 | //wait wait wait- if nothing was affected let's stop here |
1469 | 1469 | return 0; |
1470 | 1470 | } |
1471 | - foreach( $model_objs_affected_ids as $id ){ |
|
1472 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1473 | - if( $model_obj_in_entity_map ){ |
|
1474 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1475 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1471 | + foreach ($model_objs_affected_ids as $id) { |
|
1472 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1473 | + if ($model_obj_in_entity_map) { |
|
1474 | + foreach ($fields_n_values as $field => $new_value) { |
|
1475 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1476 | 1476 | } |
1477 | 1477 | } |
1478 | 1478 | } |
1479 | 1479 | //if there is a primary key on this model, we can now do a slight optimization |
1480 | - if( $this->has_primary_key_field() ){ |
|
1480 | + if ($this->has_primary_key_field()) { |
|
1481 | 1481 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1482 | 1482 | $query_params = array( |
1483 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1484 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1483 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1484 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1485 | 1485 | } |
1486 | 1486 | } |
1487 | 1487 | |
1488 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1489 | - $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql();//note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1490 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1488 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1489 | + $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql(); //note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1490 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1491 | 1491 | /** |
1492 | 1492 | * Action called after a model update call has been made. |
1493 | 1493 | * |
@@ -1496,8 +1496,8 @@ discard block |
||
1496 | 1496 | * @param array $query_params @see EEM_Base::get_all() |
1497 | 1497 | * @param int $rows_affected |
1498 | 1498 | */ |
1499 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1500 | - return $rows_affected;//how many supposedly got updated |
|
1499 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1500 | + return $rows_affected; //how many supposedly got updated |
|
1501 | 1501 | } |
1502 | 1502 | |
1503 | 1503 | |
@@ -1513,22 +1513,22 @@ discard block |
||
1513 | 1513 | * @return array just like $wpdb->get_col() |
1514 | 1514 | * @throws \EE_Error |
1515 | 1515 | */ |
1516 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1516 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1517 | 1517 | |
1518 | - if( $field_to_select ){ |
|
1519 | - $field = $this->field_settings_for( $field_to_select ); |
|
1520 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1518 | + if ($field_to_select) { |
|
1519 | + $field = $this->field_settings_for($field_to_select); |
|
1520 | + }elseif ($this->has_primary_key_field( )) { |
|
1521 | 1521 | $field = $this->get_primary_key_field(); |
1522 | - }else{ |
|
1522 | + } else { |
|
1523 | 1523 | //no primary key, just grab the first column |
1524 | - $field = reset( $this->field_settings()); |
|
1524 | + $field = reset($this->field_settings()); |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | 1527 | |
1528 | 1528 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1529 | 1529 | $select_expressions = $field->get_qualified_column(); |
1530 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1531 | - return $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1530 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1531 | + return $this->_do_wpdb_query('get_col', array($SQL)); |
|
1532 | 1532 | } |
1533 | 1533 | |
1534 | 1534 | |
@@ -1541,12 +1541,12 @@ discard block |
||
1541 | 1541 | * @return string |
1542 | 1542 | * @throws \EE_Error |
1543 | 1543 | */ |
1544 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1545 | - $query_params[ 'limit' ] = 1; |
|
1546 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1547 | - if( ! empty( $col ) ) { |
|
1548 | - return reset( $col ); |
|
1549 | - }else{ |
|
1544 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1545 | + $query_params['limit'] = 1; |
|
1546 | + $col = $this->get_col($query_params, $field_to_select); |
|
1547 | + if ( ! empty($col)) { |
|
1548 | + return reset($col); |
|
1549 | + } else { |
|
1550 | 1550 | return NULL; |
1551 | 1551 | } |
1552 | 1552 | } |
@@ -1562,19 +1562,19 @@ discard block |
||
1562 | 1562 | * @return string of SQL |
1563 | 1563 | * @throws \EE_Error |
1564 | 1564 | */ |
1565 | - public function _construct_update_sql($fields_n_values){ |
|
1565 | + public function _construct_update_sql($fields_n_values) { |
|
1566 | 1566 | /** @type WPDB $wpdb */ |
1567 | 1567 | global $wpdb; |
1568 | 1568 | $cols_n_values = array(); |
1569 | - foreach($fields_n_values as $field_name => $value){ |
|
1569 | + foreach ($fields_n_values as $field_name => $value) { |
|
1570 | 1570 | $field_obj = $this->field_settings_for($field_name); |
1571 | 1571 | //if the value is NULL, we want to assign the value to that. |
1572 | 1572 | //wpdb->prepare doesn't really handle that properly |
1573 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1574 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1573 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1574 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1575 | 1575 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1576 | 1576 | } |
1577 | - return implode(",",$cols_n_values); |
|
1577 | + return implode(",", $cols_n_values); |
|
1578 | 1578 | |
1579 | 1579 | } |
1580 | 1580 | |
@@ -1590,10 +1590,10 @@ discard block |
||
1590 | 1590 | * @return boolean whether the row got deleted or not |
1591 | 1591 | * @throws \EE_Error |
1592 | 1592 | */ |
1593 | - public function delete_permanently_by_ID( $id ) { |
|
1593 | + public function delete_permanently_by_ID($id) { |
|
1594 | 1594 | return $this->delete_permanently( |
1595 | 1595 | array( |
1596 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1596 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1597 | 1597 | 'limit' => 1 |
1598 | 1598 | ) |
1599 | 1599 | ); |
@@ -1609,10 +1609,10 @@ discard block |
||
1609 | 1609 | * @return boolean whether the row got deleted or not |
1610 | 1610 | * @throws \EE_Error |
1611 | 1611 | */ |
1612 | - public function delete_by_ID( $id ){ |
|
1612 | + public function delete_by_ID($id) { |
|
1613 | 1613 | return $this->delete( |
1614 | 1614 | array( |
1615 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1615 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1616 | 1616 | 'limit' => 1 |
1617 | 1617 | ) |
1618 | 1618 | ); |
@@ -1631,7 +1631,7 @@ discard block |
||
1631 | 1631 | * @return int how many rows got deleted |
1632 | 1632 | * @throws \EE_Error |
1633 | 1633 | */ |
1634 | - public function delete($query_params,$allow_blocking = true){ |
|
1634 | + public function delete($query_params, $allow_blocking = true) { |
|
1635 | 1635 | return $this->delete_permanently($query_params, $allow_blocking); |
1636 | 1636 | } |
1637 | 1637 | |
@@ -1649,7 +1649,7 @@ discard block |
||
1649 | 1649 | * @return int how many rows got deleted |
1650 | 1650 | * @throws \EE_Error |
1651 | 1651 | */ |
1652 | - public function delete_permanently($query_params,$allow_blocking = true){ |
|
1652 | + public function delete_permanently($query_params, $allow_blocking = true) { |
|
1653 | 1653 | /** |
1654 | 1654 | * Action called just before performing a real deletion query. You can use the |
1655 | 1655 | * model and its $query_params to find exactly which items will be deleted |
@@ -1658,31 +1658,31 @@ discard block |
||
1658 | 1658 | * @param boolean $allow_blocking whether or not to allow related model objects |
1659 | 1659 | * to block (prevent) this deletion |
1660 | 1660 | */ |
1661 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1661 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1662 | 1662 | //some MySQL databases may be running safe mode, which may restrict |
1663 | 1663 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1664 | 1664 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1665 | 1665 | //to delete them |
1666 | 1666 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1667 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1668 | - if($deletion_where){ |
|
1667 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1668 | + if ($deletion_where) { |
|
1669 | 1669 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1670 | 1670 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1671 | - $table_aliases = array_keys( $this->_tables ); |
|
1672 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1671 | + $table_aliases = array_keys($this->_tables); |
|
1672 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1673 | 1673 | |
1674 | 1674 | // /echo "delete sql:$SQL"; |
1675 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1676 | - }else{ |
|
1675 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1676 | + } else { |
|
1677 | 1677 | $rows_deleted = 0; |
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1681 | - if( $this->has_primary_key_field() ){ |
|
1682 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1683 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1684 | - if( isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] ) ){ |
|
1685 | - unset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] ); |
|
1681 | + if ($this->has_primary_key_field()) { |
|
1682 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1683 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1684 | + if (isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value])) { |
|
1685 | + unset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value]); |
|
1686 | 1686 | } |
1687 | 1687 | } |
1688 | 1688 | } |
@@ -1694,8 +1694,8 @@ discard block |
||
1694 | 1694 | * @param array $query_params @see EEM_Base::get_all() |
1695 | 1695 | * @param int $rows_deleted |
1696 | 1696 | */ |
1697 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1698 | - return $rows_deleted;//how many supposedly got deleted |
|
1697 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1698 | + return $rows_deleted; //how many supposedly got deleted |
|
1699 | 1699 | } |
1700 | 1700 | |
1701 | 1701 | |
@@ -1713,28 +1713,28 @@ discard block |
||
1713 | 1713 | * @return boolean |
1714 | 1714 | * @throws \EE_Error |
1715 | 1715 | */ |
1716 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1716 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1717 | 1717 | //first, if $ignore_this_model_obj was supplied, get its model |
1718 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1718 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1719 | 1719 | $ignored_model = $ignore_this_model_obj->get_model(); |
1720 | - }else{ |
|
1720 | + } else { |
|
1721 | 1721 | $ignored_model = null; |
1722 | 1722 | } |
1723 | 1723 | //now check all the relations of $this_model_obj_or_id and see if there |
1724 | 1724 | //are any related model objects blocking it? |
1725 | 1725 | $is_blocked = false; |
1726 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1727 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1726 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1727 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1728 | 1728 | //if $ignore_this_model_obj was supplied, then for the query |
1729 | 1729 | //on that model needs to be told to ignore $ignore_this_model_obj |
1730 | - if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){ |
|
1731 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1732 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1733 | - }else{ |
|
1730 | + if ($ignored_model && $relation_name === $ignored_model->get_this_model_name()) { |
|
1731 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1732 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1733 | + } else { |
|
1734 | 1734 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1735 | 1735 | } |
1736 | 1736 | |
1737 | - if($related_model_objects){ |
|
1737 | + if ($related_model_objects) { |
|
1738 | 1738 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1739 | 1739 | $is_blocked = true; |
1740 | 1740 | } |
@@ -1754,71 +1754,71 @@ discard block |
||
1754 | 1754 | * @throws EE_Error |
1755 | 1755 | * @return string everything that comes after the WHERE statement. |
1756 | 1756 | */ |
1757 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1758 | - if($this->has_primary_key_field()){ |
|
1757 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1758 | + if ($this->has_primary_key_field()) { |
|
1759 | 1759 | $primary_table = $this->_get_main_table(); |
1760 | 1760 | $other_tables = $this->_get_other_tables(); |
1761 | 1761 | $deletes = $query = array(); |
1762 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1762 | + foreach ($objects_for_deletion as $delete_object) { |
|
1763 | 1763 | //before we mark this object for deletion, |
1764 | 1764 | //make sure there's no related objects blocking its deletion (if we're checking) |
1765 | 1765 | if ( |
1766 | 1766 | $allow_blocking |
1767 | 1767 | && $this->delete_is_blocked_by_related_models( |
1768 | - $delete_object[ $primary_table->get_fully_qualified_pk_column() ] |
|
1768 | + $delete_object[$primary_table->get_fully_qualified_pk_column()] |
|
1769 | 1769 | ) |
1770 | 1770 | ) { |
1771 | 1771 | continue; |
1772 | 1772 | } |
1773 | 1773 | //primary table deletes |
1774 | - if ( isset( $delete_object[ $primary_table->get_fully_qualified_pk_column() ] ) ) { |
|
1775 | - $deletes[ $primary_table->get_fully_qualified_pk_column() ][] = $delete_object[ $primary_table->get_fully_qualified_pk_column() ]; |
|
1774 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1775 | + $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1776 | 1776 | } |
1777 | 1777 | //other tables |
1778 | - if ( ! empty( $other_tables ) ) { |
|
1779 | - foreach ( $other_tables as $ot ) { |
|
1778 | + if ( ! empty($other_tables)) { |
|
1779 | + foreach ($other_tables as $ot) { |
|
1780 | 1780 | //first check if we've got the foreign key column here. |
1781 | - if ( isset( $delete_object[ $ot->get_fully_qualified_fk_column() ] ) ) { |
|
1782 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_fk_column() ]; |
|
1781 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) { |
|
1782 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1783 | 1783 | } |
1784 | 1784 | // wait! it's entirely possible that we'll have a the primary key |
1785 | 1785 | // for this table in here, if it's a foreign key for one of the other secondary tables |
1786 | - if ( isset( $delete_object[ $ot->get_fully_qualified_pk_column() ] ) ) { |
|
1787 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ]; |
|
1786 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) { |
|
1787 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1788 | 1788 | } |
1789 | 1789 | // finally, it is possible that the fk for this table is found |
1790 | 1790 | // in the fully qualified pk column for the fk table, so let's see if that's there! |
1791 | - if ( isset( $delete_object[ $ot->get_fully_qualified_pk_on_fk_table() ] ) ) { |
|
1792 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ]; |
|
1791 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) { |
|
1792 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1793 | 1793 | } |
1794 | 1794 | } |
1795 | 1795 | } |
1796 | 1796 | } |
1797 | 1797 | |
1798 | 1798 | //we should have deletes now, so let's just go through and setup the where statement |
1799 | - foreach ( $deletes as $column => $values ) { |
|
1799 | + foreach ($deletes as $column => $values) { |
|
1800 | 1800 | //make sure we have unique $values; |
1801 | 1801 | $values = array_unique($values); |
1802 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1802 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1803 | 1803 | } |
1804 | 1804 | |
1805 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1806 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1805 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1806 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1807 | 1807 | $ways_to_identify_a_row = array(); |
1808 | 1808 | $fields = $this->get_combined_primary_key_fields(); |
1809 | 1809 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1810 | - foreach($objects_for_deletion as $delete_object){ |
|
1810 | + foreach ($objects_for_deletion as $delete_object) { |
|
1811 | 1811 | $values_for_each_cpk_for_a_row = array(); |
1812 | - foreach($fields as $cpk_field){ |
|
1812 | + foreach ($fields as $cpk_field) { |
|
1813 | 1813 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()]; |
1814 | 1814 | } |
1815 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1815 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1816 | 1816 | } |
1817 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1818 | - }else{ |
|
1817 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1818 | + } else { |
|
1819 | 1819 | //so there's no primary key and no combined key... |
1820 | 1820 | //sorry, can't help you |
1821 | - throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
|
1821 | + throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"), get_class($this))); |
|
1822 | 1822 | } |
1823 | 1823 | } |
1824 | 1824 | |
@@ -1834,21 +1834,21 @@ discard block |
||
1834 | 1834 | * @return int |
1835 | 1835 | * @throws \EE_Error |
1836 | 1836 | */ |
1837 | - public function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1837 | + public function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1838 | 1838 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1839 | - if($field_to_count){ |
|
1839 | + if ($field_to_count) { |
|
1840 | 1840 | $field_obj = $this->field_settings_for($field_to_count); |
1841 | 1841 | $column_to_count = $field_obj->get_qualified_column(); |
1842 | - }elseif($this->has_primary_key_field ()){ |
|
1842 | + }elseif ($this->has_primary_key_field()) { |
|
1843 | 1843 | $pk_field_obj = $this->get_primary_key_field(); |
1844 | 1844 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1845 | - }else{//there's no primary key |
|
1845 | + } else {//there's no primary key |
|
1846 | 1846 | $column_to_count = '*'; |
1847 | 1847 | } |
1848 | 1848 | |
1849 | - $column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count; |
|
1850 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1851 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1849 | + $column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count; |
|
1850 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1851 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1852 | 1852 | } |
1853 | 1853 | |
1854 | 1854 | |
@@ -1861,24 +1861,24 @@ discard block |
||
1861 | 1861 | * @return float |
1862 | 1862 | * @throws \EE_Error |
1863 | 1863 | */ |
1864 | - public function sum($query_params, $field_to_sum = NULL){ |
|
1864 | + public function sum($query_params, $field_to_sum = NULL) { |
|
1865 | 1865 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1866 | 1866 | |
1867 | - if($field_to_sum){ |
|
1867 | + if ($field_to_sum) { |
|
1868 | 1868 | $field_obj = $this->field_settings_for($field_to_sum); |
1869 | 1869 | |
1870 | - }else{ |
|
1870 | + } else { |
|
1871 | 1871 | $field_obj = $this->get_primary_key_field(); |
1872 | 1872 | } |
1873 | 1873 | $column_to_count = $field_obj->get_qualified_column(); |
1874 | 1874 | |
1875 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1876 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1875 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1876 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1877 | 1877 | $data_type = $field_obj->get_wpdb_data_type(); |
1878 | - if( $data_type === '%d' || $data_type === '%s' ){ |
|
1879 | - return (float)$return_value; |
|
1880 | - }else{//must be %f |
|
1881 | - return (float)$return_value; |
|
1878 | + if ($data_type === '%d' || $data_type === '%s') { |
|
1879 | + return (float) $return_value; |
|
1880 | + } else {//must be %f |
|
1881 | + return (float) $return_value; |
|
1882 | 1882 | } |
1883 | 1883 | } |
1884 | 1884 | |
@@ -1893,37 +1893,37 @@ discard block |
||
1893 | 1893 | * @global wpdb $wpdb |
1894 | 1894 | * @return mixed |
1895 | 1895 | */ |
1896 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1896 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1897 | 1897 | //if we're in maintenance mode level 2, DON'T run any queries |
1898 | 1898 | //because level 2 indicates the database needs updating and |
1899 | 1899 | //is probably out of sync with the code |
1900 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1900 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1901 | 1901 | throw new EE_Error(sprintf(__("Event Espresso Level 2 Maintenance mode is active. That means EE can not run ANY database queries until the necessary migration scripts have run which will take EE out of maintenance mode level 2. Please inform support of this error.", "event_espresso"))); |
1902 | 1902 | } |
1903 | 1903 | /** @type WPDB $wpdb */ |
1904 | 1904 | global $wpdb; |
1905 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1906 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1905 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1906 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1907 | 1907 | } |
1908 | - if( WP_DEBUG ){ |
|
1908 | + if (WP_DEBUG) { |
|
1909 | 1909 | $old_show_errors_value = $wpdb->show_errors; |
1910 | - $wpdb->show_errors( FALSE ); |
|
1911 | - } |
|
1912 | - $result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1913 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1914 | - if( WP_DEBUG ){ |
|
1915 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1916 | - if( ! empty( $wpdb->last_error ) ){ |
|
1917 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1918 | - }elseif( $result === false ){ |
|
1919 | - throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
|
1910 | + $wpdb->show_errors(FALSE); |
|
1911 | + } |
|
1912 | + $result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1913 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1914 | + if (WP_DEBUG) { |
|
1915 | + $wpdb->show_errors($old_show_errors_value); |
|
1916 | + if ( ! empty($wpdb->last_error)) { |
|
1917 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1918 | + }elseif ($result === false) { |
|
1919 | + throw new EE_Error(sprintf(__('WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso'), $wpdb_method, var_export($arguments_to_provide, true))); |
|
1920 | 1920 | } |
1921 | - }elseif( $result === false ) { |
|
1921 | + }elseif ($result === false) { |
|
1922 | 1922 | EE_Error::add_error( |
1923 | 1923 | sprintf( |
1924 | - __( 'A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso' ), |
|
1924 | + __('A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso'), |
|
1925 | 1925 | $wpdb_method, |
1926 | - var_export( $arguments_to_provide, true ), |
|
1926 | + var_export($arguments_to_provide, true), |
|
1927 | 1927 | $wpdb->last_error |
1928 | 1928 | ), |
1929 | 1929 | __FILE__, |
@@ -1945,26 +1945,26 @@ discard block |
||
1945 | 1945 | * @param array $arguments_to_provide |
1946 | 1946 | * @return mixed |
1947 | 1947 | */ |
1948 | - private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) { |
|
1948 | + private function _process_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1949 | 1949 | /** @type WPDB $wpdb */ |
1950 | 1950 | global $wpdb; |
1951 | 1951 | $wpdb->last_error = null; |
1952 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide ); |
|
1952 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1953 | 1953 | // was there an error running the query? but we don't care on new activations |
1954 | 1954 | // (we're going to setup the DB anyway on new activations) |
1955 | - if ( ( $result === false || ! empty( $wpdb->last_error ) ) |
|
1955 | + if (($result === false || ! empty($wpdb->last_error)) |
|
1956 | 1956 | && EE_System::instance()->detect_req_type() !== EE_System::req_type_new_activation |
1957 | 1957 | ) { |
1958 | - switch ( EEM_Base::$_db_verification_level ) { |
|
1958 | + switch (EEM_Base::$_db_verification_level) { |
|
1959 | 1959 | |
1960 | 1960 | case EEM_Base::db_verified_none : |
1961 | 1961 | // let's double-check core's DB |
1962 | - $error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide ); |
|
1962 | + $error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide); |
|
1963 | 1963 | break; |
1964 | 1964 | |
1965 | 1965 | case EEM_Base::db_verified_core : |
1966 | 1966 | // STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed |
1967 | - $error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide ); |
|
1967 | + $error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide); |
|
1968 | 1968 | break; |
1969 | 1969 | |
1970 | 1970 | case EEM_Base::db_verified_addons : |
@@ -1972,11 +1972,11 @@ discard block |
||
1972 | 1972 | return $result; |
1973 | 1973 | break; |
1974 | 1974 | } |
1975 | - if ( ! empty( $error_message ) ) { |
|
1976 | - EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' ); |
|
1977 | - trigger_error( $error_message ); |
|
1975 | + if ( ! empty($error_message)) { |
|
1976 | + EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error'); |
|
1977 | + trigger_error($error_message); |
|
1978 | 1978 | } |
1979 | - return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1979 | + return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1980 | 1980 | |
1981 | 1981 | } |
1982 | 1982 | |
@@ -1992,18 +1992,18 @@ discard block |
||
1992 | 1992 | * @param array $arguments_to_provide |
1993 | 1993 | * @return string |
1994 | 1994 | */ |
1995 | - private function _verify_core_db( $wpdb_method, $arguments_to_provide ){ |
|
1995 | + private function _verify_core_db($wpdb_method, $arguments_to_provide) { |
|
1996 | 1996 | /** @type WPDB $wpdb */ |
1997 | 1997 | global $wpdb; |
1998 | 1998 | //ok remember that we've already attempted fixing the core db, in case the problem persists |
1999 | 1999 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_core; |
2000 | 2000 | $error_message = sprintf( |
2001 | - __( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ), |
|
2001 | + __('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'), |
|
2002 | 2002 | $wpdb->last_error, |
2003 | 2003 | $wpdb_method, |
2004 | - json_encode( $arguments_to_provide ) |
|
2004 | + json_encode($arguments_to_provide) |
|
2005 | 2005 | ); |
2006 | - EE_System::instance()->initialize_db_if_no_migrations_required( false, true ); |
|
2006 | + EE_System::instance()->initialize_db_if_no_migrations_required(false, true); |
|
2007 | 2007 | return $error_message; |
2008 | 2008 | } |
2009 | 2009 | |
@@ -2016,16 +2016,16 @@ discard block |
||
2016 | 2016 | * @param $arguments_to_provide |
2017 | 2017 | * @return string |
2018 | 2018 | */ |
2019 | - private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) { |
|
2019 | + private function _verify_addons_db($wpdb_method, $arguments_to_provide) { |
|
2020 | 2020 | /** @type WPDB $wpdb */ |
2021 | 2021 | global $wpdb; |
2022 | 2022 | //ok remember that we've already attempted fixing the addons dbs, in case the problem persists |
2023 | 2023 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons; |
2024 | 2024 | $error_message = sprintf( |
2025 | - __( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ), |
|
2025 | + __('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), |
|
2026 | 2026 | $wpdb->last_error, |
2027 | 2027 | $wpdb_method, |
2028 | - json_encode( $arguments_to_provide ) |
|
2028 | + json_encode($arguments_to_provide) |
|
2029 | 2029 | ); |
2030 | 2030 | EE_System::instance()->initialize_addons(); |
2031 | 2031 | return $error_message; |
@@ -2040,7 +2040,7 @@ discard block |
||
2040 | 2040 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2041 | 2041 | * @return string |
2042 | 2042 | */ |
2043 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2043 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2044 | 2044 | return " FROM ".$model_query_info->get_full_join_sql(). |
2045 | 2045 | $model_query_info->get_where_sql(). |
2046 | 2046 | $model_query_info->get_group_by_sql(). |
@@ -2053,7 +2053,7 @@ discard block |
||
2053 | 2053 | * Set to easily debug the next X queries ran from this model. |
2054 | 2054 | * @param int $count |
2055 | 2055 | */ |
2056 | - public function show_next_x_db_queries($count = 1){ |
|
2056 | + public function show_next_x_db_queries($count = 1) { |
|
2057 | 2057 | $this->_show_next_x_db_queries = $count; |
2058 | 2058 | } |
2059 | 2059 | |
@@ -2062,8 +2062,8 @@ discard block |
||
2062 | 2062 | /** |
2063 | 2063 | * @param $sql_query |
2064 | 2064 | */ |
2065 | - public function show_db_query_if_previously_requested($sql_query){ |
|
2066 | - if($this->_show_next_x_db_queries > 0){ |
|
2065 | + public function show_db_query_if_previously_requested($sql_query) { |
|
2066 | + if ($this->_show_next_x_db_queries > 0) { |
|
2067 | 2067 | echo $sql_query; |
2068 | 2068 | $this->_show_next_x_db_queries--; |
2069 | 2069 | } |
@@ -2087,9 +2087,9 @@ discard block |
||
2087 | 2087 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
2088 | 2088 | * @throws \EE_Error |
2089 | 2089 | */ |
2090 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
2090 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
2091 | 2091 | $relation_obj = $this->related_settings_for($relationName); |
2092 | - return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2092 | + return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2093 | 2093 | } |
2094 | 2094 | |
2095 | 2095 | |
@@ -2108,9 +2108,9 @@ discard block |
||
2108 | 2108 | * @throws \EE_Error |
2109 | 2109 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
2110 | 2110 | */ |
2111 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
2111 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
2112 | 2112 | $relation_obj = $this->related_settings_for($relationName); |
2113 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
2113 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
2114 | 2114 | } |
2115 | 2115 | |
2116 | 2116 | |
@@ -2123,9 +2123,9 @@ discard block |
||
2123 | 2123 | * @return \EE_Base_Class[] |
2124 | 2124 | * @throws \EE_Error |
2125 | 2125 | */ |
2126 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
2126 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
2127 | 2127 | $relation_obj = $this->related_settings_for($relationName); |
2128 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
2128 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
2129 | 2129 | } |
2130 | 2130 | |
2131 | 2131 | |
@@ -2141,10 +2141,10 @@ discard block |
||
2141 | 2141 | * @return EE_Base_Class[] |
2142 | 2142 | * @throws \EE_Error |
2143 | 2143 | */ |
2144 | - public function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
2144 | + public function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
2145 | 2145 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2146 | 2146 | $relation_settings = $this->related_settings_for($model_name); |
2147 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
2147 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
2148 | 2148 | } |
2149 | 2149 | |
2150 | 2150 | |
@@ -2161,10 +2161,10 @@ discard block |
||
2161 | 2161 | * @return int how many deleted |
2162 | 2162 | * @throws \EE_Error |
2163 | 2163 | */ |
2164 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
2164 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
2165 | 2165 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2166 | 2166 | $relation_settings = $this->related_settings_for($model_name); |
2167 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
2167 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
2168 | 2168 | } |
2169 | 2169 | |
2170 | 2170 | |
@@ -2181,10 +2181,10 @@ discard block |
||
2181 | 2181 | * @return int how many deleted |
2182 | 2182 | * @throws \EE_Error |
2183 | 2183 | */ |
2184 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
2184 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
2185 | 2185 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2186 | 2186 | $relation_settings = $this->related_settings_for($model_name); |
2187 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
2187 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
2188 | 2188 | } |
2189 | 2189 | |
2190 | 2190 | |
@@ -2201,17 +2201,17 @@ discard block |
||
2201 | 2201 | * @return int |
2202 | 2202 | * @throws \EE_Error |
2203 | 2203 | */ |
2204 | - public function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
2204 | + public function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
2205 | 2205 | $related_model = $this->get_related_model_obj($model_name); |
2206 | 2206 | //we're just going to use the query params on the related model's normal get_all query, |
2207 | 2207 | //except add a condition to say to match the current mod |
2208 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2209 | - $query_params['default_where_conditions']='none'; |
|
2208 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2209 | + $query_params['default_where_conditions'] = 'none'; |
|
2210 | 2210 | } |
2211 | 2211 | $this_model_name = $this->get_this_model_name(); |
2212 | 2212 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2213 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2214 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
2213 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2214 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
2215 | 2215 | } |
2216 | 2216 | |
2217 | 2217 | |
@@ -2227,21 +2227,21 @@ discard block |
||
2227 | 2227 | * @return float |
2228 | 2228 | * @throws \EE_Error |
2229 | 2229 | */ |
2230 | - public function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
2230 | + public function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
2231 | 2231 | $related_model = $this->get_related_model_obj($model_name); |
2232 | - if( ! is_array( $query_params ) ){ |
|
2233 | - EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2232 | + if ( ! is_array($query_params)) { |
|
2233 | + EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2234 | 2234 | $query_params = array(); |
2235 | 2235 | } |
2236 | 2236 | //we're just going to use the query params on the related model's normal get_all query, |
2237 | 2237 | //except add a condition to say to match the current mod |
2238 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2239 | - $query_params['default_where_conditions']='none'; |
|
2238 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2239 | + $query_params['default_where_conditions'] = 'none'; |
|
2240 | 2240 | } |
2241 | 2241 | $this_model_name = $this->get_this_model_name(); |
2242 | 2242 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2243 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2244 | - return $related_model->sum($query_params,$field_to_sum); |
|
2243 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2244 | + return $related_model->sum($query_params, $field_to_sum); |
|
2245 | 2245 | } |
2246 | 2246 | |
2247 | 2247 | |
@@ -2255,12 +2255,12 @@ discard block |
||
2255 | 2255 | * @return EE_Base_Class |
2256 | 2256 | * @throws \EE_Error |
2257 | 2257 | */ |
2258 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
2259 | - $query_params['limit']=1; |
|
2260 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
2261 | - if( $results ){ |
|
2258 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
2259 | + $query_params['limit'] = 1; |
|
2260 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
2261 | + if ($results) { |
|
2262 | 2262 | return array_shift($results); |
2263 | - }else{ |
|
2263 | + } else { |
|
2264 | 2264 | return null; |
2265 | 2265 | } |
2266 | 2266 | |
@@ -2270,8 +2270,8 @@ discard block |
||
2270 | 2270 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
2271 | 2271 | * @return string |
2272 | 2272 | */ |
2273 | - public function get_this_model_name(){ |
|
2274 | - return str_replace("EEM_","",get_class($this)); |
|
2273 | + public function get_this_model_name() { |
|
2274 | + return str_replace("EEM_", "", get_class($this)); |
|
2275 | 2275 | } |
2276 | 2276 | |
2277 | 2277 | /** |
@@ -2279,14 +2279,14 @@ discard block |
||
2279 | 2279 | * @return EE_Any_Foreign_Model_Name_Field |
2280 | 2280 | * @throws EE_Error |
2281 | 2281 | */ |
2282 | - public function get_field_containing_related_model_name(){ |
|
2283 | - foreach($this->field_settings(true) as $field){ |
|
2284 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
2282 | + public function get_field_containing_related_model_name() { |
|
2283 | + foreach ($this->field_settings(true) as $field) { |
|
2284 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
2285 | 2285 | $field_with_model_name = $field; |
2286 | 2286 | } |
2287 | 2287 | } |
2288 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
2289 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
2288 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
2289 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
2290 | 2290 | } |
2291 | 2291 | return $field_with_model_name; |
2292 | 2292 | } |
@@ -2307,19 +2307,19 @@ discard block |
||
2307 | 2307 | * @return int new primary key on main table that got inserted |
2308 | 2308 | * @throws EE_Error |
2309 | 2309 | */ |
2310 | - public function insert($field_n_values){ |
|
2310 | + public function insert($field_n_values) { |
|
2311 | 2311 | /** |
2312 | 2312 | * Filters the fields and their values before inserting an item using the models |
2313 | 2313 | * @param array $fields_n_values keys are the fields and values are their new values |
2314 | 2314 | * @param EEM_Base $model the model used |
2315 | 2315 | */ |
2316 | - $field_n_values = (array)apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2317 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2316 | + $field_n_values = (array) apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2317 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2318 | 2318 | $main_table = $this->_get_main_table(); |
2319 | 2319 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2320 | - if( $new_id !== false ) { |
|
2321 | - foreach($this->_get_other_tables() as $other_table){ |
|
2322 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2320 | + if ($new_id !== false) { |
|
2321 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2322 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2323 | 2323 | } |
2324 | 2324 | } |
2325 | 2325 | /** |
@@ -2329,9 +2329,9 @@ discard block |
||
2329 | 2329 | * @param array $fields_n_values fields and their values |
2330 | 2330 | * @param int|string the ID of the newly-inserted model object |
2331 | 2331 | */ |
2332 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2332 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2333 | 2333 | return $new_id; |
2334 | - }else{ |
|
2334 | + } else { |
|
2335 | 2335 | return FALSE; |
2336 | 2336 | } |
2337 | 2337 | } |
@@ -2346,10 +2346,10 @@ discard block |
||
2346 | 2346 | * @return boolean |
2347 | 2347 | * @throws \EE_Error |
2348 | 2348 | */ |
2349 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2350 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2349 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2350 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2351 | 2351 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2352 | - if($this->exists(array($uniqueness_where_params))){ |
|
2352 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2353 | 2353 | EE_Error::add_error( |
2354 | 2354 | sprintf( |
2355 | 2355 | __( |
@@ -2359,8 +2359,8 @@ discard block |
||
2359 | 2359 | $action, |
2360 | 2360 | $this->_get_class_name(), |
2361 | 2361 | $index_name, |
2362 | - implode( ",", $index->field_names() ), |
|
2363 | - http_build_query( $uniqueness_where_params ) |
|
2362 | + implode(",", $index->field_names()), |
|
2363 | + http_build_query($uniqueness_where_params) |
|
2364 | 2364 | ), |
2365 | 2365 | __FILE__, |
2366 | 2366 | __FUNCTION__, |
@@ -2386,37 +2386,37 @@ discard block |
||
2386 | 2386 | * @throws EE_Error |
2387 | 2387 | * @return EE_Base_Class |
2388 | 2388 | */ |
2389 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2390 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2389 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2390 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2391 | 2391 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2392 | - }elseif( is_array($obj_or_fields_array)){ |
|
2392 | + }elseif (is_array($obj_or_fields_array)) { |
|
2393 | 2393 | $fields_n_values = $obj_or_fields_array; |
2394 | - }else{ |
|
2394 | + } else { |
|
2395 | 2395 | throw new EE_Error( |
2396 | 2396 | sprintf( |
2397 | 2397 | __( |
2398 | 2398 | "%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", |
2399 | 2399 | "event_espresso" |
2400 | 2400 | ), |
2401 | - get_class( $this ), |
|
2401 | + get_class($this), |
|
2402 | 2402 | $obj_or_fields_array |
2403 | 2403 | ) |
2404 | 2404 | ); |
2405 | 2405 | } |
2406 | 2406 | $query_params = array(); |
2407 | - if( $this->has_primary_key_field() && |
|
2408 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2409 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2407 | + if ($this->has_primary_key_field() && |
|
2408 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2409 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2410 | 2410 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2411 | 2411 | } |
2412 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2412 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2413 | 2413 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2414 | 2414 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2415 | 2415 | } |
2416 | 2416 | //if there is nothing to base this search on, then we shouldn't find anything |
2417 | - if( empty( $query_params ) ){ |
|
2417 | + if (empty($query_params)) { |
|
2418 | 2418 | return array(); |
2419 | - }else{ |
|
2419 | + } else { |
|
2420 | 2420 | return $this->get_one($query_params); |
2421 | 2421 | } |
2422 | 2422 | } |
@@ -2430,7 +2430,7 @@ discard block |
||
2430 | 2430 | * @return boolean |
2431 | 2431 | * @throws \EE_Error |
2432 | 2432 | */ |
2433 | - public function exists($query_params){ |
|
2433 | + public function exists($query_params) { |
|
2434 | 2434 | $query_params['limit'] = 1; |
2435 | 2435 | return $this->count($query_params) > 0; |
2436 | 2436 | } |
@@ -2444,7 +2444,7 @@ discard block |
||
2444 | 2444 | * @return boolean |
2445 | 2445 | * @throws \EE_Error |
2446 | 2446 | */ |
2447 | - public function exists_by_ID($id){ |
|
2447 | + public function exists_by_ID($id) { |
|
2448 | 2448 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2449 | 2449 | } |
2450 | 2450 | |
@@ -2464,45 +2464,45 @@ discard block |
||
2464 | 2464 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2465 | 2465 | * @return int ID of new row inserted, or FALSE on failure |
2466 | 2466 | */ |
2467 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2467 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2468 | 2468 | global $wpdb; |
2469 | 2469 | $insertion_col_n_values = array(); |
2470 | 2470 | $format_for_insertion = array(); |
2471 | 2471 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2472 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2472 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2473 | 2473 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2474 | - if($field_obj->is_auto_increment()){ |
|
2474 | + if ($field_obj->is_auto_increment()) { |
|
2475 | 2475 | continue; |
2476 | 2476 | } |
2477 | 2477 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2478 | 2478 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2479 | - if( $prepared_value !== NULL ){ |
|
2480 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2479 | + if ($prepared_value !== NULL) { |
|
2480 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2481 | 2481 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2482 | 2482 | } |
2483 | 2483 | } |
2484 | 2484 | |
2485 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2485 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2486 | 2486 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2487 | 2487 | //so add the fk to the main table as a column |
2488 | 2488 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2489 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2489 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2490 | 2490 | } |
2491 | 2491 | //insert the new entry |
2492 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2493 | - if( $result === false ) { |
|
2492 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2493 | + if ($result === false) { |
|
2494 | 2494 | return false; |
2495 | 2495 | } |
2496 | 2496 | //ok, now what do we return for the ID of the newly-inserted thing? |
2497 | - if($this->has_primary_key_field()){ |
|
2498 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2497 | + if ($this->has_primary_key_field()) { |
|
2498 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2499 | 2499 | return $wpdb->insert_id; |
2500 | - }else{ |
|
2500 | + } else { |
|
2501 | 2501 | //it's not an auto-increment primary key, so |
2502 | 2502 | //it must have been supplied |
2503 | 2503 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2504 | 2504 | } |
2505 | - }else{ |
|
2505 | + } else { |
|
2506 | 2506 | //we can't return a primary key because there is none. instead return |
2507 | 2507 | //a unique string indicating this model |
2508 | 2508 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2521,15 +2521,15 @@ discard block |
||
2521 | 2521 | * @return mixed string|int|float depending on what the table column will be expecting |
2522 | 2522 | * @throws \EE_Error |
2523 | 2523 | */ |
2524 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2524 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2525 | 2525 | //if this field doesn't allow nullable, don't allow it |
2526 | - if( ! $field_obj->is_nullable() && ( |
|
2527 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2528 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2529 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2526 | + if ( ! $field_obj->is_nullable() && ( |
|
2527 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2528 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2529 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2530 | 2530 | } |
2531 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2532 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2531 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2532 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2533 | 2533 | } |
2534 | 2534 | |
2535 | 2535 | |
@@ -2541,9 +2541,9 @@ discard block |
||
2541 | 2541 | * @param EE_Model_Field_Base $field field which will be doing the preparing of the value. If null, we assume $value is a custom selection |
2542 | 2542 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2543 | 2543 | */ |
2544 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2545 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2546 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2544 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2545 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2546 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2547 | 2547 | /** @noinspection PhpMissingBreakStatementInspection */ |
2548 | 2548 | case self::not_prepared_by_model_object: |
2549 | 2549 | $value = $field->prepare_for_set($value); |
@@ -2554,7 +2554,7 @@ discard block |
||
2554 | 2554 | //leave the value alone |
2555 | 2555 | } |
2556 | 2556 | return $value; |
2557 | - }else{ |
|
2557 | + } else { |
|
2558 | 2558 | return $value; |
2559 | 2559 | } |
2560 | 2560 | } |
@@ -2564,13 +2564,13 @@ discard block |
||
2564 | 2564 | * @return EE_Primary_Table |
2565 | 2565 | * @throws EE_Error |
2566 | 2566 | */ |
2567 | - protected function _get_main_table(){ |
|
2568 | - foreach($this->_tables as $table){ |
|
2569 | - if($table instanceof EE_Primary_Table){ |
|
2567 | + protected function _get_main_table() { |
|
2568 | + foreach ($this->_tables as $table) { |
|
2569 | + if ($table instanceof EE_Primary_Table) { |
|
2570 | 2570 | return $table; |
2571 | 2571 | } |
2572 | 2572 | } |
2573 | - throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor','event_espresso'),get_class($this))); |
|
2573 | + throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor', 'event_espresso'), get_class($this))); |
|
2574 | 2574 | } |
2575 | 2575 | |
2576 | 2576 | |
@@ -2593,7 +2593,7 @@ discard block |
||
2593 | 2593 | */ |
2594 | 2594 | public function second_table() { |
2595 | 2595 | // grab second table from tables array |
2596 | - $second_table = end( $this->_tables ); |
|
2596 | + $second_table = end($this->_tables); |
|
2597 | 2597 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2598 | 2598 | } |
2599 | 2599 | |
@@ -2606,8 +2606,8 @@ discard block |
||
2606 | 2606 | * @param string $table_alias |
2607 | 2607 | * @return EE_Primary_Table | EE_Secondary_Table |
2608 | 2608 | */ |
2609 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2610 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2609 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2610 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2611 | 2611 | } |
2612 | 2612 | |
2613 | 2613 | |
@@ -2616,10 +2616,10 @@ discard block |
||
2616 | 2616 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2617 | 2617 | * @return EE_Secondary_Table[] |
2618 | 2618 | */ |
2619 | - protected function _get_other_tables(){ |
|
2620 | - $other_tables =array(); |
|
2621 | - foreach($this->_tables as $table_alias => $table){ |
|
2622 | - if($table instanceof EE_Secondary_Table){ |
|
2619 | + protected function _get_other_tables() { |
|
2620 | + $other_tables = array(); |
|
2621 | + foreach ($this->_tables as $table_alias => $table) { |
|
2622 | + if ($table instanceof EE_Secondary_Table) { |
|
2623 | 2623 | $other_tables[$table_alias] = $table; |
2624 | 2624 | } |
2625 | 2625 | } |
@@ -2631,7 +2631,7 @@ discard block |
||
2631 | 2631 | * @param string $table_alias, array key in EEM_Base::_tables |
2632 | 2632 | * @return EE_Model_Field_Base[] |
2633 | 2633 | */ |
2634 | - public function _get_fields_for_table($table_alias){ |
|
2634 | + public function _get_fields_for_table($table_alias) { |
|
2635 | 2635 | return $this->_fields[$table_alias]; |
2636 | 2636 | } |
2637 | 2637 | |
@@ -2647,19 +2647,19 @@ discard block |
||
2647 | 2647 | * @return EE_Model_Query_Info_Carrier |
2648 | 2648 | * @throws \EE_Error |
2649 | 2649 | */ |
2650 | - public function _extract_related_models_from_query($query_params){ |
|
2650 | + public function _extract_related_models_from_query($query_params) { |
|
2651 | 2651 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2652 | - if ( array_key_exists( 0, $query_params ) ) { |
|
2653 | - $this->_extract_related_models_from_sub_params_array_keys( $query_params[0], $query_info_carrier, 0 ); |
|
2652 | + if (array_key_exists(0, $query_params)) { |
|
2653 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2654 | 2654 | } |
2655 | - if ( array_key_exists( 'group_by', $query_params ) ) { |
|
2656 | - if ( is_array( $query_params['group_by'] ) ) { |
|
2655 | + if (array_key_exists('group_by', $query_params)) { |
|
2656 | + if (is_array($query_params['group_by'])) { |
|
2657 | 2657 | $this->_extract_related_models_from_sub_params_array_values( |
2658 | 2658 | $query_params['group_by'], |
2659 | 2659 | $query_info_carrier, |
2660 | 2660 | 'group_by' |
2661 | 2661 | ); |
2662 | - } elseif ( ! empty ( $query_params['group_by'] ) ) { |
|
2662 | + } elseif ( ! empty ($query_params['group_by'])) { |
|
2663 | 2663 | $this->_extract_related_model_info_from_query_param( |
2664 | 2664 | $query_params['group_by'], |
2665 | 2665 | $query_info_carrier, |
@@ -2667,21 +2667,21 @@ discard block |
||
2667 | 2667 | ); |
2668 | 2668 | } |
2669 | 2669 | } |
2670 | - if ( array_key_exists( 'having', $query_params ) ) { |
|
2670 | + if (array_key_exists('having', $query_params)) { |
|
2671 | 2671 | $this->_extract_related_models_from_sub_params_array_keys( |
2672 | 2672 | $query_params[0], |
2673 | 2673 | $query_info_carrier, |
2674 | 2674 | 'having' |
2675 | 2675 | ); |
2676 | 2676 | } |
2677 | - if ( array_key_exists( 'order_by', $query_params ) ) { |
|
2678 | - if ( is_array( $query_params['order_by'] ) ) { |
|
2677 | + if (array_key_exists('order_by', $query_params)) { |
|
2678 | + if (is_array($query_params['order_by'])) { |
|
2679 | 2679 | $this->_extract_related_models_from_sub_params_array_keys( |
2680 | 2680 | $query_params['order_by'], |
2681 | 2681 | $query_info_carrier, |
2682 | 2682 | 'order_by' |
2683 | 2683 | ); |
2684 | - } elseif ( ! empty( $query_params['order_by'] ) ) { |
|
2684 | + } elseif ( ! empty($query_params['order_by'])) { |
|
2685 | 2685 | $this->_extract_related_model_info_from_query_param( |
2686 | 2686 | $query_params['order_by'], |
2687 | 2687 | $query_info_carrier, |
@@ -2689,7 +2689,7 @@ discard block |
||
2689 | 2689 | ); |
2690 | 2690 | } |
2691 | 2691 | } |
2692 | - if ( array_key_exists( 'force_join', $query_params ) ) { |
|
2692 | + if (array_key_exists('force_join', $query_params)) { |
|
2693 | 2693 | $this->_extract_related_models_from_sub_params_array_values( |
2694 | 2694 | $query_params['force_join'], |
2695 | 2695 | $query_info_carrier, |
@@ -2707,34 +2707,34 @@ discard block |
||
2707 | 2707 | * @throws EE_Error |
2708 | 2708 | * @return \EE_Model_Query_Info_Carrier |
2709 | 2709 | */ |
2710 | - private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2711 | - if (!empty($sub_query_params)){ |
|
2710 | + private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2711 | + if ( ! empty($sub_query_params)) { |
|
2712 | 2712 | $sub_query_params = (array) $sub_query_params; |
2713 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2713 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2714 | 2714 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2715 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2715 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2716 | 2716 | |
2717 | 2717 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2718 | 2718 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2719 | 2719 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2720 | 2720 | //of array('Registration.TXN_ID'=>23) |
2721 | 2721 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2722 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2723 | - if (! is_array($possibly_array_of_params)){ |
|
2722 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2723 | + if ( ! is_array($possibly_array_of_params)) { |
|
2724 | 2724 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2725 | - $param,$possibly_array_of_params)); |
|
2726 | - }else{ |
|
2727 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2725 | + $param, $possibly_array_of_params)); |
|
2726 | + } else { |
|
2727 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2728 | 2728 | } |
2729 | - }elseif($query_param_type === 0 //ie WHERE |
|
2729 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2730 | 2730 | && is_array($possibly_array_of_params) |
2731 | 2731 | && isset($possibly_array_of_params[2]) |
2732 | - && $possibly_array_of_params[2] == true){ |
|
2732 | + && $possibly_array_of_params[2] == true) { |
|
2733 | 2733 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2734 | 2734 | //indicating that $possible_array_of_params[1] is actually a field name, |
2735 | 2735 | //from which we should extract query parameters! |
2736 | - if( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1] ) ) { |
|
2737 | - throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"),$query_param_type,implode(",",$possibly_array_of_params))); |
|
2736 | + if ( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1])) { |
|
2737 | + throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params))); |
|
2738 | 2738 | } |
2739 | 2739 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2740 | 2740 | } |
@@ -2753,14 +2753,14 @@ discard block |
||
2753 | 2753 | * @throws EE_Error |
2754 | 2754 | * @return \EE_Model_Query_Info_Carrier |
2755 | 2755 | */ |
2756 | - private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2757 | - if (!empty($sub_query_params)){ |
|
2758 | - if(!is_array($sub_query_params)){ |
|
2759 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2756 | + private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2757 | + if ( ! empty($sub_query_params)) { |
|
2758 | + if ( ! is_array($sub_query_params)) { |
|
2759 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2760 | 2760 | } |
2761 | - foreach($sub_query_params as $param){ |
|
2761 | + foreach ($sub_query_params as $param) { |
|
2762 | 2762 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2763 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2763 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2764 | 2764 | } |
2765 | 2765 | } |
2766 | 2766 | return $model_query_info_carrier; |
@@ -2779,8 +2779,8 @@ discard block |
||
2779 | 2779 | * @throws EE_Error |
2780 | 2780 | * @return EE_Model_Query_Info_Carrier |
2781 | 2781 | */ |
2782 | - public function _create_model_query_info_carrier($query_params){ |
|
2783 | - if ( ! is_array( $query_params ) ) { |
|
2782 | + public function _create_model_query_info_carrier($query_params) { |
|
2783 | + if ( ! is_array($query_params)) { |
|
2784 | 2784 | EE_Error::doing_it_wrong( |
2785 | 2785 | 'EEM_Base::_create_model_query_info_carrier', |
2786 | 2786 | sprintf( |
@@ -2788,16 +2788,16 @@ discard block |
||
2788 | 2788 | '$query_params should be an array, you passed a variable of type %s', |
2789 | 2789 | 'event_espresso' |
2790 | 2790 | ), |
2791 | - gettype( $query_params ) |
|
2791 | + gettype($query_params) |
|
2792 | 2792 | ), |
2793 | 2793 | '4.6.0' |
2794 | 2794 | ); |
2795 | 2795 | $query_params = array(); |
2796 | 2796 | } |
2797 | - $where_query_params = isset( $query_params[0] ) ? $query_params[0] : array(); |
|
2797 | + $where_query_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
2798 | 2798 | //first check if we should alter the query to account for caps or not |
2799 | 2799 | //because the caps might require us to do extra joins |
2800 | - if ( isset( $query_params['caps'] ) && $query_params['caps'] !== 'none' ) { |
|
2800 | + if (isset($query_params['caps']) && $query_params['caps'] !== 'none') { |
|
2801 | 2801 | $query_params[0] = $where_query_params = array_replace_recursive( |
2802 | 2802 | $where_query_params, |
2803 | 2803 | $this->caps_where_conditions( |
@@ -2805,10 +2805,10 @@ discard block |
||
2805 | 2805 | ) |
2806 | 2806 | ); |
2807 | 2807 | } |
2808 | - $query_object = $this->_extract_related_models_from_query( $query_params ); |
|
2808 | + $query_object = $this->_extract_related_models_from_query($query_params); |
|
2809 | 2809 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2810 | - foreach ( $where_query_params as $key => $value ) { |
|
2811 | - if ( is_int( $key ) ) { |
|
2810 | + foreach ($where_query_params as $key => $value) { |
|
2811 | + if (is_int($key)) { |
|
2812 | 2812 | throw new EE_Error( |
2813 | 2813 | sprintf( |
2814 | 2814 | __( |
@@ -2816,16 +2816,16 @@ discard block |
||
2816 | 2816 | "event_espresso" |
2817 | 2817 | ), |
2818 | 2818 | $key, |
2819 | - var_export( $value, true ), |
|
2820 | - var_export( $query_params, true ), |
|
2821 | - get_class( $this ) |
|
2819 | + var_export($value, true), |
|
2820 | + var_export($query_params, true), |
|
2821 | + get_class($this) |
|
2822 | 2822 | ) |
2823 | 2823 | ); |
2824 | 2824 | } |
2825 | 2825 | } |
2826 | 2826 | if ( |
2827 | - array_key_exists( 'default_where_conditions', $query_params ) |
|
2828 | - && ! empty( $query_params['default_where_conditions'] ) |
|
2827 | + array_key_exists('default_where_conditions', $query_params) |
|
2828 | + && ! empty($query_params['default_where_conditions']) |
|
2829 | 2829 | ) { |
2830 | 2830 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2831 | 2831 | } else { |
@@ -2839,13 +2839,13 @@ discard block |
||
2839 | 2839 | ), |
2840 | 2840 | $where_query_params |
2841 | 2841 | ); |
2842 | - $query_object->set_where_sql( $this->_construct_where_clause( $where_query_params ) ); |
|
2842 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2843 | 2843 | // if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join. |
2844 | 2844 | // So we need to setup a subquery and use that for the main join. |
2845 | 2845 | // Note for now this only works on the primary table for the model. |
2846 | 2846 | // So for instance, you could set the limit array like this: |
2847 | 2847 | // array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2848 | - if ( array_key_exists( 'on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] ) ) { |
|
2848 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2849 | 2849 | $query_object->set_main_model_join_sql( |
2850 | 2850 | $this->_construct_limit_join_select( |
2851 | 2851 | $query_params['on_join_limit'][0], |
@@ -2854,40 +2854,40 @@ discard block |
||
2854 | 2854 | ); |
2855 | 2855 | } |
2856 | 2856 | //set limit |
2857 | - if ( array_key_exists( 'limit', $query_params ) ) { |
|
2858 | - if ( is_array( $query_params['limit'] ) ) { |
|
2859 | - if ( ! isset( $query_params['limit'][0], $query_params['limit'][1] ) ) { |
|
2857 | + if (array_key_exists('limit', $query_params)) { |
|
2858 | + if (is_array($query_params['limit'])) { |
|
2859 | + if ( ! isset($query_params['limit'][0], $query_params['limit'][1])) { |
|
2860 | 2860 | $e = sprintf( |
2861 | 2861 | __( |
2862 | 2862 | "Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", |
2863 | 2863 | "event_espresso" |
2864 | 2864 | ), |
2865 | - http_build_query( $query_params['limit'] ) |
|
2865 | + http_build_query($query_params['limit']) |
|
2866 | 2866 | ); |
2867 | - throw new EE_Error( $e . "|" . $e ); |
|
2867 | + throw new EE_Error($e."|".$e); |
|
2868 | 2868 | } |
2869 | 2869 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2870 | - $query_object->set_limit_sql( " LIMIT " . $query_params['limit'][0] . "," . $query_params['limit'][1] ); |
|
2871 | - } elseif ( ! empty ( $query_params['limit'] ) ) { |
|
2872 | - $query_object->set_limit_sql( " LIMIT " . $query_params['limit'] ); |
|
2870 | + $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
|
2871 | + } elseif ( ! empty ($query_params['limit'])) { |
|
2872 | + $query_object->set_limit_sql(" LIMIT ".$query_params['limit']); |
|
2873 | 2873 | } |
2874 | 2874 | } |
2875 | 2875 | //set order by |
2876 | - if ( array_key_exists( 'order_by', $query_params ) ) { |
|
2877 | - if ( is_array( $query_params['order_by'] ) ) { |
|
2876 | + if (array_key_exists('order_by', $query_params)) { |
|
2877 | + if (is_array($query_params['order_by'])) { |
|
2878 | 2878 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2879 | 2879 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2880 | 2880 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2881 | - if ( array_key_exists( 'order', $query_params ) ) { |
|
2881 | + if (array_key_exists('order', $query_params)) { |
|
2882 | 2882 | throw new EE_Error( |
2883 | 2883 | sprintf( |
2884 | 2884 | __( |
2885 | 2885 | "In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ", |
2886 | 2886 | "event_espresso" |
2887 | 2887 | ), |
2888 | - get_class( $this ), |
|
2889 | - implode( ", ", array_keys( $query_params['order_by'] ) ), |
|
2890 | - implode( ", ", $query_params['order_by'] ), |
|
2888 | + get_class($this), |
|
2889 | + implode(", ", array_keys($query_params['order_by'])), |
|
2890 | + implode(", ", $query_params['order_by']), |
|
2891 | 2891 | $query_params['order'] |
2892 | 2892 | ) |
2893 | 2893 | ); |
@@ -2899,57 +2899,57 @@ discard block |
||
2899 | 2899 | ); |
2900 | 2900 | //assume it's an array of fields to order by |
2901 | 2901 | $order_array = array(); |
2902 | - foreach ( $query_params['order_by'] as $field_name_to_order_by => $order ) { |
|
2903 | - $order = $this->_extract_order( $order ); |
|
2904 | - $order_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_order_by ) . SP . $order; |
|
2902 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2903 | + $order = $this->_extract_order($order); |
|
2904 | + $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
|
2905 | 2905 | } |
2906 | - $query_object->set_order_by_sql( " ORDER BY " . implode( ",", $order_array ) ); |
|
2907 | - } elseif ( ! empty ( $query_params['order_by'] ) ) { |
|
2906 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2907 | + } elseif ( ! empty ($query_params['order_by'])) { |
|
2908 | 2908 | $this->_extract_related_model_info_from_query_param( |
2909 | 2909 | $query_params['order_by'], |
2910 | 2910 | $query_object, |
2911 | 2911 | 'order', |
2912 | 2912 | $query_params['order_by'] |
2913 | 2913 | ); |
2914 | - $order = isset( $query_params['order'] ) |
|
2915 | - ? $this->_extract_order( $query_params['order'] ) |
|
2914 | + $order = isset($query_params['order']) |
|
2915 | + ? $this->_extract_order($query_params['order']) |
|
2916 | 2916 | : 'DESC'; |
2917 | 2917 | $query_object->set_order_by_sql( |
2918 | - " ORDER BY " . $this->_deduce_column_name_from_query_param( $query_params['order_by'] ) . SP . $order |
|
2918 | + " ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order |
|
2919 | 2919 | ); |
2920 | 2920 | } |
2921 | 2921 | } |
2922 | 2922 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2923 | - if ( ! array_key_exists( 'order_by', $query_params ) |
|
2924 | - && array_key_exists( 'order', $query_params ) |
|
2925 | - && ! empty( $query_params['order'] ) |
|
2923 | + if ( ! array_key_exists('order_by', $query_params) |
|
2924 | + && array_key_exists('order', $query_params) |
|
2925 | + && ! empty($query_params['order']) |
|
2926 | 2926 | ) { |
2927 | 2927 | $pk_field = $this->get_primary_key_field(); |
2928 | - $order = $this->_extract_order( $query_params['order'] ); |
|
2929 | - $query_object->set_order_by_sql( " ORDER BY " . $pk_field->get_qualified_column() . SP . $order ); |
|
2928 | + $order = $this->_extract_order($query_params['order']); |
|
2929 | + $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
|
2930 | 2930 | } |
2931 | 2931 | //set group by |
2932 | - if ( array_key_exists( 'group_by', $query_params ) ) { |
|
2933 | - if ( is_array( $query_params['group_by'] ) ) { |
|
2932 | + if (array_key_exists('group_by', $query_params)) { |
|
2933 | + if (is_array($query_params['group_by'])) { |
|
2934 | 2934 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2935 | 2935 | $group_by_array = array(); |
2936 | - foreach ( $query_params['group_by'] as $field_name_to_group_by ) { |
|
2937 | - $group_by_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_group_by ); |
|
2936 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2937 | + $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
|
2938 | 2938 | } |
2939 | - $query_object->set_group_by_sql( " GROUP BY " . implode( ", ", $group_by_array ) ); |
|
2940 | - } elseif ( ! empty ( $query_params['group_by'] ) ) { |
|
2939 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2940 | + } elseif ( ! empty ($query_params['group_by'])) { |
|
2941 | 2941 | $query_object->set_group_by_sql( |
2942 | - " GROUP BY " . $this->_deduce_column_name_from_query_param( $query_params['group_by'] ) |
|
2942 | + " GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']) |
|
2943 | 2943 | ); |
2944 | 2944 | } |
2945 | 2945 | } |
2946 | 2946 | //set having |
2947 | - if ( array_key_exists( 'having', $query_params ) && $query_params['having'] ) { |
|
2948 | - $query_object->set_having_sql( $this->_construct_having_clause( $query_params['having'] ) ); |
|
2947 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2948 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2949 | 2949 | } |
2950 | 2950 | //now, just verify they didn't pass anything wack |
2951 | - foreach ( $query_params as $query_key => $query_value ) { |
|
2952 | - if ( ! in_array( $query_key, $this->_allowed_query_params, true ) ) { |
|
2951 | + foreach ($query_params as $query_key => $query_value) { |
|
2952 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2953 | 2953 | throw new EE_Error( |
2954 | 2954 | sprintf( |
2955 | 2955 | __( |
@@ -2957,16 +2957,16 @@ discard block |
||
2957 | 2957 | 'event_espresso' |
2958 | 2958 | ), |
2959 | 2959 | $query_key, |
2960 | - get_class( $this ), |
|
2960 | + get_class($this), |
|
2961 | 2961 | // print_r( $this->_allowed_query_params, TRUE ) |
2962 | - implode( ',', $this->_allowed_query_params ) |
|
2962 | + implode(',', $this->_allowed_query_params) |
|
2963 | 2963 | ) |
2964 | 2964 | ); |
2965 | 2965 | } |
2966 | 2966 | } |
2967 | 2967 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2968 | - if ( empty( $main_model_join_sql ) ) { |
|
2969 | - $query_object->set_main_model_join_sql( $this->_construct_internal_join() ); |
|
2968 | + if (empty($main_model_join_sql)) { |
|
2969 | + $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
2970 | 2970 | } |
2971 | 2971 | return $query_object; |
2972 | 2972 | } |
@@ -2981,17 +2981,17 @@ discard block |
||
2981 | 2981 | * @return array like EEM_Base::get_all() 's $query_params[0] |
2982 | 2982 | * @throws \EE_Error |
2983 | 2983 | */ |
2984 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
2985 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
2984 | + public function caps_where_conditions($context = self::caps_read) { |
|
2985 | + EEM_Base::verify_is_valid_cap_context($context); |
|
2986 | 2986 | $cap_where_conditions = array(); |
2987 | - $cap_restrictions = $this->caps_missing( $context ); |
|
2987 | + $cap_restrictions = $this->caps_missing($context); |
|
2988 | 2988 | /** |
2989 | 2989 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
2990 | 2990 | */ |
2991 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
2992 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
2991 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
2992 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
2993 | 2993 | } |
2994 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
2994 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
2995 | 2995 | } |
2996 | 2996 | |
2997 | 2997 | /** |
@@ -3001,11 +3001,11 @@ discard block |
||
3001 | 3001 | * @return string either ASC, asc, DESC or desc |
3002 | 3002 | * @throws EE_Error |
3003 | 3003 | */ |
3004 | - private function _extract_order($should_be_order_string){ |
|
3005 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
3004 | + private function _extract_order($should_be_order_string) { |
|
3005 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
3006 | 3006 | return $should_be_order_string; |
3007 | - }else{ |
|
3008 | - throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
|
3007 | + } else { |
|
3008 | + throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"), get_class($this), $should_be_order_string)); |
|
3009 | 3009 | } |
3010 | 3010 | } |
3011 | 3011 | |
@@ -3023,7 +3023,7 @@ discard block |
||
3023 | 3023 | * @throws EE_Error |
3024 | 3024 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
3025 | 3025 | */ |
3026 | - private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier,$use_default_where_conditions = 'all',$where_query_params = array()){ |
|
3026 | + private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier, $use_default_where_conditions = 'all', $where_query_params = array()) { |
|
3027 | 3027 | $allowed_used_default_where_conditions_values = array( |
3028 | 3028 | 'all', |
3029 | 3029 | 'this_model_only', |
@@ -3031,17 +3031,17 @@ discard block |
||
3031 | 3031 | 'minimum', |
3032 | 3032 | 'none' |
3033 | 3033 | ); |
3034 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
3035 | - throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"),$use_default_where_conditions,implode(", ",$allowed_used_default_where_conditions_values))); |
|
3034 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
3035 | + throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values))); |
|
3036 | 3036 | } |
3037 | 3037 | $universal_query_params = array(); |
3038 | - if( $use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only' ){ |
|
3038 | + if ($use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only') { |
|
3039 | 3039 | $universal_query_params = $this->_get_default_where_conditions(); |
3040 | - } else if( $use_default_where_conditions === 'minimum' ) { |
|
3040 | + } else if ($use_default_where_conditions === 'minimum') { |
|
3041 | 3041 | $universal_query_params = $this->_get_minimum_where_conditions(); |
3042 | 3042 | } |
3043 | - if(in_array($use_default_where_conditions,array('all','other_models_only'))){ |
|
3044 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
3043 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
3044 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
3045 | 3045 | $related_model = $this->get_related_model_obj($model_name); |
3046 | 3046 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
3047 | 3047 | $overrides = $this->_override_defaults_or_make_null_friendly( |
@@ -3074,20 +3074,20 @@ discard block |
||
3074 | 3074 | * @return array like EEM_Base::get_all's $query_params[0] |
3075 | 3075 | * @throws \EE_Error |
3076 | 3076 | */ |
3077 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
3077 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
3078 | 3078 | $null_friendly_where_conditions = array(); |
3079 | 3079 | $none_overridden = true; |
3080 | 3080 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
3081 | 3081 | |
3082 | - foreach($default_where_conditions as $key => $val){ |
|
3083 | - if( isset($provided_where_conditions[$key])){ |
|
3082 | + foreach ($default_where_conditions as $key => $val) { |
|
3083 | + if (isset($provided_where_conditions[$key])) { |
|
3084 | 3084 | $none_overridden = false; |
3085 | - }else{ |
|
3085 | + } else { |
|
3086 | 3086 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3087 | 3087 | } |
3088 | 3088 | } |
3089 | - if( $none_overridden && $default_where_conditions){ |
|
3090 | - if($model->has_primary_key_field()){ |
|
3089 | + if ($none_overridden && $default_where_conditions) { |
|
3090 | + if ($model->has_primary_key_field()) { |
|
3091 | 3091 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
3092 | 3092 | }/*else{ |
3093 | 3093 | //@todo NO PK, use other defaults |
@@ -3104,8 +3104,8 @@ discard block |
||
3104 | 3104 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3105 | 3105 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3106 | 3106 | */ |
3107 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
3108 | - if ( $this->_ignore_where_strategy ){ |
|
3107 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
3108 | + if ($this->_ignore_where_strategy) { |
|
3109 | 3109 | return array(); |
3110 | 3110 | } |
3111 | 3111 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3119,8 +3119,8 @@ discard block |
||
3119 | 3119 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3120 | 3120 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3121 | 3121 | */ |
3122 | - protected function _get_minimum_where_conditions($model_relation_path = null){ |
|
3123 | - if ( $this->_ignore_where_strategy ){ |
|
3122 | + protected function _get_minimum_where_conditions($model_relation_path = null) { |
|
3123 | + if ($this->_ignore_where_strategy) { |
|
3124 | 3124 | return array(); |
3125 | 3125 | } |
3126 | 3126 | return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3136,16 +3136,16 @@ discard block |
||
3136 | 3136 | * @return string |
3137 | 3137 | * @throws \EE_Error |
3138 | 3138 | */ |
3139 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
3139 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
3140 | 3140 | $selects = $this->_get_columns_to_select_for_this_model(); |
3141 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
3141 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
3142 | 3142 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
3143 | - $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model( $model_relation_chain ); |
|
3144 | - foreach ( $other_model_selects as $key => $value ) { |
|
3143 | + $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain); |
|
3144 | + foreach ($other_model_selects as $key => $value) { |
|
3145 | 3145 | $selects[] = $value; |
3146 | 3146 | } |
3147 | 3147 | } |
3148 | - return implode(", ",$selects); |
|
3148 | + return implode(", ", $selects); |
|
3149 | 3149 | } |
3150 | 3150 | |
3151 | 3151 | /** |
@@ -3154,19 +3154,19 @@ discard block |
||
3154 | 3154 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
3155 | 3155 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
3156 | 3156 | */ |
3157 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
3157 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
3158 | 3158 | $fields = $this->field_settings(); |
3159 | 3159 | $selects = array(); |
3160 | 3160 | $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model_name()); |
3161 | - foreach($fields as $field_obj){ |
|
3162 | - $selects[] = $table_alias_with_model_relation_chain_prefix . $field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
3161 | + foreach ($fields as $field_obj) { |
|
3162 | + $selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
3163 | 3163 | } |
3164 | 3164 | //make sure we are also getting the PKs of each table |
3165 | 3165 | $tables = $this->get_tables(); |
3166 | - if(count($tables) > 1){ |
|
3167 | - foreach($tables as $table_obj){ |
|
3168 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
3169 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
3166 | + if (count($tables) > 1) { |
|
3167 | + foreach ($tables as $table_obj) { |
|
3168 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
3169 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
3170 | 3170 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
3171 | 3171 | } |
3172 | 3172 | } |
@@ -3196,65 +3196,65 @@ discard block |
||
3196 | 3196 | $query_param_type, |
3197 | 3197 | $original_query_param = null |
3198 | 3198 | ) { |
3199 | - if( $original_query_param === null ){ |
|
3199 | + if ($original_query_param === null) { |
|
3200 | 3200 | $original_query_param = $query_param; |
3201 | 3201 | } |
3202 | 3202 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
3203 | 3203 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
3204 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
3205 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
3204 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
3205 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
3206 | 3206 | //check to see if we have a field on this model |
3207 | 3207 | $this_model_fields = $this->field_settings(true); |
3208 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
3209 | - if($allow_fields){ |
|
3208 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
3209 | + if ($allow_fields) { |
|
3210 | 3210 | return; |
3211 | - }else{ |
|
3211 | + } else { |
|
3212 | 3212 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
3213 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3213 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3214 | 3214 | } |
3215 | 3215 | } |
3216 | 3216 | //check if this is a special logic query param |
3217 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
3218 | - if($allow_logic_query_params){ |
|
3217 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
3218 | + if ($allow_logic_query_params) { |
|
3219 | 3219 | return; |
3220 | - }else{ |
|
3220 | + } else { |
|
3221 | 3221 | throw new EE_Error( |
3222 | 3222 | sprintf( |
3223 | - __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
|
3224 | - implode( '", "', $this->_logic_query_param_keys ), |
|
3225 | - $query_param , |
|
3226 | - get_class( $this ), |
|
3223 | + __('Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso'), |
|
3224 | + implode('", "', $this->_logic_query_param_keys), |
|
3225 | + $query_param, |
|
3226 | + get_class($this), |
|
3227 | 3227 | '<br />', |
3228 | - "\t" . ' $passed_in_query_info = <pre>' . print_r( $passed_in_query_info, TRUE ) . '</pre>' . "\n\t" . ' $query_param_type = ' . $query_param_type . "\n\t" . ' $original_query_param = ' . $original_query_param |
|
3228 | + "\t".' $passed_in_query_info = <pre>'.print_r($passed_in_query_info, TRUE).'</pre>'."\n\t".' $query_param_type = '.$query_param_type."\n\t".' $original_query_param = '.$original_query_param |
|
3229 | 3229 | ) |
3230 | 3230 | ); |
3231 | 3231 | } |
3232 | 3232 | } |
3233 | 3233 | |
3234 | 3234 | //check if it's a custom selection |
3235 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3235 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3236 | 3236 | return; |
3237 | 3237 | } |
3238 | 3238 | |
3239 | 3239 | //check if has a model name at the beginning |
3240 | 3240 | //and |
3241 | 3241 | //check if it's a field on a related model |
3242 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
3243 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
3244 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3242 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
3243 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
3244 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3245 | 3245 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
3246 | - if($query_param === ''){ |
|
3246 | + if ($query_param === '') { |
|
3247 | 3247 | //nothing left to $query_param |
3248 | 3248 | //we should actually end in a field name, not a model like this! |
3249 | 3249 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3250 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
3251 | - }else{ |
|
3250 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
3251 | + } else { |
|
3252 | 3252 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3253 | 3253 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3254 | 3254 | return; |
3255 | 3255 | } |
3256 | - }elseif($query_param === $valid_related_model_name){ |
|
3257 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3256 | + }elseif ($query_param === $valid_related_model_name) { |
|
3257 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3258 | 3258 | return; |
3259 | 3259 | } |
3260 | 3260 | } |
@@ -3264,7 +3264,7 @@ discard block |
||
3264 | 3264 | //and we previously confirmed it wasn't a logic query param or field on the current model |
3265 | 3265 | //it's wack, that's what it is |
3266 | 3266 | throw new EE_Error(sprintf(__("There is no model named '%s' related to %s. Query param type is %s and original query param is %s", "event_espresso"), |
3267 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3267 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3268 | 3268 | |
3269 | 3269 | } |
3270 | 3270 | |
@@ -3283,26 +3283,26 @@ discard block |
||
3283 | 3283 | * @return void |
3284 | 3284 | * @throws \EE_Error |
3285 | 3285 | */ |
3286 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
3286 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
3287 | 3287 | $relation_obj = $this->related_settings_for($model_name); |
3288 | 3288 | |
3289 | 3289 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
3290 | 3290 | //check if the relation is HABTM, because then we're essentially doing two joins |
3291 | 3291 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
3292 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
3292 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
3293 | 3293 | $join_model_obj = $relation_obj->get_join_model(); |
3294 | 3294 | //replace the model specified with the join model for this relation chain, whi |
3295 | 3295 | $relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain); |
3296 | 3296 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3297 | 3297 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
3298 | 3298 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
3299 | - $passed_in_query_info->merge( $new_query_info ); |
|
3299 | + $passed_in_query_info->merge($new_query_info); |
|
3300 | 3300 | } |
3301 | 3301 | //now just join to the other table pointed to by the relation object, and add its data types |
3302 | 3302 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3303 | 3303 | array($model_relation_chain=>$model_name), |
3304 | 3304 | $relation_obj->get_join_statement($model_relation_chain)); |
3305 | - $passed_in_query_info->merge( $new_query_info ); |
|
3305 | + $passed_in_query_info->merge($new_query_info); |
|
3306 | 3306 | } |
3307 | 3307 | |
3308 | 3308 | |
@@ -3314,11 +3314,11 @@ discard block |
||
3314 | 3314 | * @return string of SQL |
3315 | 3315 | * @throws \EE_Error |
3316 | 3316 | */ |
3317 | - private function _construct_where_clause($where_params){ |
|
3317 | + private function _construct_where_clause($where_params) { |
|
3318 | 3318 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3319 | - if($SQL){ |
|
3320 | - return " WHERE ". $SQL; |
|
3321 | - }else{ |
|
3319 | + if ($SQL) { |
|
3320 | + return " WHERE ".$SQL; |
|
3321 | + } else { |
|
3322 | 3322 | return ''; |
3323 | 3323 | } |
3324 | 3324 | } |
@@ -3333,11 +3333,11 @@ discard block |
||
3333 | 3333 | * @return string |
3334 | 3334 | * @throws \EE_Error |
3335 | 3335 | */ |
3336 | - private function _construct_having_clause($having_params){ |
|
3336 | + private function _construct_having_clause($having_params) { |
|
3337 | 3337 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3338 | - if($SQL){ |
|
3339 | - return " HAVING ". $SQL; |
|
3340 | - }else{ |
|
3338 | + if ($SQL) { |
|
3339 | + return " HAVING ".$SQL; |
|
3340 | + } else { |
|
3341 | 3341 | return ''; |
3342 | 3342 | } |
3343 | 3343 | |
@@ -3351,16 +3351,16 @@ discard block |
||
3351 | 3351 | * @return EE_Model_Field_Base |
3352 | 3352 | * @throws EE_Error |
3353 | 3353 | */ |
3354 | - protected function _get_field_on_model($field_name,$model_name){ |
|
3354 | + protected function _get_field_on_model($field_name, $model_name) { |
|
3355 | 3355 | $model_class = 'EEM_'.$model_name; |
3356 | 3356 | $model_filepath = $model_class.".model.php"; |
3357 | - if ( is_readable($model_filepath)){ |
|
3357 | + if (is_readable($model_filepath)) { |
|
3358 | 3358 | require_once($model_filepath); |
3359 | - $model_instance=call_user_func($model_name."::instance"); |
|
3359 | + $model_instance = call_user_func($model_name."::instance"); |
|
3360 | 3360 | /* @var $model_instance EEM_Base */ |
3361 | 3361 | return $model_instance->field_settings_for($field_name); |
3362 | - }else{ |
|
3363 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
3362 | + } else { |
|
3363 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
3364 | 3364 | } |
3365 | 3365 | } |
3366 | 3366 | |
@@ -3373,41 +3373,41 @@ discard block |
||
3373 | 3373 | * @throws EE_Error |
3374 | 3374 | * @return string of SQL |
3375 | 3375 | */ |
3376 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
3377 | - $where_clauses=array(); |
|
3378 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
3379 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
3380 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
3381 | - switch($query_param){ |
|
3376 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
3377 | + $where_clauses = array(); |
|
3378 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
3379 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
3380 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
3381 | + switch ($query_param) { |
|
3382 | 3382 | case 'not': |
3383 | 3383 | case 'NOT': |
3384 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3384 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3385 | 3385 | break; |
3386 | 3386 | case 'and': |
3387 | 3387 | case 'AND': |
3388 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3388 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3389 | 3389 | break; |
3390 | 3390 | case 'or': |
3391 | 3391 | case 'OR': |
3392 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3392 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3393 | 3393 | break; |
3394 | 3394 | } |
3395 | - }else{ |
|
3395 | + } else { |
|
3396 | 3396 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3397 | 3397 | |
3398 | 3398 | //if it's not a normal field, maybe it's a custom selection? |
3399 | - if( ! $field_obj){ |
|
3400 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3399 | + if ( ! $field_obj) { |
|
3400 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3401 | 3401 | $field_obj = $this->_custom_selections[$query_param][1]; |
3402 | - }else{ |
|
3403 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3402 | + } else { |
|
3403 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3404 | 3404 | } |
3405 | 3405 | } |
3406 | 3406 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3407 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3407 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3408 | 3408 | } |
3409 | 3409 | } |
3410 | - return $where_clauses ? implode( $glue, $where_clauses ) : ''; |
|
3410 | + return $where_clauses ? implode($glue, $where_clauses) : ''; |
|
3411 | 3411 | } |
3412 | 3412 | |
3413 | 3413 | |
@@ -3418,18 +3418,18 @@ discard block |
||
3418 | 3418 | * @throws EE_Error |
3419 | 3419 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3420 | 3420 | */ |
3421 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3421 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3422 | 3422 | $field = $this->_deduce_field_from_query_param($query_param); |
3423 | 3423 | |
3424 | - if( $field ){ |
|
3425 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3426 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3427 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3424 | + if ($field) { |
|
3425 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3426 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3427 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3428 | 3428 | //maybe it's custom selection item? |
3429 | 3429 | //if so, just use it as the "column name" |
3430 | 3430 | return $query_param; |
3431 | - }else{ |
|
3432 | - throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
|
3431 | + } else { |
|
3432 | + throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"), $query_param, implode(",", $this->_custom_selections))); |
|
3433 | 3433 | } |
3434 | 3434 | } |
3435 | 3435 | |
@@ -3441,11 +3441,11 @@ discard block |
||
3441 | 3441 | * @param string $condition_query_param_key |
3442 | 3442 | * @return string |
3443 | 3443 | */ |
3444 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3444 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3445 | 3445 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3446 | - if($pos_of_star === FALSE){ |
|
3446 | + if ($pos_of_star === FALSE) { |
|
3447 | 3447 | return $condition_query_param_key; |
3448 | - }else{ |
|
3448 | + } else { |
|
3449 | 3449 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3450 | 3450 | return $condition_query_param_sans_star; |
3451 | 3451 | } |
@@ -3460,12 +3460,12 @@ discard block |
||
3460 | 3460 | * @throws EE_Error |
3461 | 3461 | * @return string |
3462 | 3462 | */ |
3463 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3464 | - if ( is_array( $op_and_value ) ) { |
|
3465 | - $operator = isset( $op_and_value[0] ) ? $this->_prepare_operator_for_sql( $op_and_value[0] ) : null; |
|
3466 | - if ( ! $operator ) { |
|
3463 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3464 | + if (is_array($op_and_value)) { |
|
3465 | + $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
|
3466 | + if ( ! $operator) { |
|
3467 | 3467 | $php_array_like_string = array(); |
3468 | - foreach ( $op_and_value as $key => $value ) { |
|
3468 | + foreach ($op_and_value as $key => $value) { |
|
3469 | 3469 | $php_array_like_string[] = "$key=>$value"; |
3470 | 3470 | } |
3471 | 3471 | throw new EE_Error( |
@@ -3474,27 +3474,27 @@ discard block |
||
3474 | 3474 | "You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", |
3475 | 3475 | "event_espresso" |
3476 | 3476 | ), |
3477 | - implode( ",", $php_array_like_string ) |
|
3477 | + implode(",", $php_array_like_string) |
|
3478 | 3478 | ) |
3479 | 3479 | ); |
3480 | 3480 | } |
3481 | - $value = isset( $op_and_value[1] ) ? $op_and_value[1] : null; |
|
3481 | + $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
|
3482 | 3482 | } else { |
3483 | 3483 | $operator = '='; |
3484 | 3484 | $value = $op_and_value; |
3485 | 3485 | } |
3486 | 3486 | //check to see if the value is actually another field |
3487 | - if ( is_array( $op_and_value ) && isset( $op_and_value[2] ) && $op_and_value[2] == true ) { |
|
3488 | - return $operator . SP . $this->_deduce_column_name_from_query_param( $value ); |
|
3489 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3487 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3488 | + return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
|
3489 | + } elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3490 | 3490 | //in this case, the value should be an array, or at least a comma-separated list |
3491 | 3491 | //it will need to handle a little differently |
3492 | - $cleaned_value = $this->_construct_in_value( $value, $field_obj ); |
|
3492 | + $cleaned_value = $this->_construct_in_value($value, $field_obj); |
|
3493 | 3493 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3494 | - return $operator . SP . $cleaned_value; |
|
3495 | - } elseif ( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3494 | + return $operator.SP.$cleaned_value; |
|
3495 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3496 | 3496 | //the value should be an array with count of two. |
3497 | - if ( count( $value ) !== 2 ) { |
|
3497 | + if (count($value) !== 2) { |
|
3498 | 3498 | throw new EE_Error( |
3499 | 3499 | sprintf( |
3500 | 3500 | __( |
@@ -3505,10 +3505,10 @@ discard block |
||
3505 | 3505 | ) |
3506 | 3506 | ); |
3507 | 3507 | } |
3508 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3509 | - return $operator . SP . $cleaned_value; |
|
3510 | - } elseif ( in_array( $operator, $this->_null_style_operators ) ) { |
|
3511 | - if ( $value !== null ) { |
|
3508 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3509 | + return $operator.SP.$cleaned_value; |
|
3510 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3511 | + if ($value !== null) { |
|
3512 | 3512 | throw new EE_Error( |
3513 | 3513 | sprintf( |
3514 | 3514 | __( |
@@ -3521,13 +3521,13 @@ discard block |
||
3521 | 3521 | ); |
3522 | 3522 | } |
3523 | 3523 | return $operator; |
3524 | - } elseif ( $operator === 'LIKE' && ! is_array( $value ) ) { |
|
3524 | + } elseif ($operator === 'LIKE' && ! is_array($value)) { |
|
3525 | 3525 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3526 | 3526 | //remove other junk. So just treat it as a string. |
3527 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, '%s' ); |
|
3528 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3529 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, $field_obj ); |
|
3530 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3527 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
|
3528 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3529 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3530 | + } elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3531 | 3531 | throw new EE_Error( |
3532 | 3532 | sprintf( |
3533 | 3533 | __( |
@@ -3538,7 +3538,7 @@ discard block |
||
3538 | 3538 | $operator |
3539 | 3539 | ) |
3540 | 3540 | ); |
3541 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3541 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3542 | 3542 | throw new EE_Error( |
3543 | 3543 | sprintf( |
3544 | 3544 | __( |
@@ -3556,7 +3556,7 @@ discard block |
||
3556 | 3556 | "It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", |
3557 | 3557 | "event_espresso" |
3558 | 3558 | ), |
3559 | - http_build_query( $op_and_value ) |
|
3559 | + http_build_query($op_and_value) |
|
3560 | 3560 | ) |
3561 | 3561 | ); |
3562 | 3562 | } |
@@ -3572,12 +3572,12 @@ discard block |
||
3572 | 3572 | * @return string |
3573 | 3573 | * @throws \EE_Error |
3574 | 3574 | */ |
3575 | - public function _construct_between_value( $values, $field_obj ) { |
|
3575 | + public function _construct_between_value($values, $field_obj) { |
|
3576 | 3576 | $cleaned_values = array(); |
3577 | - foreach ( $values as $value ) { |
|
3578 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3577 | + foreach ($values as $value) { |
|
3578 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3579 | 3579 | } |
3580 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3580 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3581 | 3581 | } |
3582 | 3582 | |
3583 | 3583 | |
@@ -3594,26 +3594,26 @@ discard block |
||
3594 | 3594 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3595 | 3595 | * @throws \EE_Error |
3596 | 3596 | */ |
3597 | - public function _construct_in_value($values, $field_obj){ |
|
3597 | + public function _construct_in_value($values, $field_obj) { |
|
3598 | 3598 | //check if the value is a CSV list |
3599 | - if(is_string($values)){ |
|
3599 | + if (is_string($values)) { |
|
3600 | 3600 | //in which case, turn it into an array |
3601 | - $values = explode(",",$values); |
|
3601 | + $values = explode(",", $values); |
|
3602 | 3602 | } |
3603 | 3603 | $cleaned_values = array(); |
3604 | - foreach($values as $value){ |
|
3605 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3604 | + foreach ($values as $value) { |
|
3605 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3606 | 3606 | } |
3607 | 3607 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3608 | 3608 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3609 | 3609 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3610 | - if(empty($cleaned_values)){ |
|
3610 | + if (empty($cleaned_values)) { |
|
3611 | 3611 | $all_fields = $this->field_settings(); |
3612 | 3612 | $a_field = array_shift($all_fields); |
3613 | 3613 | $main_table = $this->_get_main_table(); |
3614 | 3614 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3615 | 3615 | } |
3616 | - return "(".implode(",",$cleaned_values).")"; |
|
3616 | + return "(".implode(",", $cleaned_values).")"; |
|
3617 | 3617 | } |
3618 | 3618 | |
3619 | 3619 | |
@@ -3625,16 +3625,16 @@ discard block |
||
3625 | 3625 | * @throws EE_Error |
3626 | 3626 | * @return false|null|string |
3627 | 3627 | */ |
3628 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3628 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3629 | 3629 | /** @type WPDB $wpdb */ |
3630 | 3630 | global $wpdb; |
3631 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3632 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3633 | - }else{//$field_obj should really just be a data type |
|
3634 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3635 | - throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
|
3631 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3632 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3633 | + } else {//$field_obj should really just be a data type |
|
3634 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3635 | + throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"), $field_obj, implode(",", $this->_valid_wpdb_data_types))); |
|
3636 | 3636 | } |
3637 | - return $wpdb->prepare($field_obj,$value); |
|
3637 | + return $wpdb->prepare($field_obj, $value); |
|
3638 | 3638 | } |
3639 | 3639 | } |
3640 | 3640 | |
@@ -3646,27 +3646,27 @@ discard block |
||
3646 | 3646 | * @throws EE_Error |
3647 | 3647 | * @return EE_Model_Field_Base |
3648 | 3648 | */ |
3649 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3649 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3650 | 3650 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3651 | 3651 | //which will help us find the database table and column |
3652 | 3652 | |
3653 | - $query_param_parts = explode(".",$query_param_name); |
|
3654 | - if(empty($query_param_parts)){ |
|
3655 | - throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
3653 | + $query_param_parts = explode(".", $query_param_name); |
|
3654 | + if (empty($query_param_parts)) { |
|
3655 | + throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
3656 | 3656 | } |
3657 | 3657 | $number_of_parts = count($query_param_parts); |
3658 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3659 | - if($number_of_parts === 1){ |
|
3658 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3659 | + if ($number_of_parts === 1) { |
|
3660 | 3660 | $field_name = $last_query_param_part; |
3661 | 3661 | $model_obj = $this; |
3662 | - }else{// $number_of_parts >= 2 |
|
3662 | + } else {// $number_of_parts >= 2 |
|
3663 | 3663 | //the last part is the column name, and there are only 2parts. therefore... |
3664 | 3664 | $field_name = $last_query_param_part; |
3665 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3665 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3666 | 3666 | } |
3667 | - try{ |
|
3667 | + try { |
|
3668 | 3668 | return $model_obj->field_settings_for($field_name); |
3669 | - }catch(EE_Error $e){ |
|
3669 | + } catch (EE_Error $e) { |
|
3670 | 3670 | return null; |
3671 | 3671 | } |
3672 | 3672 | } |
@@ -3680,13 +3680,13 @@ discard block |
||
3680 | 3680 | * @throws EE_Error |
3681 | 3681 | * @return string |
3682 | 3682 | */ |
3683 | - public function _get_qualified_column_for_field($field_name){ |
|
3683 | + public function _get_qualified_column_for_field($field_name) { |
|
3684 | 3684 | $all_fields = $this->field_settings(); |
3685 | 3685 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3686 | - if($field){ |
|
3686 | + if ($field) { |
|
3687 | 3687 | return $field->get_qualified_column(); |
3688 | - }else{ |
|
3689 | - throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
|
3688 | + } else { |
|
3689 | + throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.", 'event_espresso'), $field_name, get_class($this))); |
|
3690 | 3690 | } |
3691 | 3691 | } |
3692 | 3692 | |
@@ -3700,17 +3700,17 @@ discard block |
||
3700 | 3700 | * @param mixed|string $limit The limit for this select |
3701 | 3701 | * @return string The final select join element for the query. |
3702 | 3702 | */ |
3703 | - public function _construct_limit_join_select( $table_alias, $limit ) { |
|
3703 | + public function _construct_limit_join_select($table_alias, $limit) { |
|
3704 | 3704 | $SQL = ''; |
3705 | - foreach ( $this->_tables as $table_obj ) { |
|
3706 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3705 | + foreach ($this->_tables as $table_obj) { |
|
3706 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3707 | 3707 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3708 | - ? $table_obj->get_select_join_limit( $limit ) |
|
3709 | - : SP . $table_obj->get_table_name() . " AS " . $table_obj->get_table_alias() . SP; |
|
3710 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3708 | + ? $table_obj->get_select_join_limit($limit) |
|
3709 | + : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3710 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3711 | 3711 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3712 | - ? $table_obj->get_select_join_limit_join( $limit ) |
|
3713 | - : SP . $table_obj->get_join_sql( $table_alias ) . SP; |
|
3712 | + ? $table_obj->get_select_join_limit_join($limit) |
|
3713 | + : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3714 | 3714 | } |
3715 | 3715 | } |
3716 | 3716 | return $SQL; |
@@ -3725,7 +3725,7 @@ discard block |
||
3725 | 3725 | * @return string SQL |
3726 | 3726 | * @throws \EE_Error |
3727 | 3727 | */ |
3728 | - public function _construct_internal_join(){ |
|
3728 | + public function _construct_internal_join() { |
|
3729 | 3729 | $SQL = $this->_get_main_table()->get_table_sql(); |
3730 | 3730 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3731 | 3731 | return $SQL; |
@@ -3746,17 +3746,17 @@ discard block |
||
3746 | 3746 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3747 | 3747 | * @return string |
3748 | 3748 | */ |
3749 | - public function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3749 | + public function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3750 | 3750 | $SQL = ''; |
3751 | 3751 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3752 | - foreach($this->_tables as $table_obj){ |
|
3753 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3754 | - if($alias_sans_prefix === $table_obj->get_table_alias()){ |
|
3752 | + foreach ($this->_tables as $table_obj) { |
|
3753 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3754 | + if ($alias_sans_prefix === $table_obj->get_table_alias()) { |
|
3755 | 3755 | //so we're joining to this table, meaning the table is already in |
3756 | 3756 | //the FROM statement, BUT the primary table isn't. So we want |
3757 | 3757 | //to add the inverse join sql |
3758 | 3758 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3759 | - }else{ |
|
3759 | + } else { |
|
3760 | 3760 | //just add a regular JOIN to this table from the primary table |
3761 | 3761 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3762 | 3762 | } |
@@ -3770,9 +3770,9 @@ discard block |
||
3770 | 3770 | * This should be a growing array of keys being table-columns (eg 'EVT_ID' and 'Event.EVT_ID'), and values being their data type (eg, '%s', '%d', etc) |
3771 | 3771 | * @return array |
3772 | 3772 | */ |
3773 | - public function _get_data_types(){ |
|
3773 | + public function _get_data_types() { |
|
3774 | 3774 | $data_types = array(); |
3775 | - foreach( $this->field_settings() as $field_obj){ |
|
3775 | + foreach ($this->field_settings() as $field_obj) { |
|
3776 | 3776 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3777 | 3777 | /** @var $field_obj EE_Model_Field_Base */ |
3778 | 3778 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3788,10 +3788,10 @@ discard block |
||
3788 | 3788 | * @throws EE_Error |
3789 | 3789 | * @return EEM_Base |
3790 | 3790 | */ |
3791 | - public function get_related_model_obj($model_name){ |
|
3791 | + public function get_related_model_obj($model_name) { |
|
3792 | 3792 | $model_classname = "EEM_".$model_name; |
3793 | - if(!class_exists($model_classname)){ |
|
3794 | - throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s",'event_espresso'),$model_name,$model_classname)); |
|
3793 | + if ( ! class_exists($model_classname)) { |
|
3794 | + throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname)); |
|
3795 | 3795 | } |
3796 | 3796 | return call_user_func($model_classname."::instance"); |
3797 | 3797 | } |
@@ -3801,7 +3801,7 @@ discard block |
||
3801 | 3801 | * Returns the array of EE_ModelRelations for this model. |
3802 | 3802 | * @return EE_Model_Relation_Base[] |
3803 | 3803 | */ |
3804 | - public function relation_settings(){ |
|
3804 | + public function relation_settings() { |
|
3805 | 3805 | return $this->_model_relations; |
3806 | 3806 | } |
3807 | 3807 | |
@@ -3811,10 +3811,10 @@ discard block |
||
3811 | 3811 | * (Eg, without an event, datetimes have little purpose.) |
3812 | 3812 | * @return EE_Belongs_To_Relation[] |
3813 | 3813 | */ |
3814 | - public function belongs_to_relations(){ |
|
3814 | + public function belongs_to_relations() { |
|
3815 | 3815 | $belongs_to_relations = array(); |
3816 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3817 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3816 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3817 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3818 | 3818 | $belongs_to_relations[$model_name] = $relation_obj; |
3819 | 3819 | } |
3820 | 3820 | } |
@@ -3829,15 +3829,15 @@ discard block |
||
3829 | 3829 | * @throws EE_Error |
3830 | 3830 | * @return EE_Model_Relation_Base |
3831 | 3831 | */ |
3832 | - public function related_settings_for($relation_name){ |
|
3833 | - $relatedModels=$this->relation_settings(); |
|
3834 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3832 | + public function related_settings_for($relation_name) { |
|
3833 | + $relatedModels = $this->relation_settings(); |
|
3834 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3835 | 3835 | throw new EE_Error( |
3836 | 3836 | sprintf( |
3837 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3837 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3838 | 3838 | $relation_name, |
3839 | 3839 | $this->_get_class_name(), |
3840 | - implode( ', ', array_keys( $relatedModels )) |
|
3840 | + implode(', ', array_keys($relatedModels)) |
|
3841 | 3841 | ) |
3842 | 3842 | ); |
3843 | 3843 | } |
@@ -3852,10 +3852,10 @@ discard block |
||
3852 | 3852 | * @throws EE_Error |
3853 | 3853 | * @return EE_Model_Field_Base |
3854 | 3854 | */ |
3855 | - public function field_settings_for($fieldName){ |
|
3856 | - $fieldSettings=$this->field_settings(true); |
|
3857 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3858 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3855 | + public function field_settings_for($fieldName) { |
|
3856 | + $fieldSettings = $this->field_settings(true); |
|
3857 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3858 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3859 | 3859 | } |
3860 | 3860 | return $fieldSettings[$fieldName]; |
3861 | 3861 | } |
@@ -3865,11 +3865,11 @@ discard block |
||
3865 | 3865 | * @param string $fieldName a key in the model's _field_settings array |
3866 | 3866 | * @return boolean |
3867 | 3867 | */ |
3868 | - public function has_field($fieldName){ |
|
3868 | + public function has_field($fieldName) { |
|
3869 | 3869 | $fieldSettings = $this->field_settings(true); |
3870 | - if( isset($fieldSettings[$fieldName])){ |
|
3870 | + if (isset($fieldSettings[$fieldName])) { |
|
3871 | 3871 | return true; |
3872 | - }else{ |
|
3872 | + } else { |
|
3873 | 3873 | return false; |
3874 | 3874 | } |
3875 | 3875 | } |
@@ -3879,11 +3879,11 @@ discard block |
||
3879 | 3879 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3880 | 3880 | * @return boolean |
3881 | 3881 | */ |
3882 | - public function has_relation($relation_name){ |
|
3882 | + public function has_relation($relation_name) { |
|
3883 | 3883 | $relations = $this->relation_settings(); |
3884 | - if(isset($relations[$relation_name])){ |
|
3884 | + if (isset($relations[$relation_name])) { |
|
3885 | 3885 | return true; |
3886 | - }else{ |
|
3886 | + } else { |
|
3887 | 3887 | return false; |
3888 | 3888 | } |
3889 | 3889 | } |
@@ -3895,7 +3895,7 @@ discard block |
||
3895 | 3895 | * @param $field_obj |
3896 | 3896 | * @return EE_Model_Field_Base |
3897 | 3897 | */ |
3898 | - public function is_primary_key_field( $field_obj ){ |
|
3898 | + public function is_primary_key_field($field_obj) { |
|
3899 | 3899 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3900 | 3900 | } |
3901 | 3901 | |
@@ -3907,16 +3907,16 @@ discard block |
||
3907 | 3907 | * @return EE_Model_Field_Base |
3908 | 3908 | * @throws EE_Error |
3909 | 3909 | */ |
3910 | - public function get_primary_key_field(){ |
|
3911 | - if( $this->_primary_key_field === NULL ){ |
|
3912 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3913 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3910 | + public function get_primary_key_field() { |
|
3911 | + if ($this->_primary_key_field === NULL) { |
|
3912 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3913 | + if ($this->is_primary_key_field($field_obj)) { |
|
3914 | 3914 | $this->_primary_key_field = $field_obj; |
3915 | 3915 | break; |
3916 | 3916 | } |
3917 | 3917 | } |
3918 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3919 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3918 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3919 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3920 | 3920 | } |
3921 | 3921 | } |
3922 | 3922 | return $this->_primary_key_field; |
@@ -3929,12 +3929,12 @@ discard block |
||
3929 | 3929 | * Internally does some caching. |
3930 | 3930 | * @return boolean |
3931 | 3931 | */ |
3932 | - public function has_primary_key_field(){ |
|
3933 | - if($this->_has_primary_key_field === null){ |
|
3934 | - try{ |
|
3932 | + public function has_primary_key_field() { |
|
3933 | + if ($this->_has_primary_key_field === null) { |
|
3934 | + try { |
|
3935 | 3935 | $this->get_primary_key_field(); |
3936 | 3936 | $this->_has_primary_key_field = true; |
3937 | - }catch(EE_Error $e){ |
|
3937 | + } catch (EE_Error $e) { |
|
3938 | 3938 | $this->_has_primary_key_field = false; |
3939 | 3939 | } |
3940 | 3940 | } |
@@ -3948,9 +3948,9 @@ discard block |
||
3948 | 3948 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3949 | 3949 | * @return EE_Model_Field_Base or null if none is found |
3950 | 3950 | */ |
3951 | - public function get_a_field_of_type($field_class_name){ |
|
3952 | - foreach($this->field_settings() as $field){ |
|
3953 | - if( $field instanceof $field_class_name ){ |
|
3951 | + public function get_a_field_of_type($field_class_name) { |
|
3952 | + foreach ($this->field_settings() as $field) { |
|
3953 | + if ($field instanceof $field_class_name) { |
|
3954 | 3954 | return $field; |
3955 | 3955 | } |
3956 | 3956 | } |
@@ -3964,22 +3964,22 @@ discard block |
||
3964 | 3964 | * @return EE_Foreign_Key_Field_Base |
3965 | 3965 | * @throws EE_Error |
3966 | 3966 | */ |
3967 | - public function get_foreign_key_to($model_name){ |
|
3968 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3969 | - foreach($this->field_settings() as $field){ |
|
3970 | - if( |
|
3967 | + public function get_foreign_key_to($model_name) { |
|
3968 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3969 | + foreach ($this->field_settings() as $field) { |
|
3970 | + if ( |
|
3971 | 3971 | $field instanceof EE_Foreign_Key_Field_Base |
3972 | - && in_array($model_name,$field->get_model_names_pointed_to() ) |
|
3972 | + && in_array($model_name, $field->get_model_names_pointed_to()) |
|
3973 | 3973 | ) { |
3974 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
3974 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
3975 | 3975 | break; |
3976 | 3976 | } |
3977 | 3977 | } |
3978 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3979 | - throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s",'event_espresso'),$model_name,get_class($this))); |
|
3978 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3979 | + throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this))); |
|
3980 | 3980 | } |
3981 | 3981 | } |
3982 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
3982 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
3983 | 3983 | } |
3984 | 3984 | |
3985 | 3985 | |
@@ -3990,7 +3990,7 @@ discard block |
||
3990 | 3990 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3991 | 3991 | * @return EE_Table_Base |
3992 | 3992 | */ |
3993 | - public function get_table_for_alias($table_alias){ |
|
3993 | + public function get_table_for_alias($table_alias) { |
|
3994 | 3994 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
3995 | 3995 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
3996 | 3996 | } |
@@ -4003,25 +4003,25 @@ discard block |
||
4003 | 4003 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
4004 | 4004 | * @return EE_Model_Field_Base[] where the keys are the field's name |
4005 | 4005 | */ |
4006 | - public function field_settings($include_db_only_fields = false){ |
|
4007 | - if( $include_db_only_fields ){ |
|
4008 | - if( $this->_cached_fields === NULL ){ |
|
4006 | + public function field_settings($include_db_only_fields = false) { |
|
4007 | + if ($include_db_only_fields) { |
|
4008 | + if ($this->_cached_fields === NULL) { |
|
4009 | 4009 | $this->_cached_fields = array(); |
4010 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
4011 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
4012 | - $this->_cached_fields[$field_name]=$field_obj; |
|
4010 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
4011 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
4012 | + $this->_cached_fields[$field_name] = $field_obj; |
|
4013 | 4013 | } |
4014 | 4014 | } |
4015 | 4015 | } |
4016 | 4016 | return $this->_cached_fields; |
4017 | - }else{ |
|
4018 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
4017 | + } else { |
|
4018 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
4019 | 4019 | $this->_cached_fields_non_db_only = array(); |
4020 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
4021 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
4020 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
4021 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
4022 | 4022 | /** @var $field_obj EE_Model_Field_Base */ |
4023 | - if( ! $field_obj->is_db_only_field() ){ |
|
4024 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
4023 | + if ( ! $field_obj->is_db_only_field()) { |
|
4024 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
4025 | 4025 | } |
4026 | 4026 | } |
4027 | 4027 | } |
@@ -4040,60 +4040,60 @@ discard block |
||
4040 | 4040 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
4041 | 4041 | * @throws \EE_Error |
4042 | 4042 | */ |
4043 | - protected function _create_objects( $rows = array() ) { |
|
4044 | - $array_of_objects=array(); |
|
4045 | - if(empty($rows)){ |
|
4043 | + protected function _create_objects($rows = array()) { |
|
4044 | + $array_of_objects = array(); |
|
4045 | + if (empty($rows)) { |
|
4046 | 4046 | return array(); |
4047 | 4047 | } |
4048 | 4048 | $count_if_model_has_no_primary_key = 0; |
4049 | 4049 | $has_primary_key = $this->has_primary_key_field(); |
4050 | 4050 | $primary_key_field = $has_primary_key ? $this->get_primary_key_field() : null; |
4051 | - foreach ( (array)$rows as $row ) { |
|
4052 | - if(empty($row)){ |
|
4051 | + foreach ((array) $rows as $row) { |
|
4052 | + if (empty($row)) { |
|
4053 | 4053 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
4054 | 4054 | return array(); |
4055 | 4055 | } |
4056 | 4056 | //check if we've already set this object in the results array, |
4057 | 4057 | //in which case there's no need to process it further (again) |
4058 | - if( $has_primary_key ) { |
|
4058 | + if ($has_primary_key) { |
|
4059 | 4059 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
4060 | 4060 | $row, |
4061 | 4061 | $primary_key_field->get_qualified_column(), |
4062 | 4062 | $primary_key_field->get_table_column() |
4063 | 4063 | ); |
4064 | - if( $table_pk_value && isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
4064 | + if ($table_pk_value && isset($array_of_objects[$table_pk_value])) { |
|
4065 | 4065 | continue; |
4066 | 4066 | } |
4067 | 4067 | } |
4068 | 4068 | $classInstance = $this->instantiate_class_from_array_or_object($row); |
4069 | - if( ! $classInstance ) { |
|
4069 | + if ( ! $classInstance) { |
|
4070 | 4070 | throw new EE_Error( |
4071 | 4071 | sprintf( |
4072 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
4072 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
4073 | 4073 | $this->get_this_model_name(), |
4074 | - http_build_query( $row ) |
|
4074 | + http_build_query($row) |
|
4075 | 4075 | ) |
4076 | 4076 | ); |
4077 | 4077 | } |
4078 | 4078 | //set the timezone on the instantiated objects |
4079 | - $classInstance->set_timezone( $this->_timezone ); |
|
4079 | + $classInstance->set_timezone($this->_timezone); |
|
4080 | 4080 | //make sure if there is any timezone setting present that we set the timezone for the object |
4081 | 4081 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
4082 | - $array_of_objects[ $key ] = $classInstance; |
|
4082 | + $array_of_objects[$key] = $classInstance; |
|
4083 | 4083 | //also, for all the relations of type BelongsTo, see if we can cache |
4084 | 4084 | //those related models |
4085 | 4085 | //(we could do this for other relations too, but if there are conditions |
4086 | 4086 | //that filtered out some fo the results, then we'd be caching an incomplete set |
4087 | 4087 | //so it requires a little more thought than just caching them immediately...) |
4088 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
4089 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
4088 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
4089 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
4090 | 4090 | //check if this model's INFO is present. If so, cache it on the model |
4091 | 4091 | $other_model = $relation_obj->get_other_model(); |
4092 | 4092 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
4093 | 4093 | //if we managed to make a model object from the results, cache it on the main model object |
4094 | - if( $other_model_obj_maybe ){ |
|
4094 | + if ($other_model_obj_maybe) { |
|
4095 | 4095 | //set timezone on these other model objects if they are present |
4096 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
4096 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
4097 | 4097 | $classInstance->cache($modelName, $other_model_obj_maybe); |
4098 | 4098 | } |
4099 | 4099 | } |
@@ -4114,12 +4114,12 @@ discard block |
||
4114 | 4114 | |
4115 | 4115 | $this_model_fields_and_values = array(); |
4116 | 4116 | //setup the row using default values; |
4117 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
4117 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
4118 | 4118 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
4119 | 4119 | } |
4120 | 4120 | |
4121 | 4121 | $className = $this->_get_class_name(); |
4122 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
4122 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
4123 | 4123 | |
4124 | 4124 | return $classInstance; |
4125 | 4125 | } |
@@ -4132,45 +4132,45 @@ discard block |
||
4132 | 4132 | * @return EE_Base_Class |
4133 | 4133 | * @throws \EE_Error |
4134 | 4134 | */ |
4135 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
4136 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
4137 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
4135 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
4136 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
4137 | + $cols_n_values = get_object_vars($cols_n_values); |
|
4138 | 4138 | } |
4139 | 4139 | $primary_key = NULL; |
4140 | 4140 | //make sure the array only has keys that are fields/columns on this model |
4141 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4142 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
4143 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
4141 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4142 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4143 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
4144 | 4144 | } |
4145 | - $className=$this->_get_class_name(); |
|
4145 | + $className = $this->_get_class_name(); |
|
4146 | 4146 | |
4147 | 4147 | //check we actually found results that we can use to build our model object |
4148 | 4148 | //if not, return null |
4149 | - if( $this->has_primary_key_field()){ |
|
4150 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
4149 | + if ($this->has_primary_key_field()) { |
|
4150 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4151 | 4151 | return NULL; |
4152 | 4152 | } |
4153 | - }else if($this->unique_indexes()){ |
|
4153 | + } else if ($this->unique_indexes()) { |
|
4154 | 4154 | $first_column = reset($this_model_fields_n_values); |
4155 | - if(empty($first_column)){ |
|
4155 | + if (empty($first_column)) { |
|
4156 | 4156 | return NULL; |
4157 | 4157 | } |
4158 | 4158 | } |
4159 | 4159 | |
4160 | 4160 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
4161 | - if ( $primary_key){ |
|
4162 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
4163 | - if( ! $classInstance) { |
|
4164 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4161 | + if ($primary_key) { |
|
4162 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
4163 | + if ( ! $classInstance) { |
|
4164 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4165 | 4165 | // add this new object to the entity map |
4166 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
4166 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
4167 | 4167 | } |
4168 | - }else{ |
|
4169 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4168 | + } else { |
|
4169 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4170 | 4170 | } |
4171 | 4171 | |
4172 | 4172 | //it is entirely possible that the instantiated class object has a set timezone_string db field and has set it's internal _timezone property accordingly (see new_instance_from_db in model objects particularly EE_Event for example). In this case, we want to make sure the model object doesn't have its timezone string overwritten by any timezone property currently set here on the model so, we intentionally override the model _timezone property with the model_object timezone property. |
4173 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
4173 | + $this->set_timezone($classInstance->get_timezone()); |
|
4174 | 4174 | return $classInstance; |
4175 | 4175 | } |
4176 | 4176 | /** |
@@ -4178,8 +4178,8 @@ discard block |
||
4178 | 4178 | * @param int|string $id the ID of the model object |
4179 | 4179 | * @return EE_Base_Class |
4180 | 4180 | */ |
4181 | - public function get_from_entity_map( $id ){ |
|
4182 | - return isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ) ? $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] : NULL; |
|
4181 | + public function get_from_entity_map($id) { |
|
4182 | + return isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id]) ? $this->_entity_map[EEM_Base::$_model_query_blog_id][$id] : NULL; |
|
4183 | 4183 | } |
4184 | 4184 | |
4185 | 4185 | |
@@ -4201,21 +4201,21 @@ discard block |
||
4201 | 4201 | * @throws EE_Error |
4202 | 4202 | * @return \EE_Base_Class |
4203 | 4203 | */ |
4204 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
4204 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
4205 | 4205 | $className = $this->_get_class_name(); |
4206 | - if( ! $object instanceof $className ){ |
|
4207 | - throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"),is_object( $object ) ? get_class( $object ) : $object, $className ) ); |
|
4206 | + if ( ! $object instanceof $className) { |
|
4207 | + throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className)); |
|
4208 | 4208 | } |
4209 | 4209 | /** @var $object EE_Base_Class */ |
4210 | - if ( ! $object->ID() ){ |
|
4211 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
4210 | + if ( ! $object->ID()) { |
|
4211 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
4212 | 4212 | } |
4213 | 4213 | // double check it's not already there |
4214 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
4215 | - if ( $classInstance ) { |
|
4214 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
4215 | + if ($classInstance) { |
|
4216 | 4216 | return $classInstance; |
4217 | 4217 | } else { |
4218 | - $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $object->ID() ] = $object; |
|
4218 | + $this->_entity_map[EEM_Base::$_model_query_blog_id][$object->ID()] = $object; |
|
4219 | 4219 | return $object; |
4220 | 4220 | } |
4221 | 4221 | } |
@@ -4228,8 +4228,8 @@ discard block |
||
4228 | 4228 | * @param array $cols_n_values |
4229 | 4229 | * @return array |
4230 | 4230 | */ |
4231 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
4232 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4231 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4232 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4233 | 4233 | } |
4234 | 4234 | |
4235 | 4235 | |
@@ -4242,23 +4242,23 @@ discard block |
||
4242 | 4242 | * @param string $cols_n_values |
4243 | 4243 | * @return array |
4244 | 4244 | */ |
4245 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
4245 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4246 | 4246 | $this_model_fields_n_values = array(); |
4247 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
4248 | - $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column() ); |
|
4247 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
4248 | + $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column()); |
|
4249 | 4249 | //there is a primary key on this table and its not set. Use defaults for all its columns |
4250 | - if( $table_pk_value === null && $table_obj->get_pk_column() ){ |
|
4251 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4252 | - if( ! $field_obj->is_db_only_field() ){ |
|
4250 | + if ($table_pk_value === null && $table_obj->get_pk_column()) { |
|
4251 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4252 | + if ( ! $field_obj->is_db_only_field()) { |
|
4253 | 4253 | //prepare field as if its coming from db |
4254 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
4255 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
4254 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
4255 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
4256 | 4256 | } |
4257 | 4257 | } |
4258 | - }else{ |
|
4258 | + } else { |
|
4259 | 4259 | //the table's rows existed. Use their values |
4260 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4261 | - if( ! $field_obj->is_db_only_field() ){ |
|
4260 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4261 | + if ( ! $field_obj->is_db_only_field()) { |
|
4262 | 4262 | $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not( |
4263 | 4263 | $cols_n_values, $field_obj->get_qualified_column(), |
4264 | 4264 | $field_obj->get_table_column() |
@@ -4278,15 +4278,15 @@ discard block |
||
4278 | 4278 | * @param $regular_column |
4279 | 4279 | * @return null |
4280 | 4280 | */ |
4281 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
4281 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
4282 | 4282 | $value = null; |
4283 | 4283 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
4284 | 4284 | //does the field on the model relate to this column retrieved from the db? |
4285 | 4285 | //or is it a db-only field? (not relating to the model) |
4286 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
4287 | - $value = $cols_n_values[ $qualified_column ]; |
|
4288 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4289 | - $value = $cols_n_values[ $regular_column ]; |
|
4286 | + if (isset($cols_n_values[$qualified_column])) { |
|
4287 | + $value = $cols_n_values[$qualified_column]; |
|
4288 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
4289 | + $value = $cols_n_values[$regular_column]; |
|
4290 | 4290 | } |
4291 | 4291 | return $value; |
4292 | 4292 | } |
@@ -4302,25 +4302,25 @@ discard block |
||
4302 | 4302 | * @return EE_Base_Class |
4303 | 4303 | * @throws \EE_Error |
4304 | 4304 | */ |
4305 | - public function refresh_entity_map_from_db( $id ){ |
|
4306 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4307 | - if( $obj_in_map ){ |
|
4305 | + public function refresh_entity_map_from_db($id) { |
|
4306 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4307 | + if ($obj_in_map) { |
|
4308 | 4308 | $wpdb_results = $this->_get_all_wpdb_results( |
4309 | - array( array( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) |
|
4309 | + array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1) |
|
4310 | 4310 | ); |
4311 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
4312 | - $one_row = reset( $wpdb_results ); |
|
4313 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
4314 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
4311 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
4312 | + $one_row = reset($wpdb_results); |
|
4313 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
4314 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
4315 | 4315 | } |
4316 | 4316 | //clear the cache of related model objects |
4317 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4318 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4317 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4318 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4319 | 4319 | } |
4320 | 4320 | } |
4321 | 4321 | return $obj_in_map; |
4322 | - }else{ |
|
4323 | - return $this->get_one_by_ID( $id ); |
|
4322 | + } else { |
|
4323 | + return $this->get_one_by_ID($id); |
|
4324 | 4324 | } |
4325 | 4325 | } |
4326 | 4326 | |
@@ -4338,24 +4338,24 @@ discard block |
||
4338 | 4338 | * @return \EE_Base_Class |
4339 | 4339 | * @throws \EE_Error |
4340 | 4340 | */ |
4341 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
4342 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4343 | - if( $obj_in_map ){ |
|
4344 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
4345 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
4346 | - $obj_in_map->set( $field_name, $value ); |
|
4341 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
4342 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4343 | + if ($obj_in_map) { |
|
4344 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
4345 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
4346 | + $obj_in_map->set($field_name, $value); |
|
4347 | 4347 | } |
4348 | 4348 | //make the model object in the entity map's cache match the $replacing_model_obj |
4349 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4350 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4351 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
4352 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
4349 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4350 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4351 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
4352 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
4353 | 4353 | } |
4354 | 4354 | } |
4355 | 4355 | } |
4356 | 4356 | return $obj_in_map; |
4357 | - }else{ |
|
4358 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
4357 | + } else { |
|
4358 | + $this->add_to_entity_map($replacing_model_obj); |
|
4359 | 4359 | return $replacing_model_obj; |
4360 | 4360 | } |
4361 | 4361 | } |
@@ -4368,7 +4368,7 @@ discard block |
||
4368 | 4368 | * require_once($this->_getClassName().".class.php"); |
4369 | 4369 | * @return string |
4370 | 4370 | */ |
4371 | - private function _get_class_name(){ |
|
4371 | + private function _get_class_name() { |
|
4372 | 4372 | return "EE_".$this->get_this_model_name(); |
4373 | 4373 | } |
4374 | 4374 | |
@@ -4381,8 +4381,8 @@ discard block |
||
4381 | 4381 | * @param int $quantity |
4382 | 4382 | * @return string |
4383 | 4383 | */ |
4384 | - public function item_name($quantity = 1){ |
|
4385 | - return (int)$quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4384 | + public function item_name($quantity = 1) { |
|
4385 | + return (int) $quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4386 | 4386 | } |
4387 | 4387 | |
4388 | 4388 | |
@@ -4409,13 +4409,13 @@ discard block |
||
4409 | 4409 | * @throws EE_Error |
4410 | 4410 | * @return mixed whatever the plugin which calls add_filter decides |
4411 | 4411 | */ |
4412 | - public function __call($methodName,$args){ |
|
4413 | - $className=get_class($this); |
|
4414 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
4415 | - if(!has_filter($tagName)){ |
|
4412 | + public function __call($methodName, $args) { |
|
4413 | + $className = get_class($this); |
|
4414 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
4415 | + if ( ! has_filter($tagName)) { |
|
4416 | 4416 | throw new EE_Error( |
4417 | 4417 | sprintf( |
4418 | - __( 'Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso' ), |
|
4418 | + __('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'), |
|
4419 | 4419 | $methodName, |
4420 | 4420 | $className, |
4421 | 4421 | $tagName, |
@@ -4424,7 +4424,7 @@ discard block |
||
4424 | 4424 | ); |
4425 | 4425 | } |
4426 | 4426 | |
4427 | - return apply_filters($tagName,null,$this,$args); |
|
4427 | + return apply_filters($tagName, null, $this, $args); |
|
4428 | 4428 | } |
4429 | 4429 | |
4430 | 4430 | |
@@ -4442,28 +4442,28 @@ discard block |
||
4442 | 4442 | * @throws EE_Error |
4443 | 4443 | * @return EE_Base_Class |
4444 | 4444 | */ |
4445 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
4445 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
4446 | 4446 | $className = $this->_get_class_name(); |
4447 | - if ( $base_class_obj_or_id instanceof $className ) { |
|
4447 | + if ($base_class_obj_or_id instanceof $className) { |
|
4448 | 4448 | $model_object = $base_class_obj_or_id; |
4449 | 4449 | } else { |
4450 | 4450 | $primary_key_field = $this->get_primary_key_field(); |
4451 | 4451 | if ( |
4452 | 4452 | $primary_key_field instanceof EE_Primary_Key_Int_Field |
4453 | 4453 | && ( |
4454 | - is_int( $base_class_obj_or_id ) |
|
4455 | - || is_string( $base_class_obj_or_id ) |
|
4454 | + is_int($base_class_obj_or_id) |
|
4455 | + || is_string($base_class_obj_or_id) |
|
4456 | 4456 | ) |
4457 | 4457 | ) { |
4458 | 4458 | // assume it's an ID. |
4459 | 4459 | // either a proper integer or a string representing an integer (eg "101" instead of 101) |
4460 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4460 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4461 | 4461 | } else if ( |
4462 | 4462 | $primary_key_field instanceof EE_Primary_Key_String_Field |
4463 | - && is_string( $base_class_obj_or_id ) |
|
4463 | + && is_string($base_class_obj_or_id) |
|
4464 | 4464 | ) { |
4465 | 4465 | // assume its a string representation of the object |
4466 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4466 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4467 | 4467 | } else { |
4468 | 4468 | throw new EE_Error( |
4469 | 4469 | sprintf( |
@@ -4473,12 +4473,12 @@ discard block |
||
4473 | 4473 | ), |
4474 | 4474 | $base_class_obj_or_id, |
4475 | 4475 | $this->_get_class_name(), |
4476 | - print_r( $base_class_obj_or_id, true ) |
|
4476 | + print_r($base_class_obj_or_id, true) |
|
4477 | 4477 | ) |
4478 | 4478 | ); |
4479 | 4479 | } |
4480 | 4480 | } |
4481 | - if ( $ensure_is_in_db && $model_object->ID() !== null ) { |
|
4481 | + if ($ensure_is_in_db && $model_object->ID() !== null) { |
|
4482 | 4482 | $model_object->save(); |
4483 | 4483 | } |
4484 | 4484 | return $model_object; |
@@ -4494,19 +4494,19 @@ discard block |
||
4494 | 4494 | * @return int|string depending on the type of this model object's ID |
4495 | 4495 | * @throws EE_Error |
4496 | 4496 | */ |
4497 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4497 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4498 | 4498 | $className = $this->_get_class_name(); |
4499 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4499 | + if ($base_class_obj_or_id instanceof $className) { |
|
4500 | 4500 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4501 | 4501 | $id = $base_class_obj_or_id->ID(); |
4502 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4502 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4503 | 4503 | //assume it's an ID |
4504 | 4504 | $id = $base_class_obj_or_id; |
4505 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4505 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4506 | 4506 | //assume its a string representation of the object |
4507 | 4507 | $id = $base_class_obj_or_id; |
4508 | - }else{ |
|
4509 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
4508 | + } else { |
|
4509 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
4510 | 4510 | } |
4511 | 4511 | return $id; |
4512 | 4512 | } |
@@ -4529,14 +4529,14 @@ discard block |
||
4529 | 4529 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4530 | 4530 | * @return void |
4531 | 4531 | */ |
4532 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4532 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4533 | 4533 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4534 | 4534 | } |
4535 | 4535 | /** |
4536 | 4536 | * Read comments for assume_values_already_prepared_by_model_object() |
4537 | 4537 | * @return int |
4538 | 4538 | */ |
4539 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4539 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4540 | 4540 | return $this->_values_already_prepared_by_model_object; |
4541 | 4541 | } |
4542 | 4542 | |
@@ -4544,17 +4544,17 @@ discard block |
||
4544 | 4544 | * Gets all the indexes on this model |
4545 | 4545 | * @return EE_Index[] |
4546 | 4546 | */ |
4547 | - public function indexes(){ |
|
4547 | + public function indexes() { |
|
4548 | 4548 | return $this->_indexes; |
4549 | 4549 | } |
4550 | 4550 | /** |
4551 | 4551 | * Gets all the Unique Indexes on this model |
4552 | 4552 | * @return EE_Unique_Index[] |
4553 | 4553 | */ |
4554 | - public function unique_indexes(){ |
|
4554 | + public function unique_indexes() { |
|
4555 | 4555 | $unique_indexes = array(); |
4556 | - foreach($this->_indexes as $name => $index){ |
|
4557 | - if($index instanceof EE_Unique_Index){ |
|
4556 | + foreach ($this->_indexes as $name => $index) { |
|
4557 | + if ($index instanceof EE_Unique_Index) { |
|
4558 | 4558 | $unique_indexes [$name] = $index; |
4559 | 4559 | } |
4560 | 4560 | } |
@@ -4572,13 +4572,13 @@ discard block |
||
4572 | 4572 | * @return EE_Model_Field_Base[] indexed by the field's name |
4573 | 4573 | * @throws \EE_Error |
4574 | 4574 | */ |
4575 | - public function get_combined_primary_key_fields(){ |
|
4576 | - foreach($this->indexes() as $index){ |
|
4577 | - if($index instanceof EE_Primary_Key_Index){ |
|
4575 | + public function get_combined_primary_key_fields() { |
|
4576 | + foreach ($this->indexes() as $index) { |
|
4577 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4578 | 4578 | return $index->fields(); |
4579 | 4579 | } |
4580 | 4580 | } |
4581 | - return array( $this->primary_key_name() => $this->get_primary_key_field()); |
|
4581 | + return array($this->primary_key_name() => $this->get_primary_key_field()); |
|
4582 | 4582 | } |
4583 | 4583 | |
4584 | 4584 | |
@@ -4592,7 +4592,7 @@ discard block |
||
4592 | 4592 | * @return string |
4593 | 4593 | * @throws \EE_Error |
4594 | 4594 | */ |
4595 | - public function get_index_primary_key_string($cols_n_values){ |
|
4595 | + public function get_index_primary_key_string($cols_n_values) { |
|
4596 | 4596 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4597 | 4597 | return http_build_query($cols_n_values_for_primary_key_index); |
4598 | 4598 | } |
@@ -4607,13 +4607,13 @@ discard block |
||
4607 | 4607 | * @return null|array |
4608 | 4608 | * @throws \EE_Error |
4609 | 4609 | */ |
4610 | - public function parse_index_primary_key_string( $index_primary_key_string) { |
|
4610 | + public function parse_index_primary_key_string($index_primary_key_string) { |
|
4611 | 4611 | $key_fields = $this->get_combined_primary_key_fields(); |
4612 | 4612 | //check all of them are in the $id |
4613 | 4613 | $key_vals_in_combined_pk = array(); |
4614 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4615 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4616 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4614 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4615 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4616 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4617 | 4617 | return NULL; |
4618 | 4618 | } |
4619 | 4619 | } |
@@ -4630,10 +4630,10 @@ discard block |
||
4630 | 4630 | * @return boolean |
4631 | 4631 | * @throws \EE_Error |
4632 | 4632 | */ |
4633 | - public function has_all_combined_primary_key_fields( $key_vals ) { |
|
4634 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4635 | - foreach( $keys_it_should_have as $key ){ |
|
4636 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4633 | + public function has_all_combined_primary_key_fields($key_vals) { |
|
4634 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4635 | + foreach ($keys_it_should_have as $key) { |
|
4636 | + if ( ! isset($key_vals[$key])) { |
|
4637 | 4637 | return false; |
4638 | 4638 | } |
4639 | 4639 | } |
@@ -4649,23 +4649,23 @@ discard block |
||
4649 | 4649 | * @throws EE_Error |
4650 | 4650 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4651 | 4651 | */ |
4652 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4652 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4653 | 4653 | |
4654 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4654 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4655 | 4655 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4656 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4656 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4657 | 4657 | $attributes_array = $model_object_or_attributes_array; |
4658 | - }else{ |
|
4659 | - throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
|
4658 | + } else { |
|
4659 | + throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"), $model_object_or_attributes_array)); |
|
4660 | 4660 | } |
4661 | 4661 | //even copies obviously won't have the same ID, so remove the primary key |
4662 | 4662 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4663 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4663 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4664 | 4664 | unset($attributes_array[$this->primary_key_name()]); |
4665 | 4665 | } |
4666 | - if(isset($query_params[0])){ |
|
4667 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4668 | - }else{ |
|
4666 | + if (isset($query_params[0])) { |
|
4667 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4668 | + } else { |
|
4669 | 4669 | $query_params[0] = $attributes_array; |
4670 | 4670 | } |
4671 | 4671 | return $this->get_all($query_params); |
@@ -4681,16 +4681,16 @@ discard block |
||
4681 | 4681 | * @return EE_Base_Class |
4682 | 4682 | * @throws \EE_Error |
4683 | 4683 | */ |
4684 | - public function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4685 | - if( ! is_array( $query_params ) ){ |
|
4686 | - EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
4684 | + public function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4685 | + if ( ! is_array($query_params)) { |
|
4686 | + EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
4687 | 4687 | $query_params = array(); |
4688 | 4688 | } |
4689 | 4689 | $query_params['limit'] = 1; |
4690 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4691 | - if(is_array($copies)){ |
|
4690 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4691 | + if (is_array($copies)) { |
|
4692 | 4692 | return array_shift($copies); |
4693 | - }else{ |
|
4693 | + } else { |
|
4694 | 4694 | return null; |
4695 | 4695 | } |
4696 | 4696 | } |
@@ -4706,10 +4706,10 @@ discard block |
||
4706 | 4706 | * @return int number of rows updated |
4707 | 4707 | * @throws \EE_Error |
4708 | 4708 | */ |
4709 | - public function update_by_ID($fields_n_values,$id){ |
|
4709 | + public function update_by_ID($fields_n_values, $id) { |
|
4710 | 4710 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4711 | 4711 | 'default_where_conditions'=>'other_models_only',); |
4712 | - return $this->update($fields_n_values,$query_params); |
|
4712 | + return $this->update($fields_n_values, $query_params); |
|
4713 | 4713 | } |
4714 | 4714 | |
4715 | 4715 | |
@@ -4720,12 +4720,12 @@ discard block |
||
4720 | 4720 | * @return string an operator which can be used in SQL |
4721 | 4721 | * @throws EE_Error |
4722 | 4722 | */ |
4723 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4723 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4724 | 4724 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4725 | - if($sql_operator){ |
|
4725 | + if ($sql_operator) { |
|
4726 | 4726 | return $sql_operator; |
4727 | - }else{ |
|
4728 | - throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
|
4727 | + } else { |
|
4728 | + throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"), $operator_supplied, implode(",", array_keys($this->_valid_operators)))); |
|
4729 | 4729 | } |
4730 | 4730 | } |
4731 | 4731 | |
@@ -4739,10 +4739,10 @@ discard block |
||
4739 | 4739 | * @return string[] |
4740 | 4740 | * @throws \EE_Error |
4741 | 4741 | */ |
4742 | - public function get_all_names($query_params = array()){ |
|
4742 | + public function get_all_names($query_params = array()) { |
|
4743 | 4743 | $objs = $this->get_all($query_params); |
4744 | 4744 | $names = array(); |
4745 | - foreach($objs as $obj){ |
|
4745 | + foreach ($objs as $obj) { |
|
4746 | 4746 | $names[$obj->ID()] = $obj->name(); |
4747 | 4747 | } |
4748 | 4748 | return $names; |
@@ -4761,11 +4761,11 @@ discard block |
||
4761 | 4761 | * @return array |
4762 | 4762 | * @throws \EE_Error |
4763 | 4763 | */ |
4764 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4765 | - if( ! $this->has_primary_key_field() ) { |
|
4766 | - if( WP_DEBUG ) { |
|
4764 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4765 | + if ( ! $this->has_primary_key_field()) { |
|
4766 | + if (WP_DEBUG) { |
|
4767 | 4767 | EE_Error::add_error( |
4768 | - __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), |
|
4768 | + __('Trying to get IDs from a model than has no primary key', 'event_espresso'), |
|
4769 | 4769 | __FILE__, |
4770 | 4770 | __FUNCTION__, |
4771 | 4771 | __LINE__ |
@@ -4773,13 +4773,13 @@ discard block |
||
4773 | 4773 | } |
4774 | 4774 | } |
4775 | 4775 | $IDs = array(); |
4776 | - foreach( $model_objects as $model_object ) { |
|
4776 | + foreach ($model_objects as $model_object) { |
|
4777 | 4777 | $id = $model_object->ID(); |
4778 | - if( ! $id ) { |
|
4779 | - if( $filter_out_empty_ids ) { |
|
4778 | + if ( ! $id) { |
|
4779 | + if ($filter_out_empty_ids) { |
|
4780 | 4780 | continue; |
4781 | 4781 | } |
4782 | - if ( WP_DEBUG ) { |
|
4782 | + if (WP_DEBUG) { |
|
4783 | 4783 | EE_Error::add_error( |
4784 | 4784 | __( |
4785 | 4785 | 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', |
@@ -4801,8 +4801,8 @@ discard block |
||
4801 | 4801 | * are no capabilities that relate to this model returns false |
4802 | 4802 | * @return string|false |
4803 | 4803 | */ |
4804 | - public function cap_slug(){ |
|
4805 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4804 | + public function cap_slug() { |
|
4805 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4806 | 4806 | } |
4807 | 4807 | |
4808 | 4808 | |
@@ -4817,34 +4817,34 @@ discard block |
||
4817 | 4817 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4818 | 4818 | * @throws \EE_Error |
4819 | 4819 | */ |
4820 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4821 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4820 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4821 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4822 | 4822 | //check if we ought to run the restriction generator first |
4823 | - if( |
|
4824 | - isset( $this->_cap_restriction_generators[ $context ] ) |
|
4825 | - && $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base |
|
4826 | - && ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() |
|
4823 | + if ( |
|
4824 | + isset($this->_cap_restriction_generators[$context]) |
|
4825 | + && $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base |
|
4826 | + && ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions() |
|
4827 | 4827 | ) { |
4828 | - $this->_cap_restrictions[ $context ] = array_merge( |
|
4829 | - $this->_cap_restrictions[ $context ], |
|
4830 | - $this->_cap_restriction_generators[ $context ]->generate_restrictions() |
|
4828 | + $this->_cap_restrictions[$context] = array_merge( |
|
4829 | + $this->_cap_restrictions[$context], |
|
4830 | + $this->_cap_restriction_generators[$context]->generate_restrictions() |
|
4831 | 4831 | ); |
4832 | 4832 | } |
4833 | 4833 | //and make sure we've finalized the construction of each restriction |
4834 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4835 | - if ( $where_conditions_obj instanceof EE_Default_Where_Conditions ) { |
|
4836 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4834 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4835 | + if ($where_conditions_obj instanceof EE_Default_Where_Conditions) { |
|
4836 | + $where_conditions_obj->_finalize_construct($this); |
|
4837 | 4837 | } |
4838 | 4838 | } |
4839 | 4839 | |
4840 | - return $this->_cap_restrictions[ $context ]; |
|
4840 | + return $this->_cap_restrictions[$context]; |
|
4841 | 4841 | } |
4842 | 4842 | |
4843 | 4843 | /** |
4844 | 4844 | * Indicating whether or not this model thinks its a wp core model |
4845 | 4845 | * @return boolean |
4846 | 4846 | */ |
4847 | - public function is_wp_core_model(){ |
|
4847 | + public function is_wp_core_model() { |
|
4848 | 4848 | return $this->_wp_core_model; |
4849 | 4849 | } |
4850 | 4850 | |
@@ -4858,12 +4858,12 @@ discard block |
||
4858 | 4858 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4859 | 4859 | * @throws \EE_Error |
4860 | 4860 | */ |
4861 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4861 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4862 | 4862 | $missing_caps = array(); |
4863 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4864 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4865 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4866 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4863 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4864 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4865 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4866 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4867 | 4867 | } |
4868 | 4868 | } |
4869 | 4869 | return $missing_caps; |
@@ -4875,7 +4875,7 @@ discard block |
||
4875 | 4875 | * one of 'read', 'edit', or 'delete' |
4876 | 4876 | */ |
4877 | 4877 | public function cap_contexts_to_cap_action_map() { |
4878 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4878 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4879 | 4879 | } |
4880 | 4880 | |
4881 | 4881 | |
@@ -4886,19 +4886,19 @@ discard block |
||
4886 | 4886 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4887 | 4887 | * @throws \EE_Error |
4888 | 4888 | */ |
4889 | - public function cap_action_for_context( $context ) { |
|
4889 | + public function cap_action_for_context($context) { |
|
4890 | 4890 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4891 | - if( isset( $mapping[ $context ] ) ) { |
|
4892 | - return $mapping[ $context ]; |
|
4891 | + if (isset($mapping[$context])) { |
|
4892 | + return $mapping[$context]; |
|
4893 | 4893 | } |
4894 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4894 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4895 | 4895 | return $action; |
4896 | 4896 | } |
4897 | 4897 | throw new EE_Error( |
4898 | 4898 | sprintf( |
4899 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4899 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4900 | 4900 | $context, |
4901 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4901 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4902 | 4902 | ) |
4903 | 4903 | ); |
4904 | 4904 | |
@@ -4909,7 +4909,7 @@ discard block |
||
4909 | 4909 | * @return array |
4910 | 4910 | */ |
4911 | 4911 | static public function valid_cap_contexts() { |
4912 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4912 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4913 | 4913 | self::caps_read, |
4914 | 4914 | self::caps_read_admin, |
4915 | 4915 | self::caps_edit, |
@@ -4925,17 +4925,17 @@ discard block |
||
4925 | 4925 | * @return bool |
4926 | 4926 | * @throws \EE_Error |
4927 | 4927 | */ |
4928 | - static public function verify_is_valid_cap_context( $context ) { |
|
4928 | + static public function verify_is_valid_cap_context($context) { |
|
4929 | 4929 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4930 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4930 | + if (in_array($context, $valid_cap_contexts)) { |
|
4931 | 4931 | return true; |
4932 | - }else{ |
|
4932 | + } else { |
|
4933 | 4933 | throw new EE_Error( |
4934 | 4934 | sprintf( |
4935 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4935 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4936 | 4936 | $context, |
4937 | - 'EEM_Base' , |
|
4938 | - implode(',', $valid_cap_contexts ) |
|
4937 | + 'EEM_Base', |
|
4938 | + implode(',', $valid_cap_contexts) |
|
4939 | 4939 | ) |
4940 | 4940 | ); |
4941 | 4941 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | |
24 | -if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
25 | - exit( 'No direct script access allowed' ); |
|
24 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
25 | + exit('No direct script access allowed'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | class Model_Data_Translator { |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | * @param string $requested_version |
41 | 41 | * @return mixed |
42 | 42 | */ |
43 | - public static function prepare_field_values_from_json( $field_obj, $original_value_maybe_array, $requested_version ) { |
|
44 | - if( is_array( $original_value_maybe_array ) ) { |
|
43 | + public static function prepare_field_values_from_json($field_obj, $original_value_maybe_array, $requested_version) { |
|
44 | + if (is_array($original_value_maybe_array)) { |
|
45 | 45 | $new_value_maybe_array = array(); |
46 | - foreach( $original_value_maybe_array as $array_key => $array_item ) { |
|
47 | - $new_value_maybe_array[ $array_key ] = Model_Data_Translator::prepare_field_value_from_json( $field_obj, $array_item, $requested_version ); |
|
46 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
47 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json($field_obj, $array_item, $requested_version); |
|
48 | 48 | } |
49 | 49 | } else { |
50 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json( $field_obj, $original_value_maybe_array, $requested_version ); |
|
50 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json($field_obj, $original_value_maybe_array, $requested_version); |
|
51 | 51 | } |
52 | 52 | return $new_value_maybe_array; |
53 | 53 | } |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | * @param string $request_version (eg 4.8.36) |
60 | 60 | * @return array |
61 | 61 | */ |
62 | - public static function prepare_field_values_for_json( $field_obj, $original_value_maybe_array, $request_version ){ |
|
63 | - if( is_array( $original_value_maybe_array ) ) { |
|
62 | + public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version) { |
|
63 | + if (is_array($original_value_maybe_array)) { |
|
64 | 64 | $new_value_maybe_array = array(); |
65 | - foreach( $original_value_maybe_array as $array_key => $array_item ) { |
|
66 | - $new_value_maybe_array[ $array_key ] = Model_Data_Translator::prepare_field_value_for_json( $field_obj, $array_item, $request_version ); |
|
65 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
66 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json($field_obj, $array_item, $request_version); |
|
67 | 67 | } |
68 | 68 | } else { |
69 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json( $field_obj, $original_value_maybe_array, $request_version ); |
|
69 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json($field_obj, $original_value_maybe_array, $request_version); |
|
70 | 70 | } |
71 | 71 | return $new_value_maybe_array; |
72 | 72 | } |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | * @param string $requested_version |
80 | 80 | * @return mixed |
81 | 81 | */ |
82 | - public static function prepare_field_value_from_json( $field_obj, $original_value, $requested_version ) { |
|
82 | + public static function prepare_field_value_from_json($field_obj, $original_value, $requested_version) { |
|
83 | 83 | $new_value = null; |
84 | - if( $field_obj instanceof \EE_Infinite_Integer_Field |
|
85 | - && in_array( $original_value, array( null, '' ), true ) ) { |
|
84 | + if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
85 | + && in_array($original_value, array(null, ''), true)) { |
|
86 | 86 | $new_value = EE_INF; |
87 | - } elseif( $field_obj instanceof \EE_Datetime_Field ) { |
|
88 | - $new_value = rest_parse_date( $original_value ); |
|
87 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
88 | + $new_value = rest_parse_date($original_value); |
|
89 | 89 | } else { |
90 | 90 | $new_value = $original_value; |
91 | 91 | } |
@@ -98,22 +98,22 @@ discard block |
||
98 | 98 | * @param mixed $original_value |
99 | 99 | * @return mixed |
100 | 100 | */ |
101 | - public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) { |
|
102 | - if( $original_value === EE_INF ) { |
|
101 | + public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) { |
|
102 | + if ($original_value === EE_INF) { |
|
103 | 103 | $new_value = Model_Data_Translator::ee_inf_in_rest; |
104 | - } elseif( $field_obj instanceof \EE_Datetime_Field ) { |
|
105 | - if( $original_value instanceof \DateTime ) { |
|
106 | - $new_value = $original_value->format( 'Y-m-d H:i:s' ); |
|
107 | - } elseif( is_int( $original_value ) ) { |
|
108 | - $new_value = date( 'Y-m-d H:i:s', $original_value ); |
|
104 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
105 | + if ($original_value instanceof \DateTime) { |
|
106 | + $new_value = $original_value->format('Y-m-d H:i:s'); |
|
107 | + } elseif (is_int($original_value)) { |
|
108 | + $new_value = date('Y-m-d H:i:s', $original_value); |
|
109 | 109 | } else { |
110 | 110 | $new_value = $original_value; |
111 | 111 | } |
112 | - $new_value = mysql_to_rfc3339( $new_value ); |
|
112 | + $new_value = mysql_to_rfc3339($new_value); |
|
113 | 113 | } else { |
114 | 114 | $new_value = $original_value; |
115 | 115 | } |
116 | - return apply_filters( 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
116 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
117 | 117 | $new_value, |
118 | 118 | $field_obj, |
119 | 119 | $original_value, |
@@ -129,29 +129,29 @@ discard block |
||
129 | 129 | * @param string $requested_version |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public static function prepare_conditions_query_params_for_models( $inputted_query_params_of_this_type, \EEM_Base $model, $requested_version ) { |
|
132 | + public static function prepare_conditions_query_params_for_models($inputted_query_params_of_this_type, \EEM_Base $model, $requested_version) { |
|
133 | 133 | $query_param_for_models = array(); |
134 | - foreach( $inputted_query_params_of_this_type as $query_param_key => $query_param_value ) { |
|
134 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
135 | 135 | $field = Model_Data_Translator::deduce_field_from_query_param( |
136 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key( $query_param_key ), |
|
136 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
137 | 137 | $model |
138 | 138 | ); |
139 | - if( $field instanceof \EE_Model_Field_Base ) { |
|
139 | + if ($field instanceof \EE_Model_Field_Base) { |
|
140 | 140 | //did they specify an operator? |
141 | - if( is_array( $query_param_value ) ) { |
|
142 | - $op = $query_param_value[ 0 ]; |
|
143 | - $translated_value = array( $op ); |
|
144 | - if( isset( $query_param_value[ 1 ] ) ) { |
|
145 | - $value = $query_param_value[ 1 ]; |
|
146 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json( $field, $value, $requested_version ); |
|
141 | + if (is_array($query_param_value)) { |
|
142 | + $op = $query_param_value[0]; |
|
143 | + $translated_value = array($op); |
|
144 | + if (isset($query_param_value[1])) { |
|
145 | + $value = $query_param_value[1]; |
|
146 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value, $requested_version); |
|
147 | 147 | } |
148 | 148 | } else { |
149 | - $translated_value = Model_Data_Translator::prepare_field_value_from_json( $field, $query_param_value, $requested_version ); |
|
149 | + $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value, $requested_version); |
|
150 | 150 | } |
151 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
151 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
152 | 152 | } else { |
153 | 153 | //so it's not for a field, assume it's a logic query param key |
154 | - $query_param_for_models[ $query_param_key ] = Model_Data_Translator::prepare_conditions_query_params_for_models( $query_param_value, $model, $requested_version ); |
|
154 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value, $model, $requested_version); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | return $query_param_for_models; |
@@ -164,27 +164,27 @@ discard block |
||
164 | 164 | * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 REST API |
165 | 165 | * @return array which can be passed into the EE4 REST API when querying a model resource |
166 | 166 | */ |
167 | - public static function prepare_query_params_for_rest_api( $model_query_params, \EEM_Base $model, $requested_version = null ) { |
|
168 | - if( $requested_version === null ) { |
|
169 | - $requested_version = \EED_Core_Rest_Api::latest_rest_api_version() ; |
|
167 | + public static function prepare_query_params_for_rest_api($model_query_params, \EEM_Base $model, $requested_version = null) { |
|
168 | + if ($requested_version === null) { |
|
169 | + $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
170 | 170 | } |
171 | 171 | $rest_query_params = $model_query_params; |
172 | - if ( isset( $model_query_params[0] ) ) { |
|
173 | - $rest_query_params[ 'where' ] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
174 | - $model_query_params[ 0 ], |
|
172 | + if (isset($model_query_params[0])) { |
|
173 | + $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
174 | + $model_query_params[0], |
|
175 | 175 | $model, |
176 | 176 | $requested_version |
177 | 177 | ); |
178 | - unset( $rest_query_params[0] ); |
|
178 | + unset($rest_query_params[0]); |
|
179 | 179 | } |
180 | - if ( isset( $model_query_params[ 'having' ] ) ) { |
|
181 | - $rest_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
182 | - $model_query_params[ 'having' ], |
|
180 | + if (isset($model_query_params['having'])) { |
|
181 | + $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
182 | + $model_query_params['having'], |
|
183 | 183 | $model, |
184 | 184 | $requested_version |
185 | 185 | ); |
186 | 186 | } |
187 | - return apply_filters( 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', $rest_query_params, $model_query_params, $model, $requested_version ); |
|
187 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', $rest_query_params, $model_query_params, $model, $requested_version); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -194,39 +194,39 @@ discard block |
||
194 | 194 | * @param string $requested_version eg "4.8.36" |
195 | 195 | * @return array ready for use in the rest api query params |
196 | 196 | */ |
197 | - public static function prepare_conditions_query_params_for_rest_api( $inputted_query_params_of_this_type, \EEM_Base $model, $requested_version ) { |
|
197 | + public static function prepare_conditions_query_params_for_rest_api($inputted_query_params_of_this_type, \EEM_Base $model, $requested_version) { |
|
198 | 198 | $query_param_for_models = array(); |
199 | - foreach( $inputted_query_params_of_this_type as $query_param_key => $query_param_value ) { |
|
199 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
200 | 200 | $field = Model_Data_Translator::deduce_field_from_query_param( |
201 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key( $query_param_key ), |
|
201 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
202 | 202 | $model |
203 | 203 | ); |
204 | - if( $field instanceof \EE_Model_Field_Base ) { |
|
204 | + if ($field instanceof \EE_Model_Field_Base) { |
|
205 | 205 | //did they specify an operator? |
206 | - if( is_array( $query_param_value ) ) { |
|
207 | - $op = $query_param_value[ 0 ]; |
|
208 | - $translated_value = array( $op ); |
|
209 | - if( isset( $query_param_value[ 1 ] ) ) { |
|
210 | - $value = $query_param_value[ 1 ]; |
|
211 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json( $field, $value, $requested_version ); |
|
206 | + if (is_array($query_param_value)) { |
|
207 | + $op = $query_param_value[0]; |
|
208 | + $translated_value = array($op); |
|
209 | + if (isset($query_param_value[1])) { |
|
210 | + $value = $query_param_value[1]; |
|
211 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value, $requested_version); |
|
212 | 212 | } |
213 | 213 | } else { |
214 | - $translated_value = Model_Data_Translator::prepare_field_value_for_json( $field, $query_param_value, $requested_version ); |
|
214 | + $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value, $requested_version); |
|
215 | 215 | } |
216 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
216 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
217 | 217 | } else { |
218 | 218 | //so it's not for a field, assume it's a logic query param key |
219 | - $query_param_for_models[ $query_param_key ] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( $query_param_value, $model, $requested_version ); |
|
219 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value, $model, $requested_version); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | return $query_param_for_models; |
223 | 223 | } |
224 | 224 | |
225 | - public static function remove_stars_and_anything_after_from_condition_query_param_key( $condition_query_param_key ) { |
|
225 | + public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
226 | 226 | $pos_of_star = strpos($condition_query_param_key, '*'); |
227 | - if($pos_of_star === FALSE){ |
|
227 | + if ($pos_of_star === FALSE) { |
|
228 | 228 | return $condition_query_param_key; |
229 | - }else{ |
|
229 | + } else { |
|
230 | 230 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
231 | 231 | return $condition_query_param_sans_star; |
232 | 232 | } |
@@ -238,26 +238,26 @@ discard block |
||
238 | 238 | * @throws EE_Error |
239 | 239 | * @return EE_Model_Field_Base |
240 | 240 | */ |
241 | - public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model){ |
|
241 | + public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) { |
|
242 | 242 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
243 | 243 | //which will help us find the database table and column |
244 | 244 | |
245 | - $query_param_parts = explode(".",$query_param_name); |
|
246 | - if(empty($query_param_parts)){ |
|
247 | - throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
245 | + $query_param_parts = explode(".", $query_param_name); |
|
246 | + if (empty($query_param_parts)) { |
|
247 | + throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
248 | 248 | } |
249 | 249 | $number_of_parts = count($query_param_parts); |
250 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
251 | - if($number_of_parts == 1){ |
|
250 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
251 | + if ($number_of_parts == 1) { |
|
252 | 252 | $field_name = $last_query_param_part; |
253 | - }else{// $number_of_parts >= 2 |
|
253 | + } else {// $number_of_parts >= 2 |
|
254 | 254 | //the last part is the column name, and there are only 2parts. therefore... |
255 | 255 | $field_name = $last_query_param_part; |
256 | - $model = \EE_Registry::instance()->load_model( $query_param_parts[ $number_of_parts - 2 ]); |
|
256 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
257 | 257 | } |
258 | - try{ |
|
258 | + try { |
|
259 | 259 | return $model->field_settings_for($field_name); |
260 | - }catch(\EE_Error $e){ |
|
260 | + } catch (\EE_Error $e) { |
|
261 | 261 | return null; |
262 | 262 | } |
263 | 263 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @author Mike Nelson |
10 | 10 | */ |
11 | 11 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
12 | -class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base{ |
|
12 | +class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base { |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * @var string $_model_name |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * And the arguments accepted by EE_Form_Input_With_Options_Base |
44 | 44 | * @throws \EE_Error |
45 | 45 | */ |
46 | - public function __construct( $input_settings = array() ) { |
|
46 | + public function __construct($input_settings = array()) { |
|
47 | 47 | //needed input settings: |
48 | 48 | //select2_args |
49 | 49 | $this->_model_name = EEH_Array::is_set( |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $query_params = EEH_Array::is_set( |
56 | 56 | $input_settings, |
57 | 57 | 'query_params', |
58 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ) |
|
58 | + array('limit' => 10, 'caps' => EEM_Base::caps_read_admin) |
|
59 | 59 | ); |
60 | 60 | $this->_value_field_name = EEH_Array::is_set( |
61 | 61 | $input_settings, |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $this->_display_field_name = EEH_Array::is_set( |
66 | 66 | $input_settings, |
67 | 67 | 'display_field_name', |
68 | - $model->get_a_field_of_type( 'EE_Text_Field_Base' )->get_name() |
|
68 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
69 | 69 | ); |
70 | 70 | $this->_add_validation_strategy( |
71 | 71 | new EE_Model_Matching_Query_Validation_Strategy( |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | ); |
78 | 78 | //get resource endpoint |
79 | 79 | $rest_controller = new EventEspresso\core\libraries\rest_api\controllers\model\Read(); |
80 | - $rest_controller->set_requested_version( EED_Core_Rest_Api::latest_rest_api_version() ); |
|
81 | - $url = $rest_controller->get_versioned_link_to( EEH_Inflector::pluralize_and_lower( $this->_model_name ) ); |
|
80 | + $rest_controller->set_requested_version(EED_Core_Rest_Api::latest_rest_api_version()); |
|
81 | + $url = $rest_controller->get_versioned_link_to(EEH_Inflector::pluralize_and_lower($this->_model_name)); |
|
82 | 82 | $default_select2_args = array( |
83 | 83 | 'ajax' => array( |
84 | 84 | 'url' => $url, |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | 'delay' => '250', |
87 | 87 | 'data_interface' => 'EE_Select2_REST_API_Interface', |
88 | 88 | 'data_interface_args' => array( |
89 | - 'default_query_params' => (object)Model_Data_Translator::prepare_query_params_for_rest_api( |
|
89 | + 'default_query_params' => (object) Model_Data_Translator::prepare_query_params_for_rest_api( |
|
90 | 90 | $query_params, |
91 | 91 | $model |
92 | 92 | ), |
93 | 93 | 'display_field' => $this->_display_field_name, |
94 | 94 | 'value_field' => $this->_value_field_name, |
95 | - 'nonce' => wp_create_nonce( 'wp_rest' ) |
|
95 | + 'nonce' => wp_create_nonce('wp_rest') |
|
96 | 96 | ), |
97 | 97 | ), |
98 | 98 | 'cache' => true, |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | ); |
101 | 101 | $select2_args = array_replace_recursive( |
102 | 102 | $default_select2_args, |
103 | - (array)EEH_Array::is_set( $input_settings, 'select2_args', array() ) |
|
103 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
104 | 104 | ); |
105 | - $this->set_display_strategy( new EE_Select2_Display_Strategy( $select2_args ) ); |
|
106 | - parent::__construct( array(), $input_settings ); |
|
105 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
106 | + parent::__construct(array(), $input_settings); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
@@ -116,33 +116,33 @@ discard block |
||
116 | 116 | * @return void |
117 | 117 | * @throws \EE_Error |
118 | 118 | */ |
119 | - public function set_default( $value ) { |
|
119 | + public function set_default($value) { |
|
120 | 120 | |
121 | - $values_for_options = (array)$value; |
|
122 | - $value_field = $this->_get_model()->field_settings_for( $this->_value_field_name ); |
|
123 | - $display_field = $this->_get_model()->field_settings_for( $this->_display_field_name ); |
|
121 | + $values_for_options = (array) $value; |
|
122 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
123 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
124 | 124 | $display_values = $this->_get_model()->get_all_wpdb_results( |
125 | 125 | array( |
126 | 126 | array( |
127 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
127 | + $this->_value_field_name => array('IN', $values_for_options) |
|
128 | 128 | ) |
129 | 129 | ), |
130 | 130 | ARRAY_A, |
131 | 131 | implode( |
132 | 132 | ',', |
133 | 133 | array( |
134 | - $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name, |
|
135 | - $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name |
|
134 | + $value_field->get_qualified_column().' AS '.$this->_value_field_name, |
|
135 | + $display_field->get_qualified_column().' AS '.$this->_display_field_name |
|
136 | 136 | ) |
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | $select_options = array(); |
140 | - foreach( $display_values as $db_rows ) { |
|
141 | - $db_rows = (array)$db_rows; |
|
142 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = $db_rows[ $this->_display_field_name ]; |
|
140 | + foreach ($display_values as $db_rows) { |
|
141 | + $db_rows = (array) $db_rows; |
|
142 | + $select_options[$db_rows[$this->_value_field_name]] = $db_rows[$this->_display_field_name]; |
|
143 | 143 | } |
144 | - $this->set_select_options( $select_options ); |
|
145 | - parent::set_default( $value ); |
|
144 | + $this->set_select_options($select_options); |
|
145 | + parent::set_default($value); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @throws EE_Error |
152 | 152 | */ |
153 | 153 | protected function _get_model() { |
154 | - if( ! EE_Registry::instance()->is_model_name( $this->_model_name ) ) { |
|
154 | + if ( ! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
155 | 155 | throw new EE_Error( |
156 | 156 | sprintf( |
157 | 157 | __( |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | ) |
163 | 163 | ); |
164 | 164 | } else { |
165 | - return EE_Registry::instance()->load_model( $this->_model_name ); |
|
165 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 4.6 |
9 | 9 | * |
10 | 10 | */ |
11 | -abstract class EE_Display_Strategy_Base extends EE_Form_Input_Strategy_Base{ |
|
11 | +abstract class EE_Display_Strategy_Base extends EE_Form_Input_Strategy_Base { |
|
12 | 12 | /** |
13 | 13 | * returns HTML and javascript related to the displaying of this input |
14 | 14 | * @return string |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | * @param string $chars - exact string of characters to remove |
25 | 25 | * @return string |
26 | 26 | */ |
27 | - protected function _remove_chars( $string = '', $chars = '-' ) { |
|
28 | - $char_length = strlen( $chars ) * -1; |
|
27 | + protected function _remove_chars($string = '', $chars = '-') { |
|
28 | + $char_length = strlen($chars) * -1; |
|
29 | 29 | // if last three characters of string is " - ", then remove it |
30 | - return substr( $string, $char_length ) === $chars ? substr( $string, 0, $char_length ) : $string; |
|
30 | + return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | * @param string $chars - exact string of characters to be added to end of string |
40 | 40 | * @return string |
41 | 41 | */ |
42 | - protected function _append_chars( $string = '', $chars = '-' ) { |
|
43 | - return $this->_remove_chars( $string, $chars ) . $chars; |
|
42 | + protected function _append_chars($string = '', $chars = '-') { |
|
43 | + return $this->_remove_chars($string, $chars).$chars; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Gets the HTML IDs of all the inputs |
48 | 48 | * @return array |
49 | 49 | */ |
50 | - public function get_html_input_ids( $add_pound_sign = false ) { |
|
51 | - return array( $this->get_input()->html_id( $add_pound_sign ) ); |
|
50 | + public function get_html_input_ids($add_pound_sign = false) { |
|
51 | + return array($this->get_input()->html_id($add_pound_sign)); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param array $other_js_data |
61 | 61 | * @return array |
62 | 62 | */ |
63 | - public function get_other_js_data( $other_js_data = array() ) { |
|
63 | + public function get_other_js_data($other_js_data = array()) { |
|
64 | 64 | return $other_js_data; |
65 | 65 | } |
66 | 66 |
@@ -208,7 +208,7 @@ |
||
208 | 208 | |
209 | 209 | /** |
210 | 210 | * @param $message |
211 | - * @param $payment |
|
211 | + * @param EEI_Payment $payment |
|
212 | 212 | */ |
213 | 213 | public function log($message,$payment){ |
214 | 214 | if($payment instanceof EEI_Payment){ |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
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 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * ------------------------------------------------------------------------ |
27 | 27 | */ |
28 | -class EEG_Aim extends EE_Onsite_Gateway{ |
|
28 | +class EEG_Aim extends EE_Onsite_Gateway { |
|
29 | 29 | |
30 | 30 | const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; //Authnet URL |
31 | 31 | |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * @param EEG_Aim $gateway_object |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - public function possibly_use_deprecated_aim_server( $url, EEG_Aim $gateway_object ) { |
|
161 | - if( $gateway_object->_server === 'authorize.net' |
|
162 | - && ! $gateway_object->_debug_mode ) { |
|
160 | + public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) { |
|
161 | + if ($gateway_object->_server === 'authorize.net' |
|
162 | + && ! $gateway_object->_debug_mode) { |
|
163 | 163 | return 'https://secure.authorize.net/gateway/transact.dll'; |
164 | 164 | } else { |
165 | 165 | return $url; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | |
184 | 184 | public function do_direct_payment($payment, $billing_info = null) { |
185 | - add_filter( 'FHEE__EEG_Aim___get_server_url', array( $this, 'possibly_use_deprecated_aim_server' ), 10, 2 ); |
|
185 | + add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
186 | 186 | // Enable test mode if needed |
187 | 187 | //4007000000027 <-- test successful visa |
188 | 188 | //4222222222222 <-- test failure card number |
@@ -193,17 +193,17 @@ discard block |
||
193 | 193 | $primary_registrant = $transaction->primary_registration(); |
194 | 194 | //if we're are charging for the full amount, show the normal line items |
195 | 195 | //and the itemized total adds up properly |
196 | - if( $this->_can_easily_itemize_transaction_for( $payment ) ){ |
|
196 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
197 | 197 | $total_line_item = $transaction->total_line_item(); |
198 | 198 | foreach ($total_line_item->get_items() as $line_item) { |
199 | 199 | $this->addLineItem($item_num++, $line_item->name(), $line_item->desc(), $line_item->quantity(), $line_item->unit_price(), 'N'); |
200 | 200 | $order_description .= $line_item->desc().', '; |
201 | 201 | } |
202 | - foreach($total_line_item->tax_descendants() as $tax_line_item){ |
|
202 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
203 | 203 | $this->addLineItem($item_num++, $tax_line_item->name(), $tax_line_item->desc(), 1, $tax_line_item->total(), 'N'); |
204 | 204 | } |
205 | - }else{//partial payment |
|
206 | - $order_description = sprintf(__("Payment of %s for %s", "event_espresso"),$payment->amount(),$primary_registrant->reg_code()); |
|
205 | + } else {//partial payment |
|
206 | + $order_description = sprintf(__("Payment of %s for %s", "event_espresso"), $payment->amount(), $primary_registrant->reg_code()); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -212,18 +212,18 @@ discard block |
||
212 | 212 | //start transaction |
213 | 213 | //if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
214 | 214 | $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
215 | - $this->setField( 'solution_id', $partner_id ); |
|
215 | + $this->setField('solution_id', $partner_id); |
|
216 | 216 | $this->setField('amount', $this->format_currency($payment->amount())); |
217 | - $this->setField('description',substr(rtrim($order_description, ', '), 0, 255)); |
|
218 | - $this->_set_sensitive_billing_data( $billing_info ); |
|
217 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
218 | + $this->_set_sensitive_billing_data($billing_info); |
|
219 | 219 | $this->setField('first_name', $billing_info['first_name']); |
220 | 220 | $this->setField('last_name', $billing_info['last_name']); |
221 | 221 | $this->setField('email', $billing_info['email']); |
222 | 222 | $this->setField('company', $billing_info['company']); |
223 | 223 | $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
224 | 224 | $this->setField('city', $billing_info['city']); |
225 | - $this->setField('state', $billing_info['state'] ); |
|
226 | - $this->setField('country', $billing_info['country'] ); |
|
225 | + $this->setField('state', $billing_info['state']); |
|
226 | + $this->setField('country', $billing_info['country']); |
|
227 | 227 | $this->setField('zip', $billing_info['zip']); |
228 | 228 | $this->setField('fax', $billing_info['fax']); |
229 | 229 | $this->setField('cust_id', $primary_registrant->ID()); |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
232 | 232 | //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
233 | 233 | //in which case, we need to generate teh invoice num per request right here... |
234 | - $this->setField('invoice_num', wp_generate_password(12,false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
234 | + $this->setField('invoice_num', wp_generate_password(12, false)); //$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
235 | 235 | //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
236 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS ); |
|
236 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
237 | 237 | |
238 | 238 | |
239 | 239 | if ($this->_test_transactions) { |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | //Capture response |
244 | 244 | $this->type = "AUTH_CAPTURE"; |
245 | 245 | $response = $this->_sendRequest($payment); |
246 | - if (!empty($response)){ |
|
246 | + if ( ! empty($response)) { |
|
247 | 247 | if ($this->_debug_mode) { |
248 | 248 | $txn_id = $response->invoice_number; |
249 | 249 | } else { |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | $payment_status = $response->approved ? $this->_pay_model->approved_status() : $this->_pay_model->declined_status(); |
253 | 253 | $payment->set_status($payment_status); |
254 | 254 | //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
255 | - $payment->set_amount( (float) $response->amount ); |
|
256 | - $payment->set_gateway_response(sprintf("%s (code: %s)",$response->response_reason_text,$response->response_reason_code)); |
|
257 | - $payment->set_txn_id_chq_nmbr( $txn_id ); |
|
255 | + $payment->set_amount((float) $response->amount); |
|
256 | + $payment->set_gateway_response(sprintf("%s (code: %s)", $response->response_reason_text, $response->response_reason_code)); |
|
257 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
258 | 258 | $payment->set_extra_accntng($primary_registrant->reg_code()); |
259 | - $payment->set_details(print_r($response,true)); |
|
259 | + $payment->set_details(print_r($response, true)); |
|
260 | 260 | } else { |
261 | 261 | $payment->set_status($this->_pay_model->failed_status()); |
262 | 262 | $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
263 | - $payment->set_details(print_r($response,true)); |
|
263 | + $payment->set_details(print_r($response, true)); |
|
264 | 264 | } |
265 | 265 | return $payment; |
266 | 266 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * what billing data gets sent |
272 | 272 | * @param array $billing_info |
273 | 273 | */ |
274 | - protected function _set_sensitive_billing_data( $billing_info ) { |
|
274 | + protected function _set_sensitive_billing_data($billing_info) { |
|
275 | 275 | $this->setField('card_num', $billing_info['credit_card']); |
276 | 276 | $this->setField('exp_date', $billing_info['exp_month'].$billing_info['exp_year']); |
277 | 277 | $this->setField('card_code', $billing_info['cvv']); |
@@ -330,22 +330,22 @@ discard block |
||
330 | 330 | $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
331 | 331 | $x_keys = array(); |
332 | 332 | foreach ($this->_x_post_fields as $key => $value) { |
333 | - $x_keys[] = "x_$key=" . urlencode($value); |
|
333 | + $x_keys[] = "x_$key=".urlencode($value); |
|
334 | 334 | } |
335 | 335 | // Add line items |
336 | 336 | foreach ($this->_additional_line_items as $key => $value) { |
337 | - $x_keys[] = "x_line_item=" . urlencode($value); |
|
337 | + $x_keys[] = "x_line_item=".urlencode($value); |
|
338 | 338 | } |
339 | 339 | $this->_log_clean_request($x_keys, $payment); |
340 | 340 | $post_url = $this->_get_server_url(); |
341 | 341 | $curl_request = curl_init($post_url); |
342 | - curl_setopt($curl_request, CURLOPT_POSTFIELDS, implode("&",$x_keys)); |
|
342 | + curl_setopt($curl_request, CURLOPT_POSTFIELDS, implode("&", $x_keys)); |
|
343 | 343 | curl_setopt($curl_request, CURLOPT_HEADER, 0); |
344 | 344 | curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
345 | 345 | curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
346 | 346 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
347 | 347 | if ($this->VERIFY_PEER) { |
348 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname( __DIR__ ) . '/ssl/cert.pem'); |
|
348 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__).'/ssl/cert.pem'); |
|
349 | 349 | } else { |
350 | 350 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
351 | 351 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | $response = curl_exec($curl_request); |
358 | 358 | |
359 | 359 | curl_close($curl_request); |
360 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
360 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
361 | 361 | |
362 | 362 | return $this->_log_and_clean_response($response_obj, $payment); |
363 | 363 | } |
@@ -366,18 +366,18 @@ discard block |
||
366 | 366 | * @param array $request_array |
367 | 367 | * @param EEI_Payment $payment |
368 | 368 | */ |
369 | - protected function _log_clean_request($request_array,$payment){ |
|
370 | - $keys_to_filter_out = array( 'x_card_num', 'x_card_code', 'x_exp_date' ); |
|
371 | - foreach($request_array as $index => $keyvaltogether ) { |
|
372 | - foreach( $keys_to_filter_out as $key ) { |
|
373 | - if( strpos( $keyvaltogether, $key ) === 0 ){ |
|
369 | + protected function _log_clean_request($request_array, $payment) { |
|
370 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
371 | + foreach ($request_array as $index => $keyvaltogether) { |
|
372 | + foreach ($keys_to_filter_out as $key) { |
|
373 | + if (strpos($keyvaltogether, $key) === 0) { |
|
374 | 374 | //found it at the first character |
375 | 375 | //so its one of them |
376 | - unset( $request_array[ $index ] ); |
|
376 | + unset($request_array[$index]); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | } |
380 | - $this->log(array('AIM Request sent:'=>$request_array, 'Server URL' => $this->_get_server_url() ),$payment); |
|
380 | + $this->log(array('AIM Request sent:'=>$request_array, 'Server URL' => $this->_get_server_url()), $payment); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | |
@@ -389,9 +389,9 @@ discard block |
||
389 | 389 | * @param EE_Payment $payment |
390 | 390 | * @return \EE_AuthorizeNetAIM_Response |
391 | 391 | */ |
392 | - private function _log_and_clean_response($response_obj,$payment){ |
|
392 | + private function _log_and_clean_response($response_obj, $payment) { |
|
393 | 393 | $response_obj->account_number = ''; |
394 | - $this->log(array('AIM Response received:'=>$response_obj),$payment); |
|
394 | + $this->log(array('AIM Response received:'=>$response_obj), $payment); |
|
395 | 395 | return $response_obj; |
396 | 396 | } |
397 | 397 | |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | // Split Array |
491 | 491 | $this->response = $response; |
492 | 492 | if ($encap_char) { |
493 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
493 | + $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
494 | 494 | } else { |
495 | 495 | $this->_response_array = explode($delimiter, $response); |
496 | 496 | } |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | $this->held = ($this->response_code === self::HELD); |
561 | 561 | |
562 | 562 | if ($this->error || $this->declined || $this->held) { |
563 | - $this->error_message = '<p><strong class="credit_card_failure">Attention: your transaction was declined for the following reason(s):</strong><br />' . $this->response_reason_text . '<br /><span class="response_code">Response Code: ' . $this->response_code . '<br /></span><span class="response_subcode">Response Subcode: ' . $this->response_subcode . '</span></p><p>To try again, <a href="#payment_options">please click here</a>.</p> '; |
|
563 | + $this->error_message = '<p><strong class="credit_card_failure">Attention: your transaction was declined for the following reason(s):</strong><br />'.$this->response_reason_text.'<br /><span class="response_code">Response Code: '.$this->response_code.'<br /></span><span class="response_subcode">Response Subcode: '.$this->response_subcode.'</span></p><p>To try again, <a href="#payment_options">please click here</a>.</p> '; |
|
564 | 564 | |
565 | 565 | |
566 | 566 | /* $this->error_message = "AuthorizeNet Error: |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | |
580 | 580 | } |
581 | 581 | |
582 | -if ( ! class_exists( 'AuthorizeNetException' ) ) { |
|
582 | +if ( ! class_exists('AuthorizeNetException')) { |
|
583 | 583 | /** |
584 | 584 | * Class AuthorizeNetException |
585 | 585 | * |
@@ -595,8 +595,8 @@ discard block |
||
595 | 595 | * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
596 | 596 | * @since 5.1.0 |
597 | 597 | */ |
598 | - public function __construct( $message = "", $code = 0, Exception $previous = null ) { |
|
599 | - parent::__construct( $message, $code, $previous ); |
|
598 | + public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
599 | + parent::__construct($message, $code, $previous); |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
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 | /** |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @subpackage |
12 | 12 | * @author Mike Nelson |
13 | 13 | */ |
14 | -class EE_PMT_Aim extends EE_PMT_Base{ |
|
14 | +class EE_PMT_Aim extends EE_PMT_Base { |
|
15 | 15 | |
16 | 16 | |
17 | 17 | /** |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | require_once($this->file_folder().'EEG_Aim.gateway.php'); |
35 | 35 | $this->_gateway = new EEG_Aim(); |
36 | 36 | $this->_pretty_name = __("Authorize.net AIM", 'event_espresso'); |
37 | - $this->_default_description = __( 'Please provide the following billing information.', 'event_espresso' ); |
|
37 | + $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
38 | 38 | $this->_requires_https = true; |
39 | 39 | } |
40 | 40 | |
@@ -47,61 +47,61 @@ discard block |
||
47 | 47 | * @return EE_Billing_Info_Form |
48 | 48 | * @throws \EE_Error |
49 | 49 | */ |
50 | - public function generate_new_billing_form( EE_Transaction $transaction = NULL ) { |
|
51 | - $billing_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance,array( |
|
50 | + public function generate_new_billing_form(EE_Transaction $transaction = NULL) { |
|
51 | + $billing_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, array( |
|
52 | 52 | 'name'=>'AIM_Form', |
53 | 53 | 'subsections'=>array( |
54 | 54 | 'credit_card'=>new EE_Credit_Card_Input(array( |
55 | 55 | 'required'=>true, |
56 | - 'html_label_text' => __( 'Card Number', 'event_espresso' ) |
|
56 | + 'html_label_text' => __('Card Number', 'event_espresso') |
|
57 | 57 | )), |
58 | 58 | 'exp_month'=>new EE_Credit_Card_Month_Input(true, array( |
59 | 59 | 'required'=>true, |
60 | - 'html_label_text' => __( 'Expiry Month', 'event_espresso' ) |
|
60 | + 'html_label_text' => __('Expiry Month', 'event_espresso') |
|
61 | 61 | )), |
62 | - 'exp_year'=>new EE_Credit_Card_Year_Input( array( |
|
62 | + 'exp_year'=>new EE_Credit_Card_Year_Input(array( |
|
63 | 63 | 'required'=>true, |
64 | - 'html_label_text' => __( 'Expiry Year', 'event_espresso' ) |
|
64 | + 'html_label_text' => __('Expiry Year', 'event_espresso') |
|
65 | 65 | )), |
66 | - 'cvv'=>new EE_CVV_Input( array( |
|
66 | + 'cvv'=>new EE_CVV_Input(array( |
|
67 | 67 | 'required'=>true, |
68 | - 'html_label_text' => __( 'CVV', 'event_espresso' ) ) ), |
|
68 | + 'html_label_text' => __('CVV', 'event_espresso') )), |
|
69 | 69 | ) |
70 | 70 | )); |
71 | - $billing_form->add_subsections( array( |
|
72 | - 'company' => new EE_Text_Input( array( |
|
71 | + $billing_form->add_subsections(array( |
|
72 | + 'company' => new EE_Text_Input(array( |
|
73 | 73 | 'html_label_text' => __('Company', 'event_espresso') |
74 | 74 | )) |
75 | - ), 'email', false ); |
|
75 | + ), 'email', false); |
|
76 | 76 | $billing_form->add_subsections( |
77 | 77 | array( |
78 | - 'fax' => new EE_Text_Input( array( |
|
78 | + 'fax' => new EE_Text_Input(array( |
|
79 | 79 | 'html_label_text' => __('Fax', 'event_espresso') |
80 | 80 | )) |
81 | 81 | ), |
82 | 82 | 'phone', |
83 | 83 | false ); |
84 | 84 | $settings_form = $this->settings_form(); |
85 | - if( $settings_form->get_input( 'excluded_billing_inputs' ) instanceof EE_Checkbox_Multi_Input ) { |
|
86 | - $billing_form->exclude( $settings_form->get_input( 'excluded_billing_inputs' )->normalized_value() ); |
|
85 | + if ($settings_form->get_input('excluded_billing_inputs') instanceof EE_Checkbox_Multi_Input) { |
|
86 | + $billing_form->exclude($settings_form->get_input('excluded_billing_inputs')->normalized_value()); |
|
87 | 87 | } |
88 | - if( $settings_form->get_input( 'required_billing_inputs' ) instanceof EE_Checkbox_Multi_Input ) { |
|
89 | - $required_inputs = $settings_form->get_input( 'required_billing_inputs' )->normalized_value(); |
|
88 | + if ($settings_form->get_input('required_billing_inputs') instanceof EE_Checkbox_Multi_Input) { |
|
89 | + $required_inputs = $settings_form->get_input('required_billing_inputs')->normalized_value(); |
|
90 | 90 | //only change the requirement of inputs which are allowed to be changed |
91 | 91 | /** @var EE_Form_Input_Base[] $inputs_to_evaluate */ |
92 | 92 | $inputs_to_evaluate = array_intersect_key( |
93 | 93 | $billing_form->inputs(), |
94 | 94 | $this->billing_input_names() |
95 | 95 | ); |
96 | - foreach( $inputs_to_evaluate as $input_name => $input ) { |
|
97 | - if( in_array( $input_name, $required_inputs ) ) { |
|
98 | - $input->set_required( true ); |
|
96 | + foreach ($inputs_to_evaluate as $input_name => $input) { |
|
97 | + if (in_array($input_name, $required_inputs)) { |
|
98 | + $input->set_required(true); |
|
99 | 99 | } else { |
100 | - $input->set_required( false ); |
|
100 | + $input->set_required(false); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
104 | - return $this->apply_billing_form_debug_settings( $billing_form ); |
|
104 | + return $this->apply_billing_form_debug_settings($billing_form); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | |
@@ -114,18 +114,18 @@ discard block |
||
114 | 114 | * @return \EE_Billing_Info_Form |
115 | 115 | * @throws \EE_Error |
116 | 116 | */ |
117 | - public function apply_billing_form_debug_settings( EE_Billing_Info_Form $billing_form ) { |
|
117 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) { |
|
118 | 118 | if ( |
119 | 119 | $this->_pm_instance->debug_mode() |
120 | - || $this->_pm_instance->get_extra_meta( 'test_transactions', TRUE, FALSE ) |
|
120 | + || $this->_pm_instance->get_extra_meta('test_transactions', TRUE, FALSE) |
|
121 | 121 | ) { |
122 | - $billing_form->get_input( 'credit_card' )->set_default( '4007000000027' ); |
|
123 | - $billing_form->get_input( 'exp_year' )->set_default( '2020' ); |
|
124 | - if( $billing_form->get_subsection( 'cvv' ) instanceof EE_Form_Input_Base ) { |
|
125 | - $billing_form->get_input( 'cvv' )->set_default( '123' ); |
|
122 | + $billing_form->get_input('credit_card')->set_default('4007000000027'); |
|
123 | + $billing_form->get_input('exp_year')->set_default('2020'); |
|
124 | + if ($billing_form->get_subsection('cvv') instanceof EE_Form_Input_Base) { |
|
125 | + $billing_form->get_input('cvv')->set_default('123'); |
|
126 | 126 | } |
127 | 127 | $billing_form->add_subsections( |
128 | - array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
128 | + array('fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html()), |
|
129 | 129 | 'credit_card' |
130 | 130 | ); |
131 | 131 | $billing_form->add_subsections( |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | 'extra_meta_inputs'=>array( |
154 | 154 | 'login_id'=>new EE_Text_Input( |
155 | 155 | array( |
156 | - 'html_label_text'=> sprintf( __("Authorize.net API Login ID %s", "event_espresso"), $this->get_help_tab_link() ), |
|
156 | + 'html_label_text'=> sprintf(__("Authorize.net API Login ID %s", "event_espresso"), $this->get_help_tab_link()), |
|
157 | 157 | 'required' => true ) |
158 | 158 | ), |
159 | 159 | 'transaction_key'=>new EE_Text_Input( |
160 | 160 | array( |
161 | - 'html_label_text'=> sprintf( __("Authorize.net Transaction Key %s", "event_espresso"), $this->get_help_tab_link() ), |
|
161 | + 'html_label_text'=> sprintf(__("Authorize.net Transaction Key %s", "event_espresso"), $this->get_help_tab_link()), |
|
162 | 162 | 'required' => true ) |
163 | 163 | ), |
164 | 164 | 'test_transactions'=>new EE_Yes_No_Input( |
165 | 165 | array( |
166 | - 'html_label_text'=> sprintf( __("Send test transactions? %s", 'event_espresso'), $this->get_help_tab_link() ), |
|
166 | + 'html_label_text'=> sprintf(__("Send test transactions? %s", 'event_espresso'), $this->get_help_tab_link()), |
|
167 | 167 | 'html_help_text'=> __("Send test transactions, even to live server", 'event_espresso'), |
168 | 168 | 'default' => false, |
169 | 169 | 'required' => true |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | 'excluded_billing_inputs' => new EE_Checkbox_Multi_Input( |
173 | 173 | $billing_input_names, |
174 | 174 | array( |
175 | - 'html_label_text' => sprintf( __("Excluded Payment Form Fields %s", 'event_espresso'), $this->get_help_tab_link() ), |
|
175 | + 'html_label_text' => sprintf(__("Excluded Payment Form Fields %s", 'event_espresso'), $this->get_help_tab_link()), |
|
176 | 176 | 'default' => array( |
177 | 177 | 'company', |
178 | 178 | 'fax', |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | 'required_billing_inputs' => new EE_Checkbox_Multi_Input( |
182 | 182 | $billing_input_names, |
183 | 183 | array( |
184 | - 'html_label_text' => sprintf( __("Required Payment Form Fields %s", 'event_espresso'), $this->get_help_tab_link() ), |
|
184 | + 'html_label_text' => sprintf(__("Required Payment Form Fields %s", 'event_espresso'), $this->get_help_tab_link()), |
|
185 | 185 | 'default' => array_diff( |
186 | - array_keys( $billing_input_names ), |
|
187 | - array( 'address2', 'phone', 'company', 'fax' ) |
|
186 | + array_keys($billing_input_names), |
|
187 | + array('address2', 'phone', 'company', 'fax') |
|
188 | 188 | ), |
189 | 189 | 'html_help_text' => __('Note: if fields are excluded they cannot be required.', 'event_espresso') |
190 | 190 | ) |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | apply_filters( |
194 | 194 | 'FHEE__EE_PMT_Aim__generate_new_settings_form__server_select_input__options', |
195 | 195 | array( |
196 | - 'akamai' => __( 'Authorize.net/Akamai (default)', 'event_espresso' ), |
|
197 | - 'authorize.net' => __( 'Authorize.net (deprecated)', 'event_espresso' ), |
|
196 | + 'akamai' => __('Authorize.net/Akamai (default)', 'event_espresso'), |
|
197 | + 'authorize.net' => __('Authorize.net (deprecated)', 'event_espresso'), |
|
198 | 198 | ), |
199 | 199 | $this |
200 | 200 | ), |
201 | 201 | array( |
202 | - 'html_label_text' => __( 'Server', 'event_espresso' ), |
|
203 | - 'html_help_text' => __( 'The Gateway Server where payment requests will be sent', 'event_espresso' ) |
|
202 | + 'html_label_text' => __('Server', 'event_espresso'), |
|
203 | + 'html_help_text' => __('The Gateway Server where payment requests will be sent', 'event_espresso') |
|
204 | 204 | ) |
205 | 205 | ) |
206 | 206 | |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | */ |
217 | 217 | public function billing_input_names() { |
218 | 218 | return array( |
219 | - 'first_name' => __( 'First Name', 'event_espresso' ), |
|
219 | + 'first_name' => __('First Name', 'event_espresso'), |
|
220 | 220 | 'last_name' => __('Last Name', 'event_espresso'), |
221 | - 'email' => __( 'Email', 'event_espresso' ), |
|
222 | - 'company' => __( 'Company', 'event_espresso' ), |
|
221 | + 'email' => __('Email', 'event_espresso'), |
|
222 | + 'company' => __('Company', 'event_espresso'), |
|
223 | 223 | 'address' => __('Address', 'event_espresso'), |
224 | 224 | 'address2' => __('Address2', 'event_espresso'), |
225 | 225 | 'city' => __('City', 'event_espresso'), |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | 'country' => __('Country', 'event_espresso'), |
228 | 228 | 'zip' => __('Zip', 'event_espresso'), |
229 | 229 | 'phone' => __('Phone', 'event_espresso'), |
230 | - 'fax' => __( 'Fax', 'event_espresso' ), |
|
230 | + 'fax' => __('Fax', 'event_espresso'), |
|
231 | 231 | 'cvv' => __('CVV', 'event_espresso') |
232 | 232 | ); |
233 | 233 | } |
@@ -239,10 +239,10 @@ discard block |
||
239 | 239 | * @param EE_Billing_Info_Form $billing_form |
240 | 240 | * @return array |
241 | 241 | */ |
242 | - protected function _get_billing_values_from_form( $billing_form ){ |
|
242 | + protected function _get_billing_values_from_form($billing_form) { |
|
243 | 243 | $all_billing_values_empty = array(); |
244 | - foreach( array_keys( $this->billing_input_names() ) as $input_name ) { |
|
245 | - $all_billing_values_empty[ $input_name ] = ''; |
|
244 | + foreach (array_keys($this->billing_input_names()) as $input_name) { |
|
245 | + $all_billing_values_empty[$input_name] = ''; |
|
246 | 246 | } |
247 | 247 | return array_merge( |
248 | 248 | $all_billing_values_empty, |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @see EE_PMT_Base::help_tabs_config() |
258 | 258 | * @return array |
259 | 259 | */ |
260 | - public function help_tabs_config(){ |
|
260 | + public function help_tabs_config() { |
|
261 | 261 | return array( |
262 | 262 | $this->get_help_tab_name() => array( |
263 | 263 | 'title' => __('Authorize.net AIM Settings', 'event_espresso'), |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
2 | 2 | // if you're a dev and want to receive all errors via email add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
3 | -if ( defined( 'WP_DEBUG' ) && WP_DEBUG === TRUE && defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS === TRUE ) { |
|
4 | - set_error_handler( array( 'EE_Error', 'error_handler' )); |
|
5 | - register_shutdown_function( array( 'EE_Error', 'fatal_error_handler' )); |
|
3 | +if (defined('WP_DEBUG') && WP_DEBUG === TRUE && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === TRUE) { |
|
4 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
5 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
6 | 6 | } |
7 | 7 | /** |
8 | 8 | * |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @access private |
65 | 65 | * @var boolean |
66 | 66 | */ |
67 | - private static $_espresso_notices = array( 'success' => FALSE, 'errors' => FALSE, 'attention' => FALSE ); |
|
67 | + private static $_espresso_notices = array('success' => FALSE, 'errors' => FALSE, 'attention' => FALSE); |
|
68 | 68 | |
69 | 69 | |
70 | 70 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | * @access public |
76 | 76 | * @echo string |
77 | 77 | */ |
78 | - function __construct( $message, $code = 0, Exception $previous = NULL ) { |
|
79 | - if ( version_compare( phpversion(), '5.3.0', '<' )) { |
|
80 | - parent::__construct( $message, $code ); |
|
78 | + function __construct($message, $code = 0, Exception $previous = NULL) { |
|
79 | + if (version_compare(phpversion(), '5.3.0', '<')) { |
|
80 | + parent::__construct($message, $code); |
|
81 | 81 | } else { |
82 | - parent::__construct( $message, $code, $previous ); |
|
82 | + parent::__construct($message, $code, $previous); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | * @param $line |
95 | 95 | * @return void |
96 | 96 | */ |
97 | - public static function error_handler( $code, $message, $file, $line ) { |
|
98 | - $type = EE_Error::error_type( $code ); |
|
97 | + public static function error_handler($code, $message, $file, $line) { |
|
98 | + $type = EE_Error::error_type($code); |
|
99 | 99 | $site = site_url(); |
100 | - switch ( $site ) { |
|
100 | + switch ($site) { |
|
101 | 101 | case 'http://ee4.eventespresso.com/' : |
102 | 102 | case 'http://ee4decaf.eventespresso.com/' : |
103 | 103 | case 'http://ee4hf.eventespresso.com/' : |
@@ -110,16 +110,16 @@ discard block |
||
110 | 110 | $to = '[email protected]'; |
111 | 111 | break; |
112 | 112 | default : |
113 | - $to = get_option( 'admin_email' ); |
|
113 | + $to = get_option('admin_email'); |
|
114 | 114 | } |
115 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
116 | - $msg = EE_Error::_format_error( $type, $message, $file, $line ); |
|
117 | - if ( function_exists( 'wp_mail' )) { |
|
118 | - add_filter( 'wp_mail_content_type', array( 'EE_Error', 'set_content_type' )); |
|
119 | - wp_mail( $to, $subject, $msg ); |
|
115 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
116 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
117 | + if (function_exists('wp_mail')) { |
|
118 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
119 | + wp_mail($to, $subject, $msg); |
|
120 | 120 | } |
121 | 121 | echo '<div id="message" class="espresso-notices error"><p>'; |
122 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
122 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
123 | 123 | echo '<br /></p></div>'; |
124 | 124 | } |
125 | 125 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param $code |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public static function error_type( $code ) { |
|
136 | - switch( $code ) { |
|
135 | + public static function error_type($code) { |
|
136 | + switch ($code) { |
|
137 | 137 | case E_ERROR: // 1 // |
138 | 138 | return 'E_ERROR'; |
139 | 139 | case E_WARNING: // 2 // |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public static function fatal_error_handler() { |
181 | 181 | $last_error = error_get_last(); |
182 | - if ( $last_error['type'] === E_ERROR ) { |
|
183 | - EE_Error::error_handler( E_ERROR, $last_error['message'], $last_error['file'], $last_error['line'] ); |
|
182 | + if ($last_error['type'] === E_ERROR) { |
|
183 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param $line |
196 | 196 | * @return string |
197 | 197 | */ |
198 | - private static function _format_error( $code, $message, $file, $line ) { |
|
198 | + private static function _format_error($code, $message, $file, $line) { |
|
199 | 199 | $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
200 | 200 | $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
201 | 201 | $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param $content_type |
214 | 214 | * @return string |
215 | 215 | */ |
216 | - public static function set_content_type( $content_type ) { |
|
216 | + public static function set_content_type($content_type) { |
|
217 | 217 | return 'text/html'; |
218 | 218 | } |
219 | 219 | |
@@ -227,24 +227,24 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function get_error() { |
229 | 229 | |
230 | - if( apply_filters( 'FHEE__EE_Error__get_error__show_normal_exceptions', FALSE ) ){ |
|
230 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', FALSE)) { |
|
231 | 231 | throw $this; |
232 | 232 | } |
233 | 233 | // get separate user and developer messages if they exist |
234 | - $msg = explode( '||', $this->getMessage() ); |
|
234 | + $msg = explode('||', $this->getMessage()); |
|
235 | 235 | $user_msg = $msg[0]; |
236 | - $dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0]; |
|
236 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
237 | 237 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
238 | 238 | |
239 | 239 | // add details to _all_exceptions array |
240 | 240 | $x_time = time(); |
241 | - self::$_all_exceptions[ $x_time ]['name'] = get_class( $this ); |
|
242 | - self::$_all_exceptions[ $x_time ]['file'] = $this->getFile(); |
|
243 | - self::$_all_exceptions[ $x_time ]['line'] = $this->getLine(); |
|
244 | - self::$_all_exceptions[ $x_time ]['msg'] = $msg; |
|
245 | - self::$_all_exceptions[ $x_time ]['code'] = $this->getCode(); |
|
246 | - self::$_all_exceptions[ $x_time ]['trace'] = $this->getTrace(); |
|
247 | - self::$_all_exceptions[ $x_time ]['string'] = $this->getTraceAsString(); |
|
241 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
242 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
243 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
244 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
245 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
246 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
247 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
248 | 248 | self::$_error_count++; |
249 | 249 | |
250 | 250 | //add_action( 'shutdown', array( $this, 'display_errors' )); |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @access public |
260 | 260 | * @return boolean |
261 | 261 | */ |
262 | - public static function has_error(){ |
|
262 | + public static function has_error() { |
|
263 | 263 | return self::$_error_count ? TRUE : FALSE; |
264 | 264 | } |
265 | 265 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @access public |
271 | 271 | * @echo string |
272 | 272 | */ |
273 | - public function display_errors(){ |
|
273 | + public function display_errors() { |
|
274 | 274 | |
275 | 275 | $trace_details = ''; |
276 | 276 | |
@@ -331,18 +331,18 @@ discard block |
||
331 | 331 | </style> |
332 | 332 | <div id="ee-error-message" class="error">'; |
333 | 333 | |
334 | - if ( ! WP_DEBUG ) { |
|
334 | + if ( ! WP_DEBUG) { |
|
335 | 335 | $output .= ' |
336 | 336 | <p>'; |
337 | 337 | } |
338 | 338 | |
339 | 339 | // cycle thru errors |
340 | - foreach ( self::$_all_exceptions as $time => $ex ) { |
|
340 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | 341 | |
342 | 342 | // process trace info |
343 | - if ( empty( $ex['trace'] )) { |
|
343 | + if (empty($ex['trace'])) { |
|
344 | 344 | |
345 | - $trace_details .= __( 'Sorry, but no trace information was available for this exception.', 'event_espresso' ); |
|
345 | + $trace_details .= __('Sorry, but no trace information was available for this exception.', 'event_espresso'); |
|
346 | 346 | |
347 | 347 | } else { |
348 | 348 | |
@@ -357,50 +357,50 @@ discard block |
||
357 | 357 | <th scope="col" align="left">Method( arguments )</th> |
358 | 358 | </tr>'; |
359 | 359 | |
360 | - $last_on_stack = count( $ex['trace'] ) - 1; |
|
360 | + $last_on_stack = count($ex['trace']) - 1; |
|
361 | 361 | // reverse array so that stack is in proper chronological order |
362 | - $sorted_trace = array_reverse( $ex['trace'] ); |
|
362 | + $sorted_trace = array_reverse($ex['trace']); |
|
363 | 363 | |
364 | - foreach ( $sorted_trace as $nmbr => $trace ) { |
|
364 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
365 | 365 | |
366 | - $file = isset( $trace['file'] ) ? $trace['file'] : '' ; |
|
367 | - $class = isset( $trace['class'] ) ? $trace['class'] : ''; |
|
368 | - $type = isset( $trace['type'] ) ? $trace['type'] : ''; |
|
369 | - $function = isset( $trace['function'] ) ? $trace['function'] : ''; |
|
370 | - $args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : ''; |
|
371 | - $line = isset( $trace['line'] ) ? $trace['line'] : ''; |
|
366 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
367 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
368 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
369 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
370 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
371 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
372 | 372 | $zebra = $nmbr % 2 ? ' odd' : ''; |
373 | 373 | |
374 | - if ( empty( $file ) && ! empty( $class )) { |
|
375 | - $a = new ReflectionClass( $class ); |
|
374 | + if (empty($file) && ! empty($class)) { |
|
375 | + $a = new ReflectionClass($class); |
|
376 | 376 | $file = $a->getFileName(); |
377 | - if ( empty( $line ) && ! empty( $function )) { |
|
378 | - $b = new ReflectionMethod( $class, $function ); |
|
377 | + if (empty($line) && ! empty($function)) { |
|
378 | + $b = new ReflectionMethod($class, $function); |
|
379 | 379 | $line = $b->getStartLine(); |
380 | 380 | } |
381 | 381 | } |
382 | 382 | |
383 | - if ( $nmbr == $last_on_stack ) { |
|
383 | + if ($nmbr == $last_on_stack) { |
|
384 | 384 | $file = $ex['file'] != '' ? $ex['file'] : $file; |
385 | 385 | $line = $ex['line'] != '' ? $ex['line'] : $line; |
386 | - $error_code = self::generate_error_code ( $file, $trace['function'], $line ); |
|
386 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | 387 | } |
388 | 388 | |
389 | - $nmbr_dsply = ! empty( $nmbr ) ? $nmbr : ' '; |
|
390 | - $line_dsply = ! empty( $line ) ? $line : ' '; |
|
391 | - $file_dsply = ! empty( $file ) ? $file : ' '; |
|
392 | - $class_dsply = ! empty( $class ) ? $class : ' '; |
|
393 | - $type_dsply = ! empty( $type ) ? $type : ' '; |
|
394 | - $function_dsply = ! empty( $function ) ? $function : ' '; |
|
395 | - $args_dsply = ! empty( $args ) ? '( ' . $args . ' )' : ''; |
|
389 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
390 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
391 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
392 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
393 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
394 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
395 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
396 | 396 | |
397 | 397 | $trace_details .= ' |
398 | 398 | <tr> |
399 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
400 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
401 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
402 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
403 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
399 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
400 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
401 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
402 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
403 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
404 | 404 | </tr>'; |
405 | 405 | |
406 | 406 | |
@@ -415,9 +415,9 @@ discard block |
||
415 | 415 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
416 | 416 | |
417 | 417 | // add generic non-identifying messages for non-privileged uesrs |
418 | - if ( ! WP_DEBUG ) { |
|
418 | + if ( ! WP_DEBUG) { |
|
419 | 419 | |
420 | - $output .= '<span class="ee-error-user-msg-spn">' . trim( $ex['msg'] ) . '</span> <sup>' . $ex['code'] . '</sup><br />'; |
|
420 | + $output .= '<span class="ee-error-user-msg-spn">'.trim($ex['msg']).'</span> <sup>'.$ex['code'].'</sup><br />'; |
|
421 | 421 | |
422 | 422 | } else { |
423 | 423 | |
@@ -425,24 +425,24 @@ discard block |
||
425 | 425 | $output .= ' |
426 | 426 | <div class="ee-error-dev-msg-dv"> |
427 | 427 | <p class="ee-error-dev-msg-pg"> |
428 | - <strong class="ee-error-dev-msg-str">An ' . $ex['name'] . ' exception was thrown!</strong> <span>code: ' . $ex['code'] . '</span><br /> |
|
429 | - <span class="big-text">"' . trim( $ex['msg'] ) . '"</span><br/> |
|
430 | - <a id="display-ee-error-trace-' . self::$_error_count . $time . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' . self::$_error_count . $time . '"> |
|
431 | - ' . __( 'click to view backtrace and class/method details', 'event_espresso' ) . ' |
|
428 | + <strong class="ee-error-dev-msg-str">An ' . $ex['name'].' exception was thrown!</strong> <span>code: '.$ex['code'].'</span><br /> |
|
429 | + <span class="big-text">"' . trim($ex['msg']).'"</span><br/> |
|
430 | + <a id="display-ee-error-trace-' . self::$_error_count.$time.'" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'.self::$_error_count.$time.'"> |
|
431 | + ' . __('click to view backtrace and class/method details', 'event_espresso').' |
|
432 | 432 | </a><br /> |
433 | 433 | <span class="small-text lt-grey-text">'.$ex['file'].' ( line no: '.$ex['line'].' )</span> |
434 | 434 | </p> |
435 | - <div id="ee-error-trace-' . self::$_error_count . $time . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
435 | + <div id="ee-error-trace-' . self::$_error_count.$time.'-dv" class="ee-error-trace-dv" style="display: none;"> |
|
436 | 436 | ' . $trace_details; |
437 | 437 | |
438 | - if ( ! empty( $class )) { |
|
438 | + if ( ! empty($class)) { |
|
439 | 439 | $output .= ' |
440 | 440 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
441 | 441 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
442 | 442 | <h3>Class Details</h3>'; |
443 | - $a = new ReflectionClass( $class ); |
|
443 | + $a = new ReflectionClass($class); |
|
444 | 444 | $output .= ' |
445 | - <pre>' . $a . '</pre> |
|
445 | + <pre>' . $a.'</pre> |
|
446 | 446 | </div> |
447 | 447 | </div>'; |
448 | 448 | } |
@@ -454,14 +454,14 @@ discard block |
||
454 | 454 | |
455 | 455 | } |
456 | 456 | |
457 | - $this->write_to_error_log( $time, $ex ); |
|
457 | + $this->write_to_error_log($time, $ex); |
|
458 | 458 | |
459 | 459 | } |
460 | 460 | |
461 | 461 | // remove last linebreak |
462 | - $output = substr( $output, 0, ( count( $output ) - 7 )); |
|
462 | + $output = substr($output, 0, (count($output) - 7)); |
|
463 | 463 | |
464 | - if ( ! WP_DEBUG ) { |
|
464 | + if ( ! WP_DEBUG) { |
|
465 | 465 | $output .= ' |
466 | 466 | </p>'; |
467 | 467 | } |
@@ -469,10 +469,10 @@ discard block |
||
469 | 469 | $output .= ' |
470 | 470 | </div>'; |
471 | 471 | |
472 | - $output .= self::_print_scripts( TRUE ); |
|
472 | + $output .= self::_print_scripts(TRUE); |
|
473 | 473 | |
474 | - if ( defined( 'DOING_AJAX' )) { |
|
475 | - echo json_encode( array( 'error' => $output )); |
|
474 | + if (defined('DOING_AJAX')) { |
|
475 | + echo json_encode(array('error' => $output)); |
|
476 | 476 | exit(); |
477 | 477 | } |
478 | 478 | |
@@ -492,29 +492,29 @@ discard block |
||
492 | 492 | * @ param array $arguments |
493 | 493 | * @ return string |
494 | 494 | */ |
495 | - private function _convert_args_to_string ( $arguments = array(), $array = FALSE ) { |
|
495 | + private function _convert_args_to_string($arguments = array(), $array = FALSE) { |
|
496 | 496 | |
497 | 497 | $arg_string = ''; |
498 | - if ( ! empty( $arguments )) { |
|
498 | + if ( ! empty($arguments)) { |
|
499 | 499 | |
500 | 500 | $args = array(); |
501 | 501 | |
502 | - foreach ( $arguments as $arg ) { |
|
502 | + foreach ($arguments as $arg) { |
|
503 | 503 | |
504 | - if ( ! empty( $arg )) { |
|
504 | + if ( ! empty($arg)) { |
|
505 | 505 | |
506 | - if ( is_string( $arg )) { |
|
507 | - $args[] = " '" . $arg . "'"; |
|
508 | - } elseif ( is_array( $arg )) { |
|
509 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string( $arg, TRUE ); |
|
510 | - } elseif ( is_null( $arg )) { |
|
506 | + if (is_string($arg)) { |
|
507 | + $args[] = " '".$arg."'"; |
|
508 | + } elseif (is_array($arg)) { |
|
509 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, TRUE); |
|
510 | + } elseif (is_null($arg)) { |
|
511 | 511 | $args[] = ' NULL'; |
512 | - } elseif ( is_bool( $arg )) { |
|
513 | - $args[] = ( $arg ) ? ' TRUE' : ' FALSE'; |
|
514 | - } elseif ( is_object( $arg )) { |
|
515 | - $args[] = ' OBJECT ' . get_class( $arg ); |
|
516 | - } elseif ( is_resource( $arg )) { |
|
517 | - $args[] = get_resource_type( $arg ); |
|
512 | + } elseif (is_bool($arg)) { |
|
513 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
514 | + } elseif (is_object($arg)) { |
|
515 | + $args[] = ' OBJECT '.get_class($arg); |
|
516 | + } elseif (is_resource($arg)) { |
|
517 | + $args[] = get_resource_type($arg); |
|
518 | 518 | } else { |
519 | 519 | $args[] = $arg; |
520 | 520 | } |
@@ -522,9 +522,9 @@ discard block |
||
522 | 522 | } |
523 | 523 | |
524 | 524 | } |
525 | - $arg_string = implode( ', ', $args ); |
|
525 | + $arg_string = implode(', ', $args); |
|
526 | 526 | } |
527 | - if ( $array ) { |
|
527 | + if ($array) { |
|
528 | 528 | $arg_string .= ' )'; |
529 | 529 | } |
530 | 530 | return $arg_string; |
@@ -544,8 +544,8 @@ discard block |
||
544 | 544 | * @param string $line the line number where the error occurred - just use __LINE__ |
545 | 545 | * @return void |
546 | 546 | */ |
547 | - public static function add_error( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) { |
|
548 | - self::_add_notice ( 'errors', $msg, $file, $func, $line ); |
|
547 | + public static function add_error($msg = NULL, $file = NULL, $func = NULL, $line = NULL) { |
|
548 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
549 | 549 | self::$_error_count++; |
550 | 550 | } |
551 | 551 | |
@@ -558,11 +558,11 @@ discard block |
||
558 | 558 | * @param string $line |
559 | 559 | * @throws EE_Error |
560 | 560 | */ |
561 | - public static function throw_exception_if_debugging( $msg = null, $file = null, $func = null, $line = null ) { |
|
562 | - if( WP_DEBUG ) { |
|
563 | - throw new EE_Error( $msg ); |
|
564 | - } else { |
|
565 | - EE_Error::add_error( $msg, $file, $func, $line ); |
|
561 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) { |
|
562 | + if (WP_DEBUG) { |
|
563 | + throw new EE_Error($msg); |
|
564 | + } else { |
|
565 | + EE_Error::add_error($msg, $file, $func, $line); |
|
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
@@ -580,8 +580,8 @@ discard block |
||
580 | 580 | * @param string $line the line number where the error occurred - just use __LINE__ |
581 | 581 | * @return void |
582 | 582 | */ |
583 | - public static function add_success( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) { |
|
584 | - self::_add_notice ( 'success', $msg, $file, $func, $line ); |
|
583 | + public static function add_success($msg = NULL, $file = NULL, $func = NULL, $line = NULL) { |
|
584 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | |
@@ -598,8 +598,8 @@ discard block |
||
598 | 598 | * @param string $line the line number where the error occurred - just use __LINE__ |
599 | 599 | * @return void |
600 | 600 | */ |
601 | - public static function add_attention( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) { |
|
602 | - self::_add_notice ( 'attention', $msg, $file, $func, $line ); |
|
601 | + public static function add_attention($msg = NULL, $file = NULL, $func = NULL, $line = NULL) { |
|
602 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | |
@@ -617,12 +617,12 @@ discard block |
||
617 | 617 | * @param string $line the line number where the error occurred - just use __LINE__ |
618 | 618 | * @return void |
619 | 619 | */ |
620 | - private static function _add_notice( $type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) { |
|
621 | - if ( empty( $msg )) { |
|
620 | + private static function _add_notice($type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL) { |
|
621 | + if (empty($msg)) { |
|
622 | 622 | EE_Error::doing_it_wrong( |
623 | - 'EE_Error::add_' . $type . '()', |
|
623 | + 'EE_Error::add_'.$type.'()', |
|
624 | 624 | sprintf( |
625 | - __( 'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso' ), |
|
625 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso'), |
|
626 | 626 | $type, |
627 | 627 | $file, |
628 | 628 | $line |
@@ -630,17 +630,17 @@ discard block |
||
630 | 630 | EVENT_ESPRESSO_VERSION |
631 | 631 | ); |
632 | 632 | } |
633 | - if ( $type == 'errors' && ( empty( $file ) || empty( $func ) || empty( $line ))) { |
|
633 | + if ($type == 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
634 | 634 | EE_Error::doing_it_wrong( |
635 | 635 | 'EE_Error::add_error()', |
636 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso' ), |
|
636 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso'), |
|
637 | 637 | EVENT_ESPRESSO_VERSION |
638 | 638 | ); |
639 | 639 | } |
640 | 640 | // get separate user and developer messages if they exist |
641 | - $msg = explode( '||', $msg ); |
|
641 | + $msg = explode('||', $msg); |
|
642 | 642 | $user_msg = $msg[0]; |
643 | - $dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0]; |
|
643 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
644 | 644 | /** |
645 | 645 | * Do an action so other code can be triggered when a notice is created |
646 | 646 | * @param string $type can be 'errors', 'attention', or 'success' |
@@ -650,22 +650,22 @@ discard block |
||
650 | 650 | * @param string $func function where error was generated |
651 | 651 | * @param string $line line where error was generated |
652 | 652 | */ |
653 | - do_action( 'AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line ); |
|
653 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
654 | 654 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
655 | 655 | // add notice if message exists |
656 | - if ( ! empty( $msg )) { |
|
656 | + if ( ! empty($msg)) { |
|
657 | 657 | // get error code |
658 | - $notice_code = EE_Error::generate_error_code( $file, $func, $line ); |
|
659 | - if ( WP_DEBUG && $type == 'errors' ) { |
|
660 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
658 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
659 | + if (WP_DEBUG && $type == 'errors') { |
|
660 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
661 | 661 | } |
662 | 662 | // add notice. Index by code if it's not blank |
663 | - if( $notice_code ) { |
|
664 | - self::$_espresso_notices[ $type ][ $notice_code ] = $msg; |
|
663 | + if ($notice_code) { |
|
664 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
665 | 665 | } else { |
666 | - self::$_espresso_notices[ $type ][] = $msg; |
|
666 | + self::$_espresso_notices[$type][] = $msg; |
|
667 | 667 | } |
668 | - add_action( 'wp_footer', array( 'EE_Error', 'enqueue_error_scripts' ), 1 ); |
|
668 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | } |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | * @access private |
720 | 720 | * @return void |
721 | 721 | */ |
722 | - public static function reset_notices(){ |
|
722 | + public static function reset_notices() { |
|
723 | 723 | self::$_espresso_notices['success'] = FALSE; |
724 | 724 | self::$_espresso_notices['attention'] = FALSE; |
725 | 725 | self::$_espresso_notices['errors'] = FALSE; |
@@ -732,14 +732,14 @@ discard block |
||
732 | 732 | * @access public |
733 | 733 | * @return int |
734 | 734 | */ |
735 | - public static function has_notices(){ |
|
735 | + public static function has_notices() { |
|
736 | 736 | $has_notices = 0; |
737 | 737 | // check for success messages |
738 | - $has_notices = self::$_espresso_notices['success'] && ! empty( self::$_espresso_notices['success'] ) ? 3 : $has_notices; |
|
738 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 : $has_notices; |
|
739 | 739 | // check for attention messages |
740 | - $has_notices = self::$_espresso_notices['attention'] && ! empty( self::$_espresso_notices['attention'] ) ? 2 : $has_notices; |
|
740 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 : $has_notices; |
|
741 | 741 | // check for error messages |
742 | - $has_notices = self::$_espresso_notices['errors'] && ! empty( self::$_espresso_notices['errors'] ) ? 1 : $has_notices; |
|
742 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 : $has_notices; |
|
743 | 743 | return $has_notices; |
744 | 744 | } |
745 | 745 | |
@@ -754,9 +754,9 @@ discard block |
||
754 | 754 | */ |
755 | 755 | public static function get_vanilla_notices() { |
756 | 756 | return array( |
757 | - 'success' => isset( self::$_espresso_notices['success'] ) ? self::$_espresso_notices['success'] : array(), |
|
758 | - 'attention' => isset( self::$_espresso_notices['attention'] ) ? self::$_espresso_notices['attention'] : array(), |
|
759 | - 'errors' => isset( self::$_espresso_notices['errors'] ) ? self::$_espresso_notices['errors'] : array(), |
|
757 | + 'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(), |
|
758 | + 'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] : array(), |
|
759 | + 'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(), |
|
760 | 760 | ); |
761 | 761 | } |
762 | 762 | |
@@ -772,8 +772,8 @@ discard block |
||
772 | 772 | * @param boolean $remove_empty whether or not to unset empty messages |
773 | 773 | * @return array |
774 | 774 | */ |
775 | - public static function get_notices( $format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE ) { |
|
776 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
775 | + public static function get_notices($format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE) { |
|
776 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
777 | 777 | |
778 | 778 | $success_messages = ''; |
779 | 779 | $attention_messages = ''; |
@@ -783,44 +783,44 @@ discard block |
||
783 | 783 | // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
784 | 784 | |
785 | 785 | // either save notices to the db |
786 | - if ( $save_to_transient ) { |
|
787 | - update_option( 'ee_notices', self::$_espresso_notices ); |
|
786 | + if ($save_to_transient) { |
|
787 | + update_option('ee_notices', self::$_espresso_notices); |
|
788 | 788 | return; |
789 | 789 | } |
790 | 790 | // grab any notices that have been previously saved |
791 | - if ( $notices = get_option( 'ee_notices', FALSE )) { |
|
792 | - foreach ( $notices as $type => $notice ) { |
|
793 | - if ( is_array( $notice ) && ! empty( $notice )) { |
|
791 | + if ($notices = get_option('ee_notices', FALSE)) { |
|
792 | + foreach ($notices as $type => $notice) { |
|
793 | + if (is_array($notice) && ! empty($notice)) { |
|
794 | 794 | // make sure that existsing notice type is an array |
795 | - self::$_espresso_notices[ $type ] = is_array( self::$_espresso_notices[ $type ] ) && ! empty( self::$_espresso_notices[ $type ] ) ? self::$_espresso_notices[ $type ] : array(); |
|
795 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) && ! empty(self::$_espresso_notices[$type]) ? self::$_espresso_notices[$type] : array(); |
|
796 | 796 | // merge stored notices with any newly created ones |
797 | - self::$_espresso_notices[ $type ] = array_merge( self::$_espresso_notices[ $type ], $notice ); |
|
797 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
798 | 798 | $print_scripts = TRUE; |
799 | 799 | } |
800 | 800 | } |
801 | 801 | // now clear any stored notices |
802 | - update_option( 'ee_notices', FALSE ); |
|
802 | + update_option('ee_notices', FALSE); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | // check for success messages |
806 | - if ( self::$_espresso_notices['success'] && ! empty( self::$_espresso_notices['success'] )) { |
|
806 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
807 | 807 | // combine messages |
808 | - $success_messages .= implode( self::$_espresso_notices['success'], '<br />' ); |
|
808 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
809 | 809 | $print_scripts = TRUE; |
810 | 810 | } |
811 | 811 | |
812 | 812 | // check for attention messages |
813 | - if ( self::$_espresso_notices['attention'] && ! empty( self::$_espresso_notices['attention'] ) ) { |
|
813 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
814 | 814 | // combine messages |
815 | - $attention_messages .= implode( self::$_espresso_notices['attention'], '<br />' ); |
|
815 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
816 | 816 | $print_scripts = TRUE; |
817 | 817 | } |
818 | 818 | |
819 | 819 | // check for error messages |
820 | - if ( self::$_espresso_notices['errors'] && ! empty( self::$_espresso_notices['errors'] ) ) { |
|
821 | - $error_messages .= count( self::$_espresso_notices['errors'] ) > 1 ? __( 'The following errors have occurred:<br />', 'event_espresso' ) : __( 'An error has occurred:<br />', 'event_espresso' ); |
|
820 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 ? __('The following errors have occurred:<br />', 'event_espresso') : __('An error has occurred:<br />', 'event_espresso'); |
|
822 | 822 | // combine messages |
823 | - $error_messages .= implode( self::$_espresso_notices['errors'], '<br />' ); |
|
823 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
824 | 824 | $print_scripts = TRUE; |
825 | 825 | } |
826 | 826 | |
@@ -834,21 +834,21 @@ discard block |
||
834 | 834 | $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
835 | 835 | $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
836 | 836 | //showMessage( $success_messages ); |
837 | - $notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $success_messages . '</p>' . $close . '</div>'; |
|
837 | + $notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$success_messages.'</p>'.$close.'</div>'; |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | if ($attention_messages != '') { |
841 | 841 | $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
842 | 842 | $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
843 | 843 | //showMessage( $error_messages, TRUE ); |
844 | - $notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $attention_messages . '</p>' . $close . '</div>'; |
|
844 | + $notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$attention_messages.'</p>'.$close.'</div>'; |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | if ($error_messages != '') { |
848 | 848 | $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
849 | 849 | $css_class = is_admin() ? 'error' : 'error fade-away'; |
850 | 850 | //showMessage( $error_messages, TRUE ); |
851 | - $notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $error_messages . '</p>' . $close . '</div>'; |
|
851 | + $notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$error_messages.'</p>'.$close.'</div>'; |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | $notices .= '</div>'; |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | 'errors' => $error_messages |
862 | 862 | ); |
863 | 863 | |
864 | - if ( $remove_empty ) { |
|
864 | + if ($remove_empty) { |
|
865 | 865 | // remove empty notices |
866 | 866 | foreach ($notices as $type => $notice) { |
867 | 867 | if (empty($notice)) { |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | } |
872 | 872 | } |
873 | 873 | |
874 | - if ( $print_scripts ) { |
|
874 | + if ($print_scripts) { |
|
875 | 875 | self::_print_scripts(); |
876 | 876 | } |
877 | 877 | |
@@ -891,17 +891,17 @@ discard block |
||
891 | 891 | * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
892 | 892 | * @return void |
893 | 893 | */ |
894 | - public static function add_persistent_admin_notice( $pan_name = '', $pan_message, $force_update = FALSE ) { |
|
895 | - if ( ! empty( $pan_name ) && ! empty( $pan_message )) { |
|
896 | - $persistent_admin_notices = get_option( 'ee_pers_admin_notices', array() ); |
|
894 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = FALSE) { |
|
895 | + if ( ! empty($pan_name) && ! empty($pan_message)) { |
|
896 | + $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
897 | 897 | //maybe initialize persistent_admin_notices |
898 | - if ( empty( $persistent_admin_notices )) { |
|
899 | - add_option( 'ee_pers_admin_notices', array(), '', 'no' ); |
|
898 | + if (empty($persistent_admin_notices)) { |
|
899 | + add_option('ee_pers_admin_notices', array(), '', 'no'); |
|
900 | 900 | } |
901 | - $pan_name = sanitize_key( $pan_name ); |
|
902 | - if ( ! array_key_exists( $pan_name, $persistent_admin_notices ) || $force_update ) { |
|
903 | - $persistent_admin_notices[ $pan_name ] = $pan_message; |
|
904 | - update_option( 'ee_pers_admin_notices', $persistent_admin_notices ); |
|
901 | + $pan_name = sanitize_key($pan_name); |
|
902 | + if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) { |
|
903 | + $persistent_admin_notices[$pan_name] = $pan_message; |
|
904 | + update_option('ee_pers_admin_notices', $persistent_admin_notices); |
|
905 | 905 | } |
906 | 906 | } |
907 | 907 | } |
@@ -917,34 +917,34 @@ discard block |
||
917 | 917 | * @param bool $return_immediately |
918 | 918 | * @return void |
919 | 919 | */ |
920 | - public static function dismiss_persistent_admin_notice( $pan_name = '', $purge = FALSE, $return_immediately = FALSE ) { |
|
921 | - $pan_name = EE_Registry::instance()->REQ->is_set( 'ee_nag_notice' ) ? EE_Registry::instance()->REQ->get( 'ee_nag_notice' ) : $pan_name; |
|
922 | - if ( ! empty( $pan_name )) { |
|
923 | - $persistent_admin_notices = get_option( 'ee_pers_admin_notices', array() ); |
|
920 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = FALSE, $return_immediately = FALSE) { |
|
921 | + $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name; |
|
922 | + if ( ! empty($pan_name)) { |
|
923 | + $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
924 | 924 | // check if notice we wish to dismiss is actually in the $persistent_admin_notices array |
925 | - if ( is_array( $persistent_admin_notices ) && isset( $persistent_admin_notices[ $pan_name ] )) { |
|
925 | + if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) { |
|
926 | 926 | // completely delete nag notice, or just NULL message so that it can NOT be added again ? |
927 | - if ( $purge ) { |
|
928 | - unset( $persistent_admin_notices[ $pan_name ] ); |
|
927 | + if ($purge) { |
|
928 | + unset($persistent_admin_notices[$pan_name]); |
|
929 | 929 | } else { |
930 | - $persistent_admin_notices[ $pan_name ] = NULL; |
|
930 | + $persistent_admin_notices[$pan_name] = NULL; |
|
931 | 931 | } |
932 | - if ( update_option( 'ee_pers_admin_notices', $persistent_admin_notices ) === FALSE ) { |
|
933 | - EE_Error::add_error( sprintf( __( 'The persistent admin notice for "%s" could not be deleted.', 'event_espresso' ), $pan_name ), __FILE__, __FUNCTION__, __LINE__ ); |
|
932 | + if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === FALSE) { |
|
933 | + EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.', 'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__); |
|
934 | 934 | } |
935 | 935 | } |
936 | 936 | } |
937 | - if ( $return_immediately ) { |
|
937 | + if ($return_immediately) { |
|
938 | 938 | return; |
939 | - } else if ( EE_Registry::instance()->REQ->ajax ) { |
|
939 | + } else if (EE_Registry::instance()->REQ->ajax) { |
|
940 | 940 | // grab any notices and concatenate into string |
941 | - echo json_encode( array( 'errors' => implode( '<br />', EE_Error::get_notices( FALSE )))); |
|
941 | + echo json_encode(array('errors' => implode('<br />', EE_Error::get_notices(FALSE)))); |
|
942 | 942 | exit(); |
943 | 943 | } else { |
944 | 944 | // save errors to a transient to be displayed on next request (after redirect) |
945 | - EE_Error::get_notices( FALSE, TRUE ); |
|
946 | - $return_url = EE_Registry::instance()->REQ->is_set( 'return_url' ) ? EE_Registry::instance()->REQ->get( 'return_url' ) : ''; |
|
947 | - wp_safe_redirect( urldecode( $return_url )); |
|
945 | + EE_Error::get_notices(FALSE, TRUE); |
|
946 | + $return_url = EE_Registry::instance()->REQ->is_set('return_url') ? EE_Registry::instance()->REQ->get('return_url') : ''; |
|
947 | + wp_safe_redirect(urldecode($return_url)); |
|
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
@@ -959,20 +959,20 @@ discard block |
||
959 | 959 | * @param string $return_url URL to go back to aftger nag notice is dismissed |
960 | 960 | * @return string |
961 | 961 | */ |
962 | - public static function display_persistent_admin_notices( $pan_name = '', $pan_message = '', $return_url = '' ) { |
|
963 | - if ( ! empty( $pan_name ) && ! empty( $pan_message )) { |
|
962 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') { |
|
963 | + if ( ! empty($pan_name) && ! empty($pan_message)) { |
|
964 | 964 | $args = array( |
965 | 965 | 'nag_notice' => $pan_name, |
966 | - 'return_url' => urlencode( $return_url ), |
|
966 | + 'return_url' => urlencode($return_url), |
|
967 | 967 | 'ajax_url' => WP_AJAX_URL, |
968 | - 'unknown_error' => __( 'An unknown error has occurred on the server while attempting to dismiss this notice.', 'event_espresso' ) |
|
968 | + 'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.', 'event_espresso') |
|
969 | 969 | ); |
970 | - wp_localize_script( 'espresso_core', 'ee_dismiss', $args ); |
|
970 | + wp_localize_script('espresso_core', 'ee_dismiss', $args); |
|
971 | 971 | return ' |
972 | - <div id="' . $pan_name . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;"> |
|
973 | - <p>' . $pan_message . '</p> |
|
974 | - <a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' . $pan_name . '"> |
|
975 | - <span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'.__( 'Dismiss', 'event_espresso' ) .' |
|
972 | + <div id="' . $pan_name.'" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;"> |
|
973 | + <p>' . $pan_message.'</p> |
|
974 | + <a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' . $pan_name.'"> |
|
975 | + <span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'.__('Dismiss', 'event_espresso').' |
|
976 | 976 | </a> |
977 | 977 | <div style="clear:both;"></div> |
978 | 978 | </div>'; |
@@ -988,24 +988,24 @@ discard block |
||
988 | 988 | * @param string $return_url |
989 | 989 | * @return array |
990 | 990 | */ |
991 | - public static function get_persistent_admin_notices( $return_url = '' ) { |
|
991 | + public static function get_persistent_admin_notices($return_url = '') { |
|
992 | 992 | $notices = ''; |
993 | 993 | // check for persistent admin notices |
994 | 994 | //filter the list though so plugins can notify the admin in a different way if they want |
995 | 995 | $persistent_admin_notices = apply_filters( |
996 | 996 | 'FHEE__EE_Error__get_persistent_admin_notices', |
997 | - get_option( 'ee_pers_admin_notices', FALSE ), |
|
997 | + get_option('ee_pers_admin_notices', FALSE), |
|
998 | 998 | 'ee_pers_admin_notices', |
999 | 999 | $return_url |
1000 | 1000 | ); |
1001 | - if ( $persistent_admin_notices ) { |
|
1001 | + if ($persistent_admin_notices) { |
|
1002 | 1002 | // load scripts |
1003 | - wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
1004 | - wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
1005 | - wp_enqueue_script( 'ee_error_js' ); |
|
1003 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
1004 | + wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, TRUE); |
|
1005 | + wp_enqueue_script('ee_error_js'); |
|
1006 | 1006 | // and display notices |
1007 | - foreach( $persistent_admin_notices as $pan_name => $pan_message ) { |
|
1008 | - $notices .= self::display_persistent_admin_notices( $pan_name, $pan_message, $return_url ); |
|
1007 | + foreach ($persistent_admin_notices as $pan_name => $pan_message) { |
|
1008 | + $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url); |
|
1009 | 1009 | } |
1010 | 1010 | } |
1011 | 1011 | return $notices; |
@@ -1020,26 +1020,26 @@ discard block |
||
1020 | 1020 | * @param bool $force_print |
1021 | 1021 | * @return void |
1022 | 1022 | */ |
1023 | - private static function _print_scripts( $force_print = FALSE ) { |
|
1024 | - if (( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' )) && ! $force_print ) { |
|
1025 | - if ( wp_script_is( 'ee_error_js', 'enqueued' )) { |
|
1023 | + private static function _print_scripts($force_print = FALSE) { |
|
1024 | + if ((did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts')) && ! $force_print) { |
|
1025 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
1026 | 1026 | return; |
1027 | - } else if ( wp_script_is( 'ee_error_js', 'registered' )) { |
|
1028 | - add_filter( 'FHEE_load_css', '__return_true' ); |
|
1029 | - add_filter( 'FHEE_load_js', '__return_true' ); |
|
1030 | - wp_enqueue_script( 'ee_error_js' ); |
|
1031 | - wp_localize_script( 'ee_error_js','ee_settings', array( 'wp_debug'=>WP_DEBUG )); |
|
1027 | + } else if (wp_script_is('ee_error_js', 'registered')) { |
|
1028 | + add_filter('FHEE_load_css', '__return_true'); |
|
1029 | + add_filter('FHEE_load_js', '__return_true'); |
|
1030 | + wp_enqueue_script('ee_error_js'); |
|
1031 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug'=>WP_DEBUG)); |
|
1032 | 1032 | } |
1033 | 1033 | } else { |
1034 | 1034 | return ' |
1035 | 1035 | <script> |
1036 | 1036 | /* <![CDATA[ */ |
1037 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
1037 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
1038 | 1038 | /* ]]> */ |
1039 | 1039 | </script> |
1040 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
1041 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
1042 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
1040 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
1041 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
1042 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
1043 | 1043 | '; |
1044 | 1044 | |
1045 | 1045 | } |
@@ -1073,11 +1073,11 @@ discard block |
||
1073 | 1073 | * @ param string $line |
1074 | 1074 | * @ return string |
1075 | 1075 | */ |
1076 | - public static function generate_error_code ( $file = '', $func = '', $line = '' ) { |
|
1077 | - $file = explode( '.', basename( $file )); |
|
1078 | - $error_code = ! empty( $file[0] ) ? $file[0] : ''; |
|
1079 | - $error_code .= ! empty( $func ) ? ' - ' . $func : ''; |
|
1080 | - $error_code .= ! empty( $line ) ? ' - ' . $line : ''; |
|
1076 | + public static function generate_error_code($file = '', $func = '', $line = '') { |
|
1077 | + $file = explode('.', basename($file)); |
|
1078 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
1079 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
1080 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
1081 | 1081 | return $error_code; |
1082 | 1082 | } |
1083 | 1083 | |
@@ -1093,36 +1093,36 @@ discard block |
||
1093 | 1093 | * @ param object $ex |
1094 | 1094 | * @ return void |
1095 | 1095 | */ |
1096 | - public function write_to_error_log ( $time = FALSE, $ex = FALSE, $clear = FALSE ) { |
|
1096 | + public function write_to_error_log($time = FALSE, $ex = FALSE, $clear = FALSE) { |
|
1097 | 1097 | |
1098 | - if ( ! $ex ) { |
|
1098 | + if ( ! $ex) { |
|
1099 | 1099 | return; |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if ( ! $time ) { |
|
1102 | + if ( ! $time) { |
|
1103 | 1103 | $time = time(); |
1104 | 1104 | } |
1105 | 1105 | |
1106 | - $exception_log = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
1107 | - $exception_log .= '[' . date( 'Y-m-d H:i:s', $time ) . '] Exception Details' . PHP_EOL; |
|
1108 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1109 | - $exception_log .= 'Code: '. $ex['code'] . PHP_EOL; |
|
1110 | - $exception_log .= 'File: '. $ex['file'] . PHP_EOL; |
|
1111 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1112 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1113 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
1114 | - $exception_log .= '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
1106 | + $exception_log = '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
1107 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
1108 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
1109 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
1110 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
1111 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
1112 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
1113 | + $exception_log .= $ex['string'].PHP_EOL; |
|
1114 | + $exception_log .= '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
1115 | 1115 | |
1116 | 1116 | try { |
1117 | - EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file ); |
|
1118 | - EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' ); |
|
1119 | - if ( ! $clear ) { |
|
1117 | + EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file); |
|
1118 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs'); |
|
1119 | + if ( ! $clear) { |
|
1120 | 1120 | //get existing log file and append new log info |
1121 | - $exception_log = EEH_File::get_file_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file ) . $exception_log; |
|
1121 | + $exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file).$exception_log; |
|
1122 | 1122 | } |
1123 | - EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, $exception_log ); |
|
1124 | - } catch( EE_Error $e ){ |
|
1125 | - EE_Error::add_error( sprintf( __( 'Event Espresso error logging could not be setup because: %s', 'event_espresso' ), $e->getMessage() )); |
|
1123 | + EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file, $exception_log); |
|
1124 | + } catch (EE_Error $e) { |
|
1125 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', 'event_espresso'), $e->getMessage())); |
|
1126 | 1126 | return; |
1127 | 1127 | } |
1128 | 1128 | |
@@ -1158,8 +1158,8 @@ discard block |
||
1158 | 1158 | $applies_when = '', |
1159 | 1159 | $error_type = null |
1160 | 1160 | ) { |
1161 | - if ( defined('WP_DEBUG') && WP_DEBUG ) { |
|
1162 | - EEH_Debug_Tools::instance()->doing_it_wrong( $function, $message, $version, $applies_when, $error_type ); |
|
1161 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1162 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1163 | 1163 | } |
1164 | 1164 | } |
1165 | 1165 | |
@@ -1193,13 +1193,13 @@ discard block |
||
1193 | 1193 | */ |
1194 | 1194 | function espresso_error_enqueue_scripts() { |
1195 | 1195 | // js for error handling |
1196 | - wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE ); |
|
1197 | - wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE ); |
|
1196 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE); |
|
1197 | + wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE); |
|
1198 | 1198 | } |
1199 | -if ( is_admin() ) { |
|
1200 | - add_action( 'admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 ); |
|
1199 | +if (is_admin()) { |
|
1200 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1201 | 1201 | } else { |
1202 | - add_action( 'wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 ); |
|
1202 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
2 | 2 | /** |
3 | 3 | * Class EEH_Debug_Tools |
4 | 4 | * |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 4.0 |
9 | 9 | * |
10 | 10 | */ |
11 | -class EEH_Debug_Tools{ |
|
11 | +class EEH_Debug_Tools { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * instance of the EEH_Autoloader object |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function instance() { |
43 | 43 | // check if class object is instantiated, and instantiated properly |
44 | - if ( ! self::$_instance instanceof EEH_Debug_Tools ) { |
|
44 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
45 | 45 | self::$_instance = new self(); |
46 | 46 | } |
47 | 47 | return self::$_instance; |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | */ |
58 | 58 | private function __construct() { |
59 | 59 | // load Kint PHP debugging library |
60 | - if ( ! class_exists( 'Kint' ) && file_exists( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' )){ |
|
60 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
61 | 61 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
62 | 62 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
63 | 63 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
64 | 64 | // so we've moved it to our test folder so that it is not included with production releases |
65 | 65 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
66 | - require_once( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' ); |
|
66 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
67 | 67 | } |
68 | 68 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
69 | 69 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
70 | 70 | // } |
71 | - $plugin = basename( EE_PLUGIN_DIR_PATH ); |
|
72 | - add_action( "activate_{$plugin}", array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' )); |
|
73 | - add_action( 'activated_plugin', array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' )); |
|
74 | - add_action( 'shutdown', array( 'EEH_Debug_Tools', 'show_db_name' )); |
|
71 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
72 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
73 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
74 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | * @return void |
83 | 83 | */ |
84 | 84 | public static function show_db_name() { |
85 | - if ( ! defined( 'DOING_AJAX' ) && ( defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS )) { |
|
86 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '. DB_NAME .'</p>'; |
|
85 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
86 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '.DB_NAME.'</p>'; |
|
87 | 87 | } |
88 | - if ( EE_DEBUG ) { |
|
88 | + if (EE_DEBUG) { |
|
89 | 89 | EEH_Debug_Tools::instance()->show_times(); |
90 | 90 | } |
91 | 91 | } |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function espresso_session_footer_dump() { |
101 | 101 | if ( |
102 | - ( defined( 'WP_DEBUG' ) && WP_DEBUG ) |
|
103 | - && ! defined( 'DOING_AJAX' ) |
|
104 | - && class_exists( 'Kint' ) |
|
105 | - && function_exists( 'wp_get_current_user' ) |
|
106 | - && current_user_can( 'update_core' ) |
|
107 | - && class_exists( 'EE_Registry' ) |
|
102 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
103 | + && ! defined('DOING_AJAX') |
|
104 | + && class_exists('Kint') |
|
105 | + && function_exists('wp_get_current_user') |
|
106 | + && current_user_can('update_core') |
|
107 | + && class_exists('EE_Registry') |
|
108 | 108 | ) { |
109 | - Kint::dump( EE_Registry::instance()->SSN->id() ); |
|
110 | - Kint::dump( EE_Registry::instance()->SSN ); |
|
109 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
110 | + Kint::dump(EE_Registry::instance()->SSN); |
|
111 | 111 | // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
112 | 112 | $this->espresso_list_hooked_functions(); |
113 | 113 | $this->show_times(); |
@@ -124,27 +124,27 @@ discard block |
||
124 | 124 | * @param string $tag |
125 | 125 | * @return void |
126 | 126 | */ |
127 | - public function espresso_list_hooked_functions( $tag='' ){ |
|
127 | + public function espresso_list_hooked_functions($tag = '') { |
|
128 | 128 | global $wp_filter; |
129 | 129 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
130 | - if ( $tag ) { |
|
131 | - $hook[$tag]=$wp_filter[$tag]; |
|
132 | - if ( ! is_array( $hook[$tag] )) { |
|
133 | - trigger_error( "Nothing found for '$tag' hook", E_USER_WARNING ); |
|
130 | + if ($tag) { |
|
131 | + $hook[$tag] = $wp_filter[$tag]; |
|
132 | + if ( ! is_array($hook[$tag])) { |
|
133 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
134 | 134 | return; |
135 | 135 | } |
136 | - echo '<h5>For Tag: '. $tag .'</h5>'; |
|
136 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
137 | 137 | } |
138 | 138 | else { |
139 | - $hook=$wp_filter; |
|
140 | - ksort( $hook ); |
|
139 | + $hook = $wp_filter; |
|
140 | + ksort($hook); |
|
141 | 141 | } |
142 | - foreach( $hook as $tag_name => $priorities ) { |
|
142 | + foreach ($hook as $tag_name => $priorities) { |
|
143 | 143 | echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
144 | - ksort( $priorities ); |
|
145 | - foreach( $priorities as $priority => $function ){ |
|
144 | + ksort($priorities); |
|
145 | + foreach ($priorities as $priority => $function) { |
|
146 | 146 | echo $priority; |
147 | - foreach( $function as $name => $properties ) { |
|
147 | + foreach ($function as $name => $properties) { |
|
148 | 148 | echo "\t$name<br />"; |
149 | 149 | } |
150 | 150 | } |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | * @param string $hook_name |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - public static function registered_filter_callbacks( $hook_name = '' ) { |
|
162 | + public static function registered_filter_callbacks($hook_name = '') { |
|
163 | 163 | $filters = array(); |
164 | 164 | global $wp_filter; |
165 | - if ( isset( $wp_filter[ $hook_name ] ) ) { |
|
166 | - $filters[ $hook_name ] = array(); |
|
167 | - foreach ( $wp_filter[ $hook_name ] as $priority => $callbacks ) { |
|
168 | - $filters[ $hook_name ][ $priority ] = array(); |
|
169 | - foreach ( $callbacks as $callback ) { |
|
170 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
165 | + if (isset($wp_filter[$hook_name])) { |
|
166 | + $filters[$hook_name] = array(); |
|
167 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
168 | + $filters[$hook_name][$priority] = array(); |
|
169 | + foreach ($callbacks as $callback) { |
|
170 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | /** |
180 | 180 | * reset_times |
181 | 181 | */ |
182 | - public function reset_times(){ |
|
182 | + public function reset_times() { |
|
183 | 183 | $this->_times = array(); |
184 | 184 | } |
185 | 185 | |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | * start_timer |
190 | 190 | * @param null $timer_name |
191 | 191 | */ |
192 | - public function start_timer( $timer_name = NULL ){ |
|
193 | - $this->_start_times[$timer_name] = microtime( TRUE ); |
|
192 | + public function start_timer($timer_name = NULL) { |
|
193 | + $this->_start_times[$timer_name] = microtime(TRUE); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -199,15 +199,15 @@ discard block |
||
199 | 199 | * stop_timer |
200 | 200 | * @param string $timer_name |
201 | 201 | */ |
202 | - public function stop_timer( $timer_name = '' ){ |
|
202 | + public function stop_timer($timer_name = '') { |
|
203 | 203 | $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
204 | - if( isset( $this->_start_times[ $timer_name ] ) ){ |
|
205 | - $start_time = $this->_start_times[ $timer_name ]; |
|
206 | - unset( $this->_start_times[ $timer_name ] ); |
|
207 | - }else{ |
|
208 | - $start_time = array_pop( $this->_start_times ); |
|
204 | + if (isset($this->_start_times[$timer_name])) { |
|
205 | + $start_time = $this->_start_times[$timer_name]; |
|
206 | + unset($this->_start_times[$timer_name]); |
|
207 | + } else { |
|
208 | + $start_time = array_pop($this->_start_times); |
|
209 | 209 | } |
210 | - $this->_times[ $timer_name ] = number_format( microtime( true ) - $start_time, 8 ); |
|
210 | + $this->_times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
218 | 218 | * @return void |
219 | 219 | */ |
220 | - public function measure_memory( $label, $output_now = false ) { |
|
221 | - $memory_used = $this->convert( memory_get_peak_usage( true ) ); |
|
222 | - $this->_memory_usage_points[ $label ] = $memory_used; |
|
223 | - if( $output_now ) { |
|
220 | + public function measure_memory($label, $output_now = false) { |
|
221 | + $memory_used = $this->convert(memory_get_peak_usage(true)); |
|
222 | + $this->_memory_usage_points[$label] = $memory_used; |
|
223 | + if ($output_now) { |
|
224 | 224 | echo "\r\n<br>$label : $memory_used"; |
225 | 225 | } |
226 | 226 | } |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param int $size |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - public function convert( $size ) { |
|
234 | - $unit=array('b','kb','mb','gb','tb','pb'); |
|
235 | - return @round( $size / pow( 1024, $i = floor( log( $size, 1024 ) ) ), 2 ) . ' ' . $unit[ absint( $i ) ]; |
|
233 | + public function convert($size) { |
|
234 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
235 | + return @round($size / pow(1024, $i = floor(log($size, 1024))), 2).' '.$unit[absint($i)]; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | |
@@ -242,25 +242,25 @@ discard block |
||
242 | 242 | * @param bool $output_now |
243 | 243 | * @return string |
244 | 244 | */ |
245 | - public function show_times($output_now=true){ |
|
245 | + public function show_times($output_now = true) { |
|
246 | 246 | $output = ''; |
247 | - if ( ! empty( $this->_times )) { |
|
247 | + if ( ! empty($this->_times)) { |
|
248 | 248 | $total = 0; |
249 | 249 | $output .= '<h2 style="margin:1em .5em 0;">Times:</h2>'; |
250 | 250 | $output .= '<span style="color:#9999CC; font-size:.8em; margin:0 1.5em 0;">( in milliseconds )</span><br />'; |
251 | - foreach( $this->_times as $timer_name => $total_time ) { |
|
252 | - $output .= $this->format_time( $timer_name, $total_time ); |
|
251 | + foreach ($this->_times as $timer_name => $total_time) { |
|
252 | + $output .= $this->format_time($timer_name, $total_time); |
|
253 | 253 | $total += $total_time; |
254 | 254 | } |
255 | 255 | $output .= '<br />'; |
256 | 256 | $output .= '<h4 style="margin:1em .5em 0;">TOTAL TIME</h4>'; |
257 | - $output .= $this->format_time( '', $total ); |
|
257 | + $output .= $this->format_time('', $total); |
|
258 | 258 | $output .= '<br />'; |
259 | 259 | } |
260 | - if ( ! empty( $this->_memory_usage_points )) { |
|
261 | - $output .= '<h2 style="margin:1em .5em 0;">Memory</h2>' . implode( '<br />', $this->_memory_usage_points ); |
|
260 | + if ( ! empty($this->_memory_usage_points)) { |
|
261 | + $output .= '<h2 style="margin:1em .5em 0;">Memory</h2>'.implode('<br />', $this->_memory_usage_points); |
|
262 | 262 | } |
263 | - if( $output_now ){ |
|
263 | + if ($output_now) { |
|
264 | 264 | echo $output; |
265 | 265 | return ''; |
266 | 266 | } |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | * @param float $total_time |
275 | 275 | * @return string |
276 | 276 | */ |
277 | - public function format_time( $timer_name, $total_time ) { |
|
277 | + public function format_time($timer_name, $total_time) { |
|
278 | 278 | $total_time = $total_time * 1000; |
279 | - switch ( $total_time ) { |
|
279 | + switch ($total_time) { |
|
280 | 280 | case $total_time < 0.01 : |
281 | 281 | $color = '#8A549A'; |
282 | 282 | $bold = 'normal'; |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | . '; font-weight:' |
308 | 308 | . $bold |
309 | 309 | . '; font-size:1.2em;">' |
310 | - . str_pad( number_format( $total_time, 5 ), 11, '0', STR_PAD_LEFT ) |
|
310 | + . str_pad(number_format($total_time, 5), 11, '0', STR_PAD_LEFT) |
|
311 | 311 | . '</span> ' |
312 | 312 | . $timer_name |
313 | 313 | . '<br />'; |
@@ -321,25 +321,25 @@ discard block |
||
321 | 321 | * @return void |
322 | 322 | */ |
323 | 323 | public static function ee_plugin_activation_errors() { |
324 | - if ( WP_DEBUG ) { |
|
324 | + if (WP_DEBUG) { |
|
325 | 325 | $activation_errors = ob_get_contents(); |
326 | - if ( ! empty( $activation_errors ) ) { |
|
327 | - $activation_errors = date( 'Y-m-d H:i:s' ) . "\n" . $activation_errors; |
|
326 | + if ( ! empty($activation_errors)) { |
|
327 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
328 | 328 | } |
329 | - espresso_load_required( 'EEH_File', EE_HELPERS . 'EEH_File.helper.php' ); |
|
330 | - if ( class_exists( 'EEH_File' )) { |
|
329 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
330 | + if (class_exists('EEH_File')) { |
|
331 | 331 | try { |
332 | - EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' ); |
|
333 | - EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors ); |
|
334 | - } catch( EE_Error $e ){ |
|
335 | - EE_Error::add_error( sprintf( __( 'The Event Espresso activation errors file could not be setup because: %s', 'event_espresso' ), $e->getMessage() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
332 | + EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'); |
|
333 | + EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors); |
|
334 | + } catch (EE_Error $e) { |
|
335 | + EE_Error::add_error(sprintf(__('The Event Espresso activation errors file could not be setup because: %s', 'event_espresso'), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
336 | 336 | } |
337 | 337 | } else { |
338 | 338 | // old school attempt |
339 | - file_put_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors ); |
|
339 | + file_put_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors); |
|
340 | 340 | } |
341 | - $activation_errors = get_option( 'ee_plugin_activation_errors', '' ) . $activation_errors; |
|
342 | - update_option( 'ee_plugin_activation_errors', $activation_errors ); |
|
341 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
342 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
@@ -368,33 +368,33 @@ discard block |
||
368 | 368 | $applies_when = '', |
369 | 369 | $error_type = null |
370 | 370 | ) { |
371 | - $applies_when = ! empty( $applies_when ) ? $applies_when : espresso_version(); |
|
371 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
372 | 372 | $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
373 | 373 | // because we swapped the parameter order around for the last two params, |
374 | 374 | // let's verify that some third party isn't still passing an error type value for the third param |
375 | - if ( is_int( $applies_when ) ) { |
|
375 | + if (is_int($applies_when)) { |
|
376 | 376 | $error_type = $applies_when; |
377 | 377 | $applies_when = espresso_version(); |
378 | 378 | } |
379 | 379 | // if not displaying notices yet, then just leave |
380 | - if ( version_compare( espresso_version(), $applies_when, '<' ) ) { |
|
380 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | - do_action( 'AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
384 | - $version = $version === null ? '' : sprintf( __('(This message was added in version %s of Event Espresso)', 'event_espresso' ), $version ); |
|
385 | - $error_message = sprintf( esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s','event_espresso' ), $function, '<strong>', '</strong>', $message, $version ); |
|
383 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
384 | + $version = $version === null ? '' : sprintf(__('(This message was added in version %s of Event Espresso)', 'event_espresso'), $version); |
|
385 | + $error_message = sprintf(esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), $function, '<strong>', '</strong>', $message, $version); |
|
386 | 386 | |
387 | 387 | //don't trigger error if doing ajax, instead we'll add a transient EE_Error notice that in theory should show on the next request. |
388 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
389 | - $error_message .= ' ' . esc_html__( 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', 'event_espresso' ); |
|
388 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
389 | + $error_message .= ' '.esc_html__('This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', 'event_espresso'); |
|
390 | 390 | $error_message .= '<ul><li>'; |
391 | - $error_message .= implode( '</li><li>', EE_Registry::instance()->REQ->params() ); |
|
391 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
392 | 392 | $error_message .= '</ul>'; |
393 | - EE_Error::add_error( $error_message, 'debug::doing_it_wrong', $function, '42' ); |
|
393 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
394 | 394 | //now we set this on the transient so it shows up on the next request. |
395 | - EE_Error::get_notices( false, true ); |
|
395 | + EE_Error::get_notices(false, true); |
|
396 | 396 | } else { |
397 | - trigger_error( $error_message, $error_type ); |
|
397 | + trigger_error($error_message, $error_type); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
@@ -416,22 +416,22 @@ discard block |
||
416 | 416 | * @param string $debug_index |
417 | 417 | * @param string $debug_key |
418 | 418 | */ |
419 | - public static function log( $class='', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO' ) { |
|
420 | - if ( WP_DEBUG && false ) { |
|
421 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
422 | - $debug_data = get_option( $debug_key, array() ); |
|
419 | + public static function log($class = '', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO') { |
|
420 | + if (WP_DEBUG && false) { |
|
421 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
422 | + $debug_data = get_option($debug_key, array()); |
|
423 | 423 | $default_data = array( |
424 | - $class => $func . '() : ' . $line, |
|
424 | + $class => $func.'() : '.$line, |
|
425 | 425 | 'REQ' => $display_request ? $_REQUEST : '', |
426 | 426 | ); |
427 | 427 | // don't serialize objects |
428 | - $info = self::strip_objects( $info ); |
|
429 | - $index = ! empty( $debug_index ) ? $debug_index : 0; |
|
430 | - if ( ! isset( $debug_data[$index] ) ) { |
|
428 | + $info = self::strip_objects($info); |
|
429 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
430 | + if ( ! isset($debug_data[$index])) { |
|
431 | 431 | $debug_data[$index] = array(); |
432 | 432 | } |
433 | - $debug_data[$index][microtime()] = array_merge( $default_data, $info ); |
|
434 | - update_option( $debug_key, $debug_data ); |
|
433 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
434 | + update_option($debug_key, $debug_data); |
|
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
@@ -443,26 +443,26 @@ discard block |
||
443 | 443 | * @param array $info |
444 | 444 | * @return array |
445 | 445 | */ |
446 | - public static function strip_objects( $info = array() ) { |
|
447 | - foreach ( $info as $key => $value ) { |
|
448 | - if ( is_array( $value ) ) { |
|
449 | - $info[ $key ] = self::strip_objects( $value ); |
|
450 | - } else if ( is_object( $value ) ) { |
|
451 | - $object_class = get_class( $value ); |
|
452 | - $info[ $object_class ] = array(); |
|
453 | - $info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : spl_object_hash( $value ); |
|
454 | - if ( method_exists( $value, 'ID' ) ) { |
|
455 | - $info[ $object_class ][ 'ID' ] = $value->ID(); |
|
446 | + public static function strip_objects($info = array()) { |
|
447 | + foreach ($info as $key => $value) { |
|
448 | + if (is_array($value)) { |
|
449 | + $info[$key] = self::strip_objects($value); |
|
450 | + } else if (is_object($value)) { |
|
451 | + $object_class = get_class($value); |
|
452 | + $info[$object_class] = array(); |
|
453 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
454 | + if (method_exists($value, 'ID')) { |
|
455 | + $info[$object_class]['ID'] = $value->ID(); |
|
456 | 456 | } |
457 | - if ( method_exists( $value, 'status' ) ) { |
|
458 | - $info[ $object_class ][ 'status' ] = $value->status(); |
|
459 | - } else if ( method_exists( $value, 'status_ID' ) ) { |
|
460 | - $info[ $object_class ][ 'status' ] = $value->status_ID(); |
|
457 | + if (method_exists($value, 'status')) { |
|
458 | + $info[$object_class]['status'] = $value->status(); |
|
459 | + } else if (method_exists($value, 'status_ID')) { |
|
460 | + $info[$object_class]['status'] = $value->status_ID(); |
|
461 | 461 | } |
462 | - unset( $info[ $key ] ); |
|
462 | + unset($info[$key]); |
|
463 | 463 | } |
464 | 464 | } |
465 | - return (array)$info; |
|
465 | + return (array) $info; |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | |
@@ -475,23 +475,23 @@ discard block |
||
475 | 475 | * @param int $header |
476 | 476 | * @param bool $die |
477 | 477 | */ |
478 | - public static function printv( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false ) { |
|
478 | + public static function printv($var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { |
|
479 | 479 | $var_name = ! $var_name ? 'string' : $var_name; |
480 | 480 | $heading_tag = 'h'; |
481 | - $heading_tag .= is_int( $header ) ? $header : 5; |
|
482 | - $var_name = ucwords( str_replace( '$', '', $var_name ) ); |
|
483 | - $is_method = method_exists( $var_name, $var ); |
|
484 | - $var_name = ucwords( str_replace( '_', ' ', $var_name ) ); |
|
481 | + $heading_tag .= is_int($header) ? $header : 5; |
|
482 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
483 | + $is_method = method_exists($var_name, $var); |
|
484 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
485 | 485 | $margin = is_admin() ? ' 180px' : '0'; |
486 | - $result = '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0' . $margin . ';"><b>' . $var_name . '</b>'; |
|
486 | + $result = '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0'.$margin.';"><b>'.$var_name.'</b>'; |
|
487 | 487 | $result .= $is_method |
488 | - ? '<span style="color:#999">::</span><span style="color:#E76700">' . $var . '()</span><br />' |
|
489 | - : '<span style="color:#999"> : </span><span style="color:#E76700">' . $var . '</span><br />'; |
|
490 | - $result .= '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file; |
|
491 | - $result .= '<br />line no: ' . $line . '</span>'; |
|
492 | - $result .= '</' . $heading_tag . '>'; |
|
493 | - if ( $die ) { |
|
494 | - die( $result ); |
|
488 | + ? '<span style="color:#999">::</span><span style="color:#E76700">'.$var.'()</span><br />' |
|
489 | + : '<span style="color:#999"> : </span><span style="color:#E76700">'.$var.'</span><br />'; |
|
490 | + $result .= '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'.$file; |
|
491 | + $result .= '<br />line no: '.$line.'</span>'; |
|
492 | + $result .= '</'.$heading_tag.'>'; |
|
493 | + if ($die) { |
|
494 | + die($result); |
|
495 | 495 | } else { |
496 | 496 | echo $result; |
497 | 497 | } |
@@ -506,36 +506,36 @@ discard block |
||
506 | 506 | * @param int $header |
507 | 507 | * @param bool $die |
508 | 508 | */ |
509 | - public static function printr( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false ) { |
|
509 | + public static function printr($var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { |
|
510 | 510 | // return; |
511 | - $file = str_replace( rtrim( ABSPATH, '\\/' ), '', $file ); |
|
511 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
512 | 512 | //$print_r = false; |
513 | - if ( is_string( $var ) ) { |
|
514 | - EEH_Debug_Tools::printv( $var, $var_name, $file, $line, $header, $die ); |
|
513 | + if (is_string($var)) { |
|
514 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $header, $die); |
|
515 | 515 | return; |
516 | - } else if ( is_object( $var ) ) { |
|
516 | + } else if (is_object($var)) { |
|
517 | 517 | $var_name = ! $var_name ? 'object' : $var_name; |
518 | 518 | //$print_r = true; |
519 | - } else if ( is_array( $var ) ) { |
|
519 | + } else if (is_array($var)) { |
|
520 | 520 | $var_name = ! $var_name ? 'array' : $var_name; |
521 | 521 | //$print_r = true; |
522 | - } else if ( is_numeric( $var ) ) { |
|
522 | + } else if (is_numeric($var)) { |
|
523 | 523 | $var_name = ! $var_name ? 'numeric' : $var_name; |
524 | - } else if ( is_null( $var ) ) { |
|
524 | + } else if (is_null($var)) { |
|
525 | 525 | $var_name = ! $var_name ? 'null' : $var_name; |
526 | 526 | } |
527 | 527 | $heading_tag = 'h'; |
528 | - $heading_tag .= is_int( $header ) ? $header : 5; |
|
529 | - $var_name = ucwords( str_replace( array( '$', '_' ), array( '', ' ' ), $var_name ) ); |
|
528 | + $heading_tag .= is_int($header) ? $header : 5; |
|
529 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
530 | 530 | $margin = is_admin() ? ' 180px' : '0'; |
531 | - $result = '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0'.$margin.';"><b>' . $var_name . '</b>'; |
|
531 | + $result = '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0'.$margin.';"><b>'.$var_name.'</b>'; |
|
532 | 532 | $result .= '<span style="color:#999;"> : </span><span style="color:#E76700;">'; |
533 | 533 | $result .= '<pre style="color:#999; padding:1em; background: #fff">'; |
534 | - $result .= var_export( $var, true ); |
|
535 | - $result .= '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;'.$margin.'">' . $file; |
|
536 | - $result .= '<br />line no: ' . $line . '</span></' . $heading_tag . '>'; |
|
537 | - if ( $die ) { |
|
538 | - die( $result ); |
|
534 | + $result .= var_export($var, true); |
|
535 | + $result .= '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;'.$margin.'">'.$file; |
|
536 | + $result .= '<br />line no: '.$line.'</span></'.$heading_tag.'>'; |
|
537 | + if ($die) { |
|
538 | + die($result); |
|
539 | 539 | } else { |
540 | 540 | echo $result; |
541 | 541 | } |
@@ -552,8 +552,8 @@ discard block |
||
552 | 552 | * borrowed from Kint Debugger |
553 | 553 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
554 | 554 | */ |
555 | -if ( class_exists('Kint') && ! function_exists( 'dump_wp_query' ) ) { |
|
556 | - function dump_wp_query(){ |
|
555 | +if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
|
556 | + function dump_wp_query() { |
|
557 | 557 | global $wp_query; |
558 | 558 | d($wp_query); |
559 | 559 | } |
@@ -563,8 +563,8 @@ discard block |
||
563 | 563 | * borrowed from Kint Debugger |
564 | 564 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
565 | 565 | */ |
566 | -if ( class_exists('Kint') && ! function_exists( 'dump_wp' ) ) { |
|
567 | - function dump_wp(){ |
|
566 | +if (class_exists('Kint') && ! function_exists('dump_wp')) { |
|
567 | + function dump_wp() { |
|
568 | 568 | global $wp; |
569 | 569 | d($wp); |
570 | 570 | } |
@@ -574,8 +574,8 @@ discard block |
||
574 | 574 | * borrowed from Kint Debugger |
575 | 575 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
576 | 576 | */ |
577 | -if ( class_exists('Kint') && ! function_exists( 'dump_post' ) ) { |
|
578 | - function dump_post(){ |
|
577 | +if (class_exists('Kint') && ! function_exists('dump_post')) { |
|
578 | + function dump_post() { |
|
579 | 579 | global $post; |
580 | 580 | d($post); |
581 | 581 | } |