@@ -39,242 +39,242 @@ |
||
39 | 39 | class FieldResolver extends ResolverBase |
40 | 40 | { |
41 | 41 | |
42 | - /** |
|
43 | - * @var mixed $model |
|
44 | - */ |
|
45 | - protected $model; |
|
42 | + /** |
|
43 | + * @var mixed $model |
|
44 | + */ |
|
45 | + protected $model; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var array $fields . |
|
49 | - */ |
|
50 | - protected $fields; |
|
47 | + /** |
|
48 | + * @var array $fields . |
|
49 | + */ |
|
50 | + protected $fields; |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * FieldResolver constructor. |
|
55 | - * |
|
56 | - * @param mixed $model The model instance. |
|
57 | - * @param array $fields The fields registered for the type. |
|
58 | - */ |
|
59 | - public function __construct($model, array $fields) |
|
60 | - { |
|
61 | - $this->model = $model; |
|
62 | - $this->fields = $fields; |
|
63 | - } |
|
53 | + /** |
|
54 | + * FieldResolver constructor. |
|
55 | + * |
|
56 | + * @param mixed $model The model instance. |
|
57 | + * @param array $fields The fields registered for the type. |
|
58 | + */ |
|
59 | + public function __construct($model, array $fields) |
|
60 | + { |
|
61 | + $this->model = $model; |
|
62 | + $this->fields = $fields; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
68 | - * @param array $args The inputArgs on the field |
|
69 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
70 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
71 | - * @return string |
|
72 | - * @throws EE_Error |
|
73 | - * @throws Exception |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - * @throws ReflectionException |
|
78 | - * @throws UserError |
|
79 | - * @throws UnexpectedEntityException |
|
80 | - * @since $VID:$ |
|
81 | - */ |
|
82 | - public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
|
83 | - { |
|
84 | - $fieldName = $info->fieldName; |
|
85 | - $field = isset($this->fields[ $fieldName ]) ? $this->fields[ $fieldName ] : null; |
|
86 | - // Field should exist in teh registered fields |
|
87 | - if ($field instanceof GraphQLField) { |
|
88 | - // check if the field should be resolved. |
|
89 | - if (! $field->shouldResolve()) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - // Give priority to the internal resolver. |
|
93 | - if ($field->hasInternalResolver()) { |
|
94 | - return $field->resolve($source, $args, $context, $info); |
|
95 | - } |
|
96 | - if (! ($source instanceof EE_Base_Class)) { |
|
97 | - return null; |
|
98 | - } |
|
99 | - // Check if the field has a key mapped to model. |
|
100 | - if (! empty($field->key())) { |
|
101 | - $value = $source->{$field->key()}(); |
|
102 | - return $field->mayBeFormatValue($value, $source); |
|
103 | - } |
|
104 | - switch ($fieldName) { |
|
105 | - case 'id': // the global ID |
|
106 | - return $this->resolveId($source); |
|
107 | - case 'cacheId': |
|
108 | - return $this->resolveCacheId($source); |
|
109 | - case 'parent': |
|
110 | - return $this->resolveParent($source); |
|
111 | - case 'event': |
|
112 | - return $this->resolveEvent($source, $args, $context); |
|
113 | - case 'wpUser': |
|
114 | - return $this->resolveWpUser($source, $args, $context); |
|
115 | - case 'state': // Venue |
|
116 | - return $this->resolveState($source); |
|
117 | - case 'country': // State, Venue |
|
118 | - return $this->resolveCountry($source); |
|
119 | - } |
|
120 | - } |
|
121 | - return null; |
|
122 | - } |
|
66 | + /** |
|
67 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
68 | + * @param array $args The inputArgs on the field |
|
69 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
70 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
71 | + * @return string |
|
72 | + * @throws EE_Error |
|
73 | + * @throws Exception |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + * @throws ReflectionException |
|
78 | + * @throws UserError |
|
79 | + * @throws UnexpectedEntityException |
|
80 | + * @since $VID:$ |
|
81 | + */ |
|
82 | + public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
|
83 | + { |
|
84 | + $fieldName = $info->fieldName; |
|
85 | + $field = isset($this->fields[ $fieldName ]) ? $this->fields[ $fieldName ] : null; |
|
86 | + // Field should exist in teh registered fields |
|
87 | + if ($field instanceof GraphQLField) { |
|
88 | + // check if the field should be resolved. |
|
89 | + if (! $field->shouldResolve()) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + // Give priority to the internal resolver. |
|
93 | + if ($field->hasInternalResolver()) { |
|
94 | + return $field->resolve($source, $args, $context, $info); |
|
95 | + } |
|
96 | + if (! ($source instanceof EE_Base_Class)) { |
|
97 | + return null; |
|
98 | + } |
|
99 | + // Check if the field has a key mapped to model. |
|
100 | + if (! empty($field->key())) { |
|
101 | + $value = $source->{$field->key()}(); |
|
102 | + return $field->mayBeFormatValue($value, $source); |
|
103 | + } |
|
104 | + switch ($fieldName) { |
|
105 | + case 'id': // the global ID |
|
106 | + return $this->resolveId($source); |
|
107 | + case 'cacheId': |
|
108 | + return $this->resolveCacheId($source); |
|
109 | + case 'parent': |
|
110 | + return $this->resolveParent($source); |
|
111 | + case 'event': |
|
112 | + return $this->resolveEvent($source, $args, $context); |
|
113 | + case 'wpUser': |
|
114 | + return $this->resolveWpUser($source, $args, $context); |
|
115 | + case 'state': // Venue |
|
116 | + return $this->resolveState($source); |
|
117 | + case 'country': // State, Venue |
|
118 | + return $this->resolveCountry($source); |
|
119 | + } |
|
120 | + } |
|
121 | + return null; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | - /** |
|
126 | - * Resolve the global ID |
|
127 | - * |
|
128 | - * @param mixed $source |
|
129 | - * @return string|null |
|
130 | - * @throws Exception |
|
131 | - * @since $VID:$ |
|
132 | - */ |
|
133 | - public function resolveId($source) |
|
134 | - { |
|
135 | - $ID = $source instanceof EE_Base_Class ? $source->ID() : 0; |
|
125 | + /** |
|
126 | + * Resolve the global ID |
|
127 | + * |
|
128 | + * @param mixed $source |
|
129 | + * @return string|null |
|
130 | + * @throws Exception |
|
131 | + * @since $VID:$ |
|
132 | + */ |
|
133 | + public function resolveId($source) |
|
134 | + { |
|
135 | + $ID = $source instanceof EE_Base_Class ? $source->ID() : 0; |
|
136 | 136 | |
137 | - return $ID ? Relay::toGlobalId($this->model->item_name(), $ID) : null; |
|
138 | - } |
|
137 | + return $ID ? Relay::toGlobalId($this->model->item_name(), $ID) : null; |
|
138 | + } |
|
139 | 139 | |
140 | 140 | |
141 | - /** |
|
142 | - * Resolve the cache ID |
|
143 | - * |
|
144 | - * @param mixed $source |
|
145 | - * @return string |
|
146 | - * @since $VID:$ |
|
147 | - */ |
|
148 | - public function resolveCacheId($source) |
|
149 | - { |
|
150 | - $model_name = $this->model->item_name(); |
|
151 | - $ID = $source->ID(); |
|
152 | - // Since cacheId does not need to be globally unique |
|
153 | - // $uniqid is sufficient, still adding the model name and ID |
|
154 | - // may be we need/use them in future. |
|
155 | - return uniqid("{$model_name}:{$ID}:", true); |
|
156 | - } |
|
141 | + /** |
|
142 | + * Resolve the cache ID |
|
143 | + * |
|
144 | + * @param mixed $source |
|
145 | + * @return string |
|
146 | + * @since $VID:$ |
|
147 | + */ |
|
148 | + public function resolveCacheId($source) |
|
149 | + { |
|
150 | + $model_name = $this->model->item_name(); |
|
151 | + $ID = $source->ID(); |
|
152 | + // Since cacheId does not need to be globally unique |
|
153 | + // $uniqid is sufficient, still adding the model name and ID |
|
154 | + // may be we need/use them in future. |
|
155 | + return uniqid("{$model_name}:{$ID}:", true); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - /** |
|
160 | - * @param mixed $source |
|
161 | - * @param $args |
|
162 | - * @param $context |
|
163 | - * @return Deferred|null |
|
164 | - * @throws Exception |
|
165 | - * @since $VID:$ |
|
166 | - */ |
|
167 | - public function resolveWpUser($source, $args, $context) |
|
168 | - { |
|
169 | - $user_id = $source->wp_user(); |
|
170 | - return $user_id |
|
171 | - ? DataSource::resolve_user($user_id, $context) |
|
172 | - : null; |
|
173 | - } |
|
159 | + /** |
|
160 | + * @param mixed $source |
|
161 | + * @param $args |
|
162 | + * @param $context |
|
163 | + * @return Deferred|null |
|
164 | + * @throws Exception |
|
165 | + * @since $VID:$ |
|
166 | + */ |
|
167 | + public function resolveWpUser($source, $args, $context) |
|
168 | + { |
|
169 | + $user_id = $source->wp_user(); |
|
170 | + return $user_id |
|
171 | + ? DataSource::resolve_user($user_id, $context) |
|
172 | + : null; |
|
173 | + } |
|
174 | 174 | |
175 | 175 | |
176 | - /** |
|
177 | - * @param mixed $source |
|
178 | - * @return EE_Base_Class|null |
|
179 | - * @throws EE_Error |
|
180 | - * @throws InvalidArgumentException |
|
181 | - * @throws InvalidDataTypeException |
|
182 | - * @throws InvalidInterfaceException |
|
183 | - * @throws ReflectionException |
|
184 | - * @since $VID:$ |
|
185 | - */ |
|
186 | - public function resolveParent($source) |
|
187 | - { |
|
188 | - return $this->model->get_one_by_ID($source->parent()); |
|
189 | - } |
|
176 | + /** |
|
177 | + * @param mixed $source |
|
178 | + * @return EE_Base_Class|null |
|
179 | + * @throws EE_Error |
|
180 | + * @throws InvalidArgumentException |
|
181 | + * @throws InvalidDataTypeException |
|
182 | + * @throws InvalidInterfaceException |
|
183 | + * @throws ReflectionException |
|
184 | + * @since $VID:$ |
|
185 | + */ |
|
186 | + public function resolveParent($source) |
|
187 | + { |
|
188 | + return $this->model->get_one_by_ID($source->parent()); |
|
189 | + } |
|
190 | 190 | |
191 | 191 | |
192 | - /** |
|
193 | - * @param mixed $source |
|
194 | - * @param $args |
|
195 | - * @param $context |
|
196 | - * @return Deferred|null |
|
197 | - * @throws EE_Error |
|
198 | - * @throws InvalidArgumentException |
|
199 | - * @throws InvalidDataTypeException |
|
200 | - * @throws InvalidInterfaceException |
|
201 | - * @throws ReflectionException |
|
202 | - * @throws UserError |
|
203 | - * @throws UnexpectedEntityException |
|
204 | - * @since $VID:$ |
|
205 | - */ |
|
206 | - public function resolveEvent($source, $args, $context) |
|
207 | - { |
|
208 | - switch (true) { |
|
209 | - case $source instanceof EE_Datetime: |
|
210 | - $event = $source->event(); |
|
211 | - break; |
|
212 | - case $source instanceof EE_Venue: |
|
213 | - case $source instanceof EE_Ticket: |
|
214 | - $event = $source->get_related_event(); |
|
215 | - break; |
|
216 | - default: |
|
217 | - $event = null; |
|
218 | - break; |
|
219 | - } |
|
220 | - return $event instanceof EE_Event |
|
221 | - ? DataSource::resolve_post_object($event->ID(), $context) |
|
222 | - : null; |
|
223 | - } |
|
192 | + /** |
|
193 | + * @param mixed $source |
|
194 | + * @param $args |
|
195 | + * @param $context |
|
196 | + * @return Deferred|null |
|
197 | + * @throws EE_Error |
|
198 | + * @throws InvalidArgumentException |
|
199 | + * @throws InvalidDataTypeException |
|
200 | + * @throws InvalidInterfaceException |
|
201 | + * @throws ReflectionException |
|
202 | + * @throws UserError |
|
203 | + * @throws UnexpectedEntityException |
|
204 | + * @since $VID:$ |
|
205 | + */ |
|
206 | + public function resolveEvent($source, $args, $context) |
|
207 | + { |
|
208 | + switch (true) { |
|
209 | + case $source instanceof EE_Datetime: |
|
210 | + $event = $source->event(); |
|
211 | + break; |
|
212 | + case $source instanceof EE_Venue: |
|
213 | + case $source instanceof EE_Ticket: |
|
214 | + $event = $source->get_related_event(); |
|
215 | + break; |
|
216 | + default: |
|
217 | + $event = null; |
|
218 | + break; |
|
219 | + } |
|
220 | + return $event instanceof EE_Event |
|
221 | + ? DataSource::resolve_post_object($event->ID(), $context) |
|
222 | + : null; |
|
223 | + } |
|
224 | 224 | |
225 | 225 | |
226 | - /** |
|
227 | - * @param mixed $source The source instance. |
|
228 | - * @return EE_Base_Class|null |
|
229 | - * @throws EE_Error |
|
230 | - * @throws InvalidArgumentException |
|
231 | - * @throws InvalidDataTypeException |
|
232 | - * @throws InvalidInterfaceException |
|
233 | - * @since $VID:$ |
|
234 | - */ |
|
235 | - public function resolveState($source) |
|
236 | - { |
|
237 | - switch (true) { |
|
238 | - case $source instanceof EE_Attendee: |
|
239 | - case $source instanceof EE_Venue: |
|
240 | - $state_id = $source->state_ID(); |
|
241 | - break; |
|
242 | - default: |
|
243 | - $state_id = null; |
|
244 | - break; |
|
245 | - } |
|
246 | - return $state_id |
|
247 | - ? EEM_State::instance()->get_one_by_ID($state_id) |
|
248 | - : null; |
|
249 | - } |
|
226 | + /** |
|
227 | + * @param mixed $source The source instance. |
|
228 | + * @return EE_Base_Class|null |
|
229 | + * @throws EE_Error |
|
230 | + * @throws InvalidArgumentException |
|
231 | + * @throws InvalidDataTypeException |
|
232 | + * @throws InvalidInterfaceException |
|
233 | + * @since $VID:$ |
|
234 | + */ |
|
235 | + public function resolveState($source) |
|
236 | + { |
|
237 | + switch (true) { |
|
238 | + case $source instanceof EE_Attendee: |
|
239 | + case $source instanceof EE_Venue: |
|
240 | + $state_id = $source->state_ID(); |
|
241 | + break; |
|
242 | + default: |
|
243 | + $state_id = null; |
|
244 | + break; |
|
245 | + } |
|
246 | + return $state_id |
|
247 | + ? EEM_State::instance()->get_one_by_ID($state_id) |
|
248 | + : null; |
|
249 | + } |
|
250 | 250 | |
251 | 251 | |
252 | - /** |
|
253 | - * @param mixed $source The source instance. |
|
254 | - * @return EE_Base_Class|null |
|
255 | - * @throws EE_Error |
|
256 | - * @throws InvalidArgumentException |
|
257 | - * @throws InvalidDataTypeException |
|
258 | - * @throws InvalidInterfaceException |
|
259 | - * @since $VID:$ |
|
260 | - */ |
|
261 | - public function resolveCountry($source) |
|
262 | - { |
|
263 | - switch (true) { |
|
264 | - case $source instanceof EE_State: |
|
265 | - $country_iso = $source->country_iso(); |
|
266 | - break; |
|
267 | - case $source instanceof EE_Attendee: |
|
268 | - case $source instanceof EE_Venue: |
|
269 | - $country_iso = $source->country_ID(); |
|
270 | - break; |
|
271 | - default: |
|
272 | - $country_iso = null; |
|
273 | - break; |
|
274 | - } |
|
252 | + /** |
|
253 | + * @param mixed $source The source instance. |
|
254 | + * @return EE_Base_Class|null |
|
255 | + * @throws EE_Error |
|
256 | + * @throws InvalidArgumentException |
|
257 | + * @throws InvalidDataTypeException |
|
258 | + * @throws InvalidInterfaceException |
|
259 | + * @since $VID:$ |
|
260 | + */ |
|
261 | + public function resolveCountry($source) |
|
262 | + { |
|
263 | + switch (true) { |
|
264 | + case $source instanceof EE_State: |
|
265 | + $country_iso = $source->country_iso(); |
|
266 | + break; |
|
267 | + case $source instanceof EE_Attendee: |
|
268 | + case $source instanceof EE_Venue: |
|
269 | + $country_iso = $source->country_ID(); |
|
270 | + break; |
|
271 | + default: |
|
272 | + $country_iso = null; |
|
273 | + break; |
|
274 | + } |
|
275 | 275 | |
276 | - return $country_iso |
|
277 | - ? EEM_Country::instance()->get_one_by_ID($country_iso) |
|
278 | - : null; |
|
279 | - } |
|
276 | + return $country_iso |
|
277 | + ? EEM_Country::instance()->get_one_by_ID($country_iso) |
|
278 | + : null; |
|
279 | + } |
|
280 | 280 | } |
@@ -19,32 +19,32 @@ |
||
19 | 19 | class AttendeesConnectionOrderbyInput extends InputBase |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * AttendeesConnectionOrderbyInput constructor. |
|
24 | - */ |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->setName($this->namespace . 'AttendeesConnectionOrderbyInput'); |
|
28 | - $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
|
29 | - parent::__construct(); |
|
30 | - } |
|
22 | + /** |
|
23 | + * AttendeesConnectionOrderbyInput constructor. |
|
24 | + */ |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->setName($this->namespace . 'AttendeesConnectionOrderbyInput'); |
|
28 | + $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
|
29 | + parent::__construct(); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @return GraphQLFieldInterface[] |
|
35 | - * @since $VID:$ |
|
36 | - */ |
|
37 | - protected function getFields() |
|
38 | - { |
|
39 | - return [ |
|
40 | - new GraphQLField( |
|
41 | - 'field', |
|
42 | - ['non_null' => $this->namespace . 'AttendeesConnectionOrderbyEnum'] |
|
43 | - ), |
|
44 | - new GraphQLField( |
|
45 | - 'order', |
|
46 | - 'OrderEnum' |
|
47 | - ), |
|
48 | - ]; |
|
49 | - } |
|
33 | + /** |
|
34 | + * @return GraphQLFieldInterface[] |
|
35 | + * @since $VID:$ |
|
36 | + */ |
|
37 | + protected function getFields() |
|
38 | + { |
|
39 | + return [ |
|
40 | + new GraphQLField( |
|
41 | + 'field', |
|
42 | + ['non_null' => $this->namespace . 'AttendeesConnectionOrderbyEnum'] |
|
43 | + ), |
|
44 | + new GraphQLField( |
|
45 | + 'order', |
|
46 | + 'OrderEnum' |
|
47 | + ), |
|
48 | + ]; |
|
49 | + } |
|
50 | 50 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() |
26 | 26 | { |
27 | - $this->setName($this->namespace . 'AttendeesConnectionOrderbyInput'); |
|
27 | + $this->setName($this->namespace.'AttendeesConnectionOrderbyInput'); |
|
28 | 28 | $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
29 | 29 | parent::__construct(); |
30 | 30 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | return [ |
40 | 40 | new GraphQLField( |
41 | 41 | 'field', |
42 | - ['non_null' => $this->namespace . 'AttendeesConnectionOrderbyEnum'] |
|
42 | + ['non_null' => $this->namespace.'AttendeesConnectionOrderbyEnum'] |
|
43 | 43 | ), |
44 | 44 | new GraphQLField( |
45 | 45 | 'order', |
@@ -24,111 +24,111 @@ |
||
24 | 24 | class LegacyEditorAssetManager extends AssetManager |
25 | 25 | { |
26 | 26 | |
27 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
28 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
29 | - const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Currency_Config $currency_config |
|
34 | - */ |
|
35 | - protected $currency_config; |
|
36 | - |
|
37 | - /** |
|
38 | - * CoreAssetRegister constructor. |
|
39 | - * |
|
40 | - * @param AssetCollection $assets |
|
41 | - * @param DomainInterface $domain |
|
42 | - * @param Registry $registry |
|
43 | - * @param EE_Currency_Config $currency_config |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - AssetCollection $assets, |
|
47 | - DomainInterface $domain, |
|
48 | - Registry $registry, |
|
49 | - EE_Currency_Config $currency_config |
|
50 | - ) { |
|
51 | - $this->currency_config = $currency_config; |
|
52 | - parent::__construct($domain, $assets, $registry); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @throws InvalidDataTypeException |
|
59 | - * @throws InvalidEntityException |
|
60 | - * @throws DuplicateCollectionIdentifierException |
|
61 | - * @throws DomainException |
|
62 | - */ |
|
63 | - public function addAssets() |
|
64 | - { |
|
65 | - $this->loadAccountingJs(); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * accounting.js for performing client-side calculations |
|
71 | - * |
|
72 | - * @throws DomainException |
|
73 | - * @throws DuplicateCollectionIdentifierException |
|
74 | - * @throws InvalidDataTypeException |
|
75 | - * @throws InvalidEntityException |
|
76 | - * @since $VID:$ |
|
77 | - */ |
|
78 | - private function loadAccountingJs() |
|
79 | - { |
|
80 | - //accounting.js library |
|
81 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
82 | - $this->addJavascript( |
|
83 | - LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
84 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
85 | - [LegacyEditorAssetManager::JS_HANDLE_UNDERSCORE], |
|
86 | - true, |
|
87 | - '0.3.2' |
|
88 | - ); |
|
89 | - |
|
90 | - $this->addJavascript( |
|
91 | - LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING, |
|
92 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
93 | - [LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
|
94 | - ) |
|
95 | - ->setInlineDataCallback( |
|
96 | - function () { |
|
97 | - wp_localize_script( |
|
98 | - LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING, |
|
99 | - 'EE_ACCOUNTING_CFG', |
|
100 | - $this->getAccountingSettings() |
|
101 | - ); |
|
102 | - } |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Returns configuration data for the accounting-js library. |
|
109 | - * |
|
110 | - * @return array |
|
111 | - * @since $VID:$ |
|
112 | - */ |
|
113 | - private function getAccountingSettings() |
|
114 | - { |
|
115 | - return [ |
|
116 | - 'currency' => [ |
|
117 | - 'symbol' => $this->currency_config->sign, |
|
118 | - 'format' => [ |
|
119 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
120 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
121 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
122 | - ], |
|
123 | - 'decimal' => $this->currency_config->dec_mrk, |
|
124 | - 'thousand' => $this->currency_config->thsnds, |
|
125 | - 'precision' => $this->currency_config->dec_plc, |
|
126 | - ], |
|
127 | - 'number' => [ |
|
128 | - 'precision' => $this->currency_config->dec_plc, |
|
129 | - 'thousand' => $this->currency_config->thsnds, |
|
130 | - 'decimal' => $this->currency_config->dec_mrk, |
|
131 | - ], |
|
132 | - ]; |
|
133 | - } |
|
27 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
28 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
29 | + const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Currency_Config $currency_config |
|
34 | + */ |
|
35 | + protected $currency_config; |
|
36 | + |
|
37 | + /** |
|
38 | + * CoreAssetRegister constructor. |
|
39 | + * |
|
40 | + * @param AssetCollection $assets |
|
41 | + * @param DomainInterface $domain |
|
42 | + * @param Registry $registry |
|
43 | + * @param EE_Currency_Config $currency_config |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + AssetCollection $assets, |
|
47 | + DomainInterface $domain, |
|
48 | + Registry $registry, |
|
49 | + EE_Currency_Config $currency_config |
|
50 | + ) { |
|
51 | + $this->currency_config = $currency_config; |
|
52 | + parent::__construct($domain, $assets, $registry); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @throws InvalidDataTypeException |
|
59 | + * @throws InvalidEntityException |
|
60 | + * @throws DuplicateCollectionIdentifierException |
|
61 | + * @throws DomainException |
|
62 | + */ |
|
63 | + public function addAssets() |
|
64 | + { |
|
65 | + $this->loadAccountingJs(); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * accounting.js for performing client-side calculations |
|
71 | + * |
|
72 | + * @throws DomainException |
|
73 | + * @throws DuplicateCollectionIdentifierException |
|
74 | + * @throws InvalidDataTypeException |
|
75 | + * @throws InvalidEntityException |
|
76 | + * @since $VID:$ |
|
77 | + */ |
|
78 | + private function loadAccountingJs() |
|
79 | + { |
|
80 | + //accounting.js library |
|
81 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
82 | + $this->addJavascript( |
|
83 | + LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
84 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
85 | + [LegacyEditorAssetManager::JS_HANDLE_UNDERSCORE], |
|
86 | + true, |
|
87 | + '0.3.2' |
|
88 | + ); |
|
89 | + |
|
90 | + $this->addJavascript( |
|
91 | + LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING, |
|
92 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
93 | + [LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
|
94 | + ) |
|
95 | + ->setInlineDataCallback( |
|
96 | + function () { |
|
97 | + wp_localize_script( |
|
98 | + LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING, |
|
99 | + 'EE_ACCOUNTING_CFG', |
|
100 | + $this->getAccountingSettings() |
|
101 | + ); |
|
102 | + } |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Returns configuration data for the accounting-js library. |
|
109 | + * |
|
110 | + * @return array |
|
111 | + * @since $VID:$ |
|
112 | + */ |
|
113 | + private function getAccountingSettings() |
|
114 | + { |
|
115 | + return [ |
|
116 | + 'currency' => [ |
|
117 | + 'symbol' => $this->currency_config->sign, |
|
118 | + 'format' => [ |
|
119 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
120 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
121 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
122 | + ], |
|
123 | + 'decimal' => $this->currency_config->dec_mrk, |
|
124 | + 'thousand' => $this->currency_config->thsnds, |
|
125 | + 'precision' => $this->currency_config->dec_plc, |
|
126 | + ], |
|
127 | + 'number' => [ |
|
128 | + 'precision' => $this->currency_config->dec_plc, |
|
129 | + 'thousand' => $this->currency_config->thsnds, |
|
130 | + 'decimal' => $this->currency_config->dec_mrk, |
|
131 | + ], |
|
132 | + ]; |
|
133 | + } |
|
134 | 134 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | // @link http://josscrowcroft.github.io/accounting.js/ |
82 | 82 | $this->addJavascript( |
83 | 83 | LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
84 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
84 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
85 | 85 | [LegacyEditorAssetManager::JS_HANDLE_UNDERSCORE], |
86 | 86 | true, |
87 | 87 | '0.3.2' |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | |
90 | 90 | $this->addJavascript( |
91 | 91 | LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING, |
92 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
92 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
93 | 93 | [LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
94 | 94 | ) |
95 | 95 | ->setInlineDataCallback( |
96 | - function () { |
|
96 | + function() { |
|
97 | 97 | wp_localize_script( |
98 | 98 | LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING, |
99 | 99 | 'EE_ACCOUNTING_CFG', |
@@ -18,55 +18,55 @@ |
||
18 | 18 | */ |
19 | 19 | class EspressoEditorAssetManager extends ReactAssetManager |
20 | 20 | { |
21 | - const JS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
22 | - const CSS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
21 | + const JS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
22 | + const CSS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @throws InvalidDataTypeException |
|
26 | - * @throws InvalidEntityException |
|
27 | - * @throws DuplicateCollectionIdentifierException |
|
28 | - * @throws DomainException |
|
29 | - */ |
|
30 | - public function addAssets() |
|
31 | - { |
|
32 | - parent::addAssets(); |
|
33 | - $this->registerJavascript(); |
|
34 | - $this->registerStyleSheets(); |
|
35 | - } |
|
24 | + /** |
|
25 | + * @throws InvalidDataTypeException |
|
26 | + * @throws InvalidEntityException |
|
27 | + * @throws DuplicateCollectionIdentifierException |
|
28 | + * @throws DomainException |
|
29 | + */ |
|
30 | + public function addAssets() |
|
31 | + { |
|
32 | + parent::addAssets(); |
|
33 | + $this->registerJavascript(); |
|
34 | + $this->registerStyleSheets(); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * Register javascript assets |
|
40 | - * |
|
41 | - * @throws InvalidDataTypeException |
|
42 | - * @throws InvalidEntityException |
|
43 | - * @throws DuplicateCollectionIdentifierException |
|
44 | - * @throws DomainException |
|
45 | - */ |
|
46 | - private function registerJavascript() |
|
47 | - { |
|
48 | - $this->addJs( |
|
49 | - EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
|
50 | - [ |
|
51 | - ReactAssetManager::JS_HANDLE_REACT, |
|
52 | - ReactAssetManager::JS_HANDLE_REACT_DOM, |
|
53 | - 'wp-i18n', |
|
54 | - CoreAssetManager::JS_HANDLE_JS_CORE, |
|
55 | - ] |
|
56 | - )->setRequiresTranslation(); |
|
57 | - } |
|
38 | + /** |
|
39 | + * Register javascript assets |
|
40 | + * |
|
41 | + * @throws InvalidDataTypeException |
|
42 | + * @throws InvalidEntityException |
|
43 | + * @throws DuplicateCollectionIdentifierException |
|
44 | + * @throws DomainException |
|
45 | + */ |
|
46 | + private function registerJavascript() |
|
47 | + { |
|
48 | + $this->addJs( |
|
49 | + EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
|
50 | + [ |
|
51 | + ReactAssetManager::JS_HANDLE_REACT, |
|
52 | + ReactAssetManager::JS_HANDLE_REACT_DOM, |
|
53 | + 'wp-i18n', |
|
54 | + CoreAssetManager::JS_HANDLE_JS_CORE, |
|
55 | + ] |
|
56 | + )->setRequiresTranslation(); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Register CSS assets. |
|
62 | - * |
|
63 | - * @throws DuplicateCollectionIdentifierException |
|
64 | - * @throws InvalidDataTypeException |
|
65 | - * @throws InvalidEntityException |
|
66 | - * @throws DomainException |
|
67 | - */ |
|
68 | - private function registerStyleSheets() |
|
69 | - { |
|
70 | - $this->addCss(EspressoEditorAssetManager::CSS_HANDLE_EDITOR); |
|
71 | - } |
|
60 | + /** |
|
61 | + * Register CSS assets. |
|
62 | + * |
|
63 | + * @throws DuplicateCollectionIdentifierException |
|
64 | + * @throws InvalidDataTypeException |
|
65 | + * @throws InvalidEntityException |
|
66 | + * @throws DomainException |
|
67 | + */ |
|
68 | + private function registerStyleSheets() |
|
69 | + { |
|
70 | + $this->addCss(EspressoEditorAssetManager::CSS_HANDLE_EDITOR); |
|
71 | + } |
|
72 | 72 | } |
@@ -32,297 +32,297 @@ |
||
32 | 32 | class CoreAssetManager extends AssetManager |
33 | 33 | { |
34 | 34 | |
35 | - // WordPress core / Third party JS asset handles |
|
36 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
37 | - |
|
38 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
39 | - |
|
40 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
41 | - |
|
42 | - const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
43 | - |
|
44 | - const JS_HANDLE_CORE = 'espresso_core'; |
|
45 | - |
|
46 | - const JS_HANDLE_I18N = 'eei18n'; |
|
47 | - |
|
48 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
49 | - |
|
50 | - const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
51 | - |
|
52 | - // EE CSS assets handles |
|
53 | - const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
54 | - |
|
55 | - const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EE_Currency_Config $currency_config |
|
59 | - */ |
|
60 | - protected $currency_config; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var EE_Template_Config $template_config |
|
64 | - */ |
|
65 | - protected $template_config; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * CoreAssetRegister constructor. |
|
70 | - * |
|
71 | - * @param AssetCollection $assets |
|
72 | - * @param EE_Currency_Config $currency_config |
|
73 | - * @param EE_Template_Config $template_config |
|
74 | - * @param DomainInterface $domain |
|
75 | - * @param Registry $registry |
|
76 | - */ |
|
77 | - public function __construct( |
|
78 | - AssetCollection $assets, |
|
79 | - EE_Currency_Config $currency_config, |
|
80 | - EE_Template_Config $template_config, |
|
81 | - DomainInterface $domain, |
|
82 | - Registry $registry |
|
83 | - ) { |
|
84 | - $this->currency_config = $currency_config; |
|
85 | - $this->template_config = $template_config; |
|
86 | - parent::__construct($domain, $assets, $registry); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @since 4.9.62.p |
|
92 | - * @throws DomainException |
|
93 | - * @throws DuplicateCollectionIdentifierException |
|
94 | - * @throws InvalidArgumentException |
|
95 | - * @throws InvalidDataTypeException |
|
96 | - * @throws InvalidEntityException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - */ |
|
99 | - public function addAssets() |
|
100 | - { |
|
101 | - $this->addJavascriptFiles(); |
|
102 | - $this->addStylesheetFiles(); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @since 4.9.62.p |
|
108 | - * @throws DomainException |
|
109 | - * @throws DuplicateCollectionIdentifierException |
|
110 | - * @throws InvalidArgumentException |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - * @throws InvalidEntityException |
|
113 | - * @throws InvalidInterfaceException |
|
114 | - */ |
|
115 | - public function addJavascriptFiles() |
|
116 | - { |
|
117 | - $this->loadCoreJs(); |
|
118 | - $this->loadJqueryValidate(); |
|
119 | - add_action( |
|
120 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
121 | - array($this, 'loadQtipJs') |
|
122 | - ); |
|
123 | - $this->registerAdminAssets(); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @throws DuplicateCollectionIdentifierException |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - * @throws InvalidEntityException |
|
131 | - * @throws DomainException |
|
132 | - * @since 4.9.62.p |
|
133 | - */ |
|
134 | - public function addStylesheetFiles() |
|
135 | - { |
|
136 | - $this->loadCoreCss(); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * core default javascript |
|
142 | - * |
|
143 | - * @since 4.9.62.p |
|
144 | - * @throws DomainException |
|
145 | - * @throws DuplicateCollectionIdentifierException |
|
146 | - * @throws InvalidArgumentException |
|
147 | - * @throws InvalidDataTypeException |
|
148 | - * @throws InvalidEntityException |
|
149 | - * @throws InvalidInterfaceException |
|
150 | - */ |
|
151 | - private function loadCoreJs() |
|
152 | - { |
|
153 | - $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR); |
|
154 | - $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
155 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
156 | - $this->registry->addData( |
|
157 | - 'paths', |
|
158 | - array( |
|
159 | - 'base_rest_route' => rest_url(), |
|
160 | - 'rest_route' => rest_url('ee/v4.8.36/'), |
|
161 | - 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
162 | - 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
163 | - 'site_url' => site_url('/'), |
|
164 | - 'admin_url' => admin_url('/'), |
|
165 | - ) |
|
166 | - ); |
|
167 | - // Event Espresso brand name |
|
168 | - $this->registry->addData('brandName', Domain::brandName()); |
|
169 | - /** site formatting values **/ |
|
170 | - $this->registry->addData( |
|
171 | - 'site_formats', |
|
172 | - array( |
|
173 | - 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
174 | - ) |
|
175 | - ); |
|
176 | - /** currency data **/ |
|
177 | - $this->registry->addData( |
|
178 | - 'currency_config', |
|
179 | - $this->getCurrencySettings() |
|
180 | - ); |
|
181 | - /** site timezone */ |
|
182 | - $this->registry->addData( |
|
183 | - 'default_timezone', |
|
184 | - array( |
|
185 | - 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
186 | - 'string' => get_option('timezone_string'), |
|
187 | - 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
188 | - ) |
|
189 | - ); |
|
190 | - /** site locale (user locale if user logged in) */ |
|
191 | - $this->registry->addData( |
|
192 | - 'locale', |
|
193 | - array( |
|
194 | - 'user' => get_user_locale(), |
|
195 | - 'site' => get_locale() |
|
196 | - ) |
|
197 | - ); |
|
198 | - |
|
199 | - $this->addJavascript( |
|
200 | - CoreAssetManager::JS_HANDLE_CORE, |
|
201 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
202 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
203 | - ) |
|
204 | - ->setInlineDataCallback( |
|
205 | - static function () { |
|
206 | - wp_localize_script( |
|
207 | - CoreAssetManager::JS_HANDLE_CORE, |
|
208 | - CoreAssetManager::JS_HANDLE_I18N, |
|
209 | - EE_Registry::$i18n_js_strings |
|
210 | - ); |
|
211 | - } |
|
212 | - ); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Returns configuration data for the js Currency VO. |
|
219 | - * @since 4.9.71.p |
|
220 | - * @return array |
|
221 | - */ |
|
222 | - private function getCurrencySettings() |
|
223 | - { |
|
224 | - return array( |
|
225 | - 'code' => $this->currency_config->code, |
|
226 | - 'singularLabel' => $this->currency_config->name, |
|
227 | - 'pluralLabel' => $this->currency_config->plural, |
|
228 | - 'sign' => $this->currency_config->sign, |
|
229 | - 'signB4' => $this->currency_config->sign_b4, |
|
230 | - 'decimalPlaces' => $this->currency_config->dec_plc, |
|
231 | - 'decimalMark' => $this->currency_config->dec_mrk, |
|
232 | - 'thousandsSeparator' => $this->currency_config->thsnds, |
|
233 | - ); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @throws DuplicateCollectionIdentifierException |
|
239 | - * @throws InvalidDataTypeException |
|
240 | - * @throws InvalidEntityException |
|
241 | - * @throws DomainException |
|
242 | - * @since 4.9.62.p |
|
243 | - */ |
|
244 | - private function loadCoreCss() |
|
245 | - { |
|
246 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
247 | - $this->addStylesheet( |
|
248 | - CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
249 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
250 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
251 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
252 | - array('dashicons') |
|
253 | - ); |
|
254 | - //Load custom style sheet if available |
|
255 | - if ($this->template_config->custom_style_sheet !== null) { |
|
256 | - $this->addStylesheet( |
|
257 | - CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
258 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
259 | - array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
260 | - ); |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * jQuery Validate for form validation |
|
268 | - * |
|
269 | - * @since 4.9.62.p |
|
270 | - * @throws DomainException |
|
271 | - * @throws DuplicateCollectionIdentifierException |
|
272 | - * @throws InvalidDataTypeException |
|
273 | - * @throws InvalidEntityException |
|
274 | - */ |
|
275 | - private function loadJqueryValidate() |
|
276 | - { |
|
277 | - $this->addJavascript( |
|
278 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
279 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
280 | - array(CoreAssetManager::JS_HANDLE_JQUERY), |
|
281 | - true, |
|
282 | - '1.15.0' |
|
283 | - ); |
|
284 | - |
|
285 | - $this->addJavascript( |
|
286 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
287 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
288 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
|
289 | - true, |
|
290 | - '1.15.0' |
|
291 | - ); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * registers assets for cleaning your ears |
|
297 | - * |
|
298 | - * @param JavascriptAsset $script |
|
299 | - */ |
|
300 | - public function loadQtipJs(JavascriptAsset $script) |
|
301 | - { |
|
302 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
303 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
304 | - if ( |
|
305 | - $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
306 | - && apply_filters('FHEE_load_qtip', false) |
|
307 | - ) { |
|
308 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * assets that are used in the WordPress admin |
|
315 | - * |
|
316 | - * @throws DuplicateCollectionIdentifierException |
|
317 | - * @throws InvalidDataTypeException |
|
318 | - * @throws InvalidEntityException |
|
319 | - * @throws DomainException |
|
320 | - * @since 4.9.62.p |
|
321 | - */ |
|
322 | - private function registerAdminAssets() |
|
323 | - { |
|
324 | - $this->addJs(CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation(); |
|
325 | - // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle. |
|
326 | - $this->addCss(CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE); |
|
327 | - } |
|
35 | + // WordPress core / Third party JS asset handles |
|
36 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
37 | + |
|
38 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
39 | + |
|
40 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
41 | + |
|
42 | + const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
43 | + |
|
44 | + const JS_HANDLE_CORE = 'espresso_core'; |
|
45 | + |
|
46 | + const JS_HANDLE_I18N = 'eei18n'; |
|
47 | + |
|
48 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
49 | + |
|
50 | + const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
51 | + |
|
52 | + // EE CSS assets handles |
|
53 | + const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
54 | + |
|
55 | + const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EE_Currency_Config $currency_config |
|
59 | + */ |
|
60 | + protected $currency_config; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var EE_Template_Config $template_config |
|
64 | + */ |
|
65 | + protected $template_config; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * CoreAssetRegister constructor. |
|
70 | + * |
|
71 | + * @param AssetCollection $assets |
|
72 | + * @param EE_Currency_Config $currency_config |
|
73 | + * @param EE_Template_Config $template_config |
|
74 | + * @param DomainInterface $domain |
|
75 | + * @param Registry $registry |
|
76 | + */ |
|
77 | + public function __construct( |
|
78 | + AssetCollection $assets, |
|
79 | + EE_Currency_Config $currency_config, |
|
80 | + EE_Template_Config $template_config, |
|
81 | + DomainInterface $domain, |
|
82 | + Registry $registry |
|
83 | + ) { |
|
84 | + $this->currency_config = $currency_config; |
|
85 | + $this->template_config = $template_config; |
|
86 | + parent::__construct($domain, $assets, $registry); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @since 4.9.62.p |
|
92 | + * @throws DomainException |
|
93 | + * @throws DuplicateCollectionIdentifierException |
|
94 | + * @throws InvalidArgumentException |
|
95 | + * @throws InvalidDataTypeException |
|
96 | + * @throws InvalidEntityException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + */ |
|
99 | + public function addAssets() |
|
100 | + { |
|
101 | + $this->addJavascriptFiles(); |
|
102 | + $this->addStylesheetFiles(); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @since 4.9.62.p |
|
108 | + * @throws DomainException |
|
109 | + * @throws DuplicateCollectionIdentifierException |
|
110 | + * @throws InvalidArgumentException |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + * @throws InvalidEntityException |
|
113 | + * @throws InvalidInterfaceException |
|
114 | + */ |
|
115 | + public function addJavascriptFiles() |
|
116 | + { |
|
117 | + $this->loadCoreJs(); |
|
118 | + $this->loadJqueryValidate(); |
|
119 | + add_action( |
|
120 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
121 | + array($this, 'loadQtipJs') |
|
122 | + ); |
|
123 | + $this->registerAdminAssets(); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @throws DuplicateCollectionIdentifierException |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + * @throws InvalidEntityException |
|
131 | + * @throws DomainException |
|
132 | + * @since 4.9.62.p |
|
133 | + */ |
|
134 | + public function addStylesheetFiles() |
|
135 | + { |
|
136 | + $this->loadCoreCss(); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * core default javascript |
|
142 | + * |
|
143 | + * @since 4.9.62.p |
|
144 | + * @throws DomainException |
|
145 | + * @throws DuplicateCollectionIdentifierException |
|
146 | + * @throws InvalidArgumentException |
|
147 | + * @throws InvalidDataTypeException |
|
148 | + * @throws InvalidEntityException |
|
149 | + * @throws InvalidInterfaceException |
|
150 | + */ |
|
151 | + private function loadCoreJs() |
|
152 | + { |
|
153 | + $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR); |
|
154 | + $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
155 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
156 | + $this->registry->addData( |
|
157 | + 'paths', |
|
158 | + array( |
|
159 | + 'base_rest_route' => rest_url(), |
|
160 | + 'rest_route' => rest_url('ee/v4.8.36/'), |
|
161 | + 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
162 | + 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
163 | + 'site_url' => site_url('/'), |
|
164 | + 'admin_url' => admin_url('/'), |
|
165 | + ) |
|
166 | + ); |
|
167 | + // Event Espresso brand name |
|
168 | + $this->registry->addData('brandName', Domain::brandName()); |
|
169 | + /** site formatting values **/ |
|
170 | + $this->registry->addData( |
|
171 | + 'site_formats', |
|
172 | + array( |
|
173 | + 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
174 | + ) |
|
175 | + ); |
|
176 | + /** currency data **/ |
|
177 | + $this->registry->addData( |
|
178 | + 'currency_config', |
|
179 | + $this->getCurrencySettings() |
|
180 | + ); |
|
181 | + /** site timezone */ |
|
182 | + $this->registry->addData( |
|
183 | + 'default_timezone', |
|
184 | + array( |
|
185 | + 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
186 | + 'string' => get_option('timezone_string'), |
|
187 | + 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
188 | + ) |
|
189 | + ); |
|
190 | + /** site locale (user locale if user logged in) */ |
|
191 | + $this->registry->addData( |
|
192 | + 'locale', |
|
193 | + array( |
|
194 | + 'user' => get_user_locale(), |
|
195 | + 'site' => get_locale() |
|
196 | + ) |
|
197 | + ); |
|
198 | + |
|
199 | + $this->addJavascript( |
|
200 | + CoreAssetManager::JS_HANDLE_CORE, |
|
201 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
202 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
203 | + ) |
|
204 | + ->setInlineDataCallback( |
|
205 | + static function () { |
|
206 | + wp_localize_script( |
|
207 | + CoreAssetManager::JS_HANDLE_CORE, |
|
208 | + CoreAssetManager::JS_HANDLE_I18N, |
|
209 | + EE_Registry::$i18n_js_strings |
|
210 | + ); |
|
211 | + } |
|
212 | + ); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Returns configuration data for the js Currency VO. |
|
219 | + * @since 4.9.71.p |
|
220 | + * @return array |
|
221 | + */ |
|
222 | + private function getCurrencySettings() |
|
223 | + { |
|
224 | + return array( |
|
225 | + 'code' => $this->currency_config->code, |
|
226 | + 'singularLabel' => $this->currency_config->name, |
|
227 | + 'pluralLabel' => $this->currency_config->plural, |
|
228 | + 'sign' => $this->currency_config->sign, |
|
229 | + 'signB4' => $this->currency_config->sign_b4, |
|
230 | + 'decimalPlaces' => $this->currency_config->dec_plc, |
|
231 | + 'decimalMark' => $this->currency_config->dec_mrk, |
|
232 | + 'thousandsSeparator' => $this->currency_config->thsnds, |
|
233 | + ); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @throws DuplicateCollectionIdentifierException |
|
239 | + * @throws InvalidDataTypeException |
|
240 | + * @throws InvalidEntityException |
|
241 | + * @throws DomainException |
|
242 | + * @since 4.9.62.p |
|
243 | + */ |
|
244 | + private function loadCoreCss() |
|
245 | + { |
|
246 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
247 | + $this->addStylesheet( |
|
248 | + CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
249 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
250 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
251 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
252 | + array('dashicons') |
|
253 | + ); |
|
254 | + //Load custom style sheet if available |
|
255 | + if ($this->template_config->custom_style_sheet !== null) { |
|
256 | + $this->addStylesheet( |
|
257 | + CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
258 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
259 | + array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
260 | + ); |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * jQuery Validate for form validation |
|
268 | + * |
|
269 | + * @since 4.9.62.p |
|
270 | + * @throws DomainException |
|
271 | + * @throws DuplicateCollectionIdentifierException |
|
272 | + * @throws InvalidDataTypeException |
|
273 | + * @throws InvalidEntityException |
|
274 | + */ |
|
275 | + private function loadJqueryValidate() |
|
276 | + { |
|
277 | + $this->addJavascript( |
|
278 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
279 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
280 | + array(CoreAssetManager::JS_HANDLE_JQUERY), |
|
281 | + true, |
|
282 | + '1.15.0' |
|
283 | + ); |
|
284 | + |
|
285 | + $this->addJavascript( |
|
286 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
287 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
288 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
|
289 | + true, |
|
290 | + '1.15.0' |
|
291 | + ); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * registers assets for cleaning your ears |
|
297 | + * |
|
298 | + * @param JavascriptAsset $script |
|
299 | + */ |
|
300 | + public function loadQtipJs(JavascriptAsset $script) |
|
301 | + { |
|
302 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
303 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
304 | + if ( |
|
305 | + $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
306 | + && apply_filters('FHEE_load_qtip', false) |
|
307 | + ) { |
|
308 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * assets that are used in the WordPress admin |
|
315 | + * |
|
316 | + * @throws DuplicateCollectionIdentifierException |
|
317 | + * @throws InvalidDataTypeException |
|
318 | + * @throws InvalidEntityException |
|
319 | + * @throws DomainException |
|
320 | + * @since 4.9.62.p |
|
321 | + */ |
|
322 | + private function registerAdminAssets() |
|
323 | + { |
|
324 | + $this->addJs(CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation(); |
|
325 | + // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle. |
|
326 | + $this->addCss(CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE); |
|
327 | + } |
|
328 | 328 | } |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | |
199 | 199 | $this->addJavascript( |
200 | 200 | CoreAssetManager::JS_HANDLE_CORE, |
201 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
201 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
202 | 202 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
203 | 203 | ) |
204 | 204 | ->setInlineDataCallback( |
205 | - static function () { |
|
205 | + static function() { |
|
206 | 206 | wp_localize_script( |
207 | 207 | CoreAssetManager::JS_HANDLE_CORE, |
208 | 208 | CoreAssetManager::JS_HANDLE_I18N, |
@@ -246,16 +246,16 @@ discard block |
||
246 | 246 | if ($this->template_config->enable_default_style && ! is_admin()) { |
247 | 247 | $this->addStylesheet( |
248 | 248 | CoreAssetManager::CSS_HANDLE_DEFAULT, |
249 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
249 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
250 | 250 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
251 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
251 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
252 | 252 | array('dashicons') |
253 | 253 | ); |
254 | 254 | //Load custom style sheet if available |
255 | 255 | if ($this->template_config->custom_style_sheet !== null) { |
256 | 256 | $this->addStylesheet( |
257 | 257 | CoreAssetManager::CSS_HANDLE_CUSTOM, |
258 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
258 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
259 | 259 | array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
260 | 260 | ); |
261 | 261 | } |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | { |
277 | 277 | $this->addJavascript( |
278 | 278 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
279 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
279 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
280 | 280 | array(CoreAssetManager::JS_HANDLE_JQUERY), |
281 | 281 | true, |
282 | 282 | '1.15.0' |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | |
285 | 285 | $this->addJavascript( |
286 | 286 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
287 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
287 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
288 | 288 | array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
289 | 289 | true, |
290 | 290 | '1.15.0' |
@@ -19,32 +19,32 @@ |
||
19 | 19 | */ |
20 | 20 | class ReactAssetManager extends AssetManager |
21 | 21 | { |
22 | - const REACT_VERSION = '16.13.1'; |
|
23 | - |
|
24 | - const JS_HANDLE_REACT = 'react'; |
|
25 | - |
|
26 | - const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @throws InvalidDataTypeException |
|
31 | - * @throws InvalidEntityException |
|
32 | - * @throws DuplicateCollectionIdentifierException |
|
33 | - * @throws DomainException |
|
34 | - */ |
|
35 | - public function addAssets() |
|
36 | - { |
|
37 | - $this->addVendorJavascript( |
|
38 | - ReactAssetManager::JS_HANDLE_REACT, |
|
39 | - [], |
|
40 | - true, |
|
41 | - ReactAssetManager::REACT_VERSION |
|
42 | - ); |
|
43 | - $this->addVendorJavascript( |
|
44 | - ReactAssetManager::JS_HANDLE_REACT_DOM, |
|
45 | - [ReactAssetManager::JS_HANDLE_REACT], |
|
46 | - true, |
|
47 | - ReactAssetManager::REACT_VERSION |
|
48 | - ); |
|
49 | - } |
|
22 | + const REACT_VERSION = '16.13.1'; |
|
23 | + |
|
24 | + const JS_HANDLE_REACT = 'react'; |
|
25 | + |
|
26 | + const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @throws InvalidDataTypeException |
|
31 | + * @throws InvalidEntityException |
|
32 | + * @throws DuplicateCollectionIdentifierException |
|
33 | + * @throws DomainException |
|
34 | + */ |
|
35 | + public function addAssets() |
|
36 | + { |
|
37 | + $this->addVendorJavascript( |
|
38 | + ReactAssetManager::JS_HANDLE_REACT, |
|
39 | + [], |
|
40 | + true, |
|
41 | + ReactAssetManager::REACT_VERSION |
|
42 | + ); |
|
43 | + $this->addVendorJavascript( |
|
44 | + ReactAssetManager::JS_HANDLE_REACT_DOM, |
|
45 | + [ReactAssetManager::JS_HANDLE_REACT], |
|
46 | + true, |
|
47 | + ReactAssetManager::REACT_VERSION |
|
48 | + ); |
|
49 | + } |
|
50 | 50 | } |