@@ -17,457 +17,457 @@ |
||
17 | 17 | abstract class EE_Shortcodes extends EE_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * holds label for library |
|
22 | - * This is used for referencing the library label |
|
23 | - * |
|
24 | - * @access public |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $label; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * This property is used for referencing a short description of the library |
|
32 | - * |
|
33 | - * @access public |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $description; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
41 | - * label/description for the shortcode. |
|
42 | - * |
|
43 | - * @access protected |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $_shortcodes; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * This will hold the incoming data item sent to the parser method |
|
51 | - * |
|
52 | - * @access protected |
|
53 | - * @var mixed (array|object) |
|
54 | - */ |
|
55 | - protected $_data; |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * some shortcodes may require extra data to parse. This property is provided for that. |
|
60 | - * |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - protected $_extra_data; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * EE_messenger used to generate the template being parsed. |
|
68 | - * |
|
69 | - * @since 4.5.0 |
|
70 | - * @var EE_messenger |
|
71 | - */ |
|
72 | - protected $_messenger; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * message type used to generate the template being parsed. |
|
77 | - * |
|
78 | - * @since 4.5.0 |
|
79 | - * @var EE_message_type |
|
80 | - */ |
|
81 | - protected $_message_type; |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * context used for the template being parsed |
|
86 | - * |
|
87 | - * @since 4.5.0 |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - protected $_context; |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Specific Message Template Group ID |
|
95 | - * |
|
96 | - * @since 4.5.0 |
|
97 | - * @var int |
|
98 | - */ |
|
99 | - protected $_GRP_ID; |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @since 4.9.0 |
|
104 | - * @type EE_Message |
|
105 | - */ |
|
106 | - protected $_message; |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
111 | - * shortcodes |
|
112 | - * |
|
113 | - * @var EEH_Parse_Shortcodes |
|
114 | - */ |
|
115 | - protected $_shortcode_helper; |
|
116 | - |
|
117 | - |
|
118 | - public function __construct() |
|
119 | - { |
|
120 | - $this->_set_defaults(); |
|
121 | - $this->_init_props(); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
127 | - * method |
|
128 | - */ |
|
129 | - private function _set_defaults() |
|
130 | - { |
|
131 | - $this->name = $this->description = ''; |
|
132 | - $this->_shortcodes = array(); |
|
133 | - $this->_set_shortcode_helper(); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * loads an instance of the EE_Shortcode_Parser helper when requested |
|
139 | - */ |
|
140 | - protected function _set_shortcode_helper() |
|
141 | - { |
|
142 | - // get shortcode_replace instance- set when _get_messages is called in child... |
|
143 | - $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - public function get_shortcode_helper() |
|
148 | - { |
|
149 | - if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
150 | - $this->_set_shortcode_helper(); |
|
151 | - } |
|
152 | - return $this->_shortcode_helper; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
158 | - * classes if necessary (see EE_Questions_Answers for example) |
|
159 | - * |
|
160 | - * @param string $shortcode incoming shortcode to be parsed |
|
161 | - * @param mixed (object|array) $data incoming data to be be used for parsing |
|
162 | - * @param mixed (object|array) $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
163 | - * @return string parsed shortcode. |
|
164 | - */ |
|
165 | - public function parser($shortcode, $data, $extra_data = array()) |
|
166 | - { |
|
167 | - |
|
168 | - // filter setup shortcodes |
|
169 | - $this->_shortcodes = $this->get_shortcodes(); |
|
170 | - |
|
171 | - // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
172 | - $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
173 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
174 | - |
|
175 | - // first we want to make sure this is a valid shortcode |
|
176 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
177 | - return false; |
|
178 | - } //get out, this parser doesn't handle the incoming shortcode. |
|
179 | - $this->_data = $data; |
|
180 | - $this->_extra_data = $extra_data; |
|
181 | - $this->_set_messages_properties(); |
|
182 | - $parsed = apply_filters( |
|
183 | - 'FHEE__' . get_class($this) . '__parser_after', |
|
184 | - $this->_parser($shortcode), |
|
185 | - $shortcode, |
|
186 | - $data, |
|
187 | - $extra_data, |
|
188 | - $this |
|
189 | - ); |
|
190 | - |
|
191 | - // note the below filter applies to ALL shortcode parsers... be careful! |
|
192 | - $parsed = apply_filters('FHEE__EE_Shortcodes__parser_after', $parsed, $shortcode, $data, $extra_data, $this); |
|
193 | - return $parsed; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * This method just returns the shortcodes in the $_shortcodes array property. |
|
199 | - * |
|
200 | - * @access public |
|
201 | - * @return array array of shortcodes => description pairs |
|
202 | - */ |
|
203 | - public function get_shortcodes() |
|
204 | - { |
|
205 | - $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
206 | - |
|
207 | - // note the below filter applies to ALL shortcode parsers... be careful! |
|
208 | - $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
209 | - |
|
210 | - return $this->_shortcodes; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
216 | - * |
|
217 | - * @abstract |
|
218 | - * @access protected |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - abstract protected function _init_props(); |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
226 | - * will have to take care of handling. |
|
227 | - * |
|
228 | - * @abstract |
|
229 | - * @access protected |
|
230 | - * @param string $shortcode the shortcode to be parsed. |
|
231 | - * @param mixed (object|array) $data incoming data for the parser. The data could be either an object or |
|
232 | - * array because there are some shortcodes that might be replaced by prepared data that |
|
233 | - * has multiple items in a list (i.e. list of attendees in an event and we're showing |
|
234 | - * fname/lname for each attendee). In this case data will be in an array. Otherwise |
|
235 | - * the data shoudl be in a properly formatted object. The |
|
236 | - * EEH_Parse_Shortcodes.helper.php describes the data object we're expecting. |
|
237 | - * @return string parsed shortcode |
|
238 | - */ |
|
239 | - abstract protected function _parser($shortcode); |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
244 | - * meets their requirements |
|
245 | - * |
|
246 | - * @return mixed (void|exception) If validation fails we'll throw an exception. |
|
247 | - */ |
|
248 | - protected function _validate_list_requirements() |
|
249 | - { |
|
250 | - |
|
251 | - // first test to make sure we've got an array! |
|
252 | - if (! is_array($this->_data)) { |
|
253 | - throw new EE_Error( |
|
254 | - sprintf( |
|
255 | - __( |
|
256 | - 'Expecting an array for the data sent to %s. Instead it was %s', |
|
257 | - 'event_espresso' |
|
258 | - ), |
|
259 | - get_class($this), |
|
260 | - gettype($this->_data) |
|
261 | - ) |
|
262 | - ); |
|
263 | - } |
|
264 | - |
|
265 | - // next test to make sure we've got the required template in the index! |
|
266 | - if (! isset($this->_data['template'])) { |
|
267 | - throw new EE_Error( |
|
268 | - sprintf( |
|
269 | - __( |
|
270 | - 'The incoming data does not have the required template index in its array', |
|
271 | - 'event_espresso' |
|
272 | - ) |
|
273 | - ) |
|
274 | - ); |
|
275 | - } |
|
276 | - |
|
277 | - // next test to make sure we've got got a data index in the incoming data array |
|
278 | - if (! isset($this->_data['data'])) { |
|
279 | - throw new EE_Error( |
|
280 | - __( |
|
281 | - 'The incoming data does not have the required data index in its array', |
|
282 | - 'event_espresso' |
|
283 | - ) |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - // all is well let's make sure _extra_data always has the values needed. |
|
288 | - // let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
289 | - if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
290 | - $this->_extra_data['data'] = $this->_data['data']; |
|
291 | - $this->_extra_data['template'] = $this->_data['template']; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * This returns any attributes that may be existing on an EE_Shortcode |
|
298 | - * |
|
299 | - * @since 4.5.0 |
|
300 | - * @param string $shortcode incoming shortcode |
|
301 | - * @return array An array with the attributes |
|
302 | - */ |
|
303 | - protected function _get_shortcode_attrs($shortcode) |
|
304 | - { |
|
305 | - // make sure the required wp helper function is present |
|
306 | - // require the shortcode file if necessary |
|
307 | - if (! function_exists('shortcode_parse_atts')) { |
|
308 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
309 | - } |
|
310 | - |
|
311 | - // let's get any attributes that may be present and set the defaults. |
|
312 | - $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
313 | - return shortcode_parse_atts($shortcode_to_parse); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
319 | - * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever |
|
320 | - * conditions existed in the opening tag. This method handles parsing the actual template to show/hide this |
|
321 | - * conditional content. |
|
322 | - * |
|
323 | - * @since 4.9.32 |
|
324 | - * |
|
325 | - * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
326 | - * @param bool $show true means the opening and closing tags are removed and the content is left showing, |
|
327 | - * false means the opening and closing tags and the contained content are removed. |
|
328 | - * @return string The template for the shortcode is returned. |
|
329 | - */ |
|
330 | - protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
|
331 | - { |
|
332 | - // first let's get all the matches in the template for this particular shortcode. |
|
333 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
334 | - |
|
335 | - if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
|
336 | - // we need to hide all instances of the matches |
|
337 | - foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
338 | - $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
339 | - $replacement = $show ? $matches[4][ $index ] : ''; |
|
340 | - $this->_data['template'] = preg_replace( |
|
341 | - '~' . $content_to_show_or_hide . '~', |
|
342 | - $replacement, |
|
343 | - $this->_data['template'] |
|
344 | - ); |
|
345 | - } |
|
346 | - } |
|
347 | - // return $template |
|
348 | - return $this->_data['template']; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * This returns the regex pattern to use for conditional shortcodes parsing. |
|
354 | - * |
|
355 | - * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
356 | - * |
|
357 | - * @param $shortcode |
|
358 | - * @since 4.9.32 |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - private function _get_conditional_block_regex($shortcode) |
|
362 | - { |
|
363 | - // get just the shortcode tag for the match |
|
364 | - preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
365 | - if (empty($shortcode_tag_matches[1])) { |
|
366 | - return $this->_data['template']; |
|
367 | - } |
|
368 | - |
|
369 | - $shortcode_tag = $shortcode_tag_matches[1]; |
|
370 | - // get attributes_part_of_tag |
|
371 | - $attributes_part = preg_quote(str_replace(array($shortcode_tag, '[', ']'), '', $shortcode)); |
|
372 | - // escape |
|
373 | - $shortcode_tag = preg_quote($shortcode_tag); |
|
374 | - |
|
375 | - return |
|
376 | - '\[' // Opening Bracket |
|
377 | - . "($shortcode_tag)$attributes_part" // 1: Shortcode Name |
|
378 | - . '(?![\w-])' // Not followed by word character or hyphen |
|
379 | - . '(' // 2: Unroll the loop: Inside the opening shortcode tag |
|
380 | - . '[^\]\/]*' // Not a closing bracket or forward slash |
|
381 | - . '(?:' |
|
382 | - . '\/(?!\])' // A forward slash not followed by a closing bracket |
|
383 | - . '[^\]\/]*' // Not a closing bracket or forward slash. |
|
384 | - . ')*?' |
|
385 | - . ')' |
|
386 | - . '(?:' |
|
387 | - . '(\/)' // 3. Self closing tag ... |
|
388 | - . '\]' // ... and closing bracket |
|
389 | - . '|' |
|
390 | - . '\]' // Closing bracket |
|
391 | - . '(?:' |
|
392 | - . '(' // 4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
393 | - . '[^\[]*+' // Not an opening bracket |
|
394 | - . '(?:' |
|
395 | - . '\[(?!\/\1\])' // An opening bracket not followed by the closing shortcode tag. |
|
396 | - . '[^\[]*+' // Not an opening bracket |
|
397 | - . ')*+' |
|
398 | - . ')' |
|
399 | - . '\[\/\1\]' // Closing shortcode tag |
|
400 | - . ')?' |
|
401 | - . ')'; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * This sets the properties related to the messages system |
|
407 | - * |
|
408 | - * @since 4.5.0 |
|
409 | - * @return void |
|
410 | - */ |
|
411 | - protected function _set_messages_properties() |
|
412 | - { |
|
413 | - // should be in _extra_data |
|
414 | - if (isset($this->_extra_data['messenger'])) { |
|
415 | - $this->_messenger = $this->_extra_data['messenger']; |
|
416 | - $this->_message_type = $this->_extra_data['message_type']; |
|
417 | - $this->_context = $this->_extra_data['message'] instanceof EE_Message |
|
418 | - ? $this->_extra_data['message']->context() : ''; |
|
419 | - $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message |
|
420 | - ? $this->_extra_data['message']->GRP_ID() : 0; |
|
421 | - $this->_message = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message'] |
|
422 | - : null; |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * This returns whatever the set message type object is that was set on this shortcode parser. |
|
429 | - * |
|
430 | - * @since 4.5.0 |
|
431 | - * @return EE_message_type |
|
432 | - */ |
|
433 | - public function get_set_message_type() |
|
434 | - { |
|
435 | - return $this->_message_type; |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * This returns whatever the set messenger object is that was set on this shortcode parser |
|
441 | - * |
|
442 | - * @since 4.5.0 |
|
443 | - * @return EE_messenger |
|
444 | - */ |
|
445 | - public function get_set_messenger() |
|
446 | - { |
|
447 | - return $this->_messenger; |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * This returns whatever the set context string is on this shortcode parser. |
|
453 | - * |
|
454 | - * @since 4.5.0 |
|
455 | - * @return string |
|
456 | - */ |
|
457 | - public function get_set_context() |
|
458 | - { |
|
459 | - return $this->_context; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * This returns whatever the set EE_Message object is on this shortcode. |
|
465 | - * |
|
466 | - * @since 4.9.0 |
|
467 | - * @return EE_Message |
|
468 | - */ |
|
469 | - public function get_set_message() |
|
470 | - { |
|
471 | - return $this->_message; |
|
472 | - } |
|
20 | + /** |
|
21 | + * holds label for library |
|
22 | + * This is used for referencing the library label |
|
23 | + * |
|
24 | + * @access public |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $label; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * This property is used for referencing a short description of the library |
|
32 | + * |
|
33 | + * @access public |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $description; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
41 | + * label/description for the shortcode. |
|
42 | + * |
|
43 | + * @access protected |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $_shortcodes; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * This will hold the incoming data item sent to the parser method |
|
51 | + * |
|
52 | + * @access protected |
|
53 | + * @var mixed (array|object) |
|
54 | + */ |
|
55 | + protected $_data; |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * some shortcodes may require extra data to parse. This property is provided for that. |
|
60 | + * |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + protected $_extra_data; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * EE_messenger used to generate the template being parsed. |
|
68 | + * |
|
69 | + * @since 4.5.0 |
|
70 | + * @var EE_messenger |
|
71 | + */ |
|
72 | + protected $_messenger; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * message type used to generate the template being parsed. |
|
77 | + * |
|
78 | + * @since 4.5.0 |
|
79 | + * @var EE_message_type |
|
80 | + */ |
|
81 | + protected $_message_type; |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * context used for the template being parsed |
|
86 | + * |
|
87 | + * @since 4.5.0 |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + protected $_context; |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Specific Message Template Group ID |
|
95 | + * |
|
96 | + * @since 4.5.0 |
|
97 | + * @var int |
|
98 | + */ |
|
99 | + protected $_GRP_ID; |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @since 4.9.0 |
|
104 | + * @type EE_Message |
|
105 | + */ |
|
106 | + protected $_message; |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
111 | + * shortcodes |
|
112 | + * |
|
113 | + * @var EEH_Parse_Shortcodes |
|
114 | + */ |
|
115 | + protected $_shortcode_helper; |
|
116 | + |
|
117 | + |
|
118 | + public function __construct() |
|
119 | + { |
|
120 | + $this->_set_defaults(); |
|
121 | + $this->_init_props(); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
127 | + * method |
|
128 | + */ |
|
129 | + private function _set_defaults() |
|
130 | + { |
|
131 | + $this->name = $this->description = ''; |
|
132 | + $this->_shortcodes = array(); |
|
133 | + $this->_set_shortcode_helper(); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * loads an instance of the EE_Shortcode_Parser helper when requested |
|
139 | + */ |
|
140 | + protected function _set_shortcode_helper() |
|
141 | + { |
|
142 | + // get shortcode_replace instance- set when _get_messages is called in child... |
|
143 | + $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + public function get_shortcode_helper() |
|
148 | + { |
|
149 | + if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
150 | + $this->_set_shortcode_helper(); |
|
151 | + } |
|
152 | + return $this->_shortcode_helper; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
158 | + * classes if necessary (see EE_Questions_Answers for example) |
|
159 | + * |
|
160 | + * @param string $shortcode incoming shortcode to be parsed |
|
161 | + * @param mixed (object|array) $data incoming data to be be used for parsing |
|
162 | + * @param mixed (object|array) $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
163 | + * @return string parsed shortcode. |
|
164 | + */ |
|
165 | + public function parser($shortcode, $data, $extra_data = array()) |
|
166 | + { |
|
167 | + |
|
168 | + // filter setup shortcodes |
|
169 | + $this->_shortcodes = $this->get_shortcodes(); |
|
170 | + |
|
171 | + // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
172 | + $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
173 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
174 | + |
|
175 | + // first we want to make sure this is a valid shortcode |
|
176 | + if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
177 | + return false; |
|
178 | + } //get out, this parser doesn't handle the incoming shortcode. |
|
179 | + $this->_data = $data; |
|
180 | + $this->_extra_data = $extra_data; |
|
181 | + $this->_set_messages_properties(); |
|
182 | + $parsed = apply_filters( |
|
183 | + 'FHEE__' . get_class($this) . '__parser_after', |
|
184 | + $this->_parser($shortcode), |
|
185 | + $shortcode, |
|
186 | + $data, |
|
187 | + $extra_data, |
|
188 | + $this |
|
189 | + ); |
|
190 | + |
|
191 | + // note the below filter applies to ALL shortcode parsers... be careful! |
|
192 | + $parsed = apply_filters('FHEE__EE_Shortcodes__parser_after', $parsed, $shortcode, $data, $extra_data, $this); |
|
193 | + return $parsed; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * This method just returns the shortcodes in the $_shortcodes array property. |
|
199 | + * |
|
200 | + * @access public |
|
201 | + * @return array array of shortcodes => description pairs |
|
202 | + */ |
|
203 | + public function get_shortcodes() |
|
204 | + { |
|
205 | + $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
206 | + |
|
207 | + // note the below filter applies to ALL shortcode parsers... be careful! |
|
208 | + $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
209 | + |
|
210 | + return $this->_shortcodes; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
216 | + * |
|
217 | + * @abstract |
|
218 | + * @access protected |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + abstract protected function _init_props(); |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
226 | + * will have to take care of handling. |
|
227 | + * |
|
228 | + * @abstract |
|
229 | + * @access protected |
|
230 | + * @param string $shortcode the shortcode to be parsed. |
|
231 | + * @param mixed (object|array) $data incoming data for the parser. The data could be either an object or |
|
232 | + * array because there are some shortcodes that might be replaced by prepared data that |
|
233 | + * has multiple items in a list (i.e. list of attendees in an event and we're showing |
|
234 | + * fname/lname for each attendee). In this case data will be in an array. Otherwise |
|
235 | + * the data shoudl be in a properly formatted object. The |
|
236 | + * EEH_Parse_Shortcodes.helper.php describes the data object we're expecting. |
|
237 | + * @return string parsed shortcode |
|
238 | + */ |
|
239 | + abstract protected function _parser($shortcode); |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
244 | + * meets their requirements |
|
245 | + * |
|
246 | + * @return mixed (void|exception) If validation fails we'll throw an exception. |
|
247 | + */ |
|
248 | + protected function _validate_list_requirements() |
|
249 | + { |
|
250 | + |
|
251 | + // first test to make sure we've got an array! |
|
252 | + if (! is_array($this->_data)) { |
|
253 | + throw new EE_Error( |
|
254 | + sprintf( |
|
255 | + __( |
|
256 | + 'Expecting an array for the data sent to %s. Instead it was %s', |
|
257 | + 'event_espresso' |
|
258 | + ), |
|
259 | + get_class($this), |
|
260 | + gettype($this->_data) |
|
261 | + ) |
|
262 | + ); |
|
263 | + } |
|
264 | + |
|
265 | + // next test to make sure we've got the required template in the index! |
|
266 | + if (! isset($this->_data['template'])) { |
|
267 | + throw new EE_Error( |
|
268 | + sprintf( |
|
269 | + __( |
|
270 | + 'The incoming data does not have the required template index in its array', |
|
271 | + 'event_espresso' |
|
272 | + ) |
|
273 | + ) |
|
274 | + ); |
|
275 | + } |
|
276 | + |
|
277 | + // next test to make sure we've got got a data index in the incoming data array |
|
278 | + if (! isset($this->_data['data'])) { |
|
279 | + throw new EE_Error( |
|
280 | + __( |
|
281 | + 'The incoming data does not have the required data index in its array', |
|
282 | + 'event_espresso' |
|
283 | + ) |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + // all is well let's make sure _extra_data always has the values needed. |
|
288 | + // let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
289 | + if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
290 | + $this->_extra_data['data'] = $this->_data['data']; |
|
291 | + $this->_extra_data['template'] = $this->_data['template']; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * This returns any attributes that may be existing on an EE_Shortcode |
|
298 | + * |
|
299 | + * @since 4.5.0 |
|
300 | + * @param string $shortcode incoming shortcode |
|
301 | + * @return array An array with the attributes |
|
302 | + */ |
|
303 | + protected function _get_shortcode_attrs($shortcode) |
|
304 | + { |
|
305 | + // make sure the required wp helper function is present |
|
306 | + // require the shortcode file if necessary |
|
307 | + if (! function_exists('shortcode_parse_atts')) { |
|
308 | + require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
309 | + } |
|
310 | + |
|
311 | + // let's get any attributes that may be present and set the defaults. |
|
312 | + $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
313 | + return shortcode_parse_atts($shortcode_to_parse); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
319 | + * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever |
|
320 | + * conditions existed in the opening tag. This method handles parsing the actual template to show/hide this |
|
321 | + * conditional content. |
|
322 | + * |
|
323 | + * @since 4.9.32 |
|
324 | + * |
|
325 | + * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
326 | + * @param bool $show true means the opening and closing tags are removed and the content is left showing, |
|
327 | + * false means the opening and closing tags and the contained content are removed. |
|
328 | + * @return string The template for the shortcode is returned. |
|
329 | + */ |
|
330 | + protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
|
331 | + { |
|
332 | + // first let's get all the matches in the template for this particular shortcode. |
|
333 | + preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
334 | + |
|
335 | + if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
|
336 | + // we need to hide all instances of the matches |
|
337 | + foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
338 | + $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
339 | + $replacement = $show ? $matches[4][ $index ] : ''; |
|
340 | + $this->_data['template'] = preg_replace( |
|
341 | + '~' . $content_to_show_or_hide . '~', |
|
342 | + $replacement, |
|
343 | + $this->_data['template'] |
|
344 | + ); |
|
345 | + } |
|
346 | + } |
|
347 | + // return $template |
|
348 | + return $this->_data['template']; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * This returns the regex pattern to use for conditional shortcodes parsing. |
|
354 | + * |
|
355 | + * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
356 | + * |
|
357 | + * @param $shortcode |
|
358 | + * @since 4.9.32 |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + private function _get_conditional_block_regex($shortcode) |
|
362 | + { |
|
363 | + // get just the shortcode tag for the match |
|
364 | + preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
365 | + if (empty($shortcode_tag_matches[1])) { |
|
366 | + return $this->_data['template']; |
|
367 | + } |
|
368 | + |
|
369 | + $shortcode_tag = $shortcode_tag_matches[1]; |
|
370 | + // get attributes_part_of_tag |
|
371 | + $attributes_part = preg_quote(str_replace(array($shortcode_tag, '[', ']'), '', $shortcode)); |
|
372 | + // escape |
|
373 | + $shortcode_tag = preg_quote($shortcode_tag); |
|
374 | + |
|
375 | + return |
|
376 | + '\[' // Opening Bracket |
|
377 | + . "($shortcode_tag)$attributes_part" // 1: Shortcode Name |
|
378 | + . '(?![\w-])' // Not followed by word character or hyphen |
|
379 | + . '(' // 2: Unroll the loop: Inside the opening shortcode tag |
|
380 | + . '[^\]\/]*' // Not a closing bracket or forward slash |
|
381 | + . '(?:' |
|
382 | + . '\/(?!\])' // A forward slash not followed by a closing bracket |
|
383 | + . '[^\]\/]*' // Not a closing bracket or forward slash. |
|
384 | + . ')*?' |
|
385 | + . ')' |
|
386 | + . '(?:' |
|
387 | + . '(\/)' // 3. Self closing tag ... |
|
388 | + . '\]' // ... and closing bracket |
|
389 | + . '|' |
|
390 | + . '\]' // Closing bracket |
|
391 | + . '(?:' |
|
392 | + . '(' // 4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
393 | + . '[^\[]*+' // Not an opening bracket |
|
394 | + . '(?:' |
|
395 | + . '\[(?!\/\1\])' // An opening bracket not followed by the closing shortcode tag. |
|
396 | + . '[^\[]*+' // Not an opening bracket |
|
397 | + . ')*+' |
|
398 | + . ')' |
|
399 | + . '\[\/\1\]' // Closing shortcode tag |
|
400 | + . ')?' |
|
401 | + . ')'; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * This sets the properties related to the messages system |
|
407 | + * |
|
408 | + * @since 4.5.0 |
|
409 | + * @return void |
|
410 | + */ |
|
411 | + protected function _set_messages_properties() |
|
412 | + { |
|
413 | + // should be in _extra_data |
|
414 | + if (isset($this->_extra_data['messenger'])) { |
|
415 | + $this->_messenger = $this->_extra_data['messenger']; |
|
416 | + $this->_message_type = $this->_extra_data['message_type']; |
|
417 | + $this->_context = $this->_extra_data['message'] instanceof EE_Message |
|
418 | + ? $this->_extra_data['message']->context() : ''; |
|
419 | + $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message |
|
420 | + ? $this->_extra_data['message']->GRP_ID() : 0; |
|
421 | + $this->_message = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message'] |
|
422 | + : null; |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * This returns whatever the set message type object is that was set on this shortcode parser. |
|
429 | + * |
|
430 | + * @since 4.5.0 |
|
431 | + * @return EE_message_type |
|
432 | + */ |
|
433 | + public function get_set_message_type() |
|
434 | + { |
|
435 | + return $this->_message_type; |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * This returns whatever the set messenger object is that was set on this shortcode parser |
|
441 | + * |
|
442 | + * @since 4.5.0 |
|
443 | + * @return EE_messenger |
|
444 | + */ |
|
445 | + public function get_set_messenger() |
|
446 | + { |
|
447 | + return $this->_messenger; |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * This returns whatever the set context string is on this shortcode parser. |
|
453 | + * |
|
454 | + * @since 4.5.0 |
|
455 | + * @return string |
|
456 | + */ |
|
457 | + public function get_set_context() |
|
458 | + { |
|
459 | + return $this->_context; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * This returns whatever the set EE_Message object is on this shortcode. |
|
465 | + * |
|
466 | + * @since 4.9.0 |
|
467 | + * @return EE_Message |
|
468 | + */ |
|
469 | + public function get_set_message() |
|
470 | + { |
|
471 | + return $this->_message; |
|
472 | + } |
|
473 | 473 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | public function get_shortcode_helper() |
148 | 148 | { |
149 | - if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
149 | + if ( ! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
150 | 150 | $this->_set_shortcode_helper(); |
151 | 151 | } |
152 | 152 | return $this->_shortcode_helper; |
@@ -170,17 +170,17 @@ discard block |
||
170 | 170 | |
171 | 171 | // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
172 | 172 | $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
173 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
173 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
174 | 174 | |
175 | 175 | // first we want to make sure this is a valid shortcode |
176 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
176 | + if ( ! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
177 | 177 | return false; |
178 | 178 | } //get out, this parser doesn't handle the incoming shortcode. |
179 | 179 | $this->_data = $data; |
180 | 180 | $this->_extra_data = $extra_data; |
181 | 181 | $this->_set_messages_properties(); |
182 | 182 | $parsed = apply_filters( |
183 | - 'FHEE__' . get_class($this) . '__parser_after', |
|
183 | + 'FHEE__'.get_class($this).'__parser_after', |
|
184 | 184 | $this->_parser($shortcode), |
185 | 185 | $shortcode, |
186 | 186 | $data, |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function get_shortcodes() |
204 | 204 | { |
205 | - $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
205 | + $this->_shortcodes = apply_filters('FHEE__'.get_class($this).'__shortcodes', $this->_shortcodes, $this); |
|
206 | 206 | |
207 | 207 | // note the below filter applies to ALL shortcode parsers... be careful! |
208 | 208 | $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | { |
250 | 250 | |
251 | 251 | // first test to make sure we've got an array! |
252 | - if (! is_array($this->_data)) { |
|
252 | + if ( ! is_array($this->_data)) { |
|
253 | 253 | throw new EE_Error( |
254 | 254 | sprintf( |
255 | 255 | __( |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | // next test to make sure we've got the required template in the index! |
266 | - if (! isset($this->_data['template'])) { |
|
266 | + if ( ! isset($this->_data['template'])) { |
|
267 | 267 | throw new EE_Error( |
268 | 268 | sprintf( |
269 | 269 | __( |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | // next test to make sure we've got got a data index in the incoming data array |
278 | - if (! isset($this->_data['data'])) { |
|
278 | + if ( ! isset($this->_data['data'])) { |
|
279 | 279 | throw new EE_Error( |
280 | 280 | __( |
281 | 281 | 'The incoming data does not have the required data index in its array', |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | { |
305 | 305 | // make sure the required wp helper function is present |
306 | 306 | // require the shortcode file if necessary |
307 | - if (! function_exists('shortcode_parse_atts')) { |
|
308 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
307 | + if ( ! function_exists('shortcode_parse_atts')) { |
|
308 | + require_once(ABSPATH.WPINC.'/shortcodes.php'); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | // let's get any attributes that may be present and set the defaults. |
@@ -330,15 +330,15 @@ discard block |
||
330 | 330 | protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
331 | 331 | { |
332 | 332 | // first let's get all the matches in the template for this particular shortcode. |
333 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
333 | + preg_match_all('~'.$this->_get_conditional_block_regex($shortcode).'~', $this->_data['template'], $matches); |
|
334 | 334 | |
335 | 335 | if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
336 | 336 | // we need to hide all instances of the matches |
337 | 337 | foreach ($matches[0] as $index => $content_to_show_or_hide) { |
338 | 338 | $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
339 | - $replacement = $show ? $matches[4][ $index ] : ''; |
|
339 | + $replacement = $show ? $matches[4][$index] : ''; |
|
340 | 340 | $this->_data['template'] = preg_replace( |
341 | - '~' . $content_to_show_or_hide . '~', |
|
341 | + '~'.$content_to_show_or_hide.'~', |
|
342 | 342 | $replacement, |
343 | 343 | $this->_data['template'] |
344 | 344 | ); |
@@ -32,42 +32,42 @@ |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | |
35 | - public function __construct() |
|
36 | - { |
|
37 | - parent::__construct(); |
|
38 | - } |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + parent::__construct(); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - protected function _init_props() |
|
42 | - { |
|
43 | - $this->label = __('Event Meta Shortcodes', 'event_espresso'); |
|
44 | - $this->description = __('All shortcodes related to Event Meta data', 'event_espresso'); |
|
45 | - $this->_shortcodes = array(); |
|
46 | - } |
|
41 | + protected function _init_props() |
|
42 | + { |
|
43 | + $this->label = __('Event Meta Shortcodes', 'event_espresso'); |
|
44 | + $this->description = __('All shortcodes related to Event Meta data', 'event_espresso'); |
|
45 | + $this->_shortcodes = array(); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * We have to overload the parent parser method because of the dynamic nature of custom event meta |
|
51 | - * |
|
52 | - * @param string $shortcode Incoming shortcode |
|
53 | - * @param mixed (array|object) $data incoming data object/array |
|
54 | - * @return string parsed code. |
|
55 | - */ |
|
56 | - public function parser($shortcode, $data, $extra_data = array()) |
|
57 | - { |
|
49 | + /** |
|
50 | + * We have to overload the parent parser method because of the dynamic nature of custom event meta |
|
51 | + * |
|
52 | + * @param string $shortcode Incoming shortcode |
|
53 | + * @param mixed (array|object) $data incoming data object/array |
|
54 | + * @return string parsed code. |
|
55 | + */ |
|
56 | + public function parser($shortcode, $data, $extra_data = array()) |
|
57 | + { |
|
58 | 58 | |
59 | - // all shortcodes will be checked in the post_meta table (assuming the shortcode matches the post_meta key); |
|
60 | - if (empty($this->_data['ID'])) { |
|
61 | - return ''; |
|
62 | - } // need the event id to do anything! |
|
59 | + // all shortcodes will be checked in the post_meta table (assuming the shortcode matches the post_meta key); |
|
60 | + if (empty($this->_data['ID'])) { |
|
61 | + return ''; |
|
62 | + } // need the event id to do anything! |
|
63 | 63 | |
64 | - $meta = get_post_meta($this->_data['ID'], $shortcode, true); |
|
64 | + $meta = get_post_meta($this->_data['ID'], $shortcode, true); |
|
65 | 65 | |
66 | - return ! empty($meta) ? $meta : ''; |
|
67 | - } |
|
66 | + return ! empty($meta) ? $meta : ''; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - protected function _parser($shortcode) |
|
71 | - { |
|
72 | - } |
|
70 | + protected function _parser($shortcode) |
|
71 | + { |
|
72 | + } |
|
73 | 73 | } |
@@ -152,6 +152,6 @@ |
||
152 | 152 | private function _get_events_from_registration(EE_Registration $registration) |
153 | 153 | { |
154 | 154 | return isset($this->_extra_data['data']->registrations) |
155 | - ? array($this->_extra_data['data']->registrations[ $registration->ID() ]['evt_obj']) : array(); |
|
155 | + ? array($this->_extra_data['data']->registrations[$registration->ID()]['evt_obj']) : array(); |
|
156 | 156 | } |
157 | 157 | } |
@@ -19,153 +19,153 @@ |
||
19 | 19 | class EE_Event_List_Shortcodes extends EE_Shortcodes |
20 | 20 | { |
21 | 21 | |
22 | - public function __construct() |
|
23 | - { |
|
24 | - parent::__construct(); |
|
25 | - } |
|
26 | - |
|
27 | - |
|
28 | - protected function _init_props() |
|
29 | - { |
|
30 | - $this->label = esc_html__('Event List Shortcodes', 'event_espresso'); |
|
31 | - $this->description = esc_html__('All shortcodes specific to event lists', 'event_espresso'); |
|
32 | - $this->_shortcodes = array( |
|
33 | - '[EVENT_LIST]' => esc_html__('Will output a list of events', 'event_espresso'), |
|
34 | - ); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param string $shortcode |
|
40 | - * @return string |
|
41 | - * @throws EE_Error |
|
42 | - * @throws ReflectionException |
|
43 | - */ |
|
44 | - protected function _parser($shortcode) |
|
45 | - { |
|
46 | - switch ($shortcode) { |
|
47 | - case '[EVENT_LIST]': |
|
48 | - return $this->_get_event_list(); |
|
49 | - } |
|
50 | - return ''; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * figure out what the incoming data is and then return the appropriate parsed value. |
|
56 | - * |
|
57 | - * @return string |
|
58 | - * @throws EE_Error |
|
59 | - * @throws ReflectionException |
|
60 | - */ |
|
61 | - private function _get_event_list() |
|
62 | - { |
|
63 | - $this->_validate_list_requirements(); |
|
64 | - |
|
65 | - if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
66 | - return $this->_get_event_list_for_main(); |
|
67 | - } elseif ($this->_data['data'] instanceof EE_Registration) { |
|
68 | - return $this->_get_event_list_for_registration(); |
|
69 | - } |
|
70 | - // prevent recursive loop |
|
71 | - return ''; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * This returns the parsed event list for main template |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - private function _get_event_list_for_main() |
|
81 | - { |
|
82 | - |
|
83 | - $valid_shortcodes = array( |
|
84 | - 'event', |
|
85 | - 'attendee_list', |
|
86 | - 'ticket_list', |
|
87 | - 'datetime_list', |
|
88 | - 'venue', |
|
89 | - 'attendee', |
|
90 | - 'recipient_list', |
|
91 | - 'recipient_details', |
|
92 | - 'primary_registration_list', |
|
93 | - 'primary_registration_details', |
|
94 | - 'event_author', |
|
95 | - 'organization', |
|
96 | - ); |
|
97 | - $template = $this->_data['template']; |
|
98 | - $data = $this->_data['data']; |
|
99 | - $events = ''; |
|
100 | - |
|
101 | - // now we need to loop through the events array in EE_Messages_Addressee and send data to the EE_Parser helper. |
|
102 | - foreach ($data->events as $event) { |
|
103 | - $events .= $this->_shortcode_helper->parse_event_list_template( |
|
104 | - $template, |
|
105 | - $event['event'], |
|
106 | - $valid_shortcodes, |
|
107 | - $this->_extra_data |
|
108 | - ); |
|
109 | - } |
|
110 | - return $events; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * This returns the parsed event list for an attendee |
|
116 | - * |
|
117 | - * @return string |
|
118 | - * @throws EE_Error |
|
119 | - * @throws ReflectionException |
|
120 | - */ |
|
121 | - private function _get_event_list_for_registration() |
|
122 | - { |
|
123 | - $valid_shortcodes = array( |
|
124 | - 'event', |
|
125 | - 'ticket_list', |
|
126 | - 'datetime_list', |
|
127 | - 'attendee', |
|
128 | - 'event_author', |
|
129 | - 'recipient_details', |
|
130 | - 'recipient_list', |
|
131 | - 'venue', |
|
132 | - 'organization', |
|
133 | - ); |
|
134 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['event_list']) |
|
135 | - ? $this->_data['template']['event_list'] : $this->_extra_data['template']['event_list']; |
|
136 | - $registration = $this->_data['data']; |
|
137 | - |
|
138 | - // let's remove any existing [ATTENDEE_LIST] shortcode from the event list template so that we don't get recursion. |
|
139 | - $template = str_replace('[ATTENDEE_LIST]', '', $template); |
|
140 | - |
|
141 | - // here we're setting up the events for the event_list template for THIS registration. |
|
142 | - $all_events = $this->_get_events_from_registration($registration); |
|
143 | - |
|
144 | - // we're NOT going to prepare a list of attendees this time around |
|
145 | - $events = ''; |
|
146 | - |
|
147 | - foreach ((array) $all_events as $event) { |
|
148 | - $events .= $this->_shortcode_helper->parse_event_list_template( |
|
149 | - $template, |
|
150 | - $event, |
|
151 | - $valid_shortcodes, |
|
152 | - $this->_extra_data |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - return $events; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param EE_Registration $registration |
|
162 | - * @return array |
|
163 | - * @throws EE_Error |
|
164 | - * @throws ReflectionException |
|
165 | - */ |
|
166 | - private function _get_events_from_registration(EE_Registration $registration) |
|
167 | - { |
|
168 | - return isset($this->_extra_data['data']->registrations) |
|
169 | - ? array($this->_extra_data['data']->registrations[ $registration->ID() ]['evt_obj']) : array(); |
|
170 | - } |
|
22 | + public function __construct() |
|
23 | + { |
|
24 | + parent::__construct(); |
|
25 | + } |
|
26 | + |
|
27 | + |
|
28 | + protected function _init_props() |
|
29 | + { |
|
30 | + $this->label = esc_html__('Event List Shortcodes', 'event_espresso'); |
|
31 | + $this->description = esc_html__('All shortcodes specific to event lists', 'event_espresso'); |
|
32 | + $this->_shortcodes = array( |
|
33 | + '[EVENT_LIST]' => esc_html__('Will output a list of events', 'event_espresso'), |
|
34 | + ); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param string $shortcode |
|
40 | + * @return string |
|
41 | + * @throws EE_Error |
|
42 | + * @throws ReflectionException |
|
43 | + */ |
|
44 | + protected function _parser($shortcode) |
|
45 | + { |
|
46 | + switch ($shortcode) { |
|
47 | + case '[EVENT_LIST]': |
|
48 | + return $this->_get_event_list(); |
|
49 | + } |
|
50 | + return ''; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * figure out what the incoming data is and then return the appropriate parsed value. |
|
56 | + * |
|
57 | + * @return string |
|
58 | + * @throws EE_Error |
|
59 | + * @throws ReflectionException |
|
60 | + */ |
|
61 | + private function _get_event_list() |
|
62 | + { |
|
63 | + $this->_validate_list_requirements(); |
|
64 | + |
|
65 | + if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
66 | + return $this->_get_event_list_for_main(); |
|
67 | + } elseif ($this->_data['data'] instanceof EE_Registration) { |
|
68 | + return $this->_get_event_list_for_registration(); |
|
69 | + } |
|
70 | + // prevent recursive loop |
|
71 | + return ''; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * This returns the parsed event list for main template |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + private function _get_event_list_for_main() |
|
81 | + { |
|
82 | + |
|
83 | + $valid_shortcodes = array( |
|
84 | + 'event', |
|
85 | + 'attendee_list', |
|
86 | + 'ticket_list', |
|
87 | + 'datetime_list', |
|
88 | + 'venue', |
|
89 | + 'attendee', |
|
90 | + 'recipient_list', |
|
91 | + 'recipient_details', |
|
92 | + 'primary_registration_list', |
|
93 | + 'primary_registration_details', |
|
94 | + 'event_author', |
|
95 | + 'organization', |
|
96 | + ); |
|
97 | + $template = $this->_data['template']; |
|
98 | + $data = $this->_data['data']; |
|
99 | + $events = ''; |
|
100 | + |
|
101 | + // now we need to loop through the events array in EE_Messages_Addressee and send data to the EE_Parser helper. |
|
102 | + foreach ($data->events as $event) { |
|
103 | + $events .= $this->_shortcode_helper->parse_event_list_template( |
|
104 | + $template, |
|
105 | + $event['event'], |
|
106 | + $valid_shortcodes, |
|
107 | + $this->_extra_data |
|
108 | + ); |
|
109 | + } |
|
110 | + return $events; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * This returns the parsed event list for an attendee |
|
116 | + * |
|
117 | + * @return string |
|
118 | + * @throws EE_Error |
|
119 | + * @throws ReflectionException |
|
120 | + */ |
|
121 | + private function _get_event_list_for_registration() |
|
122 | + { |
|
123 | + $valid_shortcodes = array( |
|
124 | + 'event', |
|
125 | + 'ticket_list', |
|
126 | + 'datetime_list', |
|
127 | + 'attendee', |
|
128 | + 'event_author', |
|
129 | + 'recipient_details', |
|
130 | + 'recipient_list', |
|
131 | + 'venue', |
|
132 | + 'organization', |
|
133 | + ); |
|
134 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['event_list']) |
|
135 | + ? $this->_data['template']['event_list'] : $this->_extra_data['template']['event_list']; |
|
136 | + $registration = $this->_data['data']; |
|
137 | + |
|
138 | + // let's remove any existing [ATTENDEE_LIST] shortcode from the event list template so that we don't get recursion. |
|
139 | + $template = str_replace('[ATTENDEE_LIST]', '', $template); |
|
140 | + |
|
141 | + // here we're setting up the events for the event_list template for THIS registration. |
|
142 | + $all_events = $this->_get_events_from_registration($registration); |
|
143 | + |
|
144 | + // we're NOT going to prepare a list of attendees this time around |
|
145 | + $events = ''; |
|
146 | + |
|
147 | + foreach ((array) $all_events as $event) { |
|
148 | + $events .= $this->_shortcode_helper->parse_event_list_template( |
|
149 | + $template, |
|
150 | + $event, |
|
151 | + $valid_shortcodes, |
|
152 | + $this->_extra_data |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + return $events; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param EE_Registration $registration |
|
162 | + * @return array |
|
163 | + * @throws EE_Error |
|
164 | + * @throws ReflectionException |
|
165 | + */ |
|
166 | + private function _get_events_from_registration(EE_Registration $registration) |
|
167 | + { |
|
168 | + return isset($this->_extra_data['data']->registrations) |
|
169 | + ? array($this->_extra_data['data']->registrations[ $registration->ID() ]['evt_obj']) : array(); |
|
170 | + } |
|
171 | 171 | } |
@@ -146,13 +146,13 @@ |
||
146 | 146 | |
147 | 147 | private function _get_datetimes_from_event(EE_Event $event, $att = null) |
148 | 148 | { |
149 | - return isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID( |
|
150 | - ) ]['dtt_objs'] : array(); |
|
149 | + return isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID( |
|
150 | + )]['dtt_objs'] : array(); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | private function _get_datetimes_from_ticket(EE_Ticket $ticket, $att = null) |
154 | 154 | { |
155 | - return isset($this->_extra_data['data']->tickets) ? $this->_extra_data['data']->tickets[ $ticket->ID( |
|
156 | - ) ]['dtt_objs'] : array(); |
|
155 | + return isset($this->_extra_data['data']->tickets) ? $this->_extra_data['data']->tickets[$ticket->ID( |
|
156 | + )]['dtt_objs'] : array(); |
|
157 | 157 | } |
158 | 158 | } |
@@ -22,141 +22,141 @@ |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - protected function _init_props() |
|
26 | - { |
|
27 | - $this->label = esc_html__('Datetime List Shortcodes', 'event_espresso'); |
|
28 | - $this->description = esc_html__('All shortcodes specific to datetime lists', 'event_espresso'); |
|
29 | - $this->_shortcodes = array( |
|
30 | - '[DATETIME_LIST]' => esc_html__( |
|
31 | - 'Will output a list of datetimes according to the layout specified in the datetime list field.', |
|
32 | - 'event_espresso' |
|
33 | - ), |
|
34 | - ); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param string $shortcode |
|
40 | - * @return string |
|
41 | - * @throws EE_Error |
|
42 | - */ |
|
43 | - protected function _parser($shortcode) |
|
44 | - { |
|
45 | - switch ($shortcode) { |
|
46 | - case '[DATETIME_LIST]': |
|
47 | - return $this->_get_datetime_list(); |
|
48 | - } |
|
49 | - return ''; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * figure out what the incoming data is and then return the appropriate parsed value. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - * @throws EE_Error |
|
58 | - */ |
|
59 | - private function _get_datetime_list() |
|
60 | - { |
|
61 | - $this->_validate_list_requirements(); |
|
62 | - |
|
63 | - if ($this->_data['data'] instanceof EE_Ticket) { |
|
64 | - return $this->_get_datetime_list_for_ticket(); |
|
65 | - } elseif ($this->_data['data'] instanceof EE_Event) { |
|
66 | - return $this->_get_datetime_list_for_event(); |
|
67 | - } elseif ($this->_data['data'] instanceof EE_Messages_Addressee && $this->_data['data']->reg_obj instanceof EE_Registration) { |
|
68 | - return $this->_get_datetime_list_for_registration(); |
|
69 | - } |
|
70 | - // prevent recursive loop |
|
71 | - return ''; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * return parsed list of datetimes for an event |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - private function _get_datetime_list_for_event() |
|
81 | - { |
|
82 | - $valid_shortcodes = array('datetime', 'attendee'); |
|
83 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list']) |
|
84 | - ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list']; |
|
85 | - $event = $this->_data['data']; |
|
86 | - |
|
87 | - // here we're setting up the datetimes for the datetime list template for THIS event. |
|
88 | - $dtt_parsed = ''; |
|
89 | - $datetimes = $this->_get_datetimes_from_event($event); |
|
90 | - |
|
91 | - // each datetime in this case should be an datetime object. |
|
92 | - foreach ($datetimes as $datetime) { |
|
93 | - $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template( |
|
94 | - $template, |
|
95 | - $datetime, |
|
96 | - $valid_shortcodes, |
|
97 | - $this->_extra_data |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - return $dtt_parsed; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * return parsed list of datetimes for an ticket |
|
107 | - * |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - private function _get_datetime_list_for_ticket() |
|
111 | - { |
|
112 | - $valid_shortcodes = array('datetime', 'attendee'); |
|
113 | - |
|
114 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list']) |
|
115 | - ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list']; |
|
116 | - $ticket = $this->_data['data']; |
|
117 | - |
|
118 | - // here we're setting up the datetimes for the datetime list template for THIS ticket. |
|
119 | - $dtt_parsed = ''; |
|
120 | - $datetimes = $this->_get_datetimes_from_ticket($ticket); |
|
121 | - |
|
122 | - // each datetime in this case should be an datetime object. |
|
123 | - foreach ($datetimes as $datetime) { |
|
124 | - $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template( |
|
125 | - $template, |
|
126 | - $datetime, |
|
127 | - $valid_shortcodes, |
|
128 | - $this->_extra_data |
|
129 | - ); |
|
130 | - } |
|
131 | - |
|
132 | - return $dtt_parsed; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * return parsed list of datetimes from a given registration. |
|
138 | - * |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - private function _get_datetime_list_for_registration() |
|
142 | - { |
|
143 | - $registration = $this->_data['data']->reg_obj; |
|
144 | - |
|
145 | - // now let's just get the ticket, set $this->_data['data'] to the ticket and then call _get_datetime_list_for__ticket(); |
|
146 | - $this->_data['data'] = $registration->ticket(); |
|
147 | - return $this->_get_datetime_list_for_ticket(); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - private function _get_datetimes_from_event(EE_Event $event, $att = null) |
|
152 | - { |
|
153 | - return isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID( |
|
154 | - ) ]['dtt_objs'] : array(); |
|
155 | - } |
|
156 | - |
|
157 | - private function _get_datetimes_from_ticket(EE_Ticket $ticket, $att = null) |
|
158 | - { |
|
159 | - return isset($this->_extra_data['data']->tickets) ? $this->_extra_data['data']->tickets[ $ticket->ID( |
|
160 | - ) ]['dtt_objs'] : array(); |
|
161 | - } |
|
25 | + protected function _init_props() |
|
26 | + { |
|
27 | + $this->label = esc_html__('Datetime List Shortcodes', 'event_espresso'); |
|
28 | + $this->description = esc_html__('All shortcodes specific to datetime lists', 'event_espresso'); |
|
29 | + $this->_shortcodes = array( |
|
30 | + '[DATETIME_LIST]' => esc_html__( |
|
31 | + 'Will output a list of datetimes according to the layout specified in the datetime list field.', |
|
32 | + 'event_espresso' |
|
33 | + ), |
|
34 | + ); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param string $shortcode |
|
40 | + * @return string |
|
41 | + * @throws EE_Error |
|
42 | + */ |
|
43 | + protected function _parser($shortcode) |
|
44 | + { |
|
45 | + switch ($shortcode) { |
|
46 | + case '[DATETIME_LIST]': |
|
47 | + return $this->_get_datetime_list(); |
|
48 | + } |
|
49 | + return ''; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * figure out what the incoming data is and then return the appropriate parsed value. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + * @throws EE_Error |
|
58 | + */ |
|
59 | + private function _get_datetime_list() |
|
60 | + { |
|
61 | + $this->_validate_list_requirements(); |
|
62 | + |
|
63 | + if ($this->_data['data'] instanceof EE_Ticket) { |
|
64 | + return $this->_get_datetime_list_for_ticket(); |
|
65 | + } elseif ($this->_data['data'] instanceof EE_Event) { |
|
66 | + return $this->_get_datetime_list_for_event(); |
|
67 | + } elseif ($this->_data['data'] instanceof EE_Messages_Addressee && $this->_data['data']->reg_obj instanceof EE_Registration) { |
|
68 | + return $this->_get_datetime_list_for_registration(); |
|
69 | + } |
|
70 | + // prevent recursive loop |
|
71 | + return ''; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * return parsed list of datetimes for an event |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + private function _get_datetime_list_for_event() |
|
81 | + { |
|
82 | + $valid_shortcodes = array('datetime', 'attendee'); |
|
83 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list']) |
|
84 | + ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list']; |
|
85 | + $event = $this->_data['data']; |
|
86 | + |
|
87 | + // here we're setting up the datetimes for the datetime list template for THIS event. |
|
88 | + $dtt_parsed = ''; |
|
89 | + $datetimes = $this->_get_datetimes_from_event($event); |
|
90 | + |
|
91 | + // each datetime in this case should be an datetime object. |
|
92 | + foreach ($datetimes as $datetime) { |
|
93 | + $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template( |
|
94 | + $template, |
|
95 | + $datetime, |
|
96 | + $valid_shortcodes, |
|
97 | + $this->_extra_data |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + return $dtt_parsed; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * return parsed list of datetimes for an ticket |
|
107 | + * |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + private function _get_datetime_list_for_ticket() |
|
111 | + { |
|
112 | + $valid_shortcodes = array('datetime', 'attendee'); |
|
113 | + |
|
114 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list']) |
|
115 | + ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list']; |
|
116 | + $ticket = $this->_data['data']; |
|
117 | + |
|
118 | + // here we're setting up the datetimes for the datetime list template for THIS ticket. |
|
119 | + $dtt_parsed = ''; |
|
120 | + $datetimes = $this->_get_datetimes_from_ticket($ticket); |
|
121 | + |
|
122 | + // each datetime in this case should be an datetime object. |
|
123 | + foreach ($datetimes as $datetime) { |
|
124 | + $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template( |
|
125 | + $template, |
|
126 | + $datetime, |
|
127 | + $valid_shortcodes, |
|
128 | + $this->_extra_data |
|
129 | + ); |
|
130 | + } |
|
131 | + |
|
132 | + return $dtt_parsed; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * return parsed list of datetimes from a given registration. |
|
138 | + * |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + private function _get_datetime_list_for_registration() |
|
142 | + { |
|
143 | + $registration = $this->_data['data']->reg_obj; |
|
144 | + |
|
145 | + // now let's just get the ticket, set $this->_data['data'] to the ticket and then call _get_datetime_list_for__ticket(); |
|
146 | + $this->_data['data'] = $registration->ticket(); |
|
147 | + return $this->_get_datetime_list_for_ticket(); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + private function _get_datetimes_from_event(EE_Event $event, $att = null) |
|
152 | + { |
|
153 | + return isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID( |
|
154 | + ) ]['dtt_objs'] : array(); |
|
155 | + } |
|
156 | + |
|
157 | + private function _get_datetimes_from_ticket(EE_Ticket $ticket, $att = null) |
|
158 | + { |
|
159 | + return isset($this->_extra_data['data']->tickets) ? $this->_extra_data['data']->tickets[ $ticket->ID( |
|
160 | + ) ]['dtt_objs'] : array(); |
|
161 | + } |
|
162 | 162 | } |
@@ -20,202 +20,202 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - protected function _init_props() |
|
24 | - { |
|
25 | - $this->label = __('Line Item List Shortcodes', 'event_espresso'); |
|
26 | - $this->description = __('All shortcodes specific to line item lists', 'event_espresso'); |
|
27 | - $this->_shortcodes = array( |
|
28 | - '[TICKET_LINE_ITEM_LIST]' => __('Outputs a list of ticket line items.', 'event_espresso'), |
|
29 | - '[TAX_LINE_ITEM_LIST]' => __('Outputs a list of tax line items.', 'event_espresso'), |
|
30 | - '[ADDITIONAL_LINE_ITEM_LIST]' => __( |
|
31 | - 'Outputs a list of additional line items (other charges or discounts)', |
|
32 | - 'event_espresso' |
|
33 | - ), |
|
34 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]' => __('Outputs a list of price modifier line items', 'event_espresso'), |
|
35 | - ); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - protected function _parser($shortcode) |
|
40 | - { |
|
41 | - |
|
42 | - switch ($shortcode) { |
|
43 | - case '[TICKET_LINE_ITEM_LIST]': |
|
44 | - return $this->_get_ticket_line_item_list(); |
|
45 | - break; |
|
46 | - |
|
47 | - case '[TAX_LINE_ITEM_LIST]': |
|
48 | - return $this->_get_tax_line_item_list(); |
|
49 | - break; |
|
50 | - |
|
51 | - case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
52 | - return $this->_get_price_mod_line_item_list(); |
|
53 | - break; |
|
54 | - |
|
55 | - case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
56 | - return $this->_get_additional_line_item_list(); |
|
57 | - break; |
|
58 | - |
|
59 | - default: |
|
60 | - return ''; |
|
61 | - break; |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
68 | - * |
|
69 | - * @since 4.5.0 |
|
70 | - * |
|
71 | - * @return string parsed ticket line item list. |
|
72 | - */ |
|
73 | - private function _get_ticket_line_item_list() |
|
74 | - { |
|
75 | - $this->_validate_list_requirements(); |
|
76 | - |
|
77 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
78 | - return ''; |
|
79 | - } |
|
80 | - |
|
81 | - $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
82 | - |
|
83 | - $ticket = $this->_data['data']; |
|
84 | - $templates = $this->_extra_data['template']; |
|
85 | - $addressee_obj = $this->_extra_data['data']; |
|
86 | - |
|
87 | - // made it here so we have an EE_Ticket, so we should have what we need. |
|
88 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
89 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
90 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
91 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
92 | - |
|
93 | - $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
94 | - : $templates['ticket_line_item_pms']; |
|
95 | - |
|
96 | - if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
97 | - return ''; |
|
98 | - } |
|
99 | - |
|
100 | - // now we just return the appropriate template parsed for each ticket. |
|
101 | - return $this->_shortcode_helper->parse_line_item_list_template( |
|
102 | - $template, |
|
103 | - $ticket_line_item, |
|
104 | - $valid_shortcodes, |
|
105 | - $this->_extra_data |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
112 | - * |
|
113 | - * @since 4.5.0 |
|
114 | - * |
|
115 | - * @return string parsed tax line item list. |
|
116 | - */ |
|
117 | - private function _get_tax_line_item_list() |
|
118 | - { |
|
119 | - |
|
120 | - $this->_validate_list_requirements(); |
|
121 | - |
|
122 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
123 | - return ''; |
|
124 | - } |
|
125 | - |
|
126 | - // made it here so we're good to go. |
|
127 | - $valid_shortcodes = array('line_item'); |
|
128 | - $templates = $this->_data['template']; |
|
129 | - |
|
130 | - $tax_line_items = $this->_data['data']->tax_line_items; |
|
131 | - $line_item_list = ''; |
|
132 | - foreach ($tax_line_items as $line_item) { |
|
133 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
134 | - $templates['tax_line_item_list'], |
|
135 | - $line_item, |
|
136 | - $valid_shortcodes, |
|
137 | - $this->_extra_data |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - return $line_item_list; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
146 | - * |
|
147 | - * @since 4.5.0 |
|
148 | - * |
|
149 | - * @return string parsed other line item list. |
|
150 | - */ |
|
151 | - private function _get_additional_line_item_list() |
|
152 | - { |
|
153 | - |
|
154 | - $this->_validate_list_requirements(); |
|
155 | - |
|
156 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
157 | - return ''; |
|
158 | - } |
|
159 | - |
|
160 | - // made it here so we're good to go. |
|
161 | - $valid_shortcodes = array('line_item'); |
|
162 | - $templates = $this->_data['template']; |
|
163 | - |
|
164 | - $additional_line_items = $this->_data['data']->additional_line_items; |
|
165 | - $line_item_list = ''; |
|
166 | - foreach ($additional_line_items as $line_item) { |
|
167 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
168 | - $templates['additional_line_item_list'], |
|
169 | - $line_item, |
|
170 | - $valid_shortcodes, |
|
171 | - $this->_extra_data |
|
172 | - ); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - return $line_item_list; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
182 | - * parent ticket line item. |
|
183 | - * |
|
184 | - * @since 4.5.0 |
|
185 | - * |
|
186 | - * @return string parsed price modifier line item list. |
|
187 | - */ |
|
188 | - private function _get_price_mod_line_item_list() |
|
189 | - { |
|
190 | - $this->_validate_list_requirements(); |
|
191 | - |
|
192 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
193 | - return ''; |
|
194 | - } |
|
195 | - |
|
196 | - // made it here so we're good to go. |
|
197 | - $main_line_item = $this->_data['data']; |
|
198 | - $templates = $this->_extra_data['template']; |
|
199 | - $addressee_obj = $this->_extra_data['data']; |
|
200 | - |
|
201 | - $valid_shortcodes = array('line_item'); |
|
202 | - |
|
203 | - $main_line_item_id = $main_line_item->ID(); |
|
204 | - |
|
205 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
206 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
207 | - |
|
208 | - $line_item_list = ''; |
|
209 | - |
|
210 | - foreach ($price_mod_line_items as $line_item) { |
|
211 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
212 | - $templates['price_modifier_line_item_list'], |
|
213 | - $line_item, |
|
214 | - $valid_shortcodes, |
|
215 | - $this->_extra_data |
|
216 | - ); |
|
217 | - } |
|
218 | - |
|
219 | - return $line_item_list; |
|
220 | - } |
|
23 | + protected function _init_props() |
|
24 | + { |
|
25 | + $this->label = __('Line Item List Shortcodes', 'event_espresso'); |
|
26 | + $this->description = __('All shortcodes specific to line item lists', 'event_espresso'); |
|
27 | + $this->_shortcodes = array( |
|
28 | + '[TICKET_LINE_ITEM_LIST]' => __('Outputs a list of ticket line items.', 'event_espresso'), |
|
29 | + '[TAX_LINE_ITEM_LIST]' => __('Outputs a list of tax line items.', 'event_espresso'), |
|
30 | + '[ADDITIONAL_LINE_ITEM_LIST]' => __( |
|
31 | + 'Outputs a list of additional line items (other charges or discounts)', |
|
32 | + 'event_espresso' |
|
33 | + ), |
|
34 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]' => __('Outputs a list of price modifier line items', 'event_espresso'), |
|
35 | + ); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + protected function _parser($shortcode) |
|
40 | + { |
|
41 | + |
|
42 | + switch ($shortcode) { |
|
43 | + case '[TICKET_LINE_ITEM_LIST]': |
|
44 | + return $this->_get_ticket_line_item_list(); |
|
45 | + break; |
|
46 | + |
|
47 | + case '[TAX_LINE_ITEM_LIST]': |
|
48 | + return $this->_get_tax_line_item_list(); |
|
49 | + break; |
|
50 | + |
|
51 | + case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
52 | + return $this->_get_price_mod_line_item_list(); |
|
53 | + break; |
|
54 | + |
|
55 | + case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
56 | + return $this->_get_additional_line_item_list(); |
|
57 | + break; |
|
58 | + |
|
59 | + default: |
|
60 | + return ''; |
|
61 | + break; |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
68 | + * |
|
69 | + * @since 4.5.0 |
|
70 | + * |
|
71 | + * @return string parsed ticket line item list. |
|
72 | + */ |
|
73 | + private function _get_ticket_line_item_list() |
|
74 | + { |
|
75 | + $this->_validate_list_requirements(); |
|
76 | + |
|
77 | + if (! $this->_data['data'] instanceof EE_Ticket) { |
|
78 | + return ''; |
|
79 | + } |
|
80 | + |
|
81 | + $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
82 | + |
|
83 | + $ticket = $this->_data['data']; |
|
84 | + $templates = $this->_extra_data['template']; |
|
85 | + $addressee_obj = $this->_extra_data['data']; |
|
86 | + |
|
87 | + // made it here so we have an EE_Ticket, so we should have what we need. |
|
88 | + $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
89 | + ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
90 | + $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
91 | + ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
92 | + |
|
93 | + $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
94 | + : $templates['ticket_line_item_pms']; |
|
95 | + |
|
96 | + if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
97 | + return ''; |
|
98 | + } |
|
99 | + |
|
100 | + // now we just return the appropriate template parsed for each ticket. |
|
101 | + return $this->_shortcode_helper->parse_line_item_list_template( |
|
102 | + $template, |
|
103 | + $ticket_line_item, |
|
104 | + $valid_shortcodes, |
|
105 | + $this->_extra_data |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
112 | + * |
|
113 | + * @since 4.5.0 |
|
114 | + * |
|
115 | + * @return string parsed tax line item list. |
|
116 | + */ |
|
117 | + private function _get_tax_line_item_list() |
|
118 | + { |
|
119 | + |
|
120 | + $this->_validate_list_requirements(); |
|
121 | + |
|
122 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
123 | + return ''; |
|
124 | + } |
|
125 | + |
|
126 | + // made it here so we're good to go. |
|
127 | + $valid_shortcodes = array('line_item'); |
|
128 | + $templates = $this->_data['template']; |
|
129 | + |
|
130 | + $tax_line_items = $this->_data['data']->tax_line_items; |
|
131 | + $line_item_list = ''; |
|
132 | + foreach ($tax_line_items as $line_item) { |
|
133 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
134 | + $templates['tax_line_item_list'], |
|
135 | + $line_item, |
|
136 | + $valid_shortcodes, |
|
137 | + $this->_extra_data |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + return $line_item_list; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
146 | + * |
|
147 | + * @since 4.5.0 |
|
148 | + * |
|
149 | + * @return string parsed other line item list. |
|
150 | + */ |
|
151 | + private function _get_additional_line_item_list() |
|
152 | + { |
|
153 | + |
|
154 | + $this->_validate_list_requirements(); |
|
155 | + |
|
156 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
157 | + return ''; |
|
158 | + } |
|
159 | + |
|
160 | + // made it here so we're good to go. |
|
161 | + $valid_shortcodes = array('line_item'); |
|
162 | + $templates = $this->_data['template']; |
|
163 | + |
|
164 | + $additional_line_items = $this->_data['data']->additional_line_items; |
|
165 | + $line_item_list = ''; |
|
166 | + foreach ($additional_line_items as $line_item) { |
|
167 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
168 | + $templates['additional_line_item_list'], |
|
169 | + $line_item, |
|
170 | + $valid_shortcodes, |
|
171 | + $this->_extra_data |
|
172 | + ); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + return $line_item_list; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
182 | + * parent ticket line item. |
|
183 | + * |
|
184 | + * @since 4.5.0 |
|
185 | + * |
|
186 | + * @return string parsed price modifier line item list. |
|
187 | + */ |
|
188 | + private function _get_price_mod_line_item_list() |
|
189 | + { |
|
190 | + $this->_validate_list_requirements(); |
|
191 | + |
|
192 | + if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
193 | + return ''; |
|
194 | + } |
|
195 | + |
|
196 | + // made it here so we're good to go. |
|
197 | + $main_line_item = $this->_data['data']; |
|
198 | + $templates = $this->_extra_data['template']; |
|
199 | + $addressee_obj = $this->_extra_data['data']; |
|
200 | + |
|
201 | + $valid_shortcodes = array('line_item'); |
|
202 | + |
|
203 | + $main_line_item_id = $main_line_item->ID(); |
|
204 | + |
|
205 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
206 | + ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
207 | + |
|
208 | + $line_item_list = ''; |
|
209 | + |
|
210 | + foreach ($price_mod_line_items as $line_item) { |
|
211 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
212 | + $templates['price_modifier_line_item_list'], |
|
213 | + $line_item, |
|
214 | + $valid_shortcodes, |
|
215 | + $this->_extra_data |
|
216 | + ); |
|
217 | + } |
|
218 | + |
|
219 | + return $line_item_list; |
|
220 | + } |
|
221 | 221 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | { |
75 | 75 | $this->_validate_list_requirements(); |
76 | 76 | |
77 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
77 | + if ( ! $this->_data['data'] instanceof EE_Ticket) { |
|
78 | 78 | return ''; |
79 | 79 | } |
80 | 80 | |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | $addressee_obj = $this->_extra_data['data']; |
86 | 86 | |
87 | 87 | // made it here so we have an EE_Ticket, so we should have what we need. |
88 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
89 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
90 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
91 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
88 | + $ticket_line_item = isset($addressee_obj->tickets[$ticket->ID()]['line_item']) |
|
89 | + ? $addressee_obj->tickets[$ticket->ID()]['line_item'] : null; |
|
90 | + $sub_line_items = isset($addressee_obj->tickets[$ticket->ID()]['sub_line_items']) |
|
91 | + ? $addressee_obj->tickets[$ticket->ID()]['sub_line_items'] : array(); |
|
92 | 92 | |
93 | 93 | $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
94 | 94 | : $templates['ticket_line_item_pms']; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | $this->_validate_list_requirements(); |
121 | 121 | |
122 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
122 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
123 | 123 | return ''; |
124 | 124 | } |
125 | 125 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | $this->_validate_list_requirements(); |
155 | 155 | |
156 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
156 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
157 | 157 | return ''; |
158 | 158 | } |
159 | 159 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | { |
190 | 190 | $this->_validate_list_requirements(); |
191 | 191 | |
192 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
192 | + if ( ! $this->_data['data'] instanceof EE_Line_Item) { |
|
193 | 193 | return ''; |
194 | 194 | } |
195 | 195 | |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | |
203 | 203 | $main_line_item_id = $main_line_item->ID(); |
204 | 204 | |
205 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
206 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
205 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[$main_line_item_id]['children']) |
|
206 | + ? $addressee_obj->line_items_with_children[$main_line_item_id]['children'] : array(); |
|
207 | 207 | |
208 | 208 | $line_item_list = ''; |
209 | 209 |
@@ -18,65 +18,65 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - protected function _init_props() |
|
22 | - { |
|
23 | - $this->label = __('Line Item Shortcodes', 'event_espresso'); |
|
24 | - $this->description = __('All shortcodes specific to line items', 'event_espresso'); |
|
25 | - $this->_shortcodes = array( |
|
26 | - '[LINE_ITEM_NAME]' => __('Outputs the line item name.', 'event_espresso'), |
|
27 | - '[LINE_ITEM_DESCRIPTION]' => __('Outputs a the description for the line item.', 'event_espresso'), |
|
28 | - '[LINE_ITEM_QUANTITY]' => __('Outputs the quantity for this line item.', 'event_espresso'), |
|
29 | - '[LINE_ITEM_AMOUNT]' => __( |
|
30 | - 'This will either output the unit price for a line item if its not a percent, or the percent of the line item (if it is percent).', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - '[LINE_ITEM_TOTAL]' => __('This outputs the line item total.', 'event_espresso'), |
|
34 | - '[LINE_ITEM_TAXABLE_*]' => __( |
|
35 | - 'This attribute type shortcode allows users to indicate what to output if a line item is taxable or not. One can use the key "symbol=" with the shortcode to indicate what they\'d like to represent a taxable line item. So doing something like <code>[LINE_ITEM_TAXABLE_* symbol="*"]</code> means that when the line item is parsed, if it\'s taxable the "*" symbol will be returned. The default symbol if no attribute is included is the "*" symbol.', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - ); |
|
39 | - } |
|
21 | + protected function _init_props() |
|
22 | + { |
|
23 | + $this->label = __('Line Item Shortcodes', 'event_espresso'); |
|
24 | + $this->description = __('All shortcodes specific to line items', 'event_espresso'); |
|
25 | + $this->_shortcodes = array( |
|
26 | + '[LINE_ITEM_NAME]' => __('Outputs the line item name.', 'event_espresso'), |
|
27 | + '[LINE_ITEM_DESCRIPTION]' => __('Outputs a the description for the line item.', 'event_espresso'), |
|
28 | + '[LINE_ITEM_QUANTITY]' => __('Outputs the quantity for this line item.', 'event_espresso'), |
|
29 | + '[LINE_ITEM_AMOUNT]' => __( |
|
30 | + 'This will either output the unit price for a line item if its not a percent, or the percent of the line item (if it is percent).', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + '[LINE_ITEM_TOTAL]' => __('This outputs the line item total.', 'event_espresso'), |
|
34 | + '[LINE_ITEM_TAXABLE_*]' => __( |
|
35 | + 'This attribute type shortcode allows users to indicate what to output if a line item is taxable or not. One can use the key "symbol=" with the shortcode to indicate what they\'d like to represent a taxable line item. So doing something like <code>[LINE_ITEM_TAXABLE_* symbol="*"]</code> means that when the line item is parsed, if it\'s taxable the "*" symbol will be returned. The default symbol if no attribute is included is the "*" symbol.', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + ); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - protected function _parser($shortcode) |
|
43 | - { |
|
44 | - // ensure that the incoming object IS a line item. If it isn't then bail early. |
|
45 | - if (! $this->_data instanceof EE_Line_Item) { |
|
46 | - return ''; |
|
47 | - } |
|
42 | + protected function _parser($shortcode) |
|
43 | + { |
|
44 | + // ensure that the incoming object IS a line item. If it isn't then bail early. |
|
45 | + if (! $this->_data instanceof EE_Line_Item) { |
|
46 | + return ''; |
|
47 | + } |
|
48 | 48 | |
49 | - $line_item = $this->_data; |
|
49 | + $line_item = $this->_data; |
|
50 | 50 | |
51 | - switch ($shortcode) { |
|
52 | - case '[LINE_ITEM_NAME]': |
|
53 | - return $line_item->name(); |
|
54 | - break; |
|
51 | + switch ($shortcode) { |
|
52 | + case '[LINE_ITEM_NAME]': |
|
53 | + return $line_item->name(); |
|
54 | + break; |
|
55 | 55 | |
56 | - case '[LINE_ITEM_DESCRIPTION]': |
|
57 | - return $line_item->desc(); |
|
58 | - break; |
|
56 | + case '[LINE_ITEM_DESCRIPTION]': |
|
57 | + return $line_item->desc(); |
|
58 | + break; |
|
59 | 59 | |
60 | - case '[LINE_ITEM_QUANTITY]': |
|
61 | - return $line_item->quantity(); |
|
62 | - break; |
|
60 | + case '[LINE_ITEM_QUANTITY]': |
|
61 | + return $line_item->quantity(); |
|
62 | + break; |
|
63 | 63 | |
64 | - case '[LINE_ITEM_AMOUNT]': |
|
65 | - return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code(); |
|
66 | - break; |
|
64 | + case '[LINE_ITEM_AMOUNT]': |
|
65 | + return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code(); |
|
66 | + break; |
|
67 | 67 | |
68 | - case '[LINE_ITEM_TOTAL]': |
|
69 | - return $line_item->total_no_code(); |
|
70 | - break; |
|
71 | - } |
|
68 | + case '[LINE_ITEM_TOTAL]': |
|
69 | + return $line_item->total_no_code(); |
|
70 | + break; |
|
71 | + } |
|
72 | 72 | |
73 | - if (strpos($shortcode, '[LINE_ITEM_TAXABLE_*') !== false) { |
|
74 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
75 | - if ($line_item->is_taxable()) { |
|
76 | - return ! empty($attrs['symbol']) ? $attrs['symbol'] : '*'; |
|
77 | - } |
|
78 | - } |
|
73 | + if (strpos($shortcode, '[LINE_ITEM_TAXABLE_*') !== false) { |
|
74 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
75 | + if ($line_item->is_taxable()) { |
|
76 | + return ! empty($attrs['symbol']) ? $attrs['symbol'] : '*'; |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - return ''; |
|
81 | - } |
|
80 | + return ''; |
|
81 | + } |
|
82 | 82 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | protected function _parser($shortcode) |
43 | 43 | { |
44 | 44 | // ensure that the incoming object IS a line item. If it isn't then bail early. |
45 | - if (! $this->_data instanceof EE_Line_Item) { |
|
45 | + if ( ! $this->_data instanceof EE_Line_Item) { |
|
46 | 46 | return ''; |
47 | 47 | } |
48 | 48 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | break; |
63 | 63 | |
64 | 64 | case '[LINE_ITEM_AMOUNT]': |
65 | - return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code(); |
|
65 | + return $line_item->is_percent() ? $line_item->percent().'%' : $line_item->unit_price_no_code(); |
|
66 | 66 | break; |
67 | 67 | |
68 | 68 | case '[LINE_ITEM_TOTAL]': |
@@ -18,83 +18,83 @@ |
||
18 | 18 | class EE_Datetime_Shortcodes extends EE_Shortcodes |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * _init_props |
|
23 | - * |
|
24 | - * @access protected |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - protected function _init_props() |
|
28 | - { |
|
29 | - $this->label = __('Datetime Shortcodes', 'event_espresso'); |
|
30 | - $this->description = __('All shortcodes specific to datetime related data', 'event_espresso'); |
|
31 | - $this->_shortcodes = array( |
|
32 | - '[DATETIME_START]' => __('The start date and time.', 'event_espresso'), |
|
33 | - '[DATETIME_END]' => __('The end date and time.', 'event_espresso'), |
|
34 | - '[DATETIME_TIMEZONE]' => __('The timezone for the date and time', 'event_espresso'), |
|
35 | - '[DATE_START]' => __('The datetime start date.', 'event_espresso'), |
|
36 | - '[DATE_END]' => __('The datetime end date.', 'event_espresso'), |
|
37 | - '[TIME_START]' => __('The datetime start time.', 'event_espresso'), |
|
38 | - '[TIME_END]' => __('The datetime end time.', 'event_espresso'), |
|
39 | - '[ICAL_LINK_*]' => __( |
|
40 | - 'The datetime iCal link. The optional "link_text" attribute can be used to set custom text within the link (Default is "Add to iCal Calendar").', |
|
41 | - 'event_espresso' |
|
42 | - ), |
|
43 | - ); |
|
44 | - } |
|
21 | + /** |
|
22 | + * _init_props |
|
23 | + * |
|
24 | + * @access protected |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + protected function _init_props() |
|
28 | + { |
|
29 | + $this->label = __('Datetime Shortcodes', 'event_espresso'); |
|
30 | + $this->description = __('All shortcodes specific to datetime related data', 'event_espresso'); |
|
31 | + $this->_shortcodes = array( |
|
32 | + '[DATETIME_START]' => __('The start date and time.', 'event_espresso'), |
|
33 | + '[DATETIME_END]' => __('The end date and time.', 'event_espresso'), |
|
34 | + '[DATETIME_TIMEZONE]' => __('The timezone for the date and time', 'event_espresso'), |
|
35 | + '[DATE_START]' => __('The datetime start date.', 'event_espresso'), |
|
36 | + '[DATE_END]' => __('The datetime end date.', 'event_espresso'), |
|
37 | + '[TIME_START]' => __('The datetime start time.', 'event_espresso'), |
|
38 | + '[TIME_END]' => __('The datetime end time.', 'event_espresso'), |
|
39 | + '[ICAL_LINK_*]' => __( |
|
40 | + 'The datetime iCal link. The optional "link_text" attribute can be used to set custom text within the link (Default is "Add to iCal Calendar").', |
|
41 | + 'event_espresso' |
|
42 | + ), |
|
43 | + ); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * _parser |
|
49 | - * |
|
50 | - * @access protected |
|
51 | - * @param string $shortcode |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - protected function _parser($shortcode) |
|
55 | - { |
|
47 | + /** |
|
48 | + * _parser |
|
49 | + * |
|
50 | + * @access protected |
|
51 | + * @param string $shortcode |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + protected function _parser($shortcode) |
|
55 | + { |
|
56 | 56 | |
57 | - if (! $this->_data instanceof EE_Datetime) { |
|
58 | - return ''; // get out cause we can only parse with the datetime object. |
|
59 | - } |
|
57 | + if (! $this->_data instanceof EE_Datetime) { |
|
58 | + return ''; // get out cause we can only parse with the datetime object. |
|
59 | + } |
|
60 | 60 | |
61 | - switch ($shortcode) { |
|
62 | - case '[DATETIME_START]': |
|
63 | - return $this->_data->get_i18n_datetime('DTT_EVT_start'); |
|
64 | - break; |
|
61 | + switch ($shortcode) { |
|
62 | + case '[DATETIME_START]': |
|
63 | + return $this->_data->get_i18n_datetime('DTT_EVT_start'); |
|
64 | + break; |
|
65 | 65 | |
66 | - case '[DATETIME_END]': |
|
67 | - return $this->_data->get_i18n_datetime('DTT_EVT_end'); |
|
68 | - break; |
|
66 | + case '[DATETIME_END]': |
|
67 | + return $this->_data->get_i18n_datetime('DTT_EVT_end'); |
|
68 | + break; |
|
69 | 69 | |
70 | - case '[DATETIME_TIMEZONE]': |
|
71 | - return $this->_data->get_timezone(); |
|
72 | - break; |
|
73 | - case '[DATE_START]': |
|
74 | - return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('date_format')); |
|
75 | - break; |
|
76 | - case '[DATE_END]': |
|
77 | - return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('date_format')); |
|
78 | - break; |
|
79 | - case '[TIME_START]': |
|
80 | - return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('time_format')); |
|
81 | - break; |
|
82 | - case '[TIME_END]': |
|
83 | - return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('time_format')); |
|
84 | - break; |
|
85 | - } |
|
70 | + case '[DATETIME_TIMEZONE]': |
|
71 | + return $this->_data->get_timezone(); |
|
72 | + break; |
|
73 | + case '[DATE_START]': |
|
74 | + return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('date_format')); |
|
75 | + break; |
|
76 | + case '[DATE_END]': |
|
77 | + return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('date_format')); |
|
78 | + break; |
|
79 | + case '[TIME_START]': |
|
80 | + return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('time_format')); |
|
81 | + break; |
|
82 | + case '[TIME_END]': |
|
83 | + return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('time_format')); |
|
84 | + break; |
|
85 | + } |
|
86 | 86 | |
87 | - if (strpos($shortcode, '[ICAL_LINK_*') !== false) { |
|
88 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
87 | + if (strpos($shortcode, '[ICAL_LINK_*') !== false) { |
|
88 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
89 | 89 | |
90 | - $link_text = empty($attrs['link_text']) ? __('Add to iCal Calendar', 'event_espresso') |
|
91 | - : $attrs['link_text']; |
|
90 | + $link_text = empty($attrs['link_text']) ? __('Add to iCal Calendar', 'event_espresso') |
|
91 | + : $attrs['link_text']; |
|
92 | 92 | |
93 | - $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url()); |
|
93 | + $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url()); |
|
94 | 94 | |
95 | - return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>'; |
|
96 | - } |
|
95 | + return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>'; |
|
96 | + } |
|
97 | 97 | |
98 | - return ''; |
|
99 | - } |
|
98 | + return ''; |
|
99 | + } |
|
100 | 100 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | protected function _parser($shortcode) |
55 | 55 | { |
56 | 56 | |
57 | - if (! $this->_data instanceof EE_Datetime) { |
|
57 | + if ( ! $this->_data instanceof EE_Datetime) { |
|
58 | 58 | return ''; // get out cause we can only parse with the datetime object. |
59 | 59 | } |
60 | 60 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url()); |
94 | 94 | |
95 | - return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>'; |
|
95 | + return '<a class="ee-ical" href="'.$URL.'">'.$link_text.'</a>'; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | return ''; |
@@ -17,783 +17,783 @@ |
||
17 | 17 | class EE_Transaction_Shortcodes extends EE_Shortcodes |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc |
|
22 | - */ |
|
23 | - protected $_invoice_pm; |
|
24 | - |
|
25 | - |
|
26 | - protected function _init_props() |
|
27 | - { |
|
28 | - $this->label = esc_html__('Transaction Shortcodes', 'event_espresso'); |
|
29 | - $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso'); |
|
30 | - $this->_shortcodes = array( |
|
31 | - '[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'), |
|
32 | - '[PAYMENT_URL]' => esc_html__( |
|
33 | - 'This is a link to make a payment for the event', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - '[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__( |
|
37 | - 'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', |
|
38 | - 'event_espresso' |
|
39 | - ) |
|
40 | - . '<ul>' |
|
41 | - . '<li>' |
|
42 | - . sprintf( |
|
43 | - esc_html__( |
|
44 | - '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - '<strong>', |
|
48 | - '</strong>' |
|
49 | - ) |
|
50 | - . '</li>' |
|
51 | - . '<li>' |
|
52 | - . sprintf( |
|
53 | - esc_html__( |
|
54 | - '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', |
|
55 | - 'event_espresso' |
|
56 | - ), |
|
57 | - '<strong>', |
|
58 | - '</strong>' |
|
59 | - ) |
|
60 | - . '</li>' |
|
61 | - . '<li>' |
|
62 | - . sprintf( |
|
63 | - esc_html__( |
|
64 | - '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', |
|
65 | - 'event_espresso' |
|
66 | - ), |
|
67 | - '<strong>', |
|
68 | - '</strong>' |
|
69 | - ) |
|
70 | - . '</li>' |
|
71 | - . '</ul>', |
|
72 | - '[PAYMENT_DUE_DATE_*]' => esc_html__( |
|
73 | - 'This is a special dynamic shortcode that allows one to output a payment due date. It will only result in a date shown if there is money owing. Three parameters are available on this shortcode:', |
|
74 | - 'event_espresso' |
|
75 | - ) |
|
76 | - . '<ul>' |
|
77 | - . '<li>' |
|
78 | - . sprintf( |
|
79 | - esc_html__( |
|
80 | - '%sformat:%s This is used to indicate what format the date is in. Default is whatever is set as date formats for your website.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - '<strong>', |
|
84 | - '</strong>' |
|
85 | - ) |
|
86 | - . '</li>' |
|
87 | - . '<li>' |
|
88 | - . sprintf( |
|
89 | - esc_html__( |
|
90 | - '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due. Defaults to 30.', |
|
91 | - 'event_espresso' |
|
92 | - ), |
|
93 | - '<strong>', |
|
94 | - '</strong>' |
|
95 | - ) |
|
96 | - . '</li>' |
|
97 | - . '<li>' |
|
98 | - . sprintf( |
|
99 | - esc_html__( |
|
100 | - '%sprefix_text:%s You can use this to indicate what text will prefix the date string. Defaults to "Payment in full due by:"', |
|
101 | - 'event_espresso' |
|
102 | - ), |
|
103 | - '<strong>', |
|
104 | - '</strong>' |
|
105 | - ) |
|
106 | - . '</li>', |
|
107 | - '[INVOICE_LINK]' => esc_html__( |
|
108 | - 'This is a full html link to the invoice', |
|
109 | - 'event_espresso' |
|
110 | - ), |
|
111 | - '[INVOICE_URL]' => esc_html__( |
|
112 | - 'This is just the url for the invoice', |
|
113 | - 'event_espresso' |
|
114 | - ), |
|
115 | - '[INVOICE_LOGO_URL]' => esc_html__( |
|
116 | - 'This returns the url for the logo uploaded via the invoice settings page.', |
|
117 | - 'event_espresso' |
|
118 | - ), |
|
119 | - '[INVOICE_LOGO]' => esc_html__( |
|
120 | - 'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', |
|
121 | - 'event_espresso' |
|
122 | - ), |
|
123 | - '[INVOICE_PAYEE_NAME]' => esc_html__( |
|
124 | - 'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', |
|
125 | - 'event_espresso' |
|
126 | - ), |
|
127 | - '[INVOICE_PAYEE_ADDRESS]' => esc_html__( |
|
128 | - 'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', |
|
129 | - 'event_espresso' |
|
130 | - ), |
|
131 | - '[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__( |
|
132 | - 'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', |
|
133 | - 'event_espresso' |
|
134 | - ), |
|
135 | - '[INVOICE_PAYEE_EMAIL]' => esc_html__( |
|
136 | - 'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - '[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf( |
|
140 | - esc_html__( |
|
141 | - 'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56. If you have no tax number in your settings, then no prefix will be output either.', |
|
142 | - 'event_espresso' |
|
143 | - ), |
|
144 | - '<code>', |
|
145 | - '</code>' |
|
146 | - ), |
|
147 | - '[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'), |
|
148 | - '[TXN_STATUS]' => esc_html__( |
|
149 | - 'The transaction status for the transaction.', |
|
150 | - 'event_espresso' |
|
151 | - ), |
|
152 | - '[TXN_STATUS_ID]' => esc_html__( |
|
153 | - 'The ID representing the transaction status as saved in the db. This tends to be useful for including with css classes for styling certain statuses differently from others.', |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - '[PAYMENT_STATUS]' => esc_html__( |
|
157 | - 'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', |
|
158 | - 'event_espresso' |
|
159 | - ), |
|
160 | - '[PAYMENT_GATEWAY]' => esc_html__( |
|
161 | - 'The payment gateway used for the transaction', |
|
162 | - 'event_espresso' |
|
163 | - ), |
|
164 | - '[AMOUNT_PAID]' => esc_html__( |
|
165 | - 'The amount paid or refunded. This will only have a value if there was a payment or refund at the time of generating the message.', |
|
166 | - 'event_espresso' |
|
167 | - ), |
|
168 | - '[LAST_AMOUNT_PAID]' => esc_html__( |
|
169 | - 'This is the last payment or refund made on the transaction related to the message being generated.', |
|
170 | - 'event_espresso' |
|
171 | - ), |
|
172 | - '[TOTAL_AMOUNT_PAID]' => esc_html__( |
|
173 | - 'This parses to the total amount paid over all payments', |
|
174 | - 'event_espresso' |
|
175 | - ), |
|
176 | - '[TOTAL_OWING]' => esc_html__( |
|
177 | - 'The total owing on a transaction with no attributes.', |
|
178 | - 'event_espresso' |
|
179 | - ), |
|
180 | - '[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'), |
|
181 | - '[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'), |
|
182 | - '[OWING_STATUS_MESSAGE_*]' => esc_html__( |
|
183 | - 'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', |
|
184 | - 'event_espresso' |
|
185 | - ) |
|
186 | - . '<p></ul>' |
|
187 | - . '<li><strong>still_owing</strong>:' |
|
188 | - . esc_html__( |
|
189 | - 'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', |
|
190 | - 'event_espresso' |
|
191 | - ) |
|
192 | - . sprintf( |
|
193 | - esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
194 | - '<a href="[PAYMENT_URL]" class="noPrint">', |
|
195 | - '</a>' |
|
196 | - ) |
|
197 | - . '</li>' |
|
198 | - . |
|
199 | - '<li><strong>none_owing</strong>:' |
|
200 | - . esc_html__( |
|
201 | - 'If the transaction is paid in full, then you can indicate how this gets displayed. Note, that it defaults to just be the total owing.', |
|
202 | - 'event_espresso' |
|
203 | - ) |
|
204 | - . '</li></ul></p>', |
|
205 | - '[TXN_TOTAL_TICKETS]' => esc_html__( |
|
206 | - 'The total number of all tickets purchased in a transaction', |
|
207 | - 'event_espresso' |
|
208 | - ), |
|
209 | - '[TKT_QTY_PURCHASED]' => sprintf( |
|
210 | - esc_html__( |
|
211 | - 'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', |
|
212 | - 'event_espresso' |
|
213 | - ), |
|
214 | - '<strong>', |
|
215 | - '</strong>' |
|
216 | - ), |
|
217 | - '[TRANSACTION_ADMIN_URL]' => esc_html__( |
|
218 | - 'The url to the admin page for this transaction', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - '[RECEIPT_URL]' => esc_html__( |
|
222 | - 'This parses to the generated url for retrieving the receipt for the transaction', |
|
223 | - 'event_espresso' |
|
224 | - ), |
|
225 | - '[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__( |
|
226 | - 'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active then will parse to an empty string.', |
|
227 | - 'event_espresso' |
|
228 | - ), |
|
229 | - '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf( |
|
230 | - esc_html__( |
|
231 | - 'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.', |
|
232 | - 'event_espresso' |
|
233 | - ), |
|
234 | - '<code>[INVOICE_RECEIPT_SWITCHER_URL]', |
|
235 | - '</code>' |
|
236 | - ), |
|
237 | - '[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__( |
|
238 | - 'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.', |
|
239 | - 'event_espresso' |
|
240 | - ), |
|
241 | - ); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @param string $shortcode the shortcode to be parsed. |
|
247 | - * @return string parsed shortcode |
|
248 | - * @throws EE_Error |
|
249 | - * @throws InvalidArgumentException |
|
250 | - * @throws ReflectionException |
|
251 | - * @throws InvalidDataTypeException |
|
252 | - * @throws InvalidInterfaceException |
|
253 | - */ |
|
254 | - protected function _parser($shortcode) |
|
255 | - { |
|
256 | - // attempt to get the transaction. Since this is potentially used in more fields, we may have to look in the |
|
257 | - // _extra_data for the transaction. |
|
258 | - $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
259 | - $transaction = ! $transaction instanceof EE_Transaction |
|
260 | - && is_array($this->_extra_data) |
|
261 | - && isset($this->_extra_data['data']) |
|
262 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
263 | - ? $this->_extra_data['data']->txn |
|
264 | - : $transaction; |
|
265 | - // payment |
|
266 | - $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null; |
|
267 | - $payment = ! $payment instanceof EE_Payment |
|
268 | - && is_array($this->_extra_data) |
|
269 | - && isset($this->_extra_data['data']) |
|
270 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
|
271 | - : $payment; |
|
272 | - if (! $transaction instanceof EE_Transaction) { |
|
273 | - return ''; |
|
274 | - } |
|
275 | - switch ($shortcode) { |
|
276 | - case '[TXN_ID]': |
|
277 | - return $transaction->ID(); |
|
278 | - break; |
|
279 | - case '[PAYMENT_URL]': |
|
280 | - $payment_url = $transaction->payment_overview_url(); |
|
281 | - return empty($payment_url) |
|
282 | - ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') |
|
283 | - : $payment_url; |
|
284 | - break; |
|
285 | - case '[INVOICE_LINK]': |
|
286 | - $invoice_url = $transaction->invoice_url(); |
|
287 | - $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
288 | - return sprintf( |
|
289 | - esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
|
290 | - '<a href="' . $invoice_url . '">', |
|
291 | - '</a>' |
|
292 | - ); |
|
293 | - break; |
|
294 | - case '[INVOICE_URL]': |
|
295 | - $invoice_url = $transaction->invoice_url(); |
|
296 | - return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
297 | - break; |
|
298 | - case '[INVOICE_LOGO_URL]': |
|
299 | - return $this->_get_invoice_logo(); |
|
300 | - break; |
|
301 | - case '[INVOICE_LOGO]': |
|
302 | - return $this->_get_invoice_logo(true); |
|
303 | - break; |
|
304 | - case '[INVOICE_PAYEE_NAME]': |
|
305 | - return $this->_get_invoice_payee_name(); |
|
306 | - break; |
|
307 | - case '[INVOICE_PAYEE_ADDRESS]': |
|
308 | - return $this->_get_invoice_payee_address(); |
|
309 | - break; |
|
310 | - case '[INVOICE_PAYMENT_INSTRUCTIONS]': |
|
311 | - return $this->_get_invoice_payment_instructions(); |
|
312 | - break; |
|
313 | - case '[INVOICE_PAYEE_EMAIL]': |
|
314 | - return $this->_get_invoice_payee_email(); |
|
315 | - break; |
|
316 | - case '[TOTAL_COST]': |
|
317 | - $total = $transaction->total(); |
|
318 | - return ! empty($total) ? EEH_Template::format_currency($total) : ''; |
|
319 | - break; |
|
320 | - case '[PAYMENT_STATUS]': |
|
321 | - $status = $transaction->pretty_status(); |
|
322 | - return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
323 | - break; /**/ |
|
324 | - // note the [payment_status] shortcode is kind of misleading because payment status might be different |
|
325 | - // from txn status so I'm adding this here for clarity. |
|
326 | - case '[TXN_STATUS]': |
|
327 | - $status = $transaction->pretty_status(); |
|
328 | - return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
329 | - break; |
|
330 | - case '[TXN_STATUS_ID]': |
|
331 | - return $transaction->status_ID(); |
|
332 | - break; |
|
333 | - case '[PAYMENT_GATEWAY]': |
|
334 | - return $this->_get_payment_gateway($transaction); |
|
335 | - break; |
|
336 | - case '[AMOUNT_PAID]': |
|
337 | - return $payment instanceof EE_Payment |
|
338 | - ? EEH_Template::format_currency($payment->amount()) |
|
339 | - : EEH_Template::format_currency(0); |
|
340 | - break; |
|
341 | - case '[LAST_AMOUNT_PAID]': |
|
342 | - $last_payment = $transaction->last_payment(); |
|
343 | - return $last_payment instanceof EE_Payment |
|
344 | - ? EEH_Template::format_currency($last_payment->amount()) |
|
345 | - : EEH_Template::format_currency(0); |
|
346 | - case '[TOTAL_AMOUNT_PAID]': |
|
347 | - return EEH_Template::format_currency($transaction->paid()); |
|
348 | - break; |
|
349 | - case '[TOTAL_OWING]': |
|
350 | - $total_owing = $transaction->remaining(); |
|
351 | - return EEH_Template::format_currency($total_owing); |
|
352 | - break; |
|
353 | - case '[TXN_SUBTOTAL]': |
|
354 | - return EEH_Template::format_currency($this->_get_subtotal()); |
|
355 | - break; |
|
356 | - case '[TXN_TAX_SUBTOTAL]': |
|
357 | - return EEH_Template::format_currency($this->_get_subtotal(true)); |
|
358 | - break; |
|
359 | - case '[TKT_QTY_PURCHASED]': |
|
360 | - case '[TXN_TOTAL_TICKETS]': |
|
361 | - return $this->_data->total_ticket_count; |
|
362 | - break; |
|
363 | - case '[TRANSACTION_ADMIN_URL]': |
|
364 | - require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
365 | - $query_args = array( |
|
366 | - 'page' => 'espresso_transactions', |
|
367 | - 'action' => 'view_transaction', |
|
368 | - 'TXN_ID' => $transaction->ID(), |
|
369 | - ); |
|
370 | - $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php')); |
|
371 | - return $url; |
|
372 | - break; |
|
373 | - case '[RECEIPT_URL]': |
|
374 | - // get primary_registration |
|
375 | - $reg = $this->_data->primary_reg_obj; |
|
376 | - if (! $reg instanceof EE_Registration) { |
|
377 | - return ''; |
|
378 | - } |
|
379 | - return $reg->receipt_url(); |
|
380 | - break; |
|
381 | - case '[INVOICE_RECEIPT_SWITCHER_URL]': |
|
382 | - return $this->_get_invoice_receipt_switcher(false); |
|
383 | - break; |
|
384 | - case '[INVOICE_RECEIPT_SWITCHER_BUTTON]': |
|
385 | - return $this->_get_invoice_receipt_switcher(); |
|
386 | - break; |
|
387 | - case '[LAST_PAYMENT_TRANSACTION_ID]': |
|
388 | - $id = ''; |
|
389 | - $payment = $payment instanceof EE_Payment && $payment->ID() !== 0 |
|
390 | - ? $payment |
|
391 | - : $transaction->last_payment(); |
|
392 | - if ($payment instanceof EE_Payment) { |
|
393 | - $id = $payment->txn_id_chq_nmbr(); |
|
394 | - } |
|
395 | - return $id; |
|
396 | - break; |
|
397 | - } |
|
398 | - if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) { |
|
399 | - return $this->_get_custom_total_owing($shortcode); |
|
400 | - } |
|
401 | - if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) { |
|
402 | - return $this->_get_invoice_payee_tax_number($shortcode); |
|
403 | - } |
|
404 | - if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) { |
|
405 | - return $this->_get_payment_link_if_needed($shortcode); |
|
406 | - } |
|
407 | - if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) { |
|
408 | - return $this->_get_payment_due_date($shortcode, $transaction); |
|
409 | - } |
|
410 | - return ''; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode |
|
416 | - * |
|
417 | - * @since 4.5.0 |
|
418 | - * @param string $shortcode the incoming shortcode |
|
419 | - * @return string parsed. |
|
420 | - * @throws EE_Error |
|
421 | - */ |
|
422 | - private function _get_custom_total_owing($shortcode) |
|
423 | - { |
|
424 | - $valid_shortcodes = array('transaction'); |
|
425 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
426 | - // ensure default is set. |
|
427 | - $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
428 | - $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
429 | - ? $addressee->txn->remaining() : 0; |
|
430 | - if ($total_owing > 0) { |
|
431 | - $owing_content = ! empty($attrs['still_owing']) |
|
432 | - ? $attrs['still_owing'] |
|
433 | - : sprintf( |
|
434 | - esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
435 | - '<a href="[PAYMENT_URL]" class="noPrint">', |
|
436 | - '</a>' |
|
437 | - ); |
|
438 | - $owing_content = $this->_shortcode_helper->parse_message_template( |
|
439 | - $owing_content, |
|
440 | - $addressee, |
|
441 | - $valid_shortcodes, |
|
442 | - $this->_message_type, |
|
443 | - $this->_messenger, |
|
444 | - $this->_message |
|
445 | - ); |
|
446 | - } else { |
|
447 | - $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : ''; |
|
448 | - } |
|
449 | - return $owing_content; |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * @param EE_Transaction $transaction |
|
455 | - * @return string |
|
456 | - * @throws EE_Error |
|
457 | - */ |
|
458 | - private function _get_payment_gateway($transaction) |
|
459 | - { |
|
460 | - if ($transaction instanceof EE_Transaction) { |
|
461 | - $pm = $transaction->payment_method(); |
|
462 | - } else { |
|
463 | - $pm = null; |
|
464 | - } |
|
465 | - return $pm instanceof EE_Payment_Method ? $pm->name() : ''; |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page. If its |
|
471 | - * not present then the organization logo is used if its found (set on the organization settings page). |
|
472 | - * |
|
473 | - * @since 4.5.0 |
|
474 | - * @param bool $img_tags TRUE means to return with the img tag wrappers. False just returns the url to the image. |
|
475 | - * @return string url or html |
|
476 | - * @throws EE_Error |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws InvalidDataTypeException |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - */ |
|
481 | - private function _get_invoice_logo($img_tags = false) |
|
482 | - { |
|
483 | - $invoice_logo_url = ''; |
|
484 | - // try to get the invoice payment method's logo for this transaction image first |
|
485 | - $pm = $this->_get_invoice_payment_method(); |
|
486 | - if ($pm instanceof EE_Payment_Method) { |
|
487 | - $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true); |
|
488 | - } |
|
489 | - if (empty($invoice_logo_url)) { |
|
490 | - $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url; |
|
491 | - } |
|
492 | - if (empty($invoice_logo_url)) { |
|
493 | - return ''; |
|
494 | - } |
|
495 | - if (! $img_tags) { |
|
496 | - return $invoice_logo_url; |
|
497 | - } |
|
498 | - // image tags have been requested. |
|
499 | - $image_size = getimagesize($invoice_logo_url); |
|
500 | - // if image is wider than 300px, set the width to 300 |
|
501 | - if ($image_size[0] > 300) { |
|
502 | - $image_width = 300; |
|
503 | - } else { |
|
504 | - $image_width = $image_size[0]; |
|
505 | - } |
|
506 | - return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * Used to retrieve the appropriate content for the invoice payee name shortcode |
|
512 | - * |
|
513 | - * @since 4.5.0 |
|
514 | - * @return string |
|
515 | - * @throws EE_Error |
|
516 | - * @throws InvalidArgumentException |
|
517 | - * @throws InvalidDataTypeException |
|
518 | - * @throws InvalidInterfaceException |
|
519 | - */ |
|
520 | - private function _get_invoice_payee_name() |
|
521 | - { |
|
522 | - $payee_name = null; |
|
523 | - $pm = $this->_get_invoice_payment_method(); |
|
524 | - if ($pm instanceof EE_Payment_Method) { |
|
525 | - $payee_name = $pm->get_extra_meta('pdf_payee_name', true); |
|
526 | - } |
|
527 | - $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name; |
|
528 | - return $payee_name; |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * gets the default invoice payment method, but has a filter so it can be overridden |
|
534 | - * |
|
535 | - * @return EE_Payment_Method|null |
|
536 | - * @throws EE_Error |
|
537 | - * @throws InvalidArgumentException |
|
538 | - * @throws InvalidDataTypeException |
|
539 | - * @throws InvalidInterfaceException |
|
540 | - */ |
|
541 | - private function _get_invoice_payment_method() |
|
542 | - { |
|
543 | - if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
544 | - $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
545 | - $transaction = ! $transaction instanceof EE_Transaction |
|
546 | - && is_array($this->_extra_data) |
|
547 | - && isset($this->_extra_data['data']) |
|
548 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
549 | - ? $this->_extra_data['data']->txn : $transaction; |
|
550 | - // get the invoice payment method, and remember it for the next call too |
|
551 | - $this->_invoice_pm = apply_filters( |
|
552 | - 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', |
|
553 | - EEM_Payment_Method::instance()->get_one_of_type('Invoice'), |
|
554 | - $transaction |
|
555 | - ); |
|
556 | - } |
|
557 | - return $this->_invoice_pm; |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * Used to retrieve the appropriate content for the invoice payee email shortcode |
|
563 | - * |
|
564 | - * @since 4.5.0 |
|
565 | - * @return string |
|
566 | - * @throws EE_Error |
|
567 | - * @throws InvalidArgumentException |
|
568 | - * @throws InvalidDataTypeException |
|
569 | - * @throws InvalidInterfaceException |
|
570 | - */ |
|
571 | - private function _get_invoice_payee_email() |
|
572 | - { |
|
573 | - $payee_email = null; |
|
574 | - $pm = $this->_get_invoice_payment_method(); |
|
575 | - if ($pm instanceof EE_Payment_Method) { |
|
576 | - $payee_email = $pm->get_extra_meta('pdf_payee_email', true); |
|
577 | - } |
|
578 | - $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
579 | - : $payee_email; |
|
580 | - return $payee_email; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Used to retrieve the appropriate content for the invoice payee tax number shortcode |
|
586 | - * |
|
587 | - * @since 4.5.0 |
|
588 | - * @param string $shortcode |
|
589 | - * @return string |
|
590 | - * @throws EE_Error |
|
591 | - * @throws InvalidArgumentException |
|
592 | - * @throws InvalidDataTypeException |
|
593 | - * @throws InvalidInterfaceException |
|
594 | - */ |
|
595 | - private function _get_invoice_payee_tax_number($shortcode) |
|
596 | - { |
|
597 | - $payee_tax_number = null; |
|
598 | - $pm = $this->_get_invoice_payment_method(); |
|
599 | - if ($pm instanceof EE_Payment_Method) { |
|
600 | - $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true); |
|
601 | - } |
|
602 | - $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat |
|
603 | - : $payee_tax_number; |
|
604 | - if (empty($payee_tax_number)) { |
|
605 | - return ''; |
|
606 | - } |
|
607 | - // any attributes? |
|
608 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
609 | - // prefix? |
|
610 | - $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
611 | - return $prefix . $payee_tax_number; |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * Used to retrieve the appropriate content for the invoice payee address shortcode. |
|
617 | - * |
|
618 | - * @since 4.5.0 |
|
619 | - * @return string |
|
620 | - * @throws EE_Error |
|
621 | - * @throws InvalidArgumentException |
|
622 | - * @throws ReflectionException |
|
623 | - * @throws InvalidDataTypeException |
|
624 | - * @throws InvalidInterfaceException |
|
625 | - */ |
|
626 | - private function _get_invoice_payee_address() |
|
627 | - { |
|
628 | - $payee_address = null; |
|
629 | - $pm = $this->_get_invoice_payment_method(); |
|
630 | - if ($pm instanceof EE_Payment_Method) { |
|
631 | - $payee_address = $pm->get_extra_meta('pdf_payee_address', true); |
|
632 | - } |
|
633 | - if (empty($payee_address)) { |
|
634 | - $organization = EE_Registry::instance()->CFG->organization; |
|
635 | - $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
636 | - $payee_address .= ! empty($organization->address_2) |
|
637 | - ? $organization->get_pretty('address_2') . '<br>' |
|
638 | - : ''; |
|
639 | - $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
640 | - // state |
|
641 | - $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
|
642 | - $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
|
643 | - // Country |
|
644 | - $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
645 | - $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
|
646 | - } |
|
647 | - return $payee_address; |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * Used to retrieve the appropriate content for the invoice payment instructions shortcode. |
|
653 | - * |
|
654 | - * @since 4.5.0 |
|
655 | - * @return string |
|
656 | - * @throws EE_Error |
|
657 | - * @throws InvalidArgumentException |
|
658 | - * @throws InvalidDataTypeException |
|
659 | - * @throws InvalidInterfaceException |
|
660 | - */ |
|
661 | - private function _get_invoice_payment_instructions() |
|
662 | - { |
|
663 | - $instructions = null; |
|
664 | - $pm = $this->_get_invoice_payment_method(); |
|
665 | - return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : ''; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * get invoice/receipt switch button or url. |
|
671 | - * |
|
672 | - * @param bool $button true (default) returns the html for a button, false just returns the url. |
|
673 | - * @return string |
|
674 | - * @throws EE_Error |
|
675 | - */ |
|
676 | - protected function _get_invoice_receipt_switcher($button = true) |
|
677 | - { |
|
678 | - $reg = $this->_data->primary_reg_obj; |
|
679 | - $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
|
680 | - if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
681 | - return ''; |
|
682 | - } |
|
683 | - $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
|
684 | - $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type |
|
685 | - ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
|
686 | - $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
|
687 | - $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
|
688 | - if (! $button) { |
|
689 | - return $switch_to_url; |
|
690 | - } |
|
691 | - if (! empty($switch_to_url)) { |
|
692 | - return ' |
|
20 | + /** |
|
21 | + * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc |
|
22 | + */ |
|
23 | + protected $_invoice_pm; |
|
24 | + |
|
25 | + |
|
26 | + protected function _init_props() |
|
27 | + { |
|
28 | + $this->label = esc_html__('Transaction Shortcodes', 'event_espresso'); |
|
29 | + $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso'); |
|
30 | + $this->_shortcodes = array( |
|
31 | + '[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'), |
|
32 | + '[PAYMENT_URL]' => esc_html__( |
|
33 | + 'This is a link to make a payment for the event', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + '[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__( |
|
37 | + 'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', |
|
38 | + 'event_espresso' |
|
39 | + ) |
|
40 | + . '<ul>' |
|
41 | + . '<li>' |
|
42 | + . sprintf( |
|
43 | + esc_html__( |
|
44 | + '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + '<strong>', |
|
48 | + '</strong>' |
|
49 | + ) |
|
50 | + . '</li>' |
|
51 | + . '<li>' |
|
52 | + . sprintf( |
|
53 | + esc_html__( |
|
54 | + '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', |
|
55 | + 'event_espresso' |
|
56 | + ), |
|
57 | + '<strong>', |
|
58 | + '</strong>' |
|
59 | + ) |
|
60 | + . '</li>' |
|
61 | + . '<li>' |
|
62 | + . sprintf( |
|
63 | + esc_html__( |
|
64 | + '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', |
|
65 | + 'event_espresso' |
|
66 | + ), |
|
67 | + '<strong>', |
|
68 | + '</strong>' |
|
69 | + ) |
|
70 | + . '</li>' |
|
71 | + . '</ul>', |
|
72 | + '[PAYMENT_DUE_DATE_*]' => esc_html__( |
|
73 | + 'This is a special dynamic shortcode that allows one to output a payment due date. It will only result in a date shown if there is money owing. Three parameters are available on this shortcode:', |
|
74 | + 'event_espresso' |
|
75 | + ) |
|
76 | + . '<ul>' |
|
77 | + . '<li>' |
|
78 | + . sprintf( |
|
79 | + esc_html__( |
|
80 | + '%sformat:%s This is used to indicate what format the date is in. Default is whatever is set as date formats for your website.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + '<strong>', |
|
84 | + '</strong>' |
|
85 | + ) |
|
86 | + . '</li>' |
|
87 | + . '<li>' |
|
88 | + . sprintf( |
|
89 | + esc_html__( |
|
90 | + '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due. Defaults to 30.', |
|
91 | + 'event_espresso' |
|
92 | + ), |
|
93 | + '<strong>', |
|
94 | + '</strong>' |
|
95 | + ) |
|
96 | + . '</li>' |
|
97 | + . '<li>' |
|
98 | + . sprintf( |
|
99 | + esc_html__( |
|
100 | + '%sprefix_text:%s You can use this to indicate what text will prefix the date string. Defaults to "Payment in full due by:"', |
|
101 | + 'event_espresso' |
|
102 | + ), |
|
103 | + '<strong>', |
|
104 | + '</strong>' |
|
105 | + ) |
|
106 | + . '</li>', |
|
107 | + '[INVOICE_LINK]' => esc_html__( |
|
108 | + 'This is a full html link to the invoice', |
|
109 | + 'event_espresso' |
|
110 | + ), |
|
111 | + '[INVOICE_URL]' => esc_html__( |
|
112 | + 'This is just the url for the invoice', |
|
113 | + 'event_espresso' |
|
114 | + ), |
|
115 | + '[INVOICE_LOGO_URL]' => esc_html__( |
|
116 | + 'This returns the url for the logo uploaded via the invoice settings page.', |
|
117 | + 'event_espresso' |
|
118 | + ), |
|
119 | + '[INVOICE_LOGO]' => esc_html__( |
|
120 | + 'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', |
|
121 | + 'event_espresso' |
|
122 | + ), |
|
123 | + '[INVOICE_PAYEE_NAME]' => esc_html__( |
|
124 | + 'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', |
|
125 | + 'event_espresso' |
|
126 | + ), |
|
127 | + '[INVOICE_PAYEE_ADDRESS]' => esc_html__( |
|
128 | + 'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', |
|
129 | + 'event_espresso' |
|
130 | + ), |
|
131 | + '[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__( |
|
132 | + 'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', |
|
133 | + 'event_espresso' |
|
134 | + ), |
|
135 | + '[INVOICE_PAYEE_EMAIL]' => esc_html__( |
|
136 | + 'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + '[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf( |
|
140 | + esc_html__( |
|
141 | + 'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56. If you have no tax number in your settings, then no prefix will be output either.', |
|
142 | + 'event_espresso' |
|
143 | + ), |
|
144 | + '<code>', |
|
145 | + '</code>' |
|
146 | + ), |
|
147 | + '[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'), |
|
148 | + '[TXN_STATUS]' => esc_html__( |
|
149 | + 'The transaction status for the transaction.', |
|
150 | + 'event_espresso' |
|
151 | + ), |
|
152 | + '[TXN_STATUS_ID]' => esc_html__( |
|
153 | + 'The ID representing the transaction status as saved in the db. This tends to be useful for including with css classes for styling certain statuses differently from others.', |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + '[PAYMENT_STATUS]' => esc_html__( |
|
157 | + 'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', |
|
158 | + 'event_espresso' |
|
159 | + ), |
|
160 | + '[PAYMENT_GATEWAY]' => esc_html__( |
|
161 | + 'The payment gateway used for the transaction', |
|
162 | + 'event_espresso' |
|
163 | + ), |
|
164 | + '[AMOUNT_PAID]' => esc_html__( |
|
165 | + 'The amount paid or refunded. This will only have a value if there was a payment or refund at the time of generating the message.', |
|
166 | + 'event_espresso' |
|
167 | + ), |
|
168 | + '[LAST_AMOUNT_PAID]' => esc_html__( |
|
169 | + 'This is the last payment or refund made on the transaction related to the message being generated.', |
|
170 | + 'event_espresso' |
|
171 | + ), |
|
172 | + '[TOTAL_AMOUNT_PAID]' => esc_html__( |
|
173 | + 'This parses to the total amount paid over all payments', |
|
174 | + 'event_espresso' |
|
175 | + ), |
|
176 | + '[TOTAL_OWING]' => esc_html__( |
|
177 | + 'The total owing on a transaction with no attributes.', |
|
178 | + 'event_espresso' |
|
179 | + ), |
|
180 | + '[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'), |
|
181 | + '[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'), |
|
182 | + '[OWING_STATUS_MESSAGE_*]' => esc_html__( |
|
183 | + 'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', |
|
184 | + 'event_espresso' |
|
185 | + ) |
|
186 | + . '<p></ul>' |
|
187 | + . '<li><strong>still_owing</strong>:' |
|
188 | + . esc_html__( |
|
189 | + 'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', |
|
190 | + 'event_espresso' |
|
191 | + ) |
|
192 | + . sprintf( |
|
193 | + esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
194 | + '<a href="[PAYMENT_URL]" class="noPrint">', |
|
195 | + '</a>' |
|
196 | + ) |
|
197 | + . '</li>' |
|
198 | + . |
|
199 | + '<li><strong>none_owing</strong>:' |
|
200 | + . esc_html__( |
|
201 | + 'If the transaction is paid in full, then you can indicate how this gets displayed. Note, that it defaults to just be the total owing.', |
|
202 | + 'event_espresso' |
|
203 | + ) |
|
204 | + . '</li></ul></p>', |
|
205 | + '[TXN_TOTAL_TICKETS]' => esc_html__( |
|
206 | + 'The total number of all tickets purchased in a transaction', |
|
207 | + 'event_espresso' |
|
208 | + ), |
|
209 | + '[TKT_QTY_PURCHASED]' => sprintf( |
|
210 | + esc_html__( |
|
211 | + 'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', |
|
212 | + 'event_espresso' |
|
213 | + ), |
|
214 | + '<strong>', |
|
215 | + '</strong>' |
|
216 | + ), |
|
217 | + '[TRANSACTION_ADMIN_URL]' => esc_html__( |
|
218 | + 'The url to the admin page for this transaction', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + '[RECEIPT_URL]' => esc_html__( |
|
222 | + 'This parses to the generated url for retrieving the receipt for the transaction', |
|
223 | + 'event_espresso' |
|
224 | + ), |
|
225 | + '[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__( |
|
226 | + 'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active then will parse to an empty string.', |
|
227 | + 'event_espresso' |
|
228 | + ), |
|
229 | + '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf( |
|
230 | + esc_html__( |
|
231 | + 'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.', |
|
232 | + 'event_espresso' |
|
233 | + ), |
|
234 | + '<code>[INVOICE_RECEIPT_SWITCHER_URL]', |
|
235 | + '</code>' |
|
236 | + ), |
|
237 | + '[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__( |
|
238 | + 'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.', |
|
239 | + 'event_espresso' |
|
240 | + ), |
|
241 | + ); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @param string $shortcode the shortcode to be parsed. |
|
247 | + * @return string parsed shortcode |
|
248 | + * @throws EE_Error |
|
249 | + * @throws InvalidArgumentException |
|
250 | + * @throws ReflectionException |
|
251 | + * @throws InvalidDataTypeException |
|
252 | + * @throws InvalidInterfaceException |
|
253 | + */ |
|
254 | + protected function _parser($shortcode) |
|
255 | + { |
|
256 | + // attempt to get the transaction. Since this is potentially used in more fields, we may have to look in the |
|
257 | + // _extra_data for the transaction. |
|
258 | + $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
259 | + $transaction = ! $transaction instanceof EE_Transaction |
|
260 | + && is_array($this->_extra_data) |
|
261 | + && isset($this->_extra_data['data']) |
|
262 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
263 | + ? $this->_extra_data['data']->txn |
|
264 | + : $transaction; |
|
265 | + // payment |
|
266 | + $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null; |
|
267 | + $payment = ! $payment instanceof EE_Payment |
|
268 | + && is_array($this->_extra_data) |
|
269 | + && isset($this->_extra_data['data']) |
|
270 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
|
271 | + : $payment; |
|
272 | + if (! $transaction instanceof EE_Transaction) { |
|
273 | + return ''; |
|
274 | + } |
|
275 | + switch ($shortcode) { |
|
276 | + case '[TXN_ID]': |
|
277 | + return $transaction->ID(); |
|
278 | + break; |
|
279 | + case '[PAYMENT_URL]': |
|
280 | + $payment_url = $transaction->payment_overview_url(); |
|
281 | + return empty($payment_url) |
|
282 | + ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') |
|
283 | + : $payment_url; |
|
284 | + break; |
|
285 | + case '[INVOICE_LINK]': |
|
286 | + $invoice_url = $transaction->invoice_url(); |
|
287 | + $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
288 | + return sprintf( |
|
289 | + esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
|
290 | + '<a href="' . $invoice_url . '">', |
|
291 | + '</a>' |
|
292 | + ); |
|
293 | + break; |
|
294 | + case '[INVOICE_URL]': |
|
295 | + $invoice_url = $transaction->invoice_url(); |
|
296 | + return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
297 | + break; |
|
298 | + case '[INVOICE_LOGO_URL]': |
|
299 | + return $this->_get_invoice_logo(); |
|
300 | + break; |
|
301 | + case '[INVOICE_LOGO]': |
|
302 | + return $this->_get_invoice_logo(true); |
|
303 | + break; |
|
304 | + case '[INVOICE_PAYEE_NAME]': |
|
305 | + return $this->_get_invoice_payee_name(); |
|
306 | + break; |
|
307 | + case '[INVOICE_PAYEE_ADDRESS]': |
|
308 | + return $this->_get_invoice_payee_address(); |
|
309 | + break; |
|
310 | + case '[INVOICE_PAYMENT_INSTRUCTIONS]': |
|
311 | + return $this->_get_invoice_payment_instructions(); |
|
312 | + break; |
|
313 | + case '[INVOICE_PAYEE_EMAIL]': |
|
314 | + return $this->_get_invoice_payee_email(); |
|
315 | + break; |
|
316 | + case '[TOTAL_COST]': |
|
317 | + $total = $transaction->total(); |
|
318 | + return ! empty($total) ? EEH_Template::format_currency($total) : ''; |
|
319 | + break; |
|
320 | + case '[PAYMENT_STATUS]': |
|
321 | + $status = $transaction->pretty_status(); |
|
322 | + return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
323 | + break; /**/ |
|
324 | + // note the [payment_status] shortcode is kind of misleading because payment status might be different |
|
325 | + // from txn status so I'm adding this here for clarity. |
|
326 | + case '[TXN_STATUS]': |
|
327 | + $status = $transaction->pretty_status(); |
|
328 | + return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
329 | + break; |
|
330 | + case '[TXN_STATUS_ID]': |
|
331 | + return $transaction->status_ID(); |
|
332 | + break; |
|
333 | + case '[PAYMENT_GATEWAY]': |
|
334 | + return $this->_get_payment_gateway($transaction); |
|
335 | + break; |
|
336 | + case '[AMOUNT_PAID]': |
|
337 | + return $payment instanceof EE_Payment |
|
338 | + ? EEH_Template::format_currency($payment->amount()) |
|
339 | + : EEH_Template::format_currency(0); |
|
340 | + break; |
|
341 | + case '[LAST_AMOUNT_PAID]': |
|
342 | + $last_payment = $transaction->last_payment(); |
|
343 | + return $last_payment instanceof EE_Payment |
|
344 | + ? EEH_Template::format_currency($last_payment->amount()) |
|
345 | + : EEH_Template::format_currency(0); |
|
346 | + case '[TOTAL_AMOUNT_PAID]': |
|
347 | + return EEH_Template::format_currency($transaction->paid()); |
|
348 | + break; |
|
349 | + case '[TOTAL_OWING]': |
|
350 | + $total_owing = $transaction->remaining(); |
|
351 | + return EEH_Template::format_currency($total_owing); |
|
352 | + break; |
|
353 | + case '[TXN_SUBTOTAL]': |
|
354 | + return EEH_Template::format_currency($this->_get_subtotal()); |
|
355 | + break; |
|
356 | + case '[TXN_TAX_SUBTOTAL]': |
|
357 | + return EEH_Template::format_currency($this->_get_subtotal(true)); |
|
358 | + break; |
|
359 | + case '[TKT_QTY_PURCHASED]': |
|
360 | + case '[TXN_TOTAL_TICKETS]': |
|
361 | + return $this->_data->total_ticket_count; |
|
362 | + break; |
|
363 | + case '[TRANSACTION_ADMIN_URL]': |
|
364 | + require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
365 | + $query_args = array( |
|
366 | + 'page' => 'espresso_transactions', |
|
367 | + 'action' => 'view_transaction', |
|
368 | + 'TXN_ID' => $transaction->ID(), |
|
369 | + ); |
|
370 | + $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php')); |
|
371 | + return $url; |
|
372 | + break; |
|
373 | + case '[RECEIPT_URL]': |
|
374 | + // get primary_registration |
|
375 | + $reg = $this->_data->primary_reg_obj; |
|
376 | + if (! $reg instanceof EE_Registration) { |
|
377 | + return ''; |
|
378 | + } |
|
379 | + return $reg->receipt_url(); |
|
380 | + break; |
|
381 | + case '[INVOICE_RECEIPT_SWITCHER_URL]': |
|
382 | + return $this->_get_invoice_receipt_switcher(false); |
|
383 | + break; |
|
384 | + case '[INVOICE_RECEIPT_SWITCHER_BUTTON]': |
|
385 | + return $this->_get_invoice_receipt_switcher(); |
|
386 | + break; |
|
387 | + case '[LAST_PAYMENT_TRANSACTION_ID]': |
|
388 | + $id = ''; |
|
389 | + $payment = $payment instanceof EE_Payment && $payment->ID() !== 0 |
|
390 | + ? $payment |
|
391 | + : $transaction->last_payment(); |
|
392 | + if ($payment instanceof EE_Payment) { |
|
393 | + $id = $payment->txn_id_chq_nmbr(); |
|
394 | + } |
|
395 | + return $id; |
|
396 | + break; |
|
397 | + } |
|
398 | + if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) { |
|
399 | + return $this->_get_custom_total_owing($shortcode); |
|
400 | + } |
|
401 | + if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) { |
|
402 | + return $this->_get_invoice_payee_tax_number($shortcode); |
|
403 | + } |
|
404 | + if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) { |
|
405 | + return $this->_get_payment_link_if_needed($shortcode); |
|
406 | + } |
|
407 | + if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) { |
|
408 | + return $this->_get_payment_due_date($shortcode, $transaction); |
|
409 | + } |
|
410 | + return ''; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode |
|
416 | + * |
|
417 | + * @since 4.5.0 |
|
418 | + * @param string $shortcode the incoming shortcode |
|
419 | + * @return string parsed. |
|
420 | + * @throws EE_Error |
|
421 | + */ |
|
422 | + private function _get_custom_total_owing($shortcode) |
|
423 | + { |
|
424 | + $valid_shortcodes = array('transaction'); |
|
425 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
426 | + // ensure default is set. |
|
427 | + $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
428 | + $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
429 | + ? $addressee->txn->remaining() : 0; |
|
430 | + if ($total_owing > 0) { |
|
431 | + $owing_content = ! empty($attrs['still_owing']) |
|
432 | + ? $attrs['still_owing'] |
|
433 | + : sprintf( |
|
434 | + esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
435 | + '<a href="[PAYMENT_URL]" class="noPrint">', |
|
436 | + '</a>' |
|
437 | + ); |
|
438 | + $owing_content = $this->_shortcode_helper->parse_message_template( |
|
439 | + $owing_content, |
|
440 | + $addressee, |
|
441 | + $valid_shortcodes, |
|
442 | + $this->_message_type, |
|
443 | + $this->_messenger, |
|
444 | + $this->_message |
|
445 | + ); |
|
446 | + } else { |
|
447 | + $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : ''; |
|
448 | + } |
|
449 | + return $owing_content; |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * @param EE_Transaction $transaction |
|
455 | + * @return string |
|
456 | + * @throws EE_Error |
|
457 | + */ |
|
458 | + private function _get_payment_gateway($transaction) |
|
459 | + { |
|
460 | + if ($transaction instanceof EE_Transaction) { |
|
461 | + $pm = $transaction->payment_method(); |
|
462 | + } else { |
|
463 | + $pm = null; |
|
464 | + } |
|
465 | + return $pm instanceof EE_Payment_Method ? $pm->name() : ''; |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page. If its |
|
471 | + * not present then the organization logo is used if its found (set on the organization settings page). |
|
472 | + * |
|
473 | + * @since 4.5.0 |
|
474 | + * @param bool $img_tags TRUE means to return with the img tag wrappers. False just returns the url to the image. |
|
475 | + * @return string url or html |
|
476 | + * @throws EE_Error |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws InvalidDataTypeException |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + */ |
|
481 | + private function _get_invoice_logo($img_tags = false) |
|
482 | + { |
|
483 | + $invoice_logo_url = ''; |
|
484 | + // try to get the invoice payment method's logo for this transaction image first |
|
485 | + $pm = $this->_get_invoice_payment_method(); |
|
486 | + if ($pm instanceof EE_Payment_Method) { |
|
487 | + $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true); |
|
488 | + } |
|
489 | + if (empty($invoice_logo_url)) { |
|
490 | + $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url; |
|
491 | + } |
|
492 | + if (empty($invoice_logo_url)) { |
|
493 | + return ''; |
|
494 | + } |
|
495 | + if (! $img_tags) { |
|
496 | + return $invoice_logo_url; |
|
497 | + } |
|
498 | + // image tags have been requested. |
|
499 | + $image_size = getimagesize($invoice_logo_url); |
|
500 | + // if image is wider than 300px, set the width to 300 |
|
501 | + if ($image_size[0] > 300) { |
|
502 | + $image_width = 300; |
|
503 | + } else { |
|
504 | + $image_width = $image_size[0]; |
|
505 | + } |
|
506 | + return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * Used to retrieve the appropriate content for the invoice payee name shortcode |
|
512 | + * |
|
513 | + * @since 4.5.0 |
|
514 | + * @return string |
|
515 | + * @throws EE_Error |
|
516 | + * @throws InvalidArgumentException |
|
517 | + * @throws InvalidDataTypeException |
|
518 | + * @throws InvalidInterfaceException |
|
519 | + */ |
|
520 | + private function _get_invoice_payee_name() |
|
521 | + { |
|
522 | + $payee_name = null; |
|
523 | + $pm = $this->_get_invoice_payment_method(); |
|
524 | + if ($pm instanceof EE_Payment_Method) { |
|
525 | + $payee_name = $pm->get_extra_meta('pdf_payee_name', true); |
|
526 | + } |
|
527 | + $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name; |
|
528 | + return $payee_name; |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * gets the default invoice payment method, but has a filter so it can be overridden |
|
534 | + * |
|
535 | + * @return EE_Payment_Method|null |
|
536 | + * @throws EE_Error |
|
537 | + * @throws InvalidArgumentException |
|
538 | + * @throws InvalidDataTypeException |
|
539 | + * @throws InvalidInterfaceException |
|
540 | + */ |
|
541 | + private function _get_invoice_payment_method() |
|
542 | + { |
|
543 | + if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
544 | + $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
545 | + $transaction = ! $transaction instanceof EE_Transaction |
|
546 | + && is_array($this->_extra_data) |
|
547 | + && isset($this->_extra_data['data']) |
|
548 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
549 | + ? $this->_extra_data['data']->txn : $transaction; |
|
550 | + // get the invoice payment method, and remember it for the next call too |
|
551 | + $this->_invoice_pm = apply_filters( |
|
552 | + 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', |
|
553 | + EEM_Payment_Method::instance()->get_one_of_type('Invoice'), |
|
554 | + $transaction |
|
555 | + ); |
|
556 | + } |
|
557 | + return $this->_invoice_pm; |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * Used to retrieve the appropriate content for the invoice payee email shortcode |
|
563 | + * |
|
564 | + * @since 4.5.0 |
|
565 | + * @return string |
|
566 | + * @throws EE_Error |
|
567 | + * @throws InvalidArgumentException |
|
568 | + * @throws InvalidDataTypeException |
|
569 | + * @throws InvalidInterfaceException |
|
570 | + */ |
|
571 | + private function _get_invoice_payee_email() |
|
572 | + { |
|
573 | + $payee_email = null; |
|
574 | + $pm = $this->_get_invoice_payment_method(); |
|
575 | + if ($pm instanceof EE_Payment_Method) { |
|
576 | + $payee_email = $pm->get_extra_meta('pdf_payee_email', true); |
|
577 | + } |
|
578 | + $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
579 | + : $payee_email; |
|
580 | + return $payee_email; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Used to retrieve the appropriate content for the invoice payee tax number shortcode |
|
586 | + * |
|
587 | + * @since 4.5.0 |
|
588 | + * @param string $shortcode |
|
589 | + * @return string |
|
590 | + * @throws EE_Error |
|
591 | + * @throws InvalidArgumentException |
|
592 | + * @throws InvalidDataTypeException |
|
593 | + * @throws InvalidInterfaceException |
|
594 | + */ |
|
595 | + private function _get_invoice_payee_tax_number($shortcode) |
|
596 | + { |
|
597 | + $payee_tax_number = null; |
|
598 | + $pm = $this->_get_invoice_payment_method(); |
|
599 | + if ($pm instanceof EE_Payment_Method) { |
|
600 | + $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true); |
|
601 | + } |
|
602 | + $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat |
|
603 | + : $payee_tax_number; |
|
604 | + if (empty($payee_tax_number)) { |
|
605 | + return ''; |
|
606 | + } |
|
607 | + // any attributes? |
|
608 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
609 | + // prefix? |
|
610 | + $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
611 | + return $prefix . $payee_tax_number; |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * Used to retrieve the appropriate content for the invoice payee address shortcode. |
|
617 | + * |
|
618 | + * @since 4.5.0 |
|
619 | + * @return string |
|
620 | + * @throws EE_Error |
|
621 | + * @throws InvalidArgumentException |
|
622 | + * @throws ReflectionException |
|
623 | + * @throws InvalidDataTypeException |
|
624 | + * @throws InvalidInterfaceException |
|
625 | + */ |
|
626 | + private function _get_invoice_payee_address() |
|
627 | + { |
|
628 | + $payee_address = null; |
|
629 | + $pm = $this->_get_invoice_payment_method(); |
|
630 | + if ($pm instanceof EE_Payment_Method) { |
|
631 | + $payee_address = $pm->get_extra_meta('pdf_payee_address', true); |
|
632 | + } |
|
633 | + if (empty($payee_address)) { |
|
634 | + $organization = EE_Registry::instance()->CFG->organization; |
|
635 | + $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
636 | + $payee_address .= ! empty($organization->address_2) |
|
637 | + ? $organization->get_pretty('address_2') . '<br>' |
|
638 | + : ''; |
|
639 | + $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
640 | + // state |
|
641 | + $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
|
642 | + $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
|
643 | + // Country |
|
644 | + $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
645 | + $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
|
646 | + } |
|
647 | + return $payee_address; |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * Used to retrieve the appropriate content for the invoice payment instructions shortcode. |
|
653 | + * |
|
654 | + * @since 4.5.0 |
|
655 | + * @return string |
|
656 | + * @throws EE_Error |
|
657 | + * @throws InvalidArgumentException |
|
658 | + * @throws InvalidDataTypeException |
|
659 | + * @throws InvalidInterfaceException |
|
660 | + */ |
|
661 | + private function _get_invoice_payment_instructions() |
|
662 | + { |
|
663 | + $instructions = null; |
|
664 | + $pm = $this->_get_invoice_payment_method(); |
|
665 | + return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : ''; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * get invoice/receipt switch button or url. |
|
671 | + * |
|
672 | + * @param bool $button true (default) returns the html for a button, false just returns the url. |
|
673 | + * @return string |
|
674 | + * @throws EE_Error |
|
675 | + */ |
|
676 | + protected function _get_invoice_receipt_switcher($button = true) |
|
677 | + { |
|
678 | + $reg = $this->_data->primary_reg_obj; |
|
679 | + $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
|
680 | + if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
681 | + return ''; |
|
682 | + } |
|
683 | + $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
|
684 | + $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type |
|
685 | + ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
|
686 | + $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
|
687 | + $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
|
688 | + if (! $button) { |
|
689 | + return $switch_to_url; |
|
690 | + } |
|
691 | + if (! empty($switch_to_url)) { |
|
692 | + return ' |
|
693 | 693 | <form method="post" action="' . $switch_to_url . '" > |
694 | 694 | <input class="print_button" type="submit" value="' . $switch_to_label . '" /> |
695 | 695 | </form> |
696 | 696 | '; |
697 | - } |
|
698 | - return ''; |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * This returns a subtotal. |
|
704 | - * |
|
705 | - * @param bool $tax if true then return the subtotal for tax otherwise return subtotal. |
|
706 | - * @return int |
|
707 | - * @throws EE_Error |
|
708 | - */ |
|
709 | - private function _get_subtotal($tax = false) |
|
710 | - { |
|
711 | - $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
|
712 | - if (! $grand_total instanceof EE_Line_Item) { |
|
713 | - return 0; |
|
714 | - } |
|
715 | - return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
|
716 | - } |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode |
|
721 | - * |
|
722 | - * @since 4.7.0 |
|
723 | - * @param string $shortcode the incoming shortcode |
|
724 | - * @return string parsed. |
|
725 | - * @throws EE_Error |
|
726 | - */ |
|
727 | - private function _get_payment_link_if_needed($shortcode) |
|
728 | - { |
|
729 | - $valid_shortcodes = array('transaction'); |
|
730 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
731 | - // ensure default is set. |
|
732 | - $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
733 | - $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
734 | - ? $addressee->txn->remaining() : 0; |
|
735 | - if ($total_owing > 0) { |
|
736 | - $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
|
737 | - $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
|
738 | - $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
|
739 | - $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
740 | - $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
741 | - $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
|
742 | - $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
743 | - $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
744 | - // we need to re run this string through the parser to catch any shortcodes that are in it. |
|
745 | - $owing_content = $this->_shortcode_helper->parse_message_template( |
|
746 | - $content, |
|
747 | - $addressee, |
|
748 | - $valid_shortcodes, |
|
749 | - $this->_message_type, |
|
750 | - $this->_messenger, |
|
751 | - $this->_message |
|
752 | - ); |
|
753 | - } else { |
|
754 | - return ''; |
|
755 | - } |
|
756 | - return $owing_content; |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode |
|
762 | - * |
|
763 | - * @since 4.8.28.rc.011 |
|
764 | - * @param string $shortcode The shortcode being parsed. |
|
765 | - * @param EE_Transaction $transaction |
|
766 | - * @return string |
|
767 | - * @throws EE_Error |
|
768 | - */ |
|
769 | - protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) |
|
770 | - { |
|
771 | - // if transaction is paid in full then we can just return an empty string |
|
772 | - if ($transaction->remaining() === 0) { |
|
773 | - return ''; |
|
774 | - } |
|
775 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
776 | - $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
|
777 | - $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30; |
|
778 | - $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
|
779 | - : esc_html__('Payment in full due by: ', 'event_espresso'); |
|
780 | - $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
|
781 | - // setup date due: |
|
782 | - try { |
|
783 | - if ($transaction_created instanceof DateTime) { |
|
784 | - $date_due = $transaction_created->add( |
|
785 | - new DateInterval('P' . $days_until_due . 'D') |
|
786 | - )->format($format); |
|
787 | - } else { |
|
788 | - throw new Exception(); |
|
789 | - } |
|
790 | - } catch (Exception $e) { |
|
791 | - // format was likely invalid. |
|
792 | - $date_due = esc_html__( |
|
793 | - 'Unable to calculate date due, likely the format string is invalid.', |
|
794 | - 'event_espresso' |
|
795 | - ); |
|
796 | - } |
|
797 | - return $prefix_text . $date_due; |
|
798 | - } |
|
697 | + } |
|
698 | + return ''; |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * This returns a subtotal. |
|
704 | + * |
|
705 | + * @param bool $tax if true then return the subtotal for tax otherwise return subtotal. |
|
706 | + * @return int |
|
707 | + * @throws EE_Error |
|
708 | + */ |
|
709 | + private function _get_subtotal($tax = false) |
|
710 | + { |
|
711 | + $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
|
712 | + if (! $grand_total instanceof EE_Line_Item) { |
|
713 | + return 0; |
|
714 | + } |
|
715 | + return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
|
716 | + } |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode |
|
721 | + * |
|
722 | + * @since 4.7.0 |
|
723 | + * @param string $shortcode the incoming shortcode |
|
724 | + * @return string parsed. |
|
725 | + * @throws EE_Error |
|
726 | + */ |
|
727 | + private function _get_payment_link_if_needed($shortcode) |
|
728 | + { |
|
729 | + $valid_shortcodes = array('transaction'); |
|
730 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
731 | + // ensure default is set. |
|
732 | + $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
733 | + $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
734 | + ? $addressee->txn->remaining() : 0; |
|
735 | + if ($total_owing > 0) { |
|
736 | + $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
|
737 | + $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
|
738 | + $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
|
739 | + $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
740 | + $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
741 | + $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
|
742 | + $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
743 | + $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
744 | + // we need to re run this string through the parser to catch any shortcodes that are in it. |
|
745 | + $owing_content = $this->_shortcode_helper->parse_message_template( |
|
746 | + $content, |
|
747 | + $addressee, |
|
748 | + $valid_shortcodes, |
|
749 | + $this->_message_type, |
|
750 | + $this->_messenger, |
|
751 | + $this->_message |
|
752 | + ); |
|
753 | + } else { |
|
754 | + return ''; |
|
755 | + } |
|
756 | + return $owing_content; |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode |
|
762 | + * |
|
763 | + * @since 4.8.28.rc.011 |
|
764 | + * @param string $shortcode The shortcode being parsed. |
|
765 | + * @param EE_Transaction $transaction |
|
766 | + * @return string |
|
767 | + * @throws EE_Error |
|
768 | + */ |
|
769 | + protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) |
|
770 | + { |
|
771 | + // if transaction is paid in full then we can just return an empty string |
|
772 | + if ($transaction->remaining() === 0) { |
|
773 | + return ''; |
|
774 | + } |
|
775 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
776 | + $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
|
777 | + $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30; |
|
778 | + $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
|
779 | + : esc_html__('Payment in full due by: ', 'event_espresso'); |
|
780 | + $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
|
781 | + // setup date due: |
|
782 | + try { |
|
783 | + if ($transaction_created instanceof DateTime) { |
|
784 | + $date_due = $transaction_created->add( |
|
785 | + new DateInterval('P' . $days_until_due . 'D') |
|
786 | + )->format($format); |
|
787 | + } else { |
|
788 | + throw new Exception(); |
|
789 | + } |
|
790 | + } catch (Exception $e) { |
|
791 | + // format was likely invalid. |
|
792 | + $date_due = esc_html__( |
|
793 | + 'Unable to calculate date due, likely the format string is invalid.', |
|
794 | + 'event_espresso' |
|
795 | + ); |
|
796 | + } |
|
797 | + return $prefix_text . $date_due; |
|
798 | + } |
|
799 | 799 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | && isset($this->_extra_data['data']) |
270 | 270 | && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
271 | 271 | : $payment; |
272 | - if (! $transaction instanceof EE_Transaction) { |
|
272 | + if ( ! $transaction instanceof EE_Transaction) { |
|
273 | 273 | return ''; |
274 | 274 | } |
275 | 275 | switch ($shortcode) { |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
288 | 288 | return sprintf( |
289 | 289 | esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
290 | - '<a href="' . $invoice_url . '">', |
|
290 | + '<a href="'.$invoice_url.'">', |
|
291 | 291 | '</a>' |
292 | 292 | ); |
293 | 293 | break; |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | return $this->_data->total_ticket_count; |
362 | 362 | break; |
363 | 363 | case '[TRANSACTION_ADMIN_URL]': |
364 | - require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
364 | + require_once EE_CORE.'admin/EE_Admin_Page.core.php'; |
|
365 | 365 | $query_args = array( |
366 | 366 | 'page' => 'espresso_transactions', |
367 | 367 | 'action' => 'view_transaction', |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | case '[RECEIPT_URL]': |
374 | 374 | // get primary_registration |
375 | 375 | $reg = $this->_data->primary_reg_obj; |
376 | - if (! $reg instanceof EE_Registration) { |
|
376 | + if ( ! $reg instanceof EE_Registration) { |
|
377 | 377 | return ''; |
378 | 378 | } |
379 | 379 | return $reg->receipt_url(); |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | if (empty($invoice_logo_url)) { |
493 | 493 | return ''; |
494 | 494 | } |
495 | - if (! $img_tags) { |
|
495 | + if ( ! $img_tags) { |
|
496 | 496 | return $invoice_logo_url; |
497 | 497 | } |
498 | 498 | // image tags have been requested. |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | } else { |
504 | 504 | $image_width = $image_size[0]; |
505 | 505 | } |
506 | - return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
506 | + return '<img class="logo screen" src="'.$invoice_logo_url.'" width="'.$image_width.'" alt="logo" />'; |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | */ |
541 | 541 | private function _get_invoice_payment_method() |
542 | 542 | { |
543 | - if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
543 | + if ( ! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
544 | 544 | $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
545 | 545 | $transaction = ! $transaction instanceof EE_Transaction |
546 | 546 | && is_array($this->_extra_data) |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | $attrs = $this->_get_shortcode_attrs($shortcode); |
609 | 609 | // prefix? |
610 | 610 | $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
611 | - return $prefix . $payee_tax_number; |
|
611 | + return $prefix.$payee_tax_number; |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | |
@@ -632,16 +632,16 @@ discard block |
||
632 | 632 | } |
633 | 633 | if (empty($payee_address)) { |
634 | 634 | $organization = EE_Registry::instance()->CFG->organization; |
635 | - $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
635 | + $payee_address = $organization->get_pretty('address_1').'<br>'; |
|
636 | 636 | $payee_address .= ! empty($organization->address_2) |
637 | - ? $organization->get_pretty('address_2') . '<br>' |
|
637 | + ? $organization->get_pretty('address_2').'<br>' |
|
638 | 638 | : ''; |
639 | - $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
639 | + $payee_address .= $organization->get_pretty('city').'<br>'; |
|
640 | 640 | // state |
641 | 641 | $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
642 | 642 | $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
643 | 643 | // Country |
644 | - $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
644 | + $payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : ''; |
|
645 | 645 | $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
646 | 646 | } |
647 | 647 | return $payee_address; |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | { |
678 | 678 | $reg = $this->_data->primary_reg_obj; |
679 | 679 | $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
680 | - if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
680 | + if ( ! $reg instanceof EE_Registration || empty($message_type)) { |
|
681 | 681 | return ''; |
682 | 682 | } |
683 | 683 | $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
@@ -685,13 +685,13 @@ discard block |
||
685 | 685 | ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
686 | 686 | $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
687 | 687 | $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
688 | - if (! $button) { |
|
688 | + if ( ! $button) { |
|
689 | 689 | return $switch_to_url; |
690 | 690 | } |
691 | - if (! empty($switch_to_url)) { |
|
691 | + if ( ! empty($switch_to_url)) { |
|
692 | 692 | return ' |
693 | - <form method="post" action="' . $switch_to_url . '" > |
|
694 | - <input class="print_button" type="submit" value="' . $switch_to_label . '" /> |
|
693 | + <form method="post" action="' . $switch_to_url.'" > |
|
694 | + <input class="print_button" type="submit" value="' . $switch_to_label.'" /> |
|
695 | 695 | </form> |
696 | 696 | '; |
697 | 697 | } |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | private function _get_subtotal($tax = false) |
710 | 710 | { |
711 | 711 | $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
712 | - if (! $grand_total instanceof EE_Line_Item) { |
|
712 | + if ( ! $grand_total instanceof EE_Line_Item) { |
|
713 | 713 | return 0; |
714 | 714 | } |
715 | 715 | return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
@@ -736,11 +736,11 @@ discard block |
||
736 | 736 | $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
737 | 737 | $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
738 | 738 | $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
739 | - $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
740 | - $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
739 | + $opening_tag = ! empty($container_tag) ? '<'.$container_tag : ''; |
|
740 | + $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag; |
|
741 | 741 | $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
742 | - $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
743 | - $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
742 | + $closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : ''; |
|
743 | + $content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag; |
|
744 | 744 | // we need to re run this string through the parser to catch any shortcodes that are in it. |
745 | 745 | $owing_content = $this->_shortcode_helper->parse_message_template( |
746 | 746 | $content, |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | try { |
783 | 783 | if ($transaction_created instanceof DateTime) { |
784 | 784 | $date_due = $transaction_created->add( |
785 | - new DateInterval('P' . $days_until_due . 'D') |
|
785 | + new DateInterval('P'.$days_until_due.'D') |
|
786 | 786 | )->format($format); |
787 | 787 | } else { |
788 | 788 | throw new Exception(); |
@@ -794,6 +794,6 @@ discard block |
||
794 | 794 | 'event_espresso' |
795 | 795 | ); |
796 | 796 | } |
797 | - return $prefix_text . $date_due; |
|
797 | + return $prefix_text.$date_due; |
|
798 | 798 | } |
799 | 799 | } |
@@ -17,315 +17,315 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * Will hold the EE_Event if available |
|
22 | - * |
|
23 | - * @var EE_Event |
|
24 | - */ |
|
25 | - protected $_event; |
|
26 | - |
|
27 | - /** |
|
28 | - * Will hold the EE_Venue if available |
|
29 | - * |
|
30 | - * @var EE_Venue |
|
31 | - */ |
|
32 | - protected $_venue; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Initialize properties |
|
37 | - */ |
|
38 | - protected function _init_props() |
|
39 | - { |
|
40 | - $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
41 | - $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
42 | - $this->_shortcodes = array( |
|
43 | - '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
44 | - '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
45 | - '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
46 | - '[VENUE_DETAILS_URL]' => sprintf( |
|
47 | - esc_html__( |
|
48 | - 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
49 | - 'event_espresso' |
|
50 | - ), |
|
51 | - '[VENUE_URL]' |
|
52 | - ), |
|
53 | - '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
54 | - '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
55 | - '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
56 | - '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
57 | - '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
58 | - '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
59 | - '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
60 | - '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
61 | - 'This just outputs the venue address in a semantic address format.', |
|
62 | - 'event_espresso' |
|
63 | - ), |
|
64 | - '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
65 | - '[VENUE_META_*]' => esc_html__( |
|
66 | - 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
67 | - 'event_espresso' |
|
68 | - ), |
|
69 | - '[GOOGLE_MAP_URL]' => esc_html__( |
|
70 | - 'URL for the google map associated with the venue.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
74 | - '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Parse incoming shortcode |
|
81 | - * |
|
82 | - * @param string $shortcode |
|
83 | - * @return string |
|
84 | - * @throws EE_Error |
|
85 | - * @throws EntityNotFoundException |
|
86 | - */ |
|
87 | - protected function _parser($shortcode) |
|
88 | - { |
|
89 | - $this->_venue = $this->_get_venue(); |
|
90 | - // If there is no venue object by now then get out. |
|
91 | - if (! $this->_venue instanceof EE_Venue) { |
|
92 | - return ''; |
|
93 | - } |
|
94 | - |
|
95 | - switch ($shortcode) { |
|
96 | - case '[VENUE_TITLE]': |
|
97 | - return $this->_venue('title'); |
|
98 | - break; |
|
99 | - |
|
100 | - case '[VENUE_DESCRIPTION]': |
|
101 | - return $this->_venue('description'); |
|
102 | - break; |
|
103 | - |
|
104 | - case '[VENUE_URL]': |
|
105 | - return $this->_venue('url'); |
|
106 | - break; |
|
107 | - |
|
108 | - case '[VENUE_IMAGE]': |
|
109 | - return $this->_venue('image'); |
|
110 | - break; |
|
111 | - |
|
112 | - case '[VENUE_PHONE]': |
|
113 | - return $this->_venue('phone'); |
|
114 | - break; |
|
115 | - |
|
116 | - case '[VENUE_ADDRESS]': |
|
117 | - return $this->_venue('address'); |
|
118 | - break; |
|
119 | - |
|
120 | - case '[VENUE_ADDRESS2]': |
|
121 | - return $this->_venue('address2'); |
|
122 | - break; |
|
123 | - |
|
124 | - case '[VENUE_CITY]': |
|
125 | - return $this->_venue('city'); |
|
126 | - break; |
|
127 | - |
|
128 | - case '[VENUE_COUNTRY]': |
|
129 | - return $this->_venue('country'); |
|
130 | - break; |
|
131 | - |
|
132 | - case '[VENUE_STATE]': |
|
133 | - return $this->_venue('state'); |
|
134 | - break; |
|
135 | - |
|
136 | - case '[VENUE_ZIP]': |
|
137 | - return $this->_venue('zip'); |
|
138 | - break; |
|
139 | - |
|
140 | - case '[VENUE_FORMATTED_ADDRESS]': |
|
141 | - return $this->_venue('formatted_address'); |
|
142 | - break; |
|
143 | - |
|
144 | - case '[GOOGLE_MAP_URL]': |
|
145 | - return $this->_venue('gmap_url'); |
|
146 | - break; |
|
147 | - |
|
148 | - case '[GOOGLE_MAP_LINK]': |
|
149 | - return $this->_venue('gmap_link'); |
|
150 | - break; |
|
151 | - |
|
152 | - case '[GOOGLE_MAP_IMAGE]': |
|
153 | - return $this->_venue('gmap_link_img'); |
|
154 | - break; |
|
155 | - |
|
156 | - case '[VENUE_DETAILS_URL]': |
|
157 | - return $this->_venue('permalink'); |
|
158 | - break; |
|
159 | - } |
|
160 | - |
|
161 | - if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
162 | - $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
163 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
164 | - |
|
165 | - // pull the meta value from the venue post |
|
166 | - $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
167 | - |
|
168 | - return ! empty($venue_meta) ? $venue_meta : ''; |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * This retrieves the EE_Venue from the available data object. |
|
174 | - * |
|
175 | - * @return EE_Venue|null |
|
176 | - * @throws EE_Error |
|
177 | - * @throws EntityNotFoundException |
|
178 | - */ |
|
179 | - private function _get_venue() |
|
180 | - { |
|
181 | - |
|
182 | - // we need the EE_Event object to get the venue. |
|
183 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
184 | - |
|
185 | - // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
186 | - // reg_obj instead. |
|
187 | - if (! $this->_event instanceof EE_Event) { |
|
188 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
189 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
190 | - |
|
191 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
192 | - ? $aee->reg_obj->event() |
|
193 | - : null; |
|
194 | - |
|
195 | - // if still empty do we have a ticket data item? |
|
196 | - $this->_event = ! $this->_event instanceof EE_Event |
|
197 | - && $this->_data instanceof EE_Ticket |
|
198 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
199 | - ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
200 | - : $this->_event; |
|
201 | - |
|
202 | - // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
203 | - // and use that. |
|
204 | - $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
205 | - ? reset($aee->events) |
|
206 | - : $this->_event; |
|
207 | - } |
|
208 | - |
|
209 | - // If we have an event object use it to pull the venue. |
|
210 | - if ($this->_event instanceof EE_Event) { |
|
211 | - return $this->_event->get_first_related('Venue'); |
|
212 | - } |
|
213 | - |
|
214 | - return null; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * This retrieves the specified venue information |
|
219 | - * |
|
220 | - * @param string $field What Venue field to retrieve |
|
221 | - * @return string What was retrieved! |
|
222 | - * @throws EE_Error |
|
223 | - * @throws EntityNotFoundException |
|
224 | - */ |
|
225 | - private function _venue($field) |
|
226 | - { |
|
227 | - |
|
228 | - if (! $this->_venue instanceof EE_Venue) { |
|
229 | - return ''; |
|
230 | - } //no venue so get out. |
|
231 | - |
|
232 | - switch ($field) { |
|
233 | - case 'title': |
|
234 | - return $this->_venue->get('VNU_name'); |
|
235 | - break; |
|
236 | - |
|
237 | - case 'description': |
|
238 | - return $this->_venue->get('VNU_desc'); |
|
239 | - break; |
|
240 | - |
|
241 | - case 'url': |
|
242 | - $url = $this->_venue->get('VNU_url'); |
|
243 | - return empty($url) ? $this->_venue->get_permalink() : $url; |
|
244 | - break; |
|
245 | - |
|
246 | - case 'permalink': |
|
247 | - return $this->_venue->get_permalink(); |
|
248 | - break; |
|
249 | - |
|
250 | - case 'image': |
|
251 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | - . '" alt="' . sprintf( |
|
253 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
254 | - $this->_venue->get('VNU_name') |
|
255 | - ) . '" />'; |
|
256 | - break; |
|
257 | - |
|
258 | - case 'phone': |
|
259 | - return $this->_venue->get('VNU_phone'); |
|
260 | - break; |
|
261 | - |
|
262 | - case 'address': |
|
263 | - return $this->_venue->get('VNU_address'); |
|
264 | - break; |
|
265 | - |
|
266 | - case 'address2': |
|
267 | - return $this->_venue->get('VNU_address2'); |
|
268 | - break; |
|
269 | - |
|
270 | - case 'city': |
|
271 | - return $this->_venue->get('VNU_city'); |
|
272 | - break; |
|
273 | - |
|
274 | - case 'state': |
|
275 | - $state = $this->_venue->state_obj(); |
|
276 | - return is_object($state) ? $state->get('STA_name') : ''; |
|
277 | - break; |
|
278 | - |
|
279 | - case 'country': |
|
280 | - $country = $this->_venue->country_obj(); |
|
281 | - return is_object($country) ? $country->get('CNT_name') : ''; |
|
282 | - break; |
|
283 | - |
|
284 | - case 'zip': |
|
285 | - return $this->_venue->get('VNU_zip'); |
|
286 | - break; |
|
287 | - |
|
288 | - case 'formatted_address': |
|
289 | - return EEH_Address::format($this->_venue); |
|
290 | - break; |
|
291 | - |
|
292 | - case 'gmap_link': |
|
293 | - case 'gmap_url': |
|
294 | - case 'gmap_link_img': |
|
295 | - $atts = $this->get_map_attributes($this->_venue, $field); |
|
296 | - return EEH_Maps::google_map_link($atts); |
|
297 | - break; |
|
298 | - } |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Generates the attributes for retrieving a google_map artifact. |
|
305 | - * |
|
306 | - * @param EE_Venue $venue |
|
307 | - * @param string $field |
|
308 | - * @return array |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
312 | - { |
|
313 | - $state = $venue->state_obj(); |
|
314 | - $country = $venue->country_obj(); |
|
315 | - $atts = array( |
|
316 | - 'id' => $venue->ID(), |
|
317 | - 'address' => $venue->get('VNU_address'), |
|
318 | - 'city' => $venue->get('VNU_city'), |
|
319 | - 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
320 | - 'zip' => $venue->get('VNU_zip'), |
|
321 | - 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
322 | - 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
323 | - 'map_w' => 200, |
|
324 | - 'map_h' => 200, |
|
325 | - ); |
|
326 | - if ($field === 'gmap_url') { |
|
327 | - $atts['type'] = 'url_only'; |
|
328 | - } |
|
329 | - return $atts; |
|
330 | - } |
|
20 | + /** |
|
21 | + * Will hold the EE_Event if available |
|
22 | + * |
|
23 | + * @var EE_Event |
|
24 | + */ |
|
25 | + protected $_event; |
|
26 | + |
|
27 | + /** |
|
28 | + * Will hold the EE_Venue if available |
|
29 | + * |
|
30 | + * @var EE_Venue |
|
31 | + */ |
|
32 | + protected $_venue; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Initialize properties |
|
37 | + */ |
|
38 | + protected function _init_props() |
|
39 | + { |
|
40 | + $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
41 | + $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
42 | + $this->_shortcodes = array( |
|
43 | + '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
44 | + '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
45 | + '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
46 | + '[VENUE_DETAILS_URL]' => sprintf( |
|
47 | + esc_html__( |
|
48 | + 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
49 | + 'event_espresso' |
|
50 | + ), |
|
51 | + '[VENUE_URL]' |
|
52 | + ), |
|
53 | + '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
54 | + '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
55 | + '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
56 | + '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
57 | + '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
58 | + '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
59 | + '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
60 | + '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
61 | + 'This just outputs the venue address in a semantic address format.', |
|
62 | + 'event_espresso' |
|
63 | + ), |
|
64 | + '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
65 | + '[VENUE_META_*]' => esc_html__( |
|
66 | + 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
67 | + 'event_espresso' |
|
68 | + ), |
|
69 | + '[GOOGLE_MAP_URL]' => esc_html__( |
|
70 | + 'URL for the google map associated with the venue.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
74 | + '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Parse incoming shortcode |
|
81 | + * |
|
82 | + * @param string $shortcode |
|
83 | + * @return string |
|
84 | + * @throws EE_Error |
|
85 | + * @throws EntityNotFoundException |
|
86 | + */ |
|
87 | + protected function _parser($shortcode) |
|
88 | + { |
|
89 | + $this->_venue = $this->_get_venue(); |
|
90 | + // If there is no venue object by now then get out. |
|
91 | + if (! $this->_venue instanceof EE_Venue) { |
|
92 | + return ''; |
|
93 | + } |
|
94 | + |
|
95 | + switch ($shortcode) { |
|
96 | + case '[VENUE_TITLE]': |
|
97 | + return $this->_venue('title'); |
|
98 | + break; |
|
99 | + |
|
100 | + case '[VENUE_DESCRIPTION]': |
|
101 | + return $this->_venue('description'); |
|
102 | + break; |
|
103 | + |
|
104 | + case '[VENUE_URL]': |
|
105 | + return $this->_venue('url'); |
|
106 | + break; |
|
107 | + |
|
108 | + case '[VENUE_IMAGE]': |
|
109 | + return $this->_venue('image'); |
|
110 | + break; |
|
111 | + |
|
112 | + case '[VENUE_PHONE]': |
|
113 | + return $this->_venue('phone'); |
|
114 | + break; |
|
115 | + |
|
116 | + case '[VENUE_ADDRESS]': |
|
117 | + return $this->_venue('address'); |
|
118 | + break; |
|
119 | + |
|
120 | + case '[VENUE_ADDRESS2]': |
|
121 | + return $this->_venue('address2'); |
|
122 | + break; |
|
123 | + |
|
124 | + case '[VENUE_CITY]': |
|
125 | + return $this->_venue('city'); |
|
126 | + break; |
|
127 | + |
|
128 | + case '[VENUE_COUNTRY]': |
|
129 | + return $this->_venue('country'); |
|
130 | + break; |
|
131 | + |
|
132 | + case '[VENUE_STATE]': |
|
133 | + return $this->_venue('state'); |
|
134 | + break; |
|
135 | + |
|
136 | + case '[VENUE_ZIP]': |
|
137 | + return $this->_venue('zip'); |
|
138 | + break; |
|
139 | + |
|
140 | + case '[VENUE_FORMATTED_ADDRESS]': |
|
141 | + return $this->_venue('formatted_address'); |
|
142 | + break; |
|
143 | + |
|
144 | + case '[GOOGLE_MAP_URL]': |
|
145 | + return $this->_venue('gmap_url'); |
|
146 | + break; |
|
147 | + |
|
148 | + case '[GOOGLE_MAP_LINK]': |
|
149 | + return $this->_venue('gmap_link'); |
|
150 | + break; |
|
151 | + |
|
152 | + case '[GOOGLE_MAP_IMAGE]': |
|
153 | + return $this->_venue('gmap_link_img'); |
|
154 | + break; |
|
155 | + |
|
156 | + case '[VENUE_DETAILS_URL]': |
|
157 | + return $this->_venue('permalink'); |
|
158 | + break; |
|
159 | + } |
|
160 | + |
|
161 | + if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
162 | + $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
163 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
164 | + |
|
165 | + // pull the meta value from the venue post |
|
166 | + $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
167 | + |
|
168 | + return ! empty($venue_meta) ? $venue_meta : ''; |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * This retrieves the EE_Venue from the available data object. |
|
174 | + * |
|
175 | + * @return EE_Venue|null |
|
176 | + * @throws EE_Error |
|
177 | + * @throws EntityNotFoundException |
|
178 | + */ |
|
179 | + private function _get_venue() |
|
180 | + { |
|
181 | + |
|
182 | + // we need the EE_Event object to get the venue. |
|
183 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
184 | + |
|
185 | + // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
186 | + // reg_obj instead. |
|
187 | + if (! $this->_event instanceof EE_Event) { |
|
188 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
189 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
190 | + |
|
191 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
192 | + ? $aee->reg_obj->event() |
|
193 | + : null; |
|
194 | + |
|
195 | + // if still empty do we have a ticket data item? |
|
196 | + $this->_event = ! $this->_event instanceof EE_Event |
|
197 | + && $this->_data instanceof EE_Ticket |
|
198 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
199 | + ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
200 | + : $this->_event; |
|
201 | + |
|
202 | + // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
203 | + // and use that. |
|
204 | + $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
205 | + ? reset($aee->events) |
|
206 | + : $this->_event; |
|
207 | + } |
|
208 | + |
|
209 | + // If we have an event object use it to pull the venue. |
|
210 | + if ($this->_event instanceof EE_Event) { |
|
211 | + return $this->_event->get_first_related('Venue'); |
|
212 | + } |
|
213 | + |
|
214 | + return null; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * This retrieves the specified venue information |
|
219 | + * |
|
220 | + * @param string $field What Venue field to retrieve |
|
221 | + * @return string What was retrieved! |
|
222 | + * @throws EE_Error |
|
223 | + * @throws EntityNotFoundException |
|
224 | + */ |
|
225 | + private function _venue($field) |
|
226 | + { |
|
227 | + |
|
228 | + if (! $this->_venue instanceof EE_Venue) { |
|
229 | + return ''; |
|
230 | + } //no venue so get out. |
|
231 | + |
|
232 | + switch ($field) { |
|
233 | + case 'title': |
|
234 | + return $this->_venue->get('VNU_name'); |
|
235 | + break; |
|
236 | + |
|
237 | + case 'description': |
|
238 | + return $this->_venue->get('VNU_desc'); |
|
239 | + break; |
|
240 | + |
|
241 | + case 'url': |
|
242 | + $url = $this->_venue->get('VNU_url'); |
|
243 | + return empty($url) ? $this->_venue->get_permalink() : $url; |
|
244 | + break; |
|
245 | + |
|
246 | + case 'permalink': |
|
247 | + return $this->_venue->get_permalink(); |
|
248 | + break; |
|
249 | + |
|
250 | + case 'image': |
|
251 | + return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | + . '" alt="' . sprintf( |
|
253 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
254 | + $this->_venue->get('VNU_name') |
|
255 | + ) . '" />'; |
|
256 | + break; |
|
257 | + |
|
258 | + case 'phone': |
|
259 | + return $this->_venue->get('VNU_phone'); |
|
260 | + break; |
|
261 | + |
|
262 | + case 'address': |
|
263 | + return $this->_venue->get('VNU_address'); |
|
264 | + break; |
|
265 | + |
|
266 | + case 'address2': |
|
267 | + return $this->_venue->get('VNU_address2'); |
|
268 | + break; |
|
269 | + |
|
270 | + case 'city': |
|
271 | + return $this->_venue->get('VNU_city'); |
|
272 | + break; |
|
273 | + |
|
274 | + case 'state': |
|
275 | + $state = $this->_venue->state_obj(); |
|
276 | + return is_object($state) ? $state->get('STA_name') : ''; |
|
277 | + break; |
|
278 | + |
|
279 | + case 'country': |
|
280 | + $country = $this->_venue->country_obj(); |
|
281 | + return is_object($country) ? $country->get('CNT_name') : ''; |
|
282 | + break; |
|
283 | + |
|
284 | + case 'zip': |
|
285 | + return $this->_venue->get('VNU_zip'); |
|
286 | + break; |
|
287 | + |
|
288 | + case 'formatted_address': |
|
289 | + return EEH_Address::format($this->_venue); |
|
290 | + break; |
|
291 | + |
|
292 | + case 'gmap_link': |
|
293 | + case 'gmap_url': |
|
294 | + case 'gmap_link_img': |
|
295 | + $atts = $this->get_map_attributes($this->_venue, $field); |
|
296 | + return EEH_Maps::google_map_link($atts); |
|
297 | + break; |
|
298 | + } |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Generates the attributes for retrieving a google_map artifact. |
|
305 | + * |
|
306 | + * @param EE_Venue $venue |
|
307 | + * @param string $field |
|
308 | + * @return array |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
312 | + { |
|
313 | + $state = $venue->state_obj(); |
|
314 | + $country = $venue->country_obj(); |
|
315 | + $atts = array( |
|
316 | + 'id' => $venue->ID(), |
|
317 | + 'address' => $venue->get('VNU_address'), |
|
318 | + 'city' => $venue->get('VNU_city'), |
|
319 | + 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
320 | + 'zip' => $venue->get('VNU_zip'), |
|
321 | + 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
322 | + 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
323 | + 'map_w' => 200, |
|
324 | + 'map_h' => 200, |
|
325 | + ); |
|
326 | + if ($field === 'gmap_url') { |
|
327 | + $atts['type'] = 'url_only'; |
|
328 | + } |
|
329 | + return $atts; |
|
330 | + } |
|
331 | 331 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | { |
89 | 89 | $this->_venue = $this->_get_venue(); |
90 | 90 | // If there is no venue object by now then get out. |
91 | - if (! $this->_venue instanceof EE_Venue) { |
|
91 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
92 | 92 | return ''; |
93 | 93 | } |
94 | 94 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
186 | 186 | // reg_obj instead. |
187 | - if (! $this->_event instanceof EE_Event) { |
|
187 | + if ( ! $this->_event instanceof EE_Event) { |
|
188 | 188 | $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
189 | 189 | $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
190 | 190 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $this->_event = ! $this->_event instanceof EE_Event |
197 | 197 | && $this->_data instanceof EE_Ticket |
198 | 198 | && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
199 | - ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
199 | + ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
200 | 200 | : $this->_event; |
201 | 201 | |
202 | 202 | // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | private function _venue($field) |
226 | 226 | { |
227 | 227 | |
228 | - if (! $this->_venue instanceof EE_Venue) { |
|
228 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
229 | 229 | return ''; |
230 | 230 | } //no venue so get out. |
231 | 231 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | break; |
249 | 249 | |
250 | 250 | case 'image': |
251 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | - . '" alt="' . sprintf( |
|
251 | + return '<img src="'.$this->_venue->feature_image_url(array(200, 200,)) |
|
252 | + . '" alt="'.sprintf( |
|
253 | 253 | esc_attr__('%s Feature Image', 'event_espresso'), |
254 | 254 | $this->_venue->get('VNU_name') |
255 | - ) . '" />'; |
|
255 | + ).'" />'; |
|
256 | 256 | break; |
257 | 257 | |
258 | 258 | case 'phone': |