Completed
Branch FET/add-crud-to-stores (19277a)
by
unknown
45:23 queued 36:46
created
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +521 added lines, -521 removed lines patch added patch discarded remove patch
@@ -31,544 +31,544 @@
 block discarded – undo
31 31
 class CoreAssetManager extends AssetManager
32 32
 {
33 33
 
34
-    // WordPress core / Third party JS asset handles
35
-    const JS_HANDLE_JQUERY = 'jquery';
34
+	// WordPress core / Third party JS asset handles
35
+	const JS_HANDLE_JQUERY = 'jquery';
36 36
 
37
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
37
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
38 38
 
39
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
39
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
40 40
 
41
-    const JS_HANDLE_UNDERSCORE = 'underscore';
41
+	const JS_HANDLE_UNDERSCORE = 'underscore';
42 42
 
43
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
43
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
44 44
 
45
-    /**
46
-     * @since 4.9.71.p
47
-     */
48
-    const JS_HANDLE_REACT = 'react';
45
+	/**
46
+	 * @since 4.9.71.p
47
+	 */
48
+	const JS_HANDLE_REACT = 'react';
49 49
 
50
-    /**
51
-     * @since 4.9.71.p
52
-     */
53
-    const JS_HANDLE_REACT_DOM = 'react-dom';
50
+	/**
51
+	 * @since 4.9.71.p
52
+	 */
53
+	const JS_HANDLE_REACT_DOM = 'react-dom';
54 54
 
55
-    /**
56
-     * @since 4.9.71.p
57
-     */
58
-    const JS_HANDLE_LODASH = 'lodash';
55
+	/**
56
+	 * @since 4.9.71.p
57
+	 */
58
+	const JS_HANDLE_LODASH = 'lodash';
59 59
 
60
-    // EE JS assets handles
61
-    const JS_HANDLE_MANIFEST = 'ee-manifest';
60
+	// EE JS assets handles
61
+	const JS_HANDLE_MANIFEST = 'ee-manifest';
62 62
 
63
-    const JS_HANDLE_JS_CORE = 'eejs-core';
63
+	const JS_HANDLE_JS_CORE = 'eejs-core';
64 64
 
65
-    const JS_HANDLE_VENDOR = 'eventespresso-vendor';
65
+	const JS_HANDLE_VENDOR = 'eventespresso-vendor';
66 66
 
67
-    const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
67
+	const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
68 68
 
69
-    const JS_HANDLE_HELPERS = 'eventespresso-helpers';
69
+	const JS_HANDLE_HELPERS = 'eventespresso-helpers';
70 70
 
71
-    const JS_HANDLE_MODEL = 'eventespresso-model';
71
+	const JS_HANDLE_MODEL = 'eventespresso-model';
72 72
 
73
-    const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
73
+	const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
74 74
 
75
-    const JS_HANDLE_HOCS = 'eventespresso-hocs';
75
+	const JS_HANDLE_HOCS = 'eventespresso-hocs';
76 76
 
77
-    const JS_HANDLE_COMPONENTS = 'eventespresso-components';
78
-
79
-    const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs';
77
+	const JS_HANDLE_COMPONENTS = 'eventespresso-components';
78
+
79
+	const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs';
80 80
 
81
-    const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
81
+	const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
82 82
 
83
-    const JS_HANDLE_CORE = 'espresso_core';
83
+	const JS_HANDLE_CORE = 'espresso_core';
84 84
 
85
-    const JS_HANDLE_I18N = 'eei18n';
86
-
87
-    const JS_HANDLE_ACCOUNTING = 'ee-accounting';
88
-
89
-    const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
90
-
91
-    // EE CSS assets handles
92
-    const CSS_HANDLE_DEFAULT = 'espresso_default';
93
-
94
-    const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
95
-
96
-    const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
97
-
98
-    /**
99
-     * @var EE_Currency_Config $currency_config
100
-     */
101
-    protected $currency_config;
102
-
103
-    /**
104
-     * @var EE_Template_Config $template_config
105
-     */
106
-    protected $template_config;
107
-
108
-
109
-    /**
110
-     * CoreAssetRegister constructor.
111
-     *
112
-     * @param AssetCollection    $assets
113
-     * @param EE_Currency_Config $currency_config
114
-     * @param EE_Template_Config $template_config
115
-     * @param DomainInterface    $domain
116
-     * @param Registry           $registry
117
-     */
118
-    public function __construct(
119
-        AssetCollection $assets,
120
-        EE_Currency_Config $currency_config,
121
-        EE_Template_Config $template_config,
122
-        DomainInterface $domain,
123
-        Registry $registry
124
-    ) {
125
-        $this->currency_config = $currency_config;
126
-        $this->template_config = $template_config;
127
-        parent::__construct($domain, $assets, $registry);
128
-    }
129
-
130
-
131
-    /**
132
-     * @since 4.9.62.p
133
-     * @throws DomainException
134
-     * @throws DuplicateCollectionIdentifierException
135
-     * @throws InvalidArgumentException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidEntityException
138
-     * @throws InvalidInterfaceException
139
-     */
140
-    public function addAssets()
141
-    {
142
-        $this->addJavascriptFiles();
143
-        $this->addStylesheetFiles();
144
-    }
145
-
146
-
147
-    /**
148
-     * @since 4.9.62.p
149
-     * @throws DomainException
150
-     * @throws DuplicateCollectionIdentifierException
151
-     * @throws InvalidArgumentException
152
-     * @throws InvalidDataTypeException
153
-     * @throws InvalidEntityException
154
-     * @throws InvalidInterfaceException
155
-     */
156
-    public function addJavascriptFiles()
157
-    {
158
-        $this->loadCoreJs();
159
-        $this->loadJqueryValidate();
160
-        $this->loadAccountingJs();
161
-        add_action(
162
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
163
-            array($this, 'loadQtipJs')
164
-        );
165
-        $this->registerAdminAssets();
166
-    }
167
-
168
-
169
-    /**
170
-     * @since 4.9.62.p
171
-     * @throws DuplicateCollectionIdentifierException
172
-     * @throws InvalidDataTypeException
173
-     * @throws InvalidEntityException
174
-     */
175
-    public function addStylesheetFiles()
176
-    {
177
-        $this->loadCoreCss();
178
-    }
179
-
180
-
181
-    /**
182
-     * core default javascript
183
-     *
184
-     * @since 4.9.62.p
185
-     * @throws DomainException
186
-     * @throws DuplicateCollectionIdentifierException
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidEntityException
190
-     * @throws InvalidInterfaceException
191
-     */
192
-    private function loadCoreJs()
193
-    {
194
-        // conditionally load third-party libraries that WP core MIGHT have.
195
-        $this->registerWpAssets();
196
-
197
-        $this->addJavascript(
198
-            CoreAssetManager::JS_HANDLE_MANIFEST,
199
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
200
-        );
201
-
202
-        $this->addJavascript(
203
-            CoreAssetManager::JS_HANDLE_JS_CORE,
204
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
205
-            array(CoreAssetManager::JS_HANDLE_MANIFEST)
206
-        )
207
-        ->setHasInlineData();
208
-
209
-        $this->addJavascript(
210
-            CoreAssetManager::JS_HANDLE_VENDOR,
211
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
212
-            array(
213
-                CoreAssetManager::JS_HANDLE_JS_CORE,
214
-                CoreAssetManager::JS_HANDLE_REACT,
215
-                CoreAssetManager::JS_HANDLE_REACT_DOM,
216
-                CoreAssetManager::JS_HANDLE_LODASH,
217
-            )
218
-        );
219
-
220
-        $this->addJavascript(
221
-            CoreAssetManager::JS_HANDLE_VALIDATORS,
222
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'validators')
223
-        )->setRequiresTranslation();
224
-
225
-        $this->addJavascript(
226
-            CoreAssetManager::JS_HANDLE_HELPERS,
227
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers'),
228
-            array(
229
-                CoreAssetManager::JS_HANDLE_VALIDATORS
230
-            )
231
-        )->setRequiresTranslation();
232
-
233
-        $this->addJavascript(
234
-            CoreAssetManager::JS_HANDLE_MODEL,
235
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
236
-            array(
237
-                CoreAssetManager::JS_HANDLE_HELPERS
238
-            )
239
-        )->setRequiresTranslation();
240
-
241
-        $this->addJavascript(
242
-            CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
243
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
244
-            array(
245
-                CoreAssetManager::JS_HANDLE_MODEL
246
-            )
247
-        )->setRequiresTranslation();
248
-
249
-        $this->addJavascript(
250
-            CoreAssetManager::JS_HANDLE_DATA_STORES,
251
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
252
-            array(
253
-                CoreAssetManager::JS_HANDLE_VENDOR,
254
-                'wp-data',
255
-                'wp-api-fetch',
256
-                CoreAssetManager::JS_HANDLE_VALUE_OBJECTS
257
-            )
258
-        )
259
-             ->setRequiresTranslation();
260
-
261
-        $this->addJavascript(
262
-            CoreAssetManager::JS_HANDLE_HOCS,
263
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocs'),
264
-            array(
265
-                CoreAssetManager::JS_HANDLE_DATA_STORES,
266
-                CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
267
-                'wp-components',
268
-            )
269
-        )->setRequiresTranslation();
270
-
271
-        $this->addJavascript(
272
-            CoreAssetManager::JS_HANDLE_COMPONENTS,
273
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
274
-            array(
275
-                CoreAssetManager::JS_HANDLE_DATA_STORES,
276
-                CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
277
-                'wp-components',
278
-            )
279
-        )
280
-        ->setRequiresTranslation();
281
-
282
-        $this->addJavascript(
283
-            CoreAssetManager::JS_HANDLE_EDITOR_HOCS,
284
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'editor-hocs'),
285
-            array(
286
-                CoreAssetManager::JS_HANDLE_COMPONENTS
287
-            )
288
-        )->setRequiresTranslation();
289
-
290
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
291
-        $this->registry->addData(
292
-            'paths',
293
-            array(
294
-                'base_rest_route' => rest_url(),
295
-                'rest_route' => rest_url('ee/v4.8.36/'),
296
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
297
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
298
-                'site_url' => site_url('/'),
299
-                'admin_url' => admin_url('/'),
300
-            )
301
-        );
302
-        /** site formatting values **/
303
-        $this->registry->addData(
304
-            'site_formats',
305
-            array(
306
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
307
-            )
308
-        );
309
-        /** currency data **/
310
-        $this->registry->addData(
311
-            'currency_config',
312
-            $this->getCurrencySettings()
313
-        );
314
-        /** site timezone */
315
-        $this->registry->addData(
316
-            'default_timezone',
317
-            array(
318
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
319
-                'string' => get_option('timezone_string'),
320
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
321
-            )
322
-        );
323
-        /** site locale (user locale if user logged in) */
324
-        $this->registry->addData(
325
-            'locale',
326
-            array(
327
-                'user' => get_user_locale(),
328
-                'site' => get_locale()
329
-            )
330
-        );
331
-
332
-        $this->addJavascript(
333
-            CoreAssetManager::JS_HANDLE_CORE,
334
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
335
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
336
-        )
337
-        ->setInlineDataCallback(
338
-            function () {
339
-                wp_localize_script(
340
-                    CoreAssetManager::JS_HANDLE_CORE,
341
-                    CoreAssetManager::JS_HANDLE_I18N,
342
-                    EE_Registry::$i18n_js_strings
343
-                );
344
-            }
345
-        );
346
-    }
347
-
348
-
349
-    /**
350
-     * Registers vendor files that are bundled with a later version WP but might not be for the current version of
351
-     * WordPress in the running environment.
352
-     *
353
-     * @throws DuplicateCollectionIdentifierException
354
-     * @throws InvalidDataTypeException
355
-     * @throws InvalidEntityException
356
-     * @throws DomainException
357
-     * @since 4.9.71.p
358
-     */
359
-    private function registerWpAssets()
360
-    {
361
-        global $wp_version;
362
-        if (version_compare($wp_version, '5.0.beta', '>=')) {
363
-            return;
364
-        }
365
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
366
-            ->setVersion('16.6.0');
367
-        $this->addVendorJavascript(
368
-            CoreAssetManager::JS_HANDLE_REACT_DOM,
369
-            array(CoreAssetManager::JS_HANDLE_REACT)
370
-        )->setVersion('16.6.0');
371
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
372
-            ->setInlineDataCallback(
373
-                function() {
374
-                    wp_add_inline_script(
375
-                        CoreAssetManager::JS_HANDLE_LODASH,
376
-                        'window.lodash = _.noConflict();'
377
-                    );
378
-                }
379
-            )
380
-            ->setVersion('4.17.11');
381
-    }
382
-
383
-
384
-    /**
385
-     * Returns configuration data for the accounting-js library.
386
-     * @since 4.9.71.p
387
-     * @return array
388
-     */
389
-    private function getAccountingSettings() {
390
-        return array(
391
-            'currency' => array(
392
-                'symbol'    => $this->currency_config->sign,
393
-                'format'    => array(
394
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
395
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
396
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
397
-                ),
398
-                'decimal'   => $this->currency_config->dec_mrk,
399
-                'thousand'  => $this->currency_config->thsnds,
400
-                'precision' => $this->currency_config->dec_plc,
401
-            ),
402
-            'number'   => array(
403
-                'precision' => $this->currency_config->dec_plc,
404
-                'thousand'  => $this->currency_config->thsnds,
405
-                'decimal'   => $this->currency_config->dec_mrk,
406
-            ),
407
-        );
408
-    }
409
-
410
-
411
-    /**
412
-     * Returns configuration data for the js Currency VO.
413
-     * @since 4.9.71.p
414
-     * @return array
415
-     */
416
-    private function getCurrencySettings()
417
-    {
418
-        return array(
419
-            'code' => $this->currency_config->code,
420
-            'singularLabel' => $this->currency_config->name,
421
-            'pluralLabel' => $this->currency_config->plural,
422
-            'sign' => $this->currency_config->sign,
423
-            'signB4' => $this->currency_config->sign_b4,
424
-            'decimalPlaces' => $this->currency_config->dec_plc,
425
-            'decimalMark' => $this->currency_config->dec_mrk,
426
-            'thousandsSeparator' => $this->currency_config->thsnds,
427
-        );
428
-    }
429
-
430
-
431
-    /**
432
-     * @since 4.9.62.p
433
-     * @throws DuplicateCollectionIdentifierException
434
-     * @throws InvalidDataTypeException
435
-     * @throws InvalidEntityException
436
-     */
437
-    private function loadCoreCss()
438
-    {
439
-        if ($this->template_config->enable_default_style && ! is_admin()) {
440
-            $this->addStylesheet(
441
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
442
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
443
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
444
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
445
-                array('dashicons')
446
-            );
447
-            //Load custom style sheet if available
448
-            if ($this->template_config->custom_style_sheet !== null) {
449
-                $this->addStylesheet(
450
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
451
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
452
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
453
-                );
454
-            }
455
-        }
456
-        $this->addStylesheet(
457
-            CoreAssetManager::CSS_HANDLE_COMPONENTS,
458
-            $this->registry->getCssUrl(
459
-                $this->domain->assetNamespace(),
460
-                'components'
461
-            )
462
-        );
463
-    }
464
-
465
-
466
-    /**
467
-     * jQuery Validate for form validation
468
-     *
469
-     * @since 4.9.62.p
470
-     * @throws DomainException
471
-     * @throws DuplicateCollectionIdentifierException
472
-     * @throws InvalidDataTypeException
473
-     * @throws InvalidEntityException
474
-     */
475
-    private function loadJqueryValidate()
476
-    {
477
-        $this->addJavascript(
478
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
479
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
480
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
481
-        )
482
-        ->setVersion('1.15.0');
483
-
484
-        $this->addJavascript(
485
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
486
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
487
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
488
-        )
489
-        ->setVersion('1.15.0');
490
-    }
491
-
492
-
493
-    /**
494
-     * accounting.js for performing client-side calculations
495
-     *
496
-     * @since 4.9.62.p
497
-     * @throws DomainException
498
-     * @throws DuplicateCollectionIdentifierException
499
-     * @throws InvalidDataTypeException
500
-     * @throws InvalidEntityException
501
-     */
502
-    private function loadAccountingJs()
503
-    {
504
-        //accounting.js library
505
-        // @link http://josscrowcroft.github.io/accounting.js/
506
-        $this->addJavascript(
507
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
508
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
509
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
510
-        )
511
-        ->setVersion('0.3.2');
512
-
513
-        $this->addJavascript(
514
-            CoreAssetManager::JS_HANDLE_ACCOUNTING,
515
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
516
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
517
-        )
518
-        ->setInlineDataCallback(
519
-            function () {
520
-                 wp_localize_script(
521
-                     CoreAssetManager::JS_HANDLE_ACCOUNTING,
522
-                     'EE_ACCOUNTING_CFG',
523
-                     $this->getAccountingSettings()
524
-                 );
525
-            }
526
-        )
527
-        ->setVersion();
528
-    }
529
-
530
-
531
-    /**
532
-     * registers assets for cleaning your ears
533
-     *
534
-     * @param JavascriptAsset $script
535
-     */
536
-    public function loadQtipJs(JavascriptAsset $script)
537
-    {
538
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
539
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
540
-        if (
541
-            $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
542
-            && apply_filters('FHEE_load_qtip', false)
543
-        ) {
544
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
545
-        }
546
-    }
547
-
548
-
549
-    /**
550
-     * assets that are used in the WordPress admin
551
-     *
552
-     * @since 4.9.62.p
553
-     * @throws DuplicateCollectionIdentifierException
554
-     * @throws InvalidDataTypeException
555
-     * @throws InvalidEntityException
556
-     */
557
-    private function registerAdminAssets()
558
-    {
559
-        $this->addJavascript(
560
-            CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
561
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
562
-            array(
563
-                CoreAssetManager::JS_HANDLE_JQUERY,
564
-                CoreAssetManager::JS_HANDLE_VENDOR,
565
-            )
566
-        )
567
-        ->setRequiresTranslation();
568
-
569
-        $this->addStylesheet(
570
-            CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
571
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
572
-        );
573
-    }
85
+	const JS_HANDLE_I18N = 'eei18n';
86
+
87
+	const JS_HANDLE_ACCOUNTING = 'ee-accounting';
88
+
89
+	const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
90
+
91
+	// EE CSS assets handles
92
+	const CSS_HANDLE_DEFAULT = 'espresso_default';
93
+
94
+	const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
95
+
96
+	const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
97
+
98
+	/**
99
+	 * @var EE_Currency_Config $currency_config
100
+	 */
101
+	protected $currency_config;
102
+
103
+	/**
104
+	 * @var EE_Template_Config $template_config
105
+	 */
106
+	protected $template_config;
107
+
108
+
109
+	/**
110
+	 * CoreAssetRegister constructor.
111
+	 *
112
+	 * @param AssetCollection    $assets
113
+	 * @param EE_Currency_Config $currency_config
114
+	 * @param EE_Template_Config $template_config
115
+	 * @param DomainInterface    $domain
116
+	 * @param Registry           $registry
117
+	 */
118
+	public function __construct(
119
+		AssetCollection $assets,
120
+		EE_Currency_Config $currency_config,
121
+		EE_Template_Config $template_config,
122
+		DomainInterface $domain,
123
+		Registry $registry
124
+	) {
125
+		$this->currency_config = $currency_config;
126
+		$this->template_config = $template_config;
127
+		parent::__construct($domain, $assets, $registry);
128
+	}
129
+
130
+
131
+	/**
132
+	 * @since 4.9.62.p
133
+	 * @throws DomainException
134
+	 * @throws DuplicateCollectionIdentifierException
135
+	 * @throws InvalidArgumentException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidEntityException
138
+	 * @throws InvalidInterfaceException
139
+	 */
140
+	public function addAssets()
141
+	{
142
+		$this->addJavascriptFiles();
143
+		$this->addStylesheetFiles();
144
+	}
145
+
146
+
147
+	/**
148
+	 * @since 4.9.62.p
149
+	 * @throws DomainException
150
+	 * @throws DuplicateCollectionIdentifierException
151
+	 * @throws InvalidArgumentException
152
+	 * @throws InvalidDataTypeException
153
+	 * @throws InvalidEntityException
154
+	 * @throws InvalidInterfaceException
155
+	 */
156
+	public function addJavascriptFiles()
157
+	{
158
+		$this->loadCoreJs();
159
+		$this->loadJqueryValidate();
160
+		$this->loadAccountingJs();
161
+		add_action(
162
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
163
+			array($this, 'loadQtipJs')
164
+		);
165
+		$this->registerAdminAssets();
166
+	}
167
+
168
+
169
+	/**
170
+	 * @since 4.9.62.p
171
+	 * @throws DuplicateCollectionIdentifierException
172
+	 * @throws InvalidDataTypeException
173
+	 * @throws InvalidEntityException
174
+	 */
175
+	public function addStylesheetFiles()
176
+	{
177
+		$this->loadCoreCss();
178
+	}
179
+
180
+
181
+	/**
182
+	 * core default javascript
183
+	 *
184
+	 * @since 4.9.62.p
185
+	 * @throws DomainException
186
+	 * @throws DuplicateCollectionIdentifierException
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidEntityException
190
+	 * @throws InvalidInterfaceException
191
+	 */
192
+	private function loadCoreJs()
193
+	{
194
+		// conditionally load third-party libraries that WP core MIGHT have.
195
+		$this->registerWpAssets();
196
+
197
+		$this->addJavascript(
198
+			CoreAssetManager::JS_HANDLE_MANIFEST,
199
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
200
+		);
201
+
202
+		$this->addJavascript(
203
+			CoreAssetManager::JS_HANDLE_JS_CORE,
204
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
205
+			array(CoreAssetManager::JS_HANDLE_MANIFEST)
206
+		)
207
+		->setHasInlineData();
208
+
209
+		$this->addJavascript(
210
+			CoreAssetManager::JS_HANDLE_VENDOR,
211
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
212
+			array(
213
+				CoreAssetManager::JS_HANDLE_JS_CORE,
214
+				CoreAssetManager::JS_HANDLE_REACT,
215
+				CoreAssetManager::JS_HANDLE_REACT_DOM,
216
+				CoreAssetManager::JS_HANDLE_LODASH,
217
+			)
218
+		);
219
+
220
+		$this->addJavascript(
221
+			CoreAssetManager::JS_HANDLE_VALIDATORS,
222
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'validators')
223
+		)->setRequiresTranslation();
224
+
225
+		$this->addJavascript(
226
+			CoreAssetManager::JS_HANDLE_HELPERS,
227
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers'),
228
+			array(
229
+				CoreAssetManager::JS_HANDLE_VALIDATORS
230
+			)
231
+		)->setRequiresTranslation();
232
+
233
+		$this->addJavascript(
234
+			CoreAssetManager::JS_HANDLE_MODEL,
235
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
236
+			array(
237
+				CoreAssetManager::JS_HANDLE_HELPERS
238
+			)
239
+		)->setRequiresTranslation();
240
+
241
+		$this->addJavascript(
242
+			CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
243
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
244
+			array(
245
+				CoreAssetManager::JS_HANDLE_MODEL
246
+			)
247
+		)->setRequiresTranslation();
248
+
249
+		$this->addJavascript(
250
+			CoreAssetManager::JS_HANDLE_DATA_STORES,
251
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
252
+			array(
253
+				CoreAssetManager::JS_HANDLE_VENDOR,
254
+				'wp-data',
255
+				'wp-api-fetch',
256
+				CoreAssetManager::JS_HANDLE_VALUE_OBJECTS
257
+			)
258
+		)
259
+			 ->setRequiresTranslation();
260
+
261
+		$this->addJavascript(
262
+			CoreAssetManager::JS_HANDLE_HOCS,
263
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'hocs'),
264
+			array(
265
+				CoreAssetManager::JS_HANDLE_DATA_STORES,
266
+				CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
267
+				'wp-components',
268
+			)
269
+		)->setRequiresTranslation();
270
+
271
+		$this->addJavascript(
272
+			CoreAssetManager::JS_HANDLE_COMPONENTS,
273
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
274
+			array(
275
+				CoreAssetManager::JS_HANDLE_DATA_STORES,
276
+				CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
277
+				'wp-components',
278
+			)
279
+		)
280
+		->setRequiresTranslation();
281
+
282
+		$this->addJavascript(
283
+			CoreAssetManager::JS_HANDLE_EDITOR_HOCS,
284
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'editor-hocs'),
285
+			array(
286
+				CoreAssetManager::JS_HANDLE_COMPONENTS
287
+			)
288
+		)->setRequiresTranslation();
289
+
290
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
291
+		$this->registry->addData(
292
+			'paths',
293
+			array(
294
+				'base_rest_route' => rest_url(),
295
+				'rest_route' => rest_url('ee/v4.8.36/'),
296
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
297
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
298
+				'site_url' => site_url('/'),
299
+				'admin_url' => admin_url('/'),
300
+			)
301
+		);
302
+		/** site formatting values **/
303
+		$this->registry->addData(
304
+			'site_formats',
305
+			array(
306
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
307
+			)
308
+		);
309
+		/** currency data **/
310
+		$this->registry->addData(
311
+			'currency_config',
312
+			$this->getCurrencySettings()
313
+		);
314
+		/** site timezone */
315
+		$this->registry->addData(
316
+			'default_timezone',
317
+			array(
318
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
319
+				'string' => get_option('timezone_string'),
320
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
321
+			)
322
+		);
323
+		/** site locale (user locale if user logged in) */
324
+		$this->registry->addData(
325
+			'locale',
326
+			array(
327
+				'user' => get_user_locale(),
328
+				'site' => get_locale()
329
+			)
330
+		);
331
+
332
+		$this->addJavascript(
333
+			CoreAssetManager::JS_HANDLE_CORE,
334
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
335
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
336
+		)
337
+		->setInlineDataCallback(
338
+			function () {
339
+				wp_localize_script(
340
+					CoreAssetManager::JS_HANDLE_CORE,
341
+					CoreAssetManager::JS_HANDLE_I18N,
342
+					EE_Registry::$i18n_js_strings
343
+				);
344
+			}
345
+		);
346
+	}
347
+
348
+
349
+	/**
350
+	 * Registers vendor files that are bundled with a later version WP but might not be for the current version of
351
+	 * WordPress in the running environment.
352
+	 *
353
+	 * @throws DuplicateCollectionIdentifierException
354
+	 * @throws InvalidDataTypeException
355
+	 * @throws InvalidEntityException
356
+	 * @throws DomainException
357
+	 * @since 4.9.71.p
358
+	 */
359
+	private function registerWpAssets()
360
+	{
361
+		global $wp_version;
362
+		if (version_compare($wp_version, '5.0.beta', '>=')) {
363
+			return;
364
+		}
365
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
366
+			->setVersion('16.6.0');
367
+		$this->addVendorJavascript(
368
+			CoreAssetManager::JS_HANDLE_REACT_DOM,
369
+			array(CoreAssetManager::JS_HANDLE_REACT)
370
+		)->setVersion('16.6.0');
371
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
372
+			->setInlineDataCallback(
373
+				function() {
374
+					wp_add_inline_script(
375
+						CoreAssetManager::JS_HANDLE_LODASH,
376
+						'window.lodash = _.noConflict();'
377
+					);
378
+				}
379
+			)
380
+			->setVersion('4.17.11');
381
+	}
382
+
383
+
384
+	/**
385
+	 * Returns configuration data for the accounting-js library.
386
+	 * @since 4.9.71.p
387
+	 * @return array
388
+	 */
389
+	private function getAccountingSettings() {
390
+		return array(
391
+			'currency' => array(
392
+				'symbol'    => $this->currency_config->sign,
393
+				'format'    => array(
394
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
395
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
396
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
397
+				),
398
+				'decimal'   => $this->currency_config->dec_mrk,
399
+				'thousand'  => $this->currency_config->thsnds,
400
+				'precision' => $this->currency_config->dec_plc,
401
+			),
402
+			'number'   => array(
403
+				'precision' => $this->currency_config->dec_plc,
404
+				'thousand'  => $this->currency_config->thsnds,
405
+				'decimal'   => $this->currency_config->dec_mrk,
406
+			),
407
+		);
408
+	}
409
+
410
+
411
+	/**
412
+	 * Returns configuration data for the js Currency VO.
413
+	 * @since 4.9.71.p
414
+	 * @return array
415
+	 */
416
+	private function getCurrencySettings()
417
+	{
418
+		return array(
419
+			'code' => $this->currency_config->code,
420
+			'singularLabel' => $this->currency_config->name,
421
+			'pluralLabel' => $this->currency_config->plural,
422
+			'sign' => $this->currency_config->sign,
423
+			'signB4' => $this->currency_config->sign_b4,
424
+			'decimalPlaces' => $this->currency_config->dec_plc,
425
+			'decimalMark' => $this->currency_config->dec_mrk,
426
+			'thousandsSeparator' => $this->currency_config->thsnds,
427
+		);
428
+	}
429
+
430
+
431
+	/**
432
+	 * @since 4.9.62.p
433
+	 * @throws DuplicateCollectionIdentifierException
434
+	 * @throws InvalidDataTypeException
435
+	 * @throws InvalidEntityException
436
+	 */
437
+	private function loadCoreCss()
438
+	{
439
+		if ($this->template_config->enable_default_style && ! is_admin()) {
440
+			$this->addStylesheet(
441
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
442
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
443
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
444
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
445
+				array('dashicons')
446
+			);
447
+			//Load custom style sheet if available
448
+			if ($this->template_config->custom_style_sheet !== null) {
449
+				$this->addStylesheet(
450
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
451
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
452
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
453
+				);
454
+			}
455
+		}
456
+		$this->addStylesheet(
457
+			CoreAssetManager::CSS_HANDLE_COMPONENTS,
458
+			$this->registry->getCssUrl(
459
+				$this->domain->assetNamespace(),
460
+				'components'
461
+			)
462
+		);
463
+	}
464
+
465
+
466
+	/**
467
+	 * jQuery Validate for form validation
468
+	 *
469
+	 * @since 4.9.62.p
470
+	 * @throws DomainException
471
+	 * @throws DuplicateCollectionIdentifierException
472
+	 * @throws InvalidDataTypeException
473
+	 * @throws InvalidEntityException
474
+	 */
475
+	private function loadJqueryValidate()
476
+	{
477
+		$this->addJavascript(
478
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
479
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
480
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
481
+		)
482
+		->setVersion('1.15.0');
483
+
484
+		$this->addJavascript(
485
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
486
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
487
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
488
+		)
489
+		->setVersion('1.15.0');
490
+	}
491
+
492
+
493
+	/**
494
+	 * accounting.js for performing client-side calculations
495
+	 *
496
+	 * @since 4.9.62.p
497
+	 * @throws DomainException
498
+	 * @throws DuplicateCollectionIdentifierException
499
+	 * @throws InvalidDataTypeException
500
+	 * @throws InvalidEntityException
501
+	 */
502
+	private function loadAccountingJs()
503
+	{
504
+		//accounting.js library
505
+		// @link http://josscrowcroft.github.io/accounting.js/
506
+		$this->addJavascript(
507
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
508
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
509
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
510
+		)
511
+		->setVersion('0.3.2');
512
+
513
+		$this->addJavascript(
514
+			CoreAssetManager::JS_HANDLE_ACCOUNTING,
515
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
516
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
517
+		)
518
+		->setInlineDataCallback(
519
+			function () {
520
+				 wp_localize_script(
521
+					 CoreAssetManager::JS_HANDLE_ACCOUNTING,
522
+					 'EE_ACCOUNTING_CFG',
523
+					 $this->getAccountingSettings()
524
+				 );
525
+			}
526
+		)
527
+		->setVersion();
528
+	}
529
+
530
+
531
+	/**
532
+	 * registers assets for cleaning your ears
533
+	 *
534
+	 * @param JavascriptAsset $script
535
+	 */
536
+	public function loadQtipJs(JavascriptAsset $script)
537
+	{
538
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
539
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
540
+		if (
541
+			$script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
542
+			&& apply_filters('FHEE_load_qtip', false)
543
+		) {
544
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
545
+		}
546
+	}
547
+
548
+
549
+	/**
550
+	 * assets that are used in the WordPress admin
551
+	 *
552
+	 * @since 4.9.62.p
553
+	 * @throws DuplicateCollectionIdentifierException
554
+	 * @throws InvalidDataTypeException
555
+	 * @throws InvalidEntityException
556
+	 */
557
+	private function registerAdminAssets()
558
+	{
559
+		$this->addJavascript(
560
+			CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
561
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
562
+			array(
563
+				CoreAssetManager::JS_HANDLE_JQUERY,
564
+				CoreAssetManager::JS_HANDLE_VENDOR,
565
+			)
566
+		)
567
+		->setRequiresTranslation();
568
+
569
+		$this->addStylesheet(
570
+			CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
571
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
572
+		);
573
+	}
574 574
 }
Please login to merge, or discard this patch.