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