@@ -155,12 +155,12 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public static function reset( $hard_reset = false, $reinstantiate = true ) { |
| 157 | 157 | if ( self::$_instance instanceof EE_Config ) { |
| 158 | - if ($hard_reset) { |
|
| 159 | - self::$_instance->_addon_option_names = array(); |
|
| 160 | - self::$_instance->_initialize_config(); |
|
| 161 | - self::$_instance->update_espresso_config(); |
|
| 162 | - } |
|
| 163 | - self::$_instance->update_addon_option_names(); |
|
| 158 | + if ($hard_reset) { |
|
| 159 | + self::$_instance->_addon_option_names = array(); |
|
| 160 | + self::$_instance->_initialize_config(); |
|
| 161 | + self::$_instance->update_espresso_config(); |
|
| 162 | + } |
|
| 163 | + self::$_instance->update_addon_option_names(); |
|
| 164 | 164 | } |
| 165 | 165 | self::$_instance = null; |
| 166 | 166 | //we don't need to reset the static properties imo because those should |
@@ -2211,7 +2211,7 @@ discard block |
||
| 2211 | 2211 | $table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
| 2212 | 2212 | // get country code from organization settings or use default |
| 2213 | 2213 | $ORG_CNT = isset( EE_Registry::instance()->CFG->organization ) |
| 2214 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2214 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2215 | 2215 | ? EE_Registry::instance()->CFG->organization->CNT_ISO |
| 2216 | 2216 | : ''; |
| 2217 | 2217 | // but override if requested |
@@ -2521,12 +2521,12 @@ discard block |
||
| 2521 | 2521 | public $help_tour_activation; |
| 2522 | 2522 | |
| 2523 | 2523 | /** |
| 2524 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2525 | - * but is incompatible with some server configuration errors |
|
| 2526 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2527 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2528 | - * |
|
| 2529 | - * @var boolean $encode_session_data |
|
| 2524 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2525 | + * but is incompatible with some server configuration errors |
|
| 2526 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2527 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2528 | + * |
|
| 2529 | + * @var boolean $encode_session_data |
|
| 2530 | 2530 | */ |
| 2531 | 2531 | private $encode_session_data = false; |
| 2532 | 2532 | |
@@ -2591,21 +2591,21 @@ discard block |
||
| 2591 | 2591 | |
| 2592 | 2592 | |
| 2593 | 2593 | |
| 2594 | - /** |
|
| 2595 | - * @return boolean |
|
| 2596 | - */ |
|
| 2597 | - public function encode_session_data() { |
|
| 2598 | - return filter_var( $this->encode_session_data, FILTER_VALIDATE_BOOLEAN ); |
|
| 2599 | - } |
|
| 2594 | + /** |
|
| 2595 | + * @return boolean |
|
| 2596 | + */ |
|
| 2597 | + public function encode_session_data() { |
|
| 2598 | + return filter_var( $this->encode_session_data, FILTER_VALIDATE_BOOLEAN ); |
|
| 2599 | + } |
|
| 2600 | 2600 | |
| 2601 | 2601 | |
| 2602 | 2602 | |
| 2603 | - /** |
|
| 2604 | - * @param boolean $encode_session_data |
|
| 2605 | - */ |
|
| 2606 | - public function set_encode_session_data( $encode_session_data ) { |
|
| 2607 | - $this->encode_session_data = filter_var( $encode_session_data, FILTER_VALIDATE_BOOLEAN ); |
|
| 2608 | - } |
|
| 2603 | + /** |
|
| 2604 | + * @param boolean $encode_session_data |
|
| 2605 | + */ |
|
| 2606 | + public function set_encode_session_data( $encode_session_data ) { |
|
| 2607 | + $this->encode_session_data = filter_var( $encode_session_data, FILTER_VALIDATE_BOOLEAN ); |
|
| 2608 | + } |
|
| 2609 | 2609 | |
| 2610 | 2610 | |
| 2611 | 2611 | |
@@ -2649,13 +2649,13 @@ discard block |
||
| 2649 | 2649 | public $current_espresso_theme; |
| 2650 | 2650 | |
| 2651 | 2651 | /** |
| 2652 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2653 | - */ |
|
| 2652 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2653 | + */ |
|
| 2654 | 2654 | public $EED_Ticket_Selector; |
| 2655 | 2655 | |
| 2656 | 2656 | /** |
| 2657 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2658 | - */ |
|
| 2657 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2658 | + */ |
|
| 2659 | 2659 | public $EED_Event_Single; |
| 2660 | 2660 | |
| 2661 | 2661 | /** |
@@ -2981,8 +2981,8 @@ discard block |
||
| 2981 | 2981 | */ |
| 2982 | 2982 | public function max_input_vars_limit_check( $input_count = 0 ) { |
| 2983 | 2983 | if ( ! empty( $this->php->max_input_vars ) |
| 2984 | - && ( $input_count >= $this->php->max_input_vars ) |
|
| 2985 | - && ( PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9 ) |
|
| 2984 | + && ( $input_count >= $this->php->max_input_vars ) |
|
| 2985 | + && ( PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9 ) |
|
| 2986 | 2986 | ) { |
| 2987 | 2987 | return sprintf( |
| 2988 | 2988 | __( |
@@ -3026,22 +3026,22 @@ discard block |
||
| 3026 | 3026 | class EE_Tax_Config extends EE_Config_Base |
| 3027 | 3027 | { |
| 3028 | 3028 | |
| 3029 | - /* |
|
| 3029 | + /* |
|
| 3030 | 3030 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3031 | 3031 | * |
| 3032 | 3032 | * @var boolean $prices_displayed_including_taxes |
| 3033 | 3033 | */ |
| 3034 | - public $prices_displayed_including_taxes; |
|
| 3034 | + public $prices_displayed_including_taxes; |
|
| 3035 | 3035 | |
| 3036 | 3036 | |
| 3037 | 3037 | |
| 3038 | - /** |
|
| 3039 | - * class constructor |
|
| 3040 | - */ |
|
| 3041 | - public function __construct() |
|
| 3042 | - { |
|
| 3043 | - $this->prices_displayed_including_taxes = true; |
|
| 3044 | - } |
|
| 3038 | + /** |
|
| 3039 | + * class constructor |
|
| 3040 | + */ |
|
| 3041 | + public function __construct() |
|
| 3042 | + { |
|
| 3043 | + $this->prices_displayed_including_taxes = true; |
|
| 3044 | + } |
|
| 3045 | 3045 | } |
| 3046 | 3046 | |
| 3047 | 3047 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public static function instance() { |
| 135 | 135 | // check if class object is instantiated, and instantiated properly |
| 136 | - if ( ! self::$_instance instanceof EE_Config ) { |
|
| 136 | + if ( ! self::$_instance instanceof EE_Config) { |
|
| 137 | 137 | self::$_instance = new self(); |
| 138 | 138 | } |
| 139 | 139 | return self::$_instance; |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | * site was put into maintenance mode) |
| 154 | 154 | * @return EE_Config |
| 155 | 155 | */ |
| 156 | - public static function reset( $hard_reset = false, $reinstantiate = true ) { |
|
| 157 | - if ( self::$_instance instanceof EE_Config ) { |
|
| 156 | + public static function reset($hard_reset = false, $reinstantiate = true) { |
|
| 157 | + if (self::$_instance instanceof EE_Config) { |
|
| 158 | 158 | if ($hard_reset) { |
| 159 | 159 | self::$_instance->_addon_option_names = array(); |
| 160 | 160 | self::$_instance->_initialize_config(); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | //we don't need to reset the static properties imo because those should |
| 167 | 167 | //only change when a module is added or removed. Currently we don't |
| 168 | 168 | //support removing a module during a request when it previously existed |
| 169 | - if ( $reinstantiate ) { |
|
| 169 | + if ($reinstantiate) { |
|
| 170 | 170 | return self::instance(); |
| 171 | 171 | } else { |
| 172 | 172 | return null; |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @access private |
| 182 | 182 | */ |
| 183 | 183 | private function __construct() { |
| 184 | - do_action( 'AHEE__EE_Config__construct__begin', $this ); |
|
| 185 | - EE_Config::$_logging_enabled = apply_filters( 'FHEE__EE_Config___construct__logging_enabled', false ); |
|
| 184 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 185 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 186 | 186 | // setup empty config classes |
| 187 | 187 | $this->_initialize_config(); |
| 188 | 188 | // load existing EE site settings |
@@ -192,17 +192,17 @@ discard block |
||
| 192 | 192 | // register shortcodes and modules |
| 193 | 193 | add_action( |
| 194 | 194 | 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
| 195 | - array( $this, 'register_shortcodes_and_modules' ), |
|
| 195 | + array($this, 'register_shortcodes_and_modules'), |
|
| 196 | 196 | 999 |
| 197 | 197 | ); |
| 198 | 198 | // initialize shortcodes and modules |
| 199 | - add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'initialize_shortcodes_and_modules' ) ); |
|
| 199 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 200 | 200 | // register widgets |
| 201 | - add_action( 'widgets_init', array( $this, 'widgets_init' ), 10 ); |
|
| 201 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 202 | 202 | // shutdown |
| 203 | - add_action( 'shutdown', array( $this, 'shutdown' ), 10 ); |
|
| 203 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 204 | 204 | // construct__end hook |
| 205 | - do_action( 'AHEE__EE_Config__construct__end', $this ); |
|
| 205 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 206 | 206 | // hardcoded hack |
| 207 | 207 | $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
| 208 | 208 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @return string current theme set. |
| 225 | 225 | */ |
| 226 | 226 | public static function get_current_theme() { |
| 227 | - return isset( self::$_instance->template_settings->current_espresso_theme ) |
|
| 227 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 228 | 228 | ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | private function _initialize_config() { |
| 240 | 240 | EE_Config::trim_log(); |
| 241 | 241 | //set defaults |
| 242 | - $this->_addon_option_names = get_option( EE_Config::ADDON_OPTION_NAMES, array() ); |
|
| 242 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 243 | 243 | $this->addons = new stdClass(); |
| 244 | 244 | // set _module_route_map |
| 245 | 245 | EE_Config::$_module_route_map = array(); |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | private function _load_core_config() { |
| 261 | 261 | // load_core_config__start hook |
| 262 | - do_action( 'AHEE__EE_Config___load_core_config__start', $this ); |
|
| 262 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 263 | 263 | $espresso_config = $this->get_espresso_config(); |
| 264 | - foreach ( $espresso_config as $config => $settings ) { |
|
| 264 | + foreach ($espresso_config as $config => $settings) { |
|
| 265 | 265 | // load_core_config__start hook |
| 266 | 266 | $settings = apply_filters( |
| 267 | 267 | 'FHEE__EE_Config___load_core_config__config_settings', |
@@ -269,22 +269,22 @@ discard block |
||
| 269 | 269 | $config, |
| 270 | 270 | $this |
| 271 | 271 | ); |
| 272 | - if ( is_object( $settings ) && property_exists( $this, $config ) ) { |
|
| 273 | - $this->{$config} = apply_filters( 'FHEE__EE_Config___load_core_config__' . $config, $settings ); |
|
| 272 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 273 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings); |
|
| 274 | 274 | //call configs populate method to ensure any defaults are set for empty values. |
| 275 | - if ( method_exists( $settings, 'populate' ) ) { |
|
| 275 | + if (method_exists($settings, 'populate')) { |
|
| 276 | 276 | $this->{$config}->populate(); |
| 277 | 277 | } |
| 278 | - if ( method_exists( $settings, 'do_hooks' ) ) { |
|
| 278 | + if (method_exists($settings, 'do_hooks')) { |
|
| 279 | 279 | $this->{$config}->do_hooks(); |
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | - if ( apply_filters( 'FHEE__EE_Config___load_core_config__update_espresso_config', false ) ) { |
|
| 283 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 284 | 284 | $this->update_espresso_config(); |
| 285 | 285 | } |
| 286 | 286 | // load_core_config__end hook |
| 287 | - do_action( 'AHEE__EE_Config___load_core_config__end', $this ); |
|
| 287 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | |
@@ -299,23 +299,23 @@ discard block |
||
| 299 | 299 | $this->core = $this->core instanceof EE_Core_Config |
| 300 | 300 | ? $this->core |
| 301 | 301 | : new EE_Core_Config(); |
| 302 | - $this->core = apply_filters( 'FHEE__EE_Config___initialize_config__core', $this->core ); |
|
| 302 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 303 | 303 | $this->organization = $this->organization instanceof EE_Organization_Config |
| 304 | 304 | ? $this->organization |
| 305 | 305 | : new EE_Organization_Config(); |
| 306 | - $this->organization = apply_filters( 'FHEE__EE_Config___initialize_config__organization', $this->organization ); |
|
| 306 | + $this->organization = apply_filters('FHEE__EE_Config___initialize_config__organization', $this->organization); |
|
| 307 | 307 | $this->currency = $this->currency instanceof EE_Currency_Config |
| 308 | 308 | ? $this->currency |
| 309 | 309 | : new EE_Currency_Config(); |
| 310 | - $this->currency = apply_filters( 'FHEE__EE_Config___initialize_config__currency', $this->currency ); |
|
| 310 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 311 | 311 | $this->registration = $this->registration instanceof EE_Registration_Config |
| 312 | 312 | ? $this->registration |
| 313 | 313 | : new EE_Registration_Config(); |
| 314 | - $this->registration = apply_filters( 'FHEE__EE_Config___initialize_config__registration', $this->registration ); |
|
| 314 | + $this->registration = apply_filters('FHEE__EE_Config___initialize_config__registration', $this->registration); |
|
| 315 | 315 | $this->admin = $this->admin instanceof EE_Admin_Config |
| 316 | 316 | ? $this->admin |
| 317 | 317 | : new EE_Admin_Config(); |
| 318 | - $this->admin = apply_filters( 'FHEE__EE_Config___initialize_config__admin', $this->admin ); |
|
| 318 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 319 | 319 | $this->template_settings = $this->template_settings instanceof EE_Template_Config |
| 320 | 320 | ? $this->template_settings |
| 321 | 321 | : new EE_Template_Config(); |
@@ -326,19 +326,19 @@ discard block |
||
| 326 | 326 | $this->map_settings = $this->map_settings instanceof EE_Map_Config |
| 327 | 327 | ? $this->map_settings |
| 328 | 328 | : new EE_Map_Config(); |
| 329 | - $this->map_settings = apply_filters( 'FHEE__EE_Config___initialize_config__map_settings', $this->map_settings ); |
|
| 329 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', $this->map_settings); |
|
| 330 | 330 | $this->environment = $this->environment instanceof EE_Environment_Config |
| 331 | 331 | ? $this->environment |
| 332 | 332 | : new EE_Environment_Config(); |
| 333 | - $this->environment = apply_filters( 'FHEE__EE_Config___initialize_config__environment', $this->environment ); |
|
| 333 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', $this->environment); |
|
| 334 | 334 | $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
| 335 | 335 | ? $this->tax_settings |
| 336 | 336 | : new EE_Tax_Config(); |
| 337 | - $this->tax_settings = apply_filters( 'FHEE__EE_Config___initialize_config__tax_settings', $this->tax_settings ); |
|
| 337 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', $this->tax_settings); |
|
| 338 | 338 | $this->gateway = $this->gateway instanceof EE_Gateway_Config |
| 339 | 339 | ? $this->gateway |
| 340 | 340 | : new EE_Gateway_Config(); |
| 341 | - $this->gateway = apply_filters( 'FHEE__EE_Config___initialize_config__gateway', $this->gateway ); |
|
| 341 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | // grab espresso configuration |
| 354 | 354 | return apply_filters( |
| 355 | 355 | 'FHEE__EE_Config__get_espresso_config__CFG', |
| 356 | - get_option( EE_Config::OPTION_NAME, array() ) |
|
| 356 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 357 | 357 | ); |
| 358 | 358 | } |
| 359 | 359 | |
@@ -367,12 +367,12 @@ discard block |
||
| 367 | 367 | * @param $old_value |
| 368 | 368 | * @param $value |
| 369 | 369 | */ |
| 370 | - public function double_check_config_comparison( $option = '', $old_value, $value ) { |
|
| 370 | + public function double_check_config_comparison($option = '', $old_value, $value) { |
|
| 371 | 371 | // make sure we're checking the ee config |
| 372 | - if ( $option === EE_Config::OPTION_NAME ) { |
|
| 372 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 373 | 373 | // run a loose comparison of the old value against the new value for type and properties, |
| 374 | 374 | // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
| 375 | - if ( $value != $old_value ) { |
|
| 375 | + if ($value != $old_value) { |
|
| 376 | 376 | // if they are NOT the same, then remove the hook, |
| 377 | 377 | // which means the subsequent update results will be based solely on the update query results |
| 378 | 378 | // the reason we do this is because, as stated above, |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | // the string it sees in the db looks the same as the new one it has been passed!!! |
| 388 | 388 | // This results in the query returning an "affected rows" value of ZERO, |
| 389 | 389 | // which gets returned immediately by WP update_option and looks like an error. |
| 390 | - remove_action( 'update_option', array( $this, 'check_config_updated' ) ); |
|
| 390 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
@@ -401,11 +401,11 @@ discard block |
||
| 401 | 401 | */ |
| 402 | 402 | protected function _reset_espresso_addon_config() { |
| 403 | 403 | $this->_addon_option_names = array(); |
| 404 | - foreach ( $this->addons as $addon_name => $addon_config_obj ) { |
|
| 405 | - $addon_config_obj = maybe_unserialize( $addon_config_obj ); |
|
| 406 | - $config_class = get_class( $addon_config_obj ); |
|
| 407 | - if ( $addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class ) { |
|
| 408 | - $this->update_config( 'addons', $addon_name, $addon_config_obj, false ); |
|
| 404 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 405 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 406 | + $config_class = get_class($addon_config_obj); |
|
| 407 | + if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
| 408 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 409 | 409 | } |
| 410 | 410 | $this->addons->{$addon_name} = null; |
| 411 | 411 | } |
@@ -421,22 +421,22 @@ discard block |
||
| 421 | 421 | * @param bool $add_error |
| 422 | 422 | * @return bool |
| 423 | 423 | */ |
| 424 | - public function update_espresso_config( $add_success = false, $add_error = true ) { |
|
| 424 | + public function update_espresso_config($add_success = false, $add_error = true) { |
|
| 425 | 425 | // don't allow config updates during WP heartbeats |
| 426 | - if ( \EE_Registry::instance()->REQ->get( 'action', '' ) === 'heartbeat' ) { |
|
| 426 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 427 | 427 | return false; |
| 428 | 428 | } |
| 429 | 429 | // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
| 430 | 430 | //$clone = clone( self::$_instance ); |
| 431 | 431 | //self::$_instance = NULL; |
| 432 | - do_action( 'AHEE__EE_Config__update_espresso_config__begin', $this ); |
|
| 432 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 433 | 433 | $this->_reset_espresso_addon_config(); |
| 434 | 434 | // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
| 435 | 435 | // but BEFORE the actual update occurs |
| 436 | - add_action( 'update_option', array( $this, 'double_check_config_comparison' ), 1, 3 ); |
|
| 436 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 437 | 437 | // now update "ee_config" |
| 438 | - $saved = update_option( EE_Config::OPTION_NAME, $this ); |
|
| 439 | - EE_Config::log( EE_Config::OPTION_NAME ); |
|
| 438 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 439 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 440 | 440 | // if not saved... check if the hook we just added still exists; |
| 441 | 441 | // if it does, it means one of two things: |
| 442 | 442 | // that update_option bailed at the ( $value === $old_value ) conditional, |
@@ -447,17 +447,17 @@ discard block |
||
| 447 | 447 | // but just means no update occurred, so don't display an error to the user. |
| 448 | 448 | // BUT... if update_option returns FALSE, AND the hook is missing, |
| 449 | 449 | // then it means that something truly went wrong |
| 450 | - $saved = ! $saved ? has_action( 'update_option', array( $this, 'double_check_config_comparison' ) ) : $saved; |
|
| 450 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 451 | 451 | // remove our action since we don't want it in the system anymore |
| 452 | - remove_action( 'update_option', array( $this, 'double_check_config_comparison' ), 1 ); |
|
| 453 | - do_action( 'AHEE__EE_Config__update_espresso_config__end', $this, $saved ); |
|
| 452 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 453 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 454 | 454 | //self::$_instance = $clone; |
| 455 | 455 | //unset( $clone ); |
| 456 | 456 | // if config remains the same or was updated successfully |
| 457 | - if ( $saved ) { |
|
| 458 | - if ( $add_success ) { |
|
| 457 | + if ($saved) { |
|
| 458 | + if ($add_success) { |
|
| 459 | 459 | EE_Error::add_success( |
| 460 | - __( 'The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso' ), |
|
| 460 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 461 | 461 | __FILE__, |
| 462 | 462 | __FUNCTION__, |
| 463 | 463 | __LINE__ |
@@ -465,9 +465,9 @@ discard block |
||
| 465 | 465 | } |
| 466 | 466 | return true; |
| 467 | 467 | } else { |
| 468 | - if ( $add_error ) { |
|
| 468 | + if ($add_error) { |
|
| 469 | 469 | EE_Error::add_error( |
| 470 | - __( 'The Event Espresso Configuration Settings were not updated.', 'event_espresso' ), |
|
| 470 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 471 | 471 | __FILE__, |
| 472 | 472 | __FUNCTION__, |
| 473 | 473 | __LINE__ |
@@ -496,16 +496,16 @@ discard block |
||
| 496 | 496 | $name = '', |
| 497 | 497 | $config_class = '', |
| 498 | 498 | $config_obj = null, |
| 499 | - $tests_to_run = array( 1, 2, 3, 4, 5, 6, 7, 8 ), |
|
| 499 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 500 | 500 | $display_errors = true |
| 501 | 501 | ) { |
| 502 | 502 | try { |
| 503 | - foreach ( $tests_to_run as $test ) { |
|
| 504 | - switch ( $test ) { |
|
| 503 | + foreach ($tests_to_run as $test) { |
|
| 504 | + switch ($test) { |
|
| 505 | 505 | // TEST #1 : check that section was set |
| 506 | 506 | case 1 : |
| 507 | - if ( empty( $section ) ) { |
|
| 508 | - if ( $display_errors ) { |
|
| 507 | + if (empty($section)) { |
|
| 508 | + if ($display_errors) { |
|
| 509 | 509 | throw new EE_Error( |
| 510 | 510 | sprintf( |
| 511 | 511 | __( |
@@ -521,11 +521,11 @@ discard block |
||
| 521 | 521 | break; |
| 522 | 522 | // TEST #2 : check that settings section exists |
| 523 | 523 | case 2 : |
| 524 | - if ( ! isset( $this->{$section} ) ) { |
|
| 525 | - if ( $display_errors ) { |
|
| 524 | + if ( ! isset($this->{$section} )) { |
|
| 525 | + if ($display_errors) { |
|
| 526 | 526 | throw new EE_Error( |
| 527 | 527 | sprintf( |
| 528 | - __( 'The "%s" configuration section does not exist.', 'event_espresso' ), |
|
| 528 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 529 | 529 | $section |
| 530 | 530 | ) |
| 531 | 531 | ); |
@@ -536,9 +536,9 @@ discard block |
||
| 536 | 536 | // TEST #3 : check that section is the proper format |
| 537 | 537 | case 3 : |
| 538 | 538 | if ( |
| 539 | - ! ( $this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass ) |
|
| 539 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 540 | 540 | ) { |
| 541 | - if ( $display_errors ) { |
|
| 541 | + if ($display_errors) { |
|
| 542 | 542 | throw new EE_Error( |
| 543 | 543 | sprintf( |
| 544 | 544 | __( |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | break; |
| 555 | 555 | // TEST #4 : check that config section name has been set |
| 556 | 556 | case 4 : |
| 557 | - if ( empty( $name ) ) { |
|
| 558 | - if ( $display_errors ) { |
|
| 557 | + if (empty($name)) { |
|
| 558 | + if ($display_errors) { |
|
| 559 | 559 | throw new EE_Error( |
| 560 | 560 | __( |
| 561 | 561 | 'No name has been provided for the specific configuration section.', |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | break; |
| 569 | 569 | // TEST #5 : check that a config class name has been set |
| 570 | 570 | case 5 : |
| 571 | - if ( empty( $config_class ) ) { |
|
| 572 | - if ( $display_errors ) { |
|
| 571 | + if (empty($config_class)) { |
|
| 572 | + if ($display_errors) { |
|
| 573 | 573 | throw new EE_Error( |
| 574 | 574 | __( |
| 575 | 575 | 'No class name has been provided for the specific configuration section.', |
@@ -582,8 +582,8 @@ discard block |
||
| 582 | 582 | break; |
| 583 | 583 | // TEST #6 : verify config class is accessible |
| 584 | 584 | case 6 : |
| 585 | - if ( ! class_exists( $config_class ) ) { |
|
| 586 | - if ( $display_errors ) { |
|
| 585 | + if ( ! class_exists($config_class)) { |
|
| 586 | + if ($display_errors) { |
|
| 587 | 587 | throw new EE_Error( |
| 588 | 588 | sprintf( |
| 589 | 589 | __( |
@@ -599,11 +599,11 @@ discard block |
||
| 599 | 599 | break; |
| 600 | 600 | // TEST #7 : check that config has even been set |
| 601 | 601 | case 7 : |
| 602 | - if ( ! isset( $this->{$section}->{$name} ) ) { |
|
| 603 | - if ( $display_errors ) { |
|
| 602 | + if ( ! isset($this->{$section}->{$name} )) { |
|
| 603 | + if ($display_errors) { |
|
| 604 | 604 | throw new EE_Error( |
| 605 | 605 | sprintf( |
| 606 | - __( 'No configuration has been set for "%1$s->%2$s".', 'event_espresso' ), |
|
| 606 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 607 | 607 | $section, |
| 608 | 608 | $name |
| 609 | 609 | ) |
@@ -612,13 +612,13 @@ discard block |
||
| 612 | 612 | return false; |
| 613 | 613 | } else { |
| 614 | 614 | // and make sure it's not serialized |
| 615 | - $this->{$section}->{$name} = maybe_unserialize( $this->{$section}->{$name} ); |
|
| 615 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name} ); |
|
| 616 | 616 | } |
| 617 | 617 | break; |
| 618 | 618 | // TEST #8 : check that config is the requested type |
| 619 | 619 | case 8 : |
| 620 | - if ( ! $this->{$section}->{$name} instanceof $config_class ) { |
|
| 621 | - if ( $display_errors ) { |
|
| 620 | + if ( ! $this->{$section}->{$name} instanceof $config_class) { |
|
| 621 | + if ($display_errors) { |
|
| 622 | 622 | throw new EE_Error( |
| 623 | 623 | sprintf( |
| 624 | 624 | __( |
@@ -636,12 +636,12 @@ discard block |
||
| 636 | 636 | break; |
| 637 | 637 | // TEST #9 : verify config object |
| 638 | 638 | case 9 : |
| 639 | - if ( ! $config_obj instanceof EE_Config_Base ) { |
|
| 640 | - if ( $display_errors ) { |
|
| 639 | + if ( ! $config_obj instanceof EE_Config_Base) { |
|
| 640 | + if ($display_errors) { |
|
| 641 | 641 | throw new EE_Error( |
| 642 | 642 | sprintf( |
| 643 | - __( 'The "%s" class is not an instance of EE_Config_Base.', 'event_espresso' ), |
|
| 644 | - print_r( $config_obj, true ) |
|
| 643 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 644 | + print_r($config_obj, true) |
|
| 645 | 645 | ) |
| 646 | 646 | ); |
| 647 | 647 | } |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | break; |
| 651 | 651 | } |
| 652 | 652 | } |
| 653 | - } catch ( EE_Error $e ) { |
|
| 653 | + } catch (EE_Error $e) { |
|
| 654 | 654 | $e->get_error(); |
| 655 | 655 | } |
| 656 | 656 | // you have successfully run the gauntlet |
@@ -667,8 +667,8 @@ discard block |
||
| 667 | 667 | * @param string $name |
| 668 | 668 | * @return string |
| 669 | 669 | */ |
| 670 | - private function _generate_config_option_name( $section = '', $name = '' ) { |
|
| 671 | - return 'ee_config-' . strtolower( $section . '-' . str_replace( array( 'EE_', 'EED_' ), '', $name ) ); |
|
| 670 | + private function _generate_config_option_name($section = '', $name = '') { |
|
| 671 | + return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | |
@@ -682,10 +682,10 @@ discard block |
||
| 682 | 682 | * @param string $name |
| 683 | 683 | * @return string |
| 684 | 684 | */ |
| 685 | - private function _set_config_class( $config_class = '', $name = '' ) { |
|
| 686 | - return ! empty( $config_class ) |
|
| 685 | + private function _set_config_class($config_class = '', $name = '') { |
|
| 686 | + return ! empty($config_class) |
|
| 687 | 687 | ? $config_class |
| 688 | - : str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $name ) ) ) . '_Config'; |
|
| 688 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config'; |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | |
@@ -700,36 +700,36 @@ discard block |
||
| 700 | 700 | * @param EE_Config_Base $config_obj |
| 701 | 701 | * @return EE_Config_Base |
| 702 | 702 | */ |
| 703 | - public function set_config( $section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null ) { |
|
| 703 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) { |
|
| 704 | 704 | // ensure config class is set to something |
| 705 | - $config_class = $this->_set_config_class( $config_class, $name ); |
|
| 705 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 706 | 706 | // run tests 1-4, 6, and 7 to verify all config params are set and valid |
| 707 | - if ( ! $this->_verify_config_params( $section, $name, $config_class, null, array( 1, 2, 3, 4, 5, 6 ) ) ) { |
|
| 707 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 708 | 708 | return null; |
| 709 | 709 | } |
| 710 | - $config_option_name = $this->_generate_config_option_name( $section, $name ); |
|
| 710 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 711 | 711 | // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
| 712 | - if ( ! isset( $this->_addon_option_names[ $config_option_name ] ) ) { |
|
| 713 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 712 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 713 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 714 | 714 | $this->update_addon_option_names(); |
| 715 | 715 | } |
| 716 | 716 | // verify the incoming config object but suppress errors |
| 717 | - if ( ! $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ), false ) ) { |
|
| 717 | + if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 718 | 718 | $config_obj = new $config_class(); |
| 719 | 719 | } |
| 720 | - if ( get_option( $config_option_name ) ) { |
|
| 721 | - EE_Config::log( $config_option_name ); |
|
| 722 | - update_option( $config_option_name, $config_obj ); |
|
| 720 | + if (get_option($config_option_name)) { |
|
| 721 | + EE_Config::log($config_option_name); |
|
| 722 | + update_option($config_option_name, $config_obj); |
|
| 723 | 723 | $this->{$section}->{$name} = $config_obj; |
| 724 | 724 | return $this->{$section}->{$name}; |
| 725 | 725 | } else { |
| 726 | 726 | // create a wp-option for this config |
| 727 | - if ( add_option( $config_option_name, $config_obj, '', 'no' ) ) { |
|
| 728 | - $this->{$section}->{$name} = maybe_unserialize( $config_obj ); |
|
| 727 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 728 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 729 | 729 | return $this->{$section}->{$name}; |
| 730 | 730 | } else { |
| 731 | 731 | EE_Error::add_error( |
| 732 | - sprintf( __( 'The "%s" could not be saved to the database.', 'event_espresso' ), $config_class ), |
|
| 732 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 733 | 733 | __FILE__, |
| 734 | 734 | __FUNCTION__, |
| 735 | 735 | __LINE__ |
@@ -752,46 +752,46 @@ discard block |
||
| 752 | 752 | * @param bool $throw_errors |
| 753 | 753 | * @return bool |
| 754 | 754 | */ |
| 755 | - public function update_config( $section = '', $name = '', $config_obj = '', $throw_errors = true ) { |
|
| 755 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) { |
|
| 756 | 756 | // don't allow config updates during WP heartbeats |
| 757 | - if ( \EE_Registry::instance()->REQ->get( 'action', '' ) === 'heartbeat' ) { |
|
| 757 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 758 | 758 | return false; |
| 759 | 759 | } |
| 760 | - $config_obj = maybe_unserialize( $config_obj ); |
|
| 760 | + $config_obj = maybe_unserialize($config_obj); |
|
| 761 | 761 | // get class name of the incoming object |
| 762 | - $config_class = get_class( $config_obj ); |
|
| 762 | + $config_class = get_class($config_obj); |
|
| 763 | 763 | // run tests 1-5 and 9 to verify config |
| 764 | 764 | if ( ! $this->_verify_config_params( |
| 765 | 765 | $section, |
| 766 | 766 | $name, |
| 767 | 767 | $config_class, |
| 768 | 768 | $config_obj, |
| 769 | - array( 1, 2, 3, 4, 7, 9 ) |
|
| 769 | + array(1, 2, 3, 4, 7, 9) |
|
| 770 | 770 | ) |
| 771 | 771 | ) { |
| 772 | 772 | return false; |
| 773 | 773 | } |
| 774 | - $config_option_name = $this->_generate_config_option_name( $section, $name ); |
|
| 774 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 775 | 775 | // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
| 776 | - if ( ! isset( $this->_addon_option_names[ $config_option_name ] ) ) { |
|
| 776 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 777 | 777 | // save new config to db |
| 778 | - if( $this->set_config( $section, $name, $config_class, $config_obj ) ) { |
|
| 778 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 779 | 779 | return true; |
| 780 | 780 | } |
| 781 | 781 | } else { |
| 782 | 782 | // first check if the record already exists |
| 783 | - $existing_config = get_option( $config_option_name ); |
|
| 784 | - $config_obj = serialize( $config_obj ); |
|
| 783 | + $existing_config = get_option($config_option_name); |
|
| 784 | + $config_obj = serialize($config_obj); |
|
| 785 | 785 | // just return if db record is already up to date (NOT type safe comparison) |
| 786 | - if ( $existing_config == $config_obj ) { |
|
| 786 | + if ($existing_config == $config_obj) { |
|
| 787 | 787 | $this->{$section}->{$name} = $config_obj; |
| 788 | 788 | return true; |
| 789 | - } else if ( update_option( $config_option_name, $config_obj ) ) { |
|
| 790 | - EE_Config::log( $config_option_name ); |
|
| 789 | + } else if (update_option($config_option_name, $config_obj)) { |
|
| 790 | + EE_Config::log($config_option_name); |
|
| 791 | 791 | // update wp-option for this config class |
| 792 | 792 | $this->{$section}->{$name} = $config_obj; |
| 793 | 793 | return true; |
| 794 | - } elseif ( $throw_errors ) { |
|
| 794 | + } elseif ($throw_errors) { |
|
| 795 | 795 | EE_Error::add_error( |
| 796 | 796 | sprintf( |
| 797 | 797 | __( |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | 'event_espresso' |
| 800 | 800 | ), |
| 801 | 801 | $config_class, |
| 802 | - 'EE_Config->' . $section . '->' . $name |
|
| 802 | + 'EE_Config->'.$section.'->'.$name |
|
| 803 | 803 | ), |
| 804 | 804 | __FILE__, |
| 805 | 805 | __FUNCTION__, |
@@ -821,34 +821,34 @@ discard block |
||
| 821 | 821 | * @param string $config_class |
| 822 | 822 | * @return mixed EE_Config_Base | NULL |
| 823 | 823 | */ |
| 824 | - public function get_config( $section = '', $name = '', $config_class = '' ) { |
|
| 824 | + public function get_config($section = '', $name = '', $config_class = '') { |
|
| 825 | 825 | // ensure config class is set to something |
| 826 | - $config_class = $this->_set_config_class( $config_class, $name ); |
|
| 826 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 827 | 827 | // run tests 1-4, 6 and 7 to verify that all params have been set |
| 828 | - if ( ! $this->_verify_config_params( $section, $name, $config_class, null, array( 1, 2, 3, 4, 5, 6 ) ) ) { |
|
| 828 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 829 | 829 | return null; |
| 830 | 830 | } |
| 831 | 831 | // now test if the requested config object exists, but suppress errors |
| 832 | - if ( $this->_verify_config_params( $section, $name, $config_class, null, array( 7, 8 ), false ) ) { |
|
| 832 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 833 | 833 | // config already exists, so pass it back |
| 834 | 834 | return $this->{$section}->{$name}; |
| 835 | 835 | } |
| 836 | 836 | // load config option from db if it exists |
| 837 | - $config_obj = $this->get_config_option( $this->_generate_config_option_name( $section, $name ) ); |
|
| 837 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 838 | 838 | // verify the newly retrieved config object, but suppress errors |
| 839 | - if ( $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ), false ) ) { |
|
| 839 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 840 | 840 | // config is good, so set it and pass it back |
| 841 | 841 | $this->{$section}->{$name} = $config_obj; |
| 842 | 842 | return $this->{$section}->{$name}; |
| 843 | 843 | } |
| 844 | 844 | // oops! $config_obj is not already set and does not exist in the db, so create a new one |
| 845 | - $config_obj = $this->set_config( $section, $name, $config_class ); |
|
| 845 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 846 | 846 | // verify the newly created config object |
| 847 | - if ( $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ) ) ) { |
|
| 847 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 848 | 848 | return $this->{$section}->{$name}; |
| 849 | 849 | } else { |
| 850 | 850 | EE_Error::add_error( |
| 851 | - sprintf( __( 'The "%s" could not be retrieved from the database.', 'event_espresso' ), $config_class ), |
|
| 851 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 852 | 852 | __FILE__, |
| 853 | 853 | __FUNCTION__, |
| 854 | 854 | __LINE__ |
@@ -866,11 +866,11 @@ discard block |
||
| 866 | 866 | * @param string $config_option_name |
| 867 | 867 | * @return mixed EE_Config_Base | FALSE |
| 868 | 868 | */ |
| 869 | - public function get_config_option( $config_option_name = '' ) { |
|
| 869 | + public function get_config_option($config_option_name = '') { |
|
| 870 | 870 | // retrieve the wp-option for this config class. |
| 871 | - $config_option = maybe_unserialize( get_option( $config_option_name, array() ) ); |
|
| 872 | - if ( empty( $config_option ) ) { |
|
| 873 | - EE_Config::log( $config_option_name . '-NOT-FOUND' ); |
|
| 871 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 872 | + if (empty($config_option)) { |
|
| 873 | + EE_Config::log($config_option_name.'-NOT-FOUND'); |
|
| 874 | 874 | } |
| 875 | 875 | return $config_option; |
| 876 | 876 | } |
@@ -882,17 +882,17 @@ discard block |
||
| 882 | 882 | * |
| 883 | 883 | * @param string $config_option_name |
| 884 | 884 | */ |
| 885 | - public static function log( $config_option_name = '' ) { |
|
| 886 | - if ( EE_Config::logging_enabled() && ! empty( $config_option_name ) ) { |
|
| 887 | - $config_log = get_option( EE_Config::LOG_NAME, array() ); |
|
| 885 | + public static function log($config_option_name = '') { |
|
| 886 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 887 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 888 | 888 | //copy incoming $_REQUEST and sanitize it so we can save it |
| 889 | 889 | $_request = $_REQUEST; |
| 890 | - array_walk_recursive( $_request, 'sanitize_text_field' ); |
|
| 891 | - $config_log[ (string) microtime( true ) ] = array( |
|
| 890 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 891 | + $config_log[(string) microtime(true)] = array( |
|
| 892 | 892 | 'config_name' => $config_option_name, |
| 893 | 893 | 'request' => $_request, |
| 894 | 894 | ); |
| 895 | - update_option( EE_Config::LOG_NAME, $config_log ); |
|
| 895 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 896 | 896 | } |
| 897 | 897 | } |
| 898 | 898 | |
@@ -903,15 +903,15 @@ discard block |
||
| 903 | 903 | * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
| 904 | 904 | */ |
| 905 | 905 | public static function trim_log() { |
| 906 | - if ( ! EE_Config::logging_enabled() ) { |
|
| 906 | + if ( ! EE_Config::logging_enabled()) { |
|
| 907 | 907 | return; |
| 908 | 908 | } |
| 909 | - $config_log = maybe_unserialize( get_option( EE_Config::LOG_NAME, array() ) ); |
|
| 910 | - $log_length = count( $config_log ); |
|
| 911 | - if ( $log_length > EE_Config::LOG_LENGTH ) { |
|
| 912 | - ksort( $config_log ); |
|
| 913 | - $config_log = array_slice( $config_log, $log_length - EE_Config::LOG_LENGTH, null, true ); |
|
| 914 | - update_option( EE_Config::LOG_NAME, $config_log ); |
|
| 909 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 910 | + $log_length = count($config_log); |
|
| 911 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 912 | + ksort($config_log); |
|
| 913 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 914 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 915 | 915 | } |
| 916 | 916 | } |
| 917 | 917 | |
@@ -926,14 +926,14 @@ discard block |
||
| 926 | 926 | * @return string |
| 927 | 927 | */ |
| 928 | 928 | public static function get_page_for_posts() { |
| 929 | - $page_for_posts = get_option( 'page_for_posts' ); |
|
| 930 | - if ( ! $page_for_posts ) { |
|
| 929 | + $page_for_posts = get_option('page_for_posts'); |
|
| 930 | + if ( ! $page_for_posts) { |
|
| 931 | 931 | return 'posts'; |
| 932 | 932 | } |
| 933 | 933 | /** @type WPDB $wpdb */ |
| 934 | 934 | global $wpdb; |
| 935 | 935 | $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
| 936 | - return $wpdb->get_var( $wpdb->prepare( $SQL, $page_for_posts ) ); |
|
| 936 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | |
@@ -989,17 +989,17 @@ discard block |
||
| 989 | 989 | ) |
| 990 | 990 | ) { |
| 991 | 991 | // grab list of installed widgets |
| 992 | - $widgets_to_register = glob( EE_WIDGETS . '*', GLOB_ONLYDIR ); |
|
| 992 | + $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR); |
|
| 993 | 993 | // filter list of modules to register |
| 994 | 994 | $widgets_to_register = apply_filters( |
| 995 | 995 | 'FHEE__EE_Config__register_widgets__widgets_to_register', |
| 996 | 996 | $widgets_to_register |
| 997 | 997 | ); |
| 998 | - if ( ! empty( $widgets_to_register ) ) { |
|
| 998 | + if ( ! empty($widgets_to_register)) { |
|
| 999 | 999 | // cycle thru widget folders |
| 1000 | - foreach ( $widgets_to_register as $widget_path ) { |
|
| 1000 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1001 | 1001 | // add to list of installed widget modules |
| 1002 | - EE_Config::register_ee_widget( $widget_path ); |
|
| 1002 | + EE_Config::register_ee_widget($widget_path); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | } |
| 1005 | 1005 | // filter list of installed modules |
@@ -1019,57 +1019,57 @@ discard block |
||
| 1019 | 1019 | * @param string $widget_path - full path up to and including widget folder |
| 1020 | 1020 | * @return void |
| 1021 | 1021 | */ |
| 1022 | - public static function register_ee_widget( $widget_path = null ) { |
|
| 1023 | - do_action( 'AHEE__EE_Config__register_widget__begin', $widget_path ); |
|
| 1022 | + public static function register_ee_widget($widget_path = null) { |
|
| 1023 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1024 | 1024 | $widget_ext = '.widget.php'; |
| 1025 | 1025 | // make all separators match |
| 1026 | - $widget_path = rtrim( str_replace( '/\\', DS, $widget_path ), DS ); |
|
| 1026 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1027 | 1027 | // does the file path INCLUDE the actual file name as part of the path ? |
| 1028 | - if ( strpos( $widget_path, $widget_ext ) !== false ) { |
|
| 1028 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1029 | 1029 | // grab and shortcode file name from directory name and break apart at dots |
| 1030 | - $file_name = explode( '.', basename( $widget_path ) ); |
|
| 1030 | + $file_name = explode('.', basename($widget_path)); |
|
| 1031 | 1031 | // take first segment from file name pieces and remove class prefix if it exists |
| 1032 | - $widget = strpos( $file_name[0], 'EEW_' ) === 0 ? substr( $file_name[0], 4 ) : $file_name[0]; |
|
| 1032 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1033 | 1033 | // sanitize shortcode directory name |
| 1034 | - $widget = sanitize_key( $widget ); |
|
| 1034 | + $widget = sanitize_key($widget); |
|
| 1035 | 1035 | // now we need to rebuild the shortcode path |
| 1036 | - $widget_path = explode( DS, $widget_path ); |
|
| 1036 | + $widget_path = explode(DS, $widget_path); |
|
| 1037 | 1037 | // remove last segment |
| 1038 | - array_pop( $widget_path ); |
|
| 1038 | + array_pop($widget_path); |
|
| 1039 | 1039 | // glue it back together |
| 1040 | - $widget_path = implode( DS, $widget_path ); |
|
| 1040 | + $widget_path = implode(DS, $widget_path); |
|
| 1041 | 1041 | } else { |
| 1042 | 1042 | // grab and sanitize widget directory name |
| 1043 | - $widget = sanitize_key( basename( $widget_path ) ); |
|
| 1043 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1044 | 1044 | } |
| 1045 | 1045 | // create classname from widget directory name |
| 1046 | - $widget = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $widget ) ) ); |
|
| 1046 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1047 | 1047 | // add class prefix |
| 1048 | - $widget_class = 'EEW_' . $widget; |
|
| 1048 | + $widget_class = 'EEW_'.$widget; |
|
| 1049 | 1049 | // does the widget exist ? |
| 1050 | - if ( ! is_readable( $widget_path . DS . $widget_class . $widget_ext ) ) { |
|
| 1050 | + if ( ! is_readable($widget_path.DS.$widget_class.$widget_ext)) { |
|
| 1051 | 1051 | $msg = sprintf( |
| 1052 | 1052 | __( |
| 1053 | 1053 | 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
| 1054 | 1054 | 'event_espresso' |
| 1055 | 1055 | ), |
| 1056 | 1056 | $widget_class, |
| 1057 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1057 | + $widget_path.DS.$widget_class.$widget_ext |
|
| 1058 | 1058 | ); |
| 1059 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1059 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1060 | 1060 | return; |
| 1061 | 1061 | } |
| 1062 | 1062 | // load the widget class file |
| 1063 | - require_once( $widget_path . DS . $widget_class . $widget_ext ); |
|
| 1063 | + require_once($widget_path.DS.$widget_class.$widget_ext); |
|
| 1064 | 1064 | // verify that class exists |
| 1065 | - if ( ! class_exists( $widget_class ) ) { |
|
| 1066 | - $msg = sprintf( __( 'The requested %s widget class does not exist.', 'event_espresso' ), $widget_class ); |
|
| 1067 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1065 | + if ( ! class_exists($widget_class)) { |
|
| 1066 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1067 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1068 | 1068 | return; |
| 1069 | 1069 | } |
| 1070 | - register_widget( $widget_class ); |
|
| 1070 | + register_widget($widget_class); |
|
| 1071 | 1071 | // add to array of registered widgets |
| 1072 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1072 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path.DS.$widget_class.$widget_ext; |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | |
@@ -1082,17 +1082,17 @@ discard block |
||
| 1082 | 1082 | */ |
| 1083 | 1083 | private function _register_shortcodes() { |
| 1084 | 1084 | // grab list of installed shortcodes |
| 1085 | - $shortcodes_to_register = glob( EE_SHORTCODES . '*', GLOB_ONLYDIR ); |
|
| 1085 | + $shortcodes_to_register = glob(EE_SHORTCODES.'*', GLOB_ONLYDIR); |
|
| 1086 | 1086 | // filter list of modules to register |
| 1087 | 1087 | $shortcodes_to_register = apply_filters( |
| 1088 | 1088 | 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
| 1089 | 1089 | $shortcodes_to_register |
| 1090 | 1090 | ); |
| 1091 | - if ( ! empty( $shortcodes_to_register ) ) { |
|
| 1091 | + if ( ! empty($shortcodes_to_register)) { |
|
| 1092 | 1092 | // cycle thru shortcode folders |
| 1093 | - foreach ( $shortcodes_to_register as $shortcode_path ) { |
|
| 1093 | + foreach ($shortcodes_to_register as $shortcode_path) { |
|
| 1094 | 1094 | // add to list of installed shortcode modules |
| 1095 | - EE_Config::register_shortcode( $shortcode_path ); |
|
| 1095 | + EE_Config::register_shortcode($shortcode_path); |
|
| 1096 | 1096 | } |
| 1097 | 1097 | } |
| 1098 | 1098 | // filter list of installed modules |
@@ -1111,64 +1111,64 @@ discard block |
||
| 1111 | 1111 | * @param string $shortcode_path - full path up to and including shortcode folder |
| 1112 | 1112 | * @return bool |
| 1113 | 1113 | */ |
| 1114 | - public static function register_shortcode( $shortcode_path = null ) { |
|
| 1115 | - do_action( 'AHEE__EE_Config__register_shortcode__begin', $shortcode_path ); |
|
| 1114 | + public static function register_shortcode($shortcode_path = null) { |
|
| 1115 | + do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
| 1116 | 1116 | $shortcode_ext = '.shortcode.php'; |
| 1117 | 1117 | // make all separators match |
| 1118 | - $shortcode_path = str_replace( array( '\\', '/' ), DS, $shortcode_path ); |
|
| 1118 | + $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path); |
|
| 1119 | 1119 | // does the file path INCLUDE the actual file name as part of the path ? |
| 1120 | - if ( strpos( $shortcode_path, $shortcode_ext ) !== false ) { |
|
| 1120 | + if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
| 1121 | 1121 | // grab shortcode file name from directory name and break apart at dots |
| 1122 | - $shortcode_file = explode( '.', basename( $shortcode_path ) ); |
|
| 1122 | + $shortcode_file = explode('.', basename($shortcode_path)); |
|
| 1123 | 1123 | // take first segment from file name pieces and remove class prefix if it exists |
| 1124 | - $shortcode = strpos( $shortcode_file[0], 'EES_' ) === 0 |
|
| 1125 | - ? substr( $shortcode_file[0], 4 ) |
|
| 1124 | + $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
| 1125 | + ? substr($shortcode_file[0], 4) |
|
| 1126 | 1126 | : $shortcode_file[0]; |
| 1127 | 1127 | // sanitize shortcode directory name |
| 1128 | - $shortcode = sanitize_key( $shortcode ); |
|
| 1128 | + $shortcode = sanitize_key($shortcode); |
|
| 1129 | 1129 | // now we need to rebuild the shortcode path |
| 1130 | - $shortcode_path = explode( DS, $shortcode_path ); |
|
| 1130 | + $shortcode_path = explode(DS, $shortcode_path); |
|
| 1131 | 1131 | // remove last segment |
| 1132 | - array_pop( $shortcode_path ); |
|
| 1132 | + array_pop($shortcode_path); |
|
| 1133 | 1133 | // glue it back together |
| 1134 | - $shortcode_path = implode( DS, $shortcode_path ) . DS; |
|
| 1134 | + $shortcode_path = implode(DS, $shortcode_path).DS; |
|
| 1135 | 1135 | } else { |
| 1136 | 1136 | // we need to generate the filename based off of the folder name |
| 1137 | 1137 | // grab and sanitize shortcode directory name |
| 1138 | - $shortcode = sanitize_key( basename( $shortcode_path ) ); |
|
| 1139 | - $shortcode_path = rtrim( $shortcode_path, DS ) . DS; |
|
| 1138 | + $shortcode = sanitize_key(basename($shortcode_path)); |
|
| 1139 | + $shortcode_path = rtrim($shortcode_path, DS).DS; |
|
| 1140 | 1140 | } |
| 1141 | 1141 | // create classname from shortcode directory or file name |
| 1142 | - $shortcode = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $shortcode ) ) ); |
|
| 1142 | + $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
| 1143 | 1143 | // add class prefix |
| 1144 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 1144 | + $shortcode_class = 'EES_'.$shortcode; |
|
| 1145 | 1145 | // does the shortcode exist ? |
| 1146 | - if ( ! is_readable( $shortcode_path . DS . $shortcode_class . $shortcode_ext ) ) { |
|
| 1146 | + if ( ! is_readable($shortcode_path.DS.$shortcode_class.$shortcode_ext)) { |
|
| 1147 | 1147 | $msg = sprintf( |
| 1148 | 1148 | __( |
| 1149 | 1149 | 'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s', |
| 1150 | 1150 | 'event_espresso' |
| 1151 | 1151 | ), |
| 1152 | 1152 | $shortcode_class, |
| 1153 | - $shortcode_path . DS . $shortcode_class . $shortcode_ext |
|
| 1153 | + $shortcode_path.DS.$shortcode_class.$shortcode_ext |
|
| 1154 | 1154 | ); |
| 1155 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1155 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1156 | 1156 | return false; |
| 1157 | 1157 | } |
| 1158 | 1158 | // load the shortcode class file |
| 1159 | - require_once( $shortcode_path . $shortcode_class . $shortcode_ext ); |
|
| 1159 | + require_once($shortcode_path.$shortcode_class.$shortcode_ext); |
|
| 1160 | 1160 | // verify that class exists |
| 1161 | - if ( ! class_exists( $shortcode_class ) ) { |
|
| 1161 | + if ( ! class_exists($shortcode_class)) { |
|
| 1162 | 1162 | $msg = sprintf( |
| 1163 | - __( 'The requested %s shortcode class does not exist.', 'event_espresso' ), |
|
| 1163 | + __('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
| 1164 | 1164 | $shortcode_class |
| 1165 | 1165 | ); |
| 1166 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1166 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1167 | 1167 | return false; |
| 1168 | 1168 | } |
| 1169 | - $shortcode = strtoupper( $shortcode ); |
|
| 1169 | + $shortcode = strtoupper($shortcode); |
|
| 1170 | 1170 | // add to array of registered shortcodes |
| 1171 | - EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 1171 | + EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext; |
|
| 1172 | 1172 | return true; |
| 1173 | 1173 | } |
| 1174 | 1174 | |
@@ -1182,22 +1182,22 @@ discard block |
||
| 1182 | 1182 | */ |
| 1183 | 1183 | private function _register_modules() { |
| 1184 | 1184 | // grab list of installed modules |
| 1185 | - $modules_to_register = glob( EE_MODULES . '*', GLOB_ONLYDIR ); |
|
| 1185 | + $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR); |
|
| 1186 | 1186 | // filter list of modules to register |
| 1187 | 1187 | $modules_to_register = apply_filters( |
| 1188 | 1188 | 'FHEE__EE_Config__register_modules__modules_to_register', |
| 1189 | 1189 | $modules_to_register |
| 1190 | 1190 | ); |
| 1191 | - if ( ! empty( $modules_to_register ) ) { |
|
| 1191 | + if ( ! empty($modules_to_register)) { |
|
| 1192 | 1192 | // loop through folders |
| 1193 | - foreach ( $modules_to_register as $module_path ) { |
|
| 1193 | + foreach ($modules_to_register as $module_path) { |
|
| 1194 | 1194 | /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
| 1195 | 1195 | if ( |
| 1196 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1197 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1196 | + $module_path !== EE_MODULES.'zzz-copy-this-module-template' |
|
| 1197 | + && $module_path !== EE_MODULES.'gateways' |
|
| 1198 | 1198 | ) { |
| 1199 | 1199 | // add to list of installed modules |
| 1200 | - EE_Config::register_module( $module_path ); |
|
| 1200 | + EE_Config::register_module($module_path); |
|
| 1201 | 1201 | } |
| 1202 | 1202 | } |
| 1203 | 1203 | } |
@@ -1217,39 +1217,39 @@ discard block |
||
| 1217 | 1217 | * @param string $module_path - full path up to and including module folder |
| 1218 | 1218 | * @return bool |
| 1219 | 1219 | */ |
| 1220 | - public static function register_module( $module_path = null ) { |
|
| 1221 | - do_action( 'AHEE__EE_Config__register_module__begin', $module_path ); |
|
| 1220 | + public static function register_module($module_path = null) { |
|
| 1221 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1222 | 1222 | $module_ext = '.module.php'; |
| 1223 | 1223 | // make all separators match |
| 1224 | - $module_path = str_replace( array( '\\', '/' ), DS, $module_path ); |
|
| 1224 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1225 | 1225 | // does the file path INCLUDE the actual file name as part of the path ? |
| 1226 | - if ( strpos( $module_path, $module_ext ) !== false ) { |
|
| 1226 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1227 | 1227 | // grab and shortcode file name from directory name and break apart at dots |
| 1228 | - $module_file = explode( '.', basename( $module_path ) ); |
|
| 1228 | + $module_file = explode('.', basename($module_path)); |
|
| 1229 | 1229 | // now we need to rebuild the shortcode path |
| 1230 | - $module_path = explode( DS, $module_path ); |
|
| 1230 | + $module_path = explode(DS, $module_path); |
|
| 1231 | 1231 | // remove last segment |
| 1232 | - array_pop( $module_path ); |
|
| 1232 | + array_pop($module_path); |
|
| 1233 | 1233 | // glue it back together |
| 1234 | - $module_path = implode( DS, $module_path ) . DS; |
|
| 1234 | + $module_path = implode(DS, $module_path).DS; |
|
| 1235 | 1235 | // take first segment from file name pieces and sanitize it |
| 1236 | - $module = preg_replace( '/[^a-zA-Z0-9_\-]/', '', $module_file[0] ); |
|
| 1236 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1237 | 1237 | // ensure class prefix is added |
| 1238 | - $module_class = strpos( $module, 'EED_' ) !== 0 ? 'EED_' . $module : $module; |
|
| 1238 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module; |
|
| 1239 | 1239 | } else { |
| 1240 | 1240 | // we need to generate the filename based off of the folder name |
| 1241 | 1241 | // grab and sanitize module name |
| 1242 | - $module = strtolower( basename( $module_path ) ); |
|
| 1243 | - $module = preg_replace( '/[^a-z0-9_\-]/', '', $module ); |
|
| 1242 | + $module = strtolower(basename($module_path)); |
|
| 1243 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1244 | 1244 | // like trailingslashit() |
| 1245 | - $module_path = rtrim( $module_path, DS ) . DS; |
|
| 1245 | + $module_path = rtrim($module_path, DS).DS; |
|
| 1246 | 1246 | // create classname from module directory name |
| 1247 | - $module = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $module ) ) ); |
|
| 1247 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1248 | 1248 | // add class prefix |
| 1249 | - $module_class = 'EED_' . $module; |
|
| 1249 | + $module_class = 'EED_'.$module; |
|
| 1250 | 1250 | } |
| 1251 | 1251 | // does the module exist ? |
| 1252 | - if ( ! is_readable( $module_path . DS . $module_class . $module_ext ) ) { |
|
| 1252 | + if ( ! is_readable($module_path.DS.$module_class.$module_ext)) { |
|
| 1253 | 1253 | $msg = sprintf( |
| 1254 | 1254 | __( |
| 1255 | 1255 | 'The requested %s module file could not be found or is not readable due to file permissions.', |
@@ -1257,19 +1257,19 @@ discard block |
||
| 1257 | 1257 | ), |
| 1258 | 1258 | $module |
| 1259 | 1259 | ); |
| 1260 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1260 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1261 | 1261 | return false; |
| 1262 | 1262 | } |
| 1263 | 1263 | // load the module class file |
| 1264 | - require_once( $module_path . $module_class . $module_ext ); |
|
| 1264 | + require_once($module_path.$module_class.$module_ext); |
|
| 1265 | 1265 | // verify that class exists |
| 1266 | - if ( ! class_exists( $module_class ) ) { |
|
| 1267 | - $msg = sprintf( __( 'The requested %s module class does not exist.', 'event_espresso' ), $module_class ); |
|
| 1268 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1266 | + if ( ! class_exists($module_class)) { |
|
| 1267 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1268 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1269 | 1269 | return false; |
| 1270 | 1270 | } |
| 1271 | 1271 | // add to array of registered modules |
| 1272 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1272 | + EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext; |
|
| 1273 | 1273 | do_action( |
| 1274 | 1274 | 'AHEE__EE_Config__register_module__complete', |
| 1275 | 1275 | $module_class, |
@@ -1289,26 +1289,26 @@ discard block |
||
| 1289 | 1289 | */ |
| 1290 | 1290 | private function _initialize_shortcodes() { |
| 1291 | 1291 | // cycle thru shortcode folders |
| 1292 | - foreach ( EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path ) { |
|
| 1292 | + foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) { |
|
| 1293 | 1293 | // add class prefix |
| 1294 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 1294 | + $shortcode_class = 'EES_'.$shortcode; |
|
| 1295 | 1295 | // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
| 1296 | 1296 | // which set hooks ? |
| 1297 | - if ( is_admin() ) { |
|
| 1297 | + if (is_admin()) { |
|
| 1298 | 1298 | // fire immediately |
| 1299 | - call_user_func( array( $shortcode_class, 'set_hooks_admin' ) ); |
|
| 1299 | + call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
| 1300 | 1300 | } else { |
| 1301 | 1301 | // delay until other systems are online |
| 1302 | 1302 | add_action( |
| 1303 | 1303 | 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
| 1304 | - array( $shortcode_class, 'set_hooks' ) |
|
| 1304 | + array($shortcode_class, 'set_hooks') |
|
| 1305 | 1305 | ); |
| 1306 | 1306 | // convert classname to UPPERCASE and create WP shortcode. |
| 1307 | - $shortcode_tag = strtoupper( $shortcode ); |
|
| 1307 | + $shortcode_tag = strtoupper($shortcode); |
|
| 1308 | 1308 | // but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor' |
| 1309 | - if ( ! shortcode_exists( $shortcode_tag ) ) { |
|
| 1309 | + if ( ! shortcode_exists($shortcode_tag)) { |
|
| 1310 | 1310 | // NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes() |
| 1311 | - add_shortcode( $shortcode_tag, array( $shortcode_class, 'fallback_shortcode_processor' ) ); |
|
| 1311 | + add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
| 1312 | 1312 | } |
| 1313 | 1313 | } |
| 1314 | 1314 | } |
@@ -1325,17 +1325,17 @@ discard block |
||
| 1325 | 1325 | */ |
| 1326 | 1326 | private function _initialize_modules() { |
| 1327 | 1327 | // cycle thru shortcode folders |
| 1328 | - foreach ( EE_Registry::instance()->modules as $module_class => $module_path ) { |
|
| 1328 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1329 | 1329 | // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
| 1330 | 1330 | // which set hooks ? |
| 1331 | - if ( is_admin() ) { |
|
| 1331 | + if (is_admin()) { |
|
| 1332 | 1332 | // fire immediately |
| 1333 | - call_user_func( array( $module_class, 'set_hooks_admin' ) ); |
|
| 1333 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1334 | 1334 | } else { |
| 1335 | 1335 | // delay until other systems are online |
| 1336 | 1336 | add_action( |
| 1337 | 1337 | 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
| 1338 | - array( $module_class, 'set_hooks' ) |
|
| 1338 | + array($module_class, 'set_hooks') |
|
| 1339 | 1339 | ); |
| 1340 | 1340 | } |
| 1341 | 1341 | } |
@@ -1353,29 +1353,29 @@ discard block |
||
| 1353 | 1353 | * @param string $key - url param key indicating a route is being called |
| 1354 | 1354 | * @return bool |
| 1355 | 1355 | */ |
| 1356 | - public static function register_route( $route = null, $module = null, $method_name = null, $key = 'ee' ) { |
|
| 1357 | - do_action( 'AHEE__EE_Config__register_route__begin', $route, $module, $method_name ); |
|
| 1358 | - $module = str_replace( 'EED_', '', $module ); |
|
| 1359 | - $module_class = 'EED_' . $module; |
|
| 1360 | - if ( ! isset( EE_Registry::instance()->modules->{$module_class} ) ) { |
|
| 1361 | - $msg = sprintf( __( 'The module %s has not been registered.', 'event_espresso' ), $module ); |
|
| 1362 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1356 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') { |
|
| 1357 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1358 | + $module = str_replace('EED_', '', $module); |
|
| 1359 | + $module_class = 'EED_'.$module; |
|
| 1360 | + if ( ! isset(EE_Registry::instance()->modules->{$module_class} )) { |
|
| 1361 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1362 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1363 | 1363 | return false; |
| 1364 | 1364 | } |
| 1365 | - if ( empty( $route ) ) { |
|
| 1366 | - $msg = sprintf( __( 'No route has been supplied.', 'event_espresso' ), $route ); |
|
| 1367 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1365 | + if (empty($route)) { |
|
| 1366 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1367 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1368 | 1368 | return false; |
| 1369 | 1369 | } |
| 1370 | - if ( ! method_exists( 'EED_' . $module, $method_name ) ) { |
|
| 1370 | + if ( ! method_exists('EED_'.$module, $method_name)) { |
|
| 1371 | 1371 | $msg = sprintf( |
| 1372 | - __( 'A valid class method for the %s route has not been supplied.', 'event_espresso' ), |
|
| 1372 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1373 | 1373 | $route |
| 1374 | 1374 | ); |
| 1375 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1375 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1376 | 1376 | return false; |
| 1377 | 1377 | } |
| 1378 | - EE_Config::$_module_route_map[ $key ][ $route ] = array( 'EED_' . $module, $method_name ); |
|
| 1378 | + EE_Config::$_module_route_map[$key][$route] = array('EED_'.$module, $method_name); |
|
| 1379 | 1379 | return true; |
| 1380 | 1380 | } |
| 1381 | 1381 | |
@@ -1389,11 +1389,11 @@ discard block |
||
| 1389 | 1389 | * @param string $key - url param key indicating a route is being called |
| 1390 | 1390 | * @return string |
| 1391 | 1391 | */ |
| 1392 | - public static function get_route( $route = null, $key = 'ee' ) { |
|
| 1393 | - do_action( 'AHEE__EE_Config__get_route__begin', $route ); |
|
| 1394 | - $route = (string) apply_filters( 'FHEE__EE_Config__get_route', $route ); |
|
| 1395 | - if ( isset( EE_Config::$_module_route_map[ $key ][ $route ] ) ) { |
|
| 1396 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1392 | + public static function get_route($route = null, $key = 'ee') { |
|
| 1393 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1394 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1395 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1396 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1397 | 1397 | } |
| 1398 | 1398 | return null; |
| 1399 | 1399 | } |
@@ -1423,49 +1423,49 @@ discard block |
||
| 1423 | 1423 | * @param string $key - url param key indicating a route is being called |
| 1424 | 1424 | * @return bool |
| 1425 | 1425 | */ |
| 1426 | - public static function register_forward( $route = null, $status = 0, $forward = null, $key = 'ee' ) { |
|
| 1427 | - do_action( 'AHEE__EE_Config__register_forward', $route, $status, $forward ); |
|
| 1428 | - if ( ! isset( EE_Config::$_module_route_map[ $key ][ $route ] ) || empty( $route ) ) { |
|
| 1426 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') { |
|
| 1427 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1428 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1429 | 1429 | $msg = sprintf( |
| 1430 | - __( 'The module route %s for this forward has not been registered.', 'event_espresso' ), |
|
| 1430 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1431 | 1431 | $route |
| 1432 | 1432 | ); |
| 1433 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1433 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1434 | 1434 | return false; |
| 1435 | 1435 | } |
| 1436 | - if ( empty( $forward ) ) { |
|
| 1437 | - $msg = sprintf( __( 'No forwarding route has been supplied.', 'event_espresso' ), $route ); |
|
| 1438 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1436 | + if (empty($forward)) { |
|
| 1437 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1438 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1439 | 1439 | return false; |
| 1440 | 1440 | } |
| 1441 | - if ( is_array( $forward ) ) { |
|
| 1442 | - if ( ! isset( $forward[1] ) ) { |
|
| 1441 | + if (is_array($forward)) { |
|
| 1442 | + if ( ! isset($forward[1])) { |
|
| 1443 | 1443 | $msg = sprintf( |
| 1444 | - __( 'A class method for the %s forwarding route has not been supplied.', 'event_espresso' ), |
|
| 1444 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1445 | 1445 | $route |
| 1446 | 1446 | ); |
| 1447 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1447 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1448 | 1448 | return false; |
| 1449 | 1449 | } |
| 1450 | - if ( ! method_exists( $forward[0], $forward[1] ) ) { |
|
| 1450 | + if ( ! method_exists($forward[0], $forward[1])) { |
|
| 1451 | 1451 | $msg = sprintf( |
| 1452 | - __( 'The class method %s for the %s forwarding route is in invalid.', 'event_espresso' ), |
|
| 1452 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1453 | 1453 | $forward[1], |
| 1454 | 1454 | $route |
| 1455 | 1455 | ); |
| 1456 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1456 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1457 | 1457 | return false; |
| 1458 | 1458 | } |
| 1459 | - } else if ( ! function_exists( $forward ) ) { |
|
| 1459 | + } else if ( ! function_exists($forward)) { |
|
| 1460 | 1460 | $msg = sprintf( |
| 1461 | - __( 'The function %s for the %s forwarding route is in invalid.', 'event_espresso' ), |
|
| 1461 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1462 | 1462 | $forward, |
| 1463 | 1463 | $route |
| 1464 | 1464 | ); |
| 1465 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1465 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1466 | 1466 | return false; |
| 1467 | 1467 | } |
| 1468 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint( $status ) ] = $forward; |
|
| 1468 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1469 | 1469 | return true; |
| 1470 | 1470 | } |
| 1471 | 1471 | |
@@ -1481,12 +1481,12 @@ discard block |
||
| 1481 | 1481 | * @param string $key - url param key indicating a route is being called |
| 1482 | 1482 | * @return string |
| 1483 | 1483 | */ |
| 1484 | - public static function get_forward( $route = null, $status = 0, $key = 'ee' ) { |
|
| 1485 | - do_action( 'AHEE__EE_Config__get_forward__begin', $route, $status ); |
|
| 1486 | - if ( isset( EE_Config::$_module_forward_map[ $key ][ $route ][ $status ] ) ) { |
|
| 1484 | + public static function get_forward($route = null, $status = 0, $key = 'ee') { |
|
| 1485 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1486 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1487 | 1487 | return apply_filters( |
| 1488 | 1488 | 'FHEE__EE_Config__get_forward', |
| 1489 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1489 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1490 | 1490 | $route, |
| 1491 | 1491 | $status |
| 1492 | 1492 | ); |
@@ -1508,17 +1508,17 @@ discard block |
||
| 1508 | 1508 | * @param string $key - url param key indicating a route is being called |
| 1509 | 1509 | * @return bool |
| 1510 | 1510 | */ |
| 1511 | - public static function register_view( $route = null, $status = 0, $view = null, $key = 'ee' ) { |
|
| 1512 | - do_action( 'AHEE__EE_Config__register_view__begin', $route, $status, $view ); |
|
| 1513 | - if ( ! isset( EE_Config::$_module_route_map[ $key ][ $route ] ) || empty( $route ) ) { |
|
| 1511 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') { |
|
| 1512 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1513 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1514 | 1514 | $msg = sprintf( |
| 1515 | - __( 'The module route %s for this view has not been registered.', 'event_espresso' ), |
|
| 1515 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1516 | 1516 | $route |
| 1517 | 1517 | ); |
| 1518 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1518 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1519 | 1519 | return false; |
| 1520 | 1520 | } |
| 1521 | - if ( ! is_readable( $view ) ) { |
|
| 1521 | + if ( ! is_readable($view)) { |
|
| 1522 | 1522 | $msg = sprintf( |
| 1523 | 1523 | __( |
| 1524 | 1524 | 'The %s view file could not be found or is not readable due to file permissions.', |
@@ -1526,10 +1526,10 @@ discard block |
||
| 1526 | 1526 | ), |
| 1527 | 1527 | $view |
| 1528 | 1528 | ); |
| 1529 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1529 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1530 | 1530 | return false; |
| 1531 | 1531 | } |
| 1532 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint( $status ) ] = $view; |
|
| 1532 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1533 | 1533 | return true; |
| 1534 | 1534 | } |
| 1535 | 1535 | |
@@ -1545,12 +1545,12 @@ discard block |
||
| 1545 | 1545 | * @param string $key - url param key indicating a route is being called |
| 1546 | 1546 | * @return string |
| 1547 | 1547 | */ |
| 1548 | - public static function get_view( $route = null, $status = 0, $key = 'ee' ) { |
|
| 1549 | - do_action( 'AHEE__EE_Config__get_view__begin', $route, $status ); |
|
| 1550 | - if ( isset( EE_Config::$_module_view_map[ $key ][ $route ][ $status ] ) ) { |
|
| 1548 | + public static function get_view($route = null, $status = 0, $key = 'ee') { |
|
| 1549 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1550 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1551 | 1551 | return apply_filters( |
| 1552 | 1552 | 'FHEE__EE_Config__get_view', |
| 1553 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1553 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1554 | 1554 | $route, |
| 1555 | 1555 | $status |
| 1556 | 1556 | ); |
@@ -1561,7 +1561,7 @@ discard block |
||
| 1561 | 1561 | |
| 1562 | 1562 | |
| 1563 | 1563 | public function update_addon_option_names() { |
| 1564 | - update_option( EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names ); |
|
| 1564 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | |
@@ -1589,22 +1589,22 @@ discard block |
||
| 1589 | 1589 | * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
| 1590 | 1590 | * @throws \EE_Error |
| 1591 | 1591 | */ |
| 1592 | - public function get_pretty( $property ) { |
|
| 1593 | - if ( ! property_exists( $this, $property ) ) { |
|
| 1592 | + public function get_pretty($property) { |
|
| 1593 | + if ( ! property_exists($this, $property)) { |
|
| 1594 | 1594 | throw new EE_Error( |
| 1595 | 1595 | sprintf( |
| 1596 | 1596 | __( |
| 1597 | 1597 | '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
| 1598 | 1598 | 'event_espresso' |
| 1599 | 1599 | ), |
| 1600 | - get_class( $this ), |
|
| 1600 | + get_class($this), |
|
| 1601 | 1601 | $property |
| 1602 | 1602 | ) |
| 1603 | 1603 | ); |
| 1604 | 1604 | } |
| 1605 | 1605 | //just handling escaping of strings for now. |
| 1606 | - if ( is_string( $this->{$property} ) ) { |
|
| 1607 | - return stripslashes( $this->{$property} ); |
|
| 1606 | + if (is_string($this->{$property} )) { |
|
| 1607 | + return stripslashes($this->{$property} ); |
|
| 1608 | 1608 | } |
| 1609 | 1609 | return $this->{$property}; |
| 1610 | 1610 | } |
@@ -1613,17 +1613,17 @@ discard block |
||
| 1613 | 1613 | |
| 1614 | 1614 | public function populate() { |
| 1615 | 1615 | //grab defaults via a new instance of this class. |
| 1616 | - $class_name = get_class( $this ); |
|
| 1616 | + $class_name = get_class($this); |
|
| 1617 | 1617 | $defaults = new $class_name; |
| 1618 | 1618 | //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
| 1619 | 1619 | //default from our $defaults object. |
| 1620 | - foreach ( get_object_vars( $defaults ) as $property => $value ) { |
|
| 1621 | - if ( $this->{$property} === null ) { |
|
| 1620 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1621 | + if ($this->{$property} === null) { |
|
| 1622 | 1622 | $this->{$property} = $value; |
| 1623 | 1623 | } |
| 1624 | 1624 | } |
| 1625 | 1625 | //cleanup |
| 1626 | - unset( $defaults ); |
|
| 1626 | + unset($defaults); |
|
| 1627 | 1627 | } |
| 1628 | 1628 | |
| 1629 | 1629 | |
@@ -1639,7 +1639,7 @@ discard block |
||
| 1639 | 1639 | * @param $a |
| 1640 | 1640 | * @return bool |
| 1641 | 1641 | */ |
| 1642 | - public function __isset( $a ) { |
|
| 1642 | + public function __isset($a) { |
|
| 1643 | 1643 | return false; |
| 1644 | 1644 | } |
| 1645 | 1645 | |
@@ -1651,7 +1651,7 @@ discard block |
||
| 1651 | 1651 | * @param $a |
| 1652 | 1652 | * @return bool |
| 1653 | 1653 | */ |
| 1654 | - public function __unset( $a ) { |
|
| 1654 | + public function __unset($a) { |
|
| 1655 | 1655 | return false; |
| 1656 | 1656 | } |
| 1657 | 1657 | |
@@ -1761,7 +1761,7 @@ discard block |
||
| 1761 | 1761 | $this->current_blog_id = get_current_blog_id(); |
| 1762 | 1762 | $this->current_blog_id = $this->current_blog_id === NULL ? 1 : $this->current_blog_id; |
| 1763 | 1763 | $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
| 1764 | - $this->ee_ueip_has_notified = is_main_site() ? get_option( 'ee_ueip_has_notified', false ) : true; |
|
| 1764 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1765 | 1765 | $this->post_shortcodes = array(); |
| 1766 | 1766 | $this->module_route_map = array(); |
| 1767 | 1767 | $this->module_forward_map = array(); |
@@ -1777,9 +1777,9 @@ discard block |
||
| 1777 | 1777 | $this->thank_you_page_url = ''; |
| 1778 | 1778 | $this->cancel_page_url = ''; |
| 1779 | 1779 | //cpt slugs |
| 1780 | - $this->event_cpt_slug = __( 'events', 'event_espresso' ); |
|
| 1780 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1781 | 1781 | //ueip constant check |
| 1782 | - if ( defined( 'EE_DISABLE_UXIP' ) && EE_DISABLE_UXIP ) { |
|
| 1782 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1783 | 1783 | $this->ee_ueip_optin = false; |
| 1784 | 1784 | $this->ee_ueip_has_notified = true; |
| 1785 | 1785 | } |
@@ -1822,11 +1822,11 @@ discard block |
||
| 1822 | 1822 | * @return string |
| 1823 | 1823 | */ |
| 1824 | 1824 | public function reg_page_url() { |
| 1825 | - if ( ! $this->reg_page_url ) { |
|
| 1825 | + if ( ! $this->reg_page_url) { |
|
| 1826 | 1826 | $this->reg_page_url = add_query_arg( |
| 1827 | - array( 'uts' => time() ), |
|
| 1828 | - get_permalink( $this->reg_page_id ) |
|
| 1829 | - ) . '#checkout'; |
|
| 1827 | + array('uts' => time()), |
|
| 1828 | + get_permalink($this->reg_page_id) |
|
| 1829 | + ).'#checkout'; |
|
| 1830 | 1830 | } |
| 1831 | 1831 | return $this->reg_page_url; |
| 1832 | 1832 | } |
@@ -1841,12 +1841,12 @@ discard block |
||
| 1841 | 1841 | * @access public |
| 1842 | 1842 | * @return string |
| 1843 | 1843 | */ |
| 1844 | - public function txn_page_url( $query_args = array() ) { |
|
| 1845 | - if ( ! $this->txn_page_url ) { |
|
| 1846 | - $this->txn_page_url = get_permalink( $this->txn_page_id ); |
|
| 1844 | + public function txn_page_url($query_args = array()) { |
|
| 1845 | + if ( ! $this->txn_page_url) { |
|
| 1846 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1847 | 1847 | } |
| 1848 | - if ( $query_args ) { |
|
| 1849 | - return add_query_arg( $query_args, $this->txn_page_url ); |
|
| 1848 | + if ($query_args) { |
|
| 1849 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1850 | 1850 | } else { |
| 1851 | 1851 | return $this->txn_page_url; |
| 1852 | 1852 | } |
@@ -1862,12 +1862,12 @@ discard block |
||
| 1862 | 1862 | * @access public |
| 1863 | 1863 | * @return string |
| 1864 | 1864 | */ |
| 1865 | - public function thank_you_page_url( $query_args = array() ) { |
|
| 1866 | - if ( ! $this->thank_you_page_url ) { |
|
| 1867 | - $this->thank_you_page_url = get_permalink( $this->thank_you_page_id ); |
|
| 1865 | + public function thank_you_page_url($query_args = array()) { |
|
| 1866 | + if ( ! $this->thank_you_page_url) { |
|
| 1867 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1868 | 1868 | } |
| 1869 | - if ( $query_args ) { |
|
| 1870 | - return add_query_arg( $query_args, $this->thank_you_page_url ); |
|
| 1869 | + if ($query_args) { |
|
| 1870 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1871 | 1871 | } else { |
| 1872 | 1872 | return $this->thank_you_page_url; |
| 1873 | 1873 | } |
@@ -1882,8 +1882,8 @@ discard block |
||
| 1882 | 1882 | * @return string |
| 1883 | 1883 | */ |
| 1884 | 1884 | public function cancel_page_url() { |
| 1885 | - if ( ! $this->cancel_page_url ) { |
|
| 1886 | - $this->cancel_page_url = get_permalink( $this->cancel_page_id ); |
|
| 1885 | + if ( ! $this->cancel_page_url) { |
|
| 1886 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1887 | 1887 | } |
| 1888 | 1888 | return $this->cancel_page_url; |
| 1889 | 1889 | } |
@@ -1912,22 +1912,22 @@ discard block |
||
| 1912 | 1912 | */ |
| 1913 | 1913 | protected function _get_main_ee_ueip_optin() { |
| 1914 | 1914 | //if this is the main site then we can just bypass our direct query. |
| 1915 | - if ( is_main_site() ) { |
|
| 1916 | - return get_option( 'ee_ueip_optin', false ); |
|
| 1915 | + if (is_main_site()) { |
|
| 1916 | + return get_option('ee_ueip_optin', false); |
|
| 1917 | 1917 | } |
| 1918 | 1918 | |
| 1919 | 1919 | //is this already cached for this request? If so use it. |
| 1920 | - if ( ! empty( EE_Core_Config::$ee_ueip_option ) ) { |
|
| 1920 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1921 | 1921 | return EE_Core_Config::$ee_ueip_option; |
| 1922 | 1922 | } |
| 1923 | 1923 | |
| 1924 | 1924 | global $wpdb; |
| 1925 | 1925 | $current_network_main_site = is_multisite() ? get_current_site() : null; |
| 1926 | - $current_main_site_id = ! empty( $current_network_main_site ) ? $current_network_main_site->blog_id : 1; |
|
| 1926 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1927 | 1927 | $option = 'ee_ueip_optin'; |
| 1928 | 1928 | |
| 1929 | 1929 | //set correct table for query |
| 1930 | - $table_name = $wpdb->get_blog_prefix( $current_main_site_id ) . 'options'; |
|
| 1930 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options'; |
|
| 1931 | 1931 | |
| 1932 | 1932 | |
| 1933 | 1933 | //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
@@ -1935,20 +1935,20 @@ discard block |
||
| 1935 | 1935 | //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
| 1936 | 1936 | //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
| 1937 | 1937 | //for the purpose of caching. |
| 1938 | - $pre = apply_filters( 'pre_option_' . $option, false, $option ); |
|
| 1939 | - if ( false !== $pre ) { |
|
| 1938 | + $pre = apply_filters('pre_option_'.$option, false, $option); |
|
| 1939 | + if (false !== $pre) { |
|
| 1940 | 1940 | EE_Core_Config::$ee_ueip_option = $pre; |
| 1941 | 1941 | return EE_Core_Config::$ee_ueip_option; |
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | - $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", $option ) ); |
|
| 1945 | - if ( is_object( $row ) ) { |
|
| 1944 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", $option)); |
|
| 1945 | + if (is_object($row)) { |
|
| 1946 | 1946 | $value = $row->option_value; |
| 1947 | 1947 | } else { //option does not exist so use default. |
| 1948 | - return apply_filters( 'default_option_' . $option, false, $option ); |
|
| 1948 | + return apply_filters('default_option_'.$option, false, $option); |
|
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | - EE_Core_Config::$ee_ueip_option = apply_filters( 'option_' . $option, maybe_unserialize( $value ), $option ); |
|
| 1951 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option); |
|
| 1952 | 1952 | return EE_Core_Config::$ee_ueip_option; |
| 1953 | 1953 | } |
| 1954 | 1954 | |
@@ -1964,7 +1964,7 @@ discard block |
||
| 1964 | 1964 | //reset all url properties |
| 1965 | 1965 | $this->_reset_urls(); |
| 1966 | 1966 | //return what to save to db |
| 1967 | - return array_keys( get_object_vars( $this ) ); |
|
| 1967 | + return array_keys(get_object_vars($this)); |
|
| 1968 | 1968 | } |
| 1969 | 1969 | |
| 1970 | 1970 | } |
@@ -2111,14 +2111,14 @@ discard block |
||
| 2111 | 2111 | */ |
| 2112 | 2112 | public function __construct() { |
| 2113 | 2113 | // set default organization settings |
| 2114 | - $this->name = get_bloginfo( 'name' ); |
|
| 2114 | + $this->name = get_bloginfo('name'); |
|
| 2115 | 2115 | $this->address_1 = '123 Onna Road'; |
| 2116 | 2116 | $this->address_2 = 'PO Box 123'; |
| 2117 | 2117 | $this->city = 'Inna City'; |
| 2118 | 2118 | $this->STA_ID = 4; |
| 2119 | 2119 | $this->CNT_ISO = 'US'; |
| 2120 | 2120 | $this->zip = '12345'; |
| 2121 | - $this->email = get_bloginfo( 'admin_email' ); |
|
| 2121 | + $this->email = get_bloginfo('admin_email'); |
|
| 2122 | 2122 | $this->phone = ''; |
| 2123 | 2123 | $this->vat = '123456789'; |
| 2124 | 2124 | $this->logo_url = ''; |
@@ -2206,46 +2206,46 @@ discard block |
||
| 2206 | 2206 | * @param string $CNT_ISO |
| 2207 | 2207 | * @throws \EE_Error |
| 2208 | 2208 | */ |
| 2209 | - public function __construct( $CNT_ISO = '' ) { |
|
| 2209 | + public function __construct($CNT_ISO = '') { |
|
| 2210 | 2210 | /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
| 2211 | - $table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
| 2211 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2212 | 2212 | // get country code from organization settings or use default |
| 2213 | - $ORG_CNT = isset( EE_Registry::instance()->CFG->organization ) |
|
| 2213 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2214 | 2214 | && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
| 2215 | 2215 | ? EE_Registry::instance()->CFG->organization->CNT_ISO |
| 2216 | 2216 | : ''; |
| 2217 | 2217 | // but override if requested |
| 2218 | - $CNT_ISO = ! empty( $CNT_ISO ) ? $CNT_ISO : $ORG_CNT; |
|
| 2218 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2219 | 2219 | // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
| 2220 | 2220 | if ( |
| 2221 | - ! empty( $CNT_ISO ) |
|
| 2221 | + ! empty($CNT_ISO) |
|
| 2222 | 2222 | && EE_Maintenance_Mode::instance()->models_can_query() |
| 2223 | - && $table_analysis->tableExists( EE_Registry::instance()->load_model( 'Country' )->table() ) |
|
| 2223 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2224 | 2224 | ) { |
| 2225 | 2225 | // retrieve the country settings from the db, just in case they have been customized |
| 2226 | - $country = EE_Registry::instance()->load_model( 'Country' )->get_one_by_ID( $CNT_ISO ); |
|
| 2227 | - if ( $country instanceof EE_Country ) { |
|
| 2228 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2229 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2230 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2231 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2232 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2233 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2234 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2235 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2226 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2227 | + if ($country instanceof EE_Country) { |
|
| 2228 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2229 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2230 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2231 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2232 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2233 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2234 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2235 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2236 | 2236 | } |
| 2237 | 2237 | } |
| 2238 | 2238 | // fallback to hardcoded defaults, in case the above failed |
| 2239 | - if ( empty( $this->code ) ) { |
|
| 2239 | + if (empty($this->code)) { |
|
| 2240 | 2240 | // set default currency settings |
| 2241 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2242 | - $this->name = __( 'Dollar', 'event_espresso' ); // Dollar |
|
| 2243 | - $this->plural = __( 'Dollars', 'event_espresso' ); // Dollars |
|
| 2244 | - $this->sign = '$'; // currency sign: $ |
|
| 2245 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2246 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2247 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2248 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2241 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2242 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2243 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2244 | + $this->sign = '$'; // currency sign: $ |
|
| 2245 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2246 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2247 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2248 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2249 | 2249 | } |
| 2250 | 2250 | } |
| 2251 | 2251 | } |
@@ -2414,7 +2414,7 @@ discard block |
||
| 2414 | 2414 | * @since 4.8.8.rc.019 |
| 2415 | 2415 | */ |
| 2416 | 2416 | public function do_hooks() { |
| 2417 | - add_action( 'AHEE__EE_Config___load_core_config__end', array( $this, 'set_default_reg_status_on_EEM_Event' ) ); |
|
| 2417 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2418 | 2418 | } |
| 2419 | 2419 | |
| 2420 | 2420 | |
@@ -2423,7 +2423,7 @@ discard block |
||
| 2423 | 2423 | * @return void |
| 2424 | 2424 | */ |
| 2425 | 2425 | public function set_default_reg_status_on_EEM_Event() { |
| 2426 | - EEM_Event::set_default_reg_status( $this->default_STS_ID ); |
|
| 2426 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2427 | 2427 | } |
| 2428 | 2428 | |
| 2429 | 2429 | |
@@ -2440,7 +2440,7 @@ discard block |
||
| 2440 | 2440 | /** |
| 2441 | 2441 | * @param boolean $track_invalid_checkout_access |
| 2442 | 2442 | */ |
| 2443 | - public function set_track_invalid_checkout_access( $track_invalid_checkout_access ) { |
|
| 2443 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) { |
|
| 2444 | 2444 | $this->track_invalid_checkout_access = filter_var( |
| 2445 | 2445 | $track_invalid_checkout_access, |
| 2446 | 2446 | FILTER_VALIDATE_BOOLEAN |
@@ -2558,10 +2558,10 @@ discard block |
||
| 2558 | 2558 | * @param bool $reset |
| 2559 | 2559 | * @return string |
| 2560 | 2560 | */ |
| 2561 | - public function log_file_name( $reset = false ) { |
|
| 2562 | - if ( empty( $this->log_file_name ) || $reset ) { |
|
| 2563 | - $this->log_file_name = sanitize_key( 'espresso_log_' . md5( uniqid( '', true ) ) ) . '.txt'; |
|
| 2564 | - EE_Config::instance()->update_espresso_config( false, false ); |
|
| 2561 | + public function log_file_name($reset = false) { |
|
| 2562 | + if (empty($this->log_file_name) || $reset) { |
|
| 2563 | + $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt'; |
|
| 2564 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2565 | 2565 | } |
| 2566 | 2566 | return $this->log_file_name; |
| 2567 | 2567 | } |
@@ -2572,10 +2572,10 @@ discard block |
||
| 2572 | 2572 | * @param bool $reset |
| 2573 | 2573 | * @return string |
| 2574 | 2574 | */ |
| 2575 | - public function debug_file_name( $reset = false ) { |
|
| 2576 | - if ( empty( $this->debug_file_name ) || $reset ) { |
|
| 2577 | - $this->debug_file_name = sanitize_key( 'espresso_debug_' . md5( uniqid( '', true ) ) ) . '.txt'; |
|
| 2578 | - EE_Config::instance()->update_espresso_config( false, false ); |
|
| 2575 | + public function debug_file_name($reset = false) { |
|
| 2576 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2577 | + $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt'; |
|
| 2578 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2579 | 2579 | } |
| 2580 | 2580 | return $this->debug_file_name; |
| 2581 | 2581 | } |
@@ -2586,7 +2586,7 @@ discard block |
||
| 2586 | 2586 | * @return string |
| 2587 | 2587 | */ |
| 2588 | 2588 | public function affiliate_id() { |
| 2589 | - return ! empty( $this->affiliate_id ) ? $this->affiliate_id : 'default'; |
|
| 2589 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2590 | 2590 | } |
| 2591 | 2591 | |
| 2592 | 2592 | |
@@ -2595,7 +2595,7 @@ discard block |
||
| 2595 | 2595 | * @return boolean |
| 2596 | 2596 | */ |
| 2597 | 2597 | public function encode_session_data() { |
| 2598 | - return filter_var( $this->encode_session_data, FILTER_VALIDATE_BOOLEAN ); |
|
| 2598 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2599 | 2599 | } |
| 2600 | 2600 | |
| 2601 | 2601 | |
@@ -2603,8 +2603,8 @@ discard block |
||
| 2603 | 2603 | /** |
| 2604 | 2604 | * @param boolean $encode_session_data |
| 2605 | 2605 | */ |
| 2606 | - public function set_encode_session_data( $encode_session_data ) { |
|
| 2607 | - $this->encode_session_data = filter_var( $encode_session_data, FILTER_VALIDATE_BOOLEAN ); |
|
| 2606 | + public function set_encode_session_data($encode_session_data) { |
|
| 2607 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2608 | 2608 | } |
| 2609 | 2609 | |
| 2610 | 2610 | |
@@ -2784,21 +2784,21 @@ discard block |
||
| 2784 | 2784 | $this->use_google_maps = true; |
| 2785 | 2785 | $this->google_map_api_key = ''; |
| 2786 | 2786 | // for event details pages (reg page) |
| 2787 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2788 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2789 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2790 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2791 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2792 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2793 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2787 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2788 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2789 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2790 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2791 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2792 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2793 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2794 | 2794 | // for event list pages |
| 2795 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2796 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2797 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2798 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2799 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2800 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2801 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2795 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2796 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2797 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2798 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2799 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2800 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2801 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2802 | 2802 | } |
| 2803 | 2803 | |
| 2804 | 2804 | } |
@@ -2960,7 +2960,7 @@ discard block |
||
| 2960 | 2960 | * @return void |
| 2961 | 2961 | */ |
| 2962 | 2962 | protected function _set_php_values() { |
| 2963 | - $this->php->max_input_vars = ini_get( 'max_input_vars' ); |
|
| 2963 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 2964 | 2964 | $this->php->version = phpversion(); |
| 2965 | 2965 | } |
| 2966 | 2966 | |
@@ -2979,10 +2979,10 @@ discard block |
||
| 2979 | 2979 | * @type string $msg Any message to be displayed. |
| 2980 | 2980 | * } |
| 2981 | 2981 | */ |
| 2982 | - public function max_input_vars_limit_check( $input_count = 0 ) { |
|
| 2983 | - if ( ! empty( $this->php->max_input_vars ) |
|
| 2984 | - && ( $input_count >= $this->php->max_input_vars ) |
|
| 2985 | - && ( PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9 ) |
|
| 2982 | + public function max_input_vars_limit_check($input_count = 0) { |
|
| 2983 | + if ( ! empty($this->php->max_input_vars) |
|
| 2984 | + && ($input_count >= $this->php->max_input_vars) |
|
| 2985 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 2986 | 2986 | ) { |
| 2987 | 2987 | return sprintf( |
| 2988 | 2988 | __( |
@@ -3078,7 +3078,7 @@ discard block |
||
| 3078 | 3078 | */ |
| 3079 | 3079 | public function __construct() { |
| 3080 | 3080 | $this->payment_settings = array(); |
| 3081 | - $this->active_gateways = array( 'Invoice' => false ); |
|
| 3081 | + $this->active_gateways = array('Invoice' => false); |
|
| 3082 | 3082 | } |
| 3083 | 3083 | } |
| 3084 | 3084 | |
@@ -325,8 +325,8 @@ |
||
| 325 | 325 | //eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
| 326 | 326 | //parent folder, "/var/something/" |
| 327 | 327 | $ds = strlen($file_or_folder_path) > 1 |
| 328 | - ? strrpos($file_or_folder_path, DS, -2) |
|
| 329 | - : strlen($file_or_folder_path); |
|
| 328 | + ? strrpos($file_or_folder_path, DS, -2) |
|
| 329 | + : strlen($file_or_folder_path); |
|
| 330 | 330 | return substr($file_or_folder_path, 0, $ds + 1); |
| 331 | 331 | } |
| 332 | 332 | |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | * @ version 4.0 |
| 13 | 13 | * |
| 14 | 14 | */ |
| 15 | -require_once( EE_HELPERS . 'EEH_Base.helper.php' ); |
|
| 16 | -require_once( EE_INTERFACES . 'EEI_Interfaces.php' ); |
|
| 15 | +require_once(EE_HELPERS.'EEH_Base.helper.php'); |
|
| 16 | +require_once(EE_INTERFACES.'EEI_Interfaces.php'); |
|
| 17 | 17 | /** |
| 18 | 18 | * |
| 19 | 19 | * Class EEH_File |
@@ -52,30 +52,30 @@ discard block |
||
| 52 | 52 | * @throws EE_Error if filesystem credentials are required |
| 53 | 53 | * @return WP_Filesystem_Base |
| 54 | 54 | */ |
| 55 | - private static function _get_wp_filesystem( $filepath = null) { |
|
| 56 | - if( apply_filters( |
|
| 55 | + private static function _get_wp_filesystem($filepath = null) { |
|
| 56 | + if (apply_filters( |
|
| 57 | 57 | 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
| 58 | - $filepath && EEH_File::is_in_uploads_folder( $filepath ), |
|
| 59 | - $filepath ) ) { |
|
| 60 | - if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) { |
|
| 61 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
| 58 | + $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
| 59 | + $filepath )) { |
|
| 60 | + if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
| 61 | + require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php'); |
|
| 62 | 62 | $method = 'direct'; |
| 63 | - $wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method ); |
|
| 63 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method); |
|
| 64 | 64 | //check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
| 65 | - if ( ! defined('FS_CHMOD_DIR') ) { |
|
| 66 | - define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) ); |
|
| 65 | + if ( ! defined('FS_CHMOD_DIR')) { |
|
| 66 | + define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755)); |
|
| 67 | 67 | } |
| 68 | - if ( ! defined('FS_CHMOD_FILE') ) { |
|
| 69 | - define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) ); |
|
| 68 | + if ( ! defined('FS_CHMOD_FILE')) { |
|
| 69 | + define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644)); |
|
| 70 | 70 | } |
| 71 | - require_once( $wp_filesystem_direct_file ); |
|
| 72 | - EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() ); |
|
| 71 | + require_once($wp_filesystem_direct_file); |
|
| 72 | + EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
| 73 | 73 | } |
| 74 | 74 | return EEH_File::$_wp_filesystem_direct; |
| 75 | 75 | } |
| 76 | 76 | global $wp_filesystem; |
| 77 | 77 | // no filesystem setup ??? |
| 78 | - if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { |
|
| 78 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
| 79 | 79 | // if some eager beaver's just trying to get in there too early... |
| 80 | 80 | // let them do it, because we are one of those eager beavers! :P |
| 81 | 81 | /** |
@@ -88,34 +88,34 @@ discard block |
||
| 88 | 88 | * and there may be troubles if the WP files are owned by a different user |
| 89 | 89 | * than the server user. But both of these issues should exist in 4.4 and earlier too |
| 90 | 90 | */ |
| 91 | - if ( FALSE && ! did_action( 'wp_loaded' )) { |
|
| 91 | + if (FALSE && ! did_action('wp_loaded')) { |
|
| 92 | 92 | $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
| 93 | - if ( WP_DEBUG ) { |
|
| 94 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
| 93 | + if (WP_DEBUG) { |
|
| 94 | + $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
| 95 | 95 | } |
| 96 | - throw new EE_Error( $msg ); |
|
| 96 | + throw new EE_Error($msg); |
|
| 97 | 97 | } else { |
| 98 | 98 | // should be loaded if we are past the wp_loaded hook... |
| 99 | - if ( ! function_exists( 'WP_Filesystem' )) { |
|
| 100 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 101 | - require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
| 99 | + if ( ! function_exists('WP_Filesystem')) { |
|
| 100 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
| 101 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
| 102 | 102 | } |
| 103 | 103 | // turn on output buffering so that we can capture the credentials form |
| 104 | 104 | ob_start(); |
| 105 | - $credentials = request_filesystem_credentials( '' ); |
|
| 105 | + $credentials = request_filesystem_credentials(''); |
|
| 106 | 106 | // store credentials form for the time being |
| 107 | 107 | EEH_File::$_credentials_form = ob_get_clean(); |
| 108 | 108 | // basically check for direct or previously configured access |
| 109 | - if ( ! WP_Filesystem( $credentials ) ) { |
|
| 109 | + if ( ! WP_Filesystem($credentials)) { |
|
| 110 | 110 | // if credentials do NOT exist |
| 111 | - if ( $credentials === FALSE ) { |
|
| 112 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
| 113 | - throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
| 114 | - } elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
| 115 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
| 111 | + if ($credentials === FALSE) { |
|
| 112 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
| 113 | + throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
| 114 | + } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
| 115 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
| 116 | 116 | throw new EE_Error( |
| 117 | 117 | sprintf( |
| 118 | - __( 'WP Filesystem Error: $1%s', 'event_espresso' ), |
|
| 118 | + __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
| 119 | 119 | $wp_filesystem->errors->get_error_message() ) ); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | * display_request_filesystem_credentials_form |
| 129 | 129 | */ |
| 130 | 130 | public static function display_request_filesystem_credentials_form() { |
| 131 | - if ( ! empty( EEH_File::$_credentials_form )) { |
|
| 132 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
| 131 | + if ( ! empty(EEH_File::$_credentials_form)) { |
|
| 132 | + echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>'; |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -147,29 +147,29 @@ discard block |
||
| 147 | 147 | * @throws EE_Error if filesystem credentials are required |
| 148 | 148 | * @return bool |
| 149 | 149 | */ |
| 150 | - public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) { |
|
| 150 | + public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') { |
|
| 151 | 151 | // load WP_Filesystem and set file permissions |
| 152 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
| 153 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
| 154 | - if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) { |
|
| 155 | - $file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name; |
|
| 156 | - $file_name .= ! empty( $file_ext ) ? ' file' : ' folder'; |
|
| 152 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 153 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 154 | + if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 155 | + $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name; |
|
| 156 | + $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
| 157 | 157 | $msg = sprintf( |
| 158 | - __( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ), |
|
| 158 | + __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
| 159 | 159 | $file_name, |
| 160 | 160 | '<br />' |
| 161 | 161 | ); |
| 162 | - if ( EEH_File::exists( $full_file_path )) { |
|
| 163 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file ); |
|
| 162 | + if (EEH_File::exists($full_file_path)) { |
|
| 163 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
| 164 | 164 | } else { |
| 165 | 165 | // no file permissions means the file was not found |
| 166 | 166 | $msg .= sprintf( |
| 167 | - __( 'Please ensure the following path is correct: "%s".', 'event_espresso' ), |
|
| 167 | + __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
| 168 | 168 | $full_file_path |
| 169 | 169 | ); |
| 170 | 170 | } |
| 171 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 172 | - throw new EE_Error( $msg . '||' . $msg ); |
|
| 171 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 172 | + throw new EE_Error($msg.'||'.$msg); |
|
| 173 | 173 | } |
| 174 | 174 | return FALSE; |
| 175 | 175 | } |
@@ -187,24 +187,24 @@ discard block |
||
| 187 | 187 | * @throws EE_Error if filesystem credentials are required |
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | - private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){ |
|
| 190 | + private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') { |
|
| 191 | 191 | // load WP_Filesystem and set file permissions |
| 192 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
| 192 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 193 | 193 | // check file permissions |
| 194 | - $perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ); |
|
| 195 | - if ( $perms ) { |
|
| 194 | + $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
| 195 | + if ($perms) { |
|
| 196 | 196 | // file permissions exist, but way be set incorrectly |
| 197 | - $type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : ''; |
|
| 198 | - $type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder'; |
|
| 197 | + $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : ''; |
|
| 198 | + $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
| 199 | 199 | return sprintf( |
| 200 | - __( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ), |
|
| 200 | + __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
| 201 | 201 | $type_of_file, |
| 202 | 202 | $perms |
| 203 | 203 | ); |
| 204 | 204 | } else { |
| 205 | 205 | // file exists but file permissions could not be read ?!?! |
| 206 | 206 | return sprintf( |
| 207 | - __( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ), |
|
| 207 | + __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
| 208 | 208 | $full_file_path |
| 209 | 209 | ); |
| 210 | 210 | } |
@@ -222,35 +222,35 @@ discard block |
||
| 222 | 222 | * can't write to it |
| 223 | 223 | * @return bool false if folder isn't writable; true if it exists and is writeable, |
| 224 | 224 | */ |
| 225 | - public static function ensure_folder_exists_and_is_writable( $folder = '' ){ |
|
| 226 | - if ( empty( $folder )) { |
|
| 225 | + public static function ensure_folder_exists_and_is_writable($folder = '') { |
|
| 226 | + if (empty($folder)) { |
|
| 227 | 227 | return false; |
| 228 | 228 | } |
| 229 | 229 | // remove ending DS |
| 230 | - $folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' )); |
|
| 231 | - $parent_folder = EEH_File::get_parent_folder( $folder ); |
|
| 230 | + $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
| 231 | + $parent_folder = EEH_File::get_parent_folder($folder); |
|
| 232 | 232 | // add DS to folder |
| 233 | - $folder = EEH_File::end_with_directory_separator( $folder ); |
|
| 234 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $folder ); |
|
| 235 | - if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) { |
|
| 233 | + $folder = EEH_File::end_with_directory_separator($folder); |
|
| 234 | + $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
| 235 | + if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 236 | 236 | //ok so it doesn't exist. Does its parent? Can we write to it? |
| 237 | - if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) { |
|
| 237 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 238 | 238 | return false; |
| 239 | 239 | } |
| 240 | - if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) { |
|
| 240 | + if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
| 241 | 241 | return false; |
| 242 | 242 | } else { |
| 243 | - if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) { |
|
| 244 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 245 | - $msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder ); |
|
| 246 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder ); |
|
| 247 | - throw new EE_Error( $msg ); |
|
| 243 | + if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 244 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 245 | + $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
| 246 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
| 247 | + throw new EE_Error($msg); |
|
| 248 | 248 | } |
| 249 | 249 | return false; |
| 250 | 250 | } |
| 251 | - EEH_File::add_index_file( $folder ); |
|
| 251 | + EEH_File::add_index_file($folder); |
|
| 252 | 252 | } |
| 253 | - } elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
| 253 | + } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 254 | 254 | return false; |
| 255 | 255 | } |
| 256 | 256 | return true; |
@@ -265,15 +265,15 @@ discard block |
||
| 265 | 265 | * @throws EE_Error if filesystem credentials are required |
| 266 | 266 | * @return bool |
| 267 | 267 | */ |
| 268 | - public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){ |
|
| 268 | + public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') { |
|
| 269 | 269 | // load WP_Filesystem and set file permissions |
| 270 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_path ); |
|
| 271 | - $full_path = EEH_File::standardise_directory_separators( $full_path ); |
|
| 272 | - if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) { |
|
| 273 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 274 | - $msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder ); |
|
| 275 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path ); |
|
| 276 | - throw new EE_Error( $msg ); |
|
| 270 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
| 271 | + $full_path = EEH_File::standardise_directory_separators($full_path); |
|
| 272 | + if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
| 273 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 274 | + $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
| 275 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
| 276 | + throw new EE_Error($msg); |
|
| 277 | 277 | } |
| 278 | 278 | return FALSE; |
| 279 | 279 | } |
@@ -290,25 +290,25 @@ discard block |
||
| 290 | 290 | * @throws EE_Error if filesystem credentials are required |
| 291 | 291 | * @return bool |
| 292 | 292 | */ |
| 293 | - public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) { |
|
| 293 | + public static function ensure_file_exists_and_is_writable($full_file_path = '') { |
|
| 294 | 294 | // load WP_Filesystem and set file permissions |
| 295 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
| 296 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
| 297 | - $parent_folder = EEH_File::get_parent_folder( $full_file_path ); |
|
| 298 | - if ( ! EEH_File::exists( $full_file_path )) { |
|
| 299 | - if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) { |
|
| 295 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 296 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 297 | + $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
| 298 | + if ( ! EEH_File::exists($full_file_path)) { |
|
| 299 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 300 | 300 | return false; |
| 301 | 301 | } |
| 302 | - if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) { |
|
| 303 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 304 | - $msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path ); |
|
| 305 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
| 306 | - throw new EE_Error( $msg ); |
|
| 302 | + if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 303 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 304 | + $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
| 305 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
| 306 | + throw new EE_Error($msg); |
|
| 307 | 307 | } |
| 308 | 308 | return false; |
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | - if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) { |
|
| 311 | + if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
| 312 | 312 | return false; |
| 313 | 313 | } |
| 314 | 314 | return true; |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @param string $file_or_folder_path |
| 321 | 321 | * @return string parent folder, ENDING with a directory separator |
| 322 | 322 | */ |
| 323 | - public static function get_parent_folder( $file_or_folder_path ) { |
|
| 323 | + public static function get_parent_folder($file_or_folder_path) { |
|
| 324 | 324 | //find the last DS, ignoring a DS on the very end |
| 325 | 325 | //eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
| 326 | 326 | //parent folder, "/var/something/" |
@@ -342,12 +342,12 @@ discard block |
||
| 342 | 342 | * @throws EE_Error if filesystem credentials are required |
| 343 | 343 | * @return string |
| 344 | 344 | */ |
| 345 | - public static function get_file_contents( $full_file_path = '' ){ |
|
| 346 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
| 347 | - if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) { |
|
| 345 | + public static function get_file_contents($full_file_path = '') { |
|
| 346 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 347 | + if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
| 348 | 348 | // load WP_Filesystem and set file permissions |
| 349 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
| 350 | - return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ); |
|
| 349 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 350 | + return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
| 351 | 351 | } |
| 352 | 352 | return ''; |
| 353 | 353 | } |
@@ -362,26 +362,26 @@ discard block |
||
| 362 | 362 | * @throws EE_Error if filesystem credentials are required |
| 363 | 363 | * @return bool |
| 364 | 364 | */ |
| 365 | - public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){ |
|
| 366 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
| 367 | - $file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : ''; |
|
| 368 | - $folder = EEH_File::remove_filename_from_filepath( $full_file_path ); |
|
| 369 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
| 370 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 371 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path ); |
|
| 372 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
| 373 | - throw new EE_Error( $msg ); |
|
| 365 | + public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') { |
|
| 366 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 367 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : ''; |
|
| 368 | + $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
| 369 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 370 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 371 | + $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
| 372 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
| 373 | + throw new EE_Error($msg); |
|
| 374 | 374 | } |
| 375 | 375 | return FALSE; |
| 376 | 376 | } |
| 377 | 377 | // load WP_Filesystem and set file permissions |
| 378 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
| 378 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 379 | 379 | // write the file |
| 380 | - if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) { |
|
| 381 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 382 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path ); |
|
| 383 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' ); |
|
| 384 | - throw new EE_Error( $msg ); |
|
| 380 | + if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
| 381 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 382 | + $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
| 383 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
| 384 | + throw new EE_Error($msg); |
|
| 385 | 385 | } |
| 386 | 386 | return FALSE; |
| 387 | 387 | } |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | * @throws EE_Error if filesystem credentials are required |
| 398 | 398 | * @return boolean |
| 399 | 399 | */ |
| 400 | - public static function delete( $filepath, $recursive = false, $type = false ) { |
|
| 400 | + public static function delete($filepath, $recursive = false, $type = false) { |
|
| 401 | 401 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 402 | - return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE; |
|
| 402 | + return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -411,9 +411,9 @@ discard block |
||
| 411 | 411 | * @throws EE_Error if filesystem credentials are required |
| 412 | 412 | * @return bool |
| 413 | 413 | */ |
| 414 | - public static function exists( $full_file_path = '' ) { |
|
| 415 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
| 416 | - return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE; |
|
| 414 | + public static function exists($full_file_path = '') { |
|
| 415 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 416 | + return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE; |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | * @throws EE_Error if filesystem credentials are required |
| 427 | 427 | * @return bool |
| 428 | 428 | */ |
| 429 | - public static function is_readable( $full_file_path = '' ) { |
|
| 430 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
| 431 | - if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) { |
|
| 429 | + public static function is_readable($full_file_path = '') { |
|
| 430 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 431 | + if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 432 | 432 | return true; |
| 433 | 433 | } else { |
| 434 | 434 | return false; |
@@ -444,8 +444,8 @@ discard block |
||
| 444 | 444 | * @param string $full_file_path |
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | - public static function remove_filename_from_filepath( $full_file_path = '' ) { |
|
| 448 | - return pathinfo( $full_file_path, PATHINFO_DIRNAME ); |
|
| 447 | + public static function remove_filename_from_filepath($full_file_path = '') { |
|
| 448 | + return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
@@ -455,8 +455,8 @@ discard block |
||
| 455 | 455 | * @param string $full_file_path |
| 456 | 456 | * @return string |
| 457 | 457 | */ |
| 458 | - public static function get_filename_from_filepath( $full_file_path = '' ) { |
|
| 459 | - return pathinfo( $full_file_path, PATHINFO_BASENAME ); |
|
| 458 | + public static function get_filename_from_filepath($full_file_path = '') { |
|
| 459 | + return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -466,8 +466,8 @@ discard block |
||
| 466 | 466 | * @param string $full_file_path |
| 467 | 467 | * @return string |
| 468 | 468 | */ |
| 469 | - public static function get_file_extension( $full_file_path = '' ) { |
|
| 470 | - return pathinfo( $full_file_path, PATHINFO_EXTENSION ); |
|
| 469 | + public static function get_file_extension($full_file_path = '') { |
|
| 470 | + return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | |
@@ -478,10 +478,10 @@ discard block |
||
| 478 | 478 | * @throws EE_Error if filesystem credentials are required |
| 479 | 479 | * @return bool |
| 480 | 480 | */ |
| 481 | - public static function add_htaccess_deny_from_all( $folder = '' ) { |
|
| 482 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
| 483 | - if ( ! EEH_File::exists( $folder . '.htaccess' ) ) { |
|
| 484 | - if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) { |
|
| 481 | + public static function add_htaccess_deny_from_all($folder = '') { |
|
| 482 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
| 483 | + if ( ! EEH_File::exists($folder.'.htaccess')) { |
|
| 484 | + if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) { |
|
| 485 | 485 | return FALSE; |
| 486 | 486 | } |
| 487 | 487 | } |
@@ -495,10 +495,10 @@ discard block |
||
| 495 | 495 | * @throws EE_Error if filesystem credentials are required |
| 496 | 496 | * @return boolean |
| 497 | 497 | */ |
| 498 | - public static function add_index_file( $folder ) { |
|
| 499 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
| 500 | - if ( ! EEH_File::exists( $folder . 'index.php' ) ) { |
|
| 501 | - if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) { |
|
| 498 | + public static function add_index_file($folder) { |
|
| 499 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
| 500 | + if ( ! EEH_File::exists($folder.'index.php')) { |
|
| 501 | + if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
| 502 | 502 | return false; |
| 503 | 503 | } |
| 504 | 504 | } |
@@ -513,11 +513,11 @@ discard block |
||
| 513 | 513 | * @param string $file_path |
| 514 | 514 | * @return string |
| 515 | 515 | */ |
| 516 | - public static function get_classname_from_filepath_with_standard_filename( $file_path ){ |
|
| 516 | + public static function get_classname_from_filepath_with_standard_filename($file_path) { |
|
| 517 | 517 | //extract file from path |
| 518 | - $filename = basename( $file_path ); |
|
| 518 | + $filename = basename($file_path); |
|
| 519 | 519 | //now remove the first period and everything after |
| 520 | - $pos_of_first_period = strpos( $filename,'.' ); |
|
| 520 | + $pos_of_first_period = strpos($filename, '.'); |
|
| 521 | 521 | return substr($filename, 0, $pos_of_first_period); |
| 522 | 522 | } |
| 523 | 523 | |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | * @param string $file_path |
| 530 | 530 | * @return string |
| 531 | 531 | */ |
| 532 | - public static function standardise_directory_separators( $file_path ){ |
|
| 533 | - return str_replace( array( '\\', '/' ), DS, $file_path ); |
|
| 532 | + public static function standardise_directory_separators($file_path) { |
|
| 533 | + return str_replace(array('\\', '/'), DS, $file_path); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | |
@@ -541,8 +541,8 @@ discard block |
||
| 541 | 541 | * @param string $file_path |
| 542 | 542 | * @return string |
| 543 | 543 | */ |
| 544 | - public static function end_with_directory_separator( $file_path ){ |
|
| 545 | - return rtrim( $file_path, '/\\' ) . DS; |
|
| 544 | + public static function end_with_directory_separator($file_path) { |
|
| 545 | + return rtrim($file_path, '/\\').DS; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | |
@@ -552,8 +552,8 @@ discard block |
||
| 552 | 552 | * @param $file_path |
| 553 | 553 | * @return string |
| 554 | 554 | */ |
| 555 | - public static function standardise_and_end_with_directory_separator( $file_path ){ |
|
| 556 | - return self::end_with_directory_separator( self::standardise_directory_separators( $file_path )); |
|
| 555 | + public static function standardise_and_end_with_directory_separator($file_path) { |
|
| 556 | + return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | |
@@ -570,21 +570,21 @@ discard block |
||
| 570 | 570 | * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
| 571 | 571 | * and values are their filepaths |
| 572 | 572 | */ |
| 573 | - public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){ |
|
| 573 | + public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) { |
|
| 574 | 574 | $class_to_folder_path = array(); |
| 575 | - foreach( $folder_paths as $folder_path ){ |
|
| 576 | - $folder_path = self::standardise_and_end_with_directory_separator( $folder_path ); |
|
| 575 | + foreach ($folder_paths as $folder_path) { |
|
| 576 | + $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
| 577 | 577 | // load WP_Filesystem and set file permissions |
| 578 | - $files_in_folder = glob( $folder_path . '*' ); |
|
| 578 | + $files_in_folder = glob($folder_path.'*'); |
|
| 579 | 579 | $class_to_folder_path = array(); |
| 580 | - if ( $files_in_folder ) { |
|
| 581 | - foreach( $files_in_folder as $file_path ){ |
|
| 580 | + if ($files_in_folder) { |
|
| 581 | + foreach ($files_in_folder as $file_path) { |
|
| 582 | 582 | //only add files, not folders |
| 583 | - if ( ! is_dir( $file_path )) { |
|
| 584 | - if ( $index_numerically ) { |
|
| 583 | + if ( ! is_dir($file_path)) { |
|
| 584 | + if ($index_numerically) { |
|
| 585 | 585 | $class_to_folder_path[] = $file_path; |
| 586 | 586 | } else { |
| 587 | - $classname = self::get_classname_from_filepath_with_standard_filename( $file_path ); |
|
| 587 | + $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
| 588 | 588 | $class_to_folder_path[$classname] = $file_path; |
| 589 | 589 | } |
| 590 | 590 | } |
@@ -604,39 +604,39 @@ discard block |
||
| 604 | 604 | * @throws EE_Error if filesystem credentials are required |
| 605 | 605 | * @return boolean success |
| 606 | 606 | */ |
| 607 | - public static function copy( $source_file, $destination_file, $overwrite = FALSE ){ |
|
| 608 | - $full_source_path = EEH_File::standardise_directory_separators( $source_file ); |
|
| 609 | - if( ! EEH_File::exists( $full_source_path ) ){ |
|
| 610 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 611 | - $msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path ); |
|
| 612 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path ); |
|
| 613 | - throw new EE_Error( $msg ); |
|
| 607 | + public static function copy($source_file, $destination_file, $overwrite = FALSE) { |
|
| 608 | + $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
| 609 | + if ( ! EEH_File::exists($full_source_path)) { |
|
| 610 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 611 | + $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
| 612 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
| 613 | + throw new EE_Error($msg); |
|
| 614 | 614 | } |
| 615 | 615 | return FALSE; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - $full_dest_path = EEH_File::standardise_directory_separators( $destination_file ); |
|
| 619 | - $folder = EEH_File::remove_filename_from_filepath( $full_dest_path ); |
|
| 620 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
| 621 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 622 | - $msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path ); |
|
| 623 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path ); |
|
| 624 | - throw new EE_Error( $msg ); |
|
| 618 | + $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
| 619 | + $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
| 620 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 621 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 622 | + $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
| 623 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
| 624 | + throw new EE_Error($msg); |
|
| 625 | 625 | } |
| 626 | 626 | return FALSE; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | // load WP_Filesystem and set file permissions |
| 630 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file ); |
|
| 630 | + $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
| 631 | 631 | // write the file |
| 632 | 632 | if ( ! $wp_filesystem->copy( |
| 633 | - EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ), |
|
| 634 | - EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ), |
|
| 633 | + EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
| 634 | + EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
| 635 | 635 | $overwrite )) { |
| 636 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 637 | - $msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path ); |
|
| 638 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' ); |
|
| 639 | - throw new EE_Error( $msg ); |
|
| 636 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 637 | + $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
| 638 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
| 639 | + throw new EE_Error($msg); |
|
| 640 | 640 | } |
| 641 | 641 | return FALSE; |
| 642 | 642 | } |
@@ -648,9 +648,9 @@ discard block |
||
| 648 | 648 | * @param string $filepath |
| 649 | 649 | * @return boolean |
| 650 | 650 | */ |
| 651 | - public static function is_in_uploads_folder( $filepath ) { |
|
| 651 | + public static function is_in_uploads_folder($filepath) { |
|
| 652 | 652 | $uploads = wp_upload_dir(); |
| 653 | - return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false; |
|
| 653 | + return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -665,9 +665,9 @@ discard block |
||
| 665 | 665 | * @return string the remote filepath (eg the filepath the filesystem method, eg |
| 666 | 666 | * ftp or ssh, will use to access the folder |
| 667 | 667 | */ |
| 668 | - public static function convert_local_filepath_to_remote_filepath( $local_filepath ) { |
|
| 669 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath ); |
|
| 670 | - return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath ); |
|
| 668 | + public static function convert_local_filepath_to_remote_filepath($local_filepath) { |
|
| 669 | + $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
| 670 | + return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath); |
|
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | 673 | // End of file EEH_File.helper.php |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
| 119 | 119 | $timezone_string = $timezone_string !== false |
| 120 | - ? $timezone_string |
|
| 121 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list( $gmt_offset ); |
|
| 120 | + ? $timezone_string |
|
| 121 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list( $gmt_offset ); |
|
| 122 | 122 | return $timezone_string; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -819,7 +819,6 @@ discard block |
||
| 819 | 819 | |
| 820 | 820 | |
| 821 | 821 | /** |
| 822 | - |
|
| 823 | 822 | * |
| 824 | 823 | * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
| 825 | 824 | * very next day then this method will return true. |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | * @return string |
| 54 | 54 | * @throws \EE_Error |
| 55 | 55 | */ |
| 56 | - public static function get_valid_timezone_string( $timezone_string = '' ) { |
|
| 56 | + public static function get_valid_timezone_string($timezone_string = '') { |
|
| 57 | 57 | // if passed a value, then use that, else get WP option |
| 58 | - $timezone_string = ! empty( $timezone_string ) ? $timezone_string : get_option( 'timezone_string' ); |
|
| 58 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 59 | 59 | // value from above exists, use that, else get timezone string from gmt_offset |
| 60 | - $timezone_string = ! empty( $timezone_string ) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 61 | - EEH_DTT_Helper::validate_timezone( $timezone_string ); |
|
| 60 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 61 | + EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 62 | 62 | return $timezone_string; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -74,18 +74,18 @@ discard block |
||
| 74 | 74 | * @return bool |
| 75 | 75 | * @throws \EE_Error |
| 76 | 76 | */ |
| 77 | - public static function validate_timezone( $timezone_string, $throw_error = true ) { |
|
| 77 | + public static function validate_timezone($timezone_string, $throw_error = true) { |
|
| 78 | 78 | // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it |
| 79 | 79 | try { |
| 80 | - new DateTimeZone( $timezone_string ); |
|
| 81 | - } catch ( Exception $e ) { |
|
| 80 | + new DateTimeZone($timezone_string); |
|
| 81 | + } catch (Exception $e) { |
|
| 82 | 82 | // sometimes we take exception to exceptions |
| 83 | - if ( ! $throw_error ) { |
|
| 83 | + if ( ! $throw_error) { |
|
| 84 | 84 | return false; |
| 85 | 85 | } |
| 86 | 86 | throw new EE_Error( |
| 87 | 87 | sprintf( |
| 88 | - __( 'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso' ), |
|
| 88 | + __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso'), |
|
| 89 | 89 | $timezone_string, |
| 90 | 90 | '<a href="http://www.php.net/manual/en/timezones.php">', |
| 91 | 91 | '</a>' |
@@ -104,21 +104,21 @@ discard block |
||
| 104 | 104 | * @param string $gmt_offset |
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | - public static function get_timezone_string_from_gmt_offset( $gmt_offset = '' ) { |
|
| 107 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') { |
|
| 108 | 108 | $timezone_string = 'UTC'; |
| 109 | - $gmt_offset = ! empty( $gmt_offset ) ? $gmt_offset : get_option( 'gmt_offset' ); |
|
| 110 | - if ( $gmt_offset !== '' ) { |
|
| 109 | + $gmt_offset = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset'); |
|
| 110 | + if ($gmt_offset !== '') { |
|
| 111 | 111 | // convert GMT offset to seconds |
| 112 | 112 | $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
| 113 | 113 | // account for WP offsets that aren't valid UTC |
| 114 | - $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets( $gmt_offset ); |
|
| 114 | + $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset); |
|
| 115 | 115 | // although we don't know the TZ abbreviation, we know the UTC offset |
| 116 | - $timezone_string = timezone_name_from_abbr( null, $gmt_offset ); |
|
| 116 | + $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 117 | 117 | } |
| 118 | 118 | // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
| 119 | 119 | $timezone_string = $timezone_string !== false |
| 120 | 120 | ? $timezone_string |
| 121 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list( $gmt_offset ); |
|
| 121 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 122 | 122 | return $timezone_string; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | * @return int seconds offset |
| 130 | 130 | */ |
| 131 | 131 | public static function get_site_timezone_gmt_offset() { |
| 132 | - $timezone_string = get_option( 'timezone_string' ); |
|
| 133 | - if ( $timezone_string ) { |
|
| 132 | + $timezone_string = get_option('timezone_string'); |
|
| 133 | + if ($timezone_string) { |
|
| 134 | 134 | try { |
| 135 | - $timezone = new DateTimeZone( $timezone_string ); |
|
| 136 | - return $timezone->getOffset( new DateTime() ); //in WordPress DateTime defaults to UTC |
|
| 137 | - } catch( Exception $e ){} |
|
| 135 | + $timezone = new DateTimeZone($timezone_string); |
|
| 136 | + return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 137 | + } catch (Exception $e) {} |
|
| 138 | 138 | } |
| 139 | - $offset = get_option( 'gmt_offset' ); |
|
| 140 | - return (int) ( $offset * HOUR_IN_SECONDS ); |
|
| 139 | + $offset = get_option('gmt_offset'); |
|
| 140 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -149,10 +149,10 @@ discard block |
||
| 149 | 149 | * @param int $gmt_offset |
| 150 | 150 | * @return int |
| 151 | 151 | */ |
| 152 | - public static function adjust_invalid_gmt_offsets( $gmt_offset = 0 ) { |
|
| 152 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) { |
|
| 153 | 153 | //make sure $gmt_offset is int |
| 154 | 154 | $gmt_offset = (int) $gmt_offset; |
| 155 | - switch ( $gmt_offset ) { |
|
| 155 | + switch ($gmt_offset) { |
|
| 156 | 156 | |
| 157 | 157 | // case -30600 : |
| 158 | 158 | // $gmt_offset = -28800; |
@@ -204,13 +204,13 @@ discard block |
||
| 204 | 204 | * @return string |
| 205 | 205 | * @throws \EE_Error |
| 206 | 206 | */ |
| 207 | - public static function get_timezone_string_from_abbreviations_list( $gmt_offset = 0 ) { |
|
| 207 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0) { |
|
| 208 | 208 | $abbreviations = timezone_abbreviations_list(); |
| 209 | - foreach ( $abbreviations as $abbreviation ) { |
|
| 210 | - foreach ( $abbreviation as $city ) { |
|
| 211 | - if ( $city['offset'] === $gmt_offset && $city['dst'] === FALSE ) { |
|
| 209 | + foreach ($abbreviations as $abbreviation) { |
|
| 210 | + foreach ($abbreviation as $city) { |
|
| 211 | + if ($city['offset'] === $gmt_offset && $city['dst'] === FALSE) { |
|
| 212 | 212 | // check if the timezone is valid but don't throw any errors if it isn't |
| 213 | - if ( EEH_DTT_Helper::validate_timezone( $city['timezone_id'], false ) ) { |
|
| 213 | + if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) { |
|
| 214 | 214 | return $city['timezone_id']; |
| 215 | 215 | } |
| 216 | 216 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | throw new EE_Error( |
| 220 | 220 | sprintf( |
| 221 | - __( 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso' ), |
|
| 221 | + __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso'), |
|
| 222 | 222 | $gmt_offset, |
| 223 | 223 | '<a href="http://www.php.net/manual/en/timezones.php">', |
| 224 | 224 | '</a>' |
@@ -232,23 +232,23 @@ discard block |
||
| 232 | 232 | * @access public |
| 233 | 233 | * @param string $timezone_string |
| 234 | 234 | */ |
| 235 | - public static function timezone_select_input( $timezone_string = '' ) { |
|
| 235 | + public static function timezone_select_input($timezone_string = '') { |
|
| 236 | 236 | // get WP date time format |
| 237 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 237 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
| 238 | 238 | // if passed a value, then use that, else get WP option |
| 239 | - $timezone_string = ! empty( $timezone_string ) ? $timezone_string : get_option( 'timezone_string' ); |
|
| 239 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 240 | 240 | // check if the timezone is valid but don't throw any errors if it isn't |
| 241 | - $timezone_string = EEH_DTT_Helper::validate_timezone( $timezone_string, false ); |
|
| 241 | + $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 242 | 242 | $gmt_offset = get_option('gmt_offset'); |
| 243 | 243 | |
| 244 | 244 | $check_zone_info = true; |
| 245 | - if ( empty( $timezone_string )) { |
|
| 245 | + if (empty($timezone_string)) { |
|
| 246 | 246 | // Create a UTC+- zone if no timezone string exists |
| 247 | 247 | $check_zone_info = false; |
| 248 | - if ( $gmt_offset > 0 ) { |
|
| 249 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 250 | - } elseif ( $gmt_offset < 0 ) { |
|
| 251 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 248 | + if ($gmt_offset > 0) { |
|
| 249 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
| 250 | + } elseif ($gmt_offset < 0) { |
|
| 251 | + $timezone_string = 'UTC'.$gmt_offset; |
|
| 252 | 252 | } else { |
| 253 | 253 | $timezone_string = 'UTC'; |
| 254 | 254 | } |
@@ -270,11 +270,11 @@ discard block |
||
| 270 | 270 | __('%1$sUTC%2$s time is %3$s'), |
| 271 | 271 | '<abbr title="Coordinated Universal Time">', |
| 272 | 272 | '</abbr>', |
| 273 | - '<code>' . date_i18n( $datetime_format , false, true ) . '</code>' |
|
| 273 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
| 274 | 274 | ); |
| 275 | 275 | ?></span> |
| 276 | - <?php if ( ! empty( $timezone_string ) || ! empty( $gmt_offset )) : ?> |
|
| 277 | - <br /><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n( $datetime_format ) . '</code>' ); ?></span> |
|
| 276 | + <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 277 | + <br /><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
| 278 | 278 | <?php endif; ?> |
| 279 | 279 | |
| 280 | 280 | <?php if ($check_zone_info && $timezone_string) : ?> |
@@ -306,10 +306,9 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | if ($found) { |
| 308 | 308 | $message = $tr['isdst'] ? |
| 309 | - __(' Daylight saving time begins on: %s.' ) : |
|
| 310 | - __(' Standard time begins on: %s.'); |
|
| 309 | + __(' Daylight saving time begins on: %s.') : __(' Standard time begins on: %s.'); |
|
| 311 | 310 | // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
| 312 | - printf( $message, '<code >' . date_i18n( $datetime_format, $tr['ts'] + ( $tz_offset - $tr['offset'] ) ). '</code >' ); |
|
| 311 | + printf($message, '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'); |
|
| 313 | 312 | } else { |
| 314 | 313 | _e('This timezone does not observe daylight saving time.'); |
| 315 | 314 | } |
@@ -339,14 +338,14 @@ discard block |
||
| 339 | 338 | * |
| 340 | 339 | * @return int $unix_timestamp with the offset applied for the given timezone. |
| 341 | 340 | */ |
| 342 | - public static function get_timestamp_with_offset( $unix_timestamp = 0, $timezone_string = '' ) { |
|
| 341 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') { |
|
| 343 | 342 | $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
| 344 | - $timezone_string = self::get_valid_timezone_string( $timezone_string ); |
|
| 345 | - $TimeZone = new DateTimeZone( $timezone_string ); |
|
| 343 | + $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 344 | + $TimeZone = new DateTimeZone($timezone_string); |
|
| 346 | 345 | |
| 347 | - $DateTime = new DateTime( '@' . $unix_timestamp, $TimeZone ); |
|
| 348 | - $offset = timezone_offset_get( $TimeZone, $DateTime ); |
|
| 349 | - return (int)$DateTime->format( 'U' ) + (int)$offset; |
|
| 346 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
| 347 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 348 | + return (int) $DateTime->format('U') + (int) $offset; |
|
| 350 | 349 | } |
| 351 | 350 | |
| 352 | 351 | |
@@ -361,17 +360,17 @@ discard block |
||
| 361 | 360 | * @param string $datetime_field_name the datetime fieldname to be manipulated |
| 362 | 361 | * @return EE_Base_Class |
| 363 | 362 | */ |
| 364 | - protected static function _set_date_time_field( EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name ) { |
|
| 363 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) { |
|
| 365 | 364 | // grab current datetime format |
| 366 | 365 | $current_format = $obj->get_format(); |
| 367 | 366 | // set new full timestamp format |
| 368 | - $obj->set_date_format( EE_Datetime_Field::mysql_date_format ); |
|
| 369 | - $obj->set_time_format( EE_Datetime_Field::mysql_time_format ); |
|
| 367 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 368 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 370 | 369 | // set the new date value using a full timestamp format so that no data is lost |
| 371 | - $obj->set( $datetime_field_name, $DateTime->format( EE_Datetime_Field::mysql_timestamp_format ) ); |
|
| 370 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 372 | 371 | // reset datetime formats |
| 373 | - $obj->set_date_format( $current_format[0] ); |
|
| 374 | - $obj->set_time_format( $current_format[1] ); |
|
| 372 | + $obj->set_date_format($current_format[0]); |
|
| 373 | + $obj->set_time_format($current_format[1]); |
|
| 375 | 374 | return $obj; |
| 376 | 375 | } |
| 377 | 376 | |
@@ -388,11 +387,11 @@ discard block |
||
| 388 | 387 | * @param integer $value what you want to increment the time by |
| 389 | 388 | * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it (chaining) |
| 390 | 389 | */ |
| 391 | - public static function date_time_add( EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1 ) { |
|
| 390 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) { |
|
| 392 | 391 | //get the raw UTC date. |
| 393 | - $DateTime = $obj->get_DateTime_object( $datetime_field_name ); |
|
| 394 | - $DateTime = EEH_DTT_Helper::calc_date( $DateTime, $period, $value ); |
|
| 395 | - return EEH_DTT_Helper::_set_date_time_field( $obj, $DateTime, $datetime_field_name ); |
|
| 392 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 393 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 394 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 396 | 395 | } |
| 397 | 396 | |
| 398 | 397 | |
@@ -407,11 +406,11 @@ discard block |
||
| 407 | 406 | * @param int $value |
| 408 | 407 | * @return \EE_Base_Class |
| 409 | 408 | */ |
| 410 | - public static function date_time_subtract( EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1 ) { |
|
| 409 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) { |
|
| 411 | 410 | //get the raw UTC date |
| 412 | - $DateTime = $obj->get_DateTime_object( $datetime_field_name ); |
|
| 413 | - $DateTime = EEH_DTT_Helper::calc_date( $DateTime, $period, $value, '-' ); |
|
| 414 | - return EEH_DTT_Helper::_set_date_time_field( $obj, $DateTime, $datetime_field_name ); |
|
| 411 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 412 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 413 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 415 | 414 | } |
| 416 | 415 | |
| 417 | 416 | |
@@ -424,44 +423,44 @@ discard block |
||
| 424 | 423 | * @return \DateTime return whatever type came in. |
| 425 | 424 | * @throws \EE_Error |
| 426 | 425 | */ |
| 427 | - protected static function _modify_datetime_object( DateTime $DateTime, $period = 'years', $value = 1, $operand = '+' ) { |
|
| 428 | - if ( ! $DateTime instanceof DateTime ) { |
|
| 426 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') { |
|
| 427 | + if ( ! $DateTime instanceof DateTime) { |
|
| 429 | 428 | throw new EE_Error( |
| 430 | 429 | sprintf( |
| 431 | - __( 'Expected a PHP DateTime object, but instead received %1$s', 'event_espresso' ), |
|
| 432 | - print_r( $DateTime, true ) |
|
| 430 | + __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 431 | + print_r($DateTime, true) |
|
| 433 | 432 | ) |
| 434 | 433 | ); |
| 435 | 434 | } |
| 436 | - switch ( $period ) { |
|
| 435 | + switch ($period) { |
|
| 437 | 436 | case 'years' : |
| 438 | - $value = 'P' . $value . 'Y'; |
|
| 437 | + $value = 'P'.$value.'Y'; |
|
| 439 | 438 | break; |
| 440 | 439 | case 'months' : |
| 441 | - $value = 'P' . $value . 'M'; |
|
| 440 | + $value = 'P'.$value.'M'; |
|
| 442 | 441 | break; |
| 443 | 442 | case 'weeks' : |
| 444 | - $value = 'P' . $value . 'W'; |
|
| 443 | + $value = 'P'.$value.'W'; |
|
| 445 | 444 | break; |
| 446 | 445 | case 'days' : |
| 447 | - $value = 'P' . $value . 'D'; |
|
| 446 | + $value = 'P'.$value.'D'; |
|
| 448 | 447 | break; |
| 449 | 448 | case 'hours' : |
| 450 | - $value = 'PT' . $value . 'H'; |
|
| 449 | + $value = 'PT'.$value.'H'; |
|
| 451 | 450 | break; |
| 452 | 451 | case 'minutes' : |
| 453 | - $value = 'PT' . $value . 'M'; |
|
| 452 | + $value = 'PT'.$value.'M'; |
|
| 454 | 453 | break; |
| 455 | 454 | case 'seconds' : |
| 456 | - $value = 'PT' . $value . 'S'; |
|
| 455 | + $value = 'PT'.$value.'S'; |
|
| 457 | 456 | break; |
| 458 | 457 | } |
| 459 | - switch ( $operand ) { |
|
| 458 | + switch ($operand) { |
|
| 460 | 459 | case '+': |
| 461 | - $DateTime->add( new DateInterval( $value ) ); |
|
| 460 | + $DateTime->add(new DateInterval($value)); |
|
| 462 | 461 | break; |
| 463 | 462 | case '-': |
| 464 | - $DateTime->sub( new DateInterval( $value ) ); |
|
| 463 | + $DateTime->sub(new DateInterval($value)); |
|
| 465 | 464 | break; |
| 466 | 465 | } |
| 467 | 466 | return $DateTime; |
@@ -477,16 +476,16 @@ discard block |
||
| 477 | 476 | * @return \DateTime return whatever type came in. |
| 478 | 477 | * @throws \EE_Error |
| 479 | 478 | */ |
| 480 | - protected static function _modify_timestamp( $timestamp, $period = 'years', $value = 1, $operand = '+' ) { |
|
| 481 | - if ( ! preg_match( EE_Datetime_Field::unix_timestamp_regex, $timestamp ) ) { |
|
| 479 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') { |
|
| 480 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 482 | 481 | throw new EE_Error( |
| 483 | 482 | sprintf( |
| 484 | - __( 'Expected a Unix timestamp, but instead received %1$s', 'event_espresso' ), |
|
| 485 | - print_r( $timestamp, true ) |
|
| 483 | + __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 484 | + print_r($timestamp, true) |
|
| 486 | 485 | ) |
| 487 | 486 | ); |
| 488 | 487 | } |
| 489 | - switch ( $period ) { |
|
| 488 | + switch ($period) { |
|
| 490 | 489 | case 'years' : |
| 491 | 490 | $value = YEAR_IN_SECONDS * $value; |
| 492 | 491 | break; |
@@ -506,9 +505,9 @@ discard block |
||
| 506 | 505 | $value = MINUTE_IN_SECONDS * $value; |
| 507 | 506 | break; |
| 508 | 507 | } |
| 509 | - switch ( $operand ) { |
|
| 508 | + switch ($operand) { |
|
| 510 | 509 | case '+': |
| 511 | - $timestamp += $value; |
|
| 510 | + $timestamp += $value; |
|
| 512 | 511 | break; |
| 513 | 512 | case '-': |
| 514 | 513 | $timestamp -= $value; |
@@ -528,11 +527,11 @@ discard block |
||
| 528 | 527 | * @param string $operand What operand you wish to use for the calculation |
| 529 | 528 | * @return mixed string|DateTime return whatever type came in. |
| 530 | 529 | */ |
| 531 | - public static function calc_date( $DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+' ) { |
|
| 532 | - if ( $DateTime_or_timestamp instanceof DateTime ) { |
|
| 533 | - return EEH_DTT_Helper::_modify_datetime_object( $DateTime_or_timestamp, $period, $value, $operand ); |
|
| 534 | - } else if ( preg_match( EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp )) { |
|
| 535 | - return EEH_DTT_Helper::_modify_timestamp( $DateTime_or_timestamp, $period, $value, $operand ); |
|
| 530 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') { |
|
| 531 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 532 | + return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 533 | + } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 534 | + return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 536 | 535 | } else { |
| 537 | 536 | //error |
| 538 | 537 | return $DateTime_or_timestamp; |
@@ -562,24 +561,24 @@ discard block |
||
| 562 | 561 | * 'moment' => //date and time format. |
| 563 | 562 | * ) |
| 564 | 563 | */ |
| 565 | - public static function convert_php_to_js_and_moment_date_formats( $date_format_string = null, $time_format_string = null ) { |
|
| 566 | - if ( $date_format_string === null ) { |
|
| 567 | - $date_format_string = get_option( 'date_format' ); |
|
| 564 | + public static function convert_php_to_js_and_moment_date_formats($date_format_string = null, $time_format_string = null) { |
|
| 565 | + if ($date_format_string === null) { |
|
| 566 | + $date_format_string = get_option('date_format'); |
|
| 568 | 567 | } |
| 569 | 568 | |
| 570 | - if ( $time_format_string === null ) { |
|
| 571 | - $time_format_string = get_option( 'time_format' ); |
|
| 569 | + if ($time_format_string === null) { |
|
| 570 | + $time_format_string = get_option('time_format'); |
|
| 572 | 571 | } |
| 573 | 572 | |
| 574 | - $date_format = self::_php_to_js_moment_converter( $date_format_string ); |
|
| 575 | - $time_format = self::_php_to_js_moment_converter( $time_format_string ); |
|
| 573 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 574 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 576 | 575 | |
| 577 | 576 | return array( |
| 578 | 577 | 'js' => array( |
| 579 | 578 | 'date' => $date_format['js'], |
| 580 | 579 | 'time' => $time_format['js'] |
| 581 | 580 | ), |
| 582 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment' ] |
|
| 581 | + 'moment' => $date_format['moment'].' '.$time_format['moment'] |
|
| 583 | 582 | ); |
| 584 | 583 | } |
| 585 | 584 | |
@@ -593,7 +592,7 @@ discard block |
||
| 593 | 592 | * |
| 594 | 593 | * @return array js and moment formats. |
| 595 | 594 | */ |
| 596 | - protected static function _php_to_js_moment_converter( $format_string ) { |
|
| 595 | + protected static function _php_to_js_moment_converter($format_string) { |
|
| 597 | 596 | /** |
| 598 | 597 | * This is a map of symbols for formats. |
| 599 | 598 | * The index is the php symbol, the equivalent values are in the array. |
@@ -750,15 +749,15 @@ discard block |
||
| 750 | 749 | $jquery_ui_format = ""; |
| 751 | 750 | $moment_format = ""; |
| 752 | 751 | $escaping = false; |
| 753 | - for ( $i = 0; $i < strlen($format_string); $i++ ) { |
|
| 752 | + for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 754 | 753 | $char = $format_string[$i]; |
| 755 | - if ( $char === '\\' ) { // PHP date format escaping character |
|
| 754 | + if ($char === '\\') { // PHP date format escaping character |
|
| 756 | 755 | $i++; |
| 757 | - if ( $escaping ) { |
|
| 756 | + if ($escaping) { |
|
| 758 | 757 | $jquery_ui_format .= $format_string[$i]; |
| 759 | 758 | $moment_format .= $format_string[$i]; |
| 760 | 759 | } else { |
| 761 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 760 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
| 762 | 761 | $moment_format .= $format_string[$i]; |
| 763 | 762 | } |
| 764 | 763 | $escaping = true; |
@@ -777,7 +776,7 @@ discard block |
||
| 777 | 776 | } |
| 778 | 777 | } |
| 779 | 778 | } |
| 780 | - return array( 'js' => $jquery_ui_format, 'moment' => $moment_format ); |
|
| 779 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 781 | 780 | } |
| 782 | 781 | |
| 783 | 782 | |
@@ -792,25 +791,25 @@ discard block |
||
| 792 | 791 | * errors is returned. So for client code calling, check for is_array() to |
| 793 | 792 | * indicate failed validations. |
| 794 | 793 | */ |
| 795 | - public static function validate_format_string( $format_string ) { |
|
| 794 | + public static function validate_format_string($format_string) { |
|
| 796 | 795 | $error_msg = array(); |
| 797 | 796 | //time format checks |
| 798 | - switch ( true ) { |
|
| 799 | - case strpos( $format_string, 'h' ) !== false : |
|
| 800 | - case strpos( $format_string, 'g' ) !== false : |
|
| 797 | + switch (true) { |
|
| 798 | + case strpos($format_string, 'h') !== false : |
|
| 799 | + case strpos($format_string, 'g') !== false : |
|
| 801 | 800 | /** |
| 802 | 801 | * if the time string has a lowercase 'h' which == 12 hour time format and there |
| 803 | 802 | * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
| 804 | 803 | * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
| 805 | 804 | */ |
| 806 | - if ( strpos( strtoupper( $format_string ), 'A' ) === false ) { |
|
| 807 | - $error_msg[] = __('There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', 'event_espresso' ); |
|
| 805 | + if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 806 | + $error_msg[] = __('There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', 'event_espresso'); |
|
| 808 | 807 | } |
| 809 | 808 | break; |
| 810 | 809 | |
| 811 | 810 | } |
| 812 | 811 | |
| 813 | - return empty( $error_msg ) ? true : $error_msg; |
|
| 812 | + return empty($error_msg) ? true : $error_msg; |
|
| 814 | 813 | } |
| 815 | 814 | |
| 816 | 815 | |
@@ -832,11 +831,11 @@ discard block |
||
| 832 | 831 | * @param mixed $date_2 |
| 833 | 832 | * @return bool |
| 834 | 833 | */ |
| 835 | - public static function dates_represent_one_24_hour_date( $date_1, $date_2 ) { |
|
| 834 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) { |
|
| 836 | 835 | |
| 837 | 836 | if ( |
| 838 | - ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime ) || |
|
| 839 | - ( $date_1->format( EE_Datetime_Field::mysql_time_format ) != '00:00:00' || $date_2->format( EE_Datetime_Field::mysql_time_format ) != '00:00:00' ) |
|
| 837 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 838 | + ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 840 | 839 | ) { |
| 841 | 840 | return false; |
| 842 | 841 | } |
@@ -853,11 +852,11 @@ discard block |
||
| 853 | 852 | * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
| 854 | 853 | * @return string |
| 855 | 854 | */ |
| 856 | - public static function get_sql_query_interval_for_offset( $timezone_string, $field_for_interval ) { |
|
| 855 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) { |
|
| 857 | 856 | try { |
| 858 | 857 | /** need to account for timezone offset on the selects */ |
| 859 | - $DateTimeZone = new DateTimeZone( $timezone_string ); |
|
| 860 | - } catch ( Exception $e ) { |
|
| 858 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 859 | + } catch (Exception $e) { |
|
| 861 | 860 | $DateTimeZone = null; |
| 862 | 861 | } |
| 863 | 862 | |
@@ -865,10 +864,10 @@ discard block |
||
| 865 | 864 | * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
| 866 | 865 | * Hence we do the calc for DateTimeZone::getOffset. |
| 867 | 866 | */ |
| 868 | - $offset = $DateTimeZone instanceof DateTimeZone ? ( $DateTimeZone->getOffset( new DateTime('now') ) ) / HOUR_IN_SECONDS : get_option( 'gmt_offset' ); |
|
| 867 | + $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 869 | 868 | $query_interval = $offset < 0 |
| 870 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset*-1 . ' HOUR)' |
|
| 871 | - : 'DATE_ADD(' . $field_for_interval .', INTERVAL ' . $offset . ' HOUR)'; |
|
| 869 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
| 870 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
| 872 | 871 | return $query_interval; |
| 873 | 872 | } |
| 874 | 873 | |
@@ -880,47 +879,47 @@ discard block |
||
| 880 | 879 | * @return string |
| 881 | 880 | */ |
| 882 | 881 | public static function get_timezone_string_for_display() { |
| 883 | - $pretty_timezone = apply_filters( 'FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '' ); |
|
| 884 | - if( ! empty( $pretty_timezone ) ) { |
|
| 885 | - return esc_html( $pretty_timezone ); |
|
| 882 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 883 | + if ( ! empty($pretty_timezone)) { |
|
| 884 | + return esc_html($pretty_timezone); |
|
| 886 | 885 | } |
| 887 | - $timezone_string = get_option( 'timezone_string' ); |
|
| 888 | - if( $timezone_string ) { |
|
| 886 | + $timezone_string = get_option('timezone_string'); |
|
| 887 | + if ($timezone_string) { |
|
| 889 | 888 | static $mo_loaded = false; |
| 890 | 889 | // Load translations for continents and cities just like wp_timezone_choice does |
| 891 | - if ( ! $mo_loaded ) { |
|
| 890 | + if ( ! $mo_loaded) { |
|
| 892 | 891 | $locale = get_locale(); |
| 893 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 894 | - load_textdomain( 'continents-cities', $mofile ); |
|
| 892 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
| 893 | + load_textdomain('continents-cities', $mofile); |
|
| 895 | 894 | $mo_loaded = true; |
| 896 | 895 | } |
| 897 | 896 | //well that was easy. |
| 898 | - $parts = explode('/', $timezone_string ); |
|
| 897 | + $parts = explode('/', $timezone_string); |
|
| 899 | 898 | //remove the continent |
| 900 | - unset( $parts[0] ); |
|
| 899 | + unset($parts[0]); |
|
| 901 | 900 | $t_parts = array(); |
| 902 | - foreach( $parts as $part ) { |
|
| 903 | - $t_parts[] = translate( str_replace( '_', ' ', $part ), 'continents-cities' ); |
|
| 901 | + foreach ($parts as $part) { |
|
| 902 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 904 | 903 | } |
| 905 | - return implode( ' - ', $t_parts ); |
|
| 904 | + return implode(' - ', $t_parts); |
|
| 906 | 905 | } |
| 907 | 906 | //they haven't set the timezone string, so let's return a string like "UTC+1" |
| 908 | - $gmt_offset = get_option( 'gmt_offset' ); |
|
| 909 | - if( intval( $gmt_offset ) >= 0 ) { |
|
| 907 | + $gmt_offset = get_option('gmt_offset'); |
|
| 908 | + if (intval($gmt_offset) >= 0) { |
|
| 910 | 909 | $prefix = '+'; |
| 911 | 910 | } else { |
| 912 | 911 | $prefix = ''; |
| 913 | 912 | } |
| 914 | - $parts = explode( '.', (string) $gmt_offset ); |
|
| 915 | - if( count( $parts ) === 1 ) { |
|
| 913 | + $parts = explode('.', (string) $gmt_offset); |
|
| 914 | + if (count($parts) === 1) { |
|
| 916 | 915 | $parts[1] = '00'; |
| 917 | 916 | } else { |
| 918 | 917 | //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
| 919 | 918 | //to minutes, eg 30 or 15, respectively |
| 920 | - $hour_fraction = (float)( '0.' . $parts[1] ); |
|
| 921 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 919 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
| 920 | + $parts[1] = (string) $hour_fraction * 60; |
|
| 922 | 921 | } |
| 923 | - return sprintf( __( 'UTC%1$s', 'event_espresso' ), $prefix . implode( ':', $parts ) ); |
|
| 922 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
| 924 | 923 | } |
| 925 | 924 | |
| 926 | 925 | |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 5 | - exit('No direct script access allowed'); |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -26,485 +26,485 @@ discard block |
||
| 26 | 26 | class Model_Data_Translator |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
| 31 | - * fields that COULD contain -1; so we use null |
|
| 32 | - */ |
|
| 33 | - const ee_inf_in_rest = null; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Prepares a possible array of input values from JSON for use by the models |
|
| 39 | - * |
|
| 40 | - * @param \EE_Model_Field_Base $field_obj |
|
| 41 | - * @param mixed $original_value_maybe_array |
|
| 42 | - * @param string $requested_version |
|
| 43 | - * @param string $timezone_string treat values as being in this timezone |
|
| 44 | - * @return mixed |
|
| 45 | - * @throws \DomainException |
|
| 46 | - */ |
|
| 47 | - public static function prepare_field_values_from_json( |
|
| 48 | - $field_obj, |
|
| 49 | - $original_value_maybe_array, |
|
| 50 | - $requested_version, |
|
| 51 | - $timezone_string = 'UTC' |
|
| 52 | - ) { |
|
| 53 | - if (is_array($original_value_maybe_array)) { |
|
| 54 | - $new_value_maybe_array = array(); |
|
| 55 | - foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
| 56 | - $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json( |
|
| 57 | - $field_obj, |
|
| 58 | - $array_item, |
|
| 59 | - $requested_version, |
|
| 60 | - $timezone_string |
|
| 61 | - ); |
|
| 62 | - } |
|
| 63 | - } else { |
|
| 64 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json( |
|
| 65 | - $field_obj, |
|
| 66 | - $original_value_maybe_array, |
|
| 67 | - $requested_version, |
|
| 68 | - $timezone_string |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - return $new_value_maybe_array; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Prepares an array of field values FOR use in JSON/REST API |
|
| 78 | - * |
|
| 79 | - * @param \EE_Model_Field_Base $field_obj |
|
| 80 | - * @param mixed $original_value_maybe_array |
|
| 81 | - * @param string $request_version (eg 4.8.36) |
|
| 82 | - * @return array |
|
| 83 | - */ |
|
| 84 | - public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version) |
|
| 85 | - { |
|
| 86 | - if (is_array($original_value_maybe_array)) { |
|
| 87 | - $new_value_maybe_array = array(); |
|
| 88 | - foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
| 89 | - $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 90 | - $field_obj, |
|
| 91 | - $array_item, |
|
| 92 | - $request_version |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - } else { |
|
| 96 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json( |
|
| 97 | - $field_obj, |
|
| 98 | - $original_value_maybe_array, |
|
| 99 | - $request_version |
|
| 100 | - ); |
|
| 101 | - } |
|
| 102 | - return $new_value_maybe_array; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Prepares incoming data from the json or $_REQUEST parameters for the models' |
|
| 109 | - * "$query_params". |
|
| 110 | - * |
|
| 111 | - * @param \EE_Model_Field_Base $field_obj |
|
| 112 | - * @param mixed $original_value |
|
| 113 | - * @param string $requested_version |
|
| 114 | - * @param string $timezone_string treat values as being in this timezone |
|
| 115 | - * @return mixed |
|
| 116 | - * @throws \DomainException |
|
| 117 | - */ |
|
| 118 | - public static function prepare_field_value_from_json( |
|
| 119 | - $field_obj, |
|
| 120 | - $original_value, |
|
| 121 | - $requested_version, |
|
| 122 | - $timezone_string = 'UTC' // UTC |
|
| 123 | - ) |
|
| 124 | - { |
|
| 125 | - $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', ''); |
|
| 126 | - $new_value = null; |
|
| 127 | - if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
| 128 | - && in_array($original_value, array(null, ''), true) |
|
| 129 | - ) { |
|
| 130 | - $new_value = EE_INF; |
|
| 131 | - } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 132 | - list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset( |
|
| 133 | - $field_obj->get_timezone_offset( |
|
| 134 | - new \DateTimeZone($timezone_string) |
|
| 135 | - ) |
|
| 136 | - ); |
|
| 137 | - $offset_string = |
|
| 138 | - str_pad( |
|
| 139 | - floor($offset_secs / HOUR_IN_SECONDS), |
|
| 140 | - 2, |
|
| 141 | - '0', |
|
| 142 | - STR_PAD_LEFT |
|
| 143 | - ) |
|
| 144 | - . ':' |
|
| 145 | - . str_pad( |
|
| 146 | - ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
| 147 | - 2, |
|
| 148 | - '0', |
|
| 149 | - STR_PAD_LEFT |
|
| 150 | - ); |
|
| 151 | - $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
| 152 | - } else { |
|
| 153 | - $new_value = $original_value; |
|
| 154 | - } |
|
| 155 | - return $new_value; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * determines what's going on with them timezone strings |
|
| 162 | - * |
|
| 163 | - * @param int $timezone_offset |
|
| 164 | - * @return array |
|
| 165 | - */ |
|
| 166 | - private static function parse_timezone_offset($timezone_offset) |
|
| 167 | - { |
|
| 168 | - $first_char = substr((string)$timezone_offset, 0, 1); |
|
| 169 | - if ($first_char === '+' || $first_char === '-') { |
|
| 170 | - $offset_sign = $first_char; |
|
| 171 | - $offset_secs = substr((string)$timezone_offset, 1); |
|
| 172 | - } else { |
|
| 173 | - $offset_sign = '+'; |
|
| 174 | - $offset_secs = $timezone_offset; |
|
| 175 | - } |
|
| 176 | - return array($offset_sign, $offset_secs); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Prepares a field's value for display in the API |
|
| 183 | - * |
|
| 184 | - * @param \EE_Model_Field_Base $field_obj |
|
| 185 | - * @param mixed $original_value |
|
| 186 | - * @param string $requested_version |
|
| 187 | - * @return mixed |
|
| 188 | - */ |
|
| 189 | - public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) |
|
| 190 | - { |
|
| 191 | - if ($original_value === EE_INF) { |
|
| 192 | - $new_value = Model_Data_Translator::ee_inf_in_rest; |
|
| 193 | - } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 194 | - if ($original_value instanceof \DateTime) { |
|
| 195 | - $new_value = $original_value->format('Y-m-d H:i:s'); |
|
| 196 | - } elseif (is_int($original_value)) { |
|
| 197 | - $new_value = date('Y-m-d H:i:s', $original_value); |
|
| 198 | - } else { |
|
| 199 | - $new_value = $original_value; |
|
| 200 | - } |
|
| 201 | - $new_value = mysql_to_rfc3339($new_value); |
|
| 202 | - } else { |
|
| 203 | - $new_value = $original_value; |
|
| 204 | - } |
|
| 205 | - return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
| 206 | - $new_value, |
|
| 207 | - $field_obj, |
|
| 208 | - $original_value, |
|
| 209 | - $requested_version |
|
| 210 | - ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Prepares condition-query-parameters (like what's in where and having) from |
|
| 217 | - * the format expected in the API to use in the models |
|
| 218 | - * |
|
| 219 | - * @param array $inputted_query_params_of_this_type |
|
| 220 | - * @param \EEM_Base $model |
|
| 221 | - * @param string $requested_version |
|
| 222 | - * @return array |
|
| 223 | - * @throws \DomainException |
|
| 224 | - * @throws \EE_Error |
|
| 225 | - */ |
|
| 226 | - public static function prepare_conditions_query_params_for_models( |
|
| 227 | - $inputted_query_params_of_this_type, |
|
| 228 | - \EEM_Base $model, |
|
| 229 | - $requested_version |
|
| 230 | - ) { |
|
| 231 | - $query_param_for_models = array(); |
|
| 232 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
| 233 | - $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key); |
|
| 234 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
| 235 | - $query_param_sans_stars, |
|
| 236 | - $model |
|
| 237 | - ); |
|
| 238 | - //double-check is it a *_gmt field? |
|
| 239 | - if ( ! $field instanceof \EE_Model_Field_Base |
|
| 240 | - && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars) |
|
| 241 | - ) { |
|
| 242 | - //yep, take off '_gmt', and find the field |
|
| 243 | - $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars); |
|
| 244 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
| 245 | - $query_param_key, |
|
| 246 | - $model |
|
| 247 | - ); |
|
| 248 | - $timezone = 'UTC'; |
|
| 249 | - } else { |
|
| 250 | - //so it's not a GMT field. Set the timezone on the model to the default |
|
| 251 | - $timezone = \EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 252 | - } |
|
| 253 | - if ($field instanceof \EE_Model_Field_Base) { |
|
| 254 | - //did they specify an operator? |
|
| 255 | - if (is_array($query_param_value)) { |
|
| 256 | - $op = $query_param_value[0]; |
|
| 257 | - $translated_value = array($op); |
|
| 258 | - if (isset($query_param_value[1])) { |
|
| 259 | - $value = $query_param_value[1]; |
|
| 260 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value, |
|
| 261 | - $requested_version, $timezone); |
|
| 262 | - } |
|
| 263 | - } else { |
|
| 264 | - $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value, |
|
| 265 | - $requested_version, $timezone); |
|
| 266 | - } |
|
| 267 | - $query_param_for_models[$query_param_key] = $translated_value; |
|
| 268 | - } else { |
|
| 269 | - //so it's not for a field, assume it's a logic query param key |
|
| 270 | - $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value, |
|
| 271 | - $model, $requested_version); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - return $query_param_for_models; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
| 281 | - * gmt date field name |
|
| 282 | - * |
|
| 283 | - * @param string $field_name |
|
| 284 | - * @return boolean |
|
| 285 | - */ |
|
| 286 | - public static function is_gmt_date_field_name($field_name) |
|
| 287 | - { |
|
| 288 | - return substr( |
|
| 289 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name), |
|
| 290 | - -4, |
|
| 291 | - 4 |
|
| 292 | - ) === '_gmt'; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
| 299 | - * |
|
| 300 | - * @param string $field_name |
|
| 301 | - * @return string |
|
| 302 | - */ |
|
| 303 | - public static function remove_gmt_from_field_name($field_name) |
|
| 304 | - { |
|
| 305 | - if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
| 306 | - return $field_name; |
|
| 307 | - } |
|
| 308 | - $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name); |
|
| 309 | - $query_param_sans_gmt_and_sans_stars = substr( |
|
| 310 | - $query_param_sans_stars, |
|
| 311 | - 0, |
|
| 312 | - strrpos( |
|
| 313 | - $field_name, |
|
| 314 | - '_gmt' |
|
| 315 | - ) |
|
| 316 | - ); |
|
| 317 | - return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Takes a field name from the REST API and prepares it for the model querying |
|
| 324 | - * |
|
| 325 | - * @param string $field_name |
|
| 326 | - * @return string |
|
| 327 | - */ |
|
| 328 | - public static function prepare_field_name_from_json($field_name) |
|
| 329 | - { |
|
| 330 | - if (Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
| 331 | - return Model_Data_Translator::remove_gmt_from_field_name($field_name); |
|
| 332 | - } |
|
| 333 | - return $field_name; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Takes array of field names from REST API and prepares for models |
|
| 340 | - * |
|
| 341 | - * @param array $field_names |
|
| 342 | - * @return array of field names (possibly include model prefixes) |
|
| 343 | - */ |
|
| 344 | - public static function prepare_field_names_from_json(array $field_names) |
|
| 345 | - { |
|
| 346 | - $new_array = array(); |
|
| 347 | - foreach ($field_names as $key => $field_name) { |
|
| 348 | - $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name); |
|
| 349 | - } |
|
| 350 | - return $new_array; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Takes array where array keys are field names (possibly with model path prefixes) |
|
| 357 | - * from the REST API and prepares them for model querying |
|
| 358 | - * |
|
| 359 | - * @param array $field_names_as_keys |
|
| 360 | - * @return array |
|
| 361 | - */ |
|
| 362 | - public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys) |
|
| 363 | - { |
|
| 364 | - $new_array = array(); |
|
| 365 | - foreach ($field_names_as_keys as $field_name => $value) { |
|
| 366 | - $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value; |
|
| 367 | - } |
|
| 368 | - return $new_array; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Prepares an array of model query params for use in the REST API |
|
| 375 | - * |
|
| 376 | - * @param array $model_query_params |
|
| 377 | - * @param \EEM_Base $model |
|
| 378 | - * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
| 379 | - * REST API |
|
| 380 | - * @return array which can be passed into the EE4 REST API when querying a model resource |
|
| 381 | - * @throws \EE_Error |
|
| 382 | - */ |
|
| 383 | - public static function prepare_query_params_for_rest_api( |
|
| 384 | - array $model_query_params, |
|
| 385 | - \EEM_Base $model, |
|
| 386 | - $requested_version = null |
|
| 387 | - ) { |
|
| 388 | - if ($requested_version === null) { |
|
| 389 | - $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
| 390 | - } |
|
| 391 | - $rest_query_params = $model_query_params; |
|
| 392 | - if (isset($model_query_params[0])) { |
|
| 393 | - $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
| 394 | - $model_query_params[0], |
|
| 395 | - $model, |
|
| 396 | - $requested_version |
|
| 397 | - ); |
|
| 398 | - unset($rest_query_params[0]); |
|
| 399 | - } |
|
| 400 | - if (isset($model_query_params['having'])) { |
|
| 401 | - $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
| 402 | - $model_query_params['having'], |
|
| 403 | - $model, |
|
| 404 | - $requested_version |
|
| 405 | - ); |
|
| 406 | - } |
|
| 407 | - return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
| 408 | - $rest_query_params, $model_query_params, $model, $requested_version); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
| 415 | - * |
|
| 416 | - * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
| 417 | - * passed into EEM_Base::get_all() |
|
| 418 | - * @param \EEM_Base $model |
|
| 419 | - * @param string $requested_version eg "4.8.36" |
|
| 420 | - * @return array ready for use in the rest api query params |
|
| 421 | - * @throws \EE_Error |
|
| 422 | - */ |
|
| 423 | - public static function prepare_conditions_query_params_for_rest_api( |
|
| 424 | - $inputted_query_params_of_this_type, |
|
| 425 | - \EEM_Base $model, |
|
| 426 | - $requested_version |
|
| 427 | - ) { |
|
| 428 | - $query_param_for_models = array(); |
|
| 429 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
| 430 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
| 431 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
| 432 | - $model |
|
| 433 | - ); |
|
| 434 | - if ($field instanceof \EE_Model_Field_Base) { |
|
| 435 | - //did they specify an operator? |
|
| 436 | - if (is_array($query_param_value)) { |
|
| 437 | - $op = $query_param_value[0]; |
|
| 438 | - $translated_value = array($op); |
|
| 439 | - if (isset($query_param_value[1])) { |
|
| 440 | - $value = $query_param_value[1]; |
|
| 441 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value, |
|
| 442 | - $requested_version); |
|
| 443 | - } |
|
| 444 | - } else { |
|
| 445 | - $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value, |
|
| 446 | - $requested_version); |
|
| 447 | - } |
|
| 448 | - $query_param_for_models[$query_param_key] = $translated_value; |
|
| 449 | - } else { |
|
| 450 | - //so it's not for a field, assume it's a logic query param key |
|
| 451 | - $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value, |
|
| 452 | - $model, $requested_version); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - return $query_param_for_models; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @param $condition_query_param_key |
|
| 462 | - * @return string |
|
| 463 | - */ |
|
| 464 | - public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) |
|
| 465 | - { |
|
| 466 | - $pos_of_star = strpos($condition_query_param_key, '*'); |
|
| 467 | - if ($pos_of_star === false) { |
|
| 468 | - return $condition_query_param_key; |
|
| 469 | - } else { |
|
| 470 | - $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
|
| 471 | - return $condition_query_param_sans_star; |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * Takes the input parameter and finds the model field that it indicates. |
|
| 479 | - * |
|
| 480 | - * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
| 481 | - * @param \EEM_Base $model |
|
| 482 | - * @return \EE_Model_Field_Base |
|
| 483 | - * @throws \EE_Error |
|
| 484 | - */ |
|
| 485 | - public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) |
|
| 486 | - { |
|
| 487 | - //ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
| 488 | - //which will help us find the database table and column |
|
| 489 | - $query_param_parts = explode('.', $query_param_name); |
|
| 490 | - if (empty($query_param_parts)) { |
|
| 491 | - throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s', |
|
| 492 | - 'event_espresso'), $query_param_name)); |
|
| 493 | - } |
|
| 494 | - $number_of_parts = count($query_param_parts); |
|
| 495 | - $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
| 496 | - if ($number_of_parts === 1) { |
|
| 497 | - $field_name = $last_query_param_part; |
|
| 498 | - } else {// $number_of_parts >= 2 |
|
| 499 | - //the last part is the column name, and there are only 2parts. therefore... |
|
| 500 | - $field_name = $last_query_param_part; |
|
| 501 | - $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
| 502 | - } |
|
| 503 | - try { |
|
| 504 | - return $model->field_settings_for($field_name); |
|
| 505 | - } catch (\EE_Error $e) { |
|
| 506 | - return null; |
|
| 507 | - } |
|
| 508 | - } |
|
| 29 | + /** |
|
| 30 | + * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
| 31 | + * fields that COULD contain -1; so we use null |
|
| 32 | + */ |
|
| 33 | + const ee_inf_in_rest = null; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Prepares a possible array of input values from JSON for use by the models |
|
| 39 | + * |
|
| 40 | + * @param \EE_Model_Field_Base $field_obj |
|
| 41 | + * @param mixed $original_value_maybe_array |
|
| 42 | + * @param string $requested_version |
|
| 43 | + * @param string $timezone_string treat values as being in this timezone |
|
| 44 | + * @return mixed |
|
| 45 | + * @throws \DomainException |
|
| 46 | + */ |
|
| 47 | + public static function prepare_field_values_from_json( |
|
| 48 | + $field_obj, |
|
| 49 | + $original_value_maybe_array, |
|
| 50 | + $requested_version, |
|
| 51 | + $timezone_string = 'UTC' |
|
| 52 | + ) { |
|
| 53 | + if (is_array($original_value_maybe_array)) { |
|
| 54 | + $new_value_maybe_array = array(); |
|
| 55 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
| 56 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json( |
|
| 57 | + $field_obj, |
|
| 58 | + $array_item, |
|
| 59 | + $requested_version, |
|
| 60 | + $timezone_string |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | + } else { |
|
| 64 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json( |
|
| 65 | + $field_obj, |
|
| 66 | + $original_value_maybe_array, |
|
| 67 | + $requested_version, |
|
| 68 | + $timezone_string |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + return $new_value_maybe_array; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Prepares an array of field values FOR use in JSON/REST API |
|
| 78 | + * |
|
| 79 | + * @param \EE_Model_Field_Base $field_obj |
|
| 80 | + * @param mixed $original_value_maybe_array |
|
| 81 | + * @param string $request_version (eg 4.8.36) |
|
| 82 | + * @return array |
|
| 83 | + */ |
|
| 84 | + public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version) |
|
| 85 | + { |
|
| 86 | + if (is_array($original_value_maybe_array)) { |
|
| 87 | + $new_value_maybe_array = array(); |
|
| 88 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
| 89 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 90 | + $field_obj, |
|
| 91 | + $array_item, |
|
| 92 | + $request_version |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + } else { |
|
| 96 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json( |
|
| 97 | + $field_obj, |
|
| 98 | + $original_value_maybe_array, |
|
| 99 | + $request_version |
|
| 100 | + ); |
|
| 101 | + } |
|
| 102 | + return $new_value_maybe_array; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Prepares incoming data from the json or $_REQUEST parameters for the models' |
|
| 109 | + * "$query_params". |
|
| 110 | + * |
|
| 111 | + * @param \EE_Model_Field_Base $field_obj |
|
| 112 | + * @param mixed $original_value |
|
| 113 | + * @param string $requested_version |
|
| 114 | + * @param string $timezone_string treat values as being in this timezone |
|
| 115 | + * @return mixed |
|
| 116 | + * @throws \DomainException |
|
| 117 | + */ |
|
| 118 | + public static function prepare_field_value_from_json( |
|
| 119 | + $field_obj, |
|
| 120 | + $original_value, |
|
| 121 | + $requested_version, |
|
| 122 | + $timezone_string = 'UTC' // UTC |
|
| 123 | + ) |
|
| 124 | + { |
|
| 125 | + $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', ''); |
|
| 126 | + $new_value = null; |
|
| 127 | + if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
| 128 | + && in_array($original_value, array(null, ''), true) |
|
| 129 | + ) { |
|
| 130 | + $new_value = EE_INF; |
|
| 131 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 132 | + list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset( |
|
| 133 | + $field_obj->get_timezone_offset( |
|
| 134 | + new \DateTimeZone($timezone_string) |
|
| 135 | + ) |
|
| 136 | + ); |
|
| 137 | + $offset_string = |
|
| 138 | + str_pad( |
|
| 139 | + floor($offset_secs / HOUR_IN_SECONDS), |
|
| 140 | + 2, |
|
| 141 | + '0', |
|
| 142 | + STR_PAD_LEFT |
|
| 143 | + ) |
|
| 144 | + . ':' |
|
| 145 | + . str_pad( |
|
| 146 | + ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
| 147 | + 2, |
|
| 148 | + '0', |
|
| 149 | + STR_PAD_LEFT |
|
| 150 | + ); |
|
| 151 | + $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
| 152 | + } else { |
|
| 153 | + $new_value = $original_value; |
|
| 154 | + } |
|
| 155 | + return $new_value; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * determines what's going on with them timezone strings |
|
| 162 | + * |
|
| 163 | + * @param int $timezone_offset |
|
| 164 | + * @return array |
|
| 165 | + */ |
|
| 166 | + private static function parse_timezone_offset($timezone_offset) |
|
| 167 | + { |
|
| 168 | + $first_char = substr((string)$timezone_offset, 0, 1); |
|
| 169 | + if ($first_char === '+' || $first_char === '-') { |
|
| 170 | + $offset_sign = $first_char; |
|
| 171 | + $offset_secs = substr((string)$timezone_offset, 1); |
|
| 172 | + } else { |
|
| 173 | + $offset_sign = '+'; |
|
| 174 | + $offset_secs = $timezone_offset; |
|
| 175 | + } |
|
| 176 | + return array($offset_sign, $offset_secs); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Prepares a field's value for display in the API |
|
| 183 | + * |
|
| 184 | + * @param \EE_Model_Field_Base $field_obj |
|
| 185 | + * @param mixed $original_value |
|
| 186 | + * @param string $requested_version |
|
| 187 | + * @return mixed |
|
| 188 | + */ |
|
| 189 | + public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) |
|
| 190 | + { |
|
| 191 | + if ($original_value === EE_INF) { |
|
| 192 | + $new_value = Model_Data_Translator::ee_inf_in_rest; |
|
| 193 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 194 | + if ($original_value instanceof \DateTime) { |
|
| 195 | + $new_value = $original_value->format('Y-m-d H:i:s'); |
|
| 196 | + } elseif (is_int($original_value)) { |
|
| 197 | + $new_value = date('Y-m-d H:i:s', $original_value); |
|
| 198 | + } else { |
|
| 199 | + $new_value = $original_value; |
|
| 200 | + } |
|
| 201 | + $new_value = mysql_to_rfc3339($new_value); |
|
| 202 | + } else { |
|
| 203 | + $new_value = $original_value; |
|
| 204 | + } |
|
| 205 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
| 206 | + $new_value, |
|
| 207 | + $field_obj, |
|
| 208 | + $original_value, |
|
| 209 | + $requested_version |
|
| 210 | + ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Prepares condition-query-parameters (like what's in where and having) from |
|
| 217 | + * the format expected in the API to use in the models |
|
| 218 | + * |
|
| 219 | + * @param array $inputted_query_params_of_this_type |
|
| 220 | + * @param \EEM_Base $model |
|
| 221 | + * @param string $requested_version |
|
| 222 | + * @return array |
|
| 223 | + * @throws \DomainException |
|
| 224 | + * @throws \EE_Error |
|
| 225 | + */ |
|
| 226 | + public static function prepare_conditions_query_params_for_models( |
|
| 227 | + $inputted_query_params_of_this_type, |
|
| 228 | + \EEM_Base $model, |
|
| 229 | + $requested_version |
|
| 230 | + ) { |
|
| 231 | + $query_param_for_models = array(); |
|
| 232 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
| 233 | + $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key); |
|
| 234 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
| 235 | + $query_param_sans_stars, |
|
| 236 | + $model |
|
| 237 | + ); |
|
| 238 | + //double-check is it a *_gmt field? |
|
| 239 | + if ( ! $field instanceof \EE_Model_Field_Base |
|
| 240 | + && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars) |
|
| 241 | + ) { |
|
| 242 | + //yep, take off '_gmt', and find the field |
|
| 243 | + $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars); |
|
| 244 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
| 245 | + $query_param_key, |
|
| 246 | + $model |
|
| 247 | + ); |
|
| 248 | + $timezone = 'UTC'; |
|
| 249 | + } else { |
|
| 250 | + //so it's not a GMT field. Set the timezone on the model to the default |
|
| 251 | + $timezone = \EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 252 | + } |
|
| 253 | + if ($field instanceof \EE_Model_Field_Base) { |
|
| 254 | + //did they specify an operator? |
|
| 255 | + if (is_array($query_param_value)) { |
|
| 256 | + $op = $query_param_value[0]; |
|
| 257 | + $translated_value = array($op); |
|
| 258 | + if (isset($query_param_value[1])) { |
|
| 259 | + $value = $query_param_value[1]; |
|
| 260 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value, |
|
| 261 | + $requested_version, $timezone); |
|
| 262 | + } |
|
| 263 | + } else { |
|
| 264 | + $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value, |
|
| 265 | + $requested_version, $timezone); |
|
| 266 | + } |
|
| 267 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
| 268 | + } else { |
|
| 269 | + //so it's not for a field, assume it's a logic query param key |
|
| 270 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value, |
|
| 271 | + $model, $requested_version); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + return $query_param_for_models; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
| 281 | + * gmt date field name |
|
| 282 | + * |
|
| 283 | + * @param string $field_name |
|
| 284 | + * @return boolean |
|
| 285 | + */ |
|
| 286 | + public static function is_gmt_date_field_name($field_name) |
|
| 287 | + { |
|
| 288 | + return substr( |
|
| 289 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name), |
|
| 290 | + -4, |
|
| 291 | + 4 |
|
| 292 | + ) === '_gmt'; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
| 299 | + * |
|
| 300 | + * @param string $field_name |
|
| 301 | + * @return string |
|
| 302 | + */ |
|
| 303 | + public static function remove_gmt_from_field_name($field_name) |
|
| 304 | + { |
|
| 305 | + if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
| 306 | + return $field_name; |
|
| 307 | + } |
|
| 308 | + $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name); |
|
| 309 | + $query_param_sans_gmt_and_sans_stars = substr( |
|
| 310 | + $query_param_sans_stars, |
|
| 311 | + 0, |
|
| 312 | + strrpos( |
|
| 313 | + $field_name, |
|
| 314 | + '_gmt' |
|
| 315 | + ) |
|
| 316 | + ); |
|
| 317 | + return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Takes a field name from the REST API and prepares it for the model querying |
|
| 324 | + * |
|
| 325 | + * @param string $field_name |
|
| 326 | + * @return string |
|
| 327 | + */ |
|
| 328 | + public static function prepare_field_name_from_json($field_name) |
|
| 329 | + { |
|
| 330 | + if (Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
| 331 | + return Model_Data_Translator::remove_gmt_from_field_name($field_name); |
|
| 332 | + } |
|
| 333 | + return $field_name; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Takes array of field names from REST API and prepares for models |
|
| 340 | + * |
|
| 341 | + * @param array $field_names |
|
| 342 | + * @return array of field names (possibly include model prefixes) |
|
| 343 | + */ |
|
| 344 | + public static function prepare_field_names_from_json(array $field_names) |
|
| 345 | + { |
|
| 346 | + $new_array = array(); |
|
| 347 | + foreach ($field_names as $key => $field_name) { |
|
| 348 | + $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name); |
|
| 349 | + } |
|
| 350 | + return $new_array; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Takes array where array keys are field names (possibly with model path prefixes) |
|
| 357 | + * from the REST API and prepares them for model querying |
|
| 358 | + * |
|
| 359 | + * @param array $field_names_as_keys |
|
| 360 | + * @return array |
|
| 361 | + */ |
|
| 362 | + public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys) |
|
| 363 | + { |
|
| 364 | + $new_array = array(); |
|
| 365 | + foreach ($field_names_as_keys as $field_name => $value) { |
|
| 366 | + $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value; |
|
| 367 | + } |
|
| 368 | + return $new_array; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Prepares an array of model query params for use in the REST API |
|
| 375 | + * |
|
| 376 | + * @param array $model_query_params |
|
| 377 | + * @param \EEM_Base $model |
|
| 378 | + * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
| 379 | + * REST API |
|
| 380 | + * @return array which can be passed into the EE4 REST API when querying a model resource |
|
| 381 | + * @throws \EE_Error |
|
| 382 | + */ |
|
| 383 | + public static function prepare_query_params_for_rest_api( |
|
| 384 | + array $model_query_params, |
|
| 385 | + \EEM_Base $model, |
|
| 386 | + $requested_version = null |
|
| 387 | + ) { |
|
| 388 | + if ($requested_version === null) { |
|
| 389 | + $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
| 390 | + } |
|
| 391 | + $rest_query_params = $model_query_params; |
|
| 392 | + if (isset($model_query_params[0])) { |
|
| 393 | + $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
| 394 | + $model_query_params[0], |
|
| 395 | + $model, |
|
| 396 | + $requested_version |
|
| 397 | + ); |
|
| 398 | + unset($rest_query_params[0]); |
|
| 399 | + } |
|
| 400 | + if (isset($model_query_params['having'])) { |
|
| 401 | + $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
| 402 | + $model_query_params['having'], |
|
| 403 | + $model, |
|
| 404 | + $requested_version |
|
| 405 | + ); |
|
| 406 | + } |
|
| 407 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
| 408 | + $rest_query_params, $model_query_params, $model, $requested_version); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
| 415 | + * |
|
| 416 | + * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
| 417 | + * passed into EEM_Base::get_all() |
|
| 418 | + * @param \EEM_Base $model |
|
| 419 | + * @param string $requested_version eg "4.8.36" |
|
| 420 | + * @return array ready for use in the rest api query params |
|
| 421 | + * @throws \EE_Error |
|
| 422 | + */ |
|
| 423 | + public static function prepare_conditions_query_params_for_rest_api( |
|
| 424 | + $inputted_query_params_of_this_type, |
|
| 425 | + \EEM_Base $model, |
|
| 426 | + $requested_version |
|
| 427 | + ) { |
|
| 428 | + $query_param_for_models = array(); |
|
| 429 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
| 430 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
| 431 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
| 432 | + $model |
|
| 433 | + ); |
|
| 434 | + if ($field instanceof \EE_Model_Field_Base) { |
|
| 435 | + //did they specify an operator? |
|
| 436 | + if (is_array($query_param_value)) { |
|
| 437 | + $op = $query_param_value[0]; |
|
| 438 | + $translated_value = array($op); |
|
| 439 | + if (isset($query_param_value[1])) { |
|
| 440 | + $value = $query_param_value[1]; |
|
| 441 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value, |
|
| 442 | + $requested_version); |
|
| 443 | + } |
|
| 444 | + } else { |
|
| 445 | + $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value, |
|
| 446 | + $requested_version); |
|
| 447 | + } |
|
| 448 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
| 449 | + } else { |
|
| 450 | + //so it's not for a field, assume it's a logic query param key |
|
| 451 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value, |
|
| 452 | + $model, $requested_version); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + return $query_param_for_models; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @param $condition_query_param_key |
|
| 462 | + * @return string |
|
| 463 | + */ |
|
| 464 | + public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) |
|
| 465 | + { |
|
| 466 | + $pos_of_star = strpos($condition_query_param_key, '*'); |
|
| 467 | + if ($pos_of_star === false) { |
|
| 468 | + return $condition_query_param_key; |
|
| 469 | + } else { |
|
| 470 | + $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
|
| 471 | + return $condition_query_param_sans_star; |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * Takes the input parameter and finds the model field that it indicates. |
|
| 479 | + * |
|
| 480 | + * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
| 481 | + * @param \EEM_Base $model |
|
| 482 | + * @return \EE_Model_Field_Base |
|
| 483 | + * @throws \EE_Error |
|
| 484 | + */ |
|
| 485 | + public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) |
|
| 486 | + { |
|
| 487 | + //ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
| 488 | + //which will help us find the database table and column |
|
| 489 | + $query_param_parts = explode('.', $query_param_name); |
|
| 490 | + if (empty($query_param_parts)) { |
|
| 491 | + throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s', |
|
| 492 | + 'event_espresso'), $query_param_name)); |
|
| 493 | + } |
|
| 494 | + $number_of_parts = count($query_param_parts); |
|
| 495 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
| 496 | + if ($number_of_parts === 1) { |
|
| 497 | + $field_name = $last_query_param_part; |
|
| 498 | + } else {// $number_of_parts >= 2 |
|
| 499 | + //the last part is the column name, and there are only 2parts. therefore... |
|
| 500 | + $field_name = $last_query_param_part; |
|
| 501 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
| 502 | + } |
|
| 503 | + try { |
|
| 504 | + return $model->field_settings_for($field_name); |
|
| 505 | + } catch (\EE_Error $e) { |
|
| 506 | + return null; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | 510 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | '0', |
| 149 | 149 | STR_PAD_LEFT |
| 150 | 150 | ); |
| 151 | - $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
| 151 | + $new_value = rest_parse_date($original_value.$offset_sign.$offset_string); |
|
| 152 | 152 | } else { |
| 153 | 153 | $new_value = $original_value; |
| 154 | 154 | } |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | private static function parse_timezone_offset($timezone_offset) |
| 167 | 167 | { |
| 168 | - $first_char = substr((string)$timezone_offset, 0, 1); |
|
| 168 | + $first_char = substr((string) $timezone_offset, 0, 1); |
|
| 169 | 169 | if ($first_char === '+' || $first_char === '-') { |
| 170 | 170 | $offset_sign = $first_char; |
| 171 | - $offset_secs = substr((string)$timezone_offset, 1); |
|
| 171 | + $offset_secs = substr((string) $timezone_offset, 1); |
|
| 172 | 172 | } else { |
| 173 | 173 | $offset_sign = '+'; |
| 174 | 174 | $offset_secs = $timezone_offset; |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even EE_Front_Controller's init phases have run |
|
| 171 | - * |
|
| 172 | - * @access public |
|
| 173 | - * @return void |
|
| 174 | - */ |
|
| 170 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even EE_Front_Controller's init phases have run |
|
| 171 | + * |
|
| 172 | + * @access public |
|
| 173 | + * @return void |
|
| 174 | + */ |
|
| 175 | 175 | public function init() { |
| 176 | 176 | //only enable most of the EE_Admin IF we're not in full maintenance mode |
| 177 | 177 | if ( EE_Maintenance_Mode::instance()->models_can_query() ){ |
@@ -456,11 +456,11 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | |
| 458 | 458 | /** |
| 459 | - * admin_init |
|
| 460 | - * |
|
| 461 | - * @access public |
|
| 462 | - * @return void |
|
| 463 | - */ |
|
| 459 | + * admin_init |
|
| 460 | + * |
|
| 461 | + * @access public |
|
| 462 | + * @return void |
|
| 463 | + */ |
|
| 464 | 464 | public function admin_init() { |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -612,24 +612,24 @@ discard block |
||
| 612 | 612 | |
| 613 | 613 | |
| 614 | 614 | /** |
| 615 | - * dismiss_persistent_admin_notice |
|
| 616 | - * |
|
| 617 | - * @access public |
|
| 618 | - * @return void |
|
| 619 | - */ |
|
| 615 | + * dismiss_persistent_admin_notice |
|
| 616 | + * |
|
| 617 | + * @access public |
|
| 618 | + * @return void |
|
| 619 | + */ |
|
| 620 | 620 | public function dismiss_ee_nag_notice_callback() { |
| 621 | 621 | EE_Error::dismiss_persistent_admin_notice(); |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | |
| 625 | 625 | |
| 626 | - /** |
|
| 627 | - * @param array $elements |
|
| 628 | - * @return array |
|
| 629 | - * @throws \EE_Error |
|
| 630 | - */ |
|
| 626 | + /** |
|
| 627 | + * @param array $elements |
|
| 628 | + * @return array |
|
| 629 | + * @throws \EE_Error |
|
| 630 | + */ |
|
| 631 | 631 | public function dashboard_glance_items($elements) { |
| 632 | - $elements = is_array($elements) ? $elements : array($elements); |
|
| 632 | + $elements = is_array($elements) ? $elements : array($elements); |
|
| 633 | 633 | $events = EEM_Event::instance()->count(); |
| 634 | 634 | $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') ); |
| 635 | 635 | $items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) ); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public static function instance() { |
| 42 | 42 | // check if class object is instantiated |
| 43 | - if ( ! self::$_instance instanceof EE_Admin ) { |
|
| 43 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
| 44 | 44 | self::$_instance = new self(); |
| 45 | 45 | } |
| 46 | 46 | return self::$_instance; |
@@ -57,30 +57,30 @@ discard block |
||
| 57 | 57 | // define global EE_Admin constants |
| 58 | 58 | $this->_define_all_constants(); |
| 59 | 59 | // set autoloaders for our admin page classes based on included path information |
| 60 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN ); |
|
| 60 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 61 | 61 | // admin hooks |
| 62 | - add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 ); |
|
| 62 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 63 | 63 | // load EE_Request_Handler early |
| 64 | - add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' )); |
|
| 65 | - add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' )); |
|
| 64 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 65 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 66 | 66 | // post shortcode tracking |
| 67 | 67 | add_action( |
| 68 | 68 | 'AHEE__EE_System__initialize_last', |
| 69 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'set_hooks_admin' ) |
|
| 69 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'set_hooks_admin') |
|
| 70 | 70 | ); |
| 71 | - add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 ); |
|
| 72 | - add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 ); |
|
| 73 | - add_action( 'admin_init', array( $this, 'admin_init' ), 100 ); |
|
| 74 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 ); |
|
| 75 | - add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 ); |
|
| 76 | - add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 ); |
|
| 77 | - add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 ); |
|
| 78 | - add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' )); |
|
| 71 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 72 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 73 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 74 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 75 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 76 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 77 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 78 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 79 | 79 | |
| 80 | 80 | //reset Environment config (we only do this on admin page loads); |
| 81 | 81 | EE_Registry::instance()->CFG->environment->recheck_values(); |
| 82 | 82 | |
| 83 | - do_action( 'AHEE__EE_Admin__loaded' ); |
|
| 83 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | */ |
| 97 | 97 | private function _define_all_constants() { |
| 98 | - define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' ); |
|
| 99 | - define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' ); |
|
| 100 | - define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS ); |
|
| 101 | - define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' ); |
|
| 102 | - define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' )); |
|
| 98 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
| 99 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
| 100 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
| 101 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
| 102 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -112,23 +112,23 @@ discard block |
||
| 112 | 112 | * @param string $plugin |
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | - public function filter_plugin_actions( $links, $plugin ) { |
|
| 115 | + public function filter_plugin_actions($links, $plugin) { |
|
| 116 | 116 | // set $main_file in stone |
| 117 | 117 | static $main_file; |
| 118 | 118 | // if $main_file is not set yet |
| 119 | - if ( ! $main_file ) { |
|
| 120 | - $main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE ); |
|
| 119 | + if ( ! $main_file) { |
|
| 120 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 121 | 121 | } |
| 122 | - if ( $plugin === $main_file ) { |
|
| 122 | + if ($plugin === $main_file) { |
|
| 123 | 123 | // compare current plugin to this one |
| 124 | - if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
| 125 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">' . __('Maintenance Mode Active', 'event_espresso' ) . '</a>'; |
|
| 126 | - array_unshift( $links, $maintenance_link ); |
|
| 124 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 125 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">'.__('Maintenance Mode Active', 'event_espresso').'</a>'; |
|
| 126 | + array_unshift($links, $maintenance_link); |
|
| 127 | 127 | } else { |
| 128 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>'; |
|
| 129 | - $events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>'; |
|
| 128 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'.__('Settings', 'event_espresso').'</a>'; |
|
| 129 | + $events_link = '<a href="admin.php?page=espresso_events">'.__('Events', 'event_espresso').'</a>'; |
|
| 130 | 130 | // add before other links |
| 131 | - array_unshift( $links, $org_settings_link, $events_link ); |
|
| 131 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | return $links; |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | * @return void |
| 144 | 144 | */ |
| 145 | 145 | public function get_request() { |
| 146 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
| 147 | - EE_Registry::instance()->load_core( 'CPT_Strategy' ); |
|
| 146 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 147 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -156,11 +156,11 @@ discard block |
||
| 156 | 156 | * @param array $admin_page_folder_names |
| 157 | 157 | * @return array |
| 158 | 158 | */ |
| 159 | - public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){ |
|
| 159 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) { |
|
| 160 | 160 | return array( |
| 161 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 162 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 163 | - 'support' => EE_ADMIN_PAGES . 'support' . DS |
|
| 161 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
| 162 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
| 163 | + 'support' => EE_ADMIN_PAGES.'support'.DS |
|
| 164 | 164 | ); |
| 165 | 165 | } |
| 166 | 166 | |
@@ -174,31 +174,31 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function init() { |
| 176 | 176 | //only enable most of the EE_Admin IF we're not in full maintenance mode |
| 177 | - if ( EE_Maintenance_Mode::instance()->models_can_query() ){ |
|
| 177 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 178 | 178 | //ok so we want to enable the entire admin |
| 179 | - add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' )); |
|
| 180 | - add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 ); |
|
| 181 | - add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 ); |
|
| 179 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 180 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 181 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 182 | 182 | //at a glance dashboard widget |
| 183 | - add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 ); |
|
| 183 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 184 | 184 | //filter for get_edit_post_link used on comments for custom post types |
| 185 | - add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 ); |
|
| 185 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 186 | 186 | } |
| 187 | 187 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
| 188 | - if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) { |
|
| 188 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 189 | 189 | try { |
| 190 | 190 | //this loads the controller for the admin pages which will setup routing etc |
| 191 | - EE_Registry::instance()->load_core( 'Admin_Page_Loader' ); |
|
| 192 | - } catch ( EE_Error $e ) { |
|
| 191 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 192 | + } catch (EE_Error $e) { |
|
| 193 | 193 | $e->get_error(); |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | - add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 ); |
|
| 196 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 197 | 197 | //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
| 198 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 ); |
|
| 199 | - add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 ); |
|
| 198 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 199 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 200 | 200 | //exclude EE critical pages from all nav menus and wp_list_pages |
| 201 | - add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 ); |
|
| 201 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | * @param object $post_type WP post type object |
| 212 | 212 | * @return object WP post type object |
| 213 | 213 | */ |
| 214 | - public function remove_pages_from_nav_menu( $post_type ) { |
|
| 214 | + public function remove_pages_from_nav_menu($post_type) { |
|
| 215 | 215 | //if this isn't the "pages" post type let's get out |
| 216 | - if ( $post_type->name !== 'page' ) { |
|
| 216 | + if ($post_type->name !== 'page') { |
|
| 217 | 217 | return $post_type; |
| 218 | 218 | } |
| 219 | 219 | $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
@@ -233,28 +233,28 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | public function enable_hidden_ee_nav_menu_metaboxes() { |
| 235 | 235 | global $wp_meta_boxes, $pagenow; |
| 236 | - if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) { |
|
| 236 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 237 | 237 | return; |
| 238 | 238 | } |
| 239 | 239 | $user = wp_get_current_user(); |
| 240 | 240 | //has this been done yet? |
| 241 | - if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) { |
|
| 241 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 242 | 242 | return; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - $hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID ); |
|
| 246 | - $initial_meta_boxes = apply_filters( 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page' ) ); |
|
| 245 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 246 | + $initial_meta_boxes = apply_filters('FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array('nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page')); |
|
| 247 | 247 | |
| 248 | - if ( is_array( $hidden_meta_boxes ) ) { |
|
| 249 | - foreach ( $hidden_meta_boxes as $key => $meta_box_id ) { |
|
| 250 | - if ( in_array( $meta_box_id, $initial_meta_boxes ) ) { |
|
| 251 | - unset( $hidden_meta_boxes[ $key ] ); |
|
| 248 | + if (is_array($hidden_meta_boxes)) { |
|
| 249 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 250 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 251 | + unset($hidden_meta_boxes[$key]); |
|
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true ); |
|
| 257 | - update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true ); |
|
| 256 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 257 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * @return void |
| 274 | 274 | */ |
| 275 | 275 | public function register_custom_nav_menu_boxes() { |
| 276 | - add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' ); |
|
| 276 | + add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core'); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
@@ -289,16 +289,16 @@ discard block |
||
| 289 | 289 | * |
| 290 | 290 | * @return string the (maybe) modified link |
| 291 | 291 | */ |
| 292 | - public function modify_edit_post_link( $link, $id ) { |
|
| 293 | - if ( ! $post = get_post( $id ) ){ |
|
| 292 | + public function modify_edit_post_link($link, $id) { |
|
| 293 | + if ( ! $post = get_post($id)) { |
|
| 294 | 294 | return $link; |
| 295 | 295 | } |
| 296 | - if ( $post->post_type === 'espresso_attendees' ) { |
|
| 296 | + if ($post->post_type === 'espresso_attendees') { |
|
| 297 | 297 | $query_args = array( |
| 298 | 298 | 'action' => 'edit_attendee', |
| 299 | 299 | 'post' => $id |
| 300 | 300 | ); |
| 301 | - return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') ); |
|
| 301 | + return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations')); |
|
| 302 | 302 | } |
| 303 | 303 | return $link; |
| 304 | 304 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | global $nav_menu_selected_id; |
| 311 | 311 | |
| 312 | 312 | $db_fields = false; |
| 313 | - $walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
| 313 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 314 | 314 | $current_tab = 'event-archives'; |
| 315 | 315 | |
| 316 | 316 | /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | ?> |
| 330 | 330 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
| 331 | 331 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 332 | - <li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>> |
|
| 333 | - <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ( $nav_menu_selected_id ) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args)));} ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 334 | - <?php _e( 'Event Archive Pages', 'event_espresso' ); ?> |
|
| 332 | + <li <?php echo ('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
|
| 333 | + <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ($nav_menu_selected_id) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args))); } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 334 | + <?php _e('Event Archive Pages', 'event_espresso'); ?> |
|
| 335 | 335 | </a> |
| 336 | 336 | </li> |
| 337 | 337 | <?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs. |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | <?php */ ?> |
| 350 | 350 | |
| 351 | 351 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
| 352 | - echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); |
|
| 352 | + echo ('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 353 | 353 | ?>"> |
| 354 | 354 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
| 355 | 355 | <?php |
| 356 | 356 | $pages = $this->_get_extra_nav_menu_pages_items(); |
| 357 | 357 | $args['walker'] = $walker; |
| 358 | - echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args ); |
|
| 358 | + echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, (object) $args); |
|
| 359 | 359 | ?> |
| 360 | 360 | </ul> |
| 361 | 361 | </div><!-- /.tabs-panel --> |
@@ -363,18 +363,18 @@ discard block |
||
| 363 | 363 | <p class="button-controls"> |
| 364 | 364 | <span class="list-controls"> |
| 365 | 365 | <a href="<?php |
| 366 | - echo esc_url( add_query_arg( |
|
| 366 | + echo esc_url(add_query_arg( |
|
| 367 | 367 | array( |
| 368 | 368 | 'extra-nav-menu-pages-tab' => 'event-archives', |
| 369 | 369 | 'selectall' => 1, |
| 370 | 370 | ), |
| 371 | - remove_query_arg( $removed_args ) |
|
| 371 | + remove_query_arg($removed_args) |
|
| 372 | 372 | )); |
| 373 | 373 | ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
| 374 | 374 | </span> |
| 375 | 375 | |
| 376 | 376 | <span class="add-to-menu"> |
| 377 | - <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-extra-nav-menu-pages' ); ?>" /> |
|
| 377 | + <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e(__('Add to Menu')); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e('submit-posttype-extra-nav-menu-pages'); ?>" /> |
|
| 378 | 378 | <span class="spinner"></span> |
| 379 | 379 | </span> |
| 380 | 380 | </p> |
@@ -395,10 +395,10 @@ discard block |
||
| 395 | 395 | private function _get_extra_nav_menu_pages_items() { |
| 396 | 396 | $menuitems[] = array( |
| 397 | 397 | 'title' => __('Event List', 'event_espresso'), |
| 398 | - 'url' => get_post_type_archive_link( 'espresso_events' ), |
|
| 398 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
| 399 | 399 | 'description' => __('Archive page for all events.', 'event_espresso') |
| 400 | 400 | ); |
| 401 | - return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems ); |
|
| 401 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | * @param $menu_item_values |
| 411 | 411 | * @return stdClass |
| 412 | 412 | */ |
| 413 | - private function _setup_extra_nav_menu_pages_items( $menu_item_values ) { |
|
| 413 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) { |
|
| 414 | 414 | $menu_item = new stdClass(); |
| 415 | 415 | $keys = array( |
| 416 | 416 | 'ID' => 0, |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | 'xfn' => '' |
| 431 | 431 | ); |
| 432 | 432 | |
| 433 | - foreach ( $keys as $key => $value) { |
|
| 434 | - $menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value; |
|
| 433 | + foreach ($keys as $key => $value) { |
|
| 434 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 435 | 435 | } |
| 436 | 436 | return $menu_item; |
| 437 | 437 | } |
@@ -470,9 +470,9 @@ discard block |
||
| 470 | 470 | * - check if doing post processing of one of EE CPTs |
| 471 | 471 | * - instantiate the corresponding EE CPT model for the post_type being processed. |
| 472 | 472 | */ |
| 473 | - if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) { |
|
| 474 | - EE_Registry::instance()->load_core( 'Register_CPTs' ); |
|
| 475 | - EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] ); |
|
| 473 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 474 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 475 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | |
@@ -481,8 +481,8 @@ discard block |
||
| 481 | 481 | * 'options-reading.php' core WordPress admin settings page. This is for user-proofing. |
| 482 | 482 | */ |
| 483 | 483 | global $pagenow; |
| 484 | - if ( $pagenow === 'options-reading.php' ) { |
|
| 485 | - add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) ); |
|
| 484 | + if ($pagenow === 'options-reading.php') { |
|
| 485 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | } |
@@ -494,25 +494,25 @@ discard block |
||
| 494 | 494 | * @param string $output Current output. |
| 495 | 495 | * @return string |
| 496 | 496 | */ |
| 497 | - public function modify_dropdown_pages( $output ) { |
|
| 497 | + public function modify_dropdown_pages($output) { |
|
| 498 | 498 | //get critical pages |
| 499 | 499 | $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
| 500 | 500 | |
| 501 | 501 | //split current output by line break for easier parsing. |
| 502 | - $split_output = explode( "\n", $output ); |
|
| 502 | + $split_output = explode("\n", $output); |
|
| 503 | 503 | |
| 504 | 504 | //loop through to remove any critical pages from the array. |
| 505 | - foreach ( $critical_pages as $page_id ) { |
|
| 506 | - $needle = 'value="' . $page_id . '"'; |
|
| 507 | - foreach( $split_output as $key => $haystack ) { |
|
| 508 | - if( strpos( $haystack, $needle ) !== false ) { |
|
| 509 | - unset( $split_output[$key] ); |
|
| 505 | + foreach ($critical_pages as $page_id) { |
|
| 506 | + $needle = 'value="'.$page_id.'"'; |
|
| 507 | + foreach ($split_output as $key => $haystack) { |
|
| 508 | + if (strpos($haystack, $needle) !== false) { |
|
| 509 | + unset($split_output[$key]); |
|
| 510 | 510 | } |
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | //replace output with the new contents |
| 515 | - return implode( "\n", $split_output ); |
|
| 515 | + return implode("\n", $split_output); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | |
@@ -526,36 +526,36 @@ discard block |
||
| 526 | 526 | public function enqueue_admin_scripts() { |
| 527 | 527 | // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
| 528 | 528 | // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script calls. |
| 529 | - wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 529 | + wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 530 | 530 | // register cookie script for future dependencies |
| 531 | - wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE ); |
|
| 531 | + wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE); |
|
| 532 | 532 | // jquery_validate loading is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
| 533 | - if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) { |
|
| 533 | + if (apply_filters('FHEE_load_jquery_validate', FALSE)) { |
|
| 534 | 534 | // register jQuery Validate |
| 535 | - wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE); |
|
| 535 | + wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE); |
|
| 536 | 536 | } |
| 537 | 537 | //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' ); |
| 538 | - if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) { |
|
| 538 | + if (apply_filters('FHEE_load_joyride', FALSE)) { |
|
| 539 | 539 | //joyride style |
| 540 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 541 | - wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION ); |
|
| 542 | - wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE ); |
|
| 540 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 541 | + wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION); |
|
| 542 | + wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', array(), '2.1', TRUE); |
|
| 543 | 543 | //joyride JS |
| 544 | - wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE ); |
|
| 544 | + wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE); |
|
| 545 | 545 | // wanna go for a joyride? |
| 546 | 546 | wp_enqueue_style('ee-joyride-css'); |
| 547 | 547 | wp_enqueue_script('jquery-joyride'); |
| 548 | 548 | } |
| 549 | 549 | //qtip is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtips', '__return_true' ); |
| 550 | - if ( apply_filters( 'FHEE_load_qtip', FALSE ) ) { |
|
| 550 | + if (apply_filters('FHEE_load_qtip', FALSE)) { |
|
| 551 | 551 | EEH_Qtip_Loader::instance()->register_and_enqueue(); |
| 552 | 552 | } |
| 553 | 553 | //accounting.js library |
| 554 | 554 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 555 | - if ( apply_filters( 'FHEE_load_accounting_js', FALSE ) ) { |
|
| 556 | - wp_register_script( 'ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 557 | - wp_register_script( 'ee-accounting-core', EE_THIRD_PARTY_URL . 'accounting/accounting.js', array('underscore'), '0.3.2', TRUE ); |
|
| 558 | - wp_enqueue_script( 'ee-accounting' ); |
|
| 555 | + if (apply_filters('FHEE_load_accounting_js', FALSE)) { |
|
| 556 | + wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 557 | + wp_register_script('ee-accounting-core', EE_THIRD_PARTY_URL.'accounting/accounting.js', array('underscore'), '0.3.2', TRUE); |
|
| 558 | + wp_enqueue_script('ee-accounting'); |
|
| 559 | 559 | // array of settings to get converted to JSON array via wp_localize_script |
| 560 | 560 | $currency_config = array( |
| 561 | 561 | 'currency' => array( |
@@ -602,11 +602,11 @@ discard block |
||
| 602 | 602 | public function get_persistent_admin_notices() { |
| 603 | 603 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
| 604 | 604 | $args = array( |
| 605 | - 'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '', |
|
| 606 | - 'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '', |
|
| 605 | + 'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '', |
|
| 606 | + 'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '', |
|
| 607 | 607 | ); |
| 608 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL ); |
|
| 609 | - echo EE_Error::get_persistent_admin_notices( $return_url ); |
|
| 608 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
|
| 609 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | |
@@ -631,24 +631,24 @@ discard block |
||
| 631 | 631 | public function dashboard_glance_items($elements) { |
| 632 | 632 | $elements = is_array($elements) ? $elements : array($elements); |
| 633 | 633 | $events = EEM_Event::instance()->count(); |
| 634 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') ); |
|
| 635 | - $items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) ); |
|
| 634 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), admin_url('admin.php')); |
|
| 635 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 636 | 636 | $items['events']['title'] = __('Click to view all Events', 'event_espresso'); |
| 637 | 637 | $registrations = EEM_Registration::instance()->count( |
| 638 | 638 | array( |
| 639 | 639 | array( |
| 640 | - 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) |
|
| 640 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete) |
|
| 641 | 641 | ) |
| 642 | 642 | ) |
| 643 | 643 | ); |
| 644 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') ); |
|
| 645 | - $items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) ); |
|
| 644 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), admin_url('admin.php')); |
|
| 645 | + $items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), number_format_i18n($registrations)); |
|
| 646 | 646 | $items['registrations']['title'] = __('Click to view all registrations', 'event_espresso'); |
| 647 | 647 | |
| 648 | - $items = (array) apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items ); |
|
| 648 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 649 | 649 | |
| 650 | - foreach ( $items as $type => $item_properties ) { |
|
| 651 | - $elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] ); |
|
| 650 | + foreach ($items as $type => $item_properties) { |
|
| 651 | + $elements[] = sprintf('<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text']); |
|
| 652 | 652 | } |
| 653 | 653 | return $elements; |
| 654 | 654 | } |
@@ -665,31 +665,31 @@ discard block |
||
| 665 | 665 | * @throws EE_Error |
| 666 | 666 | * @return string |
| 667 | 667 | */ |
| 668 | - public function check_for_invalid_datetime_formats( $value, $option ) { |
|
| 668 | + public function check_for_invalid_datetime_formats($value, $option) { |
|
| 669 | 669 | // check for date_format or time_format |
| 670 | - switch ( $option ) { |
|
| 670 | + switch ($option) { |
|
| 671 | 671 | case 'date_format' : |
| 672 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 672 | + $date_time_format = $value.' '.get_option('time_format'); |
|
| 673 | 673 | break; |
| 674 | 674 | case 'time_format' : |
| 675 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 675 | + $date_time_format = get_option('date_format').' '.$value; |
|
| 676 | 676 | break; |
| 677 | 677 | default : |
| 678 | 678 | $date_time_format = FALSE; |
| 679 | 679 | } |
| 680 | 680 | // do we have a date_time format to check ? |
| 681 | - if ( $date_time_format ) { |
|
| 682 | - $error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format ); |
|
| 681 | + if ($date_time_format) { |
|
| 682 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 683 | 683 | |
| 684 | - if ( is_array( $error_msg ) ) { |
|
| 685 | - $msg = '<p>' . sprintf( __( 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso' ), date( $date_time_format ) , $date_time_format ) . '</p><p><ul>'; |
|
| 684 | + if (is_array($error_msg)) { |
|
| 685 | + $msg = '<p>'.sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso'), date($date_time_format), $date_time_format).'</p><p><ul>'; |
|
| 686 | 686 | |
| 687 | 687 | |
| 688 | - foreach ( $error_msg as $error ) { |
|
| 689 | - $msg .= '<li>' . $error . '</li>'; |
|
| 688 | + foreach ($error_msg as $error) { |
|
| 689 | + $msg .= '<li>'.$error.'</li>'; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - $msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>'; |
|
| 692 | + $msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>'; |
|
| 693 | 693 | |
| 694 | 694 | // trigger WP settings error |
| 695 | 695 | add_settings_error( |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | ); |
| 700 | 700 | |
| 701 | 701 | // set format to something valid |
| 702 | - switch ( $option ) { |
|
| 702 | + switch ($option) { |
|
| 703 | 703 | case 'date_format' : |
| 704 | 704 | $value = 'F j, Y'; |
| 705 | 705 | break; |
@@ -721,8 +721,8 @@ discard block |
||
| 721 | 721 | * @param $content |
| 722 | 722 | * @return string |
| 723 | 723 | */ |
| 724 | - public function its_eSpresso( $content ) { |
|
| 725 | - return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content ); |
|
| 724 | + public function its_eSpresso($content) { |
|
| 725 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * @return string |
| 735 | 735 | */ |
| 736 | 736 | public function espresso_admin_footer() { |
| 737 | - return \EEH_Template::powered_by_event_espresso( 'aln-cntr', '', array( 'utm_content' => 'admin_footer' )); |
|
| 737 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | |
@@ -753,12 +753,12 @@ discard block |
||
| 753 | 753 | * @param array $config |
| 754 | 754 | * @return void |
| 755 | 755 | */ |
| 756 | - public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) { |
|
| 757 | - EE_Error::doing_it_wrong( __METHOD__, sprintf( __('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3' ); |
|
| 758 | - if ( class_exists( 'EE_Register_Admin_Page' ) ) { |
|
| 756 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) { |
|
| 757 | + EE_Error::doing_it_wrong(__METHOD__, sprintf(__('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3'); |
|
| 758 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 759 | 759 | $config['page_path'] = $page_path; |
| 760 | 760 | } |
| 761 | - EE_Register_Admin_Page::register( $page_basename, $config ); |
|
| 761 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 762 | 762 | |
| 763 | 763 | } |
| 764 | 764 | |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | * @param \WP_Post $post |
| 772 | 772 | * @return void |
| 773 | 773 | */ |
| 774 | - public static function parse_post_content_on_save( $post_ID, $post ) { |
|
| 774 | + public static function parse_post_content_on_save($post_ID, $post) { |
|
| 775 | 775 | EE_Error::doing_it_wrong( |
| 776 | 776 | __METHOD__, |
| 777 | 777 | __( |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | ), |
| 781 | 781 | '4.8.41' |
| 782 | 782 | ); |
| 783 | - EventEspresso\core\admin\PostShortcodeTracking::parse_post_content_on_save( $post_ID, $post ); |
|
| 783 | + EventEspresso\core\admin\PostShortcodeTracking::parse_post_content_on_save($post_ID, $post); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | * @param $value |
| 794 | 794 | * @return void |
| 795 | 795 | */ |
| 796 | - public function reset_page_for_posts_on_change( $option, $old_value, $value ) { |
|
| 796 | + public function reset_page_for_posts_on_change($option, $old_value, $value) { |
|
| 797 | 797 | EE_Error::doing_it_wrong( |
| 798 | 798 | __METHOD__, |
| 799 | 799 | __( |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | ), |
| 803 | 803 | '4.8.41' |
| 804 | 804 | ); |
| 805 | - EventEspresso\core\admin\PostShortcodeTracking::reset_page_for_posts_on_change( $option, $old_value, $value ); |
|
| 805 | + EventEspresso\core\admin\PostShortcodeTracking::reset_page_for_posts_on_change($option, $old_value, $value); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | } |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | protected $_table_analysis; |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | - * @var EE_Data_Migration_Manager $_instance |
|
| 130 | + * @var EE_Data_Migration_Manager $_instance |
|
| 131 | 131 | * @access private |
| 132 | - */ |
|
| 132 | + */ |
|
| 133 | 133 | private static $_instance = NULL; |
| 134 | 134 | |
| 135 | 135 | |
@@ -720,18 +720,18 @@ discard block |
||
| 720 | 720 | |
| 721 | 721 | |
| 722 | 722 | |
| 723 | - /** |
|
| 724 | - * Gets all the data migration scripts available in the core folder and folders |
|
| 725 | - * in addons. Has the side effect of adding them for autoloading |
|
| 726 | - * |
|
| 727 | - * @return array keys are expected classnames, values are their filepaths |
|
| 728 | - * @throws \EE_Error |
|
| 729 | - */ |
|
| 723 | + /** |
|
| 724 | + * Gets all the data migration scripts available in the core folder and folders |
|
| 725 | + * in addons. Has the side effect of adding them for autoloading |
|
| 726 | + * |
|
| 727 | + * @return array keys are expected classnames, values are their filepaths |
|
| 728 | + * @throws \EE_Error |
|
| 729 | + */ |
|
| 730 | 730 | public function get_all_data_migration_scripts_available(){ |
| 731 | 731 | if( ! $this->_data_migration_class_to_filepath_map){ |
| 732 | 732 | $this->_data_migration_class_to_filepath_map = array(); |
| 733 | 733 | foreach($this->get_data_migration_script_folders() as $folder_path){ |
| 734 | - $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
| 734 | + $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
| 735 | 735 | $files = glob( $folder_path. '*.dms.php' ); |
| 736 | 736 | |
| 737 | 737 | if ( empty( $files ) ) { |
@@ -748,15 +748,15 @@ discard block |
||
| 748 | 748 | if( $slug !== 'Core' ){ |
| 749 | 749 | if( ! EE_Registry::instance()->get_addon_by_name( $slug ) ) { |
| 750 | 750 | EE_Error::doing_it_wrong( |
| 751 | - __FUNCTION__, |
|
| 752 | - sprintf( |
|
| 753 | - __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ), |
|
| 754 | - $classname, |
|
| 755 | - $slug, |
|
| 756 | - implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) ) |
|
| 757 | - ), |
|
| 758 | - '4.3.0.alpha.019' |
|
| 759 | - ); |
|
| 751 | + __FUNCTION__, |
|
| 752 | + sprintf( |
|
| 753 | + __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ), |
|
| 754 | + $classname, |
|
| 755 | + $slug, |
|
| 756 | + implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) ) |
|
| 757 | + ), |
|
| 758 | + '4.3.0.alpha.019' |
|
| 759 | + ); |
|
| 760 | 760 | } |
| 761 | 761 | } |
| 762 | 762 | $this->_data_migration_class_to_filepath_map[$classname] = $file; |
@@ -939,12 +939,12 @@ discard block |
||
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
| 942 | - * Resets the borked data migration scripts so they're no longer borked |
|
| 943 | - * so we can again attempt to migrate |
|
| 944 | - * |
|
| 945 | - * @return bool |
|
| 946 | - * @throws \EE_Error |
|
| 947 | - */ |
|
| 942 | + * Resets the borked data migration scripts so they're no longer borked |
|
| 943 | + * so we can again attempt to migrate |
|
| 944 | + * |
|
| 945 | + * @return bool |
|
| 946 | + * @throws \EE_Error |
|
| 947 | + */ |
|
| 948 | 948 | public function reattempt(){ |
| 949 | 949 | //find if the last-ran script was borked |
| 950 | 950 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * to indicate it successfully migrate some data, and has nothing left to do; or EE_Data_Migration_Manager::status_fatal_error to indicate |
| 25 | 25 | * an error occurred which means the ajax script should probably stop executing. |
| 26 | 26 | */ |
| 27 | -class EE_Data_Migration_Manager{ |
|
| 27 | +class EE_Data_Migration_Manager { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * of this EE installation. Keys should be the name of the version the script upgraded to |
| 82 | 82 | * @var EE_Data_Migration_Script_Base[] |
| 83 | 83 | */ |
| 84 | - private $_data_migrations_ran =null; |
|
| 84 | + private $_data_migrations_ran = null; |
|
| 85 | 85 | /** |
| 86 | 86 | * The last ran script. It's nice to store this somewhere accessible, as its easiest |
| 87 | 87 | * to know which was the last run by which is the newest wp option; but in most of the code |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public static function instance() { |
| 143 | 143 | // check if class object is instantiated |
| 144 | - if ( ! self::$_instance instanceof EE_Data_Migration_Manager ) { |
|
| 144 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
| 145 | 145 | self::$_instance = new self(); |
| 146 | 146 | } |
| 147 | 147 | return self::$_instance; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * all new usages of the singleton should be made with Classname::instance()) and returns it |
| 152 | 152 | * @return EE_Data_Migration_Manager |
| 153 | 153 | */ |
| 154 | - public static function reset(){ |
|
| 154 | + public static function reset() { |
|
| 155 | 155 | self::$_instance = NULL; |
| 156 | 156 | return self::instance(); |
| 157 | 157 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | /** |
| 162 | 162 | * constructor |
| 163 | 163 | */ |
| 164 | - private function __construct(){ |
|
| 164 | + private function __construct() { |
|
| 165 | 165 | $this->stati_that_indicate_to_continue_migrations = array( |
| 166 | 166 | self::status_continue, |
| 167 | 167 | self::status_completed |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | ); |
| 181 | 181 | //make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
| 182 | 182 | //to be defined, because right now it doesn't get autoloaded on its own |
| 183 | - EE_Registry::instance()->load_core( 'Data_Migration_Class_Base', array(), TRUE ); |
|
| 184 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Base', array(), TRUE ); |
|
| 185 | - EE_Registry::instance()->load_core( 'DMS_Unknown_1_0_0', array(), TRUE ); |
|
| 186 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage', array(), TRUE ); |
|
| 187 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage_Table', array(), TRUE ); |
|
| 188 | - $this->_table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
| 189 | - $this->_table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
| 183 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), TRUE); |
|
| 184 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), TRUE); |
|
| 185 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), TRUE); |
|
| 186 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), TRUE); |
|
| 187 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), TRUE); |
|
| 188 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 189 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | |
@@ -199,21 +199,21 @@ discard block |
||
| 199 | 199 | * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
| 200 | 200 | * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of that plugin (eg '4.1.0') |
| 201 | 201 | */ |
| 202 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name){ |
|
| 202 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) { |
|
| 203 | 203 | $plugin_slug_and_version_string = str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_name); |
| 204 | 204 | //check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
| 205 | - $parts = explode(".",$plugin_slug_and_version_string); |
|
| 205 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
| 206 | 206 | |
| 207 | - if(count($parts) == 4){ |
|
| 207 | + if (count($parts) == 4) { |
|
| 208 | 208 | //it's 4.2-style.eg Core.4.1.0 |
| 209 | - $plugin_slug = $parts[0];//eg Core |
|
| 209 | + $plugin_slug = $parts[0]; //eg Core |
|
| 210 | 210 | $version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0 |
| 211 | - }else{ |
|
| 211 | + } else { |
|
| 212 | 212 | //it's 4.1-style: eg 4.1.0 |
| 213 | 213 | $plugin_slug = 'Core'; |
| 214 | - $version_string = $plugin_slug_and_version_string;//eg 4.1.0 |
|
| 214 | + $version_string = $plugin_slug_and_version_string; //eg 4.1.0 |
|
| 215 | 215 | } |
| 216 | - return array($plugin_slug,$version_string); |
|
| 216 | + return array($plugin_slug, $version_string); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -224,21 +224,21 @@ discard block |
||
| 224 | 224 | * @return EE_Data_Migration_Script_Base |
| 225 | 225 | * @throws EE_Error |
| 226 | 226 | */ |
| 227 | - private function _get_dms_class_from_wp_option($dms_option_name,$dms_option_value){ |
|
| 227 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) { |
|
| 228 | 228 | $data_migration_data = maybe_unserialize($dms_option_value); |
| 229 | - if(isset($data_migration_data['class']) && class_exists($data_migration_data['class'])){ |
|
| 229 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
| 230 | 230 | $class = new $data_migration_data['class']; |
| 231 | - if($class instanceof EE_Data_Migration_Script_Base){ |
|
| 231 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
| 232 | 232 | $class->instantiate_from_array_of_properties($data_migration_data); |
| 233 | 233 | return $class; |
| 234 | - }else{ |
|
| 234 | + } else { |
|
| 235 | 235 | //huh, so its an object but not a data migration script?? that shouldn't happen |
| 236 | 236 | //just leave it as an array (which will probably just get ignored) |
| 237 | - throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class'])); |
|
| 237 | + throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'), $data_migration_data['class'])); |
|
| 238 | 238 | } |
| 239 | - }else{ |
|
| 239 | + } else { |
|
| 240 | 240 | //so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
| 241 | - throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name)); |
|
| 241 | + throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | /** |
@@ -246,34 +246,34 @@ discard block |
||
| 246 | 246 | * the last ran which hasn't finished yet |
| 247 | 247 | * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy arrays in there - which should probably be ignored) |
| 248 | 248 | */ |
| 249 | - public function get_data_migrations_ran(){ |
|
| 250 | - if( ! $this->_data_migrations_ran ){ |
|
| 249 | + public function get_data_migrations_ran() { |
|
| 250 | + if ( ! $this->_data_migrations_ran) { |
|
| 251 | 251 | //setup autoloaders for each of the scripts in there |
| 252 | 252 | $this->get_all_data_migration_scripts_available(); |
| 253 | - $data_migrations_options = $this->get_all_migration_script_options();//get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 253 | + $data_migrations_options = $this->get_all_migration_script_options(); //get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 254 | 254 | |
| 255 | 255 | $data_migrations_ran = array(); |
| 256 | 256 | //convert into data migration script classes where possible |
| 257 | - foreach($data_migrations_options as $data_migration_option){ |
|
| 258 | - list($plugin_slug,$version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
| 257 | + foreach ($data_migrations_options as $data_migration_option) { |
|
| 258 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
| 259 | 259 | |
| 260 | - try{ |
|
| 261 | - $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'],$data_migration_option['option_value']); |
|
| 260 | + try { |
|
| 261 | + $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'], $data_migration_option['option_value']); |
|
| 262 | 262 | $data_migrations_ran[$plugin_slug][$version_string] = $class; |
| 263 | 263 | //ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
| 264 | 264 | $this->_last_ran_script = $class; |
| 265 | - if( ! $class->is_completed()){ |
|
| 265 | + if ( ! $class->is_completed()) { |
|
| 266 | 266 | //sometimes we also like to know which was the last incomplete script (or if there are any at all) |
| 267 | 267 | $this->_last_ran_incomplete_script = $class; |
| 268 | 268 | } |
| 269 | - }catch(EE_Error $e){ |
|
| 269 | + } catch (EE_Error $e) { |
|
| 270 | 270 | //ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
| 271 | 271 | $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']); |
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | //so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
| 275 | 275 | $this->_data_migrations_ran = $data_migrations_ran; |
| 276 | - if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran) ){ |
|
| 276 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
| 277 | 277 | $this->_data_migrations_ran = array(); |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param $new_table |
| 291 | 291 | * @return mixed string or int |
| 292 | 292 | */ |
| 293 | - public function get_mapping_new_pk( $script_name, $old_table, $old_pk, $new_table){ |
|
| 293 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) { |
|
| 294 | 294 | $script = EE_Registry::instance()->load_dms($script_name); |
| 295 | 295 | $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
| 296 | 296 | return $mapping; |
@@ -301,9 +301,9 @@ discard block |
||
| 301 | 301 | * option returned in this array is the most-recently ran DMS option |
| 302 | 302 | * @return array |
| 303 | 303 | */ |
| 304 | - public function get_all_migration_script_options(){ |
|
| 304 | + public function get_all_migration_script_options() { |
|
| 305 | 305 | global $wpdb; |
| 306 | - return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",ARRAY_A); |
|
| 306 | + return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", ARRAY_A); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -311,8 +311,8 @@ discard block |
||
| 311 | 311 | * @return array where each value is the full folder path of a folder containing data migration scripts, WITH slashes at the end of the |
| 312 | 312 | * folder name. |
| 313 | 313 | */ |
| 314 | - public function get_data_migration_script_folders(){ |
|
| 315 | - return apply_filters( 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',array(EE_CORE.'data_migration_scripts') ); |
|
| 314 | + public function get_data_migration_script_folders() { |
|
| 315 | + return apply_filters('FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', array(EE_CORE.'data_migration_scripts')); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -324,11 +324,11 @@ discard block |
||
| 324 | 324 | * } |
| 325 | 325 | * @throws EE_Error |
| 326 | 326 | */ |
| 327 | - public function script_migrates_to_version($migration_script_name){ |
|
| 327 | + public function script_migrates_to_version($migration_script_name) { |
|
| 328 | 328 | $dms_info = $this->parse_dms_classname($migration_script_name); |
| 329 | 329 | return array( |
| 330 | - 'slug'=> $dms_info[ 'slug' ], |
|
| 331 | - 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] ); |
|
| 330 | + 'slug'=> $dms_info['slug'], |
|
| 331 | + 'version'=> $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'] ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -337,13 +337,13 @@ discard block |
||
| 337 | 337 | * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
| 338 | 338 | * @throws EE_Error |
| 339 | 339 | */ |
| 340 | - public function parse_dms_classname($classname){ |
|
| 340 | + public function parse_dms_classname($classname) { |
|
| 341 | 341 | $matches = array(); |
| 342 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~',$classname,$matches); |
|
| 343 | - if( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))){ |
|
| 344 | - throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"),$classname)); |
|
| 342 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
| 343 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
| 344 | + throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"), $classname)); |
|
| 345 | 345 | } |
| 346 | - return array('slug'=>$matches[1],'major_version'=>intval($matches[2]),'minor_version'=>intval($matches[3]),'micro_version'=>intval($matches[4])); |
|
| 346 | + return array('slug'=>$matches[1], 'major_version'=>intval($matches[2]), 'minor_version'=>intval($matches[3]), 'micro_version'=>intval($matches[4])); |
|
| 347 | 347 | } |
| 348 | 348 | /** |
| 349 | 349 | * Ensures that the option indicating the current DB version is set. This should only be |
@@ -352,33 +352,33 @@ discard block |
||
| 352 | 352 | * to 4.1.x. |
| 353 | 353 | * @return string of current db state |
| 354 | 354 | */ |
| 355 | - public function ensure_current_database_state_is_set(){ |
|
| 356 | - $espresso_db_core_updates = get_option( 'espresso_db_update', array() ); |
|
| 355 | + public function ensure_current_database_state_is_set() { |
|
| 356 | + $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
| 357 | 357 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
| 358 | - if( ! $db_state ){ |
|
| 358 | + if ( ! $db_state) { |
|
| 359 | 359 | //mark the DB as being in the state as the last version in there. |
| 360 | 360 | //this is done to trigger maintenance mode and do data migration scripts |
| 361 | 361 | //if the admin installed this version of EE over 3.1.x or 4.0.x |
| 362 | 362 | //otherwise, the normal maintenance mode code is fine |
| 363 | 363 | $previous_versions_installed = array_keys($espresso_db_core_updates); |
| 364 | 364 | $previous_version_installed = end($previous_versions_installed); |
| 365 | - if(version_compare('4.1.0', $previous_version_installed)){ |
|
| 365 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
| 366 | 366 | //last installed version was less than 4.1 |
| 367 | 367 | //so we want the data migrations to happen. SO, we're going to say the DB is at that state |
| 368 | 368 | // echo "4.1.0 is greater than $previous_version_installed! update the option"; |
| 369 | 369 | $db_state = array('Core'=>$previous_version_installed); |
| 370 | - }else{ |
|
| 370 | + } else { |
|
| 371 | 371 | // echo "4.1.0 is SMALLER than $previous_version_installed"; |
| 372 | 372 | $db_state = array('Core'=>EVENT_ESPRESSO_VERSION); |
| 373 | 373 | } |
| 374 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
| 374 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 375 | 375 | } |
| 376 | 376 | //in 4.1, $db_state would have only been a simple string like '4.1.0', |
| 377 | 377 | //but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
| 378 | 378 | //db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
| 379 | - if( ! is_array($db_state)){ |
|
| 379 | + if ( ! is_array($db_state)) { |
|
| 380 | 380 | $db_state = array('Core'=>$db_state); |
| 381 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
| 381 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 382 | 382 | } |
| 383 | 383 | return $db_state; |
| 384 | 384 | } |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * or they don't apply), returns an empty array |
| 390 | 390 | * @return EE_Data_Migration_Script_Base[] |
| 391 | 391 | */ |
| 392 | - public function check_for_applicable_data_migration_scripts(){ |
|
| 392 | + public function check_for_applicable_data_migration_scripts() { |
|
| 393 | 393 | //get the option describing what options have already run |
| 394 | 394 | $scripts_ran = $this->get_data_migrations_ran(); |
| 395 | 395 | //$scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
@@ -402,62 +402,62 @@ discard block |
||
| 402 | 402 | $iteration = 0; |
| 403 | 403 | $next_database_state_to_consider = $current_database_state; |
| 404 | 404 | $theoretical_database_state = NULL; |
| 405 | - do{ |
|
| 405 | + do { |
|
| 406 | 406 | //the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
| 407 | 407 | $theoretical_database_state = $next_database_state_to_consider; |
| 408 | 408 | //the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?) |
| 409 | - foreach($script_class_and_filepaths_available as $classname => $filepath){ |
|
| 409 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
| 410 | 410 | |
| 411 | 411 | $migrates_to_version = $this->script_migrates_to_version($classname); |
| 412 | - $script_converts_plugin_slug = $migrates_to_version[ 'slug' ]; |
|
| 413 | - $script_converts_to_version = $migrates_to_version[ 'version' ]; |
|
| 412 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
| 413 | + $script_converts_to_version = $migrates_to_version['version']; |
|
| 414 | 414 | //check if this version script is DONE or not; or if it's never been ran |
| 415 | - if( ! $scripts_ran || |
|
| 415 | + if ( ! $scripts_ran || |
|
| 416 | 416 | ! isset($scripts_ran[$script_converts_plugin_slug]) || |
| 417 | - ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])){ |
|
| 417 | + ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) { |
|
| 418 | 418 | //we haven't ran this conversion script before |
| 419 | 419 | //now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
| 420 | - $script = new $classname( $this->_get_table_manager(), $this->_get_table_analysis() ); |
|
| 420 | + $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis()); |
|
| 421 | 421 | /* @var $script EE_Data_Migration_Script_Base */ |
| 422 | 422 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
| 423 | - if($can_migrate){ |
|
| 423 | + if ($can_migrate) { |
|
| 424 | 424 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
| 425 | 425 | $migrates_to_version = $script->migrates_to_version(); |
| 426 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
| 426 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
| 427 | 427 | unset($script_class_and_filepaths_available[$classname]); |
| 428 | 428 | } |
| 429 | - } elseif($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base){ |
|
| 429 | + } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) { |
|
| 430 | 430 | //this script has been ran, or at least started |
| 431 | 431 | $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
| 432 | - if( $script->get_status() != self::status_completed){ |
|
| 432 | + if ($script->get_status() != self::status_completed) { |
|
| 433 | 433 | //this script is already underway... keep going with it |
| 434 | 434 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
| 435 | 435 | $migrates_to_version = $script->migrates_to_version(); |
| 436 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
| 436 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
| 437 | 437 | unset($script_class_and_filepaths_available[$classname]); |
| 438 | - }else{ |
|
| 438 | + } else { |
|
| 439 | 439 | //it must have a status that indicates it has finished, so we don't want to try and run it again |
| 440 | 440 | } |
| 441 | - }else{ |
|
| 441 | + } else { |
|
| 442 | 442 | //it exists but it's not a proper data migration script |
| 443 | 443 | //maybe the script got renamed? or was simply removed from EE? |
| 444 | 444 | //either way, its certainly not runnable! |
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | $iteration++; |
| 448 | - }while( $next_database_state_to_consider != $theoretical_database_state && $iteration<6); |
|
| 448 | + }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
| 449 | 449 | //ok we have all the scripts that should run, now let's make them into flat array |
| 450 | 450 | $scripts_that_should_run = array(); |
| 451 | - foreach($script_classes_that_should_run_per_iteration as $scripts_at_priority){ |
|
| 451 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
| 452 | 452 | ksort($scripts_at_priority); |
| 453 | - foreach($scripts_at_priority as $scripts){ |
|
| 454 | - foreach($scripts as $script){ |
|
| 453 | + foreach ($scripts_at_priority as $scripts) { |
|
| 454 | + foreach ($scripts as $script) { |
|
| 455 | 455 | $scripts_that_should_run[get_class($script)] = $script; |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - do_action( 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run ); |
|
| 460 | + do_action('AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run); |
|
| 461 | 461 | return $scripts_that_should_run; |
| 462 | 462 | } |
| 463 | 463 | |
@@ -471,14 +471,14 @@ discard block |
||
| 471 | 471 | * @param bool $include_completed_scripts |
| 472 | 472 | * @return EE_Data_Migration_Script_Base |
| 473 | 473 | */ |
| 474 | - public function get_last_ran_script($include_completed_scripts = false){ |
|
| 474 | + public function get_last_ran_script($include_completed_scripts = false) { |
|
| 475 | 475 | //make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
| 476 | - if( ! $this->_data_migrations_ran){ |
|
| 476 | + if ( ! $this->_data_migrations_ran) { |
|
| 477 | 477 | $this->get_data_migrations_ran(); |
| 478 | 478 | } |
| 479 | - if($include_completed_scripts){ |
|
| 479 | + if ($include_completed_scripts) { |
|
| 480 | 480 | return $this->_last_ran_script; |
| 481 | - }else{ |
|
| 481 | + } else { |
|
| 482 | 482 | return $this->_last_ran_incomplete_script; |
| 483 | 483 | } |
| 484 | 484 | } |
@@ -501,19 +501,19 @@ discard block |
||
| 501 | 501 | * @type string $message string describing what was done during this step |
| 502 | 502 | * } |
| 503 | 503 | */ |
| 504 | - public function migration_step( $step_size = 0 ){ |
|
| 504 | + public function migration_step($step_size = 0) { |
|
| 505 | 505 | |
| 506 | 506 | //bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
| 507 | - if ( class_exists( 'EE_CPT_Strategy' ) ) { |
|
| 508 | - remove_action( 'pre_get_posts', array( EE_CPT_Strategy::instance(), 'pre_get_posts' ), 5 ); |
|
| 507 | + if (class_exists('EE_CPT_Strategy')) { |
|
| 508 | + remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - try{ |
|
| 511 | + try { |
|
| 512 | 512 | $currently_executing_script = $this->get_last_ran_script(); |
| 513 | - if( ! $currently_executing_script){ |
|
| 513 | + if ( ! $currently_executing_script) { |
|
| 514 | 514 | //Find the next script that needs to execute |
| 515 | 515 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
| 516 | - if( ! $scripts ){ |
|
| 516 | + if ( ! $scripts) { |
|
| 517 | 517 | //huh, no more scripts to run... apparently we're done! |
| 518 | 518 | //but dont forget to make sure initial data is there |
| 519 | 519 | //we should be good to allow them to exit maintenance mode now |
@@ -534,18 +534,18 @@ discard block |
||
| 534 | 534 | //and add to the array/wp option showing the scripts ran |
| 535 | 535 | // $this->_data_migrations_ran[$this->script_migrates_to_version(get_class($currently_executing_script))] = $currently_executing_script; |
| 536 | 536 | $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
| 537 | - $plugin_slug = $migrates_to[ 'slug' ]; |
|
| 538 | - $version = $migrates_to[ 'version' ]; |
|
| 537 | + $plugin_slug = $migrates_to['slug']; |
|
| 538 | + $version = $migrates_to['version']; |
|
| 539 | 539 | $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
| 540 | 540 | } |
| 541 | 541 | $current_script_name = get_class($currently_executing_script); |
| 542 | - }catch(Exception $e){ |
|
| 542 | + } catch (Exception $e) { |
|
| 543 | 543 | //an exception occurred while trying to get migration scripts |
| 544 | 544 | |
| 545 | - $message = sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() ); |
|
| 545 | + $message = sprintf(__("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage().'<br>', $e->getTraceAsString()); |
|
| 546 | 546 | //record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
| 547 | 547 | //but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
| 548 | - $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"),$message)); |
|
| 548 | + $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)); |
|
| 549 | 549 | return array( |
| 550 | 550 | 'records_to_migrate'=>1, |
| 551 | 551 | 'records_migrated'=>0, |
@@ -555,16 +555,16 @@ discard block |
||
| 555 | 555 | ); |
| 556 | 556 | } |
| 557 | 557 | //ok so we definitely have a data migration script |
| 558 | - try{ |
|
| 558 | + try { |
|
| 559 | 559 | //how big of a bite do we want to take? Allow users to easily override via their wp-config |
| 560 | - if( ! absint( $step_size ) > 0 ){ |
|
| 561 | - $step_size = defined( 'EE_MIGRATION_STEP_SIZE' ) && absint( EE_MIGRATION_STEP_SIZE ) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
| 560 | + if ( ! absint($step_size) > 0) { |
|
| 561 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
| 562 | 562 | } |
| 563 | 563 | //do what we came to do! |
| 564 | 564 | $currently_executing_script->migration_step($step_size); |
| 565 | 565 | //can we wrap it up and verify default data? |
| 566 | 566 | $init_dbs = false; |
| 567 | - switch($currently_executing_script->get_status()){ |
|
| 567 | + switch ($currently_executing_script->get_status()) { |
|
| 568 | 568 | case EE_Data_Migration_Manager::status_continue: |
| 569 | 569 | $response_array = array( |
| 570 | 570 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
@@ -576,16 +576,16 @@ discard block |
||
| 576 | 576 | case EE_Data_Migration_Manager::status_completed: |
| 577 | 577 | //ok so THAT script has completed |
| 578 | 578 | $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
| 579 | - $response_array = array( |
|
| 579 | + $response_array = array( |
|
| 580 | 580 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
| 581 | 581 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
| 582 | 582 | 'status'=> EE_Data_Migration_Manager::status_completed, |
| 583 | 583 | 'message'=>$currently_executing_script->get_feedback_message(), |
| 584 | - 'script'=> sprintf(__("%s Completed",'event_espresso'),$currently_executing_script->pretty_name()) |
|
| 584 | + 'script'=> sprintf(__("%s Completed", 'event_espresso'), $currently_executing_script->pretty_name()) |
|
| 585 | 585 | ); |
| 586 | 586 | //check if there are any more after this one. |
| 587 | 587 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
| 588 | - if( ! $scripts_remaining ){ |
|
| 588 | + if ( ! $scripts_remaining) { |
|
| 589 | 589 | //we should be good to allow them to exit maintenance mode now |
| 590 | 590 | EE_Maintenance_Mode::instance()->set_maintenance_level(intval(EE_Maintenance_Mode::level_0_not_in_maintenance)); |
| 591 | 591 | ////huh, no more scripts to run... apparently we're done! |
@@ -599,39 +599,39 @@ discard block |
||
| 599 | 599 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
| 600 | 600 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
| 601 | 601 | 'status'=> $currently_executing_script->get_status(), |
| 602 | - 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ",$currently_executing_script->get_errors())), |
|
| 602 | + 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ", $currently_executing_script->get_errors())), |
|
| 603 | 603 | 'script'=>$currently_executing_script->pretty_name() |
| 604 | 604 | ); |
| 605 | 605 | break; |
| 606 | 606 | } |
| 607 | - }catch(Exception $e){ |
|
| 607 | + } catch (Exception $e) { |
|
| 608 | 608 | //ok so some exception was thrown which killed the data migration script |
| 609 | 609 | //double-check we have a real script |
| 610 | - if($currently_executing_script instanceof EE_Data_Migration_Script_Base){ |
|
| 610 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
| 611 | 611 | $script_name = $currently_executing_script->pretty_name(); |
| 612 | 612 | $currently_executing_script->set_broken(); |
| 613 | 613 | $currently_executing_script->add_error($e->getMessage()); |
| 614 | - }else{ |
|
| 614 | + } else { |
|
| 615 | 615 | $script_name = __("Error getting Migration Script", "event_espresso"); |
| 616 | 616 | } |
| 617 | 617 | $response_array = array( |
| 618 | 618 | 'records_to_migrate'=>1, |
| 619 | 619 | 'records_migrated'=>0, |
| 620 | 620 | 'status'=>self::status_fatal_error, |
| 621 | - 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"),$e->getMessage()), |
|
| 621 | + 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"), $e->getMessage()), |
|
| 622 | 622 | 'script'=>$script_name |
| 623 | 623 | ); |
| 624 | 624 | } |
| 625 | 625 | $successful_save = $this->_save_migrations_ran(); |
| 626 | - if($successful_save !== TRUE){ |
|
| 626 | + if ($successful_save !== TRUE) { |
|
| 627 | 627 | //ok so the current wp option didn't save. that's tricky, because we'd like to update it |
| 628 | 628 | //and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
| 629 | 629 | //however, if we throw an exception, and return that, then the next request |
| 630 | 630 | //won't have as much info in it, and it may be able to save |
| 631 | - throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"),$successful_save)); |
|
| 631 | + throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"), $successful_save)); |
|
| 632 | 632 | } |
| 633 | 633 | //if we're all done, initialize EE plugins' default data etc. |
| 634 | - if( $init_dbs ) { |
|
| 634 | + if ($init_dbs) { |
|
| 635 | 635 | $this->initialize_db_for_enqueued_ee_plugins(); |
| 636 | 636 | } |
| 637 | 637 | return $response_array; |
@@ -649,23 +649,23 @@ discard block |
||
| 649 | 649 | * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into errors, notifications, and successes |
| 650 | 650 | * 'script'=>a pretty name of the script currently running |
| 651 | 651 | */ |
| 652 | - public function response_to_migration_ajax_request(){ |
|
| 652 | + public function response_to_migration_ajax_request() { |
|
| 653 | 653 | // //start output buffer just to make sure we don't mess up the json |
| 654 | 654 | ob_start(); |
| 655 | - try{ |
|
| 655 | + try { |
|
| 656 | 656 | $response = $this->migration_step(); |
| 657 | - }catch(Exception $e){ |
|
| 657 | + } catch (Exception $e) { |
|
| 658 | 658 | $response = array( |
| 659 | 659 | 'records_to_migrate'=>0, |
| 660 | 660 | 'records_migrated'=>0, |
| 661 | 661 | 'status'=> EE_Data_Migration_Manager::status_fatal_error, |
| 662 | - 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"),$e->getMessage()), |
|
| 662 | + 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"), $e->getMessage()), |
|
| 663 | 663 | 'script'=>'Unknown'); |
| 664 | 664 | $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
| 665 | 665 | } |
| 666 | 666 | $warnings_etc = @ob_get_contents(); |
| 667 | 667 | ob_end_clean(); |
| 668 | - $response['message'] .=$warnings_etc; |
|
| 668 | + $response['message'] .= $warnings_etc; |
|
| 669 | 669 | return $response; |
| 670 | 670 | } |
| 671 | 671 | |
@@ -678,14 +678,14 @@ discard block |
||
| 678 | 678 | * } |
| 679 | 679 | * @return void |
| 680 | 680 | */ |
| 681 | - public function update_current_database_state_to($slug_and_version = null){ |
|
| 682 | - if( ! $slug_and_version ){ |
|
| 681 | + public function update_current_database_state_to($slug_and_version = null) { |
|
| 682 | + if ( ! $slug_and_version) { |
|
| 683 | 683 | //no version was provided, assume it should be at the current code version |
| 684 | 684 | $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
| 685 | 685 | } |
| 686 | 686 | $current_database_state = get_option(self::current_database_state); |
| 687 | - $current_database_state[ $slug_and_version[ 'slug' ] ]=$slug_and_version[ 'version' ]; |
|
| 688 | - update_option(self::current_database_state,$current_database_state); |
|
| 687 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
| 688 | + update_option(self::current_database_state, $current_database_state); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -696,20 +696,20 @@ discard block |
||
| 696 | 696 | * } |
| 697 | 697 | * @return boolean |
| 698 | 698 | */ |
| 699 | - public function database_needs_updating_to( $slug_and_version ) { |
|
| 699 | + public function database_needs_updating_to($slug_and_version) { |
|
| 700 | 700 | |
| 701 | - $slug = $slug_and_version[ 'slug' ]; |
|
| 702 | - $version = $slug_and_version[ 'version' ]; |
|
| 701 | + $slug = $slug_and_version['slug']; |
|
| 702 | + $version = $slug_and_version['version']; |
|
| 703 | 703 | $current_database_state = get_option(self::current_database_state); |
| 704 | - if( ! isset( $current_database_state[ $slug ] ) ) { |
|
| 704 | + if ( ! isset($current_database_state[$slug])) { |
|
| 705 | 705 | return true; |
| 706 | - }else{ |
|
| 706 | + } else { |
|
| 707 | 707 | //just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
| 708 | - $version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3); |
|
| 709 | - $version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 ); |
|
| 708 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
| 709 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
| 710 | 710 | $needs_updating = false; |
| 711 | - foreach($version_parts_current_db_state as $offset => $version_part_in_current_db_state ) { |
|
| 712 | - if( $version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ] ) { |
|
| 711 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
| 712 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
| 713 | 713 | $needs_updating = true; |
| 714 | 714 | break; |
| 715 | 715 | } |
@@ -727,33 +727,33 @@ discard block |
||
| 727 | 727 | * @return array keys are expected classnames, values are their filepaths |
| 728 | 728 | * @throws \EE_Error |
| 729 | 729 | */ |
| 730 | - public function get_all_data_migration_scripts_available(){ |
|
| 731 | - if( ! $this->_data_migration_class_to_filepath_map){ |
|
| 730 | + public function get_all_data_migration_scripts_available() { |
|
| 731 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
| 732 | 732 | $this->_data_migration_class_to_filepath_map = array(); |
| 733 | - foreach($this->get_data_migration_script_folders() as $folder_path){ |
|
| 733 | + foreach ($this->get_data_migration_script_folders() as $folder_path) { |
|
| 734 | 734 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
| 735 | - $files = glob( $folder_path. '*.dms.php' ); |
|
| 735 | + $files = glob($folder_path.'*.dms.php'); |
|
| 736 | 736 | |
| 737 | - if ( empty( $files ) ) { |
|
| 737 | + if (empty($files)) { |
|
| 738 | 738 | continue; |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | - foreach($files as $file){ |
|
| 742 | - $pos_of_last_slash = strrpos($file,DS); |
|
| 741 | + foreach ($files as $file) { |
|
| 742 | + $pos_of_last_slash = strrpos($file, DS); |
|
| 743 | 743 | $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
| 744 | - $migrates_to = $this->script_migrates_to_version( $classname ); |
|
| 745 | - $slug = $migrates_to[ 'slug' ]; |
|
| 744 | + $migrates_to = $this->script_migrates_to_version($classname); |
|
| 745 | + $slug = $migrates_to['slug']; |
|
| 746 | 746 | //check that the slug as contained in the DMS is associated with |
| 747 | 747 | //the slug of an addon or core |
| 748 | - if( $slug !== 'Core' ){ |
|
| 749 | - if( ! EE_Registry::instance()->get_addon_by_name( $slug ) ) { |
|
| 748 | + if ($slug !== 'Core') { |
|
| 749 | + if ( ! EE_Registry::instance()->get_addon_by_name($slug)) { |
|
| 750 | 750 | EE_Error::doing_it_wrong( |
| 751 | 751 | __FUNCTION__, |
| 752 | 752 | sprintf( |
| 753 | - __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ), |
|
| 753 | + __('The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso'), |
|
| 754 | 754 | $classname, |
| 755 | 755 | $slug, |
| 756 | - implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) ) |
|
| 756 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
| 757 | 757 | ), |
| 758 | 758 | '4.3.0.alpha.019' |
| 759 | 759 | ); |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * from each addon, and check if they need updating, |
| 777 | 777 | * @return boolean |
| 778 | 778 | */ |
| 779 | - public function addons_need_updating(){ |
|
| 779 | + public function addons_need_updating() { |
|
| 780 | 780 | return false; |
| 781 | 781 | } |
| 782 | 782 | /** |
@@ -785,25 +785,25 @@ discard block |
||
| 785 | 785 | * @param string $error_message |
| 786 | 786 | * @throws EE_Error |
| 787 | 787 | */ |
| 788 | - public function add_error_to_migrations_ran($error_message){ |
|
| 788 | + public function add_error_to_migrations_ran($error_message) { |
|
| 789 | 789 | //get last-ran migration script |
| 790 | 790 | global $wpdb; |
| 791 | - $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",ARRAY_A); |
|
| 791 | + $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", ARRAY_A); |
|
| 792 | 792 | |
| 793 | 793 | $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
| 794 | 794 | //now, tread lightly because we're here because a FATAL non-catchable error |
| 795 | 795 | //was thrown last time when we were trying to run a data migration script |
| 796 | 796 | //so the fatal error could have happened while getting the migration script |
| 797 | 797 | //or doing running it... |
| 798 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix,"",$last_migration_script_option['option_name']) : null; |
|
| 798 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $last_migration_script_option['option_name']) : null; |
|
| 799 | 799 | |
| 800 | 800 | //check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
| 801 | 801 | //because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
| 802 | - if(isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed){ |
|
| 802 | + if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
| 803 | 803 | //ok then just add this error to its list of errors |
| 804 | 804 | $last_ran_migration_script_properties['_errors'][] = $error_message; |
| 805 | 805 | $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
| 806 | - }else{ |
|
| 806 | + } else { |
|
| 807 | 807 | //so we don't even know which script was last running |
| 808 | 808 | //use the data migration error stub, which is designed specifically for this type of thing |
| 809 | 809 | $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
@@ -813,39 +813,39 @@ discard block |
||
| 813 | 813 | $versions_migrated_to = 'Unknown.1.0.0'; |
| 814 | 814 | //now just to make sure appears as last (in case the were previously a fatal error like this) |
| 815 | 815 | //delete the old one |
| 816 | - delete_option( self::data_migration_script_option_prefix . $versions_migrated_to ); |
|
| 816 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
| 817 | 817 | } |
| 818 | - update_option(self::data_migration_script_option_prefix.$versions_migrated_to,$last_ran_migration_script_properties); |
|
| 818 | + update_option(self::data_migration_script_option_prefix.$versions_migrated_to, $last_ran_migration_script_properties); |
|
| 819 | 819 | |
| 820 | 820 | } |
| 821 | 821 | /** |
| 822 | 822 | * saves what data migrations have ran to the database |
| 823 | 823 | * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
| 824 | 824 | */ |
| 825 | - protected function _save_migrations_ran(){ |
|
| 826 | - if($this->_data_migrations_ran == null){ |
|
| 825 | + protected function _save_migrations_ran() { |
|
| 826 | + if ($this->_data_migrations_ran == null) { |
|
| 827 | 827 | $this->get_data_migrations_ran(); |
| 828 | 828 | } |
| 829 | 829 | //now, we don't want to save actual classes to the DB because that's messy |
| 830 | 830 | $successful_updates = true; |
| 831 | - foreach($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin){ |
|
| 832 | - foreach($migrations_ran_for_plugin as $version_string => $array_or_migration_obj){ |
|
| 831 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
| 832 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
| 833 | 833 | // echo "saving migration script to $version_string<br>"; |
| 834 | 834 | $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
| 835 | 835 | $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
| 836 | 836 | $old_option_value = get_option($option_name); |
| 837 | - if($array_or_migration_obj instanceof EE_Data_Migration_Script_Base){ |
|
| 837 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
| 838 | 838 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
| 839 | - if( $old_option_value != $script_array_for_saving){ |
|
| 840 | - $successful_updates = update_option($option_name,$script_array_for_saving); |
|
| 839 | + if ($old_option_value != $script_array_for_saving) { |
|
| 840 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
| 841 | 841 | } |
| 842 | - }else{//we don't know what this array-thing is. So just save it as-is |
|
| 842 | + } else {//we don't know what this array-thing is. So just save it as-is |
|
| 843 | 843 | // $array_of_migrations[$version_string] = $array_or_migration_obj; |
| 844 | - if($old_option_value != $array_or_migration_obj){ |
|
| 845 | - $successful_updates = update_option($option_name,$array_or_migration_obj); |
|
| 844 | + if ($old_option_value != $array_or_migration_obj) { |
|
| 845 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
| 846 | 846 | } |
| 847 | 847 | } |
| 848 | - if( ! $successful_updates ){ |
|
| 848 | + if ( ! $successful_updates) { |
|
| 849 | 849 | global $wpdb; |
| 850 | 850 | return $wpdb->last_error; |
| 851 | 851 | } |
@@ -869,17 +869,17 @@ discard block |
||
| 869 | 869 | * @return EE_Data_Migration_Script_Base |
| 870 | 870 | * @throws EE_Error |
| 871 | 871 | */ |
| 872 | - function _instantiate_script_from_properties_array($properties_array){ |
|
| 873 | - if( ! isset($properties_array['class'])){ |
|
| 874 | - throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"),implode(",",$properties_array))); |
|
| 872 | + function _instantiate_script_from_properties_array($properties_array) { |
|
| 873 | + if ( ! isset($properties_array['class'])) { |
|
| 874 | + throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), implode(",", $properties_array))); |
|
| 875 | 875 | } |
| 876 | 876 | $class_name = $properties_array['class']; |
| 877 | - if( ! class_exists($class_name)){ |
|
| 878 | - throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"),$class_name)); |
|
| 877 | + if ( ! class_exists($class_name)) { |
|
| 878 | + throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
| 879 | 879 | } |
| 880 | 880 | $class = new $class_name; |
| 881 | - if( ! $class instanceof EE_Data_Migration_Script_Base){ |
|
| 882 | - throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),$class_name,get_class($class))); |
|
| 881 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
| 882 | + throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), $class_name, get_class($class))); |
|
| 883 | 883 | } |
| 884 | 884 | $class->instantiate_from_array_of_properties($properties_array); |
| 885 | 885 | return $class; |
@@ -891,25 +891,25 @@ discard block |
||
| 891 | 891 | * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
| 892 | 892 | * @return string |
| 893 | 893 | */ |
| 894 | - public function get_most_up_to_date_dms($plugin_slug = 'Core'){ |
|
| 894 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') { |
|
| 895 | 895 | $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
| 896 | 896 | $most_up_to_date_dms_classname = NULL; |
| 897 | - foreach($class_to_filepath_map as $classname => $filepath){ |
|
| 898 | - if($most_up_to_date_dms_classname === NULL){ |
|
| 897 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
| 898 | + if ($most_up_to_date_dms_classname === NULL) { |
|
| 899 | 899 | $migrates_to = $this->script_migrates_to_version($classname); |
| 900 | - $this_plugin_slug = $migrates_to[ 'slug' ]; |
|
| 900 | + $this_plugin_slug = $migrates_to['slug']; |
|
| 901 | 901 | // $version_string = $migrates_to[ 'version' ]; |
| 902 | 902 | // $details = $this->parse_dms_classname($classname); |
| 903 | - if($this_plugin_slug == $plugin_slug){ |
|
| 903 | + if ($this_plugin_slug == $plugin_slug) { |
|
| 904 | 904 | //if it's for core, it wins |
| 905 | 905 | $most_up_to_date_dms_classname = $classname; |
| 906 | 906 | } |
| 907 | 907 | //if it wasn't for core, we must keep searching for one that is! |
| 908 | 908 | continue; |
| 909 | - }else{ |
|
| 910 | - $champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 909 | + } else { |
|
| 910 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 911 | 911 | $contender_migrates_to = $this->script_migrates_to_version($classname); |
| 912 | - if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){ |
|
| 912 | + if ($contender_migrates_to['slug'] == $plugin_slug && version_compare($champion_migrates_to['version'], $contender_migrates_to['version'], '<')) { |
|
| 913 | 913 | //so the contenders version is higher and its for Core |
| 914 | 914 | $most_up_to_date_dms_classname = $classname; |
| 915 | 915 | } |
@@ -929,11 +929,11 @@ discard block |
||
| 929 | 929 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
| 930 | 930 | * @return EE_Data_Migration_Script_Base |
| 931 | 931 | */ |
| 932 | - public function get_migration_ran( $version, $plugin_slug = 'Core' ) { |
|
| 932 | + public function get_migration_ran($version, $plugin_slug = 'Core') { |
|
| 933 | 933 | $migrations_ran = $this->get_data_migrations_ran(); |
| 934 | - if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){ |
|
| 935 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
| 936 | - }else{ |
|
| 934 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
| 935 | + return $migrations_ran[$plugin_slug][$version]; |
|
| 936 | + } else { |
|
| 937 | 937 | return NULL; |
| 938 | 938 | } |
| 939 | 939 | } |
@@ -945,20 +945,20 @@ discard block |
||
| 945 | 945 | * @return bool |
| 946 | 946 | * @throws \EE_Error |
| 947 | 947 | */ |
| 948 | - public function reattempt(){ |
|
| 948 | + public function reattempt() { |
|
| 949 | 949 | //find if the last-ran script was borked |
| 950 | 950 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
| 951 | 951 | //add an 'error' saying that we attempted to reset |
| 952 | 952 | //does it have a stage that was borked too? if so make it no longer borked |
| 953 | 953 | //add an 'error' saying we attempted to reset |
| 954 | 954 | $last_ran_script = $this->get_last_ran_script(); |
| 955 | - if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){ |
|
| 955 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
| 956 | 956 | //if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
| 957 | 957 | $last_ran_script->set_completed(); |
| 958 | - }elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
| 958 | + }elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
| 959 | 959 | $last_ran_script->reattempt(); |
| 960 | - }else{ |
|
| 961 | - throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) ); |
|
| 960 | + } else { |
|
| 961 | + throw new EE_Error(sprintf(__('Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso'), print_r($last_ran_script, true))); |
|
| 962 | 962 | } |
| 963 | 963 | return $this->_save_migrations_ran(); |
| 964 | 964 | } |
@@ -968,19 +968,19 @@ discard block |
||
| 968 | 968 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
| 969 | 969 | * @return boolean |
| 970 | 970 | */ |
| 971 | - public function migration_has_ran( $version, $plugin_slug = 'Core' ) { |
|
| 972 | - return $this->get_migration_ran( $version, $plugin_slug ) !== NULL; |
|
| 971 | + public function migration_has_ran($version, $plugin_slug = 'Core') { |
|
| 972 | + return $this->get_migration_ran($version, $plugin_slug) !== NULL; |
|
| 973 | 973 | } |
| 974 | 974 | /** |
| 975 | 975 | * Enqueues this ee plugin to have its data initialized |
| 976 | 976 | * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
| 977 | 977 | */ |
| 978 | - public function enqueue_db_initialization_for( $plugin_slug ) { |
|
| 978 | + public function enqueue_db_initialization_for($plugin_slug) { |
|
| 979 | 979 | $queue = $this->get_db_initialization_queue(); |
| 980 | - if( ! in_array( $plugin_slug, $queue ) ) { |
|
| 980 | + if ( ! in_array($plugin_slug, $queue)) { |
|
| 981 | 981 | $queue[] = $plugin_slug; |
| 982 | 982 | } |
| 983 | - update_option( self::db_init_queue_option_name, $queue ); |
|
| 983 | + update_option(self::db_init_queue_option_name, $queue); |
|
| 984 | 984 | } |
| 985 | 985 | /** |
| 986 | 986 | * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
@@ -990,26 +990,26 @@ discard block |
||
| 990 | 990 | public function initialize_db_for_enqueued_ee_plugins() { |
| 991 | 991 | // EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' ); |
| 992 | 992 | $queue = $this->get_db_initialization_queue(); |
| 993 | - foreach( $queue as $plugin_slug ) { |
|
| 994 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms( $plugin_slug ); |
|
| 995 | - if( ! $most_up_to_date_dms ) { |
|
| 993 | + foreach ($queue as $plugin_slug) { |
|
| 994 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
| 995 | + if ( ! $most_up_to_date_dms) { |
|
| 996 | 996 | //if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
| 997 | 997 | $verify_db = false; |
| 998 | - }else{ |
|
| 999 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms ); |
|
| 1000 | - $verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to ); |
|
| 998 | + } else { |
|
| 999 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
| 1000 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
| 1001 | 1001 | } |
| 1002 | - if( $plugin_slug == 'Core' ){ |
|
| 1002 | + if ($plugin_slug == 'Core') { |
|
| 1003 | 1003 | EE_System::instance()->initialize_db_if_no_migrations_required( |
| 1004 | 1004 | false, |
| 1005 | 1005 | $verify_db |
| 1006 | 1006 | ); |
| 1007 | - }else{ |
|
| 1007 | + } else { |
|
| 1008 | 1008 | //just loop through the addons to make sure their database is setup |
| 1009 | - foreach( EE_Registry::instance()->addons as $addon ) { |
|
| 1010 | - if( $addon->name() == $plugin_slug ) { |
|
| 1009 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
| 1010 | + if ($addon->name() == $plugin_slug) { |
|
| 1011 | 1011 | |
| 1012 | - $addon->initialize_db_if_no_migrations_required( $verify_db ); |
|
| 1012 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
| 1013 | 1013 | break; |
| 1014 | 1014 | } |
| 1015 | 1015 | } |
@@ -1019,7 +1019,7 @@ discard block |
||
| 1019 | 1019 | // EEH_Debug_Tools::instance()->show_times(); |
| 1020 | 1020 | //because we just initialized the DBs for the enqueued ee plugins |
| 1021 | 1021 | //we don't need to keep remembering which ones needed to be initialized |
| 1022 | - delete_option( self::db_init_queue_option_name ); |
|
| 1022 | + delete_option(self::db_init_queue_option_name); |
|
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | 1025 | /** |
@@ -1028,8 +1028,8 @@ discard block |
||
| 1028 | 1028 | * 'Core', or the return value of EE_Addon::name() for an addon |
| 1029 | 1029 | * @return array |
| 1030 | 1030 | */ |
| 1031 | - public function get_db_initialization_queue(){ |
|
| 1032 | - return get_option ( self::db_init_queue_option_name, array() ); |
|
| 1031 | + public function get_db_initialization_queue() { |
|
| 1032 | + return get_option(self::db_init_queue_option_name, array()); |
|
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | 1035 | /** |
@@ -1038,13 +1038,13 @@ discard block |
||
| 1038 | 1038 | * @throws \EE_Error |
| 1039 | 1039 | */ |
| 1040 | 1040 | protected function _get_table_analysis() { |
| 1041 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
| 1041 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 1042 | 1042 | return $this->_table_analysis; |
| 1043 | 1043 | } else { |
| 1044 | 1044 | throw new \EE_Error( |
| 1045 | 1045 | sprintf( |
| 1046 | - __( 'Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1047 | - get_class( $this ) |
|
| 1046 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1047 | + get_class($this) |
|
| 1048 | 1048 | ) |
| 1049 | 1049 | ); |
| 1050 | 1050 | } |
@@ -1056,13 +1056,13 @@ discard block |
||
| 1056 | 1056 | * @throws \EE_Error |
| 1057 | 1057 | */ |
| 1058 | 1058 | protected function _get_table_manager() { |
| 1059 | - if( $this->_table_manager instanceof TableManager ) { |
|
| 1059 | + if ($this->_table_manager instanceof TableManager) { |
|
| 1060 | 1060 | return $this->_table_manager; |
| 1061 | 1061 | } else { |
| 1062 | 1062 | throw new \EE_Error( |
| 1063 | 1063 | sprintf( |
| 1064 | - __( 'Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1065 | - get_class( $this ) |
|
| 1064 | + __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1065 | + get_class($this) |
|
| 1066 | 1066 | ) |
| 1067 | 1067 | ); |
| 1068 | 1068 | } |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | * allowed) |
| 568 | 568 | * |
| 569 | 569 | * @param string $datetime_string mysql timestamp in UTC |
| 570 | - * @return mixed null | DateTime |
|
| 570 | + * @return null|DbSafeDateTime null | DateTime |
|
| 571 | 571 | * @throws \EE_Error |
| 572 | 572 | */ |
| 573 | 573 | public function prepare_for_set_from_db($datetime_string) |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * |
| 725 | 725 | * @param \DateTimeZone $DateTimeZone |
| 726 | 726 | * @param int $time |
| 727 | - * @return mixed |
|
| 727 | + * @return integer |
|
| 728 | 728 | * @throws \DomainException |
| 729 | 729 | */ |
| 730 | 730 | public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\domain\entities\DbSafeDateTime; |
| 2 | 2 | |
| 3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -16,755 +16,755 @@ discard block |
||
| 16 | 16 | class EE_Datetime_Field extends EE_Model_Field_Base |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 21 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 22 | - * |
|
| 23 | - * @type string unix_timestamp_regex |
|
| 24 | - */ |
|
| 25 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @type string mysql_timestamp_format |
|
| 29 | - */ |
|
| 30 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @type string mysql_date_format |
|
| 34 | - */ |
|
| 35 | - const mysql_date_format = 'Y-m-d'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @type string mysql_time_format |
|
| 39 | - */ |
|
| 40 | - const mysql_time_format = 'H:i:s'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Const for using in the default value. If the field's default is set to this, |
|
| 44 | - * then we will return the time of calling `get_default_value()`, not |
|
| 45 | - * just the current time at construction |
|
| 46 | - */ |
|
| 47 | - const now = 'now'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * The following properties hold the default formats for date and time. |
|
| 51 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 52 | - * However they can also be overridden later by the set_format() method |
|
| 53 | - * (and corresponding set_date_format, set_time_format methods); |
|
| 54 | - */ |
|
| 55 | - /** |
|
| 56 | - * @type string $_date_format |
|
| 57 | - */ |
|
| 58 | - protected $_date_format = ''; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @type string $_time_format |
|
| 62 | - */ |
|
| 63 | - protected $_time_format = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @type string $_pretty_date_format |
|
| 67 | - */ |
|
| 68 | - protected $_pretty_date_format = ''; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @type string $_pretty_time_format |
|
| 72 | - */ |
|
| 73 | - protected $_pretty_time_format = ''; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @type DateTimeZone $_DateTimeZone |
|
| 77 | - */ |
|
| 78 | - protected $_DateTimeZone; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
| 82 | - */ |
|
| 83 | - protected $_UTC_DateTimeZone; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @type DateTimeZone $_blog_DateTimeZone |
|
| 87 | - */ |
|
| 88 | - protected $_blog_DateTimeZone; |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 93 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 94 | - * and time returned via getters. |
|
| 95 | - * |
|
| 96 | - * @var mixed (null|string) |
|
| 97 | - */ |
|
| 98 | - protected $_date_time_output; |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * timezone string |
|
| 103 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 104 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 105 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 106 | - * |
|
| 107 | - * @var string |
|
| 108 | - */ |
|
| 109 | - protected $_timezone_string; |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 114 | - * offsets for comparison purposes). |
|
| 115 | - * |
|
| 116 | - * @var int |
|
| 117 | - */ |
|
| 118 | - protected $_blog_offset; |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param string $table_column |
|
| 123 | - * @param string $nice_name |
|
| 124 | - * @param bool $nullable |
|
| 125 | - * @param string $default_value |
|
| 126 | - * @param string $timezone_string |
|
| 127 | - * @param string $date_format |
|
| 128 | - * @param string $time_format |
|
| 129 | - * @param string $pretty_date_format |
|
| 130 | - * @param string $pretty_time_format |
|
| 131 | - * @throws \EE_Error |
|
| 132 | - */ |
|
| 133 | - public function __construct( |
|
| 134 | - $table_column, |
|
| 135 | - $nice_name, |
|
| 136 | - $nullable, |
|
| 137 | - $default_value, |
|
| 138 | - $timezone_string = '', |
|
| 139 | - $date_format = '', |
|
| 140 | - $time_format = '', |
|
| 141 | - $pretty_date_format = '', |
|
| 142 | - $pretty_time_format = '' |
|
| 143 | - ) { |
|
| 144 | - |
|
| 145 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 146 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 147 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 148 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 149 | - |
|
| 150 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 151 | - $this->set_timezone($timezone_string); |
|
| 152 | - |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - public function get_wpdb_data_type() |
|
| 160 | - { |
|
| 161 | - return '%s'; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @return DateTimeZone |
|
| 167 | - * @throws \EE_Error |
|
| 168 | - */ |
|
| 169 | - public function get_UTC_DateTimeZone() |
|
| 170 | - { |
|
| 171 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 172 | - ? $this->_UTC_DateTimeZone |
|
| 173 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return DateTimeZone |
|
| 179 | - * @throws \EE_Error |
|
| 180 | - */ |
|
| 181 | - public function get_blog_DateTimeZone() |
|
| 182 | - { |
|
| 183 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 184 | - ? $this->_blog_DateTimeZone |
|
| 185 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 191 | - * |
|
| 192 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 193 | - * timestamp |
|
| 194 | - * @return DateTime |
|
| 195 | - */ |
|
| 196 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 197 | - { |
|
| 198 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 204 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 205 | - * |
|
| 206 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 207 | - * @return string The final assembled format string. |
|
| 208 | - */ |
|
| 209 | - protected function _get_date_time_output($pretty = false) |
|
| 210 | - { |
|
| 211 | - |
|
| 212 | - switch ($this->_date_time_output) { |
|
| 213 | - case 'time' : |
|
| 214 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 215 | - break; |
|
| 216 | - |
|
| 217 | - case 'date' : |
|
| 218 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 219 | - break; |
|
| 220 | - |
|
| 221 | - default : |
|
| 222 | - return $pretty |
|
| 223 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 224 | - : $this->_date_format . ' ' . $this->_time_format; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 231 | - * returned (using the format properties) |
|
| 232 | - * |
|
| 233 | - * @param string $what acceptable values are 'time' or 'date'. |
|
| 234 | - * Any other value will be set but will always result |
|
| 235 | - * in both 'date' and 'time' being returned. |
|
| 236 | - * @return void |
|
| 237 | - */ |
|
| 238 | - public function set_date_time_output($what = null) |
|
| 239 | - { |
|
| 240 | - $this->_date_time_output = $what; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 246 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 247 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
| 248 | - * We also set some other properties in this method. |
|
| 249 | - * |
|
| 250 | - * @param string $timezone_string A valid timezone string as described by @link |
|
| 251 | - * http://www.php.net/manual/en/timezones.php |
|
| 252 | - * @return void |
|
| 253 | - * @throws \EE_Error |
|
| 254 | - */ |
|
| 255 | - public function set_timezone($timezone_string) |
|
| 256 | - { |
|
| 257 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 258 | - // leave the timezone AS-IS if we already have one and |
|
| 259 | - // the function arg didn't provide one |
|
| 260 | - return; |
|
| 261 | - } |
|
| 262 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 263 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 264 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * _create_timezone_object_from_timezone_name |
|
| 270 | - * |
|
| 271 | - * @access protected |
|
| 272 | - * @param string $timezone_string |
|
| 273 | - * @return \DateTimeZone |
|
| 274 | - * @throws \EE_Error |
|
| 275 | - */ |
|
| 276 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 277 | - { |
|
| 278 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * This just returns whatever is set for the current timezone. |
|
| 284 | - * |
|
| 285 | - * @access public |
|
| 286 | - * @return string timezone string |
|
| 287 | - */ |
|
| 288 | - public function get_timezone() |
|
| 289 | - { |
|
| 290 | - return $this->_timezone_string; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * set the $_date_format property |
|
| 296 | - * |
|
| 297 | - * @access public |
|
| 298 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 299 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 300 | - * @return void |
|
| 301 | - */ |
|
| 302 | - public function set_date_format($format, $pretty = false) |
|
| 303 | - { |
|
| 304 | - if ($pretty) { |
|
| 305 | - $this->_pretty_date_format = $format; |
|
| 306 | - } else { |
|
| 307 | - $this->_date_format = $format; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * return the $_date_format property value. |
|
| 314 | - * |
|
| 315 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - public function get_date_format($pretty = false) |
|
| 319 | - { |
|
| 320 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * set the $_time_format property |
|
| 326 | - * |
|
| 327 | - * @access public |
|
| 328 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 329 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 330 | - * @return void |
|
| 331 | - */ |
|
| 332 | - public function set_time_format($format, $pretty = false) |
|
| 333 | - { |
|
| 334 | - if ($pretty) { |
|
| 335 | - $this->_pretty_time_format = $format; |
|
| 336 | - } else { |
|
| 337 | - $this->_time_format = $format; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * return the $_time_format property value. |
|
| 344 | - * |
|
| 345 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 346 | - * @return string |
|
| 347 | - */ |
|
| 348 | - public function get_time_format($pretty = false) |
|
| 349 | - { |
|
| 350 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * set the $_pretty_date_format property |
|
| 356 | - * |
|
| 357 | - * @access public |
|
| 358 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 359 | - * @return void |
|
| 360 | - */ |
|
| 361 | - public function set_pretty_date_format($format) |
|
| 362 | - { |
|
| 363 | - $this->_pretty_date_format = $format; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * set the $_pretty_time_format property |
|
| 369 | - * |
|
| 370 | - * @access public |
|
| 371 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 372 | - * @return void |
|
| 373 | - */ |
|
| 374 | - public function set_pretty_time_format($format) |
|
| 375 | - { |
|
| 376 | - $this->_pretty_time_format = $format; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Only sets the time portion of the datetime. |
|
| 382 | - * |
|
| 383 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 384 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 385 | - * @return DateTime |
|
| 386 | - */ |
|
| 387 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 388 | - { |
|
| 389 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 390 | - // Otherwise parse the string. |
|
| 391 | - if ($time_to_set_string instanceof DateTime) { |
|
| 392 | - $parsed = array( |
|
| 393 | - 'hour' => $time_to_set_string->format('H'), |
|
| 394 | - 'minute' => $time_to_set_string->format('i'), |
|
| 395 | - 'second' => $time_to_set_string->format('s'), |
|
| 396 | - ); |
|
| 397 | - } else { |
|
| 398 | - //parse incoming string |
|
| 399 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - //make sure $current is in the correct timezone. |
|
| 403 | - $current->setTimezone($this->_DateTimeZone); |
|
| 404 | - |
|
| 405 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Only sets the date portion of the datetime. |
|
| 411 | - * |
|
| 412 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 413 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 414 | - * @return DateTime |
|
| 415 | - */ |
|
| 416 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 417 | - { |
|
| 418 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 419 | - // Otherwise parse the string. |
|
| 420 | - if ($date_to_set_string instanceof DateTime) { |
|
| 421 | - $parsed = array( |
|
| 422 | - 'year' => $date_to_set_string->format('Y'), |
|
| 423 | - 'month' => $date_to_set_string->format('m'), |
|
| 424 | - 'day' => $date_to_set_string->format('d'), |
|
| 425 | - ); |
|
| 426 | - } else { |
|
| 427 | - //parse incoming string |
|
| 428 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - //make sure $current is in the correct timezone |
|
| 432 | - $current->setTimezone($this->_DateTimeZone); |
|
| 433 | - |
|
| 434 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
| 440 | - * datetime gets to this stage it should ALREADY be in UTC time |
|
| 441 | - * |
|
| 442 | - * @param DateTime $DateTime |
|
| 443 | - * @return string formatted date time for given timezone |
|
| 444 | - * @throws \EE_Error |
|
| 445 | - */ |
|
| 446 | - public function prepare_for_get($DateTime) |
|
| 447 | - { |
|
| 448 | - return $this->_prepare_for_display($DateTime); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
| 454 | - * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
| 455 | - * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
| 456 | - * abbreviation to the date_string. |
|
| 457 | - * |
|
| 458 | - * @param mixed $DateTime |
|
| 459 | - * @param null $schema |
|
| 460 | - * @return string |
|
| 461 | - * @throws \EE_Error |
|
| 462 | - */ |
|
| 463 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 464 | - { |
|
| 465 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 471 | - * timezone). |
|
| 472 | - * |
|
| 473 | - * @param DateTime $DateTime |
|
| 474 | - * @param bool|string $schema |
|
| 475 | - * @return string |
|
| 476 | - * @throws \EE_Error |
|
| 477 | - */ |
|
| 478 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
| 479 | - { |
|
| 480 | - if (! $DateTime instanceof DateTime) { |
|
| 481 | - if ($this->_nullable) { |
|
| 482 | - return ''; |
|
| 483 | - } else { |
|
| 484 | - if (WP_DEBUG) { |
|
| 485 | - throw new EE_Error( |
|
| 486 | - sprintf( |
|
| 487 | - __( |
|
| 488 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 489 | - 'event_espresso' |
|
| 490 | - ), |
|
| 491 | - $this->_nicename |
|
| 492 | - ) |
|
| 493 | - ); |
|
| 494 | - } else { |
|
| 495 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 496 | - EE_Error::add_error( |
|
| 497 | - sprintf( |
|
| 498 | - __( |
|
| 499 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 500 | - 'event_espresso' |
|
| 501 | - ), |
|
| 502 | - $this->_nicename |
|
| 503 | - ) |
|
| 504 | - ); |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - $format_string = $this->_get_date_time_output($schema); |
|
| 509 | - //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 510 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 511 | - if ($schema) { |
|
| 512 | - if ($this->_display_timezone()) { |
|
| 513 | - //must be explicit because schema could equal true. |
|
| 514 | - if ($schema === 'no_html') { |
|
| 515 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 516 | - } else { |
|
| 517 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 518 | - } |
|
| 519 | - } else { |
|
| 520 | - $timezone_string = ''; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - return $DateTime->format($format_string) . $timezone_string; |
|
| 524 | - } else { |
|
| 525 | - return $DateTime->format($format_string); |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 532 | - * timezone). |
|
| 533 | - * |
|
| 534 | - * @param mixed $datetime_value u |
|
| 535 | - * @return string mysql timestamp in UTC |
|
| 536 | - * @throws \EE_Error |
|
| 537 | - */ |
|
| 538 | - public function prepare_for_use_in_db($datetime_value) |
|
| 539 | - { |
|
| 540 | - //we allow an empty value or DateTime object, but nothing else. |
|
| 541 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 542 | - throw new EE_Error( |
|
| 543 | - __( |
|
| 544 | - 'The incoming value being prepared for setting in the database must either be empty or a php DateTime object', |
|
| 545 | - 'event_espresso' |
|
| 546 | - ) |
|
| 547 | - ); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - if ($datetime_value instanceof DateTime) { |
|
| 551 | - if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 552 | - $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 556 | - EE_Datetime_Field::mysql_timestamp_format |
|
| 557 | - ); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 561 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
| 567 | - * allowed) |
|
| 568 | - * |
|
| 569 | - * @param string $datetime_string mysql timestamp in UTC |
|
| 570 | - * @return mixed null | DateTime |
|
| 571 | - * @throws \EE_Error |
|
| 572 | - */ |
|
| 573 | - public function prepare_for_set_from_db($datetime_string) |
|
| 574 | - { |
|
| 575 | - //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 576 | - if (empty($datetime_string) && $this->_nullable) { |
|
| 577 | - return null; |
|
| 578 | - } |
|
| 579 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 580 | - if (empty($datetime_string)) { |
|
| 581 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 582 | - } else { |
|
| 583 | - $DateTime = DateTime::createFromFormat( |
|
| 584 | - EE_Datetime_Field::mysql_timestamp_format, |
|
| 585 | - $datetime_string, |
|
| 586 | - $this->get_UTC_DateTimeZone() |
|
| 587 | - ); |
|
| 588 | - if ($DateTime instanceof \DateTime) { |
|
| 589 | - $DateTime = new DbSafeDateTime( |
|
| 590 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 591 | - $this->get_UTC_DateTimeZone() |
|
| 592 | - ); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 597 | - // if still no datetime object, then let's just use now |
|
| 598 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 599 | - } |
|
| 600 | - // THEN apply the field's set DateTimeZone |
|
| 601 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 602 | - |
|
| 603 | - return $DateTime; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * All this method does is determine if we're going to display the timezone string or not on any output. |
|
| 609 | - * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
| 610 | - * If so, then true. |
|
| 611 | - * |
|
| 612 | - * @return bool true for yes false for no |
|
| 613 | - * @throws \EE_Error |
|
| 614 | - */ |
|
| 615 | - protected function _display_timezone() |
|
| 616 | - { |
|
| 617 | - |
|
| 618 | - // first let's do a comparison of timezone strings. |
|
| 619 | - // If they match then we can get out without any further calculations |
|
| 620 | - $blog_string = get_option('timezone_string'); |
|
| 621 | - if ($blog_string === $this->_timezone_string) { |
|
| 622 | - return false; |
|
| 623 | - } |
|
| 624 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 625 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 626 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 627 | - // now compare |
|
| 628 | - return $blog_offset !== $this_offset; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 634 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 635 | - * with. |
|
| 636 | - * |
|
| 637 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 638 | - * in the format that is set on the date_field (or DateTime |
|
| 639 | - * object)! |
|
| 640 | - * @return DateTime |
|
| 641 | - */ |
|
| 642 | - protected function _get_date_object($date_string) |
|
| 643 | - { |
|
| 644 | - //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 645 | - if ($this->_nullable && empty($date_string)) { |
|
| 646 | - return null; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - // if incoming date |
|
| 650 | - if ($date_string instanceof DateTime) { |
|
| 651 | - $date_string->setTimezone($this->_DateTimeZone); |
|
| 652 | - |
|
| 653 | - return $date_string; |
|
| 654 | - } |
|
| 655 | - // if empty date_string and made it here. |
|
| 656 | - // Return a datetime object for now in the given timezone. |
|
| 657 | - if (empty($date_string)) { |
|
| 658 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 659 | - } |
|
| 660 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 661 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 662 | - try { |
|
| 663 | - // This is operating under the assumption that the incoming Unix timestamp |
|
| 664 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 665 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 666 | - $DateTime->setTimestamp($date_string); |
|
| 667 | - |
|
| 668 | - return $DateTime; |
|
| 669 | - } catch (Exception $e) { |
|
| 670 | - // should be rare, but if things got fooled then let's just continue |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 674 | - //create the DateTime object. |
|
| 675 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 676 | - try { |
|
| 677 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 678 | - if ($DateTime instanceof DateTime) { |
|
| 679 | - $DateTime = new DbSafeDateTime( |
|
| 680 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 681 | - $this->_DateTimeZone |
|
| 682 | - ); |
|
| 683 | - } |
|
| 684 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 685 | - throw new EE_Error( |
|
| 686 | - sprintf( |
|
| 687 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 688 | - $date_string, |
|
| 689 | - $format |
|
| 690 | - ) |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - } catch (Exception $e) { |
|
| 694 | - // if we made it here then likely then something went really wrong. |
|
| 695 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 696 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return $DateTime; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * get_timezone_transitions |
|
| 706 | - * |
|
| 707 | - * @param \DateTimeZone $DateTimeZone |
|
| 708 | - * @param int $time |
|
| 709 | - * @param bool $first_only |
|
| 710 | - * @return mixed |
|
| 711 | - */ |
|
| 712 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
| 713 | - { |
|
| 714 | - $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 715 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 716 | - $transitions = $DateTimeZone->getTransitions($time); |
|
| 717 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * get_timezone_offset |
|
| 724 | - * |
|
| 725 | - * @param \DateTimeZone $DateTimeZone |
|
| 726 | - * @param int $time |
|
| 727 | - * @return mixed |
|
| 728 | - * @throws \DomainException |
|
| 729 | - */ |
|
| 730 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 731 | - { |
|
| 732 | - $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
| 733 | - if ( ! isset($transitions['offset'])) { |
|
| 734 | - throw new DomainException(); |
|
| 735 | - } |
|
| 736 | - return $transitions['offset']; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * This will take an incoming timezone string and return the abbreviation for that timezone |
|
| 742 | - * |
|
| 743 | - * @param string $timezone_string |
|
| 744 | - * @return string abbreviation |
|
| 745 | - * @throws \EE_Error |
|
| 746 | - */ |
|
| 747 | - public function get_timezone_abbrev($timezone_string) |
|
| 748 | - { |
|
| 749 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 750 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 751 | - |
|
| 752 | - return $dateTime->format('T'); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * Overrides the parent to allow for having a dynamic "now" value |
|
| 757 | - * |
|
| 758 | - * @return mixed |
|
| 759 | - */ |
|
| 760 | - public function get_default_value() |
|
| 761 | - { |
|
| 762 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 763 | - return time(); |
|
| 764 | - } else { |
|
| 765 | - return parent::get_default_value(); |
|
| 766 | - } |
|
| 767 | - } |
|
| 19 | + /** |
|
| 20 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 21 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 22 | + * |
|
| 23 | + * @type string unix_timestamp_regex |
|
| 24 | + */ |
|
| 25 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @type string mysql_timestamp_format |
|
| 29 | + */ |
|
| 30 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @type string mysql_date_format |
|
| 34 | + */ |
|
| 35 | + const mysql_date_format = 'Y-m-d'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @type string mysql_time_format |
|
| 39 | + */ |
|
| 40 | + const mysql_time_format = 'H:i:s'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Const for using in the default value. If the field's default is set to this, |
|
| 44 | + * then we will return the time of calling `get_default_value()`, not |
|
| 45 | + * just the current time at construction |
|
| 46 | + */ |
|
| 47 | + const now = 'now'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * The following properties hold the default formats for date and time. |
|
| 51 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 52 | + * However they can also be overridden later by the set_format() method |
|
| 53 | + * (and corresponding set_date_format, set_time_format methods); |
|
| 54 | + */ |
|
| 55 | + /** |
|
| 56 | + * @type string $_date_format |
|
| 57 | + */ |
|
| 58 | + protected $_date_format = ''; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @type string $_time_format |
|
| 62 | + */ |
|
| 63 | + protected $_time_format = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @type string $_pretty_date_format |
|
| 67 | + */ |
|
| 68 | + protected $_pretty_date_format = ''; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @type string $_pretty_time_format |
|
| 72 | + */ |
|
| 73 | + protected $_pretty_time_format = ''; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @type DateTimeZone $_DateTimeZone |
|
| 77 | + */ |
|
| 78 | + protected $_DateTimeZone; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
| 82 | + */ |
|
| 83 | + protected $_UTC_DateTimeZone; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @type DateTimeZone $_blog_DateTimeZone |
|
| 87 | + */ |
|
| 88 | + protected $_blog_DateTimeZone; |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 93 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 94 | + * and time returned via getters. |
|
| 95 | + * |
|
| 96 | + * @var mixed (null|string) |
|
| 97 | + */ |
|
| 98 | + protected $_date_time_output; |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * timezone string |
|
| 103 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 104 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 105 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 106 | + * |
|
| 107 | + * @var string |
|
| 108 | + */ |
|
| 109 | + protected $_timezone_string; |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 114 | + * offsets for comparison purposes). |
|
| 115 | + * |
|
| 116 | + * @var int |
|
| 117 | + */ |
|
| 118 | + protected $_blog_offset; |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param string $table_column |
|
| 123 | + * @param string $nice_name |
|
| 124 | + * @param bool $nullable |
|
| 125 | + * @param string $default_value |
|
| 126 | + * @param string $timezone_string |
|
| 127 | + * @param string $date_format |
|
| 128 | + * @param string $time_format |
|
| 129 | + * @param string $pretty_date_format |
|
| 130 | + * @param string $pretty_time_format |
|
| 131 | + * @throws \EE_Error |
|
| 132 | + */ |
|
| 133 | + public function __construct( |
|
| 134 | + $table_column, |
|
| 135 | + $nice_name, |
|
| 136 | + $nullable, |
|
| 137 | + $default_value, |
|
| 138 | + $timezone_string = '', |
|
| 139 | + $date_format = '', |
|
| 140 | + $time_format = '', |
|
| 141 | + $pretty_date_format = '', |
|
| 142 | + $pretty_time_format = '' |
|
| 143 | + ) { |
|
| 144 | + |
|
| 145 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 146 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 147 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 148 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 149 | + |
|
| 150 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 151 | + $this->set_timezone($timezone_string); |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + public function get_wpdb_data_type() |
|
| 160 | + { |
|
| 161 | + return '%s'; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @return DateTimeZone |
|
| 167 | + * @throws \EE_Error |
|
| 168 | + */ |
|
| 169 | + public function get_UTC_DateTimeZone() |
|
| 170 | + { |
|
| 171 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 172 | + ? $this->_UTC_DateTimeZone |
|
| 173 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @return DateTimeZone |
|
| 179 | + * @throws \EE_Error |
|
| 180 | + */ |
|
| 181 | + public function get_blog_DateTimeZone() |
|
| 182 | + { |
|
| 183 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 184 | + ? $this->_blog_DateTimeZone |
|
| 185 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 191 | + * |
|
| 192 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 193 | + * timestamp |
|
| 194 | + * @return DateTime |
|
| 195 | + */ |
|
| 196 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 197 | + { |
|
| 198 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 204 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 205 | + * |
|
| 206 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 207 | + * @return string The final assembled format string. |
|
| 208 | + */ |
|
| 209 | + protected function _get_date_time_output($pretty = false) |
|
| 210 | + { |
|
| 211 | + |
|
| 212 | + switch ($this->_date_time_output) { |
|
| 213 | + case 'time' : |
|
| 214 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 215 | + break; |
|
| 216 | + |
|
| 217 | + case 'date' : |
|
| 218 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 219 | + break; |
|
| 220 | + |
|
| 221 | + default : |
|
| 222 | + return $pretty |
|
| 223 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 224 | + : $this->_date_format . ' ' . $this->_time_format; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 231 | + * returned (using the format properties) |
|
| 232 | + * |
|
| 233 | + * @param string $what acceptable values are 'time' or 'date'. |
|
| 234 | + * Any other value will be set but will always result |
|
| 235 | + * in both 'date' and 'time' being returned. |
|
| 236 | + * @return void |
|
| 237 | + */ |
|
| 238 | + public function set_date_time_output($what = null) |
|
| 239 | + { |
|
| 240 | + $this->_date_time_output = $what; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 246 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 247 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
| 248 | + * We also set some other properties in this method. |
|
| 249 | + * |
|
| 250 | + * @param string $timezone_string A valid timezone string as described by @link |
|
| 251 | + * http://www.php.net/manual/en/timezones.php |
|
| 252 | + * @return void |
|
| 253 | + * @throws \EE_Error |
|
| 254 | + */ |
|
| 255 | + public function set_timezone($timezone_string) |
|
| 256 | + { |
|
| 257 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 258 | + // leave the timezone AS-IS if we already have one and |
|
| 259 | + // the function arg didn't provide one |
|
| 260 | + return; |
|
| 261 | + } |
|
| 262 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 263 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 264 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * _create_timezone_object_from_timezone_name |
|
| 270 | + * |
|
| 271 | + * @access protected |
|
| 272 | + * @param string $timezone_string |
|
| 273 | + * @return \DateTimeZone |
|
| 274 | + * @throws \EE_Error |
|
| 275 | + */ |
|
| 276 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 277 | + { |
|
| 278 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * This just returns whatever is set for the current timezone. |
|
| 284 | + * |
|
| 285 | + * @access public |
|
| 286 | + * @return string timezone string |
|
| 287 | + */ |
|
| 288 | + public function get_timezone() |
|
| 289 | + { |
|
| 290 | + return $this->_timezone_string; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * set the $_date_format property |
|
| 296 | + * |
|
| 297 | + * @access public |
|
| 298 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 299 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 300 | + * @return void |
|
| 301 | + */ |
|
| 302 | + public function set_date_format($format, $pretty = false) |
|
| 303 | + { |
|
| 304 | + if ($pretty) { |
|
| 305 | + $this->_pretty_date_format = $format; |
|
| 306 | + } else { |
|
| 307 | + $this->_date_format = $format; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * return the $_date_format property value. |
|
| 314 | + * |
|
| 315 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + public function get_date_format($pretty = false) |
|
| 319 | + { |
|
| 320 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * set the $_time_format property |
|
| 326 | + * |
|
| 327 | + * @access public |
|
| 328 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 329 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 330 | + * @return void |
|
| 331 | + */ |
|
| 332 | + public function set_time_format($format, $pretty = false) |
|
| 333 | + { |
|
| 334 | + if ($pretty) { |
|
| 335 | + $this->_pretty_time_format = $format; |
|
| 336 | + } else { |
|
| 337 | + $this->_time_format = $format; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * return the $_time_format property value. |
|
| 344 | + * |
|
| 345 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 346 | + * @return string |
|
| 347 | + */ |
|
| 348 | + public function get_time_format($pretty = false) |
|
| 349 | + { |
|
| 350 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * set the $_pretty_date_format property |
|
| 356 | + * |
|
| 357 | + * @access public |
|
| 358 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 359 | + * @return void |
|
| 360 | + */ |
|
| 361 | + public function set_pretty_date_format($format) |
|
| 362 | + { |
|
| 363 | + $this->_pretty_date_format = $format; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * set the $_pretty_time_format property |
|
| 369 | + * |
|
| 370 | + * @access public |
|
| 371 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 372 | + * @return void |
|
| 373 | + */ |
|
| 374 | + public function set_pretty_time_format($format) |
|
| 375 | + { |
|
| 376 | + $this->_pretty_time_format = $format; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Only sets the time portion of the datetime. |
|
| 382 | + * |
|
| 383 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 384 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 385 | + * @return DateTime |
|
| 386 | + */ |
|
| 387 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 388 | + { |
|
| 389 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 390 | + // Otherwise parse the string. |
|
| 391 | + if ($time_to_set_string instanceof DateTime) { |
|
| 392 | + $parsed = array( |
|
| 393 | + 'hour' => $time_to_set_string->format('H'), |
|
| 394 | + 'minute' => $time_to_set_string->format('i'), |
|
| 395 | + 'second' => $time_to_set_string->format('s'), |
|
| 396 | + ); |
|
| 397 | + } else { |
|
| 398 | + //parse incoming string |
|
| 399 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + //make sure $current is in the correct timezone. |
|
| 403 | + $current->setTimezone($this->_DateTimeZone); |
|
| 404 | + |
|
| 405 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Only sets the date portion of the datetime. |
|
| 411 | + * |
|
| 412 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 413 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 414 | + * @return DateTime |
|
| 415 | + */ |
|
| 416 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 417 | + { |
|
| 418 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 419 | + // Otherwise parse the string. |
|
| 420 | + if ($date_to_set_string instanceof DateTime) { |
|
| 421 | + $parsed = array( |
|
| 422 | + 'year' => $date_to_set_string->format('Y'), |
|
| 423 | + 'month' => $date_to_set_string->format('m'), |
|
| 424 | + 'day' => $date_to_set_string->format('d'), |
|
| 425 | + ); |
|
| 426 | + } else { |
|
| 427 | + //parse incoming string |
|
| 428 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + //make sure $current is in the correct timezone |
|
| 432 | + $current->setTimezone($this->_DateTimeZone); |
|
| 433 | + |
|
| 434 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
| 440 | + * datetime gets to this stage it should ALREADY be in UTC time |
|
| 441 | + * |
|
| 442 | + * @param DateTime $DateTime |
|
| 443 | + * @return string formatted date time for given timezone |
|
| 444 | + * @throws \EE_Error |
|
| 445 | + */ |
|
| 446 | + public function prepare_for_get($DateTime) |
|
| 447 | + { |
|
| 448 | + return $this->_prepare_for_display($DateTime); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
| 454 | + * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
| 455 | + * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
| 456 | + * abbreviation to the date_string. |
|
| 457 | + * |
|
| 458 | + * @param mixed $DateTime |
|
| 459 | + * @param null $schema |
|
| 460 | + * @return string |
|
| 461 | + * @throws \EE_Error |
|
| 462 | + */ |
|
| 463 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 464 | + { |
|
| 465 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 471 | + * timezone). |
|
| 472 | + * |
|
| 473 | + * @param DateTime $DateTime |
|
| 474 | + * @param bool|string $schema |
|
| 475 | + * @return string |
|
| 476 | + * @throws \EE_Error |
|
| 477 | + */ |
|
| 478 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
| 479 | + { |
|
| 480 | + if (! $DateTime instanceof DateTime) { |
|
| 481 | + if ($this->_nullable) { |
|
| 482 | + return ''; |
|
| 483 | + } else { |
|
| 484 | + if (WP_DEBUG) { |
|
| 485 | + throw new EE_Error( |
|
| 486 | + sprintf( |
|
| 487 | + __( |
|
| 488 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 489 | + 'event_espresso' |
|
| 490 | + ), |
|
| 491 | + $this->_nicename |
|
| 492 | + ) |
|
| 493 | + ); |
|
| 494 | + } else { |
|
| 495 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 496 | + EE_Error::add_error( |
|
| 497 | + sprintf( |
|
| 498 | + __( |
|
| 499 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 500 | + 'event_espresso' |
|
| 501 | + ), |
|
| 502 | + $this->_nicename |
|
| 503 | + ) |
|
| 504 | + ); |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + $format_string = $this->_get_date_time_output($schema); |
|
| 509 | + //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 510 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 511 | + if ($schema) { |
|
| 512 | + if ($this->_display_timezone()) { |
|
| 513 | + //must be explicit because schema could equal true. |
|
| 514 | + if ($schema === 'no_html') { |
|
| 515 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 516 | + } else { |
|
| 517 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 518 | + } |
|
| 519 | + } else { |
|
| 520 | + $timezone_string = ''; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + return $DateTime->format($format_string) . $timezone_string; |
|
| 524 | + } else { |
|
| 525 | + return $DateTime->format($format_string); |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 532 | + * timezone). |
|
| 533 | + * |
|
| 534 | + * @param mixed $datetime_value u |
|
| 535 | + * @return string mysql timestamp in UTC |
|
| 536 | + * @throws \EE_Error |
|
| 537 | + */ |
|
| 538 | + public function prepare_for_use_in_db($datetime_value) |
|
| 539 | + { |
|
| 540 | + //we allow an empty value or DateTime object, but nothing else. |
|
| 541 | + if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 542 | + throw new EE_Error( |
|
| 543 | + __( |
|
| 544 | + 'The incoming value being prepared for setting in the database must either be empty or a php DateTime object', |
|
| 545 | + 'event_espresso' |
|
| 546 | + ) |
|
| 547 | + ); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + if ($datetime_value instanceof DateTime) { |
|
| 551 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 552 | + $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 556 | + EE_Datetime_Field::mysql_timestamp_format |
|
| 557 | + ); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 561 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
| 567 | + * allowed) |
|
| 568 | + * |
|
| 569 | + * @param string $datetime_string mysql timestamp in UTC |
|
| 570 | + * @return mixed null | DateTime |
|
| 571 | + * @throws \EE_Error |
|
| 572 | + */ |
|
| 573 | + public function prepare_for_set_from_db($datetime_string) |
|
| 574 | + { |
|
| 575 | + //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 576 | + if (empty($datetime_string) && $this->_nullable) { |
|
| 577 | + return null; |
|
| 578 | + } |
|
| 579 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 580 | + if (empty($datetime_string)) { |
|
| 581 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 582 | + } else { |
|
| 583 | + $DateTime = DateTime::createFromFormat( |
|
| 584 | + EE_Datetime_Field::mysql_timestamp_format, |
|
| 585 | + $datetime_string, |
|
| 586 | + $this->get_UTC_DateTimeZone() |
|
| 587 | + ); |
|
| 588 | + if ($DateTime instanceof \DateTime) { |
|
| 589 | + $DateTime = new DbSafeDateTime( |
|
| 590 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 591 | + $this->get_UTC_DateTimeZone() |
|
| 592 | + ); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
| 597 | + // if still no datetime object, then let's just use now |
|
| 598 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 599 | + } |
|
| 600 | + // THEN apply the field's set DateTimeZone |
|
| 601 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 602 | + |
|
| 603 | + return $DateTime; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * All this method does is determine if we're going to display the timezone string or not on any output. |
|
| 609 | + * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
| 610 | + * If so, then true. |
|
| 611 | + * |
|
| 612 | + * @return bool true for yes false for no |
|
| 613 | + * @throws \EE_Error |
|
| 614 | + */ |
|
| 615 | + protected function _display_timezone() |
|
| 616 | + { |
|
| 617 | + |
|
| 618 | + // first let's do a comparison of timezone strings. |
|
| 619 | + // If they match then we can get out without any further calculations |
|
| 620 | + $blog_string = get_option('timezone_string'); |
|
| 621 | + if ($blog_string === $this->_timezone_string) { |
|
| 622 | + return false; |
|
| 623 | + } |
|
| 624 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 625 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 626 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 627 | + // now compare |
|
| 628 | + return $blog_offset !== $this_offset; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 634 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 635 | + * with. |
|
| 636 | + * |
|
| 637 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 638 | + * in the format that is set on the date_field (or DateTime |
|
| 639 | + * object)! |
|
| 640 | + * @return DateTime |
|
| 641 | + */ |
|
| 642 | + protected function _get_date_object($date_string) |
|
| 643 | + { |
|
| 644 | + //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 645 | + if ($this->_nullable && empty($date_string)) { |
|
| 646 | + return null; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + // if incoming date |
|
| 650 | + if ($date_string instanceof DateTime) { |
|
| 651 | + $date_string->setTimezone($this->_DateTimeZone); |
|
| 652 | + |
|
| 653 | + return $date_string; |
|
| 654 | + } |
|
| 655 | + // if empty date_string and made it here. |
|
| 656 | + // Return a datetime object for now in the given timezone. |
|
| 657 | + if (empty($date_string)) { |
|
| 658 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 659 | + } |
|
| 660 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 661 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 662 | + try { |
|
| 663 | + // This is operating under the assumption that the incoming Unix timestamp |
|
| 664 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 665 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 666 | + $DateTime->setTimestamp($date_string); |
|
| 667 | + |
|
| 668 | + return $DateTime; |
|
| 669 | + } catch (Exception $e) { |
|
| 670 | + // should be rare, but if things got fooled then let's just continue |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 674 | + //create the DateTime object. |
|
| 675 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 676 | + try { |
|
| 677 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 678 | + if ($DateTime instanceof DateTime) { |
|
| 679 | + $DateTime = new DbSafeDateTime( |
|
| 680 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 681 | + $this->_DateTimeZone |
|
| 682 | + ); |
|
| 683 | + } |
|
| 684 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
| 685 | + throw new EE_Error( |
|
| 686 | + sprintf( |
|
| 687 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 688 | + $date_string, |
|
| 689 | + $format |
|
| 690 | + ) |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + } catch (Exception $e) { |
|
| 694 | + // if we made it here then likely then something went really wrong. |
|
| 695 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 696 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return $DateTime; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * get_timezone_transitions |
|
| 706 | + * |
|
| 707 | + * @param \DateTimeZone $DateTimeZone |
|
| 708 | + * @param int $time |
|
| 709 | + * @param bool $first_only |
|
| 710 | + * @return mixed |
|
| 711 | + */ |
|
| 712 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
| 713 | + { |
|
| 714 | + $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 715 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 716 | + $transitions = $DateTimeZone->getTransitions($time); |
|
| 717 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * get_timezone_offset |
|
| 724 | + * |
|
| 725 | + * @param \DateTimeZone $DateTimeZone |
|
| 726 | + * @param int $time |
|
| 727 | + * @return mixed |
|
| 728 | + * @throws \DomainException |
|
| 729 | + */ |
|
| 730 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 731 | + { |
|
| 732 | + $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
| 733 | + if ( ! isset($transitions['offset'])) { |
|
| 734 | + throw new DomainException(); |
|
| 735 | + } |
|
| 736 | + return $transitions['offset']; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * This will take an incoming timezone string and return the abbreviation for that timezone |
|
| 742 | + * |
|
| 743 | + * @param string $timezone_string |
|
| 744 | + * @return string abbreviation |
|
| 745 | + * @throws \EE_Error |
|
| 746 | + */ |
|
| 747 | + public function get_timezone_abbrev($timezone_string) |
|
| 748 | + { |
|
| 749 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 750 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 751 | + |
|
| 752 | + return $dateTime->format('T'); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * Overrides the parent to allow for having a dynamic "now" value |
|
| 757 | + * |
|
| 758 | + * @return mixed |
|
| 759 | + */ |
|
| 760 | + public function get_default_value() |
|
| 761 | + { |
|
| 762 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 763 | + return time(); |
|
| 764 | + } else { |
|
| 765 | + return parent::get_default_value(); |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | 768 | |
| 769 | 769 | |
| 770 | 770 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,239 +40,239 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.025'); |
|
| 105 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + /** |
|
| 97 | + * espresso_version |
|
| 98 | + * Returns the plugin version |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + function espresso_version() |
|
| 103 | + { |
|
| 104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.025'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - /** |
|
| 197 | - * espresso_plugin_activation |
|
| 198 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 199 | - */ |
|
| 200 | - function espresso_plugin_activation() |
|
| 201 | - { |
|
| 202 | - update_option('ee_espresso_activation', true); |
|
| 203 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + /** |
|
| 197 | + * espresso_plugin_activation |
|
| 198 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 199 | + */ |
|
| 200 | + function espresso_plugin_activation() |
|
| 201 | + { |
|
| 202 | + update_option('ee_espresso_activation', true); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 206 | - /** |
|
| 207 | - * espresso_load_error_handling |
|
| 208 | - * this function loads EE's class for handling exceptions and errors |
|
| 209 | - */ |
|
| 210 | - function espresso_load_error_handling() |
|
| 211 | - { |
|
| 212 | - // load debugging tools |
|
| 213 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 214 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 215 | - EEH_Debug_Tools::instance(); |
|
| 216 | - } |
|
| 217 | - // load error handling |
|
| 218 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 219 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 220 | - } else { |
|
| 221 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 222 | - } |
|
| 223 | - } |
|
| 205 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 206 | + /** |
|
| 207 | + * espresso_load_error_handling |
|
| 208 | + * this function loads EE's class for handling exceptions and errors |
|
| 209 | + */ |
|
| 210 | + function espresso_load_error_handling() |
|
| 211 | + { |
|
| 212 | + // load debugging tools |
|
| 213 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 214 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 215 | + EEH_Debug_Tools::instance(); |
|
| 216 | + } |
|
| 217 | + // load error handling |
|
| 218 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 219 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 220 | + } else { |
|
| 221 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * espresso_load_required |
|
| 227 | - * given a class name and path, this function will load that file or throw an exception |
|
| 228 | - * |
|
| 229 | - * @param string $classname |
|
| 230 | - * @param string $full_path_to_file |
|
| 231 | - * @throws EE_Error |
|
| 232 | - */ |
|
| 233 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 234 | - { |
|
| 235 | - static $error_handling_loaded = false; |
|
| 236 | - if ( ! $error_handling_loaded) { |
|
| 237 | - espresso_load_error_handling(); |
|
| 238 | - $error_handling_loaded = true; |
|
| 239 | - } |
|
| 240 | - if (is_readable($full_path_to_file)) { |
|
| 241 | - require_once($full_path_to_file); |
|
| 242 | - } else { |
|
| 243 | - throw new EE_Error ( |
|
| 244 | - sprintf( |
|
| 245 | - esc_html__( |
|
| 246 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 247 | - 'event_espresso' |
|
| 248 | - ), |
|
| 249 | - $classname |
|
| 250 | - ) |
|
| 251 | - ); |
|
| 252 | - } |
|
| 253 | - } |
|
| 225 | + /** |
|
| 226 | + * espresso_load_required |
|
| 227 | + * given a class name and path, this function will load that file or throw an exception |
|
| 228 | + * |
|
| 229 | + * @param string $classname |
|
| 230 | + * @param string $full_path_to_file |
|
| 231 | + * @throws EE_Error |
|
| 232 | + */ |
|
| 233 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 234 | + { |
|
| 235 | + static $error_handling_loaded = false; |
|
| 236 | + if ( ! $error_handling_loaded) { |
|
| 237 | + espresso_load_error_handling(); |
|
| 238 | + $error_handling_loaded = true; |
|
| 239 | + } |
|
| 240 | + if (is_readable($full_path_to_file)) { |
|
| 241 | + require_once($full_path_to_file); |
|
| 242 | + } else { |
|
| 243 | + throw new EE_Error ( |
|
| 244 | + sprintf( |
|
| 245 | + esc_html__( |
|
| 246 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 247 | + 'event_espresso' |
|
| 248 | + ), |
|
| 249 | + $classname |
|
| 250 | + ) |
|
| 251 | + ); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 256 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 257 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 258 | - new EE_Bootstrap(); |
|
| 259 | - } |
|
| 255 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 256 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 257 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 258 | + new EE_Bootstrap(); |
|
| 259 | + } |
|
| 260 | 260 | } |
| 261 | 261 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 262 | - /** |
|
| 263 | - * deactivate_plugin |
|
| 264 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 265 | - * |
|
| 266 | - * @access public |
|
| 267 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 268 | - * @return void |
|
| 269 | - */ |
|
| 270 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 271 | - { |
|
| 272 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 273 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 274 | - } |
|
| 275 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 276 | - deactivate_plugins($plugin_basename); |
|
| 277 | - } |
|
| 262 | + /** |
|
| 263 | + * deactivate_plugin |
|
| 264 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 265 | + * |
|
| 266 | + * @access public |
|
| 267 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 268 | + * @return void |
|
| 269 | + */ |
|
| 270 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 271 | + { |
|
| 272 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 273 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 274 | + } |
|
| 275 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 276 | + deactivate_plugins($plugin_basename); |
|
| 277 | + } |
|
| 278 | 278 | } |