@@ -22,198 +22,198 @@ |
||
22 | 22 | class EE_Billing_Info_Form extends EE_Form_Section_Proper |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * The payment method this billing form is for |
|
27 | - * @var EE_Payment_Method |
|
28 | - */ |
|
29 | - protected $_pm_instance; |
|
25 | + /** |
|
26 | + * The payment method this billing form is for |
|
27 | + * @var EE_Payment_Method |
|
28 | + */ |
|
29 | + protected $_pm_instance; |
|
30 | 30 | |
31 | - /* |
|
31 | + /* |
|
32 | 32 | * Please note that there is no guarantee there's a transaction on the billing form (eg if the form were |
33 | 33 | * initialized in the admin to just display previous answers.) So this will often be `null`. |
34 | 34 | * @var EE_Transaction|null |
35 | 35 | */ |
36 | - protected $transaction; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var EventEspresso\core\services\assets\AssetCollection $assets |
|
40 | - */ |
|
41 | - protected $assets; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EventEspresso\core\domain\Domain $domain |
|
45 | - */ |
|
46 | - protected $domain; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var EventEspresso\core\services\assets\Registry $registry |
|
50 | - */ |
|
51 | - protected $registry; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param EE_Payment_Method $payment_method |
|
56 | - * @param array $options_array @see EE_Form_Section_Proper::__construct() |
|
57 | - * @throws EE_Error |
|
58 | - * @throws InvalidArgumentException |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - * @throws InvalidInterfaceException |
|
61 | - */ |
|
62 | - public function __construct(EE_Payment_Method $payment_method, $options_array = array()) |
|
63 | - { |
|
64 | - $this->_pm_instance = $payment_method; |
|
65 | - $this->_layout_strategy = new EE_Div_Per_Section_Layout(); |
|
66 | - if(isset($options_array['transaction']) && $options_array['transaction'] instanceof EE_Transaction){ |
|
67 | - $this->transaction = $options_array['transaction']; |
|
68 | - } |
|
69 | - parent::__construct($options_array); |
|
70 | - // In the future this feature may be available to other payment methods, but for now it's only PayPal Pro. |
|
71 | - if ($this->_pm_instance->type() === 'Paypal_Pro') { |
|
72 | - add_action('wp_enqueue_scripts', array($this, 'registerCardinalCommerceJs'), 2); |
|
73 | - add_action('wp_enqueue_scripts', array($this, 'enqueueCardinalCommerceJs'), 10); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Sets the payment method for this billing form |
|
81 | - * @param EE_Payment_Method $payment_method |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function set_payment_method(EE_Payment_Method $payment_method) |
|
85 | - { |
|
86 | - $this->_pm_instance = $payment_method; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns the instance of the payment method this billing form is for |
|
93 | - * @return EE_Payment_Method |
|
94 | - */ |
|
95 | - public function payment_method() |
|
96 | - { |
|
97 | - return $this->_pm_instance; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * payment_fields_autofilled_notice_html |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function payment_fields_autofilled_notice_html() |
|
107 | - { |
|
108 | - return new EE_Form_Section_HTML( |
|
109 | - EEH_HTML::p( |
|
110 | - apply_filters('FHEE__EE_Billing_Info_Form__payment_fields_autofilled_notice_html_text', __('Payment fields have been autofilled because you are in debug mode', 'event_espresso')), |
|
111 | - '', |
|
112 | - 'important-notice' |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function html_class() |
|
123 | - { |
|
124 | - return ! empty($this->_html_class) ? $this->_html_class . ' ee-billing-form' : 'ee-billing-form'; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * registers JS for Cardinal Commerce to do 3D Secure Authorization. |
|
129 | - * |
|
130 | - * @return void |
|
131 | - * @throws InvalidArgumentException |
|
132 | - * @throws InvalidDataTypeException |
|
133 | - * @throws InvalidInterfaceException |
|
134 | - * @throws DuplicateCollectionIdentifierException |
|
135 | - * @since $VID:$ |
|
136 | - */ |
|
137 | - public function registerCardinalCommerceJs() |
|
138 | - { |
|
139 | - /** @var EventEspresso\core\services\assets\AssetCollection $assets */ |
|
140 | - $this->assets = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\assets\AssetCollection'); |
|
141 | - /** @var EventEspresso\core\services\assets\Registry $registry */ |
|
142 | - $this->registry = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\assets\Registry'); |
|
143 | - /** @var EventEspresso\core\domain\Domain $domain */ |
|
144 | - $this->domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
145 | - |
|
146 | - $asset_namespace = $this->domain->assetNamespace(); |
|
147 | - |
|
148 | - $songbird_domain = $this->_pm_instance->debug_mode() |
|
149 | - ? 'songbirdstag.cardinalcommerce.com' |
|
150 | - : 'songbird.cardinalcommerce.com'; |
|
151 | - |
|
152 | - $cardinal_commerce_songbird = 'ee-cardinal-commerce-songbird'; |
|
153 | - $this->assets->add( |
|
154 | - new JavascriptAsset( |
|
155 | - $cardinal_commerce_songbird, |
|
156 | - "https://{$songbird_domain}/edge/v1/songbird.js", |
|
157 | - $this->registry->getJsDependencies( |
|
158 | - $asset_namespace, |
|
159 | - $cardinal_commerce_songbird |
|
160 | - ), |
|
161 | - true, |
|
162 | - $this->domain |
|
163 | - ), |
|
164 | - $cardinal_commerce_songbird |
|
165 | - ); |
|
166 | - |
|
167 | - $ee_pm_cardinal_commerce = 'eventespresso-payment-methods-cardinal-commerce'; |
|
168 | - $this->assets->add( |
|
169 | - new JavascriptAsset( |
|
170 | - $ee_pm_cardinal_commerce, |
|
171 | - $this->registry->getJsUrl( |
|
172 | - $asset_namespace, |
|
173 | - $ee_pm_cardinal_commerce |
|
174 | - ), |
|
175 | - array_merge( |
|
176 | - $this->registry->getJsDependencies( |
|
177 | - $asset_namespace, |
|
178 | - $ee_pm_cardinal_commerce |
|
179 | - ), |
|
180 | - [ |
|
181 | - $cardinal_commerce_songbird, |
|
182 | - CoreAssetManager::JS_HANDLE_CORE, |
|
183 | - CoreAssetManager::JS_HANDLE_JQUERY, |
|
184 | - 'single_page_checkout', |
|
185 | - CoreAssetManager::JS_HANDLE_JS_CORE, |
|
186 | - ] |
|
187 | - ), |
|
188 | - true, |
|
189 | - $this->domain |
|
190 | - ), |
|
191 | - $ee_pm_cardinal_commerce |
|
192 | - ); |
|
193 | - |
|
194 | - $cruise_jwt_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\payment_methods\cardinal_cruise\CardinalCruiseJwtFactory'); |
|
195 | - |
|
196 | - $this->registry->addData( |
|
197 | - 'cardinalCommerce', |
|
198 | - [ |
|
199 | - 'data' => [ |
|
200 | - 'slug' => $this->_pm_instance->slug(), |
|
201 | - 'jwt' => $cruise_jwt_factory->generateCruiseJwt($this->transaction) |
|
202 | - ], |
|
203 | - 'translations' => [ |
|
204 | - 'no_SPCO_error' => esc_html__('It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', 'event_espresso'), |
|
205 | - 'no_cardinal_error' => esc_html__('It appears the Cardinal Commerce Songbird.js was not loaded properly! Please refresh the page and try again or contact support.', 'event_espresso'), |
|
206 | - 'invalid_response_from_cardinal' => esc_html__('Cardinal Commerce did not send a valid response. Please retry or contact the site admin.', 'event_espresso') |
|
207 | - ] |
|
208 | - ] |
|
209 | - ); |
|
210 | - } |
|
211 | - |
|
212 | - public function enqueueCardinalCommerceJs() |
|
213 | - { |
|
214 | - wp_enqueue_script('ee-cardinal-commerce-songbird'); |
|
215 | - wp_enqueue_script('eventespresso-payment-methods-cardinal-commerce'); |
|
216 | - } |
|
36 | + protected $transaction; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var EventEspresso\core\services\assets\AssetCollection $assets |
|
40 | + */ |
|
41 | + protected $assets; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EventEspresso\core\domain\Domain $domain |
|
45 | + */ |
|
46 | + protected $domain; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var EventEspresso\core\services\assets\Registry $registry |
|
50 | + */ |
|
51 | + protected $registry; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param EE_Payment_Method $payment_method |
|
56 | + * @param array $options_array @see EE_Form_Section_Proper::__construct() |
|
57 | + * @throws EE_Error |
|
58 | + * @throws InvalidArgumentException |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + * @throws InvalidInterfaceException |
|
61 | + */ |
|
62 | + public function __construct(EE_Payment_Method $payment_method, $options_array = array()) |
|
63 | + { |
|
64 | + $this->_pm_instance = $payment_method; |
|
65 | + $this->_layout_strategy = new EE_Div_Per_Section_Layout(); |
|
66 | + if(isset($options_array['transaction']) && $options_array['transaction'] instanceof EE_Transaction){ |
|
67 | + $this->transaction = $options_array['transaction']; |
|
68 | + } |
|
69 | + parent::__construct($options_array); |
|
70 | + // In the future this feature may be available to other payment methods, but for now it's only PayPal Pro. |
|
71 | + if ($this->_pm_instance->type() === 'Paypal_Pro') { |
|
72 | + add_action('wp_enqueue_scripts', array($this, 'registerCardinalCommerceJs'), 2); |
|
73 | + add_action('wp_enqueue_scripts', array($this, 'enqueueCardinalCommerceJs'), 10); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Sets the payment method for this billing form |
|
81 | + * @param EE_Payment_Method $payment_method |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function set_payment_method(EE_Payment_Method $payment_method) |
|
85 | + { |
|
86 | + $this->_pm_instance = $payment_method; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns the instance of the payment method this billing form is for |
|
93 | + * @return EE_Payment_Method |
|
94 | + */ |
|
95 | + public function payment_method() |
|
96 | + { |
|
97 | + return $this->_pm_instance; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * payment_fields_autofilled_notice_html |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function payment_fields_autofilled_notice_html() |
|
107 | + { |
|
108 | + return new EE_Form_Section_HTML( |
|
109 | + EEH_HTML::p( |
|
110 | + apply_filters('FHEE__EE_Billing_Info_Form__payment_fields_autofilled_notice_html_text', __('Payment fields have been autofilled because you are in debug mode', 'event_espresso')), |
|
111 | + '', |
|
112 | + 'important-notice' |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function html_class() |
|
123 | + { |
|
124 | + return ! empty($this->_html_class) ? $this->_html_class . ' ee-billing-form' : 'ee-billing-form'; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * registers JS for Cardinal Commerce to do 3D Secure Authorization. |
|
129 | + * |
|
130 | + * @return void |
|
131 | + * @throws InvalidArgumentException |
|
132 | + * @throws InvalidDataTypeException |
|
133 | + * @throws InvalidInterfaceException |
|
134 | + * @throws DuplicateCollectionIdentifierException |
|
135 | + * @since $VID:$ |
|
136 | + */ |
|
137 | + public function registerCardinalCommerceJs() |
|
138 | + { |
|
139 | + /** @var EventEspresso\core\services\assets\AssetCollection $assets */ |
|
140 | + $this->assets = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\assets\AssetCollection'); |
|
141 | + /** @var EventEspresso\core\services\assets\Registry $registry */ |
|
142 | + $this->registry = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\assets\Registry'); |
|
143 | + /** @var EventEspresso\core\domain\Domain $domain */ |
|
144 | + $this->domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
145 | + |
|
146 | + $asset_namespace = $this->domain->assetNamespace(); |
|
147 | + |
|
148 | + $songbird_domain = $this->_pm_instance->debug_mode() |
|
149 | + ? 'songbirdstag.cardinalcommerce.com' |
|
150 | + : 'songbird.cardinalcommerce.com'; |
|
151 | + |
|
152 | + $cardinal_commerce_songbird = 'ee-cardinal-commerce-songbird'; |
|
153 | + $this->assets->add( |
|
154 | + new JavascriptAsset( |
|
155 | + $cardinal_commerce_songbird, |
|
156 | + "https://{$songbird_domain}/edge/v1/songbird.js", |
|
157 | + $this->registry->getJsDependencies( |
|
158 | + $asset_namespace, |
|
159 | + $cardinal_commerce_songbird |
|
160 | + ), |
|
161 | + true, |
|
162 | + $this->domain |
|
163 | + ), |
|
164 | + $cardinal_commerce_songbird |
|
165 | + ); |
|
166 | + |
|
167 | + $ee_pm_cardinal_commerce = 'eventespresso-payment-methods-cardinal-commerce'; |
|
168 | + $this->assets->add( |
|
169 | + new JavascriptAsset( |
|
170 | + $ee_pm_cardinal_commerce, |
|
171 | + $this->registry->getJsUrl( |
|
172 | + $asset_namespace, |
|
173 | + $ee_pm_cardinal_commerce |
|
174 | + ), |
|
175 | + array_merge( |
|
176 | + $this->registry->getJsDependencies( |
|
177 | + $asset_namespace, |
|
178 | + $ee_pm_cardinal_commerce |
|
179 | + ), |
|
180 | + [ |
|
181 | + $cardinal_commerce_songbird, |
|
182 | + CoreAssetManager::JS_HANDLE_CORE, |
|
183 | + CoreAssetManager::JS_HANDLE_JQUERY, |
|
184 | + 'single_page_checkout', |
|
185 | + CoreAssetManager::JS_HANDLE_JS_CORE, |
|
186 | + ] |
|
187 | + ), |
|
188 | + true, |
|
189 | + $this->domain |
|
190 | + ), |
|
191 | + $ee_pm_cardinal_commerce |
|
192 | + ); |
|
193 | + |
|
194 | + $cruise_jwt_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\payment_methods\cardinal_cruise\CardinalCruiseJwtFactory'); |
|
195 | + |
|
196 | + $this->registry->addData( |
|
197 | + 'cardinalCommerce', |
|
198 | + [ |
|
199 | + 'data' => [ |
|
200 | + 'slug' => $this->_pm_instance->slug(), |
|
201 | + 'jwt' => $cruise_jwt_factory->generateCruiseJwt($this->transaction) |
|
202 | + ], |
|
203 | + 'translations' => [ |
|
204 | + 'no_SPCO_error' => esc_html__('It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', 'event_espresso'), |
|
205 | + 'no_cardinal_error' => esc_html__('It appears the Cardinal Commerce Songbird.js was not loaded properly! Please refresh the page and try again or contact support.', 'event_espresso'), |
|
206 | + 'invalid_response_from_cardinal' => esc_html__('Cardinal Commerce did not send a valid response. Please retry or contact the site admin.', 'event_espresso') |
|
207 | + ] |
|
208 | + ] |
|
209 | + ); |
|
210 | + } |
|
211 | + |
|
212 | + public function enqueueCardinalCommerceJs() |
|
213 | + { |
|
214 | + wp_enqueue_script('ee-cardinal-commerce-songbird'); |
|
215 | + wp_enqueue_script('eventespresso-payment-methods-cardinal-commerce'); |
|
216 | + } |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // End of file EE_Billing_Info_Form.form.php |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | $this->_pm_instance = $payment_method; |
65 | 65 | $this->_layout_strategy = new EE_Div_Per_Section_Layout(); |
66 | - if(isset($options_array['transaction']) && $options_array['transaction'] instanceof EE_Transaction){ |
|
66 | + if (isset($options_array['transaction']) && $options_array['transaction'] instanceof EE_Transaction) { |
|
67 | 67 | $this->transaction = $options_array['transaction']; |
68 | 68 | } |
69 | 69 | parent::__construct($options_array); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function html_class() |
123 | 123 | { |
124 | - return ! empty($this->_html_class) ? $this->_html_class . ' ee-billing-form' : 'ee-billing-form'; |
|
124 | + return ! empty($this->_html_class) ? $this->_html_class.' ee-billing-form' : 'ee-billing-form'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -28,744 +28,744 @@ |
||
28 | 28 | class Registry |
29 | 29 | { |
30 | 30 | |
31 | - const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var AssetCollection $assets |
|
35 | - */ |
|
36 | - protected $assets; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var I18nRegistry |
|
40 | - */ |
|
41 | - private $i18n_registry; |
|
42 | - |
|
43 | - /** |
|
44 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $jsdata = array(); |
|
49 | - |
|
50 | - /** |
|
51 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
52 | - * page source. |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - private $script_handles_with_data = array(); |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Holds the manifest data obtained from registered manifest files. |
|
61 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
62 | - * Shape of this array is: |
|
63 | - * array( |
|
64 | - * 'some_namespace_slug' => array( |
|
65 | - * 'some_chunk_name' => array( |
|
66 | - * 'js' => 'filename.js' |
|
67 | - * 'css' => 'filename.js' |
|
68 | - * ), |
|
69 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
70 | - * ) |
|
71 | - * ) |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - private $manifest_data = array(); |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Holds any dependency data obtained from registered dependency map json. |
|
80 | - * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config. |
|
81 | - * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin |
|
82 | - * |
|
83 | - * @var array |
|
84 | - */ |
|
85 | - private $dependencies_data = []; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our |
|
90 | - * build process. Currently the dependency export process in webpack does not consider css imports, so we derive |
|
91 | - * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that |
|
92 | - * are used for both js and css. |
|
93 | - * @var array |
|
94 | - */ |
|
95 | - private $wp_css_handle_dependencies = [ |
|
96 | - 'wp-components', |
|
97 | - 'wp-block-editor', |
|
98 | - 'wp-block-library', |
|
99 | - 'wp-edit-post', |
|
100 | - 'wp-edit-widgets', |
|
101 | - 'wp-editor', |
|
102 | - 'wp-format-library', |
|
103 | - 'wp-list-reusable-blocks', |
|
104 | - 'wp-nux', |
|
105 | - ]; |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Registry constructor. |
|
110 | - * Hooking into WP actions for script registry. |
|
111 | - * |
|
112 | - * @param AssetCollection $assets |
|
113 | - * @param I18nRegistry $i18n_registry |
|
114 | - * @throws InvalidArgumentException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidInterfaceException |
|
117 | - */ |
|
118 | - public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
119 | - { |
|
120 | - $this->assets = $assets; |
|
121 | - $this->i18n_registry = $i18n_registry; |
|
122 | - add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
123 | - add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
124 | - add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
125 | - add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
126 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
127 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
128 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
129 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
135 | - * translation handling. |
|
136 | - * |
|
137 | - * @return I18nRegistry |
|
138 | - */ |
|
139 | - public function getI18nRegistry() |
|
140 | - { |
|
141 | - return $this->i18n_registry; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Callback for the wp_enqueue_scripts actions used to register assets. |
|
147 | - * |
|
148 | - * @since 4.9.62.p |
|
149 | - * @throws Exception |
|
150 | - */ |
|
151 | - public function registerScriptsAndStyles() |
|
152 | - { |
|
153 | - try { |
|
154 | - $this->registerScripts($this->assets->getJavascriptAssets()); |
|
155 | - $this->registerStyles($this->assets->getStylesheetAssets()); |
|
156 | - } catch (Exception $exception) { |
|
157 | - new ExceptionStackTraceDisplay($exception); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Registers JS assets with WP core |
|
164 | - * |
|
165 | - * @param JavascriptAsset[] $scripts |
|
166 | - * @throws AssetRegistrationException |
|
167 | - * @throws InvalidDataTypeException |
|
168 | - * @throws DomainException |
|
169 | - * @since 4.9.62.p |
|
170 | - */ |
|
171 | - public function registerScripts(array $scripts) |
|
172 | - { |
|
173 | - foreach ($scripts as $script) { |
|
174 | - // skip to next script if this has already been done |
|
175 | - if ($script->isRegistered()) { |
|
176 | - continue; |
|
177 | - } |
|
178 | - do_action( |
|
179 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
180 | - $script |
|
181 | - ); |
|
182 | - $registered = wp_register_script( |
|
183 | - $script->handle(), |
|
184 | - $script->source(), |
|
185 | - $script->dependencies(), |
|
186 | - $script->version(), |
|
187 | - $script->loadInFooter() |
|
188 | - ); |
|
189 | - if (! $registered && $this->debug()) { |
|
190 | - throw new AssetRegistrationException($script->handle()); |
|
191 | - } |
|
192 | - $script->setRegistered($registered); |
|
193 | - if ($script->requiresTranslation()) { |
|
194 | - $this->registerTranslation($script->handle()); |
|
195 | - } |
|
196 | - do_action( |
|
197 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
198 | - $script |
|
199 | - ); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Registers CSS assets with WP core |
|
206 | - * |
|
207 | - * @param StylesheetAsset[] $styles |
|
208 | - * @throws InvalidDataTypeException*@throws \DomainException |
|
209 | - * @throws DomainException |
|
210 | - * @since 4.9.62.p |
|
211 | - */ |
|
212 | - public function registerStyles(array $styles) |
|
213 | - { |
|
214 | - foreach ($styles as $style) { |
|
215 | - // skip to next style if this has already been done |
|
216 | - if ($style->isRegistered()) { |
|
217 | - continue; |
|
218 | - } |
|
219 | - do_action( |
|
220 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
221 | - $style |
|
222 | - ); |
|
223 | - wp_register_style( |
|
224 | - $style->handle(), |
|
225 | - $style->source(), |
|
226 | - $style->dependencies(), |
|
227 | - $style->version(), |
|
228 | - $style->media() |
|
229 | - ); |
|
230 | - $style->setRegistered(); |
|
231 | - do_action( |
|
232 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
233 | - $style |
|
234 | - ); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Call back for the script print in frontend and backend. |
|
241 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
242 | - * |
|
243 | - * @since 4.9.31.rc.015 |
|
244 | - */ |
|
245 | - public function enqueueData() |
|
246 | - { |
|
247 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
248 | - wp_add_inline_script( |
|
249 | - 'eejs-core', |
|
250 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
251 | - 'before' |
|
252 | - ); |
|
253 | - $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
254 | - foreach ($scripts as $script) { |
|
255 | - $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
256 | - if ($script->hasInlineDataCallback()) { |
|
257 | - $localize = $script->inlineDataCallback(); |
|
258 | - $localize(); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Used to add data to eejs.data object. |
|
266 | - * Note: Overriding existing data is not allowed. |
|
267 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
268 | - * If the data you add is something like this: |
|
269 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
270 | - * It will be exposed in the page source as: |
|
271 | - * eejs.data.my_plugin_data.foo == gar |
|
272 | - * |
|
273 | - * @param string $key Key used to access your data |
|
274 | - * @param string|array $value Value to attach to key |
|
275 | - * @throws InvalidArgumentException |
|
276 | - */ |
|
277 | - public function addData($key, $value) |
|
278 | - { |
|
279 | - if ($this->verifyDataNotExisting($key)) { |
|
280 | - $this->jsdata[ $key ] = $value; |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
287 | - * elements in an array. |
|
288 | - * |
|
289 | - * When you use this method, the value you include will be merged with the array on $key. |
|
290 | - * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript |
|
291 | - * object like this, eejs.data.test = [ my_data, |
|
292 | - * ] |
|
293 | - * If there has already been a scalar value attached to the data object given key (via addData for instance), then |
|
294 | - * this will throw an exception. |
|
295 | - * |
|
296 | - * Caution: Only add data using this method if you are okay with the potential for additional data added on the same |
|
297 | - * key potentially overriding the existing data on merge (specifically with associative arrays). |
|
298 | - * |
|
299 | - * @param string $key Key to attach data to. |
|
300 | - * @param string|array $value Value being registered. |
|
301 | - * @throws InvalidArgumentException |
|
302 | - */ |
|
303 | - public function pushData($key, $value) |
|
304 | - { |
|
305 | - if (isset($this->jsdata[ $key ]) |
|
306 | - && ! is_array($this->jsdata[ $key ]) |
|
307 | - ) { |
|
308 | - if (! $this->debug()) { |
|
309 | - return; |
|
310 | - } |
|
311 | - throw new InvalidArgumentException( |
|
312 | - sprintf( |
|
313 | - __( |
|
314 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
31 | + const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var AssetCollection $assets |
|
35 | + */ |
|
36 | + protected $assets; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var I18nRegistry |
|
40 | + */ |
|
41 | + private $i18n_registry; |
|
42 | + |
|
43 | + /** |
|
44 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $jsdata = array(); |
|
49 | + |
|
50 | + /** |
|
51 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
52 | + * page source. |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + private $script_handles_with_data = array(); |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Holds the manifest data obtained from registered manifest files. |
|
61 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
62 | + * Shape of this array is: |
|
63 | + * array( |
|
64 | + * 'some_namespace_slug' => array( |
|
65 | + * 'some_chunk_name' => array( |
|
66 | + * 'js' => 'filename.js' |
|
67 | + * 'css' => 'filename.js' |
|
68 | + * ), |
|
69 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
70 | + * ) |
|
71 | + * ) |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + private $manifest_data = array(); |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Holds any dependency data obtained from registered dependency map json. |
|
80 | + * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config. |
|
81 | + * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin |
|
82 | + * |
|
83 | + * @var array |
|
84 | + */ |
|
85 | + private $dependencies_data = []; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our |
|
90 | + * build process. Currently the dependency export process in webpack does not consider css imports, so we derive |
|
91 | + * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that |
|
92 | + * are used for both js and css. |
|
93 | + * @var array |
|
94 | + */ |
|
95 | + private $wp_css_handle_dependencies = [ |
|
96 | + 'wp-components', |
|
97 | + 'wp-block-editor', |
|
98 | + 'wp-block-library', |
|
99 | + 'wp-edit-post', |
|
100 | + 'wp-edit-widgets', |
|
101 | + 'wp-editor', |
|
102 | + 'wp-format-library', |
|
103 | + 'wp-list-reusable-blocks', |
|
104 | + 'wp-nux', |
|
105 | + ]; |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Registry constructor. |
|
110 | + * Hooking into WP actions for script registry. |
|
111 | + * |
|
112 | + * @param AssetCollection $assets |
|
113 | + * @param I18nRegistry $i18n_registry |
|
114 | + * @throws InvalidArgumentException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidInterfaceException |
|
117 | + */ |
|
118 | + public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
119 | + { |
|
120 | + $this->assets = $assets; |
|
121 | + $this->i18n_registry = $i18n_registry; |
|
122 | + add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
123 | + add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
124 | + add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
125 | + add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
126 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
127 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
128 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
129 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
135 | + * translation handling. |
|
136 | + * |
|
137 | + * @return I18nRegistry |
|
138 | + */ |
|
139 | + public function getI18nRegistry() |
|
140 | + { |
|
141 | + return $this->i18n_registry; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Callback for the wp_enqueue_scripts actions used to register assets. |
|
147 | + * |
|
148 | + * @since 4.9.62.p |
|
149 | + * @throws Exception |
|
150 | + */ |
|
151 | + public function registerScriptsAndStyles() |
|
152 | + { |
|
153 | + try { |
|
154 | + $this->registerScripts($this->assets->getJavascriptAssets()); |
|
155 | + $this->registerStyles($this->assets->getStylesheetAssets()); |
|
156 | + } catch (Exception $exception) { |
|
157 | + new ExceptionStackTraceDisplay($exception); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Registers JS assets with WP core |
|
164 | + * |
|
165 | + * @param JavascriptAsset[] $scripts |
|
166 | + * @throws AssetRegistrationException |
|
167 | + * @throws InvalidDataTypeException |
|
168 | + * @throws DomainException |
|
169 | + * @since 4.9.62.p |
|
170 | + */ |
|
171 | + public function registerScripts(array $scripts) |
|
172 | + { |
|
173 | + foreach ($scripts as $script) { |
|
174 | + // skip to next script if this has already been done |
|
175 | + if ($script->isRegistered()) { |
|
176 | + continue; |
|
177 | + } |
|
178 | + do_action( |
|
179 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
180 | + $script |
|
181 | + ); |
|
182 | + $registered = wp_register_script( |
|
183 | + $script->handle(), |
|
184 | + $script->source(), |
|
185 | + $script->dependencies(), |
|
186 | + $script->version(), |
|
187 | + $script->loadInFooter() |
|
188 | + ); |
|
189 | + if (! $registered && $this->debug()) { |
|
190 | + throw new AssetRegistrationException($script->handle()); |
|
191 | + } |
|
192 | + $script->setRegistered($registered); |
|
193 | + if ($script->requiresTranslation()) { |
|
194 | + $this->registerTranslation($script->handle()); |
|
195 | + } |
|
196 | + do_action( |
|
197 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
198 | + $script |
|
199 | + ); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Registers CSS assets with WP core |
|
206 | + * |
|
207 | + * @param StylesheetAsset[] $styles |
|
208 | + * @throws InvalidDataTypeException*@throws \DomainException |
|
209 | + * @throws DomainException |
|
210 | + * @since 4.9.62.p |
|
211 | + */ |
|
212 | + public function registerStyles(array $styles) |
|
213 | + { |
|
214 | + foreach ($styles as $style) { |
|
215 | + // skip to next style if this has already been done |
|
216 | + if ($style->isRegistered()) { |
|
217 | + continue; |
|
218 | + } |
|
219 | + do_action( |
|
220 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
221 | + $style |
|
222 | + ); |
|
223 | + wp_register_style( |
|
224 | + $style->handle(), |
|
225 | + $style->source(), |
|
226 | + $style->dependencies(), |
|
227 | + $style->version(), |
|
228 | + $style->media() |
|
229 | + ); |
|
230 | + $style->setRegistered(); |
|
231 | + do_action( |
|
232 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
233 | + $style |
|
234 | + ); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Call back for the script print in frontend and backend. |
|
241 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
242 | + * |
|
243 | + * @since 4.9.31.rc.015 |
|
244 | + */ |
|
245 | + public function enqueueData() |
|
246 | + { |
|
247 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
248 | + wp_add_inline_script( |
|
249 | + 'eejs-core', |
|
250 | + 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
251 | + 'before' |
|
252 | + ); |
|
253 | + $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
254 | + foreach ($scripts as $script) { |
|
255 | + $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
256 | + if ($script->hasInlineDataCallback()) { |
|
257 | + $localize = $script->inlineDataCallback(); |
|
258 | + $localize(); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Used to add data to eejs.data object. |
|
266 | + * Note: Overriding existing data is not allowed. |
|
267 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
268 | + * If the data you add is something like this: |
|
269 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
270 | + * It will be exposed in the page source as: |
|
271 | + * eejs.data.my_plugin_data.foo == gar |
|
272 | + * |
|
273 | + * @param string $key Key used to access your data |
|
274 | + * @param string|array $value Value to attach to key |
|
275 | + * @throws InvalidArgumentException |
|
276 | + */ |
|
277 | + public function addData($key, $value) |
|
278 | + { |
|
279 | + if ($this->verifyDataNotExisting($key)) { |
|
280 | + $this->jsdata[ $key ] = $value; |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
287 | + * elements in an array. |
|
288 | + * |
|
289 | + * When you use this method, the value you include will be merged with the array on $key. |
|
290 | + * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript |
|
291 | + * object like this, eejs.data.test = [ my_data, |
|
292 | + * ] |
|
293 | + * If there has already been a scalar value attached to the data object given key (via addData for instance), then |
|
294 | + * this will throw an exception. |
|
295 | + * |
|
296 | + * Caution: Only add data using this method if you are okay with the potential for additional data added on the same |
|
297 | + * key potentially overriding the existing data on merge (specifically with associative arrays). |
|
298 | + * |
|
299 | + * @param string $key Key to attach data to. |
|
300 | + * @param string|array $value Value being registered. |
|
301 | + * @throws InvalidArgumentException |
|
302 | + */ |
|
303 | + public function pushData($key, $value) |
|
304 | + { |
|
305 | + if (isset($this->jsdata[ $key ]) |
|
306 | + && ! is_array($this->jsdata[ $key ]) |
|
307 | + ) { |
|
308 | + if (! $this->debug()) { |
|
309 | + return; |
|
310 | + } |
|
311 | + throw new InvalidArgumentException( |
|
312 | + sprintf( |
|
313 | + __( |
|
314 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
315 | 315 | push values to this data element when it is an array.', |
316 | - 'event_espresso' |
|
317 | - ), |
|
318 | - $key, |
|
319 | - __METHOD__ |
|
320 | - ) |
|
321 | - ); |
|
322 | - } |
|
323 | - if ( ! isset( $this->jsdata[ $key ] ) ) { |
|
324 | - $this->jsdata[ $key ] = is_array($value) ? $value : [$value]; |
|
325 | - } else { |
|
326 | - $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value); |
|
327 | - } |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * Used to set content used by javascript for a template. |
|
333 | - * Note: Overrides of existing registered templates are not allowed. |
|
334 | - * |
|
335 | - * @param string $template_reference |
|
336 | - * @param string $template_content |
|
337 | - * @throws InvalidArgumentException |
|
338 | - */ |
|
339 | - public function addTemplate($template_reference, $template_content) |
|
340 | - { |
|
341 | - if (! isset($this->jsdata['templates'])) { |
|
342 | - $this->jsdata['templates'] = array(); |
|
343 | - } |
|
344 | - //no overrides allowed. |
|
345 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
346 | - if (! $this->debug()) { |
|
347 | - return; |
|
348 | - } |
|
349 | - throw new InvalidArgumentException( |
|
350 | - sprintf( |
|
351 | - __( |
|
352 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
353 | - 'event_espresso' |
|
354 | - ), |
|
355 | - $template_reference |
|
356 | - ) |
|
357 | - ); |
|
358 | - } |
|
359 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * Retrieve the template content already registered for the given reference. |
|
365 | - * |
|
366 | - * @param string $template_reference |
|
367 | - * @return string |
|
368 | - */ |
|
369 | - public function getTemplate($template_reference) |
|
370 | - { |
|
371 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
372 | - ? $this->jsdata['templates'][ $template_reference ] |
|
373 | - : ''; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Retrieve registered data. |
|
379 | - * |
|
380 | - * @param string $key Name of key to attach data to. |
|
381 | - * @return mixed If there is no for the given key, then false is returned. |
|
382 | - */ |
|
383 | - public function getData($key) |
|
384 | - { |
|
385 | - return isset($this->jsdata[ $key ]) |
|
386 | - ? $this->jsdata[ $key ] |
|
387 | - : false; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Verifies whether the given data exists already on the jsdata array. |
|
393 | - * Overriding data is not allowed. |
|
394 | - * |
|
395 | - * @param string $key Index for data. |
|
396 | - * @return bool If valid then return true. |
|
397 | - * @throws InvalidArgumentException if data already exists. |
|
398 | - */ |
|
399 | - protected function verifyDataNotExisting($key) |
|
400 | - { |
|
401 | - if (isset($this->jsdata[ $key ])) { |
|
402 | - if (! $this->debug()) { |
|
403 | - return false; |
|
404 | - } |
|
405 | - if (is_array($this->jsdata[ $key ])) { |
|
406 | - throw new InvalidArgumentException( |
|
407 | - sprintf( |
|
408 | - __( |
|
409 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
316 | + 'event_espresso' |
|
317 | + ), |
|
318 | + $key, |
|
319 | + __METHOD__ |
|
320 | + ) |
|
321 | + ); |
|
322 | + } |
|
323 | + if ( ! isset( $this->jsdata[ $key ] ) ) { |
|
324 | + $this->jsdata[ $key ] = is_array($value) ? $value : [$value]; |
|
325 | + } else { |
|
326 | + $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value); |
|
327 | + } |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * Used to set content used by javascript for a template. |
|
333 | + * Note: Overrides of existing registered templates are not allowed. |
|
334 | + * |
|
335 | + * @param string $template_reference |
|
336 | + * @param string $template_content |
|
337 | + * @throws InvalidArgumentException |
|
338 | + */ |
|
339 | + public function addTemplate($template_reference, $template_content) |
|
340 | + { |
|
341 | + if (! isset($this->jsdata['templates'])) { |
|
342 | + $this->jsdata['templates'] = array(); |
|
343 | + } |
|
344 | + //no overrides allowed. |
|
345 | + if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
346 | + if (! $this->debug()) { |
|
347 | + return; |
|
348 | + } |
|
349 | + throw new InvalidArgumentException( |
|
350 | + sprintf( |
|
351 | + __( |
|
352 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
353 | + 'event_espresso' |
|
354 | + ), |
|
355 | + $template_reference |
|
356 | + ) |
|
357 | + ); |
|
358 | + } |
|
359 | + $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * Retrieve the template content already registered for the given reference. |
|
365 | + * |
|
366 | + * @param string $template_reference |
|
367 | + * @return string |
|
368 | + */ |
|
369 | + public function getTemplate($template_reference) |
|
370 | + { |
|
371 | + return isset($this->jsdata['templates'][ $template_reference ]) |
|
372 | + ? $this->jsdata['templates'][ $template_reference ] |
|
373 | + : ''; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Retrieve registered data. |
|
379 | + * |
|
380 | + * @param string $key Name of key to attach data to. |
|
381 | + * @return mixed If there is no for the given key, then false is returned. |
|
382 | + */ |
|
383 | + public function getData($key) |
|
384 | + { |
|
385 | + return isset($this->jsdata[ $key ]) |
|
386 | + ? $this->jsdata[ $key ] |
|
387 | + : false; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Verifies whether the given data exists already on the jsdata array. |
|
393 | + * Overriding data is not allowed. |
|
394 | + * |
|
395 | + * @param string $key Index for data. |
|
396 | + * @return bool If valid then return true. |
|
397 | + * @throws InvalidArgumentException if data already exists. |
|
398 | + */ |
|
399 | + protected function verifyDataNotExisting($key) |
|
400 | + { |
|
401 | + if (isset($this->jsdata[ $key ])) { |
|
402 | + if (! $this->debug()) { |
|
403 | + return false; |
|
404 | + } |
|
405 | + if (is_array($this->jsdata[ $key ])) { |
|
406 | + throw new InvalidArgumentException( |
|
407 | + sprintf( |
|
408 | + __( |
|
409 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
410 | 410 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
411 | 411 | %2$s method to push your value to the array.', |
412 | - 'event_espresso' |
|
413 | - ), |
|
414 | - $key, |
|
415 | - 'pushData()' |
|
416 | - ) |
|
417 | - ); |
|
418 | - } |
|
419 | - throw new InvalidArgumentException( |
|
420 | - sprintf( |
|
421 | - __( |
|
422 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
412 | + 'event_espresso' |
|
413 | + ), |
|
414 | + $key, |
|
415 | + 'pushData()' |
|
416 | + ) |
|
417 | + ); |
|
418 | + } |
|
419 | + throw new InvalidArgumentException( |
|
420 | + sprintf( |
|
421 | + __( |
|
422 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
423 | 423 | allowed. Consider attaching your value to a different key', |
424 | - 'event_espresso' |
|
425 | - ), |
|
426 | - $key |
|
427 | - ) |
|
428 | - ); |
|
429 | - } |
|
430 | - return true; |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * Get the actual asset path for asset manifests. |
|
436 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
437 | - * |
|
438 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
439 | - * asset file location. |
|
440 | - * @param string $chunk_name |
|
441 | - * @param string $asset_type |
|
442 | - * @return string |
|
443 | - * @since 4.9.59.p |
|
444 | - */ |
|
445 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
446 | - { |
|
447 | - $url = isset( |
|
448 | - $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
449 | - $this->manifest_data[ $namespace ]['url_base'] |
|
450 | - ) |
|
451 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
452 | - . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
453 | - : $chunk_name; |
|
454 | - |
|
455 | - return apply_filters( |
|
456 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
457 | - $url, |
|
458 | - $namespace, |
|
459 | - $chunk_name, |
|
460 | - $asset_type |
|
461 | - ); |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * Return the url to a js file for the given namespace and chunk name. |
|
468 | - * |
|
469 | - * @param string $namespace |
|
470 | - * @param string $chunk_name |
|
471 | - * @return string |
|
472 | - */ |
|
473 | - public function getJsUrl($namespace, $chunk_name) |
|
474 | - { |
|
475 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Return the url to a css file for the given namespace and chunk name. |
|
481 | - * |
|
482 | - * @param string $namespace |
|
483 | - * @param string $chunk_name |
|
484 | - * @return string |
|
485 | - */ |
|
486 | - public function getCssUrl($namespace, $chunk_name) |
|
487 | - { |
|
488 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * Return the dependencies for a given asset $chunk_name |
|
494 | - * |
|
495 | - * @param string $namespace |
|
496 | - * @param string $chunk_name |
|
497 | - * @param string $asset_type |
|
498 | - * @return array |
|
499 | - * @since 4.9.82.p |
|
500 | - */ |
|
501 | - private function getDependenciesForAsset($namespace, $chunk_name, $asset_type) |
|
502 | - { |
|
503 | - $asset_index = $chunk_name . '.' . $asset_type; |
|
504 | - if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) { |
|
505 | - $path = isset($this->manifest_data[ $namespace ]['path']) |
|
506 | - ? $this->manifest_data[ $namespace ]['path'] |
|
507 | - : ''; |
|
508 | - $dependencies_index = $chunk_name . '.' . Asset::TYPE_JSON; |
|
509 | - $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ]) |
|
510 | - ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ] |
|
511 | - : |
|
512 | - ''; |
|
513 | - $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path) |
|
514 | - ? $this->getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name) |
|
515 | - : []; |
|
516 | - } |
|
517 | - return $this->dependencies_data[ $namespace ][ $asset_index ]; |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * Return dependencies according to asset type. |
|
523 | - * |
|
524 | - * For css assets, this filters the auto generated dependencies by css type. |
|
525 | - * |
|
526 | - * @param string $namespace |
|
527 | - * @param string $asset_type |
|
528 | - * @param string $file_path |
|
529 | - * @param string $chunk_name |
|
530 | - * @return array |
|
531 | - * @since 4.9.82.p |
|
532 | - */ |
|
533 | - private function getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name) |
|
534 | - { |
|
535 | - $asset_dependencies = json_decode(file_get_contents($file_path), true); |
|
536 | - if ($asset_type === Asset::TYPE_JS) { |
|
537 | - return $chunk_name === 'eejs-core' ? $asset_dependencies : array_merge( |
|
538 | - $asset_dependencies, |
|
539 | - [ CoreAssetManager::JS_HANDLE_JS_CORE ] |
|
540 | - ); |
|
541 | - } |
|
542 | - // for css we need to make sure there is actually a css file related to this chunk. |
|
543 | - if (isset($this->manifest_data[ $namespace ])) { |
|
544 | - // array of css chunk files for ee. |
|
545 | - $css_chunks = array_map( |
|
546 | - function ($value) { |
|
547 | - return str_replace('.css', '', $value); |
|
548 | - }, |
|
549 | - array_filter( |
|
550 | - array_keys($this->manifest_data[ $namespace ]), |
|
551 | - function ($value) { |
|
552 | - return strpos($value, '.css') !== false; |
|
553 | - } |
|
554 | - ) |
|
555 | - ); |
|
556 | - // add known wp chunks with css |
|
557 | - $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies); |
|
558 | - // flip for easier search |
|
559 | - $css_chunks = array_flip($css_chunks); |
|
560 | - // now let's filter the dependencies for the incoming chunk to actual chunks that have styles |
|
561 | - return array_filter( |
|
562 | - $asset_dependencies, |
|
563 | - function ($chunk_name) use ($css_chunks) { |
|
564 | - return isset($css_chunks[ $chunk_name ]); |
|
565 | - } |
|
566 | - ); |
|
567 | - } |
|
568 | - return []; |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * Get the dependencies array for the given js asset chunk name |
|
574 | - * |
|
575 | - * @param string $namespace |
|
576 | - * @param string $chunk_name |
|
577 | - * @return array |
|
578 | - * @since 4.9.82.p |
|
579 | - */ |
|
580 | - public function getJsDependencies($namespace, $chunk_name) |
|
581 | - { |
|
582 | - return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_JS); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Get the dependencies array for the given css asset chunk name |
|
588 | - * |
|
589 | - * @param string $namespace |
|
590 | - * @param string $chunk_name |
|
591 | - * @return array |
|
592 | - * @since 4.9.82.p |
|
593 | - */ |
|
594 | - public function getCssDependencies($namespace, $chunk_name) |
|
595 | - { |
|
596 | - return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_CSS); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * @since 4.9.62.p |
|
602 | - * @throws InvalidArgumentException |
|
603 | - * @throws InvalidFilePathException |
|
604 | - */ |
|
605 | - public function registerManifestFiles() |
|
606 | - { |
|
607 | - $manifest_files = $this->assets->getManifestFiles(); |
|
608 | - foreach ($manifest_files as $manifest_file) { |
|
609 | - $this->registerManifestFile( |
|
610 | - $manifest_file->assetNamespace(), |
|
611 | - $manifest_file->urlBase(), |
|
612 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST, |
|
613 | - $manifest_file->filepath() |
|
614 | - ); |
|
615 | - } |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
621 | - * |
|
622 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
623 | - * @param string $url_base The url base for the manifest file location. |
|
624 | - * @param string $manifest_file The absolute path to the manifest file. |
|
625 | - * @param string $manifest_file_path The path to the folder containing the manifest file. If not provided will be |
|
626 | - * default to `plugin_root/assets/dist`. |
|
627 | - * @throws InvalidArgumentException |
|
628 | - * @throws InvalidFilePathException |
|
629 | - * @since 4.9.59.p |
|
630 | - */ |
|
631 | - public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '') |
|
632 | - { |
|
633 | - if (isset($this->manifest_data[ $namespace ])) { |
|
634 | - if (! $this->debug()) { |
|
635 | - return; |
|
636 | - } |
|
637 | - throw new InvalidArgumentException( |
|
638 | - sprintf( |
|
639 | - esc_html__( |
|
640 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
641 | - 'event_espresso' |
|
642 | - ), |
|
643 | - $namespace |
|
644 | - ) |
|
645 | - ); |
|
646 | - } |
|
647 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
648 | - if (is_admin()) { |
|
649 | - EE_Error::add_error( |
|
650 | - sprintf( |
|
651 | - esc_html__( |
|
652 | - 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
653 | - 'event_espresso' |
|
654 | - ), |
|
655 | - 'Event Espresso', |
|
656 | - $url_base, |
|
657 | - 'plugins_url', |
|
658 | - 'WP_PLUGIN_URL' |
|
659 | - ), |
|
660 | - __FILE__, |
|
661 | - __FUNCTION__, |
|
662 | - __LINE__ |
|
663 | - ); |
|
664 | - } |
|
665 | - return; |
|
666 | - } |
|
667 | - $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
668 | - if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
669 | - $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
670 | - } |
|
671 | - if (! isset($this->manifest_data[ $namespace ]['path'])) { |
|
672 | - $this->manifest_data[ $namespace ]['path'] = $manifest_file_path; |
|
673 | - } |
|
674 | - } |
|
675 | - |
|
676 | - |
|
677 | - /** |
|
678 | - * Decodes json from the provided manifest file. |
|
679 | - * |
|
680 | - * @since 4.9.59.p |
|
681 | - * @param string $manifest_file Path to manifest file. |
|
682 | - * @return array |
|
683 | - * @throws InvalidFilePathException |
|
684 | - */ |
|
685 | - private function decodeManifestFile($manifest_file) |
|
686 | - { |
|
687 | - if (! file_exists($manifest_file)) { |
|
688 | - throw new InvalidFilePathException($manifest_file); |
|
689 | - } |
|
690 | - return json_decode(file_get_contents($manifest_file), true); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * This is used to set registered script handles that have data. |
|
696 | - * |
|
697 | - * @param string $script_handle |
|
698 | - */ |
|
699 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
700 | - { |
|
701 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - /**i |
|
424 | + 'event_espresso' |
|
425 | + ), |
|
426 | + $key |
|
427 | + ) |
|
428 | + ); |
|
429 | + } |
|
430 | + return true; |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * Get the actual asset path for asset manifests. |
|
436 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
437 | + * |
|
438 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
439 | + * asset file location. |
|
440 | + * @param string $chunk_name |
|
441 | + * @param string $asset_type |
|
442 | + * @return string |
|
443 | + * @since 4.9.59.p |
|
444 | + */ |
|
445 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
446 | + { |
|
447 | + $url = isset( |
|
448 | + $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
449 | + $this->manifest_data[ $namespace ]['url_base'] |
|
450 | + ) |
|
451 | + ? $this->manifest_data[ $namespace ]['url_base'] |
|
452 | + . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
453 | + : $chunk_name; |
|
454 | + |
|
455 | + return apply_filters( |
|
456 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
457 | + $url, |
|
458 | + $namespace, |
|
459 | + $chunk_name, |
|
460 | + $asset_type |
|
461 | + ); |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * Return the url to a js file for the given namespace and chunk name. |
|
468 | + * |
|
469 | + * @param string $namespace |
|
470 | + * @param string $chunk_name |
|
471 | + * @return string |
|
472 | + */ |
|
473 | + public function getJsUrl($namespace, $chunk_name) |
|
474 | + { |
|
475 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Return the url to a css file for the given namespace and chunk name. |
|
481 | + * |
|
482 | + * @param string $namespace |
|
483 | + * @param string $chunk_name |
|
484 | + * @return string |
|
485 | + */ |
|
486 | + public function getCssUrl($namespace, $chunk_name) |
|
487 | + { |
|
488 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * Return the dependencies for a given asset $chunk_name |
|
494 | + * |
|
495 | + * @param string $namespace |
|
496 | + * @param string $chunk_name |
|
497 | + * @param string $asset_type |
|
498 | + * @return array |
|
499 | + * @since 4.9.82.p |
|
500 | + */ |
|
501 | + private function getDependenciesForAsset($namespace, $chunk_name, $asset_type) |
|
502 | + { |
|
503 | + $asset_index = $chunk_name . '.' . $asset_type; |
|
504 | + if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) { |
|
505 | + $path = isset($this->manifest_data[ $namespace ]['path']) |
|
506 | + ? $this->manifest_data[ $namespace ]['path'] |
|
507 | + : ''; |
|
508 | + $dependencies_index = $chunk_name . '.' . Asset::TYPE_JSON; |
|
509 | + $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ]) |
|
510 | + ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ] |
|
511 | + : |
|
512 | + ''; |
|
513 | + $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path) |
|
514 | + ? $this->getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name) |
|
515 | + : []; |
|
516 | + } |
|
517 | + return $this->dependencies_data[ $namespace ][ $asset_index ]; |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * Return dependencies according to asset type. |
|
523 | + * |
|
524 | + * For css assets, this filters the auto generated dependencies by css type. |
|
525 | + * |
|
526 | + * @param string $namespace |
|
527 | + * @param string $asset_type |
|
528 | + * @param string $file_path |
|
529 | + * @param string $chunk_name |
|
530 | + * @return array |
|
531 | + * @since 4.9.82.p |
|
532 | + */ |
|
533 | + private function getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name) |
|
534 | + { |
|
535 | + $asset_dependencies = json_decode(file_get_contents($file_path), true); |
|
536 | + if ($asset_type === Asset::TYPE_JS) { |
|
537 | + return $chunk_name === 'eejs-core' ? $asset_dependencies : array_merge( |
|
538 | + $asset_dependencies, |
|
539 | + [ CoreAssetManager::JS_HANDLE_JS_CORE ] |
|
540 | + ); |
|
541 | + } |
|
542 | + // for css we need to make sure there is actually a css file related to this chunk. |
|
543 | + if (isset($this->manifest_data[ $namespace ])) { |
|
544 | + // array of css chunk files for ee. |
|
545 | + $css_chunks = array_map( |
|
546 | + function ($value) { |
|
547 | + return str_replace('.css', '', $value); |
|
548 | + }, |
|
549 | + array_filter( |
|
550 | + array_keys($this->manifest_data[ $namespace ]), |
|
551 | + function ($value) { |
|
552 | + return strpos($value, '.css') !== false; |
|
553 | + } |
|
554 | + ) |
|
555 | + ); |
|
556 | + // add known wp chunks with css |
|
557 | + $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies); |
|
558 | + // flip for easier search |
|
559 | + $css_chunks = array_flip($css_chunks); |
|
560 | + // now let's filter the dependencies for the incoming chunk to actual chunks that have styles |
|
561 | + return array_filter( |
|
562 | + $asset_dependencies, |
|
563 | + function ($chunk_name) use ($css_chunks) { |
|
564 | + return isset($css_chunks[ $chunk_name ]); |
|
565 | + } |
|
566 | + ); |
|
567 | + } |
|
568 | + return []; |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * Get the dependencies array for the given js asset chunk name |
|
574 | + * |
|
575 | + * @param string $namespace |
|
576 | + * @param string $chunk_name |
|
577 | + * @return array |
|
578 | + * @since 4.9.82.p |
|
579 | + */ |
|
580 | + public function getJsDependencies($namespace, $chunk_name) |
|
581 | + { |
|
582 | + return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_JS); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Get the dependencies array for the given css asset chunk name |
|
588 | + * |
|
589 | + * @param string $namespace |
|
590 | + * @param string $chunk_name |
|
591 | + * @return array |
|
592 | + * @since 4.9.82.p |
|
593 | + */ |
|
594 | + public function getCssDependencies($namespace, $chunk_name) |
|
595 | + { |
|
596 | + return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_CSS); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * @since 4.9.62.p |
|
602 | + * @throws InvalidArgumentException |
|
603 | + * @throws InvalidFilePathException |
|
604 | + */ |
|
605 | + public function registerManifestFiles() |
|
606 | + { |
|
607 | + $manifest_files = $this->assets->getManifestFiles(); |
|
608 | + foreach ($manifest_files as $manifest_file) { |
|
609 | + $this->registerManifestFile( |
|
610 | + $manifest_file->assetNamespace(), |
|
611 | + $manifest_file->urlBase(), |
|
612 | + $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST, |
|
613 | + $manifest_file->filepath() |
|
614 | + ); |
|
615 | + } |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
621 | + * |
|
622 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
623 | + * @param string $url_base The url base for the manifest file location. |
|
624 | + * @param string $manifest_file The absolute path to the manifest file. |
|
625 | + * @param string $manifest_file_path The path to the folder containing the manifest file. If not provided will be |
|
626 | + * default to `plugin_root/assets/dist`. |
|
627 | + * @throws InvalidArgumentException |
|
628 | + * @throws InvalidFilePathException |
|
629 | + * @since 4.9.59.p |
|
630 | + */ |
|
631 | + public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '') |
|
632 | + { |
|
633 | + if (isset($this->manifest_data[ $namespace ])) { |
|
634 | + if (! $this->debug()) { |
|
635 | + return; |
|
636 | + } |
|
637 | + throw new InvalidArgumentException( |
|
638 | + sprintf( |
|
639 | + esc_html__( |
|
640 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
641 | + 'event_espresso' |
|
642 | + ), |
|
643 | + $namespace |
|
644 | + ) |
|
645 | + ); |
|
646 | + } |
|
647 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
648 | + if (is_admin()) { |
|
649 | + EE_Error::add_error( |
|
650 | + sprintf( |
|
651 | + esc_html__( |
|
652 | + 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
653 | + 'event_espresso' |
|
654 | + ), |
|
655 | + 'Event Espresso', |
|
656 | + $url_base, |
|
657 | + 'plugins_url', |
|
658 | + 'WP_PLUGIN_URL' |
|
659 | + ), |
|
660 | + __FILE__, |
|
661 | + __FUNCTION__, |
|
662 | + __LINE__ |
|
663 | + ); |
|
664 | + } |
|
665 | + return; |
|
666 | + } |
|
667 | + $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
668 | + if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
669 | + $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
670 | + } |
|
671 | + if (! isset($this->manifest_data[ $namespace ]['path'])) { |
|
672 | + $this->manifest_data[ $namespace ]['path'] = $manifest_file_path; |
|
673 | + } |
|
674 | + } |
|
675 | + |
|
676 | + |
|
677 | + /** |
|
678 | + * Decodes json from the provided manifest file. |
|
679 | + * |
|
680 | + * @since 4.9.59.p |
|
681 | + * @param string $manifest_file Path to manifest file. |
|
682 | + * @return array |
|
683 | + * @throws InvalidFilePathException |
|
684 | + */ |
|
685 | + private function decodeManifestFile($manifest_file) |
|
686 | + { |
|
687 | + if (! file_exists($manifest_file)) { |
|
688 | + throw new InvalidFilePathException($manifest_file); |
|
689 | + } |
|
690 | + return json_decode(file_get_contents($manifest_file), true); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * This is used to set registered script handles that have data. |
|
696 | + * |
|
697 | + * @param string $script_handle |
|
698 | + */ |
|
699 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
700 | + { |
|
701 | + $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + /**i |
|
706 | 706 | * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
707 | 707 | * Dependency stored in WP_Scripts if its set. |
708 | 708 | */ |
709 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
710 | - { |
|
711 | - if (empty($this->script_handles_with_data)) { |
|
712 | - return; |
|
713 | - } |
|
714 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
715 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
716 | - } |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
722 | - * |
|
723 | - * @param string $script_handle |
|
724 | - */ |
|
725 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
726 | - { |
|
727 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
728 | - global $wp_scripts; |
|
729 | - $unset_handle = false; |
|
730 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
731 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
732 | - $unset_handle = true; |
|
733 | - } |
|
734 | - //deal with inline_scripts |
|
735 | - if ($wp_scripts->get_data($script_handle, 'before')) { |
|
736 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
737 | - $unset_handle = true; |
|
738 | - } |
|
739 | - if ($wp_scripts->get_data($script_handle, 'after')) { |
|
740 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
741 | - } |
|
742 | - if ($unset_handle) { |
|
743 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
744 | - } |
|
745 | - } |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * register translations for a registered script |
|
751 | - * |
|
752 | - * @param string $handle |
|
753 | - */ |
|
754 | - public function registerTranslation($handle) |
|
755 | - { |
|
756 | - $this->i18n_registry->registerScriptI18n($handle); |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * @since 4.9.63.p |
|
762 | - * @return bool |
|
763 | - */ |
|
764 | - private function debug() |
|
765 | - { |
|
766 | - return apply_filters( |
|
767 | - 'FHEE__EventEspresso_core_services_assets_Registry__debug', |
|
768 | - defined('EE_DEBUG') && EE_DEBUG |
|
769 | - ); |
|
770 | - } |
|
709 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
710 | + { |
|
711 | + if (empty($this->script_handles_with_data)) { |
|
712 | + return; |
|
713 | + } |
|
714 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
715 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
716 | + } |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
722 | + * |
|
723 | + * @param string $script_handle |
|
724 | + */ |
|
725 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
726 | + { |
|
727 | + if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
728 | + global $wp_scripts; |
|
729 | + $unset_handle = false; |
|
730 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
731 | + unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
732 | + $unset_handle = true; |
|
733 | + } |
|
734 | + //deal with inline_scripts |
|
735 | + if ($wp_scripts->get_data($script_handle, 'before')) { |
|
736 | + unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
737 | + $unset_handle = true; |
|
738 | + } |
|
739 | + if ($wp_scripts->get_data($script_handle, 'after')) { |
|
740 | + unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
741 | + } |
|
742 | + if ($unset_handle) { |
|
743 | + unset($this->script_handles_with_data[ $script_handle ]); |
|
744 | + } |
|
745 | + } |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * register translations for a registered script |
|
751 | + * |
|
752 | + * @param string $handle |
|
753 | + */ |
|
754 | + public function registerTranslation($handle) |
|
755 | + { |
|
756 | + $this->i18n_registry->registerScriptI18n($handle); |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * @since 4.9.63.p |
|
762 | + * @return bool |
|
763 | + */ |
|
764 | + private function debug() |
|
765 | + { |
|
766 | + return apply_filters( |
|
767 | + 'FHEE__EventEspresso_core_services_assets_Registry__debug', |
|
768 | + defined('EE_DEBUG') && EE_DEBUG |
|
769 | + ); |
|
770 | + } |
|
771 | 771 | } |
@@ -19,152 +19,152 @@ |
||
19 | 19 | */ |
20 | 20 | class CardinalCruiseJwtFactory |
21 | 21 | { |
22 | - /** |
|
23 | - * @var EE_Registration_Config |
|
24 | - */ |
|
25 | - private $reg_config; |
|
26 | - /** |
|
27 | - * @var EE_Currency_Config |
|
28 | - */ |
|
29 | - private $currency_config; |
|
22 | + /** |
|
23 | + * @var EE_Registration_Config |
|
24 | + */ |
|
25 | + private $reg_config; |
|
26 | + /** |
|
27 | + * @var EE_Currency_Config |
|
28 | + */ |
|
29 | + private $currency_config; |
|
30 | 30 | |
31 | - /** |
|
32 | - * CardinalCruiseJwt constructor. |
|
33 | - * @param EE_Registration_Config $reg_config |
|
34 | - * @param EE_Currency_Config $currency_config |
|
35 | - */ |
|
36 | - public function __construct( |
|
37 | - EE_Registration_Config $reg_config, |
|
38 | - EE_Currency_Config $currency_config |
|
39 | - ) |
|
40 | - { |
|
31 | + /** |
|
32 | + * CardinalCruiseJwt constructor. |
|
33 | + * @param EE_Registration_Config $reg_config |
|
34 | + * @param EE_Currency_Config $currency_config |
|
35 | + */ |
|
36 | + public function __construct( |
|
37 | + EE_Registration_Config $reg_config, |
|
38 | + EE_Currency_Config $currency_config |
|
39 | + ) |
|
40 | + { |
|
41 | 41 | |
42 | - $this->reg_config = $reg_config; |
|
43 | - $this->currency_config = $currency_config; |
|
44 | - } |
|
42 | + $this->reg_config = $reg_config; |
|
43 | + $this->currency_config = $currency_config; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Gets the JWT string to send to Cardinal Commerce |
|
48 | - * @since $VID:$ |
|
49 | - * @param EE_Transaction|null $transaction |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function generateCruiseJwt(EE_Transaction $transaction = null) |
|
53 | - { |
|
54 | - $iat = time(); |
|
55 | - $data = array( |
|
56 | - 'jti' => uniqid(), |
|
57 | - 'iat' => $iat, |
|
58 | - 'exp' => $iat + 7200, |
|
59 | - 'iss' => $this->reg_config->cardinal_commerce_api_identifier, |
|
60 | - 'OrgUnitId' => $this->reg_config->cardinal_commerce_api_org_unit_id, |
|
61 | - ); |
|
62 | - if ($transaction) { |
|
63 | - $payload = $this->createRequestOrderObject($transaction); |
|
64 | - $data['Payload'] = $payload; |
|
65 | - $data['ObjectifyPayload'] = true; |
|
66 | - } |
|
67 | - $rv = $this->generateJwtFromData($data); |
|
68 | - return $rv; |
|
69 | - } |
|
46 | + /** |
|
47 | + * Gets the JWT string to send to Cardinal Commerce |
|
48 | + * @since $VID:$ |
|
49 | + * @param EE_Transaction|null $transaction |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function generateCruiseJwt(EE_Transaction $transaction = null) |
|
53 | + { |
|
54 | + $iat = time(); |
|
55 | + $data = array( |
|
56 | + 'jti' => uniqid(), |
|
57 | + 'iat' => $iat, |
|
58 | + 'exp' => $iat + 7200, |
|
59 | + 'iss' => $this->reg_config->cardinal_commerce_api_identifier, |
|
60 | + 'OrgUnitId' => $this->reg_config->cardinal_commerce_api_org_unit_id, |
|
61 | + ); |
|
62 | + if ($transaction) { |
|
63 | + $payload = $this->createRequestOrderObject($transaction); |
|
64 | + $data['Payload'] = $payload; |
|
65 | + $data['ObjectifyPayload'] = true; |
|
66 | + } |
|
67 | + $rv = $this->generateJwtFromData($data); |
|
68 | + return $rv; |
|
69 | + } |
|
70 | 70 | |
71 | - private function createRequestOrderObject(EE_Transaction $transaction) |
|
72 | - { |
|
73 | - $currency_alpha = $this->currency_config->code; |
|
74 | - $raw_amount = $this->prepareAmountForCardinalCommerce($transaction->remaining(), $currency_alpha); |
|
71 | + private function createRequestOrderObject(EE_Transaction $transaction) |
|
72 | + { |
|
73 | + $currency_alpha = $this->currency_config->code; |
|
74 | + $raw_amount = $this->prepareAmountForCardinalCommerce($transaction->remaining(), $currency_alpha); |
|
75 | 75 | |
76 | - $request_order_object = array( |
|
77 | - "Consumer" => array( |
|
78 | - "BillingAddress" => array( |
|
79 | - "FirstName" => 'fname', |
|
80 | - "LastName" => 'fname', |
|
81 | - "Address1" => 'fname', |
|
82 | - "Address2" => 'fname', |
|
83 | - "City" => 'fname', |
|
84 | - "State" => 'UT', |
|
85 | - "PostalCode" => 'fname', |
|
86 | - "CountryCode" => 'US', |
|
87 | - "Phone1" => '1231231231', |
|
88 | - ), |
|
89 | - "ShippingAddress" => array( |
|
90 | - "FirstName" => 'fname', |
|
91 | - "LastName" => 'fname', |
|
92 | - "Address1" => 'fname', |
|
93 | - "Address2" => 'fname', |
|
94 | - "City" => 'fname', |
|
95 | - "State" => 'UT', |
|
96 | - "PostalCode" => 'fname', |
|
97 | - "CountryCode" => 'US', |
|
98 | - "Phone1" => '1231231231', |
|
99 | - ), |
|
100 | - "Email1" => '[email protected]', |
|
101 | - ), |
|
102 | - "OrderDetails" => array( |
|
103 | - "OrderNumber" => $transaction->ID(), |
|
104 | - "Amount" => $raw_amount, |
|
105 | - "CurrencyCode" => $currency_alpha, |
|
106 | - "OrderChannel" => "S", |
|
107 | - ), |
|
108 | - "Options" => array( |
|
109 | - "EnableCCA" => true, |
|
110 | - ), |
|
111 | - ); |
|
76 | + $request_order_object = array( |
|
77 | + "Consumer" => array( |
|
78 | + "BillingAddress" => array( |
|
79 | + "FirstName" => 'fname', |
|
80 | + "LastName" => 'fname', |
|
81 | + "Address1" => 'fname', |
|
82 | + "Address2" => 'fname', |
|
83 | + "City" => 'fname', |
|
84 | + "State" => 'UT', |
|
85 | + "PostalCode" => 'fname', |
|
86 | + "CountryCode" => 'US', |
|
87 | + "Phone1" => '1231231231', |
|
88 | + ), |
|
89 | + "ShippingAddress" => array( |
|
90 | + "FirstName" => 'fname', |
|
91 | + "LastName" => 'fname', |
|
92 | + "Address1" => 'fname', |
|
93 | + "Address2" => 'fname', |
|
94 | + "City" => 'fname', |
|
95 | + "State" => 'UT', |
|
96 | + "PostalCode" => 'fname', |
|
97 | + "CountryCode" => 'US', |
|
98 | + "Phone1" => '1231231231', |
|
99 | + ), |
|
100 | + "Email1" => '[email protected]', |
|
101 | + ), |
|
102 | + "OrderDetails" => array( |
|
103 | + "OrderNumber" => $transaction->ID(), |
|
104 | + "Amount" => $raw_amount, |
|
105 | + "CurrencyCode" => $currency_alpha, |
|
106 | + "OrderChannel" => "S", |
|
107 | + ), |
|
108 | + "Options" => array( |
|
109 | + "EnableCCA" => true, |
|
110 | + ), |
|
111 | + ); |
|
112 | 112 | |
113 | - return $request_order_object; |
|
114 | - } |
|
113 | + return $request_order_object; |
|
114 | + } |
|
115 | 115 | |
116 | - private function signJwt($header, $body) |
|
117 | - { |
|
118 | - $secret = $this->reg_config->cardinal_commerce_api_key; |
|
119 | - $plaintext = $header . '.' . $body; |
|
120 | - return $this->base64EncodeUrlSafe(hash_hmac( |
|
121 | - 'sha256', $plaintext, $secret, true)); |
|
122 | - } |
|
116 | + private function signJwt($header, $body) |
|
117 | + { |
|
118 | + $secret = $this->reg_config->cardinal_commerce_api_key; |
|
119 | + $plaintext = $header . '.' . $body; |
|
120 | + return $this->base64EncodeUrlSafe(hash_hmac( |
|
121 | + 'sha256', $plaintext, $secret, true)); |
|
122 | + } |
|
123 | 123 | |
124 | - private static function base64EncodeUrlSafe($source) |
|
125 | - { |
|
126 | - $rv = base64_encode($source); |
|
127 | - $rv = str_replace('=', '', $rv); |
|
128 | - $rv = str_replace('+', '-', $rv); |
|
129 | - $rv = str_replace('/', '_', $rv); |
|
130 | - return $rv; |
|
131 | - } |
|
124 | + private static function base64EncodeUrlSafe($source) |
|
125 | + { |
|
126 | + $rv = base64_encode($source); |
|
127 | + $rv = str_replace('=', '', $rv); |
|
128 | + $rv = str_replace('+', '-', $rv); |
|
129 | + $rv = str_replace('/', '_', $rv); |
|
130 | + return $rv; |
|
131 | + } |
|
132 | 132 | |
133 | - private function generateJwtFromData($data) |
|
134 | - { |
|
135 | - $header = $this->base64EncodeUrlSafe(json_encode(array( |
|
136 | - 'alg' => 'HS256', 'typ' => 'JWT' |
|
137 | - ))); |
|
138 | - $body = $this->base64EncodeUrlSafe(json_encode($data)); |
|
139 | - $signature = $this->signJwt($header, $body); |
|
140 | - return $header . '.' . $body . '.' . $signature; |
|
141 | - } |
|
133 | + private function generateJwtFromData($data) |
|
134 | + { |
|
135 | + $header = $this->base64EncodeUrlSafe(json_encode(array( |
|
136 | + 'alg' => 'HS256', 'typ' => 'JWT' |
|
137 | + ))); |
|
138 | + $body = $this->base64EncodeUrlSafe(json_encode($data)); |
|
139 | + $signature = $this->signJwt($header, $body); |
|
140 | + return $header . '.' . $body . '.' . $signature; |
|
141 | + } |
|
142 | 142 | |
143 | - protected function prepareAmountForCardinalCommerce($amount, $currency_alpha) |
|
144 | - { |
|
145 | - $float_amount = (float) $amount; |
|
146 | - $exponent = $this->currencyDecimalPlaces($currency_alpha); |
|
147 | - $int_amount = (int) round($float_amount * pow(10, $exponent)); |
|
148 | - return (string) $int_amount; |
|
149 | - } |
|
143 | + protected function prepareAmountForCardinalCommerce($amount, $currency_alpha) |
|
144 | + { |
|
145 | + $float_amount = (float) $amount; |
|
146 | + $exponent = $this->currencyDecimalPlaces($currency_alpha); |
|
147 | + $int_amount = (int) round($float_amount * pow(10, $exponent)); |
|
148 | + return (string) $int_amount; |
|
149 | + } |
|
150 | 150 | |
151 | - public static function currencyDecimalPlaces($alpha) |
|
152 | - { |
|
153 | - if (in_array($alpha, array( |
|
154 | - 'ADP', 'BEF', 'BIF', 'BYR', 'CLP', 'DJF', 'ESP', 'GNF', 'ISK', |
|
155 | - 'ITL', 'JPY', 'KMF', 'KRW', 'LUF', 'MGF', 'PTE', 'PYG', 'RWF', |
|
156 | - 'TPE', 'TRL', 'UYI', 'VND', 'VUV', 'XAF', 'XOF', 'XPF', |
|
157 | - ))) { |
|
158 | - return 0; |
|
159 | - } elseif (in_array($alpha, array( |
|
160 | - 'BHD', 'CSD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND', |
|
161 | - ))) { |
|
162 | - return 3; |
|
163 | - } elseif ($alpha == 'CLF') { |
|
164 | - return 4; |
|
165 | - } |
|
166 | - return 2; |
|
167 | - } |
|
151 | + public static function currencyDecimalPlaces($alpha) |
|
152 | + { |
|
153 | + if (in_array($alpha, array( |
|
154 | + 'ADP', 'BEF', 'BIF', 'BYR', 'CLP', 'DJF', 'ESP', 'GNF', 'ISK', |
|
155 | + 'ITL', 'JPY', 'KMF', 'KRW', 'LUF', 'MGF', 'PTE', 'PYG', 'RWF', |
|
156 | + 'TPE', 'TRL', 'UYI', 'VND', 'VUV', 'XAF', 'XOF', 'XPF', |
|
157 | + ))) { |
|
158 | + return 0; |
|
159 | + } elseif (in_array($alpha, array( |
|
160 | + 'BHD', 'CSD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND', |
|
161 | + ))) { |
|
162 | + return 3; |
|
163 | + } elseif ($alpha == 'CLF') { |
|
164 | + return 4; |
|
165 | + } |
|
166 | + return 2; |
|
167 | + } |
|
168 | 168 | } |
169 | 169 | // End of file CardinalCruiseJwt.php |
170 | 170 | // Location: ${NAMESPACE}/CardinalCruiseJwt.php |