Completed
Branch master (ba0702)
by
unknown
02:09
created
core/libraries/messages/messenger/EE_Email_messenger.class.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
             ),
57 57
             '<code>wp_mail</code>'
58 58
         );
59
-        $this->label               = array(
59
+        $this->label = array(
60 60
             'singular' => esc_html__('email', 'event_espresso'),
61 61
             'plural'   => esc_html__('emails', 'event_espresso'),
62 62
         );
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
             $this->_body(),
439 439
             $this->_headers()
440 440
         );
441
-        if (! $success) {
441
+        if ( ! $success) {
442 442
             EE_Error::add_error(
443 443
                 sprintf(
444 444
                     esc_html__(
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
         $this->_ensure_has_from_email_address();
483 483
         $from    = $this->_from;
484 484
         $headers = array(
485
-            'From:' . $from,
486
-            'Reply-To:' . $from,
485
+            'From:'.$from,
486
+            'Reply-To:'.$from,
487 487
             'Content-Type:text/html; charset=utf-8',
488 488
         );
489 489
 
@@ -492,8 +492,8 @@  discard block
 block discarded – undo
492 492
          * cover back compat where there may be users who have saved cc values in their db for the newsletter message
493 493
          * type which they are no longer able to change.
494 494
          */
495
-        if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
496
-            $headers[] = 'cc: ' . $this->_cc;
495
+        if ( ! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
496
+            $headers[] = 'cc: '.$this->_cc;
497 497
         }
498 498
 
499 499
         // but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
             'from'      => $this->_from,
601 601
             'main_body' => wpautop($this->_content),
602 602
         );
603
-        $body                 = $this->_get_main_template($preview);
603
+        $body = $this->_get_main_template($preview);
604 604
 
605 605
         /**
606 606
          * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
@@ -610,10 +610,10 @@  discard block
 block discarded – undo
610 610
          */
611 611
         if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
612 612
             // require CssToInlineStyles library and its dependencies via composer autoloader
613
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
613
+            require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php';
614 614
 
615 615
             // now if this isn't a preview, let's setup the body so it has inline styles
616
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
616
+            if ( ! $preview || ($preview && defined('DOING_AJAX'))) {
617 617
                 $style = file_get_contents(
618 618
                     $this->get_variation(
619 619
                         $this->_tmp_pack,
Please login to merge, or discard this patch.
Indentation   +644 added lines, -644 removed lines patch added patch discarded remove patch
@@ -6,648 +6,648 @@
 block discarded – undo
6 6
 class EE_Email_messenger extends EE_messenger
7 7
 {
8 8
 
9
-    /**
10
-     * To field for email
11
-     * @var string
12
-     */
13
-    protected $_to = '';
14
-
15
-
16
-    /**
17
-     * CC field for email.
18
-     * @var string
19
-     */
20
-    protected $_cc = '';
21
-
22
-    /**
23
-     * From field for email
24
-     * @var string
25
-     */
26
-    protected $_from = '';
27
-
28
-
29
-    /**
30
-     * Subject field for email
31
-     * @var string
32
-     */
33
-    protected $_subject = '';
34
-
35
-
36
-    /**
37
-     * Content field for email
38
-     * @var string
39
-     */
40
-    protected $_content = '';
41
-
42
-
43
-    /**
44
-     * constructor
45
-     *
46
-     * @access public
47
-     */
48
-    public function __construct()
49
-    {
50
-        // set name and description properties
51
-        $this->name                = 'email';
52
-        $this->description         = sprintf(
53
-            esc_html__(
54
-                'This messenger delivers messages via email using the built-in %s function included with WordPress',
55
-                'event_espresso'
56
-            ),
57
-            '<code>wp_mail</code>'
58
-        );
59
-        $this->label               = array(
60
-            'singular' => esc_html__('email', 'event_espresso'),
61
-            'plural'   => esc_html__('emails', 'event_espresso'),
62
-        );
63
-        $this->activate_on_install = true;
64
-
65
-        // we're using defaults so let's call parent constructor that will take care of setting up all the other
66
-        // properties
67
-        parent::__construct();
68
-    }
69
-
70
-
71
-    /**
72
-     * see abstract declaration in parent class for details.
73
-     */
74
-    protected function _set_admin_pages()
75
-    {
76
-        $this->admin_registered_pages = array(
77
-            'events_edit' => true,
78
-        );
79
-    }
80
-
81
-
82
-    /**
83
-     * see abstract declaration in parent class for details
84
-     */
85
-    protected function _set_valid_shortcodes()
86
-    {
87
-        // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
88
-        // message type.
89
-        $this->_valid_shortcodes = array(
90
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
-        );
94
-    }
95
-
96
-
97
-    /**
98
-     * see abstract declaration in parent class for details
99
-     *
100
-     * @access protected
101
-     * @return void
102
-     */
103
-    protected function _set_validator_config()
104
-    {
105
-        $valid_shortcodes = $this->get_valid_shortcodes();
106
-
107
-        $this->_validator_config = array(
108
-            'to'            => array(
109
-                'shortcodes' => $valid_shortcodes['to'],
110
-                'type'       => 'email',
111
-            ),
112
-            'cc' => array(
113
-                'shortcodes' => $valid_shortcodes['to'],
114
-                'type' => 'email',
115
-            ),
116
-            'from'          => array(
117
-                'shortcodes' => $valid_shortcodes['from'],
118
-                'type'       => 'email',
119
-            ),
120
-            'subject'       => array(
121
-                'shortcodes' => array(
122
-                    'organization',
123
-                    'primary_registration_details',
124
-                    'event_author',
125
-                    'primary_registration_details',
126
-                    'recipient_details',
127
-                ),
128
-            ),
129
-            'content'       => array(
130
-                'shortcodes' => array(
131
-                    'event_list',
132
-                    'attendee_list',
133
-                    'ticket_list',
134
-                    'organization',
135
-                    'primary_registration_details',
136
-                    'primary_registration_list',
137
-                    'event_author',
138
-                    'recipient_details',
139
-                    'recipient_list',
140
-                    'transaction',
141
-                    'messenger',
142
-                ),
143
-            ),
144
-            'attendee_list' => array(
145
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
146
-                'required'   => array('[ATTENDEE_LIST]'),
147
-            ),
148
-            'event_list'    => array(
149
-                'shortcodes' => array(
150
-                    'event',
151
-                    'attendee_list',
152
-                    'ticket_list',
153
-                    'venue',
154
-                    'datetime_list',
155
-                    'attendee',
156
-                    'primary_registration_details',
157
-                    'primary_registration_list',
158
-                    'event_author',
159
-                    'recipient_details',
160
-                    'recipient_list',
161
-                ),
162
-                'required'   => array('[EVENT_LIST]'),
163
-            ),
164
-            'ticket_list'   => array(
165
-                'shortcodes' => array(
166
-                    'event_list',
167
-                    'attendee_list',
168
-                    'ticket',
169
-                    'datetime_list',
170
-                    'primary_registration_details',
171
-                    'recipient_details',
172
-                ),
173
-                'required'   => array('[TICKET_LIST]'),
174
-            ),
175
-            'datetime_list' => array(
176
-                'shortcodes' => array('datetime'),
177
-                'required'   => array('[DATETIME_LIST]'),
178
-            ),
179
-        );
180
-    }
181
-
182
-
183
-    /**
184
-     * @see   parent EE_messenger class for docs
185
-     * @since 4.5.0
186
-     */
187
-    public function do_secondary_messenger_hooks($sending_messenger_name)
188
-    {
189
-        if ($sending_messenger_name === 'html') {
190
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
191
-        }
192
-    }
193
-
194
-
195
-    public function add_email_css(
196
-        $variation_path,
197
-        $messenger,
198
-        $message_type,
199
-        $type,
200
-        $variation,
201
-        $file_extension,
202
-        $url,
203
-        EE_Messages_Template_Pack $template_pack
204
-    ) {
205
-        // prevent recursion on this callback.
206
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
207
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
208
-
209
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
210
-        return $variation;
211
-    }
212
-
213
-
214
-    /**
215
-     * See parent for details
216
-     *
217
-     * @access protected
218
-     * @return void
219
-     */
220
-    protected function _set_test_settings_fields()
221
-    {
222
-        $this->_test_settings_fields = array(
223
-            'to'      => array(
224
-                'input'      => 'text',
225
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
226
-                'type'       => 'email',
227
-                'required'   => true,
228
-                'validation' => true,
229
-                'css_class'  => 'large-text',
230
-                'format'     => '%s',
231
-                'default'    => get_bloginfo('admin_email'),
232
-            ),
233
-            'subject' => array(
234
-                'input'      => 'hidden',
235
-                'label'      => '',
236
-                'type'       => 'string',
237
-                'required'   => false,
238
-                'validation' => false,
239
-                'format'     => '%s',
240
-                'value'      => sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
241
-                'default'    => '',
242
-                'css_class'  => '',
243
-            ),
244
-        );
245
-    }
246
-
247
-
248
-    /**
249
-     * _set_template_fields
250
-     * This sets up the fields that a messenger requires for the message to go out.
251
-     *
252
-     * @access  protected
253
-     * @return void
254
-     */
255
-    protected function _set_template_fields()
256
-    {
257
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for
258
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
259
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
260
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
261
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
262
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
263
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
264
-        // will not be displayed/parsed.
265
-        $this->_template_fields = array(
266
-            'to'      => array(
267
-                'input'      => 'text',
268
-                'label'      => esc_html_x(
269
-                    'To',
270
-                    'Label for the "To" field for email addresses',
271
-                    'event_espresso'
272
-                ),
273
-                'type'       => 'string',
274
-                'required'   => true,
275
-                'validation' => true,
276
-                'css_class'  => 'large-text',
277
-                'format'     => '%s',
278
-            ),
279
-            'cc'      => array(
280
-                'input'      => 'text',
281
-                'label'      => esc_html_x(
282
-                    'CC',
283
-                    'Label for the "Carbon Copy" field used for additional email addresses',
284
-                    'event_espresso'
285
-                ),
286
-                'type'       => 'string',
287
-                'required'   => false,
288
-                'validation' => true,
289
-                'css_class'  => 'large-text',
290
-                'format'     => '%s',
291
-            ),
292
-            'from'    => array(
293
-                'input'      => 'text',
294
-                'label'      => esc_html_x(
295
-                    'From',
296
-                    'Label for the "From" field for email addresses.',
297
-                    'event_espresso'
298
-                ),
299
-                'type'       => 'string',
300
-                'required'   => true,
301
-                'validation' => true,
302
-                'css_class'  => 'large-text',
303
-                'format'     => '%s',
304
-            ),
305
-            'subject' => array(
306
-                'input'      => 'text',
307
-                'label'      => esc_html_x(
308
-                    'Subject',
309
-                    'Label for the "Subject" field (short description of contents) for emails.',
310
-                    'event_espresso'
311
-                ),
312
-                'type'       => 'string',
313
-                'required'   => true,
314
-                'validation' => true,
315
-                'css_class'  => 'large-text',
316
-                'format'     => '%s',
317
-            ),
318
-            'content' => '',
319
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
320
-            'extra'   => array(
321
-                'content' => array(
322
-                    'main'          => array(
323
-                        'input'      => 'wp_editor',
324
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
325
-                        'type'       => 'string',
326
-                        'required'   => true,
327
-                        'validation' => true,
328
-                        'format'     => '%s',
329
-                        'rows'       => '15',
330
-                    ),
331
-                    'event_list'    => array(
332
-                        'input'               => 'wp_editor',
333
-                        'label'               => '[EVENT_LIST]',
334
-                        'type'                => 'string',
335
-                        'required'            => true,
336
-                        'validation'          => true,
337
-                        'format'              => '%s',
338
-                        'rows'                => '15',
339
-                        'shortcodes_required' => array('[EVENT_LIST]'),
340
-                    ),
341
-                    'attendee_list' => array(
342
-                        'input'               => 'textarea',
343
-                        'label'               => '[ATTENDEE_LIST]',
344
-                        'type'                => 'string',
345
-                        'required'            => true,
346
-                        'validation'          => true,
347
-                        'format'              => '%s',
348
-                        'css_class'           => 'large-text',
349
-                        'rows'                => '5',
350
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
351
-                    ),
352
-                    'ticket_list'   => array(
353
-                        'input'               => 'textarea',
354
-                        'label'               => '[TICKET_LIST]',
355
-                        'type'                => 'string',
356
-                        'required'            => true,
357
-                        'validation'          => true,
358
-                        'format'              => '%s',
359
-                        'css_class'           => 'large-text',
360
-                        'rows'                => '10',
361
-                        'shortcodes_required' => array('[TICKET_LIST]'),
362
-                    ),
363
-                    'datetime_list' => array(
364
-                        'input'               => 'textarea',
365
-                        'label'               => '[DATETIME_LIST]',
366
-                        'type'                => 'string',
367
-                        'required'            => true,
368
-                        'validation'          => true,
369
-                        'format'              => '%s',
370
-                        'css_class'           => 'large-text',
371
-                        'rows'                => '10',
372
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
373
-                    ),
374
-                ),
375
-            ),
376
-        );
377
-    }
378
-
379
-
380
-    /**
381
-     * See definition of this class in parent
382
-     */
383
-    protected function _set_default_message_types()
384
-    {
385
-        $this->_default_message_types = array(
386
-            'payment',
387
-            'payment_refund',
388
-            'registration',
389
-            'not_approved_registration',
390
-            'pending_approval',
391
-        );
392
-    }
393
-
394
-
395
-    /**
396
-     * @see   definition of this class in parent
397
-     * @since 4.5.0
398
-     */
399
-    protected function _set_valid_message_types()
400
-    {
401
-        $this->_valid_message_types = array(
402
-            'payment',
403
-            'registration',
404
-            'not_approved_registration',
405
-            'declined_registration',
406
-            'cancelled_registration',
407
-            'pending_approval',
408
-            'registration_summary',
409
-            'payment_reminder',
410
-            'payment_declined',
411
-            'payment_refund',
412
-        );
413
-    }
414
-
415
-
416
-    /**
417
-     * setting up admin_settings_fields for messenger.
418
-     */
419
-    protected function _set_admin_settings_fields()
420
-    {
421
-    }
422
-
423
-    /**
424
-     * We just deliver the messages don't kill us!!
425
-     *
426
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
427
-     *              present.
428
-     * @throws EE_Error
429
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
430
-     */
431
-    protected function _send_message()
432
-    {
433
-        $success = wp_mail(
434
-            $this->_to,
435
-            // some old values for subject may be expecting HTML entities to be decoded in the subject
436
-            // and subjects aren't interpreted as HTML, so there should be no HTML in them
437
-            wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
438
-            $this->_body(),
439
-            $this->_headers()
440
-        );
441
-        if (! $success) {
442
-            EE_Error::add_error(
443
-                sprintf(
444
-                    esc_html__(
445
-                        'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
446
-                        'event_espresso'
447
-                    ),
448
-                    $this->_to,
449
-                    $this->_from,
450
-                    '<br />'
451
-                ),
452
-                __FILE__,
453
-                __FUNCTION__,
454
-                __LINE__
455
-            );
456
-        }
457
-        return $success;
458
-    }
459
-
460
-
461
-    /**
462
-     * see parent for definition
463
-     *
464
-     * @return string html body of the message content and the related css.
465
-     * @throws EE_Error
466
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
467
-     */
468
-    protected function _preview()
469
-    {
470
-        return $this->_body(true);
471
-    }
472
-
473
-
474
-    /**
475
-     * Setup headers for email
476
-     *
477
-     * @access protected
478
-     * @return string formatted header for email
479
-     */
480
-    protected function _headers()
481
-    {
482
-        $this->_ensure_has_from_email_address();
483
-        $from    = $this->_from;
484
-        $headers = array(
485
-            'From:' . $from,
486
-            'Reply-To:' . $from,
487
-            'Content-Type:text/html; charset=utf-8',
488
-        );
489
-
490
-        /**
491
-         * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
492
-         * cover back compat where there may be users who have saved cc values in their db for the newsletter message
493
-         * type which they are no longer able to change.
494
-         */
495
-        if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
496
-            $headers[] = 'cc: ' . $this->_cc;
497
-        }
498
-
499
-        // but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
500
-        // header.
501
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
502
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
503
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
504
-    }
505
-
506
-
507
-    /**
508
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
509
-     * address for the from address to avoid problems with sending emails.
510
-     */
511
-    protected function _ensure_has_from_email_address()
512
-    {
513
-        if (empty($this->_from)) {
514
-            $this->_from = get_bloginfo('admin_email');
515
-        }
516
-    }
517
-
518
-
519
-    /**
520
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
521
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
522
-     * be empty
523
-     *
524
-     * @since 4.3.1
525
-     * @return array
526
-     */
527
-    private function _parse_from()
528
-    {
529
-        if (strpos($this->_from, '<') !== false) {
530
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
531
-            $from_name = str_replace('"', '', $from_name);
532
-            $from_name = trim($from_name);
533
-
534
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
535
-            $from_email = str_replace('>', '', $from_email);
536
-            $from_email = trim($from_email);
537
-        } elseif (trim($this->_from) !== '') {
538
-            $from_name  = '';
539
-            $from_email = trim($this->_from);
540
-        } else {
541
-            $from_name = $from_email = '';
542
-        }
543
-        return array($from_name, $from_email);
544
-    }
545
-
546
-
547
-    /**
548
-     * Callback for the wp_mail_from filter.
549
-     *
550
-     * @since 4.3.1
551
-     * @param string $from_email What the original from_email is.
552
-     * @return string
553
-     */
554
-    public function set_from_address($from_email)
555
-    {
556
-        $parsed_from = $this->_parse_from();
557
-        // includes fallback if the parsing failed.
558
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
559
-            ? $parsed_from[1]
560
-            : get_bloginfo('admin_email');
561
-        return $from_email;
562
-    }
563
-
564
-
565
-    /**
566
-     * Callback fro the wp_mail_from_name filter.
567
-     *
568
-     * @since 4.3.1
569
-     * @param string $from_name The original from_name.
570
-     * @return string
571
-     */
572
-    public function set_from_name($from_name)
573
-    {
574
-        $parsed_from = $this->_parse_from();
575
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
576
-            $from_name = $parsed_from[0];
577
-        }
578
-
579
-        // if from name is "WordPress" let's sub in the site name instead (more friendly!)
580
-        // but realize the default name is HTML entity-encoded
581
-        $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
582
-
583
-        return $from_name;
584
-    }
585
-
586
-
587
-    /**
588
-     * setup body for email
589
-     *
590
-     * @param bool $preview will determine whether this is preview template or not.
591
-     * @return string formatted body for email.
592
-     * @throws EE_Error
593
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
594
-     */
595
-    protected function _body($preview = false)
596
-    {
597
-        // setup template args!
598
-        $this->_template_args = array(
599
-            'subject'   => $this->_subject,
600
-            'from'      => $this->_from,
601
-            'main_body' => wpautop($this->_content),
602
-        );
603
-        $body                 = $this->_get_main_template($preview);
604
-
605
-        /**
606
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
607
-         *
608
-         * @type    bool $preview Indicates whether a preview is being generated or not.
609
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
610
-         */
611
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
612
-            // require CssToInlineStyles library and its dependencies via composer autoloader
613
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
614
-
615
-            // now if this isn't a preview, let's setup the body so it has inline styles
616
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
617
-                $style = file_get_contents(
618
-                    $this->get_variation(
619
-                        $this->_tmp_pack,
620
-                        $this->_incoming_message_type->name,
621
-                        false,
622
-                        'main',
623
-                        $this->_variation
624
-                    ),
625
-                    true
626
-                );
627
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
628
-                // for some reason the library has a bracket and new line at the beginning.  This takes care of that.
629
-                $body  = ltrim($CSS->convert(true), ">\n");
630
-                // see https://events.codebasehq.com/projects/event-espresso/tickets/8609
631
-                $body  = ltrim($body, "<?");
632
-            }
633
-        }
634
-        return $body;
635
-    }
636
-
637
-
638
-    /**
639
-     * This just returns any existing test settings that might be saved in the database
640
-     *
641
-     * @access public
642
-     * @return array
643
-     */
644
-    public function get_existing_test_settings()
645
-    {
646
-        $settings = parent::get_existing_test_settings();
647
-        // override subject if present because we always want it to be fresh.
648
-        if (is_array($settings) && ! empty($settings['subject'])) {
649
-            $settings['subject'] = sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
650
-        }
651
-        return $settings;
652
-    }
9
+	/**
10
+	 * To field for email
11
+	 * @var string
12
+	 */
13
+	protected $_to = '';
14
+
15
+
16
+	/**
17
+	 * CC field for email.
18
+	 * @var string
19
+	 */
20
+	protected $_cc = '';
21
+
22
+	/**
23
+	 * From field for email
24
+	 * @var string
25
+	 */
26
+	protected $_from = '';
27
+
28
+
29
+	/**
30
+	 * Subject field for email
31
+	 * @var string
32
+	 */
33
+	protected $_subject = '';
34
+
35
+
36
+	/**
37
+	 * Content field for email
38
+	 * @var string
39
+	 */
40
+	protected $_content = '';
41
+
42
+
43
+	/**
44
+	 * constructor
45
+	 *
46
+	 * @access public
47
+	 */
48
+	public function __construct()
49
+	{
50
+		// set name and description properties
51
+		$this->name                = 'email';
52
+		$this->description         = sprintf(
53
+			esc_html__(
54
+				'This messenger delivers messages via email using the built-in %s function included with WordPress',
55
+				'event_espresso'
56
+			),
57
+			'<code>wp_mail</code>'
58
+		);
59
+		$this->label               = array(
60
+			'singular' => esc_html__('email', 'event_espresso'),
61
+			'plural'   => esc_html__('emails', 'event_espresso'),
62
+		);
63
+		$this->activate_on_install = true;
64
+
65
+		// we're using defaults so let's call parent constructor that will take care of setting up all the other
66
+		// properties
67
+		parent::__construct();
68
+	}
69
+
70
+
71
+	/**
72
+	 * see abstract declaration in parent class for details.
73
+	 */
74
+	protected function _set_admin_pages()
75
+	{
76
+		$this->admin_registered_pages = array(
77
+			'events_edit' => true,
78
+		);
79
+	}
80
+
81
+
82
+	/**
83
+	 * see abstract declaration in parent class for details
84
+	 */
85
+	protected function _set_valid_shortcodes()
86
+	{
87
+		// remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
88
+		// message type.
89
+		$this->_valid_shortcodes = array(
90
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
+		);
94
+	}
95
+
96
+
97
+	/**
98
+	 * see abstract declaration in parent class for details
99
+	 *
100
+	 * @access protected
101
+	 * @return void
102
+	 */
103
+	protected function _set_validator_config()
104
+	{
105
+		$valid_shortcodes = $this->get_valid_shortcodes();
106
+
107
+		$this->_validator_config = array(
108
+			'to'            => array(
109
+				'shortcodes' => $valid_shortcodes['to'],
110
+				'type'       => 'email',
111
+			),
112
+			'cc' => array(
113
+				'shortcodes' => $valid_shortcodes['to'],
114
+				'type' => 'email',
115
+			),
116
+			'from'          => array(
117
+				'shortcodes' => $valid_shortcodes['from'],
118
+				'type'       => 'email',
119
+			),
120
+			'subject'       => array(
121
+				'shortcodes' => array(
122
+					'organization',
123
+					'primary_registration_details',
124
+					'event_author',
125
+					'primary_registration_details',
126
+					'recipient_details',
127
+				),
128
+			),
129
+			'content'       => array(
130
+				'shortcodes' => array(
131
+					'event_list',
132
+					'attendee_list',
133
+					'ticket_list',
134
+					'organization',
135
+					'primary_registration_details',
136
+					'primary_registration_list',
137
+					'event_author',
138
+					'recipient_details',
139
+					'recipient_list',
140
+					'transaction',
141
+					'messenger',
142
+				),
143
+			),
144
+			'attendee_list' => array(
145
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
146
+				'required'   => array('[ATTENDEE_LIST]'),
147
+			),
148
+			'event_list'    => array(
149
+				'shortcodes' => array(
150
+					'event',
151
+					'attendee_list',
152
+					'ticket_list',
153
+					'venue',
154
+					'datetime_list',
155
+					'attendee',
156
+					'primary_registration_details',
157
+					'primary_registration_list',
158
+					'event_author',
159
+					'recipient_details',
160
+					'recipient_list',
161
+				),
162
+				'required'   => array('[EVENT_LIST]'),
163
+			),
164
+			'ticket_list'   => array(
165
+				'shortcodes' => array(
166
+					'event_list',
167
+					'attendee_list',
168
+					'ticket',
169
+					'datetime_list',
170
+					'primary_registration_details',
171
+					'recipient_details',
172
+				),
173
+				'required'   => array('[TICKET_LIST]'),
174
+			),
175
+			'datetime_list' => array(
176
+				'shortcodes' => array('datetime'),
177
+				'required'   => array('[DATETIME_LIST]'),
178
+			),
179
+		);
180
+	}
181
+
182
+
183
+	/**
184
+	 * @see   parent EE_messenger class for docs
185
+	 * @since 4.5.0
186
+	 */
187
+	public function do_secondary_messenger_hooks($sending_messenger_name)
188
+	{
189
+		if ($sending_messenger_name === 'html') {
190
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
191
+		}
192
+	}
193
+
194
+
195
+	public function add_email_css(
196
+		$variation_path,
197
+		$messenger,
198
+		$message_type,
199
+		$type,
200
+		$variation,
201
+		$file_extension,
202
+		$url,
203
+		EE_Messages_Template_Pack $template_pack
204
+	) {
205
+		// prevent recursion on this callback.
206
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
207
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
208
+
209
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
210
+		return $variation;
211
+	}
212
+
213
+
214
+	/**
215
+	 * See parent for details
216
+	 *
217
+	 * @access protected
218
+	 * @return void
219
+	 */
220
+	protected function _set_test_settings_fields()
221
+	{
222
+		$this->_test_settings_fields = array(
223
+			'to'      => array(
224
+				'input'      => 'text',
225
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
226
+				'type'       => 'email',
227
+				'required'   => true,
228
+				'validation' => true,
229
+				'css_class'  => 'large-text',
230
+				'format'     => '%s',
231
+				'default'    => get_bloginfo('admin_email'),
232
+			),
233
+			'subject' => array(
234
+				'input'      => 'hidden',
235
+				'label'      => '',
236
+				'type'       => 'string',
237
+				'required'   => false,
238
+				'validation' => false,
239
+				'format'     => '%s',
240
+				'value'      => sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
241
+				'default'    => '',
242
+				'css_class'  => '',
243
+			),
244
+		);
245
+	}
246
+
247
+
248
+	/**
249
+	 * _set_template_fields
250
+	 * This sets up the fields that a messenger requires for the message to go out.
251
+	 *
252
+	 * @access  protected
253
+	 * @return void
254
+	 */
255
+	protected function _set_template_fields()
256
+	{
257
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for
258
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
259
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
260
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
261
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
262
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
263
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
264
+		// will not be displayed/parsed.
265
+		$this->_template_fields = array(
266
+			'to'      => array(
267
+				'input'      => 'text',
268
+				'label'      => esc_html_x(
269
+					'To',
270
+					'Label for the "To" field for email addresses',
271
+					'event_espresso'
272
+				),
273
+				'type'       => 'string',
274
+				'required'   => true,
275
+				'validation' => true,
276
+				'css_class'  => 'large-text',
277
+				'format'     => '%s',
278
+			),
279
+			'cc'      => array(
280
+				'input'      => 'text',
281
+				'label'      => esc_html_x(
282
+					'CC',
283
+					'Label for the "Carbon Copy" field used for additional email addresses',
284
+					'event_espresso'
285
+				),
286
+				'type'       => 'string',
287
+				'required'   => false,
288
+				'validation' => true,
289
+				'css_class'  => 'large-text',
290
+				'format'     => '%s',
291
+			),
292
+			'from'    => array(
293
+				'input'      => 'text',
294
+				'label'      => esc_html_x(
295
+					'From',
296
+					'Label for the "From" field for email addresses.',
297
+					'event_espresso'
298
+				),
299
+				'type'       => 'string',
300
+				'required'   => true,
301
+				'validation' => true,
302
+				'css_class'  => 'large-text',
303
+				'format'     => '%s',
304
+			),
305
+			'subject' => array(
306
+				'input'      => 'text',
307
+				'label'      => esc_html_x(
308
+					'Subject',
309
+					'Label for the "Subject" field (short description of contents) for emails.',
310
+					'event_espresso'
311
+				),
312
+				'type'       => 'string',
313
+				'required'   => true,
314
+				'validation' => true,
315
+				'css_class'  => 'large-text',
316
+				'format'     => '%s',
317
+			),
318
+			'content' => '',
319
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
320
+			'extra'   => array(
321
+				'content' => array(
322
+					'main'          => array(
323
+						'input'      => 'wp_editor',
324
+						'label'      => esc_html__('Main Content', 'event_espresso'),
325
+						'type'       => 'string',
326
+						'required'   => true,
327
+						'validation' => true,
328
+						'format'     => '%s',
329
+						'rows'       => '15',
330
+					),
331
+					'event_list'    => array(
332
+						'input'               => 'wp_editor',
333
+						'label'               => '[EVENT_LIST]',
334
+						'type'                => 'string',
335
+						'required'            => true,
336
+						'validation'          => true,
337
+						'format'              => '%s',
338
+						'rows'                => '15',
339
+						'shortcodes_required' => array('[EVENT_LIST]'),
340
+					),
341
+					'attendee_list' => array(
342
+						'input'               => 'textarea',
343
+						'label'               => '[ATTENDEE_LIST]',
344
+						'type'                => 'string',
345
+						'required'            => true,
346
+						'validation'          => true,
347
+						'format'              => '%s',
348
+						'css_class'           => 'large-text',
349
+						'rows'                => '5',
350
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
351
+					),
352
+					'ticket_list'   => array(
353
+						'input'               => 'textarea',
354
+						'label'               => '[TICKET_LIST]',
355
+						'type'                => 'string',
356
+						'required'            => true,
357
+						'validation'          => true,
358
+						'format'              => '%s',
359
+						'css_class'           => 'large-text',
360
+						'rows'                => '10',
361
+						'shortcodes_required' => array('[TICKET_LIST]'),
362
+					),
363
+					'datetime_list' => array(
364
+						'input'               => 'textarea',
365
+						'label'               => '[DATETIME_LIST]',
366
+						'type'                => 'string',
367
+						'required'            => true,
368
+						'validation'          => true,
369
+						'format'              => '%s',
370
+						'css_class'           => 'large-text',
371
+						'rows'                => '10',
372
+						'shortcodes_required' => array('[DATETIME_LIST]'),
373
+					),
374
+				),
375
+			),
376
+		);
377
+	}
378
+
379
+
380
+	/**
381
+	 * See definition of this class in parent
382
+	 */
383
+	protected function _set_default_message_types()
384
+	{
385
+		$this->_default_message_types = array(
386
+			'payment',
387
+			'payment_refund',
388
+			'registration',
389
+			'not_approved_registration',
390
+			'pending_approval',
391
+		);
392
+	}
393
+
394
+
395
+	/**
396
+	 * @see   definition of this class in parent
397
+	 * @since 4.5.0
398
+	 */
399
+	protected function _set_valid_message_types()
400
+	{
401
+		$this->_valid_message_types = array(
402
+			'payment',
403
+			'registration',
404
+			'not_approved_registration',
405
+			'declined_registration',
406
+			'cancelled_registration',
407
+			'pending_approval',
408
+			'registration_summary',
409
+			'payment_reminder',
410
+			'payment_declined',
411
+			'payment_refund',
412
+		);
413
+	}
414
+
415
+
416
+	/**
417
+	 * setting up admin_settings_fields for messenger.
418
+	 */
419
+	protected function _set_admin_settings_fields()
420
+	{
421
+	}
422
+
423
+	/**
424
+	 * We just deliver the messages don't kill us!!
425
+	 *
426
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
427
+	 *              present.
428
+	 * @throws EE_Error
429
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
430
+	 */
431
+	protected function _send_message()
432
+	{
433
+		$success = wp_mail(
434
+			$this->_to,
435
+			// some old values for subject may be expecting HTML entities to be decoded in the subject
436
+			// and subjects aren't interpreted as HTML, so there should be no HTML in them
437
+			wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
438
+			$this->_body(),
439
+			$this->_headers()
440
+		);
441
+		if (! $success) {
442
+			EE_Error::add_error(
443
+				sprintf(
444
+					esc_html__(
445
+						'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
446
+						'event_espresso'
447
+					),
448
+					$this->_to,
449
+					$this->_from,
450
+					'<br />'
451
+				),
452
+				__FILE__,
453
+				__FUNCTION__,
454
+				__LINE__
455
+			);
456
+		}
457
+		return $success;
458
+	}
459
+
460
+
461
+	/**
462
+	 * see parent for definition
463
+	 *
464
+	 * @return string html body of the message content and the related css.
465
+	 * @throws EE_Error
466
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
467
+	 */
468
+	protected function _preview()
469
+	{
470
+		return $this->_body(true);
471
+	}
472
+
473
+
474
+	/**
475
+	 * Setup headers for email
476
+	 *
477
+	 * @access protected
478
+	 * @return string formatted header for email
479
+	 */
480
+	protected function _headers()
481
+	{
482
+		$this->_ensure_has_from_email_address();
483
+		$from    = $this->_from;
484
+		$headers = array(
485
+			'From:' . $from,
486
+			'Reply-To:' . $from,
487
+			'Content-Type:text/html; charset=utf-8',
488
+		);
489
+
490
+		/**
491
+		 * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
492
+		 * cover back compat where there may be users who have saved cc values in their db for the newsletter message
493
+		 * type which they are no longer able to change.
494
+		 */
495
+		if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
496
+			$headers[] = 'cc: ' . $this->_cc;
497
+		}
498
+
499
+		// but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
500
+		// header.
501
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
502
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
503
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
504
+	}
505
+
506
+
507
+	/**
508
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
509
+	 * address for the from address to avoid problems with sending emails.
510
+	 */
511
+	protected function _ensure_has_from_email_address()
512
+	{
513
+		if (empty($this->_from)) {
514
+			$this->_from = get_bloginfo('admin_email');
515
+		}
516
+	}
517
+
518
+
519
+	/**
520
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
521
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
522
+	 * be empty
523
+	 *
524
+	 * @since 4.3.1
525
+	 * @return array
526
+	 */
527
+	private function _parse_from()
528
+	{
529
+		if (strpos($this->_from, '<') !== false) {
530
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
531
+			$from_name = str_replace('"', '', $from_name);
532
+			$from_name = trim($from_name);
533
+
534
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
535
+			$from_email = str_replace('>', '', $from_email);
536
+			$from_email = trim($from_email);
537
+		} elseif (trim($this->_from) !== '') {
538
+			$from_name  = '';
539
+			$from_email = trim($this->_from);
540
+		} else {
541
+			$from_name = $from_email = '';
542
+		}
543
+		return array($from_name, $from_email);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Callback for the wp_mail_from filter.
549
+	 *
550
+	 * @since 4.3.1
551
+	 * @param string $from_email What the original from_email is.
552
+	 * @return string
553
+	 */
554
+	public function set_from_address($from_email)
555
+	{
556
+		$parsed_from = $this->_parse_from();
557
+		// includes fallback if the parsing failed.
558
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
559
+			? $parsed_from[1]
560
+			: get_bloginfo('admin_email');
561
+		return $from_email;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Callback fro the wp_mail_from_name filter.
567
+	 *
568
+	 * @since 4.3.1
569
+	 * @param string $from_name The original from_name.
570
+	 * @return string
571
+	 */
572
+	public function set_from_name($from_name)
573
+	{
574
+		$parsed_from = $this->_parse_from();
575
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
576
+			$from_name = $parsed_from[0];
577
+		}
578
+
579
+		// if from name is "WordPress" let's sub in the site name instead (more friendly!)
580
+		// but realize the default name is HTML entity-encoded
581
+		$from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
582
+
583
+		return $from_name;
584
+	}
585
+
586
+
587
+	/**
588
+	 * setup body for email
589
+	 *
590
+	 * @param bool $preview will determine whether this is preview template or not.
591
+	 * @return string formatted body for email.
592
+	 * @throws EE_Error
593
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
594
+	 */
595
+	protected function _body($preview = false)
596
+	{
597
+		// setup template args!
598
+		$this->_template_args = array(
599
+			'subject'   => $this->_subject,
600
+			'from'      => $this->_from,
601
+			'main_body' => wpautop($this->_content),
602
+		);
603
+		$body                 = $this->_get_main_template($preview);
604
+
605
+		/**
606
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
607
+		 *
608
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
609
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
610
+		 */
611
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
612
+			// require CssToInlineStyles library and its dependencies via composer autoloader
613
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
614
+
615
+			// now if this isn't a preview, let's setup the body so it has inline styles
616
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
617
+				$style = file_get_contents(
618
+					$this->get_variation(
619
+						$this->_tmp_pack,
620
+						$this->_incoming_message_type->name,
621
+						false,
622
+						'main',
623
+						$this->_variation
624
+					),
625
+					true
626
+				);
627
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
628
+				// for some reason the library has a bracket and new line at the beginning.  This takes care of that.
629
+				$body  = ltrim($CSS->convert(true), ">\n");
630
+				// see https://events.codebasehq.com/projects/event-espresso/tickets/8609
631
+				$body  = ltrim($body, "<?");
632
+			}
633
+		}
634
+		return $body;
635
+	}
636
+
637
+
638
+	/**
639
+	 * This just returns any existing test settings that might be saved in the database
640
+	 *
641
+	 * @access public
642
+	 * @return array
643
+	 */
644
+	public function get_existing_test_settings()
645
+	{
646
+		$settings = parent::get_existing_test_settings();
647
+		// override subject if present because we always want it to be fresh.
648
+		if (is_array($settings) && ! empty($settings['subject'])) {
649
+			$settings['subject'] = sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
650
+		}
651
+		return $settings;
652
+	}
653 653
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Data_Handler_Collection.lib.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
      */
47 47
     public function get_key($classname, $data)
48 48
     {
49
-        return md5($classname . serialize($data));
49
+        return md5($classname.serialize($data));
50 50
     }
51 51
 
52 52
 
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -11,69 +11,69 @@
 block discarded – undo
11 11
 {
12 12
 
13 13
 
14
-    public function __construct()
15
-    {
16
-        $this->interface = 'EE_Messages_incoming_data';
17
-    }
18
-
19
-
20
-    /**
21
-     * This adds the EE_Messages_incoming_data data handler object to the collection.
22
-     *
23
-     * @param EE_Messages_incoming_data  $data_handler
24
-     * @param mixed                      $data           Usually an array of data used in combination with the $data_handler
25
-     *                                                   classname to create an alternative index for retrieving data_handlers.
26
-     * @return bool
27
-     */
28
-    public function add($data_handler, $data = null)
29
-    {
30
-        $data = $data === null ? array() : (array) $data;
31
-        $info['key'] = $this->get_key(get_class($data_handler), $data);
32
-        return parent::add($data_handler, $info);
33
-    }
34
-
35
-
36
-
37
-
38
-
39
-    /**
40
-     * This returns a key for retrieving data for the given references used to generate the key.
41
-     * Data handlers are cached to the repository along with a md5() generated key using known references.
42
-     * @param string    $classname      The classname of the datahandler being checked for.
43
-     * @param mixed     $data           The data that was used to instantiate the data_handler.
44
-     *
45
-     * @return  string      md5 hash using provided info.
46
-     */
47
-    public function get_key($classname, $data)
48
-    {
49
-        return md5($classname . serialize($data));
50
-    }
51
-
52
-
53
-
54
-
55
-
56
-
57
-    /**
58
-     * This returns a saved EE_Messages_incoming_data object if there is one in the repository indexed by a key matching
59
-     * the given string.
60
-     *
61
-     * @param string  $key  @see EE_Messages_Data_Handler_Collection::get_key() to setup a key formatted for searching.
62
-     *
63
-     * @return null|EE_Messages_incoming_data
64
-     */
65
-    public function get_by_key($key)
66
-    {
67
-        $this->rewind();
68
-        while ($this->valid()) {
69
-            $data = $this->getInfo();
70
-            if (isset($data['key']) && $data['key'] === $key) {
71
-                $handler = $this->current();
72
-                $this->rewind();
73
-                return $handler;
74
-            }
75
-            $this->next();
76
-        }
77
-        return null;
78
-    }
14
+	public function __construct()
15
+	{
16
+		$this->interface = 'EE_Messages_incoming_data';
17
+	}
18
+
19
+
20
+	/**
21
+	 * This adds the EE_Messages_incoming_data data handler object to the collection.
22
+	 *
23
+	 * @param EE_Messages_incoming_data  $data_handler
24
+	 * @param mixed                      $data           Usually an array of data used in combination with the $data_handler
25
+	 *                                                   classname to create an alternative index for retrieving data_handlers.
26
+	 * @return bool
27
+	 */
28
+	public function add($data_handler, $data = null)
29
+	{
30
+		$data = $data === null ? array() : (array) $data;
31
+		$info['key'] = $this->get_key(get_class($data_handler), $data);
32
+		return parent::add($data_handler, $info);
33
+	}
34
+
35
+
36
+
37
+
38
+
39
+	/**
40
+	 * This returns a key for retrieving data for the given references used to generate the key.
41
+	 * Data handlers are cached to the repository along with a md5() generated key using known references.
42
+	 * @param string    $classname      The classname of the datahandler being checked for.
43
+	 * @param mixed     $data           The data that was used to instantiate the data_handler.
44
+	 *
45
+	 * @return  string      md5 hash using provided info.
46
+	 */
47
+	public function get_key($classname, $data)
48
+	{
49
+		return md5($classname . serialize($data));
50
+	}
51
+
52
+
53
+
54
+
55
+
56
+
57
+	/**
58
+	 * This returns a saved EE_Messages_incoming_data object if there is one in the repository indexed by a key matching
59
+	 * the given string.
60
+	 *
61
+	 * @param string  $key  @see EE_Messages_Data_Handler_Collection::get_key() to setup a key formatted for searching.
62
+	 *
63
+	 * @return null|EE_Messages_incoming_data
64
+	 */
65
+	public function get_by_key($key)
66
+	{
67
+		$this->rewind();
68
+		while ($this->valid()) {
69
+			$data = $this->getInfo();
70
+			if (isset($data['key']) && $data['key'] === $key) {
71
+				$handler = $this->current();
72
+				$this->rewind();
73
+				return $handler;
74
+			}
75
+			$this->next();
76
+		}
77
+		return null;
78
+	}
79 79
 }
Please login to merge, or discard this patch.
core/libraries/messages/message_type/EE_Invoice_message_type.class.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
     protected function _set_admin_pages()
54 54
     {
55
-        $this->admin_registered_pages = array( 'events_edit' => true );
55
+        $this->admin_registered_pages = array('events_edit' => true);
56 56
     }
57 57
 
58 58
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     protected function _set_with_messengers()
68 68
     {
69 69
         $this->_with_messengers = array(
70
-            'html' => array( 'pdf' )
70
+            'html' => array('pdf')
71 71
             );
72 72
     }
73 73
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         // receipt message type data handler is 'Gateways' and it expects a transaction object.
79 79
         $transaction = $registration->transaction();
80 80
         if ($transaction instanceof EE_Transaction) {
81
-            return array( $transaction );
81
+            return array($transaction);
82 82
         }
83 83
         return array();
84 84
     }
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -13,123 +13,123 @@
 block discarded – undo
13 13
 class EE_Invoice_message_type extends EE_message_type
14 14
 {
15 15
 
16
-    public function __construct()
17
-    {
18
-        $this->name = 'invoice';
19
-        $this->description = esc_html__('The invoice message type is triggered via a url on the thank you page and via at url generated by the [INVOICE_URL] or [INVOICE_LINK] shortcode.', 'event_espresso');
20
-        $this->label = array(
21
-            'singular' => esc_html__('invoice', 'event_espresso'),
22
-            'plural' => esc_html__('invoices', 'event_espresso')
23
-        );
24
-        $this->_master_templates = array();
25
-        parent::__construct();
26
-    }
16
+	public function __construct()
17
+	{
18
+		$this->name = 'invoice';
19
+		$this->description = esc_html__('The invoice message type is triggered via a url on the thank you page and via at url generated by the [INVOICE_URL] or [INVOICE_LINK] shortcode.', 'event_espresso');
20
+		$this->label = array(
21
+			'singular' => esc_html__('invoice', 'event_espresso'),
22
+			'plural' => esc_html__('invoices', 'event_espresso')
23
+		);
24
+		$this->_master_templates = array();
25
+		parent::__construct();
26
+	}
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * @see parent::get_priority() for documentation.
32
-     * @return int
33
-     */
34
-    public function get_priority()
35
-    {
36
-        return EEM_Message::priority_high;
37
-    }
30
+	/**
31
+	 * @see parent::get_priority() for documentation.
32
+	 * @return int
33
+	 */
34
+	public function get_priority()
35
+	{
36
+		return EEM_Message::priority_high;
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * This method returns whether this message type should always generate a new copy
42
-     * when requested, or if links can be to the already generated copy.
43
-     * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table.
44
-     * Invoices always generate.
45
-     * @return bool     false means can link to generated EE_Message.  true must regenerate.
46
-     */
47
-    public function always_generate()
48
-    {
49
-        return true;
50
-    }
40
+	/**
41
+	 * This method returns whether this message type should always generate a new copy
42
+	 * when requested, or if links can be to the already generated copy.
43
+	 * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table.
44
+	 * Invoices always generate.
45
+	 * @return bool     false means can link to generated EE_Message.  true must regenerate.
46
+	 */
47
+	public function always_generate()
48
+	{
49
+		return true;
50
+	}
51 51
 
52 52
 
53
-    protected function _set_admin_pages()
54
-    {
55
-        $this->admin_registered_pages = array( 'events_edit' => true );
56
-    }
53
+	protected function _set_admin_pages()
54
+	{
55
+		$this->admin_registered_pages = array( 'events_edit' => true );
56
+	}
57 57
 
58 58
 
59 59
 
60
-    protected function _set_data_handler()
61
-    {
62
-        $this->_data_handler = 'Gateways';
63
-    }
60
+	protected function _set_data_handler()
61
+	{
62
+		$this->_data_handler = 'Gateways';
63
+	}
64 64
 
65 65
 
66 66
 
67
-    protected function _set_with_messengers()
68
-    {
69
-        $this->_with_messengers = array(
70
-            'html' => array( 'pdf' )
71
-            );
72
-    }
67
+	protected function _set_with_messengers()
68
+	{
69
+		$this->_with_messengers = array(
70
+			'html' => array( 'pdf' )
71
+			);
72
+	}
73 73
 
74 74
 
75 75
 
76
-    protected function _get_data_for_context($context, EE_Registration $registration, $id)
77
-    {
78
-        // receipt message type data handler is 'Gateways' and it expects a transaction object.
79
-        $transaction = $registration->transaction();
80
-        if ($transaction instanceof EE_Transaction) {
81
-            return array( $transaction );
82
-        }
83
-        return array();
84
-    }
76
+	protected function _get_data_for_context($context, EE_Registration $registration, $id)
77
+	{
78
+		// receipt message type data handler is 'Gateways' and it expects a transaction object.
79
+		$transaction = $registration->transaction();
80
+		if ($transaction instanceof EE_Transaction) {
81
+			return array( $transaction );
82
+		}
83
+		return array();
84
+	}
85 85
 
86 86
 
87 87
 
88
-    protected function _set_admin_settings_fields()
89
-    {
90
-        $this->_admin_settings_fields = array();
91
-    }
88
+	protected function _set_admin_settings_fields()
89
+	{
90
+		$this->_admin_settings_fields = array();
91
+	}
92 92
 
93 93
 
94 94
 
95
-    protected function _set_contexts()
96
-    {
97
-        $this->_context_label = array(
98
-            'label' => esc_html__('recipient', 'event_espresso'),
99
-            'plural' => esc_html__('recipients', 'event_espresso'),
100
-            'description' => esc_html__('Recipient\'s are who will view the invoice.', 'event_espresso')
101
-        );
95
+	protected function _set_contexts()
96
+	{
97
+		$this->_context_label = array(
98
+			'label' => esc_html__('recipient', 'event_espresso'),
99
+			'plural' => esc_html__('recipients', 'event_espresso'),
100
+			'description' => esc_html__('Recipient\'s are who will view the invoice.', 'event_espresso')
101
+		);
102 102
 
103
-        $this->_contexts = array(
104
-            'purchaser' => array(
105
-                'label' => esc_html__('Purchaser', 'event_espresso'),
106
-                'description' => esc_html__('This template goes to the person who conducted the transaction.', 'event_espresso')
107
-            )
108
-        );
109
-    }
103
+		$this->_contexts = array(
104
+			'purchaser' => array(
105
+				'label' => esc_html__('Purchaser', 'event_espresso'),
106
+				'description' => esc_html__('This template goes to the person who conducted the transaction.', 'event_espresso')
107
+			)
108
+		);
109
+	}
110 110
 
111 111
 
112 112
 
113 113
 
114
-    /**
115
-    * used to set the valid shortcodes for the receipt message type
116
-    *
117
-    * @since   4.5.0
118
-    *
119
-    * @return  void
120
-    */
121
-    protected function _set_valid_shortcodes()
122
-    {
123
-        $this->_valid_shortcodes['purchaser'] = array(
124
-            'attendee_list', 'attendee', 'datetime_list', 'datetime', 'event_list', 'event', 'event_meta', 'messenger', 'organization', 'primary_registration_list', 'primary_registration_details', 'ticket_list', 'ticket', 'transaction', 'venue', 'line_item_list', 'payment_list', 'line_item', 'payment'
125
-        );
126
-    }
114
+	/**
115
+	 * used to set the valid shortcodes for the receipt message type
116
+	 *
117
+	 * @since   4.5.0
118
+	 *
119
+	 * @return  void
120
+	 */
121
+	protected function _set_valid_shortcodes()
122
+	{
123
+		$this->_valid_shortcodes['purchaser'] = array(
124
+			'attendee_list', 'attendee', 'datetime_list', 'datetime', 'event_list', 'event', 'event_meta', 'messenger', 'organization', 'primary_registration_list', 'primary_registration_details', 'ticket_list', 'ticket', 'transaction', 'venue', 'line_item_list', 'payment_list', 'line_item', 'payment'
125
+		);
126
+	}
127 127
 
128 128
 
129 129
 
130 130
 
131
-    protected function _purchaser_addressees()
132
-    {
133
-        return parent::_primary_attendee_addressees();
134
-    }
131
+	protected function _purchaser_addressees()
132
+	{
133
+		return parent::_primary_attendee_addressees();
134
+	}
135 135
 }
Please login to merge, or discard this patch.
core/libraries/messages/message_type/EE_Receipt_message_type.class.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 
54 54
     protected function _set_admin_pages()
55 55
     {
56
-        $this->admin_registered_pages = array( 'events_edit' => true );
56
+        $this->admin_registered_pages = array('events_edit' => true);
57 57
     }
58 58
 
59 59
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     protected function _set_with_messengers()
69 69
     {
70 70
         $this->_with_messengers = array(
71
-            'html' => array( 'pdf' )
71
+            'html' => array('pdf')
72 72
         );
73 73
     }
74 74
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         // receipt message type data handler is 'Gateways' and it expects a transaction object.
80 80
         $transaction = $registration->transaction();
81 81
         if ($transaction instanceof EE_Transaction) {
82
-            return array( $transaction );
82
+            return array($transaction);
83 83
         }
84 84
         return array();
85 85
     }
Please login to merge, or discard this patch.
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -13,142 +13,142 @@
 block discarded – undo
13 13
 class EE_Receipt_message_type extends EE_message_type
14 14
 {
15 15
 
16
-    public function __construct()
17
-    {
18
-        $this->name = 'receipt';
19
-        $this->description = esc_html__('The receipt message type is triggered via a url on the thank you page and via at url generated by the [RECEIPT_URL] shortcode.', 'event_espresso');
20
-        $this->label = array(
21
-            'singular' => esc_html__('receipt', 'event_espresso'),
22
-            'plural' => esc_html__('receipts', 'event_espresso')
23
-        );
24
-        $this->_master_templates = array();
25
-        parent::__construct();
26
-    }
16
+	public function __construct()
17
+	{
18
+		$this->name = 'receipt';
19
+		$this->description = esc_html__('The receipt message type is triggered via a url on the thank you page and via at url generated by the [RECEIPT_URL] shortcode.', 'event_espresso');
20
+		$this->label = array(
21
+			'singular' => esc_html__('receipt', 'event_espresso'),
22
+			'plural' => esc_html__('receipts', 'event_espresso')
23
+		);
24
+		$this->_master_templates = array();
25
+		parent::__construct();
26
+	}
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * @see parent::get_priority() for documentation.
32
-     * @return int
33
-     */
34
-    public function get_priority()
35
-    {
36
-        return EEM_Message::priority_high;
37
-    }
38
-
39
-
40
-
41
-    /**
42
-     * This method returns whether this message type should always generate a new copy
43
-     * when requested, or if links can be to the already generated copy.
44
-     * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table.
45
-     * Receipts always generate
46
-     * @return bool     false means can link to generated EE_Message.  true must regenerate.
47
-     */
48
-    public function always_generate()
49
-    {
50
-        return true;
51
-    }
52
-
53
-
54
-    protected function _set_admin_pages()
55
-    {
56
-        $this->admin_registered_pages = array( 'events_edit' => true );
57
-    }
58
-
59
-
60
-
61
-    protected function _set_data_handler()
62
-    {
63
-        $this->_data_handler = 'Gateways';
64
-    }
65
-
66
-
67
-
68
-    protected function _set_with_messengers()
69
-    {
70
-        $this->_with_messengers = array(
71
-            'html' => array( 'pdf' )
72
-        );
73
-    }
74
-
75
-
76
-
77
-    protected function _get_data_for_context($context, EE_Registration $registration, $id)
78
-    {
79
-        // receipt message type data handler is 'Gateways' and it expects a transaction object.
80
-        $transaction = $registration->transaction();
81
-        if ($transaction instanceof EE_Transaction) {
82
-            return array( $transaction );
83
-        }
84
-        return array();
85
-    }
86
-
87
-
88
-
89
-    protected function _set_admin_settings_fields()
90
-    {
91
-        $this->_admin_settings_fields = array();
92
-    }
93
-
94
-
95
-
96
-    protected function _set_contexts()
97
-    {
98
-        $this->_context_label = array(
99
-            'label' => esc_html__('recipient', 'event_espresso'),
100
-            'plural' => esc_html__('recipients', 'event_espresso'),
101
-            'description' => esc_html__('Recipient\'s are who will view the receipt.', 'event_espresso')
102
-        );
103
-
104
-        $this->_contexts = array(
105
-            'purchaser' => array(
106
-                'label' => esc_html__('Purchaser', 'event_espresso'),
107
-                'description' => esc_html__('This template goes to the person who conducted the transaction.', 'event_espresso')
108
-            )
109
-        );
110
-    }
111
-
112
-
113
-
114
-
115
-    /**
116
-    * used to set the valid shortcodes for the receipt message type
117
-    *
118
-    * @since   4.5.0
119
-    *
120
-    * @return  void
121
-    */
122
-    protected function _set_valid_shortcodes()
123
-    {
124
-        $this->_valid_shortcodes['purchaser'] = array(
125
-            'attendee_list',
126
-            'attendee',
127
-            'datetime_list',
128
-            'datetime',
129
-            'event_list',
130
-            'event',
131
-            'event_meta',
132
-            'messenger',
133
-            'organization',
134
-            'primary_registration_list',
135
-            'primary_registration_details',
136
-            'ticket_list',
137
-            'ticket',
138
-            'transaction',
139
-            'venue',
140
-            'line_item_list',
141
-            'payment_list',
142
-            'line_item',
143
-            'payment'
144
-        );
145
-    }
146
-
30
+	/**
31
+	 * @see parent::get_priority() for documentation.
32
+	 * @return int
33
+	 */
34
+	public function get_priority()
35
+	{
36
+		return EEM_Message::priority_high;
37
+	}
38
+
39
+
40
+
41
+	/**
42
+	 * This method returns whether this message type should always generate a new copy
43
+	 * when requested, or if links can be to the already generated copy.
44
+	 * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table.
45
+	 * Receipts always generate
46
+	 * @return bool     false means can link to generated EE_Message.  true must regenerate.
47
+	 */
48
+	public function always_generate()
49
+	{
50
+		return true;
51
+	}
52
+
53
+
54
+	protected function _set_admin_pages()
55
+	{
56
+		$this->admin_registered_pages = array( 'events_edit' => true );
57
+	}
58
+
59
+
60
+
61
+	protected function _set_data_handler()
62
+	{
63
+		$this->_data_handler = 'Gateways';
64
+	}
65
+
66
+
67
+
68
+	protected function _set_with_messengers()
69
+	{
70
+		$this->_with_messengers = array(
71
+			'html' => array( 'pdf' )
72
+		);
73
+	}
74
+
75
+
76
+
77
+	protected function _get_data_for_context($context, EE_Registration $registration, $id)
78
+	{
79
+		// receipt message type data handler is 'Gateways' and it expects a transaction object.
80
+		$transaction = $registration->transaction();
81
+		if ($transaction instanceof EE_Transaction) {
82
+			return array( $transaction );
83
+		}
84
+		return array();
85
+	}
86
+
87
+
88
+
89
+	protected function _set_admin_settings_fields()
90
+	{
91
+		$this->_admin_settings_fields = array();
92
+	}
93
+
94
+
95
+
96
+	protected function _set_contexts()
97
+	{
98
+		$this->_context_label = array(
99
+			'label' => esc_html__('recipient', 'event_espresso'),
100
+			'plural' => esc_html__('recipients', 'event_espresso'),
101
+			'description' => esc_html__('Recipient\'s are who will view the receipt.', 'event_espresso')
102
+		);
103
+
104
+		$this->_contexts = array(
105
+			'purchaser' => array(
106
+				'label' => esc_html__('Purchaser', 'event_espresso'),
107
+				'description' => esc_html__('This template goes to the person who conducted the transaction.', 'event_espresso')
108
+			)
109
+		);
110
+	}
111
+
112
+
113
+
114
+
115
+	/**
116
+	 * used to set the valid shortcodes for the receipt message type
117
+	 *
118
+	 * @since   4.5.0
119
+	 *
120
+	 * @return  void
121
+	 */
122
+	protected function _set_valid_shortcodes()
123
+	{
124
+		$this->_valid_shortcodes['purchaser'] = array(
125
+			'attendee_list',
126
+			'attendee',
127
+			'datetime_list',
128
+			'datetime',
129
+			'event_list',
130
+			'event',
131
+			'event_meta',
132
+			'messenger',
133
+			'organization',
134
+			'primary_registration_list',
135
+			'primary_registration_details',
136
+			'ticket_list',
137
+			'ticket',
138
+			'transaction',
139
+			'venue',
140
+			'line_item_list',
141
+			'payment_list',
142
+			'line_item',
143
+			'payment'
144
+		);
145
+	}
146
+
147 147
 
148 148
 
149 149
 
150
-    protected function _purchaser_addressees()
151
-    {
152
-        return parent::_primary_attendee_addressees();
153
-    }
150
+	protected function _purchaser_addressees()
151
+	{
152
+		return parent::_primary_attendee_addressees();
153
+	}
154 154
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_To_Generate_From_Queue.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
      */
63 63
     protected function _get_subject($custom_subject = '')
64 64
     {
65
-        if (! empty($custom_subject)) {
65
+        if ( ! empty($custom_subject)) {
66 66
             return $custom_subject;
67 67
         }
68 68
         $this->queue->get_message_repository()->rewind();
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -13,90 +13,90 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * Will hold an EE_Messages_Queue object
18
-     * @type EE_Messages_Queue
19
-     */
20
-    public $queue = array();
16
+	/**
17
+	 * Will hold an EE_Messages_Queue object
18
+	 * @type EE_Messages_Queue
19
+	 */
20
+	public $queue = array();
21 21
 
22
-    /**
23
-     * @param string            $messenger_name  The messenger being used to send the message
24
-     * @param string            $message_type_name  The message type being used to grab variations etc.
25
-     * @param EE_Messages_Queue $queue
26
-     * @param string            $custom_subject  Used if a custom subject is desired for the generated aggregate EE_Message object
27
-     */
28
-    public function __construct($messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '')
29
-    {
30
-        $this->queue = $queue;
31
-        parent::__construct($messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle);
32
-        if ($this->valid()) {
33
-            $this->_message->set_content($this->_get_content());
34
-            $this->_message->set_subject($this->_get_subject($custom_subject));
35
-            $this->_message->set_GRP_ID($this->getGroupIdFromMessageRepo());
36
-        }
37
-    }
22
+	/**
23
+	 * @param string            $messenger_name  The messenger being used to send the message
24
+	 * @param string            $message_type_name  The message type being used to grab variations etc.
25
+	 * @param EE_Messages_Queue $queue
26
+	 * @param string            $custom_subject  Used if a custom subject is desired for the generated aggregate EE_Message object
27
+	 */
28
+	public function __construct($messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '')
29
+	{
30
+		$this->queue = $queue;
31
+		parent::__construct($messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle);
32
+		if ($this->valid()) {
33
+			$this->_message->set_content($this->_get_content());
34
+			$this->_message->set_subject($this->_get_subject($custom_subject));
35
+			$this->_message->set_GRP_ID($this->getGroupIdFromMessageRepo());
36
+		}
37
+	}
38 38
 
39 39
 
40 40
 
41
-    /**
42
-     * Uses the EE_Messages_Queue currently set on this object to generate the content
43
-     * for the single EE_Message aggregate object returned by get_EE_Message
44
-     * @return string;
45
-     */
46
-    protected function _get_content()
47
-    {
48
-        $content = '';
49
-        $this->queue->get_message_repository()->rewind();
50
-        while ($this->queue->get_message_repository()->valid()) {
51
-            $content .= $this->queue->get_message_repository()->current()->content();
52
-            $this->queue->get_message_repository()->next();
53
-        }
54
-        return $content;
55
-    }
41
+	/**
42
+	 * Uses the EE_Messages_Queue currently set on this object to generate the content
43
+	 * for the single EE_Message aggregate object returned by get_EE_Message
44
+	 * @return string;
45
+	 */
46
+	protected function _get_content()
47
+	{
48
+		$content = '';
49
+		$this->queue->get_message_repository()->rewind();
50
+		while ($this->queue->get_message_repository()->valid()) {
51
+			$content .= $this->queue->get_message_repository()->current()->content();
52
+			$this->queue->get_message_repository()->next();
53
+		}
54
+		return $content;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Return a subject string to use for `MSG_Subject` in the aggregate EE_Message object.
60
-     * @param string $custom_subject
61
-     *
62
-     * @return string
63
-     */
64
-    protected function _get_subject($custom_subject = '')
65
-    {
66
-        if (! empty($custom_subject)) {
67
-            return $custom_subject;
68
-        }
69
-        $this->queue->get_message_repository()->rewind();
70
-        $count_of_items = $this->queue->get_message_repository()->count();
58
+	/**
59
+	 * Return a subject string to use for `MSG_Subject` in the aggregate EE_Message object.
60
+	 * @param string $custom_subject
61
+	 *
62
+	 * @return string
63
+	 */
64
+	protected function _get_subject($custom_subject = '')
65
+	{
66
+		if (! empty($custom_subject)) {
67
+			return $custom_subject;
68
+		}
69
+		$this->queue->get_message_repository()->rewind();
70
+		$count_of_items = $this->queue->get_message_repository()->count();
71 71
 
72
-        // if $count of items in queue == 1, then let's just return the subject for that item.
73
-        if ($count_of_items === 1) {
74
-            return $this->queue->get_message_repository()->current()->subject();
75
-        }
76
-        // phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder
77
-        return sprintf(
78
-            _n(
79
-                'Showing Aggregate output for 1 result',
80
-                'Showing Aggregate output for %d items',
81
-                $count_of_items,
82
-                'event_espresso'
83
-            ),
84
-            $count_of_items
85
-        );
86
-        // phpcs:enable
87
-    }
72
+		// if $count of items in queue == 1, then let's just return the subject for that item.
73
+		if ($count_of_items === 1) {
74
+			return $this->queue->get_message_repository()->current()->subject();
75
+		}
76
+		// phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder
77
+		return sprintf(
78
+			_n(
79
+				'Showing Aggregate output for 1 result',
80
+				'Showing Aggregate output for %d items',
81
+				$count_of_items,
82
+				'event_espresso'
83
+			),
84
+			$count_of_items
85
+		);
86
+		// phpcs:enable
87
+	}
88 88
 
89 89
 
90
-    /**
91
-     * Uses the EE_Messages_Queue currently set on this object to set the GRP_ID
92
-     * for the single EE_Message aggregate object returned by get_EE_Message
93
-     * @return int;
94
-     */
95
-    protected function getGroupIdFromMessageRepo()
96
-    {
97
-        $this->queue->get_message_repository()->rewind();
98
-        if ($this->queue->get_message_repository()->valid()) {
99
-            return $this->queue->get_message_repository()->current()->GRP_ID();
100
-        }
101
-    }
90
+	/**
91
+	 * Uses the EE_Messages_Queue currently set on this object to set the GRP_ID
92
+	 * for the single EE_Message aggregate object returned by get_EE_Message
93
+	 * @return int;
94
+	 */
95
+	protected function getGroupIdFromMessageRepo()
96
+	{
97
+		$this->queue->get_message_repository()->rewind();
98
+		if ($this->queue->get_message_repository()->valid()) {
99
+			return $this->queue->get_message_repository()->current()->GRP_ID();
100
+		}
101
+	}
102 102
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Line_Item_List_Shortcodes.lib.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     {
75 75
         $this->_validate_list_requirements();
76 76
 
77
-        if (! $this->_data['data'] instanceof EE_Ticket) {
77
+        if ( ! $this->_data['data'] instanceof EE_Ticket) {
78 78
             return '';
79 79
         }
80 80
 
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
         $addressee_obj = $this->_extra_data['data'];
86 86
 
87 87
         // made it here so we have an EE_Ticket, so we should have what we need.
88
-        $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item'])
89
-            ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null;
90
-        $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'])
91
-            ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array();
88
+        $ticket_line_item = isset($addressee_obj->tickets[$ticket->ID()]['line_item'])
89
+            ? $addressee_obj->tickets[$ticket->ID()]['line_item'] : null;
90
+        $sub_line_items = isset($addressee_obj->tickets[$ticket->ID()]['sub_line_items'])
91
+            ? $addressee_obj->tickets[$ticket->ID()]['sub_line_items'] : array();
92 92
 
93 93
         $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms']
94 94
             : $templates['ticket_line_item_pms'];
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 
120 120
         $this->_validate_list_requirements();
121 121
 
122
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
122
+        if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) {
123 123
             return '';
124 124
         }
125 125
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 
154 154
         $this->_validate_list_requirements();
155 155
 
156
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
156
+        if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) {
157 157
             return '';
158 158
         }
159 159
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     {
190 190
         $this->_validate_list_requirements();
191 191
 
192
-        if (! $this->_data['data'] instanceof EE_Line_Item) {
192
+        if ( ! $this->_data['data'] instanceof EE_Line_Item) {
193 193
             return '';
194 194
         }
195 195
 
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 
203 203
         $main_line_item_id = $main_line_item->ID();
204 204
 
205
-        $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children'])
206
-            ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array();
205
+        $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[$main_line_item_id]['children'])
206
+            ? $addressee_obj->line_items_with_children[$main_line_item_id]['children'] : array();
207 207
 
208 208
         $line_item_list = '';
209 209
 
Please login to merge, or discard this patch.
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -20,202 +20,202 @@
 block discarded – undo
20 20
 {
21 21
 
22 22
 
23
-    protected function _init_props()
24
-    {
25
-        $this->label = esc_html__('Line Item List Shortcodes', 'event_espresso');
26
-        $this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso');
27
-        $this->_shortcodes = array(
28
-            '[TICKET_LINE_ITEM_LIST]'         => esc_html__('Outputs a list of ticket line items.', 'event_espresso'),
29
-            '[TAX_LINE_ITEM_LIST]'            => esc_html__('Outputs a list of tax line items.', 'event_espresso'),
30
-            '[ADDITIONAL_LINE_ITEM_LIST]'     => esc_html__(
31
-                'Outputs a list of additional line items (other charges or discounts)',
32
-                'event_espresso'
33
-            ),
34
-            '[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'),
35
-        );
36
-    }
37
-
38
-
39
-    protected function _parser($shortcode)
40
-    {
41
-
42
-        switch ($shortcode) {
43
-            case '[TICKET_LINE_ITEM_LIST]':
44
-                return $this->_get_ticket_line_item_list();
45
-                break;
46
-
47
-            case '[TAX_LINE_ITEM_LIST]':
48
-                return $this->_get_tax_line_item_list();
49
-                break;
50
-
51
-            case '[PRICE_MODIFIER_LINE_ITEM_LIST]':
52
-                return $this->_get_price_mod_line_item_list();
53
-                break;
54
-
55
-            case '[ADDITIONAL_LINE_ITEM_LIST]':
56
-                return $this->_get_additional_line_item_list();
57
-                break;
58
-
59
-            default:
60
-                return '';
61
-                break;
62
-        }
63
-    }
64
-
65
-
66
-    /**
67
-     * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event.
68
-     *
69
-     * @since 4.5.0
70
-     *
71
-     * @return string parsed ticket line item list.
72
-     */
73
-    private function _get_ticket_line_item_list()
74
-    {
75
-        $this->_validate_list_requirements();
76
-
77
-        if (! $this->_data['data'] instanceof EE_Ticket) {
78
-            return '';
79
-        }
80
-
81
-        $valid_shortcodes = array('line_item', 'line_item_list', 'ticket');
82
-
83
-        $ticket = $this->_data['data'];
84
-        $templates = $this->_extra_data['template'];
85
-        $addressee_obj = $this->_extra_data['data'];
86
-
87
-        // made it here so we have an EE_Ticket, so we should have what we need.
88
-        $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item'])
89
-            ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null;
90
-        $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'])
91
-            ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array();
92
-
93
-        $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms']
94
-            : $templates['ticket_line_item_pms'];
95
-
96
-        if (empty($ticket_line_item) || empty($sub_line_items)) {
97
-            return '';
98
-        }
99
-
100
-        // now we just return the appropriate template parsed for each ticket.
101
-        return $this->_shortcode_helper->parse_line_item_list_template(
102
-            $template,
103
-            $ticket_line_item,
104
-            $valid_shortcodes,
105
-            $this->_extra_data
106
-        );
107
-    }
108
-
109
-
110
-    /**
111
-     * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction.
112
-     *
113
-     * @since 4.5.0
114
-     *
115
-     * @return string  parsed tax line item list.
116
-     */
117
-    private function _get_tax_line_item_list()
118
-    {
119
-
120
-        $this->_validate_list_requirements();
121
-
122
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
123
-            return '';
124
-        }
125
-
126
-        // made it here so we're good to go.
127
-        $valid_shortcodes = array('line_item');
128
-        $templates = $this->_data['template'];
129
-
130
-        $tax_line_items = $this->_data['data']->tax_line_items;
131
-        $line_item_list = '';
132
-        foreach ($tax_line_items as $line_item) {
133
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
134
-                $templates['tax_line_item_list'],
135
-                $line_item,
136
-                $valid_shortcodes,
137
-                $this->_extra_data
138
-            );
139
-        }
140
-
141
-        return $line_item_list;
142
-    }
143
-
144
-    /**
145
-     * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction.
146
-     *
147
-     * @since 4.5.0
148
-     *
149
-     * @return string  parsed other line item list.
150
-     */
151
-    private function _get_additional_line_item_list()
152
-    {
153
-
154
-        $this->_validate_list_requirements();
155
-
156
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
157
-            return '';
158
-        }
159
-
160
-        // made it here so we're good to go.
161
-        $valid_shortcodes = array('line_item');
162
-        $templates = $this->_data['template'];
163
-
164
-        $additional_line_items = $this->_data['data']->additional_line_items;
165
-        $line_item_list = '';
166
-        foreach ($additional_line_items as $line_item) {
167
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
168
-                $templates['additional_line_item_list'],
169
-                $line_item,
170
-                $valid_shortcodes,
171
-                $this->_extra_data
172
-            );
173
-        }
174
-
175
-
176
-        return $line_item_list;
177
-    }
178
-
179
-
180
-    /**
181
-     * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a
182
-     * parent ticket line item.
183
-     *
184
-     * @since 4.5.0
185
-     *
186
-     * @return string parsed price modifier line item list.
187
-     */
188
-    private function _get_price_mod_line_item_list()
189
-    {
190
-        $this->_validate_list_requirements();
191
-
192
-        if (! $this->_data['data'] instanceof EE_Line_Item) {
193
-            return '';
194
-        }
195
-
196
-        // made it here so we're good to go.
197
-        $main_line_item = $this->_data['data'];
198
-        $templates = $this->_extra_data['template'];
199
-        $addressee_obj = $this->_extra_data['data'];
200
-
201
-        $valid_shortcodes = array('line_item');
202
-
203
-        $main_line_item_id = $main_line_item->ID();
204
-
205
-        $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children'])
206
-            ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array();
207
-
208
-        $line_item_list = '';
209
-
210
-        foreach ($price_mod_line_items as $line_item) {
211
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
212
-                $templates['price_modifier_line_item_list'],
213
-                $line_item,
214
-                $valid_shortcodes,
215
-                $this->_extra_data
216
-            );
217
-        }
218
-
219
-        return $line_item_list;
220
-    }
23
+	protected function _init_props()
24
+	{
25
+		$this->label = esc_html__('Line Item List Shortcodes', 'event_espresso');
26
+		$this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso');
27
+		$this->_shortcodes = array(
28
+			'[TICKET_LINE_ITEM_LIST]'         => esc_html__('Outputs a list of ticket line items.', 'event_espresso'),
29
+			'[TAX_LINE_ITEM_LIST]'            => esc_html__('Outputs a list of tax line items.', 'event_espresso'),
30
+			'[ADDITIONAL_LINE_ITEM_LIST]'     => esc_html__(
31
+				'Outputs a list of additional line items (other charges or discounts)',
32
+				'event_espresso'
33
+			),
34
+			'[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'),
35
+		);
36
+	}
37
+
38
+
39
+	protected function _parser($shortcode)
40
+	{
41
+
42
+		switch ($shortcode) {
43
+			case '[TICKET_LINE_ITEM_LIST]':
44
+				return $this->_get_ticket_line_item_list();
45
+				break;
46
+
47
+			case '[TAX_LINE_ITEM_LIST]':
48
+				return $this->_get_tax_line_item_list();
49
+				break;
50
+
51
+			case '[PRICE_MODIFIER_LINE_ITEM_LIST]':
52
+				return $this->_get_price_mod_line_item_list();
53
+				break;
54
+
55
+			case '[ADDITIONAL_LINE_ITEM_LIST]':
56
+				return $this->_get_additional_line_item_list();
57
+				break;
58
+
59
+			default:
60
+				return '';
61
+				break;
62
+		}
63
+	}
64
+
65
+
66
+	/**
67
+	 * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event.
68
+	 *
69
+	 * @since 4.5.0
70
+	 *
71
+	 * @return string parsed ticket line item list.
72
+	 */
73
+	private function _get_ticket_line_item_list()
74
+	{
75
+		$this->_validate_list_requirements();
76
+
77
+		if (! $this->_data['data'] instanceof EE_Ticket) {
78
+			return '';
79
+		}
80
+
81
+		$valid_shortcodes = array('line_item', 'line_item_list', 'ticket');
82
+
83
+		$ticket = $this->_data['data'];
84
+		$templates = $this->_extra_data['template'];
85
+		$addressee_obj = $this->_extra_data['data'];
86
+
87
+		// made it here so we have an EE_Ticket, so we should have what we need.
88
+		$ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item'])
89
+			? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null;
90
+		$sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'])
91
+			? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array();
92
+
93
+		$template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms']
94
+			: $templates['ticket_line_item_pms'];
95
+
96
+		if (empty($ticket_line_item) || empty($sub_line_items)) {
97
+			return '';
98
+		}
99
+
100
+		// now we just return the appropriate template parsed for each ticket.
101
+		return $this->_shortcode_helper->parse_line_item_list_template(
102
+			$template,
103
+			$ticket_line_item,
104
+			$valid_shortcodes,
105
+			$this->_extra_data
106
+		);
107
+	}
108
+
109
+
110
+	/**
111
+	 * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction.
112
+	 *
113
+	 * @since 4.5.0
114
+	 *
115
+	 * @return string  parsed tax line item list.
116
+	 */
117
+	private function _get_tax_line_item_list()
118
+	{
119
+
120
+		$this->_validate_list_requirements();
121
+
122
+		if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
123
+			return '';
124
+		}
125
+
126
+		// made it here so we're good to go.
127
+		$valid_shortcodes = array('line_item');
128
+		$templates = $this->_data['template'];
129
+
130
+		$tax_line_items = $this->_data['data']->tax_line_items;
131
+		$line_item_list = '';
132
+		foreach ($tax_line_items as $line_item) {
133
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
134
+				$templates['tax_line_item_list'],
135
+				$line_item,
136
+				$valid_shortcodes,
137
+				$this->_extra_data
138
+			);
139
+		}
140
+
141
+		return $line_item_list;
142
+	}
143
+
144
+	/**
145
+	 * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction.
146
+	 *
147
+	 * @since 4.5.0
148
+	 *
149
+	 * @return string  parsed other line item list.
150
+	 */
151
+	private function _get_additional_line_item_list()
152
+	{
153
+
154
+		$this->_validate_list_requirements();
155
+
156
+		if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
157
+			return '';
158
+		}
159
+
160
+		// made it here so we're good to go.
161
+		$valid_shortcodes = array('line_item');
162
+		$templates = $this->_data['template'];
163
+
164
+		$additional_line_items = $this->_data['data']->additional_line_items;
165
+		$line_item_list = '';
166
+		foreach ($additional_line_items as $line_item) {
167
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
168
+				$templates['additional_line_item_list'],
169
+				$line_item,
170
+				$valid_shortcodes,
171
+				$this->_extra_data
172
+			);
173
+		}
174
+
175
+
176
+		return $line_item_list;
177
+	}
178
+
179
+
180
+	/**
181
+	 * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a
182
+	 * parent ticket line item.
183
+	 *
184
+	 * @since 4.5.0
185
+	 *
186
+	 * @return string parsed price modifier line item list.
187
+	 */
188
+	private function _get_price_mod_line_item_list()
189
+	{
190
+		$this->_validate_list_requirements();
191
+
192
+		if (! $this->_data['data'] instanceof EE_Line_Item) {
193
+			return '';
194
+		}
195
+
196
+		// made it here so we're good to go.
197
+		$main_line_item = $this->_data['data'];
198
+		$templates = $this->_extra_data['template'];
199
+		$addressee_obj = $this->_extra_data['data'];
200
+
201
+		$valid_shortcodes = array('line_item');
202
+
203
+		$main_line_item_id = $main_line_item->ID();
204
+
205
+		$price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children'])
206
+			? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array();
207
+
208
+		$line_item_list = '';
209
+
210
+		foreach ($price_mod_line_items as $line_item) {
211
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
212
+				$templates['price_modifier_line_item_list'],
213
+				$line_item,
214
+				$valid_shortcodes,
215
+				$this->_extra_data
216
+			);
217
+		}
218
+
219
+		return $line_item_list;
220
+	}
221 221
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Line_Item_Shortcodes.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     protected function _parser($shortcode)
43 43
     {
44 44
         // ensure that the incoming object IS a line item.  If it isn't then bail early.
45
-        if (! $this->_data instanceof EE_Line_Item) {
45
+        if ( ! $this->_data instanceof EE_Line_Item) {
46 46
             return '';
47 47
         }
48 48
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
                 break;
63 63
 
64 64
             case '[LINE_ITEM_AMOUNT]':
65
-                return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code();
65
+                return $line_item->is_percent() ? $line_item->percent().'%' : $line_item->unit_price_no_code();
66 66
                 break;
67 67
 
68 68
             case '[LINE_ITEM_TOTAL]':
Please login to merge, or discard this patch.
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -18,65 +18,65 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    protected function _init_props()
22
-    {
23
-        $this->label = esc_html__('Line Item Shortcodes', 'event_espresso');
24
-        $this->description = esc_html__('All shortcodes specific to line items', 'event_espresso');
25
-        $this->_shortcodes = array(
26
-            '[LINE_ITEM_NAME]' => esc_html__('Outputs the line item name.', 'event_espresso'),
27
-            '[LINE_ITEM_DESCRIPTION]' => esc_html__('Outputs a the description for the line item.', 'event_espresso'),
28
-            '[LINE_ITEM_QUANTITY]' => esc_html__('Outputs the quantity for this line item.', 'event_espresso'),
29
-            '[LINE_ITEM_AMOUNT]' => esc_html__(
30
-                'This will either output the unit price for a line item if its not a percent, or the percent of the line item (if it is percent).',
31
-                'event_espresso'
32
-            ),
33
-            '[LINE_ITEM_TOTAL]' => esc_html__('This outputs the line item total.', 'event_espresso'),
34
-            '[LINE_ITEM_TAXABLE_*]' => esc_html__(
35
-                'This attribute type shortcode allows users to indicate what to output if a line item is taxable or not.  One can use the key "symbol=" with the shortcode to indicate what they\'d like to represent a taxable line item.  So doing something like <code>[LINE_ITEM_TAXABLE_* symbol="*"]</code> means that when the line item is parsed, if it\'s taxable the "*" symbol will be returned.  The default symbol if no attribute is included is the "*" symbol.',
36
-                'event_espresso'
37
-            ),
38
-        );
39
-    }
21
+	protected function _init_props()
22
+	{
23
+		$this->label = esc_html__('Line Item Shortcodes', 'event_espresso');
24
+		$this->description = esc_html__('All shortcodes specific to line items', 'event_espresso');
25
+		$this->_shortcodes = array(
26
+			'[LINE_ITEM_NAME]' => esc_html__('Outputs the line item name.', 'event_espresso'),
27
+			'[LINE_ITEM_DESCRIPTION]' => esc_html__('Outputs a the description for the line item.', 'event_espresso'),
28
+			'[LINE_ITEM_QUANTITY]' => esc_html__('Outputs the quantity for this line item.', 'event_espresso'),
29
+			'[LINE_ITEM_AMOUNT]' => esc_html__(
30
+				'This will either output the unit price for a line item if its not a percent, or the percent of the line item (if it is percent).',
31
+				'event_espresso'
32
+			),
33
+			'[LINE_ITEM_TOTAL]' => esc_html__('This outputs the line item total.', 'event_espresso'),
34
+			'[LINE_ITEM_TAXABLE_*]' => esc_html__(
35
+				'This attribute type shortcode allows users to indicate what to output if a line item is taxable or not.  One can use the key "symbol=" with the shortcode to indicate what they\'d like to represent a taxable line item.  So doing something like <code>[LINE_ITEM_TAXABLE_* symbol="*"]</code> means that when the line item is parsed, if it\'s taxable the "*" symbol will be returned.  The default symbol if no attribute is included is the "*" symbol.',
36
+				'event_espresso'
37
+			),
38
+		);
39
+	}
40 40
 
41 41
 
42
-    protected function _parser($shortcode)
43
-    {
44
-        // ensure that the incoming object IS a line item.  If it isn't then bail early.
45
-        if (! $this->_data instanceof EE_Line_Item) {
46
-            return '';
47
-        }
42
+	protected function _parser($shortcode)
43
+	{
44
+		// ensure that the incoming object IS a line item.  If it isn't then bail early.
45
+		if (! $this->_data instanceof EE_Line_Item) {
46
+			return '';
47
+		}
48 48
 
49
-        $line_item = $this->_data;
49
+		$line_item = $this->_data;
50 50
 
51
-        switch ($shortcode) {
52
-            case '[LINE_ITEM_NAME]':
53
-                return $line_item->name();
54
-                break;
51
+		switch ($shortcode) {
52
+			case '[LINE_ITEM_NAME]':
53
+				return $line_item->name();
54
+				break;
55 55
 
56
-            case '[LINE_ITEM_DESCRIPTION]':
57
-                return $line_item->desc();
58
-                break;
56
+			case '[LINE_ITEM_DESCRIPTION]':
57
+				return $line_item->desc();
58
+				break;
59 59
 
60
-            case '[LINE_ITEM_QUANTITY]':
61
-                return $line_item->quantity();
62
-                break;
60
+			case '[LINE_ITEM_QUANTITY]':
61
+				return $line_item->quantity();
62
+				break;
63 63
 
64
-            case '[LINE_ITEM_AMOUNT]':
65
-                return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code();
66
-                break;
64
+			case '[LINE_ITEM_AMOUNT]':
65
+				return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code();
66
+				break;
67 67
 
68
-            case '[LINE_ITEM_TOTAL]':
69
-                return $line_item->total_no_code();
70
-                break;
71
-        }
68
+			case '[LINE_ITEM_TOTAL]':
69
+				return $line_item->total_no_code();
70
+				break;
71
+		}
72 72
 
73
-        if (strpos($shortcode, '[LINE_ITEM_TAXABLE_*') !== false) {
74
-            $attrs = $this->_get_shortcode_attrs($shortcode);
75
-            if ($line_item->is_taxable()) {
76
-                return ! empty($attrs['symbol']) ? $attrs['symbol'] : '*';
77
-            }
78
-        }
73
+		if (strpos($shortcode, '[LINE_ITEM_TAXABLE_*') !== false) {
74
+			$attrs = $this->_get_shortcode_attrs($shortcode);
75
+			if ($line_item->is_taxable()) {
76
+				return ! empty($attrs['symbol']) ? $attrs['symbol'] : '*';
77
+			}
78
+		}
79 79
 
80
-        return '';
81
-    }
80
+		return '';
81
+	}
82 82
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Datetime_Shortcodes.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     protected function _parser($shortcode)
55 55
     {
56 56
 
57
-        if (! $this->_data instanceof EE_Datetime) {
57
+        if ( ! $this->_data instanceof EE_Datetime) {
58 58
             return ''; // get out cause we can only parse with the datetime object.
59 59
         }
60 60
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
             $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url());
94 94
 
95
-            return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>';
95
+            return '<a class="ee-ical" href="'.$URL.'">'.$link_text.'</a>';
96 96
         }
97 97
 
98 98
         return '';
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -18,83 +18,83 @@
 block discarded – undo
18 18
 class EE_Datetime_Shortcodes extends EE_Shortcodes
19 19
 {
20 20
 
21
-    /**
22
-     * _init_props
23
-     *
24
-     * @access protected
25
-     * @return void
26
-     */
27
-    protected function _init_props()
28
-    {
29
-        $this->label = esc_html__('Datetime Shortcodes', 'event_espresso');
30
-        $this->description = esc_html__('All shortcodes specific to datetime related data', 'event_espresso');
31
-        $this->_shortcodes = array(
32
-            '[DATETIME_START]' => esc_html__('The start date and time.', 'event_espresso'),
33
-            '[DATETIME_END]' => esc_html__('The end date and time.', 'event_espresso'),
34
-            '[DATETIME_TIMEZONE]' => esc_html__('The timezone for the date and time', 'event_espresso'),
35
-            '[DATE_START]' => esc_html__('The datetime start date.', 'event_espresso'),
36
-            '[DATE_END]' => esc_html__('The datetime end date.', 'event_espresso'),
37
-            '[TIME_START]' => esc_html__('The datetime start time.', 'event_espresso'),
38
-            '[TIME_END]' => esc_html__('The datetime end time.', 'event_espresso'),
39
-            '[ICAL_LINK_*]' => esc_html__(
40
-                'The datetime iCal link. The optional "link_text" attribute can be used to set custom text within the link (Default is "Add to iCal Calendar").',
41
-                'event_espresso'
42
-            ),
43
-        );
44
-    }
21
+	/**
22
+	 * _init_props
23
+	 *
24
+	 * @access protected
25
+	 * @return void
26
+	 */
27
+	protected function _init_props()
28
+	{
29
+		$this->label = esc_html__('Datetime Shortcodes', 'event_espresso');
30
+		$this->description = esc_html__('All shortcodes specific to datetime related data', 'event_espresso');
31
+		$this->_shortcodes = array(
32
+			'[DATETIME_START]' => esc_html__('The start date and time.', 'event_espresso'),
33
+			'[DATETIME_END]' => esc_html__('The end date and time.', 'event_espresso'),
34
+			'[DATETIME_TIMEZONE]' => esc_html__('The timezone for the date and time', 'event_espresso'),
35
+			'[DATE_START]' => esc_html__('The datetime start date.', 'event_espresso'),
36
+			'[DATE_END]' => esc_html__('The datetime end date.', 'event_espresso'),
37
+			'[TIME_START]' => esc_html__('The datetime start time.', 'event_espresso'),
38
+			'[TIME_END]' => esc_html__('The datetime end time.', 'event_espresso'),
39
+			'[ICAL_LINK_*]' => esc_html__(
40
+				'The datetime iCal link. The optional "link_text" attribute can be used to set custom text within the link (Default is "Add to iCal Calendar").',
41
+				'event_espresso'
42
+			),
43
+		);
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * _parser
49
-     *
50
-     * @access protected
51
-     * @param string $shortcode
52
-     * @return string
53
-     */
54
-    protected function _parser($shortcode)
55
-    {
47
+	/**
48
+	 * _parser
49
+	 *
50
+	 * @access protected
51
+	 * @param string $shortcode
52
+	 * @return string
53
+	 */
54
+	protected function _parser($shortcode)
55
+	{
56 56
 
57
-        if (! $this->_data instanceof EE_Datetime) {
58
-            return ''; // get out cause we can only parse with the datetime object.
59
-        }
57
+		if (! $this->_data instanceof EE_Datetime) {
58
+			return ''; // get out cause we can only parse with the datetime object.
59
+		}
60 60
 
61
-        switch ($shortcode) {
62
-            case '[DATETIME_START]':
63
-                return $this->_data->get_i18n_datetime('DTT_EVT_start');
64
-                break;
61
+		switch ($shortcode) {
62
+			case '[DATETIME_START]':
63
+				return $this->_data->get_i18n_datetime('DTT_EVT_start');
64
+				break;
65 65
 
66
-            case '[DATETIME_END]':
67
-                return $this->_data->get_i18n_datetime('DTT_EVT_end');
68
-                break;
66
+			case '[DATETIME_END]':
67
+				return $this->_data->get_i18n_datetime('DTT_EVT_end');
68
+				break;
69 69
 
70
-            case '[DATETIME_TIMEZONE]':
71
-                return $this->_data->get_timezone();
72
-                break;
73
-            case '[DATE_START]':
74
-                return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('date_format'));
75
-                break;
76
-            case '[DATE_END]':
77
-                return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('date_format'));
78
-                break;
79
-            case '[TIME_START]':
80
-                return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('time_format'));
81
-                break;
82
-            case '[TIME_END]':
83
-                return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('time_format'));
84
-                break;
85
-        }
70
+			case '[DATETIME_TIMEZONE]':
71
+				return $this->_data->get_timezone();
72
+				break;
73
+			case '[DATE_START]':
74
+				return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('date_format'));
75
+				break;
76
+			case '[DATE_END]':
77
+				return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('date_format'));
78
+				break;
79
+			case '[TIME_START]':
80
+				return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('time_format'));
81
+				break;
82
+			case '[TIME_END]':
83
+				return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('time_format'));
84
+				break;
85
+		}
86 86
 
87
-        if (strpos($shortcode, '[ICAL_LINK_*') !== false) {
88
-            $attrs = $this->_get_shortcode_attrs($shortcode);
87
+		if (strpos($shortcode, '[ICAL_LINK_*') !== false) {
88
+			$attrs = $this->_get_shortcode_attrs($shortcode);
89 89
 
90
-            $link_text = empty($attrs['link_text']) ? esc_html__('Add to iCal Calendar', 'event_espresso')
91
-                : $attrs['link_text'];
90
+			$link_text = empty($attrs['link_text']) ? esc_html__('Add to iCal Calendar', 'event_espresso')
91
+				: $attrs['link_text'];
92 92
 
93
-            $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url());
93
+			$URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url());
94 94
 
95
-            return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>';
96
-        }
95
+			return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>';
96
+		}
97 97
 
98
-        return '';
99
-    }
98
+		return '';
99
+	}
100 100
 }
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
@@ -17,783 +17,783 @@
 block discarded – undo
17 17
 class EE_Transaction_Shortcodes extends EE_Shortcodes
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc
22
-     */
23
-    protected $_invoice_pm;
24
-
25
-
26
-    protected function _init_props()
27
-    {
28
-        $this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
29
-        $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
30
-        $this->_shortcodes = array(
31
-            '[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
32
-            '[PAYMENT_URL]'                     => esc_html__(
33
-                'This is a link to make a payment for the event',
34
-                'event_espresso'
35
-            ),
36
-            '[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__(
37
-                'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:',
38
-                'event_espresso'
39
-            )
40
-                                                   . '<ul>'
41
-                                                   . '<li>'
42
-                                                   . sprintf(
43
-                                                       esc_html__(
44
-                                                           '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
45
-                                                           'event_espresso'
46
-                                                       ),
47
-                                                       '<strong>',
48
-                                                       '</strong>'
49
-                                                   )
50
-                                                   . '</li>'
51
-                                                   . '<li>'
52
-                                                   . sprintf(
53
-                                                       esc_html__(
54
-                                                           '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)',
55
-                                                           'event_espresso'
56
-                                                       ),
57
-                                                       '<strong>',
58
-                                                       '</strong>'
59
-                                                   )
60
-                                                   . '</li>'
61
-                                                   . '<li>'
62
-                                                   . sprintf(
63
-                                                       esc_html__(
64
-                                                           '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
65
-                                                           'event_espresso'
66
-                                                       ),
67
-                                                       '<strong>',
68
-                                                       '</strong>'
69
-                                                   )
70
-                                                   . '</li>'
71
-                                                   . '</ul>',
72
-            '[PAYMENT_DUE_DATE_*]'              => esc_html__(
73
-                'This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:',
74
-                'event_espresso'
75
-            )
76
-                                                   . '<ul>'
77
-                                                   . '<li>'
78
-                                                   . sprintf(
79
-                                                       esc_html__(
80
-                                                           '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
81
-                                                           'event_espresso'
82
-                                                       ),
83
-                                                       '<strong>',
84
-                                                       '</strong>'
85
-                                                   )
86
-                                                   . '</li>'
87
-                                                   . '<li>'
88
-                                                   . sprintf(
89
-                                                       esc_html__(
90
-                                                           '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
91
-                                                           'event_espresso'
92
-                                                       ),
93
-                                                       '<strong>',
94
-                                                       '</strong>'
95
-                                                   )
96
-                                                   . '</li>'
97
-                                                   . '<li>'
98
-                                                   . sprintf(
99
-                                                       esc_html__(
100
-                                                           '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
101
-                                                           'event_espresso'
102
-                                                       ),
103
-                                                       '<strong>',
104
-                                                       '</strong>'
105
-                                                   )
106
-                                                   . '</li>',
107
-            '[INVOICE_LINK]'                    => esc_html__(
108
-                'This is a full html link to the invoice',
109
-                'event_espresso'
110
-            ),
111
-            '[INVOICE_URL]'                     => esc_html__(
112
-                'This is just the url for the invoice',
113
-                'event_espresso'
114
-            ),
115
-            '[INVOICE_LOGO_URL]'                => esc_html__(
116
-                'This returns the url for the logo uploaded via the invoice settings page.',
117
-                'event_espresso'
118
-            ),
119
-            '[INVOICE_LOGO]'                    => esc_html__(
120
-                'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.',
121
-                'event_espresso'
122
-            ),
123
-            '[INVOICE_PAYEE_NAME]'              => esc_html__(
124
-                'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.',
125
-                'event_espresso'
126
-            ),
127
-            '[INVOICE_PAYEE_ADDRESS]'           => esc_html__(
128
-                'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.',
129
-                'event_espresso'
130
-            ),
131
-            '[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__(
132
-                'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
133
-                'event_espresso'
134
-            ),
135
-            '[INVOICE_PAYEE_EMAIL]'             => esc_html__(
136
-                'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.',
137
-                'event_espresso'
138
-            ),
139
-            '[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(
140
-                esc_html__(
141
-                    'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.',
142
-                    'event_espresso'
143
-                ),
144
-                '<code>',
145
-                '</code>'
146
-            ),
147
-            '[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
148
-            '[TXN_STATUS]'                      => esc_html__(
149
-                'The transaction status for the transaction.',
150
-                'event_espresso'
151
-            ),
152
-            '[TXN_STATUS_ID]'                   => esc_html__(
153
-                'The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.',
154
-                'event_espresso'
155
-            ),
156
-            '[PAYMENT_STATUS]'                  => esc_html__(
157
-                'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
158
-                'event_espresso'
159
-            ),
160
-            '[PAYMENT_GATEWAY]'                 => esc_html__(
161
-                'The payment gateway used for the transaction',
162
-                'event_espresso'
163
-            ),
164
-            '[AMOUNT_PAID]'                     => esc_html__(
165
-                'The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.',
166
-                'event_espresso'
167
-            ),
168
-            '[LAST_AMOUNT_PAID]'                => esc_html__(
169
-                'This is the last payment or refund made on the transaction related to the message being generated.',
170
-                'event_espresso'
171
-            ),
172
-            '[TOTAL_AMOUNT_PAID]'               => esc_html__(
173
-                'This parses to the total amount paid over all payments',
174
-                'event_espresso'
175
-            ),
176
-            '[TOTAL_OWING]'                     => esc_html__(
177
-                'The total owing on a transaction with no attributes.',
178
-                'event_espresso'
179
-            ),
180
-            '[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
181
-            '[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
182
-            '[OWING_STATUS_MESSAGE_*]'          => esc_html__(
183
-                'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
184
-                'event_espresso'
185
-            )
186
-                                                   . '<p></ul>'
187
-                                                   . '<li><strong>still_owing</strong>:'
188
-                                                   . esc_html__(
189
-                                                       'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:',
190
-                                                       'event_espresso'
191
-                                                   )
192
-                                                   . sprintf(
193
-                                                       esc_html__('%sPlease make a payment.%s', 'event_espresso'),
194
-                                                       '<a href="[PAYMENT_URL]" class="noPrint">',
195
-                                                       '</a>'
196
-                                                   )
197
-                                                   . '</li>'
198
-                                                   .
199
-                                                   '<li><strong>none_owing</strong>:'
200
-                                                   . esc_html__(
201
-                                                       'If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.',
202
-                                                       'event_espresso'
203
-                                                   )
204
-                                                   . '</li></ul></p>',
205
-            '[TXN_TOTAL_TICKETS]'               => esc_html__(
206
-                'The total number of all tickets purchased in a transaction',
207
-                'event_espresso'
208
-            ),
209
-            '[TKT_QTY_PURCHASED]'               => sprintf(
210
-                esc_html__(
211
-                    'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s',
212
-                    'event_espresso'
213
-                ),
214
-                '<strong>',
215
-                '</strong>'
216
-            ),
217
-            '[TRANSACTION_ADMIN_URL]'           => esc_html__(
218
-                'The url to the admin page for this transaction',
219
-                'event_espresso'
220
-            ),
221
-            '[RECEIPT_URL]'                     => esc_html__(
222
-                'This parses to the generated url for retrieving the receipt for the transaction',
223
-                'event_espresso'
224
-            ),
225
-            '[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__(
226
-                'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.',
227
-                'event_espresso'
228
-            ),
229
-            '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(
230
-                esc_html__(
231
-                    'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.',
232
-                    'event_espresso'
233
-                ),
234
-                '<code>[INVOICE_RECEIPT_SWITCHER_URL]',
235
-                '</code>'
236
-            ),
237
-            '[LAST_PAYMENT_TRANSACTION_ID]'     => esc_html__(
238
-                'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.',
239
-                'event_espresso'
240
-            ),
241
-        );
242
-    }
243
-
244
-
245
-    /**
246
-     * @param  string $shortcode the shortcode to be parsed.
247
-     * @return string parsed shortcode
248
-     * @throws EE_Error
249
-     * @throws InvalidArgumentException
250
-     * @throws ReflectionException
251
-     * @throws InvalidDataTypeException
252
-     * @throws InvalidInterfaceException
253
-     */
254
-    protected function _parser($shortcode)
255
-    {
256
-        // attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the
257
-        // _extra_data for the transaction.
258
-        $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
259
-        $transaction = ! $transaction instanceof EE_Transaction
260
-                       && is_array($this->_extra_data)
261
-                       && isset($this->_extra_data['data'])
262
-                       && $this->_extra_data['data'] instanceof EE_Messages_Addressee
263
-            ? $this->_extra_data['data']->txn
264
-            : $transaction;
265
-        // payment
266
-        $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
267
-        $payment = ! $payment instanceof EE_Payment
268
-                   && is_array($this->_extra_data)
269
-                   && isset($this->_extra_data['data'])
270
-                   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
271
-            : $payment;
272
-        if (! $transaction instanceof EE_Transaction) {
273
-            return '';
274
-        }
275
-        switch ($shortcode) {
276
-            case '[TXN_ID]':
277
-                return $transaction->ID();
278
-                break;
279
-            case '[PAYMENT_URL]':
280
-                $payment_url = $transaction->payment_overview_url();
281
-                return empty($payment_url)
282
-                    ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
283
-                    : $payment_url;
284
-                break;
285
-            case '[INVOICE_LINK]':
286
-                $invoice_url = $transaction->invoice_url();
287
-                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
288
-                return sprintf(
289
-                    esc_html__('%sClick here for Invoice%s', 'event_espresso'),
290
-                    '<a href="' . $invoice_url . '">',
291
-                    '</a>'
292
-                );
293
-                break;
294
-            case '[INVOICE_URL]':
295
-                $invoice_url = $transaction->invoice_url();
296
-                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
297
-                break;
298
-            case '[INVOICE_LOGO_URL]':
299
-                return $this->_get_invoice_logo();
300
-                break;
301
-            case '[INVOICE_LOGO]':
302
-                return $this->_get_invoice_logo(true);
303
-                break;
304
-            case '[INVOICE_PAYEE_NAME]':
305
-                return $this->_get_invoice_payee_name();
306
-                break;
307
-            case '[INVOICE_PAYEE_ADDRESS]':
308
-                return $this->_get_invoice_payee_address();
309
-                break;
310
-            case '[INVOICE_PAYMENT_INSTRUCTIONS]':
311
-                return $this->_get_invoice_payment_instructions();
312
-                break;
313
-            case '[INVOICE_PAYEE_EMAIL]':
314
-                return $this->_get_invoice_payee_email();
315
-                break;
316
-            case '[TOTAL_COST]':
317
-                $total = $transaction->total();
318
-                return ! empty($total) ? EEH_Template::format_currency($total) : '';
319
-                break;
320
-            case '[PAYMENT_STATUS]':
321
-                $status = $transaction->pretty_status();
322
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
323
-                break; /**/
324
-            // note the [payment_status] shortcode is kind of misleading because payment status might be different
325
-            // from txn status so I'm adding this here for clarity.
326
-            case '[TXN_STATUS]':
327
-                $status = $transaction->pretty_status();
328
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
329
-                break;
330
-            case '[TXN_STATUS_ID]':
331
-                return $transaction->status_ID();
332
-                break;
333
-            case '[PAYMENT_GATEWAY]':
334
-                return $this->_get_payment_gateway($transaction);
335
-                break;
336
-            case '[AMOUNT_PAID]':
337
-                return $payment instanceof EE_Payment
338
-                    ? EEH_Template::format_currency($payment->amount())
339
-                    : EEH_Template::format_currency(0);
340
-                break;
341
-            case '[LAST_AMOUNT_PAID]':
342
-                $last_payment = $transaction->last_payment();
343
-                return $last_payment instanceof EE_Payment
344
-                    ? EEH_Template::format_currency($last_payment->amount())
345
-                    : EEH_Template::format_currency(0);
346
-            case '[TOTAL_AMOUNT_PAID]':
347
-                return EEH_Template::format_currency($transaction->paid());
348
-                break;
349
-            case '[TOTAL_OWING]':
350
-                $total_owing = $transaction->remaining();
351
-                return EEH_Template::format_currency($total_owing);
352
-                break;
353
-            case '[TXN_SUBTOTAL]':
354
-                return EEH_Template::format_currency($this->_get_subtotal());
355
-                break;
356
-            case '[TXN_TAX_SUBTOTAL]':
357
-                return EEH_Template::format_currency($this->_get_subtotal(true));
358
-                break;
359
-            case '[TKT_QTY_PURCHASED]':
360
-            case '[TXN_TOTAL_TICKETS]':
361
-                return $this->_data->total_ticket_count;
362
-                break;
363
-            case '[TRANSACTION_ADMIN_URL]':
364
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
365
-                $query_args = array(
366
-                    'page'   => 'espresso_transactions',
367
-                    'action' => 'view_transaction',
368
-                    'TXN_ID' => $transaction->ID(),
369
-                );
370
-                $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
371
-                return $url;
372
-                break;
373
-            case '[RECEIPT_URL]':
374
-                // get primary_registration
375
-                $reg = $this->_data->primary_reg_obj;
376
-                if (! $reg instanceof EE_Registration) {
377
-                    return '';
378
-                }
379
-                return $reg->receipt_url();
380
-                break;
381
-            case '[INVOICE_RECEIPT_SWITCHER_URL]':
382
-                return $this->_get_invoice_receipt_switcher(false);
383
-                break;
384
-            case '[INVOICE_RECEIPT_SWITCHER_BUTTON]':
385
-                return $this->_get_invoice_receipt_switcher();
386
-                break;
387
-            case '[LAST_PAYMENT_TRANSACTION_ID]':
388
-                $id = '';
389
-                $payment = $payment instanceof EE_Payment && $payment->ID() !== 0
390
-                    ? $payment
391
-                    : $transaction->last_payment();
392
-                if ($payment instanceof EE_Payment) {
393
-                    $id = $payment->txn_id_chq_nmbr();
394
-                }
395
-                return $id;
396
-                break;
397
-        }
398
-        if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
399
-            return $this->_get_custom_total_owing($shortcode);
400
-        }
401
-        if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
402
-            return $this->_get_invoice_payee_tax_number($shortcode);
403
-        }
404
-        if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
405
-            return $this->_get_payment_link_if_needed($shortcode);
406
-        }
407
-        if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
408
-            return $this->_get_payment_due_date($shortcode, $transaction);
409
-        }
410
-        return '';
411
-    }
412
-
413
-
414
-    /**
415
-     * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
416
-     *
417
-     * @since 4.5.0
418
-     * @param string $shortcode the incoming shortcode
419
-     * @return string parsed.
420
-     * @throws EE_Error
421
-     */
422
-    private function _get_custom_total_owing($shortcode)
423
-    {
424
-        $valid_shortcodes = array('transaction');
425
-        $attrs = $this->_get_shortcode_attrs($shortcode);
426
-        // ensure default is set.
427
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
428
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
429
-            ? $addressee->txn->remaining() : 0;
430
-        if ($total_owing > 0) {
431
-            $owing_content = ! empty($attrs['still_owing'])
432
-                ? $attrs['still_owing']
433
-                : sprintf(
434
-                    esc_html__('%sPlease make a payment.%s', 'event_espresso'),
435
-                    '<a href="[PAYMENT_URL]" class="noPrint">',
436
-                    '</a>'
437
-                );
438
-            $owing_content = $this->_shortcode_helper->parse_message_template(
439
-                $owing_content,
440
-                $addressee,
441
-                $valid_shortcodes,
442
-                $this->_message_type,
443
-                $this->_messenger,
444
-                $this->_message
445
-            );
446
-        } else {
447
-            $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
448
-        }
449
-        return $owing_content;
450
-    }
451
-
452
-
453
-    /**
454
-     * @param EE_Transaction $transaction
455
-     * @return string
456
-     * @throws EE_Error
457
-     */
458
-    private function _get_payment_gateway($transaction)
459
-    {
460
-        if ($transaction instanceof EE_Transaction) {
461
-            $pm = $transaction->payment_method();
462
-        } else {
463
-            $pm = null;
464
-        }
465
-        return $pm instanceof EE_Payment_Method ? $pm->name() : '';
466
-    }
467
-
468
-
469
-    /**
470
-     * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
471
-     * not present then the organization logo is used if its found (set on the organization settings page).
472
-     *
473
-     * @since 4.5.0
474
-     * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
475
-     * @return string url or html
476
-     * @throws EE_Error
477
-     * @throws InvalidArgumentException
478
-     * @throws InvalidDataTypeException
479
-     * @throws InvalidInterfaceException
480
-     */
481
-    private function _get_invoice_logo($img_tags = false)
482
-    {
483
-        $invoice_logo_url = '';
484
-        // try to get the invoice payment method's logo for this transaction image first
485
-        $pm = $this->_get_invoice_payment_method();
486
-        if ($pm instanceof EE_Payment_Method) {
487
-            $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
488
-        }
489
-        if (empty($invoice_logo_url)) {
490
-            $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
491
-        }
492
-        if (empty($invoice_logo_url)) {
493
-            return '';
494
-        }
495
-        if (! $img_tags) {
496
-            return $invoice_logo_url;
497
-        }
498
-        // image tags have been requested.
499
-        $image_size = getimagesize($invoice_logo_url);
500
-        // if image is wider than 300px, set the width to 300
501
-        if ($image_size[0] > 300) {
502
-            $image_width = 300;
503
-        } else {
504
-            $image_width = $image_size[0];
505
-        }
506
-        return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
507
-    }
508
-
509
-
510
-    /**
511
-     * Used to retrieve the appropriate content for the invoice payee name shortcode
512
-     *
513
-     * @since 4.5.0
514
-     * @return string
515
-     * @throws EE_Error
516
-     * @throws InvalidArgumentException
517
-     * @throws InvalidDataTypeException
518
-     * @throws InvalidInterfaceException
519
-     */
520
-    private function _get_invoice_payee_name()
521
-    {
522
-        $payee_name = null;
523
-        $pm = $this->_get_invoice_payment_method();
524
-        if ($pm instanceof EE_Payment_Method) {
525
-            $payee_name = $pm->get_extra_meta('pdf_payee_name', true);
526
-        }
527
-        $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
528
-        return $payee_name;
529
-    }
530
-
531
-
532
-    /**
533
-     * gets the default invoice payment method, but has a filter so it can be overridden
534
-     *
535
-     * @return EE_Payment_Method|null
536
-     * @throws EE_Error
537
-     * @throws InvalidArgumentException
538
-     * @throws InvalidDataTypeException
539
-     * @throws InvalidInterfaceException
540
-     */
541
-    private function _get_invoice_payment_method()
542
-    {
543
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
544
-            $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
545
-            $transaction = ! $transaction instanceof EE_Transaction
546
-                           && is_array($this->_extra_data)
547
-                           && isset($this->_extra_data['data'])
548
-                           && $this->_extra_data['data'] instanceof EE_Messages_Addressee
549
-                ? $this->_extra_data['data']->txn : $transaction;
550
-            // get the invoice payment method, and remember it for the next call too
551
-            $this->_invoice_pm = apply_filters(
552
-                'FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
553
-                EEM_Payment_Method::instance()->get_one_of_type('Invoice'),
554
-                $transaction
555
-            );
556
-        }
557
-        return $this->_invoice_pm;
558
-    }
559
-
560
-
561
-    /**
562
-     * Used to retrieve the appropriate content for the invoice payee email shortcode
563
-     *
564
-     * @since 4.5.0
565
-     * @return string
566
-     * @throws EE_Error
567
-     * @throws InvalidArgumentException
568
-     * @throws InvalidDataTypeException
569
-     * @throws InvalidInterfaceException
570
-     */
571
-    private function _get_invoice_payee_email()
572
-    {
573
-        $payee_email = null;
574
-        $pm = $this->_get_invoice_payment_method();
575
-        if ($pm instanceof EE_Payment_Method) {
576
-            $payee_email = $pm->get_extra_meta('pdf_payee_email', true);
577
-        }
578
-        $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
579
-            : $payee_email;
580
-        return $payee_email;
581
-    }
582
-
583
-
584
-    /**
585
-     * Used to retrieve the appropriate content for the invoice payee tax number shortcode
586
-     *
587
-     * @since 4.5.0
588
-     * @param string $shortcode
589
-     * @return string
590
-     * @throws EE_Error
591
-     * @throws InvalidArgumentException
592
-     * @throws InvalidDataTypeException
593
-     * @throws InvalidInterfaceException
594
-     */
595
-    private function _get_invoice_payee_tax_number($shortcode)
596
-    {
597
-        $payee_tax_number = null;
598
-        $pm = $this->_get_invoice_payment_method();
599
-        if ($pm instanceof EE_Payment_Method) {
600
-            $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
601
-        }
602
-        $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
603
-            : $payee_tax_number;
604
-        if (empty($payee_tax_number)) {
605
-            return '';
606
-        }
607
-        // any attributes?
608
-        $attrs = $this->_get_shortcode_attrs($shortcode);
609
-        // prefix?
610
-        $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
611
-        return $prefix . $payee_tax_number;
612
-    }
613
-
614
-
615
-    /**
616
-     * Used to retrieve the appropriate content for the invoice payee address shortcode.
617
-     *
618
-     * @since 4.5.0
619
-     * @return string
620
-     * @throws EE_Error
621
-     * @throws InvalidArgumentException
622
-     * @throws ReflectionException
623
-     * @throws InvalidDataTypeException
624
-     * @throws InvalidInterfaceException
625
-     */
626
-    private function _get_invoice_payee_address()
627
-    {
628
-        $payee_address = null;
629
-        $pm = $this->_get_invoice_payment_method();
630
-        if ($pm instanceof EE_Payment_Method) {
631
-            $payee_address = $pm->get_extra_meta('pdf_payee_address', true);
632
-        }
633
-        if (empty($payee_address)) {
634
-            $organization = EE_Registry::instance()->CFG->organization;
635
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
636
-            $payee_address .= ! empty($organization->address_2)
637
-                ? $organization->get_pretty('address_2') . '<br>'
638
-                : '';
639
-            $payee_address .= $organization->get_pretty('city') . '<br>';
640
-            // state
641
-            $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
642
-            $payee_address .= $state instanceof EE_State ? $state->name() : '';
643
-            // Country
644
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
645
-            $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
646
-        }
647
-        return $payee_address;
648
-    }
649
-
650
-
651
-    /**
652
-     * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
653
-     *
654
-     * @since 4.5.0
655
-     * @return string
656
-     * @throws EE_Error
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidDataTypeException
659
-     * @throws InvalidInterfaceException
660
-     */
661
-    private function _get_invoice_payment_instructions()
662
-    {
663
-        $instructions = null;
664
-        $pm = $this->_get_invoice_payment_method();
665
-        return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
666
-    }
667
-
668
-
669
-    /**
670
-     * get invoice/receipt switch button or url.
671
-     *
672
-     * @param bool $button true (default) returns the html for a button, false just returns the url.
673
-     * @return string
674
-     * @throws EE_Error
675
-     */
676
-    protected function _get_invoice_receipt_switcher($button = true)
677
-    {
678
-        $reg = $this->_data->primary_reg_obj;
679
-        $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
680
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
681
-            return '';
682
-        }
683
-        $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
684
-        $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
685
-            ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
686
-        $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
687
-        $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
688
-        if (! $button) {
689
-            return $switch_to_url;
690
-        }
691
-        if (! empty($switch_to_url)) {
692
-            return '
20
+	/**
21
+	 * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc
22
+	 */
23
+	protected $_invoice_pm;
24
+
25
+
26
+	protected function _init_props()
27
+	{
28
+		$this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
29
+		$this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
30
+		$this->_shortcodes = array(
31
+			'[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
32
+			'[PAYMENT_URL]'                     => esc_html__(
33
+				'This is a link to make a payment for the event',
34
+				'event_espresso'
35
+			),
36
+			'[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__(
37
+				'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:',
38
+				'event_espresso'
39
+			)
40
+												   . '<ul>'
41
+												   . '<li>'
42
+												   . sprintf(
43
+													   esc_html__(
44
+														   '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
45
+														   'event_espresso'
46
+													   ),
47
+													   '<strong>',
48
+													   '</strong>'
49
+												   )
50
+												   . '</li>'
51
+												   . '<li>'
52
+												   . sprintf(
53
+													   esc_html__(
54
+														   '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)',
55
+														   'event_espresso'
56
+													   ),
57
+													   '<strong>',
58
+													   '</strong>'
59
+												   )
60
+												   . '</li>'
61
+												   . '<li>'
62
+												   . sprintf(
63
+													   esc_html__(
64
+														   '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
65
+														   'event_espresso'
66
+													   ),
67
+													   '<strong>',
68
+													   '</strong>'
69
+												   )
70
+												   . '</li>'
71
+												   . '</ul>',
72
+			'[PAYMENT_DUE_DATE_*]'              => esc_html__(
73
+				'This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:',
74
+				'event_espresso'
75
+			)
76
+												   . '<ul>'
77
+												   . '<li>'
78
+												   . sprintf(
79
+													   esc_html__(
80
+														   '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
81
+														   'event_espresso'
82
+													   ),
83
+													   '<strong>',
84
+													   '</strong>'
85
+												   )
86
+												   . '</li>'
87
+												   . '<li>'
88
+												   . sprintf(
89
+													   esc_html__(
90
+														   '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
91
+														   'event_espresso'
92
+													   ),
93
+													   '<strong>',
94
+													   '</strong>'
95
+												   )
96
+												   . '</li>'
97
+												   . '<li>'
98
+												   . sprintf(
99
+													   esc_html__(
100
+														   '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
101
+														   'event_espresso'
102
+													   ),
103
+													   '<strong>',
104
+													   '</strong>'
105
+												   )
106
+												   . '</li>',
107
+			'[INVOICE_LINK]'                    => esc_html__(
108
+				'This is a full html link to the invoice',
109
+				'event_espresso'
110
+			),
111
+			'[INVOICE_URL]'                     => esc_html__(
112
+				'This is just the url for the invoice',
113
+				'event_espresso'
114
+			),
115
+			'[INVOICE_LOGO_URL]'                => esc_html__(
116
+				'This returns the url for the logo uploaded via the invoice settings page.',
117
+				'event_espresso'
118
+			),
119
+			'[INVOICE_LOGO]'                    => esc_html__(
120
+				'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.',
121
+				'event_espresso'
122
+			),
123
+			'[INVOICE_PAYEE_NAME]'              => esc_html__(
124
+				'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.',
125
+				'event_espresso'
126
+			),
127
+			'[INVOICE_PAYEE_ADDRESS]'           => esc_html__(
128
+				'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.',
129
+				'event_espresso'
130
+			),
131
+			'[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__(
132
+				'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
133
+				'event_espresso'
134
+			),
135
+			'[INVOICE_PAYEE_EMAIL]'             => esc_html__(
136
+				'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.',
137
+				'event_espresso'
138
+			),
139
+			'[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(
140
+				esc_html__(
141
+					'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.',
142
+					'event_espresso'
143
+				),
144
+				'<code>',
145
+				'</code>'
146
+			),
147
+			'[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
148
+			'[TXN_STATUS]'                      => esc_html__(
149
+				'The transaction status for the transaction.',
150
+				'event_espresso'
151
+			),
152
+			'[TXN_STATUS_ID]'                   => esc_html__(
153
+				'The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.',
154
+				'event_espresso'
155
+			),
156
+			'[PAYMENT_STATUS]'                  => esc_html__(
157
+				'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
158
+				'event_espresso'
159
+			),
160
+			'[PAYMENT_GATEWAY]'                 => esc_html__(
161
+				'The payment gateway used for the transaction',
162
+				'event_espresso'
163
+			),
164
+			'[AMOUNT_PAID]'                     => esc_html__(
165
+				'The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.',
166
+				'event_espresso'
167
+			),
168
+			'[LAST_AMOUNT_PAID]'                => esc_html__(
169
+				'This is the last payment or refund made on the transaction related to the message being generated.',
170
+				'event_espresso'
171
+			),
172
+			'[TOTAL_AMOUNT_PAID]'               => esc_html__(
173
+				'This parses to the total amount paid over all payments',
174
+				'event_espresso'
175
+			),
176
+			'[TOTAL_OWING]'                     => esc_html__(
177
+				'The total owing on a transaction with no attributes.',
178
+				'event_espresso'
179
+			),
180
+			'[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
181
+			'[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
182
+			'[OWING_STATUS_MESSAGE_*]'          => esc_html__(
183
+				'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
184
+				'event_espresso'
185
+			)
186
+												   . '<p></ul>'
187
+												   . '<li><strong>still_owing</strong>:'
188
+												   . esc_html__(
189
+													   'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:',
190
+													   'event_espresso'
191
+												   )
192
+												   . sprintf(
193
+													   esc_html__('%sPlease make a payment.%s', 'event_espresso'),
194
+													   '<a href="[PAYMENT_URL]" class="noPrint">',
195
+													   '</a>'
196
+												   )
197
+												   . '</li>'
198
+												   .
199
+												   '<li><strong>none_owing</strong>:'
200
+												   . esc_html__(
201
+													   'If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.',
202
+													   'event_espresso'
203
+												   )
204
+												   . '</li></ul></p>',
205
+			'[TXN_TOTAL_TICKETS]'               => esc_html__(
206
+				'The total number of all tickets purchased in a transaction',
207
+				'event_espresso'
208
+			),
209
+			'[TKT_QTY_PURCHASED]'               => sprintf(
210
+				esc_html__(
211
+					'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s',
212
+					'event_espresso'
213
+				),
214
+				'<strong>',
215
+				'</strong>'
216
+			),
217
+			'[TRANSACTION_ADMIN_URL]'           => esc_html__(
218
+				'The url to the admin page for this transaction',
219
+				'event_espresso'
220
+			),
221
+			'[RECEIPT_URL]'                     => esc_html__(
222
+				'This parses to the generated url for retrieving the receipt for the transaction',
223
+				'event_espresso'
224
+			),
225
+			'[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__(
226
+				'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.',
227
+				'event_espresso'
228
+			),
229
+			'[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(
230
+				esc_html__(
231
+					'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.',
232
+					'event_espresso'
233
+				),
234
+				'<code>[INVOICE_RECEIPT_SWITCHER_URL]',
235
+				'</code>'
236
+			),
237
+			'[LAST_PAYMENT_TRANSACTION_ID]'     => esc_html__(
238
+				'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.',
239
+				'event_espresso'
240
+			),
241
+		);
242
+	}
243
+
244
+
245
+	/**
246
+	 * @param  string $shortcode the shortcode to be parsed.
247
+	 * @return string parsed shortcode
248
+	 * @throws EE_Error
249
+	 * @throws InvalidArgumentException
250
+	 * @throws ReflectionException
251
+	 * @throws InvalidDataTypeException
252
+	 * @throws InvalidInterfaceException
253
+	 */
254
+	protected function _parser($shortcode)
255
+	{
256
+		// attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the
257
+		// _extra_data for the transaction.
258
+		$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
259
+		$transaction = ! $transaction instanceof EE_Transaction
260
+					   && is_array($this->_extra_data)
261
+					   && isset($this->_extra_data['data'])
262
+					   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
263
+			? $this->_extra_data['data']->txn
264
+			: $transaction;
265
+		// payment
266
+		$payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
267
+		$payment = ! $payment instanceof EE_Payment
268
+				   && is_array($this->_extra_data)
269
+				   && isset($this->_extra_data['data'])
270
+				   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
271
+			: $payment;
272
+		if (! $transaction instanceof EE_Transaction) {
273
+			return '';
274
+		}
275
+		switch ($shortcode) {
276
+			case '[TXN_ID]':
277
+				return $transaction->ID();
278
+				break;
279
+			case '[PAYMENT_URL]':
280
+				$payment_url = $transaction->payment_overview_url();
281
+				return empty($payment_url)
282
+					? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
283
+					: $payment_url;
284
+				break;
285
+			case '[INVOICE_LINK]':
286
+				$invoice_url = $transaction->invoice_url();
287
+				$invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
288
+				return sprintf(
289
+					esc_html__('%sClick here for Invoice%s', 'event_espresso'),
290
+					'<a href="' . $invoice_url . '">',
291
+					'</a>'
292
+				);
293
+				break;
294
+			case '[INVOICE_URL]':
295
+				$invoice_url = $transaction->invoice_url();
296
+				return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
297
+				break;
298
+			case '[INVOICE_LOGO_URL]':
299
+				return $this->_get_invoice_logo();
300
+				break;
301
+			case '[INVOICE_LOGO]':
302
+				return $this->_get_invoice_logo(true);
303
+				break;
304
+			case '[INVOICE_PAYEE_NAME]':
305
+				return $this->_get_invoice_payee_name();
306
+				break;
307
+			case '[INVOICE_PAYEE_ADDRESS]':
308
+				return $this->_get_invoice_payee_address();
309
+				break;
310
+			case '[INVOICE_PAYMENT_INSTRUCTIONS]':
311
+				return $this->_get_invoice_payment_instructions();
312
+				break;
313
+			case '[INVOICE_PAYEE_EMAIL]':
314
+				return $this->_get_invoice_payee_email();
315
+				break;
316
+			case '[TOTAL_COST]':
317
+				$total = $transaction->total();
318
+				return ! empty($total) ? EEH_Template::format_currency($total) : '';
319
+				break;
320
+			case '[PAYMENT_STATUS]':
321
+				$status = $transaction->pretty_status();
322
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
323
+				break; /**/
324
+			// note the [payment_status] shortcode is kind of misleading because payment status might be different
325
+			// from txn status so I'm adding this here for clarity.
326
+			case '[TXN_STATUS]':
327
+				$status = $transaction->pretty_status();
328
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
329
+				break;
330
+			case '[TXN_STATUS_ID]':
331
+				return $transaction->status_ID();
332
+				break;
333
+			case '[PAYMENT_GATEWAY]':
334
+				return $this->_get_payment_gateway($transaction);
335
+				break;
336
+			case '[AMOUNT_PAID]':
337
+				return $payment instanceof EE_Payment
338
+					? EEH_Template::format_currency($payment->amount())
339
+					: EEH_Template::format_currency(0);
340
+				break;
341
+			case '[LAST_AMOUNT_PAID]':
342
+				$last_payment = $transaction->last_payment();
343
+				return $last_payment instanceof EE_Payment
344
+					? EEH_Template::format_currency($last_payment->amount())
345
+					: EEH_Template::format_currency(0);
346
+			case '[TOTAL_AMOUNT_PAID]':
347
+				return EEH_Template::format_currency($transaction->paid());
348
+				break;
349
+			case '[TOTAL_OWING]':
350
+				$total_owing = $transaction->remaining();
351
+				return EEH_Template::format_currency($total_owing);
352
+				break;
353
+			case '[TXN_SUBTOTAL]':
354
+				return EEH_Template::format_currency($this->_get_subtotal());
355
+				break;
356
+			case '[TXN_TAX_SUBTOTAL]':
357
+				return EEH_Template::format_currency($this->_get_subtotal(true));
358
+				break;
359
+			case '[TKT_QTY_PURCHASED]':
360
+			case '[TXN_TOTAL_TICKETS]':
361
+				return $this->_data->total_ticket_count;
362
+				break;
363
+			case '[TRANSACTION_ADMIN_URL]':
364
+				require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
365
+				$query_args = array(
366
+					'page'   => 'espresso_transactions',
367
+					'action' => 'view_transaction',
368
+					'TXN_ID' => $transaction->ID(),
369
+				);
370
+				$url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
371
+				return $url;
372
+				break;
373
+			case '[RECEIPT_URL]':
374
+				// get primary_registration
375
+				$reg = $this->_data->primary_reg_obj;
376
+				if (! $reg instanceof EE_Registration) {
377
+					return '';
378
+				}
379
+				return $reg->receipt_url();
380
+				break;
381
+			case '[INVOICE_RECEIPT_SWITCHER_URL]':
382
+				return $this->_get_invoice_receipt_switcher(false);
383
+				break;
384
+			case '[INVOICE_RECEIPT_SWITCHER_BUTTON]':
385
+				return $this->_get_invoice_receipt_switcher();
386
+				break;
387
+			case '[LAST_PAYMENT_TRANSACTION_ID]':
388
+				$id = '';
389
+				$payment = $payment instanceof EE_Payment && $payment->ID() !== 0
390
+					? $payment
391
+					: $transaction->last_payment();
392
+				if ($payment instanceof EE_Payment) {
393
+					$id = $payment->txn_id_chq_nmbr();
394
+				}
395
+				return $id;
396
+				break;
397
+		}
398
+		if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
399
+			return $this->_get_custom_total_owing($shortcode);
400
+		}
401
+		if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
402
+			return $this->_get_invoice_payee_tax_number($shortcode);
403
+		}
404
+		if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
405
+			return $this->_get_payment_link_if_needed($shortcode);
406
+		}
407
+		if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
408
+			return $this->_get_payment_due_date($shortcode, $transaction);
409
+		}
410
+		return '';
411
+	}
412
+
413
+
414
+	/**
415
+	 * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
416
+	 *
417
+	 * @since 4.5.0
418
+	 * @param string $shortcode the incoming shortcode
419
+	 * @return string parsed.
420
+	 * @throws EE_Error
421
+	 */
422
+	private function _get_custom_total_owing($shortcode)
423
+	{
424
+		$valid_shortcodes = array('transaction');
425
+		$attrs = $this->_get_shortcode_attrs($shortcode);
426
+		// ensure default is set.
427
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
428
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
429
+			? $addressee->txn->remaining() : 0;
430
+		if ($total_owing > 0) {
431
+			$owing_content = ! empty($attrs['still_owing'])
432
+				? $attrs['still_owing']
433
+				: sprintf(
434
+					esc_html__('%sPlease make a payment.%s', 'event_espresso'),
435
+					'<a href="[PAYMENT_URL]" class="noPrint">',
436
+					'</a>'
437
+				);
438
+			$owing_content = $this->_shortcode_helper->parse_message_template(
439
+				$owing_content,
440
+				$addressee,
441
+				$valid_shortcodes,
442
+				$this->_message_type,
443
+				$this->_messenger,
444
+				$this->_message
445
+			);
446
+		} else {
447
+			$owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
448
+		}
449
+		return $owing_content;
450
+	}
451
+
452
+
453
+	/**
454
+	 * @param EE_Transaction $transaction
455
+	 * @return string
456
+	 * @throws EE_Error
457
+	 */
458
+	private function _get_payment_gateway($transaction)
459
+	{
460
+		if ($transaction instanceof EE_Transaction) {
461
+			$pm = $transaction->payment_method();
462
+		} else {
463
+			$pm = null;
464
+		}
465
+		return $pm instanceof EE_Payment_Method ? $pm->name() : '';
466
+	}
467
+
468
+
469
+	/**
470
+	 * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
471
+	 * not present then the organization logo is used if its found (set on the organization settings page).
472
+	 *
473
+	 * @since 4.5.0
474
+	 * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
475
+	 * @return string url or html
476
+	 * @throws EE_Error
477
+	 * @throws InvalidArgumentException
478
+	 * @throws InvalidDataTypeException
479
+	 * @throws InvalidInterfaceException
480
+	 */
481
+	private function _get_invoice_logo($img_tags = false)
482
+	{
483
+		$invoice_logo_url = '';
484
+		// try to get the invoice payment method's logo for this transaction image first
485
+		$pm = $this->_get_invoice_payment_method();
486
+		if ($pm instanceof EE_Payment_Method) {
487
+			$invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
488
+		}
489
+		if (empty($invoice_logo_url)) {
490
+			$invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
491
+		}
492
+		if (empty($invoice_logo_url)) {
493
+			return '';
494
+		}
495
+		if (! $img_tags) {
496
+			return $invoice_logo_url;
497
+		}
498
+		// image tags have been requested.
499
+		$image_size = getimagesize($invoice_logo_url);
500
+		// if image is wider than 300px, set the width to 300
501
+		if ($image_size[0] > 300) {
502
+			$image_width = 300;
503
+		} else {
504
+			$image_width = $image_size[0];
505
+		}
506
+		return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
507
+	}
508
+
509
+
510
+	/**
511
+	 * Used to retrieve the appropriate content for the invoice payee name shortcode
512
+	 *
513
+	 * @since 4.5.0
514
+	 * @return string
515
+	 * @throws EE_Error
516
+	 * @throws InvalidArgumentException
517
+	 * @throws InvalidDataTypeException
518
+	 * @throws InvalidInterfaceException
519
+	 */
520
+	private function _get_invoice_payee_name()
521
+	{
522
+		$payee_name = null;
523
+		$pm = $this->_get_invoice_payment_method();
524
+		if ($pm instanceof EE_Payment_Method) {
525
+			$payee_name = $pm->get_extra_meta('pdf_payee_name', true);
526
+		}
527
+		$payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
528
+		return $payee_name;
529
+	}
530
+
531
+
532
+	/**
533
+	 * gets the default invoice payment method, but has a filter so it can be overridden
534
+	 *
535
+	 * @return EE_Payment_Method|null
536
+	 * @throws EE_Error
537
+	 * @throws InvalidArgumentException
538
+	 * @throws InvalidDataTypeException
539
+	 * @throws InvalidInterfaceException
540
+	 */
541
+	private function _get_invoice_payment_method()
542
+	{
543
+		if (! $this->_invoice_pm instanceof EE_Payment_Method) {
544
+			$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
545
+			$transaction = ! $transaction instanceof EE_Transaction
546
+						   && is_array($this->_extra_data)
547
+						   && isset($this->_extra_data['data'])
548
+						   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
549
+				? $this->_extra_data['data']->txn : $transaction;
550
+			// get the invoice payment method, and remember it for the next call too
551
+			$this->_invoice_pm = apply_filters(
552
+				'FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
553
+				EEM_Payment_Method::instance()->get_one_of_type('Invoice'),
554
+				$transaction
555
+			);
556
+		}
557
+		return $this->_invoice_pm;
558
+	}
559
+
560
+
561
+	/**
562
+	 * Used to retrieve the appropriate content for the invoice payee email shortcode
563
+	 *
564
+	 * @since 4.5.0
565
+	 * @return string
566
+	 * @throws EE_Error
567
+	 * @throws InvalidArgumentException
568
+	 * @throws InvalidDataTypeException
569
+	 * @throws InvalidInterfaceException
570
+	 */
571
+	private function _get_invoice_payee_email()
572
+	{
573
+		$payee_email = null;
574
+		$pm = $this->_get_invoice_payment_method();
575
+		if ($pm instanceof EE_Payment_Method) {
576
+			$payee_email = $pm->get_extra_meta('pdf_payee_email', true);
577
+		}
578
+		$payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
579
+			: $payee_email;
580
+		return $payee_email;
581
+	}
582
+
583
+
584
+	/**
585
+	 * Used to retrieve the appropriate content for the invoice payee tax number shortcode
586
+	 *
587
+	 * @since 4.5.0
588
+	 * @param string $shortcode
589
+	 * @return string
590
+	 * @throws EE_Error
591
+	 * @throws InvalidArgumentException
592
+	 * @throws InvalidDataTypeException
593
+	 * @throws InvalidInterfaceException
594
+	 */
595
+	private function _get_invoice_payee_tax_number($shortcode)
596
+	{
597
+		$payee_tax_number = null;
598
+		$pm = $this->_get_invoice_payment_method();
599
+		if ($pm instanceof EE_Payment_Method) {
600
+			$payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
601
+		}
602
+		$payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
603
+			: $payee_tax_number;
604
+		if (empty($payee_tax_number)) {
605
+			return '';
606
+		}
607
+		// any attributes?
608
+		$attrs = $this->_get_shortcode_attrs($shortcode);
609
+		// prefix?
610
+		$prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
611
+		return $prefix . $payee_tax_number;
612
+	}
613
+
614
+
615
+	/**
616
+	 * Used to retrieve the appropriate content for the invoice payee address shortcode.
617
+	 *
618
+	 * @since 4.5.0
619
+	 * @return string
620
+	 * @throws EE_Error
621
+	 * @throws InvalidArgumentException
622
+	 * @throws ReflectionException
623
+	 * @throws InvalidDataTypeException
624
+	 * @throws InvalidInterfaceException
625
+	 */
626
+	private function _get_invoice_payee_address()
627
+	{
628
+		$payee_address = null;
629
+		$pm = $this->_get_invoice_payment_method();
630
+		if ($pm instanceof EE_Payment_Method) {
631
+			$payee_address = $pm->get_extra_meta('pdf_payee_address', true);
632
+		}
633
+		if (empty($payee_address)) {
634
+			$organization = EE_Registry::instance()->CFG->organization;
635
+			$payee_address = $organization->get_pretty('address_1') . '<br>';
636
+			$payee_address .= ! empty($organization->address_2)
637
+				? $organization->get_pretty('address_2') . '<br>'
638
+				: '';
639
+			$payee_address .= $organization->get_pretty('city') . '<br>';
640
+			// state
641
+			$state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
642
+			$payee_address .= $state instanceof EE_State ? $state->name() : '';
643
+			// Country
644
+			$payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
645
+			$payee_address .= ! empty($organization->zip) ? $organization->zip : '';
646
+		}
647
+		return $payee_address;
648
+	}
649
+
650
+
651
+	/**
652
+	 * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
653
+	 *
654
+	 * @since 4.5.0
655
+	 * @return string
656
+	 * @throws EE_Error
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidDataTypeException
659
+	 * @throws InvalidInterfaceException
660
+	 */
661
+	private function _get_invoice_payment_instructions()
662
+	{
663
+		$instructions = null;
664
+		$pm = $this->_get_invoice_payment_method();
665
+		return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
666
+	}
667
+
668
+
669
+	/**
670
+	 * get invoice/receipt switch button or url.
671
+	 *
672
+	 * @param bool $button true (default) returns the html for a button, false just returns the url.
673
+	 * @return string
674
+	 * @throws EE_Error
675
+	 */
676
+	protected function _get_invoice_receipt_switcher($button = true)
677
+	{
678
+		$reg = $this->_data->primary_reg_obj;
679
+		$message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
680
+		if (! $reg instanceof EE_Registration || empty($message_type)) {
681
+			return '';
682
+		}
683
+		$switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
684
+		$switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
685
+			? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
686
+		$switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
687
+		$switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
688
+		if (! $button) {
689
+			return $switch_to_url;
690
+		}
691
+		if (! empty($switch_to_url)) {
692
+			return '
693 693
 	<form method="post" action="' . $switch_to_url . '" >
694 694
 		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
695 695
 	</form>
696 696
 			';
697
-        }
698
-        return '';
699
-    }
700
-
701
-
702
-    /**
703
-     * This returns a subtotal.
704
-     *
705
-     * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
706
-     * @return int
707
-     * @throws EE_Error
708
-     */
709
-    private function _get_subtotal($tax = false)
710
-    {
711
-        $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
712
-        if (! $grand_total instanceof EE_Line_Item) {
713
-            return 0;
714
-        }
715
-        return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
716
-    }
717
-
718
-
719
-    /**
720
-     * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
721
-     *
722
-     * @since 4.7.0
723
-     * @param string $shortcode the incoming shortcode
724
-     * @return string parsed.
725
-     * @throws EE_Error
726
-     */
727
-    private function _get_payment_link_if_needed($shortcode)
728
-    {
729
-        $valid_shortcodes = array('transaction');
730
-        $attrs = $this->_get_shortcode_attrs($shortcode);
731
-        // ensure default is set.
732
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
733
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
734
-            ? $addressee->txn->remaining() : 0;
735
-        if ($total_owing > 0) {
736
-            $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
737
-            $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
738
-            $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
739
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
740
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
741
-            $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
742
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
743
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
744
-            // we need to re run this string through the parser to catch any shortcodes that are in it.
745
-            $owing_content = $this->_shortcode_helper->parse_message_template(
746
-                $content,
747
-                $addressee,
748
-                $valid_shortcodes,
749
-                $this->_message_type,
750
-                $this->_messenger,
751
-                $this->_message
752
-            );
753
-        } else {
754
-            return '';
755
-        }
756
-        return $owing_content;
757
-    }
758
-
759
-
760
-    /**
761
-     * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
762
-     *
763
-     * @since 4.8.28.rc.011
764
-     * @param string         $shortcode The shortcode being parsed.
765
-     * @param EE_Transaction $transaction
766
-     * @return string
767
-     * @throws EE_Error
768
-     */
769
-    protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
770
-    {
771
-        // if transaction is paid in full then we can just return an empty string
772
-        if ($transaction->remaining() === 0) {
773
-            return '';
774
-        }
775
-        $attrs = $this->_get_shortcode_attrs($shortcode);
776
-        $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
777
-        $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30;
778
-        $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
779
-            : esc_html__('Payment in full due by: ', 'event_espresso');
780
-        $transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
781
-        // setup date due:
782
-        try {
783
-            if ($transaction_created instanceof DateTime) {
784
-                $date_due = $transaction_created->add(
785
-                    new DateInterval('P' . $days_until_due . 'D')
786
-                )->format($format);
787
-            } else {
788
-                throw new Exception();
789
-            }
790
-        } catch (Exception $e) {
791
-            // format was likely invalid.
792
-            $date_due = esc_html__(
793
-                'Unable to calculate date due, likely the format string is invalid.',
794
-                'event_espresso'
795
-            );
796
-        }
797
-        return $prefix_text . $date_due;
798
-    }
697
+		}
698
+		return '';
699
+	}
700
+
701
+
702
+	/**
703
+	 * This returns a subtotal.
704
+	 *
705
+	 * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
706
+	 * @return int
707
+	 * @throws EE_Error
708
+	 */
709
+	private function _get_subtotal($tax = false)
710
+	{
711
+		$grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
712
+		if (! $grand_total instanceof EE_Line_Item) {
713
+			return 0;
714
+		}
715
+		return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
716
+	}
717
+
718
+
719
+	/**
720
+	 * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
721
+	 *
722
+	 * @since 4.7.0
723
+	 * @param string $shortcode the incoming shortcode
724
+	 * @return string parsed.
725
+	 * @throws EE_Error
726
+	 */
727
+	private function _get_payment_link_if_needed($shortcode)
728
+	{
729
+		$valid_shortcodes = array('transaction');
730
+		$attrs = $this->_get_shortcode_attrs($shortcode);
731
+		// ensure default is set.
732
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
733
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
734
+			? $addressee->txn->remaining() : 0;
735
+		if ($total_owing > 0) {
736
+			$class = isset($attrs['class']) ? $attrs['class'] : 'callout';
737
+			$custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
738
+			$container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
739
+			$opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
740
+			$opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
741
+			$opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
742
+			$closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
743
+			$content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
744
+			// we need to re run this string through the parser to catch any shortcodes that are in it.
745
+			$owing_content = $this->_shortcode_helper->parse_message_template(
746
+				$content,
747
+				$addressee,
748
+				$valid_shortcodes,
749
+				$this->_message_type,
750
+				$this->_messenger,
751
+				$this->_message
752
+			);
753
+		} else {
754
+			return '';
755
+		}
756
+		return $owing_content;
757
+	}
758
+
759
+
760
+	/**
761
+	 * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
762
+	 *
763
+	 * @since 4.8.28.rc.011
764
+	 * @param string         $shortcode The shortcode being parsed.
765
+	 * @param EE_Transaction $transaction
766
+	 * @return string
767
+	 * @throws EE_Error
768
+	 */
769
+	protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
770
+	{
771
+		// if transaction is paid in full then we can just return an empty string
772
+		if ($transaction->remaining() === 0) {
773
+			return '';
774
+		}
775
+		$attrs = $this->_get_shortcode_attrs($shortcode);
776
+		$format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
777
+		$days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30;
778
+		$prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
779
+			: esc_html__('Payment in full due by: ', 'event_espresso');
780
+		$transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
781
+		// setup date due:
782
+		try {
783
+			if ($transaction_created instanceof DateTime) {
784
+				$date_due = $transaction_created->add(
785
+					new DateInterval('P' . $days_until_due . 'D')
786
+				)->format($format);
787
+			} else {
788
+				throw new Exception();
789
+			}
790
+		} catch (Exception $e) {
791
+			// format was likely invalid.
792
+			$date_due = esc_html__(
793
+				'Unable to calculate date due, likely the format string is invalid.',
794
+				'event_espresso'
795
+			);
796
+		}
797
+		return $prefix_text . $date_due;
798
+	}
799 799
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
                    && isset($this->_extra_data['data'])
270 270
                    && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
271 271
             : $payment;
272
-        if (! $transaction instanceof EE_Transaction) {
272
+        if ( ! $transaction instanceof EE_Transaction) {
273 273
             return '';
274 274
         }
275 275
         switch ($shortcode) {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
                 $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
288 288
                 return sprintf(
289 289
                     esc_html__('%sClick here for Invoice%s', 'event_espresso'),
290
-                    '<a href="' . $invoice_url . '">',
290
+                    '<a href="'.$invoice_url.'">',
291 291
                     '</a>'
292 292
                 );
293 293
                 break;
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
                 return $this->_data->total_ticket_count;
362 362
                 break;
363 363
             case '[TRANSACTION_ADMIN_URL]':
364
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
364
+                require_once EE_CORE.'admin/EE_Admin_Page.core.php';
365 365
                 $query_args = array(
366 366
                     'page'   => 'espresso_transactions',
367 367
                     'action' => 'view_transaction',
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
             case '[RECEIPT_URL]':
374 374
                 // get primary_registration
375 375
                 $reg = $this->_data->primary_reg_obj;
376
-                if (! $reg instanceof EE_Registration) {
376
+                if ( ! $reg instanceof EE_Registration) {
377 377
                     return '';
378 378
                 }
379 379
                 return $reg->receipt_url();
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
         if (empty($invoice_logo_url)) {
493 493
             return '';
494 494
         }
495
-        if (! $img_tags) {
495
+        if ( ! $img_tags) {
496 496
             return $invoice_logo_url;
497 497
         }
498 498
         // image tags have been requested.
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
         } else {
504 504
             $image_width = $image_size[0];
505 505
         }
506
-        return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
506
+        return '<img class="logo screen" src="'.$invoice_logo_url.'" width="'.$image_width.'" alt="logo" />';
507 507
     }
508 508
 
509 509
 
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
      */
541 541
     private function _get_invoice_payment_method()
542 542
     {
543
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
543
+        if ( ! $this->_invoice_pm instanceof EE_Payment_Method) {
544 544
             $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
545 545
             $transaction = ! $transaction instanceof EE_Transaction
546 546
                            && is_array($this->_extra_data)
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
         $attrs = $this->_get_shortcode_attrs($shortcode);
609 609
         // prefix?
610 610
         $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
611
-        return $prefix . $payee_tax_number;
611
+        return $prefix.$payee_tax_number;
612 612
     }
613 613
 
614 614
 
@@ -632,16 +632,16 @@  discard block
 block discarded – undo
632 632
         }
633 633
         if (empty($payee_address)) {
634 634
             $organization = EE_Registry::instance()->CFG->organization;
635
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
635
+            $payee_address = $organization->get_pretty('address_1').'<br>';
636 636
             $payee_address .= ! empty($organization->address_2)
637
-                ? $organization->get_pretty('address_2') . '<br>'
637
+                ? $organization->get_pretty('address_2').'<br>'
638 638
                 : '';
639
-            $payee_address .= $organization->get_pretty('city') . '<br>';
639
+            $payee_address .= $organization->get_pretty('city').'<br>';
640 640
             // state
641 641
             $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
642 642
             $payee_address .= $state instanceof EE_State ? $state->name() : '';
643 643
             // Country
644
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
644
+            $payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : '';
645 645
             $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
646 646
         }
647 647
         return $payee_address;
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
     {
678 678
         $reg = $this->_data->primary_reg_obj;
679 679
         $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
680
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
680
+        if ( ! $reg instanceof EE_Registration || empty($message_type)) {
681 681
             return '';
682 682
         }
683 683
         $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
@@ -685,13 +685,13 @@  discard block
 block discarded – undo
685 685
             ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
686 686
         $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
687 687
         $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
688
-        if (! $button) {
688
+        if ( ! $button) {
689 689
             return $switch_to_url;
690 690
         }
691
-        if (! empty($switch_to_url)) {
691
+        if ( ! empty($switch_to_url)) {
692 692
             return '
693
-	<form method="post" action="' . $switch_to_url . '" >
694
-		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
693
+	<form method="post" action="' . $switch_to_url.'" >
694
+		<input class="print_button" type="submit" value="' . $switch_to_label.'" />
695 695
 	</form>
696 696
 			';
697 697
         }
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
     private function _get_subtotal($tax = false)
710 710
     {
711 711
         $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
712
-        if (! $grand_total instanceof EE_Line_Item) {
712
+        if ( ! $grand_total instanceof EE_Line_Item) {
713 713
             return 0;
714 714
         }
715 715
         return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
@@ -736,11 +736,11 @@  discard block
 block discarded – undo
736 736
             $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
737 737
             $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
738 738
             $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
739
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
740
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
739
+            $opening_tag = ! empty($container_tag) ? '<'.$container_tag : '';
740
+            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag;
741 741
             $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
742
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
743
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
742
+            $closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : '';
743
+            $content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag;
744 744
             // we need to re run this string through the parser to catch any shortcodes that are in it.
745 745
             $owing_content = $this->_shortcode_helper->parse_message_template(
746 746
                 $content,
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
         try {
783 783
             if ($transaction_created instanceof DateTime) {
784 784
                 $date_due = $transaction_created->add(
785
-                    new DateInterval('P' . $days_until_due . 'D')
785
+                    new DateInterval('P'.$days_until_due.'D')
786 786
                 )->format($format);
787 787
             } else {
788 788
                 throw new Exception();
@@ -794,6 +794,6 @@  discard block
 block discarded – undo
794 794
                 'event_espresso'
795 795
             );
796 796
         }
797
-        return $prefix_text . $date_due;
797
+        return $prefix_text.$date_due;
798 798
     }
799 799
 }
Please login to merge, or discard this patch.