@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | * @param string $name |
| 492 | 492 | * @param string $config_class |
| 493 | 493 | * @param EE_Config_Base $config_obj |
| 494 | - * @param array $tests_to_run |
|
| 494 | + * @param integer[] $tests_to_run |
|
| 495 | 495 | * @param bool $display_errors |
| 496 | 496 | * @return bool TRUE on success, FALSE on fail |
| 497 | 497 | */ |
@@ -1794,7 +1794,7 @@ discard block |
||
| 1794 | 1794 | |
| 1795 | 1795 | |
| 1796 | 1796 | /** |
| 1797 | - * @return array |
|
| 1797 | + * @return integer[] |
|
| 1798 | 1798 | */ |
| 1799 | 1799 | public function get_critical_pages_array() |
| 1800 | 1800 | { |
@@ -1808,7 +1808,7 @@ discard block |
||
| 1808 | 1808 | |
| 1809 | 1809 | |
| 1810 | 1810 | /** |
| 1811 | - * @return array |
|
| 1811 | + * @return string[] |
|
| 1812 | 1812 | */ |
| 1813 | 1813 | public function get_critical_pages_shortcodes_array() |
| 1814 | 1814 | { |
@@ -3088,7 +3088,7 @@ discard block |
||
| 3088 | 3088 | * according to max_input_vars |
| 3089 | 3089 | * |
| 3090 | 3090 | * @param int $input_count the count of input vars. |
| 3091 | - * @return array { |
|
| 3091 | + * @return string { |
|
| 3092 | 3092 | * An array that represents whether available space and if no available space the error |
| 3093 | 3093 | * message. |
| 3094 | 3094 | * @type bool $has_space whether more inputs can be added. |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -13,1566 +13,1566 @@ discard block |
||
| 13 | 13 | final class EE_Config |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - const OPTION_NAME = 'ee_config'; |
|
| 17 | - |
|
| 18 | - const LOG_NAME = 'ee_config_log'; |
|
| 19 | - |
|
| 20 | - const LOG_LENGTH = 100; |
|
| 21 | - |
|
| 22 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * instance of the EE_Config object |
|
| 27 | - * |
|
| 28 | - * @var EE_Config $_instance |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var boolean $_logging_enabled |
|
| 35 | - */ |
|
| 36 | - private static $_logging_enabled = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * An StdClass whose property names are addon slugs, |
|
| 40 | - * and values are their config classes |
|
| 41 | - * |
|
| 42 | - * @var StdClass |
|
| 43 | - */ |
|
| 44 | - public $addons; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EE_Admin_Config |
|
| 48 | - */ |
|
| 49 | - public $admin; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Core_Config |
|
| 53 | - */ |
|
| 54 | - public $core; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Currency_Config |
|
| 58 | - */ |
|
| 59 | - public $currency; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var EE_Organization_Config |
|
| 63 | - */ |
|
| 64 | - public $organization; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var EE_Registration_Config |
|
| 68 | - */ |
|
| 69 | - public $registration; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_Template_Config |
|
| 73 | - */ |
|
| 74 | - public $template_settings; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Holds EE environment values. |
|
| 78 | - * |
|
| 79 | - * @var EE_Environment_Config |
|
| 80 | - */ |
|
| 81 | - public $environment; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * settings pertaining to Google maps |
|
| 85 | - * |
|
| 86 | - * @var EE_Map_Config |
|
| 87 | - */ |
|
| 88 | - public $map_settings; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * settings pertaining to Taxes |
|
| 92 | - * |
|
| 93 | - * @var EE_Tax_Config |
|
| 94 | - */ |
|
| 95 | - public $tax_settings; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @deprecated |
|
| 99 | - * @var EE_Gateway_Config |
|
| 100 | - */ |
|
| 101 | - public $gateway; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @var array $_addon_option_names |
|
| 105 | - * @access private |
|
| 106 | - */ |
|
| 107 | - private $_addon_option_names = array(); |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @var array $_module_route_map |
|
| 111 | - * @access private |
|
| 112 | - */ |
|
| 113 | - private static $_module_route_map = array(); |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var array $_module_forward_map |
|
| 117 | - * @access private |
|
| 118 | - */ |
|
| 119 | - private static $_module_forward_map = array(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var array $_module_view_map |
|
| 123 | - * @access private |
|
| 124 | - */ |
|
| 125 | - private static $_module_view_map = array(); |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @singleton method used to instantiate class object |
|
| 130 | - * @access public |
|
| 131 | - * @return EE_Config instance |
|
| 132 | - */ |
|
| 133 | - public static function instance() |
|
| 134 | - { |
|
| 135 | - // check if class object is instantiated, and instantiated properly |
|
| 136 | - if (! self::$_instance instanceof EE_Config) { |
|
| 137 | - self::$_instance = new self(); |
|
| 138 | - } |
|
| 139 | - return self::$_instance; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Resets the config |
|
| 145 | - * |
|
| 146 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 147 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 148 | - * reflect its state in the database |
|
| 149 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 150 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 151 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 152 | - * site was put into maintenance mode) |
|
| 153 | - * @return EE_Config |
|
| 154 | - */ |
|
| 155 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 156 | - { |
|
| 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(); |
|
| 164 | - } |
|
| 165 | - self::$_instance = null; |
|
| 166 | - //we don't need to reset the static properties imo because those should |
|
| 167 | - //only change when a module is added or removed. Currently we don't |
|
| 168 | - //support removing a module during a request when it previously existed |
|
| 169 | - if ($reinstantiate) { |
|
| 170 | - return self::instance(); |
|
| 171 | - } else { |
|
| 172 | - return null; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * class constructor |
|
| 179 | - * |
|
| 180 | - * @access private |
|
| 181 | - */ |
|
| 182 | - private function __construct() |
|
| 183 | - { |
|
| 184 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 185 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 186 | - // setup empty config classes |
|
| 187 | - $this->_initialize_config(); |
|
| 188 | - // load existing EE site settings |
|
| 189 | - $this->_load_core_config(); |
|
| 190 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 191 | - $this->_verify_config(); |
|
| 192 | - // register shortcodes and modules |
|
| 193 | - add_action( |
|
| 194 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 195 | - array($this, 'register_shortcodes_and_modules'), |
|
| 196 | - 999 |
|
| 197 | - ); |
|
| 198 | - // initialize shortcodes and modules |
|
| 199 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 200 | - // register widgets |
|
| 201 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 202 | - // shutdown |
|
| 203 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 204 | - // construct__end hook |
|
| 205 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 206 | - // hardcoded hack |
|
| 207 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return boolean |
|
| 213 | - */ |
|
| 214 | - public static function logging_enabled() |
|
| 215 | - { |
|
| 216 | - return self::$_logging_enabled; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * use to get the current theme if needed from static context |
|
| 222 | - * |
|
| 223 | - * @return string current theme set. |
|
| 224 | - */ |
|
| 225 | - public static function get_current_theme() |
|
| 226 | - { |
|
| 227 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 228 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * _initialize_config |
|
| 234 | - * |
|
| 235 | - * @access private |
|
| 236 | - * @return void |
|
| 237 | - */ |
|
| 238 | - private function _initialize_config() |
|
| 239 | - { |
|
| 240 | - EE_Config::trim_log(); |
|
| 241 | - //set defaults |
|
| 242 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 243 | - $this->addons = new stdClass(); |
|
| 244 | - // set _module_route_map |
|
| 245 | - EE_Config::$_module_route_map = array(); |
|
| 246 | - // set _module_forward_map |
|
| 247 | - EE_Config::$_module_forward_map = array(); |
|
| 248 | - // set _module_view_map |
|
| 249 | - EE_Config::$_module_view_map = array(); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * load core plugin configuration |
|
| 255 | - * |
|
| 256 | - * @access private |
|
| 257 | - * @return void |
|
| 258 | - */ |
|
| 259 | - private function _load_core_config() |
|
| 260 | - { |
|
| 261 | - // load_core_config__start hook |
|
| 262 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 263 | - $espresso_config = $this->get_espresso_config(); |
|
| 264 | - foreach ($espresso_config as $config => $settings) { |
|
| 265 | - // load_core_config__start hook |
|
| 266 | - $settings = apply_filters( |
|
| 267 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 268 | - $settings, |
|
| 269 | - $config, |
|
| 270 | - $this |
|
| 271 | - ); |
|
| 272 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 273 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 274 | - //call configs populate method to ensure any defaults are set for empty values. |
|
| 275 | - if (method_exists($settings, 'populate')) { |
|
| 276 | - $this->{$config}->populate(); |
|
| 277 | - } |
|
| 278 | - if (method_exists($settings, 'do_hooks')) { |
|
| 279 | - $this->{$config}->do_hooks(); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 284 | - $this->update_espresso_config(); |
|
| 285 | - } |
|
| 286 | - // load_core_config__end hook |
|
| 287 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * _verify_config |
|
| 293 | - * |
|
| 294 | - * @access protected |
|
| 295 | - * @return void |
|
| 296 | - */ |
|
| 297 | - protected function _verify_config() |
|
| 298 | - { |
|
| 299 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 300 | - ? $this->core |
|
| 301 | - : new EE_Core_Config(); |
|
| 302 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 303 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 304 | - ? $this->organization |
|
| 305 | - : new EE_Organization_Config(); |
|
| 306 | - $this->organization = apply_filters('FHEE__EE_Config___initialize_config__organization', |
|
| 307 | - $this->organization); |
|
| 308 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 309 | - ? $this->currency |
|
| 310 | - : new EE_Currency_Config(); |
|
| 311 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 312 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 313 | - ? $this->registration |
|
| 314 | - : new EE_Registration_Config(); |
|
| 315 | - $this->registration = apply_filters('FHEE__EE_Config___initialize_config__registration', |
|
| 316 | - $this->registration); |
|
| 317 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 318 | - ? $this->admin |
|
| 319 | - : new EE_Admin_Config(); |
|
| 320 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 321 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 322 | - ? $this->template_settings |
|
| 323 | - : new EE_Template_Config(); |
|
| 324 | - $this->template_settings = apply_filters( |
|
| 325 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 326 | - $this->template_settings |
|
| 327 | - ); |
|
| 328 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 329 | - ? $this->map_settings |
|
| 330 | - : new EE_Map_Config(); |
|
| 331 | - $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 332 | - $this->map_settings); |
|
| 333 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 334 | - ? $this->environment |
|
| 335 | - : new EE_Environment_Config(); |
|
| 336 | - $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 337 | - $this->environment); |
|
| 338 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 339 | - ? $this->tax_settings |
|
| 340 | - : new EE_Tax_Config(); |
|
| 341 | - $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 342 | - $this->tax_settings); |
|
| 343 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 344 | - ? $this->gateway |
|
| 345 | - : new EE_Gateway_Config(); |
|
| 346 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * get_espresso_config |
|
| 352 | - * |
|
| 353 | - * @access public |
|
| 354 | - * @return array of espresso config stuff |
|
| 355 | - */ |
|
| 356 | - public function get_espresso_config() |
|
| 357 | - { |
|
| 358 | - // grab espresso configuration |
|
| 359 | - return apply_filters( |
|
| 360 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 361 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 362 | - ); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * double_check_config_comparison |
|
| 368 | - * |
|
| 369 | - * @access public |
|
| 370 | - * @param string $option |
|
| 371 | - * @param $old_value |
|
| 372 | - * @param $value |
|
| 373 | - */ |
|
| 374 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 375 | - { |
|
| 376 | - // make sure we're checking the ee config |
|
| 377 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 378 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 379 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 380 | - if ($value != $old_value) { |
|
| 381 | - // if they are NOT the same, then remove the hook, |
|
| 382 | - // which means the subsequent update results will be based solely on the update query results |
|
| 383 | - // the reason we do this is because, as stated above, |
|
| 384 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 385 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 386 | - // If values are found to match their previous old value, |
|
| 387 | - // then WP bails before performing any update. |
|
| 388 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 389 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 390 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 391 | - // MySQL MAY ALSO NOT perform the update because |
|
| 392 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 393 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 394 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 395 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * update_espresso_config |
|
| 403 | - * |
|
| 404 | - * @access public |
|
| 405 | - */ |
|
| 406 | - protected function _reset_espresso_addon_config() |
|
| 407 | - { |
|
| 408 | - $this->_addon_option_names = array(); |
|
| 409 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 410 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 411 | - $config_class = get_class($addon_config_obj); |
|
| 412 | - if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
| 413 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 414 | - } |
|
| 415 | - $this->addons->{$addon_name} = null; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * update_espresso_config |
|
| 422 | - * |
|
| 423 | - * @access public |
|
| 424 | - * @param bool $add_success |
|
| 425 | - * @param bool $add_error |
|
| 426 | - * @return bool |
|
| 427 | - */ |
|
| 428 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 429 | - { |
|
| 430 | - // don't allow config updates during WP heartbeats |
|
| 431 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 432 | - return false; |
|
| 433 | - } |
|
| 434 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 435 | - //$clone = clone( self::$_instance ); |
|
| 436 | - //self::$_instance = NULL; |
|
| 437 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 438 | - $this->_reset_espresso_addon_config(); |
|
| 439 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 440 | - // but BEFORE the actual update occurs |
|
| 441 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 442 | - // now update "ee_config" |
|
| 443 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 444 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 445 | - // if not saved... check if the hook we just added still exists; |
|
| 446 | - // if it does, it means one of two things: |
|
| 447 | - // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 448 | - // or... |
|
| 449 | - // the db update query returned 0 rows affected |
|
| 450 | - // (probably because the data value was the same from it's perspective) |
|
| 451 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 452 | - // but just means no update occurred, so don't display an error to the user. |
|
| 453 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 454 | - // then it means that something truly went wrong |
|
| 455 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 456 | - // remove our action since we don't want it in the system anymore |
|
| 457 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 458 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 459 | - //self::$_instance = $clone; |
|
| 460 | - //unset( $clone ); |
|
| 461 | - // if config remains the same or was updated successfully |
|
| 462 | - if ($saved) { |
|
| 463 | - if ($add_success) { |
|
| 464 | - EE_Error::add_success( |
|
| 465 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 466 | - __FILE__, |
|
| 467 | - __FUNCTION__, |
|
| 468 | - __LINE__ |
|
| 469 | - ); |
|
| 470 | - } |
|
| 471 | - return true; |
|
| 472 | - } else { |
|
| 473 | - if ($add_error) { |
|
| 474 | - EE_Error::add_error( |
|
| 475 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 476 | - __FILE__, |
|
| 477 | - __FUNCTION__, |
|
| 478 | - __LINE__ |
|
| 479 | - ); |
|
| 480 | - } |
|
| 481 | - return false; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * _verify_config_params |
|
| 488 | - * |
|
| 489 | - * @access private |
|
| 490 | - * @param string $section |
|
| 491 | - * @param string $name |
|
| 492 | - * @param string $config_class |
|
| 493 | - * @param EE_Config_Base $config_obj |
|
| 494 | - * @param array $tests_to_run |
|
| 495 | - * @param bool $display_errors |
|
| 496 | - * @return bool TRUE on success, FALSE on fail |
|
| 497 | - */ |
|
| 498 | - private function _verify_config_params( |
|
| 499 | - $section = '', |
|
| 500 | - $name = '', |
|
| 501 | - $config_class = '', |
|
| 502 | - $config_obj = null, |
|
| 503 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 504 | - $display_errors = true |
|
| 505 | - ) { |
|
| 506 | - try { |
|
| 507 | - foreach ($tests_to_run as $test) { |
|
| 508 | - switch ($test) { |
|
| 509 | - // TEST #1 : check that section was set |
|
| 510 | - case 1 : |
|
| 511 | - if (empty($section)) { |
|
| 512 | - if ($display_errors) { |
|
| 513 | - throw new EE_Error( |
|
| 514 | - sprintf( |
|
| 515 | - __( |
|
| 516 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 517 | - 'event_espresso' |
|
| 518 | - ), |
|
| 519 | - $config_class |
|
| 520 | - ) |
|
| 521 | - ); |
|
| 522 | - } |
|
| 523 | - return false; |
|
| 524 | - } |
|
| 525 | - break; |
|
| 526 | - // TEST #2 : check that settings section exists |
|
| 527 | - case 2 : |
|
| 528 | - if (! isset($this->{$section})) { |
|
| 529 | - if ($display_errors) { |
|
| 530 | - throw new EE_Error( |
|
| 531 | - sprintf( |
|
| 532 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 533 | - $section |
|
| 534 | - ) |
|
| 535 | - ); |
|
| 536 | - } |
|
| 537 | - return false; |
|
| 538 | - } |
|
| 539 | - break; |
|
| 540 | - // TEST #3 : check that section is the proper format |
|
| 541 | - case 3 : |
|
| 542 | - if ( |
|
| 543 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 544 | - ) { |
|
| 545 | - if ($display_errors) { |
|
| 546 | - throw new EE_Error( |
|
| 547 | - sprintf( |
|
| 548 | - __( |
|
| 549 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 550 | - 'event_espresso' |
|
| 551 | - ), |
|
| 552 | - $section |
|
| 553 | - ) |
|
| 554 | - ); |
|
| 555 | - } |
|
| 556 | - return false; |
|
| 557 | - } |
|
| 558 | - break; |
|
| 559 | - // TEST #4 : check that config section name has been set |
|
| 560 | - case 4 : |
|
| 561 | - if (empty($name)) { |
|
| 562 | - if ($display_errors) { |
|
| 563 | - throw new EE_Error( |
|
| 564 | - __( |
|
| 565 | - 'No name has been provided for the specific configuration section.', |
|
| 566 | - 'event_espresso' |
|
| 567 | - ) |
|
| 568 | - ); |
|
| 569 | - } |
|
| 570 | - return false; |
|
| 571 | - } |
|
| 572 | - break; |
|
| 573 | - // TEST #5 : check that a config class name has been set |
|
| 574 | - case 5 : |
|
| 575 | - if (empty($config_class)) { |
|
| 576 | - if ($display_errors) { |
|
| 577 | - throw new EE_Error( |
|
| 578 | - __( |
|
| 579 | - 'No class name has been provided for the specific configuration section.', |
|
| 580 | - 'event_espresso' |
|
| 581 | - ) |
|
| 582 | - ); |
|
| 583 | - } |
|
| 584 | - return false; |
|
| 585 | - } |
|
| 586 | - break; |
|
| 587 | - // TEST #6 : verify config class is accessible |
|
| 588 | - case 6 : |
|
| 589 | - if (! class_exists($config_class)) { |
|
| 590 | - if ($display_errors) { |
|
| 591 | - throw new EE_Error( |
|
| 592 | - sprintf( |
|
| 593 | - __( |
|
| 594 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 595 | - 'event_espresso' |
|
| 596 | - ), |
|
| 597 | - $config_class |
|
| 598 | - ) |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - return false; |
|
| 602 | - } |
|
| 603 | - break; |
|
| 604 | - // TEST #7 : check that config has even been set |
|
| 605 | - case 7 : |
|
| 606 | - if (! isset($this->{$section}->{$name})) { |
|
| 607 | - if ($display_errors) { |
|
| 608 | - throw new EE_Error( |
|
| 609 | - sprintf( |
|
| 610 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 611 | - $section, |
|
| 612 | - $name |
|
| 613 | - ) |
|
| 614 | - ); |
|
| 615 | - } |
|
| 616 | - return false; |
|
| 617 | - } else { |
|
| 618 | - // and make sure it's not serialized |
|
| 619 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 620 | - } |
|
| 621 | - break; |
|
| 622 | - // TEST #8 : check that config is the requested type |
|
| 623 | - case 8 : |
|
| 624 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 625 | - if ($display_errors) { |
|
| 626 | - throw new EE_Error( |
|
| 627 | - sprintf( |
|
| 628 | - __( |
|
| 629 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 630 | - 'event_espresso' |
|
| 631 | - ), |
|
| 632 | - $section, |
|
| 633 | - $name, |
|
| 634 | - $config_class |
|
| 635 | - ) |
|
| 636 | - ); |
|
| 637 | - } |
|
| 638 | - return false; |
|
| 639 | - } |
|
| 640 | - break; |
|
| 641 | - // TEST #9 : verify config object |
|
| 642 | - case 9 : |
|
| 643 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 644 | - if ($display_errors) { |
|
| 645 | - throw new EE_Error( |
|
| 646 | - sprintf( |
|
| 647 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 648 | - print_r($config_obj, true) |
|
| 649 | - ) |
|
| 650 | - ); |
|
| 651 | - } |
|
| 652 | - return false; |
|
| 653 | - } |
|
| 654 | - break; |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - } catch (EE_Error $e) { |
|
| 658 | - $e->get_error(); |
|
| 659 | - } |
|
| 660 | - // you have successfully run the gauntlet |
|
| 661 | - return true; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * _generate_config_option_name |
|
| 667 | - * |
|
| 668 | - * @access protected |
|
| 669 | - * @param string $section |
|
| 670 | - * @param string $name |
|
| 671 | - * @return string |
|
| 672 | - */ |
|
| 673 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 674 | - { |
|
| 675 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * _set_config_class |
|
| 681 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 682 | - * |
|
| 683 | - * @access private |
|
| 684 | - * @param string $config_class |
|
| 685 | - * @param string $name |
|
| 686 | - * @return string |
|
| 687 | - */ |
|
| 688 | - private function _set_config_class($config_class = '', $name = '') |
|
| 689 | - { |
|
| 690 | - return ! empty($config_class) |
|
| 691 | - ? $config_class |
|
| 692 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * set_config |
|
| 698 | - * |
|
| 699 | - * @access protected |
|
| 700 | - * @param string $section |
|
| 701 | - * @param string $name |
|
| 702 | - * @param string $config_class |
|
| 703 | - * @param EE_Config_Base $config_obj |
|
| 704 | - * @return EE_Config_Base |
|
| 705 | - */ |
|
| 706 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 707 | - { |
|
| 708 | - // ensure config class is set to something |
|
| 709 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 710 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 711 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 712 | - return null; |
|
| 713 | - } |
|
| 714 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 715 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 716 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 717 | - $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 718 | - $this->update_addon_option_names(); |
|
| 719 | - } |
|
| 720 | - // verify the incoming config object but suppress errors |
|
| 721 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 722 | - $config_obj = new $config_class(); |
|
| 723 | - } |
|
| 724 | - if (get_option($config_option_name)) { |
|
| 725 | - EE_Config::log($config_option_name); |
|
| 726 | - update_option($config_option_name, $config_obj); |
|
| 727 | - $this->{$section}->{$name} = $config_obj; |
|
| 728 | - return $this->{$section}->{$name}; |
|
| 729 | - } else { |
|
| 730 | - // create a wp-option for this config |
|
| 731 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 732 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 733 | - return $this->{$section}->{$name}; |
|
| 734 | - } else { |
|
| 735 | - EE_Error::add_error( |
|
| 736 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 737 | - __FILE__, |
|
| 738 | - __FUNCTION__, |
|
| 739 | - __LINE__ |
|
| 740 | - ); |
|
| 741 | - return null; |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * update_config |
|
| 749 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 750 | - * |
|
| 751 | - * @access public |
|
| 752 | - * @param string $section |
|
| 753 | - * @param string $name |
|
| 754 | - * @param EE_Config_Base|string $config_obj |
|
| 755 | - * @param bool $throw_errors |
|
| 756 | - * @return bool |
|
| 757 | - */ |
|
| 758 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 759 | - { |
|
| 760 | - // don't allow config updates during WP heartbeats |
|
| 761 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 762 | - return false; |
|
| 763 | - } |
|
| 764 | - $config_obj = maybe_unserialize($config_obj); |
|
| 765 | - // get class name of the incoming object |
|
| 766 | - $config_class = get_class($config_obj); |
|
| 767 | - // run tests 1-5 and 9 to verify config |
|
| 768 | - if (! $this->_verify_config_params( |
|
| 769 | - $section, |
|
| 770 | - $name, |
|
| 771 | - $config_class, |
|
| 772 | - $config_obj, |
|
| 773 | - array(1, 2, 3, 4, 7, 9) |
|
| 774 | - ) |
|
| 775 | - ) { |
|
| 776 | - return false; |
|
| 777 | - } |
|
| 778 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 779 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 780 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 781 | - // save new config to db |
|
| 782 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 783 | - return true; |
|
| 784 | - } |
|
| 785 | - } else { |
|
| 786 | - // first check if the record already exists |
|
| 787 | - $existing_config = get_option($config_option_name); |
|
| 788 | - $config_obj = serialize($config_obj); |
|
| 789 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 790 | - if ($existing_config == $config_obj) { |
|
| 791 | - $this->{$section}->{$name} = $config_obj; |
|
| 792 | - return true; |
|
| 793 | - } else if (update_option($config_option_name, $config_obj)) { |
|
| 794 | - EE_Config::log($config_option_name); |
|
| 795 | - // update wp-option for this config class |
|
| 796 | - $this->{$section}->{$name} = $config_obj; |
|
| 797 | - return true; |
|
| 798 | - } elseif ($throw_errors) { |
|
| 799 | - EE_Error::add_error( |
|
| 800 | - sprintf( |
|
| 801 | - __( |
|
| 802 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 803 | - 'event_espresso' |
|
| 804 | - ), |
|
| 805 | - $config_class, |
|
| 806 | - 'EE_Config->' . $section . '->' . $name |
|
| 807 | - ), |
|
| 808 | - __FILE__, |
|
| 809 | - __FUNCTION__, |
|
| 810 | - __LINE__ |
|
| 811 | - ); |
|
| 812 | - } |
|
| 813 | - } |
|
| 814 | - return false; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * get_config |
|
| 820 | - * |
|
| 821 | - * @access public |
|
| 822 | - * @param string $section |
|
| 823 | - * @param string $name |
|
| 824 | - * @param string $config_class |
|
| 825 | - * @return mixed EE_Config_Base | NULL |
|
| 826 | - */ |
|
| 827 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 828 | - { |
|
| 829 | - // ensure config class is set to something |
|
| 830 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 831 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 832 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 833 | - return null; |
|
| 834 | - } |
|
| 835 | - // now test if the requested config object exists, but suppress errors |
|
| 836 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 837 | - // config already exists, so pass it back |
|
| 838 | - return $this->{$section}->{$name}; |
|
| 839 | - } |
|
| 840 | - // load config option from db if it exists |
|
| 841 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 842 | - // verify the newly retrieved config object, but suppress errors |
|
| 843 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 844 | - // config is good, so set it and pass it back |
|
| 845 | - $this->{$section}->{$name} = $config_obj; |
|
| 846 | - return $this->{$section}->{$name}; |
|
| 847 | - } |
|
| 848 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 849 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 850 | - // verify the newly created config object |
|
| 851 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 852 | - return $this->{$section}->{$name}; |
|
| 853 | - } else { |
|
| 854 | - EE_Error::add_error( |
|
| 855 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 856 | - __FILE__, |
|
| 857 | - __FUNCTION__, |
|
| 858 | - __LINE__ |
|
| 859 | - ); |
|
| 860 | - } |
|
| 861 | - return null; |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * get_config_option |
|
| 867 | - * |
|
| 868 | - * @access public |
|
| 869 | - * @param string $config_option_name |
|
| 870 | - * @return mixed EE_Config_Base | FALSE |
|
| 871 | - */ |
|
| 872 | - public function get_config_option($config_option_name = '') |
|
| 873 | - { |
|
| 874 | - // retrieve the wp-option for this config class. |
|
| 875 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 876 | - if (empty($config_option)) { |
|
| 877 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 878 | - } |
|
| 879 | - return $config_option; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * log |
|
| 885 | - * |
|
| 886 | - * @param string $config_option_name |
|
| 887 | - */ |
|
| 888 | - public static function log($config_option_name = '') |
|
| 889 | - { |
|
| 890 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 891 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 892 | - //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 893 | - $_request = $_REQUEST; |
|
| 894 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 895 | - $config_log[(string)microtime(true)] = array( |
|
| 896 | - 'config_name' => $config_option_name, |
|
| 897 | - 'request' => $_request, |
|
| 898 | - ); |
|
| 899 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * trim_log |
|
| 906 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 907 | - */ |
|
| 908 | - public static function trim_log() |
|
| 909 | - { |
|
| 910 | - if (! EE_Config::logging_enabled()) { |
|
| 911 | - return; |
|
| 912 | - } |
|
| 913 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 914 | - $log_length = count($config_log); |
|
| 915 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 916 | - ksort($config_log); |
|
| 917 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 918 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * get_page_for_posts |
|
| 925 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 926 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 927 | - * |
|
| 928 | - * @access public |
|
| 929 | - * @return string |
|
| 930 | - */ |
|
| 931 | - public static function get_page_for_posts() |
|
| 932 | - { |
|
| 933 | - $page_for_posts = get_option('page_for_posts'); |
|
| 934 | - if (! $page_for_posts) { |
|
| 935 | - return 'posts'; |
|
| 936 | - } |
|
| 937 | - /** @type WPDB $wpdb */ |
|
| 938 | - global $wpdb; |
|
| 939 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 940 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - |
|
| 944 | - /** |
|
| 945 | - * register_shortcodes_and_modules. |
|
| 946 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 947 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 948 | - * so they can help trigger maintenance mode if it's needed |
|
| 949 | - * |
|
| 950 | - * @access public |
|
| 951 | - * @return void |
|
| 952 | - */ |
|
| 953 | - public function register_shortcodes_and_modules() |
|
| 954 | - { |
|
| 955 | - // allow shortcodes to register with WP and to set hooks for the rest of the system |
|
| 956 | - EE_Registry::instance()->shortcodes = $this->_register_shortcodes(); |
|
| 957 | - // allow modules to set hooks for the rest of the system |
|
| 958 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - |
|
| 962 | - /** |
|
| 963 | - * initialize_shortcodes_and_modules |
|
| 964 | - * meaning they can start adding their hooks to get stuff done |
|
| 965 | - * |
|
| 966 | - * @access public |
|
| 967 | - * @return void |
|
| 968 | - */ |
|
| 969 | - public function initialize_shortcodes_and_modules() |
|
| 970 | - { |
|
| 971 | - // allow shortcodes to set hooks for the rest of the system |
|
| 972 | - $this->_initialize_shortcodes(); |
|
| 973 | - // allow modules to set hooks for the rest of the system |
|
| 974 | - $this->_initialize_modules(); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * widgets_init |
|
| 980 | - * |
|
| 981 | - * @access private |
|
| 982 | - * @return void |
|
| 983 | - */ |
|
| 984 | - public function widgets_init() |
|
| 985 | - { |
|
| 986 | - //only init widgets on admin pages when not in complete maintenance, and |
|
| 987 | - //on frontend when not in any maintenance mode |
|
| 988 | - if ( |
|
| 989 | - ! EE_Maintenance_Mode::instance()->level() |
|
| 990 | - || ( |
|
| 991 | - is_admin() |
|
| 992 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 993 | - ) |
|
| 994 | - ) { |
|
| 995 | - // grab list of installed widgets |
|
| 996 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 997 | - // filter list of modules to register |
|
| 998 | - $widgets_to_register = apply_filters( |
|
| 999 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1000 | - $widgets_to_register |
|
| 1001 | - ); |
|
| 1002 | - if (! empty($widgets_to_register)) { |
|
| 1003 | - // cycle thru widget folders |
|
| 1004 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1005 | - // add to list of installed widget modules |
|
| 1006 | - EE_Config::register_ee_widget($widget_path); |
|
| 1007 | - } |
|
| 1008 | - } |
|
| 1009 | - // filter list of installed modules |
|
| 1010 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1011 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1012 | - EE_Registry::instance()->widgets |
|
| 1013 | - ); |
|
| 1014 | - } |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * register_ee_widget - makes core aware of this widget |
|
| 1020 | - * |
|
| 1021 | - * @access public |
|
| 1022 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1023 | - * @return void |
|
| 1024 | - */ |
|
| 1025 | - public static function register_ee_widget($widget_path = null) |
|
| 1026 | - { |
|
| 1027 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1028 | - $widget_ext = '.widget.php'; |
|
| 1029 | - // make all separators match |
|
| 1030 | - $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1031 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1032 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1033 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1034 | - $file_name = explode('.', basename($widget_path)); |
|
| 1035 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1036 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1037 | - // sanitize shortcode directory name |
|
| 1038 | - $widget = sanitize_key($widget); |
|
| 1039 | - // now we need to rebuild the shortcode path |
|
| 1040 | - $widget_path = explode(DS, $widget_path); |
|
| 1041 | - // remove last segment |
|
| 1042 | - array_pop($widget_path); |
|
| 1043 | - // glue it back together |
|
| 1044 | - $widget_path = implode(DS, $widget_path); |
|
| 1045 | - } else { |
|
| 1046 | - // grab and sanitize widget directory name |
|
| 1047 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1048 | - } |
|
| 1049 | - // create classname from widget directory name |
|
| 1050 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1051 | - // add class prefix |
|
| 1052 | - $widget_class = 'EEW_' . $widget; |
|
| 1053 | - // does the widget exist ? |
|
| 1054 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1055 | - $msg = sprintf( |
|
| 1056 | - __( |
|
| 1057 | - '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', |
|
| 1058 | - 'event_espresso' |
|
| 1059 | - ), |
|
| 1060 | - $widget_class, |
|
| 1061 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1062 | - ); |
|
| 1063 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1064 | - return; |
|
| 1065 | - } |
|
| 1066 | - // load the widget class file |
|
| 1067 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1068 | - // verify that class exists |
|
| 1069 | - if (! class_exists($widget_class)) { |
|
| 1070 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1071 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1072 | - return; |
|
| 1073 | - } |
|
| 1074 | - register_widget($widget_class); |
|
| 1075 | - // add to array of registered widgets |
|
| 1076 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * _register_shortcodes |
|
| 1082 | - * |
|
| 1083 | - * @access private |
|
| 1084 | - * @return array |
|
| 1085 | - */ |
|
| 1086 | - private function _register_shortcodes() |
|
| 1087 | - { |
|
| 1088 | - // grab list of installed shortcodes |
|
| 1089 | - $shortcodes_to_register = glob(EE_SHORTCODES . '*', GLOB_ONLYDIR); |
|
| 1090 | - // filter list of modules to register |
|
| 1091 | - $shortcodes_to_register = apply_filters( |
|
| 1092 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 1093 | - $shortcodes_to_register |
|
| 1094 | - ); |
|
| 1095 | - if (! empty($shortcodes_to_register)) { |
|
| 1096 | - // cycle thru shortcode folders |
|
| 1097 | - foreach ($shortcodes_to_register as $shortcode_path) { |
|
| 1098 | - // add to list of installed shortcode modules |
|
| 1099 | - EE_Config::register_shortcode($shortcode_path); |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - // filter list of installed modules |
|
| 1103 | - return apply_filters( |
|
| 1104 | - 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
| 1105 | - EE_Registry::instance()->shortcodes |
|
| 1106 | - ); |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * register_shortcode - makes core aware of this shortcode |
|
| 1112 | - * |
|
| 1113 | - * @access public |
|
| 1114 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1115 | - * @return bool |
|
| 1116 | - */ |
|
| 1117 | - public static function register_shortcode($shortcode_path = null) |
|
| 1118 | - { |
|
| 1119 | - do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
| 1120 | - $shortcode_ext = '.shortcode.php'; |
|
| 1121 | - // make all separators match |
|
| 1122 | - $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path); |
|
| 1123 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1124 | - if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
| 1125 | - // grab shortcode file name from directory name and break apart at dots |
|
| 1126 | - $shortcode_file = explode('.', basename($shortcode_path)); |
|
| 1127 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1128 | - $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
| 1129 | - ? substr($shortcode_file[0], 4) |
|
| 1130 | - : $shortcode_file[0]; |
|
| 1131 | - // sanitize shortcode directory name |
|
| 1132 | - $shortcode = sanitize_key($shortcode); |
|
| 1133 | - // now we need to rebuild the shortcode path |
|
| 1134 | - $shortcode_path = explode(DS, $shortcode_path); |
|
| 1135 | - // remove last segment |
|
| 1136 | - array_pop($shortcode_path); |
|
| 1137 | - // glue it back together |
|
| 1138 | - $shortcode_path = implode(DS, $shortcode_path) . DS; |
|
| 1139 | - } else { |
|
| 1140 | - // we need to generate the filename based off of the folder name |
|
| 1141 | - // grab and sanitize shortcode directory name |
|
| 1142 | - $shortcode = sanitize_key(basename($shortcode_path)); |
|
| 1143 | - $shortcode_path = rtrim($shortcode_path, DS) . DS; |
|
| 1144 | - } |
|
| 1145 | - // create classname from shortcode directory or file name |
|
| 1146 | - $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
| 1147 | - // add class prefix |
|
| 1148 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 1149 | - // does the shortcode exist ? |
|
| 1150 | - if (! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) { |
|
| 1151 | - $msg = sprintf( |
|
| 1152 | - __( |
|
| 1153 | - 'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s', |
|
| 1154 | - 'event_espresso' |
|
| 1155 | - ), |
|
| 1156 | - $shortcode_class, |
|
| 1157 | - $shortcode_path . DS . $shortcode_class . $shortcode_ext |
|
| 1158 | - ); |
|
| 1159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1160 | - return false; |
|
| 1161 | - } |
|
| 1162 | - // load the shortcode class file |
|
| 1163 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
| 1164 | - // verify that class exists |
|
| 1165 | - if (! class_exists($shortcode_class)) { |
|
| 1166 | - $msg = sprintf( |
|
| 1167 | - __('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
| 1168 | - $shortcode_class |
|
| 1169 | - ); |
|
| 1170 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1171 | - return false; |
|
| 1172 | - } |
|
| 1173 | - $shortcode = strtoupper($shortcode); |
|
| 1174 | - // add to array of registered shortcodes |
|
| 1175 | - EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 1176 | - return true; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - /** |
|
| 1181 | - * _register_modules |
|
| 1182 | - * |
|
| 1183 | - * @access private |
|
| 1184 | - * @return array |
|
| 1185 | - */ |
|
| 1186 | - private function _register_modules() |
|
| 1187 | - { |
|
| 1188 | - // grab list of installed modules |
|
| 1189 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1190 | - // filter list of modules to register |
|
| 1191 | - $modules_to_register = apply_filters( |
|
| 1192 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1193 | - $modules_to_register |
|
| 1194 | - ); |
|
| 1195 | - if (! empty($modules_to_register)) { |
|
| 1196 | - // loop through folders |
|
| 1197 | - foreach ($modules_to_register as $module_path) { |
|
| 1198 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1199 | - if ( |
|
| 1200 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1201 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1202 | - ) { |
|
| 1203 | - // add to list of installed modules |
|
| 1204 | - EE_Config::register_module($module_path); |
|
| 1205 | - } |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - // filter list of installed modules |
|
| 1209 | - return apply_filters( |
|
| 1210 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1211 | - EE_Registry::instance()->modules |
|
| 1212 | - ); |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * register_module - makes core aware of this module |
|
| 1218 | - * |
|
| 1219 | - * @access public |
|
| 1220 | - * @param string $module_path - full path up to and including module folder |
|
| 1221 | - * @return bool |
|
| 1222 | - */ |
|
| 1223 | - public static function register_module($module_path = null) |
|
| 1224 | - { |
|
| 1225 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1226 | - $module_ext = '.module.php'; |
|
| 1227 | - // make all separators match |
|
| 1228 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1229 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1230 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1231 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1232 | - $module_file = explode('.', basename($module_path)); |
|
| 1233 | - // now we need to rebuild the shortcode path |
|
| 1234 | - $module_path = explode(DS, $module_path); |
|
| 1235 | - // remove last segment |
|
| 1236 | - array_pop($module_path); |
|
| 1237 | - // glue it back together |
|
| 1238 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1239 | - // take first segment from file name pieces and sanitize it |
|
| 1240 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1241 | - // ensure class prefix is added |
|
| 1242 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1243 | - } else { |
|
| 1244 | - // we need to generate the filename based off of the folder name |
|
| 1245 | - // grab and sanitize module name |
|
| 1246 | - $module = strtolower(basename($module_path)); |
|
| 1247 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1248 | - // like trailingslashit() |
|
| 1249 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1250 | - // create classname from module directory name |
|
| 1251 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1252 | - // add class prefix |
|
| 1253 | - $module_class = 'EED_' . $module; |
|
| 1254 | - } |
|
| 1255 | - // does the module exist ? |
|
| 1256 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1257 | - $msg = sprintf( |
|
| 1258 | - __( |
|
| 1259 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1260 | - 'event_espresso' |
|
| 1261 | - ), |
|
| 1262 | - $module |
|
| 1263 | - ); |
|
| 1264 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1265 | - return false; |
|
| 1266 | - } |
|
| 1267 | - // load the module class file |
|
| 1268 | - require_once($module_path . $module_class . $module_ext); |
|
| 1269 | - // verify that class exists |
|
| 1270 | - if (! class_exists($module_class)) { |
|
| 1271 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1272 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1273 | - return false; |
|
| 1274 | - } |
|
| 1275 | - // add to array of registered modules |
|
| 1276 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1277 | - do_action( |
|
| 1278 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1279 | - $module_class, |
|
| 1280 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1281 | - ); |
|
| 1282 | - return true; |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - |
|
| 1286 | - /** |
|
| 1287 | - * _initialize_shortcodes |
|
| 1288 | - * allow shortcodes to set hooks for the rest of the system |
|
| 1289 | - * |
|
| 1290 | - * @access private |
|
| 1291 | - * @return void |
|
| 1292 | - */ |
|
| 1293 | - private function _initialize_shortcodes() |
|
| 1294 | - { |
|
| 1295 | - // cycle thru shortcode folders |
|
| 1296 | - foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) { |
|
| 1297 | - // add class prefix |
|
| 1298 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 1299 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1300 | - // which set hooks ? |
|
| 1301 | - if (is_admin()) { |
|
| 1302 | - // fire immediately |
|
| 1303 | - call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
| 1304 | - } else { |
|
| 1305 | - // delay until other systems are online |
|
| 1306 | - add_action( |
|
| 1307 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1308 | - array($shortcode_class, 'set_hooks') |
|
| 1309 | - ); |
|
| 1310 | - // convert classname to UPPERCASE and create WP shortcode. |
|
| 1311 | - $shortcode_tag = strtoupper($shortcode); |
|
| 1312 | - // but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor' |
|
| 1313 | - if (! shortcode_exists($shortcode_tag)) { |
|
| 1314 | - // NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes() |
|
| 1315 | - add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - } |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - |
|
| 1322 | - /** |
|
| 1323 | - * _initialize_modules |
|
| 1324 | - * allow modules to set hooks for the rest of the system |
|
| 1325 | - * |
|
| 1326 | - * @access private |
|
| 1327 | - * @return void |
|
| 1328 | - */ |
|
| 1329 | - private function _initialize_modules() |
|
| 1330 | - { |
|
| 1331 | - // cycle thru shortcode folders |
|
| 1332 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1333 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1334 | - // which set hooks ? |
|
| 1335 | - if (is_admin()) { |
|
| 1336 | - // fire immediately |
|
| 1337 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1338 | - } else { |
|
| 1339 | - // delay until other systems are online |
|
| 1340 | - add_action( |
|
| 1341 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1342 | - array($module_class, 'set_hooks') |
|
| 1343 | - ); |
|
| 1344 | - } |
|
| 1345 | - } |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - |
|
| 1349 | - /** |
|
| 1350 | - * register_route - adds module method routes to route_map |
|
| 1351 | - * |
|
| 1352 | - * @access public |
|
| 1353 | - * @param string $route - "pretty" public alias for module method |
|
| 1354 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1355 | - * @param string $method_name - the actual module method to be routed to |
|
| 1356 | - * @param string $key - url param key indicating a route is being called |
|
| 1357 | - * @return bool |
|
| 1358 | - */ |
|
| 1359 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1360 | - { |
|
| 1361 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1362 | - $module = str_replace('EED_', '', $module); |
|
| 1363 | - $module_class = 'EED_' . $module; |
|
| 1364 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1365 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1366 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1367 | - return false; |
|
| 1368 | - } |
|
| 1369 | - if (empty($route)) { |
|
| 1370 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1371 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1372 | - return false; |
|
| 1373 | - } |
|
| 1374 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1375 | - $msg = sprintf( |
|
| 1376 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1377 | - $route |
|
| 1378 | - ); |
|
| 1379 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1380 | - return false; |
|
| 1381 | - } |
|
| 1382 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1383 | - return true; |
|
| 1384 | - } |
|
| 1385 | - |
|
| 1386 | - |
|
| 1387 | - /** |
|
| 1388 | - * get_route - get module method route |
|
| 1389 | - * |
|
| 1390 | - * @access public |
|
| 1391 | - * @param string $route - "pretty" public alias for module method |
|
| 1392 | - * @param string $key - url param key indicating a route is being called |
|
| 1393 | - * @return string |
|
| 1394 | - */ |
|
| 1395 | - public static function get_route($route = null, $key = 'ee') |
|
| 1396 | - { |
|
| 1397 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1398 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1399 | - if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1400 | - return EE_Config::$_module_route_map[$key][$route]; |
|
| 1401 | - } |
|
| 1402 | - return null; |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * get_routes - get ALL module method routes |
|
| 1408 | - * |
|
| 1409 | - * @access public |
|
| 1410 | - * @return array |
|
| 1411 | - */ |
|
| 1412 | - public static function get_routes() |
|
| 1413 | - { |
|
| 1414 | - return EE_Config::$_module_route_map; |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - |
|
| 1418 | - /** |
|
| 1419 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1420 | - * |
|
| 1421 | - * @access public |
|
| 1422 | - * @param string $route - "pretty" public alias for module method |
|
| 1423 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1424 | - * class, allows different forwards to be served based on status |
|
| 1425 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1426 | - * @param string $key - url param key indicating a route is being called |
|
| 1427 | - * @return bool |
|
| 1428 | - */ |
|
| 1429 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1430 | - { |
|
| 1431 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1432 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1433 | - $msg = sprintf( |
|
| 1434 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1435 | - $route |
|
| 1436 | - ); |
|
| 1437 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1438 | - return false; |
|
| 1439 | - } |
|
| 1440 | - if (empty($forward)) { |
|
| 1441 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1442 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1443 | - return false; |
|
| 1444 | - } |
|
| 1445 | - if (is_array($forward)) { |
|
| 1446 | - if (! isset($forward[1])) { |
|
| 1447 | - $msg = sprintf( |
|
| 1448 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1449 | - $route |
|
| 1450 | - ); |
|
| 1451 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | - return false; |
|
| 1453 | - } |
|
| 1454 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1455 | - $msg = sprintf( |
|
| 1456 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1457 | - $forward[1], |
|
| 1458 | - $route |
|
| 1459 | - ); |
|
| 1460 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1461 | - return false; |
|
| 1462 | - } |
|
| 1463 | - } else if (! function_exists($forward)) { |
|
| 1464 | - $msg = sprintf( |
|
| 1465 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1466 | - $forward, |
|
| 1467 | - $route |
|
| 1468 | - ); |
|
| 1469 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1470 | - return false; |
|
| 1471 | - } |
|
| 1472 | - EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1473 | - return true; |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - |
|
| 1477 | - /** |
|
| 1478 | - * get_forward - get forwarding route |
|
| 1479 | - * |
|
| 1480 | - * @access public |
|
| 1481 | - * @param string $route - "pretty" public alias for module method |
|
| 1482 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1483 | - * allows different forwards to be served based on status |
|
| 1484 | - * @param string $key - url param key indicating a route is being called |
|
| 1485 | - * @return string |
|
| 1486 | - */ |
|
| 1487 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1488 | - { |
|
| 1489 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1490 | - if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1491 | - return apply_filters( |
|
| 1492 | - 'FHEE__EE_Config__get_forward', |
|
| 1493 | - EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1494 | - $route, |
|
| 1495 | - $status |
|
| 1496 | - ); |
|
| 1497 | - } |
|
| 1498 | - return null; |
|
| 1499 | - } |
|
| 1500 | - |
|
| 1501 | - |
|
| 1502 | - /** |
|
| 1503 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1504 | - * results |
|
| 1505 | - * |
|
| 1506 | - * @access public |
|
| 1507 | - * @param string $route - "pretty" public alias for module method |
|
| 1508 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1509 | - * allows different views to be served based on status |
|
| 1510 | - * @param string $view |
|
| 1511 | - * @param string $key - url param key indicating a route is being called |
|
| 1512 | - * @return bool |
|
| 1513 | - */ |
|
| 1514 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1515 | - { |
|
| 1516 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1517 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1518 | - $msg = sprintf( |
|
| 1519 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1520 | - $route |
|
| 1521 | - ); |
|
| 1522 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1523 | - return false; |
|
| 1524 | - } |
|
| 1525 | - if (! is_readable($view)) { |
|
| 1526 | - $msg = sprintf( |
|
| 1527 | - __( |
|
| 1528 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1529 | - 'event_espresso' |
|
| 1530 | - ), |
|
| 1531 | - $view |
|
| 1532 | - ); |
|
| 1533 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1534 | - return false; |
|
| 1535 | - } |
|
| 1536 | - EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1537 | - return true; |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - |
|
| 1541 | - /** |
|
| 1542 | - * get_view - get view for route and status |
|
| 1543 | - * |
|
| 1544 | - * @access public |
|
| 1545 | - * @param string $route - "pretty" public alias for module method |
|
| 1546 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1547 | - * allows different views to be served based on status |
|
| 1548 | - * @param string $key - url param key indicating a route is being called |
|
| 1549 | - * @return string |
|
| 1550 | - */ |
|
| 1551 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1552 | - { |
|
| 1553 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1554 | - if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1555 | - return apply_filters( |
|
| 1556 | - 'FHEE__EE_Config__get_view', |
|
| 1557 | - EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1558 | - $route, |
|
| 1559 | - $status |
|
| 1560 | - ); |
|
| 1561 | - } |
|
| 1562 | - return null; |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - |
|
| 1566 | - public function update_addon_option_names() |
|
| 1567 | - { |
|
| 1568 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - |
|
| 1572 | - public function shutdown() |
|
| 1573 | - { |
|
| 1574 | - $this->update_addon_option_names(); |
|
| 1575 | - } |
|
| 16 | + const OPTION_NAME = 'ee_config'; |
|
| 17 | + |
|
| 18 | + const LOG_NAME = 'ee_config_log'; |
|
| 19 | + |
|
| 20 | + const LOG_LENGTH = 100; |
|
| 21 | + |
|
| 22 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * instance of the EE_Config object |
|
| 27 | + * |
|
| 28 | + * @var EE_Config $_instance |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var boolean $_logging_enabled |
|
| 35 | + */ |
|
| 36 | + private static $_logging_enabled = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * An StdClass whose property names are addon slugs, |
|
| 40 | + * and values are their config classes |
|
| 41 | + * |
|
| 42 | + * @var StdClass |
|
| 43 | + */ |
|
| 44 | + public $addons; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EE_Admin_Config |
|
| 48 | + */ |
|
| 49 | + public $admin; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Core_Config |
|
| 53 | + */ |
|
| 54 | + public $core; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Currency_Config |
|
| 58 | + */ |
|
| 59 | + public $currency; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var EE_Organization_Config |
|
| 63 | + */ |
|
| 64 | + public $organization; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var EE_Registration_Config |
|
| 68 | + */ |
|
| 69 | + public $registration; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_Template_Config |
|
| 73 | + */ |
|
| 74 | + public $template_settings; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Holds EE environment values. |
|
| 78 | + * |
|
| 79 | + * @var EE_Environment_Config |
|
| 80 | + */ |
|
| 81 | + public $environment; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * settings pertaining to Google maps |
|
| 85 | + * |
|
| 86 | + * @var EE_Map_Config |
|
| 87 | + */ |
|
| 88 | + public $map_settings; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * settings pertaining to Taxes |
|
| 92 | + * |
|
| 93 | + * @var EE_Tax_Config |
|
| 94 | + */ |
|
| 95 | + public $tax_settings; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @deprecated |
|
| 99 | + * @var EE_Gateway_Config |
|
| 100 | + */ |
|
| 101 | + public $gateway; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @var array $_addon_option_names |
|
| 105 | + * @access private |
|
| 106 | + */ |
|
| 107 | + private $_addon_option_names = array(); |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @var array $_module_route_map |
|
| 111 | + * @access private |
|
| 112 | + */ |
|
| 113 | + private static $_module_route_map = array(); |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var array $_module_forward_map |
|
| 117 | + * @access private |
|
| 118 | + */ |
|
| 119 | + private static $_module_forward_map = array(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var array $_module_view_map |
|
| 123 | + * @access private |
|
| 124 | + */ |
|
| 125 | + private static $_module_view_map = array(); |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @singleton method used to instantiate class object |
|
| 130 | + * @access public |
|
| 131 | + * @return EE_Config instance |
|
| 132 | + */ |
|
| 133 | + public static function instance() |
|
| 134 | + { |
|
| 135 | + // check if class object is instantiated, and instantiated properly |
|
| 136 | + if (! self::$_instance instanceof EE_Config) { |
|
| 137 | + self::$_instance = new self(); |
|
| 138 | + } |
|
| 139 | + return self::$_instance; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Resets the config |
|
| 145 | + * |
|
| 146 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 147 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 148 | + * reflect its state in the database |
|
| 149 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 150 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 151 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 152 | + * site was put into maintenance mode) |
|
| 153 | + * @return EE_Config |
|
| 154 | + */ |
|
| 155 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 156 | + { |
|
| 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(); |
|
| 164 | + } |
|
| 165 | + self::$_instance = null; |
|
| 166 | + //we don't need to reset the static properties imo because those should |
|
| 167 | + //only change when a module is added or removed. Currently we don't |
|
| 168 | + //support removing a module during a request when it previously existed |
|
| 169 | + if ($reinstantiate) { |
|
| 170 | + return self::instance(); |
|
| 171 | + } else { |
|
| 172 | + return null; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * class constructor |
|
| 179 | + * |
|
| 180 | + * @access private |
|
| 181 | + */ |
|
| 182 | + private function __construct() |
|
| 183 | + { |
|
| 184 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 185 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 186 | + // setup empty config classes |
|
| 187 | + $this->_initialize_config(); |
|
| 188 | + // load existing EE site settings |
|
| 189 | + $this->_load_core_config(); |
|
| 190 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 191 | + $this->_verify_config(); |
|
| 192 | + // register shortcodes and modules |
|
| 193 | + add_action( |
|
| 194 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 195 | + array($this, 'register_shortcodes_and_modules'), |
|
| 196 | + 999 |
|
| 197 | + ); |
|
| 198 | + // initialize shortcodes and modules |
|
| 199 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 200 | + // register widgets |
|
| 201 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 202 | + // shutdown |
|
| 203 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 204 | + // construct__end hook |
|
| 205 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 206 | + // hardcoded hack |
|
| 207 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return boolean |
|
| 213 | + */ |
|
| 214 | + public static function logging_enabled() |
|
| 215 | + { |
|
| 216 | + return self::$_logging_enabled; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * use to get the current theme if needed from static context |
|
| 222 | + * |
|
| 223 | + * @return string current theme set. |
|
| 224 | + */ |
|
| 225 | + public static function get_current_theme() |
|
| 226 | + { |
|
| 227 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 228 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * _initialize_config |
|
| 234 | + * |
|
| 235 | + * @access private |
|
| 236 | + * @return void |
|
| 237 | + */ |
|
| 238 | + private function _initialize_config() |
|
| 239 | + { |
|
| 240 | + EE_Config::trim_log(); |
|
| 241 | + //set defaults |
|
| 242 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 243 | + $this->addons = new stdClass(); |
|
| 244 | + // set _module_route_map |
|
| 245 | + EE_Config::$_module_route_map = array(); |
|
| 246 | + // set _module_forward_map |
|
| 247 | + EE_Config::$_module_forward_map = array(); |
|
| 248 | + // set _module_view_map |
|
| 249 | + EE_Config::$_module_view_map = array(); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * load core plugin configuration |
|
| 255 | + * |
|
| 256 | + * @access private |
|
| 257 | + * @return void |
|
| 258 | + */ |
|
| 259 | + private function _load_core_config() |
|
| 260 | + { |
|
| 261 | + // load_core_config__start hook |
|
| 262 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 263 | + $espresso_config = $this->get_espresso_config(); |
|
| 264 | + foreach ($espresso_config as $config => $settings) { |
|
| 265 | + // load_core_config__start hook |
|
| 266 | + $settings = apply_filters( |
|
| 267 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 268 | + $settings, |
|
| 269 | + $config, |
|
| 270 | + $this |
|
| 271 | + ); |
|
| 272 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 273 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 274 | + //call configs populate method to ensure any defaults are set for empty values. |
|
| 275 | + if (method_exists($settings, 'populate')) { |
|
| 276 | + $this->{$config}->populate(); |
|
| 277 | + } |
|
| 278 | + if (method_exists($settings, 'do_hooks')) { |
|
| 279 | + $this->{$config}->do_hooks(); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 284 | + $this->update_espresso_config(); |
|
| 285 | + } |
|
| 286 | + // load_core_config__end hook |
|
| 287 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * _verify_config |
|
| 293 | + * |
|
| 294 | + * @access protected |
|
| 295 | + * @return void |
|
| 296 | + */ |
|
| 297 | + protected function _verify_config() |
|
| 298 | + { |
|
| 299 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 300 | + ? $this->core |
|
| 301 | + : new EE_Core_Config(); |
|
| 302 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 303 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 304 | + ? $this->organization |
|
| 305 | + : new EE_Organization_Config(); |
|
| 306 | + $this->organization = apply_filters('FHEE__EE_Config___initialize_config__organization', |
|
| 307 | + $this->organization); |
|
| 308 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 309 | + ? $this->currency |
|
| 310 | + : new EE_Currency_Config(); |
|
| 311 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 312 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 313 | + ? $this->registration |
|
| 314 | + : new EE_Registration_Config(); |
|
| 315 | + $this->registration = apply_filters('FHEE__EE_Config___initialize_config__registration', |
|
| 316 | + $this->registration); |
|
| 317 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 318 | + ? $this->admin |
|
| 319 | + : new EE_Admin_Config(); |
|
| 320 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 321 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 322 | + ? $this->template_settings |
|
| 323 | + : new EE_Template_Config(); |
|
| 324 | + $this->template_settings = apply_filters( |
|
| 325 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 326 | + $this->template_settings |
|
| 327 | + ); |
|
| 328 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 329 | + ? $this->map_settings |
|
| 330 | + : new EE_Map_Config(); |
|
| 331 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 332 | + $this->map_settings); |
|
| 333 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 334 | + ? $this->environment |
|
| 335 | + : new EE_Environment_Config(); |
|
| 336 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 337 | + $this->environment); |
|
| 338 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 339 | + ? $this->tax_settings |
|
| 340 | + : new EE_Tax_Config(); |
|
| 341 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 342 | + $this->tax_settings); |
|
| 343 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 344 | + ? $this->gateway |
|
| 345 | + : new EE_Gateway_Config(); |
|
| 346 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * get_espresso_config |
|
| 352 | + * |
|
| 353 | + * @access public |
|
| 354 | + * @return array of espresso config stuff |
|
| 355 | + */ |
|
| 356 | + public function get_espresso_config() |
|
| 357 | + { |
|
| 358 | + // grab espresso configuration |
|
| 359 | + return apply_filters( |
|
| 360 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 361 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 362 | + ); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * double_check_config_comparison |
|
| 368 | + * |
|
| 369 | + * @access public |
|
| 370 | + * @param string $option |
|
| 371 | + * @param $old_value |
|
| 372 | + * @param $value |
|
| 373 | + */ |
|
| 374 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 375 | + { |
|
| 376 | + // make sure we're checking the ee config |
|
| 377 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 378 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 379 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 380 | + if ($value != $old_value) { |
|
| 381 | + // if they are NOT the same, then remove the hook, |
|
| 382 | + // which means the subsequent update results will be based solely on the update query results |
|
| 383 | + // the reason we do this is because, as stated above, |
|
| 384 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 385 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 386 | + // If values are found to match their previous old value, |
|
| 387 | + // then WP bails before performing any update. |
|
| 388 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 389 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 390 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 391 | + // MySQL MAY ALSO NOT perform the update because |
|
| 392 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 393 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 394 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 395 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * update_espresso_config |
|
| 403 | + * |
|
| 404 | + * @access public |
|
| 405 | + */ |
|
| 406 | + protected function _reset_espresso_addon_config() |
|
| 407 | + { |
|
| 408 | + $this->_addon_option_names = array(); |
|
| 409 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 410 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 411 | + $config_class = get_class($addon_config_obj); |
|
| 412 | + if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
| 413 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 414 | + } |
|
| 415 | + $this->addons->{$addon_name} = null; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * update_espresso_config |
|
| 422 | + * |
|
| 423 | + * @access public |
|
| 424 | + * @param bool $add_success |
|
| 425 | + * @param bool $add_error |
|
| 426 | + * @return bool |
|
| 427 | + */ |
|
| 428 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 429 | + { |
|
| 430 | + // don't allow config updates during WP heartbeats |
|
| 431 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 432 | + return false; |
|
| 433 | + } |
|
| 434 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 435 | + //$clone = clone( self::$_instance ); |
|
| 436 | + //self::$_instance = NULL; |
|
| 437 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 438 | + $this->_reset_espresso_addon_config(); |
|
| 439 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 440 | + // but BEFORE the actual update occurs |
|
| 441 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 442 | + // now update "ee_config" |
|
| 443 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 444 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 445 | + // if not saved... check if the hook we just added still exists; |
|
| 446 | + // if it does, it means one of two things: |
|
| 447 | + // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 448 | + // or... |
|
| 449 | + // the db update query returned 0 rows affected |
|
| 450 | + // (probably because the data value was the same from it's perspective) |
|
| 451 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 452 | + // but just means no update occurred, so don't display an error to the user. |
|
| 453 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 454 | + // then it means that something truly went wrong |
|
| 455 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 456 | + // remove our action since we don't want it in the system anymore |
|
| 457 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 458 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 459 | + //self::$_instance = $clone; |
|
| 460 | + //unset( $clone ); |
|
| 461 | + // if config remains the same or was updated successfully |
|
| 462 | + if ($saved) { |
|
| 463 | + if ($add_success) { |
|
| 464 | + EE_Error::add_success( |
|
| 465 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 466 | + __FILE__, |
|
| 467 | + __FUNCTION__, |
|
| 468 | + __LINE__ |
|
| 469 | + ); |
|
| 470 | + } |
|
| 471 | + return true; |
|
| 472 | + } else { |
|
| 473 | + if ($add_error) { |
|
| 474 | + EE_Error::add_error( |
|
| 475 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 476 | + __FILE__, |
|
| 477 | + __FUNCTION__, |
|
| 478 | + __LINE__ |
|
| 479 | + ); |
|
| 480 | + } |
|
| 481 | + return false; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * _verify_config_params |
|
| 488 | + * |
|
| 489 | + * @access private |
|
| 490 | + * @param string $section |
|
| 491 | + * @param string $name |
|
| 492 | + * @param string $config_class |
|
| 493 | + * @param EE_Config_Base $config_obj |
|
| 494 | + * @param array $tests_to_run |
|
| 495 | + * @param bool $display_errors |
|
| 496 | + * @return bool TRUE on success, FALSE on fail |
|
| 497 | + */ |
|
| 498 | + private function _verify_config_params( |
|
| 499 | + $section = '', |
|
| 500 | + $name = '', |
|
| 501 | + $config_class = '', |
|
| 502 | + $config_obj = null, |
|
| 503 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 504 | + $display_errors = true |
|
| 505 | + ) { |
|
| 506 | + try { |
|
| 507 | + foreach ($tests_to_run as $test) { |
|
| 508 | + switch ($test) { |
|
| 509 | + // TEST #1 : check that section was set |
|
| 510 | + case 1 : |
|
| 511 | + if (empty($section)) { |
|
| 512 | + if ($display_errors) { |
|
| 513 | + throw new EE_Error( |
|
| 514 | + sprintf( |
|
| 515 | + __( |
|
| 516 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 517 | + 'event_espresso' |
|
| 518 | + ), |
|
| 519 | + $config_class |
|
| 520 | + ) |
|
| 521 | + ); |
|
| 522 | + } |
|
| 523 | + return false; |
|
| 524 | + } |
|
| 525 | + break; |
|
| 526 | + // TEST #2 : check that settings section exists |
|
| 527 | + case 2 : |
|
| 528 | + if (! isset($this->{$section})) { |
|
| 529 | + if ($display_errors) { |
|
| 530 | + throw new EE_Error( |
|
| 531 | + sprintf( |
|
| 532 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 533 | + $section |
|
| 534 | + ) |
|
| 535 | + ); |
|
| 536 | + } |
|
| 537 | + return false; |
|
| 538 | + } |
|
| 539 | + break; |
|
| 540 | + // TEST #3 : check that section is the proper format |
|
| 541 | + case 3 : |
|
| 542 | + if ( |
|
| 543 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 544 | + ) { |
|
| 545 | + if ($display_errors) { |
|
| 546 | + throw new EE_Error( |
|
| 547 | + sprintf( |
|
| 548 | + __( |
|
| 549 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 550 | + 'event_espresso' |
|
| 551 | + ), |
|
| 552 | + $section |
|
| 553 | + ) |
|
| 554 | + ); |
|
| 555 | + } |
|
| 556 | + return false; |
|
| 557 | + } |
|
| 558 | + break; |
|
| 559 | + // TEST #4 : check that config section name has been set |
|
| 560 | + case 4 : |
|
| 561 | + if (empty($name)) { |
|
| 562 | + if ($display_errors) { |
|
| 563 | + throw new EE_Error( |
|
| 564 | + __( |
|
| 565 | + 'No name has been provided for the specific configuration section.', |
|
| 566 | + 'event_espresso' |
|
| 567 | + ) |
|
| 568 | + ); |
|
| 569 | + } |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 572 | + break; |
|
| 573 | + // TEST #5 : check that a config class name has been set |
|
| 574 | + case 5 : |
|
| 575 | + if (empty($config_class)) { |
|
| 576 | + if ($display_errors) { |
|
| 577 | + throw new EE_Error( |
|
| 578 | + __( |
|
| 579 | + 'No class name has been provided for the specific configuration section.', |
|
| 580 | + 'event_espresso' |
|
| 581 | + ) |
|
| 582 | + ); |
|
| 583 | + } |
|
| 584 | + return false; |
|
| 585 | + } |
|
| 586 | + break; |
|
| 587 | + // TEST #6 : verify config class is accessible |
|
| 588 | + case 6 : |
|
| 589 | + if (! class_exists($config_class)) { |
|
| 590 | + if ($display_errors) { |
|
| 591 | + throw new EE_Error( |
|
| 592 | + sprintf( |
|
| 593 | + __( |
|
| 594 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 595 | + 'event_espresso' |
|
| 596 | + ), |
|
| 597 | + $config_class |
|
| 598 | + ) |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + return false; |
|
| 602 | + } |
|
| 603 | + break; |
|
| 604 | + // TEST #7 : check that config has even been set |
|
| 605 | + case 7 : |
|
| 606 | + if (! isset($this->{$section}->{$name})) { |
|
| 607 | + if ($display_errors) { |
|
| 608 | + throw new EE_Error( |
|
| 609 | + sprintf( |
|
| 610 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 611 | + $section, |
|
| 612 | + $name |
|
| 613 | + ) |
|
| 614 | + ); |
|
| 615 | + } |
|
| 616 | + return false; |
|
| 617 | + } else { |
|
| 618 | + // and make sure it's not serialized |
|
| 619 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 620 | + } |
|
| 621 | + break; |
|
| 622 | + // TEST #8 : check that config is the requested type |
|
| 623 | + case 8 : |
|
| 624 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 625 | + if ($display_errors) { |
|
| 626 | + throw new EE_Error( |
|
| 627 | + sprintf( |
|
| 628 | + __( |
|
| 629 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 630 | + 'event_espresso' |
|
| 631 | + ), |
|
| 632 | + $section, |
|
| 633 | + $name, |
|
| 634 | + $config_class |
|
| 635 | + ) |
|
| 636 | + ); |
|
| 637 | + } |
|
| 638 | + return false; |
|
| 639 | + } |
|
| 640 | + break; |
|
| 641 | + // TEST #9 : verify config object |
|
| 642 | + case 9 : |
|
| 643 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 644 | + if ($display_errors) { |
|
| 645 | + throw new EE_Error( |
|
| 646 | + sprintf( |
|
| 647 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 648 | + print_r($config_obj, true) |
|
| 649 | + ) |
|
| 650 | + ); |
|
| 651 | + } |
|
| 652 | + return false; |
|
| 653 | + } |
|
| 654 | + break; |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + } catch (EE_Error $e) { |
|
| 658 | + $e->get_error(); |
|
| 659 | + } |
|
| 660 | + // you have successfully run the gauntlet |
|
| 661 | + return true; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * _generate_config_option_name |
|
| 667 | + * |
|
| 668 | + * @access protected |
|
| 669 | + * @param string $section |
|
| 670 | + * @param string $name |
|
| 671 | + * @return string |
|
| 672 | + */ |
|
| 673 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 674 | + { |
|
| 675 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * _set_config_class |
|
| 681 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 682 | + * |
|
| 683 | + * @access private |
|
| 684 | + * @param string $config_class |
|
| 685 | + * @param string $name |
|
| 686 | + * @return string |
|
| 687 | + */ |
|
| 688 | + private function _set_config_class($config_class = '', $name = '') |
|
| 689 | + { |
|
| 690 | + return ! empty($config_class) |
|
| 691 | + ? $config_class |
|
| 692 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * set_config |
|
| 698 | + * |
|
| 699 | + * @access protected |
|
| 700 | + * @param string $section |
|
| 701 | + * @param string $name |
|
| 702 | + * @param string $config_class |
|
| 703 | + * @param EE_Config_Base $config_obj |
|
| 704 | + * @return EE_Config_Base |
|
| 705 | + */ |
|
| 706 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 707 | + { |
|
| 708 | + // ensure config class is set to something |
|
| 709 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 710 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 711 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 712 | + return null; |
|
| 713 | + } |
|
| 714 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 715 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 716 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 717 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 718 | + $this->update_addon_option_names(); |
|
| 719 | + } |
|
| 720 | + // verify the incoming config object but suppress errors |
|
| 721 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 722 | + $config_obj = new $config_class(); |
|
| 723 | + } |
|
| 724 | + if (get_option($config_option_name)) { |
|
| 725 | + EE_Config::log($config_option_name); |
|
| 726 | + update_option($config_option_name, $config_obj); |
|
| 727 | + $this->{$section}->{$name} = $config_obj; |
|
| 728 | + return $this->{$section}->{$name}; |
|
| 729 | + } else { |
|
| 730 | + // create a wp-option for this config |
|
| 731 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 732 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 733 | + return $this->{$section}->{$name}; |
|
| 734 | + } else { |
|
| 735 | + EE_Error::add_error( |
|
| 736 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 737 | + __FILE__, |
|
| 738 | + __FUNCTION__, |
|
| 739 | + __LINE__ |
|
| 740 | + ); |
|
| 741 | + return null; |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * update_config |
|
| 749 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 750 | + * |
|
| 751 | + * @access public |
|
| 752 | + * @param string $section |
|
| 753 | + * @param string $name |
|
| 754 | + * @param EE_Config_Base|string $config_obj |
|
| 755 | + * @param bool $throw_errors |
|
| 756 | + * @return bool |
|
| 757 | + */ |
|
| 758 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 759 | + { |
|
| 760 | + // don't allow config updates during WP heartbeats |
|
| 761 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 762 | + return false; |
|
| 763 | + } |
|
| 764 | + $config_obj = maybe_unserialize($config_obj); |
|
| 765 | + // get class name of the incoming object |
|
| 766 | + $config_class = get_class($config_obj); |
|
| 767 | + // run tests 1-5 and 9 to verify config |
|
| 768 | + if (! $this->_verify_config_params( |
|
| 769 | + $section, |
|
| 770 | + $name, |
|
| 771 | + $config_class, |
|
| 772 | + $config_obj, |
|
| 773 | + array(1, 2, 3, 4, 7, 9) |
|
| 774 | + ) |
|
| 775 | + ) { |
|
| 776 | + return false; |
|
| 777 | + } |
|
| 778 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 779 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 780 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 781 | + // save new config to db |
|
| 782 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 783 | + return true; |
|
| 784 | + } |
|
| 785 | + } else { |
|
| 786 | + // first check if the record already exists |
|
| 787 | + $existing_config = get_option($config_option_name); |
|
| 788 | + $config_obj = serialize($config_obj); |
|
| 789 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 790 | + if ($existing_config == $config_obj) { |
|
| 791 | + $this->{$section}->{$name} = $config_obj; |
|
| 792 | + return true; |
|
| 793 | + } else if (update_option($config_option_name, $config_obj)) { |
|
| 794 | + EE_Config::log($config_option_name); |
|
| 795 | + // update wp-option for this config class |
|
| 796 | + $this->{$section}->{$name} = $config_obj; |
|
| 797 | + return true; |
|
| 798 | + } elseif ($throw_errors) { |
|
| 799 | + EE_Error::add_error( |
|
| 800 | + sprintf( |
|
| 801 | + __( |
|
| 802 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 803 | + 'event_espresso' |
|
| 804 | + ), |
|
| 805 | + $config_class, |
|
| 806 | + 'EE_Config->' . $section . '->' . $name |
|
| 807 | + ), |
|
| 808 | + __FILE__, |
|
| 809 | + __FUNCTION__, |
|
| 810 | + __LINE__ |
|
| 811 | + ); |
|
| 812 | + } |
|
| 813 | + } |
|
| 814 | + return false; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * get_config |
|
| 820 | + * |
|
| 821 | + * @access public |
|
| 822 | + * @param string $section |
|
| 823 | + * @param string $name |
|
| 824 | + * @param string $config_class |
|
| 825 | + * @return mixed EE_Config_Base | NULL |
|
| 826 | + */ |
|
| 827 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 828 | + { |
|
| 829 | + // ensure config class is set to something |
|
| 830 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 831 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 832 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 833 | + return null; |
|
| 834 | + } |
|
| 835 | + // now test if the requested config object exists, but suppress errors |
|
| 836 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 837 | + // config already exists, so pass it back |
|
| 838 | + return $this->{$section}->{$name}; |
|
| 839 | + } |
|
| 840 | + // load config option from db if it exists |
|
| 841 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 842 | + // verify the newly retrieved config object, but suppress errors |
|
| 843 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 844 | + // config is good, so set it and pass it back |
|
| 845 | + $this->{$section}->{$name} = $config_obj; |
|
| 846 | + return $this->{$section}->{$name}; |
|
| 847 | + } |
|
| 848 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 849 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 850 | + // verify the newly created config object |
|
| 851 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 852 | + return $this->{$section}->{$name}; |
|
| 853 | + } else { |
|
| 854 | + EE_Error::add_error( |
|
| 855 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 856 | + __FILE__, |
|
| 857 | + __FUNCTION__, |
|
| 858 | + __LINE__ |
|
| 859 | + ); |
|
| 860 | + } |
|
| 861 | + return null; |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * get_config_option |
|
| 867 | + * |
|
| 868 | + * @access public |
|
| 869 | + * @param string $config_option_name |
|
| 870 | + * @return mixed EE_Config_Base | FALSE |
|
| 871 | + */ |
|
| 872 | + public function get_config_option($config_option_name = '') |
|
| 873 | + { |
|
| 874 | + // retrieve the wp-option for this config class. |
|
| 875 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 876 | + if (empty($config_option)) { |
|
| 877 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 878 | + } |
|
| 879 | + return $config_option; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * log |
|
| 885 | + * |
|
| 886 | + * @param string $config_option_name |
|
| 887 | + */ |
|
| 888 | + public static function log($config_option_name = '') |
|
| 889 | + { |
|
| 890 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 891 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 892 | + //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 893 | + $_request = $_REQUEST; |
|
| 894 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 895 | + $config_log[(string)microtime(true)] = array( |
|
| 896 | + 'config_name' => $config_option_name, |
|
| 897 | + 'request' => $_request, |
|
| 898 | + ); |
|
| 899 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * trim_log |
|
| 906 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 907 | + */ |
|
| 908 | + public static function trim_log() |
|
| 909 | + { |
|
| 910 | + if (! EE_Config::logging_enabled()) { |
|
| 911 | + return; |
|
| 912 | + } |
|
| 913 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 914 | + $log_length = count($config_log); |
|
| 915 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 916 | + ksort($config_log); |
|
| 917 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 918 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * get_page_for_posts |
|
| 925 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 926 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 927 | + * |
|
| 928 | + * @access public |
|
| 929 | + * @return string |
|
| 930 | + */ |
|
| 931 | + public static function get_page_for_posts() |
|
| 932 | + { |
|
| 933 | + $page_for_posts = get_option('page_for_posts'); |
|
| 934 | + if (! $page_for_posts) { |
|
| 935 | + return 'posts'; |
|
| 936 | + } |
|
| 937 | + /** @type WPDB $wpdb */ |
|
| 938 | + global $wpdb; |
|
| 939 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 940 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + |
|
| 944 | + /** |
|
| 945 | + * register_shortcodes_and_modules. |
|
| 946 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 947 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 948 | + * so they can help trigger maintenance mode if it's needed |
|
| 949 | + * |
|
| 950 | + * @access public |
|
| 951 | + * @return void |
|
| 952 | + */ |
|
| 953 | + public function register_shortcodes_and_modules() |
|
| 954 | + { |
|
| 955 | + // allow shortcodes to register with WP and to set hooks for the rest of the system |
|
| 956 | + EE_Registry::instance()->shortcodes = $this->_register_shortcodes(); |
|
| 957 | + // allow modules to set hooks for the rest of the system |
|
| 958 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + |
|
| 962 | + /** |
|
| 963 | + * initialize_shortcodes_and_modules |
|
| 964 | + * meaning they can start adding their hooks to get stuff done |
|
| 965 | + * |
|
| 966 | + * @access public |
|
| 967 | + * @return void |
|
| 968 | + */ |
|
| 969 | + public function initialize_shortcodes_and_modules() |
|
| 970 | + { |
|
| 971 | + // allow shortcodes to set hooks for the rest of the system |
|
| 972 | + $this->_initialize_shortcodes(); |
|
| 973 | + // allow modules to set hooks for the rest of the system |
|
| 974 | + $this->_initialize_modules(); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * widgets_init |
|
| 980 | + * |
|
| 981 | + * @access private |
|
| 982 | + * @return void |
|
| 983 | + */ |
|
| 984 | + public function widgets_init() |
|
| 985 | + { |
|
| 986 | + //only init widgets on admin pages when not in complete maintenance, and |
|
| 987 | + //on frontend when not in any maintenance mode |
|
| 988 | + if ( |
|
| 989 | + ! EE_Maintenance_Mode::instance()->level() |
|
| 990 | + || ( |
|
| 991 | + is_admin() |
|
| 992 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 993 | + ) |
|
| 994 | + ) { |
|
| 995 | + // grab list of installed widgets |
|
| 996 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 997 | + // filter list of modules to register |
|
| 998 | + $widgets_to_register = apply_filters( |
|
| 999 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1000 | + $widgets_to_register |
|
| 1001 | + ); |
|
| 1002 | + if (! empty($widgets_to_register)) { |
|
| 1003 | + // cycle thru widget folders |
|
| 1004 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1005 | + // add to list of installed widget modules |
|
| 1006 | + EE_Config::register_ee_widget($widget_path); |
|
| 1007 | + } |
|
| 1008 | + } |
|
| 1009 | + // filter list of installed modules |
|
| 1010 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1011 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1012 | + EE_Registry::instance()->widgets |
|
| 1013 | + ); |
|
| 1014 | + } |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * register_ee_widget - makes core aware of this widget |
|
| 1020 | + * |
|
| 1021 | + * @access public |
|
| 1022 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1023 | + * @return void |
|
| 1024 | + */ |
|
| 1025 | + public static function register_ee_widget($widget_path = null) |
|
| 1026 | + { |
|
| 1027 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1028 | + $widget_ext = '.widget.php'; |
|
| 1029 | + // make all separators match |
|
| 1030 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1031 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1032 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1033 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1034 | + $file_name = explode('.', basename($widget_path)); |
|
| 1035 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1036 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1037 | + // sanitize shortcode directory name |
|
| 1038 | + $widget = sanitize_key($widget); |
|
| 1039 | + // now we need to rebuild the shortcode path |
|
| 1040 | + $widget_path = explode(DS, $widget_path); |
|
| 1041 | + // remove last segment |
|
| 1042 | + array_pop($widget_path); |
|
| 1043 | + // glue it back together |
|
| 1044 | + $widget_path = implode(DS, $widget_path); |
|
| 1045 | + } else { |
|
| 1046 | + // grab and sanitize widget directory name |
|
| 1047 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1048 | + } |
|
| 1049 | + // create classname from widget directory name |
|
| 1050 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1051 | + // add class prefix |
|
| 1052 | + $widget_class = 'EEW_' . $widget; |
|
| 1053 | + // does the widget exist ? |
|
| 1054 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1055 | + $msg = sprintf( |
|
| 1056 | + __( |
|
| 1057 | + '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', |
|
| 1058 | + 'event_espresso' |
|
| 1059 | + ), |
|
| 1060 | + $widget_class, |
|
| 1061 | + $widget_path . DS . $widget_class . $widget_ext |
|
| 1062 | + ); |
|
| 1063 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1064 | + return; |
|
| 1065 | + } |
|
| 1066 | + // load the widget class file |
|
| 1067 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1068 | + // verify that class exists |
|
| 1069 | + if (! class_exists($widget_class)) { |
|
| 1070 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1071 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1072 | + return; |
|
| 1073 | + } |
|
| 1074 | + register_widget($widget_class); |
|
| 1075 | + // add to array of registered widgets |
|
| 1076 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * _register_shortcodes |
|
| 1082 | + * |
|
| 1083 | + * @access private |
|
| 1084 | + * @return array |
|
| 1085 | + */ |
|
| 1086 | + private function _register_shortcodes() |
|
| 1087 | + { |
|
| 1088 | + // grab list of installed shortcodes |
|
| 1089 | + $shortcodes_to_register = glob(EE_SHORTCODES . '*', GLOB_ONLYDIR); |
|
| 1090 | + // filter list of modules to register |
|
| 1091 | + $shortcodes_to_register = apply_filters( |
|
| 1092 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 1093 | + $shortcodes_to_register |
|
| 1094 | + ); |
|
| 1095 | + if (! empty($shortcodes_to_register)) { |
|
| 1096 | + // cycle thru shortcode folders |
|
| 1097 | + foreach ($shortcodes_to_register as $shortcode_path) { |
|
| 1098 | + // add to list of installed shortcode modules |
|
| 1099 | + EE_Config::register_shortcode($shortcode_path); |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + // filter list of installed modules |
|
| 1103 | + return apply_filters( |
|
| 1104 | + 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
| 1105 | + EE_Registry::instance()->shortcodes |
|
| 1106 | + ); |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * register_shortcode - makes core aware of this shortcode |
|
| 1112 | + * |
|
| 1113 | + * @access public |
|
| 1114 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1115 | + * @return bool |
|
| 1116 | + */ |
|
| 1117 | + public static function register_shortcode($shortcode_path = null) |
|
| 1118 | + { |
|
| 1119 | + do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
| 1120 | + $shortcode_ext = '.shortcode.php'; |
|
| 1121 | + // make all separators match |
|
| 1122 | + $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path); |
|
| 1123 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1124 | + if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
| 1125 | + // grab shortcode file name from directory name and break apart at dots |
|
| 1126 | + $shortcode_file = explode('.', basename($shortcode_path)); |
|
| 1127 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1128 | + $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
| 1129 | + ? substr($shortcode_file[0], 4) |
|
| 1130 | + : $shortcode_file[0]; |
|
| 1131 | + // sanitize shortcode directory name |
|
| 1132 | + $shortcode = sanitize_key($shortcode); |
|
| 1133 | + // now we need to rebuild the shortcode path |
|
| 1134 | + $shortcode_path = explode(DS, $shortcode_path); |
|
| 1135 | + // remove last segment |
|
| 1136 | + array_pop($shortcode_path); |
|
| 1137 | + // glue it back together |
|
| 1138 | + $shortcode_path = implode(DS, $shortcode_path) . DS; |
|
| 1139 | + } else { |
|
| 1140 | + // we need to generate the filename based off of the folder name |
|
| 1141 | + // grab and sanitize shortcode directory name |
|
| 1142 | + $shortcode = sanitize_key(basename($shortcode_path)); |
|
| 1143 | + $shortcode_path = rtrim($shortcode_path, DS) . DS; |
|
| 1144 | + } |
|
| 1145 | + // create classname from shortcode directory or file name |
|
| 1146 | + $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
| 1147 | + // add class prefix |
|
| 1148 | + $shortcode_class = 'EES_' . $shortcode; |
|
| 1149 | + // does the shortcode exist ? |
|
| 1150 | + if (! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) { |
|
| 1151 | + $msg = sprintf( |
|
| 1152 | + __( |
|
| 1153 | + 'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s', |
|
| 1154 | + 'event_espresso' |
|
| 1155 | + ), |
|
| 1156 | + $shortcode_class, |
|
| 1157 | + $shortcode_path . DS . $shortcode_class . $shortcode_ext |
|
| 1158 | + ); |
|
| 1159 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1160 | + return false; |
|
| 1161 | + } |
|
| 1162 | + // load the shortcode class file |
|
| 1163 | + require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
| 1164 | + // verify that class exists |
|
| 1165 | + if (! class_exists($shortcode_class)) { |
|
| 1166 | + $msg = sprintf( |
|
| 1167 | + __('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
| 1168 | + $shortcode_class |
|
| 1169 | + ); |
|
| 1170 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1171 | + return false; |
|
| 1172 | + } |
|
| 1173 | + $shortcode = strtoupper($shortcode); |
|
| 1174 | + // add to array of registered shortcodes |
|
| 1175 | + EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 1176 | + return true; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + /** |
|
| 1181 | + * _register_modules |
|
| 1182 | + * |
|
| 1183 | + * @access private |
|
| 1184 | + * @return array |
|
| 1185 | + */ |
|
| 1186 | + private function _register_modules() |
|
| 1187 | + { |
|
| 1188 | + // grab list of installed modules |
|
| 1189 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1190 | + // filter list of modules to register |
|
| 1191 | + $modules_to_register = apply_filters( |
|
| 1192 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1193 | + $modules_to_register |
|
| 1194 | + ); |
|
| 1195 | + if (! empty($modules_to_register)) { |
|
| 1196 | + // loop through folders |
|
| 1197 | + foreach ($modules_to_register as $module_path) { |
|
| 1198 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1199 | + if ( |
|
| 1200 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1201 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1202 | + ) { |
|
| 1203 | + // add to list of installed modules |
|
| 1204 | + EE_Config::register_module($module_path); |
|
| 1205 | + } |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + // filter list of installed modules |
|
| 1209 | + return apply_filters( |
|
| 1210 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1211 | + EE_Registry::instance()->modules |
|
| 1212 | + ); |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * register_module - makes core aware of this module |
|
| 1218 | + * |
|
| 1219 | + * @access public |
|
| 1220 | + * @param string $module_path - full path up to and including module folder |
|
| 1221 | + * @return bool |
|
| 1222 | + */ |
|
| 1223 | + public static function register_module($module_path = null) |
|
| 1224 | + { |
|
| 1225 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1226 | + $module_ext = '.module.php'; |
|
| 1227 | + // make all separators match |
|
| 1228 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1229 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1230 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1231 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1232 | + $module_file = explode('.', basename($module_path)); |
|
| 1233 | + // now we need to rebuild the shortcode path |
|
| 1234 | + $module_path = explode(DS, $module_path); |
|
| 1235 | + // remove last segment |
|
| 1236 | + array_pop($module_path); |
|
| 1237 | + // glue it back together |
|
| 1238 | + $module_path = implode(DS, $module_path) . DS; |
|
| 1239 | + // take first segment from file name pieces and sanitize it |
|
| 1240 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1241 | + // ensure class prefix is added |
|
| 1242 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1243 | + } else { |
|
| 1244 | + // we need to generate the filename based off of the folder name |
|
| 1245 | + // grab and sanitize module name |
|
| 1246 | + $module = strtolower(basename($module_path)); |
|
| 1247 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1248 | + // like trailingslashit() |
|
| 1249 | + $module_path = rtrim($module_path, DS) . DS; |
|
| 1250 | + // create classname from module directory name |
|
| 1251 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1252 | + // add class prefix |
|
| 1253 | + $module_class = 'EED_' . $module; |
|
| 1254 | + } |
|
| 1255 | + // does the module exist ? |
|
| 1256 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1257 | + $msg = sprintf( |
|
| 1258 | + __( |
|
| 1259 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1260 | + 'event_espresso' |
|
| 1261 | + ), |
|
| 1262 | + $module |
|
| 1263 | + ); |
|
| 1264 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1265 | + return false; |
|
| 1266 | + } |
|
| 1267 | + // load the module class file |
|
| 1268 | + require_once($module_path . $module_class . $module_ext); |
|
| 1269 | + // verify that class exists |
|
| 1270 | + if (! class_exists($module_class)) { |
|
| 1271 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1272 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1273 | + return false; |
|
| 1274 | + } |
|
| 1275 | + // add to array of registered modules |
|
| 1276 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1277 | + do_action( |
|
| 1278 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1279 | + $module_class, |
|
| 1280 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1281 | + ); |
|
| 1282 | + return true; |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + |
|
| 1286 | + /** |
|
| 1287 | + * _initialize_shortcodes |
|
| 1288 | + * allow shortcodes to set hooks for the rest of the system |
|
| 1289 | + * |
|
| 1290 | + * @access private |
|
| 1291 | + * @return void |
|
| 1292 | + */ |
|
| 1293 | + private function _initialize_shortcodes() |
|
| 1294 | + { |
|
| 1295 | + // cycle thru shortcode folders |
|
| 1296 | + foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) { |
|
| 1297 | + // add class prefix |
|
| 1298 | + $shortcode_class = 'EES_' . $shortcode; |
|
| 1299 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1300 | + // which set hooks ? |
|
| 1301 | + if (is_admin()) { |
|
| 1302 | + // fire immediately |
|
| 1303 | + call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
| 1304 | + } else { |
|
| 1305 | + // delay until other systems are online |
|
| 1306 | + add_action( |
|
| 1307 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1308 | + array($shortcode_class, 'set_hooks') |
|
| 1309 | + ); |
|
| 1310 | + // convert classname to UPPERCASE and create WP shortcode. |
|
| 1311 | + $shortcode_tag = strtoupper($shortcode); |
|
| 1312 | + // but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor' |
|
| 1313 | + if (! shortcode_exists($shortcode_tag)) { |
|
| 1314 | + // NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes() |
|
| 1315 | + add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + } |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + |
|
| 1322 | + /** |
|
| 1323 | + * _initialize_modules |
|
| 1324 | + * allow modules to set hooks for the rest of the system |
|
| 1325 | + * |
|
| 1326 | + * @access private |
|
| 1327 | + * @return void |
|
| 1328 | + */ |
|
| 1329 | + private function _initialize_modules() |
|
| 1330 | + { |
|
| 1331 | + // cycle thru shortcode folders |
|
| 1332 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1333 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1334 | + // which set hooks ? |
|
| 1335 | + if (is_admin()) { |
|
| 1336 | + // fire immediately |
|
| 1337 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1338 | + } else { |
|
| 1339 | + // delay until other systems are online |
|
| 1340 | + add_action( |
|
| 1341 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1342 | + array($module_class, 'set_hooks') |
|
| 1343 | + ); |
|
| 1344 | + } |
|
| 1345 | + } |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + |
|
| 1349 | + /** |
|
| 1350 | + * register_route - adds module method routes to route_map |
|
| 1351 | + * |
|
| 1352 | + * @access public |
|
| 1353 | + * @param string $route - "pretty" public alias for module method |
|
| 1354 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1355 | + * @param string $method_name - the actual module method to be routed to |
|
| 1356 | + * @param string $key - url param key indicating a route is being called |
|
| 1357 | + * @return bool |
|
| 1358 | + */ |
|
| 1359 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1360 | + { |
|
| 1361 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1362 | + $module = str_replace('EED_', '', $module); |
|
| 1363 | + $module_class = 'EED_' . $module; |
|
| 1364 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1365 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1366 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1367 | + return false; |
|
| 1368 | + } |
|
| 1369 | + if (empty($route)) { |
|
| 1370 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1371 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1372 | + return false; |
|
| 1373 | + } |
|
| 1374 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1375 | + $msg = sprintf( |
|
| 1376 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1377 | + $route |
|
| 1378 | + ); |
|
| 1379 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1380 | + return false; |
|
| 1381 | + } |
|
| 1382 | + EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1383 | + return true; |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + |
|
| 1387 | + /** |
|
| 1388 | + * get_route - get module method route |
|
| 1389 | + * |
|
| 1390 | + * @access public |
|
| 1391 | + * @param string $route - "pretty" public alias for module method |
|
| 1392 | + * @param string $key - url param key indicating a route is being called |
|
| 1393 | + * @return string |
|
| 1394 | + */ |
|
| 1395 | + public static function get_route($route = null, $key = 'ee') |
|
| 1396 | + { |
|
| 1397 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1398 | + $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1399 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1400 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1401 | + } |
|
| 1402 | + return null; |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * get_routes - get ALL module method routes |
|
| 1408 | + * |
|
| 1409 | + * @access public |
|
| 1410 | + * @return array |
|
| 1411 | + */ |
|
| 1412 | + public static function get_routes() |
|
| 1413 | + { |
|
| 1414 | + return EE_Config::$_module_route_map; |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + |
|
| 1418 | + /** |
|
| 1419 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1420 | + * |
|
| 1421 | + * @access public |
|
| 1422 | + * @param string $route - "pretty" public alias for module method |
|
| 1423 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1424 | + * class, allows different forwards to be served based on status |
|
| 1425 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1426 | + * @param string $key - url param key indicating a route is being called |
|
| 1427 | + * @return bool |
|
| 1428 | + */ |
|
| 1429 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1430 | + { |
|
| 1431 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1432 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1433 | + $msg = sprintf( |
|
| 1434 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1435 | + $route |
|
| 1436 | + ); |
|
| 1437 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1438 | + return false; |
|
| 1439 | + } |
|
| 1440 | + if (empty($forward)) { |
|
| 1441 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1442 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1443 | + return false; |
|
| 1444 | + } |
|
| 1445 | + if (is_array($forward)) { |
|
| 1446 | + if (! isset($forward[1])) { |
|
| 1447 | + $msg = sprintf( |
|
| 1448 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1449 | + $route |
|
| 1450 | + ); |
|
| 1451 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | + return false; |
|
| 1453 | + } |
|
| 1454 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1455 | + $msg = sprintf( |
|
| 1456 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1457 | + $forward[1], |
|
| 1458 | + $route |
|
| 1459 | + ); |
|
| 1460 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1461 | + return false; |
|
| 1462 | + } |
|
| 1463 | + } else if (! function_exists($forward)) { |
|
| 1464 | + $msg = sprintf( |
|
| 1465 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1466 | + $forward, |
|
| 1467 | + $route |
|
| 1468 | + ); |
|
| 1469 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1470 | + return false; |
|
| 1471 | + } |
|
| 1472 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1473 | + return true; |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + |
|
| 1477 | + /** |
|
| 1478 | + * get_forward - get forwarding route |
|
| 1479 | + * |
|
| 1480 | + * @access public |
|
| 1481 | + * @param string $route - "pretty" public alias for module method |
|
| 1482 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1483 | + * allows different forwards to be served based on status |
|
| 1484 | + * @param string $key - url param key indicating a route is being called |
|
| 1485 | + * @return string |
|
| 1486 | + */ |
|
| 1487 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1488 | + { |
|
| 1489 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1490 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1491 | + return apply_filters( |
|
| 1492 | + 'FHEE__EE_Config__get_forward', |
|
| 1493 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1494 | + $route, |
|
| 1495 | + $status |
|
| 1496 | + ); |
|
| 1497 | + } |
|
| 1498 | + return null; |
|
| 1499 | + } |
|
| 1500 | + |
|
| 1501 | + |
|
| 1502 | + /** |
|
| 1503 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1504 | + * results |
|
| 1505 | + * |
|
| 1506 | + * @access public |
|
| 1507 | + * @param string $route - "pretty" public alias for module method |
|
| 1508 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1509 | + * allows different views to be served based on status |
|
| 1510 | + * @param string $view |
|
| 1511 | + * @param string $key - url param key indicating a route is being called |
|
| 1512 | + * @return bool |
|
| 1513 | + */ |
|
| 1514 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1515 | + { |
|
| 1516 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1517 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1518 | + $msg = sprintf( |
|
| 1519 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1520 | + $route |
|
| 1521 | + ); |
|
| 1522 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1523 | + return false; |
|
| 1524 | + } |
|
| 1525 | + if (! is_readable($view)) { |
|
| 1526 | + $msg = sprintf( |
|
| 1527 | + __( |
|
| 1528 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1529 | + 'event_espresso' |
|
| 1530 | + ), |
|
| 1531 | + $view |
|
| 1532 | + ); |
|
| 1533 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1534 | + return false; |
|
| 1535 | + } |
|
| 1536 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1537 | + return true; |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + |
|
| 1541 | + /** |
|
| 1542 | + * get_view - get view for route and status |
|
| 1543 | + * |
|
| 1544 | + * @access public |
|
| 1545 | + * @param string $route - "pretty" public alias for module method |
|
| 1546 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1547 | + * allows different views to be served based on status |
|
| 1548 | + * @param string $key - url param key indicating a route is being called |
|
| 1549 | + * @return string |
|
| 1550 | + */ |
|
| 1551 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1552 | + { |
|
| 1553 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1554 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1555 | + return apply_filters( |
|
| 1556 | + 'FHEE__EE_Config__get_view', |
|
| 1557 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1558 | + $route, |
|
| 1559 | + $status |
|
| 1560 | + ); |
|
| 1561 | + } |
|
| 1562 | + return null; |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + |
|
| 1566 | + public function update_addon_option_names() |
|
| 1567 | + { |
|
| 1568 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + |
|
| 1572 | + public function shutdown() |
|
| 1573 | + { |
|
| 1574 | + $this->update_addon_option_names(); |
|
| 1575 | + } |
|
| 1576 | 1576 | |
| 1577 | 1577 | |
| 1578 | 1578 | } |
@@ -1586,104 +1586,104 @@ discard block |
||
| 1586 | 1586 | class EE_Config_Base |
| 1587 | 1587 | { |
| 1588 | 1588 | |
| 1589 | - /** |
|
| 1590 | - * Utility function for escaping the value of a property and returning. |
|
| 1591 | - * |
|
| 1592 | - * @param string $property property name (checks to see if exists). |
|
| 1593 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1594 | - * @throws \EE_Error |
|
| 1595 | - */ |
|
| 1596 | - public function get_pretty($property) |
|
| 1597 | - { |
|
| 1598 | - if (! property_exists($this, $property)) { |
|
| 1599 | - throw new EE_Error( |
|
| 1600 | - sprintf( |
|
| 1601 | - __( |
|
| 1602 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1603 | - 'event_espresso' |
|
| 1604 | - ), |
|
| 1605 | - get_class($this), |
|
| 1606 | - $property |
|
| 1607 | - ) |
|
| 1608 | - ); |
|
| 1609 | - } |
|
| 1610 | - //just handling escaping of strings for now. |
|
| 1611 | - if (is_string($this->{$property})) { |
|
| 1612 | - return stripslashes($this->{$property}); |
|
| 1613 | - } |
|
| 1614 | - return $this->{$property}; |
|
| 1615 | - } |
|
| 1616 | - |
|
| 1617 | - |
|
| 1618 | - public function populate() |
|
| 1619 | - { |
|
| 1620 | - //grab defaults via a new instance of this class. |
|
| 1621 | - $class_name = get_class($this); |
|
| 1622 | - $defaults = new $class_name; |
|
| 1623 | - //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1624 | - //default from our $defaults object. |
|
| 1625 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1626 | - if ($this->{$property} === null) { |
|
| 1627 | - $this->{$property} = $value; |
|
| 1628 | - } |
|
| 1629 | - } |
|
| 1630 | - //cleanup |
|
| 1631 | - unset($defaults); |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * @ override magic methods |
|
| 1637 | - * @ return void |
|
| 1638 | - */ |
|
| 1589 | + /** |
|
| 1590 | + * Utility function for escaping the value of a property and returning. |
|
| 1591 | + * |
|
| 1592 | + * @param string $property property name (checks to see if exists). |
|
| 1593 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1594 | + * @throws \EE_Error |
|
| 1595 | + */ |
|
| 1596 | + public function get_pretty($property) |
|
| 1597 | + { |
|
| 1598 | + if (! property_exists($this, $property)) { |
|
| 1599 | + throw new EE_Error( |
|
| 1600 | + sprintf( |
|
| 1601 | + __( |
|
| 1602 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1603 | + 'event_espresso' |
|
| 1604 | + ), |
|
| 1605 | + get_class($this), |
|
| 1606 | + $property |
|
| 1607 | + ) |
|
| 1608 | + ); |
|
| 1609 | + } |
|
| 1610 | + //just handling escaping of strings for now. |
|
| 1611 | + if (is_string($this->{$property})) { |
|
| 1612 | + return stripslashes($this->{$property}); |
|
| 1613 | + } |
|
| 1614 | + return $this->{$property}; |
|
| 1615 | + } |
|
| 1616 | + |
|
| 1617 | + |
|
| 1618 | + public function populate() |
|
| 1619 | + { |
|
| 1620 | + //grab defaults via a new instance of this class. |
|
| 1621 | + $class_name = get_class($this); |
|
| 1622 | + $defaults = new $class_name; |
|
| 1623 | + //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1624 | + //default from our $defaults object. |
|
| 1625 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1626 | + if ($this->{$property} === null) { |
|
| 1627 | + $this->{$property} = $value; |
|
| 1628 | + } |
|
| 1629 | + } |
|
| 1630 | + //cleanup |
|
| 1631 | + unset($defaults); |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * @ override magic methods |
|
| 1637 | + * @ return void |
|
| 1638 | + */ |
|
| 1639 | 1639 | // public function __get($a) { return apply_filters('FHEE__'.get_class($this).'__get__'.$a,$this->{$a}); } |
| 1640 | 1640 | // public function __set($a,$b) { return apply_filters('FHEE__'.get_class($this).'__set__'.$a, $this->{$a} = $b ); } |
| 1641 | - /** |
|
| 1642 | - * __isset |
|
| 1643 | - * |
|
| 1644 | - * @param $a |
|
| 1645 | - * @return bool |
|
| 1646 | - */ |
|
| 1647 | - public function __isset($a) |
|
| 1648 | - { |
|
| 1649 | - return false; |
|
| 1650 | - } |
|
| 1651 | - |
|
| 1652 | - |
|
| 1653 | - /** |
|
| 1654 | - * __unset |
|
| 1655 | - * |
|
| 1656 | - * @param $a |
|
| 1657 | - * @return bool |
|
| 1658 | - */ |
|
| 1659 | - public function __unset($a) |
|
| 1660 | - { |
|
| 1661 | - return false; |
|
| 1662 | - } |
|
| 1663 | - |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * __clone |
|
| 1667 | - */ |
|
| 1668 | - public function __clone() |
|
| 1669 | - { |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - |
|
| 1673 | - /** |
|
| 1674 | - * __wakeup |
|
| 1675 | - */ |
|
| 1676 | - public function __wakeup() |
|
| 1677 | - { |
|
| 1678 | - } |
|
| 1679 | - |
|
| 1680 | - |
|
| 1681 | - /** |
|
| 1682 | - * __destruct |
|
| 1683 | - */ |
|
| 1684 | - public function __destruct() |
|
| 1685 | - { |
|
| 1686 | - } |
|
| 1641 | + /** |
|
| 1642 | + * __isset |
|
| 1643 | + * |
|
| 1644 | + * @param $a |
|
| 1645 | + * @return bool |
|
| 1646 | + */ |
|
| 1647 | + public function __isset($a) |
|
| 1648 | + { |
|
| 1649 | + return false; |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + |
|
| 1653 | + /** |
|
| 1654 | + * __unset |
|
| 1655 | + * |
|
| 1656 | + * @param $a |
|
| 1657 | + * @return bool |
|
| 1658 | + */ |
|
| 1659 | + public function __unset($a) |
|
| 1660 | + { |
|
| 1661 | + return false; |
|
| 1662 | + } |
|
| 1663 | + |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * __clone |
|
| 1667 | + */ |
|
| 1668 | + public function __clone() |
|
| 1669 | + { |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + |
|
| 1673 | + /** |
|
| 1674 | + * __wakeup |
|
| 1675 | + */ |
|
| 1676 | + public function __wakeup() |
|
| 1677 | + { |
|
| 1678 | + } |
|
| 1679 | + |
|
| 1680 | + |
|
| 1681 | + /** |
|
| 1682 | + * __destruct |
|
| 1683 | + */ |
|
| 1684 | + public function __destruct() |
|
| 1685 | + { |
|
| 1686 | + } |
|
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | 1689 | |
@@ -1693,288 +1693,288 @@ discard block |
||
| 1693 | 1693 | class EE_Core_Config extends EE_Config_Base |
| 1694 | 1694 | { |
| 1695 | 1695 | |
| 1696 | - public $current_blog_id; |
|
| 1697 | - |
|
| 1698 | - public $ee_ueip_optin; |
|
| 1699 | - |
|
| 1700 | - public $ee_ueip_has_notified; |
|
| 1701 | - |
|
| 1702 | - /** |
|
| 1703 | - * Not to be confused with the 4 critical page variables (See |
|
| 1704 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1705 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1706 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1707 | - * |
|
| 1708 | - * @var array |
|
| 1709 | - */ |
|
| 1710 | - public $post_shortcodes; |
|
| 1711 | - |
|
| 1712 | - public $module_route_map; |
|
| 1713 | - |
|
| 1714 | - public $module_forward_map; |
|
| 1715 | - |
|
| 1716 | - public $module_view_map; |
|
| 1717 | - |
|
| 1718 | - /** |
|
| 1719 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1720 | - * |
|
| 1721 | - * @var int |
|
| 1722 | - */ |
|
| 1723 | - public $reg_page_id; |
|
| 1724 | - |
|
| 1725 | - public $txn_page_id; |
|
| 1726 | - |
|
| 1727 | - public $thank_you_page_id; |
|
| 1728 | - |
|
| 1729 | - public $cancel_page_id; |
|
| 1730 | - |
|
| 1731 | - /** |
|
| 1732 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1733 | - * |
|
| 1734 | - * @var int |
|
| 1735 | - */ |
|
| 1736 | - public $reg_page_url; |
|
| 1737 | - |
|
| 1738 | - public $txn_page_url; |
|
| 1739 | - |
|
| 1740 | - public $thank_you_page_url; |
|
| 1741 | - |
|
| 1742 | - public $cancel_page_url; |
|
| 1743 | - |
|
| 1744 | - /** |
|
| 1745 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1746 | - */ |
|
| 1747 | - public $event_cpt_slug; |
|
| 1748 | - |
|
| 1749 | - |
|
| 1750 | - /** |
|
| 1751 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1752 | - * request across blog switches in a multisite context. |
|
| 1753 | - * Avoids extra queries to the db for this option. |
|
| 1754 | - * |
|
| 1755 | - * @var bool |
|
| 1756 | - */ |
|
| 1757 | - public static $ee_ueip_option; |
|
| 1758 | - |
|
| 1759 | - |
|
| 1760 | - /** |
|
| 1761 | - * class constructor |
|
| 1762 | - * |
|
| 1763 | - * @access public |
|
| 1764 | - */ |
|
| 1765 | - public function __construct() |
|
| 1766 | - { |
|
| 1767 | - // set default organization settings |
|
| 1768 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1769 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1770 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1771 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1772 | - $this->post_shortcodes = array(); |
|
| 1773 | - $this->module_route_map = array(); |
|
| 1774 | - $this->module_forward_map = array(); |
|
| 1775 | - $this->module_view_map = array(); |
|
| 1776 | - // critical EE page IDs |
|
| 1777 | - $this->reg_page_id = 0; |
|
| 1778 | - $this->txn_page_id = 0; |
|
| 1779 | - $this->thank_you_page_id = 0; |
|
| 1780 | - $this->cancel_page_id = 0; |
|
| 1781 | - // critical EE page URLs |
|
| 1782 | - $this->reg_page_url = ''; |
|
| 1783 | - $this->txn_page_url = ''; |
|
| 1784 | - $this->thank_you_page_url = ''; |
|
| 1785 | - $this->cancel_page_url = ''; |
|
| 1786 | - //cpt slugs |
|
| 1787 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1788 | - //ueip constant check |
|
| 1789 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1790 | - $this->ee_ueip_optin = false; |
|
| 1791 | - $this->ee_ueip_has_notified = true; |
|
| 1792 | - } |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - /** |
|
| 1797 | - * @return array |
|
| 1798 | - */ |
|
| 1799 | - public function get_critical_pages_array() |
|
| 1800 | - { |
|
| 1801 | - return array( |
|
| 1802 | - $this->reg_page_id, |
|
| 1803 | - $this->txn_page_id, |
|
| 1804 | - $this->thank_you_page_id, |
|
| 1805 | - $this->cancel_page_id, |
|
| 1806 | - ); |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - |
|
| 1810 | - /** |
|
| 1811 | - * @return array |
|
| 1812 | - */ |
|
| 1813 | - public function get_critical_pages_shortcodes_array() |
|
| 1814 | - { |
|
| 1815 | - return array( |
|
| 1816 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1817 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1818 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1819 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1820 | - ); |
|
| 1821 | - } |
|
| 1822 | - |
|
| 1823 | - |
|
| 1824 | - /** |
|
| 1825 | - * gets/returns URL for EE reg_page |
|
| 1826 | - * |
|
| 1827 | - * @access public |
|
| 1828 | - * @return string |
|
| 1829 | - */ |
|
| 1830 | - public function reg_page_url() |
|
| 1831 | - { |
|
| 1832 | - if (! $this->reg_page_url) { |
|
| 1833 | - $this->reg_page_url = add_query_arg( |
|
| 1834 | - array('uts' => time()), |
|
| 1835 | - get_permalink($this->reg_page_id) |
|
| 1836 | - ) . '#checkout'; |
|
| 1837 | - } |
|
| 1838 | - return $this->reg_page_url; |
|
| 1839 | - } |
|
| 1840 | - |
|
| 1841 | - |
|
| 1842 | - /** |
|
| 1843 | - * gets/returns URL for EE txn_page |
|
| 1844 | - * |
|
| 1845 | - * @param array $query_args like what gets passed to |
|
| 1846 | - * add_query_arg() as the first argument |
|
| 1847 | - * @access public |
|
| 1848 | - * @return string |
|
| 1849 | - */ |
|
| 1850 | - public function txn_page_url($query_args = array()) |
|
| 1851 | - { |
|
| 1852 | - if (! $this->txn_page_url) { |
|
| 1853 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1854 | - } |
|
| 1855 | - if ($query_args) { |
|
| 1856 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1857 | - } else { |
|
| 1858 | - return $this->txn_page_url; |
|
| 1859 | - } |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - /** |
|
| 1864 | - * gets/returns URL for EE thank_you_page |
|
| 1865 | - * |
|
| 1866 | - * @param array $query_args like what gets passed to |
|
| 1867 | - * add_query_arg() as the first argument |
|
| 1868 | - * @access public |
|
| 1869 | - * @return string |
|
| 1870 | - */ |
|
| 1871 | - public function thank_you_page_url($query_args = array()) |
|
| 1872 | - { |
|
| 1873 | - if (! $this->thank_you_page_url) { |
|
| 1874 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1875 | - } |
|
| 1876 | - if ($query_args) { |
|
| 1877 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1878 | - } else { |
|
| 1879 | - return $this->thank_you_page_url; |
|
| 1880 | - } |
|
| 1881 | - } |
|
| 1882 | - |
|
| 1883 | - |
|
| 1884 | - /** |
|
| 1885 | - * gets/returns URL for EE cancel_page |
|
| 1886 | - * |
|
| 1887 | - * @access public |
|
| 1888 | - * @return string |
|
| 1889 | - */ |
|
| 1890 | - public function cancel_page_url() |
|
| 1891 | - { |
|
| 1892 | - if (! $this->cancel_page_url) { |
|
| 1893 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1894 | - } |
|
| 1895 | - return $this->cancel_page_url; |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - |
|
| 1899 | - /** |
|
| 1900 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1901 | - * |
|
| 1902 | - * @since 4.7.5 |
|
| 1903 | - */ |
|
| 1904 | - protected function _reset_urls() |
|
| 1905 | - { |
|
| 1906 | - $this->reg_page_url = ''; |
|
| 1907 | - $this->txn_page_url = ''; |
|
| 1908 | - $this->cancel_page_url = ''; |
|
| 1909 | - $this->thank_you_page_url = ''; |
|
| 1910 | - } |
|
| 1911 | - |
|
| 1912 | - |
|
| 1913 | - /** |
|
| 1914 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1915 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1916 | - * on the main site only. |
|
| 1917 | - * |
|
| 1918 | - * @return mixed|void |
|
| 1919 | - */ |
|
| 1920 | - protected function _get_main_ee_ueip_optin() |
|
| 1921 | - { |
|
| 1922 | - //if this is the main site then we can just bypass our direct query. |
|
| 1923 | - if (is_main_site()) { |
|
| 1924 | - return get_option('ee_ueip_optin', false); |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - //is this already cached for this request? If so use it. |
|
| 1928 | - if (! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1929 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1930 | - } |
|
| 1931 | - |
|
| 1932 | - global $wpdb; |
|
| 1933 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1934 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1935 | - $option = 'ee_ueip_optin'; |
|
| 1936 | - |
|
| 1937 | - //set correct table for query |
|
| 1938 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1939 | - |
|
| 1940 | - |
|
| 1941 | - //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1942 | - //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1943 | - //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1944 | - //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1945 | - //for the purpose of caching. |
|
| 1946 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1947 | - if (false !== $pre) { |
|
| 1948 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1949 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1953 | - $option)); |
|
| 1954 | - if (is_object($row)) { |
|
| 1955 | - $value = $row->option_value; |
|
| 1956 | - } else { //option does not exist so use default. |
|
| 1957 | - return apply_filters('default_option_' . $option, false, $option); |
|
| 1958 | - } |
|
| 1959 | - |
|
| 1960 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1961 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1962 | - } |
|
| 1963 | - |
|
| 1964 | - |
|
| 1965 | - /** |
|
| 1966 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1967 | - * on the object. |
|
| 1968 | - * |
|
| 1969 | - * @return array |
|
| 1970 | - */ |
|
| 1971 | - public function __sleep() |
|
| 1972 | - { |
|
| 1973 | - //reset all url properties |
|
| 1974 | - $this->_reset_urls(); |
|
| 1975 | - //return what to save to db |
|
| 1976 | - return array_keys(get_object_vars($this)); |
|
| 1977 | - } |
|
| 1696 | + public $current_blog_id; |
|
| 1697 | + |
|
| 1698 | + public $ee_ueip_optin; |
|
| 1699 | + |
|
| 1700 | + public $ee_ueip_has_notified; |
|
| 1701 | + |
|
| 1702 | + /** |
|
| 1703 | + * Not to be confused with the 4 critical page variables (See |
|
| 1704 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1705 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1706 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1707 | + * |
|
| 1708 | + * @var array |
|
| 1709 | + */ |
|
| 1710 | + public $post_shortcodes; |
|
| 1711 | + |
|
| 1712 | + public $module_route_map; |
|
| 1713 | + |
|
| 1714 | + public $module_forward_map; |
|
| 1715 | + |
|
| 1716 | + public $module_view_map; |
|
| 1717 | + |
|
| 1718 | + /** |
|
| 1719 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1720 | + * |
|
| 1721 | + * @var int |
|
| 1722 | + */ |
|
| 1723 | + public $reg_page_id; |
|
| 1724 | + |
|
| 1725 | + public $txn_page_id; |
|
| 1726 | + |
|
| 1727 | + public $thank_you_page_id; |
|
| 1728 | + |
|
| 1729 | + public $cancel_page_id; |
|
| 1730 | + |
|
| 1731 | + /** |
|
| 1732 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1733 | + * |
|
| 1734 | + * @var int |
|
| 1735 | + */ |
|
| 1736 | + public $reg_page_url; |
|
| 1737 | + |
|
| 1738 | + public $txn_page_url; |
|
| 1739 | + |
|
| 1740 | + public $thank_you_page_url; |
|
| 1741 | + |
|
| 1742 | + public $cancel_page_url; |
|
| 1743 | + |
|
| 1744 | + /** |
|
| 1745 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1746 | + */ |
|
| 1747 | + public $event_cpt_slug; |
|
| 1748 | + |
|
| 1749 | + |
|
| 1750 | + /** |
|
| 1751 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1752 | + * request across blog switches in a multisite context. |
|
| 1753 | + * Avoids extra queries to the db for this option. |
|
| 1754 | + * |
|
| 1755 | + * @var bool |
|
| 1756 | + */ |
|
| 1757 | + public static $ee_ueip_option; |
|
| 1758 | + |
|
| 1759 | + |
|
| 1760 | + /** |
|
| 1761 | + * class constructor |
|
| 1762 | + * |
|
| 1763 | + * @access public |
|
| 1764 | + */ |
|
| 1765 | + public function __construct() |
|
| 1766 | + { |
|
| 1767 | + // set default organization settings |
|
| 1768 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1769 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1770 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1771 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1772 | + $this->post_shortcodes = array(); |
|
| 1773 | + $this->module_route_map = array(); |
|
| 1774 | + $this->module_forward_map = array(); |
|
| 1775 | + $this->module_view_map = array(); |
|
| 1776 | + // critical EE page IDs |
|
| 1777 | + $this->reg_page_id = 0; |
|
| 1778 | + $this->txn_page_id = 0; |
|
| 1779 | + $this->thank_you_page_id = 0; |
|
| 1780 | + $this->cancel_page_id = 0; |
|
| 1781 | + // critical EE page URLs |
|
| 1782 | + $this->reg_page_url = ''; |
|
| 1783 | + $this->txn_page_url = ''; |
|
| 1784 | + $this->thank_you_page_url = ''; |
|
| 1785 | + $this->cancel_page_url = ''; |
|
| 1786 | + //cpt slugs |
|
| 1787 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1788 | + //ueip constant check |
|
| 1789 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1790 | + $this->ee_ueip_optin = false; |
|
| 1791 | + $this->ee_ueip_has_notified = true; |
|
| 1792 | + } |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + /** |
|
| 1797 | + * @return array |
|
| 1798 | + */ |
|
| 1799 | + public function get_critical_pages_array() |
|
| 1800 | + { |
|
| 1801 | + return array( |
|
| 1802 | + $this->reg_page_id, |
|
| 1803 | + $this->txn_page_id, |
|
| 1804 | + $this->thank_you_page_id, |
|
| 1805 | + $this->cancel_page_id, |
|
| 1806 | + ); |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + |
|
| 1810 | + /** |
|
| 1811 | + * @return array |
|
| 1812 | + */ |
|
| 1813 | + public function get_critical_pages_shortcodes_array() |
|
| 1814 | + { |
|
| 1815 | + return array( |
|
| 1816 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1817 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1818 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1819 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1820 | + ); |
|
| 1821 | + } |
|
| 1822 | + |
|
| 1823 | + |
|
| 1824 | + /** |
|
| 1825 | + * gets/returns URL for EE reg_page |
|
| 1826 | + * |
|
| 1827 | + * @access public |
|
| 1828 | + * @return string |
|
| 1829 | + */ |
|
| 1830 | + public function reg_page_url() |
|
| 1831 | + { |
|
| 1832 | + if (! $this->reg_page_url) { |
|
| 1833 | + $this->reg_page_url = add_query_arg( |
|
| 1834 | + array('uts' => time()), |
|
| 1835 | + get_permalink($this->reg_page_id) |
|
| 1836 | + ) . '#checkout'; |
|
| 1837 | + } |
|
| 1838 | + return $this->reg_page_url; |
|
| 1839 | + } |
|
| 1840 | + |
|
| 1841 | + |
|
| 1842 | + /** |
|
| 1843 | + * gets/returns URL for EE txn_page |
|
| 1844 | + * |
|
| 1845 | + * @param array $query_args like what gets passed to |
|
| 1846 | + * add_query_arg() as the first argument |
|
| 1847 | + * @access public |
|
| 1848 | + * @return string |
|
| 1849 | + */ |
|
| 1850 | + public function txn_page_url($query_args = array()) |
|
| 1851 | + { |
|
| 1852 | + if (! $this->txn_page_url) { |
|
| 1853 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1854 | + } |
|
| 1855 | + if ($query_args) { |
|
| 1856 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1857 | + } else { |
|
| 1858 | + return $this->txn_page_url; |
|
| 1859 | + } |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + /** |
|
| 1864 | + * gets/returns URL for EE thank_you_page |
|
| 1865 | + * |
|
| 1866 | + * @param array $query_args like what gets passed to |
|
| 1867 | + * add_query_arg() as the first argument |
|
| 1868 | + * @access public |
|
| 1869 | + * @return string |
|
| 1870 | + */ |
|
| 1871 | + public function thank_you_page_url($query_args = array()) |
|
| 1872 | + { |
|
| 1873 | + if (! $this->thank_you_page_url) { |
|
| 1874 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1875 | + } |
|
| 1876 | + if ($query_args) { |
|
| 1877 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1878 | + } else { |
|
| 1879 | + return $this->thank_you_page_url; |
|
| 1880 | + } |
|
| 1881 | + } |
|
| 1882 | + |
|
| 1883 | + |
|
| 1884 | + /** |
|
| 1885 | + * gets/returns URL for EE cancel_page |
|
| 1886 | + * |
|
| 1887 | + * @access public |
|
| 1888 | + * @return string |
|
| 1889 | + */ |
|
| 1890 | + public function cancel_page_url() |
|
| 1891 | + { |
|
| 1892 | + if (! $this->cancel_page_url) { |
|
| 1893 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1894 | + } |
|
| 1895 | + return $this->cancel_page_url; |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + |
|
| 1899 | + /** |
|
| 1900 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1901 | + * |
|
| 1902 | + * @since 4.7.5 |
|
| 1903 | + */ |
|
| 1904 | + protected function _reset_urls() |
|
| 1905 | + { |
|
| 1906 | + $this->reg_page_url = ''; |
|
| 1907 | + $this->txn_page_url = ''; |
|
| 1908 | + $this->cancel_page_url = ''; |
|
| 1909 | + $this->thank_you_page_url = ''; |
|
| 1910 | + } |
|
| 1911 | + |
|
| 1912 | + |
|
| 1913 | + /** |
|
| 1914 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1915 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1916 | + * on the main site only. |
|
| 1917 | + * |
|
| 1918 | + * @return mixed|void |
|
| 1919 | + */ |
|
| 1920 | + protected function _get_main_ee_ueip_optin() |
|
| 1921 | + { |
|
| 1922 | + //if this is the main site then we can just bypass our direct query. |
|
| 1923 | + if (is_main_site()) { |
|
| 1924 | + return get_option('ee_ueip_optin', false); |
|
| 1925 | + } |
|
| 1926 | + |
|
| 1927 | + //is this already cached for this request? If so use it. |
|
| 1928 | + if (! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1929 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1930 | + } |
|
| 1931 | + |
|
| 1932 | + global $wpdb; |
|
| 1933 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1934 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1935 | + $option = 'ee_ueip_optin'; |
|
| 1936 | + |
|
| 1937 | + //set correct table for query |
|
| 1938 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1939 | + |
|
| 1940 | + |
|
| 1941 | + //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1942 | + //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1943 | + //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1944 | + //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1945 | + //for the purpose of caching. |
|
| 1946 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1947 | + if (false !== $pre) { |
|
| 1948 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1949 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1953 | + $option)); |
|
| 1954 | + if (is_object($row)) { |
|
| 1955 | + $value = $row->option_value; |
|
| 1956 | + } else { //option does not exist so use default. |
|
| 1957 | + return apply_filters('default_option_' . $option, false, $option); |
|
| 1958 | + } |
|
| 1959 | + |
|
| 1960 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1961 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1962 | + } |
|
| 1963 | + |
|
| 1964 | + |
|
| 1965 | + /** |
|
| 1966 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1967 | + * on the object. |
|
| 1968 | + * |
|
| 1969 | + * @return array |
|
| 1970 | + */ |
|
| 1971 | + public function __sleep() |
|
| 1972 | + { |
|
| 1973 | + //reset all url properties |
|
| 1974 | + $this->_reset_urls(); |
|
| 1975 | + //return what to save to db |
|
| 1976 | + return array_keys(get_object_vars($this)); |
|
| 1977 | + } |
|
| 1978 | 1978 | |
| 1979 | 1979 | } |
| 1980 | 1980 | |
@@ -1985,154 +1985,154 @@ discard block |
||
| 1985 | 1985 | class EE_Organization_Config extends EE_Config_Base |
| 1986 | 1986 | { |
| 1987 | 1987 | |
| 1988 | - /** |
|
| 1989 | - * @var string $name |
|
| 1990 | - * eg EE4.1 |
|
| 1991 | - */ |
|
| 1992 | - public $name; |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * @var string $address_1 |
|
| 1996 | - * eg 123 Onna Road |
|
| 1997 | - */ |
|
| 1998 | - public $address_1; |
|
| 1999 | - |
|
| 2000 | - /** |
|
| 2001 | - * @var string $address_2 |
|
| 2002 | - * eg PO Box 123 |
|
| 2003 | - */ |
|
| 2004 | - public $address_2; |
|
| 2005 | - |
|
| 2006 | - /** |
|
| 2007 | - * @var string $city |
|
| 2008 | - * eg Inna City |
|
| 2009 | - */ |
|
| 2010 | - public $city; |
|
| 2011 | - |
|
| 2012 | - /** |
|
| 2013 | - * @var int $STA_ID |
|
| 2014 | - * eg 4 |
|
| 2015 | - */ |
|
| 2016 | - public $STA_ID; |
|
| 2017 | - |
|
| 2018 | - /** |
|
| 2019 | - * @var string $CNT_ISO |
|
| 2020 | - * eg US |
|
| 2021 | - */ |
|
| 2022 | - public $CNT_ISO; |
|
| 2023 | - |
|
| 2024 | - /** |
|
| 2025 | - * @var string $zip |
|
| 2026 | - * eg 12345 or V1A 2B3 |
|
| 2027 | - */ |
|
| 2028 | - public $zip; |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * @var string $email |
|
| 2032 | - * eg [email protected] |
|
| 2033 | - */ |
|
| 2034 | - public $email; |
|
| 2035 | - |
|
| 2036 | - |
|
| 2037 | - /** |
|
| 2038 | - * @var string $phone |
|
| 2039 | - * eg. 111-111-1111 |
|
| 2040 | - */ |
|
| 2041 | - public $phone; |
|
| 2042 | - |
|
| 2043 | - |
|
| 2044 | - /** |
|
| 2045 | - * @var string $vat |
|
| 2046 | - * VAT/Tax Number |
|
| 2047 | - */ |
|
| 2048 | - public $vat; |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * @var string $logo_url |
|
| 2052 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2053 | - */ |
|
| 2054 | - public $logo_url; |
|
| 2055 | - |
|
| 2056 | - |
|
| 2057 | - /** |
|
| 2058 | - * The below are all various properties for holding links to organization social network profiles |
|
| 2059 | - * |
|
| 2060 | - * @var string |
|
| 2061 | - */ |
|
| 2062 | - /** |
|
| 2063 | - * facebook (facebook.com/profile.name) |
|
| 2064 | - * |
|
| 2065 | - * @var string |
|
| 2066 | - */ |
|
| 2067 | - public $facebook; |
|
| 2068 | - |
|
| 2069 | - |
|
| 2070 | - /** |
|
| 2071 | - * twitter (twitter.com/twitter_handle) |
|
| 2072 | - * |
|
| 2073 | - * @var string |
|
| 2074 | - */ |
|
| 2075 | - public $twitter; |
|
| 2076 | - |
|
| 2077 | - |
|
| 2078 | - /** |
|
| 2079 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2080 | - * |
|
| 2081 | - * @var string |
|
| 2082 | - */ |
|
| 2083 | - public $linkedin; |
|
| 2084 | - |
|
| 2085 | - |
|
| 2086 | - /** |
|
| 2087 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2088 | - * |
|
| 2089 | - * @var string |
|
| 2090 | - */ |
|
| 2091 | - public $pinterest; |
|
| 2092 | - |
|
| 2093 | - |
|
| 2094 | - /** |
|
| 2095 | - * google+ (google.com/+profileName) |
|
| 2096 | - * |
|
| 2097 | - * @var string |
|
| 2098 | - */ |
|
| 2099 | - public $google; |
|
| 2100 | - |
|
| 2101 | - |
|
| 2102 | - /** |
|
| 2103 | - * instagram (instagram.com/handle) |
|
| 2104 | - * |
|
| 2105 | - * @var string |
|
| 2106 | - */ |
|
| 2107 | - public $instagram; |
|
| 2108 | - |
|
| 2109 | - |
|
| 2110 | - /** |
|
| 2111 | - * class constructor |
|
| 2112 | - * |
|
| 2113 | - * @access public |
|
| 2114 | - */ |
|
| 2115 | - public function __construct() |
|
| 2116 | - { |
|
| 2117 | - // set default organization settings |
|
| 2118 | - $this->name = get_bloginfo('name'); |
|
| 2119 | - $this->address_1 = '123 Onna Road'; |
|
| 2120 | - $this->address_2 = 'PO Box 123'; |
|
| 2121 | - $this->city = 'Inna City'; |
|
| 2122 | - $this->STA_ID = 4; |
|
| 2123 | - $this->CNT_ISO = 'US'; |
|
| 2124 | - $this->zip = '12345'; |
|
| 2125 | - $this->email = get_bloginfo('admin_email'); |
|
| 2126 | - $this->phone = ''; |
|
| 2127 | - $this->vat = '123456789'; |
|
| 2128 | - $this->logo_url = ''; |
|
| 2129 | - $this->facebook = ''; |
|
| 2130 | - $this->twitter = ''; |
|
| 2131 | - $this->linkedin = ''; |
|
| 2132 | - $this->pinterest = ''; |
|
| 2133 | - $this->google = ''; |
|
| 2134 | - $this->instagram = ''; |
|
| 2135 | - } |
|
| 1988 | + /** |
|
| 1989 | + * @var string $name |
|
| 1990 | + * eg EE4.1 |
|
| 1991 | + */ |
|
| 1992 | + public $name; |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * @var string $address_1 |
|
| 1996 | + * eg 123 Onna Road |
|
| 1997 | + */ |
|
| 1998 | + public $address_1; |
|
| 1999 | + |
|
| 2000 | + /** |
|
| 2001 | + * @var string $address_2 |
|
| 2002 | + * eg PO Box 123 |
|
| 2003 | + */ |
|
| 2004 | + public $address_2; |
|
| 2005 | + |
|
| 2006 | + /** |
|
| 2007 | + * @var string $city |
|
| 2008 | + * eg Inna City |
|
| 2009 | + */ |
|
| 2010 | + public $city; |
|
| 2011 | + |
|
| 2012 | + /** |
|
| 2013 | + * @var int $STA_ID |
|
| 2014 | + * eg 4 |
|
| 2015 | + */ |
|
| 2016 | + public $STA_ID; |
|
| 2017 | + |
|
| 2018 | + /** |
|
| 2019 | + * @var string $CNT_ISO |
|
| 2020 | + * eg US |
|
| 2021 | + */ |
|
| 2022 | + public $CNT_ISO; |
|
| 2023 | + |
|
| 2024 | + /** |
|
| 2025 | + * @var string $zip |
|
| 2026 | + * eg 12345 or V1A 2B3 |
|
| 2027 | + */ |
|
| 2028 | + public $zip; |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * @var string $email |
|
| 2032 | + * eg [email protected] |
|
| 2033 | + */ |
|
| 2034 | + public $email; |
|
| 2035 | + |
|
| 2036 | + |
|
| 2037 | + /** |
|
| 2038 | + * @var string $phone |
|
| 2039 | + * eg. 111-111-1111 |
|
| 2040 | + */ |
|
| 2041 | + public $phone; |
|
| 2042 | + |
|
| 2043 | + |
|
| 2044 | + /** |
|
| 2045 | + * @var string $vat |
|
| 2046 | + * VAT/Tax Number |
|
| 2047 | + */ |
|
| 2048 | + public $vat; |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * @var string $logo_url |
|
| 2052 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2053 | + */ |
|
| 2054 | + public $logo_url; |
|
| 2055 | + |
|
| 2056 | + |
|
| 2057 | + /** |
|
| 2058 | + * The below are all various properties for holding links to organization social network profiles |
|
| 2059 | + * |
|
| 2060 | + * @var string |
|
| 2061 | + */ |
|
| 2062 | + /** |
|
| 2063 | + * facebook (facebook.com/profile.name) |
|
| 2064 | + * |
|
| 2065 | + * @var string |
|
| 2066 | + */ |
|
| 2067 | + public $facebook; |
|
| 2068 | + |
|
| 2069 | + |
|
| 2070 | + /** |
|
| 2071 | + * twitter (twitter.com/twitter_handle) |
|
| 2072 | + * |
|
| 2073 | + * @var string |
|
| 2074 | + */ |
|
| 2075 | + public $twitter; |
|
| 2076 | + |
|
| 2077 | + |
|
| 2078 | + /** |
|
| 2079 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2080 | + * |
|
| 2081 | + * @var string |
|
| 2082 | + */ |
|
| 2083 | + public $linkedin; |
|
| 2084 | + |
|
| 2085 | + |
|
| 2086 | + /** |
|
| 2087 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2088 | + * |
|
| 2089 | + * @var string |
|
| 2090 | + */ |
|
| 2091 | + public $pinterest; |
|
| 2092 | + |
|
| 2093 | + |
|
| 2094 | + /** |
|
| 2095 | + * google+ (google.com/+profileName) |
|
| 2096 | + * |
|
| 2097 | + * @var string |
|
| 2098 | + */ |
|
| 2099 | + public $google; |
|
| 2100 | + |
|
| 2101 | + |
|
| 2102 | + /** |
|
| 2103 | + * instagram (instagram.com/handle) |
|
| 2104 | + * |
|
| 2105 | + * @var string |
|
| 2106 | + */ |
|
| 2107 | + public $instagram; |
|
| 2108 | + |
|
| 2109 | + |
|
| 2110 | + /** |
|
| 2111 | + * class constructor |
|
| 2112 | + * |
|
| 2113 | + * @access public |
|
| 2114 | + */ |
|
| 2115 | + public function __construct() |
|
| 2116 | + { |
|
| 2117 | + // set default organization settings |
|
| 2118 | + $this->name = get_bloginfo('name'); |
|
| 2119 | + $this->address_1 = '123 Onna Road'; |
|
| 2120 | + $this->address_2 = 'PO Box 123'; |
|
| 2121 | + $this->city = 'Inna City'; |
|
| 2122 | + $this->STA_ID = 4; |
|
| 2123 | + $this->CNT_ISO = 'US'; |
|
| 2124 | + $this->zip = '12345'; |
|
| 2125 | + $this->email = get_bloginfo('admin_email'); |
|
| 2126 | + $this->phone = ''; |
|
| 2127 | + $this->vat = '123456789'; |
|
| 2128 | + $this->logo_url = ''; |
|
| 2129 | + $this->facebook = ''; |
|
| 2130 | + $this->twitter = ''; |
|
| 2131 | + $this->linkedin = ''; |
|
| 2132 | + $this->pinterest = ''; |
|
| 2133 | + $this->google = ''; |
|
| 2134 | + $this->instagram = ''; |
|
| 2135 | + } |
|
| 2136 | 2136 | |
| 2137 | 2137 | } |
| 2138 | 2138 | |
@@ -2143,115 +2143,115 @@ discard block |
||
| 2143 | 2143 | class EE_Currency_Config extends EE_Config_Base |
| 2144 | 2144 | { |
| 2145 | 2145 | |
| 2146 | - /** |
|
| 2147 | - * @var string $code |
|
| 2148 | - * eg 'US' |
|
| 2149 | - */ |
|
| 2150 | - public $code; |
|
| 2151 | - |
|
| 2152 | - /** |
|
| 2153 | - * @var string $name |
|
| 2154 | - * eg 'Dollar' |
|
| 2155 | - */ |
|
| 2156 | - public $name; |
|
| 2157 | - |
|
| 2158 | - /** |
|
| 2159 | - * plural name |
|
| 2160 | - * |
|
| 2161 | - * @var string $plural |
|
| 2162 | - * eg 'Dollars' |
|
| 2163 | - */ |
|
| 2164 | - public $plural; |
|
| 2165 | - |
|
| 2166 | - /** |
|
| 2167 | - * currency sign |
|
| 2168 | - * |
|
| 2169 | - * @var string $sign |
|
| 2170 | - * eg '$' |
|
| 2171 | - */ |
|
| 2172 | - public $sign; |
|
| 2173 | - |
|
| 2174 | - /** |
|
| 2175 | - * Whether the currency sign should come before the number or not |
|
| 2176 | - * |
|
| 2177 | - * @var boolean $sign_b4 |
|
| 2178 | - */ |
|
| 2179 | - public $sign_b4; |
|
| 2180 | - |
|
| 2181 | - /** |
|
| 2182 | - * How many digits should come after the decimal place |
|
| 2183 | - * |
|
| 2184 | - * @var int $dec_plc |
|
| 2185 | - */ |
|
| 2186 | - public $dec_plc; |
|
| 2187 | - |
|
| 2188 | - /** |
|
| 2189 | - * Symbol to use for decimal mark |
|
| 2190 | - * |
|
| 2191 | - * @var string $dec_mrk |
|
| 2192 | - * eg '.' |
|
| 2193 | - */ |
|
| 2194 | - public $dec_mrk; |
|
| 2195 | - |
|
| 2196 | - /** |
|
| 2197 | - * Symbol to use for thousands |
|
| 2198 | - * |
|
| 2199 | - * @var string $thsnds |
|
| 2200 | - * eg ',' |
|
| 2201 | - */ |
|
| 2202 | - public $thsnds; |
|
| 2203 | - |
|
| 2204 | - |
|
| 2205 | - /** |
|
| 2206 | - * class constructor |
|
| 2207 | - * |
|
| 2208 | - * @access public |
|
| 2209 | - * @param string $CNT_ISO |
|
| 2210 | - * @throws \EE_Error |
|
| 2211 | - */ |
|
| 2212 | - public function __construct($CNT_ISO = '') |
|
| 2213 | - { |
|
| 2214 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2215 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2216 | - // get country code from organization settings or use default |
|
| 2217 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2218 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2219 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2220 | - : ''; |
|
| 2221 | - // but override if requested |
|
| 2222 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2223 | - // 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 |
|
| 2224 | - if ( |
|
| 2225 | - ! empty($CNT_ISO) |
|
| 2226 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2227 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2228 | - ) { |
|
| 2229 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2230 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2231 | - if ($country instanceof EE_Country) { |
|
| 2232 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2233 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2234 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2235 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2236 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2237 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2238 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2239 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2240 | - } |
|
| 2241 | - } |
|
| 2242 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2243 | - if (empty($this->code)) { |
|
| 2244 | - // set default currency settings |
|
| 2245 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2246 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2247 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2248 | - $this->sign = '$'; // currency sign: $ |
|
| 2249 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2250 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2251 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2252 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2253 | - } |
|
| 2254 | - } |
|
| 2146 | + /** |
|
| 2147 | + * @var string $code |
|
| 2148 | + * eg 'US' |
|
| 2149 | + */ |
|
| 2150 | + public $code; |
|
| 2151 | + |
|
| 2152 | + /** |
|
| 2153 | + * @var string $name |
|
| 2154 | + * eg 'Dollar' |
|
| 2155 | + */ |
|
| 2156 | + public $name; |
|
| 2157 | + |
|
| 2158 | + /** |
|
| 2159 | + * plural name |
|
| 2160 | + * |
|
| 2161 | + * @var string $plural |
|
| 2162 | + * eg 'Dollars' |
|
| 2163 | + */ |
|
| 2164 | + public $plural; |
|
| 2165 | + |
|
| 2166 | + /** |
|
| 2167 | + * currency sign |
|
| 2168 | + * |
|
| 2169 | + * @var string $sign |
|
| 2170 | + * eg '$' |
|
| 2171 | + */ |
|
| 2172 | + public $sign; |
|
| 2173 | + |
|
| 2174 | + /** |
|
| 2175 | + * Whether the currency sign should come before the number or not |
|
| 2176 | + * |
|
| 2177 | + * @var boolean $sign_b4 |
|
| 2178 | + */ |
|
| 2179 | + public $sign_b4; |
|
| 2180 | + |
|
| 2181 | + /** |
|
| 2182 | + * How many digits should come after the decimal place |
|
| 2183 | + * |
|
| 2184 | + * @var int $dec_plc |
|
| 2185 | + */ |
|
| 2186 | + public $dec_plc; |
|
| 2187 | + |
|
| 2188 | + /** |
|
| 2189 | + * Symbol to use for decimal mark |
|
| 2190 | + * |
|
| 2191 | + * @var string $dec_mrk |
|
| 2192 | + * eg '.' |
|
| 2193 | + */ |
|
| 2194 | + public $dec_mrk; |
|
| 2195 | + |
|
| 2196 | + /** |
|
| 2197 | + * Symbol to use for thousands |
|
| 2198 | + * |
|
| 2199 | + * @var string $thsnds |
|
| 2200 | + * eg ',' |
|
| 2201 | + */ |
|
| 2202 | + public $thsnds; |
|
| 2203 | + |
|
| 2204 | + |
|
| 2205 | + /** |
|
| 2206 | + * class constructor |
|
| 2207 | + * |
|
| 2208 | + * @access public |
|
| 2209 | + * @param string $CNT_ISO |
|
| 2210 | + * @throws \EE_Error |
|
| 2211 | + */ |
|
| 2212 | + public function __construct($CNT_ISO = '') |
|
| 2213 | + { |
|
| 2214 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2215 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2216 | + // get country code from organization settings or use default |
|
| 2217 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2218 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2219 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2220 | + : ''; |
|
| 2221 | + // but override if requested |
|
| 2222 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2223 | + // 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 |
|
| 2224 | + if ( |
|
| 2225 | + ! empty($CNT_ISO) |
|
| 2226 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2227 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2228 | + ) { |
|
| 2229 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2230 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2231 | + if ($country instanceof EE_Country) { |
|
| 2232 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2233 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2234 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2235 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2236 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2237 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2238 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2239 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2240 | + } |
|
| 2241 | + } |
|
| 2242 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2243 | + if (empty($this->code)) { |
|
| 2244 | + // set default currency settings |
|
| 2245 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2246 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2247 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2248 | + $this->sign = '$'; // currency sign: $ |
|
| 2249 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2250 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2251 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2252 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2253 | + } |
|
| 2254 | + } |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | |
@@ -2261,195 +2261,195 @@ discard block |
||
| 2261 | 2261 | class EE_Registration_Config extends EE_Config_Base |
| 2262 | 2262 | { |
| 2263 | 2263 | |
| 2264 | - /** |
|
| 2265 | - * Default registration status |
|
| 2266 | - * |
|
| 2267 | - * @var string $default_STS_ID |
|
| 2268 | - * eg 'RPP' |
|
| 2269 | - */ |
|
| 2270 | - public $default_STS_ID; |
|
| 2271 | - |
|
| 2272 | - /** |
|
| 2273 | - * level of validation to apply to email addresses |
|
| 2274 | - * |
|
| 2275 | - * @var string $email_validation_level |
|
| 2276 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2277 | - */ |
|
| 2278 | - public $email_validation_level; |
|
| 2279 | - |
|
| 2280 | - /** |
|
| 2281 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2282 | - * |
|
| 2283 | - * @var boolean $show_pending_payment_options |
|
| 2284 | - */ |
|
| 2285 | - public $show_pending_payment_options; |
|
| 2286 | - |
|
| 2287 | - /** |
|
| 2288 | - * Whether to skip the registration confirmation page |
|
| 2289 | - * |
|
| 2290 | - * @var boolean $skip_reg_confirmation |
|
| 2291 | - */ |
|
| 2292 | - public $skip_reg_confirmation; |
|
| 2293 | - |
|
| 2294 | - /** |
|
| 2295 | - * an array of SPCO reg steps where: |
|
| 2296 | - * the keys denotes the reg step order |
|
| 2297 | - * each element consists of an array with the following elements: |
|
| 2298 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2299 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2300 | - * "slug" => the URL param used to trigger the reg step |
|
| 2301 | - * |
|
| 2302 | - * @var array $reg_steps |
|
| 2303 | - */ |
|
| 2304 | - public $reg_steps; |
|
| 2305 | - |
|
| 2306 | - /** |
|
| 2307 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2308 | - * |
|
| 2309 | - * @var boolean $reg_confirmation_last |
|
| 2310 | - */ |
|
| 2311 | - public $reg_confirmation_last; |
|
| 2312 | - |
|
| 2313 | - /** |
|
| 2314 | - * Whether or not to enable the EE Bot Trap |
|
| 2315 | - * |
|
| 2316 | - * @var boolean $use_bot_trap |
|
| 2317 | - */ |
|
| 2318 | - public $use_bot_trap; |
|
| 2319 | - |
|
| 2320 | - /** |
|
| 2321 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2322 | - * |
|
| 2323 | - * @var boolean $use_encryption |
|
| 2324 | - */ |
|
| 2325 | - public $use_encryption; |
|
| 2326 | - |
|
| 2327 | - /** |
|
| 2328 | - * Whether or not to use ReCaptcha |
|
| 2329 | - * |
|
| 2330 | - * @var boolean $use_captcha |
|
| 2331 | - */ |
|
| 2332 | - public $use_captcha; |
|
| 2333 | - |
|
| 2334 | - /** |
|
| 2335 | - * ReCaptcha Theme |
|
| 2336 | - * |
|
| 2337 | - * @var string $recaptcha_theme |
|
| 2338 | - * options: 'dark ', 'light' |
|
| 2339 | - */ |
|
| 2340 | - public $recaptcha_theme; |
|
| 2341 | - |
|
| 2342 | - /** |
|
| 2343 | - * ReCaptcha Type |
|
| 2344 | - * |
|
| 2345 | - * @var string $recaptcha_type |
|
| 2346 | - * options: 'audio', 'image' |
|
| 2347 | - */ |
|
| 2348 | - public $recaptcha_type; |
|
| 2349 | - |
|
| 2350 | - /** |
|
| 2351 | - * ReCaptcha language |
|
| 2352 | - * |
|
| 2353 | - * @var string $recaptcha_language |
|
| 2354 | - * eg 'en' |
|
| 2355 | - */ |
|
| 2356 | - public $recaptcha_language; |
|
| 2357 | - |
|
| 2358 | - /** |
|
| 2359 | - * ReCaptcha public key |
|
| 2360 | - * |
|
| 2361 | - * @var string $recaptcha_publickey |
|
| 2362 | - */ |
|
| 2363 | - public $recaptcha_publickey; |
|
| 2364 | - |
|
| 2365 | - /** |
|
| 2366 | - * ReCaptcha private key |
|
| 2367 | - * |
|
| 2368 | - * @var string $recaptcha_privatekey |
|
| 2369 | - */ |
|
| 2370 | - public $recaptcha_privatekey; |
|
| 2371 | - |
|
| 2372 | - /** |
|
| 2373 | - * ReCaptcha width |
|
| 2374 | - * |
|
| 2375 | - * @var int $recaptcha_width |
|
| 2376 | - * @deprecated |
|
| 2377 | - */ |
|
| 2378 | - public $recaptcha_width; |
|
| 2379 | - |
|
| 2380 | - /** |
|
| 2381 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2382 | - * |
|
| 2383 | - * @var boolean $track_invalid_checkout_access |
|
| 2384 | - */ |
|
| 2385 | - protected $track_invalid_checkout_access = true; |
|
| 2386 | - |
|
| 2387 | - |
|
| 2388 | - /** |
|
| 2389 | - * class constructor |
|
| 2390 | - * |
|
| 2391 | - * @access public |
|
| 2392 | - */ |
|
| 2393 | - public function __construct() |
|
| 2394 | - { |
|
| 2395 | - // set default registration settings |
|
| 2396 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2397 | - $this->email_validation_level = 'wp_default'; |
|
| 2398 | - $this->show_pending_payment_options = true; |
|
| 2399 | - $this->skip_reg_confirmation = false; |
|
| 2400 | - $this->reg_steps = array(); |
|
| 2401 | - $this->reg_confirmation_last = false; |
|
| 2402 | - $this->use_bot_trap = true; |
|
| 2403 | - $this->use_encryption = true; |
|
| 2404 | - $this->use_captcha = false; |
|
| 2405 | - $this->recaptcha_theme = 'light'; |
|
| 2406 | - $this->recaptcha_type = 'image'; |
|
| 2407 | - $this->recaptcha_language = 'en'; |
|
| 2408 | - $this->recaptcha_publickey = null; |
|
| 2409 | - $this->recaptcha_privatekey = null; |
|
| 2410 | - $this->recaptcha_width = 500; |
|
| 2411 | - } |
|
| 2412 | - |
|
| 2413 | - |
|
| 2414 | - /** |
|
| 2415 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2416 | - * |
|
| 2417 | - * @since 4.8.8.rc.019 |
|
| 2418 | - */ |
|
| 2419 | - public function do_hooks() |
|
| 2420 | - { |
|
| 2421 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2422 | - } |
|
| 2423 | - |
|
| 2424 | - |
|
| 2425 | - /** |
|
| 2426 | - * @return void |
|
| 2427 | - */ |
|
| 2428 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2429 | - { |
|
| 2430 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2431 | - } |
|
| 2432 | - |
|
| 2433 | - |
|
| 2434 | - /** |
|
| 2435 | - * @return boolean |
|
| 2436 | - */ |
|
| 2437 | - public function track_invalid_checkout_access() |
|
| 2438 | - { |
|
| 2439 | - return $this->track_invalid_checkout_access; |
|
| 2440 | - } |
|
| 2441 | - |
|
| 2442 | - |
|
| 2443 | - /** |
|
| 2444 | - * @param boolean $track_invalid_checkout_access |
|
| 2445 | - */ |
|
| 2446 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2447 | - { |
|
| 2448 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2449 | - $track_invalid_checkout_access, |
|
| 2450 | - FILTER_VALIDATE_BOOLEAN |
|
| 2451 | - ); |
|
| 2452 | - } |
|
| 2264 | + /** |
|
| 2265 | + * Default registration status |
|
| 2266 | + * |
|
| 2267 | + * @var string $default_STS_ID |
|
| 2268 | + * eg 'RPP' |
|
| 2269 | + */ |
|
| 2270 | + public $default_STS_ID; |
|
| 2271 | + |
|
| 2272 | + /** |
|
| 2273 | + * level of validation to apply to email addresses |
|
| 2274 | + * |
|
| 2275 | + * @var string $email_validation_level |
|
| 2276 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2277 | + */ |
|
| 2278 | + public $email_validation_level; |
|
| 2279 | + |
|
| 2280 | + /** |
|
| 2281 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2282 | + * |
|
| 2283 | + * @var boolean $show_pending_payment_options |
|
| 2284 | + */ |
|
| 2285 | + public $show_pending_payment_options; |
|
| 2286 | + |
|
| 2287 | + /** |
|
| 2288 | + * Whether to skip the registration confirmation page |
|
| 2289 | + * |
|
| 2290 | + * @var boolean $skip_reg_confirmation |
|
| 2291 | + */ |
|
| 2292 | + public $skip_reg_confirmation; |
|
| 2293 | + |
|
| 2294 | + /** |
|
| 2295 | + * an array of SPCO reg steps where: |
|
| 2296 | + * the keys denotes the reg step order |
|
| 2297 | + * each element consists of an array with the following elements: |
|
| 2298 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2299 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2300 | + * "slug" => the URL param used to trigger the reg step |
|
| 2301 | + * |
|
| 2302 | + * @var array $reg_steps |
|
| 2303 | + */ |
|
| 2304 | + public $reg_steps; |
|
| 2305 | + |
|
| 2306 | + /** |
|
| 2307 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2308 | + * |
|
| 2309 | + * @var boolean $reg_confirmation_last |
|
| 2310 | + */ |
|
| 2311 | + public $reg_confirmation_last; |
|
| 2312 | + |
|
| 2313 | + /** |
|
| 2314 | + * Whether or not to enable the EE Bot Trap |
|
| 2315 | + * |
|
| 2316 | + * @var boolean $use_bot_trap |
|
| 2317 | + */ |
|
| 2318 | + public $use_bot_trap; |
|
| 2319 | + |
|
| 2320 | + /** |
|
| 2321 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2322 | + * |
|
| 2323 | + * @var boolean $use_encryption |
|
| 2324 | + */ |
|
| 2325 | + public $use_encryption; |
|
| 2326 | + |
|
| 2327 | + /** |
|
| 2328 | + * Whether or not to use ReCaptcha |
|
| 2329 | + * |
|
| 2330 | + * @var boolean $use_captcha |
|
| 2331 | + */ |
|
| 2332 | + public $use_captcha; |
|
| 2333 | + |
|
| 2334 | + /** |
|
| 2335 | + * ReCaptcha Theme |
|
| 2336 | + * |
|
| 2337 | + * @var string $recaptcha_theme |
|
| 2338 | + * options: 'dark ', 'light' |
|
| 2339 | + */ |
|
| 2340 | + public $recaptcha_theme; |
|
| 2341 | + |
|
| 2342 | + /** |
|
| 2343 | + * ReCaptcha Type |
|
| 2344 | + * |
|
| 2345 | + * @var string $recaptcha_type |
|
| 2346 | + * options: 'audio', 'image' |
|
| 2347 | + */ |
|
| 2348 | + public $recaptcha_type; |
|
| 2349 | + |
|
| 2350 | + /** |
|
| 2351 | + * ReCaptcha language |
|
| 2352 | + * |
|
| 2353 | + * @var string $recaptcha_language |
|
| 2354 | + * eg 'en' |
|
| 2355 | + */ |
|
| 2356 | + public $recaptcha_language; |
|
| 2357 | + |
|
| 2358 | + /** |
|
| 2359 | + * ReCaptcha public key |
|
| 2360 | + * |
|
| 2361 | + * @var string $recaptcha_publickey |
|
| 2362 | + */ |
|
| 2363 | + public $recaptcha_publickey; |
|
| 2364 | + |
|
| 2365 | + /** |
|
| 2366 | + * ReCaptcha private key |
|
| 2367 | + * |
|
| 2368 | + * @var string $recaptcha_privatekey |
|
| 2369 | + */ |
|
| 2370 | + public $recaptcha_privatekey; |
|
| 2371 | + |
|
| 2372 | + /** |
|
| 2373 | + * ReCaptcha width |
|
| 2374 | + * |
|
| 2375 | + * @var int $recaptcha_width |
|
| 2376 | + * @deprecated |
|
| 2377 | + */ |
|
| 2378 | + public $recaptcha_width; |
|
| 2379 | + |
|
| 2380 | + /** |
|
| 2381 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2382 | + * |
|
| 2383 | + * @var boolean $track_invalid_checkout_access |
|
| 2384 | + */ |
|
| 2385 | + protected $track_invalid_checkout_access = true; |
|
| 2386 | + |
|
| 2387 | + |
|
| 2388 | + /** |
|
| 2389 | + * class constructor |
|
| 2390 | + * |
|
| 2391 | + * @access public |
|
| 2392 | + */ |
|
| 2393 | + public function __construct() |
|
| 2394 | + { |
|
| 2395 | + // set default registration settings |
|
| 2396 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2397 | + $this->email_validation_level = 'wp_default'; |
|
| 2398 | + $this->show_pending_payment_options = true; |
|
| 2399 | + $this->skip_reg_confirmation = false; |
|
| 2400 | + $this->reg_steps = array(); |
|
| 2401 | + $this->reg_confirmation_last = false; |
|
| 2402 | + $this->use_bot_trap = true; |
|
| 2403 | + $this->use_encryption = true; |
|
| 2404 | + $this->use_captcha = false; |
|
| 2405 | + $this->recaptcha_theme = 'light'; |
|
| 2406 | + $this->recaptcha_type = 'image'; |
|
| 2407 | + $this->recaptcha_language = 'en'; |
|
| 2408 | + $this->recaptcha_publickey = null; |
|
| 2409 | + $this->recaptcha_privatekey = null; |
|
| 2410 | + $this->recaptcha_width = 500; |
|
| 2411 | + } |
|
| 2412 | + |
|
| 2413 | + |
|
| 2414 | + /** |
|
| 2415 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2416 | + * |
|
| 2417 | + * @since 4.8.8.rc.019 |
|
| 2418 | + */ |
|
| 2419 | + public function do_hooks() |
|
| 2420 | + { |
|
| 2421 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2422 | + } |
|
| 2423 | + |
|
| 2424 | + |
|
| 2425 | + /** |
|
| 2426 | + * @return void |
|
| 2427 | + */ |
|
| 2428 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2429 | + { |
|
| 2430 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2431 | + } |
|
| 2432 | + |
|
| 2433 | + |
|
| 2434 | + /** |
|
| 2435 | + * @return boolean |
|
| 2436 | + */ |
|
| 2437 | + public function track_invalid_checkout_access() |
|
| 2438 | + { |
|
| 2439 | + return $this->track_invalid_checkout_access; |
|
| 2440 | + } |
|
| 2441 | + |
|
| 2442 | + |
|
| 2443 | + /** |
|
| 2444 | + * @param boolean $track_invalid_checkout_access |
|
| 2445 | + */ |
|
| 2446 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2447 | + { |
|
| 2448 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2449 | + $track_invalid_checkout_access, |
|
| 2450 | + FILTER_VALIDATE_BOOLEAN |
|
| 2451 | + ); |
|
| 2452 | + } |
|
| 2453 | 2453 | |
| 2454 | 2454 | |
| 2455 | 2455 | } |
@@ -2461,154 +2461,154 @@ discard block |
||
| 2461 | 2461 | class EE_Admin_Config extends EE_Config_Base |
| 2462 | 2462 | { |
| 2463 | 2463 | |
| 2464 | - /** |
|
| 2465 | - * @var boolean $use_personnel_manager |
|
| 2466 | - */ |
|
| 2467 | - public $use_personnel_manager; |
|
| 2468 | - |
|
| 2469 | - /** |
|
| 2470 | - * @var boolean $use_dashboard_widget |
|
| 2471 | - */ |
|
| 2472 | - public $use_dashboard_widget; |
|
| 2473 | - |
|
| 2474 | - /** |
|
| 2475 | - * @var int $events_in_dashboard |
|
| 2476 | - */ |
|
| 2477 | - public $events_in_dashboard; |
|
| 2478 | - |
|
| 2479 | - /** |
|
| 2480 | - * @var boolean $use_event_timezones |
|
| 2481 | - */ |
|
| 2482 | - public $use_event_timezones; |
|
| 2483 | - |
|
| 2484 | - /** |
|
| 2485 | - * @var boolean $use_full_logging |
|
| 2486 | - */ |
|
| 2487 | - public $use_full_logging; |
|
| 2488 | - |
|
| 2489 | - /** |
|
| 2490 | - * @var string $log_file_name |
|
| 2491 | - */ |
|
| 2492 | - public $log_file_name; |
|
| 2493 | - |
|
| 2494 | - /** |
|
| 2495 | - * @var string $debug_file_name |
|
| 2496 | - */ |
|
| 2497 | - public $debug_file_name; |
|
| 2498 | - |
|
| 2499 | - /** |
|
| 2500 | - * @var boolean $use_remote_logging |
|
| 2501 | - */ |
|
| 2502 | - public $use_remote_logging; |
|
| 2503 | - |
|
| 2504 | - /** |
|
| 2505 | - * @var string $remote_logging_url |
|
| 2506 | - */ |
|
| 2507 | - public $remote_logging_url; |
|
| 2508 | - |
|
| 2509 | - /** |
|
| 2510 | - * @var boolean $show_reg_footer |
|
| 2511 | - */ |
|
| 2512 | - public $show_reg_footer; |
|
| 2513 | - |
|
| 2514 | - /** |
|
| 2515 | - * @var string $affiliate_id |
|
| 2516 | - */ |
|
| 2517 | - public $affiliate_id; |
|
| 2518 | - |
|
| 2519 | - /** |
|
| 2520 | - * help tours on or off (global setting) |
|
| 2521 | - * |
|
| 2522 | - * @var boolean |
|
| 2523 | - */ |
|
| 2524 | - public $help_tour_activation; |
|
| 2525 | - |
|
| 2526 | - /** |
|
| 2527 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2528 | - * but is incompatible with some server configuration errors |
|
| 2529 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2530 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2531 | - * |
|
| 2532 | - * @var boolean $encode_session_data |
|
| 2533 | - */ |
|
| 2534 | - private $encode_session_data = false; |
|
| 2535 | - |
|
| 2536 | - |
|
| 2537 | - /** |
|
| 2538 | - * class constructor |
|
| 2539 | - * |
|
| 2540 | - * @access public |
|
| 2541 | - */ |
|
| 2542 | - public function __construct() |
|
| 2543 | - { |
|
| 2544 | - // set default general admin settings |
|
| 2545 | - $this->use_personnel_manager = true; |
|
| 2546 | - $this->use_dashboard_widget = true; |
|
| 2547 | - $this->events_in_dashboard = 30; |
|
| 2548 | - $this->use_event_timezones = false; |
|
| 2549 | - $this->use_full_logging = false; |
|
| 2550 | - $this->use_remote_logging = false; |
|
| 2551 | - $this->remote_logging_url = null; |
|
| 2552 | - $this->show_reg_footer = true; |
|
| 2553 | - $this->affiliate_id = 'default'; |
|
| 2554 | - $this->help_tour_activation = true; |
|
| 2555 | - $this->encode_session_data = false; |
|
| 2556 | - } |
|
| 2557 | - |
|
| 2558 | - |
|
| 2559 | - /** |
|
| 2560 | - * @param bool $reset |
|
| 2561 | - * @return string |
|
| 2562 | - */ |
|
| 2563 | - public function log_file_name($reset = false) |
|
| 2564 | - { |
|
| 2565 | - if (empty($this->log_file_name) || $reset) { |
|
| 2566 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2567 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2568 | - } |
|
| 2569 | - return $this->log_file_name; |
|
| 2570 | - } |
|
| 2571 | - |
|
| 2572 | - |
|
| 2573 | - /** |
|
| 2574 | - * @param bool $reset |
|
| 2575 | - * @return string |
|
| 2576 | - */ |
|
| 2577 | - public function debug_file_name($reset = false) |
|
| 2578 | - { |
|
| 2579 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2580 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2581 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2582 | - } |
|
| 2583 | - return $this->debug_file_name; |
|
| 2584 | - } |
|
| 2585 | - |
|
| 2586 | - |
|
| 2587 | - /** |
|
| 2588 | - * @return string |
|
| 2589 | - */ |
|
| 2590 | - public function affiliate_id() |
|
| 2591 | - { |
|
| 2592 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - |
|
| 2596 | - /** |
|
| 2597 | - * @return boolean |
|
| 2598 | - */ |
|
| 2599 | - public function encode_session_data() |
|
| 2600 | - { |
|
| 2601 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2602 | - } |
|
| 2603 | - |
|
| 2604 | - |
|
| 2605 | - /** |
|
| 2606 | - * @param boolean $encode_session_data |
|
| 2607 | - */ |
|
| 2608 | - public function set_encode_session_data($encode_session_data) |
|
| 2609 | - { |
|
| 2610 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2611 | - } |
|
| 2464 | + /** |
|
| 2465 | + * @var boolean $use_personnel_manager |
|
| 2466 | + */ |
|
| 2467 | + public $use_personnel_manager; |
|
| 2468 | + |
|
| 2469 | + /** |
|
| 2470 | + * @var boolean $use_dashboard_widget |
|
| 2471 | + */ |
|
| 2472 | + public $use_dashboard_widget; |
|
| 2473 | + |
|
| 2474 | + /** |
|
| 2475 | + * @var int $events_in_dashboard |
|
| 2476 | + */ |
|
| 2477 | + public $events_in_dashboard; |
|
| 2478 | + |
|
| 2479 | + /** |
|
| 2480 | + * @var boolean $use_event_timezones |
|
| 2481 | + */ |
|
| 2482 | + public $use_event_timezones; |
|
| 2483 | + |
|
| 2484 | + /** |
|
| 2485 | + * @var boolean $use_full_logging |
|
| 2486 | + */ |
|
| 2487 | + public $use_full_logging; |
|
| 2488 | + |
|
| 2489 | + /** |
|
| 2490 | + * @var string $log_file_name |
|
| 2491 | + */ |
|
| 2492 | + public $log_file_name; |
|
| 2493 | + |
|
| 2494 | + /** |
|
| 2495 | + * @var string $debug_file_name |
|
| 2496 | + */ |
|
| 2497 | + public $debug_file_name; |
|
| 2498 | + |
|
| 2499 | + /** |
|
| 2500 | + * @var boolean $use_remote_logging |
|
| 2501 | + */ |
|
| 2502 | + public $use_remote_logging; |
|
| 2503 | + |
|
| 2504 | + /** |
|
| 2505 | + * @var string $remote_logging_url |
|
| 2506 | + */ |
|
| 2507 | + public $remote_logging_url; |
|
| 2508 | + |
|
| 2509 | + /** |
|
| 2510 | + * @var boolean $show_reg_footer |
|
| 2511 | + */ |
|
| 2512 | + public $show_reg_footer; |
|
| 2513 | + |
|
| 2514 | + /** |
|
| 2515 | + * @var string $affiliate_id |
|
| 2516 | + */ |
|
| 2517 | + public $affiliate_id; |
|
| 2518 | + |
|
| 2519 | + /** |
|
| 2520 | + * help tours on or off (global setting) |
|
| 2521 | + * |
|
| 2522 | + * @var boolean |
|
| 2523 | + */ |
|
| 2524 | + public $help_tour_activation; |
|
| 2525 | + |
|
| 2526 | + /** |
|
| 2527 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2528 | + * but is incompatible with some server configuration errors |
|
| 2529 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2530 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2531 | + * |
|
| 2532 | + * @var boolean $encode_session_data |
|
| 2533 | + */ |
|
| 2534 | + private $encode_session_data = false; |
|
| 2535 | + |
|
| 2536 | + |
|
| 2537 | + /** |
|
| 2538 | + * class constructor |
|
| 2539 | + * |
|
| 2540 | + * @access public |
|
| 2541 | + */ |
|
| 2542 | + public function __construct() |
|
| 2543 | + { |
|
| 2544 | + // set default general admin settings |
|
| 2545 | + $this->use_personnel_manager = true; |
|
| 2546 | + $this->use_dashboard_widget = true; |
|
| 2547 | + $this->events_in_dashboard = 30; |
|
| 2548 | + $this->use_event_timezones = false; |
|
| 2549 | + $this->use_full_logging = false; |
|
| 2550 | + $this->use_remote_logging = false; |
|
| 2551 | + $this->remote_logging_url = null; |
|
| 2552 | + $this->show_reg_footer = true; |
|
| 2553 | + $this->affiliate_id = 'default'; |
|
| 2554 | + $this->help_tour_activation = true; |
|
| 2555 | + $this->encode_session_data = false; |
|
| 2556 | + } |
|
| 2557 | + |
|
| 2558 | + |
|
| 2559 | + /** |
|
| 2560 | + * @param bool $reset |
|
| 2561 | + * @return string |
|
| 2562 | + */ |
|
| 2563 | + public function log_file_name($reset = false) |
|
| 2564 | + { |
|
| 2565 | + if (empty($this->log_file_name) || $reset) { |
|
| 2566 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2567 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2568 | + } |
|
| 2569 | + return $this->log_file_name; |
|
| 2570 | + } |
|
| 2571 | + |
|
| 2572 | + |
|
| 2573 | + /** |
|
| 2574 | + * @param bool $reset |
|
| 2575 | + * @return string |
|
| 2576 | + */ |
|
| 2577 | + public function debug_file_name($reset = false) |
|
| 2578 | + { |
|
| 2579 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2580 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2581 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2582 | + } |
|
| 2583 | + return $this->debug_file_name; |
|
| 2584 | + } |
|
| 2585 | + |
|
| 2586 | + |
|
| 2587 | + /** |
|
| 2588 | + * @return string |
|
| 2589 | + */ |
|
| 2590 | + public function affiliate_id() |
|
| 2591 | + { |
|
| 2592 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + |
|
| 2596 | + /** |
|
| 2597 | + * @return boolean |
|
| 2598 | + */ |
|
| 2599 | + public function encode_session_data() |
|
| 2600 | + { |
|
| 2601 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2602 | + } |
|
| 2603 | + |
|
| 2604 | + |
|
| 2605 | + /** |
|
| 2606 | + * @param boolean $encode_session_data |
|
| 2607 | + */ |
|
| 2608 | + public function set_encode_session_data($encode_session_data) |
|
| 2609 | + { |
|
| 2610 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2611 | + } |
|
| 2612 | 2612 | |
| 2613 | 2613 | |
| 2614 | 2614 | } |
@@ -2620,70 +2620,70 @@ discard block |
||
| 2620 | 2620 | class EE_Template_Config extends EE_Config_Base |
| 2621 | 2621 | { |
| 2622 | 2622 | |
| 2623 | - /** |
|
| 2624 | - * @var boolean $enable_default_style |
|
| 2625 | - */ |
|
| 2626 | - public $enable_default_style; |
|
| 2627 | - |
|
| 2628 | - /** |
|
| 2629 | - * @var string $custom_style_sheet |
|
| 2630 | - */ |
|
| 2631 | - public $custom_style_sheet; |
|
| 2632 | - |
|
| 2633 | - /** |
|
| 2634 | - * @var boolean $display_address_in_regform |
|
| 2635 | - */ |
|
| 2636 | - public $display_address_in_regform; |
|
| 2637 | - |
|
| 2638 | - /** |
|
| 2639 | - * @var int $display_description_on_multi_reg_page |
|
| 2640 | - */ |
|
| 2641 | - public $display_description_on_multi_reg_page; |
|
| 2642 | - |
|
| 2643 | - /** |
|
| 2644 | - * @var boolean $use_custom_templates |
|
| 2645 | - */ |
|
| 2646 | - public $use_custom_templates; |
|
| 2647 | - |
|
| 2648 | - /** |
|
| 2649 | - * @var string $current_espresso_theme |
|
| 2650 | - */ |
|
| 2651 | - public $current_espresso_theme; |
|
| 2652 | - |
|
| 2653 | - /** |
|
| 2654 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2655 | - */ |
|
| 2656 | - public $EED_Ticket_Selector; |
|
| 2657 | - |
|
| 2658 | - /** |
|
| 2659 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2660 | - */ |
|
| 2661 | - public $EED_Event_Single; |
|
| 2662 | - |
|
| 2663 | - /** |
|
| 2664 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2665 | - */ |
|
| 2666 | - public $EED_Events_Archive; |
|
| 2667 | - |
|
| 2668 | - |
|
| 2669 | - /** |
|
| 2670 | - * class constructor |
|
| 2671 | - * |
|
| 2672 | - * @access public |
|
| 2673 | - */ |
|
| 2674 | - public function __construct() |
|
| 2675 | - { |
|
| 2676 | - // set default template settings |
|
| 2677 | - $this->enable_default_style = true; |
|
| 2678 | - $this->custom_style_sheet = null; |
|
| 2679 | - $this->display_address_in_regform = true; |
|
| 2680 | - $this->display_description_on_multi_reg_page = false; |
|
| 2681 | - $this->use_custom_templates = false; |
|
| 2682 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2683 | - $this->EED_Event_Single = null; |
|
| 2684 | - $this->EED_Events_Archive = null; |
|
| 2685 | - $this->EED_Ticket_Selector = null; |
|
| 2686 | - } |
|
| 2623 | + /** |
|
| 2624 | + * @var boolean $enable_default_style |
|
| 2625 | + */ |
|
| 2626 | + public $enable_default_style; |
|
| 2627 | + |
|
| 2628 | + /** |
|
| 2629 | + * @var string $custom_style_sheet |
|
| 2630 | + */ |
|
| 2631 | + public $custom_style_sheet; |
|
| 2632 | + |
|
| 2633 | + /** |
|
| 2634 | + * @var boolean $display_address_in_regform |
|
| 2635 | + */ |
|
| 2636 | + public $display_address_in_regform; |
|
| 2637 | + |
|
| 2638 | + /** |
|
| 2639 | + * @var int $display_description_on_multi_reg_page |
|
| 2640 | + */ |
|
| 2641 | + public $display_description_on_multi_reg_page; |
|
| 2642 | + |
|
| 2643 | + /** |
|
| 2644 | + * @var boolean $use_custom_templates |
|
| 2645 | + */ |
|
| 2646 | + public $use_custom_templates; |
|
| 2647 | + |
|
| 2648 | + /** |
|
| 2649 | + * @var string $current_espresso_theme |
|
| 2650 | + */ |
|
| 2651 | + public $current_espresso_theme; |
|
| 2652 | + |
|
| 2653 | + /** |
|
| 2654 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2655 | + */ |
|
| 2656 | + public $EED_Ticket_Selector; |
|
| 2657 | + |
|
| 2658 | + /** |
|
| 2659 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2660 | + */ |
|
| 2661 | + public $EED_Event_Single; |
|
| 2662 | + |
|
| 2663 | + /** |
|
| 2664 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2665 | + */ |
|
| 2666 | + public $EED_Events_Archive; |
|
| 2667 | + |
|
| 2668 | + |
|
| 2669 | + /** |
|
| 2670 | + * class constructor |
|
| 2671 | + * |
|
| 2672 | + * @access public |
|
| 2673 | + */ |
|
| 2674 | + public function __construct() |
|
| 2675 | + { |
|
| 2676 | + // set default template settings |
|
| 2677 | + $this->enable_default_style = true; |
|
| 2678 | + $this->custom_style_sheet = null; |
|
| 2679 | + $this->display_address_in_regform = true; |
|
| 2680 | + $this->display_description_on_multi_reg_page = false; |
|
| 2681 | + $this->use_custom_templates = false; |
|
| 2682 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2683 | + $this->EED_Event_Single = null; |
|
| 2684 | + $this->EED_Events_Archive = null; |
|
| 2685 | + $this->EED_Ticket_Selector = null; |
|
| 2686 | + } |
|
| 2687 | 2687 | |
| 2688 | 2688 | } |
| 2689 | 2689 | |
@@ -2694,114 +2694,114 @@ discard block |
||
| 2694 | 2694 | class EE_Map_Config extends EE_Config_Base |
| 2695 | 2695 | { |
| 2696 | 2696 | |
| 2697 | - /** |
|
| 2698 | - * @var boolean $use_google_maps |
|
| 2699 | - */ |
|
| 2700 | - public $use_google_maps; |
|
| 2701 | - |
|
| 2702 | - /** |
|
| 2703 | - * @var string $api_key |
|
| 2704 | - */ |
|
| 2705 | - public $google_map_api_key; |
|
| 2706 | - |
|
| 2707 | - /** |
|
| 2708 | - * @var int $event_details_map_width |
|
| 2709 | - */ |
|
| 2710 | - public $event_details_map_width; |
|
| 2711 | - |
|
| 2712 | - /** |
|
| 2713 | - * @var int $event_details_map_height |
|
| 2714 | - */ |
|
| 2715 | - public $event_details_map_height; |
|
| 2716 | - |
|
| 2717 | - /** |
|
| 2718 | - * @var int $event_details_map_zoom |
|
| 2719 | - */ |
|
| 2720 | - public $event_details_map_zoom; |
|
| 2721 | - |
|
| 2722 | - /** |
|
| 2723 | - * @var boolean $event_details_display_nav |
|
| 2724 | - */ |
|
| 2725 | - public $event_details_display_nav; |
|
| 2726 | - |
|
| 2727 | - /** |
|
| 2728 | - * @var boolean $event_details_nav_size |
|
| 2729 | - */ |
|
| 2730 | - public $event_details_nav_size; |
|
| 2731 | - |
|
| 2732 | - /** |
|
| 2733 | - * @var string $event_details_control_type |
|
| 2734 | - */ |
|
| 2735 | - public $event_details_control_type; |
|
| 2736 | - |
|
| 2737 | - /** |
|
| 2738 | - * @var string $event_details_map_align |
|
| 2739 | - */ |
|
| 2740 | - public $event_details_map_align; |
|
| 2741 | - |
|
| 2742 | - /** |
|
| 2743 | - * @var int $event_list_map_width |
|
| 2744 | - */ |
|
| 2745 | - public $event_list_map_width; |
|
| 2746 | - |
|
| 2747 | - /** |
|
| 2748 | - * @var int $event_list_map_height |
|
| 2749 | - */ |
|
| 2750 | - public $event_list_map_height; |
|
| 2751 | - |
|
| 2752 | - /** |
|
| 2753 | - * @var int $event_list_map_zoom |
|
| 2754 | - */ |
|
| 2755 | - public $event_list_map_zoom; |
|
| 2756 | - |
|
| 2757 | - /** |
|
| 2758 | - * @var boolean $event_list_display_nav |
|
| 2759 | - */ |
|
| 2760 | - public $event_list_display_nav; |
|
| 2761 | - |
|
| 2762 | - /** |
|
| 2763 | - * @var boolean $event_list_nav_size |
|
| 2764 | - */ |
|
| 2765 | - public $event_list_nav_size; |
|
| 2766 | - |
|
| 2767 | - /** |
|
| 2768 | - * @var string $event_list_control_type |
|
| 2769 | - */ |
|
| 2770 | - public $event_list_control_type; |
|
| 2771 | - |
|
| 2772 | - /** |
|
| 2773 | - * @var string $event_list_map_align |
|
| 2774 | - */ |
|
| 2775 | - public $event_list_map_align; |
|
| 2776 | - |
|
| 2777 | - |
|
| 2778 | - /** |
|
| 2779 | - * class constructor |
|
| 2780 | - * |
|
| 2781 | - * @access public |
|
| 2782 | - */ |
|
| 2783 | - public function __construct() |
|
| 2784 | - { |
|
| 2785 | - // set default map settings |
|
| 2786 | - $this->use_google_maps = true; |
|
| 2787 | - $this->google_map_api_key = ''; |
|
| 2788 | - // for event details pages (reg page) |
|
| 2789 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2790 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2791 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2792 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2793 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2794 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2795 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2796 | - // for event list pages |
|
| 2797 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2798 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2799 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2800 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2801 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2802 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2803 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2804 | - } |
|
| 2697 | + /** |
|
| 2698 | + * @var boolean $use_google_maps |
|
| 2699 | + */ |
|
| 2700 | + public $use_google_maps; |
|
| 2701 | + |
|
| 2702 | + /** |
|
| 2703 | + * @var string $api_key |
|
| 2704 | + */ |
|
| 2705 | + public $google_map_api_key; |
|
| 2706 | + |
|
| 2707 | + /** |
|
| 2708 | + * @var int $event_details_map_width |
|
| 2709 | + */ |
|
| 2710 | + public $event_details_map_width; |
|
| 2711 | + |
|
| 2712 | + /** |
|
| 2713 | + * @var int $event_details_map_height |
|
| 2714 | + */ |
|
| 2715 | + public $event_details_map_height; |
|
| 2716 | + |
|
| 2717 | + /** |
|
| 2718 | + * @var int $event_details_map_zoom |
|
| 2719 | + */ |
|
| 2720 | + public $event_details_map_zoom; |
|
| 2721 | + |
|
| 2722 | + /** |
|
| 2723 | + * @var boolean $event_details_display_nav |
|
| 2724 | + */ |
|
| 2725 | + public $event_details_display_nav; |
|
| 2726 | + |
|
| 2727 | + /** |
|
| 2728 | + * @var boolean $event_details_nav_size |
|
| 2729 | + */ |
|
| 2730 | + public $event_details_nav_size; |
|
| 2731 | + |
|
| 2732 | + /** |
|
| 2733 | + * @var string $event_details_control_type |
|
| 2734 | + */ |
|
| 2735 | + public $event_details_control_type; |
|
| 2736 | + |
|
| 2737 | + /** |
|
| 2738 | + * @var string $event_details_map_align |
|
| 2739 | + */ |
|
| 2740 | + public $event_details_map_align; |
|
| 2741 | + |
|
| 2742 | + /** |
|
| 2743 | + * @var int $event_list_map_width |
|
| 2744 | + */ |
|
| 2745 | + public $event_list_map_width; |
|
| 2746 | + |
|
| 2747 | + /** |
|
| 2748 | + * @var int $event_list_map_height |
|
| 2749 | + */ |
|
| 2750 | + public $event_list_map_height; |
|
| 2751 | + |
|
| 2752 | + /** |
|
| 2753 | + * @var int $event_list_map_zoom |
|
| 2754 | + */ |
|
| 2755 | + public $event_list_map_zoom; |
|
| 2756 | + |
|
| 2757 | + /** |
|
| 2758 | + * @var boolean $event_list_display_nav |
|
| 2759 | + */ |
|
| 2760 | + public $event_list_display_nav; |
|
| 2761 | + |
|
| 2762 | + /** |
|
| 2763 | + * @var boolean $event_list_nav_size |
|
| 2764 | + */ |
|
| 2765 | + public $event_list_nav_size; |
|
| 2766 | + |
|
| 2767 | + /** |
|
| 2768 | + * @var string $event_list_control_type |
|
| 2769 | + */ |
|
| 2770 | + public $event_list_control_type; |
|
| 2771 | + |
|
| 2772 | + /** |
|
| 2773 | + * @var string $event_list_map_align |
|
| 2774 | + */ |
|
| 2775 | + public $event_list_map_align; |
|
| 2776 | + |
|
| 2777 | + |
|
| 2778 | + /** |
|
| 2779 | + * class constructor |
|
| 2780 | + * |
|
| 2781 | + * @access public |
|
| 2782 | + */ |
|
| 2783 | + public function __construct() |
|
| 2784 | + { |
|
| 2785 | + // set default map settings |
|
| 2786 | + $this->use_google_maps = true; |
|
| 2787 | + $this->google_map_api_key = ''; |
|
| 2788 | + // for event details pages (reg page) |
|
| 2789 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2790 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2791 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2792 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2793 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2794 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2795 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2796 | + // for event list pages |
|
| 2797 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2798 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2799 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2800 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2801 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2802 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2803 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2804 | + } |
|
| 2805 | 2805 | |
| 2806 | 2806 | } |
| 2807 | 2807 | |
@@ -2812,46 +2812,46 @@ discard block |
||
| 2812 | 2812 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2813 | 2813 | { |
| 2814 | 2814 | |
| 2815 | - public $display_status_banner; |
|
| 2815 | + public $display_status_banner; |
|
| 2816 | 2816 | |
| 2817 | - public $display_description; |
|
| 2817 | + public $display_description; |
|
| 2818 | 2818 | |
| 2819 | - public $display_ticket_selector; |
|
| 2819 | + public $display_ticket_selector; |
|
| 2820 | 2820 | |
| 2821 | - public $display_datetimes; |
|
| 2821 | + public $display_datetimes; |
|
| 2822 | 2822 | |
| 2823 | - public $display_venue; |
|
| 2823 | + public $display_venue; |
|
| 2824 | 2824 | |
| 2825 | - public $display_expired_events; |
|
| 2825 | + public $display_expired_events; |
|
| 2826 | 2826 | |
| 2827 | - public $use_sortable_display_order; |
|
| 2827 | + public $use_sortable_display_order; |
|
| 2828 | 2828 | |
| 2829 | - public $display_order_tickets; |
|
| 2829 | + public $display_order_tickets; |
|
| 2830 | 2830 | |
| 2831 | - public $display_order_datetimes; |
|
| 2831 | + public $display_order_datetimes; |
|
| 2832 | 2832 | |
| 2833 | - public $display_order_event; |
|
| 2833 | + public $display_order_event; |
|
| 2834 | 2834 | |
| 2835 | - public $display_order_venue; |
|
| 2835 | + public $display_order_venue; |
|
| 2836 | 2836 | |
| 2837 | 2837 | |
| 2838 | - /** |
|
| 2839 | - * class constructor |
|
| 2840 | - */ |
|
| 2841 | - public function __construct() |
|
| 2842 | - { |
|
| 2843 | - $this->display_status_banner = 0; |
|
| 2844 | - $this->display_description = 1; |
|
| 2845 | - $this->display_ticket_selector = 0; |
|
| 2846 | - $this->display_datetimes = 1; |
|
| 2847 | - $this->display_venue = 0; |
|
| 2848 | - $this->display_expired_events = 0; |
|
| 2849 | - $this->use_sortable_display_order = false; |
|
| 2850 | - $this->display_order_tickets = 100; |
|
| 2851 | - $this->display_order_datetimes = 110; |
|
| 2852 | - $this->display_order_event = 120; |
|
| 2853 | - $this->display_order_venue = 130; |
|
| 2854 | - } |
|
| 2838 | + /** |
|
| 2839 | + * class constructor |
|
| 2840 | + */ |
|
| 2841 | + public function __construct() |
|
| 2842 | + { |
|
| 2843 | + $this->display_status_banner = 0; |
|
| 2844 | + $this->display_description = 1; |
|
| 2845 | + $this->display_ticket_selector = 0; |
|
| 2846 | + $this->display_datetimes = 1; |
|
| 2847 | + $this->display_venue = 0; |
|
| 2848 | + $this->display_expired_events = 0; |
|
| 2849 | + $this->use_sortable_display_order = false; |
|
| 2850 | + $this->display_order_tickets = 100; |
|
| 2851 | + $this->display_order_datetimes = 110; |
|
| 2852 | + $this->display_order_event = 120; |
|
| 2853 | + $this->display_order_venue = 130; |
|
| 2854 | + } |
|
| 2855 | 2855 | } |
| 2856 | 2856 | |
| 2857 | 2857 | |
@@ -2861,34 +2861,34 @@ discard block |
||
| 2861 | 2861 | class EE_Event_Single_Config extends EE_Config_Base |
| 2862 | 2862 | { |
| 2863 | 2863 | |
| 2864 | - public $display_status_banner_single; |
|
| 2864 | + public $display_status_banner_single; |
|
| 2865 | 2865 | |
| 2866 | - public $display_venue; |
|
| 2866 | + public $display_venue; |
|
| 2867 | 2867 | |
| 2868 | - public $use_sortable_display_order; |
|
| 2868 | + public $use_sortable_display_order; |
|
| 2869 | 2869 | |
| 2870 | - public $display_order_tickets; |
|
| 2870 | + public $display_order_tickets; |
|
| 2871 | 2871 | |
| 2872 | - public $display_order_datetimes; |
|
| 2872 | + public $display_order_datetimes; |
|
| 2873 | 2873 | |
| 2874 | - public $display_order_event; |
|
| 2874 | + public $display_order_event; |
|
| 2875 | 2875 | |
| 2876 | - public $display_order_venue; |
|
| 2876 | + public $display_order_venue; |
|
| 2877 | 2877 | |
| 2878 | 2878 | |
| 2879 | - /** |
|
| 2880 | - * class constructor |
|
| 2881 | - */ |
|
| 2882 | - public function __construct() |
|
| 2883 | - { |
|
| 2884 | - $this->display_status_banner_single = 0; |
|
| 2885 | - $this->display_venue = 1; |
|
| 2886 | - $this->use_sortable_display_order = false; |
|
| 2887 | - $this->display_order_tickets = 100; |
|
| 2888 | - $this->display_order_datetimes = 110; |
|
| 2889 | - $this->display_order_event = 120; |
|
| 2890 | - $this->display_order_venue = 130; |
|
| 2891 | - } |
|
| 2879 | + /** |
|
| 2880 | + * class constructor |
|
| 2881 | + */ |
|
| 2882 | + public function __construct() |
|
| 2883 | + { |
|
| 2884 | + $this->display_status_banner_single = 0; |
|
| 2885 | + $this->display_venue = 1; |
|
| 2886 | + $this->use_sortable_display_order = false; |
|
| 2887 | + $this->display_order_tickets = 100; |
|
| 2888 | + $this->display_order_datetimes = 110; |
|
| 2889 | + $this->display_order_event = 120; |
|
| 2890 | + $this->display_order_venue = 130; |
|
| 2891 | + } |
|
| 2892 | 2892 | } |
| 2893 | 2893 | |
| 2894 | 2894 | |
@@ -2898,144 +2898,144 @@ discard block |
||
| 2898 | 2898 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2899 | 2899 | { |
| 2900 | 2900 | |
| 2901 | - /** |
|
| 2902 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2903 | - */ |
|
| 2904 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2905 | - |
|
| 2906 | - /** |
|
| 2907 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2908 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2909 | - */ |
|
| 2910 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2911 | - |
|
| 2912 | - /** |
|
| 2913 | - * @var boolean $show_ticket_sale_columns |
|
| 2914 | - */ |
|
| 2915 | - public $show_ticket_sale_columns; |
|
| 2916 | - |
|
| 2917 | - /** |
|
| 2918 | - * @var boolean $show_ticket_details |
|
| 2919 | - */ |
|
| 2920 | - public $show_ticket_details; |
|
| 2921 | - |
|
| 2922 | - /** |
|
| 2923 | - * @var boolean $show_expired_tickets |
|
| 2924 | - */ |
|
| 2925 | - public $show_expired_tickets; |
|
| 2926 | - |
|
| 2927 | - /** |
|
| 2928 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 2929 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 2930 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2931 | - * |
|
| 2932 | - * @var string $show_datetime_selector |
|
| 2933 | - */ |
|
| 2934 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2935 | - |
|
| 2936 | - /** |
|
| 2937 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2938 | - * |
|
| 2939 | - * @var int $datetime_selector_threshold |
|
| 2940 | - */ |
|
| 2941 | - private $datetime_selector_threshold = 3; |
|
| 2942 | - |
|
| 2943 | - |
|
| 2944 | - /** |
|
| 2945 | - * class constructor |
|
| 2946 | - */ |
|
| 2947 | - public function __construct() |
|
| 2948 | - { |
|
| 2949 | - $this->show_ticket_sale_columns = true; |
|
| 2950 | - $this->show_ticket_details = true; |
|
| 2951 | - $this->show_expired_tickets = true; |
|
| 2952 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 2953 | - $this->datetime_selector_threshold = 3; |
|
| 2954 | - } |
|
| 2955 | - |
|
| 2956 | - |
|
| 2957 | - /** |
|
| 2958 | - * returns true if a datetime selector should be displayed |
|
| 2959 | - * |
|
| 2960 | - * @param array $datetimes |
|
| 2961 | - * @return bool |
|
| 2962 | - */ |
|
| 2963 | - public function showDatetimeSelector(array $datetimes) |
|
| 2964 | - { |
|
| 2965 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 2966 | - return ! ( |
|
| 2967 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 2968 | - || ( |
|
| 2969 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 2970 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 2971 | - ) |
|
| 2972 | - ); |
|
| 2973 | - } |
|
| 2974 | - |
|
| 2975 | - |
|
| 2976 | - /** |
|
| 2977 | - * @return string |
|
| 2978 | - */ |
|
| 2979 | - public function getShowDatetimeSelector() |
|
| 2980 | - { |
|
| 2981 | - return $this->show_datetime_selector; |
|
| 2982 | - } |
|
| 2983 | - |
|
| 2984 | - |
|
| 2985 | - /** |
|
| 2986 | - * @param bool $keys_only |
|
| 2987 | - * @return array |
|
| 2988 | - */ |
|
| 2989 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 2990 | - { |
|
| 2991 | - return $keys_only |
|
| 2992 | - ? array( |
|
| 2993 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 2994 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 2995 | - ) |
|
| 2996 | - : array( |
|
| 2997 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 2998 | - 'Do not show date & time filter', 'event_espresso' |
|
| 2999 | - ), |
|
| 3000 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3001 | - 'Maybe show date & time filter', 'event_espresso' |
|
| 3002 | - ), |
|
| 3003 | - ); |
|
| 3004 | - } |
|
| 3005 | - |
|
| 3006 | - |
|
| 3007 | - /** |
|
| 3008 | - * @param string $show_datetime_selector |
|
| 3009 | - */ |
|
| 3010 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3011 | - { |
|
| 3012 | - $this->show_datetime_selector = in_array( |
|
| 3013 | - $show_datetime_selector, |
|
| 3014 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3015 | - true |
|
| 3016 | - ) |
|
| 3017 | - ? $show_datetime_selector |
|
| 3018 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3019 | - } |
|
| 3020 | - |
|
| 3021 | - |
|
| 3022 | - /** |
|
| 3023 | - * @return int |
|
| 3024 | - */ |
|
| 3025 | - public function getDatetimeSelectorThreshold() |
|
| 3026 | - { |
|
| 3027 | - return $this->datetime_selector_threshold; |
|
| 3028 | - } |
|
| 3029 | - |
|
| 3030 | - |
|
| 3031 | - /** |
|
| 3032 | - * @param int $datetime_selector_threshold |
|
| 3033 | - */ |
|
| 3034 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3035 | - { |
|
| 3036 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3037 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3038 | - } |
|
| 2901 | + /** |
|
| 2902 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2903 | + */ |
|
| 2904 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2905 | + |
|
| 2906 | + /** |
|
| 2907 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2908 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2909 | + */ |
|
| 2910 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2911 | + |
|
| 2912 | + /** |
|
| 2913 | + * @var boolean $show_ticket_sale_columns |
|
| 2914 | + */ |
|
| 2915 | + public $show_ticket_sale_columns; |
|
| 2916 | + |
|
| 2917 | + /** |
|
| 2918 | + * @var boolean $show_ticket_details |
|
| 2919 | + */ |
|
| 2920 | + public $show_ticket_details; |
|
| 2921 | + |
|
| 2922 | + /** |
|
| 2923 | + * @var boolean $show_expired_tickets |
|
| 2924 | + */ |
|
| 2925 | + public $show_expired_tickets; |
|
| 2926 | + |
|
| 2927 | + /** |
|
| 2928 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 2929 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 2930 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2931 | + * |
|
| 2932 | + * @var string $show_datetime_selector |
|
| 2933 | + */ |
|
| 2934 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2935 | + |
|
| 2936 | + /** |
|
| 2937 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2938 | + * |
|
| 2939 | + * @var int $datetime_selector_threshold |
|
| 2940 | + */ |
|
| 2941 | + private $datetime_selector_threshold = 3; |
|
| 2942 | + |
|
| 2943 | + |
|
| 2944 | + /** |
|
| 2945 | + * class constructor |
|
| 2946 | + */ |
|
| 2947 | + public function __construct() |
|
| 2948 | + { |
|
| 2949 | + $this->show_ticket_sale_columns = true; |
|
| 2950 | + $this->show_ticket_details = true; |
|
| 2951 | + $this->show_expired_tickets = true; |
|
| 2952 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 2953 | + $this->datetime_selector_threshold = 3; |
|
| 2954 | + } |
|
| 2955 | + |
|
| 2956 | + |
|
| 2957 | + /** |
|
| 2958 | + * returns true if a datetime selector should be displayed |
|
| 2959 | + * |
|
| 2960 | + * @param array $datetimes |
|
| 2961 | + * @return bool |
|
| 2962 | + */ |
|
| 2963 | + public function showDatetimeSelector(array $datetimes) |
|
| 2964 | + { |
|
| 2965 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 2966 | + return ! ( |
|
| 2967 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 2968 | + || ( |
|
| 2969 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 2970 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 2971 | + ) |
|
| 2972 | + ); |
|
| 2973 | + } |
|
| 2974 | + |
|
| 2975 | + |
|
| 2976 | + /** |
|
| 2977 | + * @return string |
|
| 2978 | + */ |
|
| 2979 | + public function getShowDatetimeSelector() |
|
| 2980 | + { |
|
| 2981 | + return $this->show_datetime_selector; |
|
| 2982 | + } |
|
| 2983 | + |
|
| 2984 | + |
|
| 2985 | + /** |
|
| 2986 | + * @param bool $keys_only |
|
| 2987 | + * @return array |
|
| 2988 | + */ |
|
| 2989 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 2990 | + { |
|
| 2991 | + return $keys_only |
|
| 2992 | + ? array( |
|
| 2993 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 2994 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 2995 | + ) |
|
| 2996 | + : array( |
|
| 2997 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 2998 | + 'Do not show date & time filter', 'event_espresso' |
|
| 2999 | + ), |
|
| 3000 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3001 | + 'Maybe show date & time filter', 'event_espresso' |
|
| 3002 | + ), |
|
| 3003 | + ); |
|
| 3004 | + } |
|
| 3005 | + |
|
| 3006 | + |
|
| 3007 | + /** |
|
| 3008 | + * @param string $show_datetime_selector |
|
| 3009 | + */ |
|
| 3010 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3011 | + { |
|
| 3012 | + $this->show_datetime_selector = in_array( |
|
| 3013 | + $show_datetime_selector, |
|
| 3014 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3015 | + true |
|
| 3016 | + ) |
|
| 3017 | + ? $show_datetime_selector |
|
| 3018 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3019 | + } |
|
| 3020 | + |
|
| 3021 | + |
|
| 3022 | + /** |
|
| 3023 | + * @return int |
|
| 3024 | + */ |
|
| 3025 | + public function getDatetimeSelectorThreshold() |
|
| 3026 | + { |
|
| 3027 | + return $this->datetime_selector_threshold; |
|
| 3028 | + } |
|
| 3029 | + |
|
| 3030 | + |
|
| 3031 | + /** |
|
| 3032 | + * @param int $datetime_selector_threshold |
|
| 3033 | + */ |
|
| 3034 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3035 | + { |
|
| 3036 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3037 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3038 | + } |
|
| 3039 | 3039 | |
| 3040 | 3040 | |
| 3041 | 3041 | } |
@@ -3051,81 +3051,81 @@ discard block |
||
| 3051 | 3051 | class EE_Environment_Config extends EE_Config_Base |
| 3052 | 3052 | { |
| 3053 | 3053 | |
| 3054 | - /** |
|
| 3055 | - * Hold any php environment variables that we want to track. |
|
| 3056 | - * |
|
| 3057 | - * @var stdClass; |
|
| 3058 | - */ |
|
| 3059 | - public $php; |
|
| 3060 | - |
|
| 3061 | - |
|
| 3062 | - /** |
|
| 3063 | - * constructor |
|
| 3064 | - */ |
|
| 3065 | - public function __construct() |
|
| 3066 | - { |
|
| 3067 | - $this->php = new stdClass(); |
|
| 3068 | - $this->_set_php_values(); |
|
| 3069 | - } |
|
| 3070 | - |
|
| 3071 | - |
|
| 3072 | - /** |
|
| 3073 | - * This sets the php environment variables. |
|
| 3074 | - * |
|
| 3075 | - * @since 4.4.0 |
|
| 3076 | - * @return void |
|
| 3077 | - */ |
|
| 3078 | - protected function _set_php_values() |
|
| 3079 | - { |
|
| 3080 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3081 | - $this->php->version = phpversion(); |
|
| 3082 | - } |
|
| 3083 | - |
|
| 3084 | - |
|
| 3085 | - /** |
|
| 3086 | - * helper method for determining whether input_count is |
|
| 3087 | - * reaching the potential maximum the server can handle |
|
| 3088 | - * according to max_input_vars |
|
| 3089 | - * |
|
| 3090 | - * @param int $input_count the count of input vars. |
|
| 3091 | - * @return array { |
|
| 3092 | - * An array that represents whether available space and if no available space the error |
|
| 3093 | - * message. |
|
| 3094 | - * @type bool $has_space whether more inputs can be added. |
|
| 3095 | - * @type string $msg Any message to be displayed. |
|
| 3096 | - * } |
|
| 3097 | - */ |
|
| 3098 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3099 | - { |
|
| 3100 | - if (! empty($this->php->max_input_vars) |
|
| 3101 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3102 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3103 | - ) { |
|
| 3104 | - return sprintf( |
|
| 3105 | - __( |
|
| 3106 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3107 | - 'event_espresso' |
|
| 3108 | - ), |
|
| 3109 | - '<br>', |
|
| 3110 | - $input_count, |
|
| 3111 | - $this->php->max_input_vars |
|
| 3112 | - ); |
|
| 3113 | - } else { |
|
| 3114 | - return ''; |
|
| 3115 | - } |
|
| 3116 | - } |
|
| 3117 | - |
|
| 3118 | - |
|
| 3119 | - /** |
|
| 3120 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3121 | - * |
|
| 3122 | - * @since 4.4.1 |
|
| 3123 | - * @return void |
|
| 3124 | - */ |
|
| 3125 | - public function recheck_values() |
|
| 3126 | - { |
|
| 3127 | - $this->_set_php_values(); |
|
| 3128 | - } |
|
| 3054 | + /** |
|
| 3055 | + * Hold any php environment variables that we want to track. |
|
| 3056 | + * |
|
| 3057 | + * @var stdClass; |
|
| 3058 | + */ |
|
| 3059 | + public $php; |
|
| 3060 | + |
|
| 3061 | + |
|
| 3062 | + /** |
|
| 3063 | + * constructor |
|
| 3064 | + */ |
|
| 3065 | + public function __construct() |
|
| 3066 | + { |
|
| 3067 | + $this->php = new stdClass(); |
|
| 3068 | + $this->_set_php_values(); |
|
| 3069 | + } |
|
| 3070 | + |
|
| 3071 | + |
|
| 3072 | + /** |
|
| 3073 | + * This sets the php environment variables. |
|
| 3074 | + * |
|
| 3075 | + * @since 4.4.0 |
|
| 3076 | + * @return void |
|
| 3077 | + */ |
|
| 3078 | + protected function _set_php_values() |
|
| 3079 | + { |
|
| 3080 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3081 | + $this->php->version = phpversion(); |
|
| 3082 | + } |
|
| 3083 | + |
|
| 3084 | + |
|
| 3085 | + /** |
|
| 3086 | + * helper method for determining whether input_count is |
|
| 3087 | + * reaching the potential maximum the server can handle |
|
| 3088 | + * according to max_input_vars |
|
| 3089 | + * |
|
| 3090 | + * @param int $input_count the count of input vars. |
|
| 3091 | + * @return array { |
|
| 3092 | + * An array that represents whether available space and if no available space the error |
|
| 3093 | + * message. |
|
| 3094 | + * @type bool $has_space whether more inputs can be added. |
|
| 3095 | + * @type string $msg Any message to be displayed. |
|
| 3096 | + * } |
|
| 3097 | + */ |
|
| 3098 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3099 | + { |
|
| 3100 | + if (! empty($this->php->max_input_vars) |
|
| 3101 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3102 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3103 | + ) { |
|
| 3104 | + return sprintf( |
|
| 3105 | + __( |
|
| 3106 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3107 | + 'event_espresso' |
|
| 3108 | + ), |
|
| 3109 | + '<br>', |
|
| 3110 | + $input_count, |
|
| 3111 | + $this->php->max_input_vars |
|
| 3112 | + ); |
|
| 3113 | + } else { |
|
| 3114 | + return ''; |
|
| 3115 | + } |
|
| 3116 | + } |
|
| 3117 | + |
|
| 3118 | + |
|
| 3119 | + /** |
|
| 3120 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3121 | + * |
|
| 3122 | + * @since 4.4.1 |
|
| 3123 | + * @return void |
|
| 3124 | + */ |
|
| 3125 | + public function recheck_values() |
|
| 3126 | + { |
|
| 3127 | + $this->_set_php_values(); |
|
| 3128 | + } |
|
| 3129 | 3129 | |
| 3130 | 3130 | |
| 3131 | 3131 | } |
@@ -3141,21 +3141,21 @@ discard block |
||
| 3141 | 3141 | class EE_Tax_Config extends EE_Config_Base |
| 3142 | 3142 | { |
| 3143 | 3143 | |
| 3144 | - /* |
|
| 3144 | + /* |
|
| 3145 | 3145 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3146 | 3146 | * |
| 3147 | 3147 | * @var boolean $prices_displayed_including_taxes |
| 3148 | 3148 | */ |
| 3149 | - public $prices_displayed_including_taxes; |
|
| 3149 | + public $prices_displayed_including_taxes; |
|
| 3150 | 3150 | |
| 3151 | 3151 | |
| 3152 | - /** |
|
| 3153 | - * class constructor |
|
| 3154 | - */ |
|
| 3155 | - public function __construct() |
|
| 3156 | - { |
|
| 3157 | - $this->prices_displayed_including_taxes = true; |
|
| 3158 | - } |
|
| 3152 | + /** |
|
| 3153 | + * class constructor |
|
| 3154 | + */ |
|
| 3155 | + public function __construct() |
|
| 3156 | + { |
|
| 3157 | + $this->prices_displayed_including_taxes = true; |
|
| 3158 | + } |
|
| 3159 | 3159 | } |
| 3160 | 3160 | |
| 3161 | 3161 | |
@@ -3167,33 +3167,33 @@ discard block |
||
| 3167 | 3167 | class EE_Gateway_Config extends EE_Config_Base |
| 3168 | 3168 | { |
| 3169 | 3169 | |
| 3170 | - /** |
|
| 3171 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3172 | - * with any config info the gateway wants to store |
|
| 3173 | - * |
|
| 3174 | - * @var array |
|
| 3175 | - */ |
|
| 3176 | - public $payment_settings; |
|
| 3177 | - |
|
| 3178 | - /** |
|
| 3179 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3180 | - * the gateway is stored in the uploads directory |
|
| 3181 | - * |
|
| 3182 | - * @var array |
|
| 3183 | - */ |
|
| 3184 | - public $active_gateways; |
|
| 3185 | - |
|
| 3186 | - |
|
| 3187 | - /** |
|
| 3188 | - * class constructor |
|
| 3189 | - * |
|
| 3190 | - * @deprecated |
|
| 3191 | - */ |
|
| 3192 | - public function __construct() |
|
| 3193 | - { |
|
| 3194 | - $this->payment_settings = array(); |
|
| 3195 | - $this->active_gateways = array('Invoice' => false); |
|
| 3196 | - } |
|
| 3170 | + /** |
|
| 3171 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3172 | + * with any config info the gateway wants to store |
|
| 3173 | + * |
|
| 3174 | + * @var array |
|
| 3175 | + */ |
|
| 3176 | + public $payment_settings; |
|
| 3177 | + |
|
| 3178 | + /** |
|
| 3179 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3180 | + * the gateway is stored in the uploads directory |
|
| 3181 | + * |
|
| 3182 | + * @var array |
|
| 3183 | + */ |
|
| 3184 | + public $active_gateways; |
|
| 3185 | + |
|
| 3186 | + |
|
| 3187 | + /** |
|
| 3188 | + * class constructor |
|
| 3189 | + * |
|
| 3190 | + * @deprecated |
|
| 3191 | + */ |
|
| 3192 | + public function __construct() |
|
| 3193 | + { |
|
| 3194 | + $this->payment_settings = array(); |
|
| 3195 | + $this->active_gateways = array('Invoice' => false); |
|
| 3196 | + } |
|
| 3197 | 3197 | } |
| 3198 | 3198 | |
| 3199 | 3199 | // End of file EE_Config.core.php |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | public static function instance() |
| 134 | 134 | { |
| 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; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $this |
| 271 | 271 | ); |
| 272 | 272 | if (is_object($settings) && property_exists($this, $config)) { |
| 273 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 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 | 275 | if (method_exists($settings, 'populate')) { |
| 276 | 276 | $this->{$config}->populate(); |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | break; |
| 526 | 526 | // TEST #2 : check that settings section exists |
| 527 | 527 | case 2 : |
| 528 | - if (! isset($this->{$section})) { |
|
| 528 | + if ( ! isset($this->{$section})) { |
|
| 529 | 529 | if ($display_errors) { |
| 530 | 530 | throw new EE_Error( |
| 531 | 531 | sprintf( |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | break; |
| 587 | 587 | // TEST #6 : verify config class is accessible |
| 588 | 588 | case 6 : |
| 589 | - if (! class_exists($config_class)) { |
|
| 589 | + if ( ! class_exists($config_class)) { |
|
| 590 | 590 | if ($display_errors) { |
| 591 | 591 | throw new EE_Error( |
| 592 | 592 | sprintf( |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | break; |
| 604 | 604 | // TEST #7 : check that config has even been set |
| 605 | 605 | case 7 : |
| 606 | - if (! isset($this->{$section}->{$name})) { |
|
| 606 | + if ( ! isset($this->{$section}->{$name})) { |
|
| 607 | 607 | if ($display_errors) { |
| 608 | 608 | throw new EE_Error( |
| 609 | 609 | sprintf( |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | break; |
| 622 | 622 | // TEST #8 : check that config is the requested type |
| 623 | 623 | case 8 : |
| 624 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 624 | + if ( ! $this->{$section}->{$name} instanceof $config_class) { |
|
| 625 | 625 | if ($display_errors) { |
| 626 | 626 | throw new EE_Error( |
| 627 | 627 | sprintf( |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | break; |
| 641 | 641 | // TEST #9 : verify config object |
| 642 | 642 | case 9 : |
| 643 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 643 | + if ( ! $config_obj instanceof EE_Config_Base) { |
|
| 644 | 644 | if ($display_errors) { |
| 645 | 645 | throw new EE_Error( |
| 646 | 646 | sprintf( |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | */ |
| 673 | 673 | private function _generate_config_option_name($section = '', $name = '') |
| 674 | 674 | { |
| 675 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 675 | + return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | { |
| 690 | 690 | return ! empty($config_class) |
| 691 | 691 | ? $config_class |
| 692 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 692 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config'; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | |
@@ -708,17 +708,17 @@ discard block |
||
| 708 | 708 | // ensure config class is set to something |
| 709 | 709 | $config_class = $this->_set_config_class($config_class, $name); |
| 710 | 710 | // run tests 1-4, 6, and 7 to verify all config params are set and valid |
| 711 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 711 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 712 | 712 | return null; |
| 713 | 713 | } |
| 714 | 714 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 715 | 715 | // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
| 716 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 716 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 717 | 717 | $this->_addon_option_names[$config_option_name] = $config_class; |
| 718 | 718 | $this->update_addon_option_names(); |
| 719 | 719 | } |
| 720 | 720 | // verify the incoming config object but suppress errors |
| 721 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 721 | + if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 722 | 722 | $config_obj = new $config_class(); |
| 723 | 723 | } |
| 724 | 724 | if (get_option($config_option_name)) { |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | // get class name of the incoming object |
| 766 | 766 | $config_class = get_class($config_obj); |
| 767 | 767 | // run tests 1-5 and 9 to verify config |
| 768 | - if (! $this->_verify_config_params( |
|
| 768 | + if ( ! $this->_verify_config_params( |
|
| 769 | 769 | $section, |
| 770 | 770 | $name, |
| 771 | 771 | $config_class, |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | } |
| 778 | 778 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 779 | 779 | // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
| 780 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 780 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 781 | 781 | // save new config to db |
| 782 | 782 | if ($this->set_config($section, $name, $config_class, $config_obj)) { |
| 783 | 783 | return true; |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | 'event_espresso' |
| 804 | 804 | ), |
| 805 | 805 | $config_class, |
| 806 | - 'EE_Config->' . $section . '->' . $name |
|
| 806 | + 'EE_Config->'.$section.'->'.$name |
|
| 807 | 807 | ), |
| 808 | 808 | __FILE__, |
| 809 | 809 | __FUNCTION__, |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | // ensure config class is set to something |
| 830 | 830 | $config_class = $this->_set_config_class($config_class, $name); |
| 831 | 831 | // run tests 1-4, 6 and 7 to verify that all params have been set |
| 832 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 832 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 833 | 833 | return null; |
| 834 | 834 | } |
| 835 | 835 | // now test if the requested config object exists, but suppress errors |
@@ -874,7 +874,7 @@ discard block |
||
| 874 | 874 | // retrieve the wp-option for this config class. |
| 875 | 875 | $config_option = maybe_unserialize(get_option($config_option_name, array())); |
| 876 | 876 | if (empty($config_option)) { |
| 877 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 877 | + EE_Config::log($config_option_name.'-NOT-FOUND'); |
|
| 878 | 878 | } |
| 879 | 879 | return $config_option; |
| 880 | 880 | } |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | //copy incoming $_REQUEST and sanitize it so we can save it |
| 893 | 893 | $_request = $_REQUEST; |
| 894 | 894 | array_walk_recursive($_request, 'sanitize_text_field'); |
| 895 | - $config_log[(string)microtime(true)] = array( |
|
| 895 | + $config_log[(string) microtime(true)] = array( |
|
| 896 | 896 | 'config_name' => $config_option_name, |
| 897 | 897 | 'request' => $_request, |
| 898 | 898 | ); |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | */ |
| 908 | 908 | public static function trim_log() |
| 909 | 909 | { |
| 910 | - if (! EE_Config::logging_enabled()) { |
|
| 910 | + if ( ! EE_Config::logging_enabled()) { |
|
| 911 | 911 | return; |
| 912 | 912 | } |
| 913 | 913 | $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | public static function get_page_for_posts() |
| 932 | 932 | { |
| 933 | 933 | $page_for_posts = get_option('page_for_posts'); |
| 934 | - if (! $page_for_posts) { |
|
| 934 | + if ( ! $page_for_posts) { |
|
| 935 | 935 | return 'posts'; |
| 936 | 936 | } |
| 937 | 937 | /** @type WPDB $wpdb */ |
@@ -993,13 +993,13 @@ discard block |
||
| 993 | 993 | ) |
| 994 | 994 | ) { |
| 995 | 995 | // grab list of installed widgets |
| 996 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 996 | + $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR); |
|
| 997 | 997 | // filter list of modules to register |
| 998 | 998 | $widgets_to_register = apply_filters( |
| 999 | 999 | 'FHEE__EE_Config__register_widgets__widgets_to_register', |
| 1000 | 1000 | $widgets_to_register |
| 1001 | 1001 | ); |
| 1002 | - if (! empty($widgets_to_register)) { |
|
| 1002 | + if ( ! empty($widgets_to_register)) { |
|
| 1003 | 1003 | // cycle thru widget folders |
| 1004 | 1004 | foreach ($widgets_to_register as $widget_path) { |
| 1005 | 1005 | // add to list of installed widget modules |
@@ -1049,31 +1049,31 @@ discard block |
||
| 1049 | 1049 | // create classname from widget directory name |
| 1050 | 1050 | $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
| 1051 | 1051 | // add class prefix |
| 1052 | - $widget_class = 'EEW_' . $widget; |
|
| 1052 | + $widget_class = 'EEW_'.$widget; |
|
| 1053 | 1053 | // does the widget exist ? |
| 1054 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1054 | + if ( ! is_readable($widget_path.DS.$widget_class.$widget_ext)) { |
|
| 1055 | 1055 | $msg = sprintf( |
| 1056 | 1056 | __( |
| 1057 | 1057 | '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', |
| 1058 | 1058 | 'event_espresso' |
| 1059 | 1059 | ), |
| 1060 | 1060 | $widget_class, |
| 1061 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1061 | + $widget_path.DS.$widget_class.$widget_ext |
|
| 1062 | 1062 | ); |
| 1063 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1063 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1064 | 1064 | return; |
| 1065 | 1065 | } |
| 1066 | 1066 | // load the widget class file |
| 1067 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1067 | + require_once($widget_path.DS.$widget_class.$widget_ext); |
|
| 1068 | 1068 | // verify that class exists |
| 1069 | - if (! class_exists($widget_class)) { |
|
| 1069 | + if ( ! class_exists($widget_class)) { |
|
| 1070 | 1070 | $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
| 1071 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1071 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1072 | 1072 | return; |
| 1073 | 1073 | } |
| 1074 | 1074 | register_widget($widget_class); |
| 1075 | 1075 | // add to array of registered widgets |
| 1076 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1076 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path.DS.$widget_class.$widget_ext; |
|
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | |
@@ -1086,13 +1086,13 @@ discard block |
||
| 1086 | 1086 | private function _register_shortcodes() |
| 1087 | 1087 | { |
| 1088 | 1088 | // grab list of installed shortcodes |
| 1089 | - $shortcodes_to_register = glob(EE_SHORTCODES . '*', GLOB_ONLYDIR); |
|
| 1089 | + $shortcodes_to_register = glob(EE_SHORTCODES.'*', GLOB_ONLYDIR); |
|
| 1090 | 1090 | // filter list of modules to register |
| 1091 | 1091 | $shortcodes_to_register = apply_filters( |
| 1092 | 1092 | 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
| 1093 | 1093 | $shortcodes_to_register |
| 1094 | 1094 | ); |
| 1095 | - if (! empty($shortcodes_to_register)) { |
|
| 1095 | + if ( ! empty($shortcodes_to_register)) { |
|
| 1096 | 1096 | // cycle thru shortcode folders |
| 1097 | 1097 | foreach ($shortcodes_to_register as $shortcode_path) { |
| 1098 | 1098 | // add to list of installed shortcode modules |
@@ -1135,44 +1135,44 @@ discard block |
||
| 1135 | 1135 | // remove last segment |
| 1136 | 1136 | array_pop($shortcode_path); |
| 1137 | 1137 | // glue it back together |
| 1138 | - $shortcode_path = implode(DS, $shortcode_path) . DS; |
|
| 1138 | + $shortcode_path = implode(DS, $shortcode_path).DS; |
|
| 1139 | 1139 | } else { |
| 1140 | 1140 | // we need to generate the filename based off of the folder name |
| 1141 | 1141 | // grab and sanitize shortcode directory name |
| 1142 | 1142 | $shortcode = sanitize_key(basename($shortcode_path)); |
| 1143 | - $shortcode_path = rtrim($shortcode_path, DS) . DS; |
|
| 1143 | + $shortcode_path = rtrim($shortcode_path, DS).DS; |
|
| 1144 | 1144 | } |
| 1145 | 1145 | // create classname from shortcode directory or file name |
| 1146 | 1146 | $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
| 1147 | 1147 | // add class prefix |
| 1148 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 1148 | + $shortcode_class = 'EES_'.$shortcode; |
|
| 1149 | 1149 | // does the shortcode exist ? |
| 1150 | - if (! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) { |
|
| 1150 | + if ( ! is_readable($shortcode_path.DS.$shortcode_class.$shortcode_ext)) { |
|
| 1151 | 1151 | $msg = sprintf( |
| 1152 | 1152 | __( |
| 1153 | 1153 | 'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s', |
| 1154 | 1154 | 'event_espresso' |
| 1155 | 1155 | ), |
| 1156 | 1156 | $shortcode_class, |
| 1157 | - $shortcode_path . DS . $shortcode_class . $shortcode_ext |
|
| 1157 | + $shortcode_path.DS.$shortcode_class.$shortcode_ext |
|
| 1158 | 1158 | ); |
| 1159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1159 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1160 | 1160 | return false; |
| 1161 | 1161 | } |
| 1162 | 1162 | // load the shortcode class file |
| 1163 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
| 1163 | + require_once($shortcode_path.$shortcode_class.$shortcode_ext); |
|
| 1164 | 1164 | // verify that class exists |
| 1165 | - if (! class_exists($shortcode_class)) { |
|
| 1165 | + if ( ! class_exists($shortcode_class)) { |
|
| 1166 | 1166 | $msg = sprintf( |
| 1167 | 1167 | __('The requested %s shortcode class does not exist.', 'event_espresso'), |
| 1168 | 1168 | $shortcode_class |
| 1169 | 1169 | ); |
| 1170 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1170 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1171 | 1171 | return false; |
| 1172 | 1172 | } |
| 1173 | 1173 | $shortcode = strtoupper($shortcode); |
| 1174 | 1174 | // add to array of registered shortcodes |
| 1175 | - EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 1175 | + EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext; |
|
| 1176 | 1176 | return true; |
| 1177 | 1177 | } |
| 1178 | 1178 | |
@@ -1186,19 +1186,19 @@ discard block |
||
| 1186 | 1186 | private function _register_modules() |
| 1187 | 1187 | { |
| 1188 | 1188 | // grab list of installed modules |
| 1189 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1189 | + $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR); |
|
| 1190 | 1190 | // filter list of modules to register |
| 1191 | 1191 | $modules_to_register = apply_filters( |
| 1192 | 1192 | 'FHEE__EE_Config__register_modules__modules_to_register', |
| 1193 | 1193 | $modules_to_register |
| 1194 | 1194 | ); |
| 1195 | - if (! empty($modules_to_register)) { |
|
| 1195 | + if ( ! empty($modules_to_register)) { |
|
| 1196 | 1196 | // loop through folders |
| 1197 | 1197 | foreach ($modules_to_register as $module_path) { |
| 1198 | 1198 | /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
| 1199 | 1199 | if ( |
| 1200 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1201 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1200 | + $module_path !== EE_MODULES.'zzz-copy-this-module-template' |
|
| 1201 | + && $module_path !== EE_MODULES.'gateways' |
|
| 1202 | 1202 | ) { |
| 1203 | 1203 | // add to list of installed modules |
| 1204 | 1204 | EE_Config::register_module($module_path); |
@@ -1235,25 +1235,25 @@ discard block |
||
| 1235 | 1235 | // remove last segment |
| 1236 | 1236 | array_pop($module_path); |
| 1237 | 1237 | // glue it back together |
| 1238 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1238 | + $module_path = implode(DS, $module_path).DS; |
|
| 1239 | 1239 | // take first segment from file name pieces and sanitize it |
| 1240 | 1240 | $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
| 1241 | 1241 | // ensure class prefix is added |
| 1242 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1242 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module; |
|
| 1243 | 1243 | } else { |
| 1244 | 1244 | // we need to generate the filename based off of the folder name |
| 1245 | 1245 | // grab and sanitize module name |
| 1246 | 1246 | $module = strtolower(basename($module_path)); |
| 1247 | 1247 | $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
| 1248 | 1248 | // like trailingslashit() |
| 1249 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1249 | + $module_path = rtrim($module_path, DS).DS; |
|
| 1250 | 1250 | // create classname from module directory name |
| 1251 | 1251 | $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
| 1252 | 1252 | // add class prefix |
| 1253 | - $module_class = 'EED_' . $module; |
|
| 1253 | + $module_class = 'EED_'.$module; |
|
| 1254 | 1254 | } |
| 1255 | 1255 | // does the module exist ? |
| 1256 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1256 | + if ( ! is_readable($module_path.DS.$module_class.$module_ext)) { |
|
| 1257 | 1257 | $msg = sprintf( |
| 1258 | 1258 | __( |
| 1259 | 1259 | 'The requested %s module file could not be found or is not readable due to file permissions.', |
@@ -1261,19 +1261,19 @@ discard block |
||
| 1261 | 1261 | ), |
| 1262 | 1262 | $module |
| 1263 | 1263 | ); |
| 1264 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1264 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1265 | 1265 | return false; |
| 1266 | 1266 | } |
| 1267 | 1267 | // load the module class file |
| 1268 | - require_once($module_path . $module_class . $module_ext); |
|
| 1268 | + require_once($module_path.$module_class.$module_ext); |
|
| 1269 | 1269 | // verify that class exists |
| 1270 | - if (! class_exists($module_class)) { |
|
| 1270 | + if ( ! class_exists($module_class)) { |
|
| 1271 | 1271 | $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
| 1272 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1272 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1273 | 1273 | return false; |
| 1274 | 1274 | } |
| 1275 | 1275 | // add to array of registered modules |
| 1276 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1276 | + EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext; |
|
| 1277 | 1277 | do_action( |
| 1278 | 1278 | 'AHEE__EE_Config__register_module__complete', |
| 1279 | 1279 | $module_class, |
@@ -1295,7 +1295,7 @@ discard block |
||
| 1295 | 1295 | // cycle thru shortcode folders |
| 1296 | 1296 | foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) { |
| 1297 | 1297 | // add class prefix |
| 1298 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 1298 | + $shortcode_class = 'EES_'.$shortcode; |
|
| 1299 | 1299 | // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
| 1300 | 1300 | // which set hooks ? |
| 1301 | 1301 | if (is_admin()) { |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | // convert classname to UPPERCASE and create WP shortcode. |
| 1311 | 1311 | $shortcode_tag = strtoupper($shortcode); |
| 1312 | 1312 | // but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor' |
| 1313 | - if (! shortcode_exists($shortcode_tag)) { |
|
| 1313 | + if ( ! shortcode_exists($shortcode_tag)) { |
|
| 1314 | 1314 | // NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes() |
| 1315 | 1315 | add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
| 1316 | 1316 | } |
@@ -1360,26 +1360,26 @@ discard block |
||
| 1360 | 1360 | { |
| 1361 | 1361 | do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
| 1362 | 1362 | $module = str_replace('EED_', '', $module); |
| 1363 | - $module_class = 'EED_' . $module; |
|
| 1364 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1363 | + $module_class = 'EED_'.$module; |
|
| 1364 | + if ( ! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1365 | 1365 | $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
| 1366 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1366 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1367 | 1367 | return false; |
| 1368 | 1368 | } |
| 1369 | 1369 | if (empty($route)) { |
| 1370 | 1370 | $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
| 1371 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1371 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1372 | 1372 | return false; |
| 1373 | 1373 | } |
| 1374 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1374 | + if ( ! method_exists('EED_'.$module, $method_name)) { |
|
| 1375 | 1375 | $msg = sprintf( |
| 1376 | 1376 | __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
| 1377 | 1377 | $route |
| 1378 | 1378 | ); |
| 1379 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1379 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1380 | 1380 | return false; |
| 1381 | 1381 | } |
| 1382 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1382 | + EE_Config::$_module_route_map[$key][$route] = array('EED_'.$module, $method_name); |
|
| 1383 | 1383 | return true; |
| 1384 | 1384 | } |
| 1385 | 1385 | |
@@ -1395,7 +1395,7 @@ discard block |
||
| 1395 | 1395 | public static function get_route($route = null, $key = 'ee') |
| 1396 | 1396 | { |
| 1397 | 1397 | do_action('AHEE__EE_Config__get_route__begin', $route); |
| 1398 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1398 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1399 | 1399 | if (isset(EE_Config::$_module_route_map[$key][$route])) { |
| 1400 | 1400 | return EE_Config::$_module_route_map[$key][$route]; |
| 1401 | 1401 | } |
@@ -1429,44 +1429,44 @@ discard block |
||
| 1429 | 1429 | public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
| 1430 | 1430 | { |
| 1431 | 1431 | do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
| 1432 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1432 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1433 | 1433 | $msg = sprintf( |
| 1434 | 1434 | __('The module route %s for this forward has not been registered.', 'event_espresso'), |
| 1435 | 1435 | $route |
| 1436 | 1436 | ); |
| 1437 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1437 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1438 | 1438 | return false; |
| 1439 | 1439 | } |
| 1440 | 1440 | if (empty($forward)) { |
| 1441 | 1441 | $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
| 1442 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1442 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1443 | 1443 | return false; |
| 1444 | 1444 | } |
| 1445 | 1445 | if (is_array($forward)) { |
| 1446 | - if (! isset($forward[1])) { |
|
| 1446 | + if ( ! isset($forward[1])) { |
|
| 1447 | 1447 | $msg = sprintf( |
| 1448 | 1448 | __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
| 1449 | 1449 | $route |
| 1450 | 1450 | ); |
| 1451 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1451 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | 1452 | return false; |
| 1453 | 1453 | } |
| 1454 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1454 | + if ( ! method_exists($forward[0], $forward[1])) { |
|
| 1455 | 1455 | $msg = sprintf( |
| 1456 | 1456 | __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1457 | 1457 | $forward[1], |
| 1458 | 1458 | $route |
| 1459 | 1459 | ); |
| 1460 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1460 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1461 | 1461 | return false; |
| 1462 | 1462 | } |
| 1463 | - } else if (! function_exists($forward)) { |
|
| 1463 | + } else if ( ! function_exists($forward)) { |
|
| 1464 | 1464 | $msg = sprintf( |
| 1465 | 1465 | __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1466 | 1466 | $forward, |
| 1467 | 1467 | $route |
| 1468 | 1468 | ); |
| 1469 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1469 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1470 | 1470 | return false; |
| 1471 | 1471 | } |
| 1472 | 1472 | EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
@@ -1514,15 +1514,15 @@ discard block |
||
| 1514 | 1514 | public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
| 1515 | 1515 | { |
| 1516 | 1516 | do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
| 1517 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1517 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1518 | 1518 | $msg = sprintf( |
| 1519 | 1519 | __('The module route %s for this view has not been registered.', 'event_espresso'), |
| 1520 | 1520 | $route |
| 1521 | 1521 | ); |
| 1522 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1522 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1523 | 1523 | return false; |
| 1524 | 1524 | } |
| 1525 | - if (! is_readable($view)) { |
|
| 1525 | + if ( ! is_readable($view)) { |
|
| 1526 | 1526 | $msg = sprintf( |
| 1527 | 1527 | __( |
| 1528 | 1528 | 'The %s view file could not be found or is not readable due to file permissions.', |
@@ -1530,7 +1530,7 @@ discard block |
||
| 1530 | 1530 | ), |
| 1531 | 1531 | $view |
| 1532 | 1532 | ); |
| 1533 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1533 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1534 | 1534 | return false; |
| 1535 | 1535 | } |
| 1536 | 1536 | EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
@@ -1595,7 +1595,7 @@ discard block |
||
| 1595 | 1595 | */ |
| 1596 | 1596 | public function get_pretty($property) |
| 1597 | 1597 | { |
| 1598 | - if (! property_exists($this, $property)) { |
|
| 1598 | + if ( ! property_exists($this, $property)) { |
|
| 1599 | 1599 | throw new EE_Error( |
| 1600 | 1600 | sprintf( |
| 1601 | 1601 | __( |
@@ -1829,11 +1829,11 @@ discard block |
||
| 1829 | 1829 | */ |
| 1830 | 1830 | public function reg_page_url() |
| 1831 | 1831 | { |
| 1832 | - if (! $this->reg_page_url) { |
|
| 1832 | + if ( ! $this->reg_page_url) { |
|
| 1833 | 1833 | $this->reg_page_url = add_query_arg( |
| 1834 | 1834 | array('uts' => time()), |
| 1835 | 1835 | get_permalink($this->reg_page_id) |
| 1836 | - ) . '#checkout'; |
|
| 1836 | + ).'#checkout'; |
|
| 1837 | 1837 | } |
| 1838 | 1838 | return $this->reg_page_url; |
| 1839 | 1839 | } |
@@ -1849,7 +1849,7 @@ discard block |
||
| 1849 | 1849 | */ |
| 1850 | 1850 | public function txn_page_url($query_args = array()) |
| 1851 | 1851 | { |
| 1852 | - if (! $this->txn_page_url) { |
|
| 1852 | + if ( ! $this->txn_page_url) { |
|
| 1853 | 1853 | $this->txn_page_url = get_permalink($this->txn_page_id); |
| 1854 | 1854 | } |
| 1855 | 1855 | if ($query_args) { |
@@ -1870,7 +1870,7 @@ discard block |
||
| 1870 | 1870 | */ |
| 1871 | 1871 | public function thank_you_page_url($query_args = array()) |
| 1872 | 1872 | { |
| 1873 | - if (! $this->thank_you_page_url) { |
|
| 1873 | + if ( ! $this->thank_you_page_url) { |
|
| 1874 | 1874 | $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
| 1875 | 1875 | } |
| 1876 | 1876 | if ($query_args) { |
@@ -1889,7 +1889,7 @@ discard block |
||
| 1889 | 1889 | */ |
| 1890 | 1890 | public function cancel_page_url() |
| 1891 | 1891 | { |
| 1892 | - if (! $this->cancel_page_url) { |
|
| 1892 | + if ( ! $this->cancel_page_url) { |
|
| 1893 | 1893 | $this->cancel_page_url = get_permalink($this->cancel_page_id); |
| 1894 | 1894 | } |
| 1895 | 1895 | return $this->cancel_page_url; |
@@ -1925,7 +1925,7 @@ discard block |
||
| 1925 | 1925 | } |
| 1926 | 1926 | |
| 1927 | 1927 | //is this already cached for this request? If so use it. |
| 1928 | - if (! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1928 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1929 | 1929 | return EE_Core_Config::$ee_ueip_option; |
| 1930 | 1930 | } |
| 1931 | 1931 | |
@@ -1935,7 +1935,7 @@ discard block |
||
| 1935 | 1935 | $option = 'ee_ueip_optin'; |
| 1936 | 1936 | |
| 1937 | 1937 | //set correct table for query |
| 1938 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1938 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options'; |
|
| 1939 | 1939 | |
| 1940 | 1940 | |
| 1941 | 1941 | //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
@@ -1943,7 +1943,7 @@ discard block |
||
| 1943 | 1943 | //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
| 1944 | 1944 | //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
| 1945 | 1945 | //for the purpose of caching. |
| 1946 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1946 | + $pre = apply_filters('pre_option_'.$option, false, $option); |
|
| 1947 | 1947 | if (false !== $pre) { |
| 1948 | 1948 | EE_Core_Config::$ee_ueip_option = $pre; |
| 1949 | 1949 | return EE_Core_Config::$ee_ueip_option; |
@@ -1954,10 +1954,10 @@ discard block |
||
| 1954 | 1954 | if (is_object($row)) { |
| 1955 | 1955 | $value = $row->option_value; |
| 1956 | 1956 | } else { //option does not exist so use default. |
| 1957 | - return apply_filters('default_option_' . $option, false, $option); |
|
| 1957 | + return apply_filters('default_option_'.$option, false, $option); |
|
| 1958 | 1958 | } |
| 1959 | 1959 | |
| 1960 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1960 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option); |
|
| 1961 | 1961 | return EE_Core_Config::$ee_ueip_option; |
| 1962 | 1962 | } |
| 1963 | 1963 | |
@@ -2229,27 +2229,27 @@ discard block |
||
| 2229 | 2229 | // retrieve the country settings from the db, just in case they have been customized |
| 2230 | 2230 | $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
| 2231 | 2231 | if ($country instanceof EE_Country) { |
| 2232 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2233 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2234 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2235 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2236 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2237 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2238 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2239 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2232 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2233 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2234 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2235 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2236 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2237 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2238 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2239 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2240 | 2240 | } |
| 2241 | 2241 | } |
| 2242 | 2242 | // fallback to hardcoded defaults, in case the above failed |
| 2243 | 2243 | if (empty($this->code)) { |
| 2244 | 2244 | // set default currency settings |
| 2245 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2246 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2247 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2248 | - $this->sign = '$'; // currency sign: $ |
|
| 2249 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2250 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2251 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2252 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2245 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2246 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2247 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2248 | + $this->sign = '$'; // currency sign: $ |
|
| 2249 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2250 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2251 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2252 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2253 | 2253 | } |
| 2254 | 2254 | } |
| 2255 | 2255 | } |
@@ -2563,7 +2563,7 @@ discard block |
||
| 2563 | 2563 | public function log_file_name($reset = false) |
| 2564 | 2564 | { |
| 2565 | 2565 | if (empty($this->log_file_name) || $reset) { |
| 2566 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2566 | + $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt'; |
|
| 2567 | 2567 | EE_Config::instance()->update_espresso_config(false, false); |
| 2568 | 2568 | } |
| 2569 | 2569 | return $this->log_file_name; |
@@ -2577,7 +2577,7 @@ discard block |
||
| 2577 | 2577 | public function debug_file_name($reset = false) |
| 2578 | 2578 | { |
| 2579 | 2579 | if (empty($this->debug_file_name) || $reset) { |
| 2580 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2580 | + $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt'; |
|
| 2581 | 2581 | EE_Config::instance()->update_espresso_config(false, false); |
| 2582 | 2582 | } |
| 2583 | 2583 | return $this->debug_file_name; |
@@ -2786,21 +2786,21 @@ discard block |
||
| 2786 | 2786 | $this->use_google_maps = true; |
| 2787 | 2787 | $this->google_map_api_key = ''; |
| 2788 | 2788 | // for event details pages (reg page) |
| 2789 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2790 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2791 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2792 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2793 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2794 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2795 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2789 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2790 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2791 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2792 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2793 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2794 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2795 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2796 | 2796 | // for event list pages |
| 2797 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2798 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2799 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2800 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2801 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2802 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2803 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2797 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2798 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2799 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2800 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2801 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2802 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2803 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2804 | 2804 | } |
| 2805 | 2805 | |
| 2806 | 2806 | } |
@@ -3097,7 +3097,7 @@ discard block |
||
| 3097 | 3097 | */ |
| 3098 | 3098 | public function max_input_vars_limit_check($input_count = 0) |
| 3099 | 3099 | { |
| 3100 | - if (! empty($this->php->max_input_vars) |
|
| 3100 | + if ( ! empty($this->php->max_input_vars) |
|
| 3101 | 3101 | && ($input_count >= $this->php->max_input_vars) |
| 3102 | 3102 | && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
| 3103 | 3103 | ) { |
@@ -16,282 +16,282 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string $iframe_name |
|
| 21 | - */ |
|
| 22 | - private $iframe_name; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var string $route_name |
|
| 26 | - */ |
|
| 27 | - private $route_name; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var string $slug |
|
| 31 | - */ |
|
| 32 | - private $slug; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var boolean $append_filterable_content |
|
| 36 | - */ |
|
| 37 | - private $append_filterable_content; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * IframeEmbedButton constructor. |
|
| 43 | - * |
|
| 44 | - * @param string $iframe_name i18n name for the iframe. This will be used in HTML |
|
| 45 | - * @param string $route_name the name of the registered route |
|
| 46 | - * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
|
| 47 | - * will most likely be "event" since that's the only usage atm |
|
| 48 | - */ |
|
| 49 | - public function __construct( $iframe_name, $route_name, $slug = 'event' ) |
|
| 50 | - { |
|
| 51 | - $this->iframe_name = $iframe_name; |
|
| 52 | - $this->route_name = $route_name; |
|
| 53 | - $this->slug = $slug; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Adds an iframe embed code button to the Event editor. |
|
| 60 | - */ |
|
| 61 | - public function addEventEditorIframeEmbedButtonFilter() |
|
| 62 | - { |
|
| 63 | - // add button for iframe code to event editor. |
|
| 64 | - add_filter( |
|
| 65 | - 'get_sample_permalink_html', |
|
| 66 | - array( $this, 'appendIframeEmbedButtonToSamplePermalinkHtml' ), |
|
| 67 | - 10, |
|
| 68 | - 2 |
|
| 69 | - ); |
|
| 70 | - add_action( |
|
| 71 | - 'admin_enqueue_scripts', |
|
| 72 | - array( $this, 'embedButtonAssets' ), |
|
| 73 | - 10 |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param $permalink_string |
|
| 81 | - * @param $id |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - public function appendIframeEmbedButtonToSamplePermalinkHtml( $permalink_string, $id ) |
|
| 85 | - { |
|
| 86 | - return $this->eventEditorIframeEmbedButton( |
|
| 87 | - $permalink_string, |
|
| 88 | - $id |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * iframe embed code button to the Event editor. |
|
| 96 | - * |
|
| 97 | - * @param string $permalink_string |
|
| 98 | - * @param int $id |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public function eventEditorIframeEmbedButton( |
|
| 102 | - $permalink_string, |
|
| 103 | - $id |
|
| 104 | - ) { |
|
| 105 | - //make sure this is ONLY when editing and the event id has been set. |
|
| 106 | - if ( ! empty( $id ) ) { |
|
| 107 | - $post = get_post( $id ); |
|
| 108 | - //if NOT event then let's get out. |
|
| 109 | - if ( $post->post_type !== 'espresso_events' ) { |
|
| 110 | - return $permalink_string; |
|
| 111 | - } |
|
| 112 | - $permalink_string .= $this->embedButtonHtml( |
|
| 113 | - array( $this->slug => $id ), |
|
| 114 | - 'button-small' |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - return $permalink_string; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
| 124 | - * |
|
| 125 | - * @param string $action name of the WP do_action() to hook into |
|
| 126 | - */ |
|
| 127 | - public function addActionIframeEmbedButton( $action ) |
|
| 128 | - { |
|
| 129 | - // add button for iframe code to event editor. |
|
| 130 | - add_action( |
|
| 131 | - $action, |
|
| 132 | - array( $this, 'addActionIframeEmbedButtonCallback' ), |
|
| 133 | - 10, 2 |
|
| 134 | - ); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return void |
|
| 141 | - */ |
|
| 142 | - public function addActionIframeEmbedButtonCallback() |
|
| 143 | - { |
|
| 144 | - echo $this->embedButtonHtml(); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
| 151 | - * |
|
| 152 | - * @param string $filter name of the WP apply_filters() to hook into |
|
| 153 | - * @param bool $append if true, will add iframe embed button to end of content, |
|
| 154 | - * else if false, will add to the beginning of the content |
|
| 155 | - */ |
|
| 156 | - public function addFilterIframeEmbedButton( $filter, $append = true ) |
|
| 157 | - { |
|
| 158 | - $this->append_filterable_content = $append; |
|
| 159 | - // add button for iframe code to event editor. |
|
| 160 | - add_filter( |
|
| 161 | - $filter, |
|
| 162 | - array( $this, 'addFilterIframeEmbedButtonCallback' ), |
|
| 163 | - 10 |
|
| 164 | - ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param array|string $filterable_content |
|
| 171 | - * @return array|string |
|
| 172 | - */ |
|
| 173 | - public function addFilterIframeEmbedButtonCallback( $filterable_content ) |
|
| 174 | - { |
|
| 175 | - $embedButtonHtml = $this->embedButtonHtml(); |
|
| 176 | - if ( is_array( $filterable_content ) ) { |
|
| 177 | - $filterable_content = $this->append_filterable_content |
|
| 178 | - ? $filterable_content + array( $this->route_name => $embedButtonHtml ) |
|
| 179 | - : array( $this->route_name => $embedButtonHtml ) + $filterable_content; |
|
| 180 | - } else { |
|
| 181 | - $filterable_content = $this->append_filterable_content |
|
| 182 | - ? $filterable_content . $embedButtonHtml |
|
| 183 | - : $embedButtonHtml . $filterable_content; |
|
| 184 | - } |
|
| 185 | - return $filterable_content; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * iframe_embed_html |
|
| 192 | - * |
|
| 193 | - * @param array $query_args |
|
| 194 | - * @param string $button_class |
|
| 195 | - * @return string |
|
| 196 | - */ |
|
| 197 | - public function embedButtonHtml( $query_args = array(), $button_class = '' ) |
|
| 198 | - { |
|
| 199 | - // incoming args will replace the defaults listed here in the second array (union preserves first array) |
|
| 200 | - $query_args = (array)$query_args + array( $this->route_name => 'iframe' ); |
|
| 201 | - $query_args = (array)apply_filters( |
|
| 202 | - 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
| 203 | - $query_args |
|
| 204 | - ); |
|
| 205 | - // add this route to our localized vars |
|
| 206 | - $iframe_module_routes = isset( \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] ) |
|
| 207 | - ? \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] |
|
| 208 | - : array(); |
|
| 209 | - $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
| 210 | - \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] = $iframe_module_routes; |
|
| 211 | - $iframe_embed_html = \EEH_HTML::link( |
|
| 212 | - '#', |
|
| 213 | - sprintf( esc_html__( 'Embed %1$s', 'event_espresso' ), $this->iframe_name ), |
|
| 214 | - sprintf( |
|
| 215 | - esc_html__( |
|
| 216 | - 'click here to generate code for embedding %1$s iframe into another site.', |
|
| 217 | - 'event_espresso' |
|
| 218 | - ), |
|
| 219 | - \EEH_Inflector::add_indefinite_article( $this->iframe_name ) |
|
| 220 | - ), |
|
| 221 | - "{$this->route_name}-iframe-embed-trigger-js", |
|
| 222 | - 'iframe-embed-trigger-js button ' . $button_class, |
|
| 223 | - '', |
|
| 224 | - ' data-iframe_embed_button="#' . $this->route_name . '-iframe-js" tabindex="-1"' |
|
| 225 | - ); |
|
| 226 | - $iframe_embed_html .= \EEH_HTML::div( '', "{$this->route_name}-iframe-js", 'iframe-embed-wrapper-js', |
|
| 227 | - 'display:none;' ); |
|
| 228 | - $iframe_embed_html .= esc_html( |
|
| 229 | - \EEH_HTML::div( |
|
| 230 | - '<iframe src="' . add_query_arg( $query_args, site_url() ) . '" width="100%" height="100%"></iframe>', |
|
| 231 | - '', |
|
| 232 | - '', |
|
| 233 | - 'width:100%; height: 500px;' |
|
| 234 | - ) |
|
| 235 | - ); |
|
| 236 | - $iframe_embed_html .= \EEH_HTML::divx(); |
|
| 237 | - return $iframe_embed_html; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * enqueue iframe button js |
|
| 244 | - */ |
|
| 245 | - public function embedButtonAssets() |
|
| 246 | - { |
|
| 247 | - \EE_Registry::$i18n_js_strings[ 'iframe_embed_title' ] = esc_html__( |
|
| 248 | - 'copy and paste the following into any other site\'s content to display this event:', |
|
| 249 | - 'event_espresso' |
|
| 250 | - ); |
|
| 251 | - \EE_Registry::$i18n_js_strings[ 'iframe_embed_close_msg' ] = esc_html__( |
|
| 252 | - 'click anywhere outside of this window to close it.', |
|
| 253 | - 'event_espresso' |
|
| 254 | - ); |
|
| 255 | - wp_register_script( |
|
| 256 | - 'iframe_embed_button', |
|
| 257 | - plugin_dir_url( __FILE__ ) . 'iframe-embed-button.js', |
|
| 258 | - array( 'ee-dialog' ), |
|
| 259 | - EVENT_ESPRESSO_VERSION, |
|
| 260 | - true |
|
| 261 | - ); |
|
| 262 | - wp_enqueue_script( 'iframe_embed_button' ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * generates embed button sections for admin pages |
|
| 269 | - * |
|
| 270 | - * @param array $embed_buttons |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public function addIframeEmbedButtonsSection( array $embed_buttons ) |
|
| 274 | - { |
|
| 275 | - $embed_buttons = (array)apply_filters( |
|
| 276 | - 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
| 277 | - $embed_buttons |
|
| 278 | - ); |
|
| 279 | - if ( empty($embed_buttons)) { |
|
| 280 | - return ''; |
|
| 281 | - } |
|
| 282 | - // add button for iframe code to event editor. |
|
| 283 | - $html = \EEH_HTML::br( 2 ); |
|
| 284 | - $html .= \EEH_HTML::h3( esc_html__( 'iFrame Embed Code', 'event_espresso' ) ); |
|
| 285 | - $html .= \EEH_HTML::p( |
|
| 286 | - esc_html__( |
|
| 287 | - 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
| 288 | - 'event_espresso' |
|
| 289 | - ) |
|
| 290 | - ); |
|
| 291 | - $html .= ' ' . implode( ' ', $embed_buttons ) . ' '; |
|
| 292 | - $html .= \EEH_HTML::br( 2 ); |
|
| 293 | - return $html; |
|
| 294 | - } |
|
| 19 | + /** |
|
| 20 | + * @var string $iframe_name |
|
| 21 | + */ |
|
| 22 | + private $iframe_name; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var string $route_name |
|
| 26 | + */ |
|
| 27 | + private $route_name; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var string $slug |
|
| 31 | + */ |
|
| 32 | + private $slug; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var boolean $append_filterable_content |
|
| 36 | + */ |
|
| 37 | + private $append_filterable_content; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * IframeEmbedButton constructor. |
|
| 43 | + * |
|
| 44 | + * @param string $iframe_name i18n name for the iframe. This will be used in HTML |
|
| 45 | + * @param string $route_name the name of the registered route |
|
| 46 | + * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
|
| 47 | + * will most likely be "event" since that's the only usage atm |
|
| 48 | + */ |
|
| 49 | + public function __construct( $iframe_name, $route_name, $slug = 'event' ) |
|
| 50 | + { |
|
| 51 | + $this->iframe_name = $iframe_name; |
|
| 52 | + $this->route_name = $route_name; |
|
| 53 | + $this->slug = $slug; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Adds an iframe embed code button to the Event editor. |
|
| 60 | + */ |
|
| 61 | + public function addEventEditorIframeEmbedButtonFilter() |
|
| 62 | + { |
|
| 63 | + // add button for iframe code to event editor. |
|
| 64 | + add_filter( |
|
| 65 | + 'get_sample_permalink_html', |
|
| 66 | + array( $this, 'appendIframeEmbedButtonToSamplePermalinkHtml' ), |
|
| 67 | + 10, |
|
| 68 | + 2 |
|
| 69 | + ); |
|
| 70 | + add_action( |
|
| 71 | + 'admin_enqueue_scripts', |
|
| 72 | + array( $this, 'embedButtonAssets' ), |
|
| 73 | + 10 |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param $permalink_string |
|
| 81 | + * @param $id |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + public function appendIframeEmbedButtonToSamplePermalinkHtml( $permalink_string, $id ) |
|
| 85 | + { |
|
| 86 | + return $this->eventEditorIframeEmbedButton( |
|
| 87 | + $permalink_string, |
|
| 88 | + $id |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * iframe embed code button to the Event editor. |
|
| 96 | + * |
|
| 97 | + * @param string $permalink_string |
|
| 98 | + * @param int $id |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public function eventEditorIframeEmbedButton( |
|
| 102 | + $permalink_string, |
|
| 103 | + $id |
|
| 104 | + ) { |
|
| 105 | + //make sure this is ONLY when editing and the event id has been set. |
|
| 106 | + if ( ! empty( $id ) ) { |
|
| 107 | + $post = get_post( $id ); |
|
| 108 | + //if NOT event then let's get out. |
|
| 109 | + if ( $post->post_type !== 'espresso_events' ) { |
|
| 110 | + return $permalink_string; |
|
| 111 | + } |
|
| 112 | + $permalink_string .= $this->embedButtonHtml( |
|
| 113 | + array( $this->slug => $id ), |
|
| 114 | + 'button-small' |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + return $permalink_string; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
| 124 | + * |
|
| 125 | + * @param string $action name of the WP do_action() to hook into |
|
| 126 | + */ |
|
| 127 | + public function addActionIframeEmbedButton( $action ) |
|
| 128 | + { |
|
| 129 | + // add button for iframe code to event editor. |
|
| 130 | + add_action( |
|
| 131 | + $action, |
|
| 132 | + array( $this, 'addActionIframeEmbedButtonCallback' ), |
|
| 133 | + 10, 2 |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return void |
|
| 141 | + */ |
|
| 142 | + public function addActionIframeEmbedButtonCallback() |
|
| 143 | + { |
|
| 144 | + echo $this->embedButtonHtml(); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
| 151 | + * |
|
| 152 | + * @param string $filter name of the WP apply_filters() to hook into |
|
| 153 | + * @param bool $append if true, will add iframe embed button to end of content, |
|
| 154 | + * else if false, will add to the beginning of the content |
|
| 155 | + */ |
|
| 156 | + public function addFilterIframeEmbedButton( $filter, $append = true ) |
|
| 157 | + { |
|
| 158 | + $this->append_filterable_content = $append; |
|
| 159 | + // add button for iframe code to event editor. |
|
| 160 | + add_filter( |
|
| 161 | + $filter, |
|
| 162 | + array( $this, 'addFilterIframeEmbedButtonCallback' ), |
|
| 163 | + 10 |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param array|string $filterable_content |
|
| 171 | + * @return array|string |
|
| 172 | + */ |
|
| 173 | + public function addFilterIframeEmbedButtonCallback( $filterable_content ) |
|
| 174 | + { |
|
| 175 | + $embedButtonHtml = $this->embedButtonHtml(); |
|
| 176 | + if ( is_array( $filterable_content ) ) { |
|
| 177 | + $filterable_content = $this->append_filterable_content |
|
| 178 | + ? $filterable_content + array( $this->route_name => $embedButtonHtml ) |
|
| 179 | + : array( $this->route_name => $embedButtonHtml ) + $filterable_content; |
|
| 180 | + } else { |
|
| 181 | + $filterable_content = $this->append_filterable_content |
|
| 182 | + ? $filterable_content . $embedButtonHtml |
|
| 183 | + : $embedButtonHtml . $filterable_content; |
|
| 184 | + } |
|
| 185 | + return $filterable_content; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * iframe_embed_html |
|
| 192 | + * |
|
| 193 | + * @param array $query_args |
|
| 194 | + * @param string $button_class |
|
| 195 | + * @return string |
|
| 196 | + */ |
|
| 197 | + public function embedButtonHtml( $query_args = array(), $button_class = '' ) |
|
| 198 | + { |
|
| 199 | + // incoming args will replace the defaults listed here in the second array (union preserves first array) |
|
| 200 | + $query_args = (array)$query_args + array( $this->route_name => 'iframe' ); |
|
| 201 | + $query_args = (array)apply_filters( |
|
| 202 | + 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
| 203 | + $query_args |
|
| 204 | + ); |
|
| 205 | + // add this route to our localized vars |
|
| 206 | + $iframe_module_routes = isset( \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] ) |
|
| 207 | + ? \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] |
|
| 208 | + : array(); |
|
| 209 | + $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
| 210 | + \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] = $iframe_module_routes; |
|
| 211 | + $iframe_embed_html = \EEH_HTML::link( |
|
| 212 | + '#', |
|
| 213 | + sprintf( esc_html__( 'Embed %1$s', 'event_espresso' ), $this->iframe_name ), |
|
| 214 | + sprintf( |
|
| 215 | + esc_html__( |
|
| 216 | + 'click here to generate code for embedding %1$s iframe into another site.', |
|
| 217 | + 'event_espresso' |
|
| 218 | + ), |
|
| 219 | + \EEH_Inflector::add_indefinite_article( $this->iframe_name ) |
|
| 220 | + ), |
|
| 221 | + "{$this->route_name}-iframe-embed-trigger-js", |
|
| 222 | + 'iframe-embed-trigger-js button ' . $button_class, |
|
| 223 | + '', |
|
| 224 | + ' data-iframe_embed_button="#' . $this->route_name . '-iframe-js" tabindex="-1"' |
|
| 225 | + ); |
|
| 226 | + $iframe_embed_html .= \EEH_HTML::div( '', "{$this->route_name}-iframe-js", 'iframe-embed-wrapper-js', |
|
| 227 | + 'display:none;' ); |
|
| 228 | + $iframe_embed_html .= esc_html( |
|
| 229 | + \EEH_HTML::div( |
|
| 230 | + '<iframe src="' . add_query_arg( $query_args, site_url() ) . '" width="100%" height="100%"></iframe>', |
|
| 231 | + '', |
|
| 232 | + '', |
|
| 233 | + 'width:100%; height: 500px;' |
|
| 234 | + ) |
|
| 235 | + ); |
|
| 236 | + $iframe_embed_html .= \EEH_HTML::divx(); |
|
| 237 | + return $iframe_embed_html; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * enqueue iframe button js |
|
| 244 | + */ |
|
| 245 | + public function embedButtonAssets() |
|
| 246 | + { |
|
| 247 | + \EE_Registry::$i18n_js_strings[ 'iframe_embed_title' ] = esc_html__( |
|
| 248 | + 'copy and paste the following into any other site\'s content to display this event:', |
|
| 249 | + 'event_espresso' |
|
| 250 | + ); |
|
| 251 | + \EE_Registry::$i18n_js_strings[ 'iframe_embed_close_msg' ] = esc_html__( |
|
| 252 | + 'click anywhere outside of this window to close it.', |
|
| 253 | + 'event_espresso' |
|
| 254 | + ); |
|
| 255 | + wp_register_script( |
|
| 256 | + 'iframe_embed_button', |
|
| 257 | + plugin_dir_url( __FILE__ ) . 'iframe-embed-button.js', |
|
| 258 | + array( 'ee-dialog' ), |
|
| 259 | + EVENT_ESPRESSO_VERSION, |
|
| 260 | + true |
|
| 261 | + ); |
|
| 262 | + wp_enqueue_script( 'iframe_embed_button' ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * generates embed button sections for admin pages |
|
| 269 | + * |
|
| 270 | + * @param array $embed_buttons |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public function addIframeEmbedButtonsSection( array $embed_buttons ) |
|
| 274 | + { |
|
| 275 | + $embed_buttons = (array)apply_filters( |
|
| 276 | + 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
| 277 | + $embed_buttons |
|
| 278 | + ); |
|
| 279 | + if ( empty($embed_buttons)) { |
|
| 280 | + return ''; |
|
| 281 | + } |
|
| 282 | + // add button for iframe code to event editor. |
|
| 283 | + $html = \EEH_HTML::br( 2 ); |
|
| 284 | + $html .= \EEH_HTML::h3( esc_html__( 'iFrame Embed Code', 'event_espresso' ) ); |
|
| 285 | + $html .= \EEH_HTML::p( |
|
| 286 | + esc_html__( |
|
| 287 | + 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
| 288 | + 'event_espresso' |
|
| 289 | + ) |
|
| 290 | + ); |
|
| 291 | + $html .= ' ' . implode( ' ', $embed_buttons ) . ' '; |
|
| 292 | + $html .= \EEH_HTML::br( 2 ); |
|
| 293 | + return $html; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | 296 | |
| 297 | 297 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\libraries\iframe_display; |
| 3 | 3 | |
| 4 | -defined( 'ABSPATH' ) || exit; |
|
| 4 | +defined('ABSPATH') || exit; |
|
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
| 47 | 47 | * will most likely be "event" since that's the only usage atm |
| 48 | 48 | */ |
| 49 | - public function __construct( $iframe_name, $route_name, $slug = 'event' ) |
|
| 49 | + public function __construct($iframe_name, $route_name, $slug = 'event') |
|
| 50 | 50 | { |
| 51 | 51 | $this->iframe_name = $iframe_name; |
| 52 | 52 | $this->route_name = $route_name; |
@@ -63,13 +63,13 @@ discard block |
||
| 63 | 63 | // add button for iframe code to event editor. |
| 64 | 64 | add_filter( |
| 65 | 65 | 'get_sample_permalink_html', |
| 66 | - array( $this, 'appendIframeEmbedButtonToSamplePermalinkHtml' ), |
|
| 66 | + array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'), |
|
| 67 | 67 | 10, |
| 68 | 68 | 2 |
| 69 | 69 | ); |
| 70 | 70 | add_action( |
| 71 | 71 | 'admin_enqueue_scripts', |
| 72 | - array( $this, 'embedButtonAssets' ), |
|
| 72 | + array($this, 'embedButtonAssets'), |
|
| 73 | 73 | 10 |
| 74 | 74 | ); |
| 75 | 75 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param $id |
| 82 | 82 | * @return string |
| 83 | 83 | */ |
| 84 | - public function appendIframeEmbedButtonToSamplePermalinkHtml( $permalink_string, $id ) |
|
| 84 | + public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id) |
|
| 85 | 85 | { |
| 86 | 86 | return $this->eventEditorIframeEmbedButton( |
| 87 | 87 | $permalink_string, |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | $id |
| 104 | 104 | ) { |
| 105 | 105 | //make sure this is ONLY when editing and the event id has been set. |
| 106 | - if ( ! empty( $id ) ) { |
|
| 107 | - $post = get_post( $id ); |
|
| 106 | + if ( ! empty($id)) { |
|
| 107 | + $post = get_post($id); |
|
| 108 | 108 | //if NOT event then let's get out. |
| 109 | - if ( $post->post_type !== 'espresso_events' ) { |
|
| 109 | + if ($post->post_type !== 'espresso_events') { |
|
| 110 | 110 | return $permalink_string; |
| 111 | 111 | } |
| 112 | 112 | $permalink_string .= $this->embedButtonHtml( |
| 113 | - array( $this->slug => $id ), |
|
| 113 | + array($this->slug => $id), |
|
| 114 | 114 | 'button-small' |
| 115 | 115 | ); |
| 116 | 116 | } |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @param string $action name of the WP do_action() to hook into |
| 126 | 126 | */ |
| 127 | - public function addActionIframeEmbedButton( $action ) |
|
| 127 | + public function addActionIframeEmbedButton($action) |
|
| 128 | 128 | { |
| 129 | 129 | // add button for iframe code to event editor. |
| 130 | 130 | add_action( |
| 131 | 131 | $action, |
| 132 | - array( $this, 'addActionIframeEmbedButtonCallback' ), |
|
| 132 | + array($this, 'addActionIframeEmbedButtonCallback'), |
|
| 133 | 133 | 10, 2 |
| 134 | 134 | ); |
| 135 | 135 | } |
@@ -153,13 +153,13 @@ discard block |
||
| 153 | 153 | * @param bool $append if true, will add iframe embed button to end of content, |
| 154 | 154 | * else if false, will add to the beginning of the content |
| 155 | 155 | */ |
| 156 | - public function addFilterIframeEmbedButton( $filter, $append = true ) |
|
| 156 | + public function addFilterIframeEmbedButton($filter, $append = true) |
|
| 157 | 157 | { |
| 158 | 158 | $this->append_filterable_content = $append; |
| 159 | 159 | // add button for iframe code to event editor. |
| 160 | 160 | add_filter( |
| 161 | 161 | $filter, |
| 162 | - array( $this, 'addFilterIframeEmbedButtonCallback' ), |
|
| 162 | + array($this, 'addFilterIframeEmbedButtonCallback'), |
|
| 163 | 163 | 10 |
| 164 | 164 | ); |
| 165 | 165 | } |
@@ -170,17 +170,17 @@ discard block |
||
| 170 | 170 | * @param array|string $filterable_content |
| 171 | 171 | * @return array|string |
| 172 | 172 | */ |
| 173 | - public function addFilterIframeEmbedButtonCallback( $filterable_content ) |
|
| 173 | + public function addFilterIframeEmbedButtonCallback($filterable_content) |
|
| 174 | 174 | { |
| 175 | 175 | $embedButtonHtml = $this->embedButtonHtml(); |
| 176 | - if ( is_array( $filterable_content ) ) { |
|
| 176 | + if (is_array($filterable_content)) { |
|
| 177 | 177 | $filterable_content = $this->append_filterable_content |
| 178 | - ? $filterable_content + array( $this->route_name => $embedButtonHtml ) |
|
| 179 | - : array( $this->route_name => $embedButtonHtml ) + $filterable_content; |
|
| 178 | + ? $filterable_content + array($this->route_name => $embedButtonHtml) |
|
| 179 | + : array($this->route_name => $embedButtonHtml) + $filterable_content; |
|
| 180 | 180 | } else { |
| 181 | 181 | $filterable_content = $this->append_filterable_content |
| 182 | - ? $filterable_content . $embedButtonHtml |
|
| 183 | - : $embedButtonHtml . $filterable_content; |
|
| 182 | + ? $filterable_content.$embedButtonHtml |
|
| 183 | + : $embedButtonHtml.$filterable_content; |
|
| 184 | 184 | } |
| 185 | 185 | return $filterable_content; |
| 186 | 186 | } |
@@ -194,40 +194,40 @@ discard block |
||
| 194 | 194 | * @param string $button_class |
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | - public function embedButtonHtml( $query_args = array(), $button_class = '' ) |
|
| 197 | + public function embedButtonHtml($query_args = array(), $button_class = '') |
|
| 198 | 198 | { |
| 199 | 199 | // incoming args will replace the defaults listed here in the second array (union preserves first array) |
| 200 | - $query_args = (array)$query_args + array( $this->route_name => 'iframe' ); |
|
| 201 | - $query_args = (array)apply_filters( |
|
| 200 | + $query_args = (array) $query_args + array($this->route_name => 'iframe'); |
|
| 201 | + $query_args = (array) apply_filters( |
|
| 202 | 202 | 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
| 203 | 203 | $query_args |
| 204 | 204 | ); |
| 205 | 205 | // add this route to our localized vars |
| 206 | - $iframe_module_routes = isset( \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] ) |
|
| 207 | - ? \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] |
|
| 206 | + $iframe_module_routes = isset(\EE_Registry::$i18n_js_strings['iframe_module_routes']) |
|
| 207 | + ? \EE_Registry::$i18n_js_strings['iframe_module_routes'] |
|
| 208 | 208 | : array(); |
| 209 | - $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
| 210 | - \EE_Registry::$i18n_js_strings[ 'iframe_module_routes' ] = $iframe_module_routes; |
|
| 209 | + $iframe_module_routes[$this->route_name] = $this->route_name; |
|
| 210 | + \EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
|
| 211 | 211 | $iframe_embed_html = \EEH_HTML::link( |
| 212 | 212 | '#', |
| 213 | - sprintf( esc_html__( 'Embed %1$s', 'event_espresso' ), $this->iframe_name ), |
|
| 213 | + sprintf(esc_html__('Embed %1$s', 'event_espresso'), $this->iframe_name), |
|
| 214 | 214 | sprintf( |
| 215 | 215 | esc_html__( |
| 216 | 216 | 'click here to generate code for embedding %1$s iframe into another site.', |
| 217 | 217 | 'event_espresso' |
| 218 | 218 | ), |
| 219 | - \EEH_Inflector::add_indefinite_article( $this->iframe_name ) |
|
| 219 | + \EEH_Inflector::add_indefinite_article($this->iframe_name) |
|
| 220 | 220 | ), |
| 221 | 221 | "{$this->route_name}-iframe-embed-trigger-js", |
| 222 | - 'iframe-embed-trigger-js button ' . $button_class, |
|
| 222 | + 'iframe-embed-trigger-js button '.$button_class, |
|
| 223 | 223 | '', |
| 224 | - ' data-iframe_embed_button="#' . $this->route_name . '-iframe-js" tabindex="-1"' |
|
| 224 | + ' data-iframe_embed_button="#'.$this->route_name.'-iframe-js" tabindex="-1"' |
|
| 225 | 225 | ); |
| 226 | - $iframe_embed_html .= \EEH_HTML::div( '', "{$this->route_name}-iframe-js", 'iframe-embed-wrapper-js', |
|
| 227 | - 'display:none;' ); |
|
| 226 | + $iframe_embed_html .= \EEH_HTML::div('', "{$this->route_name}-iframe-js", 'iframe-embed-wrapper-js', |
|
| 227 | + 'display:none;'); |
|
| 228 | 228 | $iframe_embed_html .= esc_html( |
| 229 | 229 | \EEH_HTML::div( |
| 230 | - '<iframe src="' . add_query_arg( $query_args, site_url() ) . '" width="100%" height="100%"></iframe>', |
|
| 230 | + '<iframe src="'.add_query_arg($query_args, site_url()).'" width="100%" height="100%"></iframe>', |
|
| 231 | 231 | '', |
| 232 | 232 | '', |
| 233 | 233 | 'width:100%; height: 500px;' |
@@ -244,22 +244,22 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public function embedButtonAssets() |
| 246 | 246 | { |
| 247 | - \EE_Registry::$i18n_js_strings[ 'iframe_embed_title' ] = esc_html__( |
|
| 247 | + \EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__( |
|
| 248 | 248 | 'copy and paste the following into any other site\'s content to display this event:', |
| 249 | 249 | 'event_espresso' |
| 250 | 250 | ); |
| 251 | - \EE_Registry::$i18n_js_strings[ 'iframe_embed_close_msg' ] = esc_html__( |
|
| 251 | + \EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__( |
|
| 252 | 252 | 'click anywhere outside of this window to close it.', |
| 253 | 253 | 'event_espresso' |
| 254 | 254 | ); |
| 255 | 255 | wp_register_script( |
| 256 | 256 | 'iframe_embed_button', |
| 257 | - plugin_dir_url( __FILE__ ) . 'iframe-embed-button.js', |
|
| 258 | - array( 'ee-dialog' ), |
|
| 257 | + plugin_dir_url(__FILE__).'iframe-embed-button.js', |
|
| 258 | + array('ee-dialog'), |
|
| 259 | 259 | EVENT_ESPRESSO_VERSION, |
| 260 | 260 | true |
| 261 | 261 | ); |
| 262 | - wp_enqueue_script( 'iframe_embed_button' ); |
|
| 262 | + wp_enqueue_script('iframe_embed_button'); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -270,26 +270,26 @@ discard block |
||
| 270 | 270 | * @param array $embed_buttons |
| 271 | 271 | * @return string |
| 272 | 272 | */ |
| 273 | - public function addIframeEmbedButtonsSection( array $embed_buttons ) |
|
| 273 | + public function addIframeEmbedButtonsSection(array $embed_buttons) |
|
| 274 | 274 | { |
| 275 | - $embed_buttons = (array)apply_filters( |
|
| 275 | + $embed_buttons = (array) apply_filters( |
|
| 276 | 276 | 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
| 277 | 277 | $embed_buttons |
| 278 | 278 | ); |
| 279 | - if ( empty($embed_buttons)) { |
|
| 279 | + if (empty($embed_buttons)) { |
|
| 280 | 280 | return ''; |
| 281 | 281 | } |
| 282 | 282 | // add button for iframe code to event editor. |
| 283 | - $html = \EEH_HTML::br( 2 ); |
|
| 284 | - $html .= \EEH_HTML::h3( esc_html__( 'iFrame Embed Code', 'event_espresso' ) ); |
|
| 283 | + $html = \EEH_HTML::br(2); |
|
| 284 | + $html .= \EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso')); |
|
| 285 | 285 | $html .= \EEH_HTML::p( |
| 286 | 286 | esc_html__( |
| 287 | 287 | 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
| 288 | 288 | 'event_espresso' |
| 289 | 289 | ) |
| 290 | 290 | ); |
| 291 | - $html .= ' ' . implode( ' ', $embed_buttons ) . ' '; |
|
| 292 | - $html .= \EEH_HTML::br( 2 ); |
|
| 291 | + $html .= ' '.implode(' ', $embed_buttons).' '; |
|
| 292 | + $html .= \EEH_HTML::br(2); |
|
| 293 | 293 | return $html; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -15,21 +15,21 @@ discard block |
||
| 15 | 15 | class EventListIframeEmbedButton extends IframeEmbedButton |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * EventListIframeEmbedButton constructor. |
|
| 20 | - */ |
|
| 21 | - public function __construct() |
|
| 22 | - { |
|
| 23 | - parent::__construct( |
|
| 24 | - esc_html__( 'Event List', 'event_espresso' ), |
|
| 25 | - 'event_list' |
|
| 26 | - ); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * EventListIframeEmbedButton constructor. |
|
| 20 | + */ |
|
| 21 | + public function __construct() |
|
| 22 | + { |
|
| 23 | + parent::__construct( |
|
| 24 | + esc_html__( 'Event List', 'event_espresso' ), |
|
| 25 | + 'event_list' |
|
| 26 | + ); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | public function addEmbedButton() { |
| 32 | - add_filter( |
|
| 32 | + add_filter( |
|
| 33 | 33 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
| 34 | 34 | array( $this, 'addEventListIframeEmbedButtonSection' ) |
| 35 | 35 | ); |
@@ -49,19 +49,19 @@ discard block |
||
| 49 | 49 | * @param array $after_list_table |
| 50 | 50 | * @return array |
| 51 | 51 | */ |
| 52 | - public function addEventListIframeEmbedButtonSection( array $after_list_table ) |
|
| 53 | - { |
|
| 54 | - return \EEH_Array::insert_into_array( |
|
| 55 | - $after_list_table, |
|
| 56 | - array( |
|
| 57 | - 'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection( |
|
| 58 | - array() |
|
| 59 | - // array( 'event_list' => $this->embedButtonHtml() ) |
|
| 60 | - ) |
|
| 61 | - ), |
|
| 62 | - 'legend' |
|
| 63 | - ); |
|
| 64 | - } |
|
| 52 | + public function addEventListIframeEmbedButtonSection( array $after_list_table ) |
|
| 53 | + { |
|
| 54 | + return \EEH_Array::insert_into_array( |
|
| 55 | + $after_list_table, |
|
| 56 | + array( |
|
| 57 | + 'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection( |
|
| 58 | + array() |
|
| 59 | + // array( 'event_list' => $this->embedButtonHtml() ) |
|
| 60 | + ) |
|
| 61 | + ), |
|
| 62 | + 'legend' |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\libraries\iframe_display; |
| 3 | 3 | |
| 4 | -defined( 'ABSPATH' ) || exit; |
|
| 4 | +defined('ABSPATH') || exit; |
|
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | public function __construct() |
| 22 | 22 | { |
| 23 | 23 | parent::__construct( |
| 24 | - esc_html__( 'Event List', 'event_espresso' ), |
|
| 24 | + esc_html__('Event List', 'event_espresso'), |
|
| 25 | 25 | 'event_list' |
| 26 | 26 | ); |
| 27 | 27 | } |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | public function addEmbedButton() { |
| 32 | 32 | add_filter( |
| 33 | 33 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
| 34 | - array( $this, 'addEventListIframeEmbedButtonSection' ) |
|
| 34 | + array($this, 'addEventListIframeEmbedButtonSection') |
|
| 35 | 35 | ); |
| 36 | 36 | add_action( |
| 37 | 37 | 'admin_enqueue_scripts', |
| 38 | - array( $this, 'embedButtonAssets' ), |
|
| 38 | + array($this, 'embedButtonAssets'), |
|
| 39 | 39 | 10 |
| 40 | 40 | ); |
| 41 | 41 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @param array $after_list_table |
| 50 | 50 | * @return array |
| 51 | 51 | */ |
| 52 | - public function addEventListIframeEmbedButtonSection( array $after_list_table ) |
|
| 52 | + public function addEventListIframeEmbedButtonSection(array $after_list_table) |
|
| 53 | 53 | { |
| 54 | 54 | return \EEH_Array::insert_into_array( |
| 55 | 55 | $after_list_table, |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.27.rc.020'); |
|
| 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.27.rc.020'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - // for older WP versions |
|
| 197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | - } |
|
| 200 | - /** |
|
| 201 | - * espresso_plugin_activation |
|
| 202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | - */ |
|
| 204 | - function espresso_plugin_activation() |
|
| 205 | - { |
|
| 206 | - update_option('ee_espresso_activation', true); |
|
| 207 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + // for older WP versions |
|
| 197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | + } |
|
| 200 | + /** |
|
| 201 | + * espresso_plugin_activation |
|
| 202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | + */ |
|
| 204 | + function espresso_plugin_activation() |
|
| 205 | + { |
|
| 206 | + update_option('ee_espresso_activation', true); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | - /** |
|
| 211 | - * espresso_load_error_handling |
|
| 212 | - * this function loads EE's class for handling exceptions and errors |
|
| 213 | - */ |
|
| 214 | - function espresso_load_error_handling() |
|
| 215 | - { |
|
| 216 | - // load debugging tools |
|
| 217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | - EEH_Debug_Tools::instance(); |
|
| 220 | - } |
|
| 221 | - // load error handling |
|
| 222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | - } else { |
|
| 225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | - } |
|
| 227 | - } |
|
| 209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | + /** |
|
| 211 | + * espresso_load_error_handling |
|
| 212 | + * this function loads EE's class for handling exceptions and errors |
|
| 213 | + */ |
|
| 214 | + function espresso_load_error_handling() |
|
| 215 | + { |
|
| 216 | + // load debugging tools |
|
| 217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | + EEH_Debug_Tools::instance(); |
|
| 220 | + } |
|
| 221 | + // load error handling |
|
| 222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | + } else { |
|
| 225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * espresso_load_required |
|
| 231 | - * given a class name and path, this function will load that file or throw an exception |
|
| 232 | - * |
|
| 233 | - * @param string $classname |
|
| 234 | - * @param string $full_path_to_file |
|
| 235 | - * @throws EE_Error |
|
| 236 | - */ |
|
| 237 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | - { |
|
| 239 | - static $error_handling_loaded = false; |
|
| 240 | - if ( ! $error_handling_loaded) { |
|
| 241 | - espresso_load_error_handling(); |
|
| 242 | - $error_handling_loaded = true; |
|
| 243 | - } |
|
| 244 | - if (is_readable($full_path_to_file)) { |
|
| 245 | - require_once($full_path_to_file); |
|
| 246 | - } else { |
|
| 247 | - throw new EE_Error ( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $classname |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 229 | + /** |
|
| 230 | + * espresso_load_required |
|
| 231 | + * given a class name and path, this function will load that file or throw an exception |
|
| 232 | + * |
|
| 233 | + * @param string $classname |
|
| 234 | + * @param string $full_path_to_file |
|
| 235 | + * @throws EE_Error |
|
| 236 | + */ |
|
| 237 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | + { |
|
| 239 | + static $error_handling_loaded = false; |
|
| 240 | + if ( ! $error_handling_loaded) { |
|
| 241 | + espresso_load_error_handling(); |
|
| 242 | + $error_handling_loaded = true; |
|
| 243 | + } |
|
| 244 | + if (is_readable($full_path_to_file)) { |
|
| 245 | + require_once($full_path_to_file); |
|
| 246 | + } else { |
|
| 247 | + throw new EE_Error ( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $classname |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | - new EE_Bootstrap(); |
|
| 263 | - } |
|
| 259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | + new EE_Bootstrap(); |
|
| 263 | + } |
|
| 264 | 264 | } |
| 265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 266 | - /** |
|
| 267 | - * deactivate_plugin |
|
| 268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | - * |
|
| 270 | - * @access public |
|
| 271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | - { |
|
| 276 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | - } |
|
| 279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | - deactivate_plugins($plugin_basename); |
|
| 281 | - } |
|
| 266 | + /** |
|
| 267 | + * deactivate_plugin |
|
| 268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | + * |
|
| 270 | + * @access public |
|
| 271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | + { |
|
| 276 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | + } |
|
| 279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | + deactivate_plugins($plugin_basename); |
|
| 281 | + } |
|
| 282 | 282 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -14,243 +14,243 @@ discard block |
||
| 14 | 14 | class EEH_Activation |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * constant used to indicate a cron task is no longer in use |
|
| 19 | - */ |
|
| 20 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * option name that will indicate whether or not we still |
|
| 24 | - * need to create EE's folders in the uploads directory |
|
| 25 | - * (because if EE was installed without file system access, |
|
| 26 | - * we need to request credentials before we can create them) |
|
| 27 | - */ |
|
| 28 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * WP_User->ID |
|
| 32 | - * |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - private static $_default_creator_id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * indicates whether or not we've already verified core's default data during this request, |
|
| 39 | - * because after migrations are done, any addons activated while in maintenance mode |
|
| 40 | - * will want to setup their own default data, and they might hook into core's default data |
|
| 41 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 42 | - * This prevents doing that for EVERY single addon. |
|
| 43 | - * |
|
| 44 | - * @var boolean |
|
| 45 | - */ |
|
| 46 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 50 | - */ |
|
| 51 | - private static $table_analysis; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 55 | - */ |
|
| 56 | - private static $table_manager; |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 61 | - */ |
|
| 62 | - public static function getTableAnalysis() |
|
| 63 | - { |
|
| 64 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 66 | - } |
|
| 67 | - return self::$table_analysis; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return \EventEspresso\core\services\database\TableManager |
|
| 73 | - */ |
|
| 74 | - public static function getTableManager() |
|
| 75 | - { |
|
| 76 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 78 | - } |
|
| 79 | - return self::$table_manager; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * _ensure_table_name_has_prefix |
|
| 85 | - * |
|
| 86 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 87 | - * @access public |
|
| 88 | - * @static |
|
| 89 | - * @param $table_name |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public static function ensure_table_name_has_prefix($table_name) |
|
| 93 | - { |
|
| 94 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * system_initialization |
|
| 100 | - * ensures the EE configuration settings are loaded with at least default options set |
|
| 101 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @static |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public static function system_initialization() |
|
| 108 | - { |
|
| 109 | - EEH_Activation::reset_and_update_config(); |
|
| 110 | - //which is fired BEFORE activation of plugin anyways |
|
| 111 | - EEH_Activation::verify_default_pages_exist(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Sets the database schema and creates folders. This should |
|
| 117 | - * be called on plugin activation and reactivation |
|
| 118 | - * |
|
| 119 | - * @return boolean success, whether the database and folders are setup properly |
|
| 120 | - * @throws \EE_Error |
|
| 121 | - */ |
|
| 122 | - public static function initialize_db_and_folders() |
|
| 123 | - { |
|
| 124 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 125 | - $good_db = EEH_Activation::create_database_tables(); |
|
| 126 | - return $good_filesystem && $good_db; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * assuming we have an up-to-date database schema, this will populate it |
|
| 132 | - * with default and initial data. This should be called |
|
| 133 | - * upon activation of a new plugin, reactivation, and at the end |
|
| 134 | - * of running migration scripts |
|
| 135 | - * |
|
| 136 | - * @throws \EE_Error |
|
| 137 | - */ |
|
| 138 | - public static function initialize_db_content() |
|
| 139 | - { |
|
| 140 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 141 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 142 | - return; |
|
| 143 | - } |
|
| 144 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 145 | - |
|
| 146 | - EEH_Activation::initialize_system_questions(); |
|
| 147 | - EEH_Activation::insert_default_status_codes(); |
|
| 148 | - EEH_Activation::generate_default_message_templates(); |
|
| 149 | - EEH_Activation::create_no_ticket_prices_array(); |
|
| 150 | - EE_Registry::instance()->CAP->init_caps(); |
|
| 151 | - |
|
| 152 | - EEH_Activation::validate_messages_system(); |
|
| 153 | - EEH_Activation::insert_default_payment_methods(); |
|
| 154 | - //in case we've |
|
| 155 | - EEH_Activation::remove_cron_tasks(); |
|
| 156 | - EEH_Activation::create_cron_tasks(); |
|
| 157 | - // remove all TXN locks since that is being done via extra meta now |
|
| 158 | - delete_option('ee_locked_transactions'); |
|
| 159 | - //also, check for CAF default db content |
|
| 160 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 161 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 162 | - //which users really won't care about on initial activation |
|
| 163 | - EE_Error::overwrite_success(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 169 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 170 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 171 | - * (null) |
|
| 172 | - * |
|
| 173 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 174 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 175 | - * @return array |
|
| 176 | - * @throws \EE_Error |
|
| 177 | - */ |
|
| 178 | - public static function get_cron_tasks($which_to_include) |
|
| 179 | - { |
|
| 180 | - $cron_tasks = apply_filters( |
|
| 181 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 182 | - array( |
|
| 183 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 17 | + /** |
|
| 18 | + * constant used to indicate a cron task is no longer in use |
|
| 19 | + */ |
|
| 20 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * option name that will indicate whether or not we still |
|
| 24 | + * need to create EE's folders in the uploads directory |
|
| 25 | + * (because if EE was installed without file system access, |
|
| 26 | + * we need to request credentials before we can create them) |
|
| 27 | + */ |
|
| 28 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * WP_User->ID |
|
| 32 | + * |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + private static $_default_creator_id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * indicates whether or not we've already verified core's default data during this request, |
|
| 39 | + * because after migrations are done, any addons activated while in maintenance mode |
|
| 40 | + * will want to setup their own default data, and they might hook into core's default data |
|
| 41 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 42 | + * This prevents doing that for EVERY single addon. |
|
| 43 | + * |
|
| 44 | + * @var boolean |
|
| 45 | + */ |
|
| 46 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 50 | + */ |
|
| 51 | + private static $table_analysis; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 55 | + */ |
|
| 56 | + private static $table_manager; |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 61 | + */ |
|
| 62 | + public static function getTableAnalysis() |
|
| 63 | + { |
|
| 64 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 66 | + } |
|
| 67 | + return self::$table_analysis; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return \EventEspresso\core\services\database\TableManager |
|
| 73 | + */ |
|
| 74 | + public static function getTableManager() |
|
| 75 | + { |
|
| 76 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 78 | + } |
|
| 79 | + return self::$table_manager; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * _ensure_table_name_has_prefix |
|
| 85 | + * |
|
| 86 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 87 | + * @access public |
|
| 88 | + * @static |
|
| 89 | + * @param $table_name |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public static function ensure_table_name_has_prefix($table_name) |
|
| 93 | + { |
|
| 94 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * system_initialization |
|
| 100 | + * ensures the EE configuration settings are loaded with at least default options set |
|
| 101 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @static |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public static function system_initialization() |
|
| 108 | + { |
|
| 109 | + EEH_Activation::reset_and_update_config(); |
|
| 110 | + //which is fired BEFORE activation of plugin anyways |
|
| 111 | + EEH_Activation::verify_default_pages_exist(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Sets the database schema and creates folders. This should |
|
| 117 | + * be called on plugin activation and reactivation |
|
| 118 | + * |
|
| 119 | + * @return boolean success, whether the database and folders are setup properly |
|
| 120 | + * @throws \EE_Error |
|
| 121 | + */ |
|
| 122 | + public static function initialize_db_and_folders() |
|
| 123 | + { |
|
| 124 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 125 | + $good_db = EEH_Activation::create_database_tables(); |
|
| 126 | + return $good_filesystem && $good_db; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * assuming we have an up-to-date database schema, this will populate it |
|
| 132 | + * with default and initial data. This should be called |
|
| 133 | + * upon activation of a new plugin, reactivation, and at the end |
|
| 134 | + * of running migration scripts |
|
| 135 | + * |
|
| 136 | + * @throws \EE_Error |
|
| 137 | + */ |
|
| 138 | + public static function initialize_db_content() |
|
| 139 | + { |
|
| 140 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 141 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 142 | + return; |
|
| 143 | + } |
|
| 144 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 145 | + |
|
| 146 | + EEH_Activation::initialize_system_questions(); |
|
| 147 | + EEH_Activation::insert_default_status_codes(); |
|
| 148 | + EEH_Activation::generate_default_message_templates(); |
|
| 149 | + EEH_Activation::create_no_ticket_prices_array(); |
|
| 150 | + EE_Registry::instance()->CAP->init_caps(); |
|
| 151 | + |
|
| 152 | + EEH_Activation::validate_messages_system(); |
|
| 153 | + EEH_Activation::insert_default_payment_methods(); |
|
| 154 | + //in case we've |
|
| 155 | + EEH_Activation::remove_cron_tasks(); |
|
| 156 | + EEH_Activation::create_cron_tasks(); |
|
| 157 | + // remove all TXN locks since that is being done via extra meta now |
|
| 158 | + delete_option('ee_locked_transactions'); |
|
| 159 | + //also, check for CAF default db content |
|
| 160 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 161 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 162 | + //which users really won't care about on initial activation |
|
| 163 | + EE_Error::overwrite_success(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 169 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 170 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 171 | + * (null) |
|
| 172 | + * |
|
| 173 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 174 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 175 | + * @return array |
|
| 176 | + * @throws \EE_Error |
|
| 177 | + */ |
|
| 178 | + public static function get_cron_tasks($which_to_include) |
|
| 179 | + { |
|
| 180 | + $cron_tasks = apply_filters( |
|
| 181 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 182 | + array( |
|
| 183 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 184 | 184 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
| 185 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 186 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 187 | - ) |
|
| 188 | - ); |
|
| 189 | - if ($which_to_include === 'old') { |
|
| 190 | - $cron_tasks = array_filter( |
|
| 191 | - $cron_tasks, |
|
| 192 | - function ($value) { |
|
| 193 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 194 | - } |
|
| 195 | - ); |
|
| 196 | - } elseif ($which_to_include === 'current') { |
|
| 197 | - $cron_tasks = array_filter($cron_tasks); |
|
| 198 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 199 | - throw new EE_Error( |
|
| 200 | - sprintf( |
|
| 201 | - __( |
|
| 202 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 203 | - 'event_espresso' |
|
| 204 | - ), |
|
| 205 | - $which_to_include |
|
| 206 | - ) |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - return $cron_tasks; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 215 | - * |
|
| 216 | - * @throws \EE_Error |
|
| 217 | - */ |
|
| 218 | - public static function create_cron_tasks() |
|
| 219 | - { |
|
| 220 | - |
|
| 221 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 222 | - if (! wp_next_scheduled($hook_name)) { |
|
| 223 | - /** |
|
| 224 | - * This allows client code to define the initial start timestamp for this schedule. |
|
| 225 | - */ |
|
| 226 | - if (is_array($frequency) |
|
| 227 | - && count($frequency) === 2 |
|
| 228 | - && isset($frequency[0], $frequency[1]) |
|
| 229 | - ) { |
|
| 230 | - $start_timestamp = $frequency[0]; |
|
| 231 | - $frequency = $frequency[1]; |
|
| 232 | - } else { |
|
| 233 | - $start_timestamp = time(); |
|
| 234 | - } |
|
| 235 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Remove the currently-existing and now-removed cron tasks. |
|
| 244 | - * |
|
| 245 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 246 | - * @throws \EE_Error |
|
| 247 | - */ |
|
| 248 | - public static function remove_cron_tasks($remove_all = true) |
|
| 249 | - { |
|
| 250 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 251 | - $crons = _get_cron_array(); |
|
| 252 | - $crons = is_array($crons) ? $crons : array(); |
|
| 253 | - /* reminder of what $crons look like: |
|
| 185 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 186 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 187 | + ) |
|
| 188 | + ); |
|
| 189 | + if ($which_to_include === 'old') { |
|
| 190 | + $cron_tasks = array_filter( |
|
| 191 | + $cron_tasks, |
|
| 192 | + function ($value) { |
|
| 193 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 194 | + } |
|
| 195 | + ); |
|
| 196 | + } elseif ($which_to_include === 'current') { |
|
| 197 | + $cron_tasks = array_filter($cron_tasks); |
|
| 198 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 199 | + throw new EE_Error( |
|
| 200 | + sprintf( |
|
| 201 | + __( |
|
| 202 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 203 | + 'event_espresso' |
|
| 204 | + ), |
|
| 205 | + $which_to_include |
|
| 206 | + ) |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + return $cron_tasks; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 215 | + * |
|
| 216 | + * @throws \EE_Error |
|
| 217 | + */ |
|
| 218 | + public static function create_cron_tasks() |
|
| 219 | + { |
|
| 220 | + |
|
| 221 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 222 | + if (! wp_next_scheduled($hook_name)) { |
|
| 223 | + /** |
|
| 224 | + * This allows client code to define the initial start timestamp for this schedule. |
|
| 225 | + */ |
|
| 226 | + if (is_array($frequency) |
|
| 227 | + && count($frequency) === 2 |
|
| 228 | + && isset($frequency[0], $frequency[1]) |
|
| 229 | + ) { |
|
| 230 | + $start_timestamp = $frequency[0]; |
|
| 231 | + $frequency = $frequency[1]; |
|
| 232 | + } else { |
|
| 233 | + $start_timestamp = time(); |
|
| 234 | + } |
|
| 235 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Remove the currently-existing and now-removed cron tasks. |
|
| 244 | + * |
|
| 245 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 246 | + * @throws \EE_Error |
|
| 247 | + */ |
|
| 248 | + public static function remove_cron_tasks($remove_all = true) |
|
| 249 | + { |
|
| 250 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 251 | + $crons = _get_cron_array(); |
|
| 252 | + $crons = is_array($crons) ? $crons : array(); |
|
| 253 | + /* reminder of what $crons look like: |
|
| 254 | 254 | * Top-level keys are timestamps, and their values are arrays. |
| 255 | 255 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
| 256 | 256 | * and their values are arrays. |
@@ -267,966 +267,966 @@ discard block |
||
| 267 | 267 | * ... |
| 268 | 268 | * ... |
| 269 | 269 | */ |
| 270 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 271 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 272 | - if (is_array($hooks_to_fire_at_time)) { |
|
| 273 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 274 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 275 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 276 | - ) { |
|
| 277 | - unset($crons[$timestamp][$hook_name]); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - //also take care of any empty cron timestamps. |
|
| 281 | - if (empty($hooks_to_fire_at_time)) { |
|
| 282 | - unset($crons[$timestamp]); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - _set_cron_array($crons); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * CPT_initialization |
|
| 292 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 293 | - * |
|
| 294 | - * @access public |
|
| 295 | - * @static |
|
| 296 | - * @return void |
|
| 297 | - */ |
|
| 298 | - public static function CPT_initialization() |
|
| 299 | - { |
|
| 300 | - // register Custom Post Types |
|
| 301 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 302 | - flush_rewrite_rules(); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * reset_and_update_config |
|
| 309 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 310 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
| 311 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 312 | - * |
|
| 313 | - * @access public |
|
| 314 | - * @static |
|
| 315 | - * @return void |
|
| 316 | - */ |
|
| 317 | - public static function reset_and_update_config() |
|
| 318 | - { |
|
| 319 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 320 | - add_filter( |
|
| 321 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 322 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
| 323 | - 10, |
|
| 324 | - 3 |
|
| 325 | - ); |
|
| 326 | - //EE_Config::reset(); |
|
| 327 | - if (! EE_Config::logging_enabled()) { |
|
| 328 | - delete_option(EE_Config::LOG_NAME); |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * load_calendar_config |
|
| 335 | - * |
|
| 336 | - * @access public |
|
| 337 | - * @return void |
|
| 338 | - */ |
|
| 339 | - public static function load_calendar_config() |
|
| 340 | - { |
|
| 341 | - // grab array of all plugin folders and loop thru it |
|
| 342 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 343 | - if (empty($plugins)) { |
|
| 344 | - return; |
|
| 345 | - } |
|
| 346 | - foreach ($plugins as $plugin_path) { |
|
| 347 | - // grab plugin folder name from path |
|
| 348 | - $plugin = basename($plugin_path); |
|
| 349 | - // drill down to Espresso plugins |
|
| 350 | - // then to calendar related plugins |
|
| 351 | - if ( |
|
| 352 | - strpos($plugin, 'espresso') !== false |
|
| 353 | - || strpos($plugin, 'Espresso') !== false |
|
| 354 | - || strpos($plugin, 'ee4') !== false |
|
| 355 | - || strpos($plugin, 'EE4') !== false |
|
| 356 | - || strpos($plugin, 'calendar') !== false |
|
| 357 | - ) { |
|
| 358 | - // this is what we are looking for |
|
| 359 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 360 | - // does it exist in this folder ? |
|
| 361 | - if (is_readable($calendar_config)) { |
|
| 362 | - // YEAH! let's load it |
|
| 363 | - require_once($calendar_config); |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * _migrate_old_config_data |
|
| 373 | - * |
|
| 374 | - * @access public |
|
| 375 | - * @param array|stdClass $settings |
|
| 376 | - * @param string $config |
|
| 377 | - * @param \EE_Config $EE_Config |
|
| 378 | - * @return \stdClass |
|
| 379 | - */ |
|
| 380 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 381 | - { |
|
| 382 | - $convert_from_array = array('addons'); |
|
| 383 | - // in case old settings were saved as an array |
|
| 384 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 385 | - // convert existing settings to an object |
|
| 386 | - $config_array = $settings; |
|
| 387 | - $settings = new stdClass(); |
|
| 388 | - foreach ($config_array as $key => $value) { |
|
| 389 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 390 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 391 | - } else { |
|
| 392 | - $settings->{$key} = $value; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 396 | - } |
|
| 397 | - return $settings; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * deactivate_event_espresso |
|
| 403 | - * |
|
| 404 | - * @access public |
|
| 405 | - * @static |
|
| 406 | - * @return void |
|
| 407 | - */ |
|
| 408 | - public static function deactivate_event_espresso() |
|
| 409 | - { |
|
| 410 | - // check permissions |
|
| 411 | - if (current_user_can('activate_plugins')) { |
|
| 412 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * verify_default_pages_exist |
|
| 422 | - * |
|
| 423 | - * @access public |
|
| 424 | - * @static |
|
| 425 | - * @return void |
|
| 426 | - */ |
|
| 427 | - public static function verify_default_pages_exist() |
|
| 428 | - { |
|
| 429 | - $critical_page_problem = false; |
|
| 430 | - $critical_pages = array( |
|
| 431 | - array( |
|
| 432 | - 'id' => 'reg_page_id', |
|
| 433 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 434 | - 'post' => null, |
|
| 435 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
| 436 | - ), |
|
| 437 | - array( |
|
| 438 | - 'id' => 'txn_page_id', |
|
| 439 | - 'name' => __('Transactions', 'event_espresso'), |
|
| 440 | - 'post' => null, |
|
| 441 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 442 | - ), |
|
| 443 | - array( |
|
| 444 | - 'id' => 'thank_you_page_id', |
|
| 445 | - 'name' => __('Thank You', 'event_espresso'), |
|
| 446 | - 'post' => null, |
|
| 447 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
| 448 | - ), |
|
| 449 | - array( |
|
| 450 | - 'id' => 'cancel_page_id', |
|
| 451 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 452 | - 'post' => null, |
|
| 453 | - 'code' => 'ESPRESSO_CANCELLED', |
|
| 454 | - ), |
|
| 455 | - ); |
|
| 456 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 457 | - foreach ($critical_pages as $critical_page) { |
|
| 458 | - // is critical page ID set in config ? |
|
| 459 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 460 | - // attempt to find post by ID |
|
| 461 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 462 | - } |
|
| 463 | - // no dice? |
|
| 464 | - if ($critical_page['post'] === null) { |
|
| 465 | - // attempt to find post by title |
|
| 466 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 467 | - // still nothing? |
|
| 468 | - if ($critical_page['post'] === null) { |
|
| 469 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 470 | - // REALLY? Still nothing ??!?!? |
|
| 471 | - if ($critical_page['post'] === null) { |
|
| 472 | - $msg = __( |
|
| 473 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 474 | - 'event_espresso' |
|
| 475 | - ); |
|
| 476 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 477 | - break; |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - // track post_shortcodes |
|
| 482 | - if ($critical_page['post']) { |
|
| 483 | - EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
| 484 | - } |
|
| 485 | - // check that Post ID matches critical page ID in config |
|
| 486 | - if ( |
|
| 487 | - isset($critical_page['post']->ID) |
|
| 488 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 489 | - ) { |
|
| 490 | - //update Config with post ID |
|
| 491 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 492 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 493 | - $msg = __( |
|
| 494 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 495 | - 'event_espresso' |
|
| 496 | - ); |
|
| 497 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - $critical_page_problem = |
|
| 501 | - ! isset($critical_page['post']->post_status) |
|
| 502 | - || $critical_page['post']->post_status !== 'publish' |
|
| 503 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 504 | - ? true |
|
| 505 | - : $critical_page_problem; |
|
| 506 | - } |
|
| 507 | - if ($critical_page_problem) { |
|
| 508 | - $msg = sprintf( |
|
| 509 | - __( |
|
| 510 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 511 | - 'event_espresso' |
|
| 512 | - ), |
|
| 513 | - '<a href="' |
|
| 514 | - . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 515 | - . '">' |
|
| 516 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 517 | - . '</a>' |
|
| 518 | - ); |
|
| 519 | - EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 520 | - } |
|
| 521 | - if (EE_Error::has_notices()) { |
|
| 522 | - EE_Error::get_notices(false, true, true); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Returns the first post which uses the specified shortcode |
|
| 530 | - * |
|
| 531 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 532 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 533 | - * "[ESPRESSO_THANK_YOU" |
|
| 534 | - * (we don't search for the closing shortcode bracket because they might have added |
|
| 535 | - * parameter to the shortcode |
|
| 536 | - * @return WP_Post or NULl |
|
| 537 | - */ |
|
| 538 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 539 | - { |
|
| 540 | - global $wpdb; |
|
| 541 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 542 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 543 | - if ($post_id) { |
|
| 544 | - return get_post($post_id); |
|
| 545 | - } else { |
|
| 546 | - return null; |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * This function generates a post for critical espresso pages |
|
| 553 | - * |
|
| 554 | - * @access public |
|
| 555 | - * @static |
|
| 556 | - * @param array $critical_page |
|
| 557 | - * @return array |
|
| 558 | - */ |
|
| 559 | - public static function create_critical_page($critical_page) |
|
| 560 | - { |
|
| 561 | - |
|
| 562 | - $post_args = array( |
|
| 563 | - 'post_title' => $critical_page['name'], |
|
| 564 | - 'post_status' => 'publish', |
|
| 565 | - 'post_type' => 'page', |
|
| 566 | - 'comment_status' => 'closed', |
|
| 567 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 568 | - ); |
|
| 569 | - |
|
| 570 | - $post_id = wp_insert_post($post_args); |
|
| 571 | - if (! $post_id) { |
|
| 572 | - $msg = sprintf( |
|
| 573 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 574 | - $critical_page['name'] |
|
| 575 | - ); |
|
| 576 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 577 | - return $critical_page; |
|
| 578 | - } |
|
| 579 | - // get newly created post's details |
|
| 580 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 581 | - $msg = sprintf( |
|
| 582 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 583 | - $critical_page['name'] |
|
| 584 | - ); |
|
| 585 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - return $critical_page; |
|
| 589 | - |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * This function adds a critical page's shortcode to the post_shortcodes array |
|
| 598 | - * |
|
| 599 | - * @access private |
|
| 600 | - * @static |
|
| 601 | - * @param array $critical_page |
|
| 602 | - * @return void |
|
| 603 | - */ |
|
| 604 | - private static function _track_critical_page_post_shortcodes($critical_page = array()) |
|
| 605 | - { |
|
| 606 | - // check the goods |
|
| 607 | - if ( ! $critical_page['post'] instanceof WP_Post) { |
|
| 608 | - $msg = sprintf( |
|
| 609 | - __( |
|
| 610 | - 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', |
|
| 611 | - 'event_espresso' |
|
| 612 | - ), |
|
| 613 | - $critical_page['name'] |
|
| 614 | - ); |
|
| 615 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 616 | - return; |
|
| 617 | - } |
|
| 618 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 619 | - // map shortcode to post |
|
| 620 | - $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
| 621 | - // and make sure it's NOT added to the WP "Posts Page" |
|
| 622 | - // name of the WP Posts Page |
|
| 623 | - $posts_page = EE_Config::get_page_for_posts(); |
|
| 624 | - if (isset($EE_Core_Config->post_shortcodes[$posts_page])) { |
|
| 625 | - unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]); |
|
| 626 | - } |
|
| 627 | - if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) { |
|
| 628 | - unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]); |
|
| 629 | - } |
|
| 630 | - // update post_shortcode CFG |
|
| 631 | - if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 632 | - $msg = sprintf( |
|
| 633 | - __( |
|
| 634 | - 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', |
|
| 635 | - 'event_espresso' |
|
| 636 | - ), |
|
| 637 | - $critical_page['name'] |
|
| 638 | - ); |
|
| 639 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 647 | - * The role being used to check is filterable. |
|
| 648 | - * |
|
| 649 | - * @since 4.6.0 |
|
| 650 | - * @global WPDB $wpdb |
|
| 651 | - * @return mixed null|int WP_user ID or NULL |
|
| 652 | - */ |
|
| 653 | - public static function get_default_creator_id() |
|
| 654 | - { |
|
| 655 | - global $wpdb; |
|
| 656 | - if ( ! empty(self::$_default_creator_id)) { |
|
| 657 | - return self::$_default_creator_id; |
|
| 658 | - }/**/ |
|
| 659 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 660 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 661 | - $pre_filtered_id = apply_filters( |
|
| 662 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 663 | - false, |
|
| 664 | - $role_to_check |
|
| 665 | - ); |
|
| 666 | - if ($pre_filtered_id !== false) { |
|
| 667 | - return (int)$pre_filtered_id; |
|
| 668 | - } |
|
| 669 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 670 | - $query = $wpdb->prepare( |
|
| 671 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 672 | - '%' . $role_to_check . '%' |
|
| 673 | - ); |
|
| 674 | - $user_id = $wpdb->get_var($query); |
|
| 675 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 676 | - if ($user_id && (int)$user_id) { |
|
| 677 | - self::$_default_creator_id = (int)$user_id; |
|
| 678 | - return self::$_default_creator_id; |
|
| 679 | - } else { |
|
| 680 | - return null; |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * used by EE and EE addons during plugin activation to create tables. |
|
| 688 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 689 | - * but includes extra logic regarding activations. |
|
| 690 | - * |
|
| 691 | - * @access public |
|
| 692 | - * @static |
|
| 693 | - * @param string $table_name without the $wpdb->prefix |
|
| 694 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 695 | - * table query) |
|
| 696 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 697 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 698 | - * and new once this function is done (ie, you really do want to CREATE a |
|
| 699 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 700 | - * you just want to verify the table exists and matches this definition |
|
| 701 | - * (and if it HAS data in it you want to leave it be) |
|
| 702 | - * @return void |
|
| 703 | - * @throws EE_Error if there are database errors |
|
| 704 | - */ |
|
| 705 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 706 | - { |
|
| 707 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 708 | - return; |
|
| 709 | - } |
|
| 710 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 711 | - if ( ! function_exists('dbDelta')) { |
|
| 712 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 713 | - } |
|
| 714 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 715 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 716 | - // do we need to first delete an existing version of this table ? |
|
| 717 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 718 | - // ok, delete the table... but ONLY if it's empty |
|
| 719 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 720 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 721 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 722 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 723 | - } else if ( ! $deleted_safely) { |
|
| 724 | - // so we should be more cautious rather than just dropping tables so easily |
|
| 725 | - error_log( |
|
| 726 | - sprintf( |
|
| 727 | - __( |
|
| 728 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 729 | - 'event_espresso' |
|
| 730 | - ), |
|
| 731 | - $wp_table_name, |
|
| 732 | - '<br/>', |
|
| 733 | - 'espresso_db_update' |
|
| 734 | - ) |
|
| 735 | - ); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - $engine = str_replace('ENGINE=', '', $engine); |
|
| 739 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * add_column_if_it_doesn't_exist |
|
| 746 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 747 | - * |
|
| 748 | - * @access public |
|
| 749 | - * @static |
|
| 750 | - * @deprecated instead use TableManager::addColumn() |
|
| 751 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 752 | - * @param string $column_name |
|
| 753 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 754 | - * 'VARCHAR(10)' |
|
| 755 | - * @return bool|int |
|
| 756 | - */ |
|
| 757 | - public static function add_column_if_it_doesnt_exist( |
|
| 758 | - $table_name, |
|
| 759 | - $column_name, |
|
| 760 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
| 761 | - ) { |
|
| 762 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * get_fields_on_table |
|
| 768 | - * Gets all the fields on the database table. |
|
| 769 | - * |
|
| 770 | - * @access public |
|
| 771 | - * @deprecated instead use TableManager::getTableColumns() |
|
| 772 | - * @static |
|
| 773 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
| 774 | - * @return array of database column names |
|
| 775 | - */ |
|
| 776 | - public static function get_fields_on_table($table_name = null) |
|
| 777 | - { |
|
| 778 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * db_table_is_empty |
|
| 784 | - * |
|
| 785 | - * @access public\ |
|
| 786 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 787 | - * @static |
|
| 788 | - * @param string $table_name |
|
| 789 | - * @return bool |
|
| 790 | - */ |
|
| 791 | - public static function db_table_is_empty($table_name) |
|
| 792 | - { |
|
| 793 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * delete_db_table_if_empty |
|
| 799 | - * |
|
| 800 | - * @access public |
|
| 801 | - * @static |
|
| 802 | - * @param string $table_name |
|
| 803 | - * @return bool | int |
|
| 804 | - */ |
|
| 805 | - public static function delete_db_table_if_empty($table_name) |
|
| 806 | - { |
|
| 807 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 808 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 809 | - } |
|
| 810 | - return false; |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * delete_unused_db_table |
|
| 816 | - * |
|
| 817 | - * @access public |
|
| 818 | - * @static |
|
| 819 | - * @deprecated instead use TableManager::dropTable() |
|
| 820 | - * @param string $table_name |
|
| 821 | - * @return bool | int |
|
| 822 | - */ |
|
| 823 | - public static function delete_unused_db_table($table_name) |
|
| 824 | - { |
|
| 825 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * drop_index |
|
| 831 | - * |
|
| 832 | - * @access public |
|
| 833 | - * @static |
|
| 834 | - * @deprecated instead use TableManager::dropIndex() |
|
| 835 | - * @param string $table_name |
|
| 836 | - * @param string $index_name |
|
| 837 | - * @return bool | int |
|
| 838 | - */ |
|
| 839 | - public static function drop_index($table_name, $index_name) |
|
| 840 | - { |
|
| 841 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * create_database_tables |
|
| 848 | - * |
|
| 849 | - * @access public |
|
| 850 | - * @static |
|
| 851 | - * @throws EE_Error |
|
| 852 | - * @return boolean success (whether database is setup properly or not) |
|
| 853 | - */ |
|
| 854 | - public static function create_database_tables() |
|
| 855 | - { |
|
| 856 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 857 | - //find the migration script that sets the database to be compatible with the code |
|
| 858 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 859 | - if ($dms_name) { |
|
| 860 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 861 | - $current_data_migration_script->set_migrating(false); |
|
| 862 | - $current_data_migration_script->schema_changes_before_migration(); |
|
| 863 | - $current_data_migration_script->schema_changes_after_migration(); |
|
| 864 | - if ($current_data_migration_script->get_errors()) { |
|
| 865 | - if (WP_DEBUG) { |
|
| 866 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 867 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 868 | - } |
|
| 869 | - } else { |
|
| 870 | - EE_Error::add_error( |
|
| 871 | - __( |
|
| 872 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 270 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 271 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 272 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 273 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 274 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 275 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 276 | + ) { |
|
| 277 | + unset($crons[$timestamp][$hook_name]); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + //also take care of any empty cron timestamps. |
|
| 281 | + if (empty($hooks_to_fire_at_time)) { |
|
| 282 | + unset($crons[$timestamp]); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + _set_cron_array($crons); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * CPT_initialization |
|
| 292 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 293 | + * |
|
| 294 | + * @access public |
|
| 295 | + * @static |
|
| 296 | + * @return void |
|
| 297 | + */ |
|
| 298 | + public static function CPT_initialization() |
|
| 299 | + { |
|
| 300 | + // register Custom Post Types |
|
| 301 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 302 | + flush_rewrite_rules(); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * reset_and_update_config |
|
| 309 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 310 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
| 311 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 312 | + * |
|
| 313 | + * @access public |
|
| 314 | + * @static |
|
| 315 | + * @return void |
|
| 316 | + */ |
|
| 317 | + public static function reset_and_update_config() |
|
| 318 | + { |
|
| 319 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 320 | + add_filter( |
|
| 321 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 322 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
| 323 | + 10, |
|
| 324 | + 3 |
|
| 325 | + ); |
|
| 326 | + //EE_Config::reset(); |
|
| 327 | + if (! EE_Config::logging_enabled()) { |
|
| 328 | + delete_option(EE_Config::LOG_NAME); |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * load_calendar_config |
|
| 335 | + * |
|
| 336 | + * @access public |
|
| 337 | + * @return void |
|
| 338 | + */ |
|
| 339 | + public static function load_calendar_config() |
|
| 340 | + { |
|
| 341 | + // grab array of all plugin folders and loop thru it |
|
| 342 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 343 | + if (empty($plugins)) { |
|
| 344 | + return; |
|
| 345 | + } |
|
| 346 | + foreach ($plugins as $plugin_path) { |
|
| 347 | + // grab plugin folder name from path |
|
| 348 | + $plugin = basename($plugin_path); |
|
| 349 | + // drill down to Espresso plugins |
|
| 350 | + // then to calendar related plugins |
|
| 351 | + if ( |
|
| 352 | + strpos($plugin, 'espresso') !== false |
|
| 353 | + || strpos($plugin, 'Espresso') !== false |
|
| 354 | + || strpos($plugin, 'ee4') !== false |
|
| 355 | + || strpos($plugin, 'EE4') !== false |
|
| 356 | + || strpos($plugin, 'calendar') !== false |
|
| 357 | + ) { |
|
| 358 | + // this is what we are looking for |
|
| 359 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 360 | + // does it exist in this folder ? |
|
| 361 | + if (is_readable($calendar_config)) { |
|
| 362 | + // YEAH! let's load it |
|
| 363 | + require_once($calendar_config); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * _migrate_old_config_data |
|
| 373 | + * |
|
| 374 | + * @access public |
|
| 375 | + * @param array|stdClass $settings |
|
| 376 | + * @param string $config |
|
| 377 | + * @param \EE_Config $EE_Config |
|
| 378 | + * @return \stdClass |
|
| 379 | + */ |
|
| 380 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 381 | + { |
|
| 382 | + $convert_from_array = array('addons'); |
|
| 383 | + // in case old settings were saved as an array |
|
| 384 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 385 | + // convert existing settings to an object |
|
| 386 | + $config_array = $settings; |
|
| 387 | + $settings = new stdClass(); |
|
| 388 | + foreach ($config_array as $key => $value) { |
|
| 389 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 390 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 391 | + } else { |
|
| 392 | + $settings->{$key} = $value; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 396 | + } |
|
| 397 | + return $settings; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * deactivate_event_espresso |
|
| 403 | + * |
|
| 404 | + * @access public |
|
| 405 | + * @static |
|
| 406 | + * @return void |
|
| 407 | + */ |
|
| 408 | + public static function deactivate_event_espresso() |
|
| 409 | + { |
|
| 410 | + // check permissions |
|
| 411 | + if (current_user_can('activate_plugins')) { |
|
| 412 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * verify_default_pages_exist |
|
| 422 | + * |
|
| 423 | + * @access public |
|
| 424 | + * @static |
|
| 425 | + * @return void |
|
| 426 | + */ |
|
| 427 | + public static function verify_default_pages_exist() |
|
| 428 | + { |
|
| 429 | + $critical_page_problem = false; |
|
| 430 | + $critical_pages = array( |
|
| 431 | + array( |
|
| 432 | + 'id' => 'reg_page_id', |
|
| 433 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 434 | + 'post' => null, |
|
| 435 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
| 436 | + ), |
|
| 437 | + array( |
|
| 438 | + 'id' => 'txn_page_id', |
|
| 439 | + 'name' => __('Transactions', 'event_espresso'), |
|
| 440 | + 'post' => null, |
|
| 441 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 442 | + ), |
|
| 443 | + array( |
|
| 444 | + 'id' => 'thank_you_page_id', |
|
| 445 | + 'name' => __('Thank You', 'event_espresso'), |
|
| 446 | + 'post' => null, |
|
| 447 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
| 448 | + ), |
|
| 449 | + array( |
|
| 450 | + 'id' => 'cancel_page_id', |
|
| 451 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 452 | + 'post' => null, |
|
| 453 | + 'code' => 'ESPRESSO_CANCELLED', |
|
| 454 | + ), |
|
| 455 | + ); |
|
| 456 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 457 | + foreach ($critical_pages as $critical_page) { |
|
| 458 | + // is critical page ID set in config ? |
|
| 459 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 460 | + // attempt to find post by ID |
|
| 461 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 462 | + } |
|
| 463 | + // no dice? |
|
| 464 | + if ($critical_page['post'] === null) { |
|
| 465 | + // attempt to find post by title |
|
| 466 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 467 | + // still nothing? |
|
| 468 | + if ($critical_page['post'] === null) { |
|
| 469 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 470 | + // REALLY? Still nothing ??!?!? |
|
| 471 | + if ($critical_page['post'] === null) { |
|
| 472 | + $msg = __( |
|
| 473 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 474 | + 'event_espresso' |
|
| 475 | + ); |
|
| 476 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 477 | + break; |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + // track post_shortcodes |
|
| 482 | + if ($critical_page['post']) { |
|
| 483 | + EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
| 484 | + } |
|
| 485 | + // check that Post ID matches critical page ID in config |
|
| 486 | + if ( |
|
| 487 | + isset($critical_page['post']->ID) |
|
| 488 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 489 | + ) { |
|
| 490 | + //update Config with post ID |
|
| 491 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 492 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 493 | + $msg = __( |
|
| 494 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 495 | + 'event_espresso' |
|
| 496 | + ); |
|
| 497 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + $critical_page_problem = |
|
| 501 | + ! isset($critical_page['post']->post_status) |
|
| 502 | + || $critical_page['post']->post_status !== 'publish' |
|
| 503 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 504 | + ? true |
|
| 505 | + : $critical_page_problem; |
|
| 506 | + } |
|
| 507 | + if ($critical_page_problem) { |
|
| 508 | + $msg = sprintf( |
|
| 509 | + __( |
|
| 510 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 511 | + 'event_espresso' |
|
| 512 | + ), |
|
| 513 | + '<a href="' |
|
| 514 | + . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 515 | + . '">' |
|
| 516 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 517 | + . '</a>' |
|
| 518 | + ); |
|
| 519 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 520 | + } |
|
| 521 | + if (EE_Error::has_notices()) { |
|
| 522 | + EE_Error::get_notices(false, true, true); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Returns the first post which uses the specified shortcode |
|
| 530 | + * |
|
| 531 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 532 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 533 | + * "[ESPRESSO_THANK_YOU" |
|
| 534 | + * (we don't search for the closing shortcode bracket because they might have added |
|
| 535 | + * parameter to the shortcode |
|
| 536 | + * @return WP_Post or NULl |
|
| 537 | + */ |
|
| 538 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 539 | + { |
|
| 540 | + global $wpdb; |
|
| 541 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 542 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 543 | + if ($post_id) { |
|
| 544 | + return get_post($post_id); |
|
| 545 | + } else { |
|
| 546 | + return null; |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * This function generates a post for critical espresso pages |
|
| 553 | + * |
|
| 554 | + * @access public |
|
| 555 | + * @static |
|
| 556 | + * @param array $critical_page |
|
| 557 | + * @return array |
|
| 558 | + */ |
|
| 559 | + public static function create_critical_page($critical_page) |
|
| 560 | + { |
|
| 561 | + |
|
| 562 | + $post_args = array( |
|
| 563 | + 'post_title' => $critical_page['name'], |
|
| 564 | + 'post_status' => 'publish', |
|
| 565 | + 'post_type' => 'page', |
|
| 566 | + 'comment_status' => 'closed', |
|
| 567 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 568 | + ); |
|
| 569 | + |
|
| 570 | + $post_id = wp_insert_post($post_args); |
|
| 571 | + if (! $post_id) { |
|
| 572 | + $msg = sprintf( |
|
| 573 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 574 | + $critical_page['name'] |
|
| 575 | + ); |
|
| 576 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 577 | + return $critical_page; |
|
| 578 | + } |
|
| 579 | + // get newly created post's details |
|
| 580 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
| 581 | + $msg = sprintf( |
|
| 582 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 583 | + $critical_page['name'] |
|
| 584 | + ); |
|
| 585 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + return $critical_page; |
|
| 589 | + |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * This function adds a critical page's shortcode to the post_shortcodes array |
|
| 598 | + * |
|
| 599 | + * @access private |
|
| 600 | + * @static |
|
| 601 | + * @param array $critical_page |
|
| 602 | + * @return void |
|
| 603 | + */ |
|
| 604 | + private static function _track_critical_page_post_shortcodes($critical_page = array()) |
|
| 605 | + { |
|
| 606 | + // check the goods |
|
| 607 | + if ( ! $critical_page['post'] instanceof WP_Post) { |
|
| 608 | + $msg = sprintf( |
|
| 609 | + __( |
|
| 610 | + 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', |
|
| 611 | + 'event_espresso' |
|
| 612 | + ), |
|
| 613 | + $critical_page['name'] |
|
| 614 | + ); |
|
| 615 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 616 | + return; |
|
| 617 | + } |
|
| 618 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 619 | + // map shortcode to post |
|
| 620 | + $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
| 621 | + // and make sure it's NOT added to the WP "Posts Page" |
|
| 622 | + // name of the WP Posts Page |
|
| 623 | + $posts_page = EE_Config::get_page_for_posts(); |
|
| 624 | + if (isset($EE_Core_Config->post_shortcodes[$posts_page])) { |
|
| 625 | + unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]); |
|
| 626 | + } |
|
| 627 | + if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) { |
|
| 628 | + unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]); |
|
| 629 | + } |
|
| 630 | + // update post_shortcode CFG |
|
| 631 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 632 | + $msg = sprintf( |
|
| 633 | + __( |
|
| 634 | + 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', |
|
| 635 | + 'event_espresso' |
|
| 636 | + ), |
|
| 637 | + $critical_page['name'] |
|
| 638 | + ); |
|
| 639 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 647 | + * The role being used to check is filterable. |
|
| 648 | + * |
|
| 649 | + * @since 4.6.0 |
|
| 650 | + * @global WPDB $wpdb |
|
| 651 | + * @return mixed null|int WP_user ID or NULL |
|
| 652 | + */ |
|
| 653 | + public static function get_default_creator_id() |
|
| 654 | + { |
|
| 655 | + global $wpdb; |
|
| 656 | + if ( ! empty(self::$_default_creator_id)) { |
|
| 657 | + return self::$_default_creator_id; |
|
| 658 | + }/**/ |
|
| 659 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 660 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 661 | + $pre_filtered_id = apply_filters( |
|
| 662 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 663 | + false, |
|
| 664 | + $role_to_check |
|
| 665 | + ); |
|
| 666 | + if ($pre_filtered_id !== false) { |
|
| 667 | + return (int)$pre_filtered_id; |
|
| 668 | + } |
|
| 669 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 670 | + $query = $wpdb->prepare( |
|
| 671 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 672 | + '%' . $role_to_check . '%' |
|
| 673 | + ); |
|
| 674 | + $user_id = $wpdb->get_var($query); |
|
| 675 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 676 | + if ($user_id && (int)$user_id) { |
|
| 677 | + self::$_default_creator_id = (int)$user_id; |
|
| 678 | + return self::$_default_creator_id; |
|
| 679 | + } else { |
|
| 680 | + return null; |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * used by EE and EE addons during plugin activation to create tables. |
|
| 688 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 689 | + * but includes extra logic regarding activations. |
|
| 690 | + * |
|
| 691 | + * @access public |
|
| 692 | + * @static |
|
| 693 | + * @param string $table_name without the $wpdb->prefix |
|
| 694 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 695 | + * table query) |
|
| 696 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 697 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 698 | + * and new once this function is done (ie, you really do want to CREATE a |
|
| 699 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 700 | + * you just want to verify the table exists and matches this definition |
|
| 701 | + * (and if it HAS data in it you want to leave it be) |
|
| 702 | + * @return void |
|
| 703 | + * @throws EE_Error if there are database errors |
|
| 704 | + */ |
|
| 705 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 706 | + { |
|
| 707 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 708 | + return; |
|
| 709 | + } |
|
| 710 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 711 | + if ( ! function_exists('dbDelta')) { |
|
| 712 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 713 | + } |
|
| 714 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 715 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 716 | + // do we need to first delete an existing version of this table ? |
|
| 717 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 718 | + // ok, delete the table... but ONLY if it's empty |
|
| 719 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 720 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 721 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 722 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 723 | + } else if ( ! $deleted_safely) { |
|
| 724 | + // so we should be more cautious rather than just dropping tables so easily |
|
| 725 | + error_log( |
|
| 726 | + sprintf( |
|
| 727 | + __( |
|
| 728 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 729 | + 'event_espresso' |
|
| 730 | + ), |
|
| 731 | + $wp_table_name, |
|
| 732 | + '<br/>', |
|
| 733 | + 'espresso_db_update' |
|
| 734 | + ) |
|
| 735 | + ); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + $engine = str_replace('ENGINE=', '', $engine); |
|
| 739 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * add_column_if_it_doesn't_exist |
|
| 746 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 747 | + * |
|
| 748 | + * @access public |
|
| 749 | + * @static |
|
| 750 | + * @deprecated instead use TableManager::addColumn() |
|
| 751 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 752 | + * @param string $column_name |
|
| 753 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 754 | + * 'VARCHAR(10)' |
|
| 755 | + * @return bool|int |
|
| 756 | + */ |
|
| 757 | + public static function add_column_if_it_doesnt_exist( |
|
| 758 | + $table_name, |
|
| 759 | + $column_name, |
|
| 760 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
| 761 | + ) { |
|
| 762 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * get_fields_on_table |
|
| 768 | + * Gets all the fields on the database table. |
|
| 769 | + * |
|
| 770 | + * @access public |
|
| 771 | + * @deprecated instead use TableManager::getTableColumns() |
|
| 772 | + * @static |
|
| 773 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
| 774 | + * @return array of database column names |
|
| 775 | + */ |
|
| 776 | + public static function get_fields_on_table($table_name = null) |
|
| 777 | + { |
|
| 778 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * db_table_is_empty |
|
| 784 | + * |
|
| 785 | + * @access public\ |
|
| 786 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 787 | + * @static |
|
| 788 | + * @param string $table_name |
|
| 789 | + * @return bool |
|
| 790 | + */ |
|
| 791 | + public static function db_table_is_empty($table_name) |
|
| 792 | + { |
|
| 793 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * delete_db_table_if_empty |
|
| 799 | + * |
|
| 800 | + * @access public |
|
| 801 | + * @static |
|
| 802 | + * @param string $table_name |
|
| 803 | + * @return bool | int |
|
| 804 | + */ |
|
| 805 | + public static function delete_db_table_if_empty($table_name) |
|
| 806 | + { |
|
| 807 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 808 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 809 | + } |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * delete_unused_db_table |
|
| 816 | + * |
|
| 817 | + * @access public |
|
| 818 | + * @static |
|
| 819 | + * @deprecated instead use TableManager::dropTable() |
|
| 820 | + * @param string $table_name |
|
| 821 | + * @return bool | int |
|
| 822 | + */ |
|
| 823 | + public static function delete_unused_db_table($table_name) |
|
| 824 | + { |
|
| 825 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * drop_index |
|
| 831 | + * |
|
| 832 | + * @access public |
|
| 833 | + * @static |
|
| 834 | + * @deprecated instead use TableManager::dropIndex() |
|
| 835 | + * @param string $table_name |
|
| 836 | + * @param string $index_name |
|
| 837 | + * @return bool | int |
|
| 838 | + */ |
|
| 839 | + public static function drop_index($table_name, $index_name) |
|
| 840 | + { |
|
| 841 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * create_database_tables |
|
| 848 | + * |
|
| 849 | + * @access public |
|
| 850 | + * @static |
|
| 851 | + * @throws EE_Error |
|
| 852 | + * @return boolean success (whether database is setup properly or not) |
|
| 853 | + */ |
|
| 854 | + public static function create_database_tables() |
|
| 855 | + { |
|
| 856 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 857 | + //find the migration script that sets the database to be compatible with the code |
|
| 858 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 859 | + if ($dms_name) { |
|
| 860 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 861 | + $current_data_migration_script->set_migrating(false); |
|
| 862 | + $current_data_migration_script->schema_changes_before_migration(); |
|
| 863 | + $current_data_migration_script->schema_changes_after_migration(); |
|
| 864 | + if ($current_data_migration_script->get_errors()) { |
|
| 865 | + if (WP_DEBUG) { |
|
| 866 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 867 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 868 | + } |
|
| 869 | + } else { |
|
| 870 | + EE_Error::add_error( |
|
| 871 | + __( |
|
| 872 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 873 | 873 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
| 874 | - 'event_espresso' |
|
| 875 | - ) |
|
| 876 | - ); |
|
| 877 | - } |
|
| 878 | - return false; |
|
| 879 | - } |
|
| 880 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 881 | - } else { |
|
| 882 | - EE_Error::add_error( |
|
| 883 | - __( |
|
| 884 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 874 | + 'event_espresso' |
|
| 875 | + ) |
|
| 876 | + ); |
|
| 877 | + } |
|
| 878 | + return false; |
|
| 879 | + } |
|
| 880 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 881 | + } else { |
|
| 882 | + EE_Error::add_error( |
|
| 883 | + __( |
|
| 884 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 885 | 885 | structure. So database is probably not setup properly', |
| 886 | - 'event_espresso' |
|
| 887 | - ), |
|
| 888 | - __FILE__, |
|
| 889 | - __FUNCTION__, |
|
| 890 | - __LINE__ |
|
| 891 | - ); |
|
| 892 | - return false; |
|
| 893 | - } |
|
| 894 | - return true; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * initialize_system_questions |
|
| 901 | - * |
|
| 902 | - * @access public |
|
| 903 | - * @static |
|
| 904 | - * @return void |
|
| 905 | - */ |
|
| 906 | - public static function initialize_system_questions() |
|
| 907 | - { |
|
| 908 | - // QUESTION GROUPS |
|
| 909 | - global $wpdb; |
|
| 910 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 911 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 912 | - // what we have |
|
| 913 | - $question_groups = $wpdb->get_col($SQL); |
|
| 914 | - // check the response |
|
| 915 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 916 | - // what we should have |
|
| 917 | - $QSG_systems = array(1, 2); |
|
| 918 | - // loop thru what we should have and compare to what we have |
|
| 919 | - foreach ($QSG_systems as $QSG_system) { |
|
| 920 | - // reset values array |
|
| 921 | - $QSG_values = array(); |
|
| 922 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 923 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 924 | - // add it |
|
| 925 | - switch ($QSG_system) { |
|
| 926 | - case 1: |
|
| 927 | - $QSG_values = array( |
|
| 928 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 929 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 930 | - 'QSG_desc' => '', |
|
| 931 | - 'QSG_order' => 1, |
|
| 932 | - 'QSG_show_group_name' => 1, |
|
| 933 | - 'QSG_show_group_desc' => 1, |
|
| 934 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 935 | - 'QSG_deleted' => 0, |
|
| 936 | - ); |
|
| 937 | - break; |
|
| 938 | - case 2: |
|
| 939 | - $QSG_values = array( |
|
| 940 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 941 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 942 | - 'QSG_desc' => '', |
|
| 943 | - 'QSG_order' => 2, |
|
| 944 | - 'QSG_show_group_name' => 1, |
|
| 945 | - 'QSG_show_group_desc' => 1, |
|
| 946 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
| 947 | - 'QSG_deleted' => 0, |
|
| 948 | - ); |
|
| 949 | - break; |
|
| 950 | - } |
|
| 951 | - // make sure we have some values before inserting them |
|
| 952 | - if (! empty($QSG_values)) { |
|
| 953 | - // insert system question |
|
| 954 | - $wpdb->insert( |
|
| 955 | - $table_name, |
|
| 956 | - $QSG_values, |
|
| 957 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 958 | - ); |
|
| 959 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 960 | - } |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - // QUESTIONS |
|
| 964 | - global $wpdb; |
|
| 965 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 966 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 967 | - // what we have |
|
| 968 | - $questions = $wpdb->get_col($SQL); |
|
| 969 | - // what we should have |
|
| 970 | - $QST_systems = array( |
|
| 971 | - 'fname', |
|
| 972 | - 'lname', |
|
| 973 | - 'email', |
|
| 974 | - 'address', |
|
| 975 | - 'address2', |
|
| 976 | - 'city', |
|
| 977 | - 'country', |
|
| 978 | - 'state', |
|
| 979 | - 'zip', |
|
| 980 | - 'phone', |
|
| 981 | - ); |
|
| 982 | - $order_for_group_1 = 1; |
|
| 983 | - $order_for_group_2 = 1; |
|
| 984 | - // loop thru what we should have and compare to what we have |
|
| 985 | - foreach ($QST_systems as $QST_system) { |
|
| 986 | - // reset values array |
|
| 987 | - $QST_values = array(); |
|
| 988 | - // if we don't have what we should have |
|
| 989 | - if (! in_array($QST_system, $questions)) { |
|
| 990 | - // add it |
|
| 991 | - switch ($QST_system) { |
|
| 992 | - case 'fname': |
|
| 993 | - $QST_values = array( |
|
| 994 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 995 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 996 | - 'QST_system' => 'fname', |
|
| 997 | - 'QST_type' => 'TEXT', |
|
| 998 | - 'QST_required' => 1, |
|
| 999 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1000 | - 'QST_order' => 1, |
|
| 1001 | - 'QST_admin_only' => 0, |
|
| 1002 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1003 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1004 | - 'QST_deleted' => 0, |
|
| 1005 | - ); |
|
| 1006 | - break; |
|
| 1007 | - case 'lname': |
|
| 1008 | - $QST_values = array( |
|
| 1009 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 1010 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 1011 | - 'QST_system' => 'lname', |
|
| 1012 | - 'QST_type' => 'TEXT', |
|
| 1013 | - 'QST_required' => 1, |
|
| 1014 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1015 | - 'QST_order' => 2, |
|
| 1016 | - 'QST_admin_only' => 0, |
|
| 1017 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1018 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1019 | - 'QST_deleted' => 0, |
|
| 1020 | - ); |
|
| 1021 | - break; |
|
| 1022 | - case 'email': |
|
| 1023 | - $QST_values = array( |
|
| 1024 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 1025 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 1026 | - 'QST_system' => 'email', |
|
| 1027 | - 'QST_type' => 'EMAIL', |
|
| 1028 | - 'QST_required' => 1, |
|
| 1029 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1030 | - 'QST_order' => 3, |
|
| 1031 | - 'QST_admin_only' => 0, |
|
| 1032 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1033 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1034 | - 'QST_deleted' => 0, |
|
| 1035 | - ); |
|
| 1036 | - break; |
|
| 1037 | - case 'address': |
|
| 1038 | - $QST_values = array( |
|
| 1039 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 1040 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 1041 | - 'QST_system' => 'address', |
|
| 1042 | - 'QST_type' => 'TEXT', |
|
| 1043 | - 'QST_required' => 0, |
|
| 1044 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1045 | - 'QST_order' => 4, |
|
| 1046 | - 'QST_admin_only' => 0, |
|
| 1047 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1048 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1049 | - 'QST_deleted' => 0, |
|
| 1050 | - ); |
|
| 1051 | - break; |
|
| 1052 | - case 'address2': |
|
| 1053 | - $QST_values = array( |
|
| 1054 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1055 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1056 | - 'QST_system' => 'address2', |
|
| 1057 | - 'QST_type' => 'TEXT', |
|
| 1058 | - 'QST_required' => 0, |
|
| 1059 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1060 | - 'QST_order' => 5, |
|
| 1061 | - 'QST_admin_only' => 0, |
|
| 1062 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1063 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1064 | - 'QST_deleted' => 0, |
|
| 1065 | - ); |
|
| 1066 | - break; |
|
| 1067 | - case 'city': |
|
| 1068 | - $QST_values = array( |
|
| 1069 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1070 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1071 | - 'QST_system' => 'city', |
|
| 1072 | - 'QST_type' => 'TEXT', |
|
| 1073 | - 'QST_required' => 0, |
|
| 1074 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1075 | - 'QST_order' => 6, |
|
| 1076 | - 'QST_admin_only' => 0, |
|
| 1077 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1078 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1079 | - 'QST_deleted' => 0, |
|
| 1080 | - ); |
|
| 1081 | - break; |
|
| 1082 | - case 'country': |
|
| 1083 | - $QST_values = array( |
|
| 1084 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1085 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1086 | - 'QST_system' => 'country', |
|
| 1087 | - 'QST_type' => 'COUNTRY', |
|
| 1088 | - 'QST_required' => 0, |
|
| 1089 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1090 | - 'QST_order' => 7, |
|
| 1091 | - 'QST_admin_only' => 0, |
|
| 1092 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1093 | - 'QST_deleted' => 0, |
|
| 1094 | - ); |
|
| 1095 | - break; |
|
| 1096 | - case 'state': |
|
| 1097 | - $QST_values = array( |
|
| 1098 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1099 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1100 | - 'QST_system' => 'state', |
|
| 1101 | - 'QST_type' => 'STATE', |
|
| 1102 | - 'QST_required' => 0, |
|
| 1103 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1104 | - 'QST_order' => 8, |
|
| 1105 | - 'QST_admin_only' => 0, |
|
| 1106 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1107 | - 'QST_deleted' => 0, |
|
| 1108 | - ); |
|
| 1109 | - break; |
|
| 1110 | - case 'zip': |
|
| 1111 | - $QST_values = array( |
|
| 1112 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1113 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1114 | - 'QST_system' => 'zip', |
|
| 1115 | - 'QST_type' => 'TEXT', |
|
| 1116 | - 'QST_required' => 0, |
|
| 1117 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1118 | - 'QST_order' => 9, |
|
| 1119 | - 'QST_admin_only' => 0, |
|
| 1120 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1121 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1122 | - 'QST_deleted' => 0, |
|
| 1123 | - ); |
|
| 1124 | - break; |
|
| 1125 | - case 'phone': |
|
| 1126 | - $QST_values = array( |
|
| 1127 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1128 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1129 | - 'QST_system' => 'phone', |
|
| 1130 | - 'QST_type' => 'TEXT', |
|
| 1131 | - 'QST_required' => 0, |
|
| 1132 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1133 | - 'QST_order' => 10, |
|
| 1134 | - 'QST_admin_only' => 0, |
|
| 1135 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1136 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1137 | - 'QST_deleted' => 0, |
|
| 1138 | - ); |
|
| 1139 | - break; |
|
| 1140 | - } |
|
| 1141 | - if (! empty($QST_values)) { |
|
| 1142 | - // insert system question |
|
| 1143 | - $wpdb->insert( |
|
| 1144 | - $table_name, |
|
| 1145 | - $QST_values, |
|
| 1146 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1147 | - ); |
|
| 1148 | - $QST_ID = $wpdb->insert_id; |
|
| 1149 | - // QUESTION GROUP QUESTIONS |
|
| 1150 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1151 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1152 | - } else { |
|
| 1153 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1154 | - } |
|
| 1155 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1156 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1157 | - } else { |
|
| 1158 | - $id_col = EEM_Question_Group::instance() |
|
| 1159 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1160 | - if (is_array($id_col)) { |
|
| 1161 | - $QSG_ID = reset($id_col); |
|
| 1162 | - } else { |
|
| 1163 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1164 | - EE_Log::instance()->log( |
|
| 1165 | - __FILE__, |
|
| 1166 | - __FUNCTION__, |
|
| 1167 | - sprintf( |
|
| 1168 | - __( |
|
| 1169 | - 'Could not associate question %1$s to a question group because no system question |
|
| 886 | + 'event_espresso' |
|
| 887 | + ), |
|
| 888 | + __FILE__, |
|
| 889 | + __FUNCTION__, |
|
| 890 | + __LINE__ |
|
| 891 | + ); |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 894 | + return true; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * initialize_system_questions |
|
| 901 | + * |
|
| 902 | + * @access public |
|
| 903 | + * @static |
|
| 904 | + * @return void |
|
| 905 | + */ |
|
| 906 | + public static function initialize_system_questions() |
|
| 907 | + { |
|
| 908 | + // QUESTION GROUPS |
|
| 909 | + global $wpdb; |
|
| 910 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 911 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 912 | + // what we have |
|
| 913 | + $question_groups = $wpdb->get_col($SQL); |
|
| 914 | + // check the response |
|
| 915 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 916 | + // what we should have |
|
| 917 | + $QSG_systems = array(1, 2); |
|
| 918 | + // loop thru what we should have and compare to what we have |
|
| 919 | + foreach ($QSG_systems as $QSG_system) { |
|
| 920 | + // reset values array |
|
| 921 | + $QSG_values = array(); |
|
| 922 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 923 | + if (! in_array("$QSG_system", $question_groups)) { |
|
| 924 | + // add it |
|
| 925 | + switch ($QSG_system) { |
|
| 926 | + case 1: |
|
| 927 | + $QSG_values = array( |
|
| 928 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 929 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
| 930 | + 'QSG_desc' => '', |
|
| 931 | + 'QSG_order' => 1, |
|
| 932 | + 'QSG_show_group_name' => 1, |
|
| 933 | + 'QSG_show_group_desc' => 1, |
|
| 934 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 935 | + 'QSG_deleted' => 0, |
|
| 936 | + ); |
|
| 937 | + break; |
|
| 938 | + case 2: |
|
| 939 | + $QSG_values = array( |
|
| 940 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 941 | + 'QSG_identifier' => 'address-information-' . time(), |
|
| 942 | + 'QSG_desc' => '', |
|
| 943 | + 'QSG_order' => 2, |
|
| 944 | + 'QSG_show_group_name' => 1, |
|
| 945 | + 'QSG_show_group_desc' => 1, |
|
| 946 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
| 947 | + 'QSG_deleted' => 0, |
|
| 948 | + ); |
|
| 949 | + break; |
|
| 950 | + } |
|
| 951 | + // make sure we have some values before inserting them |
|
| 952 | + if (! empty($QSG_values)) { |
|
| 953 | + // insert system question |
|
| 954 | + $wpdb->insert( |
|
| 955 | + $table_name, |
|
| 956 | + $QSG_values, |
|
| 957 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 958 | + ); |
|
| 959 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + // QUESTIONS |
|
| 964 | + global $wpdb; |
|
| 965 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 966 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 967 | + // what we have |
|
| 968 | + $questions = $wpdb->get_col($SQL); |
|
| 969 | + // what we should have |
|
| 970 | + $QST_systems = array( |
|
| 971 | + 'fname', |
|
| 972 | + 'lname', |
|
| 973 | + 'email', |
|
| 974 | + 'address', |
|
| 975 | + 'address2', |
|
| 976 | + 'city', |
|
| 977 | + 'country', |
|
| 978 | + 'state', |
|
| 979 | + 'zip', |
|
| 980 | + 'phone', |
|
| 981 | + ); |
|
| 982 | + $order_for_group_1 = 1; |
|
| 983 | + $order_for_group_2 = 1; |
|
| 984 | + // loop thru what we should have and compare to what we have |
|
| 985 | + foreach ($QST_systems as $QST_system) { |
|
| 986 | + // reset values array |
|
| 987 | + $QST_values = array(); |
|
| 988 | + // if we don't have what we should have |
|
| 989 | + if (! in_array($QST_system, $questions)) { |
|
| 990 | + // add it |
|
| 991 | + switch ($QST_system) { |
|
| 992 | + case 'fname': |
|
| 993 | + $QST_values = array( |
|
| 994 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 995 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 996 | + 'QST_system' => 'fname', |
|
| 997 | + 'QST_type' => 'TEXT', |
|
| 998 | + 'QST_required' => 1, |
|
| 999 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1000 | + 'QST_order' => 1, |
|
| 1001 | + 'QST_admin_only' => 0, |
|
| 1002 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1003 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1004 | + 'QST_deleted' => 0, |
|
| 1005 | + ); |
|
| 1006 | + break; |
|
| 1007 | + case 'lname': |
|
| 1008 | + $QST_values = array( |
|
| 1009 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 1010 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 1011 | + 'QST_system' => 'lname', |
|
| 1012 | + 'QST_type' => 'TEXT', |
|
| 1013 | + 'QST_required' => 1, |
|
| 1014 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1015 | + 'QST_order' => 2, |
|
| 1016 | + 'QST_admin_only' => 0, |
|
| 1017 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1018 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1019 | + 'QST_deleted' => 0, |
|
| 1020 | + ); |
|
| 1021 | + break; |
|
| 1022 | + case 'email': |
|
| 1023 | + $QST_values = array( |
|
| 1024 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 1025 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 1026 | + 'QST_system' => 'email', |
|
| 1027 | + 'QST_type' => 'EMAIL', |
|
| 1028 | + 'QST_required' => 1, |
|
| 1029 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1030 | + 'QST_order' => 3, |
|
| 1031 | + 'QST_admin_only' => 0, |
|
| 1032 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1033 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1034 | + 'QST_deleted' => 0, |
|
| 1035 | + ); |
|
| 1036 | + break; |
|
| 1037 | + case 'address': |
|
| 1038 | + $QST_values = array( |
|
| 1039 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 1040 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 1041 | + 'QST_system' => 'address', |
|
| 1042 | + 'QST_type' => 'TEXT', |
|
| 1043 | + 'QST_required' => 0, |
|
| 1044 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1045 | + 'QST_order' => 4, |
|
| 1046 | + 'QST_admin_only' => 0, |
|
| 1047 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1048 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1049 | + 'QST_deleted' => 0, |
|
| 1050 | + ); |
|
| 1051 | + break; |
|
| 1052 | + case 'address2': |
|
| 1053 | + $QST_values = array( |
|
| 1054 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1055 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1056 | + 'QST_system' => 'address2', |
|
| 1057 | + 'QST_type' => 'TEXT', |
|
| 1058 | + 'QST_required' => 0, |
|
| 1059 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1060 | + 'QST_order' => 5, |
|
| 1061 | + 'QST_admin_only' => 0, |
|
| 1062 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1063 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1064 | + 'QST_deleted' => 0, |
|
| 1065 | + ); |
|
| 1066 | + break; |
|
| 1067 | + case 'city': |
|
| 1068 | + $QST_values = array( |
|
| 1069 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1070 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1071 | + 'QST_system' => 'city', |
|
| 1072 | + 'QST_type' => 'TEXT', |
|
| 1073 | + 'QST_required' => 0, |
|
| 1074 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1075 | + 'QST_order' => 6, |
|
| 1076 | + 'QST_admin_only' => 0, |
|
| 1077 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1078 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1079 | + 'QST_deleted' => 0, |
|
| 1080 | + ); |
|
| 1081 | + break; |
|
| 1082 | + case 'country': |
|
| 1083 | + $QST_values = array( |
|
| 1084 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1085 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1086 | + 'QST_system' => 'country', |
|
| 1087 | + 'QST_type' => 'COUNTRY', |
|
| 1088 | + 'QST_required' => 0, |
|
| 1089 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1090 | + 'QST_order' => 7, |
|
| 1091 | + 'QST_admin_only' => 0, |
|
| 1092 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1093 | + 'QST_deleted' => 0, |
|
| 1094 | + ); |
|
| 1095 | + break; |
|
| 1096 | + case 'state': |
|
| 1097 | + $QST_values = array( |
|
| 1098 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1099 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1100 | + 'QST_system' => 'state', |
|
| 1101 | + 'QST_type' => 'STATE', |
|
| 1102 | + 'QST_required' => 0, |
|
| 1103 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1104 | + 'QST_order' => 8, |
|
| 1105 | + 'QST_admin_only' => 0, |
|
| 1106 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1107 | + 'QST_deleted' => 0, |
|
| 1108 | + ); |
|
| 1109 | + break; |
|
| 1110 | + case 'zip': |
|
| 1111 | + $QST_values = array( |
|
| 1112 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1113 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1114 | + 'QST_system' => 'zip', |
|
| 1115 | + 'QST_type' => 'TEXT', |
|
| 1116 | + 'QST_required' => 0, |
|
| 1117 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1118 | + 'QST_order' => 9, |
|
| 1119 | + 'QST_admin_only' => 0, |
|
| 1120 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1121 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1122 | + 'QST_deleted' => 0, |
|
| 1123 | + ); |
|
| 1124 | + break; |
|
| 1125 | + case 'phone': |
|
| 1126 | + $QST_values = array( |
|
| 1127 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1128 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1129 | + 'QST_system' => 'phone', |
|
| 1130 | + 'QST_type' => 'TEXT', |
|
| 1131 | + 'QST_required' => 0, |
|
| 1132 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1133 | + 'QST_order' => 10, |
|
| 1134 | + 'QST_admin_only' => 0, |
|
| 1135 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1136 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1137 | + 'QST_deleted' => 0, |
|
| 1138 | + ); |
|
| 1139 | + break; |
|
| 1140 | + } |
|
| 1141 | + if (! empty($QST_values)) { |
|
| 1142 | + // insert system question |
|
| 1143 | + $wpdb->insert( |
|
| 1144 | + $table_name, |
|
| 1145 | + $QST_values, |
|
| 1146 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1147 | + ); |
|
| 1148 | + $QST_ID = $wpdb->insert_id; |
|
| 1149 | + // QUESTION GROUP QUESTIONS |
|
| 1150 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1151 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1152 | + } else { |
|
| 1153 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1154 | + } |
|
| 1155 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1156 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1157 | + } else { |
|
| 1158 | + $id_col = EEM_Question_Group::instance() |
|
| 1159 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1160 | + if (is_array($id_col)) { |
|
| 1161 | + $QSG_ID = reset($id_col); |
|
| 1162 | + } else { |
|
| 1163 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1164 | + EE_Log::instance()->log( |
|
| 1165 | + __FILE__, |
|
| 1166 | + __FUNCTION__, |
|
| 1167 | + sprintf( |
|
| 1168 | + __( |
|
| 1169 | + 'Could not associate question %1$s to a question group because no system question |
|
| 1170 | 1170 | group existed', |
| 1171 | - 'event_espresso' |
|
| 1172 | - ), |
|
| 1173 | - $QST_ID), |
|
| 1174 | - 'error'); |
|
| 1175 | - continue; |
|
| 1176 | - } |
|
| 1177 | - } |
|
| 1178 | - // add system questions to groups |
|
| 1179 | - $wpdb->insert( |
|
| 1180 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1181 | - array( |
|
| 1182 | - 'QSG_ID' => $QSG_ID, |
|
| 1183 | - 'QST_ID' => $QST_ID, |
|
| 1184 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1185 | - ), |
|
| 1186 | - array('%d', '%d', '%d') |
|
| 1187 | - ); |
|
| 1188 | - } |
|
| 1189 | - } |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - |
|
| 1194 | - /** |
|
| 1195 | - * Makes sure the default payment method (Invoice) is active. |
|
| 1196 | - * This used to be done automatically as part of constructing the old gateways config |
|
| 1197 | - * |
|
| 1198 | - * @throws \EE_Error |
|
| 1199 | - */ |
|
| 1200 | - public static function insert_default_payment_methods() |
|
| 1201 | - { |
|
| 1202 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1203 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1204 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1205 | - } else { |
|
| 1206 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1207 | - } |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * insert_default_status_codes |
|
| 1212 | - * |
|
| 1213 | - * @access public |
|
| 1214 | - * @static |
|
| 1215 | - * @return void |
|
| 1216 | - */ |
|
| 1217 | - public static function insert_default_status_codes() |
|
| 1218 | - { |
|
| 1219 | - |
|
| 1220 | - global $wpdb; |
|
| 1221 | - |
|
| 1222 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1223 | - |
|
| 1224 | - $table_name = EEM_Status::instance()->table(); |
|
| 1225 | - |
|
| 1226 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1227 | - $wpdb->query($SQL); |
|
| 1228 | - |
|
| 1229 | - $SQL = "INSERT INTO $table_name |
|
| 1171 | + 'event_espresso' |
|
| 1172 | + ), |
|
| 1173 | + $QST_ID), |
|
| 1174 | + 'error'); |
|
| 1175 | + continue; |
|
| 1176 | + } |
|
| 1177 | + } |
|
| 1178 | + // add system questions to groups |
|
| 1179 | + $wpdb->insert( |
|
| 1180 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1181 | + array( |
|
| 1182 | + 'QSG_ID' => $QSG_ID, |
|
| 1183 | + 'QST_ID' => $QST_ID, |
|
| 1184 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1185 | + ), |
|
| 1186 | + array('%d', '%d', '%d') |
|
| 1187 | + ); |
|
| 1188 | + } |
|
| 1189 | + } |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * Makes sure the default payment method (Invoice) is active. |
|
| 1196 | + * This used to be done automatically as part of constructing the old gateways config |
|
| 1197 | + * |
|
| 1198 | + * @throws \EE_Error |
|
| 1199 | + */ |
|
| 1200 | + public static function insert_default_payment_methods() |
|
| 1201 | + { |
|
| 1202 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1203 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1204 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1205 | + } else { |
|
| 1206 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * insert_default_status_codes |
|
| 1212 | + * |
|
| 1213 | + * @access public |
|
| 1214 | + * @static |
|
| 1215 | + * @return void |
|
| 1216 | + */ |
|
| 1217 | + public static function insert_default_status_codes() |
|
| 1218 | + { |
|
| 1219 | + |
|
| 1220 | + global $wpdb; |
|
| 1221 | + |
|
| 1222 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1223 | + |
|
| 1224 | + $table_name = EEM_Status::instance()->table(); |
|
| 1225 | + |
|
| 1226 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1227 | + $wpdb->query($SQL); |
|
| 1228 | + |
|
| 1229 | + $SQL = "INSERT INTO $table_name |
|
| 1230 | 1230 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
| 1231 | 1231 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
| 1232 | 1232 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1266,521 +1266,521 @@ discard block |
||
| 1266 | 1266 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
| 1267 | 1267 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
| 1268 | 1268 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
| 1269 | - $wpdb->query($SQL); |
|
| 1270 | - |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * create_upload_directories |
|
| 1278 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1279 | - * |
|
| 1280 | - * @access public |
|
| 1281 | - * @static |
|
| 1282 | - * @return boolean success of verifying upload directories exist |
|
| 1283 | - */ |
|
| 1284 | - public static function create_upload_directories() |
|
| 1285 | - { |
|
| 1286 | - // Create the required folders |
|
| 1287 | - $folders = array( |
|
| 1288 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1289 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1290 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1291 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1292 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1293 | - ); |
|
| 1294 | - foreach ($folders as $folder) { |
|
| 1295 | - try { |
|
| 1296 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1297 | - @ chmod($folder, 0755); |
|
| 1298 | - } catch (EE_Error $e) { |
|
| 1299 | - EE_Error::add_error( |
|
| 1300 | - sprintf( |
|
| 1301 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1302 | - $folder, |
|
| 1303 | - '<br />' . $e->getMessage() |
|
| 1304 | - ), |
|
| 1305 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1306 | - ); |
|
| 1307 | - //indicate we'll need to fix this later |
|
| 1308 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1309 | - return false; |
|
| 1310 | - } |
|
| 1311 | - } |
|
| 1312 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1313 | - //is disabled, there might be activation errors recorded in there |
|
| 1314 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1315 | - //remember EE's folders are all good |
|
| 1316 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1317 | - return true; |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - /** |
|
| 1321 | - * Whether the upload directories need to be fixed or not. |
|
| 1322 | - * If EE is installed but filesystem access isn't initially available, |
|
| 1323 | - * we need to get the user's filesystem credentials and THEN create them, |
|
| 1324 | - * so there might be period of time when EE is installed but its |
|
| 1325 | - * upload directories aren't available. This indicates such a state |
|
| 1326 | - * |
|
| 1327 | - * @return boolean |
|
| 1328 | - */ |
|
| 1329 | - public static function upload_directories_incomplete() |
|
| 1330 | - { |
|
| 1331 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - |
|
| 1335 | - /** |
|
| 1336 | - * generate_default_message_templates |
|
| 1337 | - * |
|
| 1338 | - * @static |
|
| 1339 | - * @throws EE_Error |
|
| 1340 | - * @return bool true means new templates were created. |
|
| 1341 | - * false means no templates were created. |
|
| 1342 | - * This is NOT an error flag. To check for errors you will want |
|
| 1343 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1344 | - */ |
|
| 1345 | - public static function generate_default_message_templates() |
|
| 1346 | - { |
|
| 1347 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1348 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1349 | - /* |
|
| 1269 | + $wpdb->query($SQL); |
|
| 1270 | + |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * create_upload_directories |
|
| 1278 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1279 | + * |
|
| 1280 | + * @access public |
|
| 1281 | + * @static |
|
| 1282 | + * @return boolean success of verifying upload directories exist |
|
| 1283 | + */ |
|
| 1284 | + public static function create_upload_directories() |
|
| 1285 | + { |
|
| 1286 | + // Create the required folders |
|
| 1287 | + $folders = array( |
|
| 1288 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1289 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1290 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1291 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1292 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1293 | + ); |
|
| 1294 | + foreach ($folders as $folder) { |
|
| 1295 | + try { |
|
| 1296 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1297 | + @ chmod($folder, 0755); |
|
| 1298 | + } catch (EE_Error $e) { |
|
| 1299 | + EE_Error::add_error( |
|
| 1300 | + sprintf( |
|
| 1301 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1302 | + $folder, |
|
| 1303 | + '<br />' . $e->getMessage() |
|
| 1304 | + ), |
|
| 1305 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1306 | + ); |
|
| 1307 | + //indicate we'll need to fix this later |
|
| 1308 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1309 | + return false; |
|
| 1310 | + } |
|
| 1311 | + } |
|
| 1312 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1313 | + //is disabled, there might be activation errors recorded in there |
|
| 1314 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1315 | + //remember EE's folders are all good |
|
| 1316 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1317 | + return true; |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + /** |
|
| 1321 | + * Whether the upload directories need to be fixed or not. |
|
| 1322 | + * If EE is installed but filesystem access isn't initially available, |
|
| 1323 | + * we need to get the user's filesystem credentials and THEN create them, |
|
| 1324 | + * so there might be period of time when EE is installed but its |
|
| 1325 | + * upload directories aren't available. This indicates such a state |
|
| 1326 | + * |
|
| 1327 | + * @return boolean |
|
| 1328 | + */ |
|
| 1329 | + public static function upload_directories_incomplete() |
|
| 1330 | + { |
|
| 1331 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + |
|
| 1335 | + /** |
|
| 1336 | + * generate_default_message_templates |
|
| 1337 | + * |
|
| 1338 | + * @static |
|
| 1339 | + * @throws EE_Error |
|
| 1340 | + * @return bool true means new templates were created. |
|
| 1341 | + * false means no templates were created. |
|
| 1342 | + * This is NOT an error flag. To check for errors you will want |
|
| 1343 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1344 | + */ |
|
| 1345 | + public static function generate_default_message_templates() |
|
| 1346 | + { |
|
| 1347 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1348 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1349 | + /* |
|
| 1350 | 1350 | * This first method is taking care of ensuring any default messengers |
| 1351 | 1351 | * that should be made active and have templates generated are done. |
| 1352 | 1352 | */ |
| 1353 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1354 | - $message_resource_manager |
|
| 1355 | - ); |
|
| 1356 | - /** |
|
| 1357 | - * This method is verifying there are no NEW default message types |
|
| 1358 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1359 | - */ |
|
| 1360 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1361 | - $message_resource_manager |
|
| 1362 | - ); |
|
| 1363 | - //after all is done, let's persist these changes to the db. |
|
| 1364 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1365 | - $message_resource_manager->update_active_messengers_option(); |
|
| 1366 | - // will return true if either of these are true. Otherwise will return false. |
|
| 1367 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - |
|
| 1371 | - |
|
| 1372 | - /** |
|
| 1373 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1374 | - * @return array|bool |
|
| 1375 | - * @throws \EE_Error |
|
| 1376 | - */ |
|
| 1377 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1378 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1379 | - ) { |
|
| 1380 | - /** @type EE_messenger[] $active_messengers */ |
|
| 1381 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1382 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1383 | - $templates_created = false; |
|
| 1384 | - foreach ($active_messengers as $active_messenger) { |
|
| 1385 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1386 | - $default_message_type_names_to_activate = array(); |
|
| 1387 | - // looping through each default message type reported by the messenger |
|
| 1388 | - // and setup the actual message types to activate. |
|
| 1389 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1390 | - // if already active or has already been activated before we skip |
|
| 1391 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1392 | - // we also skip if the message type is not installed. |
|
| 1393 | - if ( |
|
| 1394 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1395 | - $default_message_type_name_for_messenger, |
|
| 1396 | - $active_messenger->name |
|
| 1397 | - ) |
|
| 1398 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1399 | - $active_messenger->name, |
|
| 1400 | - $default_message_type_name_for_messenger |
|
| 1401 | - ) |
|
| 1402 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1403 | - ) { |
|
| 1404 | - continue; |
|
| 1405 | - } |
|
| 1406 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1407 | - } |
|
| 1408 | - //let's activate! |
|
| 1409 | - $message_resource_manager->ensure_message_types_are_active( |
|
| 1410 | - $default_message_type_names_to_activate, |
|
| 1411 | - $active_messenger->name, |
|
| 1412 | - false |
|
| 1413 | - ); |
|
| 1414 | - //activate the templates for these message types |
|
| 1415 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1416 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1417 | - $active_messenger->name, |
|
| 1418 | - $default_message_type_names_for_messenger, |
|
| 1419 | - '', |
|
| 1420 | - true |
|
| 1421 | - ); |
|
| 1422 | - } |
|
| 1423 | - } |
|
| 1424 | - return $templates_created; |
|
| 1425 | - } |
|
| 1426 | - |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * This will activate and generate default messengers and default message types for those messengers. |
|
| 1431 | - * |
|
| 1432 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1433 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1434 | - * False means that there were no templates generated |
|
| 1435 | - * (which could simply mean there are no default message types for a messenger). |
|
| 1436 | - * @throws EE_Error |
|
| 1437 | - */ |
|
| 1438 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1439 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1440 | - ) { |
|
| 1441 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1442 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1443 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1444 | - $templates_generated = false; |
|
| 1445 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1446 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1447 | - //verify the default message types match an installed message type. |
|
| 1448 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1449 | - if ( |
|
| 1450 | - ! isset($installed_message_types[$name]) |
|
| 1451 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1452 | - $name, |
|
| 1453 | - $messenger_to_generate->name |
|
| 1454 | - ) |
|
| 1455 | - ) { |
|
| 1456 | - unset($default_message_type_names_for_messenger[$key]); |
|
| 1457 | - } |
|
| 1458 | - } |
|
| 1459 | - // in previous iterations, the active_messengers option in the db |
|
| 1460 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1461 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1462 | - // passing off to create templates (after the refactor is done). |
|
| 1463 | - // @todo remove this comment when determined not necessary. |
|
| 1464 | - $message_resource_manager->activate_messenger( |
|
| 1465 | - $messenger_to_generate->name, |
|
| 1466 | - $default_message_type_names_for_messenger, |
|
| 1467 | - false |
|
| 1468 | - ); |
|
| 1469 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1470 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1471 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1472 | - $messenger_to_generate->name, |
|
| 1473 | - $default_message_type_names_for_messenger, |
|
| 1474 | - '', |
|
| 1475 | - true |
|
| 1476 | - ); |
|
| 1477 | - } |
|
| 1478 | - } |
|
| 1479 | - return $templates_generated; |
|
| 1480 | - } |
|
| 1481 | - |
|
| 1482 | - |
|
| 1483 | - /** |
|
| 1484 | - * This returns the default messengers to generate templates for on activation of EE. |
|
| 1485 | - * It considers: |
|
| 1486 | - * - whether a messenger is already active in the db. |
|
| 1487 | - * - whether a messenger has been made active at any time in the past. |
|
| 1488 | - * |
|
| 1489 | - * @static |
|
| 1490 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1491 | - * @return EE_messenger[] |
|
| 1492 | - */ |
|
| 1493 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1494 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1495 | - ) { |
|
| 1496 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1497 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1498 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1499 | - |
|
| 1500 | - $messengers_to_generate = array(); |
|
| 1501 | - foreach ($installed_messengers as $installed_messenger) { |
|
| 1502 | - //if installed messenger is a messenger that should be activated on install |
|
| 1503 | - //and is not already active |
|
| 1504 | - //and has never been activated |
|
| 1505 | - if ( |
|
| 1506 | - ! $installed_messenger->activate_on_install |
|
| 1507 | - || isset($active_messengers[$installed_messenger->name]) |
|
| 1508 | - || isset($has_activated[$installed_messenger->name]) |
|
| 1509 | - ) { |
|
| 1510 | - continue; |
|
| 1511 | - } |
|
| 1512 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1513 | - } |
|
| 1514 | - return $messengers_to_generate; |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - |
|
| 1518 | - /** |
|
| 1519 | - * This simply validates active message types to ensure they actually match installed |
|
| 1520 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1521 | - * rows are set inactive. |
|
| 1522 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1523 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1524 | - * are still handled in here. |
|
| 1525 | - * |
|
| 1526 | - * @since 4.3.1 |
|
| 1527 | - * @return void |
|
| 1528 | - */ |
|
| 1529 | - public static function validate_messages_system() |
|
| 1530 | - { |
|
| 1531 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1532 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1533 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1534 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - |
|
| 1538 | - /** |
|
| 1539 | - * create_no_ticket_prices_array |
|
| 1540 | - * |
|
| 1541 | - * @access public |
|
| 1542 | - * @static |
|
| 1543 | - * @return void |
|
| 1544 | - */ |
|
| 1545 | - public static function create_no_ticket_prices_array() |
|
| 1546 | - { |
|
| 1547 | - // this creates an array for tracking events that have no active ticket prices created |
|
| 1548 | - // this allows us to warn admins of the situation so that it can be corrected |
|
| 1549 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1550 | - if (! $espresso_no_ticket_prices) { |
|
| 1551 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1552 | - } |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * plugin_deactivation |
|
| 1558 | - * |
|
| 1559 | - * @access public |
|
| 1560 | - * @static |
|
| 1561 | - * @return void |
|
| 1562 | - */ |
|
| 1563 | - public static function plugin_deactivation() |
|
| 1564 | - { |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1570 | - * (like post meta or term relations) |
|
| 1571 | - * |
|
| 1572 | - * @global wpdb $wpdb |
|
| 1573 | - * @throws \EE_Error |
|
| 1574 | - */ |
|
| 1575 | - public static function delete_all_espresso_cpt_data() |
|
| 1576 | - { |
|
| 1577 | - global $wpdb; |
|
| 1578 | - //get all the CPT post_types |
|
| 1579 | - $ee_post_types = array(); |
|
| 1580 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1581 | - if (method_exists($model_name, 'instance')) { |
|
| 1582 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1583 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1584 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1585 | - } |
|
| 1586 | - } |
|
| 1587 | - } |
|
| 1588 | - //get all our CPTs |
|
| 1589 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1590 | - $cpt_ids = $wpdb->get_col($query); |
|
| 1591 | - //delete each post meta and term relations too |
|
| 1592 | - foreach ($cpt_ids as $post_id) { |
|
| 1593 | - wp_delete_post($post_id, true); |
|
| 1594 | - } |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - /** |
|
| 1598 | - * Deletes all EE custom tables |
|
| 1599 | - * |
|
| 1600 | - * @return array |
|
| 1601 | - */ |
|
| 1602 | - public static function drop_espresso_tables() |
|
| 1603 | - { |
|
| 1604 | - $tables = array(); |
|
| 1605 | - // load registry |
|
| 1606 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1607 | - if (method_exists($model_name, 'instance')) { |
|
| 1608 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1609 | - if ($model_obj instanceof EEM_Base) { |
|
| 1610 | - foreach ($model_obj->get_tables() as $table) { |
|
| 1611 | - if (strpos($table->get_table_name(), 'esp_') |
|
| 1612 | - && |
|
| 1613 | - ( |
|
| 1614 | - is_main_site()//main site? nuke them all |
|
| 1615 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1616 | - ) |
|
| 1617 | - ) { |
|
| 1618 | - $tables[] = $table->get_table_name(); |
|
| 1619 | - } |
|
| 1620 | - } |
|
| 1621 | - } |
|
| 1622 | - } |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - //there are some tables whose models were removed. |
|
| 1626 | - //they should be removed when removing all EE core's data |
|
| 1627 | - $tables_without_models = array( |
|
| 1628 | - 'esp_promotion', |
|
| 1629 | - 'esp_promotion_applied', |
|
| 1630 | - 'esp_promotion_object', |
|
| 1631 | - 'esp_promotion_rule', |
|
| 1632 | - 'esp_rule', |
|
| 1633 | - ); |
|
| 1634 | - foreach ($tables_without_models as $table) { |
|
| 1635 | - $tables[] = $table; |
|
| 1636 | - } |
|
| 1637 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1638 | - } |
|
| 1639 | - |
|
| 1640 | - |
|
| 1641 | - |
|
| 1642 | - /** |
|
| 1643 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1644 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1645 | - * Returns the list actually deleted |
|
| 1646 | - * |
|
| 1647 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1648 | - * @global WPDB $wpdb |
|
| 1649 | - * @param array $table_names |
|
| 1650 | - * @return array of table names which we deleted |
|
| 1651 | - */ |
|
| 1652 | - public static function drop_tables($table_names) |
|
| 1653 | - { |
|
| 1654 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - |
|
| 1658 | - |
|
| 1659 | - /** |
|
| 1660 | - * plugin_uninstall |
|
| 1661 | - * |
|
| 1662 | - * @access public |
|
| 1663 | - * @static |
|
| 1664 | - * @param bool $remove_all |
|
| 1665 | - * @return void |
|
| 1666 | - */ |
|
| 1667 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1668 | - { |
|
| 1669 | - global $wpdb; |
|
| 1670 | - self::drop_espresso_tables(); |
|
| 1671 | - $wp_options_to_delete = array( |
|
| 1672 | - 'ee_no_ticket_prices' => true, |
|
| 1673 | - 'ee_active_messengers' => true, |
|
| 1674 | - 'ee_has_activated_messenger' => true, |
|
| 1675 | - 'ee_flush_rewrite_rules' => true, |
|
| 1676 | - 'ee_config' => false, |
|
| 1677 | - 'ee_data_migration_current_db_state' => true, |
|
| 1678 | - 'ee_data_migration_mapping_' => false, |
|
| 1679 | - 'ee_data_migration_script_' => false, |
|
| 1680 | - 'ee_data_migrations' => true, |
|
| 1681 | - 'ee_dms_map' => false, |
|
| 1682 | - 'ee_notices' => true, |
|
| 1683 | - 'lang_file_check_' => false, |
|
| 1684 | - 'ee_maintenance_mode' => true, |
|
| 1685 | - 'ee_ueip_optin' => true, |
|
| 1686 | - 'ee_ueip_has_notified' => true, |
|
| 1687 | - 'ee_plugin_activation_errors' => true, |
|
| 1688 | - 'ee_id_mapping_from' => false, |
|
| 1689 | - 'espresso_persistent_admin_notices' => true, |
|
| 1690 | - 'ee_encryption_key' => true, |
|
| 1691 | - 'pue_force_upgrade_' => false, |
|
| 1692 | - 'pue_json_error_' => false, |
|
| 1693 | - 'pue_install_key_' => false, |
|
| 1694 | - 'pue_verification_error_' => false, |
|
| 1695 | - 'pu_dismissed_upgrade_' => false, |
|
| 1696 | - 'external_updates-' => false, |
|
| 1697 | - 'ee_extra_data' => true, |
|
| 1698 | - 'ee_ssn_' => false, |
|
| 1699 | - 'ee_rss_' => false, |
|
| 1700 | - 'ee_rte_n_tx_' => false, |
|
| 1701 | - 'ee_pers_admin_notices' => true, |
|
| 1702 | - 'ee_job_parameters_' => false, |
|
| 1703 | - 'ee_upload_directories_incomplete' => true, |
|
| 1704 | - 'ee_verified_db_collations' => true, |
|
| 1705 | - ); |
|
| 1706 | - if (is_main_site()) { |
|
| 1707 | - $wp_options_to_delete['ee_network_config'] = true; |
|
| 1708 | - } |
|
| 1709 | - $undeleted_options = array(); |
|
| 1710 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1711 | - if ($no_wildcard) { |
|
| 1712 | - if ( ! delete_option($option_name)) { |
|
| 1713 | - $undeleted_options[] = $option_name; |
|
| 1714 | - } |
|
| 1715 | - } else { |
|
| 1716 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1717 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1718 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1719 | - $undeleted_options[] = $option_name_from_wildcard; |
|
| 1720 | - } |
|
| 1721 | - } |
|
| 1722 | - } |
|
| 1723 | - } |
|
| 1724 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1725 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1726 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1727 | - $db_update_sans_ee4 = array(); |
|
| 1728 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1729 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1730 | - $db_update_sans_ee4[$version] = $times_activated; |
|
| 1731 | - } |
|
| 1732 | - } |
|
| 1733 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1734 | - } |
|
| 1735 | - $errors = ''; |
|
| 1736 | - if ( ! empty($undeleted_options)) { |
|
| 1737 | - $errors .= sprintf( |
|
| 1738 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1739 | - '<br/>', |
|
| 1740 | - implode(',<br/>', $undeleted_options) |
|
| 1741 | - ); |
|
| 1742 | - } |
|
| 1743 | - if ( ! empty($errors)) { |
|
| 1744 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1745 | - } |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - /** |
|
| 1749 | - * Gets the mysql error code from the last used query by wpdb |
|
| 1750 | - * |
|
| 1751 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1752 | - */ |
|
| 1753 | - public static function last_wpdb_error_code() |
|
| 1754 | - { |
|
| 1755 | - global $wpdb; |
|
| 1756 | - if ($wpdb->use_mysqli) { |
|
| 1757 | - return mysqli_errno($wpdb->dbh); |
|
| 1758 | - } else { |
|
| 1759 | - return mysql_errno($wpdb->dbh); |
|
| 1760 | - } |
|
| 1761 | - } |
|
| 1762 | - |
|
| 1763 | - /** |
|
| 1764 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1765 | - * |
|
| 1766 | - * @global wpdb $wpdb |
|
| 1767 | - * @deprecated instead use TableAnalysis::tableExists() |
|
| 1768 | - * @param string $table_name with or without $wpdb->prefix |
|
| 1769 | - * @return boolean |
|
| 1770 | - */ |
|
| 1771 | - public static function table_exists($table_name) |
|
| 1772 | - { |
|
| 1773 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - /** |
|
| 1777 | - * Resets the cache on EEH_Activation |
|
| 1778 | - */ |
|
| 1779 | - public static function reset() |
|
| 1780 | - { |
|
| 1781 | - self::$_default_creator_id = null; |
|
| 1782 | - self::$_initialized_db_content_already_in_this_request = false; |
|
| 1783 | - } |
|
| 1353 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1354 | + $message_resource_manager |
|
| 1355 | + ); |
|
| 1356 | + /** |
|
| 1357 | + * This method is verifying there are no NEW default message types |
|
| 1358 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1359 | + */ |
|
| 1360 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1361 | + $message_resource_manager |
|
| 1362 | + ); |
|
| 1363 | + //after all is done, let's persist these changes to the db. |
|
| 1364 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1365 | + $message_resource_manager->update_active_messengers_option(); |
|
| 1366 | + // will return true if either of these are true. Otherwise will return false. |
|
| 1367 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + |
|
| 1371 | + |
|
| 1372 | + /** |
|
| 1373 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1374 | + * @return array|bool |
|
| 1375 | + * @throws \EE_Error |
|
| 1376 | + */ |
|
| 1377 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1378 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1379 | + ) { |
|
| 1380 | + /** @type EE_messenger[] $active_messengers */ |
|
| 1381 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1382 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1383 | + $templates_created = false; |
|
| 1384 | + foreach ($active_messengers as $active_messenger) { |
|
| 1385 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1386 | + $default_message_type_names_to_activate = array(); |
|
| 1387 | + // looping through each default message type reported by the messenger |
|
| 1388 | + // and setup the actual message types to activate. |
|
| 1389 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1390 | + // if already active or has already been activated before we skip |
|
| 1391 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1392 | + // we also skip if the message type is not installed. |
|
| 1393 | + if ( |
|
| 1394 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1395 | + $default_message_type_name_for_messenger, |
|
| 1396 | + $active_messenger->name |
|
| 1397 | + ) |
|
| 1398 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1399 | + $active_messenger->name, |
|
| 1400 | + $default_message_type_name_for_messenger |
|
| 1401 | + ) |
|
| 1402 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1403 | + ) { |
|
| 1404 | + continue; |
|
| 1405 | + } |
|
| 1406 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1407 | + } |
|
| 1408 | + //let's activate! |
|
| 1409 | + $message_resource_manager->ensure_message_types_are_active( |
|
| 1410 | + $default_message_type_names_to_activate, |
|
| 1411 | + $active_messenger->name, |
|
| 1412 | + false |
|
| 1413 | + ); |
|
| 1414 | + //activate the templates for these message types |
|
| 1415 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1416 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1417 | + $active_messenger->name, |
|
| 1418 | + $default_message_type_names_for_messenger, |
|
| 1419 | + '', |
|
| 1420 | + true |
|
| 1421 | + ); |
|
| 1422 | + } |
|
| 1423 | + } |
|
| 1424 | + return $templates_created; |
|
| 1425 | + } |
|
| 1426 | + |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * This will activate and generate default messengers and default message types for those messengers. |
|
| 1431 | + * |
|
| 1432 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1433 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1434 | + * False means that there were no templates generated |
|
| 1435 | + * (which could simply mean there are no default message types for a messenger). |
|
| 1436 | + * @throws EE_Error |
|
| 1437 | + */ |
|
| 1438 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1439 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1440 | + ) { |
|
| 1441 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1442 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1443 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1444 | + $templates_generated = false; |
|
| 1445 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1446 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1447 | + //verify the default message types match an installed message type. |
|
| 1448 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1449 | + if ( |
|
| 1450 | + ! isset($installed_message_types[$name]) |
|
| 1451 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1452 | + $name, |
|
| 1453 | + $messenger_to_generate->name |
|
| 1454 | + ) |
|
| 1455 | + ) { |
|
| 1456 | + unset($default_message_type_names_for_messenger[$key]); |
|
| 1457 | + } |
|
| 1458 | + } |
|
| 1459 | + // in previous iterations, the active_messengers option in the db |
|
| 1460 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1461 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1462 | + // passing off to create templates (after the refactor is done). |
|
| 1463 | + // @todo remove this comment when determined not necessary. |
|
| 1464 | + $message_resource_manager->activate_messenger( |
|
| 1465 | + $messenger_to_generate->name, |
|
| 1466 | + $default_message_type_names_for_messenger, |
|
| 1467 | + false |
|
| 1468 | + ); |
|
| 1469 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1470 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1471 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1472 | + $messenger_to_generate->name, |
|
| 1473 | + $default_message_type_names_for_messenger, |
|
| 1474 | + '', |
|
| 1475 | + true |
|
| 1476 | + ); |
|
| 1477 | + } |
|
| 1478 | + } |
|
| 1479 | + return $templates_generated; |
|
| 1480 | + } |
|
| 1481 | + |
|
| 1482 | + |
|
| 1483 | + /** |
|
| 1484 | + * This returns the default messengers to generate templates for on activation of EE. |
|
| 1485 | + * It considers: |
|
| 1486 | + * - whether a messenger is already active in the db. |
|
| 1487 | + * - whether a messenger has been made active at any time in the past. |
|
| 1488 | + * |
|
| 1489 | + * @static |
|
| 1490 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1491 | + * @return EE_messenger[] |
|
| 1492 | + */ |
|
| 1493 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1494 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1495 | + ) { |
|
| 1496 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1497 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1498 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1499 | + |
|
| 1500 | + $messengers_to_generate = array(); |
|
| 1501 | + foreach ($installed_messengers as $installed_messenger) { |
|
| 1502 | + //if installed messenger is a messenger that should be activated on install |
|
| 1503 | + //and is not already active |
|
| 1504 | + //and has never been activated |
|
| 1505 | + if ( |
|
| 1506 | + ! $installed_messenger->activate_on_install |
|
| 1507 | + || isset($active_messengers[$installed_messenger->name]) |
|
| 1508 | + || isset($has_activated[$installed_messenger->name]) |
|
| 1509 | + ) { |
|
| 1510 | + continue; |
|
| 1511 | + } |
|
| 1512 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1513 | + } |
|
| 1514 | + return $messengers_to_generate; |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + |
|
| 1518 | + /** |
|
| 1519 | + * This simply validates active message types to ensure they actually match installed |
|
| 1520 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1521 | + * rows are set inactive. |
|
| 1522 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1523 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1524 | + * are still handled in here. |
|
| 1525 | + * |
|
| 1526 | + * @since 4.3.1 |
|
| 1527 | + * @return void |
|
| 1528 | + */ |
|
| 1529 | + public static function validate_messages_system() |
|
| 1530 | + { |
|
| 1531 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1532 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1533 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1534 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + |
|
| 1538 | + /** |
|
| 1539 | + * create_no_ticket_prices_array |
|
| 1540 | + * |
|
| 1541 | + * @access public |
|
| 1542 | + * @static |
|
| 1543 | + * @return void |
|
| 1544 | + */ |
|
| 1545 | + public static function create_no_ticket_prices_array() |
|
| 1546 | + { |
|
| 1547 | + // this creates an array for tracking events that have no active ticket prices created |
|
| 1548 | + // this allows us to warn admins of the situation so that it can be corrected |
|
| 1549 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1550 | + if (! $espresso_no_ticket_prices) { |
|
| 1551 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1552 | + } |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * plugin_deactivation |
|
| 1558 | + * |
|
| 1559 | + * @access public |
|
| 1560 | + * @static |
|
| 1561 | + * @return void |
|
| 1562 | + */ |
|
| 1563 | + public static function plugin_deactivation() |
|
| 1564 | + { |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1570 | + * (like post meta or term relations) |
|
| 1571 | + * |
|
| 1572 | + * @global wpdb $wpdb |
|
| 1573 | + * @throws \EE_Error |
|
| 1574 | + */ |
|
| 1575 | + public static function delete_all_espresso_cpt_data() |
|
| 1576 | + { |
|
| 1577 | + global $wpdb; |
|
| 1578 | + //get all the CPT post_types |
|
| 1579 | + $ee_post_types = array(); |
|
| 1580 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1581 | + if (method_exists($model_name, 'instance')) { |
|
| 1582 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1583 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1584 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1585 | + } |
|
| 1586 | + } |
|
| 1587 | + } |
|
| 1588 | + //get all our CPTs |
|
| 1589 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1590 | + $cpt_ids = $wpdb->get_col($query); |
|
| 1591 | + //delete each post meta and term relations too |
|
| 1592 | + foreach ($cpt_ids as $post_id) { |
|
| 1593 | + wp_delete_post($post_id, true); |
|
| 1594 | + } |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + /** |
|
| 1598 | + * Deletes all EE custom tables |
|
| 1599 | + * |
|
| 1600 | + * @return array |
|
| 1601 | + */ |
|
| 1602 | + public static function drop_espresso_tables() |
|
| 1603 | + { |
|
| 1604 | + $tables = array(); |
|
| 1605 | + // load registry |
|
| 1606 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1607 | + if (method_exists($model_name, 'instance')) { |
|
| 1608 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1609 | + if ($model_obj instanceof EEM_Base) { |
|
| 1610 | + foreach ($model_obj->get_tables() as $table) { |
|
| 1611 | + if (strpos($table->get_table_name(), 'esp_') |
|
| 1612 | + && |
|
| 1613 | + ( |
|
| 1614 | + is_main_site()//main site? nuke them all |
|
| 1615 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1616 | + ) |
|
| 1617 | + ) { |
|
| 1618 | + $tables[] = $table->get_table_name(); |
|
| 1619 | + } |
|
| 1620 | + } |
|
| 1621 | + } |
|
| 1622 | + } |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + //there are some tables whose models were removed. |
|
| 1626 | + //they should be removed when removing all EE core's data |
|
| 1627 | + $tables_without_models = array( |
|
| 1628 | + 'esp_promotion', |
|
| 1629 | + 'esp_promotion_applied', |
|
| 1630 | + 'esp_promotion_object', |
|
| 1631 | + 'esp_promotion_rule', |
|
| 1632 | + 'esp_rule', |
|
| 1633 | + ); |
|
| 1634 | + foreach ($tables_without_models as $table) { |
|
| 1635 | + $tables[] = $table; |
|
| 1636 | + } |
|
| 1637 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1638 | + } |
|
| 1639 | + |
|
| 1640 | + |
|
| 1641 | + |
|
| 1642 | + /** |
|
| 1643 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1644 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1645 | + * Returns the list actually deleted |
|
| 1646 | + * |
|
| 1647 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1648 | + * @global WPDB $wpdb |
|
| 1649 | + * @param array $table_names |
|
| 1650 | + * @return array of table names which we deleted |
|
| 1651 | + */ |
|
| 1652 | + public static function drop_tables($table_names) |
|
| 1653 | + { |
|
| 1654 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + |
|
| 1658 | + |
|
| 1659 | + /** |
|
| 1660 | + * plugin_uninstall |
|
| 1661 | + * |
|
| 1662 | + * @access public |
|
| 1663 | + * @static |
|
| 1664 | + * @param bool $remove_all |
|
| 1665 | + * @return void |
|
| 1666 | + */ |
|
| 1667 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1668 | + { |
|
| 1669 | + global $wpdb; |
|
| 1670 | + self::drop_espresso_tables(); |
|
| 1671 | + $wp_options_to_delete = array( |
|
| 1672 | + 'ee_no_ticket_prices' => true, |
|
| 1673 | + 'ee_active_messengers' => true, |
|
| 1674 | + 'ee_has_activated_messenger' => true, |
|
| 1675 | + 'ee_flush_rewrite_rules' => true, |
|
| 1676 | + 'ee_config' => false, |
|
| 1677 | + 'ee_data_migration_current_db_state' => true, |
|
| 1678 | + 'ee_data_migration_mapping_' => false, |
|
| 1679 | + 'ee_data_migration_script_' => false, |
|
| 1680 | + 'ee_data_migrations' => true, |
|
| 1681 | + 'ee_dms_map' => false, |
|
| 1682 | + 'ee_notices' => true, |
|
| 1683 | + 'lang_file_check_' => false, |
|
| 1684 | + 'ee_maintenance_mode' => true, |
|
| 1685 | + 'ee_ueip_optin' => true, |
|
| 1686 | + 'ee_ueip_has_notified' => true, |
|
| 1687 | + 'ee_plugin_activation_errors' => true, |
|
| 1688 | + 'ee_id_mapping_from' => false, |
|
| 1689 | + 'espresso_persistent_admin_notices' => true, |
|
| 1690 | + 'ee_encryption_key' => true, |
|
| 1691 | + 'pue_force_upgrade_' => false, |
|
| 1692 | + 'pue_json_error_' => false, |
|
| 1693 | + 'pue_install_key_' => false, |
|
| 1694 | + 'pue_verification_error_' => false, |
|
| 1695 | + 'pu_dismissed_upgrade_' => false, |
|
| 1696 | + 'external_updates-' => false, |
|
| 1697 | + 'ee_extra_data' => true, |
|
| 1698 | + 'ee_ssn_' => false, |
|
| 1699 | + 'ee_rss_' => false, |
|
| 1700 | + 'ee_rte_n_tx_' => false, |
|
| 1701 | + 'ee_pers_admin_notices' => true, |
|
| 1702 | + 'ee_job_parameters_' => false, |
|
| 1703 | + 'ee_upload_directories_incomplete' => true, |
|
| 1704 | + 'ee_verified_db_collations' => true, |
|
| 1705 | + ); |
|
| 1706 | + if (is_main_site()) { |
|
| 1707 | + $wp_options_to_delete['ee_network_config'] = true; |
|
| 1708 | + } |
|
| 1709 | + $undeleted_options = array(); |
|
| 1710 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1711 | + if ($no_wildcard) { |
|
| 1712 | + if ( ! delete_option($option_name)) { |
|
| 1713 | + $undeleted_options[] = $option_name; |
|
| 1714 | + } |
|
| 1715 | + } else { |
|
| 1716 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1717 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1718 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1719 | + $undeleted_options[] = $option_name_from_wildcard; |
|
| 1720 | + } |
|
| 1721 | + } |
|
| 1722 | + } |
|
| 1723 | + } |
|
| 1724 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1725 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1726 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1727 | + $db_update_sans_ee4 = array(); |
|
| 1728 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1729 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1730 | + $db_update_sans_ee4[$version] = $times_activated; |
|
| 1731 | + } |
|
| 1732 | + } |
|
| 1733 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1734 | + } |
|
| 1735 | + $errors = ''; |
|
| 1736 | + if ( ! empty($undeleted_options)) { |
|
| 1737 | + $errors .= sprintf( |
|
| 1738 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1739 | + '<br/>', |
|
| 1740 | + implode(',<br/>', $undeleted_options) |
|
| 1741 | + ); |
|
| 1742 | + } |
|
| 1743 | + if ( ! empty($errors)) { |
|
| 1744 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1745 | + } |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + /** |
|
| 1749 | + * Gets the mysql error code from the last used query by wpdb |
|
| 1750 | + * |
|
| 1751 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1752 | + */ |
|
| 1753 | + public static function last_wpdb_error_code() |
|
| 1754 | + { |
|
| 1755 | + global $wpdb; |
|
| 1756 | + if ($wpdb->use_mysqli) { |
|
| 1757 | + return mysqli_errno($wpdb->dbh); |
|
| 1758 | + } else { |
|
| 1759 | + return mysql_errno($wpdb->dbh); |
|
| 1760 | + } |
|
| 1761 | + } |
|
| 1762 | + |
|
| 1763 | + /** |
|
| 1764 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1765 | + * |
|
| 1766 | + * @global wpdb $wpdb |
|
| 1767 | + * @deprecated instead use TableAnalysis::tableExists() |
|
| 1768 | + * @param string $table_name with or without $wpdb->prefix |
|
| 1769 | + * @return boolean |
|
| 1770 | + */ |
|
| 1771 | + public static function table_exists($table_name) |
|
| 1772 | + { |
|
| 1773 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + /** |
|
| 1777 | + * Resets the cache on EEH_Activation |
|
| 1778 | + */ |
|
| 1779 | + public static function reset() |
|
| 1780 | + { |
|
| 1781 | + self::$_default_creator_id = null; |
|
| 1782 | + self::$_initialized_db_content_already_in_this_request = false; |
|
| 1783 | + } |
|
| 1784 | 1784 | } |
| 1785 | 1785 | // End of file EEH_Activation.helper.php |
| 1786 | 1786 | // Location: /helpers/EEH_Activation.core.php |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -26,233 +26,233 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * return the timezone set for the WP install |
|
| 31 | - * |
|
| 32 | - * @return string valid timezone string for PHP DateTimeZone() class |
|
| 33 | - */ |
|
| 34 | - public static function get_timezone() |
|
| 35 | - { |
|
| 36 | - return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * get_valid_timezone_string |
|
| 42 | - * ensures that a valid timezone string is returned |
|
| 43 | - * |
|
| 44 | - * @access protected |
|
| 45 | - * @param string $timezone_string |
|
| 46 | - * @return string |
|
| 47 | - * @throws \EE_Error |
|
| 48 | - */ |
|
| 49 | - public static function get_valid_timezone_string($timezone_string = '') |
|
| 50 | - { |
|
| 51 | - // if passed a value, then use that, else get WP option |
|
| 52 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 53 | - // value from above exists, use that, else get timezone string from gmt_offset |
|
| 54 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 55 | - EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 56 | - return $timezone_string; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 62 | - * |
|
| 63 | - * @static |
|
| 64 | - * @access public |
|
| 65 | - * @param string $timezone_string Timezone string to check |
|
| 66 | - * @param bool $throw_error |
|
| 67 | - * @return bool |
|
| 68 | - * @throws \EE_Error |
|
| 69 | - */ |
|
| 70 | - public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 71 | - { |
|
| 72 | - // 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 |
|
| 73 | - try { |
|
| 74 | - new DateTimeZone($timezone_string); |
|
| 75 | - } catch (Exception $e) { |
|
| 76 | - // sometimes we take exception to exceptions |
|
| 77 | - if (! $throw_error) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - throw new EE_Error( |
|
| 81 | - sprintf( |
|
| 82 | - __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 83 | - 'event_espresso'), |
|
| 84 | - $timezone_string, |
|
| 85 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 86 | - '</a>' |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - return true; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * _create_timezone_object_from_timezone_name |
|
| 96 | - * |
|
| 97 | - * @access protected |
|
| 98 | - * @param string $gmt_offset |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 102 | - { |
|
| 103 | - $timezone_string = 'UTC'; |
|
| 104 | - $gmt_offset = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset'); |
|
| 105 | - if ($gmt_offset !== '') { |
|
| 106 | - // convert GMT offset to seconds |
|
| 107 | - $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 108 | - // account for WP offsets that aren't valid UTC |
|
| 109 | - $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset); |
|
| 110 | - // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 111 | - $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 112 | - } |
|
| 113 | - // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 114 | - $timezone_string = $timezone_string !== false |
|
| 115 | - ? $timezone_string |
|
| 116 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 117 | - return $timezone_string; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Gets the site's GMT offset based on either the timezone string |
|
| 122 | - * (in which case teh gmt offset will vary depending on the location's |
|
| 123 | - * observance of daylight savings time) or the gmt_offset wp option |
|
| 124 | - * |
|
| 125 | - * @return int seconds offset |
|
| 126 | - */ |
|
| 127 | - public static function get_site_timezone_gmt_offset() |
|
| 128 | - { |
|
| 129 | - $timezone_string = get_option('timezone_string'); |
|
| 130 | - if ($timezone_string) { |
|
| 131 | - try { |
|
| 132 | - $timezone = new DateTimeZone($timezone_string); |
|
| 133 | - return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 134 | - } catch (Exception $e) { |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - $offset = get_option('gmt_offset'); |
|
| 138 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * _create_timezone_object_from_timezone_name |
|
| 144 | - * |
|
| 145 | - * @access public |
|
| 146 | - * @param int $gmt_offset |
|
| 147 | - * @return int |
|
| 148 | - */ |
|
| 149 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 150 | - { |
|
| 151 | - //make sure $gmt_offset is int |
|
| 152 | - $gmt_offset = (int)$gmt_offset; |
|
| 153 | - switch ($gmt_offset) { |
|
| 154 | - |
|
| 155 | - // case -30600 : |
|
| 156 | - // $gmt_offset = -28800; |
|
| 157 | - // break; |
|
| 158 | - |
|
| 159 | - case -27000 : |
|
| 160 | - $gmt_offset = -25200; |
|
| 161 | - break; |
|
| 162 | - |
|
| 163 | - case -23400 : |
|
| 164 | - $gmt_offset = -21600; |
|
| 165 | - break; |
|
| 166 | - |
|
| 167 | - case -19800 : |
|
| 168 | - $gmt_offset = -18000; |
|
| 169 | - break; |
|
| 170 | - |
|
| 171 | - case -9000 : |
|
| 172 | - $gmt_offset = -7200; |
|
| 173 | - break; |
|
| 174 | - |
|
| 175 | - case -5400 : |
|
| 176 | - $gmt_offset = -3600; |
|
| 177 | - break; |
|
| 178 | - |
|
| 179 | - case -1800 : |
|
| 180 | - $gmt_offset = 0; |
|
| 181 | - break; |
|
| 182 | - |
|
| 183 | - case 1800 : |
|
| 184 | - $gmt_offset = 3600; |
|
| 185 | - break; |
|
| 186 | - |
|
| 187 | - case 49500 : |
|
| 188 | - $gmt_offset = 50400; |
|
| 189 | - break; |
|
| 190 | - |
|
| 191 | - } |
|
| 192 | - return $gmt_offset; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * get_timezone_string_from_abbreviations_list |
|
| 198 | - * |
|
| 199 | - * @access public |
|
| 200 | - * @param int $gmt_offset |
|
| 201 | - * @return string |
|
| 202 | - * @throws \EE_Error |
|
| 203 | - */ |
|
| 204 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0) |
|
| 205 | - { |
|
| 206 | - $abbreviations = timezone_abbreviations_list(); |
|
| 207 | - foreach ($abbreviations as $abbreviation) { |
|
| 208 | - foreach ($abbreviation as $city) { |
|
| 209 | - if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 210 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
| 211 | - if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) { |
|
| 212 | - return $city['timezone_id']; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - throw new EE_Error( |
|
| 218 | - sprintf( |
|
| 219 | - __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 220 | - 'event_espresso'), |
|
| 221 | - $gmt_offset, |
|
| 222 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 223 | - '</a>' |
|
| 224 | - ) |
|
| 225 | - ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @access public |
|
| 231 | - * @param string $timezone_string |
|
| 232 | - */ |
|
| 233 | - public static function timezone_select_input($timezone_string = '') |
|
| 234 | - { |
|
| 235 | - // get WP date time format |
|
| 236 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 237 | - // if passed a value, then use that, else get WP option |
|
| 238 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 239 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
| 240 | - $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 241 | - $gmt_offset = get_option('gmt_offset'); |
|
| 242 | - |
|
| 243 | - $check_zone_info = true; |
|
| 244 | - if (empty($timezone_string)) { |
|
| 245 | - // Create a UTC+- zone if no timezone string exists |
|
| 246 | - $check_zone_info = false; |
|
| 247 | - if ($gmt_offset > 0) { |
|
| 248 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 249 | - } elseif ($gmt_offset < 0) { |
|
| 250 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 251 | - } else { |
|
| 252 | - $timezone_string = 'UTC'; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - ?> |
|
| 29 | + /** |
|
| 30 | + * return the timezone set for the WP install |
|
| 31 | + * |
|
| 32 | + * @return string valid timezone string for PHP DateTimeZone() class |
|
| 33 | + */ |
|
| 34 | + public static function get_timezone() |
|
| 35 | + { |
|
| 36 | + return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * get_valid_timezone_string |
|
| 42 | + * ensures that a valid timezone string is returned |
|
| 43 | + * |
|
| 44 | + * @access protected |
|
| 45 | + * @param string $timezone_string |
|
| 46 | + * @return string |
|
| 47 | + * @throws \EE_Error |
|
| 48 | + */ |
|
| 49 | + public static function get_valid_timezone_string($timezone_string = '') |
|
| 50 | + { |
|
| 51 | + // if passed a value, then use that, else get WP option |
|
| 52 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 53 | + // value from above exists, use that, else get timezone string from gmt_offset |
|
| 54 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 55 | + EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 56 | + return $timezone_string; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 62 | + * |
|
| 63 | + * @static |
|
| 64 | + * @access public |
|
| 65 | + * @param string $timezone_string Timezone string to check |
|
| 66 | + * @param bool $throw_error |
|
| 67 | + * @return bool |
|
| 68 | + * @throws \EE_Error |
|
| 69 | + */ |
|
| 70 | + public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 71 | + { |
|
| 72 | + // 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 |
|
| 73 | + try { |
|
| 74 | + new DateTimeZone($timezone_string); |
|
| 75 | + } catch (Exception $e) { |
|
| 76 | + // sometimes we take exception to exceptions |
|
| 77 | + if (! $throw_error) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + throw new EE_Error( |
|
| 81 | + sprintf( |
|
| 82 | + __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 83 | + 'event_espresso'), |
|
| 84 | + $timezone_string, |
|
| 85 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 86 | + '</a>' |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * _create_timezone_object_from_timezone_name |
|
| 96 | + * |
|
| 97 | + * @access protected |
|
| 98 | + * @param string $gmt_offset |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 102 | + { |
|
| 103 | + $timezone_string = 'UTC'; |
|
| 104 | + $gmt_offset = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset'); |
|
| 105 | + if ($gmt_offset !== '') { |
|
| 106 | + // convert GMT offset to seconds |
|
| 107 | + $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 108 | + // account for WP offsets that aren't valid UTC |
|
| 109 | + $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset); |
|
| 110 | + // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 111 | + $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 112 | + } |
|
| 113 | + // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 114 | + $timezone_string = $timezone_string !== false |
|
| 115 | + ? $timezone_string |
|
| 116 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 117 | + return $timezone_string; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Gets the site's GMT offset based on either the timezone string |
|
| 122 | + * (in which case teh gmt offset will vary depending on the location's |
|
| 123 | + * observance of daylight savings time) or the gmt_offset wp option |
|
| 124 | + * |
|
| 125 | + * @return int seconds offset |
|
| 126 | + */ |
|
| 127 | + public static function get_site_timezone_gmt_offset() |
|
| 128 | + { |
|
| 129 | + $timezone_string = get_option('timezone_string'); |
|
| 130 | + if ($timezone_string) { |
|
| 131 | + try { |
|
| 132 | + $timezone = new DateTimeZone($timezone_string); |
|
| 133 | + return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 134 | + } catch (Exception $e) { |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + $offset = get_option('gmt_offset'); |
|
| 138 | + return (int)($offset * HOUR_IN_SECONDS); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * _create_timezone_object_from_timezone_name |
|
| 144 | + * |
|
| 145 | + * @access public |
|
| 146 | + * @param int $gmt_offset |
|
| 147 | + * @return int |
|
| 148 | + */ |
|
| 149 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 150 | + { |
|
| 151 | + //make sure $gmt_offset is int |
|
| 152 | + $gmt_offset = (int)$gmt_offset; |
|
| 153 | + switch ($gmt_offset) { |
|
| 154 | + |
|
| 155 | + // case -30600 : |
|
| 156 | + // $gmt_offset = -28800; |
|
| 157 | + // break; |
|
| 158 | + |
|
| 159 | + case -27000 : |
|
| 160 | + $gmt_offset = -25200; |
|
| 161 | + break; |
|
| 162 | + |
|
| 163 | + case -23400 : |
|
| 164 | + $gmt_offset = -21600; |
|
| 165 | + break; |
|
| 166 | + |
|
| 167 | + case -19800 : |
|
| 168 | + $gmt_offset = -18000; |
|
| 169 | + break; |
|
| 170 | + |
|
| 171 | + case -9000 : |
|
| 172 | + $gmt_offset = -7200; |
|
| 173 | + break; |
|
| 174 | + |
|
| 175 | + case -5400 : |
|
| 176 | + $gmt_offset = -3600; |
|
| 177 | + break; |
|
| 178 | + |
|
| 179 | + case -1800 : |
|
| 180 | + $gmt_offset = 0; |
|
| 181 | + break; |
|
| 182 | + |
|
| 183 | + case 1800 : |
|
| 184 | + $gmt_offset = 3600; |
|
| 185 | + break; |
|
| 186 | + |
|
| 187 | + case 49500 : |
|
| 188 | + $gmt_offset = 50400; |
|
| 189 | + break; |
|
| 190 | + |
|
| 191 | + } |
|
| 192 | + return $gmt_offset; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * get_timezone_string_from_abbreviations_list |
|
| 198 | + * |
|
| 199 | + * @access public |
|
| 200 | + * @param int $gmt_offset |
|
| 201 | + * @return string |
|
| 202 | + * @throws \EE_Error |
|
| 203 | + */ |
|
| 204 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0) |
|
| 205 | + { |
|
| 206 | + $abbreviations = timezone_abbreviations_list(); |
|
| 207 | + foreach ($abbreviations as $abbreviation) { |
|
| 208 | + foreach ($abbreviation as $city) { |
|
| 209 | + if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 210 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
| 211 | + if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) { |
|
| 212 | + return $city['timezone_id']; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + throw new EE_Error( |
|
| 218 | + sprintf( |
|
| 219 | + __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 220 | + 'event_espresso'), |
|
| 221 | + $gmt_offset, |
|
| 222 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 223 | + '</a>' |
|
| 224 | + ) |
|
| 225 | + ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @access public |
|
| 231 | + * @param string $timezone_string |
|
| 232 | + */ |
|
| 233 | + public static function timezone_select_input($timezone_string = '') |
|
| 234 | + { |
|
| 235 | + // get WP date time format |
|
| 236 | + $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 237 | + // if passed a value, then use that, else get WP option |
|
| 238 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 239 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
| 240 | + $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 241 | + $gmt_offset = get_option('gmt_offset'); |
|
| 242 | + |
|
| 243 | + $check_zone_info = true; |
|
| 244 | + if (empty($timezone_string)) { |
|
| 245 | + // Create a UTC+- zone if no timezone string exists |
|
| 246 | + $check_zone_info = false; |
|
| 247 | + if ($gmt_offset > 0) { |
|
| 248 | + $timezone_string = 'UTC+' . $gmt_offset; |
|
| 249 | + } elseif ($gmt_offset < 0) { |
|
| 250 | + $timezone_string = 'UTC' . $gmt_offset; |
|
| 251 | + } else { |
|
| 252 | + $timezone_string = 'UTC'; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + ?> |
|
| 256 | 256 | |
| 257 | 257 | <p> |
| 258 | 258 | <label for="timezone_string"><?php _e('timezone'); ?></label> |
@@ -265,13 +265,13 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | <p> |
| 267 | 267 | <span><?php |
| 268 | - printf( |
|
| 269 | - __('%1$sUTC%2$s time is %3$s'), |
|
| 270 | - '<abbr title="Coordinated Universal Time">', |
|
| 271 | - '</abbr>', |
|
| 272 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 273 | - ); |
|
| 274 | - ?></span> |
|
| 268 | + printf( |
|
| 269 | + __('%1$sUTC%2$s time is %3$s'), |
|
| 270 | + '<abbr title="Coordinated Universal Time">', |
|
| 271 | + '</abbr>', |
|
| 272 | + '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 273 | + ); |
|
| 274 | + ?></span> |
|
| 275 | 275 | <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
| 276 | 276 | <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
| 277 | 277 | <?php endif; ?> |
@@ -280,650 +280,650 @@ discard block |
||
| 280 | 280 | <br/> |
| 281 | 281 | <span> |
| 282 | 282 | <?php |
| 283 | - // Set TZ so localtime works. |
|
| 284 | - date_default_timezone_set($timezone_string); |
|
| 285 | - $now = localtime(time(), true); |
|
| 286 | - if ($now['tm_isdst']) { |
|
| 287 | - _e('This timezone is currently in daylight saving time.'); |
|
| 288 | - } else { |
|
| 289 | - _e('This timezone is currently in standard time.'); |
|
| 290 | - } |
|
| 291 | - ?> |
|
| 283 | + // Set TZ so localtime works. |
|
| 284 | + date_default_timezone_set($timezone_string); |
|
| 285 | + $now = localtime(time(), true); |
|
| 286 | + if ($now['tm_isdst']) { |
|
| 287 | + _e('This timezone is currently in daylight saving time.'); |
|
| 288 | + } else { |
|
| 289 | + _e('This timezone is currently in standard time.'); |
|
| 290 | + } |
|
| 291 | + ?> |
|
| 292 | 292 | <br/> |
| 293 | 293 | <?php |
| 294 | - if (function_exists('timezone_transitions_get')) { |
|
| 295 | - $found = false; |
|
| 296 | - $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 297 | - $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 298 | - $right_now = time(); |
|
| 299 | - $tr['isdst'] = false; |
|
| 300 | - foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 301 | - if ($tr['ts'] > $right_now) { |
|
| 302 | - $found = true; |
|
| 303 | - break; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - if ($found) { |
|
| 308 | - $message = $tr['isdst'] ? |
|
| 309 | - __(' Daylight saving time begins on: %s.') : |
|
| 310 | - __(' Standard time begins on: %s.'); |
|
| 311 | - // 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, |
|
| 313 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 314 | - } else { |
|
| 315 | - _e('This timezone does not observe daylight saving time.'); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - // Set back to UTC. |
|
| 319 | - date_default_timezone_set('UTC'); |
|
| 320 | - ?> |
|
| 294 | + if (function_exists('timezone_transitions_get')) { |
|
| 295 | + $found = false; |
|
| 296 | + $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 297 | + $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 298 | + $right_now = time(); |
|
| 299 | + $tr['isdst'] = false; |
|
| 300 | + foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 301 | + if ($tr['ts'] > $right_now) { |
|
| 302 | + $found = true; |
|
| 303 | + break; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + if ($found) { |
|
| 308 | + $message = $tr['isdst'] ? |
|
| 309 | + __(' Daylight saving time begins on: %s.') : |
|
| 310 | + __(' Standard time begins on: %s.'); |
|
| 311 | + // 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, |
|
| 313 | + '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 314 | + } else { |
|
| 315 | + _e('This timezone does not observe daylight saving time.'); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + // Set back to UTC. |
|
| 319 | + date_default_timezone_set('UTC'); |
|
| 320 | + ?> |
|
| 321 | 321 | </span></p> |
| 322 | 322 | <?php |
| 323 | - endif; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 329 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 330 | - * the site is used. |
|
| 331 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 332 | - * computed timestamp (i.e. date_i18n() ) |
|
| 333 | - * |
|
| 334 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
| 335 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 336 | - * site will be used. |
|
| 337 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 338 | - */ |
|
| 339 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 340 | - { |
|
| 341 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 342 | - $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 343 | - $TimeZone = new DateTimeZone($timezone_string); |
|
| 344 | - |
|
| 345 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 346 | - $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 347 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * _set_date_time_field |
|
| 353 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 354 | - * |
|
| 355 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 356 | - * @param DateTime $DateTime PHP DateTime object |
|
| 357 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 358 | - * @return EE_Base_Class |
|
| 359 | - */ |
|
| 360 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 361 | - { |
|
| 362 | - // grab current datetime format |
|
| 363 | - $current_format = $obj->get_format(); |
|
| 364 | - // set new full timestamp format |
|
| 365 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 366 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 367 | - // set the new date value using a full timestamp format so that no data is lost |
|
| 368 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 369 | - // reset datetime formats |
|
| 370 | - $obj->set_date_format($current_format[0]); |
|
| 371 | - $obj->set_time_format($current_format[1]); |
|
| 372 | - return $obj; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * date_time_add |
|
| 378 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 379 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 380 | - * |
|
| 381 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 382 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 383 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 384 | - * minutes, seconds) defaults to years |
|
| 385 | - * @param integer $value what you want to increment the time by |
|
| 386 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 387 | - * (chaining) |
|
| 388 | - */ |
|
| 389 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 390 | - { |
|
| 391 | - //get the raw UTC date. |
|
| 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); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * date_time_subtract |
|
| 400 | - * same as date_time_add except subtracting value instead of adding. |
|
| 401 | - * |
|
| 402 | - * @param \EE_Base_Class $obj |
|
| 403 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 404 | - * @param string $period |
|
| 405 | - * @param int $value |
|
| 406 | - * @return \EE_Base_Class |
|
| 407 | - */ |
|
| 408 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 409 | - { |
|
| 410 | - //get the raw UTC date |
|
| 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); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 419 | - * |
|
| 420 | - * @param DateTime $DateTime DateTime object |
|
| 421 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 422 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 423 | - * @param integer $value What you want to increment the date by |
|
| 424 | - * @param string $operand What operand you wish to use for the calculation |
|
| 425 | - * @return \DateTime return whatever type came in. |
|
| 426 | - * @throws \EE_Error |
|
| 427 | - */ |
|
| 428 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 429 | - { |
|
| 430 | - if (! $DateTime instanceof DateTime) { |
|
| 431 | - throw new EE_Error( |
|
| 432 | - sprintf( |
|
| 433 | - __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 434 | - print_r($DateTime, true) |
|
| 435 | - ) |
|
| 436 | - ); |
|
| 437 | - } |
|
| 438 | - switch ($period) { |
|
| 439 | - case 'years' : |
|
| 440 | - $value = 'P' . $value . 'Y'; |
|
| 441 | - break; |
|
| 442 | - case 'months' : |
|
| 443 | - $value = 'P' . $value . 'M'; |
|
| 444 | - break; |
|
| 445 | - case 'weeks' : |
|
| 446 | - $value = 'P' . $value . 'W'; |
|
| 447 | - break; |
|
| 448 | - case 'days' : |
|
| 449 | - $value = 'P' . $value . 'D'; |
|
| 450 | - break; |
|
| 451 | - case 'hours' : |
|
| 452 | - $value = 'PT' . $value . 'H'; |
|
| 453 | - break; |
|
| 454 | - case 'minutes' : |
|
| 455 | - $value = 'PT' . $value . 'M'; |
|
| 456 | - break; |
|
| 457 | - case 'seconds' : |
|
| 458 | - $value = 'PT' . $value . 'S'; |
|
| 459 | - break; |
|
| 460 | - } |
|
| 461 | - switch ($operand) { |
|
| 462 | - case '+': |
|
| 463 | - $DateTime->add(new DateInterval($value)); |
|
| 464 | - break; |
|
| 465 | - case '-': |
|
| 466 | - $DateTime->sub(new DateInterval($value)); |
|
| 467 | - break; |
|
| 468 | - } |
|
| 469 | - return $DateTime; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 475 | - * |
|
| 476 | - * @param int $timestamp Unix timestamp |
|
| 477 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 478 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 479 | - * @param integer $value What you want to increment the date by |
|
| 480 | - * @param string $operand What operand you wish to use for the calculation |
|
| 481 | - * @return \DateTime return whatever type came in. |
|
| 482 | - * @throws \EE_Error |
|
| 483 | - */ |
|
| 484 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 485 | - { |
|
| 486 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 487 | - throw new EE_Error( |
|
| 488 | - sprintf( |
|
| 489 | - __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 490 | - print_r($timestamp, true) |
|
| 491 | - ) |
|
| 492 | - ); |
|
| 493 | - } |
|
| 494 | - switch ($period) { |
|
| 495 | - case 'years' : |
|
| 496 | - $value = YEAR_IN_SECONDS * $value; |
|
| 497 | - break; |
|
| 498 | - case 'months' : |
|
| 499 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 500 | - break; |
|
| 501 | - case 'weeks' : |
|
| 502 | - $value = WEEK_IN_SECONDS * $value; |
|
| 503 | - break; |
|
| 504 | - case 'days' : |
|
| 505 | - $value = DAY_IN_SECONDS * $value; |
|
| 506 | - break; |
|
| 507 | - case 'hours' : |
|
| 508 | - $value = HOUR_IN_SECONDS * $value; |
|
| 509 | - break; |
|
| 510 | - case 'minutes' : |
|
| 511 | - $value = MINUTE_IN_SECONDS * $value; |
|
| 512 | - break; |
|
| 513 | - } |
|
| 514 | - switch ($operand) { |
|
| 515 | - case '+': |
|
| 516 | - $timestamp += $value; |
|
| 517 | - break; |
|
| 518 | - case '-': |
|
| 519 | - $timestamp -= $value; |
|
| 520 | - break; |
|
| 521 | - } |
|
| 522 | - return $timestamp; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 528 | - * parameters and returns the new timestamp or DateTime. |
|
| 529 | - * |
|
| 530 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 531 | - * @param string $period a value to indicate what interval is being used in the |
|
| 532 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 533 | - * 'minutes', 'seconds'. Defaults to years. |
|
| 534 | - * @param integer $value What you want to increment the date by |
|
| 535 | - * @param string $operand What operand you wish to use for the calculation |
|
| 536 | - * @return mixed string|DateTime return whatever type came in. |
|
| 537 | - */ |
|
| 538 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 539 | - { |
|
| 540 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 541 | - return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 542 | - } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 543 | - return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 544 | - } else { |
|
| 545 | - //error |
|
| 546 | - return $DateTime_or_timestamp; |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 553 | - * and spit out the js and moment.js equivalent formats. |
|
| 554 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 555 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 556 | - * time picker. |
|
| 557 | - * |
|
| 558 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 559 | - * @param null $date_format_string |
|
| 560 | - * @param null $time_format_string |
|
| 561 | - * @return array |
|
| 562 | - * array( |
|
| 563 | - * 'js' => array ( |
|
| 564 | - * 'date' => //date format |
|
| 565 | - * 'time' => //time format |
|
| 566 | - * ), |
|
| 567 | - * 'moment' => //date and time format. |
|
| 568 | - * ) |
|
| 569 | - */ |
|
| 570 | - public static function convert_php_to_js_and_moment_date_formats( |
|
| 571 | - $date_format_string = null, |
|
| 572 | - $time_format_string = null |
|
| 573 | - ) { |
|
| 574 | - if ($date_format_string === null) { |
|
| 575 | - $date_format_string = get_option('date_format'); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - if ($time_format_string === null) { |
|
| 579 | - $time_format_string = get_option('time_format'); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 583 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 584 | - |
|
| 585 | - return array( |
|
| 586 | - 'js' => array( |
|
| 587 | - 'date' => $date_format['js'], |
|
| 588 | - 'time' => $time_format['js'], |
|
| 589 | - ), |
|
| 590 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * This converts incoming format string into js and moment variations. |
|
| 597 | - * |
|
| 598 | - * @param string $format_string incoming php format string |
|
| 599 | - * @return array js and moment formats. |
|
| 600 | - */ |
|
| 601 | - protected static function _php_to_js_moment_converter($format_string) |
|
| 602 | - { |
|
| 603 | - /** |
|
| 604 | - * This is a map of symbols for formats. |
|
| 605 | - * The index is the php symbol, the equivalent values are in the array. |
|
| 606 | - * |
|
| 607 | - * @var array |
|
| 608 | - */ |
|
| 609 | - $symbols_map = array( |
|
| 610 | - // Day |
|
| 611 | - //01 |
|
| 612 | - 'd' => array( |
|
| 613 | - 'js' => 'dd', |
|
| 614 | - 'moment' => 'DD', |
|
| 615 | - ), |
|
| 616 | - //Mon |
|
| 617 | - 'D' => array( |
|
| 618 | - 'js' => 'D', |
|
| 619 | - 'moment' => 'ddd', |
|
| 620 | - ), |
|
| 621 | - //1,2,...31 |
|
| 622 | - 'j' => array( |
|
| 623 | - 'js' => 'd', |
|
| 624 | - 'moment' => 'D', |
|
| 625 | - ), |
|
| 626 | - //Monday |
|
| 627 | - 'l' => array( |
|
| 628 | - 'js' => 'DD', |
|
| 629 | - 'moment' => 'dddd', |
|
| 630 | - ), |
|
| 631 | - //ISO numeric representation of the day of the week (1-6) |
|
| 632 | - 'N' => array( |
|
| 633 | - 'js' => '', |
|
| 634 | - 'moment' => 'E', |
|
| 635 | - ), |
|
| 636 | - //st,nd.rd |
|
| 637 | - 'S' => array( |
|
| 638 | - 'js' => '', |
|
| 639 | - 'moment' => 'o', |
|
| 640 | - ), |
|
| 641 | - //numeric representation of day of week (0-6) |
|
| 642 | - 'w' => array( |
|
| 643 | - 'js' => '', |
|
| 644 | - 'moment' => 'd', |
|
| 645 | - ), |
|
| 646 | - //day of year starting from 0 (0-365) |
|
| 647 | - 'z' => array( |
|
| 648 | - 'js' => 'o', |
|
| 649 | - 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 650 | - ), |
|
| 651 | - // Week |
|
| 652 | - //ISO-8601 week number of year (weeks starting on monday) |
|
| 653 | - 'W' => array( |
|
| 654 | - 'js' => '', |
|
| 655 | - 'moment' => 'w', |
|
| 656 | - ), |
|
| 657 | - // Month |
|
| 658 | - // January...December |
|
| 659 | - 'F' => array( |
|
| 660 | - 'js' => 'MM', |
|
| 661 | - 'moment' => 'MMMM', |
|
| 662 | - ), |
|
| 663 | - //01...12 |
|
| 664 | - 'm' => array( |
|
| 665 | - 'js' => 'mm', |
|
| 666 | - 'moment' => 'MM', |
|
| 667 | - ), |
|
| 668 | - //Jan...Dec |
|
| 669 | - 'M' => array( |
|
| 670 | - 'js' => 'M', |
|
| 671 | - 'moment' => 'MMM', |
|
| 672 | - ), |
|
| 673 | - //1-12 |
|
| 674 | - 'n' => array( |
|
| 675 | - 'js' => 'm', |
|
| 676 | - 'moment' => 'M', |
|
| 677 | - ), |
|
| 678 | - //number of days in given month |
|
| 679 | - 't' => array( |
|
| 680 | - 'js' => '', |
|
| 681 | - 'moment' => '', |
|
| 682 | - ), |
|
| 683 | - // Year |
|
| 684 | - //whether leap year or not 1/0 |
|
| 685 | - 'L' => array( |
|
| 686 | - 'js' => '', |
|
| 687 | - 'moment' => '', |
|
| 688 | - ), |
|
| 689 | - //ISO-8601 year number |
|
| 690 | - 'o' => array( |
|
| 691 | - 'js' => '', |
|
| 692 | - 'moment' => 'GGGG', |
|
| 693 | - ), |
|
| 694 | - //1999...2003 |
|
| 695 | - 'Y' => array( |
|
| 696 | - 'js' => 'yy', |
|
| 697 | - 'moment' => 'YYYY', |
|
| 698 | - ), |
|
| 699 | - //99...03 |
|
| 700 | - 'y' => array( |
|
| 701 | - 'js' => 'y', |
|
| 702 | - 'moment' => 'YY', |
|
| 703 | - ), |
|
| 704 | - // Time |
|
| 705 | - // am/pm |
|
| 706 | - 'a' => array( |
|
| 707 | - 'js' => 'tt', |
|
| 708 | - 'moment' => 'a', |
|
| 709 | - ), |
|
| 710 | - // AM/PM |
|
| 711 | - 'A' => array( |
|
| 712 | - 'js' => 'TT', |
|
| 713 | - 'moment' => 'A', |
|
| 714 | - ), |
|
| 715 | - // Swatch Internet Time?!? |
|
| 716 | - 'B' => array( |
|
| 717 | - 'js' => '', |
|
| 718 | - 'moment' => '', |
|
| 719 | - ), |
|
| 720 | - //1...12 |
|
| 721 | - 'g' => array( |
|
| 722 | - 'js' => 'h', |
|
| 723 | - 'moment' => 'h', |
|
| 724 | - ), |
|
| 725 | - //0...23 |
|
| 726 | - 'G' => array( |
|
| 727 | - 'js' => 'H', |
|
| 728 | - 'moment' => 'H', |
|
| 729 | - ), |
|
| 730 | - //01...12 |
|
| 731 | - 'h' => array( |
|
| 732 | - 'js' => 'hh', |
|
| 733 | - 'moment' => 'hh', |
|
| 734 | - ), |
|
| 735 | - //00...23 |
|
| 736 | - 'H' => array( |
|
| 737 | - 'js' => 'HH', |
|
| 738 | - 'moment' => 'HH', |
|
| 739 | - ), |
|
| 740 | - //00..59 |
|
| 741 | - 'i' => array( |
|
| 742 | - 'js' => 'mm', |
|
| 743 | - 'moment' => 'mm', |
|
| 744 | - ), |
|
| 745 | - //seconds... 00...59 |
|
| 746 | - 's' => array( |
|
| 747 | - 'js' => 'ss', |
|
| 748 | - 'moment' => 'ss', |
|
| 749 | - ), |
|
| 750 | - //microseconds |
|
| 751 | - 'u' => array( |
|
| 752 | - 'js' => '', |
|
| 753 | - 'moment' => '', |
|
| 754 | - ), |
|
| 755 | - ); |
|
| 756 | - $jquery_ui_format = ""; |
|
| 757 | - $moment_format = ""; |
|
| 758 | - $escaping = false; |
|
| 759 | - for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 760 | - $char = $format_string[$i]; |
|
| 761 | - if ($char === '\\') { // PHP date format escaping character |
|
| 762 | - $i++; |
|
| 763 | - if ($escaping) { |
|
| 764 | - $jquery_ui_format .= $format_string[$i]; |
|
| 765 | - $moment_format .= $format_string[$i]; |
|
| 766 | - } else { |
|
| 767 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 768 | - $moment_format .= $format_string[$i]; |
|
| 769 | - } |
|
| 770 | - $escaping = true; |
|
| 771 | - } else { |
|
| 772 | - if ($escaping) { |
|
| 773 | - $jquery_ui_format .= "'"; |
|
| 774 | - $moment_format .= "'"; |
|
| 775 | - $escaping = false; |
|
| 776 | - } |
|
| 777 | - if (isset($symbols_map[$char])) { |
|
| 778 | - $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 779 | - $moment_format .= $symbols_map[$char]['moment']; |
|
| 780 | - } else { |
|
| 781 | - $jquery_ui_format .= $char; |
|
| 782 | - $moment_format .= $char; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 792 | - * |
|
| 793 | - * @param string $format_string Incoming format string for php date(). |
|
| 794 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 795 | - * errors is returned. So for client code calling, check for is_array() to |
|
| 796 | - * indicate failed validations. |
|
| 797 | - */ |
|
| 798 | - public static function validate_format_string($format_string) |
|
| 799 | - { |
|
| 800 | - $error_msg = array(); |
|
| 801 | - //time format checks |
|
| 802 | - switch (true) { |
|
| 803 | - case strpos($format_string, 'h') !== false : |
|
| 804 | - case strpos($format_string, 'g') !== false : |
|
| 805 | - /** |
|
| 806 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 807 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 808 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 809 | - */ |
|
| 810 | - if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 811 | - $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".', |
|
| 812 | - 'event_espresso'); |
|
| 813 | - } |
|
| 814 | - break; |
|
| 815 | - |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - return empty($error_msg) ? true : $error_msg; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 824 | - * very next day then this method will return true. |
|
| 825 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 826 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 827 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 828 | - * |
|
| 829 | - * @param mixed $date_1 |
|
| 830 | - * @param mixed $date_2 |
|
| 831 | - * @return bool |
|
| 832 | - */ |
|
| 833 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 834 | - { |
|
| 835 | - |
|
| 836 | - if ( |
|
| 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') |
|
| 839 | - ) { |
|
| 840 | - return false; |
|
| 841 | - } |
|
| 842 | - return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 848 | - * Functions. |
|
| 849 | - * |
|
| 850 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 851 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 852 | - * @return string |
|
| 853 | - */ |
|
| 854 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 855 | - { |
|
| 856 | - try { |
|
| 857 | - /** need to account for timezone offset on the selects */ |
|
| 858 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 859 | - } catch (Exception $e) { |
|
| 860 | - $DateTimeZone = null; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 865 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
| 866 | - */ |
|
| 867 | - $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 868 | - $query_interval = $offset < 0 |
|
| 869 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 870 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 871 | - return $query_interval; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 876 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 877 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 878 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 879 | - * (although note that we remove any HTML that may be added) |
|
| 880 | - * |
|
| 881 | - * @return string |
|
| 882 | - */ |
|
| 883 | - public static function get_timezone_string_for_display() |
|
| 884 | - { |
|
| 885 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 886 | - if (! empty($pretty_timezone)) { |
|
| 887 | - return esc_html($pretty_timezone); |
|
| 888 | - } |
|
| 889 | - $timezone_string = get_option('timezone_string'); |
|
| 890 | - if ($timezone_string) { |
|
| 891 | - static $mo_loaded = false; |
|
| 892 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
| 893 | - if (! $mo_loaded) { |
|
| 894 | - $locale = get_locale(); |
|
| 895 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 896 | - load_textdomain('continents-cities', $mofile); |
|
| 897 | - $mo_loaded = true; |
|
| 898 | - } |
|
| 899 | - //well that was easy. |
|
| 900 | - $parts = explode('/', $timezone_string); |
|
| 901 | - //remove the continent |
|
| 902 | - unset($parts[0]); |
|
| 903 | - $t_parts = array(); |
|
| 904 | - foreach ($parts as $part) { |
|
| 905 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 906 | - } |
|
| 907 | - return implode(' - ', $t_parts); |
|
| 908 | - } |
|
| 909 | - //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 910 | - $gmt_offset = get_option('gmt_offset'); |
|
| 911 | - if (intval($gmt_offset) >= 0) { |
|
| 912 | - $prefix = '+'; |
|
| 913 | - } else { |
|
| 914 | - $prefix = ''; |
|
| 915 | - } |
|
| 916 | - $parts = explode('.', (string)$gmt_offset); |
|
| 917 | - if (count($parts) === 1) { |
|
| 918 | - $parts[1] = '00'; |
|
| 919 | - } else { |
|
| 920 | - //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 921 | - //to minutes, eg 30 or 15, respectively |
|
| 922 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 923 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 924 | - } |
|
| 925 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 926 | - } |
|
| 323 | + endif; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 329 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 330 | + * the site is used. |
|
| 331 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 332 | + * computed timestamp (i.e. date_i18n() ) |
|
| 333 | + * |
|
| 334 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
| 335 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 336 | + * site will be used. |
|
| 337 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 338 | + */ |
|
| 339 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 340 | + { |
|
| 341 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 342 | + $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 343 | + $TimeZone = new DateTimeZone($timezone_string); |
|
| 344 | + |
|
| 345 | + $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 346 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 347 | + return (int)$DateTime->format('U') + (int)$offset; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * _set_date_time_field |
|
| 353 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 354 | + * |
|
| 355 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 356 | + * @param DateTime $DateTime PHP DateTime object |
|
| 357 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 358 | + * @return EE_Base_Class |
|
| 359 | + */ |
|
| 360 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 361 | + { |
|
| 362 | + // grab current datetime format |
|
| 363 | + $current_format = $obj->get_format(); |
|
| 364 | + // set new full timestamp format |
|
| 365 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 366 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 367 | + // set the new date value using a full timestamp format so that no data is lost |
|
| 368 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 369 | + // reset datetime formats |
|
| 370 | + $obj->set_date_format($current_format[0]); |
|
| 371 | + $obj->set_time_format($current_format[1]); |
|
| 372 | + return $obj; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * date_time_add |
|
| 378 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 379 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 380 | + * |
|
| 381 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 382 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 383 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 384 | + * minutes, seconds) defaults to years |
|
| 385 | + * @param integer $value what you want to increment the time by |
|
| 386 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 387 | + * (chaining) |
|
| 388 | + */ |
|
| 389 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 390 | + { |
|
| 391 | + //get the raw UTC date. |
|
| 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); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * date_time_subtract |
|
| 400 | + * same as date_time_add except subtracting value instead of adding. |
|
| 401 | + * |
|
| 402 | + * @param \EE_Base_Class $obj |
|
| 403 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 404 | + * @param string $period |
|
| 405 | + * @param int $value |
|
| 406 | + * @return \EE_Base_Class |
|
| 407 | + */ |
|
| 408 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 409 | + { |
|
| 410 | + //get the raw UTC date |
|
| 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); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 419 | + * |
|
| 420 | + * @param DateTime $DateTime DateTime object |
|
| 421 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 422 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 423 | + * @param integer $value What you want to increment the date by |
|
| 424 | + * @param string $operand What operand you wish to use for the calculation |
|
| 425 | + * @return \DateTime return whatever type came in. |
|
| 426 | + * @throws \EE_Error |
|
| 427 | + */ |
|
| 428 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 429 | + { |
|
| 430 | + if (! $DateTime instanceof DateTime) { |
|
| 431 | + throw new EE_Error( |
|
| 432 | + sprintf( |
|
| 433 | + __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 434 | + print_r($DateTime, true) |
|
| 435 | + ) |
|
| 436 | + ); |
|
| 437 | + } |
|
| 438 | + switch ($period) { |
|
| 439 | + case 'years' : |
|
| 440 | + $value = 'P' . $value . 'Y'; |
|
| 441 | + break; |
|
| 442 | + case 'months' : |
|
| 443 | + $value = 'P' . $value . 'M'; |
|
| 444 | + break; |
|
| 445 | + case 'weeks' : |
|
| 446 | + $value = 'P' . $value . 'W'; |
|
| 447 | + break; |
|
| 448 | + case 'days' : |
|
| 449 | + $value = 'P' . $value . 'D'; |
|
| 450 | + break; |
|
| 451 | + case 'hours' : |
|
| 452 | + $value = 'PT' . $value . 'H'; |
|
| 453 | + break; |
|
| 454 | + case 'minutes' : |
|
| 455 | + $value = 'PT' . $value . 'M'; |
|
| 456 | + break; |
|
| 457 | + case 'seconds' : |
|
| 458 | + $value = 'PT' . $value . 'S'; |
|
| 459 | + break; |
|
| 460 | + } |
|
| 461 | + switch ($operand) { |
|
| 462 | + case '+': |
|
| 463 | + $DateTime->add(new DateInterval($value)); |
|
| 464 | + break; |
|
| 465 | + case '-': |
|
| 466 | + $DateTime->sub(new DateInterval($value)); |
|
| 467 | + break; |
|
| 468 | + } |
|
| 469 | + return $DateTime; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 475 | + * |
|
| 476 | + * @param int $timestamp Unix timestamp |
|
| 477 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 478 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 479 | + * @param integer $value What you want to increment the date by |
|
| 480 | + * @param string $operand What operand you wish to use for the calculation |
|
| 481 | + * @return \DateTime return whatever type came in. |
|
| 482 | + * @throws \EE_Error |
|
| 483 | + */ |
|
| 484 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 485 | + { |
|
| 486 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 487 | + throw new EE_Error( |
|
| 488 | + sprintf( |
|
| 489 | + __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 490 | + print_r($timestamp, true) |
|
| 491 | + ) |
|
| 492 | + ); |
|
| 493 | + } |
|
| 494 | + switch ($period) { |
|
| 495 | + case 'years' : |
|
| 496 | + $value = YEAR_IN_SECONDS * $value; |
|
| 497 | + break; |
|
| 498 | + case 'months' : |
|
| 499 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 500 | + break; |
|
| 501 | + case 'weeks' : |
|
| 502 | + $value = WEEK_IN_SECONDS * $value; |
|
| 503 | + break; |
|
| 504 | + case 'days' : |
|
| 505 | + $value = DAY_IN_SECONDS * $value; |
|
| 506 | + break; |
|
| 507 | + case 'hours' : |
|
| 508 | + $value = HOUR_IN_SECONDS * $value; |
|
| 509 | + break; |
|
| 510 | + case 'minutes' : |
|
| 511 | + $value = MINUTE_IN_SECONDS * $value; |
|
| 512 | + break; |
|
| 513 | + } |
|
| 514 | + switch ($operand) { |
|
| 515 | + case '+': |
|
| 516 | + $timestamp += $value; |
|
| 517 | + break; |
|
| 518 | + case '-': |
|
| 519 | + $timestamp -= $value; |
|
| 520 | + break; |
|
| 521 | + } |
|
| 522 | + return $timestamp; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 528 | + * parameters and returns the new timestamp or DateTime. |
|
| 529 | + * |
|
| 530 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 531 | + * @param string $period a value to indicate what interval is being used in the |
|
| 532 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 533 | + * 'minutes', 'seconds'. Defaults to years. |
|
| 534 | + * @param integer $value What you want to increment the date by |
|
| 535 | + * @param string $operand What operand you wish to use for the calculation |
|
| 536 | + * @return mixed string|DateTime return whatever type came in. |
|
| 537 | + */ |
|
| 538 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 539 | + { |
|
| 540 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 541 | + return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 542 | + } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 543 | + return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 544 | + } else { |
|
| 545 | + //error |
|
| 546 | + return $DateTime_or_timestamp; |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 553 | + * and spit out the js and moment.js equivalent formats. |
|
| 554 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 555 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 556 | + * time picker. |
|
| 557 | + * |
|
| 558 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 559 | + * @param null $date_format_string |
|
| 560 | + * @param null $time_format_string |
|
| 561 | + * @return array |
|
| 562 | + * array( |
|
| 563 | + * 'js' => array ( |
|
| 564 | + * 'date' => //date format |
|
| 565 | + * 'time' => //time format |
|
| 566 | + * ), |
|
| 567 | + * 'moment' => //date and time format. |
|
| 568 | + * ) |
|
| 569 | + */ |
|
| 570 | + public static function convert_php_to_js_and_moment_date_formats( |
|
| 571 | + $date_format_string = null, |
|
| 572 | + $time_format_string = null |
|
| 573 | + ) { |
|
| 574 | + if ($date_format_string === null) { |
|
| 575 | + $date_format_string = get_option('date_format'); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + if ($time_format_string === null) { |
|
| 579 | + $time_format_string = get_option('time_format'); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 583 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 584 | + |
|
| 585 | + return array( |
|
| 586 | + 'js' => array( |
|
| 587 | + 'date' => $date_format['js'], |
|
| 588 | + 'time' => $time_format['js'], |
|
| 589 | + ), |
|
| 590 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * This converts incoming format string into js and moment variations. |
|
| 597 | + * |
|
| 598 | + * @param string $format_string incoming php format string |
|
| 599 | + * @return array js and moment formats. |
|
| 600 | + */ |
|
| 601 | + protected static function _php_to_js_moment_converter($format_string) |
|
| 602 | + { |
|
| 603 | + /** |
|
| 604 | + * This is a map of symbols for formats. |
|
| 605 | + * The index is the php symbol, the equivalent values are in the array. |
|
| 606 | + * |
|
| 607 | + * @var array |
|
| 608 | + */ |
|
| 609 | + $symbols_map = array( |
|
| 610 | + // Day |
|
| 611 | + //01 |
|
| 612 | + 'd' => array( |
|
| 613 | + 'js' => 'dd', |
|
| 614 | + 'moment' => 'DD', |
|
| 615 | + ), |
|
| 616 | + //Mon |
|
| 617 | + 'D' => array( |
|
| 618 | + 'js' => 'D', |
|
| 619 | + 'moment' => 'ddd', |
|
| 620 | + ), |
|
| 621 | + //1,2,...31 |
|
| 622 | + 'j' => array( |
|
| 623 | + 'js' => 'd', |
|
| 624 | + 'moment' => 'D', |
|
| 625 | + ), |
|
| 626 | + //Monday |
|
| 627 | + 'l' => array( |
|
| 628 | + 'js' => 'DD', |
|
| 629 | + 'moment' => 'dddd', |
|
| 630 | + ), |
|
| 631 | + //ISO numeric representation of the day of the week (1-6) |
|
| 632 | + 'N' => array( |
|
| 633 | + 'js' => '', |
|
| 634 | + 'moment' => 'E', |
|
| 635 | + ), |
|
| 636 | + //st,nd.rd |
|
| 637 | + 'S' => array( |
|
| 638 | + 'js' => '', |
|
| 639 | + 'moment' => 'o', |
|
| 640 | + ), |
|
| 641 | + //numeric representation of day of week (0-6) |
|
| 642 | + 'w' => array( |
|
| 643 | + 'js' => '', |
|
| 644 | + 'moment' => 'd', |
|
| 645 | + ), |
|
| 646 | + //day of year starting from 0 (0-365) |
|
| 647 | + 'z' => array( |
|
| 648 | + 'js' => 'o', |
|
| 649 | + 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 650 | + ), |
|
| 651 | + // Week |
|
| 652 | + //ISO-8601 week number of year (weeks starting on monday) |
|
| 653 | + 'W' => array( |
|
| 654 | + 'js' => '', |
|
| 655 | + 'moment' => 'w', |
|
| 656 | + ), |
|
| 657 | + // Month |
|
| 658 | + // January...December |
|
| 659 | + 'F' => array( |
|
| 660 | + 'js' => 'MM', |
|
| 661 | + 'moment' => 'MMMM', |
|
| 662 | + ), |
|
| 663 | + //01...12 |
|
| 664 | + 'm' => array( |
|
| 665 | + 'js' => 'mm', |
|
| 666 | + 'moment' => 'MM', |
|
| 667 | + ), |
|
| 668 | + //Jan...Dec |
|
| 669 | + 'M' => array( |
|
| 670 | + 'js' => 'M', |
|
| 671 | + 'moment' => 'MMM', |
|
| 672 | + ), |
|
| 673 | + //1-12 |
|
| 674 | + 'n' => array( |
|
| 675 | + 'js' => 'm', |
|
| 676 | + 'moment' => 'M', |
|
| 677 | + ), |
|
| 678 | + //number of days in given month |
|
| 679 | + 't' => array( |
|
| 680 | + 'js' => '', |
|
| 681 | + 'moment' => '', |
|
| 682 | + ), |
|
| 683 | + // Year |
|
| 684 | + //whether leap year or not 1/0 |
|
| 685 | + 'L' => array( |
|
| 686 | + 'js' => '', |
|
| 687 | + 'moment' => '', |
|
| 688 | + ), |
|
| 689 | + //ISO-8601 year number |
|
| 690 | + 'o' => array( |
|
| 691 | + 'js' => '', |
|
| 692 | + 'moment' => 'GGGG', |
|
| 693 | + ), |
|
| 694 | + //1999...2003 |
|
| 695 | + 'Y' => array( |
|
| 696 | + 'js' => 'yy', |
|
| 697 | + 'moment' => 'YYYY', |
|
| 698 | + ), |
|
| 699 | + //99...03 |
|
| 700 | + 'y' => array( |
|
| 701 | + 'js' => 'y', |
|
| 702 | + 'moment' => 'YY', |
|
| 703 | + ), |
|
| 704 | + // Time |
|
| 705 | + // am/pm |
|
| 706 | + 'a' => array( |
|
| 707 | + 'js' => 'tt', |
|
| 708 | + 'moment' => 'a', |
|
| 709 | + ), |
|
| 710 | + // AM/PM |
|
| 711 | + 'A' => array( |
|
| 712 | + 'js' => 'TT', |
|
| 713 | + 'moment' => 'A', |
|
| 714 | + ), |
|
| 715 | + // Swatch Internet Time?!? |
|
| 716 | + 'B' => array( |
|
| 717 | + 'js' => '', |
|
| 718 | + 'moment' => '', |
|
| 719 | + ), |
|
| 720 | + //1...12 |
|
| 721 | + 'g' => array( |
|
| 722 | + 'js' => 'h', |
|
| 723 | + 'moment' => 'h', |
|
| 724 | + ), |
|
| 725 | + //0...23 |
|
| 726 | + 'G' => array( |
|
| 727 | + 'js' => 'H', |
|
| 728 | + 'moment' => 'H', |
|
| 729 | + ), |
|
| 730 | + //01...12 |
|
| 731 | + 'h' => array( |
|
| 732 | + 'js' => 'hh', |
|
| 733 | + 'moment' => 'hh', |
|
| 734 | + ), |
|
| 735 | + //00...23 |
|
| 736 | + 'H' => array( |
|
| 737 | + 'js' => 'HH', |
|
| 738 | + 'moment' => 'HH', |
|
| 739 | + ), |
|
| 740 | + //00..59 |
|
| 741 | + 'i' => array( |
|
| 742 | + 'js' => 'mm', |
|
| 743 | + 'moment' => 'mm', |
|
| 744 | + ), |
|
| 745 | + //seconds... 00...59 |
|
| 746 | + 's' => array( |
|
| 747 | + 'js' => 'ss', |
|
| 748 | + 'moment' => 'ss', |
|
| 749 | + ), |
|
| 750 | + //microseconds |
|
| 751 | + 'u' => array( |
|
| 752 | + 'js' => '', |
|
| 753 | + 'moment' => '', |
|
| 754 | + ), |
|
| 755 | + ); |
|
| 756 | + $jquery_ui_format = ""; |
|
| 757 | + $moment_format = ""; |
|
| 758 | + $escaping = false; |
|
| 759 | + for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 760 | + $char = $format_string[$i]; |
|
| 761 | + if ($char === '\\') { // PHP date format escaping character |
|
| 762 | + $i++; |
|
| 763 | + if ($escaping) { |
|
| 764 | + $jquery_ui_format .= $format_string[$i]; |
|
| 765 | + $moment_format .= $format_string[$i]; |
|
| 766 | + } else { |
|
| 767 | + $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 768 | + $moment_format .= $format_string[$i]; |
|
| 769 | + } |
|
| 770 | + $escaping = true; |
|
| 771 | + } else { |
|
| 772 | + if ($escaping) { |
|
| 773 | + $jquery_ui_format .= "'"; |
|
| 774 | + $moment_format .= "'"; |
|
| 775 | + $escaping = false; |
|
| 776 | + } |
|
| 777 | + if (isset($symbols_map[$char])) { |
|
| 778 | + $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 779 | + $moment_format .= $symbols_map[$char]['moment']; |
|
| 780 | + } else { |
|
| 781 | + $jquery_ui_format .= $char; |
|
| 782 | + $moment_format .= $char; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 792 | + * |
|
| 793 | + * @param string $format_string Incoming format string for php date(). |
|
| 794 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 795 | + * errors is returned. So for client code calling, check for is_array() to |
|
| 796 | + * indicate failed validations. |
|
| 797 | + */ |
|
| 798 | + public static function validate_format_string($format_string) |
|
| 799 | + { |
|
| 800 | + $error_msg = array(); |
|
| 801 | + //time format checks |
|
| 802 | + switch (true) { |
|
| 803 | + case strpos($format_string, 'h') !== false : |
|
| 804 | + case strpos($format_string, 'g') !== false : |
|
| 805 | + /** |
|
| 806 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 807 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 808 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 809 | + */ |
|
| 810 | + if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 811 | + $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".', |
|
| 812 | + 'event_espresso'); |
|
| 813 | + } |
|
| 814 | + break; |
|
| 815 | + |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + return empty($error_msg) ? true : $error_msg; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 824 | + * very next day then this method will return true. |
|
| 825 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 826 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 827 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 828 | + * |
|
| 829 | + * @param mixed $date_1 |
|
| 830 | + * @param mixed $date_2 |
|
| 831 | + * @return bool |
|
| 832 | + */ |
|
| 833 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 834 | + { |
|
| 835 | + |
|
| 836 | + if ( |
|
| 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') |
|
| 839 | + ) { |
|
| 840 | + return false; |
|
| 841 | + } |
|
| 842 | + return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 848 | + * Functions. |
|
| 849 | + * |
|
| 850 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 851 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 852 | + * @return string |
|
| 853 | + */ |
|
| 854 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 855 | + { |
|
| 856 | + try { |
|
| 857 | + /** need to account for timezone offset on the selects */ |
|
| 858 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 859 | + } catch (Exception $e) { |
|
| 860 | + $DateTimeZone = null; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 865 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
| 866 | + */ |
|
| 867 | + $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 868 | + $query_interval = $offset < 0 |
|
| 869 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 870 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 871 | + return $query_interval; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 876 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 877 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 878 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 879 | + * (although note that we remove any HTML that may be added) |
|
| 880 | + * |
|
| 881 | + * @return string |
|
| 882 | + */ |
|
| 883 | + public static function get_timezone_string_for_display() |
|
| 884 | + { |
|
| 885 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 886 | + if (! empty($pretty_timezone)) { |
|
| 887 | + return esc_html($pretty_timezone); |
|
| 888 | + } |
|
| 889 | + $timezone_string = get_option('timezone_string'); |
|
| 890 | + if ($timezone_string) { |
|
| 891 | + static $mo_loaded = false; |
|
| 892 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
| 893 | + if (! $mo_loaded) { |
|
| 894 | + $locale = get_locale(); |
|
| 895 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 896 | + load_textdomain('continents-cities', $mofile); |
|
| 897 | + $mo_loaded = true; |
|
| 898 | + } |
|
| 899 | + //well that was easy. |
|
| 900 | + $parts = explode('/', $timezone_string); |
|
| 901 | + //remove the continent |
|
| 902 | + unset($parts[0]); |
|
| 903 | + $t_parts = array(); |
|
| 904 | + foreach ($parts as $part) { |
|
| 905 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 906 | + } |
|
| 907 | + return implode(' - ', $t_parts); |
|
| 908 | + } |
|
| 909 | + //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 910 | + $gmt_offset = get_option('gmt_offset'); |
|
| 911 | + if (intval($gmt_offset) >= 0) { |
|
| 912 | + $prefix = '+'; |
|
| 913 | + } else { |
|
| 914 | + $prefix = ''; |
|
| 915 | + } |
|
| 916 | + $parts = explode('.', (string)$gmt_offset); |
|
| 917 | + if (count($parts) === 1) { |
|
| 918 | + $parts[1] = '00'; |
|
| 919 | + } else { |
|
| 920 | + //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 921 | + //to minutes, eg 30 or 15, respectively |
|
| 922 | + $hour_fraction = (float)('0.' . $parts[1]); |
|
| 923 | + $parts[1] = (string)$hour_fraction * 60; |
|
| 924 | + } |
|
| 925 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 926 | + } |
|
| 927 | 927 | |
| 928 | 928 | |
| 929 | 929 | }// end class EEH_DTT_Helper |
| 930 | 930 | \ No newline at end of file |
@@ -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 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | new DateTimeZone($timezone_string); |
| 75 | 75 | } catch (Exception $e) { |
| 76 | 76 | // sometimes we take exception to exceptions |
| 77 | - if (! $throw_error) { |
|
| 77 | + if ( ! $throw_error) { |
|
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | throw new EE_Error( |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | $offset = get_option('gmt_offset'); |
| 138 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 138 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
| 150 | 150 | { |
| 151 | 151 | //make sure $gmt_offset is int |
| 152 | - $gmt_offset = (int)$gmt_offset; |
|
| 152 | + $gmt_offset = (int) $gmt_offset; |
|
| 153 | 153 | switch ($gmt_offset) { |
| 154 | 154 | |
| 155 | 155 | // case -30600 : |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | public static function timezone_select_input($timezone_string = '') |
| 234 | 234 | { |
| 235 | 235 | // get WP date time format |
| 236 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 236 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
| 237 | 237 | // if passed a value, then use that, else get WP option |
| 238 | 238 | $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
| 239 | 239 | // check if the timezone is valid but don't throw any errors if it isn't |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | // Create a UTC+- zone if no timezone string exists |
| 246 | 246 | $check_zone_info = false; |
| 247 | 247 | if ($gmt_offset > 0) { |
| 248 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 248 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
| 249 | 249 | } elseif ($gmt_offset < 0) { |
| 250 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 250 | + $timezone_string = 'UTC'.$gmt_offset; |
|
| 251 | 251 | } else { |
| 252 | 252 | $timezone_string = 'UTC'; |
| 253 | 253 | } |
@@ -269,11 +269,11 @@ discard block |
||
| 269 | 269 | __('%1$sUTC%2$s time is %3$s'), |
| 270 | 270 | '<abbr title="Coordinated Universal Time">', |
| 271 | 271 | '</abbr>', |
| 272 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 272 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
| 273 | 273 | ); |
| 274 | 274 | ?></span> |
| 275 | - <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 276 | - <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
|
| 275 | + <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 276 | + <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
| 277 | 277 | <?php endif; ?> |
| 278 | 278 | |
| 279 | 279 | <?php if ($check_zone_info && $timezone_string) : ?> |
@@ -306,11 +306,10 @@ 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 | 311 | printf($message, |
| 313 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 312 | + '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'); |
|
| 314 | 313 | } else { |
| 315 | 314 | _e('This timezone does not observe daylight saving time.'); |
| 316 | 315 | } |
@@ -338,13 +337,13 @@ discard block |
||
| 338 | 337 | */ |
| 339 | 338 | public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
| 340 | 339 | { |
| 341 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 340 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
| 342 | 341 | $timezone_string = self::get_valid_timezone_string($timezone_string); |
| 343 | 342 | $TimeZone = new DateTimeZone($timezone_string); |
| 344 | 343 | |
| 345 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 344 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
| 346 | 345 | $offset = timezone_offset_get($TimeZone, $DateTime); |
| 347 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 346 | + return (int) $DateTime->format('U') + (int) $offset; |
|
| 348 | 347 | } |
| 349 | 348 | |
| 350 | 349 | |
@@ -427,7 +426,7 @@ discard block |
||
| 427 | 426 | */ |
| 428 | 427 | protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
| 429 | 428 | { |
| 430 | - if (! $DateTime instanceof DateTime) { |
|
| 429 | + if ( ! $DateTime instanceof DateTime) { |
|
| 431 | 430 | throw new EE_Error( |
| 432 | 431 | sprintf( |
| 433 | 432 | __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
@@ -437,25 +436,25 @@ discard block |
||
| 437 | 436 | } |
| 438 | 437 | switch ($period) { |
| 439 | 438 | case 'years' : |
| 440 | - $value = 'P' . $value . 'Y'; |
|
| 439 | + $value = 'P'.$value.'Y'; |
|
| 441 | 440 | break; |
| 442 | 441 | case 'months' : |
| 443 | - $value = 'P' . $value . 'M'; |
|
| 442 | + $value = 'P'.$value.'M'; |
|
| 444 | 443 | break; |
| 445 | 444 | case 'weeks' : |
| 446 | - $value = 'P' . $value . 'W'; |
|
| 445 | + $value = 'P'.$value.'W'; |
|
| 447 | 446 | break; |
| 448 | 447 | case 'days' : |
| 449 | - $value = 'P' . $value . 'D'; |
|
| 448 | + $value = 'P'.$value.'D'; |
|
| 450 | 449 | break; |
| 451 | 450 | case 'hours' : |
| 452 | - $value = 'PT' . $value . 'H'; |
|
| 451 | + $value = 'PT'.$value.'H'; |
|
| 453 | 452 | break; |
| 454 | 453 | case 'minutes' : |
| 455 | - $value = 'PT' . $value . 'M'; |
|
| 454 | + $value = 'PT'.$value.'M'; |
|
| 456 | 455 | break; |
| 457 | 456 | case 'seconds' : |
| 458 | - $value = 'PT' . $value . 'S'; |
|
| 457 | + $value = 'PT'.$value.'S'; |
|
| 459 | 458 | break; |
| 460 | 459 | } |
| 461 | 460 | switch ($operand) { |
@@ -483,7 +482,7 @@ discard block |
||
| 483 | 482 | */ |
| 484 | 483 | protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
| 485 | 484 | { |
| 486 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 485 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 487 | 486 | throw new EE_Error( |
| 488 | 487 | sprintf( |
| 489 | 488 | __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
@@ -587,7 +586,7 @@ discard block |
||
| 587 | 586 | 'date' => $date_format['js'], |
| 588 | 587 | 'time' => $time_format['js'], |
| 589 | 588 | ), |
| 590 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 589 | + 'moment' => $date_format['moment'].' '.$time_format['moment'], |
|
| 591 | 590 | ); |
| 592 | 591 | } |
| 593 | 592 | |
@@ -606,7 +605,7 @@ discard block |
||
| 606 | 605 | * |
| 607 | 606 | * @var array |
| 608 | 607 | */ |
| 609 | - $symbols_map = array( |
|
| 608 | + $symbols_map = array( |
|
| 610 | 609 | // Day |
| 611 | 610 | //01 |
| 612 | 611 | 'd' => array( |
@@ -764,7 +763,7 @@ discard block |
||
| 764 | 763 | $jquery_ui_format .= $format_string[$i]; |
| 765 | 764 | $moment_format .= $format_string[$i]; |
| 766 | 765 | } else { |
| 767 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 766 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
| 768 | 767 | $moment_format .= $format_string[$i]; |
| 769 | 768 | } |
| 770 | 769 | $escaping = true; |
@@ -834,7 +833,7 @@ discard block |
||
| 834 | 833 | { |
| 835 | 834 | |
| 836 | 835 | if ( |
| 837 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 836 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 838 | 837 | ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
| 839 | 838 | ) { |
| 840 | 839 | return false; |
@@ -866,8 +865,8 @@ discard block |
||
| 866 | 865 | */ |
| 867 | 866 | $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
| 868 | 867 | $query_interval = $offset < 0 |
| 869 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 870 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 868 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
| 869 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
| 871 | 870 | return $query_interval; |
| 872 | 871 | } |
| 873 | 872 | |
@@ -883,16 +882,16 @@ discard block |
||
| 883 | 882 | public static function get_timezone_string_for_display() |
| 884 | 883 | { |
| 885 | 884 | $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
| 886 | - if (! empty($pretty_timezone)) { |
|
| 885 | + if ( ! empty($pretty_timezone)) { |
|
| 887 | 886 | return esc_html($pretty_timezone); |
| 888 | 887 | } |
| 889 | 888 | $timezone_string = get_option('timezone_string'); |
| 890 | 889 | if ($timezone_string) { |
| 891 | 890 | static $mo_loaded = false; |
| 892 | 891 | // Load translations for continents and cities just like wp_timezone_choice does |
| 893 | - if (! $mo_loaded) { |
|
| 892 | + if ( ! $mo_loaded) { |
|
| 894 | 893 | $locale = get_locale(); |
| 895 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 894 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
| 896 | 895 | load_textdomain('continents-cities', $mofile); |
| 897 | 896 | $mo_loaded = true; |
| 898 | 897 | } |
@@ -913,16 +912,16 @@ discard block |
||
| 913 | 912 | } else { |
| 914 | 913 | $prefix = ''; |
| 915 | 914 | } |
| 916 | - $parts = explode('.', (string)$gmt_offset); |
|
| 915 | + $parts = explode('.', (string) $gmt_offset); |
|
| 917 | 916 | if (count($parts) === 1) { |
| 918 | 917 | $parts[1] = '00'; |
| 919 | 918 | } else { |
| 920 | 919 | //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
| 921 | 920 | //to minutes, eg 30 or 15, respectively |
| 922 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 923 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 921 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
| 922 | + $parts[1] = (string) $hour_fraction * 60; |
|
| 924 | 923 | } |
| 925 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 924 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
| 926 | 925 | } |
| 927 | 926 | |
| 928 | 927 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -13,168 +13,168 @@ discard block |
||
| 13 | 13 | class EE_Messages_Scheduler extends EE_Base |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Number of seconds between batch sends/generates on the cron job. |
|
| 18 | - * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
|
| 19 | - * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
|
| 20 | - * |
|
| 21 | - * @type int |
|
| 22 | - */ |
|
| 23 | - const message_cron_schedule = 300; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Constructor |
|
| 27 | - */ |
|
| 28 | - public function __construct() |
|
| 29 | - { |
|
| 30 | - //register tasks (and make sure only registered once). |
|
| 31 | - if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
| 32 | - add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - //register callbacks for scheduled events (but make sure they are set only once). |
|
| 36 | - if (! has_action('AHEE__EE_Messages_Scheduler__generation', |
|
| 37 | - array('EE_Messages_Scheduler', 'batch_generation')) |
|
| 38 | - ) { |
|
| 39 | - add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation')); |
|
| 40 | - add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending')); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - //add custom schedules |
|
| 44 | - add_filter('cron_schedules', array($this, 'custom_schedules')); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Add custom schedules for wp_cron |
|
| 50 | - * |
|
| 51 | - * @param $schedules |
|
| 52 | - */ |
|
| 53 | - public function custom_schedules($schedules) |
|
| 54 | - { |
|
| 55 | - $schedules['ee_message_cron'] = array( |
|
| 56 | - 'interval' => self::message_cron_schedule, |
|
| 57 | - 'display' => __('This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', |
|
| 58 | - 'event_espresso'), |
|
| 59 | - ); |
|
| 60 | - return $schedules; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and |
|
| 66 | - * remove. |
|
| 67 | - * |
|
| 68 | - * @param array $tasks already existing scheduled tasks |
|
| 69 | - * @return array |
|
| 70 | - */ |
|
| 71 | - public function register_scheduled_tasks($tasks) |
|
| 72 | - { |
|
| 73 | - $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron'; |
|
| 74 | - $tasks['AHEE__EE_Messages_Scheduler__sending'] = 'ee_message_cron'; |
|
| 75 | - return $tasks; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * This initiates a non-blocking separate request to execute on a scheduled task. |
|
| 81 | - * Note: The EED_Messages module has the handlers for these requests. |
|
| 82 | - * |
|
| 83 | - * @param string $task The task the request is being generated for. |
|
| 84 | - */ |
|
| 85 | - public static function initiate_scheduled_non_blocking_request($task) |
|
| 86 | - { |
|
| 87 | - if (apply_filters('EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request', |
|
| 88 | - true)) { |
|
| 89 | - $request_url = add_query_arg( |
|
| 90 | - array_merge( |
|
| 91 | - array('ee' => 'msg_cron_trigger'), |
|
| 92 | - EE_Messages_Scheduler::get_request_params($task) |
|
| 93 | - ), |
|
| 94 | - site_url() |
|
| 95 | - ); |
|
| 96 | - $request_args = array( |
|
| 97 | - 'timeout' => 300, |
|
| 98 | - 'blocking' => (defined('DOING_CRON') && DOING_CRON) || (defined('DOING_AJAX') && DOING_AJAX) ? true : false, |
|
| 99 | - 'sslverify' => false, |
|
| 100 | - 'redirection' => 10, |
|
| 101 | - ); |
|
| 102 | - $response = wp_remote_get($request_url, $request_args); |
|
| 103 | - if (is_wp_error($response)) { |
|
| 104 | - trigger_error($response->get_error_message()); |
|
| 105 | - } |
|
| 106 | - } else { |
|
| 107 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron($task); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * This returns |
|
| 114 | - * the request params used for a scheduled message task request. |
|
| 115 | - * |
|
| 116 | - * @param string $task The task the request is for. |
|
| 117 | - * @return array |
|
| 118 | - */ |
|
| 119 | - public static function get_request_params($task) |
|
| 120 | - { |
|
| 121 | - //transient is used for flood control on msg_cron_trigger requests |
|
| 122 | - $transient_key = 'ee_trans_' . uniqid($task); |
|
| 123 | - set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS); |
|
| 124 | - return array( |
|
| 125 | - 'type' => $task, |
|
| 126 | - 'key' => $transient_key, |
|
| 127 | - ); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * This is used to execute an immediate call to the run_cron task performed by EED_Messages |
|
| 133 | - * |
|
| 134 | - * @param string $task The task the request is being generated for. |
|
| 135 | - */ |
|
| 136 | - public static function initiate_immediate_request_on_cron($task) |
|
| 137 | - { |
|
| 138 | - $request_args = EE_Messages_Scheduler::get_request_params($task); |
|
| 139 | - //set those request args in the request so it gets picked up |
|
| 140 | - foreach ($request_args as $request_key => $request_value) { |
|
| 141 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 142 | - } |
|
| 143 | - EED_Messages::instance()->run_cron(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event |
|
| 149 | - */ |
|
| 150 | - public static function batch_generation() |
|
| 151 | - { |
|
| 152 | - /** |
|
| 153 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
| 154 | - */ |
|
| 155 | - if ( |
|
| 156 | - ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
| 157 | - || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 158 | - ) { |
|
| 159 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Callback for scheduled AHEE__EE_Messages_Scheduler__sending |
|
| 166 | - */ |
|
| 167 | - public static function batch_sending() |
|
| 168 | - { |
|
| 169 | - /** |
|
| 170 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
| 171 | - */ |
|
| 172 | - if ( |
|
| 173 | - ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
| 174 | - || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 175 | - ) { |
|
| 176 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron('send'); |
|
| 177 | - } |
|
| 178 | - } |
|
| 16 | + /** |
|
| 17 | + * Number of seconds between batch sends/generates on the cron job. |
|
| 18 | + * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
|
| 19 | + * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
|
| 20 | + * |
|
| 21 | + * @type int |
|
| 22 | + */ |
|
| 23 | + const message_cron_schedule = 300; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Constructor |
|
| 27 | + */ |
|
| 28 | + public function __construct() |
|
| 29 | + { |
|
| 30 | + //register tasks (and make sure only registered once). |
|
| 31 | + if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
| 32 | + add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + //register callbacks for scheduled events (but make sure they are set only once). |
|
| 36 | + if (! has_action('AHEE__EE_Messages_Scheduler__generation', |
|
| 37 | + array('EE_Messages_Scheduler', 'batch_generation')) |
|
| 38 | + ) { |
|
| 39 | + add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation')); |
|
| 40 | + add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending')); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + //add custom schedules |
|
| 44 | + add_filter('cron_schedules', array($this, 'custom_schedules')); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Add custom schedules for wp_cron |
|
| 50 | + * |
|
| 51 | + * @param $schedules |
|
| 52 | + */ |
|
| 53 | + public function custom_schedules($schedules) |
|
| 54 | + { |
|
| 55 | + $schedules['ee_message_cron'] = array( |
|
| 56 | + 'interval' => self::message_cron_schedule, |
|
| 57 | + 'display' => __('This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', |
|
| 58 | + 'event_espresso'), |
|
| 59 | + ); |
|
| 60 | + return $schedules; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and |
|
| 66 | + * remove. |
|
| 67 | + * |
|
| 68 | + * @param array $tasks already existing scheduled tasks |
|
| 69 | + * @return array |
|
| 70 | + */ |
|
| 71 | + public function register_scheduled_tasks($tasks) |
|
| 72 | + { |
|
| 73 | + $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron'; |
|
| 74 | + $tasks['AHEE__EE_Messages_Scheduler__sending'] = 'ee_message_cron'; |
|
| 75 | + return $tasks; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * This initiates a non-blocking separate request to execute on a scheduled task. |
|
| 81 | + * Note: The EED_Messages module has the handlers for these requests. |
|
| 82 | + * |
|
| 83 | + * @param string $task The task the request is being generated for. |
|
| 84 | + */ |
|
| 85 | + public static function initiate_scheduled_non_blocking_request($task) |
|
| 86 | + { |
|
| 87 | + if (apply_filters('EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request', |
|
| 88 | + true)) { |
|
| 89 | + $request_url = add_query_arg( |
|
| 90 | + array_merge( |
|
| 91 | + array('ee' => 'msg_cron_trigger'), |
|
| 92 | + EE_Messages_Scheduler::get_request_params($task) |
|
| 93 | + ), |
|
| 94 | + site_url() |
|
| 95 | + ); |
|
| 96 | + $request_args = array( |
|
| 97 | + 'timeout' => 300, |
|
| 98 | + 'blocking' => (defined('DOING_CRON') && DOING_CRON) || (defined('DOING_AJAX') && DOING_AJAX) ? true : false, |
|
| 99 | + 'sslverify' => false, |
|
| 100 | + 'redirection' => 10, |
|
| 101 | + ); |
|
| 102 | + $response = wp_remote_get($request_url, $request_args); |
|
| 103 | + if (is_wp_error($response)) { |
|
| 104 | + trigger_error($response->get_error_message()); |
|
| 105 | + } |
|
| 106 | + } else { |
|
| 107 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron($task); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * This returns |
|
| 114 | + * the request params used for a scheduled message task request. |
|
| 115 | + * |
|
| 116 | + * @param string $task The task the request is for. |
|
| 117 | + * @return array |
|
| 118 | + */ |
|
| 119 | + public static function get_request_params($task) |
|
| 120 | + { |
|
| 121 | + //transient is used for flood control on msg_cron_trigger requests |
|
| 122 | + $transient_key = 'ee_trans_' . uniqid($task); |
|
| 123 | + set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS); |
|
| 124 | + return array( |
|
| 125 | + 'type' => $task, |
|
| 126 | + 'key' => $transient_key, |
|
| 127 | + ); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * This is used to execute an immediate call to the run_cron task performed by EED_Messages |
|
| 133 | + * |
|
| 134 | + * @param string $task The task the request is being generated for. |
|
| 135 | + */ |
|
| 136 | + public static function initiate_immediate_request_on_cron($task) |
|
| 137 | + { |
|
| 138 | + $request_args = EE_Messages_Scheduler::get_request_params($task); |
|
| 139 | + //set those request args in the request so it gets picked up |
|
| 140 | + foreach ($request_args as $request_key => $request_value) { |
|
| 141 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 142 | + } |
|
| 143 | + EED_Messages::instance()->run_cron(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event |
|
| 149 | + */ |
|
| 150 | + public static function batch_generation() |
|
| 151 | + { |
|
| 152 | + /** |
|
| 153 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
| 154 | + */ |
|
| 155 | + if ( |
|
| 156 | + ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
| 157 | + || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 158 | + ) { |
|
| 159 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Callback for scheduled AHEE__EE_Messages_Scheduler__sending |
|
| 166 | + */ |
|
| 167 | + public static function batch_sending() |
|
| 168 | + { |
|
| 169 | + /** |
|
| 170 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
| 171 | + */ |
|
| 172 | + if ( |
|
| 173 | + ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
| 174 | + || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 175 | + ) { |
|
| 176 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron('send'); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | } //end EE_Messages_Scheduler |
| 181 | 181 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | public function __construct() |
| 29 | 29 | { |
| 30 | 30 | //register tasks (and make sure only registered once). |
| 31 | - if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
| 31 | + if ( ! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
| 32 | 32 | add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | //register callbacks for scheduled events (but make sure they are set only once). |
| 36 | - if (! has_action('AHEE__EE_Messages_Scheduler__generation', |
|
| 36 | + if ( ! has_action('AHEE__EE_Messages_Scheduler__generation', |
|
| 37 | 37 | array('EE_Messages_Scheduler', 'batch_generation')) |
| 38 | 38 | ) { |
| 39 | 39 | add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation')); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | if (apply_filters('EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request', |
| 88 | 88 | true)) { |
| 89 | - $request_url = add_query_arg( |
|
| 89 | + $request_url = add_query_arg( |
|
| 90 | 90 | array_merge( |
| 91 | 91 | array('ee' => 'msg_cron_trigger'), |
| 92 | 92 | EE_Messages_Scheduler::get_request_params($task) |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | 'sslverify' => false, |
| 100 | 100 | 'redirection' => 10, |
| 101 | 101 | ); |
| 102 | - $response = wp_remote_get($request_url, $request_args); |
|
| 102 | + $response = wp_remote_get($request_url, $request_args); |
|
| 103 | 103 | if (is_wp_error($response)) { |
| 104 | 104 | trigger_error($response->get_error_message()); |
| 105 | 105 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public static function get_request_params($task) |
| 120 | 120 | { |
| 121 | 121 | //transient is used for flood control on msg_cron_trigger requests |
| 122 | - $transient_key = 'ee_trans_' . uniqid($task); |
|
| 122 | + $transient_key = 'ee_trans_'.uniqid($task); |
|
| 123 | 123 | set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS); |
| 124 | 124 | return array( |
| 125 | 125 | 'type' => $task, |