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