Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
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
@@ -5,648 +5,648 @@
 block discarded – undo
5 5
  */
6 6
 class EE_Email_messenger extends EE_messenger
7 7
 {
8
-    /**
9
-     * To field for email
10
-     * @var string
11
-     */
12
-    protected $_to = '';
13
-
14
-
15
-    /**
16
-     * CC field for email.
17
-     * @var string
18
-     */
19
-    protected $_cc = '';
20
-
21
-    /**
22
-     * From field for email
23
-     * @var string
24
-     */
25
-    protected $_from = '';
26
-
27
-
28
-    /**
29
-     * Subject field for email
30
-     * @var string
31
-     */
32
-    protected $_subject = '';
33
-
34
-
35
-    /**
36
-     * Content field for email
37
-     * @var string
38
-     */
39
-    protected $_content = '';
40
-
41
-
42
-    /**
43
-     * constructor
44
-     *
45
-     * @access public
46
-     */
47
-    public function __construct()
48
-    {
49
-        // set name and description properties
50
-        $this->name                = 'email';
51
-        $this->description         = sprintf(
52
-            esc_html__(
53
-                'This messenger delivers messages via email using the built-in %s function included with WordPress',
54
-                'event_espresso'
55
-            ),
56
-            '<code>wp_mail</code>'
57
-        );
58
-        $this->label               = array(
59
-            'singular' => esc_html__('email', 'event_espresso'),
60
-            'plural'   => esc_html__('emails', 'event_espresso'),
61
-        );
62
-        $this->activate_on_install = true;
63
-
64
-        // we're using defaults so let's call parent constructor that will take care of setting up all the other
65
-        // properties
66
-        parent::__construct();
67
-    }
68
-
69
-
70
-    /**
71
-     * see abstract declaration in parent class for details.
72
-     */
73
-    protected function _set_admin_pages()
74
-    {
75
-        $this->admin_registered_pages = array(
76
-            'events_edit' => true,
77
-        );
78
-    }
79
-
80
-
81
-    /**
82
-     * see abstract declaration in parent class for details
83
-     */
84
-    protected function _set_valid_shortcodes()
85
-    {
86
-        // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
87
-        // message type.
88
-        $this->_valid_shortcodes = array(
89
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
90
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
-        );
93
-    }
94
-
95
-
96
-    /**
97
-     * see abstract declaration in parent class for details
98
-     *
99
-     * @access protected
100
-     * @return void
101
-     */
102
-    protected function _set_validator_config()
103
-    {
104
-        $valid_shortcodes = $this->get_valid_shortcodes();
105
-
106
-        $this->_validator_config = array(
107
-            'to'            => array(
108
-                'shortcodes' => $valid_shortcodes['to'],
109
-                'type'       => 'email',
110
-            ),
111
-            'cc' => array(
112
-                'shortcodes' => $valid_shortcodes['to'],
113
-                'type' => 'email',
114
-            ),
115
-            'from'          => array(
116
-                'shortcodes' => $valid_shortcodes['from'],
117
-                'type'       => 'email',
118
-            ),
119
-            'subject'       => array(
120
-                'shortcodes' => array(
121
-                    'organization',
122
-                    'primary_registration_details',
123
-                    'event_author',
124
-                    'primary_registration_details',
125
-                    'recipient_details',
126
-                ),
127
-            ),
128
-            'content'       => array(
129
-                'shortcodes' => array(
130
-                    'event_list',
131
-                    'attendee_list',
132
-                    'ticket_list',
133
-                    'organization',
134
-                    'primary_registration_details',
135
-                    'primary_registration_list',
136
-                    'event_author',
137
-                    'recipient_details',
138
-                    'recipient_list',
139
-                    'transaction',
140
-                    'messenger',
141
-                ),
142
-            ),
143
-            'attendee_list' => array(
144
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
145
-                'required'   => array('[ATTENDEE_LIST]'),
146
-            ),
147
-            'event_list'    => array(
148
-                'shortcodes' => array(
149
-                    'event',
150
-                    'attendee_list',
151
-                    'ticket_list',
152
-                    'venue',
153
-                    'datetime_list',
154
-                    'attendee',
155
-                    'primary_registration_details',
156
-                    'primary_registration_list',
157
-                    'event_author',
158
-                    'recipient_details',
159
-                    'recipient_list',
160
-                ),
161
-                'required'   => array('[EVENT_LIST]'),
162
-            ),
163
-            'ticket_list'   => array(
164
-                'shortcodes' => array(
165
-                    'event_list',
166
-                    'attendee_list',
167
-                    'ticket',
168
-                    'datetime_list',
169
-                    'primary_registration_details',
170
-                    'recipient_details',
171
-                ),
172
-                'required'   => array('[TICKET_LIST]'),
173
-            ),
174
-            'datetime_list' => array(
175
-                'shortcodes' => array('datetime'),
176
-                'required'   => array('[DATETIME_LIST]'),
177
-            ),
178
-        );
179
-    }
180
-
181
-
182
-    /**
183
-     * @see   parent EE_messenger class for docs
184
-     * @since 4.5.0
185
-     */
186
-    public function do_secondary_messenger_hooks($sending_messenger_name)
187
-    {
188
-        if ($sending_messenger_name === 'html') {
189
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
190
-        }
191
-    }
192
-
193
-
194
-    public function add_email_css(
195
-        $variation_path,
196
-        $messenger,
197
-        $message_type,
198
-        $type,
199
-        $variation,
200
-        $file_extension,
201
-        $url,
202
-        EE_Messages_Template_Pack $template_pack
203
-    ) {
204
-        // prevent recursion on this callback.
205
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
206
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
207
-
208
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
209
-        return $variation;
210
-    }
211
-
212
-
213
-    /**
214
-     * See parent for details
215
-     *
216
-     * @access protected
217
-     * @return void
218
-     */
219
-    protected function _set_test_settings_fields()
220
-    {
221
-        $this->_test_settings_fields = array(
222
-            'to'      => array(
223
-                'input'      => 'text',
224
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
225
-                'type'       => 'email',
226
-                'required'   => false,
227
-                'validation' => true,
228
-                'css_class'  => 'large-text',
229
-                'format'     => '%s',
230
-                'default'    => get_bloginfo('admin_email'),
231
-            ),
232
-            'subject' => array(
233
-                'input'      => 'hidden',
234
-                'label'      => '',
235
-                'type'       => 'string',
236
-                'required'   => false,
237
-                'validation' => false,
238
-                'format'     => '%s',
239
-                'value'      => sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
240
-                'default'    => '',
241
-                'css_class'  => '',
242
-            ),
243
-        );
244
-    }
245
-
246
-
247
-    /**
248
-     * _set_template_fields
249
-     * This sets up the fields that a messenger requires for the message to go out.
250
-     *
251
-     * @access  protected
252
-     * @return void
253
-     */
254
-    protected function _set_template_fields()
255
-    {
256
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for
257
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
258
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
259
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
260
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
261
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
262
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
263
-        // will not be displayed/parsed.
264
-        $this->_template_fields = array(
265
-            'to'      => array(
266
-                'input'      => 'text',
267
-                'label'      => esc_html_x(
268
-                    'To',
269
-                    'Label for the "To" field for email addresses',
270
-                    'event_espresso'
271
-                ),
272
-                'type'       => 'string',
273
-                'required'   => true,
274
-                'validation' => true,
275
-                'css_class'  => 'large-text',
276
-                'format'     => '%s',
277
-            ),
278
-            'cc'      => array(
279
-                'input'      => 'text',
280
-                'label'      => esc_html_x(
281
-                    'CC',
282
-                    'Label for the "Carbon Copy" field used for additional email addresses',
283
-                    'event_espresso'
284
-                ),
285
-                'type'       => 'string',
286
-                'required'   => false,
287
-                'validation' => true,
288
-                'css_class'  => 'large-text',
289
-                'format'     => '%s',
290
-            ),
291
-            'from'    => array(
292
-                'input'      => 'text',
293
-                'label'      => esc_html_x(
294
-                    'From',
295
-                    'Label for the "From" field for email addresses.',
296
-                    'event_espresso'
297
-                ),
298
-                'type'       => 'string',
299
-                'required'   => true,
300
-                'validation' => true,
301
-                'css_class'  => 'large-text',
302
-                'format'     => '%s',
303
-            ),
304
-            'subject' => array(
305
-                'input'      => 'text',
306
-                'label'      => esc_html_x(
307
-                    'Subject',
308
-                    'Label for the "Subject" field (short description of contents) for emails.',
309
-                    'event_espresso'
310
-                ),
311
-                'type'       => 'string',
312
-                'required'   => true,
313
-                'validation' => true,
314
-                'css_class'  => 'large-text',
315
-                'format'     => '%s',
316
-            ),
317
-            'content' => '',
318
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
319
-            'extra'   => array(
320
-                'content' => array(
321
-                    'main'          => array(
322
-                        'input'      => 'wp_editor',
323
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
324
-                        'type'       => 'string',
325
-                        'required'   => true,
326
-                        'validation' => true,
327
-                        'format'     => '%s',
328
-                        'rows'       => '15',
329
-                    ),
330
-                    'event_list'    => array(
331
-                        'input'               => 'wp_editor',
332
-                        'label'               => '[EVENT_LIST]',
333
-                        'type'                => 'string',
334
-                        'required'            => true,
335
-                        'validation'          => true,
336
-                        'format'              => '%s',
337
-                        'rows'                => '15',
338
-                        'shortcodes_required' => array('[EVENT_LIST]'),
339
-                    ),
340
-                    'attendee_list' => array(
341
-                        'input'               => 'textarea',
342
-                        'label'               => '[ATTENDEE_LIST]',
343
-                        'type'                => 'string',
344
-                        'required'            => true,
345
-                        'validation'          => true,
346
-                        'format'              => '%s',
347
-                        'css_class'           => 'large-text',
348
-                        'rows'                => '5',
349
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
350
-                    ),
351
-                    'ticket_list'   => array(
352
-                        'input'               => 'textarea',
353
-                        'label'               => '[TICKET_LIST]',
354
-                        'type'                => 'string',
355
-                        'required'            => true,
356
-                        'validation'          => true,
357
-                        'format'              => '%s',
358
-                        'css_class'           => 'large-text',
359
-                        'rows'                => '10',
360
-                        'shortcodes_required' => array('[TICKET_LIST]'),
361
-                    ),
362
-                    'datetime_list' => array(
363
-                        'input'               => 'textarea',
364
-                        'label'               => '[DATETIME_LIST]',
365
-                        'type'                => 'string',
366
-                        'required'            => true,
367
-                        'validation'          => true,
368
-                        'format'              => '%s',
369
-                        'css_class'           => 'large-text',
370
-                        'rows'                => '10',
371
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
372
-                    ),
373
-                ),
374
-            ),
375
-        );
376
-    }
377
-
378
-
379
-    /**
380
-     * See definition of this class in parent
381
-     */
382
-    protected function _set_default_message_types()
383
-    {
384
-        $this->_default_message_types = array(
385
-            'payment',
386
-            'payment_refund',
387
-            'registration',
388
-            'not_approved_registration',
389
-            'pending_approval',
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     * @see   definition of this class in parent
396
-     * @since 4.5.0
397
-     */
398
-    protected function _set_valid_message_types()
399
-    {
400
-        $this->_valid_message_types = array(
401
-            'payment',
402
-            'registration',
403
-            'not_approved_registration',
404
-            'declined_registration',
405
-            'cancelled_registration',
406
-            'pending_approval',
407
-            'registration_summary',
408
-            'payment_reminder',
409
-            'payment_declined',
410
-            'payment_refund',
411
-        );
412
-    }
413
-
414
-
415
-    /**
416
-     * setting up admin_settings_fields for messenger.
417
-     */
418
-    protected function _set_admin_settings_fields()
419
-    {
420
-    }
421
-
422
-    /**
423
-     * We just deliver the messages don't kill us!!
424
-     *
425
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
426
-     *              present.
427
-     * @throws EE_Error
428
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
429
-     */
430
-    protected function _send_message()
431
-    {
432
-        $success = wp_mail(
433
-            $this->_to,
434
-            // some old values for subject may be expecting HTML entities to be decoded in the subject
435
-            // and subjects aren't interpreted as HTML, so there should be no HTML in them
436
-            wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
437
-            $this->_body(),
438
-            $this->_headers()
439
-        );
440
-        if (! $success) {
441
-            EE_Error::add_error(
442
-                sprintf(
443
-                    esc_html__(
444
-                        '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',
445
-                        'event_espresso'
446
-                    ),
447
-                    $this->_to,
448
-                    $this->_from,
449
-                    '<br />'
450
-                ),
451
-                __FILE__,
452
-                __FUNCTION__,
453
-                __LINE__
454
-            );
455
-        }
456
-        return $success;
457
-    }
458
-
459
-
460
-    /**
461
-     * see parent for definition
462
-     *
463
-     * @return string html body of the message content and the related css.
464
-     * @throws EE_Error
465
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
466
-     */
467
-    protected function _preview()
468
-    {
469
-        return $this->_body(true);
470
-    }
471
-
472
-
473
-    /**
474
-     * Setup headers for email
475
-     *
476
-     * @access protected
477
-     * @return string formatted header for email
478
-     */
479
-    protected function _headers()
480
-    {
481
-        $this->_ensure_has_from_email_address();
482
-        $from    = $this->_from;
483
-        $headers = array(
484
-            'From:' . $from,
485
-            'Reply-To:' . $from,
486
-            'Content-Type:text/html; charset=utf-8',
487
-        );
488
-
489
-        /**
490
-         * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
491
-         * cover back compat where there may be users who have saved cc values in their db for the newsletter message
492
-         * type which they are no longer able to change.
493
-         */
494
-        if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
495
-            $headers[] = 'cc: ' . $this->_cc;
496
-        }
497
-
498
-        // but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
499
-        // header.
500
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
501
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
502
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
503
-    }
504
-
505
-
506
-    /**
507
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
508
-     * address for the from address to avoid problems with sending emails.
509
-     */
510
-    protected function _ensure_has_from_email_address()
511
-    {
512
-        if (empty($this->_from)) {
513
-            $this->_from = get_bloginfo('admin_email');
514
-        }
515
-    }
516
-
517
-
518
-    /**
519
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
520
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
521
-     * be empty
522
-     *
523
-     * @since 4.3.1
524
-     * @return array
525
-     */
526
-    private function _parse_from()
527
-    {
528
-        if (strpos($this->_from, '<') !== false) {
529
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
530
-            $from_name = str_replace('"', '', $from_name);
531
-            $from_name = trim($from_name);
532
-
533
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
534
-            $from_email = str_replace('>', '', $from_email);
535
-            $from_email = trim($from_email);
536
-        } elseif (trim($this->_from) !== '') {
537
-            $from_name  = '';
538
-            $from_email = trim($this->_from);
539
-        } else {
540
-            $from_name = $from_email = '';
541
-        }
542
-        return array($from_name, $from_email);
543
-    }
544
-
545
-
546
-    /**
547
-     * Callback for the wp_mail_from filter.
548
-     *
549
-     * @since 4.3.1
550
-     * @param string $from_email What the original from_email is.
551
-     * @return string
552
-     */
553
-    public function set_from_address($from_email)
554
-    {
555
-        $parsed_from = $this->_parse_from();
556
-        // includes fallback if the parsing failed.
557
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
558
-            ? $parsed_from[1]
559
-            : get_bloginfo('admin_email');
560
-        return $from_email;
561
-    }
562
-
563
-
564
-    /**
565
-     * Callback fro the wp_mail_from_name filter.
566
-     *
567
-     * @since 4.3.1
568
-     * @param string $from_name The original from_name.
569
-     * @return string
570
-     */
571
-    public function set_from_name($from_name)
572
-    {
573
-        $parsed_from = $this->_parse_from();
574
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
575
-            $from_name = $parsed_from[0];
576
-        }
577
-
578
-        // if from name is "WordPress" let's sub in the site name instead (more friendly!)
579
-        // but realize the default name is HTML entity-encoded
580
-        $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
581
-
582
-        return $from_name;
583
-    }
584
-
585
-
586
-    /**
587
-     * setup body for email
588
-     *
589
-     * @param bool $preview will determine whether this is preview template or not.
590
-     * @return string formatted body for email.
591
-     * @throws EE_Error
592
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
593
-     */
594
-    protected function _body($preview = false)
595
-    {
596
-        // setup template args!
597
-        $this->_template_args = array(
598
-            'subject'   => $this->_subject,
599
-            'from'      => $this->_from,
600
-            'main_body' => wpautop($this->_content),
601
-        );
602
-        $body                 = $this->_get_main_template($preview);
603
-
604
-        /**
605
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
606
-         *
607
-         * @type    bool $preview Indicates whether a preview is being generated or not.
608
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
609
-         */
610
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
611
-            // require CssToInlineStyles library and its dependencies via composer autoloader
612
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
613
-
614
-            // now if this isn't a preview, let's setup the body so it has inline styles
615
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
616
-                $style = file_get_contents(
617
-                    $this->get_variation(
618
-                        $this->_tmp_pack,
619
-                        $this->_incoming_message_type->name,
620
-                        false,
621
-                        'main',
622
-                        $this->_variation
623
-                    ),
624
-                    true
625
-                );
626
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
627
-                // for some reason the library has a bracket and new line at the beginning.  This takes care of that.
628
-                $body  = ltrim($CSS->convert(true), ">\n");
629
-                // see https://events.codebasehq.com/projects/event-espresso/tickets/8609
630
-                $body  = ltrim($body, "<?");
631
-            }
632
-        }
633
-        return $body;
634
-    }
635
-
636
-
637
-    /**
638
-     * This just returns any existing test settings that might be saved in the database
639
-     *
640
-     * @access public
641
-     * @return array
642
-     */
643
-    public function get_existing_test_settings()
644
-    {
645
-        $settings = parent::get_existing_test_settings();
646
-        // override subject if present because we always want it to be fresh.
647
-        if (is_array($settings) && ! empty($settings['subject'])) {
648
-            $settings['subject'] = sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
649
-        }
650
-        return $settings;
651
-    }
8
+	/**
9
+	 * To field for email
10
+	 * @var string
11
+	 */
12
+	protected $_to = '';
13
+
14
+
15
+	/**
16
+	 * CC field for email.
17
+	 * @var string
18
+	 */
19
+	protected $_cc = '';
20
+
21
+	/**
22
+	 * From field for email
23
+	 * @var string
24
+	 */
25
+	protected $_from = '';
26
+
27
+
28
+	/**
29
+	 * Subject field for email
30
+	 * @var string
31
+	 */
32
+	protected $_subject = '';
33
+
34
+
35
+	/**
36
+	 * Content field for email
37
+	 * @var string
38
+	 */
39
+	protected $_content = '';
40
+
41
+
42
+	/**
43
+	 * constructor
44
+	 *
45
+	 * @access public
46
+	 */
47
+	public function __construct()
48
+	{
49
+		// set name and description properties
50
+		$this->name                = 'email';
51
+		$this->description         = sprintf(
52
+			esc_html__(
53
+				'This messenger delivers messages via email using the built-in %s function included with WordPress',
54
+				'event_espresso'
55
+			),
56
+			'<code>wp_mail</code>'
57
+		);
58
+		$this->label               = array(
59
+			'singular' => esc_html__('email', 'event_espresso'),
60
+			'plural'   => esc_html__('emails', 'event_espresso'),
61
+		);
62
+		$this->activate_on_install = true;
63
+
64
+		// we're using defaults so let's call parent constructor that will take care of setting up all the other
65
+		// properties
66
+		parent::__construct();
67
+	}
68
+
69
+
70
+	/**
71
+	 * see abstract declaration in parent class for details.
72
+	 */
73
+	protected function _set_admin_pages()
74
+	{
75
+		$this->admin_registered_pages = array(
76
+			'events_edit' => true,
77
+		);
78
+	}
79
+
80
+
81
+	/**
82
+	 * see abstract declaration in parent class for details
83
+	 */
84
+	protected function _set_valid_shortcodes()
85
+	{
86
+		// remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
87
+		// message type.
88
+		$this->_valid_shortcodes = array(
89
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
90
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
+		);
93
+	}
94
+
95
+
96
+	/**
97
+	 * see abstract declaration in parent class for details
98
+	 *
99
+	 * @access protected
100
+	 * @return void
101
+	 */
102
+	protected function _set_validator_config()
103
+	{
104
+		$valid_shortcodes = $this->get_valid_shortcodes();
105
+
106
+		$this->_validator_config = array(
107
+			'to'            => array(
108
+				'shortcodes' => $valid_shortcodes['to'],
109
+				'type'       => 'email',
110
+			),
111
+			'cc' => array(
112
+				'shortcodes' => $valid_shortcodes['to'],
113
+				'type' => 'email',
114
+			),
115
+			'from'          => array(
116
+				'shortcodes' => $valid_shortcodes['from'],
117
+				'type'       => 'email',
118
+			),
119
+			'subject'       => array(
120
+				'shortcodes' => array(
121
+					'organization',
122
+					'primary_registration_details',
123
+					'event_author',
124
+					'primary_registration_details',
125
+					'recipient_details',
126
+				),
127
+			),
128
+			'content'       => array(
129
+				'shortcodes' => array(
130
+					'event_list',
131
+					'attendee_list',
132
+					'ticket_list',
133
+					'organization',
134
+					'primary_registration_details',
135
+					'primary_registration_list',
136
+					'event_author',
137
+					'recipient_details',
138
+					'recipient_list',
139
+					'transaction',
140
+					'messenger',
141
+				),
142
+			),
143
+			'attendee_list' => array(
144
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
145
+				'required'   => array('[ATTENDEE_LIST]'),
146
+			),
147
+			'event_list'    => array(
148
+				'shortcodes' => array(
149
+					'event',
150
+					'attendee_list',
151
+					'ticket_list',
152
+					'venue',
153
+					'datetime_list',
154
+					'attendee',
155
+					'primary_registration_details',
156
+					'primary_registration_list',
157
+					'event_author',
158
+					'recipient_details',
159
+					'recipient_list',
160
+				),
161
+				'required'   => array('[EVENT_LIST]'),
162
+			),
163
+			'ticket_list'   => array(
164
+				'shortcodes' => array(
165
+					'event_list',
166
+					'attendee_list',
167
+					'ticket',
168
+					'datetime_list',
169
+					'primary_registration_details',
170
+					'recipient_details',
171
+				),
172
+				'required'   => array('[TICKET_LIST]'),
173
+			),
174
+			'datetime_list' => array(
175
+				'shortcodes' => array('datetime'),
176
+				'required'   => array('[DATETIME_LIST]'),
177
+			),
178
+		);
179
+	}
180
+
181
+
182
+	/**
183
+	 * @see   parent EE_messenger class for docs
184
+	 * @since 4.5.0
185
+	 */
186
+	public function do_secondary_messenger_hooks($sending_messenger_name)
187
+	{
188
+		if ($sending_messenger_name === 'html') {
189
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
190
+		}
191
+	}
192
+
193
+
194
+	public function add_email_css(
195
+		$variation_path,
196
+		$messenger,
197
+		$message_type,
198
+		$type,
199
+		$variation,
200
+		$file_extension,
201
+		$url,
202
+		EE_Messages_Template_Pack $template_pack
203
+	) {
204
+		// prevent recursion on this callback.
205
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
206
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
207
+
208
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
209
+		return $variation;
210
+	}
211
+
212
+
213
+	/**
214
+	 * See parent for details
215
+	 *
216
+	 * @access protected
217
+	 * @return void
218
+	 */
219
+	protected function _set_test_settings_fields()
220
+	{
221
+		$this->_test_settings_fields = array(
222
+			'to'      => array(
223
+				'input'      => 'text',
224
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
225
+				'type'       => 'email',
226
+				'required'   => false,
227
+				'validation' => true,
228
+				'css_class'  => 'large-text',
229
+				'format'     => '%s',
230
+				'default'    => get_bloginfo('admin_email'),
231
+			),
232
+			'subject' => array(
233
+				'input'      => 'hidden',
234
+				'label'      => '',
235
+				'type'       => 'string',
236
+				'required'   => false,
237
+				'validation' => false,
238
+				'format'     => '%s',
239
+				'value'      => sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
240
+				'default'    => '',
241
+				'css_class'  => '',
242
+			),
243
+		);
244
+	}
245
+
246
+
247
+	/**
248
+	 * _set_template_fields
249
+	 * This sets up the fields that a messenger requires for the message to go out.
250
+	 *
251
+	 * @access  protected
252
+	 * @return void
253
+	 */
254
+	protected function _set_template_fields()
255
+	{
256
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for
257
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
258
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
259
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
260
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
261
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
262
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
263
+		// will not be displayed/parsed.
264
+		$this->_template_fields = array(
265
+			'to'      => array(
266
+				'input'      => 'text',
267
+				'label'      => esc_html_x(
268
+					'To',
269
+					'Label for the "To" field for email addresses',
270
+					'event_espresso'
271
+				),
272
+				'type'       => 'string',
273
+				'required'   => true,
274
+				'validation' => true,
275
+				'css_class'  => 'large-text',
276
+				'format'     => '%s',
277
+			),
278
+			'cc'      => array(
279
+				'input'      => 'text',
280
+				'label'      => esc_html_x(
281
+					'CC',
282
+					'Label for the "Carbon Copy" field used for additional email addresses',
283
+					'event_espresso'
284
+				),
285
+				'type'       => 'string',
286
+				'required'   => false,
287
+				'validation' => true,
288
+				'css_class'  => 'large-text',
289
+				'format'     => '%s',
290
+			),
291
+			'from'    => array(
292
+				'input'      => 'text',
293
+				'label'      => esc_html_x(
294
+					'From',
295
+					'Label for the "From" field for email addresses.',
296
+					'event_espresso'
297
+				),
298
+				'type'       => 'string',
299
+				'required'   => true,
300
+				'validation' => true,
301
+				'css_class'  => 'large-text',
302
+				'format'     => '%s',
303
+			),
304
+			'subject' => array(
305
+				'input'      => 'text',
306
+				'label'      => esc_html_x(
307
+					'Subject',
308
+					'Label for the "Subject" field (short description of contents) for emails.',
309
+					'event_espresso'
310
+				),
311
+				'type'       => 'string',
312
+				'required'   => true,
313
+				'validation' => true,
314
+				'css_class'  => 'large-text',
315
+				'format'     => '%s',
316
+			),
317
+			'content' => '',
318
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
319
+			'extra'   => array(
320
+				'content' => array(
321
+					'main'          => array(
322
+						'input'      => 'wp_editor',
323
+						'label'      => esc_html__('Main Content', 'event_espresso'),
324
+						'type'       => 'string',
325
+						'required'   => true,
326
+						'validation' => true,
327
+						'format'     => '%s',
328
+						'rows'       => '15',
329
+					),
330
+					'event_list'    => array(
331
+						'input'               => 'wp_editor',
332
+						'label'               => '[EVENT_LIST]',
333
+						'type'                => 'string',
334
+						'required'            => true,
335
+						'validation'          => true,
336
+						'format'              => '%s',
337
+						'rows'                => '15',
338
+						'shortcodes_required' => array('[EVENT_LIST]'),
339
+					),
340
+					'attendee_list' => array(
341
+						'input'               => 'textarea',
342
+						'label'               => '[ATTENDEE_LIST]',
343
+						'type'                => 'string',
344
+						'required'            => true,
345
+						'validation'          => true,
346
+						'format'              => '%s',
347
+						'css_class'           => 'large-text',
348
+						'rows'                => '5',
349
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
350
+					),
351
+					'ticket_list'   => array(
352
+						'input'               => 'textarea',
353
+						'label'               => '[TICKET_LIST]',
354
+						'type'                => 'string',
355
+						'required'            => true,
356
+						'validation'          => true,
357
+						'format'              => '%s',
358
+						'css_class'           => 'large-text',
359
+						'rows'                => '10',
360
+						'shortcodes_required' => array('[TICKET_LIST]'),
361
+					),
362
+					'datetime_list' => array(
363
+						'input'               => 'textarea',
364
+						'label'               => '[DATETIME_LIST]',
365
+						'type'                => 'string',
366
+						'required'            => true,
367
+						'validation'          => true,
368
+						'format'              => '%s',
369
+						'css_class'           => 'large-text',
370
+						'rows'                => '10',
371
+						'shortcodes_required' => array('[DATETIME_LIST]'),
372
+					),
373
+				),
374
+			),
375
+		);
376
+	}
377
+
378
+
379
+	/**
380
+	 * See definition of this class in parent
381
+	 */
382
+	protected function _set_default_message_types()
383
+	{
384
+		$this->_default_message_types = array(
385
+			'payment',
386
+			'payment_refund',
387
+			'registration',
388
+			'not_approved_registration',
389
+			'pending_approval',
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 * @see   definition of this class in parent
396
+	 * @since 4.5.0
397
+	 */
398
+	protected function _set_valid_message_types()
399
+	{
400
+		$this->_valid_message_types = array(
401
+			'payment',
402
+			'registration',
403
+			'not_approved_registration',
404
+			'declined_registration',
405
+			'cancelled_registration',
406
+			'pending_approval',
407
+			'registration_summary',
408
+			'payment_reminder',
409
+			'payment_declined',
410
+			'payment_refund',
411
+		);
412
+	}
413
+
414
+
415
+	/**
416
+	 * setting up admin_settings_fields for messenger.
417
+	 */
418
+	protected function _set_admin_settings_fields()
419
+	{
420
+	}
421
+
422
+	/**
423
+	 * We just deliver the messages don't kill us!!
424
+	 *
425
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
426
+	 *              present.
427
+	 * @throws EE_Error
428
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
429
+	 */
430
+	protected function _send_message()
431
+	{
432
+		$success = wp_mail(
433
+			$this->_to,
434
+			// some old values for subject may be expecting HTML entities to be decoded in the subject
435
+			// and subjects aren't interpreted as HTML, so there should be no HTML in them
436
+			wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
437
+			$this->_body(),
438
+			$this->_headers()
439
+		);
440
+		if (! $success) {
441
+			EE_Error::add_error(
442
+				sprintf(
443
+					esc_html__(
444
+						'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',
445
+						'event_espresso'
446
+					),
447
+					$this->_to,
448
+					$this->_from,
449
+					'<br />'
450
+				),
451
+				__FILE__,
452
+				__FUNCTION__,
453
+				__LINE__
454
+			);
455
+		}
456
+		return $success;
457
+	}
458
+
459
+
460
+	/**
461
+	 * see parent for definition
462
+	 *
463
+	 * @return string html body of the message content and the related css.
464
+	 * @throws EE_Error
465
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
466
+	 */
467
+	protected function _preview()
468
+	{
469
+		return $this->_body(true);
470
+	}
471
+
472
+
473
+	/**
474
+	 * Setup headers for email
475
+	 *
476
+	 * @access protected
477
+	 * @return string formatted header for email
478
+	 */
479
+	protected function _headers()
480
+	{
481
+		$this->_ensure_has_from_email_address();
482
+		$from    = $this->_from;
483
+		$headers = array(
484
+			'From:' . $from,
485
+			'Reply-To:' . $from,
486
+			'Content-Type:text/html; charset=utf-8',
487
+		);
488
+
489
+		/**
490
+		 * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
491
+		 * cover back compat where there may be users who have saved cc values in their db for the newsletter message
492
+		 * type which they are no longer able to change.
493
+		 */
494
+		if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
495
+			$headers[] = 'cc: ' . $this->_cc;
496
+		}
497
+
498
+		// but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
499
+		// header.
500
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
501
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
502
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
503
+	}
504
+
505
+
506
+	/**
507
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
508
+	 * address for the from address to avoid problems with sending emails.
509
+	 */
510
+	protected function _ensure_has_from_email_address()
511
+	{
512
+		if (empty($this->_from)) {
513
+			$this->_from = get_bloginfo('admin_email');
514
+		}
515
+	}
516
+
517
+
518
+	/**
519
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
520
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
521
+	 * be empty
522
+	 *
523
+	 * @since 4.3.1
524
+	 * @return array
525
+	 */
526
+	private function _parse_from()
527
+	{
528
+		if (strpos($this->_from, '<') !== false) {
529
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
530
+			$from_name = str_replace('"', '', $from_name);
531
+			$from_name = trim($from_name);
532
+
533
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
534
+			$from_email = str_replace('>', '', $from_email);
535
+			$from_email = trim($from_email);
536
+		} elseif (trim($this->_from) !== '') {
537
+			$from_name  = '';
538
+			$from_email = trim($this->_from);
539
+		} else {
540
+			$from_name = $from_email = '';
541
+		}
542
+		return array($from_name, $from_email);
543
+	}
544
+
545
+
546
+	/**
547
+	 * Callback for the wp_mail_from filter.
548
+	 *
549
+	 * @since 4.3.1
550
+	 * @param string $from_email What the original from_email is.
551
+	 * @return string
552
+	 */
553
+	public function set_from_address($from_email)
554
+	{
555
+		$parsed_from = $this->_parse_from();
556
+		// includes fallback if the parsing failed.
557
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
558
+			? $parsed_from[1]
559
+			: get_bloginfo('admin_email');
560
+		return $from_email;
561
+	}
562
+
563
+
564
+	/**
565
+	 * Callback fro the wp_mail_from_name filter.
566
+	 *
567
+	 * @since 4.3.1
568
+	 * @param string $from_name The original from_name.
569
+	 * @return string
570
+	 */
571
+	public function set_from_name($from_name)
572
+	{
573
+		$parsed_from = $this->_parse_from();
574
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
575
+			$from_name = $parsed_from[0];
576
+		}
577
+
578
+		// if from name is "WordPress" let's sub in the site name instead (more friendly!)
579
+		// but realize the default name is HTML entity-encoded
580
+		$from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
581
+
582
+		return $from_name;
583
+	}
584
+
585
+
586
+	/**
587
+	 * setup body for email
588
+	 *
589
+	 * @param bool $preview will determine whether this is preview template or not.
590
+	 * @return string formatted body for email.
591
+	 * @throws EE_Error
592
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
593
+	 */
594
+	protected function _body($preview = false)
595
+	{
596
+		// setup template args!
597
+		$this->_template_args = array(
598
+			'subject'   => $this->_subject,
599
+			'from'      => $this->_from,
600
+			'main_body' => wpautop($this->_content),
601
+		);
602
+		$body                 = $this->_get_main_template($preview);
603
+
604
+		/**
605
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
606
+		 *
607
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
608
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
609
+		 */
610
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
611
+			// require CssToInlineStyles library and its dependencies via composer autoloader
612
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
613
+
614
+			// now if this isn't a preview, let's setup the body so it has inline styles
615
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
616
+				$style = file_get_contents(
617
+					$this->get_variation(
618
+						$this->_tmp_pack,
619
+						$this->_incoming_message_type->name,
620
+						false,
621
+						'main',
622
+						$this->_variation
623
+					),
624
+					true
625
+				);
626
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
627
+				// for some reason the library has a bracket and new line at the beginning.  This takes care of that.
628
+				$body  = ltrim($CSS->convert(true), ">\n");
629
+				// see https://events.codebasehq.com/projects/event-espresso/tickets/8609
630
+				$body  = ltrim($body, "<?");
631
+			}
632
+		}
633
+		return $body;
634
+	}
635
+
636
+
637
+	/**
638
+	 * This just returns any existing test settings that might be saved in the database
639
+	 *
640
+	 * @access public
641
+	 * @return array
642
+	 */
643
+	public function get_existing_test_settings()
644
+	{
645
+		$settings = parent::get_existing_test_settings();
646
+		// override subject if present because we always want it to be fresh.
647
+		if (is_array($settings) && ! empty($settings['subject'])) {
648
+			$settings['subject'] = sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
649
+		}
650
+		return $settings;
651
+	}
652 652
 }
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   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -9,69 +9,69 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Messages_Data_Handler_Collection extends EE_Object_Collection
11 11
 {
12
-    public function __construct()
13
-    {
14
-        $this->interface = 'EE_Messages_incoming_data';
15
-    }
12
+	public function __construct()
13
+	{
14
+		$this->interface = 'EE_Messages_incoming_data';
15
+	}
16 16
 
17 17
 
18
-    /**
19
-     * This adds the EE_Messages_incoming_data data handler object to the collection.
20
-     *
21
-     * @param EE_Messages_incoming_data  $data_handler
22
-     * @param mixed                      $data           Usually an array of data used in combination with the $data_handler
23
-     *                                                   classname to create an alternative index for retrieving data_handlers.
24
-     * @return bool
25
-     */
26
-    public function add($data_handler, $data = ''): bool
27
-    {
28
-        $data = $data === null ? array() : (array) $data;
29
-        $info['key'] = $this->get_key(get_class($data_handler), $data);
30
-        return parent::add($data_handler, $info);
31
-    }
18
+	/**
19
+	 * This adds the EE_Messages_incoming_data data handler object to the collection.
20
+	 *
21
+	 * @param EE_Messages_incoming_data  $data_handler
22
+	 * @param mixed                      $data           Usually an array of data used in combination with the $data_handler
23
+	 *                                                   classname to create an alternative index for retrieving data_handlers.
24
+	 * @return bool
25
+	 */
26
+	public function add($data_handler, $data = ''): bool
27
+	{
28
+		$data = $data === null ? array() : (array) $data;
29
+		$info['key'] = $this->get_key(get_class($data_handler), $data);
30
+		return parent::add($data_handler, $info);
31
+	}
32 32
 
33 33
 
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * This returns a key for retrieving data for the given references used to generate the key.
39
-     * Data handlers are cached to the repository along with a md5() generated key using known references.
40
-     * @param string    $classname      The classname of the datahandler being checked for.
41
-     * @param mixed     $data           The data that was used to instantiate the data_handler.
42
-     *
43
-     * @return  string      md5 hash using provided info.
44
-     */
45
-    public function get_key($classname, $data)
46
-    {
47
-        return md5($classname . serialize($data));
48
-    }
37
+	/**
38
+	 * This returns a key for retrieving data for the given references used to generate the key.
39
+	 * Data handlers are cached to the repository along with a md5() generated key using known references.
40
+	 * @param string    $classname      The classname of the datahandler being checked for.
41
+	 * @param mixed     $data           The data that was used to instantiate the data_handler.
42
+	 *
43
+	 * @return  string      md5 hash using provided info.
44
+	 */
45
+	public function get_key($classname, $data)
46
+	{
47
+		return md5($classname . serialize($data));
48
+	}
49 49
 
50 50
 
51 51
 
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * This returns a saved EE_Messages_incoming_data object if there is one in the repository indexed by a key matching
57
-     * the given string.
58
-     *
59
-     * @param string  $key  @see EE_Messages_Data_Handler_Collection::get_key() to setup a key formatted for searching.
60
-     *
61
-     * @return null|EE_Messages_incoming_data
62
-     */
63
-    public function get_by_key($key)
64
-    {
65
-        $this->rewind();
66
-        while ($this->valid()) {
67
-            $data = $this->getInfo();
68
-            if (isset($data['key']) && $data['key'] === $key) {
69
-                $handler = $this->current();
70
-                $this->rewind();
71
-                return $handler;
72
-            }
73
-            $this->next();
74
-        }
75
-        return null;
76
-    }
55
+	/**
56
+	 * This returns a saved EE_Messages_incoming_data object if there is one in the repository indexed by a key matching
57
+	 * the given string.
58
+	 *
59
+	 * @param string  $key  @see EE_Messages_Data_Handler_Collection::get_key() to setup a key formatted for searching.
60
+	 *
61
+	 * @return null|EE_Messages_incoming_data
62
+	 */
63
+	public function get_by_key($key)
64
+	{
65
+		$this->rewind();
66
+		while ($this->valid()) {
67
+			$data = $this->getInfo();
68
+			if (isset($data['key']) && $data['key'] === $key) {
69
+				$handler = $this->current();
70
+				$this->rewind();
71
+				return $handler;
72
+			}
73
+			$this->next();
74
+		}
75
+		return null;
76
+	}
77 77
 }
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
@@ -12,123 +12,123 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Invoice_message_type extends EE_message_type
14 14
 {
15
-    public function __construct()
16
-    {
17
-        $this->name = 'invoice';
18
-        $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');
19
-        $this->label = array(
20
-            'singular' => esc_html__('invoice', 'event_espresso'),
21
-            'plural' => esc_html__('invoices', 'event_espresso')
22
-        );
23
-        $this->_master_templates = array();
24
-        parent::__construct();
25
-    }
15
+	public function __construct()
16
+	{
17
+		$this->name = 'invoice';
18
+		$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');
19
+		$this->label = array(
20
+			'singular' => esc_html__('invoice', 'event_espresso'),
21
+			'plural' => esc_html__('invoices', 'event_espresso')
22
+		);
23
+		$this->_master_templates = array();
24
+		parent::__construct();
25
+	}
26 26
 
27 27
 
28 28
 
29
-    /**
30
-     * @see parent::get_priority() for documentation.
31
-     * @return int
32
-     */
33
-    public function get_priority()
34
-    {
35
-        return EEM_Message::priority_high;
36
-    }
29
+	/**
30
+	 * @see parent::get_priority() for documentation.
31
+	 * @return int
32
+	 */
33
+	public function get_priority()
34
+	{
35
+		return EEM_Message::priority_high;
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * This method returns whether this message type should always generate a new copy
41
-     * when requested, or if links can be to the already generated copy.
42
-     * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table.
43
-     * Invoices always generate.
44
-     * @return bool     false means can link to generated EE_Message.  true must regenerate.
45
-     */
46
-    public function always_generate()
47
-    {
48
-        return true;
49
-    }
39
+	/**
40
+	 * This method returns whether this message type should always generate a new copy
41
+	 * when requested, or if links can be to the already generated copy.
42
+	 * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table.
43
+	 * Invoices always generate.
44
+	 * @return bool     false means can link to generated EE_Message.  true must regenerate.
45
+	 */
46
+	public function always_generate()
47
+	{
48
+		return true;
49
+	}
50 50
 
51 51
 
52
-    protected function _set_admin_pages()
53
-    {
54
-        $this->admin_registered_pages = array( 'events_edit' => true );
55
-    }
52
+	protected function _set_admin_pages()
53
+	{
54
+		$this->admin_registered_pages = array( 'events_edit' => true );
55
+	}
56 56
 
57 57
 
58 58
 
59
-    protected function _set_data_handler()
60
-    {
61
-        $this->_data_handler = 'Gateways';
62
-    }
59
+	protected function _set_data_handler()
60
+	{
61
+		$this->_data_handler = 'Gateways';
62
+	}
63 63
 
64 64
 
65 65
 
66
-    protected function _set_with_messengers()
67
-    {
68
-        $this->_with_messengers = array(
69
-            'html' => array( 'pdf' )
70
-            );
71
-    }
66
+	protected function _set_with_messengers()
67
+	{
68
+		$this->_with_messengers = array(
69
+			'html' => array( 'pdf' )
70
+			);
71
+	}
72 72
 
73 73
 
74 74
 
75
-    protected function _get_data_for_context($context, EE_Registration $registration, $id)
76
-    {
77
-        // receipt message type data handler is 'Gateways' and it expects a transaction object.
78
-        $transaction = $registration->transaction();
79
-        if ($transaction instanceof EE_Transaction) {
80
-            return array( $transaction );
81
-        }
82
-        return array();
83
-    }
75
+	protected function _get_data_for_context($context, EE_Registration $registration, $id)
76
+	{
77
+		// receipt message type data handler is 'Gateways' and it expects a transaction object.
78
+		$transaction = $registration->transaction();
79
+		if ($transaction instanceof EE_Transaction) {
80
+			return array( $transaction );
81
+		}
82
+		return array();
83
+	}
84 84
 
85 85
 
86 86
 
87
-    protected function _set_admin_settings_fields()
88
-    {
89
-        $this->_admin_settings_fields = array();
90
-    }
87
+	protected function _set_admin_settings_fields()
88
+	{
89
+		$this->_admin_settings_fields = array();
90
+	}
91 91
 
92 92
 
93 93
 
94
-    protected function _set_contexts()
95
-    {
96
-        $this->_context_label = array(
97
-            'label' => esc_html__('recipient', 'event_espresso'),
98
-            'plural' => esc_html__('recipients', 'event_espresso'),
99
-            'description' => esc_html__('Recipient\'s are who will view the invoice.', 'event_espresso')
100
-        );
94
+	protected function _set_contexts()
95
+	{
96
+		$this->_context_label = array(
97
+			'label' => esc_html__('recipient', 'event_espresso'),
98
+			'plural' => esc_html__('recipients', 'event_espresso'),
99
+			'description' => esc_html__('Recipient\'s are who will view the invoice.', 'event_espresso')
100
+		);
101 101
 
102
-        $this->_contexts = array(
103
-            'purchaser' => array(
104
-                'label' => esc_html__('Purchaser', 'event_espresso'),
105
-                'description' => esc_html__('This template goes to the person who conducted the transaction.', 'event_espresso')
106
-            )
107
-        );
108
-    }
102
+		$this->_contexts = array(
103
+			'purchaser' => array(
104
+				'label' => esc_html__('Purchaser', 'event_espresso'),
105
+				'description' => esc_html__('This template goes to the person who conducted the transaction.', 'event_espresso')
106
+			)
107
+		);
108
+	}
109 109
 
110 110
 
111 111
 
112 112
 
113
-    /**
114
-    * used to set the valid shortcodes for the receipt message type
115
-    *
116
-    * @since   4.5.0
117
-    *
118
-    * @return  void
119
-    */
120
-    protected function _set_valid_shortcodes()
121
-    {
122
-        $this->_valid_shortcodes['purchaser'] = array(
123
-            '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'
124
-        );
125
-    }
113
+	/**
114
+	 * used to set the valid shortcodes for the receipt message type
115
+	 *
116
+	 * @since   4.5.0
117
+	 *
118
+	 * @return  void
119
+	 */
120
+	protected function _set_valid_shortcodes()
121
+	{
122
+		$this->_valid_shortcodes['purchaser'] = array(
123
+			'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'
124
+		);
125
+	}
126 126
 
127 127
 
128 128
 
129 129
 
130
-    protected function _purchaser_addressees()
131
-    {
132
-        return parent::_primary_attendee_addressees();
133
-    }
130
+	protected function _purchaser_addressees()
131
+	{
132
+		return parent::_primary_attendee_addressees();
133
+	}
134 134
 }
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
@@ -12,142 +12,142 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Receipt_message_type extends EE_message_type
14 14
 {
15
-    public function __construct()
16
-    {
17
-        $this->name = 'receipt';
18
-        $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');
19
-        $this->label = array(
20
-            'singular' => esc_html__('receipt', 'event_espresso'),
21
-            'plural' => esc_html__('receipts', 'event_espresso')
22
-        );
23
-        $this->_master_templates = array();
24
-        parent::__construct();
25
-    }
15
+	public function __construct()
16
+	{
17
+		$this->name = 'receipt';
18
+		$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');
19
+		$this->label = array(
20
+			'singular' => esc_html__('receipt', 'event_espresso'),
21
+			'plural' => esc_html__('receipts', 'event_espresso')
22
+		);
23
+		$this->_master_templates = array();
24
+		parent::__construct();
25
+	}
26 26
 
27 27
 
28 28
 
29
-    /**
30
-     * @see parent::get_priority() for documentation.
31
-     * @return int
32
-     */
33
-    public function get_priority()
34
-    {
35
-        return EEM_Message::priority_high;
36
-    }
37
-
38
-
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
-     * Receipts 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
-
52
-
53
-    protected function _set_admin_pages()
54
-    {
55
-        $this->admin_registered_pages = array( 'events_edit' => true );
56
-    }
57
-
58
-
59
-
60
-    protected function _set_data_handler()
61
-    {
62
-        $this->_data_handler = 'Gateways';
63
-    }
64
-
65
-
66
-
67
-    protected function _set_with_messengers()
68
-    {
69
-        $this->_with_messengers = array(
70
-            'html' => array( 'pdf' )
71
-        );
72
-    }
73
-
74
-
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
-    }
85
-
86
-
87
-
88
-    protected function _set_admin_settings_fields()
89
-    {
90
-        $this->_admin_settings_fields = array();
91
-    }
92
-
93
-
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 receipt.', 'event_espresso')
101
-        );
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
-    }
110
-
111
-
112
-
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',
125
-            'attendee',
126
-            'datetime_list',
127
-            'datetime',
128
-            'event_list',
129
-            'event',
130
-            'event_meta',
131
-            'messenger',
132
-            'organization',
133
-            'primary_registration_list',
134
-            'primary_registration_details',
135
-            'ticket_list',
136
-            'ticket',
137
-            'transaction',
138
-            'venue',
139
-            'line_item_list',
140
-            'payment_list',
141
-            'line_item',
142
-            'payment'
143
-        );
144
-    }
145
-
29
+	/**
30
+	 * @see parent::get_priority() for documentation.
31
+	 * @return int
32
+	 */
33
+	public function get_priority()
34
+	{
35
+		return EEM_Message::priority_high;
36
+	}
37
+
38
+
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
+	 * Receipts 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
+
52
+
53
+	protected function _set_admin_pages()
54
+	{
55
+		$this->admin_registered_pages = array( 'events_edit' => true );
56
+	}
57
+
58
+
59
+
60
+	protected function _set_data_handler()
61
+	{
62
+		$this->_data_handler = 'Gateways';
63
+	}
64
+
65
+
66
+
67
+	protected function _set_with_messengers()
68
+	{
69
+		$this->_with_messengers = array(
70
+			'html' => array( 'pdf' )
71
+		);
72
+	}
73
+
74
+
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
+	}
85
+
86
+
87
+
88
+	protected function _set_admin_settings_fields()
89
+	{
90
+		$this->_admin_settings_fields = array();
91
+	}
92
+
93
+
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 receipt.', 'event_espresso')
101
+		);
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
+	}
110
+
111
+
112
+
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',
125
+			'attendee',
126
+			'datetime_list',
127
+			'datetime',
128
+			'event_list',
129
+			'event',
130
+			'event_meta',
131
+			'messenger',
132
+			'organization',
133
+			'primary_registration_list',
134
+			'primary_registration_details',
135
+			'ticket_list',
136
+			'ticket',
137
+			'transaction',
138
+			'venue',
139
+			'line_item_list',
140
+			'payment_list',
141
+			'line_item',
142
+			'payment'
143
+		);
144
+	}
145
+
146 146
 
147 147
 
148 148
 
149
-    protected function _purchaser_addressees()
150
-    {
151
-        return parent::_primary_attendee_addressees();
152
-    }
149
+	protected function _purchaser_addressees()
150
+	{
151
+		return parent::_primary_attendee_addressees();
152
+	}
153 153
 }
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
@@ -12,90 +12,90 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Message_To_Generate_From_Queue extends EE_Message_To_Generate
14 14
 {
15
-    /**
16
-     * Will hold an EE_Messages_Queue object
17
-     * @type EE_Messages_Queue
18
-     */
19
-    public $queue = array();
15
+	/**
16
+	 * Will hold an EE_Messages_Queue object
17
+	 * @type EE_Messages_Queue
18
+	 */
19
+	public $queue = array();
20 20
 
21
-    /**
22
-     * @param string            $messenger_name  The messenger being used to send the message
23
-     * @param string            $message_type_name  The message type being used to grab variations etc.
24
-     * @param EE_Messages_Queue $queue
25
-     * @param string            $custom_subject  Used if a custom subject is desired for the generated aggregate EE_Message object
26
-     */
27
-    public function __construct($messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '')
28
-    {
29
-        $this->queue = $queue;
30
-        parent::__construct($messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle);
31
-        if ($this->valid()) {
32
-            $this->_message->set_content($this->_get_content());
33
-            $this->_message->set_subject($this->_get_subject($custom_subject));
34
-            $this->_message->set_GRP_ID($this->getGroupIdFromMessageRepo());
35
-        }
36
-    }
21
+	/**
22
+	 * @param string            $messenger_name  The messenger being used to send the message
23
+	 * @param string            $message_type_name  The message type being used to grab variations etc.
24
+	 * @param EE_Messages_Queue $queue
25
+	 * @param string            $custom_subject  Used if a custom subject is desired for the generated aggregate EE_Message object
26
+	 */
27
+	public function __construct($messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '')
28
+	{
29
+		$this->queue = $queue;
30
+		parent::__construct($messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle);
31
+		if ($this->valid()) {
32
+			$this->_message->set_content($this->_get_content());
33
+			$this->_message->set_subject($this->_get_subject($custom_subject));
34
+			$this->_message->set_GRP_ID($this->getGroupIdFromMessageRepo());
35
+		}
36
+	}
37 37
 
38 38
 
39 39
 
40
-    /**
41
-     * Uses the EE_Messages_Queue currently set on this object to generate the content
42
-     * for the single EE_Message aggregate object returned by get_EE_Message
43
-     * @return string;
44
-     */
45
-    protected function _get_content()
46
-    {
47
-        $content = '';
48
-        $this->queue->get_message_repository()->rewind();
49
-        while ($this->queue->get_message_repository()->valid()) {
50
-            $content .= $this->queue->get_message_repository()->current()->content();
51
-            $this->queue->get_message_repository()->next();
52
-        }
53
-        return $content;
54
-    }
40
+	/**
41
+	 * Uses the EE_Messages_Queue currently set on this object to generate the content
42
+	 * for the single EE_Message aggregate object returned by get_EE_Message
43
+	 * @return string;
44
+	 */
45
+	protected function _get_content()
46
+	{
47
+		$content = '';
48
+		$this->queue->get_message_repository()->rewind();
49
+		while ($this->queue->get_message_repository()->valid()) {
50
+			$content .= $this->queue->get_message_repository()->current()->content();
51
+			$this->queue->get_message_repository()->next();
52
+		}
53
+		return $content;
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * Return a subject string to use for `MSG_Subject` in the aggregate EE_Message object.
59
-     * @param string $custom_subject
60
-     *
61
-     * @return string
62
-     */
63
-    protected function _get_subject($custom_subject = '')
64
-    {
65
-        if (! empty($custom_subject)) {
66
-            return $custom_subject;
67
-        }
68
-        $this->queue->get_message_repository()->rewind();
69
-        $count_of_items = $this->queue->get_message_repository()->count();
57
+	/**
58
+	 * Return a subject string to use for `MSG_Subject` in the aggregate EE_Message object.
59
+	 * @param string $custom_subject
60
+	 *
61
+	 * @return string
62
+	 */
63
+	protected function _get_subject($custom_subject = '')
64
+	{
65
+		if (! empty($custom_subject)) {
66
+			return $custom_subject;
67
+		}
68
+		$this->queue->get_message_repository()->rewind();
69
+		$count_of_items = $this->queue->get_message_repository()->count();
70 70
 
71
-        // if $count of items in queue == 1, then let's just return the subject for that item.
72
-        if ($count_of_items === 1) {
73
-            return $this->queue->get_message_repository()->current()->subject();
74
-        }
75
-        // phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder
76
-        return sprintf(
77
-            _n(
78
-                'Showing Aggregate output for 1 result',
79
-                'Showing Aggregate output for %d items',
80
-                $count_of_items,
81
-                'event_espresso'
82
-            ),
83
-            $count_of_items
84
-        );
85
-        // phpcs:enable
86
-    }
71
+		// if $count of items in queue == 1, then let's just return the subject for that item.
72
+		if ($count_of_items === 1) {
73
+			return $this->queue->get_message_repository()->current()->subject();
74
+		}
75
+		// phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder
76
+		return sprintf(
77
+			_n(
78
+				'Showing Aggregate output for 1 result',
79
+				'Showing Aggregate output for %d items',
80
+				$count_of_items,
81
+				'event_espresso'
82
+			),
83
+			$count_of_items
84
+		);
85
+		// phpcs:enable
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * Uses the EE_Messages_Queue currently set on this object to set the GRP_ID
91
-     * for the single EE_Message aggregate object returned by get_EE_Message
92
-     * @return int;
93
-     */
94
-    protected function getGroupIdFromMessageRepo()
95
-    {
96
-        $this->queue->get_message_repository()->rewind();
97
-        if ($this->queue->get_message_repository()->valid()) {
98
-            return $this->queue->get_message_repository()->current()->GRP_ID();
99
-        }
100
-    }
89
+	/**
90
+	 * Uses the EE_Messages_Queue currently set on this object to set the GRP_ID
91
+	 * for the single EE_Message aggregate object returned by get_EE_Message
92
+	 * @return int;
93
+	 */
94
+	protected function getGroupIdFromMessageRepo()
95
+	{
96
+		$this->queue->get_message_repository()->rewind();
97
+		if ($this->queue->get_message_repository()->valid()) {
98
+			return $this->queue->get_message_repository()->current()->GRP_ID();
99
+		}
100
+	}
101 101
 }
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
@@ -18,202 +18,202 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Line_Item_List_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    protected function _init_props()
22
-    {
23
-        $this->label = esc_html__('Line Item List Shortcodes', 'event_espresso');
24
-        $this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso');
25
-        $this->_shortcodes = array(
26
-            '[TICKET_LINE_ITEM_LIST]'         => esc_html__('Outputs a list of ticket line items.', 'event_espresso'),
27
-            '[TAX_LINE_ITEM_LIST]'            => esc_html__('Outputs a list of tax line items.', 'event_espresso'),
28
-            '[ADDITIONAL_LINE_ITEM_LIST]'     => esc_html__(
29
-                'Outputs a list of additional line items (other charges or discounts)',
30
-                'event_espresso'
31
-            ),
32
-            '[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'),
33
-        );
34
-    }
35
-
36
-
37
-    protected function _parser($shortcode)
38
-    {
39
-
40
-        switch ($shortcode) {
41
-            case '[TICKET_LINE_ITEM_LIST]':
42
-                return $this->_get_ticket_line_item_list();
43
-                break;
44
-
45
-            case '[TAX_LINE_ITEM_LIST]':
46
-                return $this->_get_tax_line_item_list();
47
-                break;
48
-
49
-            case '[PRICE_MODIFIER_LINE_ITEM_LIST]':
50
-                return $this->_get_price_mod_line_item_list();
51
-                break;
52
-
53
-            case '[ADDITIONAL_LINE_ITEM_LIST]':
54
-                return $this->_get_additional_line_item_list();
55
-                break;
56
-
57
-            default:
58
-                return '';
59
-                break;
60
-        }
61
-    }
62
-
63
-
64
-    /**
65
-     * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event.
66
-     *
67
-     * @since 4.5.0
68
-     *
69
-     * @return string parsed ticket line item list.
70
-     */
71
-    private function _get_ticket_line_item_list()
72
-    {
73
-        $this->_validate_list_requirements();
74
-
75
-        if (! $this->_data['data'] instanceof EE_Ticket) {
76
-            return '';
77
-        }
78
-
79
-        $valid_shortcodes = array('line_item', 'line_item_list', 'ticket');
80
-
81
-        $ticket = $this->_data['data'];
82
-        $templates = $this->_extra_data['template'];
83
-        $addressee_obj = $this->_extra_data['data'];
84
-
85
-        // made it here so we have an EE_Ticket, so we should have what we need.
86
-        $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item'])
87
-            ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null;
88
-        $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'])
89
-            ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array();
90
-
91
-        $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms']
92
-            : $templates['ticket_line_item_pms'];
93
-
94
-        if (empty($ticket_line_item) || empty($sub_line_items)) {
95
-            return '';
96
-        }
97
-
98
-        // now we just return the appropriate template parsed for each ticket.
99
-        return $this->_shortcode_helper->parse_line_item_list_template(
100
-            $template,
101
-            $ticket_line_item,
102
-            $valid_shortcodes,
103
-            $this->_extra_data
104
-        );
105
-    }
106
-
107
-
108
-    /**
109
-     * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction.
110
-     *
111
-     * @since 4.5.0
112
-     *
113
-     * @return string  parsed tax line item list.
114
-     */
115
-    private function _get_tax_line_item_list()
116
-    {
117
-
118
-        $this->_validate_list_requirements();
119
-
120
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
121
-            return '';
122
-        }
123
-
124
-        // made it here so we're good to go.
125
-        $valid_shortcodes = array('line_item');
126
-        $templates = $this->_data['template'];
127
-
128
-        $tax_line_items = $this->_data['data']->tax_line_items;
129
-        $line_item_list = '';
130
-        foreach ($tax_line_items as $line_item) {
131
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
132
-                $templates['tax_line_item_list'],
133
-                $line_item,
134
-                $valid_shortcodes,
135
-                $this->_extra_data
136
-            );
137
-        }
138
-
139
-        return $line_item_list;
140
-    }
141
-
142
-    /**
143
-     * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction.
144
-     *
145
-     * @since 4.5.0
146
-     *
147
-     * @return string  parsed other line item list.
148
-     */
149
-    private function _get_additional_line_item_list()
150
-    {
151
-
152
-        $this->_validate_list_requirements();
153
-
154
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
155
-            return '';
156
-        }
157
-
158
-        // made it here so we're good to go.
159
-        $valid_shortcodes = array('line_item');
160
-        $templates = $this->_data['template'];
161
-
162
-        $additional_line_items = $this->_data['data']->additional_line_items;
163
-        $line_item_list = '';
164
-        foreach ($additional_line_items as $line_item) {
165
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
166
-                $templates['additional_line_item_list'],
167
-                $line_item,
168
-                $valid_shortcodes,
169
-                $this->_extra_data
170
-            );
171
-        }
172
-
173
-
174
-        return $line_item_list;
175
-    }
176
-
177
-
178
-    /**
179
-     * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a
180
-     * parent ticket line item.
181
-     *
182
-     * @since 4.5.0
183
-     *
184
-     * @return string parsed price modifier line item list.
185
-     */
186
-    private function _get_price_mod_line_item_list()
187
-    {
188
-        $this->_validate_list_requirements();
189
-
190
-        if (! $this->_data['data'] instanceof EE_Line_Item) {
191
-            return '';
192
-        }
193
-
194
-        // made it here so we're good to go.
195
-        $main_line_item = $this->_data['data'];
196
-        $templates = $this->_extra_data['template'];
197
-        $addressee_obj = $this->_extra_data['data'];
198
-
199
-        $valid_shortcodes = array('line_item');
200
-
201
-        $main_line_item_id = $main_line_item->ID();
202
-
203
-        $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children'])
204
-            ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array();
205
-
206
-        $line_item_list = '';
207
-
208
-        foreach ($price_mod_line_items as $line_item) {
209
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
210
-                $templates['price_modifier_line_item_list'],
211
-                $line_item,
212
-                $valid_shortcodes,
213
-                $this->_extra_data
214
-            );
215
-        }
216
-
217
-        return $line_item_list;
218
-    }
21
+	protected function _init_props()
22
+	{
23
+		$this->label = esc_html__('Line Item List Shortcodes', 'event_espresso');
24
+		$this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso');
25
+		$this->_shortcodes = array(
26
+			'[TICKET_LINE_ITEM_LIST]'         => esc_html__('Outputs a list of ticket line items.', 'event_espresso'),
27
+			'[TAX_LINE_ITEM_LIST]'            => esc_html__('Outputs a list of tax line items.', 'event_espresso'),
28
+			'[ADDITIONAL_LINE_ITEM_LIST]'     => esc_html__(
29
+				'Outputs a list of additional line items (other charges or discounts)',
30
+				'event_espresso'
31
+			),
32
+			'[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'),
33
+		);
34
+	}
35
+
36
+
37
+	protected function _parser($shortcode)
38
+	{
39
+
40
+		switch ($shortcode) {
41
+			case '[TICKET_LINE_ITEM_LIST]':
42
+				return $this->_get_ticket_line_item_list();
43
+				break;
44
+
45
+			case '[TAX_LINE_ITEM_LIST]':
46
+				return $this->_get_tax_line_item_list();
47
+				break;
48
+
49
+			case '[PRICE_MODIFIER_LINE_ITEM_LIST]':
50
+				return $this->_get_price_mod_line_item_list();
51
+				break;
52
+
53
+			case '[ADDITIONAL_LINE_ITEM_LIST]':
54
+				return $this->_get_additional_line_item_list();
55
+				break;
56
+
57
+			default:
58
+				return '';
59
+				break;
60
+		}
61
+	}
62
+
63
+
64
+	/**
65
+	 * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event.
66
+	 *
67
+	 * @since 4.5.0
68
+	 *
69
+	 * @return string parsed ticket line item list.
70
+	 */
71
+	private function _get_ticket_line_item_list()
72
+	{
73
+		$this->_validate_list_requirements();
74
+
75
+		if (! $this->_data['data'] instanceof EE_Ticket) {
76
+			return '';
77
+		}
78
+
79
+		$valid_shortcodes = array('line_item', 'line_item_list', 'ticket');
80
+
81
+		$ticket = $this->_data['data'];
82
+		$templates = $this->_extra_data['template'];
83
+		$addressee_obj = $this->_extra_data['data'];
84
+
85
+		// made it here so we have an EE_Ticket, so we should have what we need.
86
+		$ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item'])
87
+			? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null;
88
+		$sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'])
89
+			? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array();
90
+
91
+		$template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms']
92
+			: $templates['ticket_line_item_pms'];
93
+
94
+		if (empty($ticket_line_item) || empty($sub_line_items)) {
95
+			return '';
96
+		}
97
+
98
+		// now we just return the appropriate template parsed for each ticket.
99
+		return $this->_shortcode_helper->parse_line_item_list_template(
100
+			$template,
101
+			$ticket_line_item,
102
+			$valid_shortcodes,
103
+			$this->_extra_data
104
+		);
105
+	}
106
+
107
+
108
+	/**
109
+	 * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction.
110
+	 *
111
+	 * @since 4.5.0
112
+	 *
113
+	 * @return string  parsed tax line item list.
114
+	 */
115
+	private function _get_tax_line_item_list()
116
+	{
117
+
118
+		$this->_validate_list_requirements();
119
+
120
+		if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
121
+			return '';
122
+		}
123
+
124
+		// made it here so we're good to go.
125
+		$valid_shortcodes = array('line_item');
126
+		$templates = $this->_data['template'];
127
+
128
+		$tax_line_items = $this->_data['data']->tax_line_items;
129
+		$line_item_list = '';
130
+		foreach ($tax_line_items as $line_item) {
131
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
132
+				$templates['tax_line_item_list'],
133
+				$line_item,
134
+				$valid_shortcodes,
135
+				$this->_extra_data
136
+			);
137
+		}
138
+
139
+		return $line_item_list;
140
+	}
141
+
142
+	/**
143
+	 * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction.
144
+	 *
145
+	 * @since 4.5.0
146
+	 *
147
+	 * @return string  parsed other line item list.
148
+	 */
149
+	private function _get_additional_line_item_list()
150
+	{
151
+
152
+		$this->_validate_list_requirements();
153
+
154
+		if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
155
+			return '';
156
+		}
157
+
158
+		// made it here so we're good to go.
159
+		$valid_shortcodes = array('line_item');
160
+		$templates = $this->_data['template'];
161
+
162
+		$additional_line_items = $this->_data['data']->additional_line_items;
163
+		$line_item_list = '';
164
+		foreach ($additional_line_items as $line_item) {
165
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
166
+				$templates['additional_line_item_list'],
167
+				$line_item,
168
+				$valid_shortcodes,
169
+				$this->_extra_data
170
+			);
171
+		}
172
+
173
+
174
+		return $line_item_list;
175
+	}
176
+
177
+
178
+	/**
179
+	 * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a
180
+	 * parent ticket line item.
181
+	 *
182
+	 * @since 4.5.0
183
+	 *
184
+	 * @return string parsed price modifier line item list.
185
+	 */
186
+	private function _get_price_mod_line_item_list()
187
+	{
188
+		$this->_validate_list_requirements();
189
+
190
+		if (! $this->_data['data'] instanceof EE_Line_Item) {
191
+			return '';
192
+		}
193
+
194
+		// made it here so we're good to go.
195
+		$main_line_item = $this->_data['data'];
196
+		$templates = $this->_extra_data['template'];
197
+		$addressee_obj = $this->_extra_data['data'];
198
+
199
+		$valid_shortcodes = array('line_item');
200
+
201
+		$main_line_item_id = $main_line_item->ID();
202
+
203
+		$price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children'])
204
+			? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array();
205
+
206
+		$line_item_list = '';
207
+
208
+		foreach ($price_mod_line_items as $line_item) {
209
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
210
+				$templates['price_modifier_line_item_list'],
211
+				$line_item,
212
+				$valid_shortcodes,
213
+				$this->_extra_data
214
+			);
215
+		}
216
+
217
+		return $line_item_list;
218
+	}
219 219
 }
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
@@ -16,65 +16,65 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Line_Item_Shortcodes extends EE_Shortcodes
18 18
 {
19
-    protected function _init_props()
20
-    {
21
-        $this->label = esc_html__('Line Item Shortcodes', 'event_espresso');
22
-        $this->description = esc_html__('All shortcodes specific to line items', 'event_espresso');
23
-        $this->_shortcodes = array(
24
-            '[LINE_ITEM_NAME]' => esc_html__('Outputs the line item name.', 'event_espresso'),
25
-            '[LINE_ITEM_DESCRIPTION]' => esc_html__('Outputs a the description for the line item.', 'event_espresso'),
26
-            '[LINE_ITEM_QUANTITY]' => esc_html__('Outputs the quantity for this line item.', 'event_espresso'),
27
-            '[LINE_ITEM_AMOUNT]' => esc_html__(
28
-                '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).',
29
-                'event_espresso'
30
-            ),
31
-            '[LINE_ITEM_TOTAL]' => esc_html__('This outputs the line item total.', 'event_espresso'),
32
-            '[LINE_ITEM_TAXABLE_*]' => esc_html__(
33
-                '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.',
34
-                'event_espresso'
35
-            ),
36
-        );
37
-    }
19
+	protected function _init_props()
20
+	{
21
+		$this->label = esc_html__('Line Item Shortcodes', 'event_espresso');
22
+		$this->description = esc_html__('All shortcodes specific to line items', 'event_espresso');
23
+		$this->_shortcodes = array(
24
+			'[LINE_ITEM_NAME]' => esc_html__('Outputs the line item name.', 'event_espresso'),
25
+			'[LINE_ITEM_DESCRIPTION]' => esc_html__('Outputs a the description for the line item.', 'event_espresso'),
26
+			'[LINE_ITEM_QUANTITY]' => esc_html__('Outputs the quantity for this line item.', 'event_espresso'),
27
+			'[LINE_ITEM_AMOUNT]' => esc_html__(
28
+				'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).',
29
+				'event_espresso'
30
+			),
31
+			'[LINE_ITEM_TOTAL]' => esc_html__('This outputs the line item total.', 'event_espresso'),
32
+			'[LINE_ITEM_TAXABLE_*]' => esc_html__(
33
+				'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.',
34
+				'event_espresso'
35
+			),
36
+		);
37
+	}
38 38
 
39 39
 
40
-    protected function _parser($shortcode)
41
-    {
42
-        // ensure that the incoming object IS a line item.  If it isn't then bail early.
43
-        if (! $this->_data instanceof EE_Line_Item) {
44
-            return '';
45
-        }
40
+	protected function _parser($shortcode)
41
+	{
42
+		// ensure that the incoming object IS a line item.  If it isn't then bail early.
43
+		if (! $this->_data instanceof EE_Line_Item) {
44
+			return '';
45
+		}
46 46
 
47
-        $line_item = $this->_data;
47
+		$line_item = $this->_data;
48 48
 
49
-        switch ($shortcode) {
50
-            case '[LINE_ITEM_NAME]':
51
-                return $line_item->name();
52
-                break;
49
+		switch ($shortcode) {
50
+			case '[LINE_ITEM_NAME]':
51
+				return $line_item->name();
52
+				break;
53 53
 
54
-            case '[LINE_ITEM_DESCRIPTION]':
55
-                return $line_item->desc();
56
-                break;
54
+			case '[LINE_ITEM_DESCRIPTION]':
55
+				return $line_item->desc();
56
+				break;
57 57
 
58
-            case '[LINE_ITEM_QUANTITY]':
59
-                return $line_item->quantity();
60
-                break;
58
+			case '[LINE_ITEM_QUANTITY]':
59
+				return $line_item->quantity();
60
+				break;
61 61
 
62
-            case '[LINE_ITEM_AMOUNT]':
63
-                return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code();
64
-                break;
62
+			case '[LINE_ITEM_AMOUNT]':
63
+				return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code();
64
+				break;
65 65
 
66
-            case '[LINE_ITEM_TOTAL]':
67
-                return $line_item->total_no_code();
68
-                break;
69
-        }
66
+			case '[LINE_ITEM_TOTAL]':
67
+				return $line_item->total_no_code();
68
+				break;
69
+		}
70 70
 
71
-        if (strpos($shortcode, '[LINE_ITEM_TAXABLE_*') !== false) {
72
-            $attrs = $this->_get_shortcode_attrs($shortcode);
73
-            if ($line_item->is_taxable()) {
74
-                return ! empty($attrs['symbol']) ? $attrs['symbol'] : '*';
75
-            }
76
-        }
71
+		if (strpos($shortcode, '[LINE_ITEM_TAXABLE_*') !== false) {
72
+			$attrs = $this->_get_shortcode_attrs($shortcode);
73
+			if ($line_item->is_taxable()) {
74
+				return ! empty($attrs['symbol']) ? $attrs['symbol'] : '*';
75
+			}
76
+		}
77 77
 
78
-        return '';
79
-    }
78
+		return '';
79
+	}
80 80
 }
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
@@ -17,83 +17,83 @@
 block discarded – undo
17 17
  */
18 18
 class EE_Datetime_Shortcodes extends EE_Shortcodes
19 19
 {
20
-    /**
21
-     * _init_props
22
-     *
23
-     * @access protected
24
-     * @return void
25
-     */
26
-    protected function _init_props()
27
-    {
28
-        $this->label = esc_html__('Datetime Shortcodes', 'event_espresso');
29
-        $this->description = esc_html__('All shortcodes specific to datetime related data', 'event_espresso');
30
-        $this->_shortcodes = array(
31
-            '[DATETIME_START]' => esc_html__('The start date and time.', 'event_espresso'),
32
-            '[DATETIME_END]' => esc_html__('The end date and time.', 'event_espresso'),
33
-            '[DATETIME_TIMEZONE]' => esc_html__('The timezone for the date and time', 'event_espresso'),
34
-            '[DATE_START]' => esc_html__('The datetime start date.', 'event_espresso'),
35
-            '[DATE_END]' => esc_html__('The datetime end date.', 'event_espresso'),
36
-            '[TIME_START]' => esc_html__('The datetime start time.', 'event_espresso'),
37
-            '[TIME_END]' => esc_html__('The datetime end time.', 'event_espresso'),
38
-            '[ICAL_LINK_*]' => esc_html__(
39
-                '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").',
40
-                'event_espresso'
41
-            ),
42
-        );
43
-    }
20
+	/**
21
+	 * _init_props
22
+	 *
23
+	 * @access protected
24
+	 * @return void
25
+	 */
26
+	protected function _init_props()
27
+	{
28
+		$this->label = esc_html__('Datetime Shortcodes', 'event_espresso');
29
+		$this->description = esc_html__('All shortcodes specific to datetime related data', 'event_espresso');
30
+		$this->_shortcodes = array(
31
+			'[DATETIME_START]' => esc_html__('The start date and time.', 'event_espresso'),
32
+			'[DATETIME_END]' => esc_html__('The end date and time.', 'event_espresso'),
33
+			'[DATETIME_TIMEZONE]' => esc_html__('The timezone for the date and time', 'event_espresso'),
34
+			'[DATE_START]' => esc_html__('The datetime start date.', 'event_espresso'),
35
+			'[DATE_END]' => esc_html__('The datetime end date.', 'event_espresso'),
36
+			'[TIME_START]' => esc_html__('The datetime start time.', 'event_espresso'),
37
+			'[TIME_END]' => esc_html__('The datetime end time.', 'event_espresso'),
38
+			'[ICAL_LINK_*]' => esc_html__(
39
+				'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").',
40
+				'event_espresso'
41
+			),
42
+		);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * _parser
48
-     *
49
-     * @access protected
50
-     * @param string $shortcode
51
-     * @return string
52
-     */
53
-    protected function _parser($shortcode)
54
-    {
46
+	/**
47
+	 * _parser
48
+	 *
49
+	 * @access protected
50
+	 * @param string $shortcode
51
+	 * @return string
52
+	 */
53
+	protected function _parser($shortcode)
54
+	{
55 55
 
56
-        if (! $this->_data instanceof EE_Datetime) {
57
-            return ''; // get out cause we can only parse with the datetime object.
58
-        }
56
+		if (! $this->_data instanceof EE_Datetime) {
57
+			return ''; // get out cause we can only parse with the datetime object.
58
+		}
59 59
 
60
-        switch ($shortcode) {
61
-            case '[DATETIME_START]':
62
-                return $this->_data->get_i18n_datetime('DTT_EVT_start');
63
-                break;
60
+		switch ($shortcode) {
61
+			case '[DATETIME_START]':
62
+				return $this->_data->get_i18n_datetime('DTT_EVT_start');
63
+				break;
64 64
 
65
-            case '[DATETIME_END]':
66
-                return $this->_data->get_i18n_datetime('DTT_EVT_end');
67
-                break;
65
+			case '[DATETIME_END]':
66
+				return $this->_data->get_i18n_datetime('DTT_EVT_end');
67
+				break;
68 68
 
69
-            case '[DATETIME_TIMEZONE]':
70
-                return $this->_data->get_timezone();
71
-                break;
72
-            case '[DATE_START]':
73
-                return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('date_format'));
74
-                break;
75
-            case '[DATE_END]':
76
-                return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('date_format'));
77
-                break;
78
-            case '[TIME_START]':
79
-                return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('time_format'));
80
-                break;
81
-            case '[TIME_END]':
82
-                return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('time_format'));
83
-                break;
84
-        }
69
+			case '[DATETIME_TIMEZONE]':
70
+				return $this->_data->get_timezone();
71
+				break;
72
+			case '[DATE_START]':
73
+				return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('date_format'));
74
+				break;
75
+			case '[DATE_END]':
76
+				return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('date_format'));
77
+				break;
78
+			case '[TIME_START]':
79
+				return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('time_format'));
80
+				break;
81
+			case '[TIME_END]':
82
+				return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('time_format'));
83
+				break;
84
+		}
85 85
 
86
-        if (strpos($shortcode, '[ICAL_LINK_*') !== false) {
87
-            $attrs = $this->_get_shortcode_attrs($shortcode);
86
+		if (strpos($shortcode, '[ICAL_LINK_*') !== false) {
87
+			$attrs = $this->_get_shortcode_attrs($shortcode);
88 88
 
89
-            $link_text = empty($attrs['link_text']) ? esc_html__('Add to iCal Calendar', 'event_espresso')
90
-                : $attrs['link_text'];
89
+			$link_text = empty($attrs['link_text']) ? esc_html__('Add to iCal Calendar', 'event_espresso')
90
+				: $attrs['link_text'];
91 91
 
92
-            $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url());
92
+			$URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url());
93 93
 
94
-            return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>';
95
-        }
94
+			return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>';
95
+		}
96 96
 
97
-        return '';
98
-    }
97
+		return '';
98
+	}
99 99
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Venue_Shortcodes.lib.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     {
89 89
         $this->_venue = $this->_get_venue();
90 90
         // If there is no venue object by now then get out.
91
-        if (! $this->_venue instanceof EE_Venue) {
91
+        if ( ! $this->_venue instanceof EE_Venue) {
92 92
             return '';
93 93
         }
94 94
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 
185 185
         // if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
186 186
         // reg_obj instead.
187
-        if (! $this->_event instanceof EE_Event) {
187
+        if ( ! $this->_event instanceof EE_Event) {
188 188
             $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
189 189
             $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
190 190
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             $this->_event = ! $this->_event instanceof EE_Event
197 197
                             && $this->_data instanceof EE_Ticket
198 198
                             && $this->_extra_data['data'] instanceof EE_Messages_Addressee
199
-                ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event']
199
+                ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
200 200
                 : $this->_event;
201 201
 
202 202
             // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
     private function _venue($field)
226 226
     {
227 227
 
228
-        if (! $this->_venue instanceof EE_Venue) {
228
+        if ( ! $this->_venue instanceof EE_Venue) {
229 229
             return '';
230 230
         } //no venue so get out.
231 231
 
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
                 break;
249 249
 
250 250
             case 'image':
251
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
252
-                       . '" alt="' . sprintf(
251
+                return '<img src="'.$this->_venue->feature_image_url(array(200, 200,))
252
+                       . '" alt="'.sprintf(
253 253
                            esc_attr__('%s Feature Image', 'event_espresso'),
254 254
                            $this->_venue->get('VNU_name')
255
-                       ) . '" />';
255
+                       ).'" />';
256 256
                 break;
257 257
 
258 258
             case 'phone':
Please login to merge, or discard this patch.
Indentation   +311 added lines, -311 removed lines patch added patch discarded remove patch
@@ -15,315 +15,315 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Venue_Shortcodes extends EE_Shortcodes
17 17
 {
18
-    /**
19
-     * Will hold the EE_Event if available
20
-     *
21
-     * @var EE_Event
22
-     */
23
-    protected $_event;
24
-
25
-    /**
26
-     * Will hold the EE_Venue if available
27
-     *
28
-     * @var EE_Venue
29
-     */
30
-    protected $_venue;
31
-
32
-
33
-    /**
34
-     * Initialize properties
35
-     */
36
-    protected function _init_props()
37
-    {
38
-        $this->label = esc_html__('Venue Shortcodes', 'event_espresso');
39
-        $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
40
-        $this->_shortcodes = array(
41
-            '[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
42
-            '[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
43
-            '[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
44
-            '[VENUE_DETAILS_URL]'       => sprintf(
45
-                esc_html__(
46
-                    'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.',
47
-                    'event_espresso'
48
-                ),
49
-                '[VENUE_URL]'
50
-            ),
51
-            '[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
52
-            '[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
53
-            '[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
54
-            '[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
55
-            '[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
56
-            '[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
57
-            '[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
58
-            '[VENUE_FORMATTED_ADDRESS]' => esc_html__(
59
-                'This just outputs the venue address in a semantic address format.',
60
-                'event_espresso'
61
-            ),
62
-            '[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
63
-            '[VENUE_META_*]'            => esc_html__(
64
-                'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.',
65
-                'event_espresso'
66
-            ),
67
-            '[GOOGLE_MAP_URL]'          => esc_html__(
68
-                'URL for the google map associated with the venue.',
69
-                'event_espresso'
70
-            ),
71
-            '[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
72
-            '[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
73
-        );
74
-    }
75
-
76
-
77
-    /**
78
-     * Parse incoming shortcode
79
-     *
80
-     * @param string $shortcode
81
-     * @return string
82
-     * @throws EE_Error
83
-     * @throws EntityNotFoundException
84
-     */
85
-    protected function _parser($shortcode)
86
-    {
87
-        $this->_venue = $this->_get_venue();
88
-        // If there is no venue object by now then get out.
89
-        if (! $this->_venue instanceof EE_Venue) {
90
-            return '';
91
-        }
92
-
93
-        switch ($shortcode) {
94
-            case '[VENUE_TITLE]':
95
-                return $this->_venue('title');
96
-                break;
97
-
98
-            case '[VENUE_DESCRIPTION]':
99
-                return $this->_venue('description');
100
-                break;
101
-
102
-            case '[VENUE_URL]':
103
-                return $this->_venue('url');
104
-                break;
105
-
106
-            case '[VENUE_IMAGE]':
107
-                return $this->_venue('image');
108
-                break;
109
-
110
-            case '[VENUE_PHONE]':
111
-                return $this->_venue('phone');
112
-                break;
113
-
114
-            case '[VENUE_ADDRESS]':
115
-                return $this->_venue('address');
116
-                break;
117
-
118
-            case '[VENUE_ADDRESS2]':
119
-                return $this->_venue('address2');
120
-                break;
121
-
122
-            case '[VENUE_CITY]':
123
-                return $this->_venue('city');
124
-                break;
125
-
126
-            case '[VENUE_COUNTRY]':
127
-                return $this->_venue('country');
128
-                break;
129
-
130
-            case '[VENUE_STATE]':
131
-                return $this->_venue('state');
132
-                break;
133
-
134
-            case '[VENUE_ZIP]':
135
-                return $this->_venue('zip');
136
-                break;
137
-
138
-            case '[VENUE_FORMATTED_ADDRESS]':
139
-                return $this->_venue('formatted_address');
140
-                break;
141
-
142
-            case '[GOOGLE_MAP_URL]':
143
-                return $this->_venue('gmap_url');
144
-                break;
145
-
146
-            case '[GOOGLE_MAP_LINK]':
147
-                return $this->_venue('gmap_link');
148
-                break;
149
-
150
-            case '[GOOGLE_MAP_IMAGE]':
151
-                return $this->_venue('gmap_link_img');
152
-                break;
153
-
154
-            case '[VENUE_DETAILS_URL]':
155
-                return $this->_venue('permalink');
156
-                break;
157
-        }
158
-
159
-        if (strpos($shortcode, '[VENUE_META_*') !== false) {
160
-            $shortcode = str_replace('[VENUE_META_*', '', $shortcode);
161
-            $shortcode = trim(str_replace(']', '', $shortcode));
162
-
163
-            // pull the meta value from the venue post
164
-            $venue_meta = $this->_venue->get_post_meta($shortcode, true);
165
-
166
-            return ! empty($venue_meta) ? $venue_meta : '';
167
-        }
168
-    }
169
-
170
-    /**
171
-     * This retrieves the EE_Venue from the available data object.
172
-     *
173
-     * @return EE_Venue|null
174
-     * @throws EE_Error
175
-     * @throws EntityNotFoundException
176
-     */
177
-    private function _get_venue()
178
-    {
179
-
180
-        // we need the EE_Event object to get the venue.
181
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
182
-
183
-        // if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
184
-        // reg_obj instead.
185
-        if (! $this->_event instanceof EE_Event) {
186
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
187
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
188
-
189
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
190
-                ? $aee->reg_obj->event()
191
-                : null;
192
-
193
-            // if still empty do we have a ticket data item?
194
-            $this->_event = ! $this->_event instanceof EE_Event
195
-                            && $this->_data instanceof EE_Ticket
196
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
197
-                ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event']
198
-                : $this->_event;
199
-
200
-            // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
201
-            // and use that.
202
-            $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
203
-                ? reset($aee->events)
204
-                : $this->_event;
205
-        }
206
-
207
-        // If we have an event object use it to pull the venue.
208
-        if ($this->_event instanceof EE_Event) {
209
-            return $this->_event->get_first_related('Venue');
210
-        }
211
-
212
-        return null;
213
-    }
214
-
215
-    /**
216
-     * This retrieves the specified venue information
217
-     *
218
-     * @param string $field What Venue field to retrieve
219
-     * @return string What was retrieved!
220
-     * @throws EE_Error
221
-     * @throws EntityNotFoundException
222
-     */
223
-    private function _venue($field)
224
-    {
225
-
226
-        if (! $this->_venue instanceof EE_Venue) {
227
-            return '';
228
-        } //no venue so get out.
229
-
230
-        switch ($field) {
231
-            case 'title':
232
-                return $this->_venue->get('VNU_name');
233
-                break;
234
-
235
-            case 'description':
236
-                return $this->_venue->get('VNU_desc');
237
-                break;
238
-
239
-            case 'url':
240
-                $url = $this->_venue->get('VNU_url');
241
-                return empty($url) ? $this->_venue->get_permalink() : $url;
242
-                break;
243
-
244
-            case 'permalink':
245
-                return $this->_venue->get_permalink();
246
-                break;
247
-
248
-            case 'image':
249
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
250
-                       . '" alt="' . sprintf(
251
-                           esc_attr__('%s Feature Image', 'event_espresso'),
252
-                           $this->_venue->get('VNU_name')
253
-                       ) . '" />';
254
-                break;
255
-
256
-            case 'phone':
257
-                return $this->_venue->get('VNU_phone');
258
-                break;
259
-
260
-            case 'address':
261
-                return $this->_venue->get('VNU_address');
262
-                break;
263
-
264
-            case 'address2':
265
-                return $this->_venue->get('VNU_address2');
266
-                break;
267
-
268
-            case 'city':
269
-                return $this->_venue->get('VNU_city');
270
-                break;
271
-
272
-            case 'state':
273
-                $state = $this->_venue->state_obj();
274
-                return is_object($state) ? $state->get('STA_name') : '';
275
-                break;
276
-
277
-            case 'country':
278
-                $country = $this->_venue->country_obj();
279
-                return is_object($country) ? $country->get('CNT_name') : '';
280
-                break;
281
-
282
-            case 'zip':
283
-                return $this->_venue->get('VNU_zip');
284
-                break;
285
-
286
-            case 'formatted_address':
287
-                return EEH_Address::format($this->_venue);
288
-                break;
289
-
290
-            case 'gmap_link':
291
-            case 'gmap_url':
292
-            case 'gmap_link_img':
293
-                $atts = $this->get_map_attributes($this->_venue, $field);
294
-                return EEH_Maps::google_map_link($atts);
295
-                break;
296
-        }
297
-        return '';
298
-    }
299
-
300
-
301
-    /**
302
-     * Generates the attributes for retrieving a google_map artifact.
303
-     *
304
-     * @param EE_Venue $venue
305
-     * @param string   $field
306
-     * @return array
307
-     * @throws EE_Error
308
-     */
309
-    protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
310
-    {
311
-        $state = $venue->state_obj();
312
-        $country = $venue->country_obj();
313
-        $atts = array(
314
-            'id'      => $venue->ID(),
315
-            'address' => $venue->get('VNU_address'),
316
-            'city'    => $venue->get('VNU_city'),
317
-            'state'   => is_object($state) ? $state->get('STA_name') : '',
318
-            'zip'     => $venue->get('VNU_zip'),
319
-            'country' => is_object($country) ? $country->get('CNT_name') : '',
320
-            'type'    => $field === 'gmap_link' ? 'url' : 'map',
321
-            'map_w'   => 200,
322
-            'map_h'   => 200,
323
-        );
324
-        if ($field === 'gmap_url') {
325
-            $atts['type'] = 'url_only';
326
-        }
327
-        return $atts;
328
-    }
18
+	/**
19
+	 * Will hold the EE_Event if available
20
+	 *
21
+	 * @var EE_Event
22
+	 */
23
+	protected $_event;
24
+
25
+	/**
26
+	 * Will hold the EE_Venue if available
27
+	 *
28
+	 * @var EE_Venue
29
+	 */
30
+	protected $_venue;
31
+
32
+
33
+	/**
34
+	 * Initialize properties
35
+	 */
36
+	protected function _init_props()
37
+	{
38
+		$this->label = esc_html__('Venue Shortcodes', 'event_espresso');
39
+		$this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
40
+		$this->_shortcodes = array(
41
+			'[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
42
+			'[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
43
+			'[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
44
+			'[VENUE_DETAILS_URL]'       => sprintf(
45
+				esc_html__(
46
+					'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.',
47
+					'event_espresso'
48
+				),
49
+				'[VENUE_URL]'
50
+			),
51
+			'[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
52
+			'[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
53
+			'[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
54
+			'[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
55
+			'[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
56
+			'[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
57
+			'[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
58
+			'[VENUE_FORMATTED_ADDRESS]' => esc_html__(
59
+				'This just outputs the venue address in a semantic address format.',
60
+				'event_espresso'
61
+			),
62
+			'[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
63
+			'[VENUE_META_*]'            => esc_html__(
64
+				'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.',
65
+				'event_espresso'
66
+			),
67
+			'[GOOGLE_MAP_URL]'          => esc_html__(
68
+				'URL for the google map associated with the venue.',
69
+				'event_espresso'
70
+			),
71
+			'[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
72
+			'[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
73
+		);
74
+	}
75
+
76
+
77
+	/**
78
+	 * Parse incoming shortcode
79
+	 *
80
+	 * @param string $shortcode
81
+	 * @return string
82
+	 * @throws EE_Error
83
+	 * @throws EntityNotFoundException
84
+	 */
85
+	protected function _parser($shortcode)
86
+	{
87
+		$this->_venue = $this->_get_venue();
88
+		// If there is no venue object by now then get out.
89
+		if (! $this->_venue instanceof EE_Venue) {
90
+			return '';
91
+		}
92
+
93
+		switch ($shortcode) {
94
+			case '[VENUE_TITLE]':
95
+				return $this->_venue('title');
96
+				break;
97
+
98
+			case '[VENUE_DESCRIPTION]':
99
+				return $this->_venue('description');
100
+				break;
101
+
102
+			case '[VENUE_URL]':
103
+				return $this->_venue('url');
104
+				break;
105
+
106
+			case '[VENUE_IMAGE]':
107
+				return $this->_venue('image');
108
+				break;
109
+
110
+			case '[VENUE_PHONE]':
111
+				return $this->_venue('phone');
112
+				break;
113
+
114
+			case '[VENUE_ADDRESS]':
115
+				return $this->_venue('address');
116
+				break;
117
+
118
+			case '[VENUE_ADDRESS2]':
119
+				return $this->_venue('address2');
120
+				break;
121
+
122
+			case '[VENUE_CITY]':
123
+				return $this->_venue('city');
124
+				break;
125
+
126
+			case '[VENUE_COUNTRY]':
127
+				return $this->_venue('country');
128
+				break;
129
+
130
+			case '[VENUE_STATE]':
131
+				return $this->_venue('state');
132
+				break;
133
+
134
+			case '[VENUE_ZIP]':
135
+				return $this->_venue('zip');
136
+				break;
137
+
138
+			case '[VENUE_FORMATTED_ADDRESS]':
139
+				return $this->_venue('formatted_address');
140
+				break;
141
+
142
+			case '[GOOGLE_MAP_URL]':
143
+				return $this->_venue('gmap_url');
144
+				break;
145
+
146
+			case '[GOOGLE_MAP_LINK]':
147
+				return $this->_venue('gmap_link');
148
+				break;
149
+
150
+			case '[GOOGLE_MAP_IMAGE]':
151
+				return $this->_venue('gmap_link_img');
152
+				break;
153
+
154
+			case '[VENUE_DETAILS_URL]':
155
+				return $this->_venue('permalink');
156
+				break;
157
+		}
158
+
159
+		if (strpos($shortcode, '[VENUE_META_*') !== false) {
160
+			$shortcode = str_replace('[VENUE_META_*', '', $shortcode);
161
+			$shortcode = trim(str_replace(']', '', $shortcode));
162
+
163
+			// pull the meta value from the venue post
164
+			$venue_meta = $this->_venue->get_post_meta($shortcode, true);
165
+
166
+			return ! empty($venue_meta) ? $venue_meta : '';
167
+		}
168
+	}
169
+
170
+	/**
171
+	 * This retrieves the EE_Venue from the available data object.
172
+	 *
173
+	 * @return EE_Venue|null
174
+	 * @throws EE_Error
175
+	 * @throws EntityNotFoundException
176
+	 */
177
+	private function _get_venue()
178
+	{
179
+
180
+		// we need the EE_Event object to get the venue.
181
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
182
+
183
+		// if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
184
+		// reg_obj instead.
185
+		if (! $this->_event instanceof EE_Event) {
186
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
187
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
188
+
189
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
190
+				? $aee->reg_obj->event()
191
+				: null;
192
+
193
+			// if still empty do we have a ticket data item?
194
+			$this->_event = ! $this->_event instanceof EE_Event
195
+							&& $this->_data instanceof EE_Ticket
196
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
197
+				? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event']
198
+				: $this->_event;
199
+
200
+			// if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
201
+			// and use that.
202
+			$this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
203
+				? reset($aee->events)
204
+				: $this->_event;
205
+		}
206
+
207
+		// If we have an event object use it to pull the venue.
208
+		if ($this->_event instanceof EE_Event) {
209
+			return $this->_event->get_first_related('Venue');
210
+		}
211
+
212
+		return null;
213
+	}
214
+
215
+	/**
216
+	 * This retrieves the specified venue information
217
+	 *
218
+	 * @param string $field What Venue field to retrieve
219
+	 * @return string What was retrieved!
220
+	 * @throws EE_Error
221
+	 * @throws EntityNotFoundException
222
+	 */
223
+	private function _venue($field)
224
+	{
225
+
226
+		if (! $this->_venue instanceof EE_Venue) {
227
+			return '';
228
+		} //no venue so get out.
229
+
230
+		switch ($field) {
231
+			case 'title':
232
+				return $this->_venue->get('VNU_name');
233
+				break;
234
+
235
+			case 'description':
236
+				return $this->_venue->get('VNU_desc');
237
+				break;
238
+
239
+			case 'url':
240
+				$url = $this->_venue->get('VNU_url');
241
+				return empty($url) ? $this->_venue->get_permalink() : $url;
242
+				break;
243
+
244
+			case 'permalink':
245
+				return $this->_venue->get_permalink();
246
+				break;
247
+
248
+			case 'image':
249
+				return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
250
+					   . '" alt="' . sprintf(
251
+						   esc_attr__('%s Feature Image', 'event_espresso'),
252
+						   $this->_venue->get('VNU_name')
253
+					   ) . '" />';
254
+				break;
255
+
256
+			case 'phone':
257
+				return $this->_venue->get('VNU_phone');
258
+				break;
259
+
260
+			case 'address':
261
+				return $this->_venue->get('VNU_address');
262
+				break;
263
+
264
+			case 'address2':
265
+				return $this->_venue->get('VNU_address2');
266
+				break;
267
+
268
+			case 'city':
269
+				return $this->_venue->get('VNU_city');
270
+				break;
271
+
272
+			case 'state':
273
+				$state = $this->_venue->state_obj();
274
+				return is_object($state) ? $state->get('STA_name') : '';
275
+				break;
276
+
277
+			case 'country':
278
+				$country = $this->_venue->country_obj();
279
+				return is_object($country) ? $country->get('CNT_name') : '';
280
+				break;
281
+
282
+			case 'zip':
283
+				return $this->_venue->get('VNU_zip');
284
+				break;
285
+
286
+			case 'formatted_address':
287
+				return EEH_Address::format($this->_venue);
288
+				break;
289
+
290
+			case 'gmap_link':
291
+			case 'gmap_url':
292
+			case 'gmap_link_img':
293
+				$atts = $this->get_map_attributes($this->_venue, $field);
294
+				return EEH_Maps::google_map_link($atts);
295
+				break;
296
+		}
297
+		return '';
298
+	}
299
+
300
+
301
+	/**
302
+	 * Generates the attributes for retrieving a google_map artifact.
303
+	 *
304
+	 * @param EE_Venue $venue
305
+	 * @param string   $field
306
+	 * @return array
307
+	 * @throws EE_Error
308
+	 */
309
+	protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
310
+	{
311
+		$state = $venue->state_obj();
312
+		$country = $venue->country_obj();
313
+		$atts = array(
314
+			'id'      => $venue->ID(),
315
+			'address' => $venue->get('VNU_address'),
316
+			'city'    => $venue->get('VNU_city'),
317
+			'state'   => is_object($state) ? $state->get('STA_name') : '',
318
+			'zip'     => $venue->get('VNU_zip'),
319
+			'country' => is_object($country) ? $country->get('CNT_name') : '',
320
+			'type'    => $field === 'gmap_link' ? 'url' : 'map',
321
+			'map_w'   => 200,
322
+			'map_h'   => 200,
323
+		);
324
+		if ($field === 'gmap_url') {
325
+			$atts['type'] = 'url_only';
326
+		}
327
+		return $atts;
328
+	}
329 329
 }
Please login to merge, or discard this patch.