Completed
Pull Request — Gutenberg/master (#637)
by Darren
117:38 queued 82:01
created
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +439 added lines, -439 removed lines patch added patch discarded remove patch
@@ -29,459 +29,459 @@
 block discarded – undo
29 29
 class CoreAssetManager extends AssetManager
30 30
 {
31 31
 
32
-    // WordPress core / Third party JS asset handles
33
-    const JS_HANDLE_JQUERY = 'jquery';
32
+	// WordPress core / Third party JS asset handles
33
+	const JS_HANDLE_JQUERY = 'jquery';
34 34
 
35
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
35
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
36 36
 
37
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
37
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
38 38
 
39
-    const JS_HANDLE_UNDERSCORE = 'underscore';
39
+	const JS_HANDLE_UNDERSCORE = 'underscore';
40 40
 
41
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
41
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
42 42
 
43
-    // EE JS assets handles
44
-    const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
43
+	// EE JS assets handles
44
+	const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
45 45
 
46
-    const JS_HANDLE_EE_JS_CORE = 'eejs-core';
46
+	const JS_HANDLE_EE_JS_CORE = 'eejs-core';
47 47
 
48
-    const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
48
+	const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
49 49
 
50
-    const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
50
+	const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
51 51
 
52
-    const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
52
+	const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
53 53
 
54
-    const JS_HANDLE_EE_MODEL = 'eventespresso-model';
54
+	const JS_HANDLE_EE_MODEL = 'eventespresso-model';
55 55
 
56
-    const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
56
+	const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
57 57
 
58
-    const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
58
+	const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
59 59
 
60
-    const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
60
+	const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
61 61
 
62
-    const JS_HANDLE_EE_JS_API = 'eejs-api';
62
+	const JS_HANDLE_EE_JS_API = 'eejs-api';
63 63
 
64
-    const JS_HANDLE_EE_CORE = 'espresso_core';
64
+	const JS_HANDLE_EE_CORE = 'espresso_core';
65 65
 
66
-    const JS_HANDLE_EE_I18N = 'eei18n';
67
-
68
-    const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
-
70
-    const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
-
72
-    // EE CSS assets handles
73
-    const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
-
75
-    const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
-
77
-    const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
-
79
-    /**
80
-     * @var EE_Currency_Config $currency_config
81
-     */
82
-    protected $currency_config;
83
-
84
-    /**
85
-     * @var EE_Template_Config $template_config
86
-     */
87
-    protected $template_config;
88
-
89
-
90
-    /**
91
-     * CoreAssetRegister constructor.
92
-     *
93
-     * @param AssetCollection    $assets
94
-     * @param EE_Currency_Config $currency_config
95
-     * @param EE_Template_Config $template_config
96
-     * @param DomainInterface    $domain
97
-     * @param Registry           $registry
98
-     */
99
-    public function __construct(
100
-        AssetCollection $assets,
101
-        EE_Currency_Config $currency_config,
102
-        EE_Template_Config $template_config,
103
-        DomainInterface $domain,
104
-        Registry $registry
105
-    ) {
106
-        $this->currency_config = $currency_config;
107
-        $this->template_config = $template_config;
108
-        parent::__construct($domain, $assets, $registry);
109
-    }
110
-
111
-
112
-    /**
113
-     * @since 4.9.62.p
114
-     * @throws DuplicateCollectionIdentifierException
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidEntityException
118
-     */
119
-    public function addAssets()
120
-    {
121
-        $this->addJavascriptFiles();
122
-        $this->addStylesheetFiles();
123
-    }
124
-
125
-
126
-    /**
127
-     * @since 4.9.62.p
128
-     * @throws DuplicateCollectionIdentifierException
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidEntityException
132
-     */
133
-    public function addJavascriptFiles()
134
-    {
135
-        $this->loadCoreJs();
136
-        $this->loadJqueryValidate();
137
-        $this->loadAccountingJs();
138
-        add_action(
139
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
-            array($this, 'loadQtipJs')
141
-        );
142
-        $this->registerAdminAssets();
143
-    }
144
-
145
-
146
-    /**
147
-     * @since 4.9.62.p
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     */
152
-    public function addStylesheetFiles()
153
-    {
154
-        $this->loadCoreCss();
155
-    }
156
-
157
-
158
-    /**
159
-     * core default javascript
160
-     *
161
-     * @since 4.9.62.p
162
-     * @throws DuplicateCollectionIdentifierException
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidEntityException
166
-     */
167
-    private function loadCoreJs()
168
-    {
169
-        $this->addJavascript(
170
-            CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
-        );
173
-
174
-        $this->addJavascript(
175
-            CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
-            array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
-        )
179
-        ->setHasInlineData();
180
-
181
-        $this->addJavascript(
182
-            CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
-            array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
-        );
186
-
187
-        $this->addJavascript(
188
-            CoreAssetManager::JS_HANDLE_EE_HELPERS,
189
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
190
-        )->setRequiresTranslation();
191
-
192
-        $this->addJavascript(
193
-            CoreAssetManager::JS_HANDLE_EE_MODEL,
194
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
195
-            array(
196
-                CoreAssetManager::JS_HANDLE_EE_HELPERS
197
-            )
198
-        )->setRequiresTranslation();
199
-
200
-        $this->addJavascript(
201
-            CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
202
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
203
-            array(
204
-                CoreAssetManager::JS_HANDLE_EE_MODEL
205
-            )
206
-        )->setRequiresTranslation();
207
-
208
-        $this->addJavascript(
209
-            CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
210
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
211
-            array(
212
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
213
-                'wp-data',
214
-                'wp-api-request',
215
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS
216
-            )
217
-        )
218
-             ->setRequiresTranslation();
219
-
220
-        $this->addJavascript(
221
-            CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
222
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
223
-            array(
224
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
225
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
226
-                'wp-components',
227
-            )
228
-        )->setRequiresTranslation();
229
-
230
-        $this->addJavascript(
231
-            CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
232
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
233
-            array(
234
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
235
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
236
-                'wp-components',
237
-            )
238
-        )
239
-        ->setRequiresTranslation();
240
-
241
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
242
-        $this->registry->addData(
243
-            'paths',
244
-            array(
245
-                'rest_route' => rest_url('ee/v4.8.36/'),
246
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
247
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
248
-                'site_url' => site_url('/'),
249
-                'admin_url' => admin_url('/'),
250
-            )
251
-        );
252
-        /** site formatting values **/
253
-        $this->registry->addData(
254
-            'site_formats',
255
-            array(
256
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
257
-            )
258
-        );
259
-        /** currency data **/
260
-        $this->registry->addData(
261
-            'currency_config',
262
-            $this->getCurrencySettings()
263
-        );
264
-        /** site timezone */
265
-        $this->registry->addData(
266
-            'default_timezone',
267
-            array(
268
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
269
-                'string' => get_option('timezone_string'),
270
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
271
-            )
272
-        );
273
-        /** site locale (user locale if user logged in) */
274
-        $this->registry->addData(
275
-            'locale',
276
-            array(
277
-                'user' => get_user_locale(),
278
-                'site' => get_locale()
279
-            )
280
-        );
281
-
282
-        $this->addJavascript(
283
-            CoreAssetManager::JS_HANDLE_EE_CORE,
284
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
285
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
286
-        )
287
-        ->setInlineDataCallback(
288
-            function () {
289
-                wp_localize_script(
290
-                    CoreAssetManager::JS_HANDLE_EE_CORE,
291
-                    CoreAssetManager::JS_HANDLE_EE_I18N,
292
-                    EE_Registry::$i18n_js_strings
293
-                );
294
-            }
295
-        );
296
-    }
297
-
298
-
299
-    /**
300
-     * Returns configuration data for the accounting-js library.
301
-     * @since $VID:$
302
-     * @return array
303
-     */
304
-    private function getAccountingSettings() {
305
-        return array(
306
-            'currency' => array(
307
-                'symbol'    => $this->currency_config->sign,
308
-                'format'    => array(
309
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
310
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
311
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
312
-                ),
313
-                'decimal'   => $this->currency_config->dec_mrk,
314
-                'thousand'  => $this->currency_config->thsnds,
315
-                'precision' => $this->currency_config->dec_plc,
316
-            ),
317
-            'number'   => array(
318
-                'precision' => $this->currency_config->dec_plc,
319
-                'thousand'  => $this->currency_config->thsnds,
320
-                'decimal'   => $this->currency_config->dec_mrk,
321
-            ),
322
-        );
323
-    }
324
-
325
-
326
-    /**
327
-     * Returns configuration data for the js Currency VO.
328
-     * @sinc $VID:$
329
-     * @return array
330
-     */
331
-    private function getCurrencySettings()
332
-    {
333
-        return array(
334
-            'code' => $this->currency_config->code,
335
-            'singularLabel' => $this->currency_config->name,
336
-            'pluralLabel' => $this->currency_config->plural,
337
-            'sign' => $this->currency_config->sign,
338
-            'signB4' => $this->currency_config->sign_b4,
339
-            'decimalPlaces' => $this->currency_config->dec_plc,
340
-            'decimalMark' => $this->currency_config->dec_mrk,
341
-            'thousandsSeparator' => $this->currency_config->thsnds,
342
-        );
343
-    }
344
-
345
-
346
-    /**
347
-     * @since 4.9.62.p
348
-     * @throws DuplicateCollectionIdentifierException
349
-     * @throws InvalidDataTypeException
350
-     * @throws InvalidEntityException
351
-     */
352
-    private function loadCoreCss()
353
-    {
354
-        if ($this->template_config->enable_default_style && ! is_admin()) {
355
-            $this->addStylesheet(
356
-                CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
357
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
358
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
359
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
360
-                array('dashicons')
361
-            );
362
-            //Load custom style sheet if available
363
-            if ($this->template_config->custom_style_sheet !== null) {
364
-                $this->addStylesheet(
365
-                    CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
366
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
367
-                    array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
368
-                );
369
-            }
370
-        }
371
-        $this->addStylesheet(
372
-            CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
373
-            $this->registry->getCssUrl(
374
-                $this->domain->assetNamespace(),
375
-                'components'
376
-            )
377
-        );
378
-    }
379
-
380
-
381
-    /**
382
-     * jQuery Validate for form validation
383
-     *
384
-     * @since 4.9.62.p
385
-     * @throws DuplicateCollectionIdentifierException
386
-     * @throws InvalidDataTypeException
387
-     * @throws InvalidEntityException
388
-     */
389
-    private function loadJqueryValidate()
390
-    {
391
-        $this->addJavascript(
392
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
393
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
394
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
395
-        )
396
-        ->setVersion('1.15.0');
397
-
398
-        $this->addJavascript(
399
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
400
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
401
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
402
-        )
403
-        ->setVersion('1.15.0');
404
-    }
405
-
406
-
407
-    /**
408
-     * accounting.js for performing client-side calculations
409
-     *
410
-     * @since 4.9.62.p
411
-     * @throws DuplicateCollectionIdentifierException
412
-     * @throws InvalidDataTypeException
413
-     * @throws InvalidEntityException
414
-     */
415
-    private function loadAccountingJs()
416
-    {
417
-        //accounting.js library
418
-        // @link http://josscrowcroft.github.io/accounting.js/
419
-        $this->addJavascript(
420
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
421
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
422
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
423
-        )
424
-        ->setVersion('0.3.2');
425
-
426
-        $this->addJavascript(
427
-            CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
428
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
429
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
430
-        )
431
-        ->setInlineDataCallback(
432
-            function () {
433
-                 wp_localize_script(
434
-                     CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
435
-                     'EE_ACCOUNTING_CFG',
436
-                     $this->getAccountingSettings()
437
-                 );
438
-            }
439
-        )
440
-        ->setVersion();
441
-    }
442
-
443
-
444
-    /**
445
-     * registers assets for cleaning your ears
446
-     *
447
-     * @param JavascriptAsset $script
448
-     */
449
-    public function loadQtipJs(JavascriptAsset $script)
450
-    {
451
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
452
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
453
-        if (
454
-            $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
455
-            && apply_filters('FHEE_load_qtip', false)
456
-        ) {
457
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
458
-        }
459
-    }
460
-
461
-
462
-    /**
463
-     * assets that are used in the WordPress admin
464
-     *
465
-     * @since 4.9.62.p
466
-     * @throws DuplicateCollectionIdentifierException
467
-     * @throws InvalidDataTypeException
468
-     * @throws InvalidEntityException
469
-     */
470
-    private function registerAdminAssets()
471
-    {
472
-        $this->addJavascript(
473
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
474
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
475
-            array(
476
-                CoreAssetManager::JS_HANDLE_JQUERY,
477
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
478
-            )
479
-        )
480
-        ->setRequiresTranslation();
481
-
482
-        $this->addStylesheet(
483
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
484
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
485
-        );
486
-    }
66
+	const JS_HANDLE_EE_I18N = 'eei18n';
67
+
68
+	const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
+
70
+	const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
+
72
+	// EE CSS assets handles
73
+	const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
+
75
+	const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
+
77
+	const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
+
79
+	/**
80
+	 * @var EE_Currency_Config $currency_config
81
+	 */
82
+	protected $currency_config;
83
+
84
+	/**
85
+	 * @var EE_Template_Config $template_config
86
+	 */
87
+	protected $template_config;
88
+
89
+
90
+	/**
91
+	 * CoreAssetRegister constructor.
92
+	 *
93
+	 * @param AssetCollection    $assets
94
+	 * @param EE_Currency_Config $currency_config
95
+	 * @param EE_Template_Config $template_config
96
+	 * @param DomainInterface    $domain
97
+	 * @param Registry           $registry
98
+	 */
99
+	public function __construct(
100
+		AssetCollection $assets,
101
+		EE_Currency_Config $currency_config,
102
+		EE_Template_Config $template_config,
103
+		DomainInterface $domain,
104
+		Registry $registry
105
+	) {
106
+		$this->currency_config = $currency_config;
107
+		$this->template_config = $template_config;
108
+		parent::__construct($domain, $assets, $registry);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @since 4.9.62.p
114
+	 * @throws DuplicateCollectionIdentifierException
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidEntityException
118
+	 */
119
+	public function addAssets()
120
+	{
121
+		$this->addJavascriptFiles();
122
+		$this->addStylesheetFiles();
123
+	}
124
+
125
+
126
+	/**
127
+	 * @since 4.9.62.p
128
+	 * @throws DuplicateCollectionIdentifierException
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidEntityException
132
+	 */
133
+	public function addJavascriptFiles()
134
+	{
135
+		$this->loadCoreJs();
136
+		$this->loadJqueryValidate();
137
+		$this->loadAccountingJs();
138
+		add_action(
139
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
+			array($this, 'loadQtipJs')
141
+		);
142
+		$this->registerAdminAssets();
143
+	}
144
+
145
+
146
+	/**
147
+	 * @since 4.9.62.p
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 */
152
+	public function addStylesheetFiles()
153
+	{
154
+		$this->loadCoreCss();
155
+	}
156
+
157
+
158
+	/**
159
+	 * core default javascript
160
+	 *
161
+	 * @since 4.9.62.p
162
+	 * @throws DuplicateCollectionIdentifierException
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidEntityException
166
+	 */
167
+	private function loadCoreJs()
168
+	{
169
+		$this->addJavascript(
170
+			CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
+		);
173
+
174
+		$this->addJavascript(
175
+			CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
+			array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
+		)
179
+		->setHasInlineData();
180
+
181
+		$this->addJavascript(
182
+			CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
+			array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
+		);
186
+
187
+		$this->addJavascript(
188
+			CoreAssetManager::JS_HANDLE_EE_HELPERS,
189
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
190
+		)->setRequiresTranslation();
191
+
192
+		$this->addJavascript(
193
+			CoreAssetManager::JS_HANDLE_EE_MODEL,
194
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
195
+			array(
196
+				CoreAssetManager::JS_HANDLE_EE_HELPERS
197
+			)
198
+		)->setRequiresTranslation();
199
+
200
+		$this->addJavascript(
201
+			CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
202
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
203
+			array(
204
+				CoreAssetManager::JS_HANDLE_EE_MODEL
205
+			)
206
+		)->setRequiresTranslation();
207
+
208
+		$this->addJavascript(
209
+			CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
210
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
211
+			array(
212
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
213
+				'wp-data',
214
+				'wp-api-request',
215
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS
216
+			)
217
+		)
218
+			 ->setRequiresTranslation();
219
+
220
+		$this->addJavascript(
221
+			CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
222
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
223
+			array(
224
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
225
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
226
+				'wp-components',
227
+			)
228
+		)->setRequiresTranslation();
229
+
230
+		$this->addJavascript(
231
+			CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
232
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
233
+			array(
234
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
235
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
236
+				'wp-components',
237
+			)
238
+		)
239
+		->setRequiresTranslation();
240
+
241
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
242
+		$this->registry->addData(
243
+			'paths',
244
+			array(
245
+				'rest_route' => rest_url('ee/v4.8.36/'),
246
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
247
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
248
+				'site_url' => site_url('/'),
249
+				'admin_url' => admin_url('/'),
250
+			)
251
+		);
252
+		/** site formatting values **/
253
+		$this->registry->addData(
254
+			'site_formats',
255
+			array(
256
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
257
+			)
258
+		);
259
+		/** currency data **/
260
+		$this->registry->addData(
261
+			'currency_config',
262
+			$this->getCurrencySettings()
263
+		);
264
+		/** site timezone */
265
+		$this->registry->addData(
266
+			'default_timezone',
267
+			array(
268
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
269
+				'string' => get_option('timezone_string'),
270
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
271
+			)
272
+		);
273
+		/** site locale (user locale if user logged in) */
274
+		$this->registry->addData(
275
+			'locale',
276
+			array(
277
+				'user' => get_user_locale(),
278
+				'site' => get_locale()
279
+			)
280
+		);
281
+
282
+		$this->addJavascript(
283
+			CoreAssetManager::JS_HANDLE_EE_CORE,
284
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
285
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
286
+		)
287
+		->setInlineDataCallback(
288
+			function () {
289
+				wp_localize_script(
290
+					CoreAssetManager::JS_HANDLE_EE_CORE,
291
+					CoreAssetManager::JS_HANDLE_EE_I18N,
292
+					EE_Registry::$i18n_js_strings
293
+				);
294
+			}
295
+		);
296
+	}
297
+
298
+
299
+	/**
300
+	 * Returns configuration data for the accounting-js library.
301
+	 * @since $VID:$
302
+	 * @return array
303
+	 */
304
+	private function getAccountingSettings() {
305
+		return array(
306
+			'currency' => array(
307
+				'symbol'    => $this->currency_config->sign,
308
+				'format'    => array(
309
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
310
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
311
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
312
+				),
313
+				'decimal'   => $this->currency_config->dec_mrk,
314
+				'thousand'  => $this->currency_config->thsnds,
315
+				'precision' => $this->currency_config->dec_plc,
316
+			),
317
+			'number'   => array(
318
+				'precision' => $this->currency_config->dec_plc,
319
+				'thousand'  => $this->currency_config->thsnds,
320
+				'decimal'   => $this->currency_config->dec_mrk,
321
+			),
322
+		);
323
+	}
324
+
325
+
326
+	/**
327
+	 * Returns configuration data for the js Currency VO.
328
+	 * @sinc $VID:$
329
+	 * @return array
330
+	 */
331
+	private function getCurrencySettings()
332
+	{
333
+		return array(
334
+			'code' => $this->currency_config->code,
335
+			'singularLabel' => $this->currency_config->name,
336
+			'pluralLabel' => $this->currency_config->plural,
337
+			'sign' => $this->currency_config->sign,
338
+			'signB4' => $this->currency_config->sign_b4,
339
+			'decimalPlaces' => $this->currency_config->dec_plc,
340
+			'decimalMark' => $this->currency_config->dec_mrk,
341
+			'thousandsSeparator' => $this->currency_config->thsnds,
342
+		);
343
+	}
344
+
345
+
346
+	/**
347
+	 * @since 4.9.62.p
348
+	 * @throws DuplicateCollectionIdentifierException
349
+	 * @throws InvalidDataTypeException
350
+	 * @throws InvalidEntityException
351
+	 */
352
+	private function loadCoreCss()
353
+	{
354
+		if ($this->template_config->enable_default_style && ! is_admin()) {
355
+			$this->addStylesheet(
356
+				CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
357
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
358
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
359
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
360
+				array('dashicons')
361
+			);
362
+			//Load custom style sheet if available
363
+			if ($this->template_config->custom_style_sheet !== null) {
364
+				$this->addStylesheet(
365
+					CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
366
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
367
+					array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
368
+				);
369
+			}
370
+		}
371
+		$this->addStylesheet(
372
+			CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
373
+			$this->registry->getCssUrl(
374
+				$this->domain->assetNamespace(),
375
+				'components'
376
+			)
377
+		);
378
+	}
379
+
380
+
381
+	/**
382
+	 * jQuery Validate for form validation
383
+	 *
384
+	 * @since 4.9.62.p
385
+	 * @throws DuplicateCollectionIdentifierException
386
+	 * @throws InvalidDataTypeException
387
+	 * @throws InvalidEntityException
388
+	 */
389
+	private function loadJqueryValidate()
390
+	{
391
+		$this->addJavascript(
392
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
393
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
394
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
395
+		)
396
+		->setVersion('1.15.0');
397
+
398
+		$this->addJavascript(
399
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
400
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
401
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
402
+		)
403
+		->setVersion('1.15.0');
404
+	}
405
+
406
+
407
+	/**
408
+	 * accounting.js for performing client-side calculations
409
+	 *
410
+	 * @since 4.9.62.p
411
+	 * @throws DuplicateCollectionIdentifierException
412
+	 * @throws InvalidDataTypeException
413
+	 * @throws InvalidEntityException
414
+	 */
415
+	private function loadAccountingJs()
416
+	{
417
+		//accounting.js library
418
+		// @link http://josscrowcroft.github.io/accounting.js/
419
+		$this->addJavascript(
420
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
421
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
422
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
423
+		)
424
+		->setVersion('0.3.2');
425
+
426
+		$this->addJavascript(
427
+			CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
428
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
429
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
430
+		)
431
+		->setInlineDataCallback(
432
+			function () {
433
+				 wp_localize_script(
434
+					 CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
435
+					 'EE_ACCOUNTING_CFG',
436
+					 $this->getAccountingSettings()
437
+				 );
438
+			}
439
+		)
440
+		->setVersion();
441
+	}
442
+
443
+
444
+	/**
445
+	 * registers assets for cleaning your ears
446
+	 *
447
+	 * @param JavascriptAsset $script
448
+	 */
449
+	public function loadQtipJs(JavascriptAsset $script)
450
+	{
451
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
452
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
453
+		if (
454
+			$script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
455
+			&& apply_filters('FHEE_load_qtip', false)
456
+		) {
457
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
458
+		}
459
+	}
460
+
461
+
462
+	/**
463
+	 * assets that are used in the WordPress admin
464
+	 *
465
+	 * @since 4.9.62.p
466
+	 * @throws DuplicateCollectionIdentifierException
467
+	 * @throws InvalidDataTypeException
468
+	 * @throws InvalidEntityException
469
+	 */
470
+	private function registerAdminAssets()
471
+	{
472
+		$this->addJavascript(
473
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
474
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
475
+			array(
476
+				CoreAssetManager::JS_HANDLE_JQUERY,
477
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
478
+			)
479
+		)
480
+		->setRequiresTranslation();
481
+
482
+		$this->addStylesheet(
483
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
484
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
485
+		);
486
+	}
487 487
 }
Please login to merge, or discard this patch.