Completed
Branch BUG/dont-show-archives-option-... (3feef4)
by
unknown
10:29 queued 28s
created
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +520 added lines, -520 removed lines patch added patch discarded remove patch
@@ -31,543 +31,543 @@
 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 $VID:$
47
-     */
48
-    const JS_HANDLE_REACT = 'react';
45
+	/**
46
+	 * @since $VID:$
47
+	 */
48
+	const JS_HANDLE_REACT = 'react';
49 49
 
50
-    /**
51
-     * @since $VID:$
52
-     */
53
-    const JS_HANDLE_REACT_DOM = 'react-dom';
50
+	/**
51
+	 * @since $VID:$
52
+	 */
53
+	const JS_HANDLE_REACT_DOM = 'react-dom';
54 54
 
55
-    /**
56
-     * @since $VID:$
57
-     */
58
-    const JS_HANDLE_LODASH = 'lodash';
55
+	/**
56
+	 * @since $VID:$
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-request',
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
-                'rest_route' => rest_url('ee/v4.8.36/'),
295
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
296
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
297
-                'site_url' => site_url('/'),
298
-                'admin_url' => admin_url('/'),
299
-            )
300
-        );
301
-        /** site formatting values **/
302
-        $this->registry->addData(
303
-            'site_formats',
304
-            array(
305
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
306
-            )
307
-        );
308
-        /** currency data **/
309
-        $this->registry->addData(
310
-            'currency_config',
311
-            $this->getCurrencySettings()
312
-        );
313
-        /** site timezone */
314
-        $this->registry->addData(
315
-            'default_timezone',
316
-            array(
317
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
318
-                'string' => get_option('timezone_string'),
319
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
320
-            )
321
-        );
322
-        /** site locale (user locale if user logged in) */
323
-        $this->registry->addData(
324
-            'locale',
325
-            array(
326
-                'user' => get_user_locale(),
327
-                'site' => get_locale()
328
-            )
329
-        );
330
-
331
-        $this->addJavascript(
332
-            CoreAssetManager::JS_HANDLE_CORE,
333
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
334
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
335
-        )
336
-        ->setInlineDataCallback(
337
-            function () {
338
-                wp_localize_script(
339
-                    CoreAssetManager::JS_HANDLE_CORE,
340
-                    CoreAssetManager::JS_HANDLE_I18N,
341
-                    EE_Registry::$i18n_js_strings
342
-                );
343
-            }
344
-        );
345
-    }
346
-
347
-
348
-    /**
349
-     * Registers vendor files that are bundled with a later version WP but might not be for the current version of
350
-     * WordPress in the running environment.
351
-     *
352
-     * @throws DuplicateCollectionIdentifierException
353
-     * @throws InvalidDataTypeException
354
-     * @throws InvalidEntityException
355
-     * @throws DomainException
356
-     * @since $VID:$
357
-     */
358
-    private function registerWpAssets()
359
-    {
360
-        global $wp_version;
361
-        if (version_compare($wp_version, '5.0.beta', '>=')) {
362
-            return;
363
-        }
364
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
365
-            ->setVersion('16.6.0');
366
-        $this->addVendorJavascript(
367
-            CoreAssetManager::JS_HANDLE_REACT_DOM,
368
-            array(CoreAssetManager::JS_HANDLE_REACT)
369
-        )->setVersion('16.6.0');
370
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
371
-            ->setInlineDataCallback(
372
-                function() {
373
-                    wp_add_inline_script(
374
-                        CoreAssetManager::JS_HANDLE_LODASH,
375
-                        'window.lodash = _.noConflict();'
376
-                    );
377
-                }
378
-            )
379
-            ->setVersion('4.17.11');
380
-    }
381
-
382
-
383
-    /**
384
-     * Returns configuration data for the accounting-js library.
385
-     * @since $VID:$
386
-     * @return array
387
-     */
388
-    private function getAccountingSettings() {
389
-        return array(
390
-            'currency' => array(
391
-                'symbol'    => $this->currency_config->sign,
392
-                'format'    => array(
393
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
394
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
395
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
396
-                ),
397
-                'decimal'   => $this->currency_config->dec_mrk,
398
-                'thousand'  => $this->currency_config->thsnds,
399
-                'precision' => $this->currency_config->dec_plc,
400
-            ),
401
-            'number'   => array(
402
-                'precision' => $this->currency_config->dec_plc,
403
-                'thousand'  => $this->currency_config->thsnds,
404
-                'decimal'   => $this->currency_config->dec_mrk,
405
-            ),
406
-        );
407
-    }
408
-
409
-
410
-    /**
411
-     * Returns configuration data for the js Currency VO.
412
-     * @since $VID:$
413
-     * @return array
414
-     */
415
-    private function getCurrencySettings()
416
-    {
417
-        return array(
418
-            'code' => $this->currency_config->code,
419
-            'singularLabel' => $this->currency_config->name,
420
-            'pluralLabel' => $this->currency_config->plural,
421
-            'sign' => $this->currency_config->sign,
422
-            'signB4' => $this->currency_config->sign_b4,
423
-            'decimalPlaces' => $this->currency_config->dec_plc,
424
-            'decimalMark' => $this->currency_config->dec_mrk,
425
-            'thousandsSeparator' => $this->currency_config->thsnds,
426
-        );
427
-    }
428
-
429
-
430
-    /**
431
-     * @since 4.9.62.p
432
-     * @throws DuplicateCollectionIdentifierException
433
-     * @throws InvalidDataTypeException
434
-     * @throws InvalidEntityException
435
-     */
436
-    private function loadCoreCss()
437
-    {
438
-        if ($this->template_config->enable_default_style && ! is_admin()) {
439
-            $this->addStylesheet(
440
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
441
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
442
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
443
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
444
-                array('dashicons')
445
-            );
446
-            //Load custom style sheet if available
447
-            if ($this->template_config->custom_style_sheet !== null) {
448
-                $this->addStylesheet(
449
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
450
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
451
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
452
-                );
453
-            }
454
-        }
455
-        $this->addStylesheet(
456
-            CoreAssetManager::CSS_HANDLE_COMPONENTS,
457
-            $this->registry->getCssUrl(
458
-                $this->domain->assetNamespace(),
459
-                'components'
460
-            )
461
-        );
462
-    }
463
-
464
-
465
-    /**
466
-     * jQuery Validate for form validation
467
-     *
468
-     * @since 4.9.62.p
469
-     * @throws DomainException
470
-     * @throws DuplicateCollectionIdentifierException
471
-     * @throws InvalidDataTypeException
472
-     * @throws InvalidEntityException
473
-     */
474
-    private function loadJqueryValidate()
475
-    {
476
-        $this->addJavascript(
477
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
478
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
479
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
480
-        )
481
-        ->setVersion('1.15.0');
482
-
483
-        $this->addJavascript(
484
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
485
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
486
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
487
-        )
488
-        ->setVersion('1.15.0');
489
-    }
490
-
491
-
492
-    /**
493
-     * accounting.js for performing client-side calculations
494
-     *
495
-     * @since 4.9.62.p
496
-     * @throws DomainException
497
-     * @throws DuplicateCollectionIdentifierException
498
-     * @throws InvalidDataTypeException
499
-     * @throws InvalidEntityException
500
-     */
501
-    private function loadAccountingJs()
502
-    {
503
-        //accounting.js library
504
-        // @link http://josscrowcroft.github.io/accounting.js/
505
-        $this->addJavascript(
506
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
507
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
508
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
509
-        )
510
-        ->setVersion('0.3.2');
511
-
512
-        $this->addJavascript(
513
-            CoreAssetManager::JS_HANDLE_ACCOUNTING,
514
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
515
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
516
-        )
517
-        ->setInlineDataCallback(
518
-            function () {
519
-                 wp_localize_script(
520
-                     CoreAssetManager::JS_HANDLE_ACCOUNTING,
521
-                     'EE_ACCOUNTING_CFG',
522
-                     $this->getAccountingSettings()
523
-                 );
524
-            }
525
-        )
526
-        ->setVersion();
527
-    }
528
-
529
-
530
-    /**
531
-     * registers assets for cleaning your ears
532
-     *
533
-     * @param JavascriptAsset $script
534
-     */
535
-    public function loadQtipJs(JavascriptAsset $script)
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 (
540
-            $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
541
-            && apply_filters('FHEE_load_qtip', false)
542
-        ) {
543
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
544
-        }
545
-    }
546
-
547
-
548
-    /**
549
-     * assets that are used in the WordPress admin
550
-     *
551
-     * @since 4.9.62.p
552
-     * @throws DuplicateCollectionIdentifierException
553
-     * @throws InvalidDataTypeException
554
-     * @throws InvalidEntityException
555
-     */
556
-    private function registerAdminAssets()
557
-    {
558
-        $this->addJavascript(
559
-            CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
560
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
561
-            array(
562
-                CoreAssetManager::JS_HANDLE_JQUERY,
563
-                CoreAssetManager::JS_HANDLE_VENDOR,
564
-            )
565
-        )
566
-        ->setRequiresTranslation();
567
-
568
-        $this->addStylesheet(
569
-            CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
570
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
571
-        );
572
-    }
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-request',
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
+				'rest_route' => rest_url('ee/v4.8.36/'),
295
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
296
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
297
+				'site_url' => site_url('/'),
298
+				'admin_url' => admin_url('/'),
299
+			)
300
+		);
301
+		/** site formatting values **/
302
+		$this->registry->addData(
303
+			'site_formats',
304
+			array(
305
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
306
+			)
307
+		);
308
+		/** currency data **/
309
+		$this->registry->addData(
310
+			'currency_config',
311
+			$this->getCurrencySettings()
312
+		);
313
+		/** site timezone */
314
+		$this->registry->addData(
315
+			'default_timezone',
316
+			array(
317
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
318
+				'string' => get_option('timezone_string'),
319
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
320
+			)
321
+		);
322
+		/** site locale (user locale if user logged in) */
323
+		$this->registry->addData(
324
+			'locale',
325
+			array(
326
+				'user' => get_user_locale(),
327
+				'site' => get_locale()
328
+			)
329
+		);
330
+
331
+		$this->addJavascript(
332
+			CoreAssetManager::JS_HANDLE_CORE,
333
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
334
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
335
+		)
336
+		->setInlineDataCallback(
337
+			function () {
338
+				wp_localize_script(
339
+					CoreAssetManager::JS_HANDLE_CORE,
340
+					CoreAssetManager::JS_HANDLE_I18N,
341
+					EE_Registry::$i18n_js_strings
342
+				);
343
+			}
344
+		);
345
+	}
346
+
347
+
348
+	/**
349
+	 * Registers vendor files that are bundled with a later version WP but might not be for the current version of
350
+	 * WordPress in the running environment.
351
+	 *
352
+	 * @throws DuplicateCollectionIdentifierException
353
+	 * @throws InvalidDataTypeException
354
+	 * @throws InvalidEntityException
355
+	 * @throws DomainException
356
+	 * @since $VID:$
357
+	 */
358
+	private function registerWpAssets()
359
+	{
360
+		global $wp_version;
361
+		if (version_compare($wp_version, '5.0.beta', '>=')) {
362
+			return;
363
+		}
364
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
365
+			->setVersion('16.6.0');
366
+		$this->addVendorJavascript(
367
+			CoreAssetManager::JS_HANDLE_REACT_DOM,
368
+			array(CoreAssetManager::JS_HANDLE_REACT)
369
+		)->setVersion('16.6.0');
370
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
371
+			->setInlineDataCallback(
372
+				function() {
373
+					wp_add_inline_script(
374
+						CoreAssetManager::JS_HANDLE_LODASH,
375
+						'window.lodash = _.noConflict();'
376
+					);
377
+				}
378
+			)
379
+			->setVersion('4.17.11');
380
+	}
381
+
382
+
383
+	/**
384
+	 * Returns configuration data for the accounting-js library.
385
+	 * @since $VID:$
386
+	 * @return array
387
+	 */
388
+	private function getAccountingSettings() {
389
+		return array(
390
+			'currency' => array(
391
+				'symbol'    => $this->currency_config->sign,
392
+				'format'    => array(
393
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
394
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
395
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
396
+				),
397
+				'decimal'   => $this->currency_config->dec_mrk,
398
+				'thousand'  => $this->currency_config->thsnds,
399
+				'precision' => $this->currency_config->dec_plc,
400
+			),
401
+			'number'   => array(
402
+				'precision' => $this->currency_config->dec_plc,
403
+				'thousand'  => $this->currency_config->thsnds,
404
+				'decimal'   => $this->currency_config->dec_mrk,
405
+			),
406
+		);
407
+	}
408
+
409
+
410
+	/**
411
+	 * Returns configuration data for the js Currency VO.
412
+	 * @since $VID:$
413
+	 * @return array
414
+	 */
415
+	private function getCurrencySettings()
416
+	{
417
+		return array(
418
+			'code' => $this->currency_config->code,
419
+			'singularLabel' => $this->currency_config->name,
420
+			'pluralLabel' => $this->currency_config->plural,
421
+			'sign' => $this->currency_config->sign,
422
+			'signB4' => $this->currency_config->sign_b4,
423
+			'decimalPlaces' => $this->currency_config->dec_plc,
424
+			'decimalMark' => $this->currency_config->dec_mrk,
425
+			'thousandsSeparator' => $this->currency_config->thsnds,
426
+		);
427
+	}
428
+
429
+
430
+	/**
431
+	 * @since 4.9.62.p
432
+	 * @throws DuplicateCollectionIdentifierException
433
+	 * @throws InvalidDataTypeException
434
+	 * @throws InvalidEntityException
435
+	 */
436
+	private function loadCoreCss()
437
+	{
438
+		if ($this->template_config->enable_default_style && ! is_admin()) {
439
+			$this->addStylesheet(
440
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
441
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
442
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
443
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
444
+				array('dashicons')
445
+			);
446
+			//Load custom style sheet if available
447
+			if ($this->template_config->custom_style_sheet !== null) {
448
+				$this->addStylesheet(
449
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
450
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
451
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
452
+				);
453
+			}
454
+		}
455
+		$this->addStylesheet(
456
+			CoreAssetManager::CSS_HANDLE_COMPONENTS,
457
+			$this->registry->getCssUrl(
458
+				$this->domain->assetNamespace(),
459
+				'components'
460
+			)
461
+		);
462
+	}
463
+
464
+
465
+	/**
466
+	 * jQuery Validate for form validation
467
+	 *
468
+	 * @since 4.9.62.p
469
+	 * @throws DomainException
470
+	 * @throws DuplicateCollectionIdentifierException
471
+	 * @throws InvalidDataTypeException
472
+	 * @throws InvalidEntityException
473
+	 */
474
+	private function loadJqueryValidate()
475
+	{
476
+		$this->addJavascript(
477
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
478
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
479
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
480
+		)
481
+		->setVersion('1.15.0');
482
+
483
+		$this->addJavascript(
484
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
485
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
486
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
487
+		)
488
+		->setVersion('1.15.0');
489
+	}
490
+
491
+
492
+	/**
493
+	 * accounting.js for performing client-side calculations
494
+	 *
495
+	 * @since 4.9.62.p
496
+	 * @throws DomainException
497
+	 * @throws DuplicateCollectionIdentifierException
498
+	 * @throws InvalidDataTypeException
499
+	 * @throws InvalidEntityException
500
+	 */
501
+	private function loadAccountingJs()
502
+	{
503
+		//accounting.js library
504
+		// @link http://josscrowcroft.github.io/accounting.js/
505
+		$this->addJavascript(
506
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
507
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
508
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
509
+		)
510
+		->setVersion('0.3.2');
511
+
512
+		$this->addJavascript(
513
+			CoreAssetManager::JS_HANDLE_ACCOUNTING,
514
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
515
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
516
+		)
517
+		->setInlineDataCallback(
518
+			function () {
519
+				 wp_localize_script(
520
+					 CoreAssetManager::JS_HANDLE_ACCOUNTING,
521
+					 'EE_ACCOUNTING_CFG',
522
+					 $this->getAccountingSettings()
523
+				 );
524
+			}
525
+		)
526
+		->setVersion();
527
+	}
528
+
529
+
530
+	/**
531
+	 * registers assets for cleaning your ears
532
+	 *
533
+	 * @param JavascriptAsset $script
534
+	 */
535
+	public function loadQtipJs(JavascriptAsset $script)
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 (
540
+			$script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
541
+			&& apply_filters('FHEE_load_qtip', false)
542
+		) {
543
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
544
+		}
545
+	}
546
+
547
+
548
+	/**
549
+	 * assets that are used in the WordPress admin
550
+	 *
551
+	 * @since 4.9.62.p
552
+	 * @throws DuplicateCollectionIdentifierException
553
+	 * @throws InvalidDataTypeException
554
+	 * @throws InvalidEntityException
555
+	 */
556
+	private function registerAdminAssets()
557
+	{
558
+		$this->addJavascript(
559
+			CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
560
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
561
+			array(
562
+				CoreAssetManager::JS_HANDLE_JQUERY,
563
+				CoreAssetManager::JS_HANDLE_VENDOR,
564
+			)
565
+		)
566
+		->setRequiresTranslation();
567
+
568
+		$this->addStylesheet(
569
+			CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
570
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
571
+		);
572
+	}
573 573
 }
Please login to merge, or discard this patch.