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