Completed
Branch fix/block-theme-excerpt (8f19eb)
by
unknown
26:32 queued 24:00
created
core/helpers/EEH_MSG_Template.helper.php 1 patch
Indentation   +1249 added lines, -1249 removed lines patch added patch discarded remove patch
@@ -15,1253 +15,1253 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Holds a collection of EE_Message_Template_Pack objects.
20
-     * @type EE_Messages_Template_Pack_Collection
21
-     */
22
-    protected static $_template_pack_collection;
23
-
24
-
25
-    /**
26
-     * @throws EE_Error
27
-     */
28
-    private static function _set_autoloader()
29
-    {
30
-        EED_Messages::set_autoloaders();
31
-    }
32
-
33
-
34
-    /**
35
-     * generate_new_templates
36
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
37
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
38
-     * for the event.
39
-     *
40
-     * @access protected
41
-     * @param string $messenger     the messenger we are generating templates for
42
-     * @param array  $message_types array of message types that the templates are generated for.
43
-     * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
44
-     *                              to use as the base for the new generated template.
45
-     * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
46
-     *                              for event specific template generation.
47
-     * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
48
-     *                for templates that are generated.  If this is an empty array then it means no templates were
49
-     *                generated which usually means there was an error.  Anything in the array with an empty value for
50
-     *                `MTP_context` means that it was not a new generated template but just reactivated (which only
51
-     *                happens for global templates that already exist in the database.
52
-     * @throws EE_Error
53
-     * @throws ReflectionException
54
-     */
55
-    public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
56
-    {
57
-        // make sure message_type is an array.
58
-        $message_types = (array) $message_types;
59
-        $templates = array();
60
-
61
-        if (empty($messenger)) {
62
-            throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
63
-        }
64
-
65
-        // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
66
-        if (empty($message_types)) {
67
-            throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
68
-        }
69
-
70
-        EEH_MSG_Template::_set_autoloader();
71
-        foreach ($message_types as $message_type) {
72
-            // if this is global template generation.
73
-            if ($global) {
74
-                // let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
75
-                if (empty($GRP_ID)) {
76
-                    $GRP_ID = EEM_Message_Template_Group::instance()->get_one(
77
-                        array(
78
-                            array(
79
-                                'MTP_messenger'    => $messenger,
80
-                                'MTP_message_type' => $message_type,
81
-                                'MTP_is_global'    => true,
82
-                            ),
83
-                        )
84
-                    );
85
-                    $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
86
-                }
87
-                // First let's determine if we already HAVE global templates for this messenger and message_type combination.
88
-                //  If we do then NO generation!!
89
-                if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
90
-                    $templates[] = array(
91
-                        'GRP_ID' => $GRP_ID,
92
-                        'MTP_context' => '',
93
-                    );
94
-                    // we already have generated templates for this so let's go to the next message type.
95
-                    continue;
96
-                }
97
-            }
98
-            $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
99
-
100
-            if (! $new_message_template_group) {
101
-                continue;
102
-            }
103
-            $templates[] = $new_message_template_group;
104
-        }
105
-
106
-        return $templates;
107
-    }
108
-
109
-
110
-    /**
111
-     * The purpose of this method is to determine if there are already generated templates in the database for the
112
-     * given variables.
113
-     *
114
-     * @param string $messenger    messenger
115
-     * @param string $message_type message type
116
-     * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
117
-     *                             template check)
118
-     * @return bool                true = generated, false = hasn't been generated.
119
-     * @throws EE_Error
120
-     */
121
-    public static function already_generated($messenger, $message_type, $GRP_ID = 0)
122
-    {
123
-        EEH_MSG_Template::_set_autoloader();
124
-        // what method we use depends on whether we have an GRP_ID or not
125
-        $count = empty($GRP_ID)
126
-            ? EEM_Message_Template::instance()->count(
127
-                array(
128
-                    array(
129
-                        'Message_Template_Group.MTP_messenger'    => $messenger,
130
-                        'Message_Template_Group.MTP_message_type' => $message_type,
131
-                        'Message_Template_Group.MTP_is_global'    => true
132
-                    )
133
-                )
134
-            )
135
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
136
-
137
-        return $count > 0;
138
-    }
139
-
140
-
141
-    /**
142
-     * Updates all message templates matching the incoming messengers and message types to active status.
143
-     *
144
-     * @static
145
-     * @param array $messenger_names    Messenger slug
146
-     * @param array $message_type_names Message type slug
147
-     * @return  int                         count of updated records.
148
-     * @throws EE_Error
149
-     */
150
-    public static function update_to_active($messenger_names, $message_type_names)
151
-    {
152
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
153
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
154
-        return EEM_Message_Template_Group::instance()->update(
155
-            array( 'MTP_is_active' => 1 ),
156
-            array(
157
-                array(
158
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
159
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
160
-                )
161
-            )
162
-        );
163
-    }
164
-
165
-
166
-    /**
167
-     * Updates all message template groups matching the incoming arguments to inactive status.
168
-     *
169
-     * @static
170
-     * @param array $messenger_names    The messenger slugs.
171
-     *                                  If empty then all templates matching the message types are marked inactive.
172
-     *                                  Otherwise only templates matching the messengers and message types.
173
-     * @param array $message_type_names The message type slugs.
174
-     *                                  If empty then all templates matching the messengers are marked inactive.
175
-     *                                  Otherwise only templates matching the messengers and message types.
176
-     *
177
-     * @return int  count of updated records.
178
-     * @throws EE_Error
179
-     */
180
-    public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
181
-    {
182
-        return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
183
-            $messenger_names,
184
-            $message_type_names
185
-        );
186
-    }
187
-
188
-
189
-    /**
190
-     * The purpose of this function is to return all installed message objects
191
-     * (messengers and message type regardless of whether they are ACTIVE or not)
192
-     *
193
-     * @param string $type
194
-     * @return array array consisting of installed messenger objects and installed message type objects.
195
-     * @throws EE_Error
196
-     * @throws ReflectionException
197
-     * @deprecated 4.9.0
198
-     * @static
199
-     */
200
-    public static function get_installed_message_objects($type = 'all')
201
-    {
202
-        self::_set_autoloader();
203
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
204
-        return array(
205
-            'messenger' => $message_resource_manager->installed_messengers(),
206
-            'message_type' => $message_resource_manager->installed_message_types()
207
-        );
208
-    }
209
-
210
-
211
-    /**
212
-     * This will return an array of shortcodes => labels from the
213
-     * messenger and message_type objects associated with this
214
-     * template.
215
-     *
216
-     * @param string $message_type
217
-     * @param string $messenger
218
-     * @param array  $fields                        What fields we're returning valid shortcodes for.
219
-     *                                              If empty then we assume all fields are to be returned. Optional.
220
-     * @param string $context                       What context we're going to return shortcodes for. Optional.
221
-     * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
222
-     *                                              but instead an array of the unique shortcodes for all the given (
223
-     *                                              or all) fields. Optional.
224
-     * @return array                                an array of shortcodes in the format
225
-     *                                              array( '[shortcode] => 'label')
226
-     *                                              OR
227
-     *                                              FALSE if no shortcodes found.
228
-     * @throws ReflectionException
229
-     * @throws EE_Error*@since 4.3.0
230
-     *
231
-     */
232
-    public static function get_shortcodes(
233
-        $message_type,
234
-        $messenger,
235
-        $fields = array(),
236
-        $context = 'admin',
237
-        $merged = false
238
-    ) {
239
-        $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
240
-        $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
241
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
242
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
243
-        // convert slug to object
244
-        $messenger = $message_resource_manager->get_messenger($messenger);
245
-
246
-        // if messenger isn't a EE_messenger resource then bail.
247
-        if (! $messenger instanceof EE_messenger) {
248
-            return array();
249
-        }
250
-
251
-        // validate class for getting our list of shortcodes
252
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
253
-        if (! class_exists($classname)) {
254
-            $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
255
-            $msg[] = sprintf(
256
-                esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
257
-                $classname
258
-            );
259
-            throw new EE_Error(implode('||', $msg));
260
-        }
261
-
262
-        /** @type EE_Messages_Validator $_VLD */
263
-        $_VLD = new $classname(array(), $context);
264
-        $valid_shortcodes = $_VLD->get_validators();
265
-
266
-        // let's make sure we're only getting the shortcode part of the validators
267
-        $shortcodes = array();
268
-        foreach ($valid_shortcodes as $field => $validators) {
269
-            $shortcodes[ $field ] = $validators['shortcodes'];
270
-        }
271
-        $valid_shortcodes = $shortcodes;
272
-
273
-        // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
274
-        if (! empty($fields)) {
275
-            $specified_shortcodes = array();
276
-            foreach ($fields as $field) {
277
-                if (isset($valid_shortcodes[ $field ])) {
278
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
279
-                }
280
-            }
281
-            $valid_shortcodes = $specified_shortcodes;
282
-        }
283
-
284
-        // if not merged then let's replace the fields with the localized fields
285
-        if (! $merged) {
286
-            // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
287
-            $field_settings = $messenger->get_template_fields();
288
-            $localized = array();
289
-            foreach ($valid_shortcodes as $field => $shortcodes) {
290
-                // get localized field label
291
-                if (isset($field_settings[ $field ])) {
292
-                    // possible that this is used as a main field.
293
-                    if (empty($field_settings[ $field ])) {
294
-                        if (isset($field_settings['extra'][ $field ])) {
295
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
296
-                        } else {
297
-                            $_field = $field;
298
-                        }
299
-                    } else {
300
-                        $_field = $field_settings[ $field ]['label'];
301
-                    }
302
-                } elseif (isset($field_settings['extra'])) {
303
-                    // loop through extra "main fields" and see if any of their children have our field
304
-                    foreach ($field_settings['extra'] as $fields) {
305
-                        if (isset($fields[ $field ])) {
306
-                            $_field = $fields[ $field ]['label'];
307
-                        } else {
308
-                            $_field = $field;
309
-                        }
310
-                    }
311
-                } else {
312
-                    $_field = $field;
313
-                }
314
-                if (isset($_field)) {
315
-                    $localized[ (string) $_field ] = $shortcodes;
316
-                }
317
-            }
318
-            $valid_shortcodes = $localized;
319
-        }
320
-
321
-        // if $merged then let's merge all the shortcodes into one list NOT indexed by field.
322
-        if ($merged) {
323
-            $merged_codes = array();
324
-            foreach ($valid_shortcodes as $shortcode) {
325
-                foreach ($shortcode as $code => $label) {
326
-                    if (isset($merged_codes[ $code ])) {
327
-                        continue;
328
-                    } else {
329
-                        $merged_codes[ $code ] = $label;
330
-                    }
331
-                }
332
-            }
333
-            $valid_shortcodes = $merged_codes;
334
-        }
335
-
336
-        return $valid_shortcodes;
337
-    }
338
-
339
-
340
-    /**
341
-     * Get Messenger object.
342
-     *
343
-     * @param string $messenger messenger slug for the messenger object we want to retrieve.
344
-     * @return EE_messenger
345
-     * @throws ReflectionException
346
-     * @throws EE_Error*@since 4.3.0
347
-     * @deprecated 4.9.0
348
-     */
349
-    public static function messenger_obj($messenger)
350
-    {
351
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
352
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
353
-        return $Message_Resource_Manager->get_messenger($messenger);
354
-    }
355
-
356
-
357
-    /**
358
-     * get Message type object
359
-     *
360
-     * @param string $message_type the slug for the message type object to retrieve
361
-     * @return EE_message_type
362
-     * @throws ReflectionException
363
-     * @throws EE_Error*@since 4.3.0
364
-     * @deprecated 4.9.0
365
-     */
366
-    public static function message_type_obj($message_type)
367
-    {
368
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
369
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
370
-        return $Message_Resource_Manager->get_message_type($message_type);
371
-    }
372
-
373
-
374
-    /**
375
-     * Given a message_type slug, will return whether that message type is active in the system or not.
376
-     *
377
-     * @since    4.3.0
378
-     * @param string $message_type message type to check for.
379
-     * @return boolean
380
-     * @throws EE_Error
381
-     * @throws ReflectionException
382
-     */
383
-    public static function is_mt_active($message_type)
384
-    {
385
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
386
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
387
-        $active_mts = $Message_Resource_Manager->list_of_active_message_types();
388
-        return in_array($message_type, $active_mts);
389
-    }
390
-
391
-
392
-    /**
393
-     * Given a messenger slug, will return whether that messenger is active in the system or not.
394
-     *
395
-     * @since    4.3.0
396
-     *
397
-     * @param string $messenger slug for messenger to check.
398
-     * @return boolean
399
-     * @throws EE_Error
400
-     * @throws ReflectionException
401
-     */
402
-    public static function is_messenger_active($messenger)
403
-    {
404
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
405
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
406
-        $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
407
-        return $active_messenger instanceof EE_messenger;
408
-    }
409
-
410
-
411
-    /**
412
-     * Used to return active messengers array stored in the wp options table.
413
-     * If no value is present in the option then an empty array is returned.
414
-     *
415
-     * @deprecated 4.9
416
-     * @since      4.3.1
417
-     *
418
-     * @return array
419
-     * @throws EE_Error
420
-     * @throws ReflectionException
421
-     */
422
-    public static function get_active_messengers_in_db()
423
-    {
424
-        EE_Error::doing_it_wrong(
425
-            __METHOD__,
426
-            esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
427
-            '4.9.0'
428
-        );
429
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
430
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
431
-        return $Message_Resource_Manager->get_active_messengers_option();
432
-    }
433
-
434
-
435
-    /**
436
-     * Used to update the active messengers array stored in the wp options table.
437
-     *
438
-     * @since      4.3.1
439
-     * @deprecated 4.9.0
440
-     *
441
-     * @param array $data_to_save Incoming data to save.
442
-     *
443
-     * @return bool FALSE if not updated, TRUE if updated.
444
-     * @throws EE_Error
445
-     * @throws ReflectionException
446
-     */
447
-    public static function update_active_messengers_in_db($data_to_save)
448
-    {
449
-        EE_Error::doing_it_wrong(
450
-            __METHOD__,
451
-            esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
452
-            '4.9.0'
453
-        );
454
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
455
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
456
-        return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
457
-    }
458
-
459
-
460
-    /**
461
-     * This does some validation of incoming params, determines what type of url is being prepped and returns the
462
-     * appropriate url trigger
463
-     *
464
-     * @param EE_message_type $message_type
465
-     * @param EE_Message $message
466
-     * @param EE_Registration | null $registration  The registration object must be included if this
467
-     *                                              is going to be a registration trigger url.
468
-     * @param string $sending_messenger             The (optional) sending messenger for the url.
469
-     *
470
-     * @return string
471
-     * @throws EE_Error
472
-     */
473
-    public static function get_url_trigger(
474
-        EE_message_type $message_type,
475
-        EE_Message $message,
476
-        $registration = null,
477
-        $sending_messenger = ''
478
-    ) {
479
-        // first determine if the url can be to the EE_Message object.
480
-        if (! $message_type->always_generate()) {
481
-            return EEH_MSG_Template::generate_browser_trigger($message);
482
-        }
483
-
484
-        // if $registration object is not valid then exit early because there's nothing that can be generated.
485
-        if (! $registration instanceof EE_Registration) {
486
-            throw new EE_Error(
487
-                esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
488
-            );
489
-        }
490
-
491
-        // validate given context
492
-        $contexts = $message_type->get_contexts();
493
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
494
-            throw new EE_Error(
495
-                sprintf(
496
-                    esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
497
-                    $message->context(),
498
-                    get_class($message_type)
499
-                )
500
-            );
501
-        }
502
-
503
-        // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
504
-        if (! empty($sending_messenger)) {
505
-            $with_messengers = $message_type->with_messengers();
506
-            if (
507
-                ! isset($with_messengers[ $message->messenger() ])
508
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
509
-            ) {
510
-                throw new EE_Error(
511
-                    sprintf(
512
-                        esc_html__(
513
-                            'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
514
-                            'event_espresso'
515
-                        ),
516
-                        $sending_messenger,
517
-                        get_class($message_type)
518
-                    )
519
-                );
520
-            }
521
-        } else {
522
-            $sending_messenger = $message->messenger();
523
-        }
524
-        return EEH_MSG_Template::generate_url_trigger(
525
-            $sending_messenger,
526
-            $message->messenger(),
527
-            $message->context(),
528
-            $message->message_type(),
529
-            $registration,
530
-            $message->GRP_ID()
531
-        );
532
-    }
533
-
534
-
535
-    /**
536
-     * This returns the url for triggering a in browser view of a specific EE_Message object.
537
-     * @param EE_Message $message
538
-     * @return string.
539
-     */
540
-    public static function generate_browser_trigger(EE_Message $message)
541
-    {
542
-        $query_args = array(
543
-            'ee' => 'msg_browser_trigger',
544
-            'token' => $message->MSG_token()
545
-        );
546
-        return apply_filters(
547
-            'FHEE__EEH_MSG_Template__generate_browser_trigger',
548
-            add_query_arg($query_args, site_url()),
549
-            $message
550
-        );
551
-    }
552
-
553
-
554
-
555
-
556
-
557
-
558
-    /**
559
-     * This returns the url for triggering an in browser view of the error saved on the incoming message object.
560
-     * @param EE_Message $message
561
-     * @return string
562
-     */
563
-    public static function generate_error_display_trigger(EE_Message $message)
564
-    {
565
-        return apply_filters(
566
-            'FHEE__EEH_MSG_Template__generate_error_display_trigger',
567
-            add_query_arg(
568
-                array(
569
-                    'ee' => 'msg_browser_error_trigger',
570
-                    'token' => $message->MSG_token()
571
-                ),
572
-                site_url()
573
-            ),
574
-            $message
575
-        );
576
-    }
577
-
578
-
579
-    /**
580
-     * This generates a url trigger for the msg_url_trigger route using the given arguments
581
-     *
582
-     * @param string          $sending_messenger      The sending messenger slug.
583
-     * @param string          $generating_messenger   The generating messenger slug.
584
-     * @param string          $context                The context for the template.
585
-     * @param string          $message_type           The message type slug
586
-     * @param EE_Registration $registration
587
-     * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
588
-     * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
589
-     *                                                trigger.
590
-     * @return string          The generated url.
591
-     * @throws EE_Error
592
-     */
593
-    public static function generate_url_trigger(
594
-        $sending_messenger,
595
-        $generating_messenger,
596
-        $context,
597
-        $message_type,
598
-        EE_Registration $registration,
599
-        $message_template_group,
600
-        $data_id = 0
601
-    ) {
602
-        $query_args = array(
603
-            'ee' => 'msg_url_trigger',
604
-            'snd_msgr' => $sending_messenger,
605
-            'gen_msgr' => $generating_messenger,
606
-            'message_type' => $message_type,
607
-            'context' => $context,
608
-            'token' => $registration->reg_url_link(),
609
-            'GRP_ID' => $message_template_group,
610
-            'id' => $data_id
611
-            );
612
-        $url = add_query_arg($query_args, get_home_url());
613
-
614
-        // made it here so now we can just get the url and filter it.  Filtered globally and by message type.
615
-        return apply_filters(
616
-            'FHEE__EEH_MSG_Template__generate_url_trigger',
617
-            $url,
618
-            $sending_messenger,
619
-            $generating_messenger,
620
-            $context,
621
-            $message_type,
622
-            $registration,
623
-            $message_template_group,
624
-            $data_id
625
-        );
626
-    }
627
-
628
-
629
-
630
-
631
-    /**
632
-     * Return the specific css for the action icon given.
633
-     *
634
-     * @param string $type  What action to return.
635
-     * @return string[]
636
-     * @since 4.9.0
637
-     */
638
-    public static function get_message_action_icon($type)
639
-    {
640
-        $action_icons = self::get_message_action_icons();
641
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
642
-    }
643
-
644
-
645
-    /**
646
-     * This is used for retrieving the css classes used for the icons representing message actions.
647
-     *
648
-     * @since 4.9.0
649
-     *
650
-     * @return array
651
-     */
652
-    public static function get_message_action_icons()
653
-    {
654
-        return apply_filters(
655
-            'FHEE__EEH_MSG_Template__message_action_icons',
656
-            array(
657
-                'view' => array(
658
-                    'label' => esc_html__('View Message', 'event_espresso'),
659
-                    'css_class' => 'dashicons dashicons-welcome-view-site',
660
-                ),
661
-                'error' => array(
662
-                    'label' => esc_html__('View Error Message', 'event_espresso'),
663
-                    'css_class' => 'dashicons dashicons-info',
664
-                ),
665
-                'see_notifications_for' => array(
666
-                    'label' => esc_html__('View Related Messages', 'event_espresso'),
667
-                    'css_class' => 'dashicons dashicons-megaphone',
668
-                ),
669
-                'generate_now' => array(
670
-                    'label' => esc_html__('Generate the message now.', 'event_espresso'),
671
-                    'css_class' => 'dashicons dashicons-admin-tools',
672
-                ),
673
-                'send_now' => array(
674
-                    'label' => esc_html__('Send Immediately', 'event_espresso'),
675
-                    'css_class' => 'dashicons dashicons-controls-forward',
676
-                ),
677
-                'queue_for_resending' => array(
678
-                    'label' => esc_html__('Queue for Resending', 'event_espresso'),
679
-                    'css_class' => 'dashicons dashicons-controls-repeat',
680
-                ),
681
-                'view_transaction' => array(
682
-                    'label' => esc_html__('View related Transaction', 'event_espresso'),
683
-                    'css_class' => 'dashicons dashicons-cart',
684
-                )
685
-            )
686
-        );
687
-    }
688
-
689
-
690
-    /**
691
-     * This returns the url for a given action related to EE_Message.
692
-     *
693
-     * @param string     $type         What type of action to return the url for.
694
-     * @param EE_Message $message      Required for generating the correct url for some types.
695
-     * @param array      $query_params Any additional query params to be included with the generated url.
696
-     *
697
-     * @return string
698
-     * @throws EE_Error
699
-     * @throws ReflectionException
700
-     * @since 4.9.0
701
-     *
702
-     */
703
-    public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
704
-    {
705
-        $action_urls = self::get_message_action_urls($message, $query_params);
706
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
707
-    }
708
-
709
-
710
-    /**
711
-     * This returns all the current urls for EE_Message actions.
712
-     *
713
-     * @since 4.9.0
714
-     *
715
-     * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
716
-     * @param array      $query_params Any additional query_params to be included with the generated url.
717
-     *
718
-     * @return array
719
-     * @throws EE_Error
720
-     * @throws ReflectionException
721
-     */
722
-    public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
723
-    {
724
-        EE_Registry::instance()->load_helper('URL');
725
-        // if $message is not an instance of EE_Message then let's just do a dummy.
726
-        $message = empty($message) ? EE_Message_Factory::create() : $message;
727
-        $action_urls =  apply_filters(
728
-            'FHEE__EEH_MSG_Template__get_message_action_url',
729
-            array(
730
-                'view' => EEH_MSG_Template::generate_browser_trigger($message),
731
-                'error' => EEH_MSG_Template::generate_error_display_trigger($message),
732
-                'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
733
-                    array_merge(
734
-                        array(
735
-                            'page' => 'espresso_messages',
736
-                            'action' => 'default',
737
-                            'filterby' => 1,
738
-                        ),
739
-                        $query_params
740
-                    ),
741
-                    admin_url('admin.php')
742
-                ),
743
-                'generate_now' => EEH_URL::add_query_args_and_nonce(
744
-                    array(
745
-                        'page' => 'espresso_messages',
746
-                        'action' => 'generate_now',
747
-                        'MSG_ID' => $message->ID()
748
-                    ),
749
-                    admin_url('admin.php')
750
-                ),
751
-                'send_now' => EEH_URL::add_query_args_and_nonce(
752
-                    array(
753
-                        'page' => 'espresso_messages',
754
-                        'action' => 'send_now',
755
-                        'MSG_ID' => $message->ID()
756
-                    ),
757
-                    admin_url('admin.php')
758
-                ),
759
-                'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
760
-                    array(
761
-                        'page' => 'espresso_messages',
762
-                        'action' => 'queue_for_resending',
763
-                        'MSG_ID' => $message->ID()
764
-                    ),
765
-                    admin_url('admin.php')
766
-                ),
767
-            )
768
-        );
769
-        if (
770
-            $message->TXN_ID() > 0
771
-            && EE_Registry::instance()->CAP->current_user_can(
772
-                'ee_read_transaction',
773
-                'espresso_transactions_default',
774
-                $message->TXN_ID()
775
-            )
776
-        ) {
777
-            $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
778
-                array(
779
-                    'page' => 'espresso_transactions',
780
-                    'action' => 'view_transaction',
781
-                    'TXN_ID' => $message->TXN_ID()
782
-                ),
783
-                admin_url('admin.php')
784
-            );
785
-        } else {
786
-            $action_urls['view_transaction'] = '';
787
-        }
788
-        return $action_urls;
789
-    }
790
-
791
-
792
-    /**
793
-     * This returns a generated link html including the icon used for the action link for EE_Message actions.
794
-     *
795
-     * @param string          $type         What type of action the link is for (if invalid type is passed in then an
796
-     *                                      empty string is returned)
797
-     * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
798
-     * @param array           $query_params Any extra query params to include in the generated link.
799
-     *
800
-     * @return string
801
-     * @throws EE_Error
802
-     * @throws ReflectionException
803
-     * @since 4.9.0
804
-     *
805
-     */
806
-    public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
807
-    {
808
-        $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
809
-        $icon_css = EEH_MSG_Template::get_message_action_icon($type);
810
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
811
-
812
-        if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
813
-            return '';
814
-        }
815
-
816
-        $icon_css['css_class'] .= esc_attr(
817
-            apply_filters(
818
-                'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
819
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
820
-                $type,
821
-                $message,
822
-                $query_params
823
-            )
824
-        );
825
-
826
-        return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
827
-    }
828
-
829
-
830
-
831
-
832
-
833
-    /**
834
-     * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
835
-     *
836
-     * @since 4.9.0
837
-     * @return array
838
-     */
839
-    public static function reg_status_to_message_type_array()
840
-    {
841
-        return (array) apply_filters(
842
-            'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
843
-            array(
844
-                EEM_Registration::status_id_approved => 'registration',
845
-                EEM_Registration::status_id_pending_payment => 'pending_approval',
846
-                EEM_Registration::status_id_not_approved => 'not_approved_registration',
847
-                EEM_Registration::status_id_cancelled => 'cancelled_registration',
848
-                EEM_Registration::status_id_declined => 'declined_registration'
849
-            )
850
-        );
851
-    }
852
-
853
-
854
-
855
-
856
-    /**
857
-     * This returns the corresponding registration message type slug to the given reg status. If there isn't a
858
-     * match, then returns an empty string.
859
-     *
860
-     * @since 4.9.0
861
-     * @param $reg_status
862
-     * @return string
863
-     */
864
-    public static function convert_reg_status_to_message_type($reg_status)
865
-    {
866
-        $reg_status_array = self::reg_status_to_message_type_array();
867
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
868
-    }
869
-
870
-
871
-    /**
872
-     * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
873
-     *
874
-     * @since 4.9.0
875
-     * @return array
876
-     */
877
-    public static function payment_status_to_message_type_array()
878
-    {
879
-        return (array) apply_filters(
880
-            'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
881
-            array(
882
-                EEM_Payment::status_id_approved => 'payment',
883
-                EEM_Payment::status_id_pending => 'payment_pending',
884
-                EEM_Payment::status_id_cancelled => 'payment_cancelled',
885
-                EEM_Payment::status_id_declined => 'payment_declined',
886
-                EEM_Payment::status_id_failed => 'payment_failed'
887
-            )
888
-        );
889
-    }
890
-
891
-
892
-
893
-
894
-    /**
895
-     * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
896
-     * an empty string is returned
897
-     *
898
-     * @since 4.9.0
899
-     * @param $payment_status
900
-     * @return string
901
-     */
902
-    public static function convert_payment_status_to_message_type($payment_status)
903
-    {
904
-        $payment_status_array = self::payment_status_to_message_type_array();
905
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
906
-    }
907
-
908
-
909
-    /**
910
-     * This is used to retrieve the template pack for the given name.
911
-     *
912
-     * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
913
-     *
914
-     * @return EE_Messages_Template_Pack
915
-     */
916
-    public static function get_template_pack($template_pack_name)
917
-    {
918
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
919
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
920
-        }
921
-
922
-        // first see if in collection already
923
-        $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
924
-
925
-        if ($template_pack instanceof EE_Messages_Template_Pack) {
926
-            return $template_pack;
927
-        }
928
-
929
-        // nope...let's get it.
930
-        // not set yet so let's attempt to get it.
931
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
932
-            ' ',
933
-            '_',
934
-            ucwords(
935
-                str_replace('_', ' ', $template_pack_name)
936
-            )
937
-        );
938
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
939
-            return self::get_template_pack('default');
940
-        } else {
941
-            $template_pack = new $pack_class_name();
942
-            self::$_template_pack_collection->add($template_pack);
943
-            return $template_pack;
944
-        }
945
-    }
946
-
947
-
948
-
949
-
950
-    /**
951
-     * Globs template packs installed in core and returns the template pack collection with all installed template packs
952
-     * in it.
953
-     *
954
-     * @since 4.9.0
955
-     *
956
-     * @return EE_Messages_Template_Pack_Collection
957
-     */
958
-    public static function get_template_pack_collection()
959
-    {
960
-        $new_collection = false;
961
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
962
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
963
-            $new_collection = true;
964
-        }
965
-
966
-        // glob the defaults directory for messages
967
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
968
-        foreach ($templates as $template_path) {
969
-            // grab folder name
970
-            $template = basename($template_path);
971
-
972
-            if (! $new_collection) {
973
-                // already have it?
974
-                if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
975
-                    continue;
976
-                }
977
-            }
978
-
979
-            // setup classname.
980
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
981
-                ' ',
982
-                '_',
983
-                ucwords(
984
-                    str_replace(
985
-                        '_',
986
-                        ' ',
987
-                        $template
988
-                    )
989
-                )
990
-            );
991
-            if (! class_exists($template_pack_class_name)) {
992
-                continue;
993
-            }
994
-            self::$_template_pack_collection->add(new $template_pack_class_name());
995
-        }
996
-
997
-        /**
998
-         * Filter for plugins to add in any additional template packs
999
-         * Note the filter name here is for backward compat, this used to be found in EED_Messages.
1000
-         */
1001
-        $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1002
-        foreach ((array) $additional_template_packs as $template_pack) {
1003
-            if (
1004
-                self::$_template_pack_collection->get_by_name(
1005
-                    $template_pack->dbref
1006
-                ) instanceof EE_Messages_Template_Pack
1007
-            ) {
1008
-                continue;
1009
-            }
1010
-            self::$_template_pack_collection->add($template_pack);
1011
-        }
1012
-        return self::$_template_pack_collection;
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * This is a wrapper for the protected _create_new_templates function
1018
-     *
1019
-     * @param string $messenger_name
1020
-     * @param string $message_type_name message type that the templates are being created for
1021
-     * @param int    $GRP_ID
1022
-     * @param bool   $global
1023
-     * @return array
1024
-     * @throws EE_Error
1025
-     * @throws ReflectionException
1026
-     */
1027
-    public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1028
-    {
1029
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1030
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1031
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1032
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1033
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1034
-            return array();
1035
-        }
1036
-        // whew made it this far!  Okay, let's go ahead and create the templates then
1037
-        return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1038
-    }
1039
-
1040
-
1041
-    /**
1042
-     * @param EE_messenger     $messenger
1043
-     * @param EE_message_type  $message_type
1044
-     * @param                  $GRP_ID
1045
-     * @param                  $global
1046
-     * @return array|mixed
1047
-     * @throws EE_Error
1048
-     * @throws ReflectionException
1049
-     */
1050
-    protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1051
-    {
1052
-        // if we're creating a custom template then we don't need to use the defaults class
1053
-        if (! $global) {
1054
-            return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1055
-        }
1056
-        /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1057
-        $Message_Template_Defaults = EE_Registry::factory(
1058
-            'EE_Messages_Template_Defaults',
1059
-            array( $messenger, $message_type, $GRP_ID )
1060
-        );
1061
-        // generate templates
1062
-        $success = $Message_Template_Defaults->create_new_templates();
1063
-
1064
-        // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1065
-        // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1066
-        // attempts.
1067
-        if (! $success) {
1068
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
1069
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1070
-            $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1071
-        }
1072
-
1073
-        /**
1074
-         * $success is in an array in the following format
1075
-         * array(
1076
-         *    'GRP_ID' => $new_grp_id,
1077
-         *    'MTP_context' => $first_context_in_new_templates,
1078
-         * )
1079
-         */
1080
-        return $success;
1081
-    }
1082
-
1083
-
1084
-    /**
1085
-     * This creates a custom template using the incoming GRP_ID
1086
-     *
1087
-     * @param EE_messenger    $messenger
1088
-     * @param EE_message_type $message_type
1089
-     * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1090
-     * @return  array $success              This will be an array in the format:
1091
-     *                                          array(
1092
-     *                                          'GRP_ID' => $new_grp_id,
1093
-     *                                          'MTP_context' => $first_context_in_created_template
1094
-     *                                          )
1095
-     * @throws EE_Error
1096
-     * @throws ReflectionException
1097
-     * @access private
1098
-     */
1099
-    private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1100
-    {
1101
-        // defaults
1102
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1103
-        // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1104
-        $Message_Template_Group = empty($GRP_ID)
1105
-            ? EEM_Message_Template_Group::instance()->get_one(
1106
-                array(
1107
-                    array(
1108
-                        'MTP_messenger'    => $messenger->name,
1109
-                        'MTP_message_type' => $message_type->name,
1110
-                        'MTP_is_global'    => true
1111
-                    )
1112
-                )
1113
-            )
1114
-            : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1115
-        // if we don't have a mtg at this point then we need to bail.
1116
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1117
-            EE_Error::add_error(
1118
-                sprintf(
1119
-                    esc_html__(
1120
-                        'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1121
-                        'event_espresso'
1122
-                    ),
1123
-                    $GRP_ID
1124
-                ),
1125
-                __FILE__,
1126
-                __FUNCTION__,
1127
-                __LINE__
1128
-            );
1129
-            return $success;
1130
-        }
1131
-        // let's get all the related message_template objects for this group.
1132
-        $message_templates = $Message_Template_Group->message_templates();
1133
-        // now we have what we need to setup the new template
1134
-        $new_mtg = clone $Message_Template_Group;
1135
-        $new_mtg->set('GRP_ID', 0);
1136
-        $new_mtg->set('MTP_is_global', false);
1137
-
1138
-        /** @var RequestInterface $request */
1139
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1140
-        $template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1141
-            ? $request->getRequestParam('templateName')
1142
-            : esc_html__('New Custom Template', 'event_espresso');
1143
-        $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1144
-            ? $request->getRequestParam('templateDescription')
1145
-            : sprintf(
1146
-                esc_html__(
1147
-                    'This is a custom template that was created for the %s messenger and %s message type.',
1148
-                    'event_espresso'
1149
-                ),
1150
-                $new_mtg->messenger_obj()->label['singular'],
1151
-                $new_mtg->message_type_obj()->label['singular']
1152
-            );
1153
-        $new_mtg->set('MTP_name', $template_name);
1154
-        $new_mtg->set('MTP_description', $template_description);
1155
-        // remove ALL relations on this template group so they don't get saved!
1156
-        $new_mtg->_remove_relations('Message_Template');
1157
-        $new_mtg->save();
1158
-        $success['GRP_ID'] = $new_mtg->ID();
1159
-        $success['template_name'] = $template_name;
1160
-        // add new message templates and add relation to.
1161
-        foreach ($message_templates as $message_template) {
1162
-            if (! $message_template instanceof EE_Message_Template) {
1163
-                continue;
1164
-            }
1165
-            $new_message_template = clone $message_template;
1166
-            $new_message_template->set('MTP_ID', 0);
1167
-            $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1168
-            $new_message_template->save();
1169
-            if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') {
1170
-                $success['MTP_context'] = $new_message_template->get('MTP_context');
1171
-            }
1172
-        }
1173
-        return $success;
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * message_type_has_active_templates_for_messenger
1179
-     *
1180
-     * @param EE_messenger    $messenger
1181
-     * @param EE_message_type $message_type
1182
-     * @param bool            $global
1183
-     * @return bool
1184
-     * @throws EE_Error
1185
-     */
1186
-    public static function message_type_has_active_templates_for_messenger(
1187
-        EE_messenger $messenger,
1188
-        EE_message_type $message_type,
1189
-        $global = false
1190
-    ) {
1191
-        // is given message_type valid for given messenger (if this is not a global save)
1192
-        if ($global) {
1193
-            return true;
1194
-        }
1195
-        $active_templates = EEM_Message_Template_Group::instance()->count(
1196
-            array(
1197
-                array(
1198
-                    'MTP_is_active'    => true,
1199
-                    'MTP_messenger'    => $messenger->name,
1200
-                    'MTP_message_type' => $message_type->name
1201
-                )
1202
-            )
1203
-        );
1204
-        if ($active_templates > 0) {
1205
-            return true;
1206
-        }
1207
-        EE_Error::add_error(
1208
-            sprintf(
1209
-                esc_html__(
1210
-                    'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1211
-                    'event_espresso'
1212
-                ),
1213
-                $message_type->name,
1214
-                $messenger->name
1215
-            ),
1216
-            __FILE__,
1217
-            __FUNCTION__,
1218
-            __LINE__
1219
-        );
1220
-        return false;
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * get_fields
1226
-     * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1227
-     *
1228
-     * @param string $messenger_name    name of EE_messenger
1229
-     * @param string $message_type_name name of EE_message_type
1230
-     * @return array
1231
-     * @throws EE_Error
1232
-     * @throws ReflectionException
1233
-     */
1234
-    public static function get_fields($messenger_name, $message_type_name)
1235
-    {
1236
-        $template_fields = array();
1237
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1238
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1239
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1240
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1241
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1242
-            return array();
1243
-        }
1244
-
1245
-        $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1246
-
1247
-        // okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1248
-        foreach ($message_type->get_contexts() as $context => $details) {
1249
-            foreach ($messenger->get_template_fields() as $field => $value) {
1250
-                if (in_array($field, $excluded_fields_for_messenger, true)) {
1251
-                    continue;
1252
-                }
1253
-                $template_fields[ $context ][ $field ] = $value;
1254
-            }
1255
-        }
1256
-        if (empty($template_fields)) {
1257
-            EE_Error::add_error(
1258
-                esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1259
-                __FILE__,
1260
-                __FUNCTION__,
1261
-                __LINE__
1262
-            );
1263
-            return array();
1264
-        }
1265
-        return $template_fields;
1266
-    }
18
+	/**
19
+	 * Holds a collection of EE_Message_Template_Pack objects.
20
+	 * @type EE_Messages_Template_Pack_Collection
21
+	 */
22
+	protected static $_template_pack_collection;
23
+
24
+
25
+	/**
26
+	 * @throws EE_Error
27
+	 */
28
+	private static function _set_autoloader()
29
+	{
30
+		EED_Messages::set_autoloaders();
31
+	}
32
+
33
+
34
+	/**
35
+	 * generate_new_templates
36
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
37
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
38
+	 * for the event.
39
+	 *
40
+	 * @access protected
41
+	 * @param string $messenger     the messenger we are generating templates for
42
+	 * @param array  $message_types array of message types that the templates are generated for.
43
+	 * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
44
+	 *                              to use as the base for the new generated template.
45
+	 * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
46
+	 *                              for event specific template generation.
47
+	 * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
48
+	 *                for templates that are generated.  If this is an empty array then it means no templates were
49
+	 *                generated which usually means there was an error.  Anything in the array with an empty value for
50
+	 *                `MTP_context` means that it was not a new generated template but just reactivated (which only
51
+	 *                happens for global templates that already exist in the database.
52
+	 * @throws EE_Error
53
+	 * @throws ReflectionException
54
+	 */
55
+	public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
56
+	{
57
+		// make sure message_type is an array.
58
+		$message_types = (array) $message_types;
59
+		$templates = array();
60
+
61
+		if (empty($messenger)) {
62
+			throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
63
+		}
64
+
65
+		// if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
66
+		if (empty($message_types)) {
67
+			throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
68
+		}
69
+
70
+		EEH_MSG_Template::_set_autoloader();
71
+		foreach ($message_types as $message_type) {
72
+			// if this is global template generation.
73
+			if ($global) {
74
+				// let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
75
+				if (empty($GRP_ID)) {
76
+					$GRP_ID = EEM_Message_Template_Group::instance()->get_one(
77
+						array(
78
+							array(
79
+								'MTP_messenger'    => $messenger,
80
+								'MTP_message_type' => $message_type,
81
+								'MTP_is_global'    => true,
82
+							),
83
+						)
84
+					);
85
+					$GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
86
+				}
87
+				// First let's determine if we already HAVE global templates for this messenger and message_type combination.
88
+				//  If we do then NO generation!!
89
+				if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
90
+					$templates[] = array(
91
+						'GRP_ID' => $GRP_ID,
92
+						'MTP_context' => '',
93
+					);
94
+					// we already have generated templates for this so let's go to the next message type.
95
+					continue;
96
+				}
97
+			}
98
+			$new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
99
+
100
+			if (! $new_message_template_group) {
101
+				continue;
102
+			}
103
+			$templates[] = $new_message_template_group;
104
+		}
105
+
106
+		return $templates;
107
+	}
108
+
109
+
110
+	/**
111
+	 * The purpose of this method is to determine if there are already generated templates in the database for the
112
+	 * given variables.
113
+	 *
114
+	 * @param string $messenger    messenger
115
+	 * @param string $message_type message type
116
+	 * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
117
+	 *                             template check)
118
+	 * @return bool                true = generated, false = hasn't been generated.
119
+	 * @throws EE_Error
120
+	 */
121
+	public static function already_generated($messenger, $message_type, $GRP_ID = 0)
122
+	{
123
+		EEH_MSG_Template::_set_autoloader();
124
+		// what method we use depends on whether we have an GRP_ID or not
125
+		$count = empty($GRP_ID)
126
+			? EEM_Message_Template::instance()->count(
127
+				array(
128
+					array(
129
+						'Message_Template_Group.MTP_messenger'    => $messenger,
130
+						'Message_Template_Group.MTP_message_type' => $message_type,
131
+						'Message_Template_Group.MTP_is_global'    => true
132
+					)
133
+				)
134
+			)
135
+			: EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
136
+
137
+		return $count > 0;
138
+	}
139
+
140
+
141
+	/**
142
+	 * Updates all message templates matching the incoming messengers and message types to active status.
143
+	 *
144
+	 * @static
145
+	 * @param array $messenger_names    Messenger slug
146
+	 * @param array $message_type_names Message type slug
147
+	 * @return  int                         count of updated records.
148
+	 * @throws EE_Error
149
+	 */
150
+	public static function update_to_active($messenger_names, $message_type_names)
151
+	{
152
+		$messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
153
+		$message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
154
+		return EEM_Message_Template_Group::instance()->update(
155
+			array( 'MTP_is_active' => 1 ),
156
+			array(
157
+				array(
158
+					'MTP_messenger'     => array( 'IN', $messenger_names ),
159
+					'MTP_message_type'  => array( 'IN', $message_type_names )
160
+				)
161
+			)
162
+		);
163
+	}
164
+
165
+
166
+	/**
167
+	 * Updates all message template groups matching the incoming arguments to inactive status.
168
+	 *
169
+	 * @static
170
+	 * @param array $messenger_names    The messenger slugs.
171
+	 *                                  If empty then all templates matching the message types are marked inactive.
172
+	 *                                  Otherwise only templates matching the messengers and message types.
173
+	 * @param array $message_type_names The message type slugs.
174
+	 *                                  If empty then all templates matching the messengers are marked inactive.
175
+	 *                                  Otherwise only templates matching the messengers and message types.
176
+	 *
177
+	 * @return int  count of updated records.
178
+	 * @throws EE_Error
179
+	 */
180
+	public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
181
+	{
182
+		return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
183
+			$messenger_names,
184
+			$message_type_names
185
+		);
186
+	}
187
+
188
+
189
+	/**
190
+	 * The purpose of this function is to return all installed message objects
191
+	 * (messengers and message type regardless of whether they are ACTIVE or not)
192
+	 *
193
+	 * @param string $type
194
+	 * @return array array consisting of installed messenger objects and installed message type objects.
195
+	 * @throws EE_Error
196
+	 * @throws ReflectionException
197
+	 * @deprecated 4.9.0
198
+	 * @static
199
+	 */
200
+	public static function get_installed_message_objects($type = 'all')
201
+	{
202
+		self::_set_autoloader();
203
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
204
+		return array(
205
+			'messenger' => $message_resource_manager->installed_messengers(),
206
+			'message_type' => $message_resource_manager->installed_message_types()
207
+		);
208
+	}
209
+
210
+
211
+	/**
212
+	 * This will return an array of shortcodes => labels from the
213
+	 * messenger and message_type objects associated with this
214
+	 * template.
215
+	 *
216
+	 * @param string $message_type
217
+	 * @param string $messenger
218
+	 * @param array  $fields                        What fields we're returning valid shortcodes for.
219
+	 *                                              If empty then we assume all fields are to be returned. Optional.
220
+	 * @param string $context                       What context we're going to return shortcodes for. Optional.
221
+	 * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
222
+	 *                                              but instead an array of the unique shortcodes for all the given (
223
+	 *                                              or all) fields. Optional.
224
+	 * @return array                                an array of shortcodes in the format
225
+	 *                                              array( '[shortcode] => 'label')
226
+	 *                                              OR
227
+	 *                                              FALSE if no shortcodes found.
228
+	 * @throws ReflectionException
229
+	 * @throws EE_Error*@since 4.3.0
230
+	 *
231
+	 */
232
+	public static function get_shortcodes(
233
+		$message_type,
234
+		$messenger,
235
+		$fields = array(),
236
+		$context = 'admin',
237
+		$merged = false
238
+	) {
239
+		$messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
240
+		$mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
241
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
242
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
243
+		// convert slug to object
244
+		$messenger = $message_resource_manager->get_messenger($messenger);
245
+
246
+		// if messenger isn't a EE_messenger resource then bail.
247
+		if (! $messenger instanceof EE_messenger) {
248
+			return array();
249
+		}
250
+
251
+		// validate class for getting our list of shortcodes
252
+		$classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
253
+		if (! class_exists($classname)) {
254
+			$msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
255
+			$msg[] = sprintf(
256
+				esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
257
+				$classname
258
+			);
259
+			throw new EE_Error(implode('||', $msg));
260
+		}
261
+
262
+		/** @type EE_Messages_Validator $_VLD */
263
+		$_VLD = new $classname(array(), $context);
264
+		$valid_shortcodes = $_VLD->get_validators();
265
+
266
+		// let's make sure we're only getting the shortcode part of the validators
267
+		$shortcodes = array();
268
+		foreach ($valid_shortcodes as $field => $validators) {
269
+			$shortcodes[ $field ] = $validators['shortcodes'];
270
+		}
271
+		$valid_shortcodes = $shortcodes;
272
+
273
+		// if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
274
+		if (! empty($fields)) {
275
+			$specified_shortcodes = array();
276
+			foreach ($fields as $field) {
277
+				if (isset($valid_shortcodes[ $field ])) {
278
+					$specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
279
+				}
280
+			}
281
+			$valid_shortcodes = $specified_shortcodes;
282
+		}
283
+
284
+		// if not merged then let's replace the fields with the localized fields
285
+		if (! $merged) {
286
+			// let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
287
+			$field_settings = $messenger->get_template_fields();
288
+			$localized = array();
289
+			foreach ($valid_shortcodes as $field => $shortcodes) {
290
+				// get localized field label
291
+				if (isset($field_settings[ $field ])) {
292
+					// possible that this is used as a main field.
293
+					if (empty($field_settings[ $field ])) {
294
+						if (isset($field_settings['extra'][ $field ])) {
295
+							$_field = $field_settings['extra'][ $field ]['main']['label'];
296
+						} else {
297
+							$_field = $field;
298
+						}
299
+					} else {
300
+						$_field = $field_settings[ $field ]['label'];
301
+					}
302
+				} elseif (isset($field_settings['extra'])) {
303
+					// loop through extra "main fields" and see if any of their children have our field
304
+					foreach ($field_settings['extra'] as $fields) {
305
+						if (isset($fields[ $field ])) {
306
+							$_field = $fields[ $field ]['label'];
307
+						} else {
308
+							$_field = $field;
309
+						}
310
+					}
311
+				} else {
312
+					$_field = $field;
313
+				}
314
+				if (isset($_field)) {
315
+					$localized[ (string) $_field ] = $shortcodes;
316
+				}
317
+			}
318
+			$valid_shortcodes = $localized;
319
+		}
320
+
321
+		// if $merged then let's merge all the shortcodes into one list NOT indexed by field.
322
+		if ($merged) {
323
+			$merged_codes = array();
324
+			foreach ($valid_shortcodes as $shortcode) {
325
+				foreach ($shortcode as $code => $label) {
326
+					if (isset($merged_codes[ $code ])) {
327
+						continue;
328
+					} else {
329
+						$merged_codes[ $code ] = $label;
330
+					}
331
+				}
332
+			}
333
+			$valid_shortcodes = $merged_codes;
334
+		}
335
+
336
+		return $valid_shortcodes;
337
+	}
338
+
339
+
340
+	/**
341
+	 * Get Messenger object.
342
+	 *
343
+	 * @param string $messenger messenger slug for the messenger object we want to retrieve.
344
+	 * @return EE_messenger
345
+	 * @throws ReflectionException
346
+	 * @throws EE_Error*@since 4.3.0
347
+	 * @deprecated 4.9.0
348
+	 */
349
+	public static function messenger_obj($messenger)
350
+	{
351
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
352
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
353
+		return $Message_Resource_Manager->get_messenger($messenger);
354
+	}
355
+
356
+
357
+	/**
358
+	 * get Message type object
359
+	 *
360
+	 * @param string $message_type the slug for the message type object to retrieve
361
+	 * @return EE_message_type
362
+	 * @throws ReflectionException
363
+	 * @throws EE_Error*@since 4.3.0
364
+	 * @deprecated 4.9.0
365
+	 */
366
+	public static function message_type_obj($message_type)
367
+	{
368
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
369
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
370
+		return $Message_Resource_Manager->get_message_type($message_type);
371
+	}
372
+
373
+
374
+	/**
375
+	 * Given a message_type slug, will return whether that message type is active in the system or not.
376
+	 *
377
+	 * @since    4.3.0
378
+	 * @param string $message_type message type to check for.
379
+	 * @return boolean
380
+	 * @throws EE_Error
381
+	 * @throws ReflectionException
382
+	 */
383
+	public static function is_mt_active($message_type)
384
+	{
385
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
386
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
387
+		$active_mts = $Message_Resource_Manager->list_of_active_message_types();
388
+		return in_array($message_type, $active_mts);
389
+	}
390
+
391
+
392
+	/**
393
+	 * Given a messenger slug, will return whether that messenger is active in the system or not.
394
+	 *
395
+	 * @since    4.3.0
396
+	 *
397
+	 * @param string $messenger slug for messenger to check.
398
+	 * @return boolean
399
+	 * @throws EE_Error
400
+	 * @throws ReflectionException
401
+	 */
402
+	public static function is_messenger_active($messenger)
403
+	{
404
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
405
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
406
+		$active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
407
+		return $active_messenger instanceof EE_messenger;
408
+	}
409
+
410
+
411
+	/**
412
+	 * Used to return active messengers array stored in the wp options table.
413
+	 * If no value is present in the option then an empty array is returned.
414
+	 *
415
+	 * @deprecated 4.9
416
+	 * @since      4.3.1
417
+	 *
418
+	 * @return array
419
+	 * @throws EE_Error
420
+	 * @throws ReflectionException
421
+	 */
422
+	public static function get_active_messengers_in_db()
423
+	{
424
+		EE_Error::doing_it_wrong(
425
+			__METHOD__,
426
+			esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
427
+			'4.9.0'
428
+		);
429
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
430
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
431
+		return $Message_Resource_Manager->get_active_messengers_option();
432
+	}
433
+
434
+
435
+	/**
436
+	 * Used to update the active messengers array stored in the wp options table.
437
+	 *
438
+	 * @since      4.3.1
439
+	 * @deprecated 4.9.0
440
+	 *
441
+	 * @param array $data_to_save Incoming data to save.
442
+	 *
443
+	 * @return bool FALSE if not updated, TRUE if updated.
444
+	 * @throws EE_Error
445
+	 * @throws ReflectionException
446
+	 */
447
+	public static function update_active_messengers_in_db($data_to_save)
448
+	{
449
+		EE_Error::doing_it_wrong(
450
+			__METHOD__,
451
+			esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
452
+			'4.9.0'
453
+		);
454
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
455
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
456
+		return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
457
+	}
458
+
459
+
460
+	/**
461
+	 * This does some validation of incoming params, determines what type of url is being prepped and returns the
462
+	 * appropriate url trigger
463
+	 *
464
+	 * @param EE_message_type $message_type
465
+	 * @param EE_Message $message
466
+	 * @param EE_Registration | null $registration  The registration object must be included if this
467
+	 *                                              is going to be a registration trigger url.
468
+	 * @param string $sending_messenger             The (optional) sending messenger for the url.
469
+	 *
470
+	 * @return string
471
+	 * @throws EE_Error
472
+	 */
473
+	public static function get_url_trigger(
474
+		EE_message_type $message_type,
475
+		EE_Message $message,
476
+		$registration = null,
477
+		$sending_messenger = ''
478
+	) {
479
+		// first determine if the url can be to the EE_Message object.
480
+		if (! $message_type->always_generate()) {
481
+			return EEH_MSG_Template::generate_browser_trigger($message);
482
+		}
483
+
484
+		// if $registration object is not valid then exit early because there's nothing that can be generated.
485
+		if (! $registration instanceof EE_Registration) {
486
+			throw new EE_Error(
487
+				esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
488
+			);
489
+		}
490
+
491
+		// validate given context
492
+		$contexts = $message_type->get_contexts();
493
+		if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
494
+			throw new EE_Error(
495
+				sprintf(
496
+					esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
497
+					$message->context(),
498
+					get_class($message_type)
499
+				)
500
+			);
501
+		}
502
+
503
+		// valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
504
+		if (! empty($sending_messenger)) {
505
+			$with_messengers = $message_type->with_messengers();
506
+			if (
507
+				! isset($with_messengers[ $message->messenger() ])
508
+				 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
509
+			) {
510
+				throw new EE_Error(
511
+					sprintf(
512
+						esc_html__(
513
+							'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
514
+							'event_espresso'
515
+						),
516
+						$sending_messenger,
517
+						get_class($message_type)
518
+					)
519
+				);
520
+			}
521
+		} else {
522
+			$sending_messenger = $message->messenger();
523
+		}
524
+		return EEH_MSG_Template::generate_url_trigger(
525
+			$sending_messenger,
526
+			$message->messenger(),
527
+			$message->context(),
528
+			$message->message_type(),
529
+			$registration,
530
+			$message->GRP_ID()
531
+		);
532
+	}
533
+
534
+
535
+	/**
536
+	 * This returns the url for triggering a in browser view of a specific EE_Message object.
537
+	 * @param EE_Message $message
538
+	 * @return string.
539
+	 */
540
+	public static function generate_browser_trigger(EE_Message $message)
541
+	{
542
+		$query_args = array(
543
+			'ee' => 'msg_browser_trigger',
544
+			'token' => $message->MSG_token()
545
+		);
546
+		return apply_filters(
547
+			'FHEE__EEH_MSG_Template__generate_browser_trigger',
548
+			add_query_arg($query_args, site_url()),
549
+			$message
550
+		);
551
+	}
552
+
553
+
554
+
555
+
556
+
557
+
558
+	/**
559
+	 * This returns the url for triggering an in browser view of the error saved on the incoming message object.
560
+	 * @param EE_Message $message
561
+	 * @return string
562
+	 */
563
+	public static function generate_error_display_trigger(EE_Message $message)
564
+	{
565
+		return apply_filters(
566
+			'FHEE__EEH_MSG_Template__generate_error_display_trigger',
567
+			add_query_arg(
568
+				array(
569
+					'ee' => 'msg_browser_error_trigger',
570
+					'token' => $message->MSG_token()
571
+				),
572
+				site_url()
573
+			),
574
+			$message
575
+		);
576
+	}
577
+
578
+
579
+	/**
580
+	 * This generates a url trigger for the msg_url_trigger route using the given arguments
581
+	 *
582
+	 * @param string          $sending_messenger      The sending messenger slug.
583
+	 * @param string          $generating_messenger   The generating messenger slug.
584
+	 * @param string          $context                The context for the template.
585
+	 * @param string          $message_type           The message type slug
586
+	 * @param EE_Registration $registration
587
+	 * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
588
+	 * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
589
+	 *                                                trigger.
590
+	 * @return string          The generated url.
591
+	 * @throws EE_Error
592
+	 */
593
+	public static function generate_url_trigger(
594
+		$sending_messenger,
595
+		$generating_messenger,
596
+		$context,
597
+		$message_type,
598
+		EE_Registration $registration,
599
+		$message_template_group,
600
+		$data_id = 0
601
+	) {
602
+		$query_args = array(
603
+			'ee' => 'msg_url_trigger',
604
+			'snd_msgr' => $sending_messenger,
605
+			'gen_msgr' => $generating_messenger,
606
+			'message_type' => $message_type,
607
+			'context' => $context,
608
+			'token' => $registration->reg_url_link(),
609
+			'GRP_ID' => $message_template_group,
610
+			'id' => $data_id
611
+			);
612
+		$url = add_query_arg($query_args, get_home_url());
613
+
614
+		// made it here so now we can just get the url and filter it.  Filtered globally and by message type.
615
+		return apply_filters(
616
+			'FHEE__EEH_MSG_Template__generate_url_trigger',
617
+			$url,
618
+			$sending_messenger,
619
+			$generating_messenger,
620
+			$context,
621
+			$message_type,
622
+			$registration,
623
+			$message_template_group,
624
+			$data_id
625
+		);
626
+	}
627
+
628
+
629
+
630
+
631
+	/**
632
+	 * Return the specific css for the action icon given.
633
+	 *
634
+	 * @param string $type  What action to return.
635
+	 * @return string[]
636
+	 * @since 4.9.0
637
+	 */
638
+	public static function get_message_action_icon($type)
639
+	{
640
+		$action_icons = self::get_message_action_icons();
641
+		return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
642
+	}
643
+
644
+
645
+	/**
646
+	 * This is used for retrieving the css classes used for the icons representing message actions.
647
+	 *
648
+	 * @since 4.9.0
649
+	 *
650
+	 * @return array
651
+	 */
652
+	public static function get_message_action_icons()
653
+	{
654
+		return apply_filters(
655
+			'FHEE__EEH_MSG_Template__message_action_icons',
656
+			array(
657
+				'view' => array(
658
+					'label' => esc_html__('View Message', 'event_espresso'),
659
+					'css_class' => 'dashicons dashicons-welcome-view-site',
660
+				),
661
+				'error' => array(
662
+					'label' => esc_html__('View Error Message', 'event_espresso'),
663
+					'css_class' => 'dashicons dashicons-info',
664
+				),
665
+				'see_notifications_for' => array(
666
+					'label' => esc_html__('View Related Messages', 'event_espresso'),
667
+					'css_class' => 'dashicons dashicons-megaphone',
668
+				),
669
+				'generate_now' => array(
670
+					'label' => esc_html__('Generate the message now.', 'event_espresso'),
671
+					'css_class' => 'dashicons dashicons-admin-tools',
672
+				),
673
+				'send_now' => array(
674
+					'label' => esc_html__('Send Immediately', 'event_espresso'),
675
+					'css_class' => 'dashicons dashicons-controls-forward',
676
+				),
677
+				'queue_for_resending' => array(
678
+					'label' => esc_html__('Queue for Resending', 'event_espresso'),
679
+					'css_class' => 'dashicons dashicons-controls-repeat',
680
+				),
681
+				'view_transaction' => array(
682
+					'label' => esc_html__('View related Transaction', 'event_espresso'),
683
+					'css_class' => 'dashicons dashicons-cart',
684
+				)
685
+			)
686
+		);
687
+	}
688
+
689
+
690
+	/**
691
+	 * This returns the url for a given action related to EE_Message.
692
+	 *
693
+	 * @param string     $type         What type of action to return the url for.
694
+	 * @param EE_Message $message      Required for generating the correct url for some types.
695
+	 * @param array      $query_params Any additional query params to be included with the generated url.
696
+	 *
697
+	 * @return string
698
+	 * @throws EE_Error
699
+	 * @throws ReflectionException
700
+	 * @since 4.9.0
701
+	 *
702
+	 */
703
+	public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
704
+	{
705
+		$action_urls = self::get_message_action_urls($message, $query_params);
706
+		return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
707
+	}
708
+
709
+
710
+	/**
711
+	 * This returns all the current urls for EE_Message actions.
712
+	 *
713
+	 * @since 4.9.0
714
+	 *
715
+	 * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
716
+	 * @param array      $query_params Any additional query_params to be included with the generated url.
717
+	 *
718
+	 * @return array
719
+	 * @throws EE_Error
720
+	 * @throws ReflectionException
721
+	 */
722
+	public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
723
+	{
724
+		EE_Registry::instance()->load_helper('URL');
725
+		// if $message is not an instance of EE_Message then let's just do a dummy.
726
+		$message = empty($message) ? EE_Message_Factory::create() : $message;
727
+		$action_urls =  apply_filters(
728
+			'FHEE__EEH_MSG_Template__get_message_action_url',
729
+			array(
730
+				'view' => EEH_MSG_Template::generate_browser_trigger($message),
731
+				'error' => EEH_MSG_Template::generate_error_display_trigger($message),
732
+				'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
733
+					array_merge(
734
+						array(
735
+							'page' => 'espresso_messages',
736
+							'action' => 'default',
737
+							'filterby' => 1,
738
+						),
739
+						$query_params
740
+					),
741
+					admin_url('admin.php')
742
+				),
743
+				'generate_now' => EEH_URL::add_query_args_and_nonce(
744
+					array(
745
+						'page' => 'espresso_messages',
746
+						'action' => 'generate_now',
747
+						'MSG_ID' => $message->ID()
748
+					),
749
+					admin_url('admin.php')
750
+				),
751
+				'send_now' => EEH_URL::add_query_args_and_nonce(
752
+					array(
753
+						'page' => 'espresso_messages',
754
+						'action' => 'send_now',
755
+						'MSG_ID' => $message->ID()
756
+					),
757
+					admin_url('admin.php')
758
+				),
759
+				'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
760
+					array(
761
+						'page' => 'espresso_messages',
762
+						'action' => 'queue_for_resending',
763
+						'MSG_ID' => $message->ID()
764
+					),
765
+					admin_url('admin.php')
766
+				),
767
+			)
768
+		);
769
+		if (
770
+			$message->TXN_ID() > 0
771
+			&& EE_Registry::instance()->CAP->current_user_can(
772
+				'ee_read_transaction',
773
+				'espresso_transactions_default',
774
+				$message->TXN_ID()
775
+			)
776
+		) {
777
+			$action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
778
+				array(
779
+					'page' => 'espresso_transactions',
780
+					'action' => 'view_transaction',
781
+					'TXN_ID' => $message->TXN_ID()
782
+				),
783
+				admin_url('admin.php')
784
+			);
785
+		} else {
786
+			$action_urls['view_transaction'] = '';
787
+		}
788
+		return $action_urls;
789
+	}
790
+
791
+
792
+	/**
793
+	 * This returns a generated link html including the icon used for the action link for EE_Message actions.
794
+	 *
795
+	 * @param string          $type         What type of action the link is for (if invalid type is passed in then an
796
+	 *                                      empty string is returned)
797
+	 * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
798
+	 * @param array           $query_params Any extra query params to include in the generated link.
799
+	 *
800
+	 * @return string
801
+	 * @throws EE_Error
802
+	 * @throws ReflectionException
803
+	 * @since 4.9.0
804
+	 *
805
+	 */
806
+	public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
807
+	{
808
+		$url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
809
+		$icon_css = EEH_MSG_Template::get_message_action_icon($type);
810
+		$title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
811
+
812
+		if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
813
+			return '';
814
+		}
815
+
816
+		$icon_css['css_class'] .= esc_attr(
817
+			apply_filters(
818
+				'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
819
+				' js-ee-message-action-link ee-message-action-link-' . $type,
820
+				$type,
821
+				$message,
822
+				$query_params
823
+			)
824
+		);
825
+
826
+		return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
827
+	}
828
+
829
+
830
+
831
+
832
+
833
+	/**
834
+	 * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
835
+	 *
836
+	 * @since 4.9.0
837
+	 * @return array
838
+	 */
839
+	public static function reg_status_to_message_type_array()
840
+	{
841
+		return (array) apply_filters(
842
+			'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
843
+			array(
844
+				EEM_Registration::status_id_approved => 'registration',
845
+				EEM_Registration::status_id_pending_payment => 'pending_approval',
846
+				EEM_Registration::status_id_not_approved => 'not_approved_registration',
847
+				EEM_Registration::status_id_cancelled => 'cancelled_registration',
848
+				EEM_Registration::status_id_declined => 'declined_registration'
849
+			)
850
+		);
851
+	}
852
+
853
+
854
+
855
+
856
+	/**
857
+	 * This returns the corresponding registration message type slug to the given reg status. If there isn't a
858
+	 * match, then returns an empty string.
859
+	 *
860
+	 * @since 4.9.0
861
+	 * @param $reg_status
862
+	 * @return string
863
+	 */
864
+	public static function convert_reg_status_to_message_type($reg_status)
865
+	{
866
+		$reg_status_array = self::reg_status_to_message_type_array();
867
+		return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
868
+	}
869
+
870
+
871
+	/**
872
+	 * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
873
+	 *
874
+	 * @since 4.9.0
875
+	 * @return array
876
+	 */
877
+	public static function payment_status_to_message_type_array()
878
+	{
879
+		return (array) apply_filters(
880
+			'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
881
+			array(
882
+				EEM_Payment::status_id_approved => 'payment',
883
+				EEM_Payment::status_id_pending => 'payment_pending',
884
+				EEM_Payment::status_id_cancelled => 'payment_cancelled',
885
+				EEM_Payment::status_id_declined => 'payment_declined',
886
+				EEM_Payment::status_id_failed => 'payment_failed'
887
+			)
888
+		);
889
+	}
890
+
891
+
892
+
893
+
894
+	/**
895
+	 * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
896
+	 * an empty string is returned
897
+	 *
898
+	 * @since 4.9.0
899
+	 * @param $payment_status
900
+	 * @return string
901
+	 */
902
+	public static function convert_payment_status_to_message_type($payment_status)
903
+	{
904
+		$payment_status_array = self::payment_status_to_message_type_array();
905
+		return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
906
+	}
907
+
908
+
909
+	/**
910
+	 * This is used to retrieve the template pack for the given name.
911
+	 *
912
+	 * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
913
+	 *
914
+	 * @return EE_Messages_Template_Pack
915
+	 */
916
+	public static function get_template_pack($template_pack_name)
917
+	{
918
+		if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
919
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
920
+		}
921
+
922
+		// first see if in collection already
923
+		$template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
924
+
925
+		if ($template_pack instanceof EE_Messages_Template_Pack) {
926
+			return $template_pack;
927
+		}
928
+
929
+		// nope...let's get it.
930
+		// not set yet so let's attempt to get it.
931
+		$pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
932
+			' ',
933
+			'_',
934
+			ucwords(
935
+				str_replace('_', ' ', $template_pack_name)
936
+			)
937
+		);
938
+		if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
939
+			return self::get_template_pack('default');
940
+		} else {
941
+			$template_pack = new $pack_class_name();
942
+			self::$_template_pack_collection->add($template_pack);
943
+			return $template_pack;
944
+		}
945
+	}
946
+
947
+
948
+
949
+
950
+	/**
951
+	 * Globs template packs installed in core and returns the template pack collection with all installed template packs
952
+	 * in it.
953
+	 *
954
+	 * @since 4.9.0
955
+	 *
956
+	 * @return EE_Messages_Template_Pack_Collection
957
+	 */
958
+	public static function get_template_pack_collection()
959
+	{
960
+		$new_collection = false;
961
+		if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
962
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
963
+			$new_collection = true;
964
+		}
965
+
966
+		// glob the defaults directory for messages
967
+		$templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
968
+		foreach ($templates as $template_path) {
969
+			// grab folder name
970
+			$template = basename($template_path);
971
+
972
+			if (! $new_collection) {
973
+				// already have it?
974
+				if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
975
+					continue;
976
+				}
977
+			}
978
+
979
+			// setup classname.
980
+			$template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
981
+				' ',
982
+				'_',
983
+				ucwords(
984
+					str_replace(
985
+						'_',
986
+						' ',
987
+						$template
988
+					)
989
+				)
990
+			);
991
+			if (! class_exists($template_pack_class_name)) {
992
+				continue;
993
+			}
994
+			self::$_template_pack_collection->add(new $template_pack_class_name());
995
+		}
996
+
997
+		/**
998
+		 * Filter for plugins to add in any additional template packs
999
+		 * Note the filter name here is for backward compat, this used to be found in EED_Messages.
1000
+		 */
1001
+		$additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1002
+		foreach ((array) $additional_template_packs as $template_pack) {
1003
+			if (
1004
+				self::$_template_pack_collection->get_by_name(
1005
+					$template_pack->dbref
1006
+				) instanceof EE_Messages_Template_Pack
1007
+			) {
1008
+				continue;
1009
+			}
1010
+			self::$_template_pack_collection->add($template_pack);
1011
+		}
1012
+		return self::$_template_pack_collection;
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * This is a wrapper for the protected _create_new_templates function
1018
+	 *
1019
+	 * @param string $messenger_name
1020
+	 * @param string $message_type_name message type that the templates are being created for
1021
+	 * @param int    $GRP_ID
1022
+	 * @param bool   $global
1023
+	 * @return array
1024
+	 * @throws EE_Error
1025
+	 * @throws ReflectionException
1026
+	 */
1027
+	public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1028
+	{
1029
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1030
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1031
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1032
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1033
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1034
+			return array();
1035
+		}
1036
+		// whew made it this far!  Okay, let's go ahead and create the templates then
1037
+		return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1038
+	}
1039
+
1040
+
1041
+	/**
1042
+	 * @param EE_messenger     $messenger
1043
+	 * @param EE_message_type  $message_type
1044
+	 * @param                  $GRP_ID
1045
+	 * @param                  $global
1046
+	 * @return array|mixed
1047
+	 * @throws EE_Error
1048
+	 * @throws ReflectionException
1049
+	 */
1050
+	protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1051
+	{
1052
+		// if we're creating a custom template then we don't need to use the defaults class
1053
+		if (! $global) {
1054
+			return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1055
+		}
1056
+		/** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1057
+		$Message_Template_Defaults = EE_Registry::factory(
1058
+			'EE_Messages_Template_Defaults',
1059
+			array( $messenger, $message_type, $GRP_ID )
1060
+		);
1061
+		// generate templates
1062
+		$success = $Message_Template_Defaults->create_new_templates();
1063
+
1064
+		// if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1065
+		// its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1066
+		// attempts.
1067
+		if (! $success) {
1068
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
1069
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1070
+			$message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1071
+		}
1072
+
1073
+		/**
1074
+		 * $success is in an array in the following format
1075
+		 * array(
1076
+		 *    'GRP_ID' => $new_grp_id,
1077
+		 *    'MTP_context' => $first_context_in_new_templates,
1078
+		 * )
1079
+		 */
1080
+		return $success;
1081
+	}
1082
+
1083
+
1084
+	/**
1085
+	 * This creates a custom template using the incoming GRP_ID
1086
+	 *
1087
+	 * @param EE_messenger    $messenger
1088
+	 * @param EE_message_type $message_type
1089
+	 * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1090
+	 * @return  array $success              This will be an array in the format:
1091
+	 *                                          array(
1092
+	 *                                          'GRP_ID' => $new_grp_id,
1093
+	 *                                          'MTP_context' => $first_context_in_created_template
1094
+	 *                                          )
1095
+	 * @throws EE_Error
1096
+	 * @throws ReflectionException
1097
+	 * @access private
1098
+	 */
1099
+	private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1100
+	{
1101
+		// defaults
1102
+		$success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1103
+		// get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1104
+		$Message_Template_Group = empty($GRP_ID)
1105
+			? EEM_Message_Template_Group::instance()->get_one(
1106
+				array(
1107
+					array(
1108
+						'MTP_messenger'    => $messenger->name,
1109
+						'MTP_message_type' => $message_type->name,
1110
+						'MTP_is_global'    => true
1111
+					)
1112
+				)
1113
+			)
1114
+			: EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1115
+		// if we don't have a mtg at this point then we need to bail.
1116
+		if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1117
+			EE_Error::add_error(
1118
+				sprintf(
1119
+					esc_html__(
1120
+						'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1121
+						'event_espresso'
1122
+					),
1123
+					$GRP_ID
1124
+				),
1125
+				__FILE__,
1126
+				__FUNCTION__,
1127
+				__LINE__
1128
+			);
1129
+			return $success;
1130
+		}
1131
+		// let's get all the related message_template objects for this group.
1132
+		$message_templates = $Message_Template_Group->message_templates();
1133
+		// now we have what we need to setup the new template
1134
+		$new_mtg = clone $Message_Template_Group;
1135
+		$new_mtg->set('GRP_ID', 0);
1136
+		$new_mtg->set('MTP_is_global', false);
1137
+
1138
+		/** @var RequestInterface $request */
1139
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1140
+		$template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1141
+			? $request->getRequestParam('templateName')
1142
+			: esc_html__('New Custom Template', 'event_espresso');
1143
+		$template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1144
+			? $request->getRequestParam('templateDescription')
1145
+			: sprintf(
1146
+				esc_html__(
1147
+					'This is a custom template that was created for the %s messenger and %s message type.',
1148
+					'event_espresso'
1149
+				),
1150
+				$new_mtg->messenger_obj()->label['singular'],
1151
+				$new_mtg->message_type_obj()->label['singular']
1152
+			);
1153
+		$new_mtg->set('MTP_name', $template_name);
1154
+		$new_mtg->set('MTP_description', $template_description);
1155
+		// remove ALL relations on this template group so they don't get saved!
1156
+		$new_mtg->_remove_relations('Message_Template');
1157
+		$new_mtg->save();
1158
+		$success['GRP_ID'] = $new_mtg->ID();
1159
+		$success['template_name'] = $template_name;
1160
+		// add new message templates and add relation to.
1161
+		foreach ($message_templates as $message_template) {
1162
+			if (! $message_template instanceof EE_Message_Template) {
1163
+				continue;
1164
+			}
1165
+			$new_message_template = clone $message_template;
1166
+			$new_message_template->set('MTP_ID', 0);
1167
+			$new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1168
+			$new_message_template->save();
1169
+			if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') {
1170
+				$success['MTP_context'] = $new_message_template->get('MTP_context');
1171
+			}
1172
+		}
1173
+		return $success;
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * message_type_has_active_templates_for_messenger
1179
+	 *
1180
+	 * @param EE_messenger    $messenger
1181
+	 * @param EE_message_type $message_type
1182
+	 * @param bool            $global
1183
+	 * @return bool
1184
+	 * @throws EE_Error
1185
+	 */
1186
+	public static function message_type_has_active_templates_for_messenger(
1187
+		EE_messenger $messenger,
1188
+		EE_message_type $message_type,
1189
+		$global = false
1190
+	) {
1191
+		// is given message_type valid for given messenger (if this is not a global save)
1192
+		if ($global) {
1193
+			return true;
1194
+		}
1195
+		$active_templates = EEM_Message_Template_Group::instance()->count(
1196
+			array(
1197
+				array(
1198
+					'MTP_is_active'    => true,
1199
+					'MTP_messenger'    => $messenger->name,
1200
+					'MTP_message_type' => $message_type->name
1201
+				)
1202
+			)
1203
+		);
1204
+		if ($active_templates > 0) {
1205
+			return true;
1206
+		}
1207
+		EE_Error::add_error(
1208
+			sprintf(
1209
+				esc_html__(
1210
+					'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1211
+					'event_espresso'
1212
+				),
1213
+				$message_type->name,
1214
+				$messenger->name
1215
+			),
1216
+			__FILE__,
1217
+			__FUNCTION__,
1218
+			__LINE__
1219
+		);
1220
+		return false;
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * get_fields
1226
+	 * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1227
+	 *
1228
+	 * @param string $messenger_name    name of EE_messenger
1229
+	 * @param string $message_type_name name of EE_message_type
1230
+	 * @return array
1231
+	 * @throws EE_Error
1232
+	 * @throws ReflectionException
1233
+	 */
1234
+	public static function get_fields($messenger_name, $message_type_name)
1235
+	{
1236
+		$template_fields = array();
1237
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1238
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1239
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1240
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1241
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1242
+			return array();
1243
+		}
1244
+
1245
+		$excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1246
+
1247
+		// okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1248
+		foreach ($message_type->get_contexts() as $context => $details) {
1249
+			foreach ($messenger->get_template_fields() as $field => $value) {
1250
+				if (in_array($field, $excluded_fields_for_messenger, true)) {
1251
+					continue;
1252
+				}
1253
+				$template_fields[ $context ][ $field ] = $value;
1254
+			}
1255
+		}
1256
+		if (empty($template_fields)) {
1257
+			EE_Error::add_error(
1258
+				esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1259
+				__FILE__,
1260
+				__FUNCTION__,
1261
+				__LINE__
1262
+			);
1263
+			return array();
1264
+		}
1265
+		return $template_fields;
1266
+	}
1267 1267
 }
Please login to merge, or discard this patch.
core/services/request/sanitizers/AllowedTags.php 1 patch
Indentation   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -13,284 +13,284 @@
 block discarded – undo
13 13
 class AllowedTags
14 14
 {
15 15
 
16
-    /**
17
-     * @var array[]
18
-     */
19
-    private static $attributes = [
20
-        'accept-charset'    => 1,
21
-        'action'            => 1,
22
-        'alt'               => 1,
23
-        'allow'             => 1,
24
-        'allowfullscreen'   => 1,
25
-        'align'             => 1,
26
-        'aria-*'            => 1,
27
-        'autocomplete'      => 1,
28
-        'bgcolor'           => 1,
29
-        'border'            => 1,
30
-        'cellpadding'       => 1,
31
-        'cellspacing'       => 1,
32
-        'checked'           => 1,
33
-        'class'             => 1,
34
-        'cols'              => 1,
35
-        'content'           => 1,
36
-        'data-*'            => 1,
37
-        'dir'               => 1,
38
-        'disabled'          => 1,
39
-        'enctype'           => 1,
40
-        'for'               => 1,
41
-        'frameborder'       => 1,
42
-        'height'            => 1,
43
-        'href'              => 1,
44
-        'id'                => 1,
45
-        'itemprop'          => 1,
46
-        'itemscope'         => 1,
47
-        'itemtype'          => 1,
48
-        'label'             => 1,
49
-        'lang'              => 1,
50
-        'leftmargin'        => 1,
51
-        'marginheight'      => 1,
52
-        'marginwidth'       => 1,
53
-        'max'               => 1,
54
-        'maxlength'         => 1,
55
-        'media'             => 1,
56
-        'method'            => 1,
57
-        'min'               => 1,
58
-        'multiple'          => 1,
59
-        'name'              => 1,
60
-        'novalidate'        => 1,
61
-        'placeholder'       => 1,
62
-        'property'          => 1,
63
-        'readonly'          => 1,
64
-        'rel'               => 1,
65
-        'required'          => 1,
66
-        'rows'              => 1,
67
-        'selected'          => 1,
68
-        'src'               => 1,
69
-        'size'              => 1,
70
-        'style'             => 1,
71
-        'step'              => 1,
72
-        'tabindex'          => 1,
73
-        'target'            => 1,
74
-        'title'             => 1,
75
-        'topmargin'         => 1,
76
-        'type'              => 1,
77
-        'value'             => 1,
78
-        'width'             => 1,
79
-    ];
80
-
81
-
82
-    /**
83
-     * @var array
84
-     */
85
-    private static $tags = [
86
-        'a',
87
-        'abbr',
88
-        'b',
89
-        'br',
90
-        'code',
91
-        'div',
92
-        'em',
93
-        'h1',
94
-        'h2',
95
-        'h3',
96
-        'h4',
97
-        'h5',
98
-        'h6',
99
-        'hr',
100
-        'i',
101
-        'img',
102
-        'li',
103
-        'ol',
104
-        'p',
105
-        'pre',
106
-        'small',
107
-        'span',
108
-        'strong',
109
-        'table',
110
-        'td',
111
-        'tr',
112
-        'ul',
113
-    ];
114
-
115
-
116
-    /**
117
-     * @var array
118
-     */
119
-    private static $allowed_tags;
120
-
121
-
122
-    /**
123
-     * @var array
124
-     */
125
-    private static $allowed_with_embed_tags;
126
-
127
-
128
-    /**
129
-     * @var array
130
-     */
131
-    private static $allowed_with_form_tags;
132
-
133
-
134
-    /**
135
-     * @var array
136
-     */
137
-    private static $allowed_with_script_and_style_tags;
138
-
139
-    /**
140
-     * @var array
141
-     */
142
-    private static $allowed_with_full_tags;
143
-
144
-
145
-    /**
146
-     * merges additional tags and attributes into the WP post tags
147
-     */
148
-    private static function initializeAllowedTags()
149
-    {
150
-        $allowed_post_tags = wp_kses_allowed_html('post');
151
-        $allowed_tags = [];
152
-        foreach (AllowedTags::$tags as $tag) {
153
-            $allowed_tags[ $tag ] = AllowedTags::$attributes;
154
-        }
155
-        AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
156
-    }
157
-
158
-
159
-    /**
160
-     * merges embed tags and attributes into the EE all tags
161
-     */
162
-    private static function initializeWithEmbedTags()
163
-    {
164
-        $all_tags = AllowedTags::getAllowedTags();
165
-        $embed_tags = [
166
-            'iframe' => AllowedTags::$attributes
167
-        ];
168
-        AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags);
169
-    }
170
-
171
-
172
-    /**
173
-     * merges form tags and attributes into the EE all tags
174
-     */
175
-    private static function initializeWithFormTags()
176
-    {
177
-        $all_tags = AllowedTags::getAllowedTags();
178
-        $form_tags = [
179
-            'form'     => AllowedTags::$attributes,
180
-            'label'    => AllowedTags::$attributes,
181
-            'input'    => AllowedTags::$attributes,
182
-            'select'   => AllowedTags::$attributes,
183
-            'option'   => AllowedTags::$attributes,
184
-            'optgroup' => AllowedTags::$attributes,
185
-            'textarea' => AllowedTags::$attributes,
186
-            'button'   => AllowedTags::$attributes,
187
-            'fieldset' => AllowedTags::$attributes,
188
-            'output'   => AllowedTags::$attributes,
189
-        ];
190
-        AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags);
191
-    }
192
-
193
-
194
-    /**
195
-     * merges form script and style tags and attributes into the EE all tags
196
-     */
197
-    private static function initializeWithScriptAndStyleTags()
198
-    {
199
-        $all_tags = AllowedTags::getAllowedTags();
200
-        $script_and_style_tags = [
201
-            'script'   => AllowedTags::$attributes,
202
-            'style'    => AllowedTags::$attributes,
203
-            'link'     => AllowedTags::$attributes,
204
-            'noscript' => AllowedTags::$attributes,
205
-        ];
206
-        AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags);
207
-    }
208
-
209
-    /**
210
-     * merges all head and body tags and attributes into the EE all tags
211
-     */
212
-    private static function initializeWithFullTags()
213
-    {
214
-        $all_tags = AllowedTags::getAllowedTags();
215
-        $full_tags = [
216
-            'script'    => AllowedTags::$attributes,
217
-            'style'     => AllowedTags::$attributes,
218
-            'link'      => AllowedTags::$attributes,
219
-            'title'     => AllowedTags::$attributes,
220
-            'meta'      => AllowedTags::$attributes,
221
-            'iframe'    => AllowedTags::$attributes,
222
-            'form'      => AllowedTags::$attributes,
223
-            'label'     => AllowedTags::$attributes,
224
-            'input'     => AllowedTags::$attributes,
225
-            'select'    => AllowedTags::$attributes,
226
-            'option'    => AllowedTags::$attributes,
227
-            'optgroup'  => AllowedTags::$attributes,
228
-            'textarea'  => AllowedTags::$attributes,
229
-            'button'    => AllowedTags::$attributes,
230
-            'fieldset'  => AllowedTags::$attributes,
231
-            'output'    => AllowedTags::$attributes,
232
-            'noscript'  => AllowedTags::$attributes,
233
-        ];
234
-        AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags);
235
-    }
236
-
237
-
238
-    /**
239
-     * @return array[]
240
-     */
241
-    public static function getAllowedTags()
242
-    {
243
-        if (empty(AllowedTags::$allowed_tags)) {
244
-            AllowedTags::initializeAllowedTags();
245
-        }
246
-        return AllowedTags::$allowed_tags;
247
-    }
248
-
249
-
250
-    /**
251
-     * @return array[]
252
-     */
253
-    public static function getWithEmbedTags()
254
-    {
255
-        if (empty(AllowedTags::$allowed_with_embed_tags)) {
256
-            AllowedTags::initializeWithEmbedTags();
257
-        }
258
-        return AllowedTags::$allowed_with_embed_tags;
259
-    }
260
-
261
-
262
-    /**
263
-     * @return array[]
264
-     */
265
-    public static function getWithFormTags()
266
-    {
267
-        if (empty(AllowedTags::$allowed_with_form_tags)) {
268
-            AllowedTags::initializeWithFormTags();
269
-        }
270
-        return AllowedTags::$allowed_with_form_tags;
271
-    }
272
-
273
-
274
-    /**
275
-     * @return array[]
276
-     */
277
-    public static function getWithScriptAndStyleTags()
278
-    {
279
-        if (empty(AllowedTags::$allowed_with_script_and_style_tags)) {
280
-            AllowedTags::initializeWithScriptAndStyleTags();
281
-        }
282
-        return AllowedTags::$allowed_with_script_and_style_tags;
283
-    }
284
-
285
-
286
-    /**
287
-     * @return array[]
288
-     */
289
-    public static function getWithFullTags()
290
-    {
291
-        if (empty(AllowedTags::$allowed_with_full_tags)) {
292
-            AllowedTags::initializeWithFullTags();
293
-        }
294
-        return AllowedTags::$allowed_with_full_tags;
295
-    }
16
+	/**
17
+	 * @var array[]
18
+	 */
19
+	private static $attributes = [
20
+		'accept-charset'    => 1,
21
+		'action'            => 1,
22
+		'alt'               => 1,
23
+		'allow'             => 1,
24
+		'allowfullscreen'   => 1,
25
+		'align'             => 1,
26
+		'aria-*'            => 1,
27
+		'autocomplete'      => 1,
28
+		'bgcolor'           => 1,
29
+		'border'            => 1,
30
+		'cellpadding'       => 1,
31
+		'cellspacing'       => 1,
32
+		'checked'           => 1,
33
+		'class'             => 1,
34
+		'cols'              => 1,
35
+		'content'           => 1,
36
+		'data-*'            => 1,
37
+		'dir'               => 1,
38
+		'disabled'          => 1,
39
+		'enctype'           => 1,
40
+		'for'               => 1,
41
+		'frameborder'       => 1,
42
+		'height'            => 1,
43
+		'href'              => 1,
44
+		'id'                => 1,
45
+		'itemprop'          => 1,
46
+		'itemscope'         => 1,
47
+		'itemtype'          => 1,
48
+		'label'             => 1,
49
+		'lang'              => 1,
50
+		'leftmargin'        => 1,
51
+		'marginheight'      => 1,
52
+		'marginwidth'       => 1,
53
+		'max'               => 1,
54
+		'maxlength'         => 1,
55
+		'media'             => 1,
56
+		'method'            => 1,
57
+		'min'               => 1,
58
+		'multiple'          => 1,
59
+		'name'              => 1,
60
+		'novalidate'        => 1,
61
+		'placeholder'       => 1,
62
+		'property'          => 1,
63
+		'readonly'          => 1,
64
+		'rel'               => 1,
65
+		'required'          => 1,
66
+		'rows'              => 1,
67
+		'selected'          => 1,
68
+		'src'               => 1,
69
+		'size'              => 1,
70
+		'style'             => 1,
71
+		'step'              => 1,
72
+		'tabindex'          => 1,
73
+		'target'            => 1,
74
+		'title'             => 1,
75
+		'topmargin'         => 1,
76
+		'type'              => 1,
77
+		'value'             => 1,
78
+		'width'             => 1,
79
+	];
80
+
81
+
82
+	/**
83
+	 * @var array
84
+	 */
85
+	private static $tags = [
86
+		'a',
87
+		'abbr',
88
+		'b',
89
+		'br',
90
+		'code',
91
+		'div',
92
+		'em',
93
+		'h1',
94
+		'h2',
95
+		'h3',
96
+		'h4',
97
+		'h5',
98
+		'h6',
99
+		'hr',
100
+		'i',
101
+		'img',
102
+		'li',
103
+		'ol',
104
+		'p',
105
+		'pre',
106
+		'small',
107
+		'span',
108
+		'strong',
109
+		'table',
110
+		'td',
111
+		'tr',
112
+		'ul',
113
+	];
114
+
115
+
116
+	/**
117
+	 * @var array
118
+	 */
119
+	private static $allowed_tags;
120
+
121
+
122
+	/**
123
+	 * @var array
124
+	 */
125
+	private static $allowed_with_embed_tags;
126
+
127
+
128
+	/**
129
+	 * @var array
130
+	 */
131
+	private static $allowed_with_form_tags;
132
+
133
+
134
+	/**
135
+	 * @var array
136
+	 */
137
+	private static $allowed_with_script_and_style_tags;
138
+
139
+	/**
140
+	 * @var array
141
+	 */
142
+	private static $allowed_with_full_tags;
143
+
144
+
145
+	/**
146
+	 * merges additional tags and attributes into the WP post tags
147
+	 */
148
+	private static function initializeAllowedTags()
149
+	{
150
+		$allowed_post_tags = wp_kses_allowed_html('post');
151
+		$allowed_tags = [];
152
+		foreach (AllowedTags::$tags as $tag) {
153
+			$allowed_tags[ $tag ] = AllowedTags::$attributes;
154
+		}
155
+		AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
156
+	}
157
+
158
+
159
+	/**
160
+	 * merges embed tags and attributes into the EE all tags
161
+	 */
162
+	private static function initializeWithEmbedTags()
163
+	{
164
+		$all_tags = AllowedTags::getAllowedTags();
165
+		$embed_tags = [
166
+			'iframe' => AllowedTags::$attributes
167
+		];
168
+		AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags);
169
+	}
170
+
171
+
172
+	/**
173
+	 * merges form tags and attributes into the EE all tags
174
+	 */
175
+	private static function initializeWithFormTags()
176
+	{
177
+		$all_tags = AllowedTags::getAllowedTags();
178
+		$form_tags = [
179
+			'form'     => AllowedTags::$attributes,
180
+			'label'    => AllowedTags::$attributes,
181
+			'input'    => AllowedTags::$attributes,
182
+			'select'   => AllowedTags::$attributes,
183
+			'option'   => AllowedTags::$attributes,
184
+			'optgroup' => AllowedTags::$attributes,
185
+			'textarea' => AllowedTags::$attributes,
186
+			'button'   => AllowedTags::$attributes,
187
+			'fieldset' => AllowedTags::$attributes,
188
+			'output'   => AllowedTags::$attributes,
189
+		];
190
+		AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags);
191
+	}
192
+
193
+
194
+	/**
195
+	 * merges form script and style tags and attributes into the EE all tags
196
+	 */
197
+	private static function initializeWithScriptAndStyleTags()
198
+	{
199
+		$all_tags = AllowedTags::getAllowedTags();
200
+		$script_and_style_tags = [
201
+			'script'   => AllowedTags::$attributes,
202
+			'style'    => AllowedTags::$attributes,
203
+			'link'     => AllowedTags::$attributes,
204
+			'noscript' => AllowedTags::$attributes,
205
+		];
206
+		AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags);
207
+	}
208
+
209
+	/**
210
+	 * merges all head and body tags and attributes into the EE all tags
211
+	 */
212
+	private static function initializeWithFullTags()
213
+	{
214
+		$all_tags = AllowedTags::getAllowedTags();
215
+		$full_tags = [
216
+			'script'    => AllowedTags::$attributes,
217
+			'style'     => AllowedTags::$attributes,
218
+			'link'      => AllowedTags::$attributes,
219
+			'title'     => AllowedTags::$attributes,
220
+			'meta'      => AllowedTags::$attributes,
221
+			'iframe'    => AllowedTags::$attributes,
222
+			'form'      => AllowedTags::$attributes,
223
+			'label'     => AllowedTags::$attributes,
224
+			'input'     => AllowedTags::$attributes,
225
+			'select'    => AllowedTags::$attributes,
226
+			'option'    => AllowedTags::$attributes,
227
+			'optgroup'  => AllowedTags::$attributes,
228
+			'textarea'  => AllowedTags::$attributes,
229
+			'button'    => AllowedTags::$attributes,
230
+			'fieldset'  => AllowedTags::$attributes,
231
+			'output'    => AllowedTags::$attributes,
232
+			'noscript'  => AllowedTags::$attributes,
233
+		];
234
+		AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags);
235
+	}
236
+
237
+
238
+	/**
239
+	 * @return array[]
240
+	 */
241
+	public static function getAllowedTags()
242
+	{
243
+		if (empty(AllowedTags::$allowed_tags)) {
244
+			AllowedTags::initializeAllowedTags();
245
+		}
246
+		return AllowedTags::$allowed_tags;
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return array[]
252
+	 */
253
+	public static function getWithEmbedTags()
254
+	{
255
+		if (empty(AllowedTags::$allowed_with_embed_tags)) {
256
+			AllowedTags::initializeWithEmbedTags();
257
+		}
258
+		return AllowedTags::$allowed_with_embed_tags;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @return array[]
264
+	 */
265
+	public static function getWithFormTags()
266
+	{
267
+		if (empty(AllowedTags::$allowed_with_form_tags)) {
268
+			AllowedTags::initializeWithFormTags();
269
+		}
270
+		return AllowedTags::$allowed_with_form_tags;
271
+	}
272
+
273
+
274
+	/**
275
+	 * @return array[]
276
+	 */
277
+	public static function getWithScriptAndStyleTags()
278
+	{
279
+		if (empty(AllowedTags::$allowed_with_script_and_style_tags)) {
280
+			AllowedTags::initializeWithScriptAndStyleTags();
281
+		}
282
+		return AllowedTags::$allowed_with_script_and_style_tags;
283
+	}
284
+
285
+
286
+	/**
287
+	 * @return array[]
288
+	 */
289
+	public static function getWithFullTags()
290
+	{
291
+		if (empty(AllowedTags::$allowed_with_full_tags)) {
292
+			AllowedTags::initializeWithFullTags();
293
+		}
294
+		return AllowedTags::$allowed_with_full_tags;
295
+	}
296 296
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.010');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.010');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/messages/EE_messenger.lib.php 1 patch
Indentation   +740 added lines, -740 removed lines patch added patch discarded remove patch
@@ -19,182 +19,182 @@  discard block
 block discarded – undo
19 19
 
20 20
 
21 21
 
22
-    /**
23
-     * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
24
-     * This property gets set by the _set_default_message_types() method.
25
-     *
26
-     * @var array
27
-     */
28
-    protected $_default_message_types = array();
22
+	/**
23
+	 * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
24
+	 * This property gets set by the _set_default_message_types() method.
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected $_default_message_types = array();
29 29
 
30 30
 
31 31
 
32 32
 
33
-    /**
34
-     * This property holds the message types that are valid for use with this messenger.
35
-     * It gets set by the _set_valid_message_types() method.
36
-     *
37
-     * @var array
38
-     */
39
-    protected $_valid_message_types = array();
33
+	/**
34
+	 * This property holds the message types that are valid for use with this messenger.
35
+	 * It gets set by the _set_valid_message_types() method.
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $_valid_message_types = array();
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
45
-     *
46
-     * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
47
-     *
48
-     * Array should be in this format:
49
-     *
50
-     * array(
51
-     *  'field_name(i.e.to)' => array(
52
-     *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
53
-     *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => esc_html__('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
54
-     *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
55
-     *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
56
-     *  )
57
-     * )
58
-     *
59
-     * @var array
60
-     */
61
-    protected $_validator_config = array();
43
+	/**
44
+	 * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
45
+	 *
46
+	 * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
47
+	 *
48
+	 * Array should be in this format:
49
+	 *
50
+	 * array(
51
+	 *  'field_name(i.e.to)' => array(
52
+	 *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
53
+	 *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => esc_html__('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
54
+	 *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
55
+	 *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
56
+	 *  )
57
+	 * )
58
+	 *
59
+	 * @var array
60
+	 */
61
+	protected $_validator_config = array();
62 62
 
63 63
 
64 64
 
65
-    /**
66
-     * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
67
-     * @var object
68
-     */
69
-    protected $_EEM_data;
65
+	/**
66
+	 * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
67
+	 * @var object
68
+	 */
69
+	protected $_EEM_data;
70 70
 
71 71
 
72 72
 
73
-    /**
74
-     * this property just holds an array of the various template refs.
75
-     * @var array
76
-     */
77
-    protected $_template_fields = array();
73
+	/**
74
+	 * this property just holds an array of the various template refs.
75
+	 * @var array
76
+	 */
77
+	protected $_template_fields = array();
78 78
 
79 79
 
80 80
 
81 81
 
82
-    /**
83
-     * This holds an array of the arguments used in parsing a template for the sender.
84
-     * @var array
85
-     */
86
-    protected $_template_args = array();
82
+	/**
83
+	 * This holds an array of the arguments used in parsing a template for the sender.
84
+	 * @var array
85
+	 */
86
+	protected $_template_args = array();
87 87
 
88 88
 
89 89
 
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
95
-     *
96
-     * @protected
97
-     * @var array
98
-     */
99
-    protected $_test_settings_fields = array();
93
+	/**
94
+	 * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
95
+	 *
96
+	 * @protected
97
+	 * @var array
98
+	 */
99
+	protected $_test_settings_fields = array();
100 100
 
101 101
 
102 102
 
103 103
 
104 104
 
105 105
 
106
-    /**
107
-     * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
108
-     *
109
-     * @since 4.5.0
110
-     *
111
-     * @var EE_Messages_Template_Pack
112
-     */
113
-    protected $_tmp_pack;
106
+	/**
107
+	 * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
108
+	 *
109
+	 * @since 4.5.0
110
+	 *
111
+	 * @var EE_Messages_Template_Pack
112
+	 */
113
+	protected $_tmp_pack;
114 114
 
115 115
 
116 116
 
117 117
 
118
-    /**
119
-     * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
120
-     *
121
-     * @since 4.5.0
122
-     *
123
-     * @var string
124
-     */
125
-    protected $_variation;
118
+	/**
119
+	 * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
120
+	 *
121
+	 * @since 4.5.0
122
+	 *
123
+	 * @var string
124
+	 */
125
+	protected $_variation;
126 126
 
127 127
 
128 128
 
129 129
 
130 130
 
131
-    /**
132
-     * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
133
-     *
134
-     *  - template pack
135
-     *  - template variation
136
-     *
137
-     * @since 4.5.0
138
-     *
139
-     * @var stdClass
140
-     */
141
-    protected $_supports_labels;
131
+	/**
132
+	 * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
133
+	 *
134
+	 *  - template pack
135
+	 *  - template variation
136
+	 *
137
+	 * @since 4.5.0
138
+	 *
139
+	 * @var stdClass
140
+	 */
141
+	protected $_supports_labels;
142 142
 
143 143
 
144 144
 
145 145
 
146 146
 
147
-    /**
148
-     * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
149
-     *
150
-     * @var EE_message_type
151
-     */
152
-    protected $_incoming_message_type;
147
+	/**
148
+	 * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
149
+	 *
150
+	 * @var EE_message_type
151
+	 */
152
+	protected $_incoming_message_type;
153 153
 
154 154
 
155 155
 
156
-    /**
157
-     * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
158
-     *
159
-     * @var bool
160
-     */
161
-    public $activate_on_install = false;
156
+	/**
157
+	 * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
158
+	 *
159
+	 * @var bool
160
+	 */
161
+	public $activate_on_install = false;
162 162
 
163 163
 
164 164
 
165 165
 
166 166
 
167
-    public function __construct()
168
-    {
169
-        $this->_EEM_data = EEM_Message_Template_Group::instance();
170
-        $this->_messages_item_type = 'messenger';
167
+	public function __construct()
168
+	{
169
+		$this->_EEM_data = EEM_Message_Template_Group::instance();
170
+		$this->_messages_item_type = 'messenger';
171 171
 
172
-        parent::__construct();
172
+		parent::__construct();
173 173
 
174
-        $this->_set_test_settings_fields();
175
-        $this->_set_template_fields();
176
-        $this->_set_default_message_types();
177
-        $this->_set_valid_message_types();
178
-        $this->_set_validator_config();
174
+		$this->_set_test_settings_fields();
175
+		$this->_set_template_fields();
176
+		$this->_set_default_message_types();
177
+		$this->_set_valid_message_types();
178
+		$this->_set_validator_config();
179 179
 
180 180
 
181
-        $this->_supports_labels = new stdClass();
182
-        $this->_set_supports_labels();
183
-    }
181
+		$this->_supports_labels = new stdClass();
182
+		$this->_set_supports_labels();
183
+	}
184 184
 
185 185
 
186 186
 
187 187
 
188 188
 
189
-    /**
190
-     * _set_template_fields
191
-     * This sets up the fields that a messenger requires for the message to go out.
192
-     *
193
-     * @abstract
194
-     * @access  protected
195
-     * @return void
196
-     */
197
-    abstract protected function _set_template_fields();
189
+	/**
190
+	 * _set_template_fields
191
+	 * This sets up the fields that a messenger requires for the message to go out.
192
+	 *
193
+	 * @abstract
194
+	 * @access  protected
195
+	 * @return void
196
+	 */
197
+	abstract protected function _set_template_fields();
198 198
 
199 199
 
200 200
 
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 
205 205
 
206 206
 
207
-    /**
208
-     * This method sets the _default_message_type property (see definition in docs attached to property)
209
-     *
210
-     * @abstract
211
-     * @access protected
212
-     * @return void
213
-     */
214
-    abstract protected function _set_default_message_types();
207
+	/**
208
+	 * This method sets the _default_message_type property (see definition in docs attached to property)
209
+	 *
210
+	 * @abstract
211
+	 * @access protected
212
+	 * @return void
213
+	 */
214
+	abstract protected function _set_default_message_types();
215 215
 
216 216
 
217 217
 
@@ -219,15 +219,15 @@  discard block
 block discarded – undo
219 219
 
220 220
 
221 221
 
222
-    /**
223
-     * Sets the _valid_message_types property (see definition in cods attached to property)
224
-     *
225
-     * @since 4.5.0
226
-     *
227
-     * @abstract
228
-     * @return void
229
-     */
230
-    abstract protected function _set_valid_message_types();
222
+	/**
223
+	 * Sets the _valid_message_types property (see definition in cods attached to property)
224
+	 *
225
+	 * @since 4.5.0
226
+	 *
227
+	 * @abstract
228
+	 * @return void
229
+	 */
230
+	abstract protected function _set_valid_message_types();
231 231
 
232 232
 
233 233
 
@@ -235,171 +235,171 @@  discard block
 block discarded – undo
235 235
 
236 236
 
237 237
 
238
-    /**
239
-     * Child classes must declare the $_validator_config property using this method.
240
-     * See comments for $_validator_config for details on what it is used for.
241
-     *
242
-     * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
243
-     *
244
-     * @access protected
245
-     * @return void
246
-     */
247
-    abstract protected function _set_validator_config();
238
+	/**
239
+	 * Child classes must declare the $_validator_config property using this method.
240
+	 * See comments for $_validator_config for details on what it is used for.
241
+	 *
242
+	 * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
243
+	 *
244
+	 * @access protected
245
+	 * @return void
246
+	 */
247
+	abstract protected function _set_validator_config();
248 248
 
249 249
 
250 250
 
251 251
 
252 252
 
253 253
 
254
-    /**
255
-     * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
256
-     *
257
-     * @return bool|WP_Error
258
-     * @throw \Exception
259
-     */
260
-    abstract protected function _send_message();
254
+	/**
255
+	 * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
256
+	 *
257
+	 * @return bool|WP_Error
258
+	 * @throw \Exception
259
+	 */
260
+	abstract protected function _send_message();
261 261
 
262 262
 
263 263
 
264 264
 
265
-    /**
266
-     * We give you pretty previews of the messages!
267
-     * @return string html body for message content.
268
-     */
269
-    abstract protected function _preview();
265
+	/**
266
+	 * We give you pretty previews of the messages!
267
+	 * @return string html body for message content.
268
+	 */
269
+	abstract protected function _preview();
270 270
 
271 271
 
272 272
 
273 273
 
274
-    /**
275
-     * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
276
-     *
277
-     * @since 4.5.0
278
-     *
279
-     * @return void
280
-     */
281
-    public function enqueue_scripts_styles()
282
-    {
283
-        do_action('AHEE__EE_messenger__enqueue_scripts_styles');
284
-    }
274
+	/**
275
+	 * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
276
+	 *
277
+	 * @since 4.5.0
278
+	 *
279
+	 * @return void
280
+	 */
281
+	public function enqueue_scripts_styles()
282
+	{
283
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
284
+	}
285 285
 
286 286
 
287 287
 
288 288
 
289 289
 
290
-    /**
291
-     * This is used to indicate whether a messenger must be sent immediately or not.
292
-     * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
293
-     * away.  The PDF messenger is similar.
294
-     *
295
-     * This flag thus overrides any priorities that may be set on the message type used to generate the message.
296
-     *
297
-     * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
298
-     *
299
-     * @since  4.9.0
300
-     * @return bool
301
-     */
302
-    public function send_now()
303
-    {
304
-        return false;
305
-    }
290
+	/**
291
+	 * This is used to indicate whether a messenger must be sent immediately or not.
292
+	 * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
293
+	 * away.  The PDF messenger is similar.
294
+	 *
295
+	 * This flag thus overrides any priorities that may be set on the message type used to generate the message.
296
+	 *
297
+	 * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
298
+	 *
299
+	 * @since  4.9.0
300
+	 * @return bool
301
+	 */
302
+	public function send_now()
303
+	{
304
+		return false;
305
+	}
306 306
 
307 307
 
308 308
 
309 309
 
310 310
 
311
-    /**
312
-     * This is a way for a messenger to indicate whether it allows an empty to field or not.
313
-     * Note: If the generated message is a for a preview, this value is ignored.
314
-     * @since 4.9.0
315
-     * @return bool
316
-     */
317
-    public function allow_empty_to_field()
318
-    {
319
-        return false;
320
-    }
311
+	/**
312
+	 * This is a way for a messenger to indicate whether it allows an empty to field or not.
313
+	 * Note: If the generated message is a for a preview, this value is ignored.
314
+	 * @since 4.9.0
315
+	 * @return bool
316
+	 */
317
+	public function allow_empty_to_field()
318
+	{
319
+		return false;
320
+	}
321 321
 
322 322
 
323 323
 
324 324
 
325 325
 
326
-    /**
327
-     * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
328
-     * @see property definition for info on how its formatted.
329
-     *
330
-     * @since 4.5.0;
331
-     * @return void
332
-     */
333
-    protected function _set_supports_labels()
334
-    {
335
-        $this->_set_supports_labels_defaults();
336
-    }
326
+	/**
327
+	 * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
328
+	 * @see property definition for info on how its formatted.
329
+	 *
330
+	 * @since 4.5.0;
331
+	 * @return void
332
+	 */
333
+	protected function _set_supports_labels()
334
+	{
335
+		$this->_set_supports_labels_defaults();
336
+	}
337 337
 
338 338
 
339 339
 
340 340
 
341 341
 
342
-    /**
343
-     * Sets the defaults for the _supports_labels property.
344
-     *
345
-     * @since 4.5.0
346
-     *
347
-     * @return void
348
-     */
349
-    private function _set_supports_labels_defaults()
350
-    {
351
-        $this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso');
352
-        $this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso');
353
-        $this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso');
342
+	/**
343
+	 * Sets the defaults for the _supports_labels property.
344
+	 *
345
+	 * @since 4.5.0
346
+	 *
347
+	 * @return void
348
+	 */
349
+	private function _set_supports_labels_defaults()
350
+	{
351
+		$this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso');
352
+		$this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso');
353
+		$this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso');
354 354
 
355
-        $this->_supports_labels->template_variation_description = esc_html__('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
355
+		$this->_supports_labels->template_variation_description = esc_html__('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
356 356
 
357
-        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
358
-    }
357
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
358
+	}
359 359
 
360 360
 
361 361
 
362 362
 
363 363
 
364
-    /**
365
-     * This returns the _supports_labels property.
366
-     *
367
-     * @since 4.5.0
368
-     *
369
-     * @return stdClass
370
-     */
371
-    public function get_supports_labels()
372
-    {
373
-        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
374
-            $this->_set_supports_labels_defaults();
375
-        }
376
-        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
377
-    }
364
+	/**
365
+	 * This returns the _supports_labels property.
366
+	 *
367
+	 * @since 4.5.0
368
+	 *
369
+	 * @return stdClass
370
+	 */
371
+	public function get_supports_labels()
372
+	{
373
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
374
+			$this->_set_supports_labels_defaults();
375
+		}
376
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
377
+	}
378 378
 
379 379
 
380 380
 
381 381
 
382
-    /**
383
-     * Used to retrieve a variation (typically the path/url to a css file)
384
-     *
385
-     * @since 4.5.0
386
-     *
387
-     * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
388
-     * @param string                    $message_type_name The name property of the message type that we need the variation for.
389
-     * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
390
-     * @param string                    $type What variation type to return. Default is 'main'.
391
-     * @param string               $variation What variation for the template pack
392
-     * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
393
-     *
394
-     * @return string                    path or url for the requested variation.
395
-     */
396
-    public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
397
-    {
398
-        $this->_tmp_pack = $pack;
399
-        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
400
-        $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
401
-        return $variation_path;
402
-    }
382
+	/**
383
+	 * Used to retrieve a variation (typically the path/url to a css file)
384
+	 *
385
+	 * @since 4.5.0
386
+	 *
387
+	 * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
388
+	 * @param string                    $message_type_name The name property of the message type that we need the variation for.
389
+	 * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
390
+	 * @param string                    $type What variation type to return. Default is 'main'.
391
+	 * @param string               $variation What variation for the template pack
392
+	 * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
393
+	 *
394
+	 * @return string                    path or url for the requested variation.
395
+	 */
396
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
397
+	{
398
+		$this->_tmp_pack = $pack;
399
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
400
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
401
+		return $variation_path;
402
+	}
403 403
 
404 404
 
405 405
 
@@ -407,497 +407,497 @@  discard block
 block discarded – undo
407 407
 
408 408
 
409 409
 
410
-    /**
411
-     * This just returns the default message types associated with this messenger when it is first activated.
412
-     *
413
-     * @access public
414
-     * @return array
415
-     */
416
-    public function get_default_message_types()
417
-    {
418
-        $class = get_class($this);
410
+	/**
411
+	 * This just returns the default message types associated with this messenger when it is first activated.
412
+	 *
413
+	 * @access public
414
+	 * @return array
415
+	 */
416
+	public function get_default_message_types()
417
+	{
418
+		$class = get_class($this);
419 419
 
420
-        // messenger specific filter
421
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
420
+		// messenger specific filter
421
+		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
422 422
 
423
-        // all messengers filter
424
-        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
425
-        return $default_types;
426
-    }
423
+		// all messengers filter
424
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
425
+		return $default_types;
426
+	}
427 427
 
428 428
 
429 429
 
430 430
 
431
-    /**
432
-     * Returns the valid message types associated with this messenger.
433
-     *
434
-     * @since 4.5.0
435
-     *
436
-     * @return array
437
-     */
438
-    public function get_valid_message_types()
439
-    {
440
-        $class = get_class($this);
441
-
442
-        // messenger specific filter
443
-        // messenger specific filter
444
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
445
-
446
-        // all messengers filter
447
-        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
448
-        return $valid_types;
449
-    }
450
-
451
-
452
-
453
-
454
-
455
-    /**
456
-     * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
457
-     *
458
-     * @access public
459
-     * @param array $new_config Whatever is put in here will reset the _validator_config property
460
-     */
461
-    public function set_validator_config($new_config)
462
-    {
463
-        $this->_validator_config = $new_config;
464
-    }
465
-
466
-
467
-
468
-
469
-    /**
470
-     * This returns the _validator_config property
471
-     *
472
-     * @access public
473
-     * @return array
474
-     */
475
-    public function get_validator_config()
476
-    {
477
-        $class = get_class($this);
478
-
479
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
480
-        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
481
-        return $config;
482
-    }
483
-
484
-
485
-
486
-
487
-    /**
488
-     * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
489
-     *
490
-     * @param string $page the slug of the EE admin page
491
-     * @param array $message_types an array of active message type objects
492
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
493
-     * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
494
-     * @access public
495
-     * @return string content for page
496
-     */
497
-    public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
498
-    {
499
-        return $this->_get_admin_page_content($page, $action, $extra, $message_types);
500
-    }
501
-
502
-
503
-
504
-    /**
505
-     * @param $message_types
506
-     * @param array $extra
507
-     * @return mixed|string
508
-     */
509
-    protected function _get_admin_content_events_edit($message_types, $extra)
510
-    {
511
-        // defaults
512
-        $template_args = array();
513
-        $selector_rows = '';
514
-
515
-        // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
516
-        $event_id = isset($extra['event']) ? $extra['event'] : null;
517
-
518
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
519
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
520
-
521
-        // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
522
-        $global_templates = EEM_Message_Template_Group::instance()->get_all(
523
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
524
-        );
525
-        $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
526
-            $event_id,
527
-            array(
528
-                'MTP_messenger' => $this->name,
529
-                'MTP_is_active' => true
530
-            )
531
-        );
532
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
533
-
534
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
535
-        foreach ($global_templates as $mtpgID => $mtpg) {
536
-            if ($mtpg instanceof EE_Message_Template_Group) {
537
-                // verify this message type is supposed to show on this page
538
-                $mtp_obj = $mtpg->message_type_obj();
539
-                if (! $mtp_obj instanceof EE_message_type) {
540
-                    continue;
541
-                }
542
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
543
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
544
-                    continue;
545
-                }
546
-                $select_values = array();
547
-                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
548
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
549
-                // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
550
-                if (! $mtpg->get('MTP_is_override')) {
551
-                    // any custom templates for this message type?
552
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
553
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
554
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
555
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
556
-                    }
557
-                }
558
-                // if there is no $default_value then we set it as the global
559
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
560
-                $c_config = $mtpg->contexts_config();
561
-                $edit_context = key(array_slice($c_config, -1));
562
-                $edit_url_query_args = [
563
-                    'page' => 'espresso_messages',
564
-                    'action' => 'edit_message_template',
565
-                    'id' => $default_value,
566
-                    'evt_id' => $event_id,
567
-                    'context' => $edit_context,
568
-                ];
569
-                $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
570
-                $create_url_query_args = [
571
-                    'page' => 'espresso_messages',
572
-                    'action' => 'add_new_message_template',
573
-                    'GRP_ID' => $default_value,
574
-                    'message_type' => $mtpg->message_type(),
575
-                    'messenger' => $this->name
576
-                ];
577
-                $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
578
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
579
-                $st_args['mt_slug'] = $mtpg->message_type();
580
-                $st_args['messenger_slug'] = $this->name;
581
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
582
-                // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
583
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . esc_html__('Create New Custom', 'event_espresso') . '</a>';
584
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
585
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . esc_html__('Edit', 'event_espresso') . '</a>' : '';
586
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
587
-            }
588
-        }
589
-
590
-        // if no selectors present then get out.
591
-        if (empty($selector_rows)) {
592
-            return '';
593
-        }
594
-
595
-        $template_args['selector_rows'] = $selector_rows;
596
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
597
-    }
598
-
599
-
600
-
601
-
602
-
603
-
604
-    /**
605
-     * get_template_fields
606
-     *
607
-     * @access public
608
-     * @return array $this->_template_fields
609
-     */
610
-    public function get_template_fields()
611
-    {
612
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
613
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
614
-        return $template_fields;
615
-    }
616
-
617
-
618
-
619
-
620
-    /** SETUP METHODS **/
621
-    /**
622
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
623
-     * @param string $item
624
-     * @param mixed $value
625
-     */
626
-    protected function _set_template_value($item, $value)
627
-    {
628
-        if (array_key_exists($item, $this->_template_fields)) {
629
-            $prop = '_' . $item;
630
-            $this->{$prop} = $value;
631
-        }
632
-    }
633
-
634
-    /**
635
-     * Sets up the message for sending.
636
-     *
637
-     * @param  EE_message $message the message object that contains details about the message.
638
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
639
-     *
640
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
641
-     *              added to EE_Error.
642
-     *              true = message sent successfully
643
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
644
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
645
-     *
646
-     * @throws SendMessageException
647
-     */
648
-    final public function send_message($message, EE_message_type $message_type)
649
-    {
650
-        try {
651
-            $this->_validate_and_setup($message);
652
-            $this->_incoming_message_type = $message_type;
653
-            $response = $this->_send_message();
654
-            if ($response instanceof WP_Error) {
655
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
656
-                $response = false;
657
-            }
658
-        } catch (\Exception $e) {
659
-            // convert to an instance of SendMessageException
660
-            throw new SendMessageException($e->getMessage());
661
-        }
662
-        return $response;
663
-    }
664
-
665
-
666
-
667
-    /**
668
-     * Sets up and returns message preview
669
-     * @param  EE_Message $message incoming message object
670
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
671
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
672
-     * @return string          return the message html content
673
-     */
674
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
675
-    {
676
-        $this->_validate_and_setup($message);
677
-
678
-        $this->_incoming_message_type = $message_type;
679
-
680
-        if ($send) {
681
-            // are we overriding any existing template fields?
682
-            $settings = apply_filters(
683
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
684
-                $this->get_existing_test_settings(),
685
-                $this,
686
-                $send,
687
-                $message,
688
-                $message_type
689
-            );
690
-            if (! empty($settings)) {
691
-                foreach ($settings as $field => $value) {
692
-                    $this->_set_template_value($field, $value);
693
-                }
694
-            }
695
-        }
696
-
697
-        // enqueue preview js so that any links/buttons on the page are disabled.
698
-        if (! $send) {
699
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
700
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
701
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
702
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
703
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
704
-        }
705
-
706
-        return $send ? $this->_send_message() : $this->_preview();
707
-    }
708
-
709
-
710
-
711
-
712
-    /**
713
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
714
-     *
715
-     * @since 4.5.0
716
-     *
717
-     * @return void
718
-     */
719
-    public function add_preview_script()
720
-    {
721
-        // error message
722
-        EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
723
-            __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
724
-        );
725
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
726
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
727
-        wp_enqueue_script('ee-messages-preview-js');
728
-    }
729
-
730
-
731
-
732
-
733
-    /**
734
-     * simply validates the incoming message object and then sets up the properties for the messenger
735
-     * @param  EE_Message $message
736
-     * @throws EE_Error
737
-     */
738
-    protected function _validate_and_setup(EE_Message $message)
739
-    {
740
-        $template_pack = $message->get_template_pack();
741
-        $variation = $message->get_template_pack_variation();
742
-
743
-        // verify we have the required template pack value on the $message object.
744
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
745
-            throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
746
-        }
747
-
748
-        $this->_tmp_pack = $template_pack;
749
-
750
-        $this->_variation = $variation ? $variation : 'default';
751
-
752
-        $template_fields = $this->get_template_fields();
753
-
754
-        foreach ($template_fields as $template => $value) {
755
-            if ($template !== 'extra') {
756
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
757
-                $message_template_value = $column_value ? $column_value : null;
758
-                $this->_set_template_value($template, $message_template_value);
759
-            }
760
-        }
761
-    }
762
-
763
-
764
-
765
-    /**
766
-     * Utility method for child classes to get the contents of a template file and return
767
-     *
768
-     * We're assuming the child messenger class has already setup template args!
769
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
770
-     * @return string
771
-     * @throws \EE_Error
772
-     */
773
-    protected function _get_main_template($preview = false)
774
-    {
775
-        $type = $preview ? 'preview' : 'main';
776
-
777
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
778
-
779
-        // check file exists and is readable
780
-        if (!is_readable($wrapper_template)) {
781
-            throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
782
-        }
783
-
784
-        // add message type to template args
785
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
786
-
787
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
788
-    }
789
-
790
-
791
-
792
-    /**
793
-     * set the _test_settings_fields property
794
-     *
795
-     * @access protected
796
-     * @return void
797
-     */
798
-    protected function _set_test_settings_fields()
799
-    {
800
-        $this->_test_settings_fields = array();
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * return the _test_settings_fields property
807
-     * @return array
808
-     */
809
-    public function get_test_settings_fields()
810
-    {
811
-        return $this->_test_settings_fields;
812
-    }
813
-
814
-
815
-
816
-
817
-    /**
818
-     * This just returns any existing test settings that might be saved in the database
819
-     *
820
-     * @access public
821
-     * @return array
822
-     */
823
-    public function get_existing_test_settings()
824
-    {
825
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
826
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
827
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
828
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
829
-    }
830
-
831
-
832
-
833
-    /**
834
-     * All this does is set the existing test settings (in the db) for the messenger
835
-     *
836
-     * @access public
837
-     * @param $settings
838
-     * @return bool success/fail
839
-     */
840
-    public function set_existing_test_settings($settings)
841
-    {
842
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
843
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
844
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
845
-        $existing[ $this->name ]['test_settings'] = $settings;
846
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
847
-    }
848
-
849
-
850
-
851
-    /**
852
-     * This just returns the field label for a given field setup in the _template_fields property.
853
-     *
854
-     * @since   4.3.0
855
-     *
856
-     * @param string $field The field to retrieve the label for
857
-     * @return string             The label
858
-     */
859
-    public function get_field_label($field)
860
-    {
861
-        // first let's see if the field requests is in the top level array.
862
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
863
-            return $this->_template[ $field ]['label'];
864
-        }
865
-
866
-        // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
867
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
868
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
869
-        }
870
-
871
-        // now it's possible this field may just be existing in any of the extra array items.
872
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
873
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
874
-                if (!is_array($subfields)) {
875
-                    continue;
876
-                }
877
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
878
-                    return $subfields[ $field ]['label'];
879
-                }
880
-            }
881
-        }
882
-
883
-        // if we made it here then there's no label set so let's just return the $field.
884
-        return $field;
885
-    }
886
-
887
-
888
-
889
-
890
-    /**
891
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
892
-     *
893
-     * @since 4.5.0
894
-     *
895
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
896
-     *
897
-     * @return void
898
-     */
899
-    public function do_secondary_messenger_hooks($sending_messenger_name)
900
-    {
901
-        return;
902
-    }
431
+	/**
432
+	 * Returns the valid message types associated with this messenger.
433
+	 *
434
+	 * @since 4.5.0
435
+	 *
436
+	 * @return array
437
+	 */
438
+	public function get_valid_message_types()
439
+	{
440
+		$class = get_class($this);
441
+
442
+		// messenger specific filter
443
+		// messenger specific filter
444
+		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
445
+
446
+		// all messengers filter
447
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
448
+		return $valid_types;
449
+	}
450
+
451
+
452
+
453
+
454
+
455
+	/**
456
+	 * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
457
+	 *
458
+	 * @access public
459
+	 * @param array $new_config Whatever is put in here will reset the _validator_config property
460
+	 */
461
+	public function set_validator_config($new_config)
462
+	{
463
+		$this->_validator_config = $new_config;
464
+	}
465
+
466
+
467
+
468
+
469
+	/**
470
+	 * This returns the _validator_config property
471
+	 *
472
+	 * @access public
473
+	 * @return array
474
+	 */
475
+	public function get_validator_config()
476
+	{
477
+		$class = get_class($this);
478
+
479
+		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
480
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
481
+		return $config;
482
+	}
483
+
484
+
485
+
486
+
487
+	/**
488
+	 * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
489
+	 *
490
+	 * @param string $page the slug of the EE admin page
491
+	 * @param array $message_types an array of active message type objects
492
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
493
+	 * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
494
+	 * @access public
495
+	 * @return string content for page
496
+	 */
497
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
498
+	{
499
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
500
+	}
501
+
502
+
503
+
504
+	/**
505
+	 * @param $message_types
506
+	 * @param array $extra
507
+	 * @return mixed|string
508
+	 */
509
+	protected function _get_admin_content_events_edit($message_types, $extra)
510
+	{
511
+		// defaults
512
+		$template_args = array();
513
+		$selector_rows = '';
514
+
515
+		// we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
516
+		$event_id = isset($extra['event']) ? $extra['event'] : null;
517
+
518
+		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
519
+		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
520
+
521
+		// array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
522
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(
523
+			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
524
+		);
525
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
526
+			$event_id,
527
+			array(
528
+				'MTP_messenger' => $this->name,
529
+				'MTP_is_active' => true
530
+			)
531
+		);
532
+		$templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
533
+
534
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
535
+		foreach ($global_templates as $mtpgID => $mtpg) {
536
+			if ($mtpg instanceof EE_Message_Template_Group) {
537
+				// verify this message type is supposed to show on this page
538
+				$mtp_obj = $mtpg->message_type_obj();
539
+				if (! $mtp_obj instanceof EE_message_type) {
540
+					continue;
541
+				}
542
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
543
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
544
+					continue;
545
+				}
546
+				$select_values = array();
547
+				$select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
548
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
549
+				// if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
550
+				if (! $mtpg->get('MTP_is_override')) {
551
+					// any custom templates for this message type?
552
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
553
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
554
+						$select_values[ $cmtpgID ] = $cmtpg->name();
555
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
556
+					}
557
+				}
558
+				// if there is no $default_value then we set it as the global
559
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
560
+				$c_config = $mtpg->contexts_config();
561
+				$edit_context = key(array_slice($c_config, -1));
562
+				$edit_url_query_args = [
563
+					'page' => 'espresso_messages',
564
+					'action' => 'edit_message_template',
565
+					'id' => $default_value,
566
+					'evt_id' => $event_id,
567
+					'context' => $edit_context,
568
+				];
569
+				$edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
570
+				$create_url_query_args = [
571
+					'page' => 'espresso_messages',
572
+					'action' => 'add_new_message_template',
573
+					'GRP_ID' => $default_value,
574
+					'message_type' => $mtpg->message_type(),
575
+					'messenger' => $this->name
576
+				];
577
+				$create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
578
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
579
+				$st_args['mt_slug'] = $mtpg->message_type();
580
+				$st_args['messenger_slug'] = $this->name;
581
+				$st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
582
+				// note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
583
+				$st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . esc_html__('Create New Custom', 'event_espresso') . '</a>';
584
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
585
+				$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . esc_html__('Edit', 'event_espresso') . '</a>' : '';
586
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
587
+			}
588
+		}
589
+
590
+		// if no selectors present then get out.
591
+		if (empty($selector_rows)) {
592
+			return '';
593
+		}
594
+
595
+		$template_args['selector_rows'] = $selector_rows;
596
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
597
+	}
598
+
599
+
600
+
601
+
602
+
603
+
604
+	/**
605
+	 * get_template_fields
606
+	 *
607
+	 * @access public
608
+	 * @return array $this->_template_fields
609
+	 */
610
+	public function get_template_fields()
611
+	{
612
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
613
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
614
+		return $template_fields;
615
+	}
616
+
617
+
618
+
619
+
620
+	/** SETUP METHODS **/
621
+	/**
622
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
623
+	 * @param string $item
624
+	 * @param mixed $value
625
+	 */
626
+	protected function _set_template_value($item, $value)
627
+	{
628
+		if (array_key_exists($item, $this->_template_fields)) {
629
+			$prop = '_' . $item;
630
+			$this->{$prop} = $value;
631
+		}
632
+	}
633
+
634
+	/**
635
+	 * Sets up the message for sending.
636
+	 *
637
+	 * @param  EE_message $message the message object that contains details about the message.
638
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
639
+	 *
640
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
641
+	 *              added to EE_Error.
642
+	 *              true = message sent successfully
643
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
644
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
645
+	 *
646
+	 * @throws SendMessageException
647
+	 */
648
+	final public function send_message($message, EE_message_type $message_type)
649
+	{
650
+		try {
651
+			$this->_validate_and_setup($message);
652
+			$this->_incoming_message_type = $message_type;
653
+			$response = $this->_send_message();
654
+			if ($response instanceof WP_Error) {
655
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
656
+				$response = false;
657
+			}
658
+		} catch (\Exception $e) {
659
+			// convert to an instance of SendMessageException
660
+			throw new SendMessageException($e->getMessage());
661
+		}
662
+		return $response;
663
+	}
664
+
665
+
666
+
667
+	/**
668
+	 * Sets up and returns message preview
669
+	 * @param  EE_Message $message incoming message object
670
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
671
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
672
+	 * @return string          return the message html content
673
+	 */
674
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
675
+	{
676
+		$this->_validate_and_setup($message);
677
+
678
+		$this->_incoming_message_type = $message_type;
679
+
680
+		if ($send) {
681
+			// are we overriding any existing template fields?
682
+			$settings = apply_filters(
683
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
684
+				$this->get_existing_test_settings(),
685
+				$this,
686
+				$send,
687
+				$message,
688
+				$message_type
689
+			);
690
+			if (! empty($settings)) {
691
+				foreach ($settings as $field => $value) {
692
+					$this->_set_template_value($field, $value);
693
+				}
694
+			}
695
+		}
696
+
697
+		// enqueue preview js so that any links/buttons on the page are disabled.
698
+		if (! $send) {
699
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
700
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
701
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
702
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
703
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
704
+		}
705
+
706
+		return $send ? $this->_send_message() : $this->_preview();
707
+	}
708
+
709
+
710
+
711
+
712
+	/**
713
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
714
+	 *
715
+	 * @since 4.5.0
716
+	 *
717
+	 * @return void
718
+	 */
719
+	public function add_preview_script()
720
+	{
721
+		// error message
722
+		EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
723
+			__('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
724
+		);
725
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
726
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
727
+		wp_enqueue_script('ee-messages-preview-js');
728
+	}
729
+
730
+
731
+
732
+
733
+	/**
734
+	 * simply validates the incoming message object and then sets up the properties for the messenger
735
+	 * @param  EE_Message $message
736
+	 * @throws EE_Error
737
+	 */
738
+	protected function _validate_and_setup(EE_Message $message)
739
+	{
740
+		$template_pack = $message->get_template_pack();
741
+		$variation = $message->get_template_pack_variation();
742
+
743
+		// verify we have the required template pack value on the $message object.
744
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
745
+			throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
746
+		}
747
+
748
+		$this->_tmp_pack = $template_pack;
749
+
750
+		$this->_variation = $variation ? $variation : 'default';
751
+
752
+		$template_fields = $this->get_template_fields();
753
+
754
+		foreach ($template_fields as $template => $value) {
755
+			if ($template !== 'extra') {
756
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
757
+				$message_template_value = $column_value ? $column_value : null;
758
+				$this->_set_template_value($template, $message_template_value);
759
+			}
760
+		}
761
+	}
762
+
763
+
764
+
765
+	/**
766
+	 * Utility method for child classes to get the contents of a template file and return
767
+	 *
768
+	 * We're assuming the child messenger class has already setup template args!
769
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
770
+	 * @return string
771
+	 * @throws \EE_Error
772
+	 */
773
+	protected function _get_main_template($preview = false)
774
+	{
775
+		$type = $preview ? 'preview' : 'main';
776
+
777
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
778
+
779
+		// check file exists and is readable
780
+		if (!is_readable($wrapper_template)) {
781
+			throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
782
+		}
783
+
784
+		// add message type to template args
785
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
786
+
787
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
788
+	}
789
+
790
+
791
+
792
+	/**
793
+	 * set the _test_settings_fields property
794
+	 *
795
+	 * @access protected
796
+	 * @return void
797
+	 */
798
+	protected function _set_test_settings_fields()
799
+	{
800
+		$this->_test_settings_fields = array();
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * return the _test_settings_fields property
807
+	 * @return array
808
+	 */
809
+	public function get_test_settings_fields()
810
+	{
811
+		return $this->_test_settings_fields;
812
+	}
813
+
814
+
815
+
816
+
817
+	/**
818
+	 * This just returns any existing test settings that might be saved in the database
819
+	 *
820
+	 * @access public
821
+	 * @return array
822
+	 */
823
+	public function get_existing_test_settings()
824
+	{
825
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
826
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
827
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
828
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
829
+	}
830
+
831
+
832
+
833
+	/**
834
+	 * All this does is set the existing test settings (in the db) for the messenger
835
+	 *
836
+	 * @access public
837
+	 * @param $settings
838
+	 * @return bool success/fail
839
+	 */
840
+	public function set_existing_test_settings($settings)
841
+	{
842
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
843
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
844
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
845
+		$existing[ $this->name ]['test_settings'] = $settings;
846
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
847
+	}
848
+
849
+
850
+
851
+	/**
852
+	 * This just returns the field label for a given field setup in the _template_fields property.
853
+	 *
854
+	 * @since   4.3.0
855
+	 *
856
+	 * @param string $field The field to retrieve the label for
857
+	 * @return string             The label
858
+	 */
859
+	public function get_field_label($field)
860
+	{
861
+		// first let's see if the field requests is in the top level array.
862
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
863
+			return $this->_template[ $field ]['label'];
864
+		}
865
+
866
+		// nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
867
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
868
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
869
+		}
870
+
871
+		// now it's possible this field may just be existing in any of the extra array items.
872
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
873
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
874
+				if (!is_array($subfields)) {
875
+					continue;
876
+				}
877
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
878
+					return $subfields[ $field ]['label'];
879
+				}
880
+			}
881
+		}
882
+
883
+		// if we made it here then there's no label set so let's just return the $field.
884
+		return $field;
885
+	}
886
+
887
+
888
+
889
+
890
+	/**
891
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
892
+	 *
893
+	 * @since 4.5.0
894
+	 *
895
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
896
+	 *
897
+	 * @return void
898
+	 */
899
+	public function do_secondary_messenger_hooks($sending_messenger_name)
900
+	{
901
+		return;
902
+	}
903 903
 }
Please login to merge, or discard this patch.
core/EED_Module.module.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -15,141 +15,141 @@
 block discarded – undo
15 15
 abstract class EED_Module extends EE_Configurable implements ResettableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * rendered output to be returned to WP
20
-     *
21
-     * @var    string $output
22
-     */
23
-    protected $output = '';
24
-
25
-    /**
26
-     * the current active espresso template theme
27
-     *
28
-     * @var    string $theme
29
-     */
30
-    protected $theme = '';
31
-
32
-
33
-    /**
34
-     * @return void
35
-     */
36
-    public static function reset()
37
-    {
38
-        $module_name = get_called_class();
39
-        new $module_name();
40
-    }
41
-
42
-
43
-    /**
44
-     *    set_hooks - for hooking into EE Core, other modules, etc
45
-     *
46
-     * @access    public
47
-     * @return    void
48
-     */
49
-    public static function set_hooks()
50
-    {
51
-    }
52
-
53
-
54
-    /**
55
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
56
-     *
57
-     * @access    public
58
-     * @return    void
59
-     */
60
-    public static function set_hooks_admin()
61
-    {
62
-    }
63
-
64
-
65
-    /**
66
-     *    run - initial module setup
67
-     *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
68
-     *
69
-     * @access    public
70
-     * @var            WP $WP
71
-     * @return    void
72
-     */
73
-    abstract public function run($WP);
74
-
75
-
76
-    /**
77
-     * EED_Module constructor.
78
-     */
79
-    final public function __construct()
80
-    {
81
-        $this->theme = EE_Config::get_current_theme();
82
-        $module_name = $this->module_name();
83
-        EE_Registry::instance()->modules->{$module_name} = $this;
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string $module_name
89
-     * @return EED_Module|mixed
90
-     * @throws EE_Error
91
-     * @throws ReflectionException
92
-     */
93
-    protected static function get_instance($module_name = '')
94
-    {
95
-        $module_name = ! empty($module_name)
96
-            ? $module_name
97
-            : get_called_class();
98
-        if (
99
-            ! isset(EE_Registry::instance()->modules->{$module_name})
100
-            || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
101
-        ) {
102
-            EE_Registry::instance()->add_module($module_name);
103
-        }
104
-        return EE_Registry::instance()->get_module($module_name);
105
-    }
106
-
107
-
108
-    /**
109
-     *    module_name
110
-     *
111
-     * @access    public
112
-     * @return    string
113
-     */
114
-    public function module_name()
115
-    {
116
-        return get_class($this);
117
-    }
118
-
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    public function theme()
124
-    {
125
-        return $this->theme;
126
-    }
127
-
128
-
129
-    /**
130
-     * @return RequestInterface
131
-     * @since   4.10.14.p
132
-     */
133
-    protected static function getRequest()
134
-    {
135
-        static $request;
136
-        if (! $request instanceof RequestInterface) {
137
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
138
-        }
139
-        return $request;
140
-    }
141
-
142
-
143
-    /**
144
-     * @return ResponseInterface
145
-     * @since   4.10.14.p
146
-     */
147
-    protected static function getResponse()
148
-    {
149
-        static $response;
150
-        if (! $response instanceof RequestInterface) {
151
-            $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
152
-        }
153
-        return $response;
154
-    }
18
+	/**
19
+	 * rendered output to be returned to WP
20
+	 *
21
+	 * @var    string $output
22
+	 */
23
+	protected $output = '';
24
+
25
+	/**
26
+	 * the current active espresso template theme
27
+	 *
28
+	 * @var    string $theme
29
+	 */
30
+	protected $theme = '';
31
+
32
+
33
+	/**
34
+	 * @return void
35
+	 */
36
+	public static function reset()
37
+	{
38
+		$module_name = get_called_class();
39
+		new $module_name();
40
+	}
41
+
42
+
43
+	/**
44
+	 *    set_hooks - for hooking into EE Core, other modules, etc
45
+	 *
46
+	 * @access    public
47
+	 * @return    void
48
+	 */
49
+	public static function set_hooks()
50
+	{
51
+	}
52
+
53
+
54
+	/**
55
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
56
+	 *
57
+	 * @access    public
58
+	 * @return    void
59
+	 */
60
+	public static function set_hooks_admin()
61
+	{
62
+	}
63
+
64
+
65
+	/**
66
+	 *    run - initial module setup
67
+	 *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
68
+	 *
69
+	 * @access    public
70
+	 * @var            WP $WP
71
+	 * @return    void
72
+	 */
73
+	abstract public function run($WP);
74
+
75
+
76
+	/**
77
+	 * EED_Module constructor.
78
+	 */
79
+	final public function __construct()
80
+	{
81
+		$this->theme = EE_Config::get_current_theme();
82
+		$module_name = $this->module_name();
83
+		EE_Registry::instance()->modules->{$module_name} = $this;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string $module_name
89
+	 * @return EED_Module|mixed
90
+	 * @throws EE_Error
91
+	 * @throws ReflectionException
92
+	 */
93
+	protected static function get_instance($module_name = '')
94
+	{
95
+		$module_name = ! empty($module_name)
96
+			? $module_name
97
+			: get_called_class();
98
+		if (
99
+			! isset(EE_Registry::instance()->modules->{$module_name})
100
+			|| ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
101
+		) {
102
+			EE_Registry::instance()->add_module($module_name);
103
+		}
104
+		return EE_Registry::instance()->get_module($module_name);
105
+	}
106
+
107
+
108
+	/**
109
+	 *    module_name
110
+	 *
111
+	 * @access    public
112
+	 * @return    string
113
+	 */
114
+	public function module_name()
115
+	{
116
+		return get_class($this);
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	public function theme()
124
+	{
125
+		return $this->theme;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @return RequestInterface
131
+	 * @since   4.10.14.p
132
+	 */
133
+	protected static function getRequest()
134
+	{
135
+		static $request;
136
+		if (! $request instanceof RequestInterface) {
137
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
138
+		}
139
+		return $request;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @return ResponseInterface
145
+	 * @since   4.10.14.p
146
+	 */
147
+	protected static function getResponse()
148
+	{
149
+		static $response;
150
+		if (! $response instanceof RequestInterface) {
151
+			$response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
152
+		}
153
+		return $response;
154
+	}
155 155
 }
Please login to merge, or discard this patch.
modules/events_archive/EED_Events_Archive.module.php 2 patches
Indentation   +1052 added lines, -1052 removed lines patch added patch discarded remove patch
@@ -17,1047 +17,1047 @@  discard block
 block discarded – undo
17 17
 class EED_Events_Archive extends EED_Module
18 18
 {
19 19
 
20
-    const EVENT_DETAILS_PRIORITY   = 100;
21
-
22
-    const EVENT_DATETIMES_PRIORITY = 110;
23
-
24
-    const EVENT_TICKETS_PRIORITY   = 120;
25
-
26
-    const EVENT_VENUES_PRIORITY    = 130;
27
-
28
-
29
-    public static $espresso_event_list_ID    = 0;
30
-
31
-    public static $espresso_grid_event_lists = [];
32
-
33
-    /**
34
-     * @type bool $using_get_the_excerpt
35
-     */
36
-    protected static $using_get_the_excerpt = false;
37
-
38
-    /**
39
-     * Used to flag when the event list is being called from an external iframe.
40
-     *
41
-     * @var bool $iframe
42
-     */
43
-    protected static $iframe = false;
44
-
45
-    /**
46
-     * @var EventListIframeEmbedButton $_iframe_embed_button
47
-     */
48
-    private static $_iframe_embed_button;
49
-
50
-    /**
51
-     * @type EE_Template_Part_Manager $template_parts
52
-     */
53
-    protected $template_parts;
54
-
55
-
56
-    /**
57
-     * @return EED_Events_Archive
58
-     * @throws EE_Error
59
-     * @throws ReflectionException
60
-     */
61
-    public static function instance()
62
-    {
63
-        return parent::get_instance(__CLASS__);
64
-    }
65
-
66
-
67
-    /**
68
-     * for hooking into EE Core, other modules, etc
69
-     *
70
-     * @return void
71
-     * @throws InvalidArgumentException
72
-     * @throws InvalidDataTypeException
73
-     * @throws InvalidInterfaceException
74
-     */
75
-    public static function set_hooks()
76
-    {
77
-        /** @var CustomPostTypeDefinitions $custom_post_type_definitions */
78
-        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(CustomPostTypeDefinitions::class);
79
-        $custom_post_types            = $custom_post_type_definitions->getDefinitions();
80
-        EE_Config::register_route(
81
-            $custom_post_types['espresso_events']['plural_slug'],
82
-            'Events_Archive',
83
-            'run'
84
-        );
85
-        EE_Config::register_route(
86
-            'event_list',
87
-            'Events_Archive',
88
-            'event_list'
89
-        );
90
-        EE_Config::register_route(
91
-            'iframe',
92
-            'Events_Archive',
93
-            'event_list_iframe',
94
-            'event_list'
95
-        );
96
-        add_action('wp_loaded', ['EED_Events_Archive', 'set_definitions'], 2);
97
-    }
98
-
99
-
100
-    /**
101
-     * for hooking into EE Admin Core, other modules, etc
102
-     *
103
-     * @return void
104
-     */
105
-    public static function set_hooks_admin()
106
-    {
107
-        add_action('wp_loaded', ['EED_Events_Archive', 'set_definitions'], 2);
108
-        // hook into the end of the \EE_Admin_Page::_load_page_dependencies()
109
-        // to load assets for "espresso_events" page on the "default" route (action)
110
-        add_action(
111
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
112
-            ['EED_Events_Archive', 'event_list_iframe_embed_button'],
113
-            10
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * @return void
120
-     */
121
-    public static function set_definitions()
122
-    {
123
-        define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
124
-        define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
125
-    }
126
-
127
-
128
-    /**
129
-     * set up EE_Events_Archive_Config
130
-     */
131
-    protected function set_config()
132
-    {
133
-        $this->set_config_section('template_settings');
134
-        $this->set_config_class('EE_Events_Archive_Config');
135
-        $this->set_config_name('EED_Events_Archive');
136
-    }
137
-
138
-
139
-    /**
140
-     * @return EventListIframeEmbedButton
141
-     */
142
-    public static function get_iframe_embed_button()
143
-    {
144
-        if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
145
-            self::$_iframe_embed_button = new EventListIframeEmbedButton();
146
-        }
147
-        return self::$_iframe_embed_button;
148
-    }
149
-
150
-
151
-    /**
152
-     * @return void
153
-     */
154
-    public static function event_list_iframe_embed_button()
155
-    {
156
-        $iframe_embed_button = EED_Events_Archive::get_iframe_embed_button();
157
-        $iframe_embed_button->addEmbedButton();
158
-    }
159
-
160
-
161
-    /**
162
-     * @param EE_Events_Archive_Config|null $config
163
-     * @return EE_Template_Part_Manager
164
-     * @throws EE_Error
165
-     */
166
-    public function initialize_template_parts(EE_Events_Archive_Config $config = null)
167
-    {
168
-        $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
169
-        EEH_Autoloader::instance()->register_template_part_autoloaders();
170
-        $template_parts = new EE_Template_Part_Manager();
171
-        $template_parts->add_template_part(
172
-            'tickets',
173
-            esc_html__('Ticket Selector', 'event_espresso'),
174
-            'content-espresso_events-tickets.php',
175
-            $config->display_order_tickets
176
-        );
177
-        $template_parts->add_template_part(
178
-            'datetimes',
179
-            esc_html__('Dates and Times', 'event_espresso'),
180
-            'content-espresso_events-datetimes.php',
181
-            $config->display_order_datetimes
182
-        );
183
-        $template_parts->add_template_part(
184
-            'event',
185
-            esc_html__('Event Description', 'event_espresso'),
186
-            'content-espresso_events-details.php',
187
-            $config->display_order_event
188
-        );
189
-        $template_parts->add_template_part(
190
-            'venue',
191
-            esc_html__('Venue Information', 'event_espresso'),
192
-            'content-espresso_events-venues.php',
193
-            $config->display_order_venue
194
-        );
195
-        do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
196
-        return $template_parts;
197
-    }
198
-
199
-
200
-    /**
201
-     * initial module setup
202
-     * this gets called by the EE_Front_Controller if the module route is found in the incoming request
203
-     *
204
-     * @param WP $WP
205
-     * @return void
206
-     */
207
-    public function run($WP)
208
-    {
209
-        do_action('AHEE__EED_Events_Archive__before_run');
210
-        // ensure valid EE_Events_Archive_Config() object exists
211
-        $this->set_config();
212
-        /** @type EE_Events_Archive_Config $config */
213
-        $config = $this->config();
214
-        // load other required components
215
-        $this->load_event_list_assets();
216
-        // filter the WP posts_join, posts_where, and posts_orderby SQL clauses
217
-        // add query filters
218
-        EEH_Event_Query::add_query_filters();
219
-        // set params that will get used by the filters
220
-        EEH_Event_Query::set_query_params(
221
-            '',                             // month
222
-            '',                             // category
223
-            $config->display_expired_events // show_expired
224
-        );
225
-        // check what template is loaded
226
-        add_filter('template_include', [$this, 'template_include'], 999, 1);
227
-    }
228
-
229
-
230
-    /**
231
-     * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
232
-     *
233
-     * @return void
234
-     */
235
-    public function event_list()
236
-    {
237
-        // ensure valid EE_Events_Archive_Config() object exists
238
-        $this->set_config();
239
-        // load other required components
240
-        $this->load_event_list_assets();
241
-    }
242
-
243
-
244
-    /**
245
-     * @return void
246
-     * @throws EE_Error
247
-     * @throws ReflectionException
248
-     */
249
-    public function event_list_iframe()
250
-    {
251
-        EED_Events_Archive::$iframe = true;
252
-        $event_list_iframe          = new EventsArchiveIframe($this);
253
-        $event_list_iframe->display();
254
-    }
255
-
256
-
257
-    /**
258
-     * @return bool
259
-     */
260
-    public static function is_iframe()
261
-    {
262
-        return EED_Events_Archive::$iframe;
263
-    }
264
-
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public static function link_target()
270
-    {
271
-        return EED_Events_Archive::$iframe ? ' target="_blank"' : '';
272
-    }
273
-
274
-
275
-    /**
276
-     * @param string $template
277
-     * @return string
278
-     * @throws EE_Error
279
-     * @throws ReflectionException
280
-     */
281
-    public function template_include($template = '')
282
-    {
283
-        // don't add content filter for dedicated EE child themes or private posts
284
-        if (! EEH_Template::is_espresso_theme()) {
285
-            /** @type EE_Events_Archive_Config $config */
286
-            $config = $this->config();
287
-            // add status banner ?
288
-            if ($config->display_status_banner) {
289
-                add_filter('the_title', ['EED_Events_Archive', 'the_title'], 100, 2);
290
-            }
291
-            // if NOT a custom template
292
-            if (
293
-                apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
294
-                || EE_Registry::instance()
295
-                              ->load_core('Front_Controller')
296
-                              ->get_selected_template() !== 'archive-espresso_events.php'
297
-            ) {
298
-                add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
299
-                // load functions.php file for the theme (loaded by WP if using child theme)
300
-                EEH_Template::load_espresso_theme_functions();
301
-                EED_Events_Archive::addEventDetailsFilters();
302
-                // don't display entry meta because the existing theme will take care of that
303
-                add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
304
-            }
305
-        }
306
-        return $template;
307
-    }
308
-
309
-
310
-    /**
311
-     * kinda hacky, but if a theme is using get_the_excerpt(),
312
-     * then we need to remove our filters on the_content()
313
-     *
314
-     * @param string $excerpt
315
-     * @return string
316
-     * @throws EE_Error
317
-     * @throws ReflectionException
318
-     */
319
-    public static function get_the_excerpt($excerpt = '')
320
-    {
321
-        if (post_password_required()) {
322
-            return $excerpt;
323
-        }
324
-        if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
325
-            EED_Events_Archive::removeEventDetailsFilters(false);
326
-            $excerpt = EED_Events_Archive::event_details($excerpt);
327
-        } else {
328
-            EED_Events_Archive::$using_get_the_excerpt = true;
329
-            add_filter('wp_trim_excerpt', ['EED_Events_Archive', 'end_get_the_excerpt'], 999, 1);
330
-        }
331
-        return $excerpt;
332
-    }
333
-
334
-
335
-    /**
336
-     * @param string $text
337
-     * @return string
338
-     */
339
-    public static function end_get_the_excerpt($text = '')
340
-    {
341
-        EED_Events_Archive::$using_get_the_excerpt = false;
342
-        return $text;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param string $title
348
-     * @param string $id
349
-     * @return string
350
-     * @throws EE_Error
351
-     * @throws ReflectionException
352
-     */
353
-    public static function the_title($title = '', $id = '')
354
-    {
355
-        global $post;
356
-        if ($post instanceof WP_Post) {
357
-            return (EED_Events_Archive::isBlockTheme() || in_the_loop()) && $post->ID == $id
358
-                ? espresso_event_status_banner($post->ID) . $title
359
-                : $title;
360
-        }
361
-        return $title;
362
-    }
363
-
364
-
365
-    /**
366
-     * @param string $content
367
-     * @return string
368
-     * @throws EE_Error
369
-     * @throws ReflectionException
370
-     */
371
-    public static function event_details($content)
372
-    {
373
-        global $post;
374
-        static $current_post_ID = 0;
375
-        if (
376
-            $current_post_ID !== $post->ID
377
-            && $post->post_type === 'espresso_events'
378
-            && ! EED_Events_Archive::$using_get_the_excerpt
379
-            && ! post_password_required()
380
-            && (
381
-                apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
382
-                || ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
383
-            )
384
-        ) {
385
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
386
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
387
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
388
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
389
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
390
-            // so the following allows this filter to be applied multiple times, but only once for real
391
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
392
-            if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
393
-                $content = EED_Events_Archive::use_sortable_display_order();
394
-            } else {
395
-                $content = EED_Events_Archive::use_filterable_display_order();
396
-            }
397
-        }
398
-        return $content;
399
-    }
400
-
401
-
402
-    /**
403
-     * @return string
404
-     * @throws EE_Error
405
-     * @throws ReflectionException
406
-     */
407
-    protected static function use_sortable_display_order()
408
-    {
409
-        // no further password checks required atm
410
-        add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
411
-        // remove this callback from being applied to the_content()
412
-        EED_Events_Archive::removeEventDetailsFilters();
413
-        // now add additional content depending on whether event is using the_excerpt() or the_content()
414
-        EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
415
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
416
-        $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
417
-        // re-add our main filters (or else the next event won't have them)
418
-        EED_Events_Archive::addEventDetailsFilters();
419
-        remove_filter(
420
-            'FHEE__EED_Events_Archive__event_details__no_post_password_required',
421
-            '__return_true'
422
-        );
423
-        return $content;
424
-    }
425
-
426
-
427
-    /**
428
-     * @return string
429
-     */
430
-    protected static function use_filterable_display_order()
431
-    {
432
-        // remove this callback from being applied to the_content()
433
-        EED_Events_Archive::removeEventDetailsFilters();
434
-        // now add additional content depending on whether event is using the_excerpt() or the_content()
435
-        EED_Events_Archive::_add_additional_excerpt_filters();
436
-        EED_Events_Archive::_add_additional_content_filters();
437
-        do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
438
-        // now load our template
439
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
440
-        // re-add our main filters (or else the next event won't have them)
441
-        EED_Events_Archive::addEventDetailsFilters();
442
-        // but remove the other filters so that they don't get applied to the next post
443
-        EED_Events_Archive::_remove_additional_events_archive_filters();
444
-        do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
445
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
446
-        // return ! empty( $template ) ? $template : $content;
447
-        return $content;
448
-    }
449
-
450
-
451
-    /**
452
-     * adds datetimes ABOVE content
453
-     *
454
-     * @param string $content
455
-     * @return string
456
-     */
457
-    public static function event_datetimes($content)
458
-    {
459
-        if (post_password_required()) {
460
-            return $content;
461
-        }
462
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
463
-    }
464
-
465
-
466
-    /**
467
-     * adds tickets ABOVE content (which includes datetimes)
468
-     *
469
-     * @param string $content
470
-     * @return string
471
-     */
472
-    public static function event_tickets($content)
473
-    {
474
-        if (post_password_required()) {
475
-            return $content;
476
-        }
477
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
478
-    }
479
-
480
-
481
-    /**
482
-     * adds venues BELOW content
483
-     *
484
-     * @param string $content
485
-     * @return string
486
-     */
487
-    public static function event_venue($content)
488
-    {
489
-        return EED_Events_Archive::event_venues($content);
490
-    }
491
-
492
-
493
-    /**
494
-     * adds venues BELOW content
495
-     *
496
-     * @param string $content
497
-     * @return string
498
-     */
499
-    public static function event_venues($content)
500
-    {
501
-        if (post_password_required()) {
502
-            return $content;
503
-        }
504
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
505
-    }
506
-
507
-
508
-    /**
509
-     * @return bool
510
-     * @since $VID:$
511
-     */
512
-    public static function isBlockTheme()
513
-    {
514
-        return function_exists('wp_is_block_theme') && wp_is_block_theme();
515
-    }
516
-
517
-
518
-    /**
519
-     * @return string
520
-     * @since $VID:$
521
-     */
522
-    public static function getExcerptFilter()
523
-    {
524
-        static $excerpt_filter = null;
525
-        if ($excerpt_filter === null) {
526
-            $excerpt_filter = EED_Events_Archive::isBlockTheme() ? 'get_the_excerpt' : 'the_excerpt';
527
-        }
528
-        return $excerpt_filter;
529
-    }
530
-
531
-
532
-    /**
533
-     * @since $VID:$
534
-     */
535
-    protected static function addEventDetailsFilters()
536
-    {
537
-        add_filter(
538
-            'the_content',
539
-            ['EED_Events_Archive', 'event_details'],
540
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
541
-        );
542
-        // but because we don't know if the theme is using the_excerpt()
543
-        add_filter(
544
-            EED_Events_Archive::getExcerptFilter(),
545
-            ['EED_Events_Archive', 'event_details'],
546
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
547
-        );
548
-        // and just in case they are running get_the_excerpt() which DESTROYS things
549
-        add_filter('get_the_excerpt', ['EED_Events_Archive', 'get_the_excerpt'], 1, 1);
550
-    }
551
-
552
-
553
-    /**
554
-     * @param bool $and_get_the_excerpt
555
-     * @since $VID:$
556
-     */
557
-    protected static function removeEventDetailsFilters($and_get_the_excerpt = true)
558
-    {
559
-        // we need to first remove all callbacks from being applied to the_content()
560
-        // (otherwise it will recurse and blow up the interweb)
561
-        remove_filter(
562
-            'the_content',
563
-            ['EED_Events_Archive', 'event_details'],
564
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
565
-        );
566
-        remove_filter(
567
-            EED_Events_Archive::getExcerptFilter(),
568
-            ['EED_Events_Archive', 'event_details'],
569
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
570
-        );
571
-        if ($and_get_the_excerpt) {
572
-            remove_filter('get_the_excerpt', ['EED_Events_Archive', 'get_the_excerpt'], 1);
573
-        }
574
-    }
575
-
576
-
577
-    /**
578
-     * @return void
579
-     */
580
-    private static function _add_additional_excerpt_filters()
581
-    {
582
-        add_filter(
583
-            EED_Events_Archive::getExcerptFilter(),
584
-            ['EED_Events_Archive', 'event_datetimes'],
585
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
586
-        );
587
-        add_filter(
588
-            EED_Events_Archive::getExcerptFilter(),
589
-            ['EED_Events_Archive', 'event_tickets'],
590
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
591
-        );
592
-        add_filter(
593
-            EED_Events_Archive::getExcerptFilter(),
594
-            ['EED_Events_Archive', 'event_venues'],
595
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
596
-        );
597
-    }
598
-
599
-
600
-    /**
601
-     * @return void
602
-     */
603
-    private static function _add_additional_content_filters()
604
-    {
605
-        add_filter(
606
-            'the_content',
607
-            ['EED_Events_Archive', 'event_datetimes'],
608
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
609
-        );
610
-        add_filter(
611
-            'the_content',
612
-            ['EED_Events_Archive', 'event_tickets'],
613
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
614
-        );
615
-        add_filter(
616
-            'the_content',
617
-            ['EED_Events_Archive', 'event_venues'],
618
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
619
-        );
620
-    }
621
-
622
-
623
-    /**
624
-     * @return void
625
-     */
626
-    private static function _remove_additional_events_archive_filters()
627
-    {
628
-        remove_filter(
629
-            EED_Events_Archive::getExcerptFilter(),
630
-            ['EED_Events_Archive', 'event_datetimes'],
631
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
632
-        );
633
-        remove_filter(
634
-            EED_Events_Archive::getExcerptFilter(),
635
-            ['EED_Events_Archive', 'event_tickets'],
636
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
637
-        );
638
-        remove_filter(
639
-            EED_Events_Archive::getExcerptFilter(),
640
-            ['EED_Events_Archive', 'event_venues'],
641
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
642
-        );
643
-        remove_filter(
644
-            'the_content',
645
-            ['EED_Events_Archive', 'event_datetimes'],
646
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
647
-        );
648
-        remove_filter(
649
-            'the_content',
650
-            ['EED_Events_Archive', 'event_tickets'],
651
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
652
-        );
653
-        remove_filter(
654
-            'the_content',
655
-            ['EED_Events_Archive', 'event_venues'],
656
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
657
-        );
658
-    }
659
-
660
-
661
-    /**
662
-     * @return void
663
-     */
664
-    public static function remove_all_events_archive_filters()
665
-    {
666
-        // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
667
-        remove_filter('the_title', ['EED_Events_Archive', 'the_title'], 1);
668
-        remove_filter(
669
-            EED_Events_Archive::getExcerptFilter(),
670
-            ['EED_Events_Archive', 'event_details'],
671
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
672
-        );
673
-        remove_filter(
674
-            EED_Events_Archive::getExcerptFilter(),
675
-            ['EED_Events_Archive', 'event_datetimes'],
676
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
677
-        );
678
-        remove_filter(
679
-            EED_Events_Archive::getExcerptFilter(),
680
-            ['EED_Events_Archive', 'event_tickets'],
681
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
682
-        );
683
-        remove_filter(
684
-            EED_Events_Archive::getExcerptFilter(),
685
-            ['EED_Events_Archive', 'event_venues'],
686
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
687
-        );
688
-        remove_filter(
689
-            'the_content',
690
-            ['EED_Events_Archive', 'event_details'],
691
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
692
-        );
693
-        remove_filter(
694
-            'the_content',
695
-            ['EED_Events_Archive', 'event_datetimes'],
696
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
697
-        );
698
-        remove_filter(
699
-            'the_content',
700
-            ['EED_Events_Archive', 'event_tickets'],
701
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
702
-        );
703
-        remove_filter(
704
-            'the_content',
705
-            ['EED_Events_Archive', 'event_venues'],
706
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
707
-        );
708
-        // don't display entry meta because the existing theme will take care of that
709
-        remove_filter(
710
-            'FHEE__content_espresso_events_details_template__display_entry_meta',
711
-            '__return_false'
712
-        );
713
-    }
714
-
715
-
716
-    /**
717
-     * @return void
718
-     */
719
-    public function load_event_list_assets()
720
-    {
721
-        do_action('AHEE__EED_Events_Archive__before_load_assets');
722
-        add_filter('FHEE_load_EE_Session', '__return_true');
723
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
724
-        add_action('wp_enqueue_scripts', [$this, 'wp_enqueue_scripts'], 10);
725
-        if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
726
-            add_action('wp_enqueue_scripts', ['EEH_Maps', 'espresso_google_map_js'], 11);
727
-        }
728
-    }
729
-
730
-
731
-    /**
732
-     * @return void
733
-     * @throws EE_Error
734
-     */
735
-    public function wp_enqueue_scripts()
736
-    {
737
-        // get some style
738
-        if (apply_filters('FHEE_enable_default_espresso_css', false)) {
739
-            // first check uploads folder
740
-            if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
741
-                wp_register_style(
742
-                    $this->theme,
743
-                    get_stylesheet_directory_uri() . $this->theme . '/style.css',
744
-                    ['dashicons', 'espresso_default']
745
-                );
746
-            }
747
-            wp_enqueue_style($this->theme);
748
-        }
749
-    }
750
-
751
-
752
-    /**
753
-     * @static
754
-     * @return void
755
-     */
756
-    public static function template_settings_form()
757
-    {
758
-        $template_settings                     = EE_Registry::instance()->CFG->template_settings;
759
-        $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive)
760
-            ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
761
-        $template_settings->EED_Events_Archive = apply_filters(
762
-            'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
763
-            $template_settings->EED_Events_Archive
764
-        );
765
-        $events_archive_settings               = [
766
-            'display_status_banner'   => 0,
767
-            'display_description'     => 1,
768
-            'display_ticket_selector' => 0,
769
-            'display_datetimes'       => 1,
770
-            'display_venue'           => 0,
771
-            'display_expired_events'  => 0,
772
-        ];
773
-        $events_archive_settings               = array_merge(
774
-            $events_archive_settings,
775
-            (array) $template_settings->EED_Events_Archive
776
-        );
777
-        EEH_Template::display_template(
778
-            EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
779
-            $events_archive_settings
780
-        );
781
-    }
782
-
783
-
784
-    /**
785
-     * @param EE_Template_Config $CFG
786
-     * @param array              $REQ
787
-     * @return EE_Template_Config
788
-     */
789
-    public static function update_template_settings($CFG, $REQ)
790
-    {
791
-        $CFG->EED_Events_Archive = new EE_Events_Archive_Config();
792
-        // unless we are resetting the config...
793
-        if (
794
-            ! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
795
-            || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
796
-        ) {
797
-            $CFG->EED_Events_Archive->display_status_banner   = isset($REQ['EED_Events_Archive_display_status_banner'])
798
-                ? absint($REQ['EED_Events_Archive_display_status_banner'])
799
-                : 0;
800
-            $CFG->EED_Events_Archive->display_description     = isset($REQ['EED_Events_Archive_display_description'])
801
-                ? absint($REQ['EED_Events_Archive_display_description'])
802
-                : 1;
803
-            $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
804
-                ? absint($REQ['EED_Events_Archive_display_ticket_selector'])
805
-                : 0;
806
-            $CFG->EED_Events_Archive->display_datetimes       = isset($REQ['EED_Events_Archive_display_datetimes'])
807
-                ? absint($REQ['EED_Events_Archive_display_datetimes'])
808
-                : 1;
809
-            $CFG->EED_Events_Archive->display_venue           = isset($REQ['EED_Events_Archive_display_venue'])
810
-                ? absint($REQ['EED_Events_Archive_display_venue'])
811
-                : 0;
812
-            $CFG->EED_Events_Archive->display_expired_events  = isset($REQ['EED_Events_Archive_display_expired_events'])
813
-                ? absint($REQ['EED_Events_Archive_display_expired_events'])
814
-                : 0;
815
-        }
816
-        return $CFG;
817
-    }
818
-
819
-
820
-    /**
821
-     * @param string $extra_class
822
-     * @return string
823
-     */
824
-    public static function event_list_css($extra_class = '')
825
-    {
826
-        $event_list_css   = ! empty($extra_class) ? [$extra_class] : [];
827
-        $event_list_css[] = 'espresso-event-list-event';
828
-        return implode(' ', $event_list_css);
829
-    }
830
-
831
-
832
-    /**
833
-     * @return array
834
-     * @throws EE_Error
835
-     * @throws ReflectionException
836
-     */
837
-    public static function event_categories()
838
-    {
839
-        return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
840
-    }
841
-
842
-
843
-    /**
844
-     * @param $value
845
-     * @return bool
846
-     */
847
-    public static function display_description($value)
848
-    {
849
-        $config              = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
850
-        $display_description = isset($config->display_description) ? $config->display_description : 1;
851
-        return $display_description === $value;
852
-    }
853
-
854
-
855
-    /**
856
-     * @return bool
857
-     */
858
-    public static function display_ticket_selector()
859
-    {
860
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
861
-        return isset($config->display_ticket_selector) && $config->display_ticket_selector;
862
-    }
863
-
864
-
865
-    /**
866
-     * @return bool
867
-     * @throws EE_Error
868
-     * @throws ReflectionException
869
-     */
870
-    public static function display_venue()
871
-    {
872
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
873
-        return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name();
874
-    }
875
-
876
-
877
-    /**
878
-     * @return bool
879
-     */
880
-    public static function display_datetimes()
881
-    {
882
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
883
-        return isset($config->display_datetimes) && $config->display_datetimes;
884
-    }
885
-
886
-
887
-    /**
888
-     * @return string
889
-     */
890
-    public static function event_list_title()
891
-    {
892
-        return apply_filters(
893
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
894
-            esc_html__('Upcoming Events', 'event_espresso')
895
-        );
896
-    }
897
-
898
-
899
-    // GRAVEYARD
900
-
901
-
902
-    /**
903
-     * @since 4.4.0
904
-     */
905
-    public static function _doing_it_wrong_notice($function = '')
906
-    {
907
-        EE_Error::doing_it_wrong(
908
-            __FUNCTION__,
909
-            sprintf(
910
-                esc_html__(
911
-                    'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s',
912
-                    'event_espresso'
913
-                ),
914
-                $function,
915
-                '<br />',
916
-                '4.6.0'
917
-            ),
918
-            '4.4.0'
919
-        );
920
-    }
921
-
922
-
923
-    /**
924
-     * @deprecated
925
-     * @since 4.4.0
926
-     */
927
-    public function get_post_data()
928
-    {
929
-        EEH_Event_Query::set_query_params();
930
-    }
931
-
932
-
933
-    /**
934
-     * @throws EE_Error
935
-     * @since 4.4.0
936
-     * @deprecated
937
-     */
938
-    public function posts_fields($SQL, WP_Query $wp_query)
939
-    {
940
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
941
-        return EEH_Event_Query::posts_fields($SQL, $wp_query);
942
-    }
943
-
944
-
945
-    /**
946
-     * @throws EE_Error
947
-     * @since 4.4.0
948
-     * @deprecated
949
-     */
950
-    public static function posts_fields_sql_for_orderby($orderby_params = [])
951
-    {
952
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
953
-        return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
954
-    }
955
-
956
-
957
-    /**
958
-     * @throws EE_Error
959
-     * @since 4.4.0
960
-     * @deprecated
961
-     */
962
-    public function posts_join($SQL, WP_Query $wp_query)
963
-    {
964
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
965
-        return EEH_Event_Query::posts_join($SQL, $wp_query);
966
-    }
967
-
968
-
969
-    /**
970
-     * @deprecated
971
-     * @since 4.4.0
972
-     */
973
-    public static function posts_join_sql_for_terms($join_terms = null)
974
-    {
975
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
976
-        return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
977
-    }
978
-
979
-
980
-    /**
981
-     * @throws EE_Error
982
-     * @since 4.4.0
983
-     * @deprecated
984
-     */
985
-    public static function posts_join_for_orderby($orderby_params = [])
986
-    {
987
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
988
-        return EEH_Event_Query::posts_join_for_orderby($orderby_params);
989
-    }
990
-
991
-
992
-    /**
993
-     * @throws EE_Error
994
-     * @since 4.4.0
995
-     * @deprecated
996
-     */
997
-    public function posts_where($SQL, WP_Query $wp_query)
998
-    {
999
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1000
-        return EEH_Event_Query::posts_where($SQL, $wp_query);
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * @throws EE_Error
1006
-     * @since 4.4.0
1007
-     * @deprecated
1008
-     */
1009
-    public static function posts_where_sql_for_show_expired($show_expired = false)
1010
-    {
1011
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1012
-        return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * @deprecated
1018
-     * @since 4.4.0
1019
-     */
1020
-    public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
1021
-    {
1022
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1023
-        return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * @throws EE_Error
1029
-     * @since 4.4.0
1030
-     * @deprecated
1031
-     */
1032
-    public static function posts_where_sql_for_event_list_month($month = null)
1033
-    {
1034
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1035
-        return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * @throws EE_Error
1041
-     * @since 4.4.0
1042
-     * @deprecated
1043
-     */
1044
-    public function posts_orderby($SQL, WP_Query $wp_query)
1045
-    {
1046
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1047
-        return EEH_Event_Query::posts_orderby($SQL, $wp_query);
1048
-    }
1049
-
1050
-
1051
-    /**
1052
-     * @throws EE_Error
1053
-     * @since 4.4.0
1054
-     * @deprecated
1055
-     */
1056
-    public static function posts_orderby_sql($orderby_params = [], $sort = 'ASC')
1057
-    {
1058
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1059
-        return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
1060
-    }
20
+	const EVENT_DETAILS_PRIORITY   = 100;
21
+
22
+	const EVENT_DATETIMES_PRIORITY = 110;
23
+
24
+	const EVENT_TICKETS_PRIORITY   = 120;
25
+
26
+	const EVENT_VENUES_PRIORITY    = 130;
27
+
28
+
29
+	public static $espresso_event_list_ID    = 0;
30
+
31
+	public static $espresso_grid_event_lists = [];
32
+
33
+	/**
34
+	 * @type bool $using_get_the_excerpt
35
+	 */
36
+	protected static $using_get_the_excerpt = false;
37
+
38
+	/**
39
+	 * Used to flag when the event list is being called from an external iframe.
40
+	 *
41
+	 * @var bool $iframe
42
+	 */
43
+	protected static $iframe = false;
44
+
45
+	/**
46
+	 * @var EventListIframeEmbedButton $_iframe_embed_button
47
+	 */
48
+	private static $_iframe_embed_button;
49
+
50
+	/**
51
+	 * @type EE_Template_Part_Manager $template_parts
52
+	 */
53
+	protected $template_parts;
54
+
55
+
56
+	/**
57
+	 * @return EED_Events_Archive
58
+	 * @throws EE_Error
59
+	 * @throws ReflectionException
60
+	 */
61
+	public static function instance()
62
+	{
63
+		return parent::get_instance(__CLASS__);
64
+	}
65
+
66
+
67
+	/**
68
+	 * for hooking into EE Core, other modules, etc
69
+	 *
70
+	 * @return void
71
+	 * @throws InvalidArgumentException
72
+	 * @throws InvalidDataTypeException
73
+	 * @throws InvalidInterfaceException
74
+	 */
75
+	public static function set_hooks()
76
+	{
77
+		/** @var CustomPostTypeDefinitions $custom_post_type_definitions */
78
+		$custom_post_type_definitions = LoaderFactory::getLoader()->getShared(CustomPostTypeDefinitions::class);
79
+		$custom_post_types            = $custom_post_type_definitions->getDefinitions();
80
+		EE_Config::register_route(
81
+			$custom_post_types['espresso_events']['plural_slug'],
82
+			'Events_Archive',
83
+			'run'
84
+		);
85
+		EE_Config::register_route(
86
+			'event_list',
87
+			'Events_Archive',
88
+			'event_list'
89
+		);
90
+		EE_Config::register_route(
91
+			'iframe',
92
+			'Events_Archive',
93
+			'event_list_iframe',
94
+			'event_list'
95
+		);
96
+		add_action('wp_loaded', ['EED_Events_Archive', 'set_definitions'], 2);
97
+	}
98
+
99
+
100
+	/**
101
+	 * for hooking into EE Admin Core, other modules, etc
102
+	 *
103
+	 * @return void
104
+	 */
105
+	public static function set_hooks_admin()
106
+	{
107
+		add_action('wp_loaded', ['EED_Events_Archive', 'set_definitions'], 2);
108
+		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
109
+		// to load assets for "espresso_events" page on the "default" route (action)
110
+		add_action(
111
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
112
+			['EED_Events_Archive', 'event_list_iframe_embed_button'],
113
+			10
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return void
120
+	 */
121
+	public static function set_definitions()
122
+	{
123
+		define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
124
+		define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
125
+	}
126
+
127
+
128
+	/**
129
+	 * set up EE_Events_Archive_Config
130
+	 */
131
+	protected function set_config()
132
+	{
133
+		$this->set_config_section('template_settings');
134
+		$this->set_config_class('EE_Events_Archive_Config');
135
+		$this->set_config_name('EED_Events_Archive');
136
+	}
137
+
138
+
139
+	/**
140
+	 * @return EventListIframeEmbedButton
141
+	 */
142
+	public static function get_iframe_embed_button()
143
+	{
144
+		if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
145
+			self::$_iframe_embed_button = new EventListIframeEmbedButton();
146
+		}
147
+		return self::$_iframe_embed_button;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @return void
153
+	 */
154
+	public static function event_list_iframe_embed_button()
155
+	{
156
+		$iframe_embed_button = EED_Events_Archive::get_iframe_embed_button();
157
+		$iframe_embed_button->addEmbedButton();
158
+	}
159
+
160
+
161
+	/**
162
+	 * @param EE_Events_Archive_Config|null $config
163
+	 * @return EE_Template_Part_Manager
164
+	 * @throws EE_Error
165
+	 */
166
+	public function initialize_template_parts(EE_Events_Archive_Config $config = null)
167
+	{
168
+		$config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
169
+		EEH_Autoloader::instance()->register_template_part_autoloaders();
170
+		$template_parts = new EE_Template_Part_Manager();
171
+		$template_parts->add_template_part(
172
+			'tickets',
173
+			esc_html__('Ticket Selector', 'event_espresso'),
174
+			'content-espresso_events-tickets.php',
175
+			$config->display_order_tickets
176
+		);
177
+		$template_parts->add_template_part(
178
+			'datetimes',
179
+			esc_html__('Dates and Times', 'event_espresso'),
180
+			'content-espresso_events-datetimes.php',
181
+			$config->display_order_datetimes
182
+		);
183
+		$template_parts->add_template_part(
184
+			'event',
185
+			esc_html__('Event Description', 'event_espresso'),
186
+			'content-espresso_events-details.php',
187
+			$config->display_order_event
188
+		);
189
+		$template_parts->add_template_part(
190
+			'venue',
191
+			esc_html__('Venue Information', 'event_espresso'),
192
+			'content-espresso_events-venues.php',
193
+			$config->display_order_venue
194
+		);
195
+		do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
196
+		return $template_parts;
197
+	}
198
+
199
+
200
+	/**
201
+	 * initial module setup
202
+	 * this gets called by the EE_Front_Controller if the module route is found in the incoming request
203
+	 *
204
+	 * @param WP $WP
205
+	 * @return void
206
+	 */
207
+	public function run($WP)
208
+	{
209
+		do_action('AHEE__EED_Events_Archive__before_run');
210
+		// ensure valid EE_Events_Archive_Config() object exists
211
+		$this->set_config();
212
+		/** @type EE_Events_Archive_Config $config */
213
+		$config = $this->config();
214
+		// load other required components
215
+		$this->load_event_list_assets();
216
+		// filter the WP posts_join, posts_where, and posts_orderby SQL clauses
217
+		// add query filters
218
+		EEH_Event_Query::add_query_filters();
219
+		// set params that will get used by the filters
220
+		EEH_Event_Query::set_query_params(
221
+			'',                             // month
222
+			'',                             // category
223
+			$config->display_expired_events // show_expired
224
+		);
225
+		// check what template is loaded
226
+		add_filter('template_include', [$this, 'template_include'], 999, 1);
227
+	}
228
+
229
+
230
+	/**
231
+	 * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
232
+	 *
233
+	 * @return void
234
+	 */
235
+	public function event_list()
236
+	{
237
+		// ensure valid EE_Events_Archive_Config() object exists
238
+		$this->set_config();
239
+		// load other required components
240
+		$this->load_event_list_assets();
241
+	}
242
+
243
+
244
+	/**
245
+	 * @return void
246
+	 * @throws EE_Error
247
+	 * @throws ReflectionException
248
+	 */
249
+	public function event_list_iframe()
250
+	{
251
+		EED_Events_Archive::$iframe = true;
252
+		$event_list_iframe          = new EventsArchiveIframe($this);
253
+		$event_list_iframe->display();
254
+	}
255
+
256
+
257
+	/**
258
+	 * @return bool
259
+	 */
260
+	public static function is_iframe()
261
+	{
262
+		return EED_Events_Archive::$iframe;
263
+	}
264
+
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public static function link_target()
270
+	{
271
+		return EED_Events_Archive::$iframe ? ' target="_blank"' : '';
272
+	}
273
+
274
+
275
+	/**
276
+	 * @param string $template
277
+	 * @return string
278
+	 * @throws EE_Error
279
+	 * @throws ReflectionException
280
+	 */
281
+	public function template_include($template = '')
282
+	{
283
+		// don't add content filter for dedicated EE child themes or private posts
284
+		if (! EEH_Template::is_espresso_theme()) {
285
+			/** @type EE_Events_Archive_Config $config */
286
+			$config = $this->config();
287
+			// add status banner ?
288
+			if ($config->display_status_banner) {
289
+				add_filter('the_title', ['EED_Events_Archive', 'the_title'], 100, 2);
290
+			}
291
+			// if NOT a custom template
292
+			if (
293
+				apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
294
+				|| EE_Registry::instance()
295
+							  ->load_core('Front_Controller')
296
+							  ->get_selected_template() !== 'archive-espresso_events.php'
297
+			) {
298
+				add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
299
+				// load functions.php file for the theme (loaded by WP if using child theme)
300
+				EEH_Template::load_espresso_theme_functions();
301
+				EED_Events_Archive::addEventDetailsFilters();
302
+				// don't display entry meta because the existing theme will take care of that
303
+				add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
304
+			}
305
+		}
306
+		return $template;
307
+	}
308
+
309
+
310
+	/**
311
+	 * kinda hacky, but if a theme is using get_the_excerpt(),
312
+	 * then we need to remove our filters on the_content()
313
+	 *
314
+	 * @param string $excerpt
315
+	 * @return string
316
+	 * @throws EE_Error
317
+	 * @throws ReflectionException
318
+	 */
319
+	public static function get_the_excerpt($excerpt = '')
320
+	{
321
+		if (post_password_required()) {
322
+			return $excerpt;
323
+		}
324
+		if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
325
+			EED_Events_Archive::removeEventDetailsFilters(false);
326
+			$excerpt = EED_Events_Archive::event_details($excerpt);
327
+		} else {
328
+			EED_Events_Archive::$using_get_the_excerpt = true;
329
+			add_filter('wp_trim_excerpt', ['EED_Events_Archive', 'end_get_the_excerpt'], 999, 1);
330
+		}
331
+		return $excerpt;
332
+	}
333
+
334
+
335
+	/**
336
+	 * @param string $text
337
+	 * @return string
338
+	 */
339
+	public static function end_get_the_excerpt($text = '')
340
+	{
341
+		EED_Events_Archive::$using_get_the_excerpt = false;
342
+		return $text;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param string $title
348
+	 * @param string $id
349
+	 * @return string
350
+	 * @throws EE_Error
351
+	 * @throws ReflectionException
352
+	 */
353
+	public static function the_title($title = '', $id = '')
354
+	{
355
+		global $post;
356
+		if ($post instanceof WP_Post) {
357
+			return (EED_Events_Archive::isBlockTheme() || in_the_loop()) && $post->ID == $id
358
+				? espresso_event_status_banner($post->ID) . $title
359
+				: $title;
360
+		}
361
+		return $title;
362
+	}
363
+
364
+
365
+	/**
366
+	 * @param string $content
367
+	 * @return string
368
+	 * @throws EE_Error
369
+	 * @throws ReflectionException
370
+	 */
371
+	public static function event_details($content)
372
+	{
373
+		global $post;
374
+		static $current_post_ID = 0;
375
+		if (
376
+			$current_post_ID !== $post->ID
377
+			&& $post->post_type === 'espresso_events'
378
+			&& ! EED_Events_Archive::$using_get_the_excerpt
379
+			&& ! post_password_required()
380
+			&& (
381
+				apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
382
+				|| ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
383
+			)
384
+		) {
385
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
386
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
387
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
388
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
389
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
390
+			// so the following allows this filter to be applied multiple times, but only once for real
391
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
392
+			if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
393
+				$content = EED_Events_Archive::use_sortable_display_order();
394
+			} else {
395
+				$content = EED_Events_Archive::use_filterable_display_order();
396
+			}
397
+		}
398
+		return $content;
399
+	}
400
+
401
+
402
+	/**
403
+	 * @return string
404
+	 * @throws EE_Error
405
+	 * @throws ReflectionException
406
+	 */
407
+	protected static function use_sortable_display_order()
408
+	{
409
+		// no further password checks required atm
410
+		add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
411
+		// remove this callback from being applied to the_content()
412
+		EED_Events_Archive::removeEventDetailsFilters();
413
+		// now add additional content depending on whether event is using the_excerpt() or the_content()
414
+		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
415
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
416
+		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
417
+		// re-add our main filters (or else the next event won't have them)
418
+		EED_Events_Archive::addEventDetailsFilters();
419
+		remove_filter(
420
+			'FHEE__EED_Events_Archive__event_details__no_post_password_required',
421
+			'__return_true'
422
+		);
423
+		return $content;
424
+	}
425
+
426
+
427
+	/**
428
+	 * @return string
429
+	 */
430
+	protected static function use_filterable_display_order()
431
+	{
432
+		// remove this callback from being applied to the_content()
433
+		EED_Events_Archive::removeEventDetailsFilters();
434
+		// now add additional content depending on whether event is using the_excerpt() or the_content()
435
+		EED_Events_Archive::_add_additional_excerpt_filters();
436
+		EED_Events_Archive::_add_additional_content_filters();
437
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
438
+		// now load our template
439
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
440
+		// re-add our main filters (or else the next event won't have them)
441
+		EED_Events_Archive::addEventDetailsFilters();
442
+		// but remove the other filters so that they don't get applied to the next post
443
+		EED_Events_Archive::_remove_additional_events_archive_filters();
444
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
445
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
446
+		// return ! empty( $template ) ? $template : $content;
447
+		return $content;
448
+	}
449
+
450
+
451
+	/**
452
+	 * adds datetimes ABOVE content
453
+	 *
454
+	 * @param string $content
455
+	 * @return string
456
+	 */
457
+	public static function event_datetimes($content)
458
+	{
459
+		if (post_password_required()) {
460
+			return $content;
461
+		}
462
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
463
+	}
464
+
465
+
466
+	/**
467
+	 * adds tickets ABOVE content (which includes datetimes)
468
+	 *
469
+	 * @param string $content
470
+	 * @return string
471
+	 */
472
+	public static function event_tickets($content)
473
+	{
474
+		if (post_password_required()) {
475
+			return $content;
476
+		}
477
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
478
+	}
479
+
480
+
481
+	/**
482
+	 * adds venues BELOW content
483
+	 *
484
+	 * @param string $content
485
+	 * @return string
486
+	 */
487
+	public static function event_venue($content)
488
+	{
489
+		return EED_Events_Archive::event_venues($content);
490
+	}
491
+
492
+
493
+	/**
494
+	 * adds venues BELOW content
495
+	 *
496
+	 * @param string $content
497
+	 * @return string
498
+	 */
499
+	public static function event_venues($content)
500
+	{
501
+		if (post_password_required()) {
502
+			return $content;
503
+		}
504
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
505
+	}
506
+
507
+
508
+	/**
509
+	 * @return bool
510
+	 * @since $VID:$
511
+	 */
512
+	public static function isBlockTheme()
513
+	{
514
+		return function_exists('wp_is_block_theme') && wp_is_block_theme();
515
+	}
516
+
517
+
518
+	/**
519
+	 * @return string
520
+	 * @since $VID:$
521
+	 */
522
+	public static function getExcerptFilter()
523
+	{
524
+		static $excerpt_filter = null;
525
+		if ($excerpt_filter === null) {
526
+			$excerpt_filter = EED_Events_Archive::isBlockTheme() ? 'get_the_excerpt' : 'the_excerpt';
527
+		}
528
+		return $excerpt_filter;
529
+	}
530
+
531
+
532
+	/**
533
+	 * @since $VID:$
534
+	 */
535
+	protected static function addEventDetailsFilters()
536
+	{
537
+		add_filter(
538
+			'the_content',
539
+			['EED_Events_Archive', 'event_details'],
540
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
541
+		);
542
+		// but because we don't know if the theme is using the_excerpt()
543
+		add_filter(
544
+			EED_Events_Archive::getExcerptFilter(),
545
+			['EED_Events_Archive', 'event_details'],
546
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
547
+		);
548
+		// and just in case they are running get_the_excerpt() which DESTROYS things
549
+		add_filter('get_the_excerpt', ['EED_Events_Archive', 'get_the_excerpt'], 1, 1);
550
+	}
551
+
552
+
553
+	/**
554
+	 * @param bool $and_get_the_excerpt
555
+	 * @since $VID:$
556
+	 */
557
+	protected static function removeEventDetailsFilters($and_get_the_excerpt = true)
558
+	{
559
+		// we need to first remove all callbacks from being applied to the_content()
560
+		// (otherwise it will recurse and blow up the interweb)
561
+		remove_filter(
562
+			'the_content',
563
+			['EED_Events_Archive', 'event_details'],
564
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
565
+		);
566
+		remove_filter(
567
+			EED_Events_Archive::getExcerptFilter(),
568
+			['EED_Events_Archive', 'event_details'],
569
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
570
+		);
571
+		if ($and_get_the_excerpt) {
572
+			remove_filter('get_the_excerpt', ['EED_Events_Archive', 'get_the_excerpt'], 1);
573
+		}
574
+	}
575
+
576
+
577
+	/**
578
+	 * @return void
579
+	 */
580
+	private static function _add_additional_excerpt_filters()
581
+	{
582
+		add_filter(
583
+			EED_Events_Archive::getExcerptFilter(),
584
+			['EED_Events_Archive', 'event_datetimes'],
585
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
586
+		);
587
+		add_filter(
588
+			EED_Events_Archive::getExcerptFilter(),
589
+			['EED_Events_Archive', 'event_tickets'],
590
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
591
+		);
592
+		add_filter(
593
+			EED_Events_Archive::getExcerptFilter(),
594
+			['EED_Events_Archive', 'event_venues'],
595
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
596
+		);
597
+	}
598
+
599
+
600
+	/**
601
+	 * @return void
602
+	 */
603
+	private static function _add_additional_content_filters()
604
+	{
605
+		add_filter(
606
+			'the_content',
607
+			['EED_Events_Archive', 'event_datetimes'],
608
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
609
+		);
610
+		add_filter(
611
+			'the_content',
612
+			['EED_Events_Archive', 'event_tickets'],
613
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
614
+		);
615
+		add_filter(
616
+			'the_content',
617
+			['EED_Events_Archive', 'event_venues'],
618
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
619
+		);
620
+	}
621
+
622
+
623
+	/**
624
+	 * @return void
625
+	 */
626
+	private static function _remove_additional_events_archive_filters()
627
+	{
628
+		remove_filter(
629
+			EED_Events_Archive::getExcerptFilter(),
630
+			['EED_Events_Archive', 'event_datetimes'],
631
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
632
+		);
633
+		remove_filter(
634
+			EED_Events_Archive::getExcerptFilter(),
635
+			['EED_Events_Archive', 'event_tickets'],
636
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
637
+		);
638
+		remove_filter(
639
+			EED_Events_Archive::getExcerptFilter(),
640
+			['EED_Events_Archive', 'event_venues'],
641
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
642
+		);
643
+		remove_filter(
644
+			'the_content',
645
+			['EED_Events_Archive', 'event_datetimes'],
646
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
647
+		);
648
+		remove_filter(
649
+			'the_content',
650
+			['EED_Events_Archive', 'event_tickets'],
651
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
652
+		);
653
+		remove_filter(
654
+			'the_content',
655
+			['EED_Events_Archive', 'event_venues'],
656
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
657
+		);
658
+	}
659
+
660
+
661
+	/**
662
+	 * @return void
663
+	 */
664
+	public static function remove_all_events_archive_filters()
665
+	{
666
+		// remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
667
+		remove_filter('the_title', ['EED_Events_Archive', 'the_title'], 1);
668
+		remove_filter(
669
+			EED_Events_Archive::getExcerptFilter(),
670
+			['EED_Events_Archive', 'event_details'],
671
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
672
+		);
673
+		remove_filter(
674
+			EED_Events_Archive::getExcerptFilter(),
675
+			['EED_Events_Archive', 'event_datetimes'],
676
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
677
+		);
678
+		remove_filter(
679
+			EED_Events_Archive::getExcerptFilter(),
680
+			['EED_Events_Archive', 'event_tickets'],
681
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
682
+		);
683
+		remove_filter(
684
+			EED_Events_Archive::getExcerptFilter(),
685
+			['EED_Events_Archive', 'event_venues'],
686
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
687
+		);
688
+		remove_filter(
689
+			'the_content',
690
+			['EED_Events_Archive', 'event_details'],
691
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
692
+		);
693
+		remove_filter(
694
+			'the_content',
695
+			['EED_Events_Archive', 'event_datetimes'],
696
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
697
+		);
698
+		remove_filter(
699
+			'the_content',
700
+			['EED_Events_Archive', 'event_tickets'],
701
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
702
+		);
703
+		remove_filter(
704
+			'the_content',
705
+			['EED_Events_Archive', 'event_venues'],
706
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
707
+		);
708
+		// don't display entry meta because the existing theme will take care of that
709
+		remove_filter(
710
+			'FHEE__content_espresso_events_details_template__display_entry_meta',
711
+			'__return_false'
712
+		);
713
+	}
714
+
715
+
716
+	/**
717
+	 * @return void
718
+	 */
719
+	public function load_event_list_assets()
720
+	{
721
+		do_action('AHEE__EED_Events_Archive__before_load_assets');
722
+		add_filter('FHEE_load_EE_Session', '__return_true');
723
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
724
+		add_action('wp_enqueue_scripts', [$this, 'wp_enqueue_scripts'], 10);
725
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
726
+			add_action('wp_enqueue_scripts', ['EEH_Maps', 'espresso_google_map_js'], 11);
727
+		}
728
+	}
729
+
730
+
731
+	/**
732
+	 * @return void
733
+	 * @throws EE_Error
734
+	 */
735
+	public function wp_enqueue_scripts()
736
+	{
737
+		// get some style
738
+		if (apply_filters('FHEE_enable_default_espresso_css', false)) {
739
+			// first check uploads folder
740
+			if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
741
+				wp_register_style(
742
+					$this->theme,
743
+					get_stylesheet_directory_uri() . $this->theme . '/style.css',
744
+					['dashicons', 'espresso_default']
745
+				);
746
+			}
747
+			wp_enqueue_style($this->theme);
748
+		}
749
+	}
750
+
751
+
752
+	/**
753
+	 * @static
754
+	 * @return void
755
+	 */
756
+	public static function template_settings_form()
757
+	{
758
+		$template_settings                     = EE_Registry::instance()->CFG->template_settings;
759
+		$template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive)
760
+			? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
761
+		$template_settings->EED_Events_Archive = apply_filters(
762
+			'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
763
+			$template_settings->EED_Events_Archive
764
+		);
765
+		$events_archive_settings               = [
766
+			'display_status_banner'   => 0,
767
+			'display_description'     => 1,
768
+			'display_ticket_selector' => 0,
769
+			'display_datetimes'       => 1,
770
+			'display_venue'           => 0,
771
+			'display_expired_events'  => 0,
772
+		];
773
+		$events_archive_settings               = array_merge(
774
+			$events_archive_settings,
775
+			(array) $template_settings->EED_Events_Archive
776
+		);
777
+		EEH_Template::display_template(
778
+			EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
779
+			$events_archive_settings
780
+		);
781
+	}
782
+
783
+
784
+	/**
785
+	 * @param EE_Template_Config $CFG
786
+	 * @param array              $REQ
787
+	 * @return EE_Template_Config
788
+	 */
789
+	public static function update_template_settings($CFG, $REQ)
790
+	{
791
+		$CFG->EED_Events_Archive = new EE_Events_Archive_Config();
792
+		// unless we are resetting the config...
793
+		if (
794
+			! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
795
+			|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
796
+		) {
797
+			$CFG->EED_Events_Archive->display_status_banner   = isset($REQ['EED_Events_Archive_display_status_banner'])
798
+				? absint($REQ['EED_Events_Archive_display_status_banner'])
799
+				: 0;
800
+			$CFG->EED_Events_Archive->display_description     = isset($REQ['EED_Events_Archive_display_description'])
801
+				? absint($REQ['EED_Events_Archive_display_description'])
802
+				: 1;
803
+			$CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
804
+				? absint($REQ['EED_Events_Archive_display_ticket_selector'])
805
+				: 0;
806
+			$CFG->EED_Events_Archive->display_datetimes       = isset($REQ['EED_Events_Archive_display_datetimes'])
807
+				? absint($REQ['EED_Events_Archive_display_datetimes'])
808
+				: 1;
809
+			$CFG->EED_Events_Archive->display_venue           = isset($REQ['EED_Events_Archive_display_venue'])
810
+				? absint($REQ['EED_Events_Archive_display_venue'])
811
+				: 0;
812
+			$CFG->EED_Events_Archive->display_expired_events  = isset($REQ['EED_Events_Archive_display_expired_events'])
813
+				? absint($REQ['EED_Events_Archive_display_expired_events'])
814
+				: 0;
815
+		}
816
+		return $CFG;
817
+	}
818
+
819
+
820
+	/**
821
+	 * @param string $extra_class
822
+	 * @return string
823
+	 */
824
+	public static function event_list_css($extra_class = '')
825
+	{
826
+		$event_list_css   = ! empty($extra_class) ? [$extra_class] : [];
827
+		$event_list_css[] = 'espresso-event-list-event';
828
+		return implode(' ', $event_list_css);
829
+	}
830
+
831
+
832
+	/**
833
+	 * @return array
834
+	 * @throws EE_Error
835
+	 * @throws ReflectionException
836
+	 */
837
+	public static function event_categories()
838
+	{
839
+		return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
840
+	}
841
+
842
+
843
+	/**
844
+	 * @param $value
845
+	 * @return bool
846
+	 */
847
+	public static function display_description($value)
848
+	{
849
+		$config              = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
850
+		$display_description = isset($config->display_description) ? $config->display_description : 1;
851
+		return $display_description === $value;
852
+	}
853
+
854
+
855
+	/**
856
+	 * @return bool
857
+	 */
858
+	public static function display_ticket_selector()
859
+	{
860
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
861
+		return isset($config->display_ticket_selector) && $config->display_ticket_selector;
862
+	}
863
+
864
+
865
+	/**
866
+	 * @return bool
867
+	 * @throws EE_Error
868
+	 * @throws ReflectionException
869
+	 */
870
+	public static function display_venue()
871
+	{
872
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
873
+		return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name();
874
+	}
875
+
876
+
877
+	/**
878
+	 * @return bool
879
+	 */
880
+	public static function display_datetimes()
881
+	{
882
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
883
+		return isset($config->display_datetimes) && $config->display_datetimes;
884
+	}
885
+
886
+
887
+	/**
888
+	 * @return string
889
+	 */
890
+	public static function event_list_title()
891
+	{
892
+		return apply_filters(
893
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
894
+			esc_html__('Upcoming Events', 'event_espresso')
895
+		);
896
+	}
897
+
898
+
899
+	// GRAVEYARD
900
+
901
+
902
+	/**
903
+	 * @since 4.4.0
904
+	 */
905
+	public static function _doing_it_wrong_notice($function = '')
906
+	{
907
+		EE_Error::doing_it_wrong(
908
+			__FUNCTION__,
909
+			sprintf(
910
+				esc_html__(
911
+					'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s',
912
+					'event_espresso'
913
+				),
914
+				$function,
915
+				'<br />',
916
+				'4.6.0'
917
+			),
918
+			'4.4.0'
919
+		);
920
+	}
921
+
922
+
923
+	/**
924
+	 * @deprecated
925
+	 * @since 4.4.0
926
+	 */
927
+	public function get_post_data()
928
+	{
929
+		EEH_Event_Query::set_query_params();
930
+	}
931
+
932
+
933
+	/**
934
+	 * @throws EE_Error
935
+	 * @since 4.4.0
936
+	 * @deprecated
937
+	 */
938
+	public function posts_fields($SQL, WP_Query $wp_query)
939
+	{
940
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
941
+		return EEH_Event_Query::posts_fields($SQL, $wp_query);
942
+	}
943
+
944
+
945
+	/**
946
+	 * @throws EE_Error
947
+	 * @since 4.4.0
948
+	 * @deprecated
949
+	 */
950
+	public static function posts_fields_sql_for_orderby($orderby_params = [])
951
+	{
952
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
953
+		return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
954
+	}
955
+
956
+
957
+	/**
958
+	 * @throws EE_Error
959
+	 * @since 4.4.0
960
+	 * @deprecated
961
+	 */
962
+	public function posts_join($SQL, WP_Query $wp_query)
963
+	{
964
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
965
+		return EEH_Event_Query::posts_join($SQL, $wp_query);
966
+	}
967
+
968
+
969
+	/**
970
+	 * @deprecated
971
+	 * @since 4.4.0
972
+	 */
973
+	public static function posts_join_sql_for_terms($join_terms = null)
974
+	{
975
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
976
+		return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
977
+	}
978
+
979
+
980
+	/**
981
+	 * @throws EE_Error
982
+	 * @since 4.4.0
983
+	 * @deprecated
984
+	 */
985
+	public static function posts_join_for_orderby($orderby_params = [])
986
+	{
987
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
988
+		return EEH_Event_Query::posts_join_for_orderby($orderby_params);
989
+	}
990
+
991
+
992
+	/**
993
+	 * @throws EE_Error
994
+	 * @since 4.4.0
995
+	 * @deprecated
996
+	 */
997
+	public function posts_where($SQL, WP_Query $wp_query)
998
+	{
999
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1000
+		return EEH_Event_Query::posts_where($SQL, $wp_query);
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * @throws EE_Error
1006
+	 * @since 4.4.0
1007
+	 * @deprecated
1008
+	 */
1009
+	public static function posts_where_sql_for_show_expired($show_expired = false)
1010
+	{
1011
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1012
+		return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * @deprecated
1018
+	 * @since 4.4.0
1019
+	 */
1020
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
1021
+	{
1022
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1023
+		return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * @throws EE_Error
1029
+	 * @since 4.4.0
1030
+	 * @deprecated
1031
+	 */
1032
+	public static function posts_where_sql_for_event_list_month($month = null)
1033
+	{
1034
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1035
+		return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * @throws EE_Error
1041
+	 * @since 4.4.0
1042
+	 * @deprecated
1043
+	 */
1044
+	public function posts_orderby($SQL, WP_Query $wp_query)
1045
+	{
1046
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1047
+		return EEH_Event_Query::posts_orderby($SQL, $wp_query);
1048
+	}
1049
+
1050
+
1051
+	/**
1052
+	 * @throws EE_Error
1053
+	 * @since 4.4.0
1054
+	 * @deprecated
1055
+	 */
1056
+	public static function posts_orderby_sql($orderby_params = [], $sort = 'ASC')
1057
+	{
1058
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1059
+		return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
1060
+	}
1061 1061
 }
1062 1062
 
1063 1063
 
@@ -1066,9 +1066,9 @@  discard block
 block discarded – undo
1066 1066
  */
1067 1067
 function espresso_get_event_list_ID()
1068 1068
 {
1069
-    EED_Events_Archive::$espresso_event_list_ID++;
1070
-    EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
1071
-    return EED_Events_Archive::$espresso_event_list_ID;
1069
+	EED_Events_Archive::$espresso_event_list_ID++;
1070
+	EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
1071
+	return EED_Events_Archive::$espresso_event_list_ID;
1072 1072
 }
1073 1073
 
1074 1074
 
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
  */
1078 1078
 function espresso_event_list_title()
1079 1079
 {
1080
-    return EED_Events_Archive::event_list_title();
1080
+	return EED_Events_Archive::event_list_title();
1081 1081
 }
1082 1082
 
1083 1083
 
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
  */
1088 1088
 function espresso_event_list_css($extra_class = '')
1089 1089
 {
1090
-    return EED_Events_Archive::event_list_css($extra_class);
1090
+	return EED_Events_Archive::event_list_css($extra_class);
1091 1091
 }
1092 1092
 
1093 1093
 
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
  */
1099 1099
 function espresso_get_event_categories()
1100 1100
 {
1101
-    return EED_Events_Archive::event_categories();
1101
+	return EED_Events_Archive::event_categories();
1102 1102
 }
1103 1103
 
1104 1104
 
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
  */
1108 1108
 function espresso_display_full_description_in_event_list()
1109 1109
 {
1110
-    return EED_Events_Archive::display_description(2);
1110
+	return EED_Events_Archive::display_description(2);
1111 1111
 }
1112 1112
 
1113 1113
 
@@ -1116,7 +1116,7 @@  discard block
 block discarded – undo
1116 1116
  */
1117 1117
 function espresso_display_excerpt_in_event_list()
1118 1118
 {
1119
-    return EED_Events_Archive::display_description(1);
1119
+	return EED_Events_Archive::display_description(1);
1120 1120
 }
1121 1121
 
1122 1122
 
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
  */
1126 1126
 function espresso_display_ticket_selector_in_event_list()
1127 1127
 {
1128
-    return EED_Events_Archive::display_ticket_selector();
1128
+	return EED_Events_Archive::display_ticket_selector();
1129 1129
 }
1130 1130
 
1131 1131
 
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
  */
1137 1137
 function espresso_display_venue_in_event_list()
1138 1138
 {
1139
-    return EED_Events_Archive::display_venue();
1139
+	return EED_Events_Archive::display_venue();
1140 1140
 }
1141 1141
 
1142 1142
 
@@ -1145,5 +1145,5 @@  discard block
 block discarded – undo
1145 1145
  */
1146 1146
 function espresso_display_datetimes_in_event_list()
1147 1147
 {
1148
-    return EED_Events_Archive::display_datetimes();
1148
+	return EED_Events_Archive::display_datetimes();
1149 1149
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public static function set_definitions()
122 122
     {
123
-        define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
124
-        define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
123
+        define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
124
+        define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/');
125 125
     }
126 126
 
127 127
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public static function get_iframe_embed_button()
143 143
     {
144
-        if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
144
+        if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
145 145
             self::$_iframe_embed_button = new EventListIframeEmbedButton();
146 146
         }
147 147
         return self::$_iframe_embed_button;
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
         EEH_Event_Query::add_query_filters();
219 219
         // set params that will get used by the filters
220 220
         EEH_Event_Query::set_query_params(
221
-            '',                             // month
222
-            '',                             // category
221
+            '', // month
222
+            '', // category
223 223
             $config->display_expired_events // show_expired
224 224
         );
225 225
         // check what template is loaded
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
     public function template_include($template = '')
282 282
     {
283 283
         // don't add content filter for dedicated EE child themes or private posts
284
-        if (! EEH_Template::is_espresso_theme()) {
284
+        if ( ! EEH_Template::is_espresso_theme()) {
285 285
             /** @type EE_Events_Archive_Config $config */
286 286
             $config = $this->config();
287 287
             // add status banner ?
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         global $post;
356 356
         if ($post instanceof WP_Post) {
357 357
             return (EED_Events_Archive::isBlockTheme() || in_the_loop()) && $post->ID == $id
358
-                ? espresso_event_status_banner($post->ID) . $title
358
+                ? espresso_event_status_banner($post->ID).$title
359 359
                 : $title;
360 360
         }
361 361
         return $title;
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
         if (post_password_required()) {
460 460
             return $content;
461 461
         }
462
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
462
+        return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content;
463 463
     }
464 464
 
465 465
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         if (post_password_required()) {
475 475
             return $content;
476 476
         }
477
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
477
+        return EEH_Template::locate_template('content-espresso_events-tickets.php').$content;
478 478
     }
479 479
 
480 480
 
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
         if (post_password_required()) {
502 502
             return $content;
503 503
         }
504
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
504
+        return $content.EEH_Template::locate_template('content-espresso_events-venues.php');
505 505
     }
506 506
 
507 507
 
@@ -737,10 +737,10 @@  discard block
 block discarded – undo
737 737
         // get some style
738 738
         if (apply_filters('FHEE_enable_default_espresso_css', false)) {
739 739
             // first check uploads folder
740
-            if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
740
+            if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.'/style.css')) {
741 741
                 wp_register_style(
742 742
                     $this->theme,
743
-                    get_stylesheet_directory_uri() . $this->theme . '/style.css',
743
+                    get_stylesheet_directory_uri().$this->theme.'/style.css',
744 744
                     ['dashicons', 'espresso_default']
745 745
                 );
746 746
             }
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
             'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
763 763
             $template_settings->EED_Events_Archive
764 764
         );
765
-        $events_archive_settings               = [
765
+        $events_archive_settings = [
766 766
             'display_status_banner'   => 0,
767 767
             'display_description'     => 1,
768 768
             'display_ticket_selector' => 0,
@@ -770,12 +770,12 @@  discard block
 block discarded – undo
770 770
             'display_venue'           => 0,
771 771
             'display_expired_events'  => 0,
772 772
         ];
773
-        $events_archive_settings               = array_merge(
773
+        $events_archive_settings = array_merge(
774 774
             $events_archive_settings,
775 775
             (array) $template_settings->EED_Events_Archive
776 776
         );
777 777
         EEH_Template::display_template(
778
-            EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
778
+            EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php',
779 779
             $events_archive_settings
780 780
         );
781 781
     }
Please login to merge, or discard this patch.