Completed
Branch master (7421d0)
by
unknown
11:25 queued 06:55
created
core/libraries/shortcodes/EE_Shortcodes.lib.php 2 patches
Indentation   +448 added lines, -448 removed lines patch added patch discarded remove patch
@@ -15,452 +15,452 @@
 block discarded – undo
15 15
  */
16 16
 abstract class EE_Shortcodes extends EE_Base
17 17
 {
18
-    /**
19
-     * holds label for library
20
-     * This is used for referencing the library label
21
-     *
22
-     * @var string
23
-     */
24
-    public string $label;
25
-
26
-
27
-    public string $name;
28
-
29
-
30
-    /**
31
-     * This property is used for referencing a short description of the library
32
-     *
33
-     * @var string
34
-     */
35
-    public string $description;
36
-
37
-
38
-    /**
39
-     * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a
40
-     * label/description for the shortcode.
41
-     *
42
-     * @var array
43
-     */
44
-    protected array $_shortcodes = [];
45
-
46
-
47
-    /**
48
-     * This will hold the incoming data item sent to the parser method
49
-     *
50
-     * @var array|object
51
-     */
52
-    protected $_data;
53
-
54
-
55
-    /**
56
-     * some shortcodes may require extra data to parse.  This property is provided for that.
57
-     *
58
-     * @var array|EE_Messages_Addressee
59
-     */
60
-    protected $_extra_data;
61
-
62
-
63
-    /**
64
-     * EE_messenger used to generate the template being parsed.
65
-     *
66
-     * @since 4.5.0
67
-     * @var EE_messenger
68
-     */
69
-    protected EE_messenger $_messenger;
70
-
71
-
72
-    /**
73
-     * message type used to generate the template being parsed.
74
-     *
75
-     * @since 4.5.0
76
-     * @var EE_message_type|null
77
-     */
78
-    protected ?EE_message_type $_message_type = null;
79
-
80
-
81
-    /**
82
-     * context used for the template being parsed
83
-     *
84
-     * @since 4.5.0
85
-     * @var string
86
-     */
87
-    protected string $_context;
88
-
89
-
90
-    /**
91
-     * Specific Message Template Group ID
92
-     *
93
-     * @since 4.5.0
94
-     * @var int
95
-     */
96
-    protected int $_GRP_ID;
97
-
98
-
99
-    /**
100
-     * @since 4.9.0
101
-     * @type EE_Message|null
102
-     */
103
-    protected ?EE_Message $_message = null;
104
-
105
-
106
-    /**
107
-     * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type
108
-     * shortcodes
109
-     *
110
-     * @var EEH_Parse_Shortcodes
111
-     */
112
-    protected EEH_Parse_Shortcodes $_shortcode_helper;
113
-
114
-
115
-    public function __construct()
116
-    {
117
-        $this->_set_defaults();
118
-        $this->_set_shortcode_helper();
119
-        $this->_init_props();
120
-    }
121
-
122
-
123
-    /**
124
-     * This sets the defaults for the properties.  Child classes will override these properties in their _init_props
125
-     * method
126
-     */
127
-    private function _set_defaults()
128
-    {
129
-        $this->name        = $this->description = '';
130
-        $this->_shortcodes = [];
131
-    }
132
-
133
-
134
-    /**
135
-     * loads an instance of the EE_Shortcode_Parser helper when requested
136
-     */
137
-    protected function _set_shortcode_helper()
138
-    {
139
-        // get shortcode_replace instance - set when _get_messages is called in child...
140
-        $this->_shortcode_helper = new EEH_Parse_Shortcodes();
141
-    }
142
-
143
-
144
-    public function get_shortcode_helper(): EEH_Parse_Shortcodes
145
-    {
146
-        return $this->_shortcode_helper;
147
-    }
148
-
149
-
150
-    /**
151
-     * This is the public method for kicking of the parser included with each child.  It can be overridden by child
152
-     * classes if necessary (see EE_Questions_Answers for example)
153
-     *
154
-     * @param string       $shortcode  incoming shortcode to be parsed
155
-     * @param object|array $data       incoming data to be used for parsing
156
-     * @param object|array $extra_data extra incoming data (usually EE_Messages_Addressee)
157
-     * @return string            parsed shortcode.
158
-     */
159
-    public function parser(string $shortcode, $data, $extra_data = []): string
160
-    {
161
-        // filter setup shortcodes
162
-        $this->_shortcodes = $this->get_shortcodes();
163
-
164
-        // we need to set up any dynamic shortcodes so that they work with the array_key_exists
165
-        preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
166
-        $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
167
-
168
-        // first we want to make sure this is a valid shortcode
169
-        if (! array_key_exists($sc_to_verify, $this->_shortcodes)) {
170
-            // get out, this parser doesn't handle the incoming shortcode.
171
-            return '';
172
-        }
173
-        $this->_data       = $data;
174
-        $this->_extra_data = $extra_data;
175
-        $this->_set_messages_properties();
176
-        $parsed = (string) apply_filters(
177
-            'FHEE__' . get_class($this) . '__parser_after',
178
-            $this->_parser($shortcode),
179
-            $shortcode,
180
-            $data,
181
-            $extra_data,
182
-            $this
183
-        );
184
-
185
-        // note the below filter applies to ALL shortcode parsers... be careful!
186
-        return (string) apply_filters(
187
-            'FHEE__EE_Shortcodes__parser_after',
188
-            $parsed,
189
-            $shortcode,
190
-            $data,
191
-            $extra_data,
192
-            $this
193
-        );
194
-    }
195
-
196
-
197
-    /**
198
-     * This method just returns the shortcodes in the $_shortcodes array property.
199
-     *
200
-     * @return array array of shortcodes => description pairs
201
-     */
202
-    public function get_shortcodes(): array
203
-    {
204
-        $this->_shortcodes =
205
-            (array) 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 = (array) 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
-     * @return void
219
-     */
220
-    abstract protected function _init_props();
221
-
222
-
223
-    /**
224
-     * This method will give parsing instructions for each shortcode defined in the _shortcodes array.  Child methods
225
-     * will have to take care of handling.
226
-     *
227
-     * @abstract
228
-     * @param string $shortcode    the shortcode to be parsed.
229
-     * @return string parsed shortcode
230
-     */
231
-    abstract protected function _parser($shortcode);
232
-
233
-
234
-    /**
235
-     * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it
236
-     * meets their requirements
237
-     *
238
-     * @return void If validation fails we'll throw an exception.
239
-     * @throws EE_Error
240
-     */
241
-    protected function _validate_list_requirements()
242
-    {
243
-        // first test to make sure we've got an array!
244
-        if (! is_array($this->_data)) {
245
-            throw new EE_Error(
246
-                sprintf(
247
-                    esc_html__(
248
-                        'Expecting an array for the data sent to %s. Instead it was %s',
249
-                        'event_espresso'
250
-                    ),
251
-                    get_class($this),
252
-                    gettype($this->_data)
253
-                )
254
-            );
255
-        }
256
-
257
-        // next test to make sure we've got the required template in the index!
258
-        if (! isset($this->_data['template'])) {
259
-            throw new EE_Error(
260
-                esc_html__(
261
-                    'The incoming data does not have the required template index in its array',
262
-                    'event_espresso'
263
-                )
264
-            );
265
-        }
266
-
267
-        // next test to make sure we've got a data index in the incoming data array
268
-        if (! isset($this->_data['data'])) {
269
-            throw new EE_Error(
270
-                esc_html__(
271
-                    'The incoming data does not have the required data index in its array',
272
-                    'event_espresso'
273
-                )
274
-            );
275
-        }
276
-
277
-        // all is well let's make sure _extra_data always has the values needed.
278
-        // let's make sure that extra_data includes all templates (for later parsing if necessary)
279
-        if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) {
280
-            $this->_extra_data['data']     = $this->_data['data'];
281
-            $this->_extra_data['template'] = $this->_data['template'];
282
-        }
283
-    }
284
-
285
-
286
-    /**
287
-     * This returns any attributes that may be existing on an EE_Shortcode
288
-     *
289
-     * @param string $shortcode incoming shortcode
290
-     * @return array An array with the attributes
291
-     * @since 4.5.0
292
-     */
293
-    protected function _get_shortcode_attrs(string $shortcode): array
294
-    {
295
-        // make sure the required wp helper function is present
296
-        // require the shortcode file if necessary
297
-        if (! function_exists('shortcode_parse_atts')) {
298
-            require_once(ABSPATH . WPINC . '/shortcodes.php');
299
-        }
300
-
301
-        // let's get any attributes that may be present and set the defaults.
302
-        $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode));
303
-        return shortcode_parse_atts($shortcode_to_parse);
304
-    }
305
-
306
-
307
-    /**
308
-     * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding
309
-     * closing tag (eg `[/IF_*]`).  The content within the tags will be displayed/hidden depending on whatever
310
-     * conditions existed in the opening tag.  This method handles parsing the actual template to show/hide this
311
-     * conditional content.
312
-     *
313
-     * @param string $shortcode This should be original shortcode as used in the template and passed to the parser.
314
-     * @param bool   $show      true means the opening and closing tags are removed and the content is left showing,
315
-     *                          false means the opening and closing tags and the contained content are removed.
316
-     * @return string     The template for the shortcode is returned.
317
-     * @since 4.9.32
318
-     *
319
-     */
320
-    protected function _mutate_conditional_block_in_template(string $shortcode, bool $show = true): string
321
-    {
322
-        // first let's get all the matches in the template for this particular shortcode.
323
-        preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches);
324
-
325
-        if ($matches && is_array($matches[0]) && ! empty($matches[0])) {
326
-            // we need to hide all instances of the matches
327
-            foreach ($matches[0] as $index => $content_to_show_or_hide) {
328
-                $content_to_show_or_hide = preg_quote($content_to_show_or_hide);
329
-                $replacement             = $show ? $matches[4][ $index ] : '';
330
-                $this->_data['template'] = preg_replace(
331
-                    '~' . $content_to_show_or_hide . '~',
332
-                    $replacement,
333
-                    $this->_data['template']
334
-                );
335
-            }
336
-        }
337
-        // return $template
338
-        return $this->_data['template'];
339
-    }
340
-
341
-
342
-    /**
343
-     * This returns the regex pattern to use for conditional shortcodes parsing.
344
-     *
345
-     * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php
346
-     *
347
-     * @param string $shortcode
348
-     * @return string
349
-     * @since 4.9.32
350
-     */
351
-    private function _get_conditional_block_regex(string $shortcode): string
352
-    {
353
-        // get just the shortcode tag for the match
354
-        preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches);
355
-        if (empty($shortcode_tag_matches[1])) {
356
-            return $this->_data['template'];
357
-        }
358
-
359
-        $shortcode_tag = $shortcode_tag_matches[1];
360
-        // get attributes_part_of_tag
361
-        $attributes_part = preg_quote(str_replace([$shortcode_tag, '[', ']'], '', $shortcode));
362
-        // escape
363
-        $shortcode_tag = preg_quote($shortcode_tag);
364
-
365
-        return
366
-            '\['                                  // Opening Bracket
367
-            . "($shortcode_tag)$attributes_part"    // 1: Shortcode Name
368
-            . '(?![\w-])'                           // Not followed by word character or hyphen
369
-            . '('                                   // 2: Unroll the loop: Inside the opening shortcode tag
370
-            . '[^\]\/]*'                          // Not a closing bracket or forward slash
371
-            . '(?:'
372
-            . '\/(?!\])'                      // A forward slash not followed by a closing bracket
373
-            . '[^\]\/]*'                      // Not a closing bracket or forward slash.
374
-            . ')*?'
375
-            . ')'
376
-            . '(?:'
377
-            . '(\/)'                              // 3. Self closing tag ...
378
-            . '\]'                                // ... and closing bracket
379
-            . '|'
380
-            . '\]'                                // Closing bracket
381
-            . '(?:'
382
-            . '('                             // 4: Unroll the loop: Optionally, anything between the opening and closing brackets
383
-            . '[^\[]*+'                   // Not an opening bracket
384
-            . '(?:'
385
-            . '\[(?!\/\1\])'          // An opening bracket not followed by the closing shortcode tag.
386
-            . '[^\[]*+'               // Not an opening bracket
387
-            . ')*+'
388
-            . ')'
389
-            . '\[\/\1\]'                      // Closing shortcode tag
390
-            . ')?'
391
-            . ')';
392
-    }
393
-
394
-
395
-    /**
396
-     * This sets the properties related to the messages system
397
-     *
398
-     * @return void
399
-     * @since 4.5.0
400
-     */
401
-    protected function _set_messages_properties()
402
-    {
403
-        // should be in _extra_data
404
-        if (isset($this->_extra_data['messenger'])) {
405
-            $this->_messenger    = $this->_extra_data['messenger'];
406
-            $this->_message_type = $this->_extra_data['message_type'];
407
-            $this->_context      = $this->_extra_data['message'] instanceof EE_Message
408
-                ? $this->_extra_data['message']->context()
409
-                : '';
410
-            $this->_GRP_ID       = $this->_extra_data['message'] instanceof EE_Message
411
-                ? $this->_extra_data['message']->GRP_ID()
412
-                : 0;
413
-            $this->_message      = $this->_extra_data['message'] instanceof EE_Message
414
-                ? $this->_extra_data['message']
415
-                : null;
416
-        }
417
-    }
418
-
419
-
420
-    /**
421
-     * This returns whatever the set message type object is that was set on this shortcode parser.
422
-     *
423
-     * @return EE_message_type|null
424
-     * @since 4.5.0
425
-     */
426
-    public function get_set_message_type(): ?EE_message_type
427
-    {
428
-        return $this->_message_type;
429
-    }
430
-
431
-
432
-    /**
433
-     * This returns whatever the set messenger object is that was set on this shortcode parser
434
-     *
435
-     * @return EE_messenger
436
-     * @since 4.5.0
437
-     */
438
-    public function get_set_messenger(): EE_messenger
439
-    {
440
-        return $this->_messenger;
441
-    }
442
-
443
-
444
-    /**
445
-     * This returns whatever the set context string is on this shortcode parser.
446
-     *
447
-     * @return string
448
-     * @since 4.5.0
449
-     */
450
-    public function get_set_context(): string
451
-    {
452
-        return $this->_context;
453
-    }
454
-
455
-
456
-    /**
457
-     * This returns whatever the set EE_Message object is on this shortcode.
458
-     *
459
-     * @return EE_Message|null
460
-     * @since 4.9.0
461
-     */
462
-    public function get_set_message(): ?EE_Message
463
-    {
464
-        return $this->_message;
465
-    }
18
+	/**
19
+	 * holds label for library
20
+	 * This is used for referencing the library label
21
+	 *
22
+	 * @var string
23
+	 */
24
+	public string $label;
25
+
26
+
27
+	public string $name;
28
+
29
+
30
+	/**
31
+	 * This property is used for referencing a short description of the library
32
+	 *
33
+	 * @var string
34
+	 */
35
+	public string $description;
36
+
37
+
38
+	/**
39
+	 * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a
40
+	 * label/description for the shortcode.
41
+	 *
42
+	 * @var array
43
+	 */
44
+	protected array $_shortcodes = [];
45
+
46
+
47
+	/**
48
+	 * This will hold the incoming data item sent to the parser method
49
+	 *
50
+	 * @var array|object
51
+	 */
52
+	protected $_data;
53
+
54
+
55
+	/**
56
+	 * some shortcodes may require extra data to parse.  This property is provided for that.
57
+	 *
58
+	 * @var array|EE_Messages_Addressee
59
+	 */
60
+	protected $_extra_data;
61
+
62
+
63
+	/**
64
+	 * EE_messenger used to generate the template being parsed.
65
+	 *
66
+	 * @since 4.5.0
67
+	 * @var EE_messenger
68
+	 */
69
+	protected EE_messenger $_messenger;
70
+
71
+
72
+	/**
73
+	 * message type used to generate the template being parsed.
74
+	 *
75
+	 * @since 4.5.0
76
+	 * @var EE_message_type|null
77
+	 */
78
+	protected ?EE_message_type $_message_type = null;
79
+
80
+
81
+	/**
82
+	 * context used for the template being parsed
83
+	 *
84
+	 * @since 4.5.0
85
+	 * @var string
86
+	 */
87
+	protected string $_context;
88
+
89
+
90
+	/**
91
+	 * Specific Message Template Group ID
92
+	 *
93
+	 * @since 4.5.0
94
+	 * @var int
95
+	 */
96
+	protected int $_GRP_ID;
97
+
98
+
99
+	/**
100
+	 * @since 4.9.0
101
+	 * @type EE_Message|null
102
+	 */
103
+	protected ?EE_Message $_message = null;
104
+
105
+
106
+	/**
107
+	 * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type
108
+	 * shortcodes
109
+	 *
110
+	 * @var EEH_Parse_Shortcodes
111
+	 */
112
+	protected EEH_Parse_Shortcodes $_shortcode_helper;
113
+
114
+
115
+	public function __construct()
116
+	{
117
+		$this->_set_defaults();
118
+		$this->_set_shortcode_helper();
119
+		$this->_init_props();
120
+	}
121
+
122
+
123
+	/**
124
+	 * This sets the defaults for the properties.  Child classes will override these properties in their _init_props
125
+	 * method
126
+	 */
127
+	private function _set_defaults()
128
+	{
129
+		$this->name        = $this->description = '';
130
+		$this->_shortcodes = [];
131
+	}
132
+
133
+
134
+	/**
135
+	 * loads an instance of the EE_Shortcode_Parser helper when requested
136
+	 */
137
+	protected function _set_shortcode_helper()
138
+	{
139
+		// get shortcode_replace instance - set when _get_messages is called in child...
140
+		$this->_shortcode_helper = new EEH_Parse_Shortcodes();
141
+	}
142
+
143
+
144
+	public function get_shortcode_helper(): EEH_Parse_Shortcodes
145
+	{
146
+		return $this->_shortcode_helper;
147
+	}
148
+
149
+
150
+	/**
151
+	 * This is the public method for kicking of the parser included with each child.  It can be overridden by child
152
+	 * classes if necessary (see EE_Questions_Answers for example)
153
+	 *
154
+	 * @param string       $shortcode  incoming shortcode to be parsed
155
+	 * @param object|array $data       incoming data to be used for parsing
156
+	 * @param object|array $extra_data extra incoming data (usually EE_Messages_Addressee)
157
+	 * @return string            parsed shortcode.
158
+	 */
159
+	public function parser(string $shortcode, $data, $extra_data = []): string
160
+	{
161
+		// filter setup shortcodes
162
+		$this->_shortcodes = $this->get_shortcodes();
163
+
164
+		// we need to set up any dynamic shortcodes so that they work with the array_key_exists
165
+		preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
166
+		$sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
167
+
168
+		// first we want to make sure this is a valid shortcode
169
+		if (! array_key_exists($sc_to_verify, $this->_shortcodes)) {
170
+			// get out, this parser doesn't handle the incoming shortcode.
171
+			return '';
172
+		}
173
+		$this->_data       = $data;
174
+		$this->_extra_data = $extra_data;
175
+		$this->_set_messages_properties();
176
+		$parsed = (string) apply_filters(
177
+			'FHEE__' . get_class($this) . '__parser_after',
178
+			$this->_parser($shortcode),
179
+			$shortcode,
180
+			$data,
181
+			$extra_data,
182
+			$this
183
+		);
184
+
185
+		// note the below filter applies to ALL shortcode parsers... be careful!
186
+		return (string) apply_filters(
187
+			'FHEE__EE_Shortcodes__parser_after',
188
+			$parsed,
189
+			$shortcode,
190
+			$data,
191
+			$extra_data,
192
+			$this
193
+		);
194
+	}
195
+
196
+
197
+	/**
198
+	 * This method just returns the shortcodes in the $_shortcodes array property.
199
+	 *
200
+	 * @return array array of shortcodes => description pairs
201
+	 */
202
+	public function get_shortcodes(): array
203
+	{
204
+		$this->_shortcodes =
205
+			(array) 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 = (array) 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
+	 * @return void
219
+	 */
220
+	abstract protected function _init_props();
221
+
222
+
223
+	/**
224
+	 * This method will give parsing instructions for each shortcode defined in the _shortcodes array.  Child methods
225
+	 * will have to take care of handling.
226
+	 *
227
+	 * @abstract
228
+	 * @param string $shortcode    the shortcode to be parsed.
229
+	 * @return string parsed shortcode
230
+	 */
231
+	abstract protected function _parser($shortcode);
232
+
233
+
234
+	/**
235
+	 * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it
236
+	 * meets their requirements
237
+	 *
238
+	 * @return void If validation fails we'll throw an exception.
239
+	 * @throws EE_Error
240
+	 */
241
+	protected function _validate_list_requirements()
242
+	{
243
+		// first test to make sure we've got an array!
244
+		if (! is_array($this->_data)) {
245
+			throw new EE_Error(
246
+				sprintf(
247
+					esc_html__(
248
+						'Expecting an array for the data sent to %s. Instead it was %s',
249
+						'event_espresso'
250
+					),
251
+					get_class($this),
252
+					gettype($this->_data)
253
+				)
254
+			);
255
+		}
256
+
257
+		// next test to make sure we've got the required template in the index!
258
+		if (! isset($this->_data['template'])) {
259
+			throw new EE_Error(
260
+				esc_html__(
261
+					'The incoming data does not have the required template index in its array',
262
+					'event_espresso'
263
+				)
264
+			);
265
+		}
266
+
267
+		// next test to make sure we've got a data index in the incoming data array
268
+		if (! isset($this->_data['data'])) {
269
+			throw new EE_Error(
270
+				esc_html__(
271
+					'The incoming data does not have the required data index in its array',
272
+					'event_espresso'
273
+				)
274
+			);
275
+		}
276
+
277
+		// all is well let's make sure _extra_data always has the values needed.
278
+		// let's make sure that extra_data includes all templates (for later parsing if necessary)
279
+		if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) {
280
+			$this->_extra_data['data']     = $this->_data['data'];
281
+			$this->_extra_data['template'] = $this->_data['template'];
282
+		}
283
+	}
284
+
285
+
286
+	/**
287
+	 * This returns any attributes that may be existing on an EE_Shortcode
288
+	 *
289
+	 * @param string $shortcode incoming shortcode
290
+	 * @return array An array with the attributes
291
+	 * @since 4.5.0
292
+	 */
293
+	protected function _get_shortcode_attrs(string $shortcode): array
294
+	{
295
+		// make sure the required wp helper function is present
296
+		// require the shortcode file if necessary
297
+		if (! function_exists('shortcode_parse_atts')) {
298
+			require_once(ABSPATH . WPINC . '/shortcodes.php');
299
+		}
300
+
301
+		// let's get any attributes that may be present and set the defaults.
302
+		$shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode));
303
+		return shortcode_parse_atts($shortcode_to_parse);
304
+	}
305
+
306
+
307
+	/**
308
+	 * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding
309
+	 * closing tag (eg `[/IF_*]`).  The content within the tags will be displayed/hidden depending on whatever
310
+	 * conditions existed in the opening tag.  This method handles parsing the actual template to show/hide this
311
+	 * conditional content.
312
+	 *
313
+	 * @param string $shortcode This should be original shortcode as used in the template and passed to the parser.
314
+	 * @param bool   $show      true means the opening and closing tags are removed and the content is left showing,
315
+	 *                          false means the opening and closing tags and the contained content are removed.
316
+	 * @return string     The template for the shortcode is returned.
317
+	 * @since 4.9.32
318
+	 *
319
+	 */
320
+	protected function _mutate_conditional_block_in_template(string $shortcode, bool $show = true): string
321
+	{
322
+		// first let's get all the matches in the template for this particular shortcode.
323
+		preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches);
324
+
325
+		if ($matches && is_array($matches[0]) && ! empty($matches[0])) {
326
+			// we need to hide all instances of the matches
327
+			foreach ($matches[0] as $index => $content_to_show_or_hide) {
328
+				$content_to_show_or_hide = preg_quote($content_to_show_or_hide);
329
+				$replacement             = $show ? $matches[4][ $index ] : '';
330
+				$this->_data['template'] = preg_replace(
331
+					'~' . $content_to_show_or_hide . '~',
332
+					$replacement,
333
+					$this->_data['template']
334
+				);
335
+			}
336
+		}
337
+		// return $template
338
+		return $this->_data['template'];
339
+	}
340
+
341
+
342
+	/**
343
+	 * This returns the regex pattern to use for conditional shortcodes parsing.
344
+	 *
345
+	 * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php
346
+	 *
347
+	 * @param string $shortcode
348
+	 * @return string
349
+	 * @since 4.9.32
350
+	 */
351
+	private function _get_conditional_block_regex(string $shortcode): string
352
+	{
353
+		// get just the shortcode tag for the match
354
+		preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches);
355
+		if (empty($shortcode_tag_matches[1])) {
356
+			return $this->_data['template'];
357
+		}
358
+
359
+		$shortcode_tag = $shortcode_tag_matches[1];
360
+		// get attributes_part_of_tag
361
+		$attributes_part = preg_quote(str_replace([$shortcode_tag, '[', ']'], '', $shortcode));
362
+		// escape
363
+		$shortcode_tag = preg_quote($shortcode_tag);
364
+
365
+		return
366
+			'\['                                  // Opening Bracket
367
+			. "($shortcode_tag)$attributes_part"    // 1: Shortcode Name
368
+			. '(?![\w-])'                           // Not followed by word character or hyphen
369
+			. '('                                   // 2: Unroll the loop: Inside the opening shortcode tag
370
+			. '[^\]\/]*'                          // Not a closing bracket or forward slash
371
+			. '(?:'
372
+			. '\/(?!\])'                      // A forward slash not followed by a closing bracket
373
+			. '[^\]\/]*'                      // Not a closing bracket or forward slash.
374
+			. ')*?'
375
+			. ')'
376
+			. '(?:'
377
+			. '(\/)'                              // 3. Self closing tag ...
378
+			. '\]'                                // ... and closing bracket
379
+			. '|'
380
+			. '\]'                                // Closing bracket
381
+			. '(?:'
382
+			. '('                             // 4: Unroll the loop: Optionally, anything between the opening and closing brackets
383
+			. '[^\[]*+'                   // Not an opening bracket
384
+			. '(?:'
385
+			. '\[(?!\/\1\])'          // An opening bracket not followed by the closing shortcode tag.
386
+			. '[^\[]*+'               // Not an opening bracket
387
+			. ')*+'
388
+			. ')'
389
+			. '\[\/\1\]'                      // Closing shortcode tag
390
+			. ')?'
391
+			. ')';
392
+	}
393
+
394
+
395
+	/**
396
+	 * This sets the properties related to the messages system
397
+	 *
398
+	 * @return void
399
+	 * @since 4.5.0
400
+	 */
401
+	protected function _set_messages_properties()
402
+	{
403
+		// should be in _extra_data
404
+		if (isset($this->_extra_data['messenger'])) {
405
+			$this->_messenger    = $this->_extra_data['messenger'];
406
+			$this->_message_type = $this->_extra_data['message_type'];
407
+			$this->_context      = $this->_extra_data['message'] instanceof EE_Message
408
+				? $this->_extra_data['message']->context()
409
+				: '';
410
+			$this->_GRP_ID       = $this->_extra_data['message'] instanceof EE_Message
411
+				? $this->_extra_data['message']->GRP_ID()
412
+				: 0;
413
+			$this->_message      = $this->_extra_data['message'] instanceof EE_Message
414
+				? $this->_extra_data['message']
415
+				: null;
416
+		}
417
+	}
418
+
419
+
420
+	/**
421
+	 * This returns whatever the set message type object is that was set on this shortcode parser.
422
+	 *
423
+	 * @return EE_message_type|null
424
+	 * @since 4.5.0
425
+	 */
426
+	public function get_set_message_type(): ?EE_message_type
427
+	{
428
+		return $this->_message_type;
429
+	}
430
+
431
+
432
+	/**
433
+	 * This returns whatever the set messenger object is that was set on this shortcode parser
434
+	 *
435
+	 * @return EE_messenger
436
+	 * @since 4.5.0
437
+	 */
438
+	public function get_set_messenger(): EE_messenger
439
+	{
440
+		return $this->_messenger;
441
+	}
442
+
443
+
444
+	/**
445
+	 * This returns whatever the set context string is on this shortcode parser.
446
+	 *
447
+	 * @return string
448
+	 * @since 4.5.0
449
+	 */
450
+	public function get_set_context(): string
451
+	{
452
+		return $this->_context;
453
+	}
454
+
455
+
456
+	/**
457
+	 * This returns whatever the set EE_Message object is on this shortcode.
458
+	 *
459
+	 * @return EE_Message|null
460
+	 * @since 4.9.0
461
+	 */
462
+	public function get_set_message(): ?EE_Message
463
+	{
464
+		return $this->_message;
465
+	}
466 466
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 
164 164
         // we need to set up any dynamic shortcodes so that they work with the array_key_exists
165 165
         preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
166
-        $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
166
+        $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode;
167 167
 
168 168
         // first we want to make sure this is a valid shortcode
169
-        if (! array_key_exists($sc_to_verify, $this->_shortcodes)) {
169
+        if ( ! array_key_exists($sc_to_verify, $this->_shortcodes)) {
170 170
             // get out, this parser doesn't handle the incoming shortcode.
171 171
             return '';
172 172
         }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         $this->_extra_data = $extra_data;
175 175
         $this->_set_messages_properties();
176 176
         $parsed = (string) apply_filters(
177
-            'FHEE__' . get_class($this) . '__parser_after',
177
+            'FHEE__'.get_class($this).'__parser_after',
178 178
             $this->_parser($shortcode),
179 179
             $shortcode,
180 180
             $data,
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     public function get_shortcodes(): array
203 203
     {
204 204
         $this->_shortcodes =
205
-            (array) apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this);
205
+            (array) 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 = (array) apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this);
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     protected function _validate_list_requirements()
242 242
     {
243 243
         // first test to make sure we've got an array!
244
-        if (! is_array($this->_data)) {
244
+        if ( ! is_array($this->_data)) {
245 245
             throw new EE_Error(
246 246
                 sprintf(
247 247
                     esc_html__(
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         }
256 256
 
257 257
         // next test to make sure we've got the required template in the index!
258
-        if (! isset($this->_data['template'])) {
258
+        if ( ! isset($this->_data['template'])) {
259 259
             throw new EE_Error(
260 260
                 esc_html__(
261 261
                     'The incoming data does not have the required template index in its array',
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
         }
266 266
 
267 267
         // next test to make sure we've got a data index in the incoming data array
268
-        if (! isset($this->_data['data'])) {
268
+        if ( ! isset($this->_data['data'])) {
269 269
             throw new EE_Error(
270 270
                 esc_html__(
271 271
                     'The incoming data does not have the required data index in its array',
@@ -294,8 +294,8 @@  discard block
 block discarded – undo
294 294
     {
295 295
         // make sure the required wp helper function is present
296 296
         // require the shortcode file if necessary
297
-        if (! function_exists('shortcode_parse_atts')) {
298
-            require_once(ABSPATH . WPINC . '/shortcodes.php');
297
+        if ( ! function_exists('shortcode_parse_atts')) {
298
+            require_once(ABSPATH.WPINC.'/shortcodes.php');
299 299
         }
300 300
 
301 301
         // let's get any attributes that may be present and set the defaults.
@@ -320,15 +320,15 @@  discard block
 block discarded – undo
320 320
     protected function _mutate_conditional_block_in_template(string $shortcode, bool $show = true): string
321 321
     {
322 322
         // first let's get all the matches in the template for this particular shortcode.
323
-        preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches);
323
+        preg_match_all('~'.$this->_get_conditional_block_regex($shortcode).'~', $this->_data['template'], $matches);
324 324
 
325 325
         if ($matches && is_array($matches[0]) && ! empty($matches[0])) {
326 326
             // we need to hide all instances of the matches
327 327
             foreach ($matches[0] as $index => $content_to_show_or_hide) {
328 328
                 $content_to_show_or_hide = preg_quote($content_to_show_or_hide);
329
-                $replacement             = $show ? $matches[4][ $index ] : '';
329
+                $replacement             = $show ? $matches[4][$index] : '';
330 330
                 $this->_data['template'] = preg_replace(
331
-                    '~' . $content_to_show_or_hide . '~',
331
+                    '~'.$content_to_show_or_hide.'~',
332 332
                     $replacement,
333 333
                     $this->_data['template']
334 334
                 );
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Event_Author_Shortcodes.lib.php 2 patches
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -19,120 +19,120 @@
 block discarded – undo
19 19
  */
20 20
 class EE_Event_Author_Shortcodes extends EE_Shortcodes
21 21
 {
22
-    public function __construct()
23
-    {
24
-        parent::__construct();
25
-    }
22
+	public function __construct()
23
+	{
24
+		parent::__construct();
25
+	}
26 26
 
27 27
 
28
-    protected function _init_props()
29
-    {
30
-        $this->label = esc_html__('Event Author Details Shortcodes', 'event_espresso');
31
-        $this->description = esc_html__('All shortcodes specific to event_author data', 'event_espresso');
32
-        $this->_shortcodes = array(
33
-            '[EVENT_AUTHOR_FNAME]' => esc_html__('Parses to the first name of the event author.', 'event_espresso'),
34
-            '[EVENT_AUTHOR_LNAME]' => esc_html__('Parses to the last name of the event author.', 'event_espresso'),
35
-            '[EVENT_AUTHOR_FORMATTED_EMAIL]' => esc_html__(
36
-                'Parses to a formatted email address of the event author (fname lname &lt;[email protected]&gt;).  <strong>NOTE:</strong> If the event author has not filled out their WordPress user profile then the organization name will be used as the "From" name.',
37
-                'event_espresso'
38
-            ),
39
-            '[EVENT_AUTHOR_EMAIL]' => esc_html__(
40
-                'Parses to the unformatted email address of the event author',
41
-                'event_espresso'
42
-            ),
43
-        );
44
-    }
28
+	protected function _init_props()
29
+	{
30
+		$this->label = esc_html__('Event Author Details Shortcodes', 'event_espresso');
31
+		$this->description = esc_html__('All shortcodes specific to event_author data', 'event_espresso');
32
+		$this->_shortcodes = array(
33
+			'[EVENT_AUTHOR_FNAME]' => esc_html__('Parses to the first name of the event author.', 'event_espresso'),
34
+			'[EVENT_AUTHOR_LNAME]' => esc_html__('Parses to the last name of the event author.', 'event_espresso'),
35
+			'[EVENT_AUTHOR_FORMATTED_EMAIL]' => esc_html__(
36
+				'Parses to a formatted email address of the event author (fname lname &lt;[email protected]&gt;).  <strong>NOTE:</strong> If the event author has not filled out their WordPress user profile then the organization name will be used as the "From" name.',
37
+				'event_espresso'
38
+			),
39
+			'[EVENT_AUTHOR_EMAIL]' => esc_html__(
40
+				'Parses to the unformatted email address of the event author',
41
+				'event_espresso'
42
+			),
43
+		);
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * @param string $shortcode
49
-     * @throws EE_Error
50
-     */
51
-    protected function _parser($shortcode)
52
-    {
53
-        // make sure we end up with a copy of the EE_Messages_Addressee object
54
-        $recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
55
-        $recipient = ! $recipient instanceof EE_Messages_Addressee
56
-            && is_array($this->_data)
57
-            && isset($this->_data['data'])
58
-            && $this->_data['data'] instanceof EE_Messages_Addressee
59
-                ? $this->_data['data']
60
-                : $recipient;
61
-        $recipient = ! $recipient instanceof EE_Messages_Addressee
62
-            && ! empty($this->_extra_data['data'])
63
-            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
64
-                ? $this->_extra_data['data']
65
-                : $recipient;
47
+	/**
48
+	 * @param string $shortcode
49
+	 * @throws EE_Error
50
+	 */
51
+	protected function _parser($shortcode)
52
+	{
53
+		// make sure we end up with a copy of the EE_Messages_Addressee object
54
+		$recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
55
+		$recipient = ! $recipient instanceof EE_Messages_Addressee
56
+			&& is_array($this->_data)
57
+			&& isset($this->_data['data'])
58
+			&& $this->_data['data'] instanceof EE_Messages_Addressee
59
+				? $this->_data['data']
60
+				: $recipient;
61
+		$recipient = ! $recipient instanceof EE_Messages_Addressee
62
+			&& ! empty($this->_extra_data['data'])
63
+			&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
64
+				? $this->_extra_data['data']
65
+				: $recipient;
66 66
 
67
-        // now it's possible that $recipient is not an instance of EE_Messages_Addressee in which case we need to see if $this->_data is an instance of $event.
68
-        $event = $this->_data instanceof EE_Event ? $this->_data : null;
67
+		// now it's possible that $recipient is not an instance of EE_Messages_Addressee in which case we need to see if $this->_data is an instance of $event.
68
+		$event = $this->_data instanceof EE_Event ? $this->_data : null;
69 69
 
70
-        if (! $recipient instanceof EE_Messages_Addressee && ! $event instanceof EE_Event) {
71
-            return '';
72
-        }
70
+		if (! $recipient instanceof EE_Messages_Addressee && ! $event instanceof EE_Event) {
71
+			return '';
72
+		}
73 73
 
74
-        switch ($shortcode) {
75
-            case '[EVENT_AUTHOR_FNAME]':
76
-                $fname = ! empty($recipient) ? $recipient->fname : null;
77
-                if (empty($fname) && ! empty($event)) {
78
-                    $user = $this->_get_author_for_event($event);
79
-                    $fname = $user->first_name;
80
-                }
81
-                return $fname;
74
+		switch ($shortcode) {
75
+			case '[EVENT_AUTHOR_FNAME]':
76
+				$fname = ! empty($recipient) ? $recipient->fname : null;
77
+				if (empty($fname) && ! empty($event)) {
78
+					$user = $this->_get_author_for_event($event);
79
+					$fname = $user->first_name;
80
+				}
81
+				return $fname;
82 82
 
83
-            case '[EVENT_AUTHOR_LNAME]':
84
-                $lname = ! empty($recipient) ? $recipient->lname : null;
85
-                if (empty($lname) && ! empty($event)) {
86
-                    $user = $this->_get_author_for_event($event);
87
-                    $lname = $user->last_name;
88
-                }
89
-                return $lname;
83
+			case '[EVENT_AUTHOR_LNAME]':
84
+				$lname = ! empty($recipient) ? $recipient->lname : null;
85
+				if (empty($lname) && ! empty($event)) {
86
+					$user = $this->_get_author_for_event($event);
87
+					$lname = $user->last_name;
88
+				}
89
+				return $lname;
90 90
 
91
-            case '[EVENT_AUTHOR_FORMATTED_EMAIL]':
92
-                if (! empty($recipient)) {
93
-                    $email = ! empty($recipient->fname)
94
-                        ? $recipient->fname . ' ' . $recipient->lname . '<' . $recipient->admin_email . '>'
95
-                        : EE_Registry::instance()->CFG->organization->get_pretty(
96
-                            'name'
97
-                        ) . '<' . $recipient->admin_email . '>';
98
-                } else {
99
-                    $email = null;
100
-                }
101
-                if (empty($email) && ! empty($event)) {
102
-                    $user = $this->_get_author_for_event($event);
103
-                    $email = ! empty($user->first_name)
104
-                        ? $user->first_name . ' ' . $user->last_name . '<' . $user->user_email . '>'
105
-                        : EE_Registry::instance()->CFG->organization->get_pretty(
106
-                            'name'
107
-                        ) . '<' . $user->user_email . '>';
108
-                }
109
-                return $email;
91
+			case '[EVENT_AUTHOR_FORMATTED_EMAIL]':
92
+				if (! empty($recipient)) {
93
+					$email = ! empty($recipient->fname)
94
+						? $recipient->fname . ' ' . $recipient->lname . '<' . $recipient->admin_email . '>'
95
+						: EE_Registry::instance()->CFG->organization->get_pretty(
96
+							'name'
97
+						) . '<' . $recipient->admin_email . '>';
98
+				} else {
99
+					$email = null;
100
+				}
101
+				if (empty($email) && ! empty($event)) {
102
+					$user = $this->_get_author_for_event($event);
103
+					$email = ! empty($user->first_name)
104
+						? $user->first_name . ' ' . $user->last_name . '<' . $user->user_email . '>'
105
+						: EE_Registry::instance()->CFG->organization->get_pretty(
106
+							'name'
107
+						) . '<' . $user->user_email . '>';
108
+				}
109
+				return $email;
110 110
 
111
-            case '[EVENT_AUTHOR_EMAIL]':
112
-                $email = ! empty($recipient) ? $recipient->admin_email : null;
113
-                if (empty($email) && ! empty($event)) {
114
-                    $user = $this->_get_author_for_event($event);
115
-                    $email = $user->user_email;
116
-                }
117
-                return $email;
111
+			case '[EVENT_AUTHOR_EMAIL]':
112
+				$email = ! empty($recipient) ? $recipient->admin_email : null;
113
+				if (empty($email) && ! empty($event)) {
114
+					$user = $this->_get_author_for_event($event);
115
+					$email = $user->user_email;
116
+				}
117
+				return $email;
118 118
 
119
-            default:
120
-                return '';
121
-        }
122
-    }
119
+			default:
120
+				return '';
121
+		}
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * Helper method to return the user object for the author of the given EE_Event
127
-     *
128
-     * @param EE_Event $event
129
-     *
130
-     * @return WP_User
131
-     */
132
-    private function _get_author_for_event(EE_Event $event)
133
-    {
134
-        $author_id = $event->wp_user();
135
-        $user_data = get_userdata((int) $author_id);
136
-        return $user_data;
137
-    }
125
+	/**
126
+	 * Helper method to return the user object for the author of the given EE_Event
127
+	 *
128
+	 * @param EE_Event $event
129
+	 *
130
+	 * @return WP_User
131
+	 */
132
+	private function _get_author_for_event(EE_Event $event)
133
+	{
134
+		$author_id = $event->wp_user();
135
+		$user_data = get_userdata((int) $author_id);
136
+		return $user_data;
137
+	}
138 138
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         // now it's possible that $recipient is not an instance of EE_Messages_Addressee in which case we need to see if $this->_data is an instance of $event.
68 68
         $event = $this->_data instanceof EE_Event ? $this->_data : null;
69 69
 
70
-        if (! $recipient instanceof EE_Messages_Addressee && ! $event instanceof EE_Event) {
70
+        if ( ! $recipient instanceof EE_Messages_Addressee && ! $event instanceof EE_Event) {
71 71
             return '';
72 72
         }
73 73
 
@@ -89,22 +89,22 @@  discard block
 block discarded – undo
89 89
                 return $lname;
90 90
 
91 91
             case '[EVENT_AUTHOR_FORMATTED_EMAIL]':
92
-                if (! empty($recipient)) {
92
+                if ( ! empty($recipient)) {
93 93
                     $email = ! empty($recipient->fname)
94
-                        ? $recipient->fname . ' ' . $recipient->lname . '<' . $recipient->admin_email . '>'
94
+                        ? $recipient->fname.' '.$recipient->lname.'<'.$recipient->admin_email.'>'
95 95
                         : EE_Registry::instance()->CFG->organization->get_pretty(
96 96
                             'name'
97
-                        ) . '<' . $recipient->admin_email . '>';
97
+                        ).'<'.$recipient->admin_email.'>';
98 98
                 } else {
99 99
                     $email = null;
100 100
                 }
101 101
                 if (empty($email) && ! empty($event)) {
102 102
                     $user = $this->_get_author_for_event($event);
103 103
                     $email = ! empty($user->first_name)
104
-                        ? $user->first_name . ' ' . $user->last_name . '<' . $user->user_email . '>'
104
+                        ? $user->first_name.' '.$user->last_name.'<'.$user->user_email.'>'
105 105
                         : EE_Registry::instance()->CFG->organization->get_pretty(
106 106
                             'name'
107
-                        ) . '<' . $user->user_email . '>';
107
+                        ).'<'.$user->user_email.'>';
108 108
                 }
109 109
                 return $email;
110 110
 
Please login to merge, or discard this patch.
libraries/shortcodes/EE_Primary_Registration_Details_Shortcodes.lib.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -15,199 +15,199 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Primary_Registration_Details_Shortcodes extends EE_Shortcodes
17 17
 {
18
-    protected function _init_props()
19
-    {
20
-        $this->label       = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso');
21
-        $this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso');
22
-        $this->_shortcodes = [
23
-            '[PRIMARY_REGISTRANT_FNAME]'                  => esc_html__(
24
-                'Parses to the first name of the primary registration for the transaction.',
25
-                'event_espresso'
26
-            ),
27
-            '[PRIMARY_REGISTRANT_LNAME]'                  => esc_html__(
28
-                'Parses to the last name of the primary registration for the transaction.',
29
-                'event_espresso'
30
-            ),
31
-            '[PRIMARY_REGISTRANT_EMAIL]'                  => esc_html__(
32
-                'Parses to the email address of the primary registration for the transaction.',
33
-                'event_espresso'
34
-            ),
35
-            '[PRIMARY_REGISTRANT_REGISTRATION_ID]'        => esc_html__(
36
-                'Parses to the registration ID of the primary registrant for the transaction.',
37
-                'event_espresso'
38
-            ),
39
-            '[PRIMARY_REGISTRANT_REGISTRATION_CODE]'      => esc_html__(
40
-                'Parses to the registration code of the primary registrant for the transaction.',
41
-                'event_espresso'
42
-            ),
43
-            '[PRIMARY_REGISTRANT_PHONE_NUMBER]'           => esc_html__(
44
-                'The Phone Number for the primary registrant for the transaction.',
45
-                'event_espresso'
46
-            ),
47
-            '[PRIMARY_REGISTRANT_ADDRESS]'                => esc_html__(
48
-                'The Address for the primary registrant for the transaction.',
49
-                'event_espresso'
50
-            ),
51
-            '[PRIMARY_REGISTRANT_ADDRESS2]'               => esc_html__(
52
-                'Whatever was in the address 2 field for the primary registrant for the transaction.',
53
-                'event_espresso'
54
-            ),
55
-            '[PRIMARY_REGISTRANT_CITY]'                   => esc_html__(
56
-                'The city for the primary registrant for the transaction.',
57
-                'event_espresso'
58
-            ),
59
-            '[PRIMARY_REGISTRANT_ZIP_PC]'                 => esc_html__(
60
-                'The ZIP (or Postal) Code for the primary registrant for the transaction.',
61
-                'event_espresso'
62
-            ),
63
-            '[PRIMARY_REGISTRANT_ADDRESS_STATE]'          => esc_html__(
64
-                'The state/province for the primary registrant for the transaction.',
65
-                'event_espresso'
66
-            ),
67
-            '[PRIMARY_REGISTRANT_COUNTRY]'                => esc_html__(
68
-                'The country for the primary registrant for the transaction.',
69
-                'event_espresso'
70
-            ),
71
-            '[PRIMARY_REGISTRANT_REGISTRATION_DATE]'      => esc_html__(
72
-                'The date the registration occured for the primary registration.',
73
-                'event_espresso'
74
-            ),
75
-            '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__(
76
-                'Generates a link for the given registration to edit this registration details on the frontend.',
77
-                'event_espresso'
78
-            ),
79
-            '[PRIMARY_REGISTRANT_ANSWER_*]'               => esc_html__(
80
-                'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.',
81
-                'event_espresso'
82
-            ),
83
-        ];
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string $shortcode
89
-     * @return string
90
-     * @throws EE_Error
91
-     * @throws ReflectionException
92
-     * @since 5.0.20.p
93
-     */
94
-    protected function _parser($shortcode)
95
-    {
96
-        // make sure we end up with a copy of the EE_Messages_Addressee object
97
-        $primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
98
-        $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee
99
-        && is_array($this->_data)
100
-        && isset($this->_data['data'])
101
-        && $this->_data['data'] instanceof EE_Messages_Addressee
102
-            ? $this->_data['data']
103
-            : $primary_registration;
104
-        $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee
105
-        && ! empty($this->_extra_data['data'])
106
-        && $this->_extra_data['data'] instanceof EE_Messages_Addressee
107
-            ? $this->_extra_data['data']
108
-            : $primary_registration;
109
-
110
-        if (! $primary_registration instanceof EE_Messages_Addressee) {
111
-            return '';
112
-        }
113
-
114
-        $attendee    = $primary_registration->primary_att_obj;
115
-        $primary_reg = $primary_registration->primary_reg_obj;
116
-
117
-        if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
118
-            return '';
119
-        }
120
-
121
-        switch ($shortcode) {
122
-            case '[PRIMARY_REGISTRANT_FNAME]':
123
-                return $attendee->fname();
124
-
125
-            case '[PRIMARY_REGISTRANT_LNAME]':
126
-                return $attendee->lname();
127
-
128
-            case '[PRIMARY_REGISTRANT_EMAIL]':
129
-                return $attendee->email();
130
-
131
-            case '[PRIMARY_REGISTRANT_REGISTRATION_ID]':
132
-                return $primary_reg->ID();
133
-
134
-            case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]':
135
-                return $primary_reg->reg_code();
136
-
137
-            case '[PRIMARY_REGISTRANT_PHONE_NUMBER]':
138
-                return $attendee->phone();
139
-
140
-            case '[PRIMARY_REGISTRANT_ADDRESS]':
141
-                return $attendee->address();
142
-
143
-            case '[PRIMARY_REGISTRANT_ADDRESS2]':
144
-                return $attendee->address2();
145
-
146
-            case '[PRIMARY_REGISTRANT_CITY]':
147
-                return $attendee->city();
148
-
149
-            case '[PRIMARY_REGISTRANT_ZIP_PC]':
150
-                return $attendee->zip();
151
-
152
-            case '[PRIMARY_REGISTRANT_ADDRESS_STATE]':
153
-                $state_obj = $attendee->state_obj();
154
-                return $state_obj instanceof EE_State ? $state_obj->name() : '';
155
-
156
-            case '[PRIMARY_REGISTRANT_COUNTRY]':
157
-                $country_obj = $attendee->country_obj();
158
-                return $country_obj instanceof EE_Country ? $country_obj->name() : '';
159
-
160
-            case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
161
-                if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
162
-                    return '';
163
-                }
164
-                return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
165
-
166
-            case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]':
167
-                return $primary_reg->edit_attendee_information_url();
168
-        }
169
-
170
-        if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) {
171
-            $shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode);
172
-            $shortcode = trim(str_replace(']', '', $shortcode));
173
-
174
-
175
-            // now let's figure out what question has this text
176
-            if (empty($primary_registration->questions)) {
177
-                return '';
178
-            }
179
-
180
-            foreach ($primary_registration->questions as $ansid => $question) {
181
-                if (
182
-                    $question instanceof EE_Question
183
-                    && trim($question->get('QST_display_text')) === trim($shortcode)
184
-                    && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
185
-                ) {
186
-                    /** @var EE_Answer $primary_reg_ansid */
187
-                    $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
188
-
189
-                    // what we show for the answer depends on the question type!
190
-                    switch ($question->get('QST_type')) {
191
-                        case EEM_Question::QST_type_state:
192
-                            $state  = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
193
-                            $answer = $state instanceof EE_State ? $state->name() : '';
194
-                            break;
195
-
196
-                        case EEM_Question::QST_type_country:
197
-                            $country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
198
-                            $answer  = $country instanceof EE_Country ? $country->name() : '';
199
-                            break;
200
-
201
-                        default:
202
-                            $answer = (string) $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop');
203
-                            break;
204
-                    }
205
-
206
-                    return $answer;
207
-                }
208
-            }
209
-        }
18
+	protected function _init_props()
19
+	{
20
+		$this->label       = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso');
21
+		$this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso');
22
+		$this->_shortcodes = [
23
+			'[PRIMARY_REGISTRANT_FNAME]'                  => esc_html__(
24
+				'Parses to the first name of the primary registration for the transaction.',
25
+				'event_espresso'
26
+			),
27
+			'[PRIMARY_REGISTRANT_LNAME]'                  => esc_html__(
28
+				'Parses to the last name of the primary registration for the transaction.',
29
+				'event_espresso'
30
+			),
31
+			'[PRIMARY_REGISTRANT_EMAIL]'                  => esc_html__(
32
+				'Parses to the email address of the primary registration for the transaction.',
33
+				'event_espresso'
34
+			),
35
+			'[PRIMARY_REGISTRANT_REGISTRATION_ID]'        => esc_html__(
36
+				'Parses to the registration ID of the primary registrant for the transaction.',
37
+				'event_espresso'
38
+			),
39
+			'[PRIMARY_REGISTRANT_REGISTRATION_CODE]'      => esc_html__(
40
+				'Parses to the registration code of the primary registrant for the transaction.',
41
+				'event_espresso'
42
+			),
43
+			'[PRIMARY_REGISTRANT_PHONE_NUMBER]'           => esc_html__(
44
+				'The Phone Number for the primary registrant for the transaction.',
45
+				'event_espresso'
46
+			),
47
+			'[PRIMARY_REGISTRANT_ADDRESS]'                => esc_html__(
48
+				'The Address for the primary registrant for the transaction.',
49
+				'event_espresso'
50
+			),
51
+			'[PRIMARY_REGISTRANT_ADDRESS2]'               => esc_html__(
52
+				'Whatever was in the address 2 field for the primary registrant for the transaction.',
53
+				'event_espresso'
54
+			),
55
+			'[PRIMARY_REGISTRANT_CITY]'                   => esc_html__(
56
+				'The city for the primary registrant for the transaction.',
57
+				'event_espresso'
58
+			),
59
+			'[PRIMARY_REGISTRANT_ZIP_PC]'                 => esc_html__(
60
+				'The ZIP (or Postal) Code for the primary registrant for the transaction.',
61
+				'event_espresso'
62
+			),
63
+			'[PRIMARY_REGISTRANT_ADDRESS_STATE]'          => esc_html__(
64
+				'The state/province for the primary registrant for the transaction.',
65
+				'event_espresso'
66
+			),
67
+			'[PRIMARY_REGISTRANT_COUNTRY]'                => esc_html__(
68
+				'The country for the primary registrant for the transaction.',
69
+				'event_espresso'
70
+			),
71
+			'[PRIMARY_REGISTRANT_REGISTRATION_DATE]'      => esc_html__(
72
+				'The date the registration occured for the primary registration.',
73
+				'event_espresso'
74
+			),
75
+			'[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__(
76
+				'Generates a link for the given registration to edit this registration details on the frontend.',
77
+				'event_espresso'
78
+			),
79
+			'[PRIMARY_REGISTRANT_ANSWER_*]'               => esc_html__(
80
+				'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.',
81
+				'event_espresso'
82
+			),
83
+		];
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string $shortcode
89
+	 * @return string
90
+	 * @throws EE_Error
91
+	 * @throws ReflectionException
92
+	 * @since 5.0.20.p
93
+	 */
94
+	protected function _parser($shortcode)
95
+	{
96
+		// make sure we end up with a copy of the EE_Messages_Addressee object
97
+		$primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
98
+		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee
99
+		&& is_array($this->_data)
100
+		&& isset($this->_data['data'])
101
+		&& $this->_data['data'] instanceof EE_Messages_Addressee
102
+			? $this->_data['data']
103
+			: $primary_registration;
104
+		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee
105
+		&& ! empty($this->_extra_data['data'])
106
+		&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
107
+			? $this->_extra_data['data']
108
+			: $primary_registration;
109
+
110
+		if (! $primary_registration instanceof EE_Messages_Addressee) {
111
+			return '';
112
+		}
113
+
114
+		$attendee    = $primary_registration->primary_att_obj;
115
+		$primary_reg = $primary_registration->primary_reg_obj;
116
+
117
+		if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
118
+			return '';
119
+		}
120
+
121
+		switch ($shortcode) {
122
+			case '[PRIMARY_REGISTRANT_FNAME]':
123
+				return $attendee->fname();
124
+
125
+			case '[PRIMARY_REGISTRANT_LNAME]':
126
+				return $attendee->lname();
127
+
128
+			case '[PRIMARY_REGISTRANT_EMAIL]':
129
+				return $attendee->email();
130
+
131
+			case '[PRIMARY_REGISTRANT_REGISTRATION_ID]':
132
+				return $primary_reg->ID();
133
+
134
+			case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]':
135
+				return $primary_reg->reg_code();
136
+
137
+			case '[PRIMARY_REGISTRANT_PHONE_NUMBER]':
138
+				return $attendee->phone();
139
+
140
+			case '[PRIMARY_REGISTRANT_ADDRESS]':
141
+				return $attendee->address();
142
+
143
+			case '[PRIMARY_REGISTRANT_ADDRESS2]':
144
+				return $attendee->address2();
145
+
146
+			case '[PRIMARY_REGISTRANT_CITY]':
147
+				return $attendee->city();
148
+
149
+			case '[PRIMARY_REGISTRANT_ZIP_PC]':
150
+				return $attendee->zip();
151
+
152
+			case '[PRIMARY_REGISTRANT_ADDRESS_STATE]':
153
+				$state_obj = $attendee->state_obj();
154
+				return $state_obj instanceof EE_State ? $state_obj->name() : '';
155
+
156
+			case '[PRIMARY_REGISTRANT_COUNTRY]':
157
+				$country_obj = $attendee->country_obj();
158
+				return $country_obj instanceof EE_Country ? $country_obj->name() : '';
159
+
160
+			case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
161
+				if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
162
+					return '';
163
+				}
164
+				return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
165
+
166
+			case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]':
167
+				return $primary_reg->edit_attendee_information_url();
168
+		}
169
+
170
+		if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) {
171
+			$shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode);
172
+			$shortcode = trim(str_replace(']', '', $shortcode));
173
+
174
+
175
+			// now let's figure out what question has this text
176
+			if (empty($primary_registration->questions)) {
177
+				return '';
178
+			}
179
+
180
+			foreach ($primary_registration->questions as $ansid => $question) {
181
+				if (
182
+					$question instanceof EE_Question
183
+					&& trim($question->get('QST_display_text')) === trim($shortcode)
184
+					&& isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
185
+				) {
186
+					/** @var EE_Answer $primary_reg_ansid */
187
+					$primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
188
+
189
+					// what we show for the answer depends on the question type!
190
+					switch ($question->get('QST_type')) {
191
+						case EEM_Question::QST_type_state:
192
+							$state  = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
193
+							$answer = $state instanceof EE_State ? $state->name() : '';
194
+							break;
195
+
196
+						case EEM_Question::QST_type_country:
197
+							$country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
198
+							$answer  = $country instanceof EE_Country ? $country->name() : '';
199
+							break;
200
+
201
+						default:
202
+							$answer = (string) $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop');
203
+							break;
204
+					}
205
+
206
+					return $answer;
207
+				}
208
+			}
209
+		}
210 210
 
211
-        return '';
212
-    }
211
+		return '';
212
+	}
213 213
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
             ? $this->_extra_data['data']
108 108
             : $primary_registration;
109 109
 
110
-        if (! $primary_registration instanceof EE_Messages_Addressee) {
110
+        if ( ! $primary_registration instanceof EE_Messages_Addressee) {
111 111
             return '';
112 112
         }
113 113
 
114 114
         $attendee    = $primary_registration->primary_att_obj;
115 115
         $primary_reg = $primary_registration->primary_reg_obj;
116 116
 
117
-        if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
117
+        if ( ! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
118 118
             return '';
119 119
         }
120 120
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
                 return $country_obj instanceof EE_Country ? $country_obj->name() : '';
159 159
 
160 160
             case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
161
-                if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
161
+                if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration) {
162 162
                     return '';
163 163
                 }
164 164
                 return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
                 if (
182 182
                     $question instanceof EE_Question
183 183
                     && trim($question->get('QST_display_text')) === trim($shortcode)
184
-                    && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
184
+                    && isset($primary_registration->registrations[$primary_reg->ID()]['ans_objs'][$ansid])
185 185
                 ) {
186 186
                     /** @var EE_Answer $primary_reg_ansid */
187
-                    $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
187
+                    $primary_reg_ansid = $primary_registration->registrations[$primary_reg->ID()]['ans_objs'][$ansid];
188 188
 
189 189
                     // what we show for the answer depends on the question type!
190 190
                     switch ($question->get('QST_type')) {
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Attendee_List_Shortcodes.lib.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -18,166 +18,166 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Attendee_List_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    protected function _init_props()
22
-    {
23
-        $this->label       = esc_html__('Attendee List Shortcodes', 'event_espresso');
24
-        $this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso');
25
-        $this->_shortcodes = [
26
-            '[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'),
27
-        ];
28
-    }
29
-
30
-
31
-    /**
32
-     * @param string $shortcode
33
-     * @return string
34
-     * @throws EE_Error
35
-     * @throws ReflectionException
36
-     */
37
-    protected function _parser($shortcode)
38
-    {
39
-        if ($shortcode == '[ATTENDEE_LIST]') {
40
-            return $this->_get_attendee_list();
41
-        }
42
-        return '';
43
-    }
44
-
45
-
46
-    /**
47
-     * figure out what the incoming data is and then return the appropriate parsed value.
48
-     *
49
-     * @return string
50
-     * @throws EE_Error
51
-     * @throws ReflectionException
52
-     */
53
-    private function _get_attendee_list()
54
-    {
55
-        $this->_validate_list_requirements();
56
-
57
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
58
-            return $this->_get_attendee_list_for_main();
59
-        }
60
-        if ($this->_data['data'] instanceof EE_Event) {
61
-            return $this->_get_attendee_list_for_event();
62
-        }
63
-        if ($this->_data['data'] instanceof EE_Ticket) {
64
-            return $this->_get_registration_list_for_ticket();
65
-        }
66
-        // prevent recursive loop
67
-        return '';
68
-    }
69
-
70
-
71
-    /**
72
-     * This returns the parsed attendee list for main template;
73
-     */
74
-    private function _get_attendee_list_for_main()
75
-    {
76
-        $valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details'];
77
-        $template         = $this->_data['template'];
78
-        $data             = $this->_data['data'];
79
-        $attendees        = '';
80
-
81
-
82
-        // now we need to loop through the attendee list and send data to the EE_Parser helper.
83
-        foreach ($data->reg_objs as $registration) {
84
-            $attendees .= $this->_shortcode_helper->parse_attendee_list_template(
85
-                $template,
86
-                $registration,
87
-                $valid_shortcodes,
88
-                $this->_extra_data
89
-            );
90
-        }
91
-
92
-        return $attendees;
93
-    }
94
-
95
-
96
-    /**
97
-     * return parsed list of attendees for an event
98
-     *
99
-     * @return string
100
-     * @throws EE_Error
101
-     * @throws ReflectionException
102
-     */
103
-    private function _get_attendee_list_for_event()
104
-    {
105
-        $valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details'];
106
-        $template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
107
-            ? $this->_data['template']['attendee_list']
108
-            : $this->_extra_data['template']['attendee_list'];
109
-        $event            = $this->_data['data'];
110
-
111
-        // let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion.
112
-        $template = str_replace('[EVENT_LIST]', '', $template);
113
-
114
-        // here we're setting up the attendees for the attendee_list template for THIS event.
115
-        $att_result    = '';
116
-        $registrations = $this->_get_registrations_from_event($event);
117
-
118
-        // each attendee in this case should be an attendee object.
119
-        foreach ($registrations as $registration) {
120
-            $att_result .= $this->_shortcode_helper->parse_attendee_list_template(
121
-                $template,
122
-                $registration,
123
-                $valid_shortcodes,
124
-                $this->_extra_data
125
-            );
126
-        }
127
-
128
-        return $att_result;
129
-    }
130
-
131
-
132
-    /**
133
-     * return parsed list of attendees for a ticket
134
-     *
135
-     * @return string
136
-     */
137
-    private function _get_registration_list_for_ticket()
138
-    {
139
-        $valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details'];
140
-        $template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
141
-            ? $this->_data['template']['attendee_list']
142
-            : $this->_extra_data['template']['attendee_list'];
143
-        $ticket           = $this->_data['data'];
144
-
145
-        // let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion.
146
-        $template = str_replace('[TICKET_LIST]', '', $template);
147
-        $template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template);
148
-        $template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template);
149
-
150
-        // here we're setting up the attendees for the attendee_list template for THIS ticket.
151
-        $att_result    = '';
152
-        $registrations =
153
-            isset($this->_extra_data['data']->tickets)
154
-                ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs']
155
-                : [];
156
-
157
-        // each attendee in this case should be an attendee object.
158
-        foreach ($registrations as $registration) {
159
-            $att_result .= $this->_shortcode_helper->parse_attendee_list_template(
160
-                $template,
161
-                $registration,
162
-                $valid_shortcodes,
163
-                $this->_extra_data
164
-            );
165
-        }
166
-
167
-        return $att_result;
168
-    }
169
-
170
-
171
-    /**
172
-     * @param EE_Event $event
173
-     * @return array|mixed
174
-     * @throws EE_Error
175
-     * @throws ReflectionException
176
-     */
177
-    private function _get_registrations_from_event(EE_Event $event)
178
-    {
179
-        return isset($this->_extra_data['data']->events)
180
-            ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs']
181
-            : [];
182
-    }
21
+	protected function _init_props()
22
+	{
23
+		$this->label       = esc_html__('Attendee List Shortcodes', 'event_espresso');
24
+		$this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso');
25
+		$this->_shortcodes = [
26
+			'[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'),
27
+		];
28
+	}
29
+
30
+
31
+	/**
32
+	 * @param string $shortcode
33
+	 * @return string
34
+	 * @throws EE_Error
35
+	 * @throws ReflectionException
36
+	 */
37
+	protected function _parser($shortcode)
38
+	{
39
+		if ($shortcode == '[ATTENDEE_LIST]') {
40
+			return $this->_get_attendee_list();
41
+		}
42
+		return '';
43
+	}
44
+
45
+
46
+	/**
47
+	 * figure out what the incoming data is and then return the appropriate parsed value.
48
+	 *
49
+	 * @return string
50
+	 * @throws EE_Error
51
+	 * @throws ReflectionException
52
+	 */
53
+	private function _get_attendee_list()
54
+	{
55
+		$this->_validate_list_requirements();
56
+
57
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
58
+			return $this->_get_attendee_list_for_main();
59
+		}
60
+		if ($this->_data['data'] instanceof EE_Event) {
61
+			return $this->_get_attendee_list_for_event();
62
+		}
63
+		if ($this->_data['data'] instanceof EE_Ticket) {
64
+			return $this->_get_registration_list_for_ticket();
65
+		}
66
+		// prevent recursive loop
67
+		return '';
68
+	}
69
+
70
+
71
+	/**
72
+	 * This returns the parsed attendee list for main template;
73
+	 */
74
+	private function _get_attendee_list_for_main()
75
+	{
76
+		$valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details'];
77
+		$template         = $this->_data['template'];
78
+		$data             = $this->_data['data'];
79
+		$attendees        = '';
80
+
81
+
82
+		// now we need to loop through the attendee list and send data to the EE_Parser helper.
83
+		foreach ($data->reg_objs as $registration) {
84
+			$attendees .= $this->_shortcode_helper->parse_attendee_list_template(
85
+				$template,
86
+				$registration,
87
+				$valid_shortcodes,
88
+				$this->_extra_data
89
+			);
90
+		}
91
+
92
+		return $attendees;
93
+	}
94
+
95
+
96
+	/**
97
+	 * return parsed list of attendees for an event
98
+	 *
99
+	 * @return string
100
+	 * @throws EE_Error
101
+	 * @throws ReflectionException
102
+	 */
103
+	private function _get_attendee_list_for_event()
104
+	{
105
+		$valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details'];
106
+		$template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
107
+			? $this->_data['template']['attendee_list']
108
+			: $this->_extra_data['template']['attendee_list'];
109
+		$event            = $this->_data['data'];
110
+
111
+		// let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion.
112
+		$template = str_replace('[EVENT_LIST]', '', $template);
113
+
114
+		// here we're setting up the attendees for the attendee_list template for THIS event.
115
+		$att_result    = '';
116
+		$registrations = $this->_get_registrations_from_event($event);
117
+
118
+		// each attendee in this case should be an attendee object.
119
+		foreach ($registrations as $registration) {
120
+			$att_result .= $this->_shortcode_helper->parse_attendee_list_template(
121
+				$template,
122
+				$registration,
123
+				$valid_shortcodes,
124
+				$this->_extra_data
125
+			);
126
+		}
127
+
128
+		return $att_result;
129
+	}
130
+
131
+
132
+	/**
133
+	 * return parsed list of attendees for a ticket
134
+	 *
135
+	 * @return string
136
+	 */
137
+	private function _get_registration_list_for_ticket()
138
+	{
139
+		$valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details'];
140
+		$template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
141
+			? $this->_data['template']['attendee_list']
142
+			: $this->_extra_data['template']['attendee_list'];
143
+		$ticket           = $this->_data['data'];
144
+
145
+		// let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion.
146
+		$template = str_replace('[TICKET_LIST]', '', $template);
147
+		$template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template);
148
+		$template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template);
149
+
150
+		// here we're setting up the attendees for the attendee_list template for THIS ticket.
151
+		$att_result    = '';
152
+		$registrations =
153
+			isset($this->_extra_data['data']->tickets)
154
+				? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs']
155
+				: [];
156
+
157
+		// each attendee in this case should be an attendee object.
158
+		foreach ($registrations as $registration) {
159
+			$att_result .= $this->_shortcode_helper->parse_attendee_list_template(
160
+				$template,
161
+				$registration,
162
+				$valid_shortcodes,
163
+				$this->_extra_data
164
+			);
165
+		}
166
+
167
+		return $att_result;
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param EE_Event $event
173
+	 * @return array|mixed
174
+	 * @throws EE_Error
175
+	 * @throws ReflectionException
176
+	 */
177
+	private function _get_registrations_from_event(EE_Event $event)
178
+	{
179
+		return isset($this->_extra_data['data']->events)
180
+			? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs']
181
+			: [];
182
+	}
183 183
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Recipient_Details_Shortcodes.lib.php 2 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -18,343 +18,343 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Recipient_Details_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    protected $_recipient;
22
-
23
-    protected $_registrations_for_recipient;
24
-
25
-
26
-    protected function _init_props()
27
-    {
28
-        $this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso');
29
-        $this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso');
30
-        $this->_shortcodes = array(
31
-            '[RECIPIENT_FNAME]'                  => esc_html__(
32
-                'Parses to the first name of the recipient for the message.',
33
-                'event_espresso'
34
-            ),
35
-            '[RECIPIENT_LNAME]'                  => esc_html__(
36
-                'Parses to the last name of the recipient for the message.',
37
-                'event_espresso'
38
-            ),
39
-            '[RECIPIENT_EMAIL]'                  => esc_html__(
40
-                'Parses to the email address of the recipient for the message.',
41
-                'event_espresso'
42
-            ),
43
-            '[RECIPIENT_REGISTRATION_ID]'        => esc_html__(
44
-                'Parses to the registration ID of the recipient for the message.',
45
-                'event_espresso'
46
-            ),
47
-            '[RECIPIENT_REGISTRATION_CODE]'      => esc_html__(
48
-                'Parses to the registration code of the recipient for the message.',
49
-                'event_espresso'
50
-            ),
51
-            '[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__(
52
-                'Parses to a link for frontend editing of the registration for the recipient.',
53
-                'event_espresso'
54
-            ),
55
-            '[RECIPIENT_PHONE_NUMBER]'           => esc_html__(
56
-                'The Phone Number for the recipient of the message.',
57
-                'event_espresso'
58
-            ),
59
-            '[RECIPIENT_ADDRESS]'                => esc_html__(
60
-                'The Address for the recipient of the message.',
61
-                'event_espresso'
62
-            ),
63
-            '[RECIPIENT_ADDRESS2]'               => esc_html__(
64
-                'Whatever was in the address 2 field for the recipient of the message.',
65
-                'event_espresso'
66
-            ),
67
-            '[RECIPIENT_CITY]'                   => esc_html__(
68
-                'The city for the recipient of the message.',
69
-                'event_espresso'
70
-            ),
71
-            '[RECIPIENT_ZIP_PC]'                 => esc_html__(
72
-                'The ZIP (or Postal) Code for the recipient of the message.',
73
-                'event_espresso'
74
-            ),
75
-            '[RECIPIENT_ADDRESS_STATE]'          => esc_html__(
76
-                'The state/province for the recipient of the message.',
77
-                'event_espresso'
78
-            ),
79
-            '[RECIPIENT_COUNTRY]'                => esc_html__(
80
-                'The country for the recipient of the message.',
81
-                'event_espresso'
82
-            ),
83
-            '[RECIPIENT_ANSWER_*]'               => esc_html__(
84
-                'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.',
85
-                'event_espresso'
86
-            ),
87
-            '[RECIPIENT_TOTAL_AMOUNT_PAID]'      => esc_html__(
88
-                'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient.  Otherwise the value of 0 is printed.',
89
-                'event_espresso'
90
-            ),
91
-        );
92
-    }
93
-
94
-
95
-    /**
96
-     * @access protected
97
-     * @param string $shortcode the shortcode to be parsed.
98
-     * @return string parsed shortcode
99
-     * @throws EE_Error
100
-     * @throws ReflectionException
101
-     */
102
-    protected function _parser($shortcode)
103
-    {
104
-
105
-        // make sure we end up with a copy of the EE_Messages_Addressee object
106
-        $this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
107
-        $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
108
-                            && is_array($this->_data)
109
-                            && isset($this->_data['data'])
110
-                            && $this->_data['data'] instanceof EE_Messages_Addressee
111
-            ? $this->_data['data']
112
-            :
113
-            $this->_recipient;
114
-        $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
115
-                            && ! empty($this->_extra_data['data'])
116
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
117
-            ? $this->_extra_data['data']
118
-            : $this->_recipient;
119
-
120
-        if (! $this->_recipient instanceof EE_Messages_Addressee) {
121
-            return '';
122
-        }
123
-
124
-        $attendee = $this->_recipient->att_obj;
125
-        if (! $attendee instanceof EE_Attendee) {
126
-            return '';
127
-        }
128
-
129
-        $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
130
-            ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
131
-            : array();
132
-
133
-        switch ($shortcode) {
134
-            case '[RECIPIENT_FNAME]':
135
-                return $attendee->fname();
136
-
137
-            case '[RECIPIENT_LNAME]':
138
-                return $attendee->lname();
139
-
140
-            case '[RECIPIENT_EMAIL]':
141
-                return $attendee->email();
142
-
143
-            case '[RECIPIENT_REGISTRATION_ID]':
144
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
145
-                    return '';
146
-                }
147
-                return $this->_get_reg_id();
148
-
149
-            case '[RECIPIENT_REGISTRATION_CODE]':
150
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
151
-                    return '';
152
-                }
153
-                return $this->_get_reg_code();
154
-
155
-            case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
156
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
157
-                    return '';
158
-                }
159
-                return $this->_recipient->reg_obj->edit_attendee_information_url();
160
-
161
-            case '[RECIPIENT_PHONE_NUMBER]':
162
-                return $attendee->phone();
163
-
164
-            case '[RECIPIENT_ADDRESS]':
165
-                return $attendee->address();
166
-
167
-            case '[RECIPIENT_ADDRESS2]':
168
-                return $attendee->address2();
169
-
170
-            case '[RECIPIENT_CITY]':
171
-                return $attendee->city();
172
-
173
-            case '[RECIPIENT_ZIP_PC]':
174
-                return $attendee->zip();
175
-
176
-            case '[RECIPIENT_ADDRESS_STATE]':
177
-                $state_obj = $attendee->state_obj();
178
-                return $state_obj instanceof EE_State ? $state_obj->name() : '';
179
-
180
-            case '[RECIPIENT_COUNTRY]':
181
-                $country_obj = $attendee->country_obj();
182
-                return $country_obj instanceof EE_Country ? $country_obj->name() : '';
183
-
184
-            case '[RECIPIENT_TOTAL_AMOUNT_PAID]':
185
-                return $this->_recipient->reg_obj instanceof EE_Registration
186
-                    ? $this->_recipient->reg_obj->pretty_paid()
187
-                    : 0;
188
-        }
189
-
190
-        if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) {
191
-            $shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode);
192
-            $shortcode = trim(str_replace(']', '', $shortcode));
193
-
194
-
195
-            // now let's figure out what question has this text
196
-            if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) {
197
-                return '';
198
-            }
199
-
200
-            foreach ($this->_recipient->questions as $ansid => $question) {
201
-                if (
202
-                    $question instanceof EE_Question
203
-                    && trim($question->display_text()) === trim($shortcode)
204
-                    && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
205
-                ) {
206
-                    $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
207
-
208
-                    // what we show for the answer depends on the question type!
209
-                    switch ($question->get('QST_type')) {
210
-                        case EEM_Question::QST_type_state:
211
-                            $state = EEM_State::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
212
-                            $answer = $state instanceof EE_State ? $state->name() : '';
213
-                            break;
214
-
215
-                        case EEM_Question::QST_type_country:
216
-                            $country = EEM_Country::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
217
-                            $answer = $country instanceof EE_Country ? $country->name() : '';
218
-                            break;
219
-
220
-                        default:
221
-                            $answer = $recipient_ansid->get_pretty('ANS_value', 'no_wpautop');
222
-                            break;
223
-                    }
224
-
225
-                    return $answer;
226
-                }
227
-            }
228
-        }
229
-
230
-        return '';
231
-    }
232
-
233
-
234
-    /**
235
-     * Returns the EE_Messages_Addressee object for the recipient.
236
-     *
237
-     * @since 4.5.0
238
-     *
239
-     * @return EE_Messages_Addressee
240
-     */
241
-    public function get_recipient()
242
-    {
243
-        return $this->_recipient;
244
-    }
245
-
246
-
247
-    /**
248
-     * returns the reg code for the recipient depending on the context and whether the recipient has multiple
249
-     * registrations or not.
250
-     *
251
-     * @return string
252
-     */
253
-    protected function _get_reg_code()
254
-    {
255
-
256
-        // if only one related registration for the recipient then just return that reg code.
257
-        if (count($this->_registrations_for_recipient) <= 1) {
258
-            return $this->_recipient->reg_obj->reg_code();
259
-        }
260
-
261
-        // k more than one registration so let's see if we can get specific to context
262
-        // are we parsing event_list?
263
-        if ($this->_data instanceof EE_Event) {
264
-            $reg_code = array();
265
-            // loop through registrations for recipient and see if there is a match for this event
266
-            foreach ($this->_registrations_for_recipient as $reg) {
267
-                if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
268
-                    $reg_code[] = $reg->reg_code();
269
-                }
270
-            }
271
-            return implode(', ', $reg_code);
272
-        }
273
-
274
-        // are we parsing ticket list?
275
-        if ($this->_data instanceof EE_Ticket) {
276
-            $reg_code = array();
277
-            // loop through each registration for recipient and see if there is a match for this ticket
278
-            foreach ($this->_registrations_for_recipient as $reg) {
279
-                if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
280
-                    $reg_code[] = $reg->reg_code();
281
-                }
282
-            }
283
-            return implode(', ', $reg_code);
284
-        }
285
-
286
-        // do we have a specific reg_obj?  Let's use it
287
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
288
-            return $this->_data->reg_obj->reg_code();
289
-        }
290
-
291
-        // do we have a specific reg_obj?  Let's use it
292
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
293
-            return $this->_data->reg_obj->reg_code();
294
-        }
295
-
296
-        // not able to determine the single reg code so let's return a comma delimited list of reg codes.
297
-        $reg_code = array();
298
-        foreach ($this->_registrations_for_recipient as $reg) {
299
-            if ($reg instanceof EE_Registration) {
300
-                $reg_code[] = $reg->reg_code();
301
-            }
302
-        }
303
-        return implode(', ', $reg_code);
304
-    }
305
-
306
-
307
-    /**
308
-     * returns the reg ID for the recipient depending on the context and whether the recipient has multiple
309
-     * registrations or not.
310
-     *
311
-     * @return int|string
312
-     */
313
-    protected function _get_reg_id()
314
-    {
315
-
316
-        // if only one related registration for the recipient then just return that reg code.
317
-        if (count($this->_registrations_for_recipient) <= 1) {
318
-            return $this->_recipient->reg_obj->ID();
319
-        }
320
-
321
-        // k more than one registration so let's see if we can get specific to context
322
-        // are we parsing event_list?
323
-        if ($this->_data instanceof EE_Event) {
324
-            $registration_ids = array();
325
-            // loop through registrations for recipient and see if there is a match for this event
326
-            foreach ($this->_registrations_for_recipient as $reg) {
327
-                if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
328
-                    $registration_ids[] = $reg->ID();
329
-                }
330
-            }
331
-            return implode(', ', $registration_ids);
332
-        }
333
-
334
-        // are we parsing ticket list?
335
-        if ($this->_data instanceof EE_Ticket) {
336
-            $registration_ids = array();
337
-            // loop through each registration for recipient and see if there is a match for this ticket
338
-            foreach ($this->_registrations_for_recipient as $reg) {
339
-                if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
340
-                    $registration_ids = $reg->ID();
341
-                }
342
-            }
343
-            return implode(', ', $registration_ids);
344
-        }
345
-
346
-        // do we have a specific reg_obj?  Let's use it
347
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
348
-            return $this->_data->reg_obj->ID();
349
-        }
350
-
351
-        // not able to determine the single reg code so let's return a comma delimited list of reg codes.
352
-        $registration_ids = array();
353
-        foreach ($this->_registrations_for_recipient as $reg) {
354
-            if ($reg instanceof EE_Registration) {
355
-                $registration_ids[] = $reg->ID();
356
-            }
357
-        }
358
-        return implode(', ', $registration_ids);
359
-    }
21
+	protected $_recipient;
22
+
23
+	protected $_registrations_for_recipient;
24
+
25
+
26
+	protected function _init_props()
27
+	{
28
+		$this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso');
29
+		$this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso');
30
+		$this->_shortcodes = array(
31
+			'[RECIPIENT_FNAME]'                  => esc_html__(
32
+				'Parses to the first name of the recipient for the message.',
33
+				'event_espresso'
34
+			),
35
+			'[RECIPIENT_LNAME]'                  => esc_html__(
36
+				'Parses to the last name of the recipient for the message.',
37
+				'event_espresso'
38
+			),
39
+			'[RECIPIENT_EMAIL]'                  => esc_html__(
40
+				'Parses to the email address of the recipient for the message.',
41
+				'event_espresso'
42
+			),
43
+			'[RECIPIENT_REGISTRATION_ID]'        => esc_html__(
44
+				'Parses to the registration ID of the recipient for the message.',
45
+				'event_espresso'
46
+			),
47
+			'[RECIPIENT_REGISTRATION_CODE]'      => esc_html__(
48
+				'Parses to the registration code of the recipient for the message.',
49
+				'event_espresso'
50
+			),
51
+			'[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__(
52
+				'Parses to a link for frontend editing of the registration for the recipient.',
53
+				'event_espresso'
54
+			),
55
+			'[RECIPIENT_PHONE_NUMBER]'           => esc_html__(
56
+				'The Phone Number for the recipient of the message.',
57
+				'event_espresso'
58
+			),
59
+			'[RECIPIENT_ADDRESS]'                => esc_html__(
60
+				'The Address for the recipient of the message.',
61
+				'event_espresso'
62
+			),
63
+			'[RECIPIENT_ADDRESS2]'               => esc_html__(
64
+				'Whatever was in the address 2 field for the recipient of the message.',
65
+				'event_espresso'
66
+			),
67
+			'[RECIPIENT_CITY]'                   => esc_html__(
68
+				'The city for the recipient of the message.',
69
+				'event_espresso'
70
+			),
71
+			'[RECIPIENT_ZIP_PC]'                 => esc_html__(
72
+				'The ZIP (or Postal) Code for the recipient of the message.',
73
+				'event_espresso'
74
+			),
75
+			'[RECIPIENT_ADDRESS_STATE]'          => esc_html__(
76
+				'The state/province for the recipient of the message.',
77
+				'event_espresso'
78
+			),
79
+			'[RECIPIENT_COUNTRY]'                => esc_html__(
80
+				'The country for the recipient of the message.',
81
+				'event_espresso'
82
+			),
83
+			'[RECIPIENT_ANSWER_*]'               => esc_html__(
84
+				'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.',
85
+				'event_espresso'
86
+			),
87
+			'[RECIPIENT_TOTAL_AMOUNT_PAID]'      => esc_html__(
88
+				'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient.  Otherwise the value of 0 is printed.',
89
+				'event_espresso'
90
+			),
91
+		);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @access protected
97
+	 * @param string $shortcode the shortcode to be parsed.
98
+	 * @return string parsed shortcode
99
+	 * @throws EE_Error
100
+	 * @throws ReflectionException
101
+	 */
102
+	protected function _parser($shortcode)
103
+	{
104
+
105
+		// make sure we end up with a copy of the EE_Messages_Addressee object
106
+		$this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
107
+		$this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
108
+							&& is_array($this->_data)
109
+							&& isset($this->_data['data'])
110
+							&& $this->_data['data'] instanceof EE_Messages_Addressee
111
+			? $this->_data['data']
112
+			:
113
+			$this->_recipient;
114
+		$this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
115
+							&& ! empty($this->_extra_data['data'])
116
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
117
+			? $this->_extra_data['data']
118
+			: $this->_recipient;
119
+
120
+		if (! $this->_recipient instanceof EE_Messages_Addressee) {
121
+			return '';
122
+		}
123
+
124
+		$attendee = $this->_recipient->att_obj;
125
+		if (! $attendee instanceof EE_Attendee) {
126
+			return '';
127
+		}
128
+
129
+		$this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
130
+			? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
131
+			: array();
132
+
133
+		switch ($shortcode) {
134
+			case '[RECIPIENT_FNAME]':
135
+				return $attendee->fname();
136
+
137
+			case '[RECIPIENT_LNAME]':
138
+				return $attendee->lname();
139
+
140
+			case '[RECIPIENT_EMAIL]':
141
+				return $attendee->email();
142
+
143
+			case '[RECIPIENT_REGISTRATION_ID]':
144
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
145
+					return '';
146
+				}
147
+				return $this->_get_reg_id();
148
+
149
+			case '[RECIPIENT_REGISTRATION_CODE]':
150
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
151
+					return '';
152
+				}
153
+				return $this->_get_reg_code();
154
+
155
+			case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
156
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
157
+					return '';
158
+				}
159
+				return $this->_recipient->reg_obj->edit_attendee_information_url();
160
+
161
+			case '[RECIPIENT_PHONE_NUMBER]':
162
+				return $attendee->phone();
163
+
164
+			case '[RECIPIENT_ADDRESS]':
165
+				return $attendee->address();
166
+
167
+			case '[RECIPIENT_ADDRESS2]':
168
+				return $attendee->address2();
169
+
170
+			case '[RECIPIENT_CITY]':
171
+				return $attendee->city();
172
+
173
+			case '[RECIPIENT_ZIP_PC]':
174
+				return $attendee->zip();
175
+
176
+			case '[RECIPIENT_ADDRESS_STATE]':
177
+				$state_obj = $attendee->state_obj();
178
+				return $state_obj instanceof EE_State ? $state_obj->name() : '';
179
+
180
+			case '[RECIPIENT_COUNTRY]':
181
+				$country_obj = $attendee->country_obj();
182
+				return $country_obj instanceof EE_Country ? $country_obj->name() : '';
183
+
184
+			case '[RECIPIENT_TOTAL_AMOUNT_PAID]':
185
+				return $this->_recipient->reg_obj instanceof EE_Registration
186
+					? $this->_recipient->reg_obj->pretty_paid()
187
+					: 0;
188
+		}
189
+
190
+		if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) {
191
+			$shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode);
192
+			$shortcode = trim(str_replace(']', '', $shortcode));
193
+
194
+
195
+			// now let's figure out what question has this text
196
+			if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) {
197
+				return '';
198
+			}
199
+
200
+			foreach ($this->_recipient->questions as $ansid => $question) {
201
+				if (
202
+					$question instanceof EE_Question
203
+					&& trim($question->display_text()) === trim($shortcode)
204
+					&& isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
205
+				) {
206
+					$recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
207
+
208
+					// what we show for the answer depends on the question type!
209
+					switch ($question->get('QST_type')) {
210
+						case EEM_Question::QST_type_state:
211
+							$state = EEM_State::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
212
+							$answer = $state instanceof EE_State ? $state->name() : '';
213
+							break;
214
+
215
+						case EEM_Question::QST_type_country:
216
+							$country = EEM_Country::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
217
+							$answer = $country instanceof EE_Country ? $country->name() : '';
218
+							break;
219
+
220
+						default:
221
+							$answer = $recipient_ansid->get_pretty('ANS_value', 'no_wpautop');
222
+							break;
223
+					}
224
+
225
+					return $answer;
226
+				}
227
+			}
228
+		}
229
+
230
+		return '';
231
+	}
232
+
233
+
234
+	/**
235
+	 * Returns the EE_Messages_Addressee object for the recipient.
236
+	 *
237
+	 * @since 4.5.0
238
+	 *
239
+	 * @return EE_Messages_Addressee
240
+	 */
241
+	public function get_recipient()
242
+	{
243
+		return $this->_recipient;
244
+	}
245
+
246
+
247
+	/**
248
+	 * returns the reg code for the recipient depending on the context and whether the recipient has multiple
249
+	 * registrations or not.
250
+	 *
251
+	 * @return string
252
+	 */
253
+	protected function _get_reg_code()
254
+	{
255
+
256
+		// if only one related registration for the recipient then just return that reg code.
257
+		if (count($this->_registrations_for_recipient) <= 1) {
258
+			return $this->_recipient->reg_obj->reg_code();
259
+		}
260
+
261
+		// k more than one registration so let's see if we can get specific to context
262
+		// are we parsing event_list?
263
+		if ($this->_data instanceof EE_Event) {
264
+			$reg_code = array();
265
+			// loop through registrations for recipient and see if there is a match for this event
266
+			foreach ($this->_registrations_for_recipient as $reg) {
267
+				if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
268
+					$reg_code[] = $reg->reg_code();
269
+				}
270
+			}
271
+			return implode(', ', $reg_code);
272
+		}
273
+
274
+		// are we parsing ticket list?
275
+		if ($this->_data instanceof EE_Ticket) {
276
+			$reg_code = array();
277
+			// loop through each registration for recipient and see if there is a match for this ticket
278
+			foreach ($this->_registrations_for_recipient as $reg) {
279
+				if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
280
+					$reg_code[] = $reg->reg_code();
281
+				}
282
+			}
283
+			return implode(', ', $reg_code);
284
+		}
285
+
286
+		// do we have a specific reg_obj?  Let's use it
287
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
288
+			return $this->_data->reg_obj->reg_code();
289
+		}
290
+
291
+		// do we have a specific reg_obj?  Let's use it
292
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
293
+			return $this->_data->reg_obj->reg_code();
294
+		}
295
+
296
+		// not able to determine the single reg code so let's return a comma delimited list of reg codes.
297
+		$reg_code = array();
298
+		foreach ($this->_registrations_for_recipient as $reg) {
299
+			if ($reg instanceof EE_Registration) {
300
+				$reg_code[] = $reg->reg_code();
301
+			}
302
+		}
303
+		return implode(', ', $reg_code);
304
+	}
305
+
306
+
307
+	/**
308
+	 * returns the reg ID for the recipient depending on the context and whether the recipient has multiple
309
+	 * registrations or not.
310
+	 *
311
+	 * @return int|string
312
+	 */
313
+	protected function _get_reg_id()
314
+	{
315
+
316
+		// if only one related registration for the recipient then just return that reg code.
317
+		if (count($this->_registrations_for_recipient) <= 1) {
318
+			return $this->_recipient->reg_obj->ID();
319
+		}
320
+
321
+		// k more than one registration so let's see if we can get specific to context
322
+		// are we parsing event_list?
323
+		if ($this->_data instanceof EE_Event) {
324
+			$registration_ids = array();
325
+			// loop through registrations for recipient and see if there is a match for this event
326
+			foreach ($this->_registrations_for_recipient as $reg) {
327
+				if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
328
+					$registration_ids[] = $reg->ID();
329
+				}
330
+			}
331
+			return implode(', ', $registration_ids);
332
+		}
333
+
334
+		// are we parsing ticket list?
335
+		if ($this->_data instanceof EE_Ticket) {
336
+			$registration_ids = array();
337
+			// loop through each registration for recipient and see if there is a match for this ticket
338
+			foreach ($this->_registrations_for_recipient as $reg) {
339
+				if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
340
+					$registration_ids = $reg->ID();
341
+				}
342
+			}
343
+			return implode(', ', $registration_ids);
344
+		}
345
+
346
+		// do we have a specific reg_obj?  Let's use it
347
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
348
+			return $this->_data->reg_obj->ID();
349
+		}
350
+
351
+		// not able to determine the single reg code so let's return a comma delimited list of reg codes.
352
+		$registration_ids = array();
353
+		foreach ($this->_registrations_for_recipient as $reg) {
354
+			if ($reg instanceof EE_Registration) {
355
+				$registration_ids[] = $reg->ID();
356
+			}
357
+		}
358
+		return implode(', ', $registration_ids);
359
+	}
360 360
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -117,17 +117,17 @@  discard block
 block discarded – undo
117 117
             ? $this->_extra_data['data']
118 118
             : $this->_recipient;
119 119
 
120
-        if (! $this->_recipient instanceof EE_Messages_Addressee) {
120
+        if ( ! $this->_recipient instanceof EE_Messages_Addressee) {
121 121
             return '';
122 122
         }
123 123
 
124 124
         $attendee = $this->_recipient->att_obj;
125
-        if (! $attendee instanceof EE_Attendee) {
125
+        if ( ! $attendee instanceof EE_Attendee) {
126 126
             return '';
127 127
         }
128 128
 
129
-        $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
130
-            ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
129
+        $this->_registrations_for_recipient = isset($this->_recipient->attendees[$attendee->ID()]['reg_objs'])
130
+            ? $this->_recipient->attendees[$attendee->ID()]['reg_objs']
131 131
             : array();
132 132
 
133 133
         switch ($shortcode) {
@@ -141,19 +141,19 @@  discard block
 block discarded – undo
141 141
                 return $attendee->email();
142 142
 
143 143
             case '[RECIPIENT_REGISTRATION_ID]':
144
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
144
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
145 145
                     return '';
146 146
                 }
147 147
                 return $this->_get_reg_id();
148 148
 
149 149
             case '[RECIPIENT_REGISTRATION_CODE]':
150
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
150
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
151 151
                     return '';
152 152
                 }
153 153
                 return $this->_get_reg_code();
154 154
 
155 155
             case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
156
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
156
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
157 157
                     return '';
158 158
                 }
159 159
                 return $this->_recipient->reg_obj->edit_attendee_information_url();
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
                 if (
202 202
                     $question instanceof EE_Question
203 203
                     && trim($question->display_text()) === trim($shortcode)
204
-                    && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
204
+                    && isset($this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid])
205 205
                 ) {
206
-                    $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
206
+                    $recipient_ansid = $this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid];
207 207
 
208 208
                     // what we show for the answer depends on the question type!
209 209
                     switch ($question->get('QST_type')) {
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Payment_Shortcodes.lib.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -16,87 +16,87 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Payment_Shortcodes extends EE_Shortcodes
18 18
 {
19
-    protected function _init_props()
20
-    {
21
-        $this->label = esc_html__('Payment Shortcodes', 'event_espresso');
22
-        $this->description = esc_html__('All shortcodes specific to payments.', 'event_espresso');
23
-        $this->_shortcodes = array(
24
-            '[PAYMENT_TIMESTAMP]' => esc_html__(
25
-                'Outputs the date of the payment (using the default date format).',
26
-                'event_espresso'
27
-            ),
28
-            '[PAYMENT_METHOD]' => esc_html__('Outputs a the payment method.', 'event_espresso'),
29
-            '[PAYMENT_AMOUNT]' => esc_html__('Outputs the payment amount (with currency symbol).', 'event_espresso'),
30
-            '[PAYMENT_GATEWAY]' => esc_html__('Outputs the gateway used for the payment.', 'event_espresso'),
31
-            '[PAYMENT_GATEWAY_RESPONSE]' => esc_html__('Outputs the payment gateway response.', 'event_espresso'),
32
-            '[PAYMENT_GATEWAY_TXN_ID]' => esc_html__(
33
-                'This will either be the gateway transaction ID, or the manual ID added with payment applied via the admin.',
34
-                'event_espresso'
35
-            ),
36
-            '[PAYMENT_PO_NUMBER]' => esc_html__('Purchase Order number (if present)', 'event_espresso'),
37
-            '[PAYMENT_EXTRA_ACCOUNTING]' => esc_html__(
38
-                'Any extra accounting messages. Typically added with payments made via the admin.',
39
-                'event_espresso'
40
-            ),
41
-            '[PAYMENT_STATUS]' => esc_html__('The status of the payment.', 'event_espresso'),
42
-            // '[PAYMENT_STATUS_WITH_ICONS]' => esc_html__('The status of the payment including icons representing the status.', 'event_espresso')
43
-        );
44
-    }
19
+	protected function _init_props()
20
+	{
21
+		$this->label = esc_html__('Payment Shortcodes', 'event_espresso');
22
+		$this->description = esc_html__('All shortcodes specific to payments.', 'event_espresso');
23
+		$this->_shortcodes = array(
24
+			'[PAYMENT_TIMESTAMP]' => esc_html__(
25
+				'Outputs the date of the payment (using the default date format).',
26
+				'event_espresso'
27
+			),
28
+			'[PAYMENT_METHOD]' => esc_html__('Outputs a the payment method.', 'event_espresso'),
29
+			'[PAYMENT_AMOUNT]' => esc_html__('Outputs the payment amount (with currency symbol).', 'event_espresso'),
30
+			'[PAYMENT_GATEWAY]' => esc_html__('Outputs the gateway used for the payment.', 'event_espresso'),
31
+			'[PAYMENT_GATEWAY_RESPONSE]' => esc_html__('Outputs the payment gateway response.', 'event_espresso'),
32
+			'[PAYMENT_GATEWAY_TXN_ID]' => esc_html__(
33
+				'This will either be the gateway transaction ID, or the manual ID added with payment applied via the admin.',
34
+				'event_espresso'
35
+			),
36
+			'[PAYMENT_PO_NUMBER]' => esc_html__('Purchase Order number (if present)', 'event_espresso'),
37
+			'[PAYMENT_EXTRA_ACCOUNTING]' => esc_html__(
38
+				'Any extra accounting messages. Typically added with payments made via the admin.',
39
+				'event_espresso'
40
+			),
41
+			'[PAYMENT_STATUS]' => esc_html__('The status of the payment.', 'event_espresso'),
42
+			// '[PAYMENT_STATUS_WITH_ICONS]' => esc_html__('The status of the payment including icons representing the status.', 'event_espresso')
43
+		);
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * @param string $shortcode
49
-     * @throws EE_Error
50
-     * @throws ReflectionException
51
-     */
52
-    protected function _parser($shortcode)
53
-    {
54
-        // ensure that the incoming object is an EE_Payment object.  If it isn't then bail early.
55
-        if (! $this->_data instanceof EE_Payment) {
56
-            return '';
57
-        }
47
+	/**
48
+	 * @param string $shortcode
49
+	 * @throws EE_Error
50
+	 * @throws ReflectionException
51
+	 */
52
+	protected function _parser($shortcode)
53
+	{
54
+		// ensure that the incoming object is an EE_Payment object.  If it isn't then bail early.
55
+		if (! $this->_data instanceof EE_Payment) {
56
+			return '';
57
+		}
58 58
 
59
-        $payment = $this->_data;
59
+		$payment = $this->_data;
60 60
 
61
-        switch ($shortcode) {
62
-            case '[PAYMENT_TIMESTAMP]':
63
-                return $payment->timestamp();
61
+		switch ($shortcode) {
62
+			case '[PAYMENT_TIMESTAMP]':
63
+				return $payment->timestamp();
64 64
 
65
-            case '[PAYMENT_METHOD]':
66
-                // previously the column 'PAY_source' was known as 'PAY_method'
67
-                return $payment->source();
65
+			case '[PAYMENT_METHOD]':
66
+				// previously the column 'PAY_source' was known as 'PAY_method'
67
+				return $payment->source();
68 68
 
69
-            case '[PAYMENT_AMOUNT]':
70
-                return $payment->amount_no_code();
69
+			case '[PAYMENT_AMOUNT]':
70
+				return $payment->amount_no_code();
71 71
 
72
-            case '[PAYMENT_GATEWAY]':
73
-                // previously teh column 'PMD_ID' was more-or-less 'PAY_gateway'
74
-                if ($payment->payment_method() instanceof EE_Payment_Method) {
75
-                    return $payment->payment_method()->name();
76
-                } else {
77
-                    return esc_html__('Unknown', 'event_espresso');
78
-                }
72
+			case '[PAYMENT_GATEWAY]':
73
+				// previously teh column 'PMD_ID' was more-or-less 'PAY_gateway'
74
+				if ($payment->payment_method() instanceof EE_Payment_Method) {
75
+					return $payment->payment_method()->name();
76
+				} else {
77
+					return esc_html__('Unknown', 'event_espresso');
78
+				}
79 79
 
80
-            case '[PAYMENT_GATEWAY_RESPONSE]':
81
-                return $payment->gateway_response();
80
+			case '[PAYMENT_GATEWAY_RESPONSE]':
81
+				return $payment->gateway_response();
82 82
 
83
-            case '[PAYMENT_GATEWAY_TXN_ID]':
84
-                return $payment->txn_id_chq_nmbr();
83
+			case '[PAYMENT_GATEWAY_TXN_ID]':
84
+				return $payment->txn_id_chq_nmbr();
85 85
 
86
-            case '[PAYMENT_PO_NUMBER]':
87
-                return $payment->po_number();
86
+			case '[PAYMENT_PO_NUMBER]':
87
+				return $payment->po_number();
88 88
 
89
-            case '[PAYMENT_EXTRA_ACCOUNTING]':
90
-                return $payment->extra_accntng();
89
+			case '[PAYMENT_EXTRA_ACCOUNTING]':
90
+				return $payment->extra_accntng();
91 91
 
92
-            case '[PAYMENT_STATUS]':
93
-                return $payment->pretty_status();
92
+			case '[PAYMENT_STATUS]':
93
+				return $payment->pretty_status();
94 94
 
95
-            case '[PAYMENT_STATUS_WITH_ICONS]':
96
-                return $payment->pretty_status(true);
95
+			case '[PAYMENT_STATUS_WITH_ICONS]':
96
+				return $payment->pretty_status(true);
97 97
 
98
-            default:
99
-                return '';
100
-        }
101
-    }
98
+			default:
99
+				return '';
100
+		}
101
+	}
102 102
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Transaction_Shortcodes.lib.php 2 patches
Indentation   +775 added lines, -775 removed lines patch added patch discarded remove patch
@@ -16,783 +16,783 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Transaction_Shortcodes extends EE_Shortcodes
18 18
 {
19
-    /**
20
-     * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc
21
-     */
22
-    protected $_invoice_pm;
23
-
24
-
25
-    protected function _init_props()
26
-    {
27
-        $this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
28
-        $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
29
-        $this->_shortcodes = array(
30
-            '[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
31
-            '[PAYMENT_URL]'                     => esc_html__(
32
-                'This is a link to make a payment for the event',
33
-                'event_espresso'
34
-            ),
35
-            '[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__(
36
-                '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:',
37
-                'event_espresso'
38
-            )
39
-                                                   . '<ul>'
40
-                                                   . '<li>'
41
-                                                   . sprintf(
42
-                                                       esc_html__(
43
-                                                           '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
44
-                                                           'event_espresso'
45
-                                                       ),
46
-                                                       '<strong>',
47
-                                                       '</strong>'
48
-                                                   )
49
-                                                   . '</li>'
50
-                                                   . '<li>'
51
-                                                   . sprintf(
52
-                                                       esc_html__(
53
-                                                           '%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.)',
54
-                                                           'event_espresso'
55
-                                                       ),
56
-                                                       '<strong>',
57
-                                                       '</strong>'
58
-                                                   )
59
-                                                   . '</li>'
60
-                                                   . '<li>'
61
-                                                   . sprintf(
62
-                                                       esc_html__(
63
-                                                           '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
64
-                                                           'event_espresso'
65
-                                                       ),
66
-                                                       '<strong>',
67
-                                                       '</strong>'
68
-                                                   )
69
-                                                   . '</li>'
70
-                                                   . '</ul>',
71
-            '[PAYMENT_DUE_DATE_*]'              => esc_html__(
72
-                '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:',
73
-                'event_espresso'
74
-            )
75
-                                                   . '<ul>'
76
-                                                   . '<li>'
77
-                                                   . sprintf(
78
-                                                       esc_html__(
79
-                                                           '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
80
-                                                           'event_espresso'
81
-                                                       ),
82
-                                                       '<strong>',
83
-                                                       '</strong>'
84
-                                                   )
85
-                                                   . '</li>'
86
-                                                   . '<li>'
87
-                                                   . sprintf(
88
-                                                       esc_html__(
89
-                                                           '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
90
-                                                           'event_espresso'
91
-                                                       ),
92
-                                                       '<strong>',
93
-                                                       '</strong>'
94
-                                                   )
95
-                                                   . '</li>'
96
-                                                   . '<li>'
97
-                                                   . sprintf(
98
-                                                       esc_html__(
99
-                                                           '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
100
-                                                           'event_espresso'
101
-                                                       ),
102
-                                                       '<strong>',
103
-                                                       '</strong>'
104
-                                                   )
105
-                                                   . '</li>',
106
-            '[INVOICE_LINK]'                    => esc_html__(
107
-                'This is a full html link to the invoice',
108
-                'event_espresso'
109
-            ),
110
-            '[INVOICE_URL]'                     => esc_html__(
111
-                'This is just the url for the invoice',
112
-                'event_espresso'
113
-            ),
114
-            '[INVOICE_LOGO_URL]'                => esc_html__(
115
-                'This returns the url for the logo uploaded via the invoice settings page.',
116
-                'event_espresso'
117
-            ),
118
-            '[INVOICE_LOGO]'                    => esc_html__(
119
-                '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.',
120
-                'event_espresso'
121
-            ),
122
-            '[INVOICE_PAYEE_NAME]'              => esc_html__(
123
-                '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.',
124
-                'event_espresso'
125
-            ),
126
-            '[INVOICE_PAYEE_ADDRESS]'           => esc_html__(
127
-                '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.',
128
-                'event_espresso'
129
-            ),
130
-            '[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__(
131
-                'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
132
-                'event_espresso'
133
-            ),
134
-            '[INVOICE_PAYEE_EMAIL]'             => esc_html__(
135
-                '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.',
136
-                'event_espresso'
137
-            ),
138
-            '[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(
139
-                esc_html__(
140
-                    '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.',
141
-                    'event_espresso'
142
-                ),
143
-                '<code>',
144
-                '</code>'
145
-            ),
146
-            '[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
147
-            '[TXN_STATUS]'                      => esc_html__(
148
-                'The transaction status for the transaction.',
149
-                'event_espresso'
150
-            ),
151
-            '[TXN_STATUS_ID]'                   => esc_html__(
152
-                '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.',
153
-                'event_espresso'
154
-            ),
155
-            '[PAYMENT_STATUS]'                  => esc_html__(
156
-                'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
157
-                'event_espresso'
158
-            ),
159
-            '[PAYMENT_GATEWAY]'                 => esc_html__(
160
-                'The payment gateway used for the transaction',
161
-                'event_espresso'
162
-            ),
163
-            '[AMOUNT_PAID]'                     => esc_html__(
164
-                '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.',
165
-                'event_espresso'
166
-            ),
167
-            '[LAST_AMOUNT_PAID]'                => esc_html__(
168
-                'This is the last payment or refund made on the transaction related to the message being generated.',
169
-                'event_espresso'
170
-            ),
171
-            '[TOTAL_AMOUNT_PAID]'               => esc_html__(
172
-                'This parses to the total amount paid over all payments',
173
-                'event_espresso'
174
-            ),
175
-            '[TOTAL_OWING]'                     => esc_html__(
176
-                'The total owing on a transaction with no attributes.',
177
-                'event_espresso'
178
-            ),
179
-            '[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
180
-            '[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
181
-            '[OWING_STATUS_MESSAGE_*]'          => esc_html__(
182
-                'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
183
-                'event_espresso'
184
-            )
185
-                                                   . '<p></ul>'
186
-                                                   . '<li><strong>still_owing</strong>:'
187
-                                                   . esc_html__(
188
-                                                       '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:',
189
-                                                       'event_espresso'
190
-                                                   )
191
-                                                   . sprintf(
192
-                                                       esc_html__('%sPlease make a payment.%s', 'event_espresso'),
193
-                                                       '<a href="[PAYMENT_URL]" class="noPrint">',
194
-                                                       '</a>'
195
-                                                   )
196
-                                                   . '</li>'
197
-                                                   .
198
-                                                   '<li><strong>none_owing</strong>:'
199
-                                                   . esc_html__(
200
-                                                       '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.',
201
-                                                       'event_espresso'
202
-                                                   )
203
-                                                   . '</li></ul></p>',
204
-            '[TXN_TOTAL_TICKETS]'               => esc_html__(
205
-                'The total number of all tickets purchased in a transaction',
206
-                'event_espresso'
207
-            ),
208
-            '[TKT_QTY_PURCHASED]'               => sprintf(
209
-                esc_html__(
210
-                    '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',
211
-                    'event_espresso'
212
-                ),
213
-                '<strong>',
214
-                '</strong>'
215
-            ),
216
-            '[TRANSACTION_ADMIN_URL]'           => esc_html__(
217
-                'The url to the admin page for this transaction',
218
-                'event_espresso'
219
-            ),
220
-            '[RECEIPT_URL]'                     => esc_html__(
221
-                'This parses to the generated url for retrieving the receipt for the transaction',
222
-                'event_espresso'
223
-            ),
224
-            '[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__(
225
-                '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.',
226
-                'event_espresso'
227
-            ),
228
-            '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(
229
-                esc_html__(
230
-                    'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.',
231
-                    'event_espresso'
232
-                ),
233
-                '<code>[INVOICE_RECEIPT_SWITCHER_URL]',
234
-                '</code>'
235
-            ),
236
-            '[LAST_PAYMENT_TRANSACTION_ID]'     => esc_html__(
237
-                '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.',
238
-                'event_espresso'
239
-            ),
240
-        );
241
-    }
242
-
243
-
244
-    /**
245
-     * @param  string $shortcode the shortcode to be parsed.
246
-     * @return string parsed shortcode
247
-     * @throws EE_Error
248
-     * @throws InvalidArgumentException
249
-     * @throws ReflectionException
250
-     * @throws InvalidDataTypeException
251
-     * @throws InvalidInterfaceException
252
-     */
253
-    protected function _parser($shortcode)
254
-    {
255
-        // attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the
256
-        // _extra_data for the transaction.
257
-        $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
258
-        $transaction = ! $transaction instanceof EE_Transaction
259
-                       && is_array($this->_extra_data)
260
-                       && isset($this->_extra_data['data'])
261
-                       && $this->_extra_data['data'] instanceof EE_Messages_Addressee
262
-            ? $this->_extra_data['data']->txn
263
-            : $transaction;
264
-        // payment
265
-        $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
266
-        $payment = ! $payment instanceof EE_Payment
267
-                   && is_array($this->_extra_data)
268
-                   && isset($this->_extra_data['data'])
269
-                   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
270
-            : $payment;
271
-        if (! $transaction instanceof EE_Transaction) {
272
-            return '';
273
-        }
274
-        switch ($shortcode) {
275
-            case '[TXN_ID]':
276
-                return $transaction->ID();
277
-
278
-            case '[PAYMENT_URL]':
279
-                $payment_url = $transaction->payment_overview_url();
280
-                return empty($payment_url)
281
-                    ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
282
-                    : $payment_url;
283
-
284
-            case '[INVOICE_LINK]':
285
-                $invoice_url = $transaction->invoice_url();
286
-                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
287
-                return sprintf(
288
-                    esc_html__('%sClick here for Invoice%s', 'event_espresso'),
289
-                    '<a href="' . $invoice_url . '">',
290
-                    '</a>'
291
-                );
292
-
293
-            case '[INVOICE_URL]':
294
-                $invoice_url = $transaction->invoice_url();
295
-                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
296
-
297
-            case '[INVOICE_LOGO_URL]':
298
-                return $this->_get_invoice_logo();
299
-
300
-            case '[INVOICE_LOGO]':
301
-                return $this->_get_invoice_logo(true);
302
-
303
-            case '[INVOICE_PAYEE_NAME]':
304
-                return $this->_get_invoice_payee_name();
305
-
306
-            case '[INVOICE_PAYEE_ADDRESS]':
307
-                return $this->_get_invoice_payee_address();
308
-
309
-            case '[INVOICE_PAYMENT_INSTRUCTIONS]':
310
-                return $this->_get_invoice_payment_instructions();
311
-
312
-            case '[INVOICE_PAYEE_EMAIL]':
313
-                return $this->_get_invoice_payee_email();
314
-                break;
315
-            case '[TOTAL_COST]':
316
-                $total = $transaction->total();
317
-                return ! empty($total) ? EEH_Template::format_currency($total) : '';
318
-
319
-            // note the [payment_status] shortcode is kind of misleading because payment status might be different
320
-            // from txn status so I'm adding this here for clarity.
321
-            case '[PAYMENT_STATUS]':
322
-            case '[TXN_STATUS]':
323
-                $status = $transaction->pretty_status();
324
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
325
-
326
-            case '[TXN_STATUS_ID]':
327
-                return $transaction->status_ID();
328
-
329
-            case '[PAYMENT_GATEWAY]':
330
-                return $this->_get_payment_gateway($transaction);
331
-
332
-            case '[AMOUNT_PAID]':
333
-                return $payment instanceof EE_Payment
334
-                    ? EEH_Template::format_currency($payment->amount())
335
-                    : EEH_Template::format_currency(0);
336
-
337
-            case '[LAST_AMOUNT_PAID]':
338
-                $last_payment = $transaction->last_payment();
339
-                return $last_payment instanceof EE_Payment
340
-                    ? EEH_Template::format_currency($last_payment->amount())
341
-                    : EEH_Template::format_currency(0);
342
-
343
-            case '[TOTAL_AMOUNT_PAID]':
344
-                return EEH_Template::format_currency($transaction->paid());
345
-
346
-            case '[TOTAL_OWING]':
347
-                $total_owing = $transaction->remaining();
348
-                return EEH_Template::format_currency($total_owing);
349
-
350
-            case '[TXN_SUBTOTAL]':
351
-                return EEH_Template::format_currency($this->_get_subtotal());
352
-
353
-            case '[TXN_TAX_SUBTOTAL]':
354
-                return EEH_Template::format_currency($this->_get_subtotal(true));
355
-
356
-            case '[TKT_QTY_PURCHASED]':
357
-            case '[TXN_TOTAL_TICKETS]':
358
-                return $this->_data->total_ticket_count;
359
-
360
-            case '[TRANSACTION_ADMIN_URL]':
361
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
362
-                $query_args = array(
363
-                    'page'   => 'espresso_transactions',
364
-                    'action' => 'view_transaction',
365
-                    'TXN_ID' => $transaction->ID(),
366
-                );
367
-                return EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
368
-
369
-            case '[RECEIPT_URL]':
370
-                // get primary_registration
371
-                $reg = $this->_data->primary_reg_obj;
372
-                if (! $reg instanceof EE_Registration) {
373
-                    return '';
374
-                }
375
-                return $reg->receipt_url();
376
-
377
-            case '[INVOICE_RECEIPT_SWITCHER_URL]':
378
-                return $this->_get_invoice_receipt_switcher(false);
379
-
380
-            case '[INVOICE_RECEIPT_SWITCHER_BUTTON]':
381
-                return $this->_get_invoice_receipt_switcher();
382
-
383
-            case '[LAST_PAYMENT_TRANSACTION_ID]':
384
-                $id = '';
385
-                $payment = $payment instanceof EE_Payment && $payment->ID() !== 0
386
-                    ? $payment
387
-                    : $transaction->last_payment();
388
-                if ($payment instanceof EE_Payment) {
389
-                    $id = $payment->txn_id_chq_nmbr();
390
-                }
391
-                return $id;
392
-        }
393
-
394
-        if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
395
-            return $this->_get_custom_total_owing($shortcode);
396
-        }
397
-        if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
398
-            return $this->_get_invoice_payee_tax_number($shortcode);
399
-        }
400
-        if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
401
-            return $this->_get_payment_link_if_needed($shortcode);
402
-        }
403
-        if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
404
-            return $this->_get_payment_due_date($shortcode, $transaction);
405
-        }
406
-        return '';
407
-    }
408
-
409
-
410
-    /**
411
-     * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
412
-     *
413
-     * @since 4.5.0
414
-     * @param string $shortcode the incoming shortcode
415
-     * @return string parsed.
416
-     * @throws EE_Error
417
-     */
418
-    private function _get_custom_total_owing($shortcode)
419
-    {
420
-        $valid_shortcodes = array('transaction');
421
-        $attrs = $this->_get_shortcode_attrs($shortcode);
422
-        // ensure default is set.
423
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
424
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
425
-            ? $addressee->txn->remaining() : 0;
426
-        if ($total_owing > 0) {
427
-            $owing_content = ! empty($attrs['still_owing'])
428
-                ? $attrs['still_owing']
429
-                : sprintf(
430
-                    esc_html__('%sPlease make a payment.%s', 'event_espresso'),
431
-                    '<a href="[PAYMENT_URL]" class="noPrint">',
432
-                    '</a>'
433
-                );
434
-            $owing_content = $this->_shortcode_helper->parse_message_template(
435
-                $owing_content,
436
-                $addressee,
437
-                $valid_shortcodes,
438
-                $this->_message_type,
439
-                $this->_messenger,
440
-                $this->_message
441
-            );
442
-        } else {
443
-            $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
444
-        }
445
-        return $owing_content;
446
-    }
447
-
448
-
449
-    /**
450
-     * @param EE_Transaction $transaction
451
-     * @return string
452
-     * @throws EE_Error
453
-     */
454
-    private function _get_payment_gateway($transaction)
455
-    {
456
-        if ($transaction instanceof EE_Transaction) {
457
-            $pm = $transaction->payment_method();
458
-        } else {
459
-            $pm = null;
460
-        }
461
-        return $pm instanceof EE_Payment_Method ? $pm->name() : '';
462
-    }
463
-
464
-
465
-    /**
466
-     * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
467
-     * not present then the organization logo is used if its found (set on the organization settings page).
468
-     *
469
-     * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
470
-     * @return string url or html
471
-     * @throws EE_Error
472
-     * @throws InvalidArgumentException
473
-     * @throws InvalidDataTypeException
474
-     * @throws InvalidInterfaceException
475
-     * @throws ReflectionException
476
-     * @since 4.5.0
477
-     */
478
-    private function _get_invoice_logo(bool $img_tags = false): string
479
-    {
480
-        $invoice_logo_url = '';
481
-        // try to get the invoice payment method's logo for this transaction image first
482
-        $pm = $this->_get_invoice_payment_method();
483
-        if ($pm instanceof EE_Payment_Method) {
484
-            $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
485
-        }
486
-        if (empty($invoice_logo_url)) {
487
-            $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
488
-        }
489
-        if (empty($invoice_logo_url)) {
490
-            return '';
491
-        }
492
-        if (! $img_tags) {
493
-            return $invoice_logo_url;
494
-        }
495
-        $invoice_logo_url = esc_url_raw($invoice_logo_url);
496
-        // image tags have been requested.
497
-        $image_size = @getimagesize($invoice_logo_url);
498
-        $image_width_attr = '';
499
-        // if image is wider than 300px, set the width to 300
500
-        if ($image_size !== false) {
501
-            $image_width = min($image_size[0], 300);
502
-            $image_width = esc_attr($image_width);
503
-            $image_width_attr = " width='$image_width'";
504
-        }
505
-        return '<img class="logo screen" src="' . $invoice_logo_url . '"' . $image_width_attr . ' alt="logo" />';
506
-    }
507
-
508
-
509
-    /**
510
-     * Used to retrieve the appropriate content for the invoice payee name shortcode
511
-     *
512
-     * @since 4.5.0
513
-     * @return string
514
-     * @throws EE_Error
515
-     * @throws InvalidArgumentException
516
-     * @throws InvalidDataTypeException
517
-     * @throws InvalidInterfaceException
518
-     */
519
-    private function _get_invoice_payee_name()
520
-    {
521
-        $payee_name = null;
522
-        $pm = $this->_get_invoice_payment_method();
523
-        if ($pm instanceof EE_Payment_Method) {
524
-            $payee_name = $pm->get_extra_meta('pdf_payee_name', true);
525
-        }
526
-        $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
527
-        return $payee_name;
528
-    }
529
-
530
-
531
-    /**
532
-     * gets the default invoice payment method, but has a filter so it can be overridden
533
-     *
534
-     * @return EE_Payment_Method|null
535
-     * @throws EE_Error
536
-     * @throws InvalidArgumentException
537
-     * @throws InvalidDataTypeException
538
-     * @throws InvalidInterfaceException
539
-     */
540
-    private function _get_invoice_payment_method()
541
-    {
542
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
543
-            $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
544
-            $transaction = ! $transaction instanceof EE_Transaction
545
-                           && is_array($this->_extra_data)
546
-                           && isset($this->_extra_data['data'])
547
-                           && $this->_extra_data['data'] instanceof EE_Messages_Addressee
548
-                ? $this->_extra_data['data']->txn : $transaction;
549
-            // get the invoice payment method, and remember it for the next call too
550
-            $this->_invoice_pm = apply_filters(
551
-                'FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
552
-                EEM_Payment_Method::instance()->get_one_of_type('Invoice'),
553
-                $transaction
554
-            );
555
-        }
556
-        return $this->_invoice_pm;
557
-    }
558
-
559
-
560
-    /**
561
-     * Used to retrieve the appropriate content for the invoice payee email shortcode
562
-     *
563
-     * @since 4.5.0
564
-     * @return string
565
-     * @throws EE_Error
566
-     * @throws InvalidArgumentException
567
-     * @throws InvalidDataTypeException
568
-     * @throws InvalidInterfaceException
569
-     */
570
-    private function _get_invoice_payee_email()
571
-    {
572
-        $payee_email = null;
573
-        $pm = $this->_get_invoice_payment_method();
574
-        if ($pm instanceof EE_Payment_Method) {
575
-            $payee_email = $pm->get_extra_meta('pdf_payee_email', true);
576
-        }
577
-        $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
578
-            : $payee_email;
579
-        return $payee_email;
580
-    }
581
-
582
-
583
-    /**
584
-     * Used to retrieve the appropriate content for the invoice payee tax number shortcode
585
-     *
586
-     * @since 4.5.0
587
-     * @param string $shortcode
588
-     * @return string
589
-     * @throws EE_Error
590
-     * @throws InvalidArgumentException
591
-     * @throws InvalidDataTypeException
592
-     * @throws InvalidInterfaceException
593
-     */
594
-    private function _get_invoice_payee_tax_number($shortcode)
595
-    {
596
-        $payee_tax_number = null;
597
-        $pm = $this->_get_invoice_payment_method();
598
-        if ($pm instanceof EE_Payment_Method) {
599
-            $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
600
-        }
601
-        $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
602
-            : $payee_tax_number;
603
-        if (empty($payee_tax_number)) {
604
-            return '';
605
-        }
606
-        // any attributes?
607
-        $attrs = $this->_get_shortcode_attrs($shortcode);
608
-        // prefix?
609
-        $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
610
-        return $prefix . $payee_tax_number;
611
-    }
612
-
613
-
614
-    /**
615
-     * Used to retrieve the appropriate content for the invoice payee address shortcode.
616
-     *
617
-     * @since 4.5.0
618
-     * @return string
619
-     * @throws EE_Error
620
-     * @throws InvalidArgumentException
621
-     * @throws ReflectionException
622
-     * @throws InvalidDataTypeException
623
-     * @throws InvalidInterfaceException
624
-     */
625
-    private function _get_invoice_payee_address()
626
-    {
627
-        $payee_address = null;
628
-        $pm = $this->_get_invoice_payment_method();
629
-        if ($pm instanceof EE_Payment_Method) {
630
-            $payee_address = $pm->get_extra_meta('pdf_payee_address', true);
631
-        }
632
-        if (empty($payee_address)) {
633
-            $organization = EE_Registry::instance()->CFG->organization;
634
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
635
-            $payee_address .= ! empty($organization->address_2)
636
-                ? $organization->get_pretty('address_2') . '<br>'
637
-                : '';
638
-            $payee_address .= $organization->get_pretty('city') . '<br>';
639
-            // state
640
-            $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
641
-            $payee_address .= $state instanceof EE_State ? $state->name() : '';
642
-            // Country
643
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
644
-            $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
645
-        }
646
-        return $payee_address;
647
-    }
648
-
649
-
650
-    /**
651
-     * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
652
-     *
653
-     * @since 4.5.0
654
-     * @return string
655
-     * @throws EE_Error
656
-     * @throws InvalidArgumentException
657
-     * @throws InvalidDataTypeException
658
-     * @throws InvalidInterfaceException
659
-     */
660
-    private function _get_invoice_payment_instructions()
661
-    {
662
-        $instructions = null;
663
-        $pm = $this->_get_invoice_payment_method();
664
-        return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
665
-    }
666
-
667
-
668
-    /**
669
-     * get invoice/receipt switch button or url.
670
-     *
671
-     * @param bool $button true (default) returns the html for a button, false just returns the url.
672
-     * @return string
673
-     * @throws EE_Error
674
-     */
675
-    protected function _get_invoice_receipt_switcher($button = true)
676
-    {
677
-        $reg = $this->_data->primary_reg_obj;
678
-        $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
679
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
680
-            return '';
681
-        }
682
-        $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
683
-        $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
684
-            ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
685
-        $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
686
-        $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
687
-        if (! $button) {
688
-            return $switch_to_url;
689
-        }
690
-        if (! empty($switch_to_url)) {
691
-            return '
19
+	/**
20
+	 * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc
21
+	 */
22
+	protected $_invoice_pm;
23
+
24
+
25
+	protected function _init_props()
26
+	{
27
+		$this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
28
+		$this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
29
+		$this->_shortcodes = array(
30
+			'[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
31
+			'[PAYMENT_URL]'                     => esc_html__(
32
+				'This is a link to make a payment for the event',
33
+				'event_espresso'
34
+			),
35
+			'[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__(
36
+				'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:',
37
+				'event_espresso'
38
+			)
39
+												   . '<ul>'
40
+												   . '<li>'
41
+												   . sprintf(
42
+													   esc_html__(
43
+														   '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
44
+														   'event_espresso'
45
+													   ),
46
+													   '<strong>',
47
+													   '</strong>'
48
+												   )
49
+												   . '</li>'
50
+												   . '<li>'
51
+												   . sprintf(
52
+													   esc_html__(
53
+														   '%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.)',
54
+														   'event_espresso'
55
+													   ),
56
+													   '<strong>',
57
+													   '</strong>'
58
+												   )
59
+												   . '</li>'
60
+												   . '<li>'
61
+												   . sprintf(
62
+													   esc_html__(
63
+														   '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
64
+														   'event_espresso'
65
+													   ),
66
+													   '<strong>',
67
+													   '</strong>'
68
+												   )
69
+												   . '</li>'
70
+												   . '</ul>',
71
+			'[PAYMENT_DUE_DATE_*]'              => esc_html__(
72
+				'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:',
73
+				'event_espresso'
74
+			)
75
+												   . '<ul>'
76
+												   . '<li>'
77
+												   . sprintf(
78
+													   esc_html__(
79
+														   '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
80
+														   'event_espresso'
81
+													   ),
82
+													   '<strong>',
83
+													   '</strong>'
84
+												   )
85
+												   . '</li>'
86
+												   . '<li>'
87
+												   . sprintf(
88
+													   esc_html__(
89
+														   '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
90
+														   'event_espresso'
91
+													   ),
92
+													   '<strong>',
93
+													   '</strong>'
94
+												   )
95
+												   . '</li>'
96
+												   . '<li>'
97
+												   . sprintf(
98
+													   esc_html__(
99
+														   '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
100
+														   'event_espresso'
101
+													   ),
102
+													   '<strong>',
103
+													   '</strong>'
104
+												   )
105
+												   . '</li>',
106
+			'[INVOICE_LINK]'                    => esc_html__(
107
+				'This is a full html link to the invoice',
108
+				'event_espresso'
109
+			),
110
+			'[INVOICE_URL]'                     => esc_html__(
111
+				'This is just the url for the invoice',
112
+				'event_espresso'
113
+			),
114
+			'[INVOICE_LOGO_URL]'                => esc_html__(
115
+				'This returns the url for the logo uploaded via the invoice settings page.',
116
+				'event_espresso'
117
+			),
118
+			'[INVOICE_LOGO]'                    => esc_html__(
119
+				'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.',
120
+				'event_espresso'
121
+			),
122
+			'[INVOICE_PAYEE_NAME]'              => esc_html__(
123
+				'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.',
124
+				'event_espresso'
125
+			),
126
+			'[INVOICE_PAYEE_ADDRESS]'           => esc_html__(
127
+				'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.',
128
+				'event_espresso'
129
+			),
130
+			'[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__(
131
+				'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
132
+				'event_espresso'
133
+			),
134
+			'[INVOICE_PAYEE_EMAIL]'             => esc_html__(
135
+				'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.',
136
+				'event_espresso'
137
+			),
138
+			'[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(
139
+				esc_html__(
140
+					'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.',
141
+					'event_espresso'
142
+				),
143
+				'<code>',
144
+				'</code>'
145
+			),
146
+			'[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
147
+			'[TXN_STATUS]'                      => esc_html__(
148
+				'The transaction status for the transaction.',
149
+				'event_espresso'
150
+			),
151
+			'[TXN_STATUS_ID]'                   => esc_html__(
152
+				'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.',
153
+				'event_espresso'
154
+			),
155
+			'[PAYMENT_STATUS]'                  => esc_html__(
156
+				'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
157
+				'event_espresso'
158
+			),
159
+			'[PAYMENT_GATEWAY]'                 => esc_html__(
160
+				'The payment gateway used for the transaction',
161
+				'event_espresso'
162
+			),
163
+			'[AMOUNT_PAID]'                     => esc_html__(
164
+				'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.',
165
+				'event_espresso'
166
+			),
167
+			'[LAST_AMOUNT_PAID]'                => esc_html__(
168
+				'This is the last payment or refund made on the transaction related to the message being generated.',
169
+				'event_espresso'
170
+			),
171
+			'[TOTAL_AMOUNT_PAID]'               => esc_html__(
172
+				'This parses to the total amount paid over all payments',
173
+				'event_espresso'
174
+			),
175
+			'[TOTAL_OWING]'                     => esc_html__(
176
+				'The total owing on a transaction with no attributes.',
177
+				'event_espresso'
178
+			),
179
+			'[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
180
+			'[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
181
+			'[OWING_STATUS_MESSAGE_*]'          => esc_html__(
182
+				'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
183
+				'event_espresso'
184
+			)
185
+												   . '<p></ul>'
186
+												   . '<li><strong>still_owing</strong>:'
187
+												   . esc_html__(
188
+													   '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:',
189
+													   'event_espresso'
190
+												   )
191
+												   . sprintf(
192
+													   esc_html__('%sPlease make a payment.%s', 'event_espresso'),
193
+													   '<a href="[PAYMENT_URL]" class="noPrint">',
194
+													   '</a>'
195
+												   )
196
+												   . '</li>'
197
+												   .
198
+												   '<li><strong>none_owing</strong>:'
199
+												   . esc_html__(
200
+													   '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.',
201
+													   'event_espresso'
202
+												   )
203
+												   . '</li></ul></p>',
204
+			'[TXN_TOTAL_TICKETS]'               => esc_html__(
205
+				'The total number of all tickets purchased in a transaction',
206
+				'event_espresso'
207
+			),
208
+			'[TKT_QTY_PURCHASED]'               => sprintf(
209
+				esc_html__(
210
+					'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',
211
+					'event_espresso'
212
+				),
213
+				'<strong>',
214
+				'</strong>'
215
+			),
216
+			'[TRANSACTION_ADMIN_URL]'           => esc_html__(
217
+				'The url to the admin page for this transaction',
218
+				'event_espresso'
219
+			),
220
+			'[RECEIPT_URL]'                     => esc_html__(
221
+				'This parses to the generated url for retrieving the receipt for the transaction',
222
+				'event_espresso'
223
+			),
224
+			'[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__(
225
+				'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.',
226
+				'event_espresso'
227
+			),
228
+			'[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(
229
+				esc_html__(
230
+					'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.',
231
+					'event_espresso'
232
+				),
233
+				'<code>[INVOICE_RECEIPT_SWITCHER_URL]',
234
+				'</code>'
235
+			),
236
+			'[LAST_PAYMENT_TRANSACTION_ID]'     => esc_html__(
237
+				'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.',
238
+				'event_espresso'
239
+			),
240
+		);
241
+	}
242
+
243
+
244
+	/**
245
+	 * @param  string $shortcode the shortcode to be parsed.
246
+	 * @return string parsed shortcode
247
+	 * @throws EE_Error
248
+	 * @throws InvalidArgumentException
249
+	 * @throws ReflectionException
250
+	 * @throws InvalidDataTypeException
251
+	 * @throws InvalidInterfaceException
252
+	 */
253
+	protected function _parser($shortcode)
254
+	{
255
+		// attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the
256
+		// _extra_data for the transaction.
257
+		$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
258
+		$transaction = ! $transaction instanceof EE_Transaction
259
+					   && is_array($this->_extra_data)
260
+					   && isset($this->_extra_data['data'])
261
+					   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
262
+			? $this->_extra_data['data']->txn
263
+			: $transaction;
264
+		// payment
265
+		$payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
266
+		$payment = ! $payment instanceof EE_Payment
267
+				   && is_array($this->_extra_data)
268
+				   && isset($this->_extra_data['data'])
269
+				   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
270
+			: $payment;
271
+		if (! $transaction instanceof EE_Transaction) {
272
+			return '';
273
+		}
274
+		switch ($shortcode) {
275
+			case '[TXN_ID]':
276
+				return $transaction->ID();
277
+
278
+			case '[PAYMENT_URL]':
279
+				$payment_url = $transaction->payment_overview_url();
280
+				return empty($payment_url)
281
+					? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
282
+					: $payment_url;
283
+
284
+			case '[INVOICE_LINK]':
285
+				$invoice_url = $transaction->invoice_url();
286
+				$invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
287
+				return sprintf(
288
+					esc_html__('%sClick here for Invoice%s', 'event_espresso'),
289
+					'<a href="' . $invoice_url . '">',
290
+					'</a>'
291
+				);
292
+
293
+			case '[INVOICE_URL]':
294
+				$invoice_url = $transaction->invoice_url();
295
+				return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
296
+
297
+			case '[INVOICE_LOGO_URL]':
298
+				return $this->_get_invoice_logo();
299
+
300
+			case '[INVOICE_LOGO]':
301
+				return $this->_get_invoice_logo(true);
302
+
303
+			case '[INVOICE_PAYEE_NAME]':
304
+				return $this->_get_invoice_payee_name();
305
+
306
+			case '[INVOICE_PAYEE_ADDRESS]':
307
+				return $this->_get_invoice_payee_address();
308
+
309
+			case '[INVOICE_PAYMENT_INSTRUCTIONS]':
310
+				return $this->_get_invoice_payment_instructions();
311
+
312
+			case '[INVOICE_PAYEE_EMAIL]':
313
+				return $this->_get_invoice_payee_email();
314
+				break;
315
+			case '[TOTAL_COST]':
316
+				$total = $transaction->total();
317
+				return ! empty($total) ? EEH_Template::format_currency($total) : '';
318
+
319
+			// note the [payment_status] shortcode is kind of misleading because payment status might be different
320
+			// from txn status so I'm adding this here for clarity.
321
+			case '[PAYMENT_STATUS]':
322
+			case '[TXN_STATUS]':
323
+				$status = $transaction->pretty_status();
324
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
325
+
326
+			case '[TXN_STATUS_ID]':
327
+				return $transaction->status_ID();
328
+
329
+			case '[PAYMENT_GATEWAY]':
330
+				return $this->_get_payment_gateway($transaction);
331
+
332
+			case '[AMOUNT_PAID]':
333
+				return $payment instanceof EE_Payment
334
+					? EEH_Template::format_currency($payment->amount())
335
+					: EEH_Template::format_currency(0);
336
+
337
+			case '[LAST_AMOUNT_PAID]':
338
+				$last_payment = $transaction->last_payment();
339
+				return $last_payment instanceof EE_Payment
340
+					? EEH_Template::format_currency($last_payment->amount())
341
+					: EEH_Template::format_currency(0);
342
+
343
+			case '[TOTAL_AMOUNT_PAID]':
344
+				return EEH_Template::format_currency($transaction->paid());
345
+
346
+			case '[TOTAL_OWING]':
347
+				$total_owing = $transaction->remaining();
348
+				return EEH_Template::format_currency($total_owing);
349
+
350
+			case '[TXN_SUBTOTAL]':
351
+				return EEH_Template::format_currency($this->_get_subtotal());
352
+
353
+			case '[TXN_TAX_SUBTOTAL]':
354
+				return EEH_Template::format_currency($this->_get_subtotal(true));
355
+
356
+			case '[TKT_QTY_PURCHASED]':
357
+			case '[TXN_TOTAL_TICKETS]':
358
+				return $this->_data->total_ticket_count;
359
+
360
+			case '[TRANSACTION_ADMIN_URL]':
361
+				require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
362
+				$query_args = array(
363
+					'page'   => 'espresso_transactions',
364
+					'action' => 'view_transaction',
365
+					'TXN_ID' => $transaction->ID(),
366
+				);
367
+				return EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
368
+
369
+			case '[RECEIPT_URL]':
370
+				// get primary_registration
371
+				$reg = $this->_data->primary_reg_obj;
372
+				if (! $reg instanceof EE_Registration) {
373
+					return '';
374
+				}
375
+				return $reg->receipt_url();
376
+
377
+			case '[INVOICE_RECEIPT_SWITCHER_URL]':
378
+				return $this->_get_invoice_receipt_switcher(false);
379
+
380
+			case '[INVOICE_RECEIPT_SWITCHER_BUTTON]':
381
+				return $this->_get_invoice_receipt_switcher();
382
+
383
+			case '[LAST_PAYMENT_TRANSACTION_ID]':
384
+				$id = '';
385
+				$payment = $payment instanceof EE_Payment && $payment->ID() !== 0
386
+					? $payment
387
+					: $transaction->last_payment();
388
+				if ($payment instanceof EE_Payment) {
389
+					$id = $payment->txn_id_chq_nmbr();
390
+				}
391
+				return $id;
392
+		}
393
+
394
+		if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
395
+			return $this->_get_custom_total_owing($shortcode);
396
+		}
397
+		if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
398
+			return $this->_get_invoice_payee_tax_number($shortcode);
399
+		}
400
+		if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
401
+			return $this->_get_payment_link_if_needed($shortcode);
402
+		}
403
+		if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
404
+			return $this->_get_payment_due_date($shortcode, $transaction);
405
+		}
406
+		return '';
407
+	}
408
+
409
+
410
+	/**
411
+	 * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
412
+	 *
413
+	 * @since 4.5.0
414
+	 * @param string $shortcode the incoming shortcode
415
+	 * @return string parsed.
416
+	 * @throws EE_Error
417
+	 */
418
+	private function _get_custom_total_owing($shortcode)
419
+	{
420
+		$valid_shortcodes = array('transaction');
421
+		$attrs = $this->_get_shortcode_attrs($shortcode);
422
+		// ensure default is set.
423
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
424
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
425
+			? $addressee->txn->remaining() : 0;
426
+		if ($total_owing > 0) {
427
+			$owing_content = ! empty($attrs['still_owing'])
428
+				? $attrs['still_owing']
429
+				: sprintf(
430
+					esc_html__('%sPlease make a payment.%s', 'event_espresso'),
431
+					'<a href="[PAYMENT_URL]" class="noPrint">',
432
+					'</a>'
433
+				);
434
+			$owing_content = $this->_shortcode_helper->parse_message_template(
435
+				$owing_content,
436
+				$addressee,
437
+				$valid_shortcodes,
438
+				$this->_message_type,
439
+				$this->_messenger,
440
+				$this->_message
441
+			);
442
+		} else {
443
+			$owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
444
+		}
445
+		return $owing_content;
446
+	}
447
+
448
+
449
+	/**
450
+	 * @param EE_Transaction $transaction
451
+	 * @return string
452
+	 * @throws EE_Error
453
+	 */
454
+	private function _get_payment_gateway($transaction)
455
+	{
456
+		if ($transaction instanceof EE_Transaction) {
457
+			$pm = $transaction->payment_method();
458
+		} else {
459
+			$pm = null;
460
+		}
461
+		return $pm instanceof EE_Payment_Method ? $pm->name() : '';
462
+	}
463
+
464
+
465
+	/**
466
+	 * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
467
+	 * not present then the organization logo is used if its found (set on the organization settings page).
468
+	 *
469
+	 * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
470
+	 * @return string url or html
471
+	 * @throws EE_Error
472
+	 * @throws InvalidArgumentException
473
+	 * @throws InvalidDataTypeException
474
+	 * @throws InvalidInterfaceException
475
+	 * @throws ReflectionException
476
+	 * @since 4.5.0
477
+	 */
478
+	private function _get_invoice_logo(bool $img_tags = false): string
479
+	{
480
+		$invoice_logo_url = '';
481
+		// try to get the invoice payment method's logo for this transaction image first
482
+		$pm = $this->_get_invoice_payment_method();
483
+		if ($pm instanceof EE_Payment_Method) {
484
+			$invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
485
+		}
486
+		if (empty($invoice_logo_url)) {
487
+			$invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
488
+		}
489
+		if (empty($invoice_logo_url)) {
490
+			return '';
491
+		}
492
+		if (! $img_tags) {
493
+			return $invoice_logo_url;
494
+		}
495
+		$invoice_logo_url = esc_url_raw($invoice_logo_url);
496
+		// image tags have been requested.
497
+		$image_size = @getimagesize($invoice_logo_url);
498
+		$image_width_attr = '';
499
+		// if image is wider than 300px, set the width to 300
500
+		if ($image_size !== false) {
501
+			$image_width = min($image_size[0], 300);
502
+			$image_width = esc_attr($image_width);
503
+			$image_width_attr = " width='$image_width'";
504
+		}
505
+		return '<img class="logo screen" src="' . $invoice_logo_url . '"' . $image_width_attr . ' alt="logo" />';
506
+	}
507
+
508
+
509
+	/**
510
+	 * Used to retrieve the appropriate content for the invoice payee name shortcode
511
+	 *
512
+	 * @since 4.5.0
513
+	 * @return string
514
+	 * @throws EE_Error
515
+	 * @throws InvalidArgumentException
516
+	 * @throws InvalidDataTypeException
517
+	 * @throws InvalidInterfaceException
518
+	 */
519
+	private function _get_invoice_payee_name()
520
+	{
521
+		$payee_name = null;
522
+		$pm = $this->_get_invoice_payment_method();
523
+		if ($pm instanceof EE_Payment_Method) {
524
+			$payee_name = $pm->get_extra_meta('pdf_payee_name', true);
525
+		}
526
+		$payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
527
+		return $payee_name;
528
+	}
529
+
530
+
531
+	/**
532
+	 * gets the default invoice payment method, but has a filter so it can be overridden
533
+	 *
534
+	 * @return EE_Payment_Method|null
535
+	 * @throws EE_Error
536
+	 * @throws InvalidArgumentException
537
+	 * @throws InvalidDataTypeException
538
+	 * @throws InvalidInterfaceException
539
+	 */
540
+	private function _get_invoice_payment_method()
541
+	{
542
+		if (! $this->_invoice_pm instanceof EE_Payment_Method) {
543
+			$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
544
+			$transaction = ! $transaction instanceof EE_Transaction
545
+						   && is_array($this->_extra_data)
546
+						   && isset($this->_extra_data['data'])
547
+						   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
548
+				? $this->_extra_data['data']->txn : $transaction;
549
+			// get the invoice payment method, and remember it for the next call too
550
+			$this->_invoice_pm = apply_filters(
551
+				'FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
552
+				EEM_Payment_Method::instance()->get_one_of_type('Invoice'),
553
+				$transaction
554
+			);
555
+		}
556
+		return $this->_invoice_pm;
557
+	}
558
+
559
+
560
+	/**
561
+	 * Used to retrieve the appropriate content for the invoice payee email shortcode
562
+	 *
563
+	 * @since 4.5.0
564
+	 * @return string
565
+	 * @throws EE_Error
566
+	 * @throws InvalidArgumentException
567
+	 * @throws InvalidDataTypeException
568
+	 * @throws InvalidInterfaceException
569
+	 */
570
+	private function _get_invoice_payee_email()
571
+	{
572
+		$payee_email = null;
573
+		$pm = $this->_get_invoice_payment_method();
574
+		if ($pm instanceof EE_Payment_Method) {
575
+			$payee_email = $pm->get_extra_meta('pdf_payee_email', true);
576
+		}
577
+		$payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
578
+			: $payee_email;
579
+		return $payee_email;
580
+	}
581
+
582
+
583
+	/**
584
+	 * Used to retrieve the appropriate content for the invoice payee tax number shortcode
585
+	 *
586
+	 * @since 4.5.0
587
+	 * @param string $shortcode
588
+	 * @return string
589
+	 * @throws EE_Error
590
+	 * @throws InvalidArgumentException
591
+	 * @throws InvalidDataTypeException
592
+	 * @throws InvalidInterfaceException
593
+	 */
594
+	private function _get_invoice_payee_tax_number($shortcode)
595
+	{
596
+		$payee_tax_number = null;
597
+		$pm = $this->_get_invoice_payment_method();
598
+		if ($pm instanceof EE_Payment_Method) {
599
+			$payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
600
+		}
601
+		$payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
602
+			: $payee_tax_number;
603
+		if (empty($payee_tax_number)) {
604
+			return '';
605
+		}
606
+		// any attributes?
607
+		$attrs = $this->_get_shortcode_attrs($shortcode);
608
+		// prefix?
609
+		$prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
610
+		return $prefix . $payee_tax_number;
611
+	}
612
+
613
+
614
+	/**
615
+	 * Used to retrieve the appropriate content for the invoice payee address shortcode.
616
+	 *
617
+	 * @since 4.5.0
618
+	 * @return string
619
+	 * @throws EE_Error
620
+	 * @throws InvalidArgumentException
621
+	 * @throws ReflectionException
622
+	 * @throws InvalidDataTypeException
623
+	 * @throws InvalidInterfaceException
624
+	 */
625
+	private function _get_invoice_payee_address()
626
+	{
627
+		$payee_address = null;
628
+		$pm = $this->_get_invoice_payment_method();
629
+		if ($pm instanceof EE_Payment_Method) {
630
+			$payee_address = $pm->get_extra_meta('pdf_payee_address', true);
631
+		}
632
+		if (empty($payee_address)) {
633
+			$organization = EE_Registry::instance()->CFG->organization;
634
+			$payee_address = $organization->get_pretty('address_1') . '<br>';
635
+			$payee_address .= ! empty($organization->address_2)
636
+				? $organization->get_pretty('address_2') . '<br>'
637
+				: '';
638
+			$payee_address .= $organization->get_pretty('city') . '<br>';
639
+			// state
640
+			$state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
641
+			$payee_address .= $state instanceof EE_State ? $state->name() : '';
642
+			// Country
643
+			$payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
644
+			$payee_address .= ! empty($organization->zip) ? $organization->zip : '';
645
+		}
646
+		return $payee_address;
647
+	}
648
+
649
+
650
+	/**
651
+	 * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
652
+	 *
653
+	 * @since 4.5.0
654
+	 * @return string
655
+	 * @throws EE_Error
656
+	 * @throws InvalidArgumentException
657
+	 * @throws InvalidDataTypeException
658
+	 * @throws InvalidInterfaceException
659
+	 */
660
+	private function _get_invoice_payment_instructions()
661
+	{
662
+		$instructions = null;
663
+		$pm = $this->_get_invoice_payment_method();
664
+		return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
665
+	}
666
+
667
+
668
+	/**
669
+	 * get invoice/receipt switch button or url.
670
+	 *
671
+	 * @param bool $button true (default) returns the html for a button, false just returns the url.
672
+	 * @return string
673
+	 * @throws EE_Error
674
+	 */
675
+	protected function _get_invoice_receipt_switcher($button = true)
676
+	{
677
+		$reg = $this->_data->primary_reg_obj;
678
+		$message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
679
+		if (! $reg instanceof EE_Registration || empty($message_type)) {
680
+			return '';
681
+		}
682
+		$switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
683
+		$switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
684
+			? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
685
+		$switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
686
+		$switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
687
+		if (! $button) {
688
+			return $switch_to_url;
689
+		}
690
+		if (! empty($switch_to_url)) {
691
+			return '
692 692
 	<form method="post" action="' . $switch_to_url . '" >
693 693
 		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
694 694
 	</form>
695 695
 			';
696
-        }
697
-        return '';
698
-    }
699
-
700
-
701
-    /**
702
-     * This returns a subtotal.
703
-     *
704
-     * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
705
-     * @return int
706
-     * @throws EE_Error
707
-     */
708
-    private function _get_subtotal($tax = false)
709
-    {
710
-        $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
711
-        if (! $grand_total instanceof EE_Line_Item) {
712
-            return 0;
713
-        }
714
-        return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
715
-    }
716
-
717
-
718
-    /**
719
-     * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
720
-     *
721
-     * @since 4.7.0
722
-     * @param string $shortcode the incoming shortcode
723
-     * @return string parsed.
724
-     * @throws EE_Error
725
-     */
726
-    private function _get_payment_link_if_needed($shortcode)
727
-    {
728
-        $valid_shortcodes = array('transaction');
729
-        $attrs = $this->_get_shortcode_attrs($shortcode);
730
-        // ensure default is set.
731
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
732
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
733
-            ? $addressee->txn->remaining() : 0;
734
-        if ($total_owing > 0) {
735
-            $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
736
-            $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
737
-            $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
738
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
739
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
740
-            $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
741
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
742
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
743
-            // we need to re run this string through the parser to catch any shortcodes that are in it.
744
-            $owing_content = $this->_shortcode_helper->parse_message_template(
745
-                $content,
746
-                $addressee,
747
-                $valid_shortcodes,
748
-                $this->_message_type,
749
-                $this->_messenger,
750
-                $this->_message
751
-            );
752
-        } else {
753
-            return '';
754
-        }
755
-        return $owing_content;
756
-    }
757
-
758
-
759
-    /**
760
-     * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
761
-     *
762
-     * @since 4.8.28.rc.011
763
-     * @param string         $shortcode The shortcode being parsed.
764
-     * @param EE_Transaction $transaction
765
-     * @return string
766
-     * @throws EE_Error
767
-     */
768
-    protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
769
-    {
770
-        // if transaction is paid in full then we can just return an empty string
771
-        if ($transaction->remaining() === 0) {
772
-            return '';
773
-        }
774
-        $attrs = $this->_get_shortcode_attrs($shortcode);
775
-        $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
776
-        $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30;
777
-        $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
778
-            : esc_html__('Payment in full due by: ', 'event_espresso');
779
-        $transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
780
-        // setup date due:
781
-        try {
782
-            if ($transaction_created instanceof DateTime) {
783
-                $date_due = $transaction_created->add(
784
-                    new DateInterval('P' . $days_until_due . 'D')
785
-                )->format($format);
786
-            } else {
787
-                throw new Exception();
788
-            }
789
-        } catch (Exception $e) {
790
-            // format was likely invalid.
791
-            $date_due = esc_html__(
792
-                'Unable to calculate date due, likely the format string is invalid.',
793
-                'event_espresso'
794
-            );
795
-        }
796
-        return $prefix_text . $date_due;
797
-    }
696
+		}
697
+		return '';
698
+	}
699
+
700
+
701
+	/**
702
+	 * This returns a subtotal.
703
+	 *
704
+	 * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
705
+	 * @return int
706
+	 * @throws EE_Error
707
+	 */
708
+	private function _get_subtotal($tax = false)
709
+	{
710
+		$grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
711
+		if (! $grand_total instanceof EE_Line_Item) {
712
+			return 0;
713
+		}
714
+		return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
715
+	}
716
+
717
+
718
+	/**
719
+	 * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
720
+	 *
721
+	 * @since 4.7.0
722
+	 * @param string $shortcode the incoming shortcode
723
+	 * @return string parsed.
724
+	 * @throws EE_Error
725
+	 */
726
+	private function _get_payment_link_if_needed($shortcode)
727
+	{
728
+		$valid_shortcodes = array('transaction');
729
+		$attrs = $this->_get_shortcode_attrs($shortcode);
730
+		// ensure default is set.
731
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
732
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
733
+			? $addressee->txn->remaining() : 0;
734
+		if ($total_owing > 0) {
735
+			$class = isset($attrs['class']) ? $attrs['class'] : 'callout';
736
+			$custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
737
+			$container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
738
+			$opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
739
+			$opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
740
+			$opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
741
+			$closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
742
+			$content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
743
+			// we need to re run this string through the parser to catch any shortcodes that are in it.
744
+			$owing_content = $this->_shortcode_helper->parse_message_template(
745
+				$content,
746
+				$addressee,
747
+				$valid_shortcodes,
748
+				$this->_message_type,
749
+				$this->_messenger,
750
+				$this->_message
751
+			);
752
+		} else {
753
+			return '';
754
+		}
755
+		return $owing_content;
756
+	}
757
+
758
+
759
+	/**
760
+	 * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
761
+	 *
762
+	 * @since 4.8.28.rc.011
763
+	 * @param string         $shortcode The shortcode being parsed.
764
+	 * @param EE_Transaction $transaction
765
+	 * @return string
766
+	 * @throws EE_Error
767
+	 */
768
+	protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
769
+	{
770
+		// if transaction is paid in full then we can just return an empty string
771
+		if ($transaction->remaining() === 0) {
772
+			return '';
773
+		}
774
+		$attrs = $this->_get_shortcode_attrs($shortcode);
775
+		$format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
776
+		$days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30;
777
+		$prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
778
+			: esc_html__('Payment in full due by: ', 'event_espresso');
779
+		$transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
780
+		// setup date due:
781
+		try {
782
+			if ($transaction_created instanceof DateTime) {
783
+				$date_due = $transaction_created->add(
784
+					new DateInterval('P' . $days_until_due . 'D')
785
+				)->format($format);
786
+			} else {
787
+				throw new Exception();
788
+			}
789
+		} catch (Exception $e) {
790
+			// format was likely invalid.
791
+			$date_due = esc_html__(
792
+				'Unable to calculate date due, likely the format string is invalid.',
793
+				'event_espresso'
794
+			);
795
+		}
796
+		return $prefix_text . $date_due;
797
+	}
798 798
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
                    && isset($this->_extra_data['data'])
269 269
                    && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
270 270
             : $payment;
271
-        if (! $transaction instanceof EE_Transaction) {
271
+        if ( ! $transaction instanceof EE_Transaction) {
272 272
             return '';
273 273
         }
274 274
         switch ($shortcode) {
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
                 $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
287 287
                 return sprintf(
288 288
                     esc_html__('%sClick here for Invoice%s', 'event_espresso'),
289
-                    '<a href="' . $invoice_url . '">',
289
+                    '<a href="'.$invoice_url.'">',
290 290
                     '</a>'
291 291
                 );
292 292
 
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
                 return $this->_data->total_ticket_count;
359 359
 
360 360
             case '[TRANSACTION_ADMIN_URL]':
361
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
361
+                require_once EE_CORE.'admin/EE_Admin_Page.core.php';
362 362
                 $query_args = array(
363 363
                     'page'   => 'espresso_transactions',
364 364
                     'action' => 'view_transaction',
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
             case '[RECEIPT_URL]':
370 370
                 // get primary_registration
371 371
                 $reg = $this->_data->primary_reg_obj;
372
-                if (! $reg instanceof EE_Registration) {
372
+                if ( ! $reg instanceof EE_Registration) {
373 373
                     return '';
374 374
                 }
375 375
                 return $reg->receipt_url();
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         if (empty($invoice_logo_url)) {
490 490
             return '';
491 491
         }
492
-        if (! $img_tags) {
492
+        if ( ! $img_tags) {
493 493
             return $invoice_logo_url;
494 494
         }
495 495
         $invoice_logo_url = esc_url_raw($invoice_logo_url);
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
             $image_width = esc_attr($image_width);
503 503
             $image_width_attr = " width='$image_width'";
504 504
         }
505
-        return '<img class="logo screen" src="' . $invoice_logo_url . '"' . $image_width_attr . ' alt="logo" />';
505
+        return '<img class="logo screen" src="'.$invoice_logo_url.'"'.$image_width_attr.' alt="logo" />';
506 506
     }
507 507
 
508 508
 
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
      */
540 540
     private function _get_invoice_payment_method()
541 541
     {
542
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
542
+        if ( ! $this->_invoice_pm instanceof EE_Payment_Method) {
543 543
             $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
544 544
             $transaction = ! $transaction instanceof EE_Transaction
545 545
                            && is_array($this->_extra_data)
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
         $attrs = $this->_get_shortcode_attrs($shortcode);
608 608
         // prefix?
609 609
         $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
610
-        return $prefix . $payee_tax_number;
610
+        return $prefix.$payee_tax_number;
611 611
     }
612 612
 
613 613
 
@@ -631,16 +631,16 @@  discard block
 block discarded – undo
631 631
         }
632 632
         if (empty($payee_address)) {
633 633
             $organization = EE_Registry::instance()->CFG->organization;
634
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
634
+            $payee_address = $organization->get_pretty('address_1').'<br>';
635 635
             $payee_address .= ! empty($organization->address_2)
636
-                ? $organization->get_pretty('address_2') . '<br>'
636
+                ? $organization->get_pretty('address_2').'<br>'
637 637
                 : '';
638
-            $payee_address .= $organization->get_pretty('city') . '<br>';
638
+            $payee_address .= $organization->get_pretty('city').'<br>';
639 639
             // state
640 640
             $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
641 641
             $payee_address .= $state instanceof EE_State ? $state->name() : '';
642 642
             // Country
643
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
643
+            $payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : '';
644 644
             $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
645 645
         }
646 646
         return $payee_address;
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
     {
677 677
         $reg = $this->_data->primary_reg_obj;
678 678
         $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
679
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
679
+        if ( ! $reg instanceof EE_Registration || empty($message_type)) {
680 680
             return '';
681 681
         }
682 682
         $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
@@ -684,13 +684,13 @@  discard block
 block discarded – undo
684 684
             ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
685 685
         $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
686 686
         $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
687
-        if (! $button) {
687
+        if ( ! $button) {
688 688
             return $switch_to_url;
689 689
         }
690
-        if (! empty($switch_to_url)) {
690
+        if ( ! empty($switch_to_url)) {
691 691
             return '
692
-	<form method="post" action="' . $switch_to_url . '" >
693
-		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
692
+	<form method="post" action="' . $switch_to_url.'" >
693
+		<input class="print_button" type="submit" value="' . $switch_to_label.'" />
694 694
 	</form>
695 695
 			';
696 696
         }
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
     private function _get_subtotal($tax = false)
709 709
     {
710 710
         $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
711
-        if (! $grand_total instanceof EE_Line_Item) {
711
+        if ( ! $grand_total instanceof EE_Line_Item) {
712 712
             return 0;
713 713
         }
714 714
         return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
@@ -735,11 +735,11 @@  discard block
 block discarded – undo
735 735
             $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
736 736
             $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
737 737
             $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
738
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
739
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
738
+            $opening_tag = ! empty($container_tag) ? '<'.$container_tag : '';
739
+            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag;
740 740
             $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
741
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
742
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
741
+            $closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : '';
742
+            $content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag;
743 743
             // we need to re run this string through the parser to catch any shortcodes that are in it.
744 744
             $owing_content = $this->_shortcode_helper->parse_message_template(
745 745
                 $content,
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
         try {
782 782
             if ($transaction_created instanceof DateTime) {
783 783
                 $date_due = $transaction_created->add(
784
-                    new DateInterval('P' . $days_until_due . 'D')
784
+                    new DateInterval('P'.$days_until_due.'D')
785 785
                 )->format($format);
786 786
             } else {
787 787
                 throw new Exception();
@@ -793,6 +793,6 @@  discard block
 block discarded – undo
793 793
                 'event_espresso'
794 794
             );
795 795
         }
796
-        return $prefix_text . $date_due;
796
+        return $prefix_text.$date_due;
797 797
     }
798 798
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Messenger_Shortcodes.lib.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -22,165 +22,165 @@
 block discarded – undo
22 22
  */
23 23
 class EE_Messenger_Shortcodes extends EE_Shortcodes
24 24
 {
25
-    /**
26
-     * Hold array of active messengers indexed by messenger name.
27
-     *
28
-     * @since 4.5.0
29
-     *
30
-     * @var EE_messenger[]
31
-     */
32
-    protected $_active_messengers = array();
33
-
34
-
35
-    protected function _init_props()
36
-    {
37
-        $this->label = esc_html__('Messenger Shortcodes', 'event_espresso');
38
-        $this->description = esc_html__('All shortcodes that are messenger specific.', 'event_espresso');
39
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
40
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
41
-        // add messages about what happens  when the messenger is active.
42
-        $this->_active_messengers = $message_resource_manager->active_messengers();
43
-
44
-        $this->_shortcodes['[DISPLAY_HTML_URL]'] = esc_html__(
45
-            'This will return a link to view the template in a browser if the html messenger is active.',
46
-            'event_espresso'
47
-        );
48
-        $this->_shortcodes['[DISPLAY_PDF_URL]'] = esc_html__(
49
-            'This will return a link to generate a pdf for the template if the pdf messenger is active.',
50
-            'event_espresso'
51
-        );
52
-        $this->_shortcodes['[DISPLAY_PDF_BUTTON]'] = esc_html__(
53
-            'This will return html for a download pdf button trigger if the pdf messenger is active.',
54
-            'event_espresso'
55
-        );
56
-
57
-        /** @var RequestInterface $request */
58
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
59
-        $action = $request->getRequestParam('action');
60
-        // show error message about buttons/urls not working as expected if messenger deactivated.
61
-        if ($action === 'update_message_template' && is_admin()) {
62
-            if (! isset($this->_active_messengers['pdf'])) {
63
-                EE_Error::add_attention(
64
-                    esc_html__(
65
-                        'Be aware that the pdf messenger is inactive.  This means that any pdf related shortcodes will parse to an empty string.',
66
-                        'event_espresso'
67
-                    )
68
-                );
69
-            }
70
-
71
-            if (! isset($this->_active_messengers['html'])) {
72
-                EE_Error::add_attention(
73
-                    esc_html__(
74
-                        'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.',
75
-                        'event_espresso'
76
-                    )
77
-                );
78
-            }
79
-        }
80
-    }
81
-
82
-
83
-    /**
84
-     * @param string $shortcode
85
-     * @throws EE_Error
86
-     */
87
-    protected function _parser($shortcode)
88
-    {
89
-        // make sure we end up with a copy of the EE_Messages_Addressee object
90
-        $recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
91
-        $recipient = ! $recipient instanceof EE_Messages_Addressee
92
-            && is_array($this->_data)
93
-            && isset($this->_data['data'])
94
-            && $this->_data['data'] instanceof EE_Messages_Addressee
95
-                ? $this->_data['data']
96
-                : $recipient;
97
-        $recipient = ! $recipient instanceof EE_Messages_Addressee
98
-            && ! empty($this->_extra_data['data'])
99
-            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
100
-                ? $this->_extra_data['data']
101
-                : $recipient;
102
-
103
-        if (! $recipient instanceof EE_Messages_Addressee) {
104
-            return '';
105
-        }
106
-
107
-        switch ($shortcode) {
108
-            case '[DISPLAY_HTML_URL]':
109
-                return isset($this->_active_messengers['html']) ? $this->_get_url($recipient, 'html') : '';
110
-
111
-            case '[DISPLAY_PDF_URL]':
112
-                return isset($this->_active_messengers['pdf']) ? $this->_get_url($recipient, 'pdf') : '';
113
-
114
-            case '[DISPLAY_PDF_BUTTON]':
115
-                return isset($this->_active_messengers['pdf']) ? $this->_get_button($recipient, 'pdf') : '';
116
-        }
117
-        return '';
118
-    }
119
-
120
-
121
-    /**
122
-     * This method takes the incoming data and figures out from it what the message type is and evt_id/grp_id and uses
123
-     * that to generate the html for a button in the template.
124
-     *
125
-     * @since 4.5.0
126
-     *
127
-     * @param EE_Messages_Addressee $recipient
128
-     * @param string                $sending_messenger 'html' or 'pdf'
129
-     *
130
-     * @return string                Generated html
131
-     */
132
-    private function _get_button(EE_Messages_Addressee $recipient, $sending_messenger)
133
-    {
134
-        $download_text = $sending_messenger == 'pdf'
135
-            ? esc_html__('Download PDF', 'event_espresso')
136
-            : esc_html__(
137
-                'Show HTML',
138
-                'event_espresso'
139
-            );
140
-        $content = '
25
+	/**
26
+	 * Hold array of active messengers indexed by messenger name.
27
+	 *
28
+	 * @since 4.5.0
29
+	 *
30
+	 * @var EE_messenger[]
31
+	 */
32
+	protected $_active_messengers = array();
33
+
34
+
35
+	protected function _init_props()
36
+	{
37
+		$this->label = esc_html__('Messenger Shortcodes', 'event_espresso');
38
+		$this->description = esc_html__('All shortcodes that are messenger specific.', 'event_espresso');
39
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
40
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
41
+		// add messages about what happens  when the messenger is active.
42
+		$this->_active_messengers = $message_resource_manager->active_messengers();
43
+
44
+		$this->_shortcodes['[DISPLAY_HTML_URL]'] = esc_html__(
45
+			'This will return a link to view the template in a browser if the html messenger is active.',
46
+			'event_espresso'
47
+		);
48
+		$this->_shortcodes['[DISPLAY_PDF_URL]'] = esc_html__(
49
+			'This will return a link to generate a pdf for the template if the pdf messenger is active.',
50
+			'event_espresso'
51
+		);
52
+		$this->_shortcodes['[DISPLAY_PDF_BUTTON]'] = esc_html__(
53
+			'This will return html for a download pdf button trigger if the pdf messenger is active.',
54
+			'event_espresso'
55
+		);
56
+
57
+		/** @var RequestInterface $request */
58
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
59
+		$action = $request->getRequestParam('action');
60
+		// show error message about buttons/urls not working as expected if messenger deactivated.
61
+		if ($action === 'update_message_template' && is_admin()) {
62
+			if (! isset($this->_active_messengers['pdf'])) {
63
+				EE_Error::add_attention(
64
+					esc_html__(
65
+						'Be aware that the pdf messenger is inactive.  This means that any pdf related shortcodes will parse to an empty string.',
66
+						'event_espresso'
67
+					)
68
+				);
69
+			}
70
+
71
+			if (! isset($this->_active_messengers['html'])) {
72
+				EE_Error::add_attention(
73
+					esc_html__(
74
+						'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.',
75
+						'event_espresso'
76
+					)
77
+				);
78
+			}
79
+		}
80
+	}
81
+
82
+
83
+	/**
84
+	 * @param string $shortcode
85
+	 * @throws EE_Error
86
+	 */
87
+	protected function _parser($shortcode)
88
+	{
89
+		// make sure we end up with a copy of the EE_Messages_Addressee object
90
+		$recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
91
+		$recipient = ! $recipient instanceof EE_Messages_Addressee
92
+			&& is_array($this->_data)
93
+			&& isset($this->_data['data'])
94
+			&& $this->_data['data'] instanceof EE_Messages_Addressee
95
+				? $this->_data['data']
96
+				: $recipient;
97
+		$recipient = ! $recipient instanceof EE_Messages_Addressee
98
+			&& ! empty($this->_extra_data['data'])
99
+			&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
100
+				? $this->_extra_data['data']
101
+				: $recipient;
102
+
103
+		if (! $recipient instanceof EE_Messages_Addressee) {
104
+			return '';
105
+		}
106
+
107
+		switch ($shortcode) {
108
+			case '[DISPLAY_HTML_URL]':
109
+				return isset($this->_active_messengers['html']) ? $this->_get_url($recipient, 'html') : '';
110
+
111
+			case '[DISPLAY_PDF_URL]':
112
+				return isset($this->_active_messengers['pdf']) ? $this->_get_url($recipient, 'pdf') : '';
113
+
114
+			case '[DISPLAY_PDF_BUTTON]':
115
+				return isset($this->_active_messengers['pdf']) ? $this->_get_button($recipient, 'pdf') : '';
116
+		}
117
+		return '';
118
+	}
119
+
120
+
121
+	/**
122
+	 * This method takes the incoming data and figures out from it what the message type is and evt_id/grp_id and uses
123
+	 * that to generate the html for a button in the template.
124
+	 *
125
+	 * @since 4.5.0
126
+	 *
127
+	 * @param EE_Messages_Addressee $recipient
128
+	 * @param string                $sending_messenger 'html' or 'pdf'
129
+	 *
130
+	 * @return string                Generated html
131
+	 */
132
+	private function _get_button(EE_Messages_Addressee $recipient, $sending_messenger)
133
+	{
134
+		$download_text = $sending_messenger == 'pdf'
135
+			? esc_html__('Download PDF', 'event_espresso')
136
+			: esc_html__(
137
+				'Show HTML',
138
+				'event_espresso'
139
+			);
140
+		$content = '
141 141
 <form method="post" action="' . $this->_get_url($recipient, $sending_messenger) . '" >
142 142
 	<input class="print_button" type="submit" value="' . $download_text . '" />
143 143
 </form>
144 144
 		';
145
-        return $content;
146
-    }
147
-
148
-
149
-    /**
150
-     * This method takes the incoming data and figures out from it what the message type is and
151
-     * evt_id/grp_id and uses that to generate the url for displaying the template in a browser.
152
-     *
153
-     * @since 4.5.0
154
-     *
155
-     * @param EE_Messages_Addressee $recipient
156
-     * @param string                $sending_messenger
157
-     *
158
-     * @return string The generated url for displaying the link.
159
-     * @throws EE_Error
160
-     */
161
-    private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger)
162
-    {
163
-
164
-        $reg = $recipient->reg_obj;
165
-        $reg = ! $reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg;
166
-
167
-
168
-        if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) {
169
-            EE_Registry::instance()->load_helper('MSG_Template');
170
-            try {
171
-                return EEH_MSG_Template::get_url_trigger(
172
-                    $this->_message_type,
173
-                    $this->_message,
174
-                    $reg,
175
-                    $sending_messenger
176
-                );
177
-            } catch (EE_Error $e) {
178
-                if (WP_DEBUG) {
179
-                    $e->get_error();
180
-                }
181
-            }
182
-        }
183
-
184
-        return '';
185
-    }
145
+		return $content;
146
+	}
147
+
148
+
149
+	/**
150
+	 * This method takes the incoming data and figures out from it what the message type is and
151
+	 * evt_id/grp_id and uses that to generate the url for displaying the template in a browser.
152
+	 *
153
+	 * @since 4.5.0
154
+	 *
155
+	 * @param EE_Messages_Addressee $recipient
156
+	 * @param string                $sending_messenger
157
+	 *
158
+	 * @return string The generated url for displaying the link.
159
+	 * @throws EE_Error
160
+	 */
161
+	private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger)
162
+	{
163
+
164
+		$reg = $recipient->reg_obj;
165
+		$reg = ! $reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg;
166
+
167
+
168
+		if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) {
169
+			EE_Registry::instance()->load_helper('MSG_Template');
170
+			try {
171
+				return EEH_MSG_Template::get_url_trigger(
172
+					$this->_message_type,
173
+					$this->_message,
174
+					$reg,
175
+					$sending_messenger
176
+				);
177
+			} catch (EE_Error $e) {
178
+				if (WP_DEBUG) {
179
+					$e->get_error();
180
+				}
181
+			}
182
+		}
183
+
184
+		return '';
185
+	}
186 186
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         $action = $request->getRequestParam('action');
60 60
         // show error message about buttons/urls not working as expected if messenger deactivated.
61 61
         if ($action === 'update_message_template' && is_admin()) {
62
-            if (! isset($this->_active_messengers['pdf'])) {
62
+            if ( ! isset($this->_active_messengers['pdf'])) {
63 63
                 EE_Error::add_attention(
64 64
                     esc_html__(
65 65
                         'Be aware that the pdf messenger is inactive.  This means that any pdf related shortcodes will parse to an empty string.',
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
                 );
69 69
             }
70 70
 
71
-            if (! isset($this->_active_messengers['html'])) {
71
+            if ( ! isset($this->_active_messengers['html'])) {
72 72
                 EE_Error::add_attention(
73 73
                     esc_html__(
74 74
                         'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.',
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
                 ? $this->_extra_data['data']
101 101
                 : $recipient;
102 102
 
103
-        if (! $recipient instanceof EE_Messages_Addressee) {
103
+        if ( ! $recipient instanceof EE_Messages_Addressee) {
104 104
             return '';
105 105
         }
106 106
 
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
                 'event_espresso'
139 139
             );
140 140
         $content = '
141
-<form method="post" action="' . $this->_get_url($recipient, $sending_messenger) . '" >
142
-	<input class="print_button" type="submit" value="' . $download_text . '" />
141
+<form method="post" action="' . $this->_get_url($recipient, $sending_messenger).'" >
142
+	<input class="print_button" type="submit" value="' . $download_text.'" />
143 143
 </form>
144 144
 		';
145 145
         return $content;
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Venue_Shortcodes.lib.php 1 patch
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -15,299 +15,299 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Venue_Shortcodes extends EE_Shortcodes
17 17
 {
18
-    /**
19
-     * Will hold the EE_Event if available
20
-     *
21
-     * @var EE_Event
22
-     */
23
-    protected $_event;
24
-
25
-    /**
26
-     * Will hold the EE_Venue if available
27
-     *
28
-     * @var EE_Venue
29
-     */
30
-    protected $_venue;
31
-
32
-
33
-    /**
34
-     * Initialize properties
35
-     */
36
-    protected function _init_props()
37
-    {
38
-        $this->label = esc_html__('Venue Shortcodes', 'event_espresso');
39
-        $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
40
-        $this->_shortcodes = array(
41
-            '[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
42
-            '[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
43
-            '[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
44
-            '[VENUE_DETAILS_URL]'       => sprintf(
45
-                esc_html__(
46
-                    '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.',
47
-                    'event_espresso'
48
-                ),
49
-                '[VENUE_URL]'
50
-            ),
51
-            '[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
52
-            '[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
53
-            '[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
54
-            '[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
55
-            '[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
56
-            '[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
57
-            '[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
58
-            '[VENUE_FORMATTED_ADDRESS]' => esc_html__(
59
-                'This just outputs the venue address in a semantic address format.',
60
-                'event_espresso'
61
-            ),
62
-            '[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
63
-            '[VENUE_META_*]'            => esc_html__(
64
-                '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.',
65
-                'event_espresso'
66
-            ),
67
-            '[GOOGLE_MAP_URL]'          => esc_html__(
68
-                'URL for the google map associated with the venue.',
69
-                'event_espresso'
70
-            ),
71
-            '[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
72
-            '[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
73
-        );
74
-    }
75
-
76
-
77
-    /**
78
-     * Parse incoming shortcode
79
-     *
80
-     * @param string $shortcode
81
-     * @return string
82
-     * @throws EE_Error
83
-     * @throws EntityNotFoundException
84
-     */
85
-    protected function _parser($shortcode)
86
-    {
87
-        $this->_venue = $this->_get_venue();
88
-        // If there is no venue object by now then get out.
89
-        if (! $this->_venue instanceof EE_Venue) {
90
-            return '';
91
-        }
92
-
93
-        switch ($shortcode) {
94
-            case '[VENUE_TITLE]':
95
-                return $this->_venue('title');
96
-
97
-            case '[VENUE_DESCRIPTION]':
98
-                return $this->_venue('description');
99
-
100
-            case '[VENUE_URL]':
101
-                return $this->_venue('url');
102
-
103
-            case '[VENUE_IMAGE]':
104
-                return $this->_venue('image');
105
-
106
-            case '[VENUE_PHONE]':
107
-                return $this->_venue('phone');
108
-
109
-            case '[VENUE_ADDRESS]':
110
-                return $this->_venue('address');
111
-
112
-            case '[VENUE_ADDRESS2]':
113
-                return $this->_venue('address2');
114
-
115
-            case '[VENUE_CITY]':
116
-                return $this->_venue('city');
117
-
118
-            case '[VENUE_COUNTRY]':
119
-                return $this->_venue('country');
120
-
121
-            case '[VENUE_STATE]':
122
-                return $this->_venue('state');
123
-
124
-            case '[VENUE_ZIP]':
125
-                return $this->_venue('zip');
126
-
127
-            case '[VENUE_FORMATTED_ADDRESS]':
128
-                return $this->_venue('formatted_address');
129
-
130
-            case '[GOOGLE_MAP_URL]':
131
-                return $this->_venue('gmap_url');
132
-
133
-            case '[GOOGLE_MAP_LINK]':
134
-                return $this->_venue('gmap_link');
135
-
136
-            case '[GOOGLE_MAP_IMAGE]':
137
-                return $this->_venue('gmap_link_img');
138
-
139
-            case '[VENUE_DETAILS_URL]':
140
-                return $this->_venue('permalink');
141
-        }
142
-
143
-        if (strpos($shortcode, '[VENUE_META_*') !== false) {
144
-            $shortcode = str_replace('[VENUE_META_*', '', $shortcode);
145
-            $shortcode = trim(str_replace(']', '', $shortcode));
146
-
147
-            // pull the meta value from the venue post
148
-            $venue_meta = $this->_venue->get_post_meta($shortcode, true);
149
-
150
-            return ! empty($venue_meta) ? $venue_meta : '';
151
-        }
152
-    }
153
-
154
-    /**
155
-     * This retrieves the EE_Venue from the available data object.
156
-     *
157
-     * @return EE_Venue|null
158
-     * @throws EE_Error
159
-     * @throws EntityNotFoundException
160
-     */
161
-    private function _get_venue()
162
-    {
163
-
164
-        // we need the EE_Event object to get the venue.
165
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
166
-
167
-        // 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
168
-        // reg_obj instead.
169
-        if (! $this->_event instanceof EE_Event) {
170
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
171
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
172
-
173
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
174
-                ? $aee->reg_obj->event()
175
-                : null;
176
-
177
-            // if still empty do we have a ticket data item?
178
-            $this->_event = ! $this->_event instanceof EE_Event
179
-                            && $this->_data instanceof EE_Ticket
180
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
181
-                ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event']
182
-                : $this->_event;
183
-
184
-            // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
185
-            // and use that.
186
-            $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
187
-                ? reset($aee->events)
188
-                : $this->_event;
189
-        }
190
-
191
-        // If we have an event object use it to pull the venue.
192
-        if ($this->_event instanceof EE_Event) {
193
-            return $this->_event->get_first_related('Venue');
194
-        }
195
-
196
-        return null;
197
-    }
198
-
199
-    /**
200
-     * This retrieves the specified venue information
201
-     *
202
-     * @param string $field What Venue field to retrieve
203
-     * @return string What was retrieved!
204
-     * @throws EE_Error
205
-     * @throws EntityNotFoundException
206
-     */
207
-    private function _venue($field)
208
-    {
209
-
210
-        if (! $this->_venue instanceof EE_Venue) {
211
-            return '';
212
-        } //no venue so get out.
213
-
214
-        switch ($field) {
215
-            case 'title':
216
-                return $this->_venue->get('VNU_name');
217
-                break;
218
-
219
-            case 'description':
220
-                return $this->_venue->get('VNU_desc');
221
-                break;
222
-
223
-            case 'url':
224
-                $url = $this->_venue->get('VNU_url');
225
-                return empty($url) ? $this->_venue->get_permalink() : $url;
226
-                break;
227
-
228
-            case 'permalink':
229
-                return $this->_venue->get_permalink();
230
-                break;
231
-
232
-            case 'image':
233
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
234
-                       . '" alt="' . sprintf(
235
-                           esc_attr__('%s Feature Image', 'event_espresso'),
236
-                           $this->_venue->get('VNU_name')
237
-                       ) . '" />';
238
-                break;
239
-
240
-            case 'phone':
241
-                return $this->_venue->get('VNU_phone');
242
-                break;
243
-
244
-            case 'address':
245
-                return $this->_venue->get('VNU_address');
246
-                break;
247
-
248
-            case 'address2':
249
-                return $this->_venue->get('VNU_address2');
250
-                break;
251
-
252
-            case 'city':
253
-                return $this->_venue->get('VNU_city');
254
-                break;
255
-
256
-            case 'state':
257
-                $state = $this->_venue->state_obj();
258
-                return is_object($state) ? $state->get('STA_name') : '';
259
-                break;
260
-
261
-            case 'country':
262
-                $country = $this->_venue->country_obj();
263
-                return is_object($country) ? $country->get('CNT_name') : '';
264
-                break;
265
-
266
-            case 'zip':
267
-                return $this->_venue->get('VNU_zip');
268
-                break;
269
-
270
-            case 'formatted_address':
271
-                return EEH_Address::format($this->_venue);
272
-                break;
273
-
274
-            case 'gmap_link':
275
-            case 'gmap_url':
276
-            case 'gmap_link_img':
277
-                $atts = $this->get_map_attributes($this->_venue, $field);
278
-                return EEH_Maps::google_map_link($atts);
279
-                break;
280
-        }
281
-        return '';
282
-    }
283
-
284
-
285
-    /**
286
-     * Generates the attributes for retrieving a google_map artifact.
287
-     *
288
-     * @param EE_Venue $venue
289
-     * @param string   $field
290
-     * @return array
291
-     * @throws EE_Error
292
-     */
293
-    protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
294
-    {
295
-        $state = $venue->state_obj();
296
-        $country = $venue->country_obj();
297
-        $atts = array(
298
-            'id'      => $venue->ID(),
299
-            'address' => $venue->get('VNU_address'),
300
-            'city'    => $venue->get('VNU_city'),
301
-            'state'   => is_object($state) ? $state->get('STA_name') : '',
302
-            'zip'     => $venue->get('VNU_zip'),
303
-            'country' => is_object($country) ? $country->get('CNT_name') : '',
304
-            'type'    => $field === 'gmap_link' ? 'url' : 'map',
305
-            'map_w'   => 200,
306
-            'map_h'   => 200,
307
-        );
308
-        if ($field === 'gmap_url') {
309
-            $atts['type'] = 'url_only';
310
-        }
311
-        return $atts;
312
-    }
18
+	/**
19
+	 * Will hold the EE_Event if available
20
+	 *
21
+	 * @var EE_Event
22
+	 */
23
+	protected $_event;
24
+
25
+	/**
26
+	 * Will hold the EE_Venue if available
27
+	 *
28
+	 * @var EE_Venue
29
+	 */
30
+	protected $_venue;
31
+
32
+
33
+	/**
34
+	 * Initialize properties
35
+	 */
36
+	protected function _init_props()
37
+	{
38
+		$this->label = esc_html__('Venue Shortcodes', 'event_espresso');
39
+		$this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
40
+		$this->_shortcodes = array(
41
+			'[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
42
+			'[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
43
+			'[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
44
+			'[VENUE_DETAILS_URL]'       => sprintf(
45
+				esc_html__(
46
+					'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.',
47
+					'event_espresso'
48
+				),
49
+				'[VENUE_URL]'
50
+			),
51
+			'[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
52
+			'[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
53
+			'[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
54
+			'[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
55
+			'[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
56
+			'[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
57
+			'[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
58
+			'[VENUE_FORMATTED_ADDRESS]' => esc_html__(
59
+				'This just outputs the venue address in a semantic address format.',
60
+				'event_espresso'
61
+			),
62
+			'[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
63
+			'[VENUE_META_*]'            => esc_html__(
64
+				'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.',
65
+				'event_espresso'
66
+			),
67
+			'[GOOGLE_MAP_URL]'          => esc_html__(
68
+				'URL for the google map associated with the venue.',
69
+				'event_espresso'
70
+			),
71
+			'[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
72
+			'[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
73
+		);
74
+	}
75
+
76
+
77
+	/**
78
+	 * Parse incoming shortcode
79
+	 *
80
+	 * @param string $shortcode
81
+	 * @return string
82
+	 * @throws EE_Error
83
+	 * @throws EntityNotFoundException
84
+	 */
85
+	protected function _parser($shortcode)
86
+	{
87
+		$this->_venue = $this->_get_venue();
88
+		// If there is no venue object by now then get out.
89
+		if (! $this->_venue instanceof EE_Venue) {
90
+			return '';
91
+		}
92
+
93
+		switch ($shortcode) {
94
+			case '[VENUE_TITLE]':
95
+				return $this->_venue('title');
96
+
97
+			case '[VENUE_DESCRIPTION]':
98
+				return $this->_venue('description');
99
+
100
+			case '[VENUE_URL]':
101
+				return $this->_venue('url');
102
+
103
+			case '[VENUE_IMAGE]':
104
+				return $this->_venue('image');
105
+
106
+			case '[VENUE_PHONE]':
107
+				return $this->_venue('phone');
108
+
109
+			case '[VENUE_ADDRESS]':
110
+				return $this->_venue('address');
111
+
112
+			case '[VENUE_ADDRESS2]':
113
+				return $this->_venue('address2');
114
+
115
+			case '[VENUE_CITY]':
116
+				return $this->_venue('city');
117
+
118
+			case '[VENUE_COUNTRY]':
119
+				return $this->_venue('country');
120
+
121
+			case '[VENUE_STATE]':
122
+				return $this->_venue('state');
123
+
124
+			case '[VENUE_ZIP]':
125
+				return $this->_venue('zip');
126
+
127
+			case '[VENUE_FORMATTED_ADDRESS]':
128
+				return $this->_venue('formatted_address');
129
+
130
+			case '[GOOGLE_MAP_URL]':
131
+				return $this->_venue('gmap_url');
132
+
133
+			case '[GOOGLE_MAP_LINK]':
134
+				return $this->_venue('gmap_link');
135
+
136
+			case '[GOOGLE_MAP_IMAGE]':
137
+				return $this->_venue('gmap_link_img');
138
+
139
+			case '[VENUE_DETAILS_URL]':
140
+				return $this->_venue('permalink');
141
+		}
142
+
143
+		if (strpos($shortcode, '[VENUE_META_*') !== false) {
144
+			$shortcode = str_replace('[VENUE_META_*', '', $shortcode);
145
+			$shortcode = trim(str_replace(']', '', $shortcode));
146
+
147
+			// pull the meta value from the venue post
148
+			$venue_meta = $this->_venue->get_post_meta($shortcode, true);
149
+
150
+			return ! empty($venue_meta) ? $venue_meta : '';
151
+		}
152
+	}
153
+
154
+	/**
155
+	 * This retrieves the EE_Venue from the available data object.
156
+	 *
157
+	 * @return EE_Venue|null
158
+	 * @throws EE_Error
159
+	 * @throws EntityNotFoundException
160
+	 */
161
+	private function _get_venue()
162
+	{
163
+
164
+		// we need the EE_Event object to get the venue.
165
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
166
+
167
+		// 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
168
+		// reg_obj instead.
169
+		if (! $this->_event instanceof EE_Event) {
170
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
171
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
172
+
173
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
174
+				? $aee->reg_obj->event()
175
+				: null;
176
+
177
+			// if still empty do we have a ticket data item?
178
+			$this->_event = ! $this->_event instanceof EE_Event
179
+							&& $this->_data instanceof EE_Ticket
180
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
181
+				? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event']
182
+				: $this->_event;
183
+
184
+			// if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
185
+			// and use that.
186
+			$this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
187
+				? reset($aee->events)
188
+				: $this->_event;
189
+		}
190
+
191
+		// If we have an event object use it to pull the venue.
192
+		if ($this->_event instanceof EE_Event) {
193
+			return $this->_event->get_first_related('Venue');
194
+		}
195
+
196
+		return null;
197
+	}
198
+
199
+	/**
200
+	 * This retrieves the specified venue information
201
+	 *
202
+	 * @param string $field What Venue field to retrieve
203
+	 * @return string What was retrieved!
204
+	 * @throws EE_Error
205
+	 * @throws EntityNotFoundException
206
+	 */
207
+	private function _venue($field)
208
+	{
209
+
210
+		if (! $this->_venue instanceof EE_Venue) {
211
+			return '';
212
+		} //no venue so get out.
213
+
214
+		switch ($field) {
215
+			case 'title':
216
+				return $this->_venue->get('VNU_name');
217
+				break;
218
+
219
+			case 'description':
220
+				return $this->_venue->get('VNU_desc');
221
+				break;
222
+
223
+			case 'url':
224
+				$url = $this->_venue->get('VNU_url');
225
+				return empty($url) ? $this->_venue->get_permalink() : $url;
226
+				break;
227
+
228
+			case 'permalink':
229
+				return $this->_venue->get_permalink();
230
+				break;
231
+
232
+			case 'image':
233
+				return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
234
+					   . '" alt="' . sprintf(
235
+						   esc_attr__('%s Feature Image', 'event_espresso'),
236
+						   $this->_venue->get('VNU_name')
237
+					   ) . '" />';
238
+				break;
239
+
240
+			case 'phone':
241
+				return $this->_venue->get('VNU_phone');
242
+				break;
243
+
244
+			case 'address':
245
+				return $this->_venue->get('VNU_address');
246
+				break;
247
+
248
+			case 'address2':
249
+				return $this->_venue->get('VNU_address2');
250
+				break;
251
+
252
+			case 'city':
253
+				return $this->_venue->get('VNU_city');
254
+				break;
255
+
256
+			case 'state':
257
+				$state = $this->_venue->state_obj();
258
+				return is_object($state) ? $state->get('STA_name') : '';
259
+				break;
260
+
261
+			case 'country':
262
+				$country = $this->_venue->country_obj();
263
+				return is_object($country) ? $country->get('CNT_name') : '';
264
+				break;
265
+
266
+			case 'zip':
267
+				return $this->_venue->get('VNU_zip');
268
+				break;
269
+
270
+			case 'formatted_address':
271
+				return EEH_Address::format($this->_venue);
272
+				break;
273
+
274
+			case 'gmap_link':
275
+			case 'gmap_url':
276
+			case 'gmap_link_img':
277
+				$atts = $this->get_map_attributes($this->_venue, $field);
278
+				return EEH_Maps::google_map_link($atts);
279
+				break;
280
+		}
281
+		return '';
282
+	}
283
+
284
+
285
+	/**
286
+	 * Generates the attributes for retrieving a google_map artifact.
287
+	 *
288
+	 * @param EE_Venue $venue
289
+	 * @param string   $field
290
+	 * @return array
291
+	 * @throws EE_Error
292
+	 */
293
+	protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
294
+	{
295
+		$state = $venue->state_obj();
296
+		$country = $venue->country_obj();
297
+		$atts = array(
298
+			'id'      => $venue->ID(),
299
+			'address' => $venue->get('VNU_address'),
300
+			'city'    => $venue->get('VNU_city'),
301
+			'state'   => is_object($state) ? $state->get('STA_name') : '',
302
+			'zip'     => $venue->get('VNU_zip'),
303
+			'country' => is_object($country) ? $country->get('CNT_name') : '',
304
+			'type'    => $field === 'gmap_link' ? 'url' : 'map',
305
+			'map_w'   => 200,
306
+			'map_h'   => 200,
307
+		);
308
+		if ($field === 'gmap_url') {
309
+			$atts['type'] = 'url_only';
310
+		}
311
+		return $atts;
312
+	}
313 313
 }
Please login to merge, or discard this patch.