@@ -25,562 +25,562 @@ |
||
| 25 | 25 | class Registry |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - const ASSET_TYPE_CSS = 'css'; |
|
| 29 | - const ASSET_TYPE_JS = 'js'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Template_Config $template_config |
|
| 33 | - */ |
|
| 34 | - protected $template_config; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var EE_Currency_Config $currency_config |
|
| 38 | - */ |
|
| 39 | - protected $currency_config; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $jsdata = array(); |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 51 | - * page source. |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - protected $script_handles_with_data = array(); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var DomainInterface |
|
| 59 | - */ |
|
| 60 | - protected $domain; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Holds all the registered asset manifest files. |
|
| 65 | - * @var array |
|
| 66 | - */ |
|
| 67 | - private $registered_manifest_files = array(); |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Holds the manifest maps setup the first time a manifest map is requested via loading the |
|
| 72 | - * $registered_manifest_files |
|
| 73 | - * Manifests are maps of asset chunk name to actual built asset filenames. |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - private $cached_manifest = array(); |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Registry constructor. |
|
| 82 | - * Hooking into WP actions for script registry. |
|
| 83 | - * |
|
| 84 | - * @param EE_Template_Config $template_config |
|
| 85 | - * @param EE_Currency_Config $currency_config |
|
| 86 | - * @param DomainInterface $domain |
|
| 87 | - */ |
|
| 88 | - public function __construct( |
|
| 89 | - EE_Template_Config $template_config, |
|
| 90 | - EE_Currency_Config $currency_config, |
|
| 91 | - DomainInterface $domain |
|
| 92 | - ) { |
|
| 93 | - $this->template_config = $template_config; |
|
| 94 | - $this->currency_config = $currency_config; |
|
| 95 | - $this->domain = $domain; |
|
| 96 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 97 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 98 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 99 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 100 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 101 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Callback for the WP script actions. |
|
| 107 | - * Used to register globally accessible core scripts. |
|
| 108 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 109 | - * |
|
| 110 | - * @throws InvalidFilePathException |
|
| 111 | - */ |
|
| 112 | - public function scripts() |
|
| 113 | - { |
|
| 114 | - global $wp_version; |
|
| 115 | - wp_register_script( |
|
| 116 | - 'ee-manifest', |
|
| 117 | - $this->getAssetUrl('manifest', self::ASSET_TYPE_JS), |
|
| 118 | - array(), |
|
| 119 | - null, |
|
| 120 | - true |
|
| 121 | - ); |
|
| 122 | - wp_register_script( |
|
| 123 | - 'eejs-core', |
|
| 124 | - $this->getAssetUrl('eejs', self::ASSET_TYPE_JS), |
|
| 125 | - array('ee-manifest'), |
|
| 126 | - null, |
|
| 127 | - true |
|
| 128 | - ); |
|
| 129 | - wp_register_script( |
|
| 130 | - 'ee-vendor-react', |
|
| 131 | - $this->getAssetUrl('vendorReact', self::ASSET_TYPE_JS), |
|
| 132 | - array('eejs-core'), |
|
| 133 | - null, |
|
| 134 | - true |
|
| 135 | - ); |
|
| 136 | - //only run this if WordPress 4.4.0 > is in use. |
|
| 137 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 138 | - //js.api |
|
| 139 | - wp_register_script( |
|
| 140 | - 'eejs-api', |
|
| 141 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 142 | - array('underscore', 'eejs-core'), |
|
| 143 | - EVENT_ESPRESSO_VERSION, |
|
| 144 | - true |
|
| 145 | - ); |
|
| 146 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 147 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 148 | - } |
|
| 149 | - if (! is_admin()) { |
|
| 150 | - $this->loadCoreCss(); |
|
| 151 | - } |
|
| 152 | - $this->registerManifestFile($this->domain->distributionAssetsPath() . 'build-manifest.json'); |
|
| 153 | - $this->loadCoreJs(); |
|
| 154 | - $this->loadJqueryValidate(); |
|
| 155 | - $this->loadAccountingJs(); |
|
| 156 | - $this->loadQtipJs(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Call back for the script print in frontend and backend. |
|
| 163 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 164 | - * |
|
| 165 | - * @since 4.9.31.rc.015 |
|
| 166 | - */ |
|
| 167 | - public function enqueueData() |
|
| 168 | - { |
|
| 169 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 170 | - wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
| 171 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 172 | - $this->localizeAccountingJs(); |
|
| 173 | - $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
| 174 | - $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Used to add data to eejs.data object. |
|
| 181 | - * Note: Overriding existing data is not allowed. |
|
| 182 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 183 | - * If the data you add is something like this: |
|
| 184 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 185 | - * It will be exposed in the page source as: |
|
| 186 | - * eejs.data.my_plugin_data.foo == gar |
|
| 187 | - * |
|
| 188 | - * @param string $key Key used to access your data |
|
| 189 | - * @param string|array $value Value to attach to key |
|
| 190 | - * @throws InvalidArgumentException |
|
| 191 | - */ |
|
| 192 | - public function addData($key, $value) |
|
| 193 | - { |
|
| 194 | - if ($this->verifyDataNotExisting($key)) { |
|
| 195 | - $this->jsdata[$key] = $value; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 203 | - * elements in an array. |
|
| 204 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 205 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 206 | - * object like this, eejs.data.test = [ my_data, |
|
| 207 | - * ] |
|
| 208 | - * If there has already been a scalar value attached to the data object given key, then |
|
| 209 | - * this will throw an exception. |
|
| 210 | - * |
|
| 211 | - * @param string $key Key to attach data to. |
|
| 212 | - * @param string|array $value Value being registered. |
|
| 213 | - * @throws InvalidArgumentException |
|
| 214 | - */ |
|
| 215 | - public function pushData($key, $value) |
|
| 216 | - { |
|
| 217 | - if (isset($this->jsdata[$key]) |
|
| 218 | - && ! is_array($this->jsdata[$key]) |
|
| 219 | - ) { |
|
| 220 | - throw new invalidArgumentException( |
|
| 221 | - sprintf( |
|
| 222 | - __( |
|
| 223 | - '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 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Template_Config $template_config |
|
| 33 | + */ |
|
| 34 | + protected $template_config; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var EE_Currency_Config $currency_config |
|
| 38 | + */ |
|
| 39 | + protected $currency_config; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $jsdata = array(); |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 51 | + * page source. |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + protected $script_handles_with_data = array(); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var DomainInterface |
|
| 59 | + */ |
|
| 60 | + protected $domain; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Holds all the registered asset manifest files. |
|
| 65 | + * @var array |
|
| 66 | + */ |
|
| 67 | + private $registered_manifest_files = array(); |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Holds the manifest maps setup the first time a manifest map is requested via loading the |
|
| 72 | + * $registered_manifest_files |
|
| 73 | + * Manifests are maps of asset chunk name to actual built asset filenames. |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + private $cached_manifest = array(); |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Registry constructor. |
|
| 82 | + * Hooking into WP actions for script registry. |
|
| 83 | + * |
|
| 84 | + * @param EE_Template_Config $template_config |
|
| 85 | + * @param EE_Currency_Config $currency_config |
|
| 86 | + * @param DomainInterface $domain |
|
| 87 | + */ |
|
| 88 | + public function __construct( |
|
| 89 | + EE_Template_Config $template_config, |
|
| 90 | + EE_Currency_Config $currency_config, |
|
| 91 | + DomainInterface $domain |
|
| 92 | + ) { |
|
| 93 | + $this->template_config = $template_config; |
|
| 94 | + $this->currency_config = $currency_config; |
|
| 95 | + $this->domain = $domain; |
|
| 96 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 97 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 98 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 99 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 100 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 101 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Callback for the WP script actions. |
|
| 107 | + * Used to register globally accessible core scripts. |
|
| 108 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 109 | + * |
|
| 110 | + * @throws InvalidFilePathException |
|
| 111 | + */ |
|
| 112 | + public function scripts() |
|
| 113 | + { |
|
| 114 | + global $wp_version; |
|
| 115 | + wp_register_script( |
|
| 116 | + 'ee-manifest', |
|
| 117 | + $this->getAssetUrl('manifest', self::ASSET_TYPE_JS), |
|
| 118 | + array(), |
|
| 119 | + null, |
|
| 120 | + true |
|
| 121 | + ); |
|
| 122 | + wp_register_script( |
|
| 123 | + 'eejs-core', |
|
| 124 | + $this->getAssetUrl('eejs', self::ASSET_TYPE_JS), |
|
| 125 | + array('ee-manifest'), |
|
| 126 | + null, |
|
| 127 | + true |
|
| 128 | + ); |
|
| 129 | + wp_register_script( |
|
| 130 | + 'ee-vendor-react', |
|
| 131 | + $this->getAssetUrl('vendorReact', self::ASSET_TYPE_JS), |
|
| 132 | + array('eejs-core'), |
|
| 133 | + null, |
|
| 134 | + true |
|
| 135 | + ); |
|
| 136 | + //only run this if WordPress 4.4.0 > is in use. |
|
| 137 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 138 | + //js.api |
|
| 139 | + wp_register_script( |
|
| 140 | + 'eejs-api', |
|
| 141 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 142 | + array('underscore', 'eejs-core'), |
|
| 143 | + EVENT_ESPRESSO_VERSION, |
|
| 144 | + true |
|
| 145 | + ); |
|
| 146 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 147 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 148 | + } |
|
| 149 | + if (! is_admin()) { |
|
| 150 | + $this->loadCoreCss(); |
|
| 151 | + } |
|
| 152 | + $this->registerManifestFile($this->domain->distributionAssetsPath() . 'build-manifest.json'); |
|
| 153 | + $this->loadCoreJs(); |
|
| 154 | + $this->loadJqueryValidate(); |
|
| 155 | + $this->loadAccountingJs(); |
|
| 156 | + $this->loadQtipJs(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Call back for the script print in frontend and backend. |
|
| 163 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 164 | + * |
|
| 165 | + * @since 4.9.31.rc.015 |
|
| 166 | + */ |
|
| 167 | + public function enqueueData() |
|
| 168 | + { |
|
| 169 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 170 | + wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
| 171 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 172 | + $this->localizeAccountingJs(); |
|
| 173 | + $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
| 174 | + $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Used to add data to eejs.data object. |
|
| 181 | + * Note: Overriding existing data is not allowed. |
|
| 182 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 183 | + * If the data you add is something like this: |
|
| 184 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 185 | + * It will be exposed in the page source as: |
|
| 186 | + * eejs.data.my_plugin_data.foo == gar |
|
| 187 | + * |
|
| 188 | + * @param string $key Key used to access your data |
|
| 189 | + * @param string|array $value Value to attach to key |
|
| 190 | + * @throws InvalidArgumentException |
|
| 191 | + */ |
|
| 192 | + public function addData($key, $value) |
|
| 193 | + { |
|
| 194 | + if ($this->verifyDataNotExisting($key)) { |
|
| 195 | + $this->jsdata[$key] = $value; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 203 | + * elements in an array. |
|
| 204 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 205 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 206 | + * object like this, eejs.data.test = [ my_data, |
|
| 207 | + * ] |
|
| 208 | + * If there has already been a scalar value attached to the data object given key, then |
|
| 209 | + * this will throw an exception. |
|
| 210 | + * |
|
| 211 | + * @param string $key Key to attach data to. |
|
| 212 | + * @param string|array $value Value being registered. |
|
| 213 | + * @throws InvalidArgumentException |
|
| 214 | + */ |
|
| 215 | + public function pushData($key, $value) |
|
| 216 | + { |
|
| 217 | + if (isset($this->jsdata[$key]) |
|
| 218 | + && ! is_array($this->jsdata[$key]) |
|
| 219 | + ) { |
|
| 220 | + throw new invalidArgumentException( |
|
| 221 | + sprintf( |
|
| 222 | + __( |
|
| 223 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 224 | 224 | push values to this data element when it is an array.', |
| 225 | - 'event_espresso' |
|
| 226 | - ), |
|
| 227 | - $key, |
|
| 228 | - __METHOD__ |
|
| 229 | - ) |
|
| 230 | - ); |
|
| 231 | - } |
|
| 232 | - $this->jsdata[$key][] = $value; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Used to set content used by javascript for a template. |
|
| 239 | - * Note: Overrides of existing registered templates are not allowed. |
|
| 240 | - * |
|
| 241 | - * @param string $template_reference |
|
| 242 | - * @param string $template_content |
|
| 243 | - * @throws InvalidArgumentException |
|
| 244 | - */ |
|
| 245 | - public function addTemplate($template_reference, $template_content) |
|
| 246 | - { |
|
| 247 | - if (! isset($this->jsdata['templates'])) { |
|
| 248 | - $this->jsdata['templates'] = array(); |
|
| 249 | - } |
|
| 250 | - //no overrides allowed. |
|
| 251 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 252 | - throw new invalidArgumentException( |
|
| 253 | - sprintf( |
|
| 254 | - __( |
|
| 255 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 256 | - 'event_espresso' |
|
| 257 | - ), |
|
| 258 | - $template_reference |
|
| 259 | - ) |
|
| 260 | - ); |
|
| 261 | - } |
|
| 262 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Retrieve the template content already registered for the given reference. |
|
| 269 | - * |
|
| 270 | - * @param string $template_reference |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public function getTemplate($template_reference) |
|
| 274 | - { |
|
| 275 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 276 | - ? $this->jsdata['templates'][$template_reference] |
|
| 277 | - : ''; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Retrieve registered data. |
|
| 284 | - * |
|
| 285 | - * @param string $key Name of key to attach data to. |
|
| 286 | - * @return mixed If there is no for the given key, then false is returned. |
|
| 287 | - */ |
|
| 288 | - public function getData($key) |
|
| 289 | - { |
|
| 290 | - return isset($this->jsdata[$key]) |
|
| 291 | - ? $this->jsdata[$key] |
|
| 292 | - : false; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Get the actual asset path for asset manifests. |
|
| 298 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
| 299 | - * @param string $chunk_name |
|
| 300 | - * @param string $asset_type |
|
| 301 | - * @return string |
|
| 302 | - * @throws InvalidFilePathException |
|
| 303 | - * @since $VID:$ |
|
| 304 | - */ |
|
| 305 | - public function getAssetUrl($chunk_name, $asset_type) |
|
| 306 | - { |
|
| 307 | - if (empty($this->cached_manifest)) { |
|
| 308 | - $this->registerManifests(); |
|
| 309 | - } |
|
| 310 | - return isset($this->cached_manifest[$chunk_name][$asset_type]) |
|
| 311 | - ? $this->domain->distributionAssetsUrl() . $this->cached_manifest[$chunk_name][$asset_type] |
|
| 312 | - : $chunk_name; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
| 318 | - * |
|
| 319 | - * @param string $manifest_file The absolute path to the manifest file. |
|
| 320 | - * @throws InvalidFilePathException |
|
| 321 | - * @since $VID:$ |
|
| 322 | - */ |
|
| 323 | - public function registerManifestFile($manifest_file) |
|
| 324 | - { |
|
| 325 | - if (! file_exists($manifest_file)) { |
|
| 326 | - throw new InvalidFilePathException($manifest_file); |
|
| 327 | - } |
|
| 328 | - $this->registered_manifest_files[] = $manifest_file; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Register any asset manifests. |
|
| 334 | - * @throws InvalidFilePathException |
|
| 335 | - * @since $VID:$ |
|
| 336 | - */ |
|
| 337 | - private function registerManifests() |
|
| 338 | - { |
|
| 339 | - if (! empty($this->cached_manifest)) { |
|
| 340 | - //already registered get out. This usually means that a $chunk_name (argument for getAssetUrl call) either |
|
| 341 | - //doesn't exist in any registered manifest files. This could be because the $chunk_name is an actual file |
|
| 342 | - //url and thus not registered in the manifest, or a plugin registered its manifest files too late. |
|
| 343 | - return; |
|
| 344 | - } |
|
| 345 | - $this->registered_manifest_files = (array) apply_filters( |
|
| 346 | - 'FHEE__EventEspresso_core_services_assets_Registry__registerManifests__registered_manifest_files', |
|
| 347 | - $this->registered_manifest_files |
|
| 348 | - ); |
|
| 349 | - foreach ($this->registered_manifest_files as $file) { |
|
| 350 | - if (! file_exists($file)) { |
|
| 351 | - throw new InvalidFilePathException($file); |
|
| 352 | - } |
|
| 353 | - /** recommended to avoid array_merge in loops */ |
|
| 354 | - $this->cached_manifest[] = json_decode(file_get_contents($file), true); |
|
| 355 | - } |
|
| 356 | - //PHP below 5.6 |
|
| 357 | - $this->cached_manifest = call_user_func_array('array_merge', $this->cached_manifest); |
|
| 358 | - //We can use this once we require PHP5.6+ |
|
| 359 | - //$this->cached_manifest = array_merge(...$this->cached_manifest); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Verifies whether the given data exists already on the jsdata array. |
|
| 366 | - * Overriding data is not allowed. |
|
| 367 | - * |
|
| 368 | - * @param string $key Index for data. |
|
| 369 | - * @return bool If valid then return true. |
|
| 370 | - * @throws InvalidArgumentException if data already exists. |
|
| 371 | - */ |
|
| 372 | - protected function verifyDataNotExisting($key) |
|
| 373 | - { |
|
| 374 | - if (isset($this->jsdata[$key])) { |
|
| 375 | - if (is_array($this->jsdata[$key])) { |
|
| 376 | - throw new InvalidArgumentException( |
|
| 377 | - sprintf( |
|
| 378 | - __( |
|
| 379 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
| 225 | + 'event_espresso' |
|
| 226 | + ), |
|
| 227 | + $key, |
|
| 228 | + __METHOD__ |
|
| 229 | + ) |
|
| 230 | + ); |
|
| 231 | + } |
|
| 232 | + $this->jsdata[$key][] = $value; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Used to set content used by javascript for a template. |
|
| 239 | + * Note: Overrides of existing registered templates are not allowed. |
|
| 240 | + * |
|
| 241 | + * @param string $template_reference |
|
| 242 | + * @param string $template_content |
|
| 243 | + * @throws InvalidArgumentException |
|
| 244 | + */ |
|
| 245 | + public function addTemplate($template_reference, $template_content) |
|
| 246 | + { |
|
| 247 | + if (! isset($this->jsdata['templates'])) { |
|
| 248 | + $this->jsdata['templates'] = array(); |
|
| 249 | + } |
|
| 250 | + //no overrides allowed. |
|
| 251 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 252 | + throw new invalidArgumentException( |
|
| 253 | + sprintf( |
|
| 254 | + __( |
|
| 255 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 256 | + 'event_espresso' |
|
| 257 | + ), |
|
| 258 | + $template_reference |
|
| 259 | + ) |
|
| 260 | + ); |
|
| 261 | + } |
|
| 262 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Retrieve the template content already registered for the given reference. |
|
| 269 | + * |
|
| 270 | + * @param string $template_reference |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public function getTemplate($template_reference) |
|
| 274 | + { |
|
| 275 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 276 | + ? $this->jsdata['templates'][$template_reference] |
|
| 277 | + : ''; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Retrieve registered data. |
|
| 284 | + * |
|
| 285 | + * @param string $key Name of key to attach data to. |
|
| 286 | + * @return mixed If there is no for the given key, then false is returned. |
|
| 287 | + */ |
|
| 288 | + public function getData($key) |
|
| 289 | + { |
|
| 290 | + return isset($this->jsdata[$key]) |
|
| 291 | + ? $this->jsdata[$key] |
|
| 292 | + : false; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Get the actual asset path for asset manifests. |
|
| 298 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
| 299 | + * @param string $chunk_name |
|
| 300 | + * @param string $asset_type |
|
| 301 | + * @return string |
|
| 302 | + * @throws InvalidFilePathException |
|
| 303 | + * @since $VID:$ |
|
| 304 | + */ |
|
| 305 | + public function getAssetUrl($chunk_name, $asset_type) |
|
| 306 | + { |
|
| 307 | + if (empty($this->cached_manifest)) { |
|
| 308 | + $this->registerManifests(); |
|
| 309 | + } |
|
| 310 | + return isset($this->cached_manifest[$chunk_name][$asset_type]) |
|
| 311 | + ? $this->domain->distributionAssetsUrl() . $this->cached_manifest[$chunk_name][$asset_type] |
|
| 312 | + : $chunk_name; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
| 318 | + * |
|
| 319 | + * @param string $manifest_file The absolute path to the manifest file. |
|
| 320 | + * @throws InvalidFilePathException |
|
| 321 | + * @since $VID:$ |
|
| 322 | + */ |
|
| 323 | + public function registerManifestFile($manifest_file) |
|
| 324 | + { |
|
| 325 | + if (! file_exists($manifest_file)) { |
|
| 326 | + throw new InvalidFilePathException($manifest_file); |
|
| 327 | + } |
|
| 328 | + $this->registered_manifest_files[] = $manifest_file; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Register any asset manifests. |
|
| 334 | + * @throws InvalidFilePathException |
|
| 335 | + * @since $VID:$ |
|
| 336 | + */ |
|
| 337 | + private function registerManifests() |
|
| 338 | + { |
|
| 339 | + if (! empty($this->cached_manifest)) { |
|
| 340 | + //already registered get out. This usually means that a $chunk_name (argument for getAssetUrl call) either |
|
| 341 | + //doesn't exist in any registered manifest files. This could be because the $chunk_name is an actual file |
|
| 342 | + //url and thus not registered in the manifest, or a plugin registered its manifest files too late. |
|
| 343 | + return; |
|
| 344 | + } |
|
| 345 | + $this->registered_manifest_files = (array) apply_filters( |
|
| 346 | + 'FHEE__EventEspresso_core_services_assets_Registry__registerManifests__registered_manifest_files', |
|
| 347 | + $this->registered_manifest_files |
|
| 348 | + ); |
|
| 349 | + foreach ($this->registered_manifest_files as $file) { |
|
| 350 | + if (! file_exists($file)) { |
|
| 351 | + throw new InvalidFilePathException($file); |
|
| 352 | + } |
|
| 353 | + /** recommended to avoid array_merge in loops */ |
|
| 354 | + $this->cached_manifest[] = json_decode(file_get_contents($file), true); |
|
| 355 | + } |
|
| 356 | + //PHP below 5.6 |
|
| 357 | + $this->cached_manifest = call_user_func_array('array_merge', $this->cached_manifest); |
|
| 358 | + //We can use this once we require PHP5.6+ |
|
| 359 | + //$this->cached_manifest = array_merge(...$this->cached_manifest); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Verifies whether the given data exists already on the jsdata array. |
|
| 366 | + * Overriding data is not allowed. |
|
| 367 | + * |
|
| 368 | + * @param string $key Index for data. |
|
| 369 | + * @return bool If valid then return true. |
|
| 370 | + * @throws InvalidArgumentException if data already exists. |
|
| 371 | + */ |
|
| 372 | + protected function verifyDataNotExisting($key) |
|
| 373 | + { |
|
| 374 | + if (isset($this->jsdata[$key])) { |
|
| 375 | + if (is_array($this->jsdata[$key])) { |
|
| 376 | + throw new InvalidArgumentException( |
|
| 377 | + sprintf( |
|
| 378 | + __( |
|
| 379 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
| 380 | 380 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
| 381 | 381 | %2$s method to push your value to the array.', |
| 382 | - 'event_espresso' |
|
| 383 | - ), |
|
| 384 | - $key, |
|
| 385 | - 'pushData()' |
|
| 386 | - ) |
|
| 387 | - ); |
|
| 388 | - } |
|
| 389 | - throw new InvalidArgumentException( |
|
| 390 | - sprintf( |
|
| 391 | - __( |
|
| 392 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 382 | + 'event_espresso' |
|
| 383 | + ), |
|
| 384 | + $key, |
|
| 385 | + 'pushData()' |
|
| 386 | + ) |
|
| 387 | + ); |
|
| 388 | + } |
|
| 389 | + throw new InvalidArgumentException( |
|
| 390 | + sprintf( |
|
| 391 | + __( |
|
| 392 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 393 | 393 | allowed. Consider attaching your value to a different key', |
| 394 | - 'event_espresso' |
|
| 395 | - ), |
|
| 396 | - $key |
|
| 397 | - ) |
|
| 398 | - ); |
|
| 399 | - } |
|
| 400 | - return true; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * registers core default stylesheets |
|
| 407 | - */ |
|
| 408 | - private function loadCoreCss() |
|
| 409 | - { |
|
| 410 | - if ($this->template_config->enable_default_style) { |
|
| 411 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 412 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 413 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 414 | - wp_register_style( |
|
| 415 | - 'espresso_default', |
|
| 416 | - $default_stylesheet_path, |
|
| 417 | - array('dashicons'), |
|
| 418 | - EVENT_ESPRESSO_VERSION |
|
| 419 | - ); |
|
| 420 | - //Load custom style sheet if available |
|
| 421 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 422 | - wp_register_style( |
|
| 423 | - 'espresso_custom_css', |
|
| 424 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 425 | - array('espresso_default'), |
|
| 426 | - EVENT_ESPRESSO_VERSION |
|
| 427 | - ); |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * registers core default javascript |
|
| 436 | - */ |
|
| 437 | - private function loadCoreJs() |
|
| 438 | - { |
|
| 439 | - // load core js |
|
| 440 | - wp_register_script( |
|
| 441 | - 'espresso_core', |
|
| 442 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 443 | - array('jquery'), |
|
| 444 | - EVENT_ESPRESSO_VERSION, |
|
| 445 | - true |
|
| 446 | - ); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * registers jQuery Validate for form validation |
|
| 453 | - */ |
|
| 454 | - private function loadJqueryValidate() |
|
| 455 | - { |
|
| 456 | - // register jQuery Validate and additional methods |
|
| 457 | - wp_register_script( |
|
| 458 | - 'jquery-validate', |
|
| 459 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 460 | - array('jquery'), |
|
| 461 | - '1.15.0', |
|
| 462 | - true |
|
| 463 | - ); |
|
| 464 | - wp_register_script( |
|
| 465 | - 'jquery-validate-extra-methods', |
|
| 466 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 467 | - array('jquery', 'jquery-validate'), |
|
| 468 | - '1.15.0', |
|
| 469 | - true |
|
| 470 | - ); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * registers accounting.js for performing client-side calculations |
|
| 477 | - */ |
|
| 478 | - private function loadAccountingJs() |
|
| 479 | - { |
|
| 480 | - //accounting.js library |
|
| 481 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 482 | - wp_register_script( |
|
| 483 | - 'ee-accounting-core', |
|
| 484 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 485 | - array('underscore'), |
|
| 486 | - '0.3.2', |
|
| 487 | - true |
|
| 488 | - ); |
|
| 489 | - wp_register_script( |
|
| 490 | - 'ee-accounting', |
|
| 491 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 492 | - array('ee-accounting-core'), |
|
| 493 | - EVENT_ESPRESSO_VERSION, |
|
| 494 | - true |
|
| 495 | - ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * registers accounting.js for performing client-side calculations |
|
| 502 | - */ |
|
| 503 | - private function localizeAccountingJs() |
|
| 504 | - { |
|
| 505 | - wp_localize_script( |
|
| 506 | - 'ee-accounting', |
|
| 507 | - 'EE_ACCOUNTING_CFG', |
|
| 508 | - array( |
|
| 509 | - 'currency' => array( |
|
| 510 | - 'symbol' => $this->currency_config->sign, |
|
| 511 | - 'format' => array( |
|
| 512 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 513 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 514 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 515 | - ), |
|
| 516 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 517 | - 'thousand' => $this->currency_config->thsnds, |
|
| 518 | - 'precision' => $this->currency_config->dec_plc, |
|
| 519 | - ), |
|
| 520 | - 'number' => array( |
|
| 521 | - 'precision' => $this->currency_config->dec_plc, |
|
| 522 | - 'thousand' => $this->currency_config->thsnds, |
|
| 523 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 524 | - ), |
|
| 525 | - ) |
|
| 526 | - ); |
|
| 527 | - $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * registers assets for cleaning your ears |
|
| 534 | - */ |
|
| 535 | - private function loadQtipJs() |
|
| 536 | - { |
|
| 537 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 538 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 539 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 540 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * This is used to set registered script handles that have data. |
|
| 547 | - * @param string $script_handle |
|
| 548 | - */ |
|
| 549 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 550 | - { |
|
| 551 | - $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
| 557 | - * Dependency stored in WP_Scripts if its set. |
|
| 558 | - */ |
|
| 559 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 560 | - { |
|
| 561 | - if (empty($this->script_handles_with_data)) { |
|
| 562 | - return; |
|
| 563 | - } |
|
| 564 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
| 565 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
| 572 | - * @param string $script_handle |
|
| 573 | - */ |
|
| 574 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 575 | - { |
|
| 576 | - if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 577 | - global $wp_scripts; |
|
| 578 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 579 | - unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 580 | - unset($this->script_handles_with_data[$script_handle]); |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - } |
|
| 394 | + 'event_espresso' |
|
| 395 | + ), |
|
| 396 | + $key |
|
| 397 | + ) |
|
| 398 | + ); |
|
| 399 | + } |
|
| 400 | + return true; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * registers core default stylesheets |
|
| 407 | + */ |
|
| 408 | + private function loadCoreCss() |
|
| 409 | + { |
|
| 410 | + if ($this->template_config->enable_default_style) { |
|
| 411 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 412 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 413 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 414 | + wp_register_style( |
|
| 415 | + 'espresso_default', |
|
| 416 | + $default_stylesheet_path, |
|
| 417 | + array('dashicons'), |
|
| 418 | + EVENT_ESPRESSO_VERSION |
|
| 419 | + ); |
|
| 420 | + //Load custom style sheet if available |
|
| 421 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 422 | + wp_register_style( |
|
| 423 | + 'espresso_custom_css', |
|
| 424 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 425 | + array('espresso_default'), |
|
| 426 | + EVENT_ESPRESSO_VERSION |
|
| 427 | + ); |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * registers core default javascript |
|
| 436 | + */ |
|
| 437 | + private function loadCoreJs() |
|
| 438 | + { |
|
| 439 | + // load core js |
|
| 440 | + wp_register_script( |
|
| 441 | + 'espresso_core', |
|
| 442 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 443 | + array('jquery'), |
|
| 444 | + EVENT_ESPRESSO_VERSION, |
|
| 445 | + true |
|
| 446 | + ); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * registers jQuery Validate for form validation |
|
| 453 | + */ |
|
| 454 | + private function loadJqueryValidate() |
|
| 455 | + { |
|
| 456 | + // register jQuery Validate and additional methods |
|
| 457 | + wp_register_script( |
|
| 458 | + 'jquery-validate', |
|
| 459 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 460 | + array('jquery'), |
|
| 461 | + '1.15.0', |
|
| 462 | + true |
|
| 463 | + ); |
|
| 464 | + wp_register_script( |
|
| 465 | + 'jquery-validate-extra-methods', |
|
| 466 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 467 | + array('jquery', 'jquery-validate'), |
|
| 468 | + '1.15.0', |
|
| 469 | + true |
|
| 470 | + ); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * registers accounting.js for performing client-side calculations |
|
| 477 | + */ |
|
| 478 | + private function loadAccountingJs() |
|
| 479 | + { |
|
| 480 | + //accounting.js library |
|
| 481 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 482 | + wp_register_script( |
|
| 483 | + 'ee-accounting-core', |
|
| 484 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 485 | + array('underscore'), |
|
| 486 | + '0.3.2', |
|
| 487 | + true |
|
| 488 | + ); |
|
| 489 | + wp_register_script( |
|
| 490 | + 'ee-accounting', |
|
| 491 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 492 | + array('ee-accounting-core'), |
|
| 493 | + EVENT_ESPRESSO_VERSION, |
|
| 494 | + true |
|
| 495 | + ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * registers accounting.js for performing client-side calculations |
|
| 502 | + */ |
|
| 503 | + private function localizeAccountingJs() |
|
| 504 | + { |
|
| 505 | + wp_localize_script( |
|
| 506 | + 'ee-accounting', |
|
| 507 | + 'EE_ACCOUNTING_CFG', |
|
| 508 | + array( |
|
| 509 | + 'currency' => array( |
|
| 510 | + 'symbol' => $this->currency_config->sign, |
|
| 511 | + 'format' => array( |
|
| 512 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 513 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 514 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 515 | + ), |
|
| 516 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 517 | + 'thousand' => $this->currency_config->thsnds, |
|
| 518 | + 'precision' => $this->currency_config->dec_plc, |
|
| 519 | + ), |
|
| 520 | + 'number' => array( |
|
| 521 | + 'precision' => $this->currency_config->dec_plc, |
|
| 522 | + 'thousand' => $this->currency_config->thsnds, |
|
| 523 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 524 | + ), |
|
| 525 | + ) |
|
| 526 | + ); |
|
| 527 | + $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * registers assets for cleaning your ears |
|
| 534 | + */ |
|
| 535 | + private function loadQtipJs() |
|
| 536 | + { |
|
| 537 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 538 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 539 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 540 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * This is used to set registered script handles that have data. |
|
| 547 | + * @param string $script_handle |
|
| 548 | + */ |
|
| 549 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 550 | + { |
|
| 551 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
| 557 | + * Dependency stored in WP_Scripts if its set. |
|
| 558 | + */ |
|
| 559 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 560 | + { |
|
| 561 | + if (empty($this->script_handles_with_data)) { |
|
| 562 | + return; |
|
| 563 | + } |
|
| 564 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
| 565 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
| 572 | + * @param string $script_handle |
|
| 573 | + */ |
|
| 574 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 575 | + { |
|
| 576 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 577 | + global $wp_scripts; |
|
| 578 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 579 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 580 | + unset($this->script_handles_with_data[$script_handle]); |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | 585 | |
| 586 | 586 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | //js.api |
| 139 | 139 | wp_register_script( |
| 140 | 140 | 'eejs-api', |
| 141 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 141 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
| 142 | 142 | array('underscore', 'eejs-core'), |
| 143 | 143 | EVENT_ESPRESSO_VERSION, |
| 144 | 144 | true |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
| 147 | 147 | $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
| 148 | 148 | } |
| 149 | - if (! is_admin()) { |
|
| 149 | + if ( ! is_admin()) { |
|
| 150 | 150 | $this->loadCoreCss(); |
| 151 | 151 | } |
| 152 | - $this->registerManifestFile($this->domain->distributionAssetsPath() . 'build-manifest.json'); |
|
| 152 | + $this->registerManifestFile($this->domain->distributionAssetsPath().'build-manifest.json'); |
|
| 153 | 153 | $this->loadCoreJs(); |
| 154 | 154 | $this->loadJqueryValidate(); |
| 155 | 155 | $this->loadAccountingJs(); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public function addTemplate($template_reference, $template_content) |
| 246 | 246 | { |
| 247 | - if (! isset($this->jsdata['templates'])) { |
|
| 247 | + if ( ! isset($this->jsdata['templates'])) { |
|
| 248 | 248 | $this->jsdata['templates'] = array(); |
| 249 | 249 | } |
| 250 | 250 | //no overrides allowed. |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $this->registerManifests(); |
| 309 | 309 | } |
| 310 | 310 | return isset($this->cached_manifest[$chunk_name][$asset_type]) |
| 311 | - ? $this->domain->distributionAssetsUrl() . $this->cached_manifest[$chunk_name][$asset_type] |
|
| 311 | + ? $this->domain->distributionAssetsUrl().$this->cached_manifest[$chunk_name][$asset_type] |
|
| 312 | 312 | : $chunk_name; |
| 313 | 313 | } |
| 314 | 314 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | public function registerManifestFile($manifest_file) |
| 324 | 324 | { |
| 325 | - if (! file_exists($manifest_file)) { |
|
| 325 | + if ( ! file_exists($manifest_file)) { |
|
| 326 | 326 | throw new InvalidFilePathException($manifest_file); |
| 327 | 327 | } |
| 328 | 328 | $this->registered_manifest_files[] = $manifest_file; |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | */ |
| 337 | 337 | private function registerManifests() |
| 338 | 338 | { |
| 339 | - if (! empty($this->cached_manifest)) { |
|
| 339 | + if ( ! empty($this->cached_manifest)) { |
|
| 340 | 340 | //already registered get out. This usually means that a $chunk_name (argument for getAssetUrl call) either |
| 341 | 341 | //doesn't exist in any registered manifest files. This could be because the $chunk_name is an actual file |
| 342 | 342 | //url and thus not registered in the manifest, or a plugin registered its manifest files too late. |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | $this->registered_manifest_files |
| 348 | 348 | ); |
| 349 | 349 | foreach ($this->registered_manifest_files as $file) { |
| 350 | - if (! file_exists($file)) { |
|
| 350 | + if ( ! file_exists($file)) { |
|
| 351 | 351 | throw new InvalidFilePathException($file); |
| 352 | 352 | } |
| 353 | 353 | /** recommended to avoid array_merge in loops */ |
@@ -408,9 +408,9 @@ discard block |
||
| 408 | 408 | private function loadCoreCss() |
| 409 | 409 | { |
| 410 | 410 | if ($this->template_config->enable_default_style) { |
| 411 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 411 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
| 412 | 412 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
| 413 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 413 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css'; |
|
| 414 | 414 | wp_register_style( |
| 415 | 415 | 'espresso_default', |
| 416 | 416 | $default_stylesheet_path, |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | if ($this->template_config->custom_style_sheet !== null) { |
| 422 | 422 | wp_register_style( |
| 423 | 423 | 'espresso_custom_css', |
| 424 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 424 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
| 425 | 425 | array('espresso_default'), |
| 426 | 426 | EVENT_ESPRESSO_VERSION |
| 427 | 427 | ); |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | // load core js |
| 440 | 440 | wp_register_script( |
| 441 | 441 | 'espresso_core', |
| 442 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 442 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 443 | 443 | array('jquery'), |
| 444 | 444 | EVENT_ESPRESSO_VERSION, |
| 445 | 445 | true |
@@ -456,14 +456,14 @@ discard block |
||
| 456 | 456 | // register jQuery Validate and additional methods |
| 457 | 457 | wp_register_script( |
| 458 | 458 | 'jquery-validate', |
| 459 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 459 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
| 460 | 460 | array('jquery'), |
| 461 | 461 | '1.15.0', |
| 462 | 462 | true |
| 463 | 463 | ); |
| 464 | 464 | wp_register_script( |
| 465 | 465 | 'jquery-validate-extra-methods', |
| 466 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 466 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
| 467 | 467 | array('jquery', 'jquery-validate'), |
| 468 | 468 | '1.15.0', |
| 469 | 469 | true |
@@ -481,14 +481,14 @@ discard block |
||
| 481 | 481 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 482 | 482 | wp_register_script( |
| 483 | 483 | 'ee-accounting-core', |
| 484 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 484 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
| 485 | 485 | array('underscore'), |
| 486 | 486 | '0.3.2', |
| 487 | 487 | true |
| 488 | 488 | ); |
| 489 | 489 | wp_register_script( |
| 490 | 490 | 'ee-accounting', |
| 491 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 491 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
| 492 | 492 | array('ee-accounting-core'), |
| 493 | 493 | EVENT_ESPRESSO_VERSION, |
| 494 | 494 | true |