@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $this->registerManifestFile( |
| 105 | 105 | self::ASSET_NAMESPACE, |
| 106 | 106 | $this->domain->distributionAssetsUrl(), |
| 107 | - $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
| 107 | + $this->domain->distributionAssetsPath().'build-manifest.json' |
|
| 108 | 108 | ); |
| 109 | 109 | add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
| 110 | 110 | add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | //js.api |
| 150 | 150 | wp_register_script( |
| 151 | 151 | 'eejs-api', |
| 152 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 152 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
| 153 | 153 | array('underscore', 'eejs-core'), |
| 154 | 154 | EVENT_ESPRESSO_VERSION, |
| 155 | 155 | true |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
| 158 | 158 | $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
| 159 | 159 | } |
| 160 | - if (! is_admin()) { |
|
| 160 | + if ( ! is_admin()) { |
|
| 161 | 161 | $this->loadCoreCss(); |
| 162 | 162 | } |
| 163 | 163 | $this->loadCoreJs(); |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | public function addTemplate($template_reference, $template_content) |
| 256 | 256 | { |
| 257 | - if (! isset($this->jsdata['templates'])) { |
|
| 257 | + if ( ! isset($this->jsdata['templates'])) { |
|
| 258 | 258 | $this->jsdata['templates'] = array(); |
| 259 | 259 | } |
| 260 | 260 | //no overrides allowed. |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | ); |
| 369 | 369 | } |
| 370 | 370 | $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
| 371 | - if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 371 | + if ( ! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 372 | 372 | $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
| 373 | 373 | } |
| 374 | 374 | } |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | private function decodeManifestFile($manifest_file) |
| 387 | 387 | { |
| 388 | - if (! file_exists($manifest_file)) { |
|
| 388 | + if ( ! file_exists($manifest_file)) { |
|
| 389 | 389 | throw new InvalidFilePathException($manifest_file); |
| 390 | 390 | } |
| 391 | 391 | return json_decode(file_get_contents($manifest_file), true); |
@@ -440,9 +440,9 @@ discard block |
||
| 440 | 440 | private function loadCoreCss() |
| 441 | 441 | { |
| 442 | 442 | if ($this->template_config->enable_default_style) { |
| 443 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 443 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
| 444 | 444 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
| 445 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 445 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css'; |
|
| 446 | 446 | wp_register_style( |
| 447 | 447 | 'espresso_default', |
| 448 | 448 | $default_stylesheet_path, |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | if ($this->template_config->custom_style_sheet !== null) { |
| 454 | 454 | wp_register_style( |
| 455 | 455 | 'espresso_custom_css', |
| 456 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 456 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
| 457 | 457 | array('espresso_default'), |
| 458 | 458 | EVENT_ESPRESSO_VERSION |
| 459 | 459 | ); |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | // load core js |
| 472 | 472 | wp_register_script( |
| 473 | 473 | 'espresso_core', |
| 474 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 474 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 475 | 475 | array('jquery'), |
| 476 | 476 | EVENT_ESPRESSO_VERSION, |
| 477 | 477 | true |
@@ -488,14 +488,14 @@ discard block |
||
| 488 | 488 | // register jQuery Validate and additional methods |
| 489 | 489 | wp_register_script( |
| 490 | 490 | 'jquery-validate', |
| 491 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 491 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
| 492 | 492 | array('jquery'), |
| 493 | 493 | '1.15.0', |
| 494 | 494 | true |
| 495 | 495 | ); |
| 496 | 496 | wp_register_script( |
| 497 | 497 | 'jquery-validate-extra-methods', |
| 498 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 498 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
| 499 | 499 | array('jquery', 'jquery-validate'), |
| 500 | 500 | '1.15.0', |
| 501 | 501 | true |
@@ -513,14 +513,14 @@ discard block |
||
| 513 | 513 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 514 | 514 | wp_register_script( |
| 515 | 515 | 'ee-accounting-core', |
| 516 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 516 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
| 517 | 517 | array('underscore'), |
| 518 | 518 | '0.3.2', |
| 519 | 519 | true |
| 520 | 520 | ); |
| 521 | 521 | wp_register_script( |
| 522 | 522 | 'ee-accounting', |
| 523 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 523 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
| 524 | 524 | array('ee-accounting-core'), |
| 525 | 525 | EVENT_ESPRESSO_VERSION, |
| 526 | 526 | true |
@@ -25,616 +25,616 @@ |
||
| 25 | 25 | class Registry |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - const ASSET_TYPE_CSS = 'css'; |
|
| 29 | - const ASSET_TYPE_JS = 'js'; |
|
| 30 | - const ASSET_NAMESPACE = 'core'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var EE_Template_Config $template_config |
|
| 34 | - */ |
|
| 35 | - protected $template_config; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var EE_Currency_Config $currency_config |
|
| 39 | - */ |
|
| 40 | - protected $currency_config; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected $jsdata = array(); |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 52 | - * page source. |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - protected $script_handles_with_data = array(); |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var DomainInterface |
|
| 60 | - */ |
|
| 61 | - protected $domain; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Holds the manifest data obtained from registered manifest files. |
|
| 67 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
| 68 | - * Shape of this array is: |
|
| 69 | - * |
|
| 70 | - * array( |
|
| 71 | - * 'some_namespace_slug' => array( |
|
| 72 | - * 'some_chunk_name' => array( |
|
| 73 | - * 'js' => 'filename.js' |
|
| 74 | - * 'css' => 'filename.js' |
|
| 75 | - * ), |
|
| 76 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
| 77 | - * ) |
|
| 78 | - * ) |
|
| 79 | - * |
|
| 80 | - * @var array |
|
| 81 | - */ |
|
| 82 | - private $manifest_data = array(); |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Registry constructor. |
|
| 87 | - * Hooking into WP actions for script registry. |
|
| 88 | - * |
|
| 89 | - * @param EE_Template_Config $template_config |
|
| 90 | - * @param EE_Currency_Config $currency_config |
|
| 91 | - * @param DomainInterface $domain |
|
| 92 | - * @throws InvalidArgumentException |
|
| 93 | - * @throws InvalidFilePathException |
|
| 94 | - */ |
|
| 95 | - public function __construct( |
|
| 96 | - EE_Template_Config $template_config, |
|
| 97 | - EE_Currency_Config $currency_config, |
|
| 98 | - DomainInterface $domain |
|
| 99 | - ) { |
|
| 100 | - $this->template_config = $template_config; |
|
| 101 | - $this->currency_config = $currency_config; |
|
| 102 | - $this->domain = $domain; |
|
| 103 | - $this->registerManifestFile( |
|
| 104 | - self::ASSET_NAMESPACE, |
|
| 105 | - $this->domain->distributionAssetsUrl(), |
|
| 106 | - $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
| 107 | - ); |
|
| 108 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 109 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 110 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 111 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 112 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 113 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Callback for the WP script actions. |
|
| 118 | - * Used to register globally accessible core scripts. |
|
| 119 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 120 | - * |
|
| 121 | - */ |
|
| 122 | - public function scripts() |
|
| 123 | - { |
|
| 124 | - global $wp_version; |
|
| 125 | - wp_register_script( |
|
| 126 | - 'ee-manifest', |
|
| 127 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'manifest', self::ASSET_TYPE_JS), |
|
| 128 | - array(), |
|
| 129 | - null, |
|
| 130 | - true |
|
| 131 | - ); |
|
| 132 | - wp_register_script( |
|
| 133 | - 'eejs-core', |
|
| 134 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'eejs', self::ASSET_TYPE_JS), |
|
| 135 | - array('ee-manifest'), |
|
| 136 | - null, |
|
| 137 | - true |
|
| 138 | - ); |
|
| 139 | - wp_register_script( |
|
| 140 | - 'ee-vendor-react', |
|
| 141 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'reactVendor', self::ASSET_TYPE_JS), |
|
| 142 | - array('eejs-core'), |
|
| 143 | - null, |
|
| 144 | - true |
|
| 145 | - ); |
|
| 146 | - //only run this if WordPress 4.4.0 > is in use. |
|
| 147 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 148 | - //js.api |
|
| 149 | - wp_register_script( |
|
| 150 | - 'eejs-api', |
|
| 151 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 152 | - array('underscore', 'eejs-core'), |
|
| 153 | - EVENT_ESPRESSO_VERSION, |
|
| 154 | - true |
|
| 155 | - ); |
|
| 156 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 157 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 158 | - } |
|
| 159 | - if (! is_admin()) { |
|
| 160 | - $this->loadCoreCss(); |
|
| 161 | - } |
|
| 162 | - $this->loadCoreJs(); |
|
| 163 | - $this->loadJqueryValidate(); |
|
| 164 | - $this->loadAccountingJs(); |
|
| 165 | - $this->loadQtipJs(); |
|
| 166 | - $this->registerAdminAssets(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Call back for the script print in frontend and backend. |
|
| 173 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 174 | - * |
|
| 175 | - * @since 4.9.31.rc.015 |
|
| 176 | - */ |
|
| 177 | - public function enqueueData() |
|
| 178 | - { |
|
| 179 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 180 | - wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
| 181 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 182 | - $this->localizeAccountingJs(); |
|
| 183 | - $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
| 184 | - $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Used to add data to eejs.data object. |
|
| 191 | - * Note: Overriding existing data is not allowed. |
|
| 192 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 193 | - * If the data you add is something like this: |
|
| 194 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 195 | - * It will be exposed in the page source as: |
|
| 196 | - * eejs.data.my_plugin_data.foo == gar |
|
| 197 | - * |
|
| 198 | - * @param string $key Key used to access your data |
|
| 199 | - * @param string|array $value Value to attach to key |
|
| 200 | - * @throws InvalidArgumentException |
|
| 201 | - */ |
|
| 202 | - public function addData($key, $value) |
|
| 203 | - { |
|
| 204 | - if ($this->verifyDataNotExisting($key)) { |
|
| 205 | - $this->jsdata[$key] = $value; |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 213 | - * elements in an array. |
|
| 214 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 215 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 216 | - * object like this, eejs.data.test = [ my_data, |
|
| 217 | - * ] |
|
| 218 | - * If there has already been a scalar value attached to the data object given key, then |
|
| 219 | - * this will throw an exception. |
|
| 220 | - * |
|
| 221 | - * @param string $key Key to attach data to. |
|
| 222 | - * @param string|array $value Value being registered. |
|
| 223 | - * @throws InvalidArgumentException |
|
| 224 | - */ |
|
| 225 | - public function pushData($key, $value) |
|
| 226 | - { |
|
| 227 | - if (isset($this->jsdata[$key]) |
|
| 228 | - && ! is_array($this->jsdata[$key]) |
|
| 229 | - ) { |
|
| 230 | - throw new invalidArgumentException( |
|
| 231 | - sprintf( |
|
| 232 | - __( |
|
| 233 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 28 | + const ASSET_TYPE_CSS = 'css'; |
|
| 29 | + const ASSET_TYPE_JS = 'js'; |
|
| 30 | + const ASSET_NAMESPACE = 'core'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var EE_Template_Config $template_config |
|
| 34 | + */ |
|
| 35 | + protected $template_config; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var EE_Currency_Config $currency_config |
|
| 39 | + */ |
|
| 40 | + protected $currency_config; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected $jsdata = array(); |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 52 | + * page source. |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + protected $script_handles_with_data = array(); |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var DomainInterface |
|
| 60 | + */ |
|
| 61 | + protected $domain; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Holds the manifest data obtained from registered manifest files. |
|
| 67 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
| 68 | + * Shape of this array is: |
|
| 69 | + * |
|
| 70 | + * array( |
|
| 71 | + * 'some_namespace_slug' => array( |
|
| 72 | + * 'some_chunk_name' => array( |
|
| 73 | + * 'js' => 'filename.js' |
|
| 74 | + * 'css' => 'filename.js' |
|
| 75 | + * ), |
|
| 76 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
| 77 | + * ) |
|
| 78 | + * ) |
|
| 79 | + * |
|
| 80 | + * @var array |
|
| 81 | + */ |
|
| 82 | + private $manifest_data = array(); |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Registry constructor. |
|
| 87 | + * Hooking into WP actions for script registry. |
|
| 88 | + * |
|
| 89 | + * @param EE_Template_Config $template_config |
|
| 90 | + * @param EE_Currency_Config $currency_config |
|
| 91 | + * @param DomainInterface $domain |
|
| 92 | + * @throws InvalidArgumentException |
|
| 93 | + * @throws InvalidFilePathException |
|
| 94 | + */ |
|
| 95 | + public function __construct( |
|
| 96 | + EE_Template_Config $template_config, |
|
| 97 | + EE_Currency_Config $currency_config, |
|
| 98 | + DomainInterface $domain |
|
| 99 | + ) { |
|
| 100 | + $this->template_config = $template_config; |
|
| 101 | + $this->currency_config = $currency_config; |
|
| 102 | + $this->domain = $domain; |
|
| 103 | + $this->registerManifestFile( |
|
| 104 | + self::ASSET_NAMESPACE, |
|
| 105 | + $this->domain->distributionAssetsUrl(), |
|
| 106 | + $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
| 107 | + ); |
|
| 108 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 109 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 110 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 111 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 112 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 113 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Callback for the WP script actions. |
|
| 118 | + * Used to register globally accessible core scripts. |
|
| 119 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 120 | + * |
|
| 121 | + */ |
|
| 122 | + public function scripts() |
|
| 123 | + { |
|
| 124 | + global $wp_version; |
|
| 125 | + wp_register_script( |
|
| 126 | + 'ee-manifest', |
|
| 127 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'manifest', self::ASSET_TYPE_JS), |
|
| 128 | + array(), |
|
| 129 | + null, |
|
| 130 | + true |
|
| 131 | + ); |
|
| 132 | + wp_register_script( |
|
| 133 | + 'eejs-core', |
|
| 134 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'eejs', self::ASSET_TYPE_JS), |
|
| 135 | + array('ee-manifest'), |
|
| 136 | + null, |
|
| 137 | + true |
|
| 138 | + ); |
|
| 139 | + wp_register_script( |
|
| 140 | + 'ee-vendor-react', |
|
| 141 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'reactVendor', self::ASSET_TYPE_JS), |
|
| 142 | + array('eejs-core'), |
|
| 143 | + null, |
|
| 144 | + true |
|
| 145 | + ); |
|
| 146 | + //only run this if WordPress 4.4.0 > is in use. |
|
| 147 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 148 | + //js.api |
|
| 149 | + wp_register_script( |
|
| 150 | + 'eejs-api', |
|
| 151 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 152 | + array('underscore', 'eejs-core'), |
|
| 153 | + EVENT_ESPRESSO_VERSION, |
|
| 154 | + true |
|
| 155 | + ); |
|
| 156 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 157 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 158 | + } |
|
| 159 | + if (! is_admin()) { |
|
| 160 | + $this->loadCoreCss(); |
|
| 161 | + } |
|
| 162 | + $this->loadCoreJs(); |
|
| 163 | + $this->loadJqueryValidate(); |
|
| 164 | + $this->loadAccountingJs(); |
|
| 165 | + $this->loadQtipJs(); |
|
| 166 | + $this->registerAdminAssets(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Call back for the script print in frontend and backend. |
|
| 173 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 174 | + * |
|
| 175 | + * @since 4.9.31.rc.015 |
|
| 176 | + */ |
|
| 177 | + public function enqueueData() |
|
| 178 | + { |
|
| 179 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 180 | + wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
| 181 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 182 | + $this->localizeAccountingJs(); |
|
| 183 | + $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
| 184 | + $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Used to add data to eejs.data object. |
|
| 191 | + * Note: Overriding existing data is not allowed. |
|
| 192 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 193 | + * If the data you add is something like this: |
|
| 194 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 195 | + * It will be exposed in the page source as: |
|
| 196 | + * eejs.data.my_plugin_data.foo == gar |
|
| 197 | + * |
|
| 198 | + * @param string $key Key used to access your data |
|
| 199 | + * @param string|array $value Value to attach to key |
|
| 200 | + * @throws InvalidArgumentException |
|
| 201 | + */ |
|
| 202 | + public function addData($key, $value) |
|
| 203 | + { |
|
| 204 | + if ($this->verifyDataNotExisting($key)) { |
|
| 205 | + $this->jsdata[$key] = $value; |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 213 | + * elements in an array. |
|
| 214 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 215 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 216 | + * object like this, eejs.data.test = [ my_data, |
|
| 217 | + * ] |
|
| 218 | + * If there has already been a scalar value attached to the data object given key, then |
|
| 219 | + * this will throw an exception. |
|
| 220 | + * |
|
| 221 | + * @param string $key Key to attach data to. |
|
| 222 | + * @param string|array $value Value being registered. |
|
| 223 | + * @throws InvalidArgumentException |
|
| 224 | + */ |
|
| 225 | + public function pushData($key, $value) |
|
| 226 | + { |
|
| 227 | + if (isset($this->jsdata[$key]) |
|
| 228 | + && ! is_array($this->jsdata[$key]) |
|
| 229 | + ) { |
|
| 230 | + throw new invalidArgumentException( |
|
| 231 | + sprintf( |
|
| 232 | + __( |
|
| 233 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 234 | 234 | push values to this data element when it is an array.', |
| 235 | - 'event_espresso' |
|
| 236 | - ), |
|
| 237 | - $key, |
|
| 238 | - __METHOD__ |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - $this->jsdata[$key][] = $value; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Used to set content used by javascript for a template. |
|
| 249 | - * Note: Overrides of existing registered templates are not allowed. |
|
| 250 | - * |
|
| 251 | - * @param string $template_reference |
|
| 252 | - * @param string $template_content |
|
| 253 | - * @throws InvalidArgumentException |
|
| 254 | - */ |
|
| 255 | - public function addTemplate($template_reference, $template_content) |
|
| 256 | - { |
|
| 257 | - if (! isset($this->jsdata['templates'])) { |
|
| 258 | - $this->jsdata['templates'] = array(); |
|
| 259 | - } |
|
| 260 | - //no overrides allowed. |
|
| 261 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 262 | - throw new invalidArgumentException( |
|
| 263 | - sprintf( |
|
| 264 | - __( |
|
| 265 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 266 | - 'event_espresso' |
|
| 267 | - ), |
|
| 268 | - $template_reference |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Retrieve the template content already registered for the given reference. |
|
| 279 | - * |
|
| 280 | - * @param string $template_reference |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 283 | - public function getTemplate($template_reference) |
|
| 284 | - { |
|
| 285 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 286 | - ? $this->jsdata['templates'][$template_reference] |
|
| 287 | - : ''; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Retrieve registered data. |
|
| 294 | - * |
|
| 295 | - * @param string $key Name of key to attach data to. |
|
| 296 | - * @return mixed If there is no for the given key, then false is returned. |
|
| 297 | - */ |
|
| 298 | - public function getData($key) |
|
| 299 | - { |
|
| 300 | - return isset($this->jsdata[$key]) |
|
| 301 | - ? $this->jsdata[$key] |
|
| 302 | - : false; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Get the actual asset path for asset manifests. |
|
| 308 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
| 309 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
| 310 | - * asset file location. |
|
| 311 | - * @param string $chunk_name |
|
| 312 | - * @param string $asset_type |
|
| 313 | - * @return string |
|
| 314 | - * @since $VID:$ |
|
| 315 | - */ |
|
| 316 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
| 317 | - { |
|
| 318 | - $url = isset( |
|
| 319 | - $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
| 320 | - $this->manifest_data[$namespace]['url_base'] |
|
| 321 | - ) |
|
| 322 | - ? $this->manifest_data[$namespace]['url_base'] |
|
| 323 | - . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
| 324 | - : $chunk_name; |
|
| 325 | - return apply_filters( |
|
| 326 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
| 327 | - $url, |
|
| 328 | - $namespace, |
|
| 329 | - $chunk_name, |
|
| 330 | - $asset_type |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
| 337 | - * |
|
| 338 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
| 339 | - * @param string $url_base The url base for the manifest file location. |
|
| 340 | - * @param string $manifest_file The absolute path to the manifest file. |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - * @throws InvalidFilePathException |
|
| 343 | - * @since $VID:$ |
|
| 344 | - */ |
|
| 345 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
| 346 | - { |
|
| 347 | - if (isset($this->manifest_data[$namespace])) { |
|
| 348 | - throw new InvalidArgumentException( |
|
| 349 | - sprintf( |
|
| 350 | - esc_html__( |
|
| 351 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
| 352 | - 'event_espresso' |
|
| 353 | - ), |
|
| 354 | - $namespace |
|
| 355 | - ) |
|
| 356 | - ); |
|
| 357 | - } |
|
| 358 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
| 359 | - throw new InvalidArgumentException( |
|
| 360 | - sprintf( |
|
| 361 | - esc_html__( |
|
| 362 | - 'The provided value for %1$s is not a valid url. The url provided was: %2$s', |
|
| 363 | - 'event_espresso' |
|
| 364 | - ), |
|
| 365 | - '$url_base', |
|
| 366 | - $url_base |
|
| 367 | - ) |
|
| 368 | - ); |
|
| 369 | - } |
|
| 370 | - $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
| 371 | - if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 372 | - $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Decodes json from the provided manifest file. |
|
| 380 | - * |
|
| 381 | - * @since $VID:$ |
|
| 382 | - * @param string $manifest_file Path to manifest file. |
|
| 383 | - * @return array |
|
| 384 | - * @throws InvalidFilePathException |
|
| 385 | - */ |
|
| 386 | - private function decodeManifestFile($manifest_file) |
|
| 387 | - { |
|
| 388 | - if (! file_exists($manifest_file)) { |
|
| 389 | - throw new InvalidFilePathException($manifest_file); |
|
| 390 | - } |
|
| 391 | - return json_decode(file_get_contents($manifest_file), true); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Verifies whether the given data exists already on the jsdata array. |
|
| 398 | - * Overriding data is not allowed. |
|
| 399 | - * |
|
| 400 | - * @param string $key Index for data. |
|
| 401 | - * @return bool If valid then return true. |
|
| 402 | - * @throws InvalidArgumentException if data already exists. |
|
| 403 | - */ |
|
| 404 | - protected function verifyDataNotExisting($key) |
|
| 405 | - { |
|
| 406 | - if (isset($this->jsdata[$key])) { |
|
| 407 | - if (is_array($this->jsdata[$key])) { |
|
| 408 | - throw new InvalidArgumentException( |
|
| 409 | - sprintf( |
|
| 410 | - __( |
|
| 411 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
| 235 | + 'event_espresso' |
|
| 236 | + ), |
|
| 237 | + $key, |
|
| 238 | + __METHOD__ |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + $this->jsdata[$key][] = $value; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Used to set content used by javascript for a template. |
|
| 249 | + * Note: Overrides of existing registered templates are not allowed. |
|
| 250 | + * |
|
| 251 | + * @param string $template_reference |
|
| 252 | + * @param string $template_content |
|
| 253 | + * @throws InvalidArgumentException |
|
| 254 | + */ |
|
| 255 | + public function addTemplate($template_reference, $template_content) |
|
| 256 | + { |
|
| 257 | + if (! isset($this->jsdata['templates'])) { |
|
| 258 | + $this->jsdata['templates'] = array(); |
|
| 259 | + } |
|
| 260 | + //no overrides allowed. |
|
| 261 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 262 | + throw new invalidArgumentException( |
|
| 263 | + sprintf( |
|
| 264 | + __( |
|
| 265 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 266 | + 'event_espresso' |
|
| 267 | + ), |
|
| 268 | + $template_reference |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Retrieve the template content already registered for the given reference. |
|
| 279 | + * |
|
| 280 | + * @param string $template_reference |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | + public function getTemplate($template_reference) |
|
| 284 | + { |
|
| 285 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 286 | + ? $this->jsdata['templates'][$template_reference] |
|
| 287 | + : ''; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Retrieve registered data. |
|
| 294 | + * |
|
| 295 | + * @param string $key Name of key to attach data to. |
|
| 296 | + * @return mixed If there is no for the given key, then false is returned. |
|
| 297 | + */ |
|
| 298 | + public function getData($key) |
|
| 299 | + { |
|
| 300 | + return isset($this->jsdata[$key]) |
|
| 301 | + ? $this->jsdata[$key] |
|
| 302 | + : false; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Get the actual asset path for asset manifests. |
|
| 308 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
| 309 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
| 310 | + * asset file location. |
|
| 311 | + * @param string $chunk_name |
|
| 312 | + * @param string $asset_type |
|
| 313 | + * @return string |
|
| 314 | + * @since $VID:$ |
|
| 315 | + */ |
|
| 316 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
| 317 | + { |
|
| 318 | + $url = isset( |
|
| 319 | + $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
| 320 | + $this->manifest_data[$namespace]['url_base'] |
|
| 321 | + ) |
|
| 322 | + ? $this->manifest_data[$namespace]['url_base'] |
|
| 323 | + . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
| 324 | + : $chunk_name; |
|
| 325 | + return apply_filters( |
|
| 326 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
| 327 | + $url, |
|
| 328 | + $namespace, |
|
| 329 | + $chunk_name, |
|
| 330 | + $asset_type |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
| 337 | + * |
|
| 338 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
| 339 | + * @param string $url_base The url base for the manifest file location. |
|
| 340 | + * @param string $manifest_file The absolute path to the manifest file. |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + * @throws InvalidFilePathException |
|
| 343 | + * @since $VID:$ |
|
| 344 | + */ |
|
| 345 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
| 346 | + { |
|
| 347 | + if (isset($this->manifest_data[$namespace])) { |
|
| 348 | + throw new InvalidArgumentException( |
|
| 349 | + sprintf( |
|
| 350 | + esc_html__( |
|
| 351 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
| 352 | + 'event_espresso' |
|
| 353 | + ), |
|
| 354 | + $namespace |
|
| 355 | + ) |
|
| 356 | + ); |
|
| 357 | + } |
|
| 358 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
| 359 | + throw new InvalidArgumentException( |
|
| 360 | + sprintf( |
|
| 361 | + esc_html__( |
|
| 362 | + 'The provided value for %1$s is not a valid url. The url provided was: %2$s', |
|
| 363 | + 'event_espresso' |
|
| 364 | + ), |
|
| 365 | + '$url_base', |
|
| 366 | + $url_base |
|
| 367 | + ) |
|
| 368 | + ); |
|
| 369 | + } |
|
| 370 | + $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
| 371 | + if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 372 | + $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Decodes json from the provided manifest file. |
|
| 380 | + * |
|
| 381 | + * @since $VID:$ |
|
| 382 | + * @param string $manifest_file Path to manifest file. |
|
| 383 | + * @return array |
|
| 384 | + * @throws InvalidFilePathException |
|
| 385 | + */ |
|
| 386 | + private function decodeManifestFile($manifest_file) |
|
| 387 | + { |
|
| 388 | + if (! file_exists($manifest_file)) { |
|
| 389 | + throw new InvalidFilePathException($manifest_file); |
|
| 390 | + } |
|
| 391 | + return json_decode(file_get_contents($manifest_file), true); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Verifies whether the given data exists already on the jsdata array. |
|
| 398 | + * Overriding data is not allowed. |
|
| 399 | + * |
|
| 400 | + * @param string $key Index for data. |
|
| 401 | + * @return bool If valid then return true. |
|
| 402 | + * @throws InvalidArgumentException if data already exists. |
|
| 403 | + */ |
|
| 404 | + protected function verifyDataNotExisting($key) |
|
| 405 | + { |
|
| 406 | + if (isset($this->jsdata[$key])) { |
|
| 407 | + if (is_array($this->jsdata[$key])) { |
|
| 408 | + throw new InvalidArgumentException( |
|
| 409 | + sprintf( |
|
| 410 | + __( |
|
| 411 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
| 412 | 412 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
| 413 | 413 | %2$s method to push your value to the array.', |
| 414 | - 'event_espresso' |
|
| 415 | - ), |
|
| 416 | - $key, |
|
| 417 | - 'pushData()' |
|
| 418 | - ) |
|
| 419 | - ); |
|
| 420 | - } |
|
| 421 | - throw new InvalidArgumentException( |
|
| 422 | - sprintf( |
|
| 423 | - __( |
|
| 424 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 414 | + 'event_espresso' |
|
| 415 | + ), |
|
| 416 | + $key, |
|
| 417 | + 'pushData()' |
|
| 418 | + ) |
|
| 419 | + ); |
|
| 420 | + } |
|
| 421 | + throw new InvalidArgumentException( |
|
| 422 | + sprintf( |
|
| 423 | + __( |
|
| 424 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 425 | 425 | allowed. Consider attaching your value to a different key', |
| 426 | - 'event_espresso' |
|
| 427 | - ), |
|
| 428 | - $key |
|
| 429 | - ) |
|
| 430 | - ); |
|
| 431 | - } |
|
| 432 | - return true; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * registers core default stylesheets |
|
| 439 | - */ |
|
| 440 | - private function loadCoreCss() |
|
| 441 | - { |
|
| 442 | - if ($this->template_config->enable_default_style) { |
|
| 443 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 444 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 445 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 446 | - wp_register_style( |
|
| 447 | - 'espresso_default', |
|
| 448 | - $default_stylesheet_path, |
|
| 449 | - array('dashicons'), |
|
| 450 | - EVENT_ESPRESSO_VERSION |
|
| 451 | - ); |
|
| 452 | - //Load custom style sheet if available |
|
| 453 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 454 | - wp_register_style( |
|
| 455 | - 'espresso_custom_css', |
|
| 456 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 457 | - array('espresso_default'), |
|
| 458 | - EVENT_ESPRESSO_VERSION |
|
| 459 | - ); |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * registers core default javascript |
|
| 468 | - */ |
|
| 469 | - private function loadCoreJs() |
|
| 470 | - { |
|
| 471 | - // load core js |
|
| 472 | - wp_register_script( |
|
| 473 | - 'espresso_core', |
|
| 474 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 475 | - array('jquery'), |
|
| 476 | - EVENT_ESPRESSO_VERSION, |
|
| 477 | - true |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * registers jQuery Validate for form validation |
|
| 485 | - */ |
|
| 486 | - private function loadJqueryValidate() |
|
| 487 | - { |
|
| 488 | - // register jQuery Validate and additional methods |
|
| 489 | - wp_register_script( |
|
| 490 | - 'jquery-validate', |
|
| 491 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 492 | - array('jquery'), |
|
| 493 | - '1.15.0', |
|
| 494 | - true |
|
| 495 | - ); |
|
| 496 | - wp_register_script( |
|
| 497 | - 'jquery-validate-extra-methods', |
|
| 498 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 499 | - array('jquery', 'jquery-validate'), |
|
| 500 | - '1.15.0', |
|
| 501 | - true |
|
| 502 | - ); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * registers accounting.js for performing client-side calculations |
|
| 509 | - */ |
|
| 510 | - private function loadAccountingJs() |
|
| 511 | - { |
|
| 512 | - //accounting.js library |
|
| 513 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 514 | - wp_register_script( |
|
| 515 | - 'ee-accounting-core', |
|
| 516 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 517 | - array('underscore'), |
|
| 518 | - '0.3.2', |
|
| 519 | - true |
|
| 520 | - ); |
|
| 521 | - wp_register_script( |
|
| 522 | - 'ee-accounting', |
|
| 523 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 524 | - array('ee-accounting-core'), |
|
| 525 | - EVENT_ESPRESSO_VERSION, |
|
| 526 | - true |
|
| 527 | - ); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * registers accounting.js for performing client-side calculations |
|
| 534 | - */ |
|
| 535 | - private function localizeAccountingJs() |
|
| 536 | - { |
|
| 537 | - wp_localize_script( |
|
| 538 | - 'ee-accounting', |
|
| 539 | - 'EE_ACCOUNTING_CFG', |
|
| 540 | - array( |
|
| 541 | - 'currency' => array( |
|
| 542 | - 'symbol' => $this->currency_config->sign, |
|
| 543 | - 'format' => array( |
|
| 544 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 545 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 546 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 547 | - ), |
|
| 548 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 549 | - 'thousand' => $this->currency_config->thsnds, |
|
| 550 | - 'precision' => $this->currency_config->dec_plc, |
|
| 551 | - ), |
|
| 552 | - 'number' => array( |
|
| 553 | - 'precision' => $this->currency_config->dec_plc, |
|
| 554 | - 'thousand' => $this->currency_config->thsnds, |
|
| 555 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 556 | - ), |
|
| 557 | - ) |
|
| 558 | - ); |
|
| 559 | - $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * registers assets for cleaning your ears |
|
| 566 | - */ |
|
| 567 | - private function loadQtipJs() |
|
| 568 | - { |
|
| 569 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 570 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 571 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 572 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * This is used to set registered script handles that have data. |
|
| 579 | - * @param string $script_handle |
|
| 580 | - */ |
|
| 581 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 582 | - { |
|
| 583 | - $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
| 589 | - * Dependency stored in WP_Scripts if its set. |
|
| 590 | - */ |
|
| 591 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 592 | - { |
|
| 593 | - if (empty($this->script_handles_with_data)) { |
|
| 594 | - return; |
|
| 595 | - } |
|
| 596 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
| 597 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 598 | - } |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
| 604 | - * @param string $script_handle |
|
| 605 | - */ |
|
| 606 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 607 | - { |
|
| 608 | - if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 609 | - global $wp_scripts; |
|
| 610 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 611 | - unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 612 | - unset($this->script_handles_with_data[$script_handle]); |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * Registers assets that are used in the WordPress admin. |
|
| 620 | - */ |
|
| 621 | - private function registerAdminAssets() |
|
| 622 | - { |
|
| 623 | - wp_register_script( |
|
| 624 | - 'ee-wp-plugins-page', |
|
| 625 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_JS), |
|
| 626 | - array( |
|
| 627 | - 'jquery', |
|
| 628 | - 'ee-vendor-react' |
|
| 629 | - ), |
|
| 630 | - null, |
|
| 631 | - true |
|
| 632 | - ); |
|
| 633 | - wp_register_style( |
|
| 634 | - 'ee-wp-plugins-page', |
|
| 635 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_CSS), |
|
| 636 | - array(), |
|
| 637 | - null |
|
| 638 | - ); |
|
| 639 | - } |
|
| 426 | + 'event_espresso' |
|
| 427 | + ), |
|
| 428 | + $key |
|
| 429 | + ) |
|
| 430 | + ); |
|
| 431 | + } |
|
| 432 | + return true; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * registers core default stylesheets |
|
| 439 | + */ |
|
| 440 | + private function loadCoreCss() |
|
| 441 | + { |
|
| 442 | + if ($this->template_config->enable_default_style) { |
|
| 443 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 444 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 445 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 446 | + wp_register_style( |
|
| 447 | + 'espresso_default', |
|
| 448 | + $default_stylesheet_path, |
|
| 449 | + array('dashicons'), |
|
| 450 | + EVENT_ESPRESSO_VERSION |
|
| 451 | + ); |
|
| 452 | + //Load custom style sheet if available |
|
| 453 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 454 | + wp_register_style( |
|
| 455 | + 'espresso_custom_css', |
|
| 456 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 457 | + array('espresso_default'), |
|
| 458 | + EVENT_ESPRESSO_VERSION |
|
| 459 | + ); |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * registers core default javascript |
|
| 468 | + */ |
|
| 469 | + private function loadCoreJs() |
|
| 470 | + { |
|
| 471 | + // load core js |
|
| 472 | + wp_register_script( |
|
| 473 | + 'espresso_core', |
|
| 474 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 475 | + array('jquery'), |
|
| 476 | + EVENT_ESPRESSO_VERSION, |
|
| 477 | + true |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * registers jQuery Validate for form validation |
|
| 485 | + */ |
|
| 486 | + private function loadJqueryValidate() |
|
| 487 | + { |
|
| 488 | + // register jQuery Validate and additional methods |
|
| 489 | + wp_register_script( |
|
| 490 | + 'jquery-validate', |
|
| 491 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 492 | + array('jquery'), |
|
| 493 | + '1.15.0', |
|
| 494 | + true |
|
| 495 | + ); |
|
| 496 | + wp_register_script( |
|
| 497 | + 'jquery-validate-extra-methods', |
|
| 498 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 499 | + array('jquery', 'jquery-validate'), |
|
| 500 | + '1.15.0', |
|
| 501 | + true |
|
| 502 | + ); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * registers accounting.js for performing client-side calculations |
|
| 509 | + */ |
|
| 510 | + private function loadAccountingJs() |
|
| 511 | + { |
|
| 512 | + //accounting.js library |
|
| 513 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 514 | + wp_register_script( |
|
| 515 | + 'ee-accounting-core', |
|
| 516 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 517 | + array('underscore'), |
|
| 518 | + '0.3.2', |
|
| 519 | + true |
|
| 520 | + ); |
|
| 521 | + wp_register_script( |
|
| 522 | + 'ee-accounting', |
|
| 523 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 524 | + array('ee-accounting-core'), |
|
| 525 | + EVENT_ESPRESSO_VERSION, |
|
| 526 | + true |
|
| 527 | + ); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * registers accounting.js for performing client-side calculations |
|
| 534 | + */ |
|
| 535 | + private function localizeAccountingJs() |
|
| 536 | + { |
|
| 537 | + wp_localize_script( |
|
| 538 | + 'ee-accounting', |
|
| 539 | + 'EE_ACCOUNTING_CFG', |
|
| 540 | + array( |
|
| 541 | + 'currency' => array( |
|
| 542 | + 'symbol' => $this->currency_config->sign, |
|
| 543 | + 'format' => array( |
|
| 544 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 545 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 546 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 547 | + ), |
|
| 548 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 549 | + 'thousand' => $this->currency_config->thsnds, |
|
| 550 | + 'precision' => $this->currency_config->dec_plc, |
|
| 551 | + ), |
|
| 552 | + 'number' => array( |
|
| 553 | + 'precision' => $this->currency_config->dec_plc, |
|
| 554 | + 'thousand' => $this->currency_config->thsnds, |
|
| 555 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 556 | + ), |
|
| 557 | + ) |
|
| 558 | + ); |
|
| 559 | + $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * registers assets for cleaning your ears |
|
| 566 | + */ |
|
| 567 | + private function loadQtipJs() |
|
| 568 | + { |
|
| 569 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 570 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 571 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 572 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * This is used to set registered script handles that have data. |
|
| 579 | + * @param string $script_handle |
|
| 580 | + */ |
|
| 581 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 582 | + { |
|
| 583 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
| 589 | + * Dependency stored in WP_Scripts if its set. |
|
| 590 | + */ |
|
| 591 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 592 | + { |
|
| 593 | + if (empty($this->script_handles_with_data)) { |
|
| 594 | + return; |
|
| 595 | + } |
|
| 596 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
| 597 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 598 | + } |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
| 604 | + * @param string $script_handle |
|
| 605 | + */ |
|
| 606 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 607 | + { |
|
| 608 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 609 | + global $wp_scripts; |
|
| 610 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 611 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 612 | + unset($this->script_handles_with_data[$script_handle]); |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * Registers assets that are used in the WordPress admin. |
|
| 620 | + */ |
|
| 621 | + private function registerAdminAssets() |
|
| 622 | + { |
|
| 623 | + wp_register_script( |
|
| 624 | + 'ee-wp-plugins-page', |
|
| 625 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_JS), |
|
| 626 | + array( |
|
| 627 | + 'jquery', |
|
| 628 | + 'ee-vendor-react' |
|
| 629 | + ), |
|
| 630 | + null, |
|
| 631 | + true |
|
| 632 | + ); |
|
| 633 | + wp_register_style( |
|
| 634 | + 'ee-wp-plugins-page', |
|
| 635 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_CSS), |
|
| 636 | + array(), |
|
| 637 | + null |
|
| 638 | + ); |
|
| 639 | + } |
|
| 640 | 640 | } |
@@ -19,94 +19,94 @@ |
||
| 19 | 19 | class ExitModal |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var Registry |
|
| 24 | - */ |
|
| 25 | - private $assets_registry; |
|
| 22 | + /** |
|
| 23 | + * @var Registry |
|
| 24 | + */ |
|
| 25 | + private $assets_registry; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * ExitModal constructor. |
|
| 29 | - * |
|
| 30 | - * @param Registry $assets_registry |
|
| 31 | - */ |
|
| 32 | - public function __construct(Registry $assets_registry) |
|
| 33 | - { |
|
| 34 | - $this->assets_registry = $assets_registry; |
|
| 35 | - add_action('in_admin_footer', array($this, 'modalContainer')); |
|
| 36 | - add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
| 37 | - } |
|
| 27 | + /** |
|
| 28 | + * ExitModal constructor. |
|
| 29 | + * |
|
| 30 | + * @param Registry $assets_registry |
|
| 31 | + */ |
|
| 32 | + public function __construct(Registry $assets_registry) |
|
| 33 | + { |
|
| 34 | + $this->assets_registry = $assets_registry; |
|
| 35 | + add_action('in_admin_footer', array($this, 'modalContainer')); |
|
| 36 | + add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Callback on in_admin_footer that is used to output the exit modal container. |
|
| 42 | - */ |
|
| 43 | - public function modalContainer() |
|
| 44 | - { |
|
| 45 | - echo '<div id="ee-exit-survey-modal"></div>'; |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * Callback on in_admin_footer that is used to output the exit modal container. |
|
| 42 | + */ |
|
| 43 | + public function modalContainer() |
|
| 44 | + { |
|
| 45 | + echo '<div id="ee-exit-survey-modal"></div>'; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
| 51 | - * |
|
| 52 | - * @throws InvalidArgumentException |
|
| 53 | - */ |
|
| 54 | - public function enqueues() |
|
| 55 | - { |
|
| 56 | - $current_user = new WP_User(get_current_user_id()); |
|
| 57 | - $this->assets_registry->addData( |
|
| 58 | - 'exitModali18n', |
|
| 59 | - array( |
|
| 60 | - 'introText' => htmlspecialchars( |
|
| 61 | - __( |
|
| 62 | - 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
| 63 | - 'event_espresso' |
|
| 64 | - ), |
|
| 65 | - ENT_NOQUOTES |
|
| 66 | - ), |
|
| 67 | - 'doSurveyButtonText' => htmlspecialchars( |
|
| 68 | - __( |
|
| 69 | - 'Sure I\'ll help', |
|
| 70 | - 'event_espresso' |
|
| 71 | - ), |
|
| 72 | - ENT_NOQUOTES |
|
| 73 | - ), |
|
| 74 | - 'skipButtonText' => htmlspecialchars( |
|
| 75 | - __( |
|
| 76 | - 'Skip', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - ENT_NOQUOTES |
|
| 80 | - ) |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - $this->assets_registry->addData( |
|
| 84 | - 'exitModalInfo', |
|
| 85 | - array( |
|
| 86 | - 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
| 87 | - 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
| 88 | - 'website' => htmlspecialchars(site_url()), |
|
| 89 | - 'isModalActive' => $this->isModalActive() |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 49 | + /** |
|
| 50 | + * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
| 51 | + * |
|
| 52 | + * @throws InvalidArgumentException |
|
| 53 | + */ |
|
| 54 | + public function enqueues() |
|
| 55 | + { |
|
| 56 | + $current_user = new WP_User(get_current_user_id()); |
|
| 57 | + $this->assets_registry->addData( |
|
| 58 | + 'exitModali18n', |
|
| 59 | + array( |
|
| 60 | + 'introText' => htmlspecialchars( |
|
| 61 | + __( |
|
| 62 | + 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
| 63 | + 'event_espresso' |
|
| 64 | + ), |
|
| 65 | + ENT_NOQUOTES |
|
| 66 | + ), |
|
| 67 | + 'doSurveyButtonText' => htmlspecialchars( |
|
| 68 | + __( |
|
| 69 | + 'Sure I\'ll help', |
|
| 70 | + 'event_espresso' |
|
| 71 | + ), |
|
| 72 | + ENT_NOQUOTES |
|
| 73 | + ), |
|
| 74 | + 'skipButtonText' => htmlspecialchars( |
|
| 75 | + __( |
|
| 76 | + 'Skip', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + ENT_NOQUOTES |
|
| 80 | + ) |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + $this->assets_registry->addData( |
|
| 84 | + 'exitModalInfo', |
|
| 85 | + array( |
|
| 86 | + 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
| 87 | + 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
| 88 | + 'website' => htmlspecialchars(site_url()), |
|
| 89 | + 'isModalActive' => $this->isModalActive() |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | 92 | |
| 93 | - wp_enqueue_script('ee-wp-plugins-page'); |
|
| 94 | - wp_enqueue_style('ee-wp-plugins-page'); |
|
| 95 | - } |
|
| 93 | + wp_enqueue_script('ee-wp-plugins-page'); |
|
| 94 | + wp_enqueue_style('ee-wp-plugins-page'); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - private function isModalActive() |
|
| 103 | - { |
|
| 104 | - return filter_var( |
|
| 105 | - apply_filters( |
|
| 106 | - 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
| 107 | - true |
|
| 108 | - ), |
|
| 109 | - FILTER_VALIDATE_BOOLEAN |
|
| 110 | - ); |
|
| 111 | - } |
|
| 98 | + /** |
|
| 99 | + * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + private function isModalActive() |
|
| 103 | + { |
|
| 104 | + return filter_var( |
|
| 105 | + apply_filters( |
|
| 106 | + 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
| 107 | + true |
|
| 108 | + ), |
|
| 109 | + FILTER_VALIDATE_BOOLEAN |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | \ No newline at end of file |
@@ -473,7 +473,7 @@ |
||
| 473 | 473 | * |
| 474 | 474 | * @param EE_Ticket $ticket |
| 475 | 475 | * @param int $qty |
| 476 | - * @return TRUE on success, FALSE on fail |
|
| 476 | + * @return boolean on success, FALSE on fail |
|
| 477 | 477 | * @throws InvalidArgumentException |
| 478 | 478 | * @throws InvalidInterfaceException |
| 479 | 479 | * @throws InvalidDataTypeException |
@@ -34,526 +34,526 @@ |
||
| 34 | 34 | class ProcessTicketSelector |
| 35 | 35 | { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var EE_Cart $cart |
|
| 39 | - */ |
|
| 40 | - private $cart; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var EE_Core_Config $core_config |
|
| 44 | - */ |
|
| 45 | - private $core_config; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var Request $request |
|
| 49 | - */ |
|
| 50 | - private $request; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var EE_Session $session |
|
| 54 | - */ |
|
| 55 | - private $session; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var EEM_Ticket $ticket_model |
|
| 59 | - */ |
|
| 60 | - private $ticket_model; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var TicketDatetimeAvailabilityTracker $tracker |
|
| 64 | - */ |
|
| 65 | - private $tracker; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * ProcessTicketSelector constructor. |
|
| 70 | - * NOTE: PLZ use the Loader to instantiate this class if need be |
|
| 71 | - * so that all dependencies get injected correctly (which will happen automatically) |
|
| 72 | - * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
| 73 | - * |
|
| 74 | - * @param EE_Core_Config $core_config |
|
| 75 | - * @param Request $request |
|
| 76 | - * @param EE_Session $session |
|
| 77 | - * @param EEM_Ticket $ticket_model |
|
| 78 | - * @param TicketDatetimeAvailabilityTracker $tracker |
|
| 79 | - * @throws InvalidArgumentException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - public function __construct( |
|
| 84 | - EE_Core_Config $core_config = null, |
|
| 85 | - Request $request = null, |
|
| 86 | - EE_Session $session = null, |
|
| 87 | - EEM_Ticket $ticket_model = null, |
|
| 88 | - TicketDatetimeAvailabilityTracker $tracker = null |
|
| 89 | - ) { |
|
| 90 | - /** @var LoaderInterface $loader */ |
|
| 91 | - $loader = LoaderFactory::getLoader(); |
|
| 92 | - $this->core_config = $core_config instanceof EE_Core_Config |
|
| 93 | - ? $core_config |
|
| 94 | - : $loader->getShared('EE_Core_Config'); |
|
| 95 | - $this->request = $request instanceof Request |
|
| 96 | - ? $request |
|
| 97 | - : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 98 | - $this->session = $session instanceof EE_Session |
|
| 99 | - ? $session |
|
| 100 | - : $loader->getShared('EE_Session'); |
|
| 101 | - $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
| 102 | - ? $ticket_model |
|
| 103 | - : $loader->getShared('EEM_Ticket'); |
|
| 104 | - $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
| 105 | - ? $tracker |
|
| 106 | - : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * cancelTicketSelections |
|
| 112 | - * |
|
| 113 | - * @return bool |
|
| 114 | - * @throws EE_Error |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - * @throws InvalidInterfaceException |
|
| 117 | - * @throws InvalidDataTypeException |
|
| 118 | - */ |
|
| 119 | - public function cancelTicketSelections() |
|
| 120 | - { |
|
| 121 | - // check nonce |
|
| 122 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 123 | - return false; |
|
| 124 | - } |
|
| 125 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 126 | - if ($this->request->requestParamIsSet('event_id')) { |
|
| 127 | - EEH_URL::safeRedirectAndExit( |
|
| 128 | - EEH_Event_View::event_link_url( |
|
| 129 | - $this->request->getRequestParam('event_id') |
|
| 130 | - ) |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - EEH_URL::safeRedirectAndExit( |
|
| 134 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 135 | - ); |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * processTicketSelectorNonce |
|
| 142 | - * |
|
| 143 | - * @param string $nonce_name |
|
| 144 | - * @param string $id |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
| 148 | - { |
|
| 149 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
| 150 | - if ( |
|
| 151 | - ! $this->request->isAdmin() |
|
| 152 | - && ( |
|
| 153 | - ! $this->request->is_set($nonce_name_with_id) |
|
| 154 | - || ! wp_verify_nonce( |
|
| 155 | - $this->request->get($nonce_name_with_id), |
|
| 156 | - $nonce_name |
|
| 157 | - ) |
|
| 158 | - ) |
|
| 159 | - ) { |
|
| 160 | - EE_Error::add_error( |
|
| 161 | - sprintf( |
|
| 162 | - esc_html__( |
|
| 163 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 164 | - 'event_espresso' |
|
| 165 | - ), |
|
| 166 | - '<br/>' |
|
| 167 | - ), |
|
| 168 | - __FILE__, |
|
| 169 | - __FUNCTION__, |
|
| 170 | - __LINE__ |
|
| 171 | - ); |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - return true; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * process_ticket_selections |
|
| 180 | - * |
|
| 181 | - * @return array|bool |
|
| 182 | - * @throws EE_Error |
|
| 183 | - * @throws InvalidArgumentException |
|
| 184 | - * @throws InvalidDataTypeException |
|
| 185 | - * @throws InvalidInterfaceException |
|
| 186 | - */ |
|
| 187 | - public function processTicketSelections() |
|
| 188 | - { |
|
| 189 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 190 | - if($this->request->isBot()) { |
|
| 191 | - EEH_URL::safeRedirectAndExit( |
|
| 192 | - apply_filters( |
|
| 193 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
| 194 | - site_url() |
|
| 195 | - ) |
|
| 196 | - ); |
|
| 197 | - } |
|
| 198 | - // do we have an event id? |
|
| 199 | - $id = $this->getEventId(); |
|
| 200 | - // we should really only have 1 registration in the works now |
|
| 201 | - // (ie, no MER) so unless otherwise requested, clear the session |
|
| 202 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 203 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 204 | - } |
|
| 205 | - // validate/sanitize/filter data |
|
| 206 | - $valid = apply_filters( |
|
| 207 | - 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
| 208 | - $this->validatePostData($id) |
|
| 209 | - ); |
|
| 210 | - //check total tickets ordered vs max number of attendees that can register |
|
| 211 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 212 | - $this->maxAttendeesViolation($valid); |
|
| 213 | - } else { |
|
| 214 | - // all data appears to be valid |
|
| 215 | - if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
| 216 | - return true; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 220 | - // at this point, just return if registration is being made from admin |
|
| 221 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - if ($valid['return_url']) { |
|
| 225 | - EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
| 226 | - } |
|
| 227 | - if ($id) { |
|
| 228 | - EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
| 229 | - } |
|
| 230 | - echo EE_Error::get_notices(); |
|
| 231 | - return false; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @return int |
|
| 237 | - */ |
|
| 238 | - private function getEventId() |
|
| 239 | - { |
|
| 240 | - // do we have an event id? |
|
| 241 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
| 242 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 243 | - EE_Error::add_error( |
|
| 244 | - sprintf( |
|
| 245 | - esc_html__( |
|
| 246 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 247 | - 'event_espresso' |
|
| 248 | - ), |
|
| 249 | - '<br/>' |
|
| 250 | - ), |
|
| 251 | - __FILE__, |
|
| 252 | - __FUNCTION__, |
|
| 253 | - __LINE__ |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - //if event id is valid |
|
| 257 | - return absint($this->request->getRequestParam('tkt-slctr-event-id')); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * validate_post_data |
|
| 263 | - * |
|
| 264 | - * @param int $id |
|
| 265 | - * @return array|FALSE |
|
| 266 | - */ |
|
| 267 | - private function validatePostData($id = 0) |
|
| 268 | - { |
|
| 269 | - if (! $id) { |
|
| 270 | - EE_Error::add_error( |
|
| 271 | - esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
| 272 | - __FILE__, |
|
| 273 | - __FUNCTION__, |
|
| 274 | - __LINE__ |
|
| 275 | - ); |
|
| 276 | - return false; |
|
| 277 | - } |
|
| 278 | - // start with an empty array() |
|
| 279 | - $valid_data = array(); |
|
| 280 | - // grab valid id |
|
| 281 | - $valid_data['id'] = $id; |
|
| 282 | - // array of other form names |
|
| 283 | - $inputs_to_clean = array( |
|
| 284 | - 'event_id' => 'tkt-slctr-event-id', |
|
| 285 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 286 | - 'rows' => 'tkt-slctr-rows-', |
|
| 287 | - 'qty' => 'tkt-slctr-qty-', |
|
| 288 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 289 | - 'return_url' => 'tkt-slctr-return-url-', |
|
| 290 | - ); |
|
| 291 | - // let's track the total number of tickets ordered.' |
|
| 292 | - $valid_data['total_tickets'] = 0; |
|
| 293 | - // cycle through $inputs_to_clean array |
|
| 294 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 295 | - // check for POST data |
|
| 296 | - if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
| 297 | - // grab value |
|
| 298 | - $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
| 299 | - switch ($what) { |
|
| 300 | - // integers |
|
| 301 | - case 'event_id': |
|
| 302 | - $valid_data[ $what ] = absint($input_value); |
|
| 303 | - // get event via the event id we put in the form |
|
| 304 | - break; |
|
| 305 | - case 'rows': |
|
| 306 | - case 'max_atndz': |
|
| 307 | - $valid_data[ $what ] = absint($input_value); |
|
| 308 | - break; |
|
| 309 | - // arrays of integers |
|
| 310 | - case 'qty': |
|
| 311 | - /** @var array $row_qty */ |
|
| 312 | - $row_qty = $input_value; |
|
| 313 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 314 | - if (! is_array($row_qty)) { |
|
| 315 | - /** @var string $row_qty */ |
|
| 316 | - // get number of rows |
|
| 317 | - $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
| 318 | - ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
| 319 | - : 1; |
|
| 320 | - // explode integers by the dash |
|
| 321 | - $row_qty = explode('-', $row_qty); |
|
| 322 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
| 323 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 324 | - $row_qty = array($row => $qty); |
|
| 325 | - for ($x = 1; $x <= $rows; $x++) { |
|
| 326 | - if (! isset($row_qty[ $x ])) { |
|
| 327 | - $row_qty[ $x ] = 0; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - ksort($row_qty); |
|
| 332 | - // cycle thru values |
|
| 333 | - foreach ($row_qty as $qty) { |
|
| 334 | - $qty = absint($qty); |
|
| 335 | - // sanitize as integers |
|
| 336 | - $valid_data[ $what ][] = $qty; |
|
| 337 | - $valid_data['total_tickets'] += $qty; |
|
| 338 | - } |
|
| 339 | - break; |
|
| 340 | - // array of integers |
|
| 341 | - case 'ticket_id': |
|
| 342 | - // cycle thru values |
|
| 343 | - foreach ((array) $input_value as $key => $value) { |
|
| 344 | - // allow only integers |
|
| 345 | - $valid_data[ $what ][ $key ] = absint($value); |
|
| 346 | - } |
|
| 347 | - break; |
|
| 348 | - case 'return_url' : |
|
| 349 | - // grab and sanitize return-url |
|
| 350 | - $input_value = esc_url_raw($input_value); |
|
| 351 | - // was the request coming from an iframe ? if so, then: |
|
| 352 | - if (strpos($input_value, 'event_list=iframe')) { |
|
| 353 | - // get anchor fragment |
|
| 354 | - $input_value = explode('#', $input_value); |
|
| 355 | - $input_value = end($input_value); |
|
| 356 | - // use event list url instead, but append anchor |
|
| 357 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 358 | - } |
|
| 359 | - $valid_data[ $what ] = $input_value; |
|
| 360 | - break; |
|
| 361 | - } // end switch $what |
|
| 362 | - } |
|
| 363 | - } // end foreach $inputs_to_clean |
|
| 364 | - return $valid_data; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @param array $valid |
|
| 370 | - */ |
|
| 371 | - private function maxAttendeesViolation(array $valid) |
|
| 372 | - { |
|
| 373 | - // ordering too many tickets !!! |
|
| 374 | - $total_tickets_string = esc_html( |
|
| 375 | - _n( |
|
| 376 | - 'You have attempted to purchase %s ticket.', |
|
| 377 | - 'You have attempted to purchase %s tickets.', |
|
| 378 | - $valid['total_tickets'], |
|
| 379 | - 'event_espresso' |
|
| 380 | - ) |
|
| 381 | - ); |
|
| 382 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 383 | - // dev only message |
|
| 384 | - $max_attendees_string = esc_html( |
|
| 385 | - _n( |
|
| 386 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 387 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 388 | - $valid['max_atndz'], |
|
| 389 | - 'event_espresso' |
|
| 390 | - ) |
|
| 391 | - ); |
|
| 392 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 393 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @param array $valid |
|
| 399 | - * @return int|TRUE |
|
| 400 | - * @throws EE_Error |
|
| 401 | - * @throws InvalidArgumentException |
|
| 402 | - * @throws InvalidDataTypeException |
|
| 403 | - * @throws InvalidInterfaceException |
|
| 404 | - */ |
|
| 405 | - private function addTicketsToCart(array $valid) |
|
| 406 | - { |
|
| 407 | - $tickets_added = 0; |
|
| 408 | - $tickets_selected = false; |
|
| 409 | - if($valid['total_tickets'] > 0){ |
|
| 410 | - // load cart using factory because we don't want to do so until actually needed |
|
| 411 | - $this->cart = CartFactory::getCart(); |
|
| 412 | - // cycle thru the number of data rows sent from the event listing |
|
| 413 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 414 | - // does this row actually contain a ticket quantity? |
|
| 415 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
| 416 | - // YES we have a ticket quantity |
|
| 417 | - $tickets_selected = true; |
|
| 418 | - $valid_ticket = false; |
|
| 419 | - // \EEH_Debug_Tools::printr( |
|
| 420 | - // $valid['ticket_id'][ $x ], |
|
| 421 | - // '$valid[\'ticket_id\'][ $x ]', |
|
| 422 | - // __FILE__, __LINE__ |
|
| 423 | - // ); |
|
| 424 | - if (isset($valid['ticket_id'][ $x ])) { |
|
| 425 | - // get ticket via the ticket id we put in the form |
|
| 426 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
| 427 | - if ($ticket instanceof EE_Ticket) { |
|
| 428 | - $valid_ticket = true; |
|
| 429 | - $tickets_added += $this->addTicketToCart( |
|
| 430 | - $ticket, |
|
| 431 | - $valid['qty'][ $x ] |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - if ($valid_ticket !== true) { |
|
| 436 | - // nothing added to cart retrieved |
|
| 437 | - EE_Error::add_error( |
|
| 438 | - sprintf( |
|
| 439 | - esc_html__( |
|
| 440 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 441 | - 'event_espresso' |
|
| 442 | - ), |
|
| 443 | - '<br/>' |
|
| 444 | - ), |
|
| 445 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 446 | - ); |
|
| 447 | - } |
|
| 448 | - if (EE_Error::has_error()) { |
|
| 449 | - break; |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - do_action( |
|
| 455 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 456 | - $this->cart, |
|
| 457 | - $this |
|
| 458 | - ); |
|
| 459 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 460 | - // no ticket quantities were selected |
|
| 461 | - EE_Error::add_error( |
|
| 462 | - esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
| 463 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 464 | - ); |
|
| 465 | - } |
|
| 466 | - return $tickets_added; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * adds a ticket to the cart |
|
| 473 | - * |
|
| 474 | - * @param EE_Ticket $ticket |
|
| 475 | - * @param int $qty |
|
| 476 | - * @return TRUE on success, FALSE on fail |
|
| 477 | - * @throws InvalidArgumentException |
|
| 478 | - * @throws InvalidInterfaceException |
|
| 479 | - * @throws InvalidDataTypeException |
|
| 480 | - * @throws EE_Error |
|
| 481 | - */ |
|
| 482 | - private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
| 483 | - { |
|
| 484 | - // get the number of spaces left for this datetime ticket |
|
| 485 | - $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
| 486 | - // compare available spaces against the number of tickets being purchased |
|
| 487 | - if ($available_spaces >= $qty) { |
|
| 488 | - // allow addons to prevent a ticket from being added to cart |
|
| 489 | - if ( |
|
| 490 | - ! apply_filters( |
|
| 491 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 492 | - true, |
|
| 493 | - $ticket, |
|
| 494 | - $qty, |
|
| 495 | - $available_spaces |
|
| 496 | - ) |
|
| 497 | - ) { |
|
| 498 | - return false; |
|
| 499 | - } |
|
| 500 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 501 | - // add event to cart |
|
| 502 | - if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
| 503 | - $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 504 | - return true; |
|
| 505 | - } |
|
| 506 | - return false; |
|
| 507 | - } |
|
| 508 | - $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
| 509 | - return false; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * @param $tickets_added |
|
| 515 | - * @return bool |
|
| 516 | - * @throws InvalidInterfaceException |
|
| 517 | - * @throws InvalidDataTypeException |
|
| 518 | - * @throws EE_Error |
|
| 519 | - * @throws InvalidArgumentException |
|
| 520 | - */ |
|
| 521 | - private function processSuccessfulCart($tickets_added) |
|
| 522 | - { |
|
| 523 | - // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 524 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 525 | - // make sure cart is loaded |
|
| 526 | - if(! $this->cart instanceof EE_Cart){ |
|
| 527 | - $this->cart = CartFactory::getCart(); |
|
| 528 | - } |
|
| 529 | - do_action( |
|
| 530 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 531 | - $this->cart, |
|
| 532 | - $this |
|
| 533 | - ); |
|
| 534 | - $this->cart->recalculate_all_cart_totals(); |
|
| 535 | - $this->cart->save_cart(false); |
|
| 536 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 537 | - // just return TRUE for registrations being made from admin |
|
| 538 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 539 | - return true; |
|
| 540 | - } |
|
| 541 | - EEH_URL::safeRedirectAndExit( |
|
| 542 | - apply_filters( |
|
| 543 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 544 | - $this->core_config->reg_page_url() |
|
| 545 | - ) |
|
| 546 | - ); |
|
| 547 | - } |
|
| 548 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 549 | - // nothing added to cart |
|
| 550 | - EE_Error::add_attention( |
|
| 551 | - esc_html__('No tickets were added for the event', 'event_espresso'), |
|
| 552 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 553 | - ); |
|
| 554 | - } |
|
| 555 | - return false; |
|
| 556 | - } |
|
| 37 | + /** |
|
| 38 | + * @var EE_Cart $cart |
|
| 39 | + */ |
|
| 40 | + private $cart; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var EE_Core_Config $core_config |
|
| 44 | + */ |
|
| 45 | + private $core_config; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var Request $request |
|
| 49 | + */ |
|
| 50 | + private $request; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var EE_Session $session |
|
| 54 | + */ |
|
| 55 | + private $session; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var EEM_Ticket $ticket_model |
|
| 59 | + */ |
|
| 60 | + private $ticket_model; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var TicketDatetimeAvailabilityTracker $tracker |
|
| 64 | + */ |
|
| 65 | + private $tracker; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * ProcessTicketSelector constructor. |
|
| 70 | + * NOTE: PLZ use the Loader to instantiate this class if need be |
|
| 71 | + * so that all dependencies get injected correctly (which will happen automatically) |
|
| 72 | + * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
| 73 | + * |
|
| 74 | + * @param EE_Core_Config $core_config |
|
| 75 | + * @param Request $request |
|
| 76 | + * @param EE_Session $session |
|
| 77 | + * @param EEM_Ticket $ticket_model |
|
| 78 | + * @param TicketDatetimeAvailabilityTracker $tracker |
|
| 79 | + * @throws InvalidArgumentException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + public function __construct( |
|
| 84 | + EE_Core_Config $core_config = null, |
|
| 85 | + Request $request = null, |
|
| 86 | + EE_Session $session = null, |
|
| 87 | + EEM_Ticket $ticket_model = null, |
|
| 88 | + TicketDatetimeAvailabilityTracker $tracker = null |
|
| 89 | + ) { |
|
| 90 | + /** @var LoaderInterface $loader */ |
|
| 91 | + $loader = LoaderFactory::getLoader(); |
|
| 92 | + $this->core_config = $core_config instanceof EE_Core_Config |
|
| 93 | + ? $core_config |
|
| 94 | + : $loader->getShared('EE_Core_Config'); |
|
| 95 | + $this->request = $request instanceof Request |
|
| 96 | + ? $request |
|
| 97 | + : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 98 | + $this->session = $session instanceof EE_Session |
|
| 99 | + ? $session |
|
| 100 | + : $loader->getShared('EE_Session'); |
|
| 101 | + $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
| 102 | + ? $ticket_model |
|
| 103 | + : $loader->getShared('EEM_Ticket'); |
|
| 104 | + $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
| 105 | + ? $tracker |
|
| 106 | + : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * cancelTicketSelections |
|
| 112 | + * |
|
| 113 | + * @return bool |
|
| 114 | + * @throws EE_Error |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + * @throws InvalidInterfaceException |
|
| 117 | + * @throws InvalidDataTypeException |
|
| 118 | + */ |
|
| 119 | + public function cancelTicketSelections() |
|
| 120 | + { |
|
| 121 | + // check nonce |
|
| 122 | + if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 123 | + return false; |
|
| 124 | + } |
|
| 125 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 126 | + if ($this->request->requestParamIsSet('event_id')) { |
|
| 127 | + EEH_URL::safeRedirectAndExit( |
|
| 128 | + EEH_Event_View::event_link_url( |
|
| 129 | + $this->request->getRequestParam('event_id') |
|
| 130 | + ) |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + EEH_URL::safeRedirectAndExit( |
|
| 134 | + site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 135 | + ); |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * processTicketSelectorNonce |
|
| 142 | + * |
|
| 143 | + * @param string $nonce_name |
|
| 144 | + * @param string $id |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
| 148 | + { |
|
| 149 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
| 150 | + if ( |
|
| 151 | + ! $this->request->isAdmin() |
|
| 152 | + && ( |
|
| 153 | + ! $this->request->is_set($nonce_name_with_id) |
|
| 154 | + || ! wp_verify_nonce( |
|
| 155 | + $this->request->get($nonce_name_with_id), |
|
| 156 | + $nonce_name |
|
| 157 | + ) |
|
| 158 | + ) |
|
| 159 | + ) { |
|
| 160 | + EE_Error::add_error( |
|
| 161 | + sprintf( |
|
| 162 | + esc_html__( |
|
| 163 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 164 | + 'event_espresso' |
|
| 165 | + ), |
|
| 166 | + '<br/>' |
|
| 167 | + ), |
|
| 168 | + __FILE__, |
|
| 169 | + __FUNCTION__, |
|
| 170 | + __LINE__ |
|
| 171 | + ); |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + return true; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * process_ticket_selections |
|
| 180 | + * |
|
| 181 | + * @return array|bool |
|
| 182 | + * @throws EE_Error |
|
| 183 | + * @throws InvalidArgumentException |
|
| 184 | + * @throws InvalidDataTypeException |
|
| 185 | + * @throws InvalidInterfaceException |
|
| 186 | + */ |
|
| 187 | + public function processTicketSelections() |
|
| 188 | + { |
|
| 189 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 190 | + if($this->request->isBot()) { |
|
| 191 | + EEH_URL::safeRedirectAndExit( |
|
| 192 | + apply_filters( |
|
| 193 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
| 194 | + site_url() |
|
| 195 | + ) |
|
| 196 | + ); |
|
| 197 | + } |
|
| 198 | + // do we have an event id? |
|
| 199 | + $id = $this->getEventId(); |
|
| 200 | + // we should really only have 1 registration in the works now |
|
| 201 | + // (ie, no MER) so unless otherwise requested, clear the session |
|
| 202 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 203 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 204 | + } |
|
| 205 | + // validate/sanitize/filter data |
|
| 206 | + $valid = apply_filters( |
|
| 207 | + 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
| 208 | + $this->validatePostData($id) |
|
| 209 | + ); |
|
| 210 | + //check total tickets ordered vs max number of attendees that can register |
|
| 211 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 212 | + $this->maxAttendeesViolation($valid); |
|
| 213 | + } else { |
|
| 214 | + // all data appears to be valid |
|
| 215 | + if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
| 216 | + return true; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 220 | + // at this point, just return if registration is being made from admin |
|
| 221 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + if ($valid['return_url']) { |
|
| 225 | + EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
| 226 | + } |
|
| 227 | + if ($id) { |
|
| 228 | + EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
| 229 | + } |
|
| 230 | + echo EE_Error::get_notices(); |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @return int |
|
| 237 | + */ |
|
| 238 | + private function getEventId() |
|
| 239 | + { |
|
| 240 | + // do we have an event id? |
|
| 241 | + if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
| 242 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 243 | + EE_Error::add_error( |
|
| 244 | + sprintf( |
|
| 245 | + esc_html__( |
|
| 246 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 247 | + 'event_espresso' |
|
| 248 | + ), |
|
| 249 | + '<br/>' |
|
| 250 | + ), |
|
| 251 | + __FILE__, |
|
| 252 | + __FUNCTION__, |
|
| 253 | + __LINE__ |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + //if event id is valid |
|
| 257 | + return absint($this->request->getRequestParam('tkt-slctr-event-id')); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * validate_post_data |
|
| 263 | + * |
|
| 264 | + * @param int $id |
|
| 265 | + * @return array|FALSE |
|
| 266 | + */ |
|
| 267 | + private function validatePostData($id = 0) |
|
| 268 | + { |
|
| 269 | + if (! $id) { |
|
| 270 | + EE_Error::add_error( |
|
| 271 | + esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
| 272 | + __FILE__, |
|
| 273 | + __FUNCTION__, |
|
| 274 | + __LINE__ |
|
| 275 | + ); |
|
| 276 | + return false; |
|
| 277 | + } |
|
| 278 | + // start with an empty array() |
|
| 279 | + $valid_data = array(); |
|
| 280 | + // grab valid id |
|
| 281 | + $valid_data['id'] = $id; |
|
| 282 | + // array of other form names |
|
| 283 | + $inputs_to_clean = array( |
|
| 284 | + 'event_id' => 'tkt-slctr-event-id', |
|
| 285 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 286 | + 'rows' => 'tkt-slctr-rows-', |
|
| 287 | + 'qty' => 'tkt-slctr-qty-', |
|
| 288 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 289 | + 'return_url' => 'tkt-slctr-return-url-', |
|
| 290 | + ); |
|
| 291 | + // let's track the total number of tickets ordered.' |
|
| 292 | + $valid_data['total_tickets'] = 0; |
|
| 293 | + // cycle through $inputs_to_clean array |
|
| 294 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 295 | + // check for POST data |
|
| 296 | + if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
| 297 | + // grab value |
|
| 298 | + $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
| 299 | + switch ($what) { |
|
| 300 | + // integers |
|
| 301 | + case 'event_id': |
|
| 302 | + $valid_data[ $what ] = absint($input_value); |
|
| 303 | + // get event via the event id we put in the form |
|
| 304 | + break; |
|
| 305 | + case 'rows': |
|
| 306 | + case 'max_atndz': |
|
| 307 | + $valid_data[ $what ] = absint($input_value); |
|
| 308 | + break; |
|
| 309 | + // arrays of integers |
|
| 310 | + case 'qty': |
|
| 311 | + /** @var array $row_qty */ |
|
| 312 | + $row_qty = $input_value; |
|
| 313 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 314 | + if (! is_array($row_qty)) { |
|
| 315 | + /** @var string $row_qty */ |
|
| 316 | + // get number of rows |
|
| 317 | + $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
| 318 | + ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
| 319 | + : 1; |
|
| 320 | + // explode integers by the dash |
|
| 321 | + $row_qty = explode('-', $row_qty); |
|
| 322 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
| 323 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 324 | + $row_qty = array($row => $qty); |
|
| 325 | + for ($x = 1; $x <= $rows; $x++) { |
|
| 326 | + if (! isset($row_qty[ $x ])) { |
|
| 327 | + $row_qty[ $x ] = 0; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + ksort($row_qty); |
|
| 332 | + // cycle thru values |
|
| 333 | + foreach ($row_qty as $qty) { |
|
| 334 | + $qty = absint($qty); |
|
| 335 | + // sanitize as integers |
|
| 336 | + $valid_data[ $what ][] = $qty; |
|
| 337 | + $valid_data['total_tickets'] += $qty; |
|
| 338 | + } |
|
| 339 | + break; |
|
| 340 | + // array of integers |
|
| 341 | + case 'ticket_id': |
|
| 342 | + // cycle thru values |
|
| 343 | + foreach ((array) $input_value as $key => $value) { |
|
| 344 | + // allow only integers |
|
| 345 | + $valid_data[ $what ][ $key ] = absint($value); |
|
| 346 | + } |
|
| 347 | + break; |
|
| 348 | + case 'return_url' : |
|
| 349 | + // grab and sanitize return-url |
|
| 350 | + $input_value = esc_url_raw($input_value); |
|
| 351 | + // was the request coming from an iframe ? if so, then: |
|
| 352 | + if (strpos($input_value, 'event_list=iframe')) { |
|
| 353 | + // get anchor fragment |
|
| 354 | + $input_value = explode('#', $input_value); |
|
| 355 | + $input_value = end($input_value); |
|
| 356 | + // use event list url instead, but append anchor |
|
| 357 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 358 | + } |
|
| 359 | + $valid_data[ $what ] = $input_value; |
|
| 360 | + break; |
|
| 361 | + } // end switch $what |
|
| 362 | + } |
|
| 363 | + } // end foreach $inputs_to_clean |
|
| 364 | + return $valid_data; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @param array $valid |
|
| 370 | + */ |
|
| 371 | + private function maxAttendeesViolation(array $valid) |
|
| 372 | + { |
|
| 373 | + // ordering too many tickets !!! |
|
| 374 | + $total_tickets_string = esc_html( |
|
| 375 | + _n( |
|
| 376 | + 'You have attempted to purchase %s ticket.', |
|
| 377 | + 'You have attempted to purchase %s tickets.', |
|
| 378 | + $valid['total_tickets'], |
|
| 379 | + 'event_espresso' |
|
| 380 | + ) |
|
| 381 | + ); |
|
| 382 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 383 | + // dev only message |
|
| 384 | + $max_attendees_string = esc_html( |
|
| 385 | + _n( |
|
| 386 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 387 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 388 | + $valid['max_atndz'], |
|
| 389 | + 'event_espresso' |
|
| 390 | + ) |
|
| 391 | + ); |
|
| 392 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 393 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @param array $valid |
|
| 399 | + * @return int|TRUE |
|
| 400 | + * @throws EE_Error |
|
| 401 | + * @throws InvalidArgumentException |
|
| 402 | + * @throws InvalidDataTypeException |
|
| 403 | + * @throws InvalidInterfaceException |
|
| 404 | + */ |
|
| 405 | + private function addTicketsToCart(array $valid) |
|
| 406 | + { |
|
| 407 | + $tickets_added = 0; |
|
| 408 | + $tickets_selected = false; |
|
| 409 | + if($valid['total_tickets'] > 0){ |
|
| 410 | + // load cart using factory because we don't want to do so until actually needed |
|
| 411 | + $this->cart = CartFactory::getCart(); |
|
| 412 | + // cycle thru the number of data rows sent from the event listing |
|
| 413 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 414 | + // does this row actually contain a ticket quantity? |
|
| 415 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
| 416 | + // YES we have a ticket quantity |
|
| 417 | + $tickets_selected = true; |
|
| 418 | + $valid_ticket = false; |
|
| 419 | + // \EEH_Debug_Tools::printr( |
|
| 420 | + // $valid['ticket_id'][ $x ], |
|
| 421 | + // '$valid[\'ticket_id\'][ $x ]', |
|
| 422 | + // __FILE__, __LINE__ |
|
| 423 | + // ); |
|
| 424 | + if (isset($valid['ticket_id'][ $x ])) { |
|
| 425 | + // get ticket via the ticket id we put in the form |
|
| 426 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
| 427 | + if ($ticket instanceof EE_Ticket) { |
|
| 428 | + $valid_ticket = true; |
|
| 429 | + $tickets_added += $this->addTicketToCart( |
|
| 430 | + $ticket, |
|
| 431 | + $valid['qty'][ $x ] |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + if ($valid_ticket !== true) { |
|
| 436 | + // nothing added to cart retrieved |
|
| 437 | + EE_Error::add_error( |
|
| 438 | + sprintf( |
|
| 439 | + esc_html__( |
|
| 440 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 441 | + 'event_espresso' |
|
| 442 | + ), |
|
| 443 | + '<br/>' |
|
| 444 | + ), |
|
| 445 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 446 | + ); |
|
| 447 | + } |
|
| 448 | + if (EE_Error::has_error()) { |
|
| 449 | + break; |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + do_action( |
|
| 455 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 456 | + $this->cart, |
|
| 457 | + $this |
|
| 458 | + ); |
|
| 459 | + if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 460 | + // no ticket quantities were selected |
|
| 461 | + EE_Error::add_error( |
|
| 462 | + esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
| 463 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | + return $tickets_added; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * adds a ticket to the cart |
|
| 473 | + * |
|
| 474 | + * @param EE_Ticket $ticket |
|
| 475 | + * @param int $qty |
|
| 476 | + * @return TRUE on success, FALSE on fail |
|
| 477 | + * @throws InvalidArgumentException |
|
| 478 | + * @throws InvalidInterfaceException |
|
| 479 | + * @throws InvalidDataTypeException |
|
| 480 | + * @throws EE_Error |
|
| 481 | + */ |
|
| 482 | + private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
| 483 | + { |
|
| 484 | + // get the number of spaces left for this datetime ticket |
|
| 485 | + $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
| 486 | + // compare available spaces against the number of tickets being purchased |
|
| 487 | + if ($available_spaces >= $qty) { |
|
| 488 | + // allow addons to prevent a ticket from being added to cart |
|
| 489 | + if ( |
|
| 490 | + ! apply_filters( |
|
| 491 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 492 | + true, |
|
| 493 | + $ticket, |
|
| 494 | + $qty, |
|
| 495 | + $available_spaces |
|
| 496 | + ) |
|
| 497 | + ) { |
|
| 498 | + return false; |
|
| 499 | + } |
|
| 500 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 501 | + // add event to cart |
|
| 502 | + if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
| 503 | + $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 504 | + return true; |
|
| 505 | + } |
|
| 506 | + return false; |
|
| 507 | + } |
|
| 508 | + $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
| 509 | + return false; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * @param $tickets_added |
|
| 515 | + * @return bool |
|
| 516 | + * @throws InvalidInterfaceException |
|
| 517 | + * @throws InvalidDataTypeException |
|
| 518 | + * @throws EE_Error |
|
| 519 | + * @throws InvalidArgumentException |
|
| 520 | + */ |
|
| 521 | + private function processSuccessfulCart($tickets_added) |
|
| 522 | + { |
|
| 523 | + // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 524 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 525 | + // make sure cart is loaded |
|
| 526 | + if(! $this->cart instanceof EE_Cart){ |
|
| 527 | + $this->cart = CartFactory::getCart(); |
|
| 528 | + } |
|
| 529 | + do_action( |
|
| 530 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 531 | + $this->cart, |
|
| 532 | + $this |
|
| 533 | + ); |
|
| 534 | + $this->cart->recalculate_all_cart_totals(); |
|
| 535 | + $this->cart->save_cart(false); |
|
| 536 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 537 | + // just return TRUE for registrations being made from admin |
|
| 538 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 539 | + return true; |
|
| 540 | + } |
|
| 541 | + EEH_URL::safeRedirectAndExit( |
|
| 542 | + apply_filters( |
|
| 543 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 544 | + $this->core_config->reg_page_url() |
|
| 545 | + ) |
|
| 546 | + ); |
|
| 547 | + } |
|
| 548 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 549 | + // nothing added to cart |
|
| 550 | + EE_Error::add_attention( |
|
| 551 | + esc_html__('No tickets were added for the event', 'event_espresso'), |
|
| 552 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 553 | + ); |
|
| 554 | + } |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 557 | 557 | } |
| 558 | 558 | // End of file ProcessTicketSelector.php |
| 559 | 559 | // Location: /ProcessTicketSelector.php |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function cancelTicketSelections() |
| 120 | 120 | { |
| 121 | 121 | // check nonce |
| 122 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 122 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | $this->session->clear_session(__CLASS__, __FUNCTION__); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | ); |
| 132 | 132 | } |
| 133 | 133 | EEH_URL::safeRedirectAndExit( |
| 134 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 134 | + site_url('/'.$this->core_config->event_cpt_slug.'/') |
|
| 135 | 135 | ); |
| 136 | 136 | return true; |
| 137 | 137 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | public function processTicketSelections() |
| 188 | 188 | { |
| 189 | 189 | do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
| 190 | - if($this->request->isBot()) { |
|
| 190 | + if ($this->request->isBot()) { |
|
| 191 | 191 | EEH_URL::safeRedirectAndExit( |
| 192 | 192 | apply_filters( |
| 193 | 193 | 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | private function getEventId() |
| 239 | 239 | { |
| 240 | 240 | // do we have an event id? |
| 241 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
| 241 | + if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
| 242 | 242 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
| 243 | 243 | EE_Error::add_error( |
| 244 | 244 | sprintf( |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | private function validatePostData($id = 0) |
| 268 | 268 | { |
| 269 | - if (! $id) { |
|
| 269 | + if ( ! $id) { |
|
| 270 | 270 | EE_Error::add_error( |
| 271 | 271 | esc_html__('The event id provided was not valid.', 'event_espresso'), |
| 272 | 272 | __FILE__, |
@@ -293,29 +293,29 @@ discard block |
||
| 293 | 293 | // cycle through $inputs_to_clean array |
| 294 | 294 | foreach ($inputs_to_clean as $what => $input_to_clean) { |
| 295 | 295 | // check for POST data |
| 296 | - if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
| 296 | + if ($this->request->requestParamIsSet($input_to_clean.$id)) { |
|
| 297 | 297 | // grab value |
| 298 | - $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
| 298 | + $input_value = $this->request->getRequestParam($input_to_clean.$id); |
|
| 299 | 299 | switch ($what) { |
| 300 | 300 | // integers |
| 301 | 301 | case 'event_id': |
| 302 | - $valid_data[ $what ] = absint($input_value); |
|
| 302 | + $valid_data[$what] = absint($input_value); |
|
| 303 | 303 | // get event via the event id we put in the form |
| 304 | 304 | break; |
| 305 | 305 | case 'rows': |
| 306 | 306 | case 'max_atndz': |
| 307 | - $valid_data[ $what ] = absint($input_value); |
|
| 307 | + $valid_data[$what] = absint($input_value); |
|
| 308 | 308 | break; |
| 309 | 309 | // arrays of integers |
| 310 | 310 | case 'qty': |
| 311 | 311 | /** @var array $row_qty */ |
| 312 | 312 | $row_qty = $input_value; |
| 313 | 313 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
| 314 | - if (! is_array($row_qty)) { |
|
| 314 | + if ( ! is_array($row_qty)) { |
|
| 315 | 315 | /** @var string $row_qty */ |
| 316 | 316 | // get number of rows |
| 317 | - $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
| 318 | - ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
| 317 | + $rows = $this->request->requestParamIsSet('tkt-slctr-rows-'.$id) |
|
| 318 | + ? absint($this->request->getRequestParam('tkt-slctr-rows-'.$id)) |
|
| 319 | 319 | : 1; |
| 320 | 320 | // explode integers by the dash |
| 321 | 321 | $row_qty = explode('-', $row_qty); |
@@ -323,8 +323,8 @@ discard block |
||
| 323 | 323 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
| 324 | 324 | $row_qty = array($row => $qty); |
| 325 | 325 | for ($x = 1; $x <= $rows; $x++) { |
| 326 | - if (! isset($row_qty[ $x ])) { |
|
| 327 | - $row_qty[ $x ] = 0; |
|
| 326 | + if ( ! isset($row_qty[$x])) { |
|
| 327 | + $row_qty[$x] = 0; |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | foreach ($row_qty as $qty) { |
| 334 | 334 | $qty = absint($qty); |
| 335 | 335 | // sanitize as integers |
| 336 | - $valid_data[ $what ][] = $qty; |
|
| 336 | + $valid_data[$what][] = $qty; |
|
| 337 | 337 | $valid_data['total_tickets'] += $qty; |
| 338 | 338 | } |
| 339 | 339 | break; |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | // cycle thru values |
| 343 | 343 | foreach ((array) $input_value as $key => $value) { |
| 344 | 344 | // allow only integers |
| 345 | - $valid_data[ $what ][ $key ] = absint($value); |
|
| 345 | + $valid_data[$what][$key] = absint($value); |
|
| 346 | 346 | } |
| 347 | 347 | break; |
| 348 | 348 | case 'return_url' : |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | $input_value = explode('#', $input_value); |
| 355 | 355 | $input_value = end($input_value); |
| 356 | 356 | // use event list url instead, but append anchor |
| 357 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 357 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
| 358 | 358 | } |
| 359 | - $valid_data[ $what ] = $input_value; |
|
| 359 | + $valid_data[$what] = $input_value; |
|
| 360 | 360 | break; |
| 361 | 361 | } // end switch $what |
| 362 | 362 | } |
@@ -389,8 +389,8 @@ discard block |
||
| 389 | 389 | 'event_espresso' |
| 390 | 390 | ) |
| 391 | 391 | ); |
| 392 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 393 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 392 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 393 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
@@ -406,13 +406,13 @@ discard block |
||
| 406 | 406 | { |
| 407 | 407 | $tickets_added = 0; |
| 408 | 408 | $tickets_selected = false; |
| 409 | - if($valid['total_tickets'] > 0){ |
|
| 409 | + if ($valid['total_tickets'] > 0) { |
|
| 410 | 410 | // load cart using factory because we don't want to do so until actually needed |
| 411 | 411 | $this->cart = CartFactory::getCart(); |
| 412 | 412 | // cycle thru the number of data rows sent from the event listing |
| 413 | 413 | for ($x = 0; $x < $valid['rows']; $x++) { |
| 414 | 414 | // does this row actually contain a ticket quantity? |
| 415 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
| 415 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
| 416 | 416 | // YES we have a ticket quantity |
| 417 | 417 | $tickets_selected = true; |
| 418 | 418 | $valid_ticket = false; |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | // '$valid[\'ticket_id\'][ $x ]', |
| 422 | 422 | // __FILE__, __LINE__ |
| 423 | 423 | // ); |
| 424 | - if (isset($valid['ticket_id'][ $x ])) { |
|
| 424 | + if (isset($valid['ticket_id'][$x])) { |
|
| 425 | 425 | // get ticket via the ticket id we put in the form |
| 426 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
| 426 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]); |
|
| 427 | 427 | if ($ticket instanceof EE_Ticket) { |
| 428 | - $valid_ticket = true; |
|
| 428 | + $valid_ticket = true; |
|
| 429 | 429 | $tickets_added += $this->addTicketToCart( |
| 430 | 430 | $ticket, |
| 431 | - $valid['qty'][ $x ] |
|
| 431 | + $valid['qty'][$x] |
|
| 432 | 432 | ); |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | $this->cart, |
| 457 | 457 | $this |
| 458 | 458 | ); |
| 459 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 459 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 460 | 460 | // no ticket quantities were selected |
| 461 | 461 | EE_Error::add_error( |
| 462 | 462 | esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
| 524 | 524 | if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
| 525 | 525 | // make sure cart is loaded |
| 526 | - if(! $this->cart instanceof EE_Cart){ |
|
| 526 | + if ( ! $this->cart instanceof EE_Cart) { |
|
| 527 | 527 | $this->cart = CartFactory::getCart(); |
| 528 | 528 | } |
| 529 | 529 | do_action( |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | ) |
| 546 | 546 | ); |
| 547 | 547 | } |
| 548 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 548 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 549 | 549 | // nothing added to cart |
| 550 | 550 | EE_Error::add_attention( |
| 551 | 551 | esc_html__('No tickets were added for the event', 'event_espresso'), |
@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | // if you're a dev and want to receive all errors via email |
| 12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
| 13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
| 14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
| 15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
| 14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
| 15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | |
@@ -27,258 +27,258 @@ discard block |
||
| 27 | 27 | class EE_Error extends Exception |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * name of the file to log exceptions to |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * stores details for all exception |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - private static $_all_exceptions = array(); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * tracks number of errors |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - private static $_error_count = 0; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var array $_espresso_notices |
|
| 56 | - */ |
|
| 57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @override default exception handling |
|
| 63 | - * @param string $message |
|
| 64 | - * @param int $code |
|
| 65 | - * @param Exception|null $previous |
|
| 66 | - */ |
|
| 67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
| 68 | - { |
|
| 69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 70 | - parent::__construct($message, $code); |
|
| 71 | - } else { |
|
| 72 | - parent::__construct($message, $code, $previous); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * error_handler |
|
| 79 | - * |
|
| 80 | - * @param $code |
|
| 81 | - * @param $message |
|
| 82 | - * @param $file |
|
| 83 | - * @param $line |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public static function error_handler($code, $message, $file, $line) |
|
| 87 | - { |
|
| 88 | - $type = EE_Error::error_type($code); |
|
| 89 | - $site = site_url(); |
|
| 90 | - switch ($site) { |
|
| 91 | - case 'http://ee4.eventespresso.com/' : |
|
| 92 | - case 'http://ee4decaf.eventespresso.com/' : |
|
| 93 | - case 'http://ee4hf.eventespresso.com/' : |
|
| 94 | - case 'http://ee4a.eventespresso.com/' : |
|
| 95 | - case 'http://ee4ad.eventespresso.com/' : |
|
| 96 | - case 'http://ee4b.eventespresso.com/' : |
|
| 97 | - case 'http://ee4bd.eventespresso.com/' : |
|
| 98 | - case 'http://ee4d.eventespresso.com/' : |
|
| 99 | - case 'http://ee4dd.eventespresso.com/' : |
|
| 100 | - $to = '[email protected]'; |
|
| 101 | - break; |
|
| 102 | - default : |
|
| 103 | - $to = get_option('admin_email'); |
|
| 104 | - } |
|
| 105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 106 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
| 107 | - if (function_exists('wp_mail')) { |
|
| 108 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 109 | - wp_mail($to, $subject, $msg); |
|
| 110 | - } |
|
| 111 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
| 112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 113 | - echo '<br /></p></div>'; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * error_type |
|
| 120 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
| 121 | - * |
|
| 122 | - * @param $code |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public static function error_type($code) |
|
| 126 | - { |
|
| 127 | - switch ($code) { |
|
| 128 | - case E_ERROR: // 1 // |
|
| 129 | - return 'E_ERROR'; |
|
| 130 | - case E_WARNING: // 2 // |
|
| 131 | - return 'E_WARNING'; |
|
| 132 | - case E_PARSE: // 4 // |
|
| 133 | - return 'E_PARSE'; |
|
| 134 | - case E_NOTICE: // 8 // |
|
| 135 | - return 'E_NOTICE'; |
|
| 136 | - case E_CORE_ERROR: // 16 // |
|
| 137 | - return 'E_CORE_ERROR'; |
|
| 138 | - case E_CORE_WARNING: // 32 // |
|
| 139 | - return 'E_CORE_WARNING'; |
|
| 140 | - case E_COMPILE_ERROR: // 64 // |
|
| 141 | - return 'E_COMPILE_ERROR'; |
|
| 142 | - case E_COMPILE_WARNING: // 128 // |
|
| 143 | - return 'E_COMPILE_WARNING'; |
|
| 144 | - case E_USER_ERROR: // 256 // |
|
| 145 | - return 'E_USER_ERROR'; |
|
| 146 | - case E_USER_WARNING: // 512 // |
|
| 147 | - return 'E_USER_WARNING'; |
|
| 148 | - case E_USER_NOTICE: // 1024 // |
|
| 149 | - return 'E_USER_NOTICE'; |
|
| 150 | - case E_STRICT: // 2048 // |
|
| 151 | - return 'E_STRICT'; |
|
| 152 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
| 153 | - return 'E_RECOVERABLE_ERROR'; |
|
| 154 | - case E_DEPRECATED: // 8192 // |
|
| 155 | - return 'E_DEPRECATED'; |
|
| 156 | - case E_USER_DEPRECATED: // 16384 // |
|
| 157 | - return 'E_USER_DEPRECATED'; |
|
| 158 | - case E_ALL: // 16384 // |
|
| 159 | - return 'E_ALL'; |
|
| 160 | - } |
|
| 161 | - return ''; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * fatal_error_handler |
|
| 168 | - * |
|
| 169 | - * @return void |
|
| 170 | - */ |
|
| 171 | - public static function fatal_error_handler() |
|
| 172 | - { |
|
| 173 | - $last_error = error_get_last(); |
|
| 174 | - if ($last_error['type'] === E_ERROR) { |
|
| 175 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * _format_error |
|
| 183 | - * |
|
| 184 | - * @param $code |
|
| 185 | - * @param $message |
|
| 186 | - * @param $file |
|
| 187 | - * @param $line |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - private static function _format_error($code, $message, $file, $line) |
|
| 191 | - { |
|
| 192 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
| 193 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
| 194 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
| 195 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
| 196 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
| 197 | - $html .= '</tbody></table>'; |
|
| 198 | - return $html; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * set_content_type |
|
| 205 | - * |
|
| 206 | - * @param $content_type |
|
| 207 | - * @return string |
|
| 208 | - */ |
|
| 209 | - public static function set_content_type($content_type) |
|
| 210 | - { |
|
| 211 | - return 'text/html'; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @return void |
|
| 218 | - * @throws EE_Error |
|
| 219 | - * @throws ReflectionException |
|
| 220 | - */ |
|
| 221 | - public function get_error() |
|
| 222 | - { |
|
| 223 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
| 224 | - throw $this; |
|
| 225 | - } |
|
| 226 | - // get separate user and developer messages if they exist |
|
| 227 | - $msg = explode('||', $this->getMessage()); |
|
| 228 | - $user_msg = $msg[0]; |
|
| 229 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 230 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 231 | - // add details to _all_exceptions array |
|
| 232 | - $x_time = time(); |
|
| 233 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
| 234 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
| 235 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
| 236 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
| 237 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
| 238 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
| 239 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
| 240 | - self::$_error_count++; |
|
| 241 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
| 242 | - $this->display_errors(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param bool $check_stored |
|
| 248 | - * @param string $type_to_check |
|
| 249 | - * @return bool |
|
| 250 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 251 | - * @throws \InvalidArgumentException |
|
| 252 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 253 | - * @throws InvalidInterfaceException |
|
| 254 | - */ |
|
| 255 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
| 256 | - { |
|
| 257 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
| 258 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
| 259 | - ? true |
|
| 260 | - : false; |
|
| 261 | - if ($check_stored && ! $has_error) { |
|
| 262 | - $notices = EE_Error::getStoredNotices(); |
|
| 263 | - foreach ($notices as $type => $notice) { |
|
| 264 | - if ($type === $type_to_check && $notice) { |
|
| 265 | - return true; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - return $has_error; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @echo string |
|
| 276 | - * @throws \ReflectionException |
|
| 277 | - */ |
|
| 278 | - public function display_errors() |
|
| 279 | - { |
|
| 280 | - $trace_details = ''; |
|
| 281 | - $output = ' |
|
| 30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * name of the file to log exceptions to |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * stores details for all exception |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + private static $_all_exceptions = array(); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * tracks number of errors |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + private static $_error_count = 0; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var array $_espresso_notices |
|
| 56 | + */ |
|
| 57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @override default exception handling |
|
| 63 | + * @param string $message |
|
| 64 | + * @param int $code |
|
| 65 | + * @param Exception|null $previous |
|
| 66 | + */ |
|
| 67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
| 68 | + { |
|
| 69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 70 | + parent::__construct($message, $code); |
|
| 71 | + } else { |
|
| 72 | + parent::__construct($message, $code, $previous); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * error_handler |
|
| 79 | + * |
|
| 80 | + * @param $code |
|
| 81 | + * @param $message |
|
| 82 | + * @param $file |
|
| 83 | + * @param $line |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public static function error_handler($code, $message, $file, $line) |
|
| 87 | + { |
|
| 88 | + $type = EE_Error::error_type($code); |
|
| 89 | + $site = site_url(); |
|
| 90 | + switch ($site) { |
|
| 91 | + case 'http://ee4.eventespresso.com/' : |
|
| 92 | + case 'http://ee4decaf.eventespresso.com/' : |
|
| 93 | + case 'http://ee4hf.eventespresso.com/' : |
|
| 94 | + case 'http://ee4a.eventespresso.com/' : |
|
| 95 | + case 'http://ee4ad.eventespresso.com/' : |
|
| 96 | + case 'http://ee4b.eventespresso.com/' : |
|
| 97 | + case 'http://ee4bd.eventespresso.com/' : |
|
| 98 | + case 'http://ee4d.eventespresso.com/' : |
|
| 99 | + case 'http://ee4dd.eventespresso.com/' : |
|
| 100 | + $to = '[email protected]'; |
|
| 101 | + break; |
|
| 102 | + default : |
|
| 103 | + $to = get_option('admin_email'); |
|
| 104 | + } |
|
| 105 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 106 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
| 107 | + if (function_exists('wp_mail')) { |
|
| 108 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 109 | + wp_mail($to, $subject, $msg); |
|
| 110 | + } |
|
| 111 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
| 112 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 113 | + echo '<br /></p></div>'; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * error_type |
|
| 120 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
| 121 | + * |
|
| 122 | + * @param $code |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public static function error_type($code) |
|
| 126 | + { |
|
| 127 | + switch ($code) { |
|
| 128 | + case E_ERROR: // 1 // |
|
| 129 | + return 'E_ERROR'; |
|
| 130 | + case E_WARNING: // 2 // |
|
| 131 | + return 'E_WARNING'; |
|
| 132 | + case E_PARSE: // 4 // |
|
| 133 | + return 'E_PARSE'; |
|
| 134 | + case E_NOTICE: // 8 // |
|
| 135 | + return 'E_NOTICE'; |
|
| 136 | + case E_CORE_ERROR: // 16 // |
|
| 137 | + return 'E_CORE_ERROR'; |
|
| 138 | + case E_CORE_WARNING: // 32 // |
|
| 139 | + return 'E_CORE_WARNING'; |
|
| 140 | + case E_COMPILE_ERROR: // 64 // |
|
| 141 | + return 'E_COMPILE_ERROR'; |
|
| 142 | + case E_COMPILE_WARNING: // 128 // |
|
| 143 | + return 'E_COMPILE_WARNING'; |
|
| 144 | + case E_USER_ERROR: // 256 // |
|
| 145 | + return 'E_USER_ERROR'; |
|
| 146 | + case E_USER_WARNING: // 512 // |
|
| 147 | + return 'E_USER_WARNING'; |
|
| 148 | + case E_USER_NOTICE: // 1024 // |
|
| 149 | + return 'E_USER_NOTICE'; |
|
| 150 | + case E_STRICT: // 2048 // |
|
| 151 | + return 'E_STRICT'; |
|
| 152 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
| 153 | + return 'E_RECOVERABLE_ERROR'; |
|
| 154 | + case E_DEPRECATED: // 8192 // |
|
| 155 | + return 'E_DEPRECATED'; |
|
| 156 | + case E_USER_DEPRECATED: // 16384 // |
|
| 157 | + return 'E_USER_DEPRECATED'; |
|
| 158 | + case E_ALL: // 16384 // |
|
| 159 | + return 'E_ALL'; |
|
| 160 | + } |
|
| 161 | + return ''; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * fatal_error_handler |
|
| 168 | + * |
|
| 169 | + * @return void |
|
| 170 | + */ |
|
| 171 | + public static function fatal_error_handler() |
|
| 172 | + { |
|
| 173 | + $last_error = error_get_last(); |
|
| 174 | + if ($last_error['type'] === E_ERROR) { |
|
| 175 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * _format_error |
|
| 183 | + * |
|
| 184 | + * @param $code |
|
| 185 | + * @param $message |
|
| 186 | + * @param $file |
|
| 187 | + * @param $line |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + private static function _format_error($code, $message, $file, $line) |
|
| 191 | + { |
|
| 192 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
| 193 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
| 194 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
| 195 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
| 196 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
| 197 | + $html .= '</tbody></table>'; |
|
| 198 | + return $html; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * set_content_type |
|
| 205 | + * |
|
| 206 | + * @param $content_type |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 209 | + public static function set_content_type($content_type) |
|
| 210 | + { |
|
| 211 | + return 'text/html'; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @return void |
|
| 218 | + * @throws EE_Error |
|
| 219 | + * @throws ReflectionException |
|
| 220 | + */ |
|
| 221 | + public function get_error() |
|
| 222 | + { |
|
| 223 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
| 224 | + throw $this; |
|
| 225 | + } |
|
| 226 | + // get separate user and developer messages if they exist |
|
| 227 | + $msg = explode('||', $this->getMessage()); |
|
| 228 | + $user_msg = $msg[0]; |
|
| 229 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 230 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 231 | + // add details to _all_exceptions array |
|
| 232 | + $x_time = time(); |
|
| 233 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
| 234 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
| 235 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
| 236 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
| 237 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
| 238 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
| 239 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
| 240 | + self::$_error_count++; |
|
| 241 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
| 242 | + $this->display_errors(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param bool $check_stored |
|
| 248 | + * @param string $type_to_check |
|
| 249 | + * @return bool |
|
| 250 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 251 | + * @throws \InvalidArgumentException |
|
| 252 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 253 | + * @throws InvalidInterfaceException |
|
| 254 | + */ |
|
| 255 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
| 256 | + { |
|
| 257 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
| 258 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
| 259 | + ? true |
|
| 260 | + : false; |
|
| 261 | + if ($check_stored && ! $has_error) { |
|
| 262 | + $notices = EE_Error::getStoredNotices(); |
|
| 263 | + foreach ($notices as $type => $notice) { |
|
| 264 | + if ($type === $type_to_check && $notice) { |
|
| 265 | + return true; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + return $has_error; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @echo string |
|
| 276 | + * @throws \ReflectionException |
|
| 277 | + */ |
|
| 278 | + public function display_errors() |
|
| 279 | + { |
|
| 280 | + $trace_details = ''; |
|
| 281 | + $output = ' |
|
| 282 | 282 | <style type="text/css"> |
| 283 | 283 | #ee-error-message { |
| 284 | 284 | max-width:90% !important; |
@@ -334,21 +334,21 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | </style> |
| 336 | 336 | <div id="ee-error-message" class="error">'; |
| 337 | - if (! WP_DEBUG) { |
|
| 338 | - $output .= ' |
|
| 337 | + if (! WP_DEBUG) { |
|
| 338 | + $output .= ' |
|
| 339 | 339 | <p>'; |
| 340 | - } |
|
| 341 | - // cycle thru errors |
|
| 342 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
| 343 | - $error_code = ''; |
|
| 344 | - // process trace info |
|
| 345 | - if (empty($ex['trace'])) { |
|
| 346 | - $trace_details .= __( |
|
| 347 | - 'Sorry, but no trace information was available for this exception.', |
|
| 348 | - 'event_espresso' |
|
| 349 | - ); |
|
| 350 | - } else { |
|
| 351 | - $trace_details .= ' |
|
| 340 | + } |
|
| 341 | + // cycle thru errors |
|
| 342 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
| 343 | + $error_code = ''; |
|
| 344 | + // process trace info |
|
| 345 | + if (empty($ex['trace'])) { |
|
| 346 | + $trace_details .= __( |
|
| 347 | + 'Sorry, but no trace information was available for this exception.', |
|
| 348 | + 'event_espresso' |
|
| 349 | + ); |
|
| 350 | + } else { |
|
| 351 | + $trace_details .= ' |
|
| 352 | 352 | <div id="ee-trace-details"> |
| 353 | 353 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
| 354 | 354 | <tr> |
@@ -358,43 +358,43 @@ discard block |
||
| 358 | 358 | <th scope="col" align="left">Class</th> |
| 359 | 359 | <th scope="col" align="left">Method( arguments )</th> |
| 360 | 360 | </tr>'; |
| 361 | - $last_on_stack = count($ex['trace']) - 1; |
|
| 362 | - // reverse array so that stack is in proper chronological order |
|
| 363 | - $sorted_trace = array_reverse($ex['trace']); |
|
| 364 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
| 365 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 366 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
| 367 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 368 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 369 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 370 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 371 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
| 372 | - if (empty($file) && ! empty($class)) { |
|
| 373 | - $a = new ReflectionClass($class); |
|
| 374 | - $file = $a->getFileName(); |
|
| 375 | - if (empty($line) && ! empty($function)) { |
|
| 376 | - try { |
|
| 377 | - //if $function is a closure, this throws an exception |
|
| 378 | - $b = new ReflectionMethod($class, $function); |
|
| 379 | - $line = $b->getStartLine(); |
|
| 380 | - } catch (Exception $closure_exception) { |
|
| 381 | - $line = 'unknown'; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - if ($nmbr === $last_on_stack) { |
|
| 386 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
| 387 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
| 388 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
| 389 | - } |
|
| 390 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
| 391 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
| 392 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
| 393 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
| 394 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
| 395 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
| 396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 397 | - $trace_details .= ' |
|
| 361 | + $last_on_stack = count($ex['trace']) - 1; |
|
| 362 | + // reverse array so that stack is in proper chronological order |
|
| 363 | + $sorted_trace = array_reverse($ex['trace']); |
|
| 364 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
| 365 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 366 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
| 367 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 368 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 369 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 370 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 371 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
| 372 | + if (empty($file) && ! empty($class)) { |
|
| 373 | + $a = new ReflectionClass($class); |
|
| 374 | + $file = $a->getFileName(); |
|
| 375 | + if (empty($line) && ! empty($function)) { |
|
| 376 | + try { |
|
| 377 | + //if $function is a closure, this throws an exception |
|
| 378 | + $b = new ReflectionMethod($class, $function); |
|
| 379 | + $line = $b->getStartLine(); |
|
| 380 | + } catch (Exception $closure_exception) { |
|
| 381 | + $line = 'unknown'; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + if ($nmbr === $last_on_stack) { |
|
| 386 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
| 387 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
| 388 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
| 389 | + } |
|
| 390 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
| 391 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
| 392 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
| 393 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
| 394 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
| 395 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
| 396 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 397 | + $trace_details .= ' |
|
| 398 | 398 | <tr> |
| 399 | 399 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
| 400 | 400 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -402,633 +402,633 @@ discard block |
||
| 402 | 402 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
| 403 | 403 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
| 404 | 404 | </tr>'; |
| 405 | - } |
|
| 406 | - $trace_details .= ' |
|
| 405 | + } |
|
| 406 | + $trace_details .= ' |
|
| 407 | 407 | </table> |
| 408 | 408 | </div>'; |
| 409 | - } |
|
| 410 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
| 411 | - // add generic non-identifying messages for non-privileged users |
|
| 412 | - if (! WP_DEBUG) { |
|
| 413 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
| 414 | - . trim($ex['msg']) |
|
| 415 | - . '</span> <sup>' |
|
| 416 | - . $ex['code'] |
|
| 417 | - . '</sup><br />'; |
|
| 418 | - } else { |
|
| 419 | - // or helpful developer messages if debugging is on |
|
| 420 | - $output .= ' |
|
| 409 | + } |
|
| 410 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
| 411 | + // add generic non-identifying messages for non-privileged users |
|
| 412 | + if (! WP_DEBUG) { |
|
| 413 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
| 414 | + . trim($ex['msg']) |
|
| 415 | + . '</span> <sup>' |
|
| 416 | + . $ex['code'] |
|
| 417 | + . '</sup><br />'; |
|
| 418 | + } else { |
|
| 419 | + // or helpful developer messages if debugging is on |
|
| 420 | + $output .= ' |
|
| 421 | 421 | <div class="ee-error-dev-msg-dv"> |
| 422 | 422 | <p class="ee-error-dev-msg-pg"> |
| 423 | 423 | <strong class="ee-error-dev-msg-str">An ' |
| 424 | - . $ex['name'] |
|
| 425 | - . ' exception was thrown!</strong> <span>code: ' |
|
| 426 | - . $ex['code'] |
|
| 427 | - . '</span><br /> |
|
| 424 | + . $ex['name'] |
|
| 425 | + . ' exception was thrown!</strong> <span>code: ' |
|
| 426 | + . $ex['code'] |
|
| 427 | + . '</span><br /> |
|
| 428 | 428 | <span class="big-text">"' |
| 429 | - . trim($ex['msg']) |
|
| 430 | - . '"</span><br/> |
|
| 429 | + . trim($ex['msg']) |
|
| 430 | + . '"</span><br/> |
|
| 431 | 431 | <a id="display-ee-error-trace-' |
| 432 | - . self::$_error_count |
|
| 433 | - . $time |
|
| 434 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
| 435 | - . self::$_error_count |
|
| 436 | - . $time |
|
| 437 | - . '"> |
|
| 432 | + . self::$_error_count |
|
| 433 | + . $time |
|
| 434 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
| 435 | + . self::$_error_count |
|
| 436 | + . $time |
|
| 437 | + . '"> |
|
| 438 | 438 | ' |
| 439 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
| 440 | - . ' |
|
| 439 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
| 440 | + . ' |
|
| 441 | 441 | </a><br /> |
| 442 | 442 | <span class="small-text lt-grey-text">' |
| 443 | - . $ex['file'] |
|
| 444 | - . ' ( line no: ' |
|
| 445 | - . $ex['line'] |
|
| 446 | - . ' )</span> |
|
| 443 | + . $ex['file'] |
|
| 444 | + . ' ( line no: ' |
|
| 445 | + . $ex['line'] |
|
| 446 | + . ' )</span> |
|
| 447 | 447 | </p> |
| 448 | 448 | <div id="ee-error-trace-' |
| 449 | - . self::$_error_count |
|
| 450 | - . $time |
|
| 451 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 449 | + . self::$_error_count |
|
| 450 | + . $time |
|
| 451 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 452 | 452 | ' |
| 453 | - . $trace_details; |
|
| 454 | - if (! empty($class)) { |
|
| 455 | - $output .= ' |
|
| 453 | + . $trace_details; |
|
| 454 | + if (! empty($class)) { |
|
| 455 | + $output .= ' |
|
| 456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
| 457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
| 458 | 458 | <h3>Class Details</h3>'; |
| 459 | - $a = new ReflectionClass($class); |
|
| 460 | - $output .= ' |
|
| 459 | + $a = new ReflectionClass($class); |
|
| 460 | + $output .= ' |
|
| 461 | 461 | <pre>' . $a . '</pre> |
| 462 | 462 | </div> |
| 463 | 463 | </div>'; |
| 464 | - } |
|
| 465 | - $output .= ' |
|
| 464 | + } |
|
| 465 | + $output .= ' |
|
| 466 | 466 | </div> |
| 467 | 467 | </div> |
| 468 | 468 | <br />'; |
| 469 | - } |
|
| 470 | - $this->write_to_error_log($time, $ex); |
|
| 471 | - } |
|
| 472 | - // remove last linebreak |
|
| 473 | - $output = substr($output, 0, -6); |
|
| 474 | - if (! WP_DEBUG) { |
|
| 475 | - $output .= ' |
|
| 469 | + } |
|
| 470 | + $this->write_to_error_log($time, $ex); |
|
| 471 | + } |
|
| 472 | + // remove last linebreak |
|
| 473 | + $output = substr($output, 0, -6); |
|
| 474 | + if (! WP_DEBUG) { |
|
| 475 | + $output .= ' |
|
| 476 | 476 | </p>'; |
| 477 | - } |
|
| 478 | - $output .= ' |
|
| 477 | + } |
|
| 478 | + $output .= ' |
|
| 479 | 479 | </div>'; |
| 480 | - $output .= self::_print_scripts(true); |
|
| 481 | - if (defined('DOING_AJAX')) { |
|
| 482 | - echo wp_json_encode(array('error' => $output)); |
|
| 483 | - exit(); |
|
| 484 | - } |
|
| 485 | - echo $output; |
|
| 486 | - die(); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * generate string from exception trace args |
|
| 493 | - * |
|
| 494 | - * @param array $arguments |
|
| 495 | - * @param bool $array |
|
| 496 | - * @return string |
|
| 497 | - */ |
|
| 498 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
| 499 | - { |
|
| 500 | - $arg_string = ''; |
|
| 501 | - if (! empty($arguments)) { |
|
| 502 | - $args = array(); |
|
| 503 | - foreach ($arguments as $arg) { |
|
| 504 | - if (! empty($arg)) { |
|
| 505 | - if (is_string($arg)) { |
|
| 506 | - $args[] = " '" . $arg . "'"; |
|
| 507 | - } elseif (is_array($arg)) { |
|
| 508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 509 | - } elseif ($arg === null) { |
|
| 510 | - $args[] = ' NULL'; |
|
| 511 | - } elseif (is_bool($arg)) { |
|
| 512 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
| 513 | - } elseif (is_object($arg)) { |
|
| 514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
| 515 | - } elseif (is_resource($arg)) { |
|
| 516 | - $args[] = get_resource_type($arg); |
|
| 517 | - } else { |
|
| 518 | - $args[] = $arg; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - $arg_string = implode(', ', $args); |
|
| 523 | - } |
|
| 524 | - if ($array) { |
|
| 525 | - $arg_string .= ' )'; |
|
| 526 | - } |
|
| 527 | - return $arg_string; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * add error message |
|
| 534 | - * |
|
| 535 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 536 | - * separate messages for user || dev |
|
| 537 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 538 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 539 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 540 | - * @return void |
|
| 541 | - */ |
|
| 542 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
| 543 | - { |
|
| 544 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
| 545 | - self::$_error_count++; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
| 552 | - * adds an error |
|
| 553 | - * |
|
| 554 | - * @param string $msg |
|
| 555 | - * @param string $file |
|
| 556 | - * @param string $func |
|
| 557 | - * @param string $line |
|
| 558 | - * @throws EE_Error |
|
| 559 | - */ |
|
| 560 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
| 561 | - { |
|
| 562 | - if (WP_DEBUG) { |
|
| 563 | - throw new EE_Error($msg); |
|
| 564 | - } |
|
| 565 | - EE_Error::add_error($msg, $file, $func, $line); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * add success message |
|
| 572 | - * |
|
| 573 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 574 | - * separate messages for user || dev |
|
| 575 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 576 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 577 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 578 | - * @return void |
|
| 579 | - */ |
|
| 580 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
| 581 | - { |
|
| 582 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * add attention message |
|
| 589 | - * |
|
| 590 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 591 | - * separate messages for user || dev |
|
| 592 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 593 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 594 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 595 | - * @return void |
|
| 596 | - */ |
|
| 597 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
| 598 | - { |
|
| 599 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * @param string $type whether the message is for a success or error notification |
|
| 606 | - * @param string $msg the message to display to users or developers |
|
| 607 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
| 608 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 609 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 610 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 611 | - * @return void |
|
| 612 | - */ |
|
| 613 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
| 614 | - { |
|
| 615 | - if (empty($msg)) { |
|
| 616 | - EE_Error::doing_it_wrong( |
|
| 617 | - 'EE_Error::add_' . $type . '()', |
|
| 618 | - sprintf( |
|
| 619 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
| 620 | - 'event_espresso'), |
|
| 621 | - $type, |
|
| 622 | - $file, |
|
| 623 | - $line |
|
| 624 | - ), |
|
| 625 | - EVENT_ESPRESSO_VERSION |
|
| 626 | - ); |
|
| 627 | - } |
|
| 628 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
| 629 | - EE_Error::doing_it_wrong( |
|
| 630 | - 'EE_Error::add_error()', |
|
| 631 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
| 632 | - 'event_espresso'), |
|
| 633 | - EVENT_ESPRESSO_VERSION |
|
| 634 | - ); |
|
| 635 | - } |
|
| 636 | - // get separate user and developer messages if they exist |
|
| 637 | - $msg = explode('||', $msg); |
|
| 638 | - $user_msg = $msg[0]; |
|
| 639 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 640 | - /** |
|
| 641 | - * Do an action so other code can be triggered when a notice is created |
|
| 642 | - * |
|
| 643 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
| 644 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
| 645 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
| 646 | - * @param string $file file where error was generated |
|
| 647 | - * @param string $func function where error was generated |
|
| 648 | - * @param string $line line where error was generated |
|
| 649 | - */ |
|
| 650 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
| 651 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 652 | - // add notice if message exists |
|
| 653 | - if (! empty($msg)) { |
|
| 654 | - // get error code |
|
| 655 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
| 656 | - if (WP_DEBUG && $type === 'errors') { |
|
| 657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 658 | - } |
|
| 659 | - // add notice. Index by code if it's not blank |
|
| 660 | - if ($notice_code) { |
|
| 661 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
| 662 | - } else { |
|
| 663 | - self::$_espresso_notices[$type][] = $msg; |
|
| 664 | - } |
|
| 665 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * in some case it may be necessary to overwrite the existing success messages |
|
| 672 | - * |
|
| 673 | - * @return void |
|
| 674 | - */ |
|
| 675 | - public static function overwrite_success() |
|
| 676 | - { |
|
| 677 | - self::$_espresso_notices['success'] = false; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * in some case it may be necessary to overwrite the existing attention messages |
|
| 684 | - * |
|
| 685 | - * @return void |
|
| 686 | - */ |
|
| 687 | - public static function overwrite_attention() |
|
| 688 | - { |
|
| 689 | - self::$_espresso_notices['attention'] = false; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * in some case it may be necessary to overwrite the existing error messages |
|
| 696 | - * |
|
| 697 | - * @return void |
|
| 698 | - */ |
|
| 699 | - public static function overwrite_errors() |
|
| 700 | - { |
|
| 701 | - self::$_espresso_notices['errors'] = false; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * @return void |
|
| 708 | - */ |
|
| 709 | - public static function reset_notices() |
|
| 710 | - { |
|
| 711 | - self::$_espresso_notices['success'] = false; |
|
| 712 | - self::$_espresso_notices['attention'] = false; |
|
| 713 | - self::$_espresso_notices['errors'] = false; |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * @return int |
|
| 720 | - */ |
|
| 721 | - public static function has_notices() |
|
| 722 | - { |
|
| 723 | - $has_notices = 0; |
|
| 724 | - // check for success messages |
|
| 725 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
| 726 | - ? 3 |
|
| 727 | - : $has_notices; |
|
| 728 | - // check for attention messages |
|
| 729 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
| 730 | - ? 2 |
|
| 731 | - : $has_notices; |
|
| 732 | - // check for error messages |
|
| 733 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
| 734 | - ? 1 |
|
| 735 | - : $has_notices; |
|
| 736 | - return $has_notices; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
| 742 | - * |
|
| 743 | - * @since 4.9.0 |
|
| 744 | - * @return array |
|
| 745 | - */ |
|
| 746 | - public static function get_vanilla_notices() |
|
| 747 | - { |
|
| 748 | - return array( |
|
| 749 | - 'success' => isset(self::$_espresso_notices['success']) |
|
| 750 | - ? self::$_espresso_notices['success'] |
|
| 751 | - : array(), |
|
| 752 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
| 753 | - ? self::$_espresso_notices['attention'] |
|
| 754 | - : array(), |
|
| 755 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
| 756 | - ? self::$_espresso_notices['errors'] |
|
| 757 | - : array(), |
|
| 758 | - ); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * @return array |
|
| 764 | - * @throws InvalidArgumentException |
|
| 765 | - * @throws InvalidDataTypeException |
|
| 766 | - * @throws InvalidInterfaceException |
|
| 767 | - */ |
|
| 768 | - public static function getStoredNotices() |
|
| 769 | - { |
|
| 770 | - if ($user_id = get_current_user_id()) { |
|
| 771 | - // get notices for logged in user |
|
| 772 | - $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
| 773 | - return is_array($notices) ? $notices : array(); |
|
| 774 | - } |
|
| 775 | - if (EE_Session::isLoadedAndActive()) { |
|
| 776 | - // get notices for user currently engaged in a session |
|
| 777 | - $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 778 | - return is_array($session_data) ? $session_data : array(); |
|
| 779 | - } |
|
| 780 | - // get global notices and hope they apply to the current site visitor |
|
| 781 | - $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 782 | - return is_array($notices) ? $notices : array(); |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - /** |
|
| 787 | - * @param array $notices |
|
| 788 | - * @return bool |
|
| 789 | - * @throws InvalidArgumentException |
|
| 790 | - * @throws InvalidDataTypeException |
|
| 791 | - * @throws InvalidInterfaceException |
|
| 792 | - */ |
|
| 793 | - public static function storeNotices(array $notices) |
|
| 794 | - { |
|
| 795 | - if ($user_id = get_current_user_id()) { |
|
| 796 | - // store notices for logged in user |
|
| 797 | - return (bool) update_user_option( |
|
| 798 | - $user_id, |
|
| 799 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
| 800 | - $notices |
|
| 801 | - ); |
|
| 802 | - } |
|
| 803 | - if (EE_Session::isLoadedAndActive()) { |
|
| 804 | - // store notices for user currently engaged in a session |
|
| 805 | - return EE_Session::instance()->set_session_data( |
|
| 806 | - array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
| 807 | - ); |
|
| 808 | - } |
|
| 809 | - // store global notices and hope they apply to the same site visitor on the next request |
|
| 810 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * @return bool|TRUE |
|
| 816 | - * @throws InvalidArgumentException |
|
| 817 | - * @throws InvalidDataTypeException |
|
| 818 | - * @throws InvalidInterfaceException |
|
| 819 | - */ |
|
| 820 | - public static function clearNotices() |
|
| 821 | - { |
|
| 822 | - if ($user_id = get_current_user_id()) { |
|
| 823 | - // clear notices for logged in user |
|
| 824 | - return (bool) update_user_option( |
|
| 825 | - $user_id, |
|
| 826 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
| 827 | - array() |
|
| 828 | - ); |
|
| 829 | - } |
|
| 830 | - if (EE_Session::isLoadedAndActive()) { |
|
| 831 | - // clear notices for user currently engaged in a session |
|
| 832 | - return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 833 | - } |
|
| 834 | - // clear global notices and hope none belonged to some for some other site visitor |
|
| 835 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * saves notices to the db for retrieval on next request |
|
| 841 | - * |
|
| 842 | - * @return void |
|
| 843 | - * @throws InvalidArgumentException |
|
| 844 | - * @throws InvalidDataTypeException |
|
| 845 | - * @throws InvalidInterfaceException |
|
| 846 | - */ |
|
| 847 | - public static function stashNoticesBeforeRedirect() |
|
| 848 | - { |
|
| 849 | - EE_Error::get_notices(false, true); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * compile all error or success messages into one string |
|
| 855 | - * |
|
| 856 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
| 857 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
| 858 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
| 859 | - * - ONLY do this just before redirecting |
|
| 860 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
| 861 | - * @return array |
|
| 862 | - * @throws InvalidArgumentException |
|
| 863 | - * @throws InvalidDataTypeException |
|
| 864 | - * @throws InvalidInterfaceException |
|
| 865 | - */ |
|
| 866 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
| 867 | - { |
|
| 868 | - $success_messages = ''; |
|
| 869 | - $attention_messages = ''; |
|
| 870 | - $error_messages = ''; |
|
| 871 | - // either save notices to the db |
|
| 872 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
| 873 | - self::$_espresso_notices = array_merge( |
|
| 874 | - EE_Error::getStoredNotices(), |
|
| 875 | - self::$_espresso_notices |
|
| 876 | - ); |
|
| 877 | - EE_Error::storeNotices(self::$_espresso_notices); |
|
| 878 | - return array(); |
|
| 879 | - } |
|
| 880 | - $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
| 881 | - // check for success messages |
|
| 882 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
| 883 | - // combine messages |
|
| 884 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
| 885 | - $print_scripts = true; |
|
| 886 | - } |
|
| 887 | - // check for attention messages |
|
| 888 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
| 889 | - // combine messages |
|
| 890 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
| 891 | - $print_scripts = true; |
|
| 892 | - } |
|
| 893 | - // check for error messages |
|
| 894 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
| 895 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
| 896 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
| 897 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
| 898 | - // combine messages |
|
| 899 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
| 900 | - $print_scripts = true; |
|
| 901 | - } |
|
| 902 | - if ($format_output) { |
|
| 903 | - $notices = EE_Error::formatNoticesOutput( |
|
| 904 | - $success_messages, |
|
| 905 | - $attention_messages, |
|
| 906 | - $error_messages |
|
| 907 | - ); |
|
| 908 | - } else { |
|
| 909 | - $notices = array( |
|
| 910 | - 'success' => $success_messages, |
|
| 911 | - 'attention' => $attention_messages, |
|
| 912 | - 'errors' => $error_messages, |
|
| 913 | - ); |
|
| 914 | - if ($remove_empty) { |
|
| 915 | - // remove empty notices |
|
| 916 | - foreach ($notices as $type => $notice) { |
|
| 917 | - if (empty($notice)) { |
|
| 918 | - unset($notices[$type]); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - if ($print_scripts) { |
|
| 924 | - self::_print_scripts(); |
|
| 925 | - } |
|
| 926 | - return $notices; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * @return bool |
|
| 932 | - * @throws InvalidArgumentException |
|
| 933 | - * @throws InvalidDataTypeException |
|
| 934 | - * @throws InvalidInterfaceException |
|
| 935 | - */ |
|
| 936 | - private static function combineExistingAndNewNotices() |
|
| 937 | - { |
|
| 938 | - $print_scripts = false; |
|
| 939 | - // grab any notices that have been previously saved |
|
| 940 | - $notices = EE_Error::getStoredNotices(); |
|
| 941 | - if (! empty($notices)) { |
|
| 942 | - foreach ($notices as $type => $notice) { |
|
| 943 | - if (is_array($notice) && ! empty($notice)) { |
|
| 944 | - // make sure that existing notice type is an array |
|
| 945 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
| 946 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
| 947 | - ? self::$_espresso_notices[ $type ] |
|
| 948 | - : array(); |
|
| 949 | - // add newly created notices to existing ones |
|
| 950 | - self::$_espresso_notices[ $type ] += $notice; |
|
| 951 | - $print_scripts = true; |
|
| 952 | - } |
|
| 953 | - } |
|
| 954 | - // now clear any stored notices |
|
| 955 | - EE_Error::clearNotices(); |
|
| 956 | - } |
|
| 957 | - return $print_scripts; |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - |
|
| 961 | - /** |
|
| 962 | - * @param string $success_messages |
|
| 963 | - * @param string $attention_messages |
|
| 964 | - * @param string $error_messages |
|
| 965 | - * @return string |
|
| 966 | - */ |
|
| 967 | - private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
| 968 | - { |
|
| 969 | - $notices = '<div id="espresso-notices">'; |
|
| 970 | - $close = is_admin() |
|
| 971 | - ? '' |
|
| 972 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
| 973 | - if ($success_messages !== '') { |
|
| 974 | - $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
| 975 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
| 976 | - //showMessage( $success_messages ); |
|
| 977 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 978 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 979 | - . 'style="display:none;">' |
|
| 980 | - . '<p>' . $success_messages . '</p>' |
|
| 981 | - . $close |
|
| 982 | - . '</div>'; |
|
| 983 | - } |
|
| 984 | - if ($attention_messages !== '') { |
|
| 985 | - $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
| 986 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
| 987 | - //showMessage( $error_messages, TRUE ); |
|
| 988 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 989 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 990 | - . 'style="display:none;">' |
|
| 991 | - . '<p>' . $attention_messages . '</p>' |
|
| 992 | - . $close |
|
| 993 | - . '</div>'; |
|
| 994 | - } |
|
| 995 | - if ($error_messages !== '') { |
|
| 996 | - $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
| 997 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
| 998 | - //showMessage( $error_messages, TRUE ); |
|
| 999 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 1000 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 1001 | - . 'style="display:none;">' |
|
| 1002 | - . '<p>' . $error_messages . '</p>' |
|
| 1003 | - . $close |
|
| 1004 | - . '</div>'; |
|
| 1005 | - } |
|
| 1006 | - $notices .= '</div>'; |
|
| 1007 | - return $notices; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - /** |
|
| 1013 | - * _print_scripts |
|
| 1014 | - * |
|
| 1015 | - * @param bool $force_print |
|
| 1016 | - * @return string |
|
| 1017 | - */ |
|
| 1018 | - private static function _print_scripts($force_print = false) |
|
| 1019 | - { |
|
| 1020 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1021 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
| 1022 | - return ''; |
|
| 1023 | - } |
|
| 1024 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
| 1025 | - wp_enqueue_style('espresso_default'); |
|
| 1026 | - wp_enqueue_style('espresso_custom_css'); |
|
| 1027 | - wp_enqueue_script('ee_error_js'); |
|
| 1028 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 1029 | - } |
|
| 1030 | - } else { |
|
| 1031 | - return ' |
|
| 480 | + $output .= self::_print_scripts(true); |
|
| 481 | + if (defined('DOING_AJAX')) { |
|
| 482 | + echo wp_json_encode(array('error' => $output)); |
|
| 483 | + exit(); |
|
| 484 | + } |
|
| 485 | + echo $output; |
|
| 486 | + die(); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * generate string from exception trace args |
|
| 493 | + * |
|
| 494 | + * @param array $arguments |
|
| 495 | + * @param bool $array |
|
| 496 | + * @return string |
|
| 497 | + */ |
|
| 498 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
| 499 | + { |
|
| 500 | + $arg_string = ''; |
|
| 501 | + if (! empty($arguments)) { |
|
| 502 | + $args = array(); |
|
| 503 | + foreach ($arguments as $arg) { |
|
| 504 | + if (! empty($arg)) { |
|
| 505 | + if (is_string($arg)) { |
|
| 506 | + $args[] = " '" . $arg . "'"; |
|
| 507 | + } elseif (is_array($arg)) { |
|
| 508 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 509 | + } elseif ($arg === null) { |
|
| 510 | + $args[] = ' NULL'; |
|
| 511 | + } elseif (is_bool($arg)) { |
|
| 512 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
| 513 | + } elseif (is_object($arg)) { |
|
| 514 | + $args[] = ' OBJECT ' . get_class($arg); |
|
| 515 | + } elseif (is_resource($arg)) { |
|
| 516 | + $args[] = get_resource_type($arg); |
|
| 517 | + } else { |
|
| 518 | + $args[] = $arg; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + $arg_string = implode(', ', $args); |
|
| 523 | + } |
|
| 524 | + if ($array) { |
|
| 525 | + $arg_string .= ' )'; |
|
| 526 | + } |
|
| 527 | + return $arg_string; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * add error message |
|
| 534 | + * |
|
| 535 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 536 | + * separate messages for user || dev |
|
| 537 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 538 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 539 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 540 | + * @return void |
|
| 541 | + */ |
|
| 542 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
| 543 | + { |
|
| 544 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
| 545 | + self::$_error_count++; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
| 552 | + * adds an error |
|
| 553 | + * |
|
| 554 | + * @param string $msg |
|
| 555 | + * @param string $file |
|
| 556 | + * @param string $func |
|
| 557 | + * @param string $line |
|
| 558 | + * @throws EE_Error |
|
| 559 | + */ |
|
| 560 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
| 561 | + { |
|
| 562 | + if (WP_DEBUG) { |
|
| 563 | + throw new EE_Error($msg); |
|
| 564 | + } |
|
| 565 | + EE_Error::add_error($msg, $file, $func, $line); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * add success message |
|
| 572 | + * |
|
| 573 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 574 | + * separate messages for user || dev |
|
| 575 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 576 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 577 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 578 | + * @return void |
|
| 579 | + */ |
|
| 580 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
| 581 | + { |
|
| 582 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * add attention message |
|
| 589 | + * |
|
| 590 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 591 | + * separate messages for user || dev |
|
| 592 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 593 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 594 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 595 | + * @return void |
|
| 596 | + */ |
|
| 597 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
| 598 | + { |
|
| 599 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @param string $type whether the message is for a success or error notification |
|
| 606 | + * @param string $msg the message to display to users or developers |
|
| 607 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
| 608 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 609 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 610 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 611 | + * @return void |
|
| 612 | + */ |
|
| 613 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
| 614 | + { |
|
| 615 | + if (empty($msg)) { |
|
| 616 | + EE_Error::doing_it_wrong( |
|
| 617 | + 'EE_Error::add_' . $type . '()', |
|
| 618 | + sprintf( |
|
| 619 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
| 620 | + 'event_espresso'), |
|
| 621 | + $type, |
|
| 622 | + $file, |
|
| 623 | + $line |
|
| 624 | + ), |
|
| 625 | + EVENT_ESPRESSO_VERSION |
|
| 626 | + ); |
|
| 627 | + } |
|
| 628 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
| 629 | + EE_Error::doing_it_wrong( |
|
| 630 | + 'EE_Error::add_error()', |
|
| 631 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
| 632 | + 'event_espresso'), |
|
| 633 | + EVENT_ESPRESSO_VERSION |
|
| 634 | + ); |
|
| 635 | + } |
|
| 636 | + // get separate user and developer messages if they exist |
|
| 637 | + $msg = explode('||', $msg); |
|
| 638 | + $user_msg = $msg[0]; |
|
| 639 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 640 | + /** |
|
| 641 | + * Do an action so other code can be triggered when a notice is created |
|
| 642 | + * |
|
| 643 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
| 644 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
| 645 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
| 646 | + * @param string $file file where error was generated |
|
| 647 | + * @param string $func function where error was generated |
|
| 648 | + * @param string $line line where error was generated |
|
| 649 | + */ |
|
| 650 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
| 651 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 652 | + // add notice if message exists |
|
| 653 | + if (! empty($msg)) { |
|
| 654 | + // get error code |
|
| 655 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
| 656 | + if (WP_DEBUG && $type === 'errors') { |
|
| 657 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 658 | + } |
|
| 659 | + // add notice. Index by code if it's not blank |
|
| 660 | + if ($notice_code) { |
|
| 661 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
| 662 | + } else { |
|
| 663 | + self::$_espresso_notices[$type][] = $msg; |
|
| 664 | + } |
|
| 665 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * in some case it may be necessary to overwrite the existing success messages |
|
| 672 | + * |
|
| 673 | + * @return void |
|
| 674 | + */ |
|
| 675 | + public static function overwrite_success() |
|
| 676 | + { |
|
| 677 | + self::$_espresso_notices['success'] = false; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * in some case it may be necessary to overwrite the existing attention messages |
|
| 684 | + * |
|
| 685 | + * @return void |
|
| 686 | + */ |
|
| 687 | + public static function overwrite_attention() |
|
| 688 | + { |
|
| 689 | + self::$_espresso_notices['attention'] = false; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * in some case it may be necessary to overwrite the existing error messages |
|
| 696 | + * |
|
| 697 | + * @return void |
|
| 698 | + */ |
|
| 699 | + public static function overwrite_errors() |
|
| 700 | + { |
|
| 701 | + self::$_espresso_notices['errors'] = false; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * @return void |
|
| 708 | + */ |
|
| 709 | + public static function reset_notices() |
|
| 710 | + { |
|
| 711 | + self::$_espresso_notices['success'] = false; |
|
| 712 | + self::$_espresso_notices['attention'] = false; |
|
| 713 | + self::$_espresso_notices['errors'] = false; |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * @return int |
|
| 720 | + */ |
|
| 721 | + public static function has_notices() |
|
| 722 | + { |
|
| 723 | + $has_notices = 0; |
|
| 724 | + // check for success messages |
|
| 725 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
| 726 | + ? 3 |
|
| 727 | + : $has_notices; |
|
| 728 | + // check for attention messages |
|
| 729 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
| 730 | + ? 2 |
|
| 731 | + : $has_notices; |
|
| 732 | + // check for error messages |
|
| 733 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
| 734 | + ? 1 |
|
| 735 | + : $has_notices; |
|
| 736 | + return $has_notices; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
| 742 | + * |
|
| 743 | + * @since 4.9.0 |
|
| 744 | + * @return array |
|
| 745 | + */ |
|
| 746 | + public static function get_vanilla_notices() |
|
| 747 | + { |
|
| 748 | + return array( |
|
| 749 | + 'success' => isset(self::$_espresso_notices['success']) |
|
| 750 | + ? self::$_espresso_notices['success'] |
|
| 751 | + : array(), |
|
| 752 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
| 753 | + ? self::$_espresso_notices['attention'] |
|
| 754 | + : array(), |
|
| 755 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
| 756 | + ? self::$_espresso_notices['errors'] |
|
| 757 | + : array(), |
|
| 758 | + ); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * @return array |
|
| 764 | + * @throws InvalidArgumentException |
|
| 765 | + * @throws InvalidDataTypeException |
|
| 766 | + * @throws InvalidInterfaceException |
|
| 767 | + */ |
|
| 768 | + public static function getStoredNotices() |
|
| 769 | + { |
|
| 770 | + if ($user_id = get_current_user_id()) { |
|
| 771 | + // get notices for logged in user |
|
| 772 | + $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
| 773 | + return is_array($notices) ? $notices : array(); |
|
| 774 | + } |
|
| 775 | + if (EE_Session::isLoadedAndActive()) { |
|
| 776 | + // get notices for user currently engaged in a session |
|
| 777 | + $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 778 | + return is_array($session_data) ? $session_data : array(); |
|
| 779 | + } |
|
| 780 | + // get global notices and hope they apply to the current site visitor |
|
| 781 | + $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 782 | + return is_array($notices) ? $notices : array(); |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + /** |
|
| 787 | + * @param array $notices |
|
| 788 | + * @return bool |
|
| 789 | + * @throws InvalidArgumentException |
|
| 790 | + * @throws InvalidDataTypeException |
|
| 791 | + * @throws InvalidInterfaceException |
|
| 792 | + */ |
|
| 793 | + public static function storeNotices(array $notices) |
|
| 794 | + { |
|
| 795 | + if ($user_id = get_current_user_id()) { |
|
| 796 | + // store notices for logged in user |
|
| 797 | + return (bool) update_user_option( |
|
| 798 | + $user_id, |
|
| 799 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
| 800 | + $notices |
|
| 801 | + ); |
|
| 802 | + } |
|
| 803 | + if (EE_Session::isLoadedAndActive()) { |
|
| 804 | + // store notices for user currently engaged in a session |
|
| 805 | + return EE_Session::instance()->set_session_data( |
|
| 806 | + array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
| 807 | + ); |
|
| 808 | + } |
|
| 809 | + // store global notices and hope they apply to the same site visitor on the next request |
|
| 810 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * @return bool|TRUE |
|
| 816 | + * @throws InvalidArgumentException |
|
| 817 | + * @throws InvalidDataTypeException |
|
| 818 | + * @throws InvalidInterfaceException |
|
| 819 | + */ |
|
| 820 | + public static function clearNotices() |
|
| 821 | + { |
|
| 822 | + if ($user_id = get_current_user_id()) { |
|
| 823 | + // clear notices for logged in user |
|
| 824 | + return (bool) update_user_option( |
|
| 825 | + $user_id, |
|
| 826 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
| 827 | + array() |
|
| 828 | + ); |
|
| 829 | + } |
|
| 830 | + if (EE_Session::isLoadedAndActive()) { |
|
| 831 | + // clear notices for user currently engaged in a session |
|
| 832 | + return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 833 | + } |
|
| 834 | + // clear global notices and hope none belonged to some for some other site visitor |
|
| 835 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * saves notices to the db for retrieval on next request |
|
| 841 | + * |
|
| 842 | + * @return void |
|
| 843 | + * @throws InvalidArgumentException |
|
| 844 | + * @throws InvalidDataTypeException |
|
| 845 | + * @throws InvalidInterfaceException |
|
| 846 | + */ |
|
| 847 | + public static function stashNoticesBeforeRedirect() |
|
| 848 | + { |
|
| 849 | + EE_Error::get_notices(false, true); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * compile all error or success messages into one string |
|
| 855 | + * |
|
| 856 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
| 857 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
| 858 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
| 859 | + * - ONLY do this just before redirecting |
|
| 860 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
| 861 | + * @return array |
|
| 862 | + * @throws InvalidArgumentException |
|
| 863 | + * @throws InvalidDataTypeException |
|
| 864 | + * @throws InvalidInterfaceException |
|
| 865 | + */ |
|
| 866 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
| 867 | + { |
|
| 868 | + $success_messages = ''; |
|
| 869 | + $attention_messages = ''; |
|
| 870 | + $error_messages = ''; |
|
| 871 | + // either save notices to the db |
|
| 872 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
| 873 | + self::$_espresso_notices = array_merge( |
|
| 874 | + EE_Error::getStoredNotices(), |
|
| 875 | + self::$_espresso_notices |
|
| 876 | + ); |
|
| 877 | + EE_Error::storeNotices(self::$_espresso_notices); |
|
| 878 | + return array(); |
|
| 879 | + } |
|
| 880 | + $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
| 881 | + // check for success messages |
|
| 882 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
| 883 | + // combine messages |
|
| 884 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
| 885 | + $print_scripts = true; |
|
| 886 | + } |
|
| 887 | + // check for attention messages |
|
| 888 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
| 889 | + // combine messages |
|
| 890 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
| 891 | + $print_scripts = true; |
|
| 892 | + } |
|
| 893 | + // check for error messages |
|
| 894 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
| 895 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
| 896 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
| 897 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
| 898 | + // combine messages |
|
| 899 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
| 900 | + $print_scripts = true; |
|
| 901 | + } |
|
| 902 | + if ($format_output) { |
|
| 903 | + $notices = EE_Error::formatNoticesOutput( |
|
| 904 | + $success_messages, |
|
| 905 | + $attention_messages, |
|
| 906 | + $error_messages |
|
| 907 | + ); |
|
| 908 | + } else { |
|
| 909 | + $notices = array( |
|
| 910 | + 'success' => $success_messages, |
|
| 911 | + 'attention' => $attention_messages, |
|
| 912 | + 'errors' => $error_messages, |
|
| 913 | + ); |
|
| 914 | + if ($remove_empty) { |
|
| 915 | + // remove empty notices |
|
| 916 | + foreach ($notices as $type => $notice) { |
|
| 917 | + if (empty($notice)) { |
|
| 918 | + unset($notices[$type]); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + if ($print_scripts) { |
|
| 924 | + self::_print_scripts(); |
|
| 925 | + } |
|
| 926 | + return $notices; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * @return bool |
|
| 932 | + * @throws InvalidArgumentException |
|
| 933 | + * @throws InvalidDataTypeException |
|
| 934 | + * @throws InvalidInterfaceException |
|
| 935 | + */ |
|
| 936 | + private static function combineExistingAndNewNotices() |
|
| 937 | + { |
|
| 938 | + $print_scripts = false; |
|
| 939 | + // grab any notices that have been previously saved |
|
| 940 | + $notices = EE_Error::getStoredNotices(); |
|
| 941 | + if (! empty($notices)) { |
|
| 942 | + foreach ($notices as $type => $notice) { |
|
| 943 | + if (is_array($notice) && ! empty($notice)) { |
|
| 944 | + // make sure that existing notice type is an array |
|
| 945 | + self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
| 946 | + && ! empty(self::$_espresso_notices[ $type ]) |
|
| 947 | + ? self::$_espresso_notices[ $type ] |
|
| 948 | + : array(); |
|
| 949 | + // add newly created notices to existing ones |
|
| 950 | + self::$_espresso_notices[ $type ] += $notice; |
|
| 951 | + $print_scripts = true; |
|
| 952 | + } |
|
| 953 | + } |
|
| 954 | + // now clear any stored notices |
|
| 955 | + EE_Error::clearNotices(); |
|
| 956 | + } |
|
| 957 | + return $print_scripts; |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + |
|
| 961 | + /** |
|
| 962 | + * @param string $success_messages |
|
| 963 | + * @param string $attention_messages |
|
| 964 | + * @param string $error_messages |
|
| 965 | + * @return string |
|
| 966 | + */ |
|
| 967 | + private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
| 968 | + { |
|
| 969 | + $notices = '<div id="espresso-notices">'; |
|
| 970 | + $close = is_admin() |
|
| 971 | + ? '' |
|
| 972 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
| 973 | + if ($success_messages !== '') { |
|
| 974 | + $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
| 975 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
| 976 | + //showMessage( $success_messages ); |
|
| 977 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 978 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 979 | + . 'style="display:none;">' |
|
| 980 | + . '<p>' . $success_messages . '</p>' |
|
| 981 | + . $close |
|
| 982 | + . '</div>'; |
|
| 983 | + } |
|
| 984 | + if ($attention_messages !== '') { |
|
| 985 | + $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
| 986 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
| 987 | + //showMessage( $error_messages, TRUE ); |
|
| 988 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 989 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 990 | + . 'style="display:none;">' |
|
| 991 | + . '<p>' . $attention_messages . '</p>' |
|
| 992 | + . $close |
|
| 993 | + . '</div>'; |
|
| 994 | + } |
|
| 995 | + if ($error_messages !== '') { |
|
| 996 | + $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
| 997 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
| 998 | + //showMessage( $error_messages, TRUE ); |
|
| 999 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 1000 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 1001 | + . 'style="display:none;">' |
|
| 1002 | + . '<p>' . $error_messages . '</p>' |
|
| 1003 | + . $close |
|
| 1004 | + . '</div>'; |
|
| 1005 | + } |
|
| 1006 | + $notices .= '</div>'; |
|
| 1007 | + return $notices; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + /** |
|
| 1013 | + * _print_scripts |
|
| 1014 | + * |
|
| 1015 | + * @param bool $force_print |
|
| 1016 | + * @return string |
|
| 1017 | + */ |
|
| 1018 | + private static function _print_scripts($force_print = false) |
|
| 1019 | + { |
|
| 1020 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1021 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
| 1022 | + return ''; |
|
| 1023 | + } |
|
| 1024 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
| 1025 | + wp_enqueue_style('espresso_default'); |
|
| 1026 | + wp_enqueue_style('espresso_custom_css'); |
|
| 1027 | + wp_enqueue_script('ee_error_js'); |
|
| 1028 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 1029 | + } |
|
| 1030 | + } else { |
|
| 1031 | + return ' |
|
| 1032 | 1032 | <script> |
| 1033 | 1033 | /* <![CDATA[ */ |
| 1034 | 1034 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -1038,223 +1038,223 @@ discard block |
||
| 1038 | 1038 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
| 1039 | 1039 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
| 1040 | 1040 | '; |
| 1041 | - } |
|
| 1042 | - return ''; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public static function enqueue_error_scripts() |
|
| 1051 | - { |
|
| 1052 | - self::_print_scripts(); |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - |
|
| 1057 | - /** |
|
| 1058 | - * create error code from filepath, function name, |
|
| 1059 | - * and line number where exception or error was thrown |
|
| 1060 | - * |
|
| 1061 | - * @param string $file |
|
| 1062 | - * @param string $func |
|
| 1063 | - * @param string $line |
|
| 1064 | - * @return string |
|
| 1065 | - */ |
|
| 1066 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
| 1067 | - { |
|
| 1068 | - $file = explode('.', basename($file)); |
|
| 1069 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
| 1070 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1071 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1072 | - return $error_code; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * write exception details to log file |
|
| 1079 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
| 1080 | - * |
|
| 1081 | - * @param int $time |
|
| 1082 | - * @param array $ex |
|
| 1083 | - * @param bool $clear |
|
| 1084 | - * @return void |
|
| 1085 | - */ |
|
| 1086 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
| 1087 | - { |
|
| 1088 | - if (empty($ex)) { |
|
| 1089 | - return; |
|
| 1090 | - } |
|
| 1091 | - if (! $time) { |
|
| 1092 | - $time = time(); |
|
| 1093 | - } |
|
| 1094 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
| 1095 | - . PHP_EOL; |
|
| 1096 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1097 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1098 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1099 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1100 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1101 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1102 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1103 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
| 1104 | - . PHP_EOL; |
|
| 1105 | - try { |
|
| 1106 | - error_log($exception_log); |
|
| 1107 | - } catch (EE_Error $e) { |
|
| 1108 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
| 1109 | - 'event_espresso'), $e->getMessage())); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
| 1117 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
| 1118 | - * but the code execution is done in a manner that could lead to unexpected results |
|
| 1119 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
| 1120 | - * A good test for knowing whether to use this method is: |
|
| 1121 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
| 1122 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
| 1123 | - * 2. If this is loaded before something else, it won't break anything, |
|
| 1124 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
| 1125 | - * |
|
| 1126 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
| 1127 | - * @param string $function The function that was called |
|
| 1128 | - * @param string $message A message explaining what has been done incorrectly |
|
| 1129 | - * @param string $version The version of Event Espresso where the error was added |
|
| 1130 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 1131 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 1132 | - * but not have any notices appear until a later version. This allows developers |
|
| 1133 | - * extra time to update their code before notices appear. |
|
| 1134 | - * @param int $error_type |
|
| 1135 | - */ |
|
| 1136 | - public static function doing_it_wrong( |
|
| 1137 | - $function, |
|
| 1138 | - $message, |
|
| 1139 | - $version, |
|
| 1140 | - $applies_when = '', |
|
| 1141 | - $error_type = null |
|
| 1142 | - ) { |
|
| 1143 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 1144 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
| 1152 | - * |
|
| 1153 | - * @return array { |
|
| 1154 | - * @type array $success all the success messages |
|
| 1155 | - * @type array $errors all the error messages |
|
| 1156 | - * @type array $attention all the attention messages |
|
| 1157 | - * } |
|
| 1158 | - */ |
|
| 1159 | - public static function get_raw_notices() |
|
| 1160 | - { |
|
| 1161 | - return self::$_espresso_notices; |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * @deprecated 4.9.27 |
|
| 1168 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1169 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1170 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
| 1171 | - * @return void |
|
| 1172 | - * @throws InvalidDataTypeException |
|
| 1173 | - */ |
|
| 1174 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
| 1175 | - { |
|
| 1176 | - new PersistentAdminNotice( |
|
| 1177 | - $pan_name, |
|
| 1178 | - $pan_message, |
|
| 1179 | - $force_update |
|
| 1180 | - ); |
|
| 1181 | - EE_Error::doing_it_wrong( |
|
| 1182 | - __METHOD__, |
|
| 1183 | - sprintf( |
|
| 1184 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1185 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
| 1186 | - ), |
|
| 1187 | - '4.9.27' |
|
| 1188 | - ); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - |
|
| 1193 | - /** |
|
| 1194 | - * @deprecated 4.9.27 |
|
| 1195 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
| 1196 | - * @param bool $purge |
|
| 1197 | - * @param bool $return |
|
| 1198 | - * @throws DomainException |
|
| 1199 | - * @throws InvalidInterfaceException |
|
| 1200 | - * @throws InvalidDataTypeException |
|
| 1201 | - * @throws ServiceNotFoundException |
|
| 1202 | - * @throws InvalidArgumentException |
|
| 1203 | - */ |
|
| 1204 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
| 1205 | - { |
|
| 1206 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 1207 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 1208 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1209 | - ); |
|
| 1210 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
| 1211 | - EE_Error::doing_it_wrong( |
|
| 1212 | - __METHOD__, |
|
| 1213 | - sprintf( |
|
| 1214 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1215 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1216 | - ), |
|
| 1217 | - '4.9.27' |
|
| 1218 | - ); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * @deprecated 4.9.27 |
|
| 1225 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1226 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1227 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
| 1228 | - */ |
|
| 1229 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
| 1230 | - { |
|
| 1231 | - EE_Error::doing_it_wrong( |
|
| 1232 | - __METHOD__, |
|
| 1233 | - sprintf( |
|
| 1234 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1235 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1236 | - ), |
|
| 1237 | - '4.9.27' |
|
| 1238 | - ); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * @deprecated 4.9.27 |
|
| 1245 | - * @param string $return_url |
|
| 1246 | - */ |
|
| 1247 | - public static function get_persistent_admin_notices($return_url = '') |
|
| 1248 | - { |
|
| 1249 | - EE_Error::doing_it_wrong( |
|
| 1250 | - __METHOD__, |
|
| 1251 | - sprintf( |
|
| 1252 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1253 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1254 | - ), |
|
| 1255 | - '4.9.27' |
|
| 1256 | - ); |
|
| 1257 | - } |
|
| 1041 | + } |
|
| 1042 | + return ''; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public static function enqueue_error_scripts() |
|
| 1051 | + { |
|
| 1052 | + self::_print_scripts(); |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + |
|
| 1057 | + /** |
|
| 1058 | + * create error code from filepath, function name, |
|
| 1059 | + * and line number where exception or error was thrown |
|
| 1060 | + * |
|
| 1061 | + * @param string $file |
|
| 1062 | + * @param string $func |
|
| 1063 | + * @param string $line |
|
| 1064 | + * @return string |
|
| 1065 | + */ |
|
| 1066 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
| 1067 | + { |
|
| 1068 | + $file = explode('.', basename($file)); |
|
| 1069 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
| 1070 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1071 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1072 | + return $error_code; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * write exception details to log file |
|
| 1079 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
| 1080 | + * |
|
| 1081 | + * @param int $time |
|
| 1082 | + * @param array $ex |
|
| 1083 | + * @param bool $clear |
|
| 1084 | + * @return void |
|
| 1085 | + */ |
|
| 1086 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
| 1087 | + { |
|
| 1088 | + if (empty($ex)) { |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1091 | + if (! $time) { |
|
| 1092 | + $time = time(); |
|
| 1093 | + } |
|
| 1094 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
| 1095 | + . PHP_EOL; |
|
| 1096 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1097 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1098 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1099 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1100 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1101 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1102 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1103 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
| 1104 | + . PHP_EOL; |
|
| 1105 | + try { |
|
| 1106 | + error_log($exception_log); |
|
| 1107 | + } catch (EE_Error $e) { |
|
| 1108 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
| 1109 | + 'event_espresso'), $e->getMessage())); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
| 1117 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
| 1118 | + * but the code execution is done in a manner that could lead to unexpected results |
|
| 1119 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
| 1120 | + * A good test for knowing whether to use this method is: |
|
| 1121 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
| 1122 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
| 1123 | + * 2. If this is loaded before something else, it won't break anything, |
|
| 1124 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
| 1125 | + * |
|
| 1126 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
| 1127 | + * @param string $function The function that was called |
|
| 1128 | + * @param string $message A message explaining what has been done incorrectly |
|
| 1129 | + * @param string $version The version of Event Espresso where the error was added |
|
| 1130 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 1131 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 1132 | + * but not have any notices appear until a later version. This allows developers |
|
| 1133 | + * extra time to update their code before notices appear. |
|
| 1134 | + * @param int $error_type |
|
| 1135 | + */ |
|
| 1136 | + public static function doing_it_wrong( |
|
| 1137 | + $function, |
|
| 1138 | + $message, |
|
| 1139 | + $version, |
|
| 1140 | + $applies_when = '', |
|
| 1141 | + $error_type = null |
|
| 1142 | + ) { |
|
| 1143 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 1144 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
| 1152 | + * |
|
| 1153 | + * @return array { |
|
| 1154 | + * @type array $success all the success messages |
|
| 1155 | + * @type array $errors all the error messages |
|
| 1156 | + * @type array $attention all the attention messages |
|
| 1157 | + * } |
|
| 1158 | + */ |
|
| 1159 | + public static function get_raw_notices() |
|
| 1160 | + { |
|
| 1161 | + return self::$_espresso_notices; |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * @deprecated 4.9.27 |
|
| 1168 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1169 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1170 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
| 1171 | + * @return void |
|
| 1172 | + * @throws InvalidDataTypeException |
|
| 1173 | + */ |
|
| 1174 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
| 1175 | + { |
|
| 1176 | + new PersistentAdminNotice( |
|
| 1177 | + $pan_name, |
|
| 1178 | + $pan_message, |
|
| 1179 | + $force_update |
|
| 1180 | + ); |
|
| 1181 | + EE_Error::doing_it_wrong( |
|
| 1182 | + __METHOD__, |
|
| 1183 | + sprintf( |
|
| 1184 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1185 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
| 1186 | + ), |
|
| 1187 | + '4.9.27' |
|
| 1188 | + ); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + |
|
| 1193 | + /** |
|
| 1194 | + * @deprecated 4.9.27 |
|
| 1195 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
| 1196 | + * @param bool $purge |
|
| 1197 | + * @param bool $return |
|
| 1198 | + * @throws DomainException |
|
| 1199 | + * @throws InvalidInterfaceException |
|
| 1200 | + * @throws InvalidDataTypeException |
|
| 1201 | + * @throws ServiceNotFoundException |
|
| 1202 | + * @throws InvalidArgumentException |
|
| 1203 | + */ |
|
| 1204 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
| 1205 | + { |
|
| 1206 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 1207 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 1208 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1209 | + ); |
|
| 1210 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
| 1211 | + EE_Error::doing_it_wrong( |
|
| 1212 | + __METHOD__, |
|
| 1213 | + sprintf( |
|
| 1214 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1215 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1216 | + ), |
|
| 1217 | + '4.9.27' |
|
| 1218 | + ); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * @deprecated 4.9.27 |
|
| 1225 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1226 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1227 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
| 1228 | + */ |
|
| 1229 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
| 1230 | + { |
|
| 1231 | + EE_Error::doing_it_wrong( |
|
| 1232 | + __METHOD__, |
|
| 1233 | + sprintf( |
|
| 1234 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1235 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1236 | + ), |
|
| 1237 | + '4.9.27' |
|
| 1238 | + ); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * @deprecated 4.9.27 |
|
| 1245 | + * @param string $return_url |
|
| 1246 | + */ |
|
| 1247 | + public static function get_persistent_admin_notices($return_url = '') |
|
| 1248 | + { |
|
| 1249 | + EE_Error::doing_it_wrong( |
|
| 1250 | + __METHOD__, |
|
| 1251 | + sprintf( |
|
| 1252 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1253 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1254 | + ), |
|
| 1255 | + '4.9.27' |
|
| 1256 | + ); |
|
| 1257 | + } |
|
| 1258 | 1258 | |
| 1259 | 1259 | |
| 1260 | 1260 | |
@@ -1269,27 +1269,27 @@ discard block |
||
| 1269 | 1269 | */ |
| 1270 | 1270 | function espresso_error_enqueue_scripts() |
| 1271 | 1271 | { |
| 1272 | - // js for error handling |
|
| 1273 | - wp_register_script( |
|
| 1274 | - 'espresso_core', |
|
| 1275 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1276 | - array('jquery'), |
|
| 1277 | - EVENT_ESPRESSO_VERSION, |
|
| 1278 | - false |
|
| 1279 | - ); |
|
| 1280 | - wp_register_script( |
|
| 1281 | - 'ee_error_js', |
|
| 1282 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1283 | - array('espresso_core'), |
|
| 1284 | - EVENT_ESPRESSO_VERSION, |
|
| 1285 | - false |
|
| 1286 | - ); |
|
| 1272 | + // js for error handling |
|
| 1273 | + wp_register_script( |
|
| 1274 | + 'espresso_core', |
|
| 1275 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1276 | + array('jquery'), |
|
| 1277 | + EVENT_ESPRESSO_VERSION, |
|
| 1278 | + false |
|
| 1279 | + ); |
|
| 1280 | + wp_register_script( |
|
| 1281 | + 'ee_error_js', |
|
| 1282 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1283 | + array('espresso_core'), |
|
| 1284 | + EVENT_ESPRESSO_VERSION, |
|
| 1285 | + false |
|
| 1286 | + ); |
|
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | if (is_admin()) { |
| 1290 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1290 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1291 | 1291 | } else { |
| 1292 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1292 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | default : |
| 103 | 103 | $to = get_option('admin_email'); |
| 104 | 104 | } |
| 105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 105 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
| 106 | 106 | $msg = EE_Error::_format_error($type, $message, $file, $line); |
| 107 | 107 | if (function_exists('wp_mail')) { |
| 108 | 108 | add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
| 109 | 109 | wp_mail($to, $subject, $msg); |
| 110 | 110 | } |
| 111 | 111 | echo '<div id="message" class="espresso-notices error"><p>'; |
| 112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 112 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
| 113 | 113 | echo '<br /></p></div>'; |
| 114 | 114 | } |
| 115 | 115 | |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | </style> |
| 336 | 336 | <div id="ee-error-message" class="error">'; |
| 337 | - if (! WP_DEBUG) { |
|
| 337 | + if ( ! WP_DEBUG) { |
|
| 338 | 338 | $output .= ' |
| 339 | 339 | <p>'; |
| 340 | 340 | } |
@@ -393,14 +393,14 @@ discard block |
||
| 393 | 393 | $class_dsply = ! empty($class) ? $class : ' '; |
| 394 | 394 | $type_dsply = ! empty($type) ? $type : ' '; |
| 395 | 395 | $function_dsply = ! empty($function) ? $function : ' '; |
| 396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 396 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
| 397 | 397 | $trace_details .= ' |
| 398 | 398 | <tr> |
| 399 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
| 400 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
| 401 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
| 402 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
| 403 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
| 399 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
| 400 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
| 401 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
| 402 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
| 403 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
| 404 | 404 | </tr>'; |
| 405 | 405 | } |
| 406 | 406 | $trace_details .= ' |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | } |
| 410 | 410 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
| 411 | 411 | // add generic non-identifying messages for non-privileged users |
| 412 | - if (! WP_DEBUG) { |
|
| 412 | + if ( ! WP_DEBUG) { |
|
| 413 | 413 | $output .= '<span class="ee-error-user-msg-spn">' |
| 414 | 414 | . trim($ex['msg']) |
| 415 | 415 | . '</span> <sup>' |
@@ -451,14 +451,14 @@ discard block |
||
| 451 | 451 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
| 452 | 452 | ' |
| 453 | 453 | . $trace_details; |
| 454 | - if (! empty($class)) { |
|
| 454 | + if ( ! empty($class)) { |
|
| 455 | 455 | $output .= ' |
| 456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
| 457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
| 458 | 458 | <h3>Class Details</h3>'; |
| 459 | 459 | $a = new ReflectionClass($class); |
| 460 | 460 | $output .= ' |
| 461 | - <pre>' . $a . '</pre> |
|
| 461 | + <pre>' . $a.'</pre> |
|
| 462 | 462 | </div> |
| 463 | 463 | </div>'; |
| 464 | 464 | } |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | } |
| 472 | 472 | // remove last linebreak |
| 473 | 473 | $output = substr($output, 0, -6); |
| 474 | - if (! WP_DEBUG) { |
|
| 474 | + if ( ! WP_DEBUG) { |
|
| 475 | 475 | $output .= ' |
| 476 | 476 | </p>'; |
| 477 | 477 | } |
@@ -498,20 +498,20 @@ discard block |
||
| 498 | 498 | private function _convert_args_to_string($arguments = array(), $array = false) |
| 499 | 499 | { |
| 500 | 500 | $arg_string = ''; |
| 501 | - if (! empty($arguments)) { |
|
| 501 | + if ( ! empty($arguments)) { |
|
| 502 | 502 | $args = array(); |
| 503 | 503 | foreach ($arguments as $arg) { |
| 504 | - if (! empty($arg)) { |
|
| 504 | + if ( ! empty($arg)) { |
|
| 505 | 505 | if (is_string($arg)) { |
| 506 | - $args[] = " '" . $arg . "'"; |
|
| 506 | + $args[] = " '".$arg."'"; |
|
| 507 | 507 | } elseif (is_array($arg)) { |
| 508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 508 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true); |
|
| 509 | 509 | } elseif ($arg === null) { |
| 510 | 510 | $args[] = ' NULL'; |
| 511 | 511 | } elseif (is_bool($arg)) { |
| 512 | 512 | $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
| 513 | 513 | } elseif (is_object($arg)) { |
| 514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
| 514 | + $args[] = ' OBJECT '.get_class($arg); |
|
| 515 | 515 | } elseif (is_resource($arg)) { |
| 516 | 516 | $args[] = get_resource_type($arg); |
| 517 | 517 | } else { |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | { |
| 615 | 615 | if (empty($msg)) { |
| 616 | 616 | EE_Error::doing_it_wrong( |
| 617 | - 'EE_Error::add_' . $type . '()', |
|
| 617 | + 'EE_Error::add_'.$type.'()', |
|
| 618 | 618 | sprintf( |
| 619 | 619 | __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
| 620 | 620 | 'event_espresso'), |
@@ -650,11 +650,11 @@ discard block |
||
| 650 | 650 | do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
| 651 | 651 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
| 652 | 652 | // add notice if message exists |
| 653 | - if (! empty($msg)) { |
|
| 653 | + if ( ! empty($msg)) { |
|
| 654 | 654 | // get error code |
| 655 | 655 | $notice_code = EE_Error::generate_error_code($file, $func, $line); |
| 656 | 656 | if (WP_DEBUG && $type === 'errors') { |
| 657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 657 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
| 658 | 658 | } |
| 659 | 659 | // add notice. Index by code if it's not blank |
| 660 | 660 | if ($notice_code) { |
@@ -882,13 +882,13 @@ discard block |
||
| 882 | 882 | if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
| 883 | 883 | // combine messages |
| 884 | 884 | $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
| 885 | - $print_scripts = true; |
|
| 885 | + $print_scripts = true; |
|
| 886 | 886 | } |
| 887 | 887 | // check for attention messages |
| 888 | 888 | if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
| 889 | 889 | // combine messages |
| 890 | 890 | $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
| 891 | - $print_scripts = true; |
|
| 891 | + $print_scripts = true; |
|
| 892 | 892 | } |
| 893 | 893 | // check for error messages |
| 894 | 894 | if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | : __('An error has occurred:<br />', 'event_espresso'); |
| 898 | 898 | // combine messages |
| 899 | 899 | $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
| 900 | - $print_scripts = true; |
|
| 900 | + $print_scripts = true; |
|
| 901 | 901 | } |
| 902 | 902 | if ($format_output) { |
| 903 | 903 | $notices = EE_Error::formatNoticesOutput( |
@@ -938,16 +938,16 @@ discard block |
||
| 938 | 938 | $print_scripts = false; |
| 939 | 939 | // grab any notices that have been previously saved |
| 940 | 940 | $notices = EE_Error::getStoredNotices(); |
| 941 | - if (! empty($notices)) { |
|
| 941 | + if ( ! empty($notices)) { |
|
| 942 | 942 | foreach ($notices as $type => $notice) { |
| 943 | 943 | if (is_array($notice) && ! empty($notice)) { |
| 944 | 944 | // make sure that existing notice type is an array |
| 945 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
| 946 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
| 947 | - ? self::$_espresso_notices[ $type ] |
|
| 945 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
| 946 | + && ! empty(self::$_espresso_notices[$type]) |
|
| 947 | + ? self::$_espresso_notices[$type] |
|
| 948 | 948 | : array(); |
| 949 | 949 | // add newly created notices to existing ones |
| 950 | - self::$_espresso_notices[ $type ] += $notice; |
|
| 950 | + self::$_espresso_notices[$type] += $notice; |
|
| 951 | 951 | $print_scripts = true; |
| 952 | 952 | } |
| 953 | 953 | } |
@@ -974,10 +974,10 @@ discard block |
||
| 974 | 974 | $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
| 975 | 975 | $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
| 976 | 976 | //showMessage( $success_messages ); |
| 977 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 978 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 977 | + $notices .= '<div id="'.$css_id.'" ' |
|
| 978 | + . 'class="espresso-notices '.$css_class.'" ' |
|
| 979 | 979 | . 'style="display:none;">' |
| 980 | - . '<p>' . $success_messages . '</p>' |
|
| 980 | + . '<p>'.$success_messages.'</p>' |
|
| 981 | 981 | . $close |
| 982 | 982 | . '</div>'; |
| 983 | 983 | } |
@@ -985,10 +985,10 @@ discard block |
||
| 985 | 985 | $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
| 986 | 986 | $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
| 987 | 987 | //showMessage( $error_messages, TRUE ); |
| 988 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 989 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 988 | + $notices .= '<div id="'.$css_id.'" ' |
|
| 989 | + . 'class="espresso-notices '.$css_class.'" ' |
|
| 990 | 990 | . 'style="display:none;">' |
| 991 | - . '<p>' . $attention_messages . '</p>' |
|
| 991 | + . '<p>'.$attention_messages.'</p>' |
|
| 992 | 992 | . $close |
| 993 | 993 | . '</div>'; |
| 994 | 994 | } |
@@ -996,10 +996,10 @@ discard block |
||
| 996 | 996 | $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
| 997 | 997 | $css_class = is_admin() ? 'error' : 'error fade-away'; |
| 998 | 998 | //showMessage( $error_messages, TRUE ); |
| 999 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 1000 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 999 | + $notices .= '<div id="'.$css_id.'" ' |
|
| 1000 | + . 'class="espresso-notices '.$css_class.'" ' |
|
| 1001 | 1001 | . 'style="display:none;">' |
| 1002 | - . '<p>' . $error_messages . '</p>' |
|
| 1002 | + . '<p>'.$error_messages.'</p>' |
|
| 1003 | 1003 | . $close |
| 1004 | 1004 | . '</div>'; |
| 1005 | 1005 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | */ |
| 1018 | 1018 | private static function _print_scripts($force_print = false) |
| 1019 | 1019 | { |
| 1020 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1020 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1021 | 1021 | if (wp_script_is('ee_error_js', 'enqueued')) { |
| 1022 | 1022 | return ''; |
| 1023 | 1023 | } |
@@ -1031,12 +1031,12 @@ discard block |
||
| 1031 | 1031 | return ' |
| 1032 | 1032 | <script> |
| 1033 | 1033 | /* <![CDATA[ */ |
| 1034 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
| 1034 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
| 1035 | 1035 | /* ]]> */ |
| 1036 | 1036 | </script> |
| 1037 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
| 1038 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
| 1039 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
| 1037 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
| 1038 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
| 1039 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
| 1040 | 1040 | '; |
| 1041 | 1041 | } |
| 1042 | 1042 | return ''; |
@@ -1067,8 +1067,8 @@ discard block |
||
| 1067 | 1067 | { |
| 1068 | 1068 | $file = explode('.', basename($file)); |
| 1069 | 1069 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
| 1070 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1071 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1070 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
| 1071 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
| 1072 | 1072 | return $error_code; |
| 1073 | 1073 | } |
| 1074 | 1074 | |
@@ -1088,18 +1088,18 @@ discard block |
||
| 1088 | 1088 | if (empty($ex)) { |
| 1089 | 1089 | return; |
| 1090 | 1090 | } |
| 1091 | - if (! $time) { |
|
| 1091 | + if ( ! $time) { |
|
| 1092 | 1092 | $time = time(); |
| 1093 | 1093 | } |
| 1094 | 1094 | $exception_log = '----------------------------------------------------------------------------------------' |
| 1095 | 1095 | . PHP_EOL; |
| 1096 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1097 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1098 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1099 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1100 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1101 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1102 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1096 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
| 1097 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
| 1098 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
| 1099 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
| 1100 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
| 1101 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
| 1102 | + $exception_log .= $ex['string'].PHP_EOL; |
|
| 1103 | 1103 | $exception_log .= '----------------------------------------------------------------------------------------' |
| 1104 | 1104 | . PHP_EOL; |
| 1105 | 1105 | try { |
@@ -1272,14 +1272,14 @@ discard block |
||
| 1272 | 1272 | // js for error handling |
| 1273 | 1273 | wp_register_script( |
| 1274 | 1274 | 'espresso_core', |
| 1275 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1275 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 1276 | 1276 | array('jquery'), |
| 1277 | 1277 | EVENT_ESPRESSO_VERSION, |
| 1278 | 1278 | false |
| 1279 | 1279 | ); |
| 1280 | 1280 | wp_register_script( |
| 1281 | 1281 | 'ee_error_js', |
| 1282 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1282 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
| 1283 | 1283 | array('espresso_core'), |
| 1284 | 1284 | EVENT_ESPRESSO_VERSION, |
| 1285 | 1285 | false |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - 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 | - ); ?> |
|
| 52 | + 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 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | |
| 64 | 64 | } else { |
| 65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | - /** |
|
| 68 | - * espresso_minimum_php_version_error |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | + /** |
|
| 68 | + * espresso_minimum_php_version_error |
|
| 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 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.070'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.070'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -17,2474 +17,2474 @@ discard block |
||
| 17 | 17 | final class EE_Config implements ResettableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - const OPTION_NAME = 'ee_config'; |
|
| 20 | + const OPTION_NAME = 'ee_config'; |
|
| 21 | + |
|
| 22 | + const LOG_NAME = 'ee_config_log'; |
|
| 23 | + |
|
| 24 | + const LOG_LENGTH = 100; |
|
| 25 | + |
|
| 26 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * instance of the EE_Config object |
|
| 31 | + * |
|
| 32 | + * @var EE_Config $_instance |
|
| 33 | + * @access private |
|
| 34 | + */ |
|
| 35 | + private static $_instance; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var boolean $_logging_enabled |
|
| 39 | + */ |
|
| 40 | + private static $_logging_enabled = false; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 44 | + */ |
|
| 45 | + private $legacy_shortcodes_manager; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * An StdClass whose property names are addon slugs, |
|
| 49 | + * and values are their config classes |
|
| 50 | + * |
|
| 51 | + * @var StdClass |
|
| 52 | + */ |
|
| 53 | + public $addons; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var EE_Admin_Config |
|
| 57 | + */ |
|
| 58 | + public $admin; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var EE_Core_Config |
|
| 62 | + */ |
|
| 63 | + public $core; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var EE_Currency_Config |
|
| 67 | + */ |
|
| 68 | + public $currency; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var EE_Organization_Config |
|
| 72 | + */ |
|
| 73 | + public $organization; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var EE_Registration_Config |
|
| 77 | + */ |
|
| 78 | + public $registration; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var EE_Template_Config |
|
| 82 | + */ |
|
| 83 | + public $template_settings; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Holds EE environment values. |
|
| 87 | + * |
|
| 88 | + * @var EE_Environment_Config |
|
| 89 | + */ |
|
| 90 | + public $environment; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * settings pertaining to Google maps |
|
| 94 | + * |
|
| 95 | + * @var EE_Map_Config |
|
| 96 | + */ |
|
| 97 | + public $map_settings; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * settings pertaining to Taxes |
|
| 101 | + * |
|
| 102 | + * @var EE_Tax_Config |
|
| 103 | + */ |
|
| 104 | + public $tax_settings; |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Settings pertaining to global messages settings. |
|
| 109 | + * |
|
| 110 | + * @var EE_Messages_Config |
|
| 111 | + */ |
|
| 112 | + public $messages; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @deprecated |
|
| 116 | + * @var EE_Gateway_Config |
|
| 117 | + */ |
|
| 118 | + public $gateway; |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @var array $_addon_option_names |
|
| 122 | + * @access private |
|
| 123 | + */ |
|
| 124 | + private $_addon_option_names = array(); |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @var array $_module_route_map |
|
| 128 | + * @access private |
|
| 129 | + */ |
|
| 130 | + private static $_module_route_map = array(); |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @var array $_module_forward_map |
|
| 134 | + * @access private |
|
| 135 | + */ |
|
| 136 | + private static $_module_forward_map = array(); |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @var array $_module_view_map |
|
| 140 | + * @access private |
|
| 141 | + */ |
|
| 142 | + private static $_module_view_map = array(); |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @singleton method used to instantiate class object |
|
| 148 | + * @access public |
|
| 149 | + * @return EE_Config instance |
|
| 150 | + */ |
|
| 151 | + public static function instance() |
|
| 152 | + { |
|
| 153 | + // check if class object is instantiated, and instantiated properly |
|
| 154 | + if (! self::$_instance instanceof EE_Config) { |
|
| 155 | + self::$_instance = new self(); |
|
| 156 | + } |
|
| 157 | + return self::$_instance; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Resets the config |
|
| 164 | + * |
|
| 165 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 166 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 167 | + * reflect its state in the database |
|
| 168 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 169 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 170 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 171 | + * site was put into maintenance mode) |
|
| 172 | + * @return EE_Config |
|
| 173 | + */ |
|
| 174 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 175 | + { |
|
| 176 | + if (self::$_instance instanceof EE_Config) { |
|
| 177 | + if ($hard_reset) { |
|
| 178 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 179 | + self::$_instance->_addon_option_names = array(); |
|
| 180 | + self::$_instance->_initialize_config(); |
|
| 181 | + self::$_instance->update_espresso_config(); |
|
| 182 | + } |
|
| 183 | + self::$_instance->update_addon_option_names(); |
|
| 184 | + } |
|
| 185 | + self::$_instance = null; |
|
| 186 | + //we don't need to reset the static properties imo because those should |
|
| 187 | + //only change when a module is added or removed. Currently we don't |
|
| 188 | + //support removing a module during a request when it previously existed |
|
| 189 | + if ($reinstantiate) { |
|
| 190 | + return self::instance(); |
|
| 191 | + } else { |
|
| 192 | + return null; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * class constructor |
|
| 200 | + * |
|
| 201 | + * @access private |
|
| 202 | + */ |
|
| 203 | + private function __construct() |
|
| 204 | + { |
|
| 205 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 206 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 207 | + // setup empty config classes |
|
| 208 | + $this->_initialize_config(); |
|
| 209 | + // load existing EE site settings |
|
| 210 | + $this->_load_core_config(); |
|
| 211 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 212 | + $this->_verify_config(); |
|
| 213 | + // register shortcodes and modules |
|
| 214 | + add_action( |
|
| 215 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 216 | + array($this, 'register_shortcodes_and_modules'), |
|
| 217 | + 999 |
|
| 218 | + ); |
|
| 219 | + // initialize shortcodes and modules |
|
| 220 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 221 | + // register widgets |
|
| 222 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 223 | + // shutdown |
|
| 224 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 225 | + // construct__end hook |
|
| 226 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 227 | + // hardcoded hack |
|
| 228 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @return boolean |
|
| 235 | + */ |
|
| 236 | + public static function logging_enabled() |
|
| 237 | + { |
|
| 238 | + return self::$_logging_enabled; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * use to get the current theme if needed from static context |
|
| 245 | + * |
|
| 246 | + * @return string current theme set. |
|
| 247 | + */ |
|
| 248 | + public static function get_current_theme() |
|
| 249 | + { |
|
| 250 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 251 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * _initialize_config |
|
| 258 | + * |
|
| 259 | + * @access private |
|
| 260 | + * @return void |
|
| 261 | + */ |
|
| 262 | + private function _initialize_config() |
|
| 263 | + { |
|
| 264 | + EE_Config::trim_log(); |
|
| 265 | + //set defaults |
|
| 266 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 267 | + $this->addons = new stdClass(); |
|
| 268 | + // set _module_route_map |
|
| 269 | + EE_Config::$_module_route_map = array(); |
|
| 270 | + // set _module_forward_map |
|
| 271 | + EE_Config::$_module_forward_map = array(); |
|
| 272 | + // set _module_view_map |
|
| 273 | + EE_Config::$_module_view_map = array(); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * load core plugin configuration |
|
| 280 | + * |
|
| 281 | + * @access private |
|
| 282 | + * @return void |
|
| 283 | + */ |
|
| 284 | + private function _load_core_config() |
|
| 285 | + { |
|
| 286 | + // load_core_config__start hook |
|
| 287 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 288 | + $espresso_config = $this->get_espresso_config(); |
|
| 289 | + foreach ($espresso_config as $config => $settings) { |
|
| 290 | + // load_core_config__start hook |
|
| 291 | + $settings = apply_filters( |
|
| 292 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 293 | + $settings, |
|
| 294 | + $config, |
|
| 295 | + $this |
|
| 296 | + ); |
|
| 297 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 298 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 299 | + //call configs populate method to ensure any defaults are set for empty values. |
|
| 300 | + if (method_exists($settings, 'populate')) { |
|
| 301 | + $this->{$config}->populate(); |
|
| 302 | + } |
|
| 303 | + if (method_exists($settings, 'do_hooks')) { |
|
| 304 | + $this->{$config}->do_hooks(); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 309 | + $this->update_espresso_config(); |
|
| 310 | + } |
|
| 311 | + // load_core_config__end hook |
|
| 312 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * _verify_config |
|
| 319 | + * |
|
| 320 | + * @access protected |
|
| 321 | + * @return void |
|
| 322 | + */ |
|
| 323 | + protected function _verify_config() |
|
| 324 | + { |
|
| 325 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 326 | + ? $this->core |
|
| 327 | + : new EE_Core_Config(); |
|
| 328 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 329 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 330 | + ? $this->organization |
|
| 331 | + : new EE_Organization_Config(); |
|
| 332 | + $this->organization = apply_filters( |
|
| 333 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 334 | + $this->organization |
|
| 335 | + ); |
|
| 336 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 337 | + ? $this->currency |
|
| 338 | + : new EE_Currency_Config(); |
|
| 339 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 340 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 341 | + ? $this->registration |
|
| 342 | + : new EE_Registration_Config(); |
|
| 343 | + $this->registration = apply_filters( |
|
| 344 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 345 | + $this->registration |
|
| 346 | + ); |
|
| 347 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 348 | + ? $this->admin |
|
| 349 | + : new EE_Admin_Config(); |
|
| 350 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 351 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 352 | + ? $this->template_settings |
|
| 353 | + : new EE_Template_Config(); |
|
| 354 | + $this->template_settings = apply_filters( |
|
| 355 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 356 | + $this->template_settings |
|
| 357 | + ); |
|
| 358 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 359 | + ? $this->map_settings |
|
| 360 | + : new EE_Map_Config(); |
|
| 361 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 362 | + $this->map_settings); |
|
| 363 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 364 | + ? $this->environment |
|
| 365 | + : new EE_Environment_Config(); |
|
| 366 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 367 | + $this->environment); |
|
| 368 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 369 | + ? $this->tax_settings |
|
| 370 | + : new EE_Tax_Config(); |
|
| 371 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 372 | + $this->tax_settings); |
|
| 373 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 374 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 375 | + ? $this->messages |
|
| 376 | + : new EE_Messages_Config(); |
|
| 377 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 378 | + ? $this->gateway |
|
| 379 | + : new EE_Gateway_Config(); |
|
| 380 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 381 | + $this->legacy_shortcodes_manager = null; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * get_espresso_config |
|
| 387 | + * |
|
| 388 | + * @access public |
|
| 389 | + * @return array of espresso config stuff |
|
| 390 | + */ |
|
| 391 | + public function get_espresso_config() |
|
| 392 | + { |
|
| 393 | + // grab espresso configuration |
|
| 394 | + return apply_filters( |
|
| 395 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 396 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 397 | + ); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * double_check_config_comparison |
|
| 404 | + * |
|
| 405 | + * @access public |
|
| 406 | + * @param string $option |
|
| 407 | + * @param $old_value |
|
| 408 | + * @param $value |
|
| 409 | + */ |
|
| 410 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 411 | + { |
|
| 412 | + // make sure we're checking the ee config |
|
| 413 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 414 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 415 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 416 | + if ($value != $old_value) { |
|
| 417 | + // if they are NOT the same, then remove the hook, |
|
| 418 | + // which means the subsequent update results will be based solely on the update query results |
|
| 419 | + // the reason we do this is because, as stated above, |
|
| 420 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 421 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 422 | + // If values are found to match their previous old value, |
|
| 423 | + // then WP bails before performing any update. |
|
| 424 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 425 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 426 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 427 | + // MySQL MAY ALSO NOT perform the update because |
|
| 428 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 429 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 430 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 431 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * update_espresso_config |
|
| 440 | + * |
|
| 441 | + * @access public |
|
| 442 | + */ |
|
| 443 | + protected function _reset_espresso_addon_config() |
|
| 444 | + { |
|
| 445 | + $this->_addon_option_names = array(); |
|
| 446 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 447 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 448 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 449 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 450 | + } |
|
| 451 | + $this->addons->{$addon_name} = null; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * update_espresso_config |
|
| 459 | + * |
|
| 460 | + * @access public |
|
| 461 | + * @param bool $add_success |
|
| 462 | + * @param bool $add_error |
|
| 463 | + * @return bool |
|
| 464 | + */ |
|
| 465 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 466 | + { |
|
| 467 | + // don't allow config updates during WP heartbeats |
|
| 468 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 469 | + return false; |
|
| 470 | + } |
|
| 471 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 472 | + //$clone = clone( self::$_instance ); |
|
| 473 | + //self::$_instance = NULL; |
|
| 474 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 475 | + $this->_reset_espresso_addon_config(); |
|
| 476 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 477 | + // but BEFORE the actual update occurs |
|
| 478 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 479 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 480 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 481 | + $this->legacy_shortcodes_manager = null; |
|
| 482 | + // now update "ee_config" |
|
| 483 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 484 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 485 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 486 | + // if not saved... check if the hook we just added still exists; |
|
| 487 | + // if it does, it means one of two things: |
|
| 488 | + // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 489 | + // or... |
|
| 490 | + // the db update query returned 0 rows affected |
|
| 491 | + // (probably because the data value was the same from it's perspective) |
|
| 492 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 493 | + // but just means no update occurred, so don't display an error to the user. |
|
| 494 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 495 | + // then it means that something truly went wrong |
|
| 496 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 497 | + // remove our action since we don't want it in the system anymore |
|
| 498 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 499 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 500 | + //self::$_instance = $clone; |
|
| 501 | + //unset( $clone ); |
|
| 502 | + // if config remains the same or was updated successfully |
|
| 503 | + if ($saved) { |
|
| 504 | + if ($add_success) { |
|
| 505 | + EE_Error::add_success( |
|
| 506 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 507 | + __FILE__, |
|
| 508 | + __FUNCTION__, |
|
| 509 | + __LINE__ |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + return true; |
|
| 513 | + } else { |
|
| 514 | + if ($add_error) { |
|
| 515 | + EE_Error::add_error( |
|
| 516 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 517 | + __FILE__, |
|
| 518 | + __FUNCTION__, |
|
| 519 | + __LINE__ |
|
| 520 | + ); |
|
| 521 | + } |
|
| 522 | + return false; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * _verify_config_params |
|
| 530 | + * |
|
| 531 | + * @access private |
|
| 532 | + * @param string $section |
|
| 533 | + * @param string $name |
|
| 534 | + * @param string $config_class |
|
| 535 | + * @param EE_Config_Base $config_obj |
|
| 536 | + * @param array $tests_to_run |
|
| 537 | + * @param bool $display_errors |
|
| 538 | + * @return bool TRUE on success, FALSE on fail |
|
| 539 | + */ |
|
| 540 | + private function _verify_config_params( |
|
| 541 | + $section = '', |
|
| 542 | + $name = '', |
|
| 543 | + $config_class = '', |
|
| 544 | + $config_obj = null, |
|
| 545 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 546 | + $display_errors = true |
|
| 547 | + ) { |
|
| 548 | + try { |
|
| 549 | + foreach ($tests_to_run as $test) { |
|
| 550 | + switch ($test) { |
|
| 551 | + // TEST #1 : check that section was set |
|
| 552 | + case 1 : |
|
| 553 | + if (empty($section)) { |
|
| 554 | + if ($display_errors) { |
|
| 555 | + throw new EE_Error( |
|
| 556 | + sprintf( |
|
| 557 | + __( |
|
| 558 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 559 | + 'event_espresso' |
|
| 560 | + ), |
|
| 561 | + $config_class |
|
| 562 | + ) |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + break; |
|
| 568 | + // TEST #2 : check that settings section exists |
|
| 569 | + case 2 : |
|
| 570 | + if (! isset($this->{$section})) { |
|
| 571 | + if ($display_errors) { |
|
| 572 | + throw new EE_Error( |
|
| 573 | + sprintf( |
|
| 574 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 575 | + $section |
|
| 576 | + ) |
|
| 577 | + ); |
|
| 578 | + } |
|
| 579 | + return false; |
|
| 580 | + } |
|
| 581 | + break; |
|
| 582 | + // TEST #3 : check that section is the proper format |
|
| 583 | + case 3 : |
|
| 584 | + if ( |
|
| 585 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 586 | + ) { |
|
| 587 | + if ($display_errors) { |
|
| 588 | + throw new EE_Error( |
|
| 589 | + sprintf( |
|
| 590 | + __( |
|
| 591 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 592 | + 'event_espresso' |
|
| 593 | + ), |
|
| 594 | + $section |
|
| 595 | + ) |
|
| 596 | + ); |
|
| 597 | + } |
|
| 598 | + return false; |
|
| 599 | + } |
|
| 600 | + break; |
|
| 601 | + // TEST #4 : check that config section name has been set |
|
| 602 | + case 4 : |
|
| 603 | + if (empty($name)) { |
|
| 604 | + if ($display_errors) { |
|
| 605 | + throw new EE_Error( |
|
| 606 | + __( |
|
| 607 | + 'No name has been provided for the specific configuration section.', |
|
| 608 | + 'event_espresso' |
|
| 609 | + ) |
|
| 610 | + ); |
|
| 611 | + } |
|
| 612 | + return false; |
|
| 613 | + } |
|
| 614 | + break; |
|
| 615 | + // TEST #5 : check that a config class name has been set |
|
| 616 | + case 5 : |
|
| 617 | + if (empty($config_class)) { |
|
| 618 | + if ($display_errors) { |
|
| 619 | + throw new EE_Error( |
|
| 620 | + __( |
|
| 621 | + 'No class name has been provided for the specific configuration section.', |
|
| 622 | + 'event_espresso' |
|
| 623 | + ) |
|
| 624 | + ); |
|
| 625 | + } |
|
| 626 | + return false; |
|
| 627 | + } |
|
| 628 | + break; |
|
| 629 | + // TEST #6 : verify config class is accessible |
|
| 630 | + case 6 : |
|
| 631 | + if (! class_exists($config_class)) { |
|
| 632 | + if ($display_errors) { |
|
| 633 | + throw new EE_Error( |
|
| 634 | + sprintf( |
|
| 635 | + __( |
|
| 636 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 637 | + 'event_espresso' |
|
| 638 | + ), |
|
| 639 | + $config_class |
|
| 640 | + ) |
|
| 641 | + ); |
|
| 642 | + } |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 645 | + break; |
|
| 646 | + // TEST #7 : check that config has even been set |
|
| 647 | + case 7 : |
|
| 648 | + if (! isset($this->{$section}->{$name})) { |
|
| 649 | + if ($display_errors) { |
|
| 650 | + throw new EE_Error( |
|
| 651 | + sprintf( |
|
| 652 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 653 | + $section, |
|
| 654 | + $name |
|
| 655 | + ) |
|
| 656 | + ); |
|
| 657 | + } |
|
| 658 | + return false; |
|
| 659 | + } else { |
|
| 660 | + // and make sure it's not serialized |
|
| 661 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 662 | + } |
|
| 663 | + break; |
|
| 664 | + // TEST #8 : check that config is the requested type |
|
| 665 | + case 8 : |
|
| 666 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 667 | + if ($display_errors) { |
|
| 668 | + throw new EE_Error( |
|
| 669 | + sprintf( |
|
| 670 | + __( |
|
| 671 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 672 | + 'event_espresso' |
|
| 673 | + ), |
|
| 674 | + $section, |
|
| 675 | + $name, |
|
| 676 | + $config_class |
|
| 677 | + ) |
|
| 678 | + ); |
|
| 679 | + } |
|
| 680 | + return false; |
|
| 681 | + } |
|
| 682 | + break; |
|
| 683 | + // TEST #9 : verify config object |
|
| 684 | + case 9 : |
|
| 685 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 686 | + if ($display_errors) { |
|
| 687 | + throw new EE_Error( |
|
| 688 | + sprintf( |
|
| 689 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 690 | + print_r($config_obj, true) |
|
| 691 | + ) |
|
| 692 | + ); |
|
| 693 | + } |
|
| 694 | + return false; |
|
| 695 | + } |
|
| 696 | + break; |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + } catch (EE_Error $e) { |
|
| 700 | + $e->get_error(); |
|
| 701 | + } |
|
| 702 | + // you have successfully run the gauntlet |
|
| 703 | + return true; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * _generate_config_option_name |
|
| 710 | + * |
|
| 711 | + * @access protected |
|
| 712 | + * @param string $section |
|
| 713 | + * @param string $name |
|
| 714 | + * @return string |
|
| 715 | + */ |
|
| 716 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 717 | + { |
|
| 718 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * _set_config_class |
|
| 725 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 726 | + * |
|
| 727 | + * @access private |
|
| 728 | + * @param string $config_class |
|
| 729 | + * @param string $name |
|
| 730 | + * @return string |
|
| 731 | + */ |
|
| 732 | + private function _set_config_class($config_class = '', $name = '') |
|
| 733 | + { |
|
| 734 | + return ! empty($config_class) |
|
| 735 | + ? $config_class |
|
| 736 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * set_config |
|
| 743 | + * |
|
| 744 | + * @access protected |
|
| 745 | + * @param string $section |
|
| 746 | + * @param string $name |
|
| 747 | + * @param string $config_class |
|
| 748 | + * @param EE_Config_Base $config_obj |
|
| 749 | + * @return EE_Config_Base |
|
| 750 | + */ |
|
| 751 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 752 | + { |
|
| 753 | + // ensure config class is set to something |
|
| 754 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 755 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 756 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 757 | + return null; |
|
| 758 | + } |
|
| 759 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 760 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 761 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 762 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 763 | + $this->update_addon_option_names(); |
|
| 764 | + } |
|
| 765 | + // verify the incoming config object but suppress errors |
|
| 766 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 767 | + $config_obj = new $config_class(); |
|
| 768 | + } |
|
| 769 | + if (get_option($config_option_name)) { |
|
| 770 | + EE_Config::log($config_option_name); |
|
| 771 | + update_option($config_option_name, $config_obj); |
|
| 772 | + $this->{$section}->{$name} = $config_obj; |
|
| 773 | + return $this->{$section}->{$name}; |
|
| 774 | + } else { |
|
| 775 | + // create a wp-option for this config |
|
| 776 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 777 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 778 | + return $this->{$section}->{$name}; |
|
| 779 | + } else { |
|
| 780 | + EE_Error::add_error( |
|
| 781 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 782 | + __FILE__, |
|
| 783 | + __FUNCTION__, |
|
| 784 | + __LINE__ |
|
| 785 | + ); |
|
| 786 | + return null; |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * update_config |
|
| 795 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 796 | + * |
|
| 797 | + * @access public |
|
| 798 | + * @param string $section |
|
| 799 | + * @param string $name |
|
| 800 | + * @param EE_Config_Base|string $config_obj |
|
| 801 | + * @param bool $throw_errors |
|
| 802 | + * @return bool |
|
| 803 | + */ |
|
| 804 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 805 | + { |
|
| 806 | + // don't allow config updates during WP heartbeats |
|
| 807 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + $config_obj = maybe_unserialize($config_obj); |
|
| 811 | + // get class name of the incoming object |
|
| 812 | + $config_class = get_class($config_obj); |
|
| 813 | + // run tests 1-5 and 9 to verify config |
|
| 814 | + if (! $this->_verify_config_params( |
|
| 815 | + $section, |
|
| 816 | + $name, |
|
| 817 | + $config_class, |
|
| 818 | + $config_obj, |
|
| 819 | + array(1, 2, 3, 4, 7, 9) |
|
| 820 | + ) |
|
| 821 | + ) { |
|
| 822 | + return false; |
|
| 823 | + } |
|
| 824 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 825 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 826 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 827 | + // save new config to db |
|
| 828 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 829 | + return true; |
|
| 830 | + } |
|
| 831 | + } else { |
|
| 832 | + // first check if the record already exists |
|
| 833 | + $existing_config = get_option($config_option_name); |
|
| 834 | + $config_obj = serialize($config_obj); |
|
| 835 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 836 | + if ($existing_config == $config_obj) { |
|
| 837 | + $this->{$section}->{$name} = $config_obj; |
|
| 838 | + return true; |
|
| 839 | + } else if (update_option($config_option_name, $config_obj)) { |
|
| 840 | + EE_Config::log($config_option_name); |
|
| 841 | + // update wp-option for this config class |
|
| 842 | + $this->{$section}->{$name} = $config_obj; |
|
| 843 | + return true; |
|
| 844 | + } elseif ($throw_errors) { |
|
| 845 | + EE_Error::add_error( |
|
| 846 | + sprintf( |
|
| 847 | + __( |
|
| 848 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 849 | + 'event_espresso' |
|
| 850 | + ), |
|
| 851 | + $config_class, |
|
| 852 | + 'EE_Config->' . $section . '->' . $name |
|
| 853 | + ), |
|
| 854 | + __FILE__, |
|
| 855 | + __FUNCTION__, |
|
| 856 | + __LINE__ |
|
| 857 | + ); |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | + return false; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * get_config |
|
| 867 | + * |
|
| 868 | + * @access public |
|
| 869 | + * @param string $section |
|
| 870 | + * @param string $name |
|
| 871 | + * @param string $config_class |
|
| 872 | + * @return mixed EE_Config_Base | NULL |
|
| 873 | + */ |
|
| 874 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 875 | + { |
|
| 876 | + // ensure config class is set to something |
|
| 877 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 878 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 879 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 880 | + return null; |
|
| 881 | + } |
|
| 882 | + // now test if the requested config object exists, but suppress errors |
|
| 883 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 884 | + // config already exists, so pass it back |
|
| 885 | + return $this->{$section}->{$name}; |
|
| 886 | + } |
|
| 887 | + // load config option from db if it exists |
|
| 888 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 889 | + // verify the newly retrieved config object, but suppress errors |
|
| 890 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 891 | + // config is good, so set it and pass it back |
|
| 892 | + $this->{$section}->{$name} = $config_obj; |
|
| 893 | + return $this->{$section}->{$name}; |
|
| 894 | + } |
|
| 895 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 896 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 897 | + // verify the newly created config object |
|
| 898 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 899 | + return $this->{$section}->{$name}; |
|
| 900 | + } else { |
|
| 901 | + EE_Error::add_error( |
|
| 902 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 903 | + __FILE__, |
|
| 904 | + __FUNCTION__, |
|
| 905 | + __LINE__ |
|
| 906 | + ); |
|
| 907 | + } |
|
| 908 | + return null; |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * get_config_option |
|
| 915 | + * |
|
| 916 | + * @access public |
|
| 917 | + * @param string $config_option_name |
|
| 918 | + * @return mixed EE_Config_Base | FALSE |
|
| 919 | + */ |
|
| 920 | + public function get_config_option($config_option_name = '') |
|
| 921 | + { |
|
| 922 | + // retrieve the wp-option for this config class. |
|
| 923 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 924 | + if (empty($config_option)) { |
|
| 925 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 926 | + } |
|
| 927 | + return $config_option; |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + |
|
| 932 | + /** |
|
| 933 | + * log |
|
| 934 | + * |
|
| 935 | + * @param string $config_option_name |
|
| 936 | + */ |
|
| 937 | + public static function log($config_option_name = '') |
|
| 938 | + { |
|
| 939 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 940 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 941 | + //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 942 | + $_request = $_REQUEST; |
|
| 943 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 944 | + $config_log[(string)microtime(true)] = array( |
|
| 945 | + 'config_name' => $config_option_name, |
|
| 946 | + 'request' => $_request, |
|
| 947 | + ); |
|
| 948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * trim_log |
|
| 956 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 957 | + */ |
|
| 958 | + public static function trim_log() |
|
| 959 | + { |
|
| 960 | + if (! EE_Config::logging_enabled()) { |
|
| 961 | + return; |
|
| 962 | + } |
|
| 963 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 964 | + $log_length = count($config_log); |
|
| 965 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 966 | + ksort($config_log); |
|
| 967 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 968 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 969 | + } |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * get_page_for_posts |
|
| 976 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 977 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 978 | + * |
|
| 979 | + * @access public |
|
| 980 | + * @return string |
|
| 981 | + */ |
|
| 982 | + public static function get_page_for_posts() |
|
| 983 | + { |
|
| 984 | + $page_for_posts = get_option('page_for_posts'); |
|
| 985 | + if (! $page_for_posts) { |
|
| 986 | + return 'posts'; |
|
| 987 | + } |
|
| 988 | + /** @type WPDB $wpdb */ |
|
| 989 | + global $wpdb; |
|
| 990 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 991 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * register_shortcodes_and_modules. |
|
| 998 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 999 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 1000 | + * so they can help trigger maintenance mode if it's needed |
|
| 1001 | + * |
|
| 1002 | + * @access public |
|
| 1003 | + * @return void |
|
| 1004 | + */ |
|
| 1005 | + public function register_shortcodes_and_modules() |
|
| 1006 | + { |
|
| 1007 | + // allow modules to set hooks for the rest of the system |
|
| 1008 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + |
|
| 1013 | + /** |
|
| 1014 | + * initialize_shortcodes_and_modules |
|
| 1015 | + * meaning they can start adding their hooks to get stuff done |
|
| 1016 | + * |
|
| 1017 | + * @access public |
|
| 1018 | + * @return void |
|
| 1019 | + */ |
|
| 1020 | + public function initialize_shortcodes_and_modules() |
|
| 1021 | + { |
|
| 1022 | + // allow modules to set hooks for the rest of the system |
|
| 1023 | + $this->_initialize_modules(); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * widgets_init |
|
| 1030 | + * |
|
| 1031 | + * @access private |
|
| 1032 | + * @return void |
|
| 1033 | + */ |
|
| 1034 | + public function widgets_init() |
|
| 1035 | + { |
|
| 1036 | + //only init widgets on admin pages when not in complete maintenance, and |
|
| 1037 | + //on frontend when not in any maintenance mode |
|
| 1038 | + if ( |
|
| 1039 | + ! EE_Maintenance_Mode::instance()->level() |
|
| 1040 | + || ( |
|
| 1041 | + is_admin() |
|
| 1042 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1043 | + ) |
|
| 1044 | + ) { |
|
| 1045 | + // grab list of installed widgets |
|
| 1046 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1047 | + // filter list of modules to register |
|
| 1048 | + $widgets_to_register = apply_filters( |
|
| 1049 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1050 | + $widgets_to_register |
|
| 1051 | + ); |
|
| 1052 | + if (! empty($widgets_to_register)) { |
|
| 1053 | + // cycle thru widget folders |
|
| 1054 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1055 | + // add to list of installed widget modules |
|
| 1056 | + EE_Config::register_ee_widget($widget_path); |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + // filter list of installed modules |
|
| 1060 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1061 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1062 | + EE_Registry::instance()->widgets |
|
| 1063 | + ); |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * register_ee_widget - makes core aware of this widget |
|
| 1071 | + * |
|
| 1072 | + * @access public |
|
| 1073 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1074 | + * @return void |
|
| 1075 | + */ |
|
| 1076 | + public static function register_ee_widget($widget_path = null) |
|
| 1077 | + { |
|
| 1078 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1079 | + $widget_ext = '.widget.php'; |
|
| 1080 | + // make all separators match |
|
| 1081 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1082 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1083 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1084 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1085 | + $file_name = explode('.', basename($widget_path)); |
|
| 1086 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1087 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1088 | + // sanitize shortcode directory name |
|
| 1089 | + $widget = sanitize_key($widget); |
|
| 1090 | + // now we need to rebuild the shortcode path |
|
| 1091 | + $widget_path = explode(DS, $widget_path); |
|
| 1092 | + // remove last segment |
|
| 1093 | + array_pop($widget_path); |
|
| 1094 | + // glue it back together |
|
| 1095 | + $widget_path = implode(DS, $widget_path); |
|
| 1096 | + } else { |
|
| 1097 | + // grab and sanitize widget directory name |
|
| 1098 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1099 | + } |
|
| 1100 | + // create classname from widget directory name |
|
| 1101 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1102 | + // add class prefix |
|
| 1103 | + $widget_class = 'EEW_' . $widget; |
|
| 1104 | + // does the widget exist ? |
|
| 1105 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1106 | + $msg = sprintf( |
|
| 1107 | + __( |
|
| 1108 | + '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', |
|
| 1109 | + 'event_espresso' |
|
| 1110 | + ), |
|
| 1111 | + $widget_class, |
|
| 1112 | + $widget_path . DS . $widget_class . $widget_ext |
|
| 1113 | + ); |
|
| 1114 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1115 | + return; |
|
| 1116 | + } |
|
| 1117 | + // load the widget class file |
|
| 1118 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1119 | + // verify that class exists |
|
| 1120 | + if (! class_exists($widget_class)) { |
|
| 1121 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1122 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1123 | + return; |
|
| 1124 | + } |
|
| 1125 | + register_widget($widget_class); |
|
| 1126 | + // add to array of registered widgets |
|
| 1127 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + /** |
|
| 1133 | + * _register_modules |
|
| 1134 | + * |
|
| 1135 | + * @access private |
|
| 1136 | + * @return array |
|
| 1137 | + */ |
|
| 1138 | + private function _register_modules() |
|
| 1139 | + { |
|
| 1140 | + // grab list of installed modules |
|
| 1141 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1142 | + // filter list of modules to register |
|
| 1143 | + $modules_to_register = apply_filters( |
|
| 1144 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1145 | + $modules_to_register |
|
| 1146 | + ); |
|
| 1147 | + if (! empty($modules_to_register)) { |
|
| 1148 | + // loop through folders |
|
| 1149 | + foreach ($modules_to_register as $module_path) { |
|
| 1150 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1151 | + if ( |
|
| 1152 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1153 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1154 | + ) { |
|
| 1155 | + // add to list of installed modules |
|
| 1156 | + EE_Config::register_module($module_path); |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + } |
|
| 1160 | + // filter list of installed modules |
|
| 1161 | + return apply_filters( |
|
| 1162 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1163 | + EE_Registry::instance()->modules |
|
| 1164 | + ); |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * register_module - makes core aware of this module |
|
| 1171 | + * |
|
| 1172 | + * @access public |
|
| 1173 | + * @param string $module_path - full path up to and including module folder |
|
| 1174 | + * @return bool |
|
| 1175 | + */ |
|
| 1176 | + public static function register_module($module_path = null) |
|
| 1177 | + { |
|
| 1178 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1179 | + $module_ext = '.module.php'; |
|
| 1180 | + // make all separators match |
|
| 1181 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1182 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1183 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1184 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1185 | + $module_file = explode('.', basename($module_path)); |
|
| 1186 | + // now we need to rebuild the shortcode path |
|
| 1187 | + $module_path = explode(DS, $module_path); |
|
| 1188 | + // remove last segment |
|
| 1189 | + array_pop($module_path); |
|
| 1190 | + // glue it back together |
|
| 1191 | + $module_path = implode(DS, $module_path) . DS; |
|
| 1192 | + // take first segment from file name pieces and sanitize it |
|
| 1193 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1194 | + // ensure class prefix is added |
|
| 1195 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1196 | + } else { |
|
| 1197 | + // we need to generate the filename based off of the folder name |
|
| 1198 | + // grab and sanitize module name |
|
| 1199 | + $module = strtolower(basename($module_path)); |
|
| 1200 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1201 | + // like trailingslashit() |
|
| 1202 | + $module_path = rtrim($module_path, DS) . DS; |
|
| 1203 | + // create classname from module directory name |
|
| 1204 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1205 | + // add class prefix |
|
| 1206 | + $module_class = 'EED_' . $module; |
|
| 1207 | + } |
|
| 1208 | + // does the module exist ? |
|
| 1209 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1210 | + $msg = sprintf( |
|
| 1211 | + __( |
|
| 1212 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1213 | + 'event_espresso' |
|
| 1214 | + ), |
|
| 1215 | + $module |
|
| 1216 | + ); |
|
| 1217 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1218 | + return false; |
|
| 1219 | + } |
|
| 1220 | + // load the module class file |
|
| 1221 | + require_once($module_path . $module_class . $module_ext); |
|
| 1222 | + // verify that class exists |
|
| 1223 | + if (! class_exists($module_class)) { |
|
| 1224 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1225 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1226 | + return false; |
|
| 1227 | + } |
|
| 1228 | + // add to array of registered modules |
|
| 1229 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1230 | + do_action( |
|
| 1231 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1232 | + $module_class, |
|
| 1233 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1234 | + ); |
|
| 1235 | + return true; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * _initialize_modules |
|
| 1242 | + * allow modules to set hooks for the rest of the system |
|
| 1243 | + * |
|
| 1244 | + * @access private |
|
| 1245 | + * @return void |
|
| 1246 | + */ |
|
| 1247 | + private function _initialize_modules() |
|
| 1248 | + { |
|
| 1249 | + // cycle thru shortcode folders |
|
| 1250 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1251 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1252 | + // which set hooks ? |
|
| 1253 | + if (is_admin()) { |
|
| 1254 | + // fire immediately |
|
| 1255 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1256 | + } else { |
|
| 1257 | + // delay until other systems are online |
|
| 1258 | + add_action( |
|
| 1259 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1260 | + array($module_class, 'set_hooks') |
|
| 1261 | + ); |
|
| 1262 | + } |
|
| 1263 | + } |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + |
|
| 1267 | + |
|
| 1268 | + /** |
|
| 1269 | + * register_route - adds module method routes to route_map |
|
| 1270 | + * |
|
| 1271 | + * @access public |
|
| 1272 | + * @param string $route - "pretty" public alias for module method |
|
| 1273 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1274 | + * @param string $method_name - the actual module method to be routed to |
|
| 1275 | + * @param string $key - url param key indicating a route is being called |
|
| 1276 | + * @return bool |
|
| 1277 | + */ |
|
| 1278 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1279 | + { |
|
| 1280 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1281 | + $module = str_replace('EED_', '', $module); |
|
| 1282 | + $module_class = 'EED_' . $module; |
|
| 1283 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1284 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1285 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1286 | + return false; |
|
| 1287 | + } |
|
| 1288 | + if (empty($route)) { |
|
| 1289 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1290 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1291 | + return false; |
|
| 1292 | + } |
|
| 1293 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1294 | + $msg = sprintf( |
|
| 1295 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1296 | + $route |
|
| 1297 | + ); |
|
| 1298 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1299 | + return false; |
|
| 1300 | + } |
|
| 1301 | + EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1302 | + return true; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * get_route - get module method route |
|
| 1309 | + * |
|
| 1310 | + * @access public |
|
| 1311 | + * @param string $route - "pretty" public alias for module method |
|
| 1312 | + * @param string $key - url param key indicating a route is being called |
|
| 1313 | + * @return string |
|
| 1314 | + */ |
|
| 1315 | + public static function get_route($route = null, $key = 'ee') |
|
| 1316 | + { |
|
| 1317 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1318 | + $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1319 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1320 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1321 | + } |
|
| 1322 | + return null; |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + |
|
| 1327 | + /** |
|
| 1328 | + * get_routes - get ALL module method routes |
|
| 1329 | + * |
|
| 1330 | + * @access public |
|
| 1331 | + * @return array |
|
| 1332 | + */ |
|
| 1333 | + public static function get_routes() |
|
| 1334 | + { |
|
| 1335 | + return EE_Config::$_module_route_map; |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + |
|
| 1339 | + |
|
| 1340 | + /** |
|
| 1341 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1342 | + * |
|
| 1343 | + * @access public |
|
| 1344 | + * @param string $route - "pretty" public alias for module method |
|
| 1345 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1346 | + * class, allows different forwards to be served based on status |
|
| 1347 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1348 | + * @param string $key - url param key indicating a route is being called |
|
| 1349 | + * @return bool |
|
| 1350 | + */ |
|
| 1351 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1352 | + { |
|
| 1353 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1354 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1355 | + $msg = sprintf( |
|
| 1356 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1357 | + $route |
|
| 1358 | + ); |
|
| 1359 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1360 | + return false; |
|
| 1361 | + } |
|
| 1362 | + if (empty($forward)) { |
|
| 1363 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1364 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1365 | + return false; |
|
| 1366 | + } |
|
| 1367 | + if (is_array($forward)) { |
|
| 1368 | + if (! isset($forward[1])) { |
|
| 1369 | + $msg = sprintf( |
|
| 1370 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1371 | + $route |
|
| 1372 | + ); |
|
| 1373 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1374 | + return false; |
|
| 1375 | + } |
|
| 1376 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1377 | + $msg = sprintf( |
|
| 1378 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1379 | + $forward[1], |
|
| 1380 | + $route |
|
| 1381 | + ); |
|
| 1382 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1383 | + return false; |
|
| 1384 | + } |
|
| 1385 | + } else if (! function_exists($forward)) { |
|
| 1386 | + $msg = sprintf( |
|
| 1387 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1388 | + $forward, |
|
| 1389 | + $route |
|
| 1390 | + ); |
|
| 1391 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1392 | + return false; |
|
| 1393 | + } |
|
| 1394 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1395 | + return true; |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + |
|
| 1399 | + |
|
| 1400 | + /** |
|
| 1401 | + * get_forward - get forwarding route |
|
| 1402 | + * |
|
| 1403 | + * @access public |
|
| 1404 | + * @param string $route - "pretty" public alias for module method |
|
| 1405 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1406 | + * allows different forwards to be served based on status |
|
| 1407 | + * @param string $key - url param key indicating a route is being called |
|
| 1408 | + * @return string |
|
| 1409 | + */ |
|
| 1410 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1411 | + { |
|
| 1412 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1413 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1414 | + return apply_filters( |
|
| 1415 | + 'FHEE__EE_Config__get_forward', |
|
| 1416 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1417 | + $route, |
|
| 1418 | + $status |
|
| 1419 | + ); |
|
| 1420 | + } |
|
| 1421 | + return null; |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1428 | + * results |
|
| 1429 | + * |
|
| 1430 | + * @access public |
|
| 1431 | + * @param string $route - "pretty" public alias for module method |
|
| 1432 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1433 | + * allows different views to be served based on status |
|
| 1434 | + * @param string $view |
|
| 1435 | + * @param string $key - url param key indicating a route is being called |
|
| 1436 | + * @return bool |
|
| 1437 | + */ |
|
| 1438 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1439 | + { |
|
| 1440 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1441 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1442 | + $msg = sprintf( |
|
| 1443 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1444 | + $route |
|
| 1445 | + ); |
|
| 1446 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1447 | + return false; |
|
| 1448 | + } |
|
| 1449 | + if (! is_readable($view)) { |
|
| 1450 | + $msg = sprintf( |
|
| 1451 | + __( |
|
| 1452 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1453 | + 'event_espresso' |
|
| 1454 | + ), |
|
| 1455 | + $view |
|
| 1456 | + ); |
|
| 1457 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1458 | + return false; |
|
| 1459 | + } |
|
| 1460 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1461 | + return true; |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * get_view - get view for route and status |
|
| 1468 | + * |
|
| 1469 | + * @access public |
|
| 1470 | + * @param string $route - "pretty" public alias for module method |
|
| 1471 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1472 | + * allows different views to be served based on status |
|
| 1473 | + * @param string $key - url param key indicating a route is being called |
|
| 1474 | + * @return string |
|
| 1475 | + */ |
|
| 1476 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1477 | + { |
|
| 1478 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1479 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1480 | + return apply_filters( |
|
| 1481 | + 'FHEE__EE_Config__get_view', |
|
| 1482 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1483 | + $route, |
|
| 1484 | + $status |
|
| 1485 | + ); |
|
| 1486 | + } |
|
| 1487 | + return null; |
|
| 1488 | + } |
|
| 1489 | + |
|
| 1490 | + |
|
| 1491 | + |
|
| 1492 | + public function update_addon_option_names() |
|
| 1493 | + { |
|
| 1494 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + |
|
| 1499 | + public function shutdown() |
|
| 1500 | + { |
|
| 1501 | + $this->update_addon_option_names(); |
|
| 1502 | + } |
|
| 1503 | + |
|
| 1504 | + |
|
| 1505 | + |
|
| 1506 | + /** |
|
| 1507 | + * @return LegacyShortcodesManager |
|
| 1508 | + */ |
|
| 1509 | + public static function getLegacyShortcodesManager() |
|
| 1510 | + { |
|
| 1511 | + |
|
| 1512 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1513 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1514 | + EE_Registry::instance() |
|
| 1515 | + ); |
|
| 1516 | + } |
|
| 1517 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + |
|
| 1521 | + |
|
| 1522 | + /** |
|
| 1523 | + * register_shortcode - makes core aware of this shortcode |
|
| 1524 | + * |
|
| 1525 | + * @deprecated 4.9.26 |
|
| 1526 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1527 | + * @return bool |
|
| 1528 | + */ |
|
| 1529 | + public static function register_shortcode($shortcode_path = null) |
|
| 1530 | + { |
|
| 1531 | + EE_Error::doing_it_wrong( |
|
| 1532 | + __METHOD__, |
|
| 1533 | + __( |
|
| 1534 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1535 | + 'event_espresso' |
|
| 1536 | + ), |
|
| 1537 | + '4.9.26' |
|
| 1538 | + ); |
|
| 1539 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1540 | + } |
|
| 21 | 1541 | |
| 22 | - const LOG_NAME = 'ee_config_log'; |
|
| 23 | 1542 | |
| 24 | - const LOG_LENGTH = 100; |
|
| 25 | 1543 | |
| 26 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * instance of the EE_Config object |
|
| 31 | - * |
|
| 32 | - * @var EE_Config $_instance |
|
| 33 | - * @access private |
|
| 34 | - */ |
|
| 35 | - private static $_instance; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var boolean $_logging_enabled |
|
| 39 | - */ |
|
| 40 | - private static $_logging_enabled = false; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 44 | - */ |
|
| 45 | - private $legacy_shortcodes_manager; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * An StdClass whose property names are addon slugs, |
|
| 49 | - * and values are their config classes |
|
| 50 | - * |
|
| 51 | - * @var StdClass |
|
| 52 | - */ |
|
| 53 | - public $addons; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var EE_Admin_Config |
|
| 57 | - */ |
|
| 58 | - public $admin; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var EE_Core_Config |
|
| 62 | - */ |
|
| 63 | - public $core; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var EE_Currency_Config |
|
| 67 | - */ |
|
| 68 | - public $currency; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var EE_Organization_Config |
|
| 72 | - */ |
|
| 73 | - public $organization; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var EE_Registration_Config |
|
| 77 | - */ |
|
| 78 | - public $registration; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var EE_Template_Config |
|
| 82 | - */ |
|
| 83 | - public $template_settings; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Holds EE environment values. |
|
| 87 | - * |
|
| 88 | - * @var EE_Environment_Config |
|
| 89 | - */ |
|
| 90 | - public $environment; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * settings pertaining to Google maps |
|
| 94 | - * |
|
| 95 | - * @var EE_Map_Config |
|
| 96 | - */ |
|
| 97 | - public $map_settings; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * settings pertaining to Taxes |
|
| 101 | - * |
|
| 102 | - * @var EE_Tax_Config |
|
| 103 | - */ |
|
| 104 | - public $tax_settings; |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Settings pertaining to global messages settings. |
|
| 109 | - * |
|
| 110 | - * @var EE_Messages_Config |
|
| 111 | - */ |
|
| 112 | - public $messages; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @deprecated |
|
| 116 | - * @var EE_Gateway_Config |
|
| 117 | - */ |
|
| 118 | - public $gateway; |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @var array $_addon_option_names |
|
| 122 | - * @access private |
|
| 123 | - */ |
|
| 124 | - private $_addon_option_names = array(); |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @var array $_module_route_map |
|
| 128 | - * @access private |
|
| 129 | - */ |
|
| 130 | - private static $_module_route_map = array(); |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @var array $_module_forward_map |
|
| 134 | - * @access private |
|
| 135 | - */ |
|
| 136 | - private static $_module_forward_map = array(); |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @var array $_module_view_map |
|
| 140 | - * @access private |
|
| 141 | - */ |
|
| 142 | - private static $_module_view_map = array(); |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @singleton method used to instantiate class object |
|
| 148 | - * @access public |
|
| 149 | - * @return EE_Config instance |
|
| 150 | - */ |
|
| 151 | - public static function instance() |
|
| 152 | - { |
|
| 153 | - // check if class object is instantiated, and instantiated properly |
|
| 154 | - if (! self::$_instance instanceof EE_Config) { |
|
| 155 | - self::$_instance = new self(); |
|
| 156 | - } |
|
| 157 | - return self::$_instance; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Resets the config |
|
| 164 | - * |
|
| 165 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 166 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 167 | - * reflect its state in the database |
|
| 168 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 169 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 170 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 171 | - * site was put into maintenance mode) |
|
| 172 | - * @return EE_Config |
|
| 173 | - */ |
|
| 174 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 175 | - { |
|
| 176 | - if (self::$_instance instanceof EE_Config) { |
|
| 177 | - if ($hard_reset) { |
|
| 178 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 179 | - self::$_instance->_addon_option_names = array(); |
|
| 180 | - self::$_instance->_initialize_config(); |
|
| 181 | - self::$_instance->update_espresso_config(); |
|
| 182 | - } |
|
| 183 | - self::$_instance->update_addon_option_names(); |
|
| 184 | - } |
|
| 185 | - self::$_instance = null; |
|
| 186 | - //we don't need to reset the static properties imo because those should |
|
| 187 | - //only change when a module is added or removed. Currently we don't |
|
| 188 | - //support removing a module during a request when it previously existed |
|
| 189 | - if ($reinstantiate) { |
|
| 190 | - return self::instance(); |
|
| 191 | - } else { |
|
| 192 | - return null; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * class constructor |
|
| 200 | - * |
|
| 201 | - * @access private |
|
| 202 | - */ |
|
| 203 | - private function __construct() |
|
| 204 | - { |
|
| 205 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 206 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 207 | - // setup empty config classes |
|
| 208 | - $this->_initialize_config(); |
|
| 209 | - // load existing EE site settings |
|
| 210 | - $this->_load_core_config(); |
|
| 211 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 212 | - $this->_verify_config(); |
|
| 213 | - // register shortcodes and modules |
|
| 214 | - add_action( |
|
| 215 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 216 | - array($this, 'register_shortcodes_and_modules'), |
|
| 217 | - 999 |
|
| 218 | - ); |
|
| 219 | - // initialize shortcodes and modules |
|
| 220 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 221 | - // register widgets |
|
| 222 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 223 | - // shutdown |
|
| 224 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 225 | - // construct__end hook |
|
| 226 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 227 | - // hardcoded hack |
|
| 228 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @return boolean |
|
| 235 | - */ |
|
| 236 | - public static function logging_enabled() |
|
| 237 | - { |
|
| 238 | - return self::$_logging_enabled; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * use to get the current theme if needed from static context |
|
| 245 | - * |
|
| 246 | - * @return string current theme set. |
|
| 247 | - */ |
|
| 248 | - public static function get_current_theme() |
|
| 249 | - { |
|
| 250 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 251 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * _initialize_config |
|
| 258 | - * |
|
| 259 | - * @access private |
|
| 260 | - * @return void |
|
| 261 | - */ |
|
| 262 | - private function _initialize_config() |
|
| 263 | - { |
|
| 264 | - EE_Config::trim_log(); |
|
| 265 | - //set defaults |
|
| 266 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 267 | - $this->addons = new stdClass(); |
|
| 268 | - // set _module_route_map |
|
| 269 | - EE_Config::$_module_route_map = array(); |
|
| 270 | - // set _module_forward_map |
|
| 271 | - EE_Config::$_module_forward_map = array(); |
|
| 272 | - // set _module_view_map |
|
| 273 | - EE_Config::$_module_view_map = array(); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * load core plugin configuration |
|
| 280 | - * |
|
| 281 | - * @access private |
|
| 282 | - * @return void |
|
| 283 | - */ |
|
| 284 | - private function _load_core_config() |
|
| 285 | - { |
|
| 286 | - // load_core_config__start hook |
|
| 287 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 288 | - $espresso_config = $this->get_espresso_config(); |
|
| 289 | - foreach ($espresso_config as $config => $settings) { |
|
| 290 | - // load_core_config__start hook |
|
| 291 | - $settings = apply_filters( |
|
| 292 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 293 | - $settings, |
|
| 294 | - $config, |
|
| 295 | - $this |
|
| 296 | - ); |
|
| 297 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 298 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 299 | - //call configs populate method to ensure any defaults are set for empty values. |
|
| 300 | - if (method_exists($settings, 'populate')) { |
|
| 301 | - $this->{$config}->populate(); |
|
| 302 | - } |
|
| 303 | - if (method_exists($settings, 'do_hooks')) { |
|
| 304 | - $this->{$config}->do_hooks(); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 309 | - $this->update_espresso_config(); |
|
| 310 | - } |
|
| 311 | - // load_core_config__end hook |
|
| 312 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * _verify_config |
|
| 319 | - * |
|
| 320 | - * @access protected |
|
| 321 | - * @return void |
|
| 322 | - */ |
|
| 323 | - protected function _verify_config() |
|
| 324 | - { |
|
| 325 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 326 | - ? $this->core |
|
| 327 | - : new EE_Core_Config(); |
|
| 328 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 329 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 330 | - ? $this->organization |
|
| 331 | - : new EE_Organization_Config(); |
|
| 332 | - $this->organization = apply_filters( |
|
| 333 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 334 | - $this->organization |
|
| 335 | - ); |
|
| 336 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 337 | - ? $this->currency |
|
| 338 | - : new EE_Currency_Config(); |
|
| 339 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 340 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 341 | - ? $this->registration |
|
| 342 | - : new EE_Registration_Config(); |
|
| 343 | - $this->registration = apply_filters( |
|
| 344 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 345 | - $this->registration |
|
| 346 | - ); |
|
| 347 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 348 | - ? $this->admin |
|
| 349 | - : new EE_Admin_Config(); |
|
| 350 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 351 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 352 | - ? $this->template_settings |
|
| 353 | - : new EE_Template_Config(); |
|
| 354 | - $this->template_settings = apply_filters( |
|
| 355 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 356 | - $this->template_settings |
|
| 357 | - ); |
|
| 358 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 359 | - ? $this->map_settings |
|
| 360 | - : new EE_Map_Config(); |
|
| 361 | - $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 362 | - $this->map_settings); |
|
| 363 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 364 | - ? $this->environment |
|
| 365 | - : new EE_Environment_Config(); |
|
| 366 | - $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 367 | - $this->environment); |
|
| 368 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 369 | - ? $this->tax_settings |
|
| 370 | - : new EE_Tax_Config(); |
|
| 371 | - $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 372 | - $this->tax_settings); |
|
| 373 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 374 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 375 | - ? $this->messages |
|
| 376 | - : new EE_Messages_Config(); |
|
| 377 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 378 | - ? $this->gateway |
|
| 379 | - : new EE_Gateway_Config(); |
|
| 380 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 381 | - $this->legacy_shortcodes_manager = null; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * get_espresso_config |
|
| 387 | - * |
|
| 388 | - * @access public |
|
| 389 | - * @return array of espresso config stuff |
|
| 390 | - */ |
|
| 391 | - public function get_espresso_config() |
|
| 392 | - { |
|
| 393 | - // grab espresso configuration |
|
| 394 | - return apply_filters( |
|
| 395 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 396 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 397 | - ); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * double_check_config_comparison |
|
| 404 | - * |
|
| 405 | - * @access public |
|
| 406 | - * @param string $option |
|
| 407 | - * @param $old_value |
|
| 408 | - * @param $value |
|
| 409 | - */ |
|
| 410 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 411 | - { |
|
| 412 | - // make sure we're checking the ee config |
|
| 413 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 414 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 415 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 416 | - if ($value != $old_value) { |
|
| 417 | - // if they are NOT the same, then remove the hook, |
|
| 418 | - // which means the subsequent update results will be based solely on the update query results |
|
| 419 | - // the reason we do this is because, as stated above, |
|
| 420 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 421 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 422 | - // If values are found to match their previous old value, |
|
| 423 | - // then WP bails before performing any update. |
|
| 424 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 425 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 426 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 427 | - // MySQL MAY ALSO NOT perform the update because |
|
| 428 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 429 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 430 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 431 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * update_espresso_config |
|
| 440 | - * |
|
| 441 | - * @access public |
|
| 442 | - */ |
|
| 443 | - protected function _reset_espresso_addon_config() |
|
| 444 | - { |
|
| 445 | - $this->_addon_option_names = array(); |
|
| 446 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 447 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 448 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 449 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 450 | - } |
|
| 451 | - $this->addons->{$addon_name} = null; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * update_espresso_config |
|
| 459 | - * |
|
| 460 | - * @access public |
|
| 461 | - * @param bool $add_success |
|
| 462 | - * @param bool $add_error |
|
| 463 | - * @return bool |
|
| 464 | - */ |
|
| 465 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 466 | - { |
|
| 467 | - // don't allow config updates during WP heartbeats |
|
| 468 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 469 | - return false; |
|
| 470 | - } |
|
| 471 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 472 | - //$clone = clone( self::$_instance ); |
|
| 473 | - //self::$_instance = NULL; |
|
| 474 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 475 | - $this->_reset_espresso_addon_config(); |
|
| 476 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 477 | - // but BEFORE the actual update occurs |
|
| 478 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 479 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 480 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 481 | - $this->legacy_shortcodes_manager = null; |
|
| 482 | - // now update "ee_config" |
|
| 483 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 484 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 485 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 486 | - // if not saved... check if the hook we just added still exists; |
|
| 487 | - // if it does, it means one of two things: |
|
| 488 | - // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 489 | - // or... |
|
| 490 | - // the db update query returned 0 rows affected |
|
| 491 | - // (probably because the data value was the same from it's perspective) |
|
| 492 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 493 | - // but just means no update occurred, so don't display an error to the user. |
|
| 494 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 495 | - // then it means that something truly went wrong |
|
| 496 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 497 | - // remove our action since we don't want it in the system anymore |
|
| 498 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 499 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 500 | - //self::$_instance = $clone; |
|
| 501 | - //unset( $clone ); |
|
| 502 | - // if config remains the same or was updated successfully |
|
| 503 | - if ($saved) { |
|
| 504 | - if ($add_success) { |
|
| 505 | - EE_Error::add_success( |
|
| 506 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 507 | - __FILE__, |
|
| 508 | - __FUNCTION__, |
|
| 509 | - __LINE__ |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - return true; |
|
| 513 | - } else { |
|
| 514 | - if ($add_error) { |
|
| 515 | - EE_Error::add_error( |
|
| 516 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 517 | - __FILE__, |
|
| 518 | - __FUNCTION__, |
|
| 519 | - __LINE__ |
|
| 520 | - ); |
|
| 521 | - } |
|
| 522 | - return false; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * _verify_config_params |
|
| 530 | - * |
|
| 531 | - * @access private |
|
| 532 | - * @param string $section |
|
| 533 | - * @param string $name |
|
| 534 | - * @param string $config_class |
|
| 535 | - * @param EE_Config_Base $config_obj |
|
| 536 | - * @param array $tests_to_run |
|
| 537 | - * @param bool $display_errors |
|
| 538 | - * @return bool TRUE on success, FALSE on fail |
|
| 539 | - */ |
|
| 540 | - private function _verify_config_params( |
|
| 541 | - $section = '', |
|
| 542 | - $name = '', |
|
| 543 | - $config_class = '', |
|
| 544 | - $config_obj = null, |
|
| 545 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 546 | - $display_errors = true |
|
| 547 | - ) { |
|
| 548 | - try { |
|
| 549 | - foreach ($tests_to_run as $test) { |
|
| 550 | - switch ($test) { |
|
| 551 | - // TEST #1 : check that section was set |
|
| 552 | - case 1 : |
|
| 553 | - if (empty($section)) { |
|
| 554 | - if ($display_errors) { |
|
| 555 | - throw new EE_Error( |
|
| 556 | - sprintf( |
|
| 557 | - __( |
|
| 558 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 559 | - 'event_espresso' |
|
| 560 | - ), |
|
| 561 | - $config_class |
|
| 562 | - ) |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - break; |
|
| 568 | - // TEST #2 : check that settings section exists |
|
| 569 | - case 2 : |
|
| 570 | - if (! isset($this->{$section})) { |
|
| 571 | - if ($display_errors) { |
|
| 572 | - throw new EE_Error( |
|
| 573 | - sprintf( |
|
| 574 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 575 | - $section |
|
| 576 | - ) |
|
| 577 | - ); |
|
| 578 | - } |
|
| 579 | - return false; |
|
| 580 | - } |
|
| 581 | - break; |
|
| 582 | - // TEST #3 : check that section is the proper format |
|
| 583 | - case 3 : |
|
| 584 | - if ( |
|
| 585 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 586 | - ) { |
|
| 587 | - if ($display_errors) { |
|
| 588 | - throw new EE_Error( |
|
| 589 | - sprintf( |
|
| 590 | - __( |
|
| 591 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 592 | - 'event_espresso' |
|
| 593 | - ), |
|
| 594 | - $section |
|
| 595 | - ) |
|
| 596 | - ); |
|
| 597 | - } |
|
| 598 | - return false; |
|
| 599 | - } |
|
| 600 | - break; |
|
| 601 | - // TEST #4 : check that config section name has been set |
|
| 602 | - case 4 : |
|
| 603 | - if (empty($name)) { |
|
| 604 | - if ($display_errors) { |
|
| 605 | - throw new EE_Error( |
|
| 606 | - __( |
|
| 607 | - 'No name has been provided for the specific configuration section.', |
|
| 608 | - 'event_espresso' |
|
| 609 | - ) |
|
| 610 | - ); |
|
| 611 | - } |
|
| 612 | - return false; |
|
| 613 | - } |
|
| 614 | - break; |
|
| 615 | - // TEST #5 : check that a config class name has been set |
|
| 616 | - case 5 : |
|
| 617 | - if (empty($config_class)) { |
|
| 618 | - if ($display_errors) { |
|
| 619 | - throw new EE_Error( |
|
| 620 | - __( |
|
| 621 | - 'No class name has been provided for the specific configuration section.', |
|
| 622 | - 'event_espresso' |
|
| 623 | - ) |
|
| 624 | - ); |
|
| 625 | - } |
|
| 626 | - return false; |
|
| 627 | - } |
|
| 628 | - break; |
|
| 629 | - // TEST #6 : verify config class is accessible |
|
| 630 | - case 6 : |
|
| 631 | - if (! class_exists($config_class)) { |
|
| 632 | - if ($display_errors) { |
|
| 633 | - throw new EE_Error( |
|
| 634 | - sprintf( |
|
| 635 | - __( |
|
| 636 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 637 | - 'event_espresso' |
|
| 638 | - ), |
|
| 639 | - $config_class |
|
| 640 | - ) |
|
| 641 | - ); |
|
| 642 | - } |
|
| 643 | - return false; |
|
| 644 | - } |
|
| 645 | - break; |
|
| 646 | - // TEST #7 : check that config has even been set |
|
| 647 | - case 7 : |
|
| 648 | - if (! isset($this->{$section}->{$name})) { |
|
| 649 | - if ($display_errors) { |
|
| 650 | - throw new EE_Error( |
|
| 651 | - sprintf( |
|
| 652 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 653 | - $section, |
|
| 654 | - $name |
|
| 655 | - ) |
|
| 656 | - ); |
|
| 657 | - } |
|
| 658 | - return false; |
|
| 659 | - } else { |
|
| 660 | - // and make sure it's not serialized |
|
| 661 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 662 | - } |
|
| 663 | - break; |
|
| 664 | - // TEST #8 : check that config is the requested type |
|
| 665 | - case 8 : |
|
| 666 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 667 | - if ($display_errors) { |
|
| 668 | - throw new EE_Error( |
|
| 669 | - sprintf( |
|
| 670 | - __( |
|
| 671 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 672 | - 'event_espresso' |
|
| 673 | - ), |
|
| 674 | - $section, |
|
| 675 | - $name, |
|
| 676 | - $config_class |
|
| 677 | - ) |
|
| 678 | - ); |
|
| 679 | - } |
|
| 680 | - return false; |
|
| 681 | - } |
|
| 682 | - break; |
|
| 683 | - // TEST #9 : verify config object |
|
| 684 | - case 9 : |
|
| 685 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 686 | - if ($display_errors) { |
|
| 687 | - throw new EE_Error( |
|
| 688 | - sprintf( |
|
| 689 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 690 | - print_r($config_obj, true) |
|
| 691 | - ) |
|
| 692 | - ); |
|
| 693 | - } |
|
| 694 | - return false; |
|
| 695 | - } |
|
| 696 | - break; |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - } catch (EE_Error $e) { |
|
| 700 | - $e->get_error(); |
|
| 701 | - } |
|
| 702 | - // you have successfully run the gauntlet |
|
| 703 | - return true; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * _generate_config_option_name |
|
| 710 | - * |
|
| 711 | - * @access protected |
|
| 712 | - * @param string $section |
|
| 713 | - * @param string $name |
|
| 714 | - * @return string |
|
| 715 | - */ |
|
| 716 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 717 | - { |
|
| 718 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * _set_config_class |
|
| 725 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 726 | - * |
|
| 727 | - * @access private |
|
| 728 | - * @param string $config_class |
|
| 729 | - * @param string $name |
|
| 730 | - * @return string |
|
| 731 | - */ |
|
| 732 | - private function _set_config_class($config_class = '', $name = '') |
|
| 733 | - { |
|
| 734 | - return ! empty($config_class) |
|
| 735 | - ? $config_class |
|
| 736 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * set_config |
|
| 743 | - * |
|
| 744 | - * @access protected |
|
| 745 | - * @param string $section |
|
| 746 | - * @param string $name |
|
| 747 | - * @param string $config_class |
|
| 748 | - * @param EE_Config_Base $config_obj |
|
| 749 | - * @return EE_Config_Base |
|
| 750 | - */ |
|
| 751 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 752 | - { |
|
| 753 | - // ensure config class is set to something |
|
| 754 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 755 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 756 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 757 | - return null; |
|
| 758 | - } |
|
| 759 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 760 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 761 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 762 | - $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 763 | - $this->update_addon_option_names(); |
|
| 764 | - } |
|
| 765 | - // verify the incoming config object but suppress errors |
|
| 766 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 767 | - $config_obj = new $config_class(); |
|
| 768 | - } |
|
| 769 | - if (get_option($config_option_name)) { |
|
| 770 | - EE_Config::log($config_option_name); |
|
| 771 | - update_option($config_option_name, $config_obj); |
|
| 772 | - $this->{$section}->{$name} = $config_obj; |
|
| 773 | - return $this->{$section}->{$name}; |
|
| 774 | - } else { |
|
| 775 | - // create a wp-option for this config |
|
| 776 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 777 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 778 | - return $this->{$section}->{$name}; |
|
| 779 | - } else { |
|
| 780 | - EE_Error::add_error( |
|
| 781 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 782 | - __FILE__, |
|
| 783 | - __FUNCTION__, |
|
| 784 | - __LINE__ |
|
| 785 | - ); |
|
| 786 | - return null; |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * update_config |
|
| 795 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 796 | - * |
|
| 797 | - * @access public |
|
| 798 | - * @param string $section |
|
| 799 | - * @param string $name |
|
| 800 | - * @param EE_Config_Base|string $config_obj |
|
| 801 | - * @param bool $throw_errors |
|
| 802 | - * @return bool |
|
| 803 | - */ |
|
| 804 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 805 | - { |
|
| 806 | - // don't allow config updates during WP heartbeats |
|
| 807 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - $config_obj = maybe_unserialize($config_obj); |
|
| 811 | - // get class name of the incoming object |
|
| 812 | - $config_class = get_class($config_obj); |
|
| 813 | - // run tests 1-5 and 9 to verify config |
|
| 814 | - if (! $this->_verify_config_params( |
|
| 815 | - $section, |
|
| 816 | - $name, |
|
| 817 | - $config_class, |
|
| 818 | - $config_obj, |
|
| 819 | - array(1, 2, 3, 4, 7, 9) |
|
| 820 | - ) |
|
| 821 | - ) { |
|
| 822 | - return false; |
|
| 823 | - } |
|
| 824 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 825 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 826 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 827 | - // save new config to db |
|
| 828 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 829 | - return true; |
|
| 830 | - } |
|
| 831 | - } else { |
|
| 832 | - // first check if the record already exists |
|
| 833 | - $existing_config = get_option($config_option_name); |
|
| 834 | - $config_obj = serialize($config_obj); |
|
| 835 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 836 | - if ($existing_config == $config_obj) { |
|
| 837 | - $this->{$section}->{$name} = $config_obj; |
|
| 838 | - return true; |
|
| 839 | - } else if (update_option($config_option_name, $config_obj)) { |
|
| 840 | - EE_Config::log($config_option_name); |
|
| 841 | - // update wp-option for this config class |
|
| 842 | - $this->{$section}->{$name} = $config_obj; |
|
| 843 | - return true; |
|
| 844 | - } elseif ($throw_errors) { |
|
| 845 | - EE_Error::add_error( |
|
| 846 | - sprintf( |
|
| 847 | - __( |
|
| 848 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 849 | - 'event_espresso' |
|
| 850 | - ), |
|
| 851 | - $config_class, |
|
| 852 | - 'EE_Config->' . $section . '->' . $name |
|
| 853 | - ), |
|
| 854 | - __FILE__, |
|
| 855 | - __FUNCTION__, |
|
| 856 | - __LINE__ |
|
| 857 | - ); |
|
| 858 | - } |
|
| 859 | - } |
|
| 860 | - return false; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * get_config |
|
| 867 | - * |
|
| 868 | - * @access public |
|
| 869 | - * @param string $section |
|
| 870 | - * @param string $name |
|
| 871 | - * @param string $config_class |
|
| 872 | - * @return mixed EE_Config_Base | NULL |
|
| 873 | - */ |
|
| 874 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 875 | - { |
|
| 876 | - // ensure config class is set to something |
|
| 877 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 878 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 879 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 880 | - return null; |
|
| 881 | - } |
|
| 882 | - // now test if the requested config object exists, but suppress errors |
|
| 883 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 884 | - // config already exists, so pass it back |
|
| 885 | - return $this->{$section}->{$name}; |
|
| 886 | - } |
|
| 887 | - // load config option from db if it exists |
|
| 888 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 889 | - // verify the newly retrieved config object, but suppress errors |
|
| 890 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 891 | - // config is good, so set it and pass it back |
|
| 892 | - $this->{$section}->{$name} = $config_obj; |
|
| 893 | - return $this->{$section}->{$name}; |
|
| 894 | - } |
|
| 895 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 896 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 897 | - // verify the newly created config object |
|
| 898 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 899 | - return $this->{$section}->{$name}; |
|
| 900 | - } else { |
|
| 901 | - EE_Error::add_error( |
|
| 902 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 903 | - __FILE__, |
|
| 904 | - __FUNCTION__, |
|
| 905 | - __LINE__ |
|
| 906 | - ); |
|
| 907 | - } |
|
| 908 | - return null; |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * get_config_option |
|
| 915 | - * |
|
| 916 | - * @access public |
|
| 917 | - * @param string $config_option_name |
|
| 918 | - * @return mixed EE_Config_Base | FALSE |
|
| 919 | - */ |
|
| 920 | - public function get_config_option($config_option_name = '') |
|
| 921 | - { |
|
| 922 | - // retrieve the wp-option for this config class. |
|
| 923 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 924 | - if (empty($config_option)) { |
|
| 925 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 926 | - } |
|
| 927 | - return $config_option; |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - |
|
| 932 | - /** |
|
| 933 | - * log |
|
| 934 | - * |
|
| 935 | - * @param string $config_option_name |
|
| 936 | - */ |
|
| 937 | - public static function log($config_option_name = '') |
|
| 938 | - { |
|
| 939 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 940 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 941 | - //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 942 | - $_request = $_REQUEST; |
|
| 943 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 944 | - $config_log[(string)microtime(true)] = array( |
|
| 945 | - 'config_name' => $config_option_name, |
|
| 946 | - 'request' => $_request, |
|
| 947 | - ); |
|
| 948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * trim_log |
|
| 956 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 957 | - */ |
|
| 958 | - public static function trim_log() |
|
| 959 | - { |
|
| 960 | - if (! EE_Config::logging_enabled()) { |
|
| 961 | - return; |
|
| 962 | - } |
|
| 963 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 964 | - $log_length = count($config_log); |
|
| 965 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 966 | - ksort($config_log); |
|
| 967 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 968 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 969 | - } |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * get_page_for_posts |
|
| 976 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 977 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 978 | - * |
|
| 979 | - * @access public |
|
| 980 | - * @return string |
|
| 981 | - */ |
|
| 982 | - public static function get_page_for_posts() |
|
| 983 | - { |
|
| 984 | - $page_for_posts = get_option('page_for_posts'); |
|
| 985 | - if (! $page_for_posts) { |
|
| 986 | - return 'posts'; |
|
| 987 | - } |
|
| 988 | - /** @type WPDB $wpdb */ |
|
| 989 | - global $wpdb; |
|
| 990 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 991 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - |
|
| 996 | - /** |
|
| 997 | - * register_shortcodes_and_modules. |
|
| 998 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 999 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 1000 | - * so they can help trigger maintenance mode if it's needed |
|
| 1001 | - * |
|
| 1002 | - * @access public |
|
| 1003 | - * @return void |
|
| 1004 | - */ |
|
| 1005 | - public function register_shortcodes_and_modules() |
|
| 1006 | - { |
|
| 1007 | - // allow modules to set hooks for the rest of the system |
|
| 1008 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - |
|
| 1013 | - /** |
|
| 1014 | - * initialize_shortcodes_and_modules |
|
| 1015 | - * meaning they can start adding their hooks to get stuff done |
|
| 1016 | - * |
|
| 1017 | - * @access public |
|
| 1018 | - * @return void |
|
| 1019 | - */ |
|
| 1020 | - public function initialize_shortcodes_and_modules() |
|
| 1021 | - { |
|
| 1022 | - // allow modules to set hooks for the rest of the system |
|
| 1023 | - $this->_initialize_modules(); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * widgets_init |
|
| 1030 | - * |
|
| 1031 | - * @access private |
|
| 1032 | - * @return void |
|
| 1033 | - */ |
|
| 1034 | - public function widgets_init() |
|
| 1035 | - { |
|
| 1036 | - //only init widgets on admin pages when not in complete maintenance, and |
|
| 1037 | - //on frontend when not in any maintenance mode |
|
| 1038 | - if ( |
|
| 1039 | - ! EE_Maintenance_Mode::instance()->level() |
|
| 1040 | - || ( |
|
| 1041 | - is_admin() |
|
| 1042 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1043 | - ) |
|
| 1044 | - ) { |
|
| 1045 | - // grab list of installed widgets |
|
| 1046 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1047 | - // filter list of modules to register |
|
| 1048 | - $widgets_to_register = apply_filters( |
|
| 1049 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1050 | - $widgets_to_register |
|
| 1051 | - ); |
|
| 1052 | - if (! empty($widgets_to_register)) { |
|
| 1053 | - // cycle thru widget folders |
|
| 1054 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1055 | - // add to list of installed widget modules |
|
| 1056 | - EE_Config::register_ee_widget($widget_path); |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - // filter list of installed modules |
|
| 1060 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1061 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1062 | - EE_Registry::instance()->widgets |
|
| 1063 | - ); |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * register_ee_widget - makes core aware of this widget |
|
| 1071 | - * |
|
| 1072 | - * @access public |
|
| 1073 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1074 | - * @return void |
|
| 1075 | - */ |
|
| 1076 | - public static function register_ee_widget($widget_path = null) |
|
| 1077 | - { |
|
| 1078 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1079 | - $widget_ext = '.widget.php'; |
|
| 1080 | - // make all separators match |
|
| 1081 | - $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1082 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1083 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1084 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1085 | - $file_name = explode('.', basename($widget_path)); |
|
| 1086 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1087 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1088 | - // sanitize shortcode directory name |
|
| 1089 | - $widget = sanitize_key($widget); |
|
| 1090 | - // now we need to rebuild the shortcode path |
|
| 1091 | - $widget_path = explode(DS, $widget_path); |
|
| 1092 | - // remove last segment |
|
| 1093 | - array_pop($widget_path); |
|
| 1094 | - // glue it back together |
|
| 1095 | - $widget_path = implode(DS, $widget_path); |
|
| 1096 | - } else { |
|
| 1097 | - // grab and sanitize widget directory name |
|
| 1098 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1099 | - } |
|
| 1100 | - // create classname from widget directory name |
|
| 1101 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1102 | - // add class prefix |
|
| 1103 | - $widget_class = 'EEW_' . $widget; |
|
| 1104 | - // does the widget exist ? |
|
| 1105 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1106 | - $msg = sprintf( |
|
| 1107 | - __( |
|
| 1108 | - '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', |
|
| 1109 | - 'event_espresso' |
|
| 1110 | - ), |
|
| 1111 | - $widget_class, |
|
| 1112 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1113 | - ); |
|
| 1114 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1115 | - return; |
|
| 1116 | - } |
|
| 1117 | - // load the widget class file |
|
| 1118 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1119 | - // verify that class exists |
|
| 1120 | - if (! class_exists($widget_class)) { |
|
| 1121 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1122 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1123 | - return; |
|
| 1124 | - } |
|
| 1125 | - register_widget($widget_class); |
|
| 1126 | - // add to array of registered widgets |
|
| 1127 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - /** |
|
| 1133 | - * _register_modules |
|
| 1134 | - * |
|
| 1135 | - * @access private |
|
| 1136 | - * @return array |
|
| 1137 | - */ |
|
| 1138 | - private function _register_modules() |
|
| 1139 | - { |
|
| 1140 | - // grab list of installed modules |
|
| 1141 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1142 | - // filter list of modules to register |
|
| 1143 | - $modules_to_register = apply_filters( |
|
| 1144 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1145 | - $modules_to_register |
|
| 1146 | - ); |
|
| 1147 | - if (! empty($modules_to_register)) { |
|
| 1148 | - // loop through folders |
|
| 1149 | - foreach ($modules_to_register as $module_path) { |
|
| 1150 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1151 | - if ( |
|
| 1152 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1153 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1154 | - ) { |
|
| 1155 | - // add to list of installed modules |
|
| 1156 | - EE_Config::register_module($module_path); |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - } |
|
| 1160 | - // filter list of installed modules |
|
| 1161 | - return apply_filters( |
|
| 1162 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1163 | - EE_Registry::instance()->modules |
|
| 1164 | - ); |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * register_module - makes core aware of this module |
|
| 1171 | - * |
|
| 1172 | - * @access public |
|
| 1173 | - * @param string $module_path - full path up to and including module folder |
|
| 1174 | - * @return bool |
|
| 1175 | - */ |
|
| 1176 | - public static function register_module($module_path = null) |
|
| 1177 | - { |
|
| 1178 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1179 | - $module_ext = '.module.php'; |
|
| 1180 | - // make all separators match |
|
| 1181 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1182 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1183 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1184 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1185 | - $module_file = explode('.', basename($module_path)); |
|
| 1186 | - // now we need to rebuild the shortcode path |
|
| 1187 | - $module_path = explode(DS, $module_path); |
|
| 1188 | - // remove last segment |
|
| 1189 | - array_pop($module_path); |
|
| 1190 | - // glue it back together |
|
| 1191 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1192 | - // take first segment from file name pieces and sanitize it |
|
| 1193 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1194 | - // ensure class prefix is added |
|
| 1195 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1196 | - } else { |
|
| 1197 | - // we need to generate the filename based off of the folder name |
|
| 1198 | - // grab and sanitize module name |
|
| 1199 | - $module = strtolower(basename($module_path)); |
|
| 1200 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1201 | - // like trailingslashit() |
|
| 1202 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1203 | - // create classname from module directory name |
|
| 1204 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1205 | - // add class prefix |
|
| 1206 | - $module_class = 'EED_' . $module; |
|
| 1207 | - } |
|
| 1208 | - // does the module exist ? |
|
| 1209 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1210 | - $msg = sprintf( |
|
| 1211 | - __( |
|
| 1212 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1213 | - 'event_espresso' |
|
| 1214 | - ), |
|
| 1215 | - $module |
|
| 1216 | - ); |
|
| 1217 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1218 | - return false; |
|
| 1219 | - } |
|
| 1220 | - // load the module class file |
|
| 1221 | - require_once($module_path . $module_class . $module_ext); |
|
| 1222 | - // verify that class exists |
|
| 1223 | - if (! class_exists($module_class)) { |
|
| 1224 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1225 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1226 | - return false; |
|
| 1227 | - } |
|
| 1228 | - // add to array of registered modules |
|
| 1229 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1230 | - do_action( |
|
| 1231 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1232 | - $module_class, |
|
| 1233 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1234 | - ); |
|
| 1235 | - return true; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * _initialize_modules |
|
| 1242 | - * allow modules to set hooks for the rest of the system |
|
| 1243 | - * |
|
| 1244 | - * @access private |
|
| 1245 | - * @return void |
|
| 1246 | - */ |
|
| 1247 | - private function _initialize_modules() |
|
| 1248 | - { |
|
| 1249 | - // cycle thru shortcode folders |
|
| 1250 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1251 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1252 | - // which set hooks ? |
|
| 1253 | - if (is_admin()) { |
|
| 1254 | - // fire immediately |
|
| 1255 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1256 | - } else { |
|
| 1257 | - // delay until other systems are online |
|
| 1258 | - add_action( |
|
| 1259 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1260 | - array($module_class, 'set_hooks') |
|
| 1261 | - ); |
|
| 1262 | - } |
|
| 1263 | - } |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - |
|
| 1267 | - |
|
| 1268 | - /** |
|
| 1269 | - * register_route - adds module method routes to route_map |
|
| 1270 | - * |
|
| 1271 | - * @access public |
|
| 1272 | - * @param string $route - "pretty" public alias for module method |
|
| 1273 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1274 | - * @param string $method_name - the actual module method to be routed to |
|
| 1275 | - * @param string $key - url param key indicating a route is being called |
|
| 1276 | - * @return bool |
|
| 1277 | - */ |
|
| 1278 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1279 | - { |
|
| 1280 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1281 | - $module = str_replace('EED_', '', $module); |
|
| 1282 | - $module_class = 'EED_' . $module; |
|
| 1283 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1284 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1285 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1286 | - return false; |
|
| 1287 | - } |
|
| 1288 | - if (empty($route)) { |
|
| 1289 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1290 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1291 | - return false; |
|
| 1292 | - } |
|
| 1293 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1294 | - $msg = sprintf( |
|
| 1295 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1296 | - $route |
|
| 1297 | - ); |
|
| 1298 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1299 | - return false; |
|
| 1300 | - } |
|
| 1301 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1302 | - return true; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * get_route - get module method route |
|
| 1309 | - * |
|
| 1310 | - * @access public |
|
| 1311 | - * @param string $route - "pretty" public alias for module method |
|
| 1312 | - * @param string $key - url param key indicating a route is being called |
|
| 1313 | - * @return string |
|
| 1314 | - */ |
|
| 1315 | - public static function get_route($route = null, $key = 'ee') |
|
| 1316 | - { |
|
| 1317 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1318 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1319 | - if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1320 | - return EE_Config::$_module_route_map[$key][$route]; |
|
| 1321 | - } |
|
| 1322 | - return null; |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - |
|
| 1327 | - /** |
|
| 1328 | - * get_routes - get ALL module method routes |
|
| 1329 | - * |
|
| 1330 | - * @access public |
|
| 1331 | - * @return array |
|
| 1332 | - */ |
|
| 1333 | - public static function get_routes() |
|
| 1334 | - { |
|
| 1335 | - return EE_Config::$_module_route_map; |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - |
|
| 1339 | - |
|
| 1340 | - /** |
|
| 1341 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1342 | - * |
|
| 1343 | - * @access public |
|
| 1344 | - * @param string $route - "pretty" public alias for module method |
|
| 1345 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1346 | - * class, allows different forwards to be served based on status |
|
| 1347 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1348 | - * @param string $key - url param key indicating a route is being called |
|
| 1349 | - * @return bool |
|
| 1350 | - */ |
|
| 1351 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1352 | - { |
|
| 1353 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1354 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1355 | - $msg = sprintf( |
|
| 1356 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1357 | - $route |
|
| 1358 | - ); |
|
| 1359 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1360 | - return false; |
|
| 1361 | - } |
|
| 1362 | - if (empty($forward)) { |
|
| 1363 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1364 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1365 | - return false; |
|
| 1366 | - } |
|
| 1367 | - if (is_array($forward)) { |
|
| 1368 | - if (! isset($forward[1])) { |
|
| 1369 | - $msg = sprintf( |
|
| 1370 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1371 | - $route |
|
| 1372 | - ); |
|
| 1373 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1374 | - return false; |
|
| 1375 | - } |
|
| 1376 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1377 | - $msg = sprintf( |
|
| 1378 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1379 | - $forward[1], |
|
| 1380 | - $route |
|
| 1381 | - ); |
|
| 1382 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1383 | - return false; |
|
| 1384 | - } |
|
| 1385 | - } else if (! function_exists($forward)) { |
|
| 1386 | - $msg = sprintf( |
|
| 1387 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1388 | - $forward, |
|
| 1389 | - $route |
|
| 1390 | - ); |
|
| 1391 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1392 | - return false; |
|
| 1393 | - } |
|
| 1394 | - EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1395 | - return true; |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - |
|
| 1399 | - |
|
| 1400 | - /** |
|
| 1401 | - * get_forward - get forwarding route |
|
| 1402 | - * |
|
| 1403 | - * @access public |
|
| 1404 | - * @param string $route - "pretty" public alias for module method |
|
| 1405 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1406 | - * allows different forwards to be served based on status |
|
| 1407 | - * @param string $key - url param key indicating a route is being called |
|
| 1408 | - * @return string |
|
| 1409 | - */ |
|
| 1410 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1411 | - { |
|
| 1412 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1413 | - if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1414 | - return apply_filters( |
|
| 1415 | - 'FHEE__EE_Config__get_forward', |
|
| 1416 | - EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1417 | - $route, |
|
| 1418 | - $status |
|
| 1419 | - ); |
|
| 1420 | - } |
|
| 1421 | - return null; |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1428 | - * results |
|
| 1429 | - * |
|
| 1430 | - * @access public |
|
| 1431 | - * @param string $route - "pretty" public alias for module method |
|
| 1432 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1433 | - * allows different views to be served based on status |
|
| 1434 | - * @param string $view |
|
| 1435 | - * @param string $key - url param key indicating a route is being called |
|
| 1436 | - * @return bool |
|
| 1437 | - */ |
|
| 1438 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1439 | - { |
|
| 1440 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1441 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1442 | - $msg = sprintf( |
|
| 1443 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1444 | - $route |
|
| 1445 | - ); |
|
| 1446 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1447 | - return false; |
|
| 1448 | - } |
|
| 1449 | - if (! is_readable($view)) { |
|
| 1450 | - $msg = sprintf( |
|
| 1451 | - __( |
|
| 1452 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1453 | - 'event_espresso' |
|
| 1454 | - ), |
|
| 1455 | - $view |
|
| 1456 | - ); |
|
| 1457 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1458 | - return false; |
|
| 1459 | - } |
|
| 1460 | - EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1461 | - return true; |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * get_view - get view for route and status |
|
| 1468 | - * |
|
| 1469 | - * @access public |
|
| 1470 | - * @param string $route - "pretty" public alias for module method |
|
| 1471 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1472 | - * allows different views to be served based on status |
|
| 1473 | - * @param string $key - url param key indicating a route is being called |
|
| 1474 | - * @return string |
|
| 1475 | - */ |
|
| 1476 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1477 | - { |
|
| 1478 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1479 | - if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1480 | - return apply_filters( |
|
| 1481 | - 'FHEE__EE_Config__get_view', |
|
| 1482 | - EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1483 | - $route, |
|
| 1484 | - $status |
|
| 1485 | - ); |
|
| 1486 | - } |
|
| 1487 | - return null; |
|
| 1488 | - } |
|
| 1489 | - |
|
| 1490 | - |
|
| 1491 | - |
|
| 1492 | - public function update_addon_option_names() |
|
| 1493 | - { |
|
| 1494 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - |
|
| 1499 | - public function shutdown() |
|
| 1500 | - { |
|
| 1501 | - $this->update_addon_option_names(); |
|
| 1502 | - } |
|
| 1503 | - |
|
| 1504 | - |
|
| 1505 | - |
|
| 1506 | - /** |
|
| 1507 | - * @return LegacyShortcodesManager |
|
| 1508 | - */ |
|
| 1509 | - public static function getLegacyShortcodesManager() |
|
| 1510 | - { |
|
| 1511 | - |
|
| 1512 | - if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1513 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1514 | - EE_Registry::instance() |
|
| 1515 | - ); |
|
| 1516 | - } |
|
| 1517 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - |
|
| 1521 | - |
|
| 1522 | - /** |
|
| 1523 | - * register_shortcode - makes core aware of this shortcode |
|
| 1524 | - * |
|
| 1525 | - * @deprecated 4.9.26 |
|
| 1526 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1527 | - * @return bool |
|
| 1528 | - */ |
|
| 1529 | - public static function register_shortcode($shortcode_path = null) |
|
| 1530 | - { |
|
| 1531 | - EE_Error::doing_it_wrong( |
|
| 1532 | - __METHOD__, |
|
| 1533 | - __( |
|
| 1534 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1535 | - 'event_espresso' |
|
| 1536 | - ), |
|
| 1537 | - '4.9.26' |
|
| 1538 | - ); |
|
| 1539 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - |
|
| 1543 | - |
|
| 1544 | -} |
|
| 1545 | - |
|
| 1546 | - |
|
| 1547 | - |
|
| 1548 | -/** |
|
| 1549 | - * Base class used for config classes. These classes should generally not have |
|
| 1550 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1551 | - * basically, they should just be well-defined stdClasses |
|
| 1552 | - */ |
|
| 1553 | -class EE_Config_Base |
|
| 1554 | -{ |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * Utility function for escaping the value of a property and returning. |
|
| 1558 | - * |
|
| 1559 | - * @param string $property property name (checks to see if exists). |
|
| 1560 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1561 | - * @throws \EE_Error |
|
| 1562 | - */ |
|
| 1563 | - public function get_pretty($property) |
|
| 1564 | - { |
|
| 1565 | - if (! property_exists($this, $property)) { |
|
| 1566 | - throw new EE_Error( |
|
| 1567 | - sprintf( |
|
| 1568 | - __( |
|
| 1569 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1570 | - 'event_espresso' |
|
| 1571 | - ), |
|
| 1572 | - get_class($this), |
|
| 1573 | - $property |
|
| 1574 | - ) |
|
| 1575 | - ); |
|
| 1576 | - } |
|
| 1577 | - //just handling escaping of strings for now. |
|
| 1578 | - if (is_string($this->{$property})) { |
|
| 1579 | - return stripslashes($this->{$property}); |
|
| 1580 | - } |
|
| 1581 | - return $this->{$property}; |
|
| 1582 | - } |
|
| 1583 | - |
|
| 1584 | - |
|
| 1585 | - |
|
| 1586 | - public function populate() |
|
| 1587 | - { |
|
| 1588 | - //grab defaults via a new instance of this class. |
|
| 1589 | - $class_name = get_class($this); |
|
| 1590 | - $defaults = new $class_name; |
|
| 1591 | - //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1592 | - //default from our $defaults object. |
|
| 1593 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1594 | - if ($this->{$property} === null) { |
|
| 1595 | - $this->{$property} = $value; |
|
| 1596 | - } |
|
| 1597 | - } |
|
| 1598 | - //cleanup |
|
| 1599 | - unset($defaults); |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * __isset |
|
| 1606 | - * |
|
| 1607 | - * @param $a |
|
| 1608 | - * @return bool |
|
| 1609 | - */ |
|
| 1610 | - public function __isset($a) |
|
| 1611 | - { |
|
| 1612 | - return false; |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - |
|
| 1616 | - |
|
| 1617 | - /** |
|
| 1618 | - * __unset |
|
| 1619 | - * |
|
| 1620 | - * @param $a |
|
| 1621 | - * @return bool |
|
| 1622 | - */ |
|
| 1623 | - public function __unset($a) |
|
| 1624 | - { |
|
| 1625 | - return false; |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * __clone |
|
| 1632 | - */ |
|
| 1633 | - public function __clone() |
|
| 1634 | - { |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - |
|
| 1638 | - |
|
| 1639 | - /** |
|
| 1640 | - * __wakeup |
|
| 1641 | - */ |
|
| 1642 | - public function __wakeup() |
|
| 1643 | - { |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * __destruct |
|
| 1650 | - */ |
|
| 1651 | - public function __destruct() |
|
| 1652 | - { |
|
| 1653 | - } |
|
| 1654 | -} |
|
| 1655 | - |
|
| 1656 | - |
|
| 1657 | - |
|
| 1658 | -/** |
|
| 1659 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1660 | - */ |
|
| 1661 | -class EE_Core_Config extends EE_Config_Base |
|
| 1662 | -{ |
|
| 1663 | - |
|
| 1664 | - public $current_blog_id; |
|
| 1665 | - |
|
| 1666 | - public $ee_ueip_optin; |
|
| 1667 | - |
|
| 1668 | - public $ee_ueip_has_notified; |
|
| 1669 | - |
|
| 1670 | - /** |
|
| 1671 | - * Not to be confused with the 4 critical page variables (See |
|
| 1672 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1673 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1674 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1675 | - * |
|
| 1676 | - * @var array |
|
| 1677 | - */ |
|
| 1678 | - public $post_shortcodes; |
|
| 1679 | - |
|
| 1680 | - public $module_route_map; |
|
| 1681 | - |
|
| 1682 | - public $module_forward_map; |
|
| 1683 | - |
|
| 1684 | - public $module_view_map; |
|
| 1685 | - |
|
| 1686 | - /** |
|
| 1687 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1688 | - * |
|
| 1689 | - * @var int |
|
| 1690 | - */ |
|
| 1691 | - public $reg_page_id; |
|
| 1692 | - |
|
| 1693 | - public $txn_page_id; |
|
| 1694 | - |
|
| 1695 | - public $thank_you_page_id; |
|
| 1696 | - |
|
| 1697 | - public $cancel_page_id; |
|
| 1698 | - |
|
| 1699 | - /** |
|
| 1700 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1701 | - * |
|
| 1702 | - * @var int |
|
| 1703 | - */ |
|
| 1704 | - public $reg_page_url; |
|
| 1705 | - |
|
| 1706 | - public $txn_page_url; |
|
| 1707 | - |
|
| 1708 | - public $thank_you_page_url; |
|
| 1709 | - |
|
| 1710 | - public $cancel_page_url; |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1714 | - */ |
|
| 1715 | - public $event_cpt_slug; |
|
| 1716 | - |
|
| 1717 | - |
|
| 1718 | - /** |
|
| 1719 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1720 | - * request across blog switches in a multisite context. |
|
| 1721 | - * Avoids extra queries to the db for this option. |
|
| 1722 | - * |
|
| 1723 | - * @var bool |
|
| 1724 | - */ |
|
| 1725 | - public static $ee_ueip_option; |
|
| 1726 | - |
|
| 1727 | - |
|
| 1728 | - |
|
| 1729 | - /** |
|
| 1730 | - * class constructor |
|
| 1731 | - * |
|
| 1732 | - * @access public |
|
| 1733 | - */ |
|
| 1734 | - public function __construct() |
|
| 1735 | - { |
|
| 1736 | - // set default organization settings |
|
| 1737 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1738 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1739 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1740 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1741 | - $this->post_shortcodes = array(); |
|
| 1742 | - $this->module_route_map = array(); |
|
| 1743 | - $this->module_forward_map = array(); |
|
| 1744 | - $this->module_view_map = array(); |
|
| 1745 | - // critical EE page IDs |
|
| 1746 | - $this->reg_page_id = 0; |
|
| 1747 | - $this->txn_page_id = 0; |
|
| 1748 | - $this->thank_you_page_id = 0; |
|
| 1749 | - $this->cancel_page_id = 0; |
|
| 1750 | - // critical EE page URLs |
|
| 1751 | - $this->reg_page_url = ''; |
|
| 1752 | - $this->txn_page_url = ''; |
|
| 1753 | - $this->thank_you_page_url = ''; |
|
| 1754 | - $this->cancel_page_url = ''; |
|
| 1755 | - //cpt slugs |
|
| 1756 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1757 | - //ueip constant check |
|
| 1758 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1759 | - $this->ee_ueip_optin = false; |
|
| 1760 | - $this->ee_ueip_has_notified = true; |
|
| 1761 | - } |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - |
|
| 1765 | - |
|
| 1766 | - /** |
|
| 1767 | - * @return array |
|
| 1768 | - */ |
|
| 1769 | - public function get_critical_pages_array() |
|
| 1770 | - { |
|
| 1771 | - return array( |
|
| 1772 | - $this->reg_page_id, |
|
| 1773 | - $this->txn_page_id, |
|
| 1774 | - $this->thank_you_page_id, |
|
| 1775 | - $this->cancel_page_id, |
|
| 1776 | - ); |
|
| 1777 | - } |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - |
|
| 1781 | - /** |
|
| 1782 | - * @return array |
|
| 1783 | - */ |
|
| 1784 | - public function get_critical_pages_shortcodes_array() |
|
| 1785 | - { |
|
| 1786 | - return array( |
|
| 1787 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1788 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1789 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1790 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1791 | - ); |
|
| 1792 | - } |
|
| 1793 | - |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - /** |
|
| 1797 | - * gets/returns URL for EE reg_page |
|
| 1798 | - * |
|
| 1799 | - * @access public |
|
| 1800 | - * @return string |
|
| 1801 | - */ |
|
| 1802 | - public function reg_page_url() |
|
| 1803 | - { |
|
| 1804 | - if (! $this->reg_page_url) { |
|
| 1805 | - $this->reg_page_url = add_query_arg( |
|
| 1806 | - array('uts' => time()), |
|
| 1807 | - get_permalink($this->reg_page_id) |
|
| 1808 | - ) . '#checkout'; |
|
| 1809 | - } |
|
| 1810 | - return $this->reg_page_url; |
|
| 1811 | - } |
|
| 1812 | - |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - /** |
|
| 1816 | - * gets/returns URL for EE txn_page |
|
| 1817 | - * |
|
| 1818 | - * @param array $query_args like what gets passed to |
|
| 1819 | - * add_query_arg() as the first argument |
|
| 1820 | - * @access public |
|
| 1821 | - * @return string |
|
| 1822 | - */ |
|
| 1823 | - public function txn_page_url($query_args = array()) |
|
| 1824 | - { |
|
| 1825 | - if (! $this->txn_page_url) { |
|
| 1826 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1827 | - } |
|
| 1828 | - if ($query_args) { |
|
| 1829 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1830 | - } else { |
|
| 1831 | - return $this->txn_page_url; |
|
| 1832 | - } |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - |
|
| 1836 | - |
|
| 1837 | - /** |
|
| 1838 | - * gets/returns URL for EE thank_you_page |
|
| 1839 | - * |
|
| 1840 | - * @param array $query_args like what gets passed to |
|
| 1841 | - * add_query_arg() as the first argument |
|
| 1842 | - * @access public |
|
| 1843 | - * @return string |
|
| 1844 | - */ |
|
| 1845 | - public function thank_you_page_url($query_args = array()) |
|
| 1846 | - { |
|
| 1847 | - if (! $this->thank_you_page_url) { |
|
| 1848 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1849 | - } |
|
| 1850 | - if ($query_args) { |
|
| 1851 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1852 | - } else { |
|
| 1853 | - return $this->thank_you_page_url; |
|
| 1854 | - } |
|
| 1855 | - } |
|
| 1856 | - |
|
| 1857 | - |
|
| 1858 | - |
|
| 1859 | - /** |
|
| 1860 | - * gets/returns URL for EE cancel_page |
|
| 1861 | - * |
|
| 1862 | - * @access public |
|
| 1863 | - * @return string |
|
| 1864 | - */ |
|
| 1865 | - public function cancel_page_url() |
|
| 1866 | - { |
|
| 1867 | - if (! $this->cancel_page_url) { |
|
| 1868 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1869 | - } |
|
| 1870 | - return $this->cancel_page_url; |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - |
|
| 1874 | - |
|
| 1875 | - /** |
|
| 1876 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1877 | - * |
|
| 1878 | - * @since 4.7.5 |
|
| 1879 | - */ |
|
| 1880 | - protected function _reset_urls() |
|
| 1881 | - { |
|
| 1882 | - $this->reg_page_url = ''; |
|
| 1883 | - $this->txn_page_url = ''; |
|
| 1884 | - $this->cancel_page_url = ''; |
|
| 1885 | - $this->thank_you_page_url = ''; |
|
| 1886 | - } |
|
| 1887 | - |
|
| 1888 | - |
|
| 1889 | - |
|
| 1890 | - /** |
|
| 1891 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1892 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1893 | - * on the main site only. |
|
| 1894 | - * |
|
| 1895 | - * @return mixed|void |
|
| 1896 | - */ |
|
| 1897 | - protected function _get_main_ee_ueip_optin() |
|
| 1898 | - { |
|
| 1899 | - //if this is the main site then we can just bypass our direct query. |
|
| 1900 | - if (is_main_site()) { |
|
| 1901 | - return get_option('ee_ueip_optin', false); |
|
| 1902 | - } |
|
| 1903 | - //is this already cached for this request? If so use it. |
|
| 1904 | - if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1905 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1906 | - } |
|
| 1907 | - global $wpdb; |
|
| 1908 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1909 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1910 | - $option = 'ee_ueip_optin'; |
|
| 1911 | - //set correct table for query |
|
| 1912 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1913 | - //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1914 | - //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1915 | - //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1916 | - //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1917 | - //for the purpose of caching. |
|
| 1918 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1919 | - if (false !== $pre) { |
|
| 1920 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1921 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1922 | - } |
|
| 1923 | - $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1924 | - $option)); |
|
| 1925 | - if (is_object($row)) { |
|
| 1926 | - $value = $row->option_value; |
|
| 1927 | - } else { //option does not exist so use default. |
|
| 1928 | - return apply_filters('default_option_' . $option, false, $option); |
|
| 1929 | - } |
|
| 1930 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1931 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - /** |
|
| 1935 | - * Utility function for escaping the value of a property and returning. |
|
| 1936 | - * |
|
| 1937 | - * @param string $property property name (checks to see if exists). |
|
| 1938 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1939 | - * @throws \EE_Error |
|
| 1940 | - */ |
|
| 1941 | - public function get_pretty($property) |
|
| 1942 | - { |
|
| 1943 | - if ($property === 'ee_ueip_optin') { |
|
| 1944 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1945 | - } |
|
| 1946 | - return parent::get_pretty($property); |
|
| 1947 | - } |
|
| 1948 | - |
|
| 1949 | - |
|
| 1950 | - /** |
|
| 1951 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1952 | - * on the object. |
|
| 1953 | - * |
|
| 1954 | - * @return array |
|
| 1955 | - */ |
|
| 1956 | - public function __sleep() |
|
| 1957 | - { |
|
| 1958 | - //reset all url properties |
|
| 1959 | - $this->_reset_urls(); |
|
| 1960 | - //return what to save to db |
|
| 1961 | - return array_keys(get_object_vars($this)); |
|
| 1962 | - } |
|
| 1963 | - |
|
| 1964 | -} |
|
| 1965 | - |
|
| 1966 | - |
|
| 1967 | - |
|
| 1968 | -/** |
|
| 1969 | - * Config class for storing info on the Organization |
|
| 1970 | - */ |
|
| 1971 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1972 | -{ |
|
| 1973 | - |
|
| 1974 | - /** |
|
| 1975 | - * @var string $name |
|
| 1976 | - * eg EE4.1 |
|
| 1977 | - */ |
|
| 1978 | - public $name; |
|
| 1979 | - |
|
| 1980 | - /** |
|
| 1981 | - * @var string $address_1 |
|
| 1982 | - * eg 123 Onna Road |
|
| 1983 | - */ |
|
| 1984 | - public $address_1; |
|
| 1985 | - |
|
| 1986 | - /** |
|
| 1987 | - * @var string $address_2 |
|
| 1988 | - * eg PO Box 123 |
|
| 1989 | - */ |
|
| 1990 | - public $address_2; |
|
| 1991 | - |
|
| 1992 | - /** |
|
| 1993 | - * @var string $city |
|
| 1994 | - * eg Inna City |
|
| 1995 | - */ |
|
| 1996 | - public $city; |
|
| 1997 | - |
|
| 1998 | - /** |
|
| 1999 | - * @var int $STA_ID |
|
| 2000 | - * eg 4 |
|
| 2001 | - */ |
|
| 2002 | - public $STA_ID; |
|
| 2003 | - |
|
| 2004 | - /** |
|
| 2005 | - * @var string $CNT_ISO |
|
| 2006 | - * eg US |
|
| 2007 | - */ |
|
| 2008 | - public $CNT_ISO; |
|
| 2009 | - |
|
| 2010 | - /** |
|
| 2011 | - * @var string $zip |
|
| 2012 | - * eg 12345 or V1A 2B3 |
|
| 2013 | - */ |
|
| 2014 | - public $zip; |
|
| 2015 | - |
|
| 2016 | - /** |
|
| 2017 | - * @var string $email |
|
| 2018 | - * eg [email protected] |
|
| 2019 | - */ |
|
| 2020 | - public $email; |
|
| 2021 | - |
|
| 2022 | - |
|
| 2023 | - /** |
|
| 2024 | - * @var string $phone |
|
| 2025 | - * eg. 111-111-1111 |
|
| 2026 | - */ |
|
| 2027 | - public $phone; |
|
| 2028 | - |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * @var string $vat |
|
| 2032 | - * VAT/Tax Number |
|
| 2033 | - */ |
|
| 2034 | - public $vat; |
|
| 2035 | - |
|
| 2036 | - /** |
|
| 2037 | - * @var string $logo_url |
|
| 2038 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2039 | - */ |
|
| 2040 | - public $logo_url; |
|
| 2041 | - |
|
| 2042 | - |
|
| 2043 | - /** |
|
| 2044 | - * The below are all various properties for holding links to organization social network profiles |
|
| 2045 | - * |
|
| 2046 | - * @var string |
|
| 2047 | - */ |
|
| 2048 | - /** |
|
| 2049 | - * facebook (facebook.com/profile.name) |
|
| 2050 | - * |
|
| 2051 | - * @var string |
|
| 2052 | - */ |
|
| 2053 | - public $facebook; |
|
| 2054 | - |
|
| 2055 | - |
|
| 2056 | - /** |
|
| 2057 | - * twitter (twitter.com/twitter_handle) |
|
| 2058 | - * |
|
| 2059 | - * @var string |
|
| 2060 | - */ |
|
| 2061 | - public $twitter; |
|
| 2062 | - |
|
| 2063 | - |
|
| 2064 | - /** |
|
| 2065 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2066 | - * |
|
| 2067 | - * @var string |
|
| 2068 | - */ |
|
| 2069 | - public $linkedin; |
|
| 2070 | - |
|
| 2071 | - |
|
| 2072 | - /** |
|
| 2073 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2074 | - * |
|
| 2075 | - * @var string |
|
| 2076 | - */ |
|
| 2077 | - public $pinterest; |
|
| 2078 | - |
|
| 2079 | - |
|
| 2080 | - /** |
|
| 2081 | - * google+ (google.com/+profileName) |
|
| 2082 | - * |
|
| 2083 | - * @var string |
|
| 2084 | - */ |
|
| 2085 | - public $google; |
|
| 2086 | - |
|
| 2087 | - |
|
| 2088 | - /** |
|
| 2089 | - * instagram (instagram.com/handle) |
|
| 2090 | - * |
|
| 2091 | - * @var string |
|
| 2092 | - */ |
|
| 2093 | - public $instagram; |
|
| 2094 | - |
|
| 2095 | - |
|
| 2096 | - |
|
| 2097 | - /** |
|
| 2098 | - * class constructor |
|
| 2099 | - * |
|
| 2100 | - * @access public |
|
| 2101 | - */ |
|
| 2102 | - public function __construct() |
|
| 2103 | - { |
|
| 2104 | - // set default organization settings |
|
| 2105 | - //decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2106 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2107 | - $this->address_1 = '123 Onna Road'; |
|
| 2108 | - $this->address_2 = 'PO Box 123'; |
|
| 2109 | - $this->city = 'Inna City'; |
|
| 2110 | - $this->STA_ID = 4; |
|
| 2111 | - $this->CNT_ISO = 'US'; |
|
| 2112 | - $this->zip = '12345'; |
|
| 2113 | - $this->email = get_bloginfo('admin_email'); |
|
| 2114 | - $this->phone = ''; |
|
| 2115 | - $this->vat = '123456789'; |
|
| 2116 | - $this->logo_url = ''; |
|
| 2117 | - $this->facebook = ''; |
|
| 2118 | - $this->twitter = ''; |
|
| 2119 | - $this->linkedin = ''; |
|
| 2120 | - $this->pinterest = ''; |
|
| 2121 | - $this->google = ''; |
|
| 2122 | - $this->instagram = ''; |
|
| 2123 | - } |
|
| 2124 | - |
|
| 2125 | -} |
|
| 2126 | - |
|
| 2127 | - |
|
| 2128 | - |
|
| 2129 | -/** |
|
| 2130 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2131 | - */ |
|
| 2132 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2133 | -{ |
|
| 2134 | - |
|
| 2135 | - /** |
|
| 2136 | - * @var string $code |
|
| 2137 | - * eg 'US' |
|
| 2138 | - */ |
|
| 2139 | - public $code; |
|
| 2140 | - |
|
| 2141 | - /** |
|
| 2142 | - * @var string $name |
|
| 2143 | - * eg 'Dollar' |
|
| 2144 | - */ |
|
| 2145 | - public $name; |
|
| 2146 | - |
|
| 2147 | - /** |
|
| 2148 | - * plural name |
|
| 2149 | - * |
|
| 2150 | - * @var string $plural |
|
| 2151 | - * eg 'Dollars' |
|
| 2152 | - */ |
|
| 2153 | - public $plural; |
|
| 2154 | - |
|
| 2155 | - /** |
|
| 2156 | - * currency sign |
|
| 2157 | - * |
|
| 2158 | - * @var string $sign |
|
| 2159 | - * eg '$' |
|
| 2160 | - */ |
|
| 2161 | - public $sign; |
|
| 2162 | - |
|
| 2163 | - /** |
|
| 2164 | - * Whether the currency sign should come before the number or not |
|
| 2165 | - * |
|
| 2166 | - * @var boolean $sign_b4 |
|
| 2167 | - */ |
|
| 2168 | - public $sign_b4; |
|
| 2169 | - |
|
| 2170 | - /** |
|
| 2171 | - * How many digits should come after the decimal place |
|
| 2172 | - * |
|
| 2173 | - * @var int $dec_plc |
|
| 2174 | - */ |
|
| 2175 | - public $dec_plc; |
|
| 2176 | - |
|
| 2177 | - /** |
|
| 2178 | - * Symbol to use for decimal mark |
|
| 2179 | - * |
|
| 2180 | - * @var string $dec_mrk |
|
| 2181 | - * eg '.' |
|
| 2182 | - */ |
|
| 2183 | - public $dec_mrk; |
|
| 2184 | - |
|
| 2185 | - /** |
|
| 2186 | - * Symbol to use for thousands |
|
| 2187 | - * |
|
| 2188 | - * @var string $thsnds |
|
| 2189 | - * eg ',' |
|
| 2190 | - */ |
|
| 2191 | - public $thsnds; |
|
| 2192 | - |
|
| 2193 | - |
|
| 2194 | - |
|
| 2195 | - /** |
|
| 2196 | - * class constructor |
|
| 2197 | - * |
|
| 2198 | - * @access public |
|
| 2199 | - * @param string $CNT_ISO |
|
| 2200 | - * @throws \EE_Error |
|
| 2201 | - */ |
|
| 2202 | - public function __construct($CNT_ISO = '') |
|
| 2203 | - { |
|
| 2204 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2205 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2206 | - // get country code from organization settings or use default |
|
| 2207 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2208 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2209 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2210 | - : ''; |
|
| 2211 | - // but override if requested |
|
| 2212 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2213 | - // 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 |
|
| 2214 | - if ( |
|
| 2215 | - ! empty($CNT_ISO) |
|
| 2216 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2217 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2218 | - ) { |
|
| 2219 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2220 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2221 | - if ($country instanceof EE_Country) { |
|
| 2222 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2223 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2224 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2225 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2226 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2227 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2228 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2229 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2230 | - } |
|
| 2231 | - } |
|
| 2232 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2233 | - if (empty($this->code)) { |
|
| 2234 | - // set default currency settings |
|
| 2235 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2236 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2237 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2238 | - $this->sign = '$'; // currency sign: $ |
|
| 2239 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2240 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2241 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2242 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2243 | - } |
|
| 2244 | - } |
|
| 2245 | -} |
|
| 2246 | - |
|
| 2247 | - |
|
| 2248 | - |
|
| 2249 | -/** |
|
| 2250 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2251 | - */ |
|
| 2252 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2253 | -{ |
|
| 2254 | - |
|
| 2255 | - /** |
|
| 2256 | - * Default registration status |
|
| 2257 | - * |
|
| 2258 | - * @var string $default_STS_ID |
|
| 2259 | - * eg 'RPP' |
|
| 2260 | - */ |
|
| 2261 | - public $default_STS_ID; |
|
| 2262 | - |
|
| 2263 | - |
|
| 2264 | - /** |
|
| 2265 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2266 | - * registrations) |
|
| 2267 | - * @var int |
|
| 2268 | - */ |
|
| 2269 | - public $default_maximum_number_of_tickets; |
|
| 2270 | - |
|
| 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', 'invisible' |
|
| 2339 | - */ |
|
| 2340 | - public $recaptcha_theme; |
|
| 1544 | +} |
|
| 2341 | 1545 | |
| 2342 | - /** |
|
| 2343 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2344 | - * |
|
| 2345 | - * @var string $recaptcha_badge |
|
| 2346 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2347 | - */ |
|
| 2348 | - public $recaptcha_badge; |
|
| 2349 | 1546 | |
| 2350 | - /** |
|
| 2351 | - * ReCaptcha Type |
|
| 2352 | - * |
|
| 2353 | - * @var string $recaptcha_type |
|
| 2354 | - * options: 'audio', 'image' |
|
| 2355 | - */ |
|
| 2356 | - public $recaptcha_type; |
|
| 2357 | 1547 | |
| 2358 | - /** |
|
| 2359 | - * ReCaptcha language |
|
| 2360 | - * |
|
| 2361 | - * @var string $recaptcha_language |
|
| 2362 | - * eg 'en' |
|
| 2363 | - */ |
|
| 2364 | - public $recaptcha_language; |
|
| 1548 | +/** |
|
| 1549 | + * Base class used for config classes. These classes should generally not have |
|
| 1550 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1551 | + * basically, they should just be well-defined stdClasses |
|
| 1552 | + */ |
|
| 1553 | +class EE_Config_Base |
|
| 1554 | +{ |
|
| 2365 | 1555 | |
| 2366 | - /** |
|
| 2367 | - * ReCaptcha public key |
|
| 2368 | - * |
|
| 2369 | - * @var string $recaptcha_publickey |
|
| 2370 | - */ |
|
| 2371 | - public $recaptcha_publickey; |
|
| 1556 | + /** |
|
| 1557 | + * Utility function for escaping the value of a property and returning. |
|
| 1558 | + * |
|
| 1559 | + * @param string $property property name (checks to see if exists). |
|
| 1560 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1561 | + * @throws \EE_Error |
|
| 1562 | + */ |
|
| 1563 | + public function get_pretty($property) |
|
| 1564 | + { |
|
| 1565 | + if (! property_exists($this, $property)) { |
|
| 1566 | + throw new EE_Error( |
|
| 1567 | + sprintf( |
|
| 1568 | + __( |
|
| 1569 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1570 | + 'event_espresso' |
|
| 1571 | + ), |
|
| 1572 | + get_class($this), |
|
| 1573 | + $property |
|
| 1574 | + ) |
|
| 1575 | + ); |
|
| 1576 | + } |
|
| 1577 | + //just handling escaping of strings for now. |
|
| 1578 | + if (is_string($this->{$property})) { |
|
| 1579 | + return stripslashes($this->{$property}); |
|
| 1580 | + } |
|
| 1581 | + return $this->{$property}; |
|
| 1582 | + } |
|
| 1583 | + |
|
| 1584 | + |
|
| 1585 | + |
|
| 1586 | + public function populate() |
|
| 1587 | + { |
|
| 1588 | + //grab defaults via a new instance of this class. |
|
| 1589 | + $class_name = get_class($this); |
|
| 1590 | + $defaults = new $class_name; |
|
| 1591 | + //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1592 | + //default from our $defaults object. |
|
| 1593 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1594 | + if ($this->{$property} === null) { |
|
| 1595 | + $this->{$property} = $value; |
|
| 1596 | + } |
|
| 1597 | + } |
|
| 1598 | + //cleanup |
|
| 1599 | + unset($defaults); |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * __isset |
|
| 1606 | + * |
|
| 1607 | + * @param $a |
|
| 1608 | + * @return bool |
|
| 1609 | + */ |
|
| 1610 | + public function __isset($a) |
|
| 1611 | + { |
|
| 1612 | + return false; |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + |
|
| 1616 | + |
|
| 1617 | + /** |
|
| 1618 | + * __unset |
|
| 1619 | + * |
|
| 1620 | + * @param $a |
|
| 1621 | + * @return bool |
|
| 1622 | + */ |
|
| 1623 | + public function __unset($a) |
|
| 1624 | + { |
|
| 1625 | + return false; |
|
| 1626 | + } |
|
| 1627 | + |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * __clone |
|
| 1632 | + */ |
|
| 1633 | + public function __clone() |
|
| 1634 | + { |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + |
|
| 1638 | + |
|
| 1639 | + /** |
|
| 1640 | + * __wakeup |
|
| 1641 | + */ |
|
| 1642 | + public function __wakeup() |
|
| 1643 | + { |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * __destruct |
|
| 1650 | + */ |
|
| 1651 | + public function __destruct() |
|
| 1652 | + { |
|
| 1653 | + } |
|
| 1654 | +} |
|
| 2372 | 1655 | |
| 2373 | - /** |
|
| 2374 | - * ReCaptcha private key |
|
| 2375 | - * |
|
| 2376 | - * @var string $recaptcha_privatekey |
|
| 2377 | - */ |
|
| 2378 | - public $recaptcha_privatekey; |
|
| 2379 | 1656 | |
| 2380 | - /** |
|
| 2381 | - * array of form names protected by ReCaptcha |
|
| 2382 | - * |
|
| 2383 | - * @var array $recaptcha_protected_forms |
|
| 2384 | - */ |
|
| 2385 | - public $recaptcha_protected_forms; |
|
| 2386 | 1657 | |
| 2387 | - /** |
|
| 2388 | - * ReCaptcha width |
|
| 2389 | - * |
|
| 2390 | - * @var int $recaptcha_width |
|
| 2391 | - * @deprecated |
|
| 2392 | - */ |
|
| 2393 | - public $recaptcha_width; |
|
| 1658 | +/** |
|
| 1659 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1660 | + */ |
|
| 1661 | +class EE_Core_Config extends EE_Config_Base |
|
| 1662 | +{ |
|
| 2394 | 1663 | |
| 2395 | - /** |
|
| 2396 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2397 | - * |
|
| 2398 | - * @var boolean $track_invalid_checkout_access |
|
| 2399 | - */ |
|
| 2400 | - protected $track_invalid_checkout_access = true; |
|
| 1664 | + public $current_blog_id; |
|
| 1665 | + |
|
| 1666 | + public $ee_ueip_optin; |
|
| 1667 | + |
|
| 1668 | + public $ee_ueip_has_notified; |
|
| 1669 | + |
|
| 1670 | + /** |
|
| 1671 | + * Not to be confused with the 4 critical page variables (See |
|
| 1672 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1673 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1674 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1675 | + * |
|
| 1676 | + * @var array |
|
| 1677 | + */ |
|
| 1678 | + public $post_shortcodes; |
|
| 1679 | + |
|
| 1680 | + public $module_route_map; |
|
| 1681 | + |
|
| 1682 | + public $module_forward_map; |
|
| 1683 | + |
|
| 1684 | + public $module_view_map; |
|
| 1685 | + |
|
| 1686 | + /** |
|
| 1687 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1688 | + * |
|
| 1689 | + * @var int |
|
| 1690 | + */ |
|
| 1691 | + public $reg_page_id; |
|
| 1692 | + |
|
| 1693 | + public $txn_page_id; |
|
| 1694 | + |
|
| 1695 | + public $thank_you_page_id; |
|
| 1696 | + |
|
| 1697 | + public $cancel_page_id; |
|
| 1698 | + |
|
| 1699 | + /** |
|
| 1700 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1701 | + * |
|
| 1702 | + * @var int |
|
| 1703 | + */ |
|
| 1704 | + public $reg_page_url; |
|
| 1705 | + |
|
| 1706 | + public $txn_page_url; |
|
| 1707 | + |
|
| 1708 | + public $thank_you_page_url; |
|
| 1709 | + |
|
| 1710 | + public $cancel_page_url; |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1714 | + */ |
|
| 1715 | + public $event_cpt_slug; |
|
| 1716 | + |
|
| 1717 | + |
|
| 1718 | + /** |
|
| 1719 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1720 | + * request across blog switches in a multisite context. |
|
| 1721 | + * Avoids extra queries to the db for this option. |
|
| 1722 | + * |
|
| 1723 | + * @var bool |
|
| 1724 | + */ |
|
| 1725 | + public static $ee_ueip_option; |
|
| 1726 | + |
|
| 1727 | + |
|
| 1728 | + |
|
| 1729 | + /** |
|
| 1730 | + * class constructor |
|
| 1731 | + * |
|
| 1732 | + * @access public |
|
| 1733 | + */ |
|
| 1734 | + public function __construct() |
|
| 1735 | + { |
|
| 1736 | + // set default organization settings |
|
| 1737 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1738 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1739 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1740 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1741 | + $this->post_shortcodes = array(); |
|
| 1742 | + $this->module_route_map = array(); |
|
| 1743 | + $this->module_forward_map = array(); |
|
| 1744 | + $this->module_view_map = array(); |
|
| 1745 | + // critical EE page IDs |
|
| 1746 | + $this->reg_page_id = 0; |
|
| 1747 | + $this->txn_page_id = 0; |
|
| 1748 | + $this->thank_you_page_id = 0; |
|
| 1749 | + $this->cancel_page_id = 0; |
|
| 1750 | + // critical EE page URLs |
|
| 1751 | + $this->reg_page_url = ''; |
|
| 1752 | + $this->txn_page_url = ''; |
|
| 1753 | + $this->thank_you_page_url = ''; |
|
| 1754 | + $this->cancel_page_url = ''; |
|
| 1755 | + //cpt slugs |
|
| 1756 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1757 | + //ueip constant check |
|
| 1758 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1759 | + $this->ee_ueip_optin = false; |
|
| 1760 | + $this->ee_ueip_has_notified = true; |
|
| 1761 | + } |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + |
|
| 1766 | + /** |
|
| 1767 | + * @return array |
|
| 1768 | + */ |
|
| 1769 | + public function get_critical_pages_array() |
|
| 1770 | + { |
|
| 1771 | + return array( |
|
| 1772 | + $this->reg_page_id, |
|
| 1773 | + $this->txn_page_id, |
|
| 1774 | + $this->thank_you_page_id, |
|
| 1775 | + $this->cancel_page_id, |
|
| 1776 | + ); |
|
| 1777 | + } |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + |
|
| 1781 | + /** |
|
| 1782 | + * @return array |
|
| 1783 | + */ |
|
| 1784 | + public function get_critical_pages_shortcodes_array() |
|
| 1785 | + { |
|
| 1786 | + return array( |
|
| 1787 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1788 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1789 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1790 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1791 | + ); |
|
| 1792 | + } |
|
| 1793 | + |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + /** |
|
| 1797 | + * gets/returns URL for EE reg_page |
|
| 1798 | + * |
|
| 1799 | + * @access public |
|
| 1800 | + * @return string |
|
| 1801 | + */ |
|
| 1802 | + public function reg_page_url() |
|
| 1803 | + { |
|
| 1804 | + if (! $this->reg_page_url) { |
|
| 1805 | + $this->reg_page_url = add_query_arg( |
|
| 1806 | + array('uts' => time()), |
|
| 1807 | + get_permalink($this->reg_page_id) |
|
| 1808 | + ) . '#checkout'; |
|
| 1809 | + } |
|
| 1810 | + return $this->reg_page_url; |
|
| 1811 | + } |
|
| 1812 | + |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + /** |
|
| 1816 | + * gets/returns URL for EE txn_page |
|
| 1817 | + * |
|
| 1818 | + * @param array $query_args like what gets passed to |
|
| 1819 | + * add_query_arg() as the first argument |
|
| 1820 | + * @access public |
|
| 1821 | + * @return string |
|
| 1822 | + */ |
|
| 1823 | + public function txn_page_url($query_args = array()) |
|
| 1824 | + { |
|
| 1825 | + if (! $this->txn_page_url) { |
|
| 1826 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1827 | + } |
|
| 1828 | + if ($query_args) { |
|
| 1829 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1830 | + } else { |
|
| 1831 | + return $this->txn_page_url; |
|
| 1832 | + } |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + |
|
| 1836 | + |
|
| 1837 | + /** |
|
| 1838 | + * gets/returns URL for EE thank_you_page |
|
| 1839 | + * |
|
| 1840 | + * @param array $query_args like what gets passed to |
|
| 1841 | + * add_query_arg() as the first argument |
|
| 1842 | + * @access public |
|
| 1843 | + * @return string |
|
| 1844 | + */ |
|
| 1845 | + public function thank_you_page_url($query_args = array()) |
|
| 1846 | + { |
|
| 1847 | + if (! $this->thank_you_page_url) { |
|
| 1848 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1849 | + } |
|
| 1850 | + if ($query_args) { |
|
| 1851 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1852 | + } else { |
|
| 1853 | + return $this->thank_you_page_url; |
|
| 1854 | + } |
|
| 1855 | + } |
|
| 1856 | + |
|
| 1857 | + |
|
| 1858 | + |
|
| 1859 | + /** |
|
| 1860 | + * gets/returns URL for EE cancel_page |
|
| 1861 | + * |
|
| 1862 | + * @access public |
|
| 1863 | + * @return string |
|
| 1864 | + */ |
|
| 1865 | + public function cancel_page_url() |
|
| 1866 | + { |
|
| 1867 | + if (! $this->cancel_page_url) { |
|
| 1868 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1869 | + } |
|
| 1870 | + return $this->cancel_page_url; |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + |
|
| 1874 | + |
|
| 1875 | + /** |
|
| 1876 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1877 | + * |
|
| 1878 | + * @since 4.7.5 |
|
| 1879 | + */ |
|
| 1880 | + protected function _reset_urls() |
|
| 1881 | + { |
|
| 1882 | + $this->reg_page_url = ''; |
|
| 1883 | + $this->txn_page_url = ''; |
|
| 1884 | + $this->cancel_page_url = ''; |
|
| 1885 | + $this->thank_you_page_url = ''; |
|
| 1886 | + } |
|
| 1887 | + |
|
| 1888 | + |
|
| 1889 | + |
|
| 1890 | + /** |
|
| 1891 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1892 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1893 | + * on the main site only. |
|
| 1894 | + * |
|
| 1895 | + * @return mixed|void |
|
| 1896 | + */ |
|
| 1897 | + protected function _get_main_ee_ueip_optin() |
|
| 1898 | + { |
|
| 1899 | + //if this is the main site then we can just bypass our direct query. |
|
| 1900 | + if (is_main_site()) { |
|
| 1901 | + return get_option('ee_ueip_optin', false); |
|
| 1902 | + } |
|
| 1903 | + //is this already cached for this request? If so use it. |
|
| 1904 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1905 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1906 | + } |
|
| 1907 | + global $wpdb; |
|
| 1908 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1909 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1910 | + $option = 'ee_ueip_optin'; |
|
| 1911 | + //set correct table for query |
|
| 1912 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1913 | + //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1914 | + //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1915 | + //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1916 | + //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1917 | + //for the purpose of caching. |
|
| 1918 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1919 | + if (false !== $pre) { |
|
| 1920 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1921 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1922 | + } |
|
| 1923 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1924 | + $option)); |
|
| 1925 | + if (is_object($row)) { |
|
| 1926 | + $value = $row->option_value; |
|
| 1927 | + } else { //option does not exist so use default. |
|
| 1928 | + return apply_filters('default_option_' . $option, false, $option); |
|
| 1929 | + } |
|
| 1930 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1931 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + /** |
|
| 1935 | + * Utility function for escaping the value of a property and returning. |
|
| 1936 | + * |
|
| 1937 | + * @param string $property property name (checks to see if exists). |
|
| 1938 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1939 | + * @throws \EE_Error |
|
| 1940 | + */ |
|
| 1941 | + public function get_pretty($property) |
|
| 1942 | + { |
|
| 1943 | + if ($property === 'ee_ueip_optin') { |
|
| 1944 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1945 | + } |
|
| 1946 | + return parent::get_pretty($property); |
|
| 1947 | + } |
|
| 1948 | + |
|
| 1949 | + |
|
| 1950 | + /** |
|
| 1951 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1952 | + * on the object. |
|
| 1953 | + * |
|
| 1954 | + * @return array |
|
| 1955 | + */ |
|
| 1956 | + public function __sleep() |
|
| 1957 | + { |
|
| 1958 | + //reset all url properties |
|
| 1959 | + $this->_reset_urls(); |
|
| 1960 | + //return what to save to db |
|
| 1961 | + return array_keys(get_object_vars($this)); |
|
| 1962 | + } |
|
| 2401 | 1963 | |
| 1964 | +} |
|
| 2402 | 1965 | |
| 2403 | 1966 | |
| 2404 | - /** |
|
| 2405 | - * class constructor |
|
| 2406 | - * |
|
| 2407 | - * @access public |
|
| 2408 | - */ |
|
| 2409 | - public function __construct() |
|
| 2410 | - { |
|
| 2411 | - // set default registration settings |
|
| 2412 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2413 | - $this->email_validation_level = 'wp_default'; |
|
| 2414 | - $this->show_pending_payment_options = true; |
|
| 2415 | - $this->skip_reg_confirmation = false; |
|
| 2416 | - $this->reg_steps = array(); |
|
| 2417 | - $this->reg_confirmation_last = false; |
|
| 2418 | - $this->use_bot_trap = true; |
|
| 2419 | - $this->use_encryption = true; |
|
| 2420 | - $this->use_captcha = false; |
|
| 2421 | - $this->recaptcha_theme = 'light'; |
|
| 2422 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2423 | - $this->recaptcha_type = 'image'; |
|
| 2424 | - $this->recaptcha_language = 'en'; |
|
| 2425 | - $this->recaptcha_publickey = null; |
|
| 2426 | - $this->recaptcha_privatekey = null; |
|
| 2427 | - $this->recaptcha_protected_forms = array(); |
|
| 2428 | - $this->recaptcha_width = 500; |
|
| 2429 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2430 | - } |
|
| 2431 | - |
|
| 2432 | - |
|
| 2433 | - |
|
| 2434 | - /** |
|
| 2435 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2436 | - * |
|
| 2437 | - * @since 4.8.8.rc.019 |
|
| 2438 | - */ |
|
| 2439 | - public function do_hooks() |
|
| 2440 | - { |
|
| 2441 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2442 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2443 | - } |
|
| 2444 | 1967 | |
| 1968 | +/** |
|
| 1969 | + * Config class for storing info on the Organization |
|
| 1970 | + */ |
|
| 1971 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1972 | +{ |
|
| 2445 | 1973 | |
| 1974 | + /** |
|
| 1975 | + * @var string $name |
|
| 1976 | + * eg EE4.1 |
|
| 1977 | + */ |
|
| 1978 | + public $name; |
|
| 1979 | + |
|
| 1980 | + /** |
|
| 1981 | + * @var string $address_1 |
|
| 1982 | + * eg 123 Onna Road |
|
| 1983 | + */ |
|
| 1984 | + public $address_1; |
|
| 1985 | + |
|
| 1986 | + /** |
|
| 1987 | + * @var string $address_2 |
|
| 1988 | + * eg PO Box 123 |
|
| 1989 | + */ |
|
| 1990 | + public $address_2; |
|
| 1991 | + |
|
| 1992 | + /** |
|
| 1993 | + * @var string $city |
|
| 1994 | + * eg Inna City |
|
| 1995 | + */ |
|
| 1996 | + public $city; |
|
| 1997 | + |
|
| 1998 | + /** |
|
| 1999 | + * @var int $STA_ID |
|
| 2000 | + * eg 4 |
|
| 2001 | + */ |
|
| 2002 | + public $STA_ID; |
|
| 2003 | + |
|
| 2004 | + /** |
|
| 2005 | + * @var string $CNT_ISO |
|
| 2006 | + * eg US |
|
| 2007 | + */ |
|
| 2008 | + public $CNT_ISO; |
|
| 2009 | + |
|
| 2010 | + /** |
|
| 2011 | + * @var string $zip |
|
| 2012 | + * eg 12345 or V1A 2B3 |
|
| 2013 | + */ |
|
| 2014 | + public $zip; |
|
| 2015 | + |
|
| 2016 | + /** |
|
| 2017 | + * @var string $email |
|
| 2018 | + * eg [email protected] |
|
| 2019 | + */ |
|
| 2020 | + public $email; |
|
| 2021 | + |
|
| 2022 | + |
|
| 2023 | + /** |
|
| 2024 | + * @var string $phone |
|
| 2025 | + * eg. 111-111-1111 |
|
| 2026 | + */ |
|
| 2027 | + public $phone; |
|
| 2028 | + |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * @var string $vat |
|
| 2032 | + * VAT/Tax Number |
|
| 2033 | + */ |
|
| 2034 | + public $vat; |
|
| 2035 | + |
|
| 2036 | + /** |
|
| 2037 | + * @var string $logo_url |
|
| 2038 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2039 | + */ |
|
| 2040 | + public $logo_url; |
|
| 2041 | + |
|
| 2042 | + |
|
| 2043 | + /** |
|
| 2044 | + * The below are all various properties for holding links to organization social network profiles |
|
| 2045 | + * |
|
| 2046 | + * @var string |
|
| 2047 | + */ |
|
| 2048 | + /** |
|
| 2049 | + * facebook (facebook.com/profile.name) |
|
| 2050 | + * |
|
| 2051 | + * @var string |
|
| 2052 | + */ |
|
| 2053 | + public $facebook; |
|
| 2054 | + |
|
| 2055 | + |
|
| 2056 | + /** |
|
| 2057 | + * twitter (twitter.com/twitter_handle) |
|
| 2058 | + * |
|
| 2059 | + * @var string |
|
| 2060 | + */ |
|
| 2061 | + public $twitter; |
|
| 2062 | + |
|
| 2063 | + |
|
| 2064 | + /** |
|
| 2065 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2066 | + * |
|
| 2067 | + * @var string |
|
| 2068 | + */ |
|
| 2069 | + public $linkedin; |
|
| 2070 | + |
|
| 2071 | + |
|
| 2072 | + /** |
|
| 2073 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2074 | + * |
|
| 2075 | + * @var string |
|
| 2076 | + */ |
|
| 2077 | + public $pinterest; |
|
| 2078 | + |
|
| 2079 | + |
|
| 2080 | + /** |
|
| 2081 | + * google+ (google.com/+profileName) |
|
| 2082 | + * |
|
| 2083 | + * @var string |
|
| 2084 | + */ |
|
| 2085 | + public $google; |
|
| 2086 | + |
|
| 2087 | + |
|
| 2088 | + /** |
|
| 2089 | + * instagram (instagram.com/handle) |
|
| 2090 | + * |
|
| 2091 | + * @var string |
|
| 2092 | + */ |
|
| 2093 | + public $instagram; |
|
| 2094 | + |
|
| 2095 | + |
|
| 2096 | + |
|
| 2097 | + /** |
|
| 2098 | + * class constructor |
|
| 2099 | + * |
|
| 2100 | + * @access public |
|
| 2101 | + */ |
|
| 2102 | + public function __construct() |
|
| 2103 | + { |
|
| 2104 | + // set default organization settings |
|
| 2105 | + //decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2106 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2107 | + $this->address_1 = '123 Onna Road'; |
|
| 2108 | + $this->address_2 = 'PO Box 123'; |
|
| 2109 | + $this->city = 'Inna City'; |
|
| 2110 | + $this->STA_ID = 4; |
|
| 2111 | + $this->CNT_ISO = 'US'; |
|
| 2112 | + $this->zip = '12345'; |
|
| 2113 | + $this->email = get_bloginfo('admin_email'); |
|
| 2114 | + $this->phone = ''; |
|
| 2115 | + $this->vat = '123456789'; |
|
| 2116 | + $this->logo_url = ''; |
|
| 2117 | + $this->facebook = ''; |
|
| 2118 | + $this->twitter = ''; |
|
| 2119 | + $this->linkedin = ''; |
|
| 2120 | + $this->pinterest = ''; |
|
| 2121 | + $this->google = ''; |
|
| 2122 | + $this->instagram = ''; |
|
| 2123 | + } |
|
| 2446 | 2124 | |
| 2447 | - /** |
|
| 2448 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
| 2449 | - * field matches the config setting for default_STS_ID. |
|
| 2450 | - */ |
|
| 2451 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2452 | - { |
|
| 2453 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2454 | - } |
|
| 2125 | +} |
|
| 2455 | 2126 | |
| 2456 | 2127 | |
| 2457 | - /** |
|
| 2458 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2459 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2460 | - */ |
|
| 2461 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2462 | - { |
|
| 2463 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2464 | - } |
|
| 2465 | 2128 | |
| 2129 | +/** |
|
| 2130 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2131 | + */ |
|
| 2132 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2133 | +{ |
|
| 2466 | 2134 | |
| 2135 | + /** |
|
| 2136 | + * @var string $code |
|
| 2137 | + * eg 'US' |
|
| 2138 | + */ |
|
| 2139 | + public $code; |
|
| 2140 | + |
|
| 2141 | + /** |
|
| 2142 | + * @var string $name |
|
| 2143 | + * eg 'Dollar' |
|
| 2144 | + */ |
|
| 2145 | + public $name; |
|
| 2146 | + |
|
| 2147 | + /** |
|
| 2148 | + * plural name |
|
| 2149 | + * |
|
| 2150 | + * @var string $plural |
|
| 2151 | + * eg 'Dollars' |
|
| 2152 | + */ |
|
| 2153 | + public $plural; |
|
| 2154 | + |
|
| 2155 | + /** |
|
| 2156 | + * currency sign |
|
| 2157 | + * |
|
| 2158 | + * @var string $sign |
|
| 2159 | + * eg '$' |
|
| 2160 | + */ |
|
| 2161 | + public $sign; |
|
| 2162 | + |
|
| 2163 | + /** |
|
| 2164 | + * Whether the currency sign should come before the number or not |
|
| 2165 | + * |
|
| 2166 | + * @var boolean $sign_b4 |
|
| 2167 | + */ |
|
| 2168 | + public $sign_b4; |
|
| 2169 | + |
|
| 2170 | + /** |
|
| 2171 | + * How many digits should come after the decimal place |
|
| 2172 | + * |
|
| 2173 | + * @var int $dec_plc |
|
| 2174 | + */ |
|
| 2175 | + public $dec_plc; |
|
| 2176 | + |
|
| 2177 | + /** |
|
| 2178 | + * Symbol to use for decimal mark |
|
| 2179 | + * |
|
| 2180 | + * @var string $dec_mrk |
|
| 2181 | + * eg '.' |
|
| 2182 | + */ |
|
| 2183 | + public $dec_mrk; |
|
| 2184 | + |
|
| 2185 | + /** |
|
| 2186 | + * Symbol to use for thousands |
|
| 2187 | + * |
|
| 2188 | + * @var string $thsnds |
|
| 2189 | + * eg ',' |
|
| 2190 | + */ |
|
| 2191 | + public $thsnds; |
|
| 2192 | + |
|
| 2193 | + |
|
| 2194 | + |
|
| 2195 | + /** |
|
| 2196 | + * class constructor |
|
| 2197 | + * |
|
| 2198 | + * @access public |
|
| 2199 | + * @param string $CNT_ISO |
|
| 2200 | + * @throws \EE_Error |
|
| 2201 | + */ |
|
| 2202 | + public function __construct($CNT_ISO = '') |
|
| 2203 | + { |
|
| 2204 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2205 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2206 | + // get country code from organization settings or use default |
|
| 2207 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2208 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2209 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2210 | + : ''; |
|
| 2211 | + // but override if requested |
|
| 2212 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2213 | + // 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 |
|
| 2214 | + if ( |
|
| 2215 | + ! empty($CNT_ISO) |
|
| 2216 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2217 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2218 | + ) { |
|
| 2219 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2220 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2221 | + if ($country instanceof EE_Country) { |
|
| 2222 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2223 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2224 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2225 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2226 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2227 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2228 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2229 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2230 | + } |
|
| 2231 | + } |
|
| 2232 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2233 | + if (empty($this->code)) { |
|
| 2234 | + // set default currency settings |
|
| 2235 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2236 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2237 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2238 | + $this->sign = '$'; // currency sign: $ |
|
| 2239 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2240 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2241 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2242 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2243 | + } |
|
| 2244 | + } |
|
| 2245 | +} |
|
| 2467 | 2246 | |
| 2468 | - /** |
|
| 2469 | - * @return boolean |
|
| 2470 | - */ |
|
| 2471 | - public function track_invalid_checkout_access() |
|
| 2472 | - { |
|
| 2473 | - return $this->track_invalid_checkout_access; |
|
| 2474 | - } |
|
| 2475 | 2247 | |
| 2476 | 2248 | |
| 2249 | +/** |
|
| 2250 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2251 | + */ |
|
| 2252 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2253 | +{ |
|
| 2477 | 2254 | |
| 2478 | - /** |
|
| 2479 | - * @param boolean $track_invalid_checkout_access |
|
| 2480 | - */ |
|
| 2481 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2482 | - { |
|
| 2483 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2484 | - $track_invalid_checkout_access, |
|
| 2485 | - FILTER_VALIDATE_BOOLEAN |
|
| 2486 | - ); |
|
| 2487 | - } |
|
| 2255 | + /** |
|
| 2256 | + * Default registration status |
|
| 2257 | + * |
|
| 2258 | + * @var string $default_STS_ID |
|
| 2259 | + * eg 'RPP' |
|
| 2260 | + */ |
|
| 2261 | + public $default_STS_ID; |
|
| 2262 | + |
|
| 2263 | + |
|
| 2264 | + /** |
|
| 2265 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2266 | + * registrations) |
|
| 2267 | + * @var int |
|
| 2268 | + */ |
|
| 2269 | + public $default_maximum_number_of_tickets; |
|
| 2270 | + |
|
| 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', 'invisible' |
|
| 2339 | + */ |
|
| 2340 | + public $recaptcha_theme; |
|
| 2341 | + |
|
| 2342 | + /** |
|
| 2343 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2344 | + * |
|
| 2345 | + * @var string $recaptcha_badge |
|
| 2346 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2347 | + */ |
|
| 2348 | + public $recaptcha_badge; |
|
| 2349 | + |
|
| 2350 | + /** |
|
| 2351 | + * ReCaptcha Type |
|
| 2352 | + * |
|
| 2353 | + * @var string $recaptcha_type |
|
| 2354 | + * options: 'audio', 'image' |
|
| 2355 | + */ |
|
| 2356 | + public $recaptcha_type; |
|
| 2357 | + |
|
| 2358 | + /** |
|
| 2359 | + * ReCaptcha language |
|
| 2360 | + * |
|
| 2361 | + * @var string $recaptcha_language |
|
| 2362 | + * eg 'en' |
|
| 2363 | + */ |
|
| 2364 | + public $recaptcha_language; |
|
| 2365 | + |
|
| 2366 | + /** |
|
| 2367 | + * ReCaptcha public key |
|
| 2368 | + * |
|
| 2369 | + * @var string $recaptcha_publickey |
|
| 2370 | + */ |
|
| 2371 | + public $recaptcha_publickey; |
|
| 2372 | + |
|
| 2373 | + /** |
|
| 2374 | + * ReCaptcha private key |
|
| 2375 | + * |
|
| 2376 | + * @var string $recaptcha_privatekey |
|
| 2377 | + */ |
|
| 2378 | + public $recaptcha_privatekey; |
|
| 2379 | + |
|
| 2380 | + /** |
|
| 2381 | + * array of form names protected by ReCaptcha |
|
| 2382 | + * |
|
| 2383 | + * @var array $recaptcha_protected_forms |
|
| 2384 | + */ |
|
| 2385 | + public $recaptcha_protected_forms; |
|
| 2386 | + |
|
| 2387 | + /** |
|
| 2388 | + * ReCaptcha width |
|
| 2389 | + * |
|
| 2390 | + * @var int $recaptcha_width |
|
| 2391 | + * @deprecated |
|
| 2392 | + */ |
|
| 2393 | + public $recaptcha_width; |
|
| 2394 | + |
|
| 2395 | + /** |
|
| 2396 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2397 | + * |
|
| 2398 | + * @var boolean $track_invalid_checkout_access |
|
| 2399 | + */ |
|
| 2400 | + protected $track_invalid_checkout_access = true; |
|
| 2401 | + |
|
| 2402 | + |
|
| 2403 | + |
|
| 2404 | + /** |
|
| 2405 | + * class constructor |
|
| 2406 | + * |
|
| 2407 | + * @access public |
|
| 2408 | + */ |
|
| 2409 | + public function __construct() |
|
| 2410 | + { |
|
| 2411 | + // set default registration settings |
|
| 2412 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2413 | + $this->email_validation_level = 'wp_default'; |
|
| 2414 | + $this->show_pending_payment_options = true; |
|
| 2415 | + $this->skip_reg_confirmation = false; |
|
| 2416 | + $this->reg_steps = array(); |
|
| 2417 | + $this->reg_confirmation_last = false; |
|
| 2418 | + $this->use_bot_trap = true; |
|
| 2419 | + $this->use_encryption = true; |
|
| 2420 | + $this->use_captcha = false; |
|
| 2421 | + $this->recaptcha_theme = 'light'; |
|
| 2422 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2423 | + $this->recaptcha_type = 'image'; |
|
| 2424 | + $this->recaptcha_language = 'en'; |
|
| 2425 | + $this->recaptcha_publickey = null; |
|
| 2426 | + $this->recaptcha_privatekey = null; |
|
| 2427 | + $this->recaptcha_protected_forms = array(); |
|
| 2428 | + $this->recaptcha_width = 500; |
|
| 2429 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2430 | + } |
|
| 2431 | + |
|
| 2432 | + |
|
| 2433 | + |
|
| 2434 | + /** |
|
| 2435 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2436 | + * |
|
| 2437 | + * @since 4.8.8.rc.019 |
|
| 2438 | + */ |
|
| 2439 | + public function do_hooks() |
|
| 2440 | + { |
|
| 2441 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2442 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2443 | + } |
|
| 2444 | + |
|
| 2445 | + |
|
| 2446 | + |
|
| 2447 | + /** |
|
| 2448 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
| 2449 | + * field matches the config setting for default_STS_ID. |
|
| 2450 | + */ |
|
| 2451 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2452 | + { |
|
| 2453 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2454 | + } |
|
| 2455 | + |
|
| 2456 | + |
|
| 2457 | + /** |
|
| 2458 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2459 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2460 | + */ |
|
| 2461 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2462 | + { |
|
| 2463 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2464 | + } |
|
| 2465 | + |
|
| 2466 | + |
|
| 2467 | + |
|
| 2468 | + /** |
|
| 2469 | + * @return boolean |
|
| 2470 | + */ |
|
| 2471 | + public function track_invalid_checkout_access() |
|
| 2472 | + { |
|
| 2473 | + return $this->track_invalid_checkout_access; |
|
| 2474 | + } |
|
| 2475 | + |
|
| 2476 | + |
|
| 2477 | + |
|
| 2478 | + /** |
|
| 2479 | + * @param boolean $track_invalid_checkout_access |
|
| 2480 | + */ |
|
| 2481 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2482 | + { |
|
| 2483 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2484 | + $track_invalid_checkout_access, |
|
| 2485 | + FILTER_VALIDATE_BOOLEAN |
|
| 2486 | + ); |
|
| 2487 | + } |
|
| 2488 | 2488 | |
| 2489 | 2489 | |
| 2490 | 2490 | |
@@ -2498,160 +2498,160 @@ discard block |
||
| 2498 | 2498 | class EE_Admin_Config extends EE_Config_Base |
| 2499 | 2499 | { |
| 2500 | 2500 | |
| 2501 | - /** |
|
| 2502 | - * @var boolean $use_personnel_manager |
|
| 2503 | - */ |
|
| 2504 | - public $use_personnel_manager; |
|
| 2505 | - |
|
| 2506 | - /** |
|
| 2507 | - * @var boolean $use_dashboard_widget |
|
| 2508 | - */ |
|
| 2509 | - public $use_dashboard_widget; |
|
| 2510 | - |
|
| 2511 | - /** |
|
| 2512 | - * @var int $events_in_dashboard |
|
| 2513 | - */ |
|
| 2514 | - public $events_in_dashboard; |
|
| 2515 | - |
|
| 2516 | - /** |
|
| 2517 | - * @var boolean $use_event_timezones |
|
| 2518 | - */ |
|
| 2519 | - public $use_event_timezones; |
|
| 2520 | - |
|
| 2521 | - /** |
|
| 2522 | - * @var boolean $use_full_logging |
|
| 2523 | - */ |
|
| 2524 | - public $use_full_logging; |
|
| 2525 | - |
|
| 2526 | - /** |
|
| 2527 | - * @var string $log_file_name |
|
| 2528 | - */ |
|
| 2529 | - public $log_file_name; |
|
| 2530 | - |
|
| 2531 | - /** |
|
| 2532 | - * @var string $debug_file_name |
|
| 2533 | - */ |
|
| 2534 | - public $debug_file_name; |
|
| 2535 | - |
|
| 2536 | - /** |
|
| 2537 | - * @var boolean $use_remote_logging |
|
| 2538 | - */ |
|
| 2539 | - public $use_remote_logging; |
|
| 2540 | - |
|
| 2541 | - /** |
|
| 2542 | - * @var string $remote_logging_url |
|
| 2543 | - */ |
|
| 2544 | - public $remote_logging_url; |
|
| 2545 | - |
|
| 2546 | - /** |
|
| 2547 | - * @var boolean $show_reg_footer |
|
| 2548 | - */ |
|
| 2549 | - public $show_reg_footer; |
|
| 2550 | - |
|
| 2551 | - /** |
|
| 2552 | - * @var string $affiliate_id |
|
| 2553 | - */ |
|
| 2554 | - public $affiliate_id; |
|
| 2555 | - |
|
| 2556 | - /** |
|
| 2557 | - * help tours on or off (global setting) |
|
| 2558 | - * |
|
| 2559 | - * @var boolean |
|
| 2560 | - */ |
|
| 2561 | - public $help_tour_activation; |
|
| 2562 | - |
|
| 2563 | - /** |
|
| 2564 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2565 | - * but is incompatible with some server configuration errors |
|
| 2566 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2567 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2568 | - * |
|
| 2569 | - * @var boolean $encode_session_data |
|
| 2570 | - */ |
|
| 2571 | - private $encode_session_data = false; |
|
| 2572 | - |
|
| 2573 | - |
|
| 2574 | - |
|
| 2575 | - /** |
|
| 2576 | - * class constructor |
|
| 2577 | - * |
|
| 2578 | - * @access public |
|
| 2579 | - */ |
|
| 2580 | - public function __construct() |
|
| 2581 | - { |
|
| 2582 | - // set default general admin settings |
|
| 2583 | - $this->use_personnel_manager = true; |
|
| 2584 | - $this->use_dashboard_widget = true; |
|
| 2585 | - $this->events_in_dashboard = 30; |
|
| 2586 | - $this->use_event_timezones = false; |
|
| 2587 | - $this->use_full_logging = false; |
|
| 2588 | - $this->use_remote_logging = false; |
|
| 2589 | - $this->remote_logging_url = null; |
|
| 2590 | - $this->show_reg_footer = true; |
|
| 2591 | - $this->affiliate_id = 'default'; |
|
| 2592 | - $this->help_tour_activation = true; |
|
| 2593 | - $this->encode_session_data = false; |
|
| 2594 | - } |
|
| 2595 | - |
|
| 2596 | - |
|
| 2597 | - |
|
| 2598 | - /** |
|
| 2599 | - * @param bool $reset |
|
| 2600 | - * @return string |
|
| 2601 | - */ |
|
| 2602 | - public function log_file_name($reset = false) |
|
| 2603 | - { |
|
| 2604 | - if (empty($this->log_file_name) || $reset) { |
|
| 2605 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2606 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2607 | - } |
|
| 2608 | - return $this->log_file_name; |
|
| 2609 | - } |
|
| 2610 | - |
|
| 2611 | - |
|
| 2612 | - |
|
| 2613 | - /** |
|
| 2614 | - * @param bool $reset |
|
| 2615 | - * @return string |
|
| 2616 | - */ |
|
| 2617 | - public function debug_file_name($reset = false) |
|
| 2618 | - { |
|
| 2619 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2620 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2621 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2622 | - } |
|
| 2623 | - return $this->debug_file_name; |
|
| 2624 | - } |
|
| 2625 | - |
|
| 2626 | - |
|
| 2627 | - |
|
| 2628 | - /** |
|
| 2629 | - * @return string |
|
| 2630 | - */ |
|
| 2631 | - public function affiliate_id() |
|
| 2632 | - { |
|
| 2633 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - |
|
| 2637 | - |
|
| 2638 | - /** |
|
| 2639 | - * @return boolean |
|
| 2640 | - */ |
|
| 2641 | - public function encode_session_data() |
|
| 2642 | - { |
|
| 2643 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2644 | - } |
|
| 2645 | - |
|
| 2646 | - |
|
| 2647 | - |
|
| 2648 | - /** |
|
| 2649 | - * @param boolean $encode_session_data |
|
| 2650 | - */ |
|
| 2651 | - public function set_encode_session_data($encode_session_data) |
|
| 2652 | - { |
|
| 2653 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2654 | - } |
|
| 2501 | + /** |
|
| 2502 | + * @var boolean $use_personnel_manager |
|
| 2503 | + */ |
|
| 2504 | + public $use_personnel_manager; |
|
| 2505 | + |
|
| 2506 | + /** |
|
| 2507 | + * @var boolean $use_dashboard_widget |
|
| 2508 | + */ |
|
| 2509 | + public $use_dashboard_widget; |
|
| 2510 | + |
|
| 2511 | + /** |
|
| 2512 | + * @var int $events_in_dashboard |
|
| 2513 | + */ |
|
| 2514 | + public $events_in_dashboard; |
|
| 2515 | + |
|
| 2516 | + /** |
|
| 2517 | + * @var boolean $use_event_timezones |
|
| 2518 | + */ |
|
| 2519 | + public $use_event_timezones; |
|
| 2520 | + |
|
| 2521 | + /** |
|
| 2522 | + * @var boolean $use_full_logging |
|
| 2523 | + */ |
|
| 2524 | + public $use_full_logging; |
|
| 2525 | + |
|
| 2526 | + /** |
|
| 2527 | + * @var string $log_file_name |
|
| 2528 | + */ |
|
| 2529 | + public $log_file_name; |
|
| 2530 | + |
|
| 2531 | + /** |
|
| 2532 | + * @var string $debug_file_name |
|
| 2533 | + */ |
|
| 2534 | + public $debug_file_name; |
|
| 2535 | + |
|
| 2536 | + /** |
|
| 2537 | + * @var boolean $use_remote_logging |
|
| 2538 | + */ |
|
| 2539 | + public $use_remote_logging; |
|
| 2540 | + |
|
| 2541 | + /** |
|
| 2542 | + * @var string $remote_logging_url |
|
| 2543 | + */ |
|
| 2544 | + public $remote_logging_url; |
|
| 2545 | + |
|
| 2546 | + /** |
|
| 2547 | + * @var boolean $show_reg_footer |
|
| 2548 | + */ |
|
| 2549 | + public $show_reg_footer; |
|
| 2550 | + |
|
| 2551 | + /** |
|
| 2552 | + * @var string $affiliate_id |
|
| 2553 | + */ |
|
| 2554 | + public $affiliate_id; |
|
| 2555 | + |
|
| 2556 | + /** |
|
| 2557 | + * help tours on or off (global setting) |
|
| 2558 | + * |
|
| 2559 | + * @var boolean |
|
| 2560 | + */ |
|
| 2561 | + public $help_tour_activation; |
|
| 2562 | + |
|
| 2563 | + /** |
|
| 2564 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2565 | + * but is incompatible with some server configuration errors |
|
| 2566 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2567 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2568 | + * |
|
| 2569 | + * @var boolean $encode_session_data |
|
| 2570 | + */ |
|
| 2571 | + private $encode_session_data = false; |
|
| 2572 | + |
|
| 2573 | + |
|
| 2574 | + |
|
| 2575 | + /** |
|
| 2576 | + * class constructor |
|
| 2577 | + * |
|
| 2578 | + * @access public |
|
| 2579 | + */ |
|
| 2580 | + public function __construct() |
|
| 2581 | + { |
|
| 2582 | + // set default general admin settings |
|
| 2583 | + $this->use_personnel_manager = true; |
|
| 2584 | + $this->use_dashboard_widget = true; |
|
| 2585 | + $this->events_in_dashboard = 30; |
|
| 2586 | + $this->use_event_timezones = false; |
|
| 2587 | + $this->use_full_logging = false; |
|
| 2588 | + $this->use_remote_logging = false; |
|
| 2589 | + $this->remote_logging_url = null; |
|
| 2590 | + $this->show_reg_footer = true; |
|
| 2591 | + $this->affiliate_id = 'default'; |
|
| 2592 | + $this->help_tour_activation = true; |
|
| 2593 | + $this->encode_session_data = false; |
|
| 2594 | + } |
|
| 2595 | + |
|
| 2596 | + |
|
| 2597 | + |
|
| 2598 | + /** |
|
| 2599 | + * @param bool $reset |
|
| 2600 | + * @return string |
|
| 2601 | + */ |
|
| 2602 | + public function log_file_name($reset = false) |
|
| 2603 | + { |
|
| 2604 | + if (empty($this->log_file_name) || $reset) { |
|
| 2605 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2606 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2607 | + } |
|
| 2608 | + return $this->log_file_name; |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + |
|
| 2612 | + |
|
| 2613 | + /** |
|
| 2614 | + * @param bool $reset |
|
| 2615 | + * @return string |
|
| 2616 | + */ |
|
| 2617 | + public function debug_file_name($reset = false) |
|
| 2618 | + { |
|
| 2619 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2620 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2621 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2622 | + } |
|
| 2623 | + return $this->debug_file_name; |
|
| 2624 | + } |
|
| 2625 | + |
|
| 2626 | + |
|
| 2627 | + |
|
| 2628 | + /** |
|
| 2629 | + * @return string |
|
| 2630 | + */ |
|
| 2631 | + public function affiliate_id() |
|
| 2632 | + { |
|
| 2633 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2634 | + } |
|
| 2635 | + |
|
| 2636 | + |
|
| 2637 | + |
|
| 2638 | + /** |
|
| 2639 | + * @return boolean |
|
| 2640 | + */ |
|
| 2641 | + public function encode_session_data() |
|
| 2642 | + { |
|
| 2643 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2644 | + } |
|
| 2645 | + |
|
| 2646 | + |
|
| 2647 | + |
|
| 2648 | + /** |
|
| 2649 | + * @param boolean $encode_session_data |
|
| 2650 | + */ |
|
| 2651 | + public function set_encode_session_data($encode_session_data) |
|
| 2652 | + { |
|
| 2653 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2654 | + } |
|
| 2655 | 2655 | |
| 2656 | 2656 | |
| 2657 | 2657 | |
@@ -2665,71 +2665,71 @@ discard block |
||
| 2665 | 2665 | class EE_Template_Config extends EE_Config_Base |
| 2666 | 2666 | { |
| 2667 | 2667 | |
| 2668 | - /** |
|
| 2669 | - * @var boolean $enable_default_style |
|
| 2670 | - */ |
|
| 2671 | - public $enable_default_style; |
|
| 2672 | - |
|
| 2673 | - /** |
|
| 2674 | - * @var string $custom_style_sheet |
|
| 2675 | - */ |
|
| 2676 | - public $custom_style_sheet; |
|
| 2677 | - |
|
| 2678 | - /** |
|
| 2679 | - * @var boolean $display_address_in_regform |
|
| 2680 | - */ |
|
| 2681 | - public $display_address_in_regform; |
|
| 2682 | - |
|
| 2683 | - /** |
|
| 2684 | - * @var int $display_description_on_multi_reg_page |
|
| 2685 | - */ |
|
| 2686 | - public $display_description_on_multi_reg_page; |
|
| 2687 | - |
|
| 2688 | - /** |
|
| 2689 | - * @var boolean $use_custom_templates |
|
| 2690 | - */ |
|
| 2691 | - public $use_custom_templates; |
|
| 2692 | - |
|
| 2693 | - /** |
|
| 2694 | - * @var string $current_espresso_theme |
|
| 2695 | - */ |
|
| 2696 | - public $current_espresso_theme; |
|
| 2697 | - |
|
| 2698 | - /** |
|
| 2699 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2700 | - */ |
|
| 2701 | - public $EED_Ticket_Selector; |
|
| 2702 | - |
|
| 2703 | - /** |
|
| 2704 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2705 | - */ |
|
| 2706 | - public $EED_Event_Single; |
|
| 2707 | - |
|
| 2708 | - /** |
|
| 2709 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2710 | - */ |
|
| 2711 | - public $EED_Events_Archive; |
|
| 2712 | - |
|
| 2713 | - |
|
| 2714 | - |
|
| 2715 | - /** |
|
| 2716 | - * class constructor |
|
| 2717 | - * |
|
| 2718 | - * @access public |
|
| 2719 | - */ |
|
| 2720 | - public function __construct() |
|
| 2721 | - { |
|
| 2722 | - // set default template settings |
|
| 2723 | - $this->enable_default_style = true; |
|
| 2724 | - $this->custom_style_sheet = null; |
|
| 2725 | - $this->display_address_in_regform = true; |
|
| 2726 | - $this->display_description_on_multi_reg_page = false; |
|
| 2727 | - $this->use_custom_templates = false; |
|
| 2728 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2729 | - $this->EED_Event_Single = null; |
|
| 2730 | - $this->EED_Events_Archive = null; |
|
| 2731 | - $this->EED_Ticket_Selector = null; |
|
| 2732 | - } |
|
| 2668 | + /** |
|
| 2669 | + * @var boolean $enable_default_style |
|
| 2670 | + */ |
|
| 2671 | + public $enable_default_style; |
|
| 2672 | + |
|
| 2673 | + /** |
|
| 2674 | + * @var string $custom_style_sheet |
|
| 2675 | + */ |
|
| 2676 | + public $custom_style_sheet; |
|
| 2677 | + |
|
| 2678 | + /** |
|
| 2679 | + * @var boolean $display_address_in_regform |
|
| 2680 | + */ |
|
| 2681 | + public $display_address_in_regform; |
|
| 2682 | + |
|
| 2683 | + /** |
|
| 2684 | + * @var int $display_description_on_multi_reg_page |
|
| 2685 | + */ |
|
| 2686 | + public $display_description_on_multi_reg_page; |
|
| 2687 | + |
|
| 2688 | + /** |
|
| 2689 | + * @var boolean $use_custom_templates |
|
| 2690 | + */ |
|
| 2691 | + public $use_custom_templates; |
|
| 2692 | + |
|
| 2693 | + /** |
|
| 2694 | + * @var string $current_espresso_theme |
|
| 2695 | + */ |
|
| 2696 | + public $current_espresso_theme; |
|
| 2697 | + |
|
| 2698 | + /** |
|
| 2699 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2700 | + */ |
|
| 2701 | + public $EED_Ticket_Selector; |
|
| 2702 | + |
|
| 2703 | + /** |
|
| 2704 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2705 | + */ |
|
| 2706 | + public $EED_Event_Single; |
|
| 2707 | + |
|
| 2708 | + /** |
|
| 2709 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2710 | + */ |
|
| 2711 | + public $EED_Events_Archive; |
|
| 2712 | + |
|
| 2713 | + |
|
| 2714 | + |
|
| 2715 | + /** |
|
| 2716 | + * class constructor |
|
| 2717 | + * |
|
| 2718 | + * @access public |
|
| 2719 | + */ |
|
| 2720 | + public function __construct() |
|
| 2721 | + { |
|
| 2722 | + // set default template settings |
|
| 2723 | + $this->enable_default_style = true; |
|
| 2724 | + $this->custom_style_sheet = null; |
|
| 2725 | + $this->display_address_in_regform = true; |
|
| 2726 | + $this->display_description_on_multi_reg_page = false; |
|
| 2727 | + $this->use_custom_templates = false; |
|
| 2728 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2729 | + $this->EED_Event_Single = null; |
|
| 2730 | + $this->EED_Events_Archive = null; |
|
| 2731 | + $this->EED_Ticket_Selector = null; |
|
| 2732 | + } |
|
| 2733 | 2733 | |
| 2734 | 2734 | } |
| 2735 | 2735 | |
@@ -2741,115 +2741,115 @@ discard block |
||
| 2741 | 2741 | class EE_Map_Config extends EE_Config_Base |
| 2742 | 2742 | { |
| 2743 | 2743 | |
| 2744 | - /** |
|
| 2745 | - * @var boolean $use_google_maps |
|
| 2746 | - */ |
|
| 2747 | - public $use_google_maps; |
|
| 2748 | - |
|
| 2749 | - /** |
|
| 2750 | - * @var string $api_key |
|
| 2751 | - */ |
|
| 2752 | - public $google_map_api_key; |
|
| 2753 | - |
|
| 2754 | - /** |
|
| 2755 | - * @var int $event_details_map_width |
|
| 2756 | - */ |
|
| 2757 | - public $event_details_map_width; |
|
| 2758 | - |
|
| 2759 | - /** |
|
| 2760 | - * @var int $event_details_map_height |
|
| 2761 | - */ |
|
| 2762 | - public $event_details_map_height; |
|
| 2763 | - |
|
| 2764 | - /** |
|
| 2765 | - * @var int $event_details_map_zoom |
|
| 2766 | - */ |
|
| 2767 | - public $event_details_map_zoom; |
|
| 2768 | - |
|
| 2769 | - /** |
|
| 2770 | - * @var boolean $event_details_display_nav |
|
| 2771 | - */ |
|
| 2772 | - public $event_details_display_nav; |
|
| 2773 | - |
|
| 2774 | - /** |
|
| 2775 | - * @var boolean $event_details_nav_size |
|
| 2776 | - */ |
|
| 2777 | - public $event_details_nav_size; |
|
| 2778 | - |
|
| 2779 | - /** |
|
| 2780 | - * @var string $event_details_control_type |
|
| 2781 | - */ |
|
| 2782 | - public $event_details_control_type; |
|
| 2783 | - |
|
| 2784 | - /** |
|
| 2785 | - * @var string $event_details_map_align |
|
| 2786 | - */ |
|
| 2787 | - public $event_details_map_align; |
|
| 2788 | - |
|
| 2789 | - /** |
|
| 2790 | - * @var int $event_list_map_width |
|
| 2791 | - */ |
|
| 2792 | - public $event_list_map_width; |
|
| 2793 | - |
|
| 2794 | - /** |
|
| 2795 | - * @var int $event_list_map_height |
|
| 2796 | - */ |
|
| 2797 | - public $event_list_map_height; |
|
| 2798 | - |
|
| 2799 | - /** |
|
| 2800 | - * @var int $event_list_map_zoom |
|
| 2801 | - */ |
|
| 2802 | - public $event_list_map_zoom; |
|
| 2803 | - |
|
| 2804 | - /** |
|
| 2805 | - * @var boolean $event_list_display_nav |
|
| 2806 | - */ |
|
| 2807 | - public $event_list_display_nav; |
|
| 2808 | - |
|
| 2809 | - /** |
|
| 2810 | - * @var boolean $event_list_nav_size |
|
| 2811 | - */ |
|
| 2812 | - public $event_list_nav_size; |
|
| 2813 | - |
|
| 2814 | - /** |
|
| 2815 | - * @var string $event_list_control_type |
|
| 2816 | - */ |
|
| 2817 | - public $event_list_control_type; |
|
| 2818 | - |
|
| 2819 | - /** |
|
| 2820 | - * @var string $event_list_map_align |
|
| 2821 | - */ |
|
| 2822 | - public $event_list_map_align; |
|
| 2823 | - |
|
| 2824 | - |
|
| 2825 | - |
|
| 2826 | - /** |
|
| 2827 | - * class constructor |
|
| 2828 | - * |
|
| 2829 | - * @access public |
|
| 2830 | - */ |
|
| 2831 | - public function __construct() |
|
| 2832 | - { |
|
| 2833 | - // set default map settings |
|
| 2834 | - $this->use_google_maps = true; |
|
| 2835 | - $this->google_map_api_key = ''; |
|
| 2836 | - // for event details pages (reg page) |
|
| 2837 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2838 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2839 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2840 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2841 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2842 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2843 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2844 | - // for event list pages |
|
| 2845 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2846 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2847 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2848 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2849 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2850 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2851 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2852 | - } |
|
| 2744 | + /** |
|
| 2745 | + * @var boolean $use_google_maps |
|
| 2746 | + */ |
|
| 2747 | + public $use_google_maps; |
|
| 2748 | + |
|
| 2749 | + /** |
|
| 2750 | + * @var string $api_key |
|
| 2751 | + */ |
|
| 2752 | + public $google_map_api_key; |
|
| 2753 | + |
|
| 2754 | + /** |
|
| 2755 | + * @var int $event_details_map_width |
|
| 2756 | + */ |
|
| 2757 | + public $event_details_map_width; |
|
| 2758 | + |
|
| 2759 | + /** |
|
| 2760 | + * @var int $event_details_map_height |
|
| 2761 | + */ |
|
| 2762 | + public $event_details_map_height; |
|
| 2763 | + |
|
| 2764 | + /** |
|
| 2765 | + * @var int $event_details_map_zoom |
|
| 2766 | + */ |
|
| 2767 | + public $event_details_map_zoom; |
|
| 2768 | + |
|
| 2769 | + /** |
|
| 2770 | + * @var boolean $event_details_display_nav |
|
| 2771 | + */ |
|
| 2772 | + public $event_details_display_nav; |
|
| 2773 | + |
|
| 2774 | + /** |
|
| 2775 | + * @var boolean $event_details_nav_size |
|
| 2776 | + */ |
|
| 2777 | + public $event_details_nav_size; |
|
| 2778 | + |
|
| 2779 | + /** |
|
| 2780 | + * @var string $event_details_control_type |
|
| 2781 | + */ |
|
| 2782 | + public $event_details_control_type; |
|
| 2783 | + |
|
| 2784 | + /** |
|
| 2785 | + * @var string $event_details_map_align |
|
| 2786 | + */ |
|
| 2787 | + public $event_details_map_align; |
|
| 2788 | + |
|
| 2789 | + /** |
|
| 2790 | + * @var int $event_list_map_width |
|
| 2791 | + */ |
|
| 2792 | + public $event_list_map_width; |
|
| 2793 | + |
|
| 2794 | + /** |
|
| 2795 | + * @var int $event_list_map_height |
|
| 2796 | + */ |
|
| 2797 | + public $event_list_map_height; |
|
| 2798 | + |
|
| 2799 | + /** |
|
| 2800 | + * @var int $event_list_map_zoom |
|
| 2801 | + */ |
|
| 2802 | + public $event_list_map_zoom; |
|
| 2803 | + |
|
| 2804 | + /** |
|
| 2805 | + * @var boolean $event_list_display_nav |
|
| 2806 | + */ |
|
| 2807 | + public $event_list_display_nav; |
|
| 2808 | + |
|
| 2809 | + /** |
|
| 2810 | + * @var boolean $event_list_nav_size |
|
| 2811 | + */ |
|
| 2812 | + public $event_list_nav_size; |
|
| 2813 | + |
|
| 2814 | + /** |
|
| 2815 | + * @var string $event_list_control_type |
|
| 2816 | + */ |
|
| 2817 | + public $event_list_control_type; |
|
| 2818 | + |
|
| 2819 | + /** |
|
| 2820 | + * @var string $event_list_map_align |
|
| 2821 | + */ |
|
| 2822 | + public $event_list_map_align; |
|
| 2823 | + |
|
| 2824 | + |
|
| 2825 | + |
|
| 2826 | + /** |
|
| 2827 | + * class constructor |
|
| 2828 | + * |
|
| 2829 | + * @access public |
|
| 2830 | + */ |
|
| 2831 | + public function __construct() |
|
| 2832 | + { |
|
| 2833 | + // set default map settings |
|
| 2834 | + $this->use_google_maps = true; |
|
| 2835 | + $this->google_map_api_key = ''; |
|
| 2836 | + // for event details pages (reg page) |
|
| 2837 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2838 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2839 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2840 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2841 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2842 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2843 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2844 | + // for event list pages |
|
| 2845 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2846 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2847 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2848 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2849 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2850 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2851 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2852 | + } |
|
| 2853 | 2853 | |
| 2854 | 2854 | } |
| 2855 | 2855 | |
@@ -2861,47 +2861,47 @@ discard block |
||
| 2861 | 2861 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2862 | 2862 | { |
| 2863 | 2863 | |
| 2864 | - public $display_status_banner; |
|
| 2864 | + public $display_status_banner; |
|
| 2865 | 2865 | |
| 2866 | - public $display_description; |
|
| 2866 | + public $display_description; |
|
| 2867 | 2867 | |
| 2868 | - public $display_ticket_selector; |
|
| 2868 | + public $display_ticket_selector; |
|
| 2869 | 2869 | |
| 2870 | - public $display_datetimes; |
|
| 2870 | + public $display_datetimes; |
|
| 2871 | 2871 | |
| 2872 | - public $display_venue; |
|
| 2872 | + public $display_venue; |
|
| 2873 | 2873 | |
| 2874 | - public $display_expired_events; |
|
| 2874 | + public $display_expired_events; |
|
| 2875 | 2875 | |
| 2876 | - public $use_sortable_display_order; |
|
| 2876 | + public $use_sortable_display_order; |
|
| 2877 | 2877 | |
| 2878 | - public $display_order_tickets; |
|
| 2878 | + public $display_order_tickets; |
|
| 2879 | 2879 | |
| 2880 | - public $display_order_datetimes; |
|
| 2880 | + public $display_order_datetimes; |
|
| 2881 | 2881 | |
| 2882 | - public $display_order_event; |
|
| 2882 | + public $display_order_event; |
|
| 2883 | 2883 | |
| 2884 | - public $display_order_venue; |
|
| 2884 | + public $display_order_venue; |
|
| 2885 | 2885 | |
| 2886 | 2886 | |
| 2887 | 2887 | |
| 2888 | - /** |
|
| 2889 | - * class constructor |
|
| 2890 | - */ |
|
| 2891 | - public function __construct() |
|
| 2892 | - { |
|
| 2893 | - $this->display_status_banner = 0; |
|
| 2894 | - $this->display_description = 1; |
|
| 2895 | - $this->display_ticket_selector = 0; |
|
| 2896 | - $this->display_datetimes = 1; |
|
| 2897 | - $this->display_venue = 0; |
|
| 2898 | - $this->display_expired_events = 0; |
|
| 2899 | - $this->use_sortable_display_order = false; |
|
| 2900 | - $this->display_order_tickets = 100; |
|
| 2901 | - $this->display_order_datetimes = 110; |
|
| 2902 | - $this->display_order_event = 120; |
|
| 2903 | - $this->display_order_venue = 130; |
|
| 2904 | - } |
|
| 2888 | + /** |
|
| 2889 | + * class constructor |
|
| 2890 | + */ |
|
| 2891 | + public function __construct() |
|
| 2892 | + { |
|
| 2893 | + $this->display_status_banner = 0; |
|
| 2894 | + $this->display_description = 1; |
|
| 2895 | + $this->display_ticket_selector = 0; |
|
| 2896 | + $this->display_datetimes = 1; |
|
| 2897 | + $this->display_venue = 0; |
|
| 2898 | + $this->display_expired_events = 0; |
|
| 2899 | + $this->use_sortable_display_order = false; |
|
| 2900 | + $this->display_order_tickets = 100; |
|
| 2901 | + $this->display_order_datetimes = 110; |
|
| 2902 | + $this->display_order_event = 120; |
|
| 2903 | + $this->display_order_venue = 130; |
|
| 2904 | + } |
|
| 2905 | 2905 | } |
| 2906 | 2906 | |
| 2907 | 2907 | |
@@ -2912,35 +2912,35 @@ discard block |
||
| 2912 | 2912 | class EE_Event_Single_Config extends EE_Config_Base |
| 2913 | 2913 | { |
| 2914 | 2914 | |
| 2915 | - public $display_status_banner_single; |
|
| 2915 | + public $display_status_banner_single; |
|
| 2916 | 2916 | |
| 2917 | - public $display_venue; |
|
| 2917 | + public $display_venue; |
|
| 2918 | 2918 | |
| 2919 | - public $use_sortable_display_order; |
|
| 2919 | + public $use_sortable_display_order; |
|
| 2920 | 2920 | |
| 2921 | - public $display_order_tickets; |
|
| 2921 | + public $display_order_tickets; |
|
| 2922 | 2922 | |
| 2923 | - public $display_order_datetimes; |
|
| 2923 | + public $display_order_datetimes; |
|
| 2924 | 2924 | |
| 2925 | - public $display_order_event; |
|
| 2925 | + public $display_order_event; |
|
| 2926 | 2926 | |
| 2927 | - public $display_order_venue; |
|
| 2927 | + public $display_order_venue; |
|
| 2928 | 2928 | |
| 2929 | 2929 | |
| 2930 | 2930 | |
| 2931 | - /** |
|
| 2932 | - * class constructor |
|
| 2933 | - */ |
|
| 2934 | - public function __construct() |
|
| 2935 | - { |
|
| 2936 | - $this->display_status_banner_single = 0; |
|
| 2937 | - $this->display_venue = 1; |
|
| 2938 | - $this->use_sortable_display_order = false; |
|
| 2939 | - $this->display_order_tickets = 100; |
|
| 2940 | - $this->display_order_datetimes = 110; |
|
| 2941 | - $this->display_order_event = 120; |
|
| 2942 | - $this->display_order_venue = 130; |
|
| 2943 | - } |
|
| 2931 | + /** |
|
| 2932 | + * class constructor |
|
| 2933 | + */ |
|
| 2934 | + public function __construct() |
|
| 2935 | + { |
|
| 2936 | + $this->display_status_banner_single = 0; |
|
| 2937 | + $this->display_venue = 1; |
|
| 2938 | + $this->use_sortable_display_order = false; |
|
| 2939 | + $this->display_order_tickets = 100; |
|
| 2940 | + $this->display_order_datetimes = 110; |
|
| 2941 | + $this->display_order_event = 120; |
|
| 2942 | + $this->display_order_venue = 130; |
|
| 2943 | + } |
|
| 2944 | 2944 | } |
| 2945 | 2945 | |
| 2946 | 2946 | |
@@ -2951,152 +2951,152 @@ discard block |
||
| 2951 | 2951 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2952 | 2952 | { |
| 2953 | 2953 | |
| 2954 | - /** |
|
| 2955 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2956 | - */ |
|
| 2957 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2958 | - |
|
| 2959 | - /** |
|
| 2960 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2961 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2962 | - */ |
|
| 2963 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2964 | - |
|
| 2965 | - /** |
|
| 2966 | - * @var boolean $show_ticket_sale_columns |
|
| 2967 | - */ |
|
| 2968 | - public $show_ticket_sale_columns; |
|
| 2969 | - |
|
| 2970 | - /** |
|
| 2971 | - * @var boolean $show_ticket_details |
|
| 2972 | - */ |
|
| 2973 | - public $show_ticket_details; |
|
| 2974 | - |
|
| 2975 | - /** |
|
| 2976 | - * @var boolean $show_expired_tickets |
|
| 2977 | - */ |
|
| 2978 | - public $show_expired_tickets; |
|
| 2979 | - |
|
| 2980 | - /** |
|
| 2981 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 2982 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 2983 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2984 | - * |
|
| 2985 | - * @var string $show_datetime_selector |
|
| 2986 | - */ |
|
| 2987 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2988 | - |
|
| 2989 | - /** |
|
| 2990 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2991 | - * |
|
| 2992 | - * @var int $datetime_selector_threshold |
|
| 2993 | - */ |
|
| 2994 | - private $datetime_selector_threshold = 3; |
|
| 2995 | - |
|
| 2996 | - |
|
| 2997 | - |
|
| 2998 | - /** |
|
| 2999 | - * class constructor |
|
| 3000 | - */ |
|
| 3001 | - public function __construct() |
|
| 3002 | - { |
|
| 3003 | - $this->show_ticket_sale_columns = true; |
|
| 3004 | - $this->show_ticket_details = true; |
|
| 3005 | - $this->show_expired_tickets = true; |
|
| 3006 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3007 | - $this->datetime_selector_threshold = 3; |
|
| 3008 | - } |
|
| 3009 | - |
|
| 3010 | - |
|
| 3011 | - |
|
| 3012 | - /** |
|
| 3013 | - * returns true if a datetime selector should be displayed |
|
| 3014 | - * |
|
| 3015 | - * @param array $datetimes |
|
| 3016 | - * @return bool |
|
| 3017 | - */ |
|
| 3018 | - public function showDatetimeSelector(array $datetimes) |
|
| 3019 | - { |
|
| 3020 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3021 | - return ! ( |
|
| 3022 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3023 | - || ( |
|
| 3024 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3025 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3026 | - ) |
|
| 3027 | - ); |
|
| 3028 | - } |
|
| 3029 | - |
|
| 3030 | - |
|
| 3031 | - |
|
| 3032 | - /** |
|
| 3033 | - * @return string |
|
| 3034 | - */ |
|
| 3035 | - public function getShowDatetimeSelector() |
|
| 3036 | - { |
|
| 3037 | - return $this->show_datetime_selector; |
|
| 3038 | - } |
|
| 3039 | - |
|
| 3040 | - |
|
| 3041 | - |
|
| 3042 | - /** |
|
| 3043 | - * @param bool $keys_only |
|
| 3044 | - * @return array |
|
| 3045 | - */ |
|
| 3046 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3047 | - { |
|
| 3048 | - return $keys_only |
|
| 3049 | - ? array( |
|
| 3050 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3051 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3052 | - ) |
|
| 3053 | - : array( |
|
| 3054 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3055 | - 'Do not show date & time filter', 'event_espresso' |
|
| 3056 | - ), |
|
| 3057 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3058 | - 'Maybe show date & time filter', 'event_espresso' |
|
| 3059 | - ), |
|
| 3060 | - ); |
|
| 3061 | - } |
|
| 3062 | - |
|
| 3063 | - |
|
| 3064 | - |
|
| 3065 | - /** |
|
| 3066 | - * @param string $show_datetime_selector |
|
| 3067 | - */ |
|
| 3068 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3069 | - { |
|
| 3070 | - $this->show_datetime_selector = in_array( |
|
| 3071 | - $show_datetime_selector, |
|
| 3072 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3073 | - true |
|
| 3074 | - ) |
|
| 3075 | - ? $show_datetime_selector |
|
| 3076 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3077 | - } |
|
| 3078 | - |
|
| 3079 | - |
|
| 3080 | - |
|
| 3081 | - /** |
|
| 3082 | - * @return int |
|
| 3083 | - */ |
|
| 3084 | - public function getDatetimeSelectorThreshold() |
|
| 3085 | - { |
|
| 3086 | - return $this->datetime_selector_threshold; |
|
| 3087 | - } |
|
| 3088 | - |
|
| 3089 | - |
|
| 3090 | - |
|
| 3091 | - |
|
| 3092 | - /** |
|
| 3093 | - * @param int $datetime_selector_threshold |
|
| 3094 | - */ |
|
| 3095 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3096 | - { |
|
| 3097 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3098 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3099 | - } |
|
| 2954 | + /** |
|
| 2955 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2956 | + */ |
|
| 2957 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2958 | + |
|
| 2959 | + /** |
|
| 2960 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2961 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2962 | + */ |
|
| 2963 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2964 | + |
|
| 2965 | + /** |
|
| 2966 | + * @var boolean $show_ticket_sale_columns |
|
| 2967 | + */ |
|
| 2968 | + public $show_ticket_sale_columns; |
|
| 2969 | + |
|
| 2970 | + /** |
|
| 2971 | + * @var boolean $show_ticket_details |
|
| 2972 | + */ |
|
| 2973 | + public $show_ticket_details; |
|
| 2974 | + |
|
| 2975 | + /** |
|
| 2976 | + * @var boolean $show_expired_tickets |
|
| 2977 | + */ |
|
| 2978 | + public $show_expired_tickets; |
|
| 2979 | + |
|
| 2980 | + /** |
|
| 2981 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 2982 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 2983 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2984 | + * |
|
| 2985 | + * @var string $show_datetime_selector |
|
| 2986 | + */ |
|
| 2987 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2988 | + |
|
| 2989 | + /** |
|
| 2990 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2991 | + * |
|
| 2992 | + * @var int $datetime_selector_threshold |
|
| 2993 | + */ |
|
| 2994 | + private $datetime_selector_threshold = 3; |
|
| 2995 | + |
|
| 2996 | + |
|
| 2997 | + |
|
| 2998 | + /** |
|
| 2999 | + * class constructor |
|
| 3000 | + */ |
|
| 3001 | + public function __construct() |
|
| 3002 | + { |
|
| 3003 | + $this->show_ticket_sale_columns = true; |
|
| 3004 | + $this->show_ticket_details = true; |
|
| 3005 | + $this->show_expired_tickets = true; |
|
| 3006 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3007 | + $this->datetime_selector_threshold = 3; |
|
| 3008 | + } |
|
| 3009 | + |
|
| 3010 | + |
|
| 3011 | + |
|
| 3012 | + /** |
|
| 3013 | + * returns true if a datetime selector should be displayed |
|
| 3014 | + * |
|
| 3015 | + * @param array $datetimes |
|
| 3016 | + * @return bool |
|
| 3017 | + */ |
|
| 3018 | + public function showDatetimeSelector(array $datetimes) |
|
| 3019 | + { |
|
| 3020 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3021 | + return ! ( |
|
| 3022 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3023 | + || ( |
|
| 3024 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3025 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3026 | + ) |
|
| 3027 | + ); |
|
| 3028 | + } |
|
| 3029 | + |
|
| 3030 | + |
|
| 3031 | + |
|
| 3032 | + /** |
|
| 3033 | + * @return string |
|
| 3034 | + */ |
|
| 3035 | + public function getShowDatetimeSelector() |
|
| 3036 | + { |
|
| 3037 | + return $this->show_datetime_selector; |
|
| 3038 | + } |
|
| 3039 | + |
|
| 3040 | + |
|
| 3041 | + |
|
| 3042 | + /** |
|
| 3043 | + * @param bool $keys_only |
|
| 3044 | + * @return array |
|
| 3045 | + */ |
|
| 3046 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3047 | + { |
|
| 3048 | + return $keys_only |
|
| 3049 | + ? array( |
|
| 3050 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3051 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3052 | + ) |
|
| 3053 | + : array( |
|
| 3054 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3055 | + 'Do not show date & time filter', 'event_espresso' |
|
| 3056 | + ), |
|
| 3057 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3058 | + 'Maybe show date & time filter', 'event_espresso' |
|
| 3059 | + ), |
|
| 3060 | + ); |
|
| 3061 | + } |
|
| 3062 | + |
|
| 3063 | + |
|
| 3064 | + |
|
| 3065 | + /** |
|
| 3066 | + * @param string $show_datetime_selector |
|
| 3067 | + */ |
|
| 3068 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3069 | + { |
|
| 3070 | + $this->show_datetime_selector = in_array( |
|
| 3071 | + $show_datetime_selector, |
|
| 3072 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3073 | + true |
|
| 3074 | + ) |
|
| 3075 | + ? $show_datetime_selector |
|
| 3076 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3077 | + } |
|
| 3078 | + |
|
| 3079 | + |
|
| 3080 | + |
|
| 3081 | + /** |
|
| 3082 | + * @return int |
|
| 3083 | + */ |
|
| 3084 | + public function getDatetimeSelectorThreshold() |
|
| 3085 | + { |
|
| 3086 | + return $this->datetime_selector_threshold; |
|
| 3087 | + } |
|
| 3088 | + |
|
| 3089 | + |
|
| 3090 | + |
|
| 3091 | + |
|
| 3092 | + /** |
|
| 3093 | + * @param int $datetime_selector_threshold |
|
| 3094 | + */ |
|
| 3095 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3096 | + { |
|
| 3097 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3098 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3099 | + } |
|
| 3100 | 3100 | |
| 3101 | 3101 | |
| 3102 | 3102 | |
@@ -3114,85 +3114,85 @@ discard block |
||
| 3114 | 3114 | class EE_Environment_Config extends EE_Config_Base |
| 3115 | 3115 | { |
| 3116 | 3116 | |
| 3117 | - /** |
|
| 3118 | - * Hold any php environment variables that we want to track. |
|
| 3119 | - * |
|
| 3120 | - * @var stdClass; |
|
| 3121 | - */ |
|
| 3122 | - public $php; |
|
| 3123 | - |
|
| 3124 | - |
|
| 3125 | - |
|
| 3126 | - /** |
|
| 3127 | - * constructor |
|
| 3128 | - */ |
|
| 3129 | - public function __construct() |
|
| 3130 | - { |
|
| 3131 | - $this->php = new stdClass(); |
|
| 3132 | - $this->_set_php_values(); |
|
| 3133 | - } |
|
| 3134 | - |
|
| 3135 | - |
|
| 3136 | - |
|
| 3137 | - /** |
|
| 3138 | - * This sets the php environment variables. |
|
| 3139 | - * |
|
| 3140 | - * @since 4.4.0 |
|
| 3141 | - * @return void |
|
| 3142 | - */ |
|
| 3143 | - protected function _set_php_values() |
|
| 3144 | - { |
|
| 3145 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3146 | - $this->php->version = phpversion(); |
|
| 3147 | - } |
|
| 3148 | - |
|
| 3149 | - |
|
| 3150 | - |
|
| 3151 | - /** |
|
| 3152 | - * helper method for determining whether input_count is |
|
| 3153 | - * reaching the potential maximum the server can handle |
|
| 3154 | - * according to max_input_vars |
|
| 3155 | - * |
|
| 3156 | - * @param int $input_count the count of input vars. |
|
| 3157 | - * @return array { |
|
| 3158 | - * An array that represents whether available space and if no available space the error |
|
| 3159 | - * message. |
|
| 3160 | - * @type bool $has_space whether more inputs can be added. |
|
| 3161 | - * @type string $msg Any message to be displayed. |
|
| 3162 | - * } |
|
| 3163 | - */ |
|
| 3164 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3165 | - { |
|
| 3166 | - if (! empty($this->php->max_input_vars) |
|
| 3167 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3168 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3169 | - ) { |
|
| 3170 | - return sprintf( |
|
| 3171 | - __( |
|
| 3172 | - '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.', |
|
| 3173 | - 'event_espresso' |
|
| 3174 | - ), |
|
| 3175 | - '<br>', |
|
| 3176 | - $input_count, |
|
| 3177 | - $this->php->max_input_vars |
|
| 3178 | - ); |
|
| 3179 | - } else { |
|
| 3180 | - return ''; |
|
| 3181 | - } |
|
| 3182 | - } |
|
| 3183 | - |
|
| 3184 | - |
|
| 3185 | - |
|
| 3186 | - /** |
|
| 3187 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3188 | - * |
|
| 3189 | - * @since 4.4.1 |
|
| 3190 | - * @return void |
|
| 3191 | - */ |
|
| 3192 | - public function recheck_values() |
|
| 3193 | - { |
|
| 3194 | - $this->_set_php_values(); |
|
| 3195 | - } |
|
| 3117 | + /** |
|
| 3118 | + * Hold any php environment variables that we want to track. |
|
| 3119 | + * |
|
| 3120 | + * @var stdClass; |
|
| 3121 | + */ |
|
| 3122 | + public $php; |
|
| 3123 | + |
|
| 3124 | + |
|
| 3125 | + |
|
| 3126 | + /** |
|
| 3127 | + * constructor |
|
| 3128 | + */ |
|
| 3129 | + public function __construct() |
|
| 3130 | + { |
|
| 3131 | + $this->php = new stdClass(); |
|
| 3132 | + $this->_set_php_values(); |
|
| 3133 | + } |
|
| 3134 | + |
|
| 3135 | + |
|
| 3136 | + |
|
| 3137 | + /** |
|
| 3138 | + * This sets the php environment variables. |
|
| 3139 | + * |
|
| 3140 | + * @since 4.4.0 |
|
| 3141 | + * @return void |
|
| 3142 | + */ |
|
| 3143 | + protected function _set_php_values() |
|
| 3144 | + { |
|
| 3145 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3146 | + $this->php->version = phpversion(); |
|
| 3147 | + } |
|
| 3148 | + |
|
| 3149 | + |
|
| 3150 | + |
|
| 3151 | + /** |
|
| 3152 | + * helper method for determining whether input_count is |
|
| 3153 | + * reaching the potential maximum the server can handle |
|
| 3154 | + * according to max_input_vars |
|
| 3155 | + * |
|
| 3156 | + * @param int $input_count the count of input vars. |
|
| 3157 | + * @return array { |
|
| 3158 | + * An array that represents whether available space and if no available space the error |
|
| 3159 | + * message. |
|
| 3160 | + * @type bool $has_space whether more inputs can be added. |
|
| 3161 | + * @type string $msg Any message to be displayed. |
|
| 3162 | + * } |
|
| 3163 | + */ |
|
| 3164 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3165 | + { |
|
| 3166 | + if (! empty($this->php->max_input_vars) |
|
| 3167 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3168 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3169 | + ) { |
|
| 3170 | + return sprintf( |
|
| 3171 | + __( |
|
| 3172 | + '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.', |
|
| 3173 | + 'event_espresso' |
|
| 3174 | + ), |
|
| 3175 | + '<br>', |
|
| 3176 | + $input_count, |
|
| 3177 | + $this->php->max_input_vars |
|
| 3178 | + ); |
|
| 3179 | + } else { |
|
| 3180 | + return ''; |
|
| 3181 | + } |
|
| 3182 | + } |
|
| 3183 | + |
|
| 3184 | + |
|
| 3185 | + |
|
| 3186 | + /** |
|
| 3187 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3188 | + * |
|
| 3189 | + * @since 4.4.1 |
|
| 3190 | + * @return void |
|
| 3191 | + */ |
|
| 3192 | + public function recheck_values() |
|
| 3193 | + { |
|
| 3194 | + $this->_set_php_values(); |
|
| 3195 | + } |
|
| 3196 | 3196 | |
| 3197 | 3197 | |
| 3198 | 3198 | |
@@ -3210,22 +3210,22 @@ discard block |
||
| 3210 | 3210 | class EE_Tax_Config extends EE_Config_Base |
| 3211 | 3211 | { |
| 3212 | 3212 | |
| 3213 | - /* |
|
| 3213 | + /* |
|
| 3214 | 3214 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3215 | 3215 | * |
| 3216 | 3216 | * @var boolean $prices_displayed_including_taxes |
| 3217 | 3217 | */ |
| 3218 | - public $prices_displayed_including_taxes; |
|
| 3218 | + public $prices_displayed_including_taxes; |
|
| 3219 | 3219 | |
| 3220 | 3220 | |
| 3221 | 3221 | |
| 3222 | - /** |
|
| 3223 | - * class constructor |
|
| 3224 | - */ |
|
| 3225 | - public function __construct() |
|
| 3226 | - { |
|
| 3227 | - $this->prices_displayed_including_taxes = true; |
|
| 3228 | - } |
|
| 3222 | + /** |
|
| 3223 | + * class constructor |
|
| 3224 | + */ |
|
| 3225 | + public function __construct() |
|
| 3226 | + { |
|
| 3227 | + $this->prices_displayed_including_taxes = true; |
|
| 3228 | + } |
|
| 3229 | 3229 | } |
| 3230 | 3230 | |
| 3231 | 3231 | |
@@ -3240,17 +3240,17 @@ discard block |
||
| 3240 | 3240 | class EE_Messages_Config extends EE_Config_Base |
| 3241 | 3241 | { |
| 3242 | 3242 | |
| 3243 | - /** |
|
| 3244 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3245 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3246 | - * |
|
| 3247 | - * @var integer |
|
| 3248 | - */ |
|
| 3249 | - public $delete_threshold; |
|
| 3250 | - |
|
| 3251 | - public function __construct() { |
|
| 3252 | - $this->delete_threshold = 0; |
|
| 3253 | - } |
|
| 3243 | + /** |
|
| 3244 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3245 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3246 | + * |
|
| 3247 | + * @var integer |
|
| 3248 | + */ |
|
| 3249 | + public $delete_threshold; |
|
| 3250 | + |
|
| 3251 | + public function __construct() { |
|
| 3252 | + $this->delete_threshold = 0; |
|
| 3253 | + } |
|
| 3254 | 3254 | } |
| 3255 | 3255 | |
| 3256 | 3256 | |
@@ -3262,34 +3262,34 @@ discard block |
||
| 3262 | 3262 | class EE_Gateway_Config extends EE_Config_Base |
| 3263 | 3263 | { |
| 3264 | 3264 | |
| 3265 | - /** |
|
| 3266 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3267 | - * with any config info the gateway wants to store |
|
| 3268 | - * |
|
| 3269 | - * @var array |
|
| 3270 | - */ |
|
| 3271 | - public $payment_settings; |
|
| 3272 | - |
|
| 3273 | - /** |
|
| 3274 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3275 | - * the gateway is stored in the uploads directory |
|
| 3276 | - * |
|
| 3277 | - * @var array |
|
| 3278 | - */ |
|
| 3279 | - public $active_gateways; |
|
| 3280 | - |
|
| 3281 | - |
|
| 3282 | - |
|
| 3283 | - /** |
|
| 3284 | - * class constructor |
|
| 3285 | - * |
|
| 3286 | - * @deprecated |
|
| 3287 | - */ |
|
| 3288 | - public function __construct() |
|
| 3289 | - { |
|
| 3290 | - $this->payment_settings = array(); |
|
| 3291 | - $this->active_gateways = array('Invoice' => false); |
|
| 3292 | - } |
|
| 3265 | + /** |
|
| 3266 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3267 | + * with any config info the gateway wants to store |
|
| 3268 | + * |
|
| 3269 | + * @var array |
|
| 3270 | + */ |
|
| 3271 | + public $payment_settings; |
|
| 3272 | + |
|
| 3273 | + /** |
|
| 3274 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3275 | + * the gateway is stored in the uploads directory |
|
| 3276 | + * |
|
| 3277 | + * @var array |
|
| 3278 | + */ |
|
| 3279 | + public $active_gateways; |
|
| 3280 | + |
|
| 3281 | + |
|
| 3282 | + |
|
| 3283 | + /** |
|
| 3284 | + * class constructor |
|
| 3285 | + * |
|
| 3286 | + * @deprecated |
|
| 3287 | + */ |
|
| 3288 | + public function __construct() |
|
| 3289 | + { |
|
| 3290 | + $this->payment_settings = array(); |
|
| 3291 | + $this->active_gateways = array('Invoice' => false); |
|
| 3292 | + } |
|
| 3293 | 3293 | } |
| 3294 | 3294 | |
| 3295 | 3295 | // End of file EE_Config.core.php |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use EventEspresso\core\services\request\ResponseInterface; |
| 9 | 9 | |
| 10 | 10 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 11 | - exit('No direct script access allowed'); |
|
| 11 | + exit('No direct script access allowed'); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | |
@@ -25,891 +25,891 @@ discard block |
||
| 25 | 25 | class EE_Dependency_Map |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * This means that the requested class dependency is not present in the dependency map |
|
| 30 | - */ |
|
| 31 | - const not_registered = 0; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 35 | - */ |
|
| 36 | - const load_new_object = 1; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 40 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 41 | - */ |
|
| 42 | - const load_from_cache = 2; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * When registering a dependency, |
|
| 46 | - * this indicates to keep any existing dependencies that already exist, |
|
| 47 | - * and simply discard any new dependencies declared in the incoming data |
|
| 48 | - */ |
|
| 49 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * When registering a dependency, |
|
| 53 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 54 | - */ |
|
| 55 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @type EE_Dependency_Map $_instance |
|
| 61 | - */ |
|
| 62 | - protected static $_instance; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type RequestInterface $request |
|
| 66 | - */ |
|
| 67 | - protected $request; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @type LegacyRequestInterface $legacy_request |
|
| 71 | - */ |
|
| 72 | - protected $legacy_request; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type ResponseInterface $response |
|
| 76 | - */ |
|
| 77 | - protected $response; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @type LoaderInterface $loader |
|
| 81 | - */ |
|
| 82 | - protected $loader; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @type array $_dependency_map |
|
| 86 | - */ |
|
| 87 | - protected $_dependency_map = array(); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @type array $_class_loaders |
|
| 91 | - */ |
|
| 92 | - protected $_class_loaders = array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @type array $_aliases |
|
| 96 | - */ |
|
| 97 | - protected $_aliases = array(); |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * EE_Dependency_Map constructor. |
|
| 103 | - */ |
|
| 104 | - protected function __construct() |
|
| 105 | - { |
|
| 106 | - // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 107 | - do_action('EE_Dependency_Map____construct'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @throws InvalidDataTypeException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - */ |
|
| 117 | - public function initialize() |
|
| 118 | - { |
|
| 119 | - $this->_register_core_dependencies(); |
|
| 120 | - $this->_register_core_class_loaders(); |
|
| 121 | - $this->_register_core_aliases(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @singleton method used to instantiate class object |
|
| 128 | - * @return EE_Dependency_Map |
|
| 129 | - */ |
|
| 130 | - public static function instance() { |
|
| 131 | - // check if class object is instantiated, and instantiated properly |
|
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | - self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
|
| 134 | - } |
|
| 135 | - return self::$_instance; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param RequestInterface $request |
|
| 141 | - */ |
|
| 142 | - public function setRequest(RequestInterface $request) |
|
| 143 | - { |
|
| 144 | - $this->request = $request; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @param LegacyRequestInterface $legacy_request |
|
| 150 | - */ |
|
| 151 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 152 | - { |
|
| 153 | - $this->legacy_request = $legacy_request; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param ResponseInterface $response |
|
| 159 | - */ |
|
| 160 | - public function setResponse(ResponseInterface $response) |
|
| 161 | - { |
|
| 162 | - $this->response = $response; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param LoaderInterface $loader |
|
| 169 | - */ |
|
| 170 | - public function setLoader(LoaderInterface $loader) |
|
| 171 | - { |
|
| 172 | - $this->loader = $loader; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param string $class |
|
| 179 | - * @param array $dependencies |
|
| 180 | - * @param int $overwrite |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public static function register_dependencies( |
|
| 184 | - $class, |
|
| 185 | - array $dependencies, |
|
| 186 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 187 | - ) { |
|
| 188 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 195 | - * to the class specified by the first parameter. |
|
| 196 | - * IMPORTANT !!! |
|
| 197 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 198 | - * the order of the constructor parameters for the class in question. |
|
| 199 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 200 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 201 | - * |
|
| 202 | - * @param string $class |
|
| 203 | - * @param array $dependencies |
|
| 204 | - * @param int $overwrite |
|
| 205 | - * @return bool |
|
| 206 | - */ |
|
| 207 | - public function registerDependencies( |
|
| 208 | - $class, |
|
| 209 | - array $dependencies, |
|
| 210 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 211 | - ) { |
|
| 212 | - $class = trim($class, '\\'); |
|
| 213 | - $registered = false; |
|
| 214 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 216 | - } |
|
| 217 | - // we need to make sure that any aliases used when registering a dependency |
|
| 218 | - // get resolved to the correct class name |
|
| 219 | - foreach ($dependencies as $dependency => $load_source) { |
|
| 220 | - $alias = self::$_instance->get_alias($dependency); |
|
| 221 | - if ( |
|
| 222 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 223 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 224 | - ) { |
|
| 225 | - unset($dependencies[$dependency]); |
|
| 226 | - $dependencies[$alias] = $load_source; |
|
| 227 | - $registered = true; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - // now add our two lists of dependencies together. |
|
| 231 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 232 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 233 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 234 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 235 | - // especially with numerically indexed arrays |
|
| 236 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 237 | - // now we need to ensure that the resulting dependencies |
|
| 238 | - // array only has the entries that are required for the class |
|
| 239 | - // so first count how many dependencies were originally registered for the class |
|
| 240 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 241 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 242 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 243 | - // then truncate the final array to match that count |
|
| 244 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 245 | - // otherwise just take the incoming array because nothing previously existed |
|
| 246 | - : $dependencies; |
|
| 247 | - return $registered; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @param string $class_name |
|
| 254 | - * @param string $loader |
|
| 255 | - * @return bool |
|
| 256 | - * @throws DomainException |
|
| 257 | - */ |
|
| 258 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 259 | - { |
|
| 260 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | - throw new DomainException( |
|
| 262 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 266 | - if ( |
|
| 267 | - ! is_callable($loader) |
|
| 268 | - && ( |
|
| 269 | - strpos($loader, 'load_') !== 0 |
|
| 270 | - || ! method_exists('EE_Registry', $loader) |
|
| 271 | - ) |
|
| 272 | - ) { |
|
| 273 | - throw new DomainException( |
|
| 274 | - sprintf( |
|
| 275 | - esc_html__( |
|
| 276 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 277 | - 'event_espresso' |
|
| 278 | - ), |
|
| 279 | - $loader |
|
| 280 | - ) |
|
| 281 | - ); |
|
| 282 | - } |
|
| 283 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 284 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 286 | - return true; |
|
| 287 | - } |
|
| 288 | - return false; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @return array |
|
| 295 | - */ |
|
| 296 | - public function dependency_map() |
|
| 297 | - { |
|
| 298 | - return $this->_dependency_map; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 305 | - * |
|
| 306 | - * @param string $class_name |
|
| 307 | - * @return boolean |
|
| 308 | - */ |
|
| 309 | - public function has($class_name = '') |
|
| 310 | - { |
|
| 311 | - // all legacy models have the same dependencies |
|
| 312 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 313 | - $class_name = 'LEGACY_MODELS'; |
|
| 314 | - } |
|
| 315 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 322 | - * |
|
| 323 | - * @param string $class_name |
|
| 324 | - * @param string $dependency |
|
| 325 | - * @return bool |
|
| 326 | - */ |
|
| 327 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 328 | - { |
|
| 329 | - // all legacy models have the same dependencies |
|
| 330 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 331 | - $class_name = 'LEGACY_MODELS'; |
|
| 332 | - } |
|
| 333 | - $dependency = $this->get_alias($dependency); |
|
| 334 | - return isset($this->_dependency_map[$class_name][$dependency]) |
|
| 335 | - ? true |
|
| 336 | - : false; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 343 | - * |
|
| 344 | - * @param string $class_name |
|
| 345 | - * @param string $dependency |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 349 | - { |
|
| 350 | - // all legacy models have the same dependencies |
|
| 351 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 352 | - $class_name = 'LEGACY_MODELS'; |
|
| 353 | - } |
|
| 354 | - $dependency = $this->get_alias($dependency); |
|
| 355 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 356 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 357 | - : EE_Dependency_Map::not_registered; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @param string $class_name |
|
| 364 | - * @return string | Closure |
|
| 365 | - */ |
|
| 366 | - public function class_loader($class_name) |
|
| 367 | - { |
|
| 368 | - // all legacy models use load_model() |
|
| 369 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 370 | - return 'load_model'; |
|
| 371 | - } |
|
| 372 | - $class_name = $this->get_alias($class_name); |
|
| 373 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @return array |
|
| 380 | - */ |
|
| 381 | - public function class_loaders() |
|
| 382 | - { |
|
| 383 | - return $this->_class_loaders; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * adds an alias for a classname |
|
| 390 | - * |
|
| 391 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 392 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 393 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 394 | - */ |
|
| 395 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 396 | - { |
|
| 397 | - if ($for_class !== '') { |
|
| 398 | - if (! isset($this->_aliases[$for_class])) { |
|
| 399 | - $this->_aliases[$for_class] = array(); |
|
| 400 | - } |
|
| 401 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 402 | - } |
|
| 403 | - $this->_aliases[$class_name] = $alias; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * returns TRUE if the provided class name has an alias |
|
| 410 | - * |
|
| 411 | - * @param string $class_name |
|
| 412 | - * @param string $for_class |
|
| 413 | - * @return bool |
|
| 414 | - */ |
|
| 415 | - public function has_alias($class_name = '', $for_class = '') |
|
| 416 | - { |
|
| 417 | - return isset($this->_aliases[$for_class][$class_name]) |
|
| 418 | - || ( |
|
| 419 | - isset($this->_aliases[$class_name]) |
|
| 420 | - && ! is_array($this->_aliases[$class_name]) |
|
| 421 | - ); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 428 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 429 | - * for example: |
|
| 430 | - * if the following two entries were added to the _aliases array: |
|
| 431 | - * array( |
|
| 432 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 433 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 434 | - * ) |
|
| 435 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 436 | - * to load an instance of 'some\namespace\classname' |
|
| 437 | - * |
|
| 438 | - * @param string $class_name |
|
| 439 | - * @param string $for_class |
|
| 440 | - * @return string |
|
| 441 | - */ |
|
| 442 | - public function get_alias($class_name = '', $for_class = '') |
|
| 443 | - { |
|
| 444 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 445 | - return $class_name; |
|
| 446 | - } |
|
| 447 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 448 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 449 | - } |
|
| 450 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 457 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 458 | - * This is done by using the following class constants: |
|
| 459 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 460 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 461 | - */ |
|
| 462 | - protected function _register_core_dependencies() |
|
| 463 | - { |
|
| 464 | - $this->_dependency_map = array( |
|
| 465 | - 'EE_Request_Handler' => array( |
|
| 466 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 467 | - ), |
|
| 468 | - 'EE_System' => array( |
|
| 469 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 470 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 473 | - ), |
|
| 474 | - 'EE_Session' => array( |
|
| 475 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 476 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 477 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 478 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - ), |
|
| 480 | - 'EE_Cart' => array( |
|
| 481 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 482 | - ), |
|
| 483 | - 'EE_Front_Controller' => array( |
|
| 484 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 485 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 487 | - ), |
|
| 488 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 489 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 490 | - ), |
|
| 491 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 492 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 493 | - ), |
|
| 494 | - 'EE_Message_Resource_Manager' => array( |
|
| 495 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 496 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 497 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 498 | - ), |
|
| 499 | - 'EE_Message_Factory' => array( |
|
| 500 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 501 | - ), |
|
| 502 | - 'EE_messages' => array( |
|
| 503 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 504 | - ), |
|
| 505 | - 'EE_Messages_Generator' => array( |
|
| 506 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 507 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 508 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 509 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 510 | - ), |
|
| 511 | - 'EE_Messages_Processor' => array( |
|
| 512 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 513 | - ), |
|
| 514 | - 'EE_Messages_Queue' => array( |
|
| 515 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 516 | - ), |
|
| 517 | - 'EE_Messages_Template_Defaults' => array( |
|
| 518 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 519 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 520 | - ), |
|
| 521 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 522 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 524 | - ), |
|
| 525 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 526 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 527 | - ), |
|
| 528 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 529 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 530 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 531 | - ), |
|
| 532 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 533 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 534 | - ), |
|
| 535 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 536 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 537 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 538 | - ), |
|
| 539 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 540 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 541 | - ), |
|
| 542 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 543 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ), |
|
| 545 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 546 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - ), |
|
| 548 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 549 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 550 | - ), |
|
| 551 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 552 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 553 | - ), |
|
| 554 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 555 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - ), |
|
| 557 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 558 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 559 | - ), |
|
| 560 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 561 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 562 | - ), |
|
| 563 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 564 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - ), |
|
| 566 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 567 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - ), |
|
| 569 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 570 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 571 | - ), |
|
| 572 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 573 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 574 | - ), |
|
| 575 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 576 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 577 | - ), |
|
| 578 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | - ), |
|
| 581 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 582 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 583 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 584 | - ), |
|
| 585 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 586 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 587 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | - ), |
|
| 589 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 590 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 591 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 592 | - ), |
|
| 593 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 594 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 595 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 596 | - ), |
|
| 597 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 598 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 599 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | - ), |
|
| 601 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 602 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 604 | - ), |
|
| 605 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 606 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 607 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 608 | - ), |
|
| 609 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 610 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 611 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | - ), |
|
| 613 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 614 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 616 | - ), |
|
| 617 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 618 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 619 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 620 | - ), |
|
| 621 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 622 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 623 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 624 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
| 625 | - ), |
|
| 626 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 627 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 628 | - ), |
|
| 629 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 630 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 631 | - ), |
|
| 632 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 633 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 634 | - ), |
|
| 635 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 636 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 637 | - ), |
|
| 638 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 639 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 640 | - ), |
|
| 641 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 642 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 643 | - ), |
|
| 644 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 645 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 646 | - ), |
|
| 647 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 648 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 649 | - ), |
|
| 650 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 651 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 652 | - ), |
|
| 653 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 654 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 655 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 656 | - ), |
|
| 657 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 658 | - null, |
|
| 659 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 660 | - ), |
|
| 661 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 662 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 663 | - ), |
|
| 664 | - 'LEGACY_MODELS' => array( |
|
| 665 | - null, |
|
| 666 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 667 | - ), |
|
| 668 | - 'EE_Module_Request_Router' => array( |
|
| 669 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 670 | - ), |
|
| 671 | - 'EE_Registration_Processor' => array( |
|
| 672 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 673 | - ), |
|
| 674 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 675 | - null, |
|
| 676 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 677 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 678 | - ), |
|
| 679 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
| 680 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
| 681 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache |
|
| 682 | - ), |
|
| 28 | + /** |
|
| 29 | + * This means that the requested class dependency is not present in the dependency map |
|
| 30 | + */ |
|
| 31 | + const not_registered = 0; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 35 | + */ |
|
| 36 | + const load_new_object = 1; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 40 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 41 | + */ |
|
| 42 | + const load_from_cache = 2; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * When registering a dependency, |
|
| 46 | + * this indicates to keep any existing dependencies that already exist, |
|
| 47 | + * and simply discard any new dependencies declared in the incoming data |
|
| 48 | + */ |
|
| 49 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * When registering a dependency, |
|
| 53 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 54 | + */ |
|
| 55 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @type EE_Dependency_Map $_instance |
|
| 61 | + */ |
|
| 62 | + protected static $_instance; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type RequestInterface $request |
|
| 66 | + */ |
|
| 67 | + protected $request; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @type LegacyRequestInterface $legacy_request |
|
| 71 | + */ |
|
| 72 | + protected $legacy_request; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type ResponseInterface $response |
|
| 76 | + */ |
|
| 77 | + protected $response; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @type LoaderInterface $loader |
|
| 81 | + */ |
|
| 82 | + protected $loader; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @type array $_dependency_map |
|
| 86 | + */ |
|
| 87 | + protected $_dependency_map = array(); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @type array $_class_loaders |
|
| 91 | + */ |
|
| 92 | + protected $_class_loaders = array(); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @type array $_aliases |
|
| 96 | + */ |
|
| 97 | + protected $_aliases = array(); |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * EE_Dependency_Map constructor. |
|
| 103 | + */ |
|
| 104 | + protected function __construct() |
|
| 105 | + { |
|
| 106 | + // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 107 | + do_action('EE_Dependency_Map____construct'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @throws InvalidDataTypeException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + */ |
|
| 117 | + public function initialize() |
|
| 118 | + { |
|
| 119 | + $this->_register_core_dependencies(); |
|
| 120 | + $this->_register_core_class_loaders(); |
|
| 121 | + $this->_register_core_aliases(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @singleton method used to instantiate class object |
|
| 128 | + * @return EE_Dependency_Map |
|
| 129 | + */ |
|
| 130 | + public static function instance() { |
|
| 131 | + // check if class object is instantiated, and instantiated properly |
|
| 132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | + self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
|
| 134 | + } |
|
| 135 | + return self::$_instance; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param RequestInterface $request |
|
| 141 | + */ |
|
| 142 | + public function setRequest(RequestInterface $request) |
|
| 143 | + { |
|
| 144 | + $this->request = $request; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @param LegacyRequestInterface $legacy_request |
|
| 150 | + */ |
|
| 151 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 152 | + { |
|
| 153 | + $this->legacy_request = $legacy_request; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param ResponseInterface $response |
|
| 159 | + */ |
|
| 160 | + public function setResponse(ResponseInterface $response) |
|
| 161 | + { |
|
| 162 | + $this->response = $response; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param LoaderInterface $loader |
|
| 169 | + */ |
|
| 170 | + public function setLoader(LoaderInterface $loader) |
|
| 171 | + { |
|
| 172 | + $this->loader = $loader; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param string $class |
|
| 179 | + * @param array $dependencies |
|
| 180 | + * @param int $overwrite |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public static function register_dependencies( |
|
| 184 | + $class, |
|
| 185 | + array $dependencies, |
|
| 186 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 187 | + ) { |
|
| 188 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 195 | + * to the class specified by the first parameter. |
|
| 196 | + * IMPORTANT !!! |
|
| 197 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 198 | + * the order of the constructor parameters for the class in question. |
|
| 199 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 200 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 201 | + * |
|
| 202 | + * @param string $class |
|
| 203 | + * @param array $dependencies |
|
| 204 | + * @param int $overwrite |
|
| 205 | + * @return bool |
|
| 206 | + */ |
|
| 207 | + public function registerDependencies( |
|
| 208 | + $class, |
|
| 209 | + array $dependencies, |
|
| 210 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 211 | + ) { |
|
| 212 | + $class = trim($class, '\\'); |
|
| 213 | + $registered = false; |
|
| 214 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 216 | + } |
|
| 217 | + // we need to make sure that any aliases used when registering a dependency |
|
| 218 | + // get resolved to the correct class name |
|
| 219 | + foreach ($dependencies as $dependency => $load_source) { |
|
| 220 | + $alias = self::$_instance->get_alias($dependency); |
|
| 221 | + if ( |
|
| 222 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 223 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 224 | + ) { |
|
| 225 | + unset($dependencies[$dependency]); |
|
| 226 | + $dependencies[$alias] = $load_source; |
|
| 227 | + $registered = true; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + // now add our two lists of dependencies together. |
|
| 231 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 232 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 233 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 234 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 235 | + // especially with numerically indexed arrays |
|
| 236 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 237 | + // now we need to ensure that the resulting dependencies |
|
| 238 | + // array only has the entries that are required for the class |
|
| 239 | + // so first count how many dependencies were originally registered for the class |
|
| 240 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 241 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 242 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 243 | + // then truncate the final array to match that count |
|
| 244 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 245 | + // otherwise just take the incoming array because nothing previously existed |
|
| 246 | + : $dependencies; |
|
| 247 | + return $registered; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @param string $class_name |
|
| 254 | + * @param string $loader |
|
| 255 | + * @return bool |
|
| 256 | + * @throws DomainException |
|
| 257 | + */ |
|
| 258 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 259 | + { |
|
| 260 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | + throw new DomainException( |
|
| 262 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 266 | + if ( |
|
| 267 | + ! is_callable($loader) |
|
| 268 | + && ( |
|
| 269 | + strpos($loader, 'load_') !== 0 |
|
| 270 | + || ! method_exists('EE_Registry', $loader) |
|
| 271 | + ) |
|
| 272 | + ) { |
|
| 273 | + throw new DomainException( |
|
| 274 | + sprintf( |
|
| 275 | + esc_html__( |
|
| 276 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 277 | + 'event_espresso' |
|
| 278 | + ), |
|
| 279 | + $loader |
|
| 280 | + ) |
|
| 281 | + ); |
|
| 282 | + } |
|
| 283 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 284 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 286 | + return true; |
|
| 287 | + } |
|
| 288 | + return false; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @return array |
|
| 295 | + */ |
|
| 296 | + public function dependency_map() |
|
| 297 | + { |
|
| 298 | + return $this->_dependency_map; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 305 | + * |
|
| 306 | + * @param string $class_name |
|
| 307 | + * @return boolean |
|
| 308 | + */ |
|
| 309 | + public function has($class_name = '') |
|
| 310 | + { |
|
| 311 | + // all legacy models have the same dependencies |
|
| 312 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 313 | + $class_name = 'LEGACY_MODELS'; |
|
| 314 | + } |
|
| 315 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 322 | + * |
|
| 323 | + * @param string $class_name |
|
| 324 | + * @param string $dependency |
|
| 325 | + * @return bool |
|
| 326 | + */ |
|
| 327 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 328 | + { |
|
| 329 | + // all legacy models have the same dependencies |
|
| 330 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 331 | + $class_name = 'LEGACY_MODELS'; |
|
| 332 | + } |
|
| 333 | + $dependency = $this->get_alias($dependency); |
|
| 334 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
| 335 | + ? true |
|
| 336 | + : false; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 343 | + * |
|
| 344 | + * @param string $class_name |
|
| 345 | + * @param string $dependency |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 349 | + { |
|
| 350 | + // all legacy models have the same dependencies |
|
| 351 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 352 | + $class_name = 'LEGACY_MODELS'; |
|
| 353 | + } |
|
| 354 | + $dependency = $this->get_alias($dependency); |
|
| 355 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 356 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 357 | + : EE_Dependency_Map::not_registered; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @param string $class_name |
|
| 364 | + * @return string | Closure |
|
| 365 | + */ |
|
| 366 | + public function class_loader($class_name) |
|
| 367 | + { |
|
| 368 | + // all legacy models use load_model() |
|
| 369 | + if(strpos($class_name, 'EEM_') === 0){ |
|
| 370 | + return 'load_model'; |
|
| 371 | + } |
|
| 372 | + $class_name = $this->get_alias($class_name); |
|
| 373 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @return array |
|
| 380 | + */ |
|
| 381 | + public function class_loaders() |
|
| 382 | + { |
|
| 383 | + return $this->_class_loaders; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * adds an alias for a classname |
|
| 390 | + * |
|
| 391 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 392 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 393 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 394 | + */ |
|
| 395 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 396 | + { |
|
| 397 | + if ($for_class !== '') { |
|
| 398 | + if (! isset($this->_aliases[$for_class])) { |
|
| 399 | + $this->_aliases[$for_class] = array(); |
|
| 400 | + } |
|
| 401 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 402 | + } |
|
| 403 | + $this->_aliases[$class_name] = $alias; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * returns TRUE if the provided class name has an alias |
|
| 410 | + * |
|
| 411 | + * @param string $class_name |
|
| 412 | + * @param string $for_class |
|
| 413 | + * @return bool |
|
| 414 | + */ |
|
| 415 | + public function has_alias($class_name = '', $for_class = '') |
|
| 416 | + { |
|
| 417 | + return isset($this->_aliases[$for_class][$class_name]) |
|
| 418 | + || ( |
|
| 419 | + isset($this->_aliases[$class_name]) |
|
| 420 | + && ! is_array($this->_aliases[$class_name]) |
|
| 421 | + ); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 428 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 429 | + * for example: |
|
| 430 | + * if the following two entries were added to the _aliases array: |
|
| 431 | + * array( |
|
| 432 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 433 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 434 | + * ) |
|
| 435 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 436 | + * to load an instance of 'some\namespace\classname' |
|
| 437 | + * |
|
| 438 | + * @param string $class_name |
|
| 439 | + * @param string $for_class |
|
| 440 | + * @return string |
|
| 441 | + */ |
|
| 442 | + public function get_alias($class_name = '', $for_class = '') |
|
| 443 | + { |
|
| 444 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 445 | + return $class_name; |
|
| 446 | + } |
|
| 447 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 448 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 449 | + } |
|
| 450 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 457 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 458 | + * This is done by using the following class constants: |
|
| 459 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 460 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 461 | + */ |
|
| 462 | + protected function _register_core_dependencies() |
|
| 463 | + { |
|
| 464 | + $this->_dependency_map = array( |
|
| 465 | + 'EE_Request_Handler' => array( |
|
| 466 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 467 | + ), |
|
| 468 | + 'EE_System' => array( |
|
| 469 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 470 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 473 | + ), |
|
| 474 | + 'EE_Session' => array( |
|
| 475 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 476 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 477 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 478 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + ), |
|
| 480 | + 'EE_Cart' => array( |
|
| 481 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 482 | + ), |
|
| 483 | + 'EE_Front_Controller' => array( |
|
| 484 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 485 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 487 | + ), |
|
| 488 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 489 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 490 | + ), |
|
| 491 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 492 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 493 | + ), |
|
| 494 | + 'EE_Message_Resource_Manager' => array( |
|
| 495 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 496 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 497 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 498 | + ), |
|
| 499 | + 'EE_Message_Factory' => array( |
|
| 500 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 501 | + ), |
|
| 502 | + 'EE_messages' => array( |
|
| 503 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 504 | + ), |
|
| 505 | + 'EE_Messages_Generator' => array( |
|
| 506 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 507 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 508 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 509 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 510 | + ), |
|
| 511 | + 'EE_Messages_Processor' => array( |
|
| 512 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 513 | + ), |
|
| 514 | + 'EE_Messages_Queue' => array( |
|
| 515 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 516 | + ), |
|
| 517 | + 'EE_Messages_Template_Defaults' => array( |
|
| 518 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 519 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 520 | + ), |
|
| 521 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 522 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 524 | + ), |
|
| 525 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 526 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 527 | + ), |
|
| 528 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 529 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 530 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 531 | + ), |
|
| 532 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 533 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 534 | + ), |
|
| 535 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 536 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 537 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 538 | + ), |
|
| 539 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 540 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 541 | + ), |
|
| 542 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 543 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ), |
|
| 545 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 546 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + ), |
|
| 548 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 549 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 550 | + ), |
|
| 551 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 552 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 553 | + ), |
|
| 554 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 555 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + ), |
|
| 557 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 558 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 559 | + ), |
|
| 560 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 561 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 562 | + ), |
|
| 563 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 564 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + ), |
|
| 566 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 567 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + ), |
|
| 569 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 570 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 571 | + ), |
|
| 572 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 573 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 574 | + ), |
|
| 575 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 576 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 577 | + ), |
|
| 578 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | + ), |
|
| 581 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 582 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 583 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 584 | + ), |
|
| 585 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 586 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 587 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | + ), |
|
| 589 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 590 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 591 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 592 | + ), |
|
| 593 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 594 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 595 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 596 | + ), |
|
| 597 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 598 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 599 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | + ), |
|
| 601 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 602 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 604 | + ), |
|
| 605 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 606 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 607 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 608 | + ), |
|
| 609 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 610 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 611 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | + ), |
|
| 613 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 614 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 616 | + ), |
|
| 617 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 618 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 619 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 620 | + ), |
|
| 621 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 622 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 623 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 624 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
| 625 | + ), |
|
| 626 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 627 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 628 | + ), |
|
| 629 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 630 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 631 | + ), |
|
| 632 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 633 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 634 | + ), |
|
| 635 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 636 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 637 | + ), |
|
| 638 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 639 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 640 | + ), |
|
| 641 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 642 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 643 | + ), |
|
| 644 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 645 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 646 | + ), |
|
| 647 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 648 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 649 | + ), |
|
| 650 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 651 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 652 | + ), |
|
| 653 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 654 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 655 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 656 | + ), |
|
| 657 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 658 | + null, |
|
| 659 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 660 | + ), |
|
| 661 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 662 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 663 | + ), |
|
| 664 | + 'LEGACY_MODELS' => array( |
|
| 665 | + null, |
|
| 666 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 667 | + ), |
|
| 668 | + 'EE_Module_Request_Router' => array( |
|
| 669 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 670 | + ), |
|
| 671 | + 'EE_Registration_Processor' => array( |
|
| 672 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 673 | + ), |
|
| 674 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 675 | + null, |
|
| 676 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 677 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 678 | + ), |
|
| 679 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
| 680 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
| 681 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache |
|
| 682 | + ), |
|
| 683 | 683 | 'EE_Admin_Transactions_List_Table' => array( |
| 684 | - null, |
|
| 685 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 686 | - ), |
|
| 687 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
| 688 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 689 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 690 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache |
|
| 691 | - ), |
|
| 692 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
| 693 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
| 694 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
| 695 | - ), |
|
| 696 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
| 697 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 698 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 699 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 700 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 701 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 702 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 703 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
| 704 | - ), |
|
| 705 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
| 706 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
| 707 | - ), |
|
| 708 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
| 709 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
| 710 | - ), |
|
| 711 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
| 712 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 713 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 714 | - ), |
|
| 715 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
| 716 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 717 | - ), |
|
| 718 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
| 719 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 720 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 721 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 722 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 723 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 724 | - ), |
|
| 725 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
| 726 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 727 | - ), |
|
| 728 | - ); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * Registers how core classes are loaded. |
|
| 735 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 736 | - * 'EE_Request_Handler' => 'load_core' |
|
| 737 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 738 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 739 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 740 | - * 'Some_Class' => function () { |
|
| 741 | - * return new Some_Class(); |
|
| 742 | - * }, |
|
| 743 | - * This is required for instantiating dependencies |
|
| 744 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 745 | - * 'Required_Interface' => function () { |
|
| 746 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 747 | - * }, |
|
| 748 | - * |
|
| 749 | - * @throws InvalidInterfaceException |
|
| 750 | - * @throws InvalidDataTypeException |
|
| 751 | - * @throws InvalidArgumentException |
|
| 752 | - */ |
|
| 753 | - protected function _register_core_class_loaders() |
|
| 754 | - { |
|
| 755 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 756 | - //be used in a closure. |
|
| 757 | - $request = &$this->request; |
|
| 758 | - $response = &$this->response; |
|
| 759 | - $legacy_request = &$this->legacy_request; |
|
| 760 | - // $loader = &$this->loader; |
|
| 761 | - $this->_class_loaders = array( |
|
| 762 | - //load_core |
|
| 763 | - 'EE_Capabilities' => 'load_core', |
|
| 764 | - 'EE_Encryption' => 'load_core', |
|
| 765 | - 'EE_Front_Controller' => 'load_core', |
|
| 766 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 767 | - 'EE_Registry' => 'load_core', |
|
| 768 | - 'EE_Request' => function () use (&$legacy_request) { |
|
| 769 | - return $legacy_request; |
|
| 770 | - }, |
|
| 771 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 772 | - return $request; |
|
| 773 | - }, |
|
| 774 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 775 | - return $response; |
|
| 776 | - }, |
|
| 777 | - 'EE_Request_Handler' => 'load_core', |
|
| 778 | - 'EE_Session' => 'load_core', |
|
| 779 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 780 | - 'EE_System' => 'load_core', |
|
| 781 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 782 | - 'EE_Register_CPTs' => 'load_core', |
|
| 783 | - 'EE_Admin' => 'load_core', |
|
| 784 | - //load_lib |
|
| 785 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 786 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 787 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 788 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 789 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 790 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 791 | - 'EE_Message_Repository' => 'load_lib', |
|
| 792 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 793 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 794 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 795 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 796 | - 'EE_Messages_Generator' => function () { |
|
| 797 | - return EE_Registry::instance()->load_lib( |
|
| 798 | - 'Messages_Generator', |
|
| 799 | - array(), |
|
| 800 | - false, |
|
| 801 | - false |
|
| 802 | - ); |
|
| 803 | - }, |
|
| 804 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 805 | - return EE_Registry::instance()->load_lib( |
|
| 806 | - 'Messages_Template_Defaults', |
|
| 807 | - $arguments, |
|
| 808 | - false, |
|
| 809 | - false |
|
| 810 | - ); |
|
| 811 | - }, |
|
| 812 | - //load_helper |
|
| 813 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 814 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 815 | - return new EEH_Parse_Shortcodes(); |
|
| 816 | - } |
|
| 817 | - return null; |
|
| 818 | - }, |
|
| 819 | - 'EE_Template_Config' => function () { |
|
| 820 | - return EE_Config::instance()->template_settings; |
|
| 821 | - }, |
|
| 822 | - 'EE_Currency_Config' => function () { |
|
| 823 | - return EE_Config::instance()->currency; |
|
| 824 | - }, |
|
| 825 | - 'EE_Registration_Config' => function () { |
|
| 826 | - return EE_Config::instance()->registration; |
|
| 827 | - }, |
|
| 828 | - 'EE_Core_Config' => function () { |
|
| 829 | - return EE_Config::instance()->core; |
|
| 830 | - }, |
|
| 831 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 832 | - return LoaderFactory::getLoader(); |
|
| 833 | - }, |
|
| 834 | - 'EE_Network_Config' => function() { |
|
| 835 | - return EE_Network_Config::instance(); |
|
| 836 | - }, |
|
| 837 | - 'EE_Config' => function () { |
|
| 838 | - return EE_Config::instance(); |
|
| 839 | - } |
|
| 840 | - ); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - /** |
|
| 846 | - * can be used for supplying alternate names for classes, |
|
| 847 | - * or for connecting interface names to instantiable classes |
|
| 848 | - */ |
|
| 849 | - protected function _register_core_aliases() |
|
| 850 | - { |
|
| 851 | - $this->_aliases = array( |
|
| 852 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 853 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 854 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 855 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 856 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 857 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 858 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 859 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 860 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 861 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 862 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 863 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 864 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 865 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 866 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 867 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 868 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 869 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 870 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 871 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 872 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 873 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 874 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 875 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 876 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 877 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 878 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 879 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 880 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 881 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 882 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 883 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 884 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 885 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 886 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 887 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 888 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 889 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 890 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 891 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 892 | - ); |
|
| 893 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 894 | - $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 895 | - } |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 902 | - * request Primarily used by unit tests. |
|
| 903 | - * |
|
| 904 | - * @throws InvalidDataTypeException |
|
| 905 | - * @throws InvalidInterfaceException |
|
| 906 | - * @throws InvalidArgumentException |
|
| 907 | - */ |
|
| 908 | - public function reset() |
|
| 909 | - { |
|
| 910 | - $this->_register_core_class_loaders(); |
|
| 911 | - $this->_register_core_dependencies(); |
|
| 912 | - } |
|
| 684 | + null, |
|
| 685 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 686 | + ), |
|
| 687 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
| 688 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 689 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 690 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache |
|
| 691 | + ), |
|
| 692 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
| 693 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
| 694 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
| 695 | + ), |
|
| 696 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
| 697 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 698 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 699 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 700 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 701 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 702 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 703 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
| 704 | + ), |
|
| 705 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
| 706 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
| 707 | + ), |
|
| 708 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
| 709 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
| 710 | + ), |
|
| 711 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
| 712 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 713 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 714 | + ), |
|
| 715 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
| 716 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 717 | + ), |
|
| 718 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
| 719 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 720 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 721 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 722 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 723 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 724 | + ), |
|
| 725 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
| 726 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 727 | + ), |
|
| 728 | + ); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * Registers how core classes are loaded. |
|
| 735 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 736 | + * 'EE_Request_Handler' => 'load_core' |
|
| 737 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 738 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 739 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 740 | + * 'Some_Class' => function () { |
|
| 741 | + * return new Some_Class(); |
|
| 742 | + * }, |
|
| 743 | + * This is required for instantiating dependencies |
|
| 744 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 745 | + * 'Required_Interface' => function () { |
|
| 746 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 747 | + * }, |
|
| 748 | + * |
|
| 749 | + * @throws InvalidInterfaceException |
|
| 750 | + * @throws InvalidDataTypeException |
|
| 751 | + * @throws InvalidArgumentException |
|
| 752 | + */ |
|
| 753 | + protected function _register_core_class_loaders() |
|
| 754 | + { |
|
| 755 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 756 | + //be used in a closure. |
|
| 757 | + $request = &$this->request; |
|
| 758 | + $response = &$this->response; |
|
| 759 | + $legacy_request = &$this->legacy_request; |
|
| 760 | + // $loader = &$this->loader; |
|
| 761 | + $this->_class_loaders = array( |
|
| 762 | + //load_core |
|
| 763 | + 'EE_Capabilities' => 'load_core', |
|
| 764 | + 'EE_Encryption' => 'load_core', |
|
| 765 | + 'EE_Front_Controller' => 'load_core', |
|
| 766 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 767 | + 'EE_Registry' => 'load_core', |
|
| 768 | + 'EE_Request' => function () use (&$legacy_request) { |
|
| 769 | + return $legacy_request; |
|
| 770 | + }, |
|
| 771 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 772 | + return $request; |
|
| 773 | + }, |
|
| 774 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 775 | + return $response; |
|
| 776 | + }, |
|
| 777 | + 'EE_Request_Handler' => 'load_core', |
|
| 778 | + 'EE_Session' => 'load_core', |
|
| 779 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 780 | + 'EE_System' => 'load_core', |
|
| 781 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 782 | + 'EE_Register_CPTs' => 'load_core', |
|
| 783 | + 'EE_Admin' => 'load_core', |
|
| 784 | + //load_lib |
|
| 785 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 786 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 787 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 788 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 789 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 790 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 791 | + 'EE_Message_Repository' => 'load_lib', |
|
| 792 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 793 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 794 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 795 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 796 | + 'EE_Messages_Generator' => function () { |
|
| 797 | + return EE_Registry::instance()->load_lib( |
|
| 798 | + 'Messages_Generator', |
|
| 799 | + array(), |
|
| 800 | + false, |
|
| 801 | + false |
|
| 802 | + ); |
|
| 803 | + }, |
|
| 804 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 805 | + return EE_Registry::instance()->load_lib( |
|
| 806 | + 'Messages_Template_Defaults', |
|
| 807 | + $arguments, |
|
| 808 | + false, |
|
| 809 | + false |
|
| 810 | + ); |
|
| 811 | + }, |
|
| 812 | + //load_helper |
|
| 813 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 814 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 815 | + return new EEH_Parse_Shortcodes(); |
|
| 816 | + } |
|
| 817 | + return null; |
|
| 818 | + }, |
|
| 819 | + 'EE_Template_Config' => function () { |
|
| 820 | + return EE_Config::instance()->template_settings; |
|
| 821 | + }, |
|
| 822 | + 'EE_Currency_Config' => function () { |
|
| 823 | + return EE_Config::instance()->currency; |
|
| 824 | + }, |
|
| 825 | + 'EE_Registration_Config' => function () { |
|
| 826 | + return EE_Config::instance()->registration; |
|
| 827 | + }, |
|
| 828 | + 'EE_Core_Config' => function () { |
|
| 829 | + return EE_Config::instance()->core; |
|
| 830 | + }, |
|
| 831 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 832 | + return LoaderFactory::getLoader(); |
|
| 833 | + }, |
|
| 834 | + 'EE_Network_Config' => function() { |
|
| 835 | + return EE_Network_Config::instance(); |
|
| 836 | + }, |
|
| 837 | + 'EE_Config' => function () { |
|
| 838 | + return EE_Config::instance(); |
|
| 839 | + } |
|
| 840 | + ); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + /** |
|
| 846 | + * can be used for supplying alternate names for classes, |
|
| 847 | + * or for connecting interface names to instantiable classes |
|
| 848 | + */ |
|
| 849 | + protected function _register_core_aliases() |
|
| 850 | + { |
|
| 851 | + $this->_aliases = array( |
|
| 852 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 853 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 854 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 855 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 856 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 857 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 858 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 859 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 860 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 861 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 862 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 863 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 864 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 865 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 866 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 867 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 868 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 869 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 870 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 871 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 872 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 873 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 874 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 875 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 876 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 877 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 878 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 879 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 880 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 881 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 882 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 883 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 884 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 885 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 886 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 887 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 888 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 889 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 890 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 891 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 892 | + ); |
|
| 893 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 894 | + $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + |
|
| 900 | + /** |
|
| 901 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 902 | + * request Primarily used by unit tests. |
|
| 903 | + * |
|
| 904 | + * @throws InvalidDataTypeException |
|
| 905 | + * @throws InvalidInterfaceException |
|
| 906 | + * @throws InvalidArgumentException |
|
| 907 | + */ |
|
| 908 | + public function reset() |
|
| 909 | + { |
|
| 910 | + $this->_register_core_class_loaders(); |
|
| 911 | + $this->_register_core_dependencies(); |
|
| 912 | + } |
|
| 913 | 913 | |
| 914 | 914 | |
| 915 | 915 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | use EventEspresso\core\services\request\RequestInterface; |
| 8 | 8 | use EventEspresso\core\services\request\ResponseInterface; |
| 9 | 9 | |
| 10 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 11 | 11 | exit('No direct script access allowed'); |
| 12 | 12 | } |
| 13 | 13 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public static function instance() { |
| 131 | 131 | // check if class object is instantiated, and instantiated properly |
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 132 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | 133 | self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
| 134 | 134 | } |
| 135 | 135 | return self::$_instance; |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | ) { |
| 212 | 212 | $class = trim($class, '\\'); |
| 213 | 213 | $registered = false; |
| 214 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 214 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
| 215 | + self::$_instance->_dependency_map[$class] = array(); |
|
| 216 | 216 | } |
| 217 | 217 | // we need to make sure that any aliases used when registering a dependency |
| 218 | 218 | // get resolved to the correct class name |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $alias = self::$_instance->get_alias($dependency); |
| 221 | 221 | if ( |
| 222 | 222 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
| 223 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 223 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
| 224 | 224 | ) { |
| 225 | 225 | unset($dependencies[$dependency]); |
| 226 | 226 | $dependencies[$alias] = $load_source; |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
| 234 | 234 | // Union is way faster than array_merge() but should be used with caution... |
| 235 | 235 | // especially with numerically indexed arrays |
| 236 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 236 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
| 237 | 237 | // now we need to ensure that the resulting dependencies |
| 238 | 238 | // array only has the entries that are required for the class |
| 239 | 239 | // so first count how many dependencies were originally registered for the class |
| 240 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 240 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
| 241 | 241 | // if that count is non-zero (meaning dependencies were already registered) |
| 242 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 242 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
| 243 | 243 | // then truncate the final array to match that count |
| 244 | 244 | ? array_slice($dependencies, 0, $dependency_count) |
| 245 | 245 | // otherwise just take the incoming array because nothing previously existed |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public static function register_class_loader($class_name, $loader = 'load_core') |
| 259 | 259 | { |
| 260 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 260 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | 261 | throw new DomainException( |
| 262 | 262 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
| 263 | 263 | ); |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | ); |
| 282 | 282 | } |
| 283 | 283 | $class_name = self::$_instance->get_alias($class_name); |
| 284 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 284 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | 285 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 286 | 286 | return true; |
| 287 | 287 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | public function class_loader($class_name) |
| 367 | 367 | { |
| 368 | 368 | // all legacy models use load_model() |
| 369 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 369 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 370 | 370 | return 'load_model'; |
| 371 | 371 | } |
| 372 | 372 | $class_name = $this->get_alias($class_name); |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | public function add_alias($class_name, $alias, $for_class = '') |
| 396 | 396 | { |
| 397 | 397 | if ($for_class !== '') { |
| 398 | - if (! isset($this->_aliases[$for_class])) { |
|
| 398 | + if ( ! isset($this->_aliases[$for_class])) { |
|
| 399 | 399 | $this->_aliases[$for_class] = array(); |
| 400 | 400 | } |
| 401 | 401 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -441,10 +441,10 @@ discard block |
||
| 441 | 441 | */ |
| 442 | 442 | public function get_alias($class_name = '', $for_class = '') |
| 443 | 443 | { |
| 444 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 444 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
| 445 | 445 | return $class_name; |
| 446 | 446 | } |
| 447 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 447 | + if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { |
|
| 448 | 448 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
| 449 | 449 | } |
| 450 | 450 | return $this->get_alias($this->_aliases[$class_name]); |
@@ -765,13 +765,13 @@ discard block |
||
| 765 | 765 | 'EE_Front_Controller' => 'load_core', |
| 766 | 766 | 'EE_Module_Request_Router' => 'load_core', |
| 767 | 767 | 'EE_Registry' => 'load_core', |
| 768 | - 'EE_Request' => function () use (&$legacy_request) { |
|
| 768 | + 'EE_Request' => function() use (&$legacy_request) { |
|
| 769 | 769 | return $legacy_request; |
| 770 | 770 | }, |
| 771 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 771 | + 'EventEspresso\core\services\request\Request' => function() use (&$request) { |
|
| 772 | 772 | return $request; |
| 773 | 773 | }, |
| 774 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 774 | + 'EventEspresso\core\services\request\Response' => function() use (&$response) { |
|
| 775 | 775 | return $response; |
| 776 | 776 | }, |
| 777 | 777 | 'EE_Request_Handler' => 'load_core', |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 794 | 794 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 795 | 795 | 'EE_Payment_Method_Manager' => 'load_lib', |
| 796 | - 'EE_Messages_Generator' => function () { |
|
| 796 | + 'EE_Messages_Generator' => function() { |
|
| 797 | 797 | return EE_Registry::instance()->load_lib( |
| 798 | 798 | 'Messages_Generator', |
| 799 | 799 | array(), |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | false |
| 802 | 802 | ); |
| 803 | 803 | }, |
| 804 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 804 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 805 | 805 | return EE_Registry::instance()->load_lib( |
| 806 | 806 | 'Messages_Template_Defaults', |
| 807 | 807 | $arguments, |
@@ -810,31 +810,31 @@ discard block |
||
| 810 | 810 | ); |
| 811 | 811 | }, |
| 812 | 812 | //load_helper |
| 813 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 813 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 814 | 814 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 815 | 815 | return new EEH_Parse_Shortcodes(); |
| 816 | 816 | } |
| 817 | 817 | return null; |
| 818 | 818 | }, |
| 819 | - 'EE_Template_Config' => function () { |
|
| 819 | + 'EE_Template_Config' => function() { |
|
| 820 | 820 | return EE_Config::instance()->template_settings; |
| 821 | 821 | }, |
| 822 | - 'EE_Currency_Config' => function () { |
|
| 822 | + 'EE_Currency_Config' => function() { |
|
| 823 | 823 | return EE_Config::instance()->currency; |
| 824 | 824 | }, |
| 825 | - 'EE_Registration_Config' => function () { |
|
| 825 | + 'EE_Registration_Config' => function() { |
|
| 826 | 826 | return EE_Config::instance()->registration; |
| 827 | 827 | }, |
| 828 | - 'EE_Core_Config' => function () { |
|
| 828 | + 'EE_Core_Config' => function() { |
|
| 829 | 829 | return EE_Config::instance()->core; |
| 830 | 830 | }, |
| 831 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 831 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
| 832 | 832 | return LoaderFactory::getLoader(); |
| 833 | 833 | }, |
| 834 | 834 | 'EE_Network_Config' => function() { |
| 835 | 835 | return EE_Network_Config::instance(); |
| 836 | 836 | }, |
| 837 | - 'EE_Config' => function () { |
|
| 837 | + 'EE_Config' => function() { |
|
| 838 | 838 | return EE_Config::instance(); |
| 839 | 839 | } |
| 840 | 840 | ); |
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
| 891 | 891 | 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
| 892 | 892 | ); |
| 893 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 893 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 894 | 894 | $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
| 895 | 895 | } |
| 896 | 896 | } |