Completed
Branch models-cleanup/main (0d2dda)
by
unknown
09:34
created
core/libraries/messages/defaults/EE_Messages_Template_Pack.core.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -310,6 +310,7 @@
 block discarded – undo
310 310
      * @param EE_message_type                          $message_type
311 311
      * @param string                                   $field          The field reference for the specific template being looked up.
312 312
      * @param string                                   $context      The context reference for the specific template being looked up
313
+     * @param EE_Messages_Template_Pack_Default|null $default_pack
313 314
      *
314 315
      * @return string          The template contents.
315 316
      */
Please login to merge, or discard this patch.
Indentation   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -14,511 +14,511 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * This defines the base_path where the templates are located.
19
-     *
20
-     * @since            4.5.0
21
-     *
22
-     * @var string
23
-     */
24
-    protected $_base_path;
17
+	/**
18
+	 * This defines the base_path where the templates are located.
19
+	 *
20
+	 * @since            4.5.0
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $_base_path;
25 25
 
26 26
 
27 27
 
28 28
 
29
-    /**
30
-     * This defines the base_url where things are found for this template pack (possibly variations).
31
-     *
32
-     * @since 4.5.0
33
-     *
34
-     * @var string
35
-     */
36
-    protected $_base_url;
29
+	/**
30
+	 * This defines the base_url where things are found for this template pack (possibly variations).
31
+	 *
32
+	 * @since 4.5.0
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $_base_url;
37 37
 
38 38
 
39 39
 
40
-    /**
41
-     * localized label for this template pack
42
-     *
43
-     * @since            4.5.0
44
-     *
45
-     * @var string
46
-     */
47
-    public $label;
40
+	/**
41
+	 * localized label for this template pack
42
+	 *
43
+	 * @since            4.5.0
44
+	 *
45
+	 * @var string
46
+	 */
47
+	public $label;
48 48
 
49 49
 
50 50
 
51 51
 
52
-    /**
53
-     * used to contain a description for the template pack.
54
-     *
55
-     * @since 4.5.0
56
-     *
57
-     * @var string
58
-     */
59
-    public $description;
52
+	/**
53
+	 * used to contain a description for the template pack.
54
+	 *
55
+	 * @since 4.5.0
56
+	 *
57
+	 * @var string
58
+	 */
59
+	public $description;
60 60
 
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * How this template is referenced in the db
66
-     *
67
-     * @since 4.5.0
68
-     *
69
-     * @var string
70
-     */
71
-    public $dbref;
64
+	/**
65
+	 * How this template is referenced in the db
66
+	 *
67
+	 * @since 4.5.0
68
+	 *
69
+	 * @var string
70
+	 */
71
+	public $dbref;
72 72
 
73 73
 
74 74
 
75 75
 
76
-    /**
77
-     * This is an array indexed by messenger and with an array of message types as values that indicate what messenger and message type this template pack supports by default.  It is possible for this to be modified by plugins via filters, but out of the box, this is what the template pack supports.
78
-     *
79
-     * @since 4.5.0
80
-     *
81
-     * @var array.
82
-     */
83
-    protected $_supports = array();
76
+	/**
77
+	 * This is an array indexed by messenger and with an array of message types as values that indicate what messenger and message type this template pack supports by default.  It is possible for this to be modified by plugins via filters, but out of the box, this is what the template pack supports.
78
+	 *
79
+	 * @since 4.5.0
80
+	 *
81
+	 * @var array.
82
+	 */
83
+	protected $_supports = array();
84 84
 
85 85
 
86 86
 
87 87
 
88 88
 
89
-    /**
90
-     * Holds the retrieved default templates for this template pack in a multidimensional array indexed by context and field, for a given messenger and message type.  Example format:
91
-     *
92
-     * $templates = array(
93
-     *  'email' => array(
94
-     *      'registration' => array(
95
-     *          'admin' => array(
96
-     *              'to' => 'contents',
97
-     *              'from' => 'contents',
98
-     *              'subject' => 'contents',
99
-     *              'content' => 'contents',
100
-     *              'event_list' => 'contents',
101
-     *              'attendee_list' => 'contents'
102
-     *          ),
103
-     *          'attendee' => array(
104
-     *              'to' => 'contents',
105
-     *              'from' => 'contents',
106
-     *              'subject' => 'contents',
107
-     *              'content' => 'contents',
108
-     *              'event_list' => 'contents',
109
-     *              'attendee_list' => 'contents',
110
-     *          ),
111
-     *      )
112
-     *  )
113
-     * )
114
-     *
115
-     * @since 4.5.0
116
-     *
117
-     * @var array
118
-     */
119
-    protected $_templates = array();
89
+	/**
90
+	 * Holds the retrieved default templates for this template pack in a multidimensional array indexed by context and field, for a given messenger and message type.  Example format:
91
+	 *
92
+	 * $templates = array(
93
+	 *  'email' => array(
94
+	 *      'registration' => array(
95
+	 *          'admin' => array(
96
+	 *              'to' => 'contents',
97
+	 *              'from' => 'contents',
98
+	 *              'subject' => 'contents',
99
+	 *              'content' => 'contents',
100
+	 *              'event_list' => 'contents',
101
+	 *              'attendee_list' => 'contents'
102
+	 *          ),
103
+	 *          'attendee' => array(
104
+	 *              'to' => 'contents',
105
+	 *              'from' => 'contents',
106
+	 *              'subject' => 'contents',
107
+	 *              'content' => 'contents',
108
+	 *              'event_list' => 'contents',
109
+	 *              'attendee_list' => 'contents',
110
+	 *          ),
111
+	 *      )
112
+	 *  )
113
+	 * )
114
+	 *
115
+	 * @since 4.5.0
116
+	 *
117
+	 * @var array
118
+	 */
119
+	protected $_templates = array();
120 120
 
121 121
 
122 122
 
123 123
 
124 124
 
125 125
 
126
-    /**
127
-     * Template Packs must ALWAYS have a default variation defined.  This property allow one to override the default variation labels per messenger.
128
-     * example:
129
-     * $this->_default_variation_labels = array( 'email' =>  __('Default', 'event_espresso' ) );
130
-     *
131
-     * @var array
132
-     */
133
-    protected $_default_variation_labels = array();
126
+	/**
127
+	 * Template Packs must ALWAYS have a default variation defined.  This property allow one to override the default variation labels per messenger.
128
+	 * example:
129
+	 * $this->_default_variation_labels = array( 'email' =>  __('Default', 'event_espresso' ) );
130
+	 *
131
+	 * @var array
132
+	 */
133
+	protected $_default_variation_labels = array();
134 134
 
135 135
 
136 136
 
137 137
 
138
-    /**
139
-     * This is an array of extra css variations for message templates indexed by messenger with the values as an array or message types the variations apply to as the key  and then values are an array with variation slugs as the key and label as the value. Note the default variation is not included in this array.  So the structure is:
140
-     * array(
141
-     *  'email' => array(
142
-     *  )
143
-     * )
144
-     *
145
-     * Keep in mind that this property is used both for indicating valid variations for a given message type and messenger but the variation files themselves are ONLY unique to the messenger.  So if you have a variation for the html messenger referenced by the slug "sunset_red" Then the variation file for the main type will be html_main_sunset_red.css.  All the array in this property allows you to do, is indicate that with certain message types the sunset_red variation is available but for other message types its not.  But you could NOT have a sunset_red variation file for one messenger/message_type and a different one for another messenger/message_type.  If you want different css looks then you can define a different structural layout for the template , messenger, message type combination and in the same sunset_red.css variation file just add css specific to that layout.
146
-     *
147
-     * @since 4.5.0
148
-     *
149
-     * @var array
150
-     */
151
-    public $_variations = array();
152
-
153
-
154
-
155
-
156
-    /**
157
-     * Template pack constructor
158
-     *
159
-     * @since 4.5.0
160
-     */
161
-    public function __construct()
162
-    {
163
-        $this->_set_props();
164
-        // make sure classname is correct
165
-        $classname = get_class($this);
166
-        // make sure required props have been set
167
-
168
-        // if label is empty then throw an error because we should have it defined by now.
169
-        if (! isset($this->label)) {
170
-            throw new EE_Error(sprintf(__('The label property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
171
-        }
172
-
173
-
174
-        // the reference for this template pack
175
-        if (! isset($this->dbref)) {
176
-            throw new EE_Error(sprintf(__('The dbref property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
177
-        }
178
-
179
-        // make sure dbref is safe
180
-        $this->dbref = str_replace('-', '_', sanitize_key($this->dbref));
181
-
182
-        $should_be = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->dbref)));
183
-
184
-        if ($should_be !== $classname) {
185
-            throw new EE_Error(sprintf(__('The name of the template pack instantiated class is "%s".  It should be "%s".  Make sure that the name of the template pack class matches is prepended with "EE_Messages_Template_Pack_" and appended with a sentence case iteration of the value for your template pack\'s dbref property.', 'event_espresso'), $classname, $should_be));
186
-        }
187
-
188
-        // if _base_path is not set then throw an error because a base path string is needed.
189
-        if (empty($this->_base_path)) {
190
-            throw new EE_Error(sprintf(__('The _base_path property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
191
-        }
192
-
193
-
194
-        // if _base_url is not set then throw an error because a  string is needed for variations.
195
-        if (empty($this->_base_url)) {
196
-            throw new EE_Error(sprintf(__('The _base_url property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
197
-        }
198
-
199
-
200
-        // if $supports is not set then throw an error because that effectively means this template_pack does not have any templates!
201
-        if (empty($this->_supports)) {
202
-            throw new EE_Error(sprintf(__('The supports property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
203
-        }
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * This method should be used to define the following properties:
210
-     * - label
211
-     * - dbref
212
-     * - description
213
-     * - _base_path
214
-     * - _base_url
215
-     * - supports
216
-     * - variations
217
-     *
218
-     * @since 4.5.0
219
-     * @return void.
220
-     * @abstract
221
-     */
222
-    abstract protected function _set_props();
223
-
224
-
225
-
226
-
227
-    /**
228
-     * Wrapper for get_templates() ( @see get_templates() for documentation)
229
-     *
230
-     * @since 4.5.0
231
-     *
232
-     * @param EE_messenger    $messenger
233
-     * @param EE_message_type $message_type
234
-     *
235
-     * @return array
236
-     */
237
-    public function get_templates(EE_messenger $messenger, EE_message_type $message_type)
238
-    {
239
-        return isset($this->_templates[ $messenger->name ][ $message_type->name ]) ? $this->_templates[ $messenger->name ][ $message_type->name ] : $this->_get_templates($messenger, $message_type);
240
-    }
241
-
242
-
243
-
244
-
245
-    /**
246
-     * This takes the incoming messenger and message type objects, uses them to get the set fields and contexts, then attempts to retrieve the templates matching those for this given template pack.
247
-     *
248
-     * @since 4.5.0
249
-     *
250
-     * @param EE_messenger    $messenger
251
-     * @param EE_message_type $message_type
252
-     *
253
-     * @return array          Returns an multi-level associative array indexed by template context and field in the format:
254
-     *                                array( 'context' => array( 'field' => 'value', 'another-field', 'value' ) );
255
-     */
256
-    protected function _get_templates(EE_messenger $messenger, EE_message_type $message_type)
257
-    {
258
-        $templates = array();
259
-
260
-        /**
261
-         * Retrieving the default pack for later usage of default templates for template packs that
262
-         * are NOT the default pack ( or an extension of the default pack ).
263
-         * We ONLY set this variable to be the default pack IF the loaded class is NOT the default
264
-         * pack.  This prevents recursion in _get_specific_template().  The intention is that for
265
-         * template packs that are NOT default packs, we use the default template pack to provide
266
-         * the final fallback templates if there aren't any defined for the called template pack.
267
-         *
268
-         * @type EE_Messages_Template_Pack_Default | null $default_pack
269
-         */
270
-        $default_pack = ! $this instanceof EE_Messages_Template_Pack_Default ? new EE_Messages_Template_Pack_Default() : null;
271
-
272
-        $fields = $messenger->get_template_fields();
273
-        $contexts = $message_type->get_contexts();
274
-
275
-
276
-        foreach ($contexts as $context => $details) {
277
-            foreach ($fields as $field => $field_details) {
278
-                if (empty($field_details)) {
279
-                    continue;
280
-                }
281
-                /**
282
-                 * is this a field array (linked to a main field)?
283
-                 */
284
-                if ($field == 'extra') {
285
-                    foreach ($field_details as $main_field => $sub_fields) {
286
-                        foreach ($sub_fields as $sub_field => $sub_field_details) {
287
-                            // make sure that the template_field_ref matches what the main template field is for this template group.
288
-                            $template_field_ref = $sub_field == 'main' ? $main_field : $sub_field;
289
-                            $templates[ $context ][ $main_field ][ $sub_field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
290
-                        }
291
-                    }
292
-                } else {
293
-                    $templates[ $context ][ $field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
294
-                }
295
-            }
296
-        }
297
-
298
-        $templates = apply_filters('FHEE__EE_Template_Pack___get_templates__templates', $templates, $messenger, $message_type, $this);
299
-
300
-        $this->_templates[ $messenger->name ][ $message_type->name ] = $templates;
301
-         return $templates;
302
-    }
303
-
304
-
305
-    /**
306
-     * Utility method for retrieving a specific template matching the given parameters
307
-     *
308
-     * @param null | EE_Messages_Template_Pack_Default $default_pack
309
-     * @param EE_messenger                             $messenger
310
-     * @param EE_message_type                          $message_type
311
-     * @param string                                   $field          The field reference for the specific template being looked up.
312
-     * @param string                                   $context      The context reference for the specific template being looked up
313
-     *
314
-     * @return string          The template contents.
315
-     */
316
-    protected function _get_specific_template($default_pack, EE_messenger $messenger, EE_message_type $message_type, $field, $context)
317
-    {
318
-
319
-        // default templates
320
-        $default_templates = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_templates($messenger, $message_type) : array();
321
-
322
-        // first we allow for the $_base_path to be filtered.  However, we assign this to a new variable so that we have the original base_path as a fallback.
323
-        $filtered_base_path = apply_filters('FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', $this->_base_path, $messenger, $message_type, $field, $context, $this);
324
-
325
-        $master_templates = $message_type->get_master_templates();
326
-        $master_templates_mt = isset($master_templates[ $messenger->name ]) ? $master_templates[ $messenger->name ] : $message_type->name;
327
-        $full_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '_' . $context . '.template.php';
328
-        $fallback_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '.template.php';
329
-        $mt_defined_full_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
330
-        $mt_defined_fallback_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
331
-        $base_defined_full_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
332
-        $base_defined_fallback_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
333
-
334
-        /**
335
-         * Template checks are done hierarchically in the following order:
336
-         *
337
-         * - a match for the full messenger name, message type, context and field in the full path for the given template pack.
338
-         * - a match for the full messenger name, message type, field in the full path for the given template pack.
339
-         * - a match for the full messenger name, message type, field, context in the path grabbed for the related message type defined in the _master_templates property for the message type (i.e. all registration message types share the same template as the main registration message type).
340
-         * - match for the full messenger name, message type, field for the related message type defined in the _master templates property for the message type
341
-         * - a match for a default template matching the messenger, name, context, field (as set by the default template packs).
342
-         * - empty string.
343
-         */
344
-
345
-
346
-        if (is_readable($full_path)) {
347
-            $actual_path = $full_path;
348
-        } elseif (is_readable($fallback_path)) {
349
-            $actual_path = $fallback_path;
350
-        } elseif (is_readable($mt_defined_full_path)) {
351
-            $actual_path = $mt_defined_full_path;
352
-        } elseif (is_readable($mt_defined_fallback_path)) {
353
-            $actual_path = $mt_defined_fallback_path;
354
-        } elseif (is_readable($base_defined_full_path)) {
355
-            $actual_path = $base_defined_full_path;
356
-        } elseif (is_readable($base_defined_fallback_path)) {
357
-            $actual_path = $base_defined_fallback_path;
358
-        } else {
359
-            $actual_path = '';
360
-        }
361
-        if (empty($actual_path)) {
362
-            $contents = isset($default_templates[ $context ][ $field ]) ? $default_templates[ $context ][ $field ] : '';
363
-        } else {
364
-            $contents = EEH_Template::display_template($actual_path, array(), true);
365
-        }
366
-
367
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_specific_template__contents', $contents, $actual_path, $messenger, $message_type, $field, $context, $this);
368
-    }
369
-
370
-
371
-
372
-
373
-
374
-    /**
375
-     * Return filtered _supports property.
376
-     *
377
-     * @since 4.5.0
378
-     *
379
-     * @return array
380
-     */
381
-    public function get_supports()
382
-    {
383
-        $supports = apply_filters('FHEE__' . get_class($this) . '__get_supports', $this->_supports);
384
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_supports', $supports, $this);
385
-    }
386
-
387
-
388
-
389
-
390
-    /**
391
-     * This simply returns the $_default_variation_labels property value.
392
-     *
393
-     * @since 4.5.0
394
-     *
395
-     * @param string $messenger if the messenger slug is returned then the default label for the specific messenger is retrieved.  If it doesn't exist then the __('Default', 'event_espresso') is returned.  If NO value is provided then whatever is set on the _default_variation_labels property is returned.
396
-     *
397
-     * @return array|string
398
-     */
399
-    public function get_default_variation_labels($messenger = '')
400
-    {
401
-        $label = empty($messenger) ? $this->_default_variation_labels : array();
402
-        $label = empty($label) && ! empty($this->_default_variation_labels[ $messenger ]) ? $this->_default_variation_labels[ $messenger ] : __('Default', 'event_espresso');
403
-
404
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_default_variation_labels', $label, $this->_default_variation_labels, $messenger);
405
-    }
406
-
407
-
408
-
409
-
410
-
411
-    /**
412
-     * This simply returns the _variations property.
413
-     *
414
-     * @since 4.5.0
415
-     *
416
-     * @param string $messenger if included then css variations matching the messenger are returned.  Otherwise, just the default variation is included.  If both message type AND messenger are empty then all variations are returned.
417
-     * @param string $message_type if included then css variations matching the message_type are returned (must have $messenger set).  Otherwise the array of variations per message type are returned.  If message_type is provided but NOT the messenger, then just all variations for all messengers are returned.
418
-     * @return array
419
-     */
420
-    public function get_variations($messenger = '', $message_type = '')
421
-    {
422
-        $messenger_variations = ! empty($messenger) && isset($this->_variations[ $messenger ]) ? $this->_variations[ $messenger ] : array();
423
-
424
-        // message_type provided? IF so, then we've requested a specific set of variations, so we need to make sure we set it as empty if that's not present.
425
-        $variations = !empty($messenger) && !empty($message_type) && isset($messenger_variations[ $message_type ]) ? $messenger_variations[ $message_type ] : array();
426
-
427
-        // now let's account for the possibility we just want all the variations for a messenger (which is indicated by providing the messenger but not the message type).
428
-        $variations = empty($variations) && !empty($messenger) && empty($message_type) ? $messenger_variations : $variations;
429
-
430
-        // filter per template pack and globally.
431
-        $variations = apply_filters('FHEE__' . get_class($this) . '__get_variations', $variations, $messenger, $message_type);
432
-        $variations = apply_filters('FHEE__EE_Messages_Template_Pack__get_variations', $variations, $messenger, $message_type, $this);
433
-
434
-        // prepend the _default_variation, but ONLY if we're returning the fully validated array.
435
-        if (!empty($messenger) && !empty($message_type) && ! empty($variations)) {
436
-            $variations = array( 'default' => $this->get_default_variation_labels($messenger) ) + $variations;
437
-        }
438
-
439
-        return empty($variations) ? array( 'default' => $this->get_default_variation_labels('dft') ) : $variations;
440
-    }
441
-
442
-
443
-
444
-
445
-    /**
446
-     * This is typically called by EE_messenger objects to get the specific css variation defined for the messenger, message_type and type (i.e. inline, wpeditor, preview etc.)
447
-     *
448
-     * @since 4.5.0
449
-     *
450
-     * @param string $messenger messenger slug
451
-     * @param string $message_type message_type slug
452
-     * @param string $type           variation type (i.e. inline, base, wpeditor, preview etc. //this varies per messenger).
453
-     * @param string $variation    this should match one of the defined variations in the _variations property on this class.
454
-     * @param string $file_extension  What type of file the variation file is (defaults to css)
455
-     * @param bool   $url          if true then return the url otherwise path.
456
-     * @param bool   $skip_filters This should not be set directly, its used internally to skip filters when the default template pack is called internally as the fallback.
457
-     *
458
-     * @return string The variation path or url (typically css reference)
459
-     */
460
-    public function get_variation($messenger, $message_type, $type, $variation, $url = true, $file_extension = '.css', $skip_filters = false)
461
-    {
138
+	/**
139
+	 * This is an array of extra css variations for message templates indexed by messenger with the values as an array or message types the variations apply to as the key  and then values are an array with variation slugs as the key and label as the value. Note the default variation is not included in this array.  So the structure is:
140
+	 * array(
141
+	 *  'email' => array(
142
+	 *  )
143
+	 * )
144
+	 *
145
+	 * Keep in mind that this property is used both for indicating valid variations for a given message type and messenger but the variation files themselves are ONLY unique to the messenger.  So if you have a variation for the html messenger referenced by the slug "sunset_red" Then the variation file for the main type will be html_main_sunset_red.css.  All the array in this property allows you to do, is indicate that with certain message types the sunset_red variation is available but for other message types its not.  But you could NOT have a sunset_red variation file for one messenger/message_type and a different one for another messenger/message_type.  If you want different css looks then you can define a different structural layout for the template , messenger, message type combination and in the same sunset_red.css variation file just add css specific to that layout.
146
+	 *
147
+	 * @since 4.5.0
148
+	 *
149
+	 * @var array
150
+	 */
151
+	public $_variations = array();
152
+
153
+
154
+
155
+
156
+	/**
157
+	 * Template pack constructor
158
+	 *
159
+	 * @since 4.5.0
160
+	 */
161
+	public function __construct()
162
+	{
163
+		$this->_set_props();
164
+		// make sure classname is correct
165
+		$classname = get_class($this);
166
+		// make sure required props have been set
167
+
168
+		// if label is empty then throw an error because we should have it defined by now.
169
+		if (! isset($this->label)) {
170
+			throw new EE_Error(sprintf(__('The label property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
171
+		}
172
+
173
+
174
+		// the reference for this template pack
175
+		if (! isset($this->dbref)) {
176
+			throw new EE_Error(sprintf(__('The dbref property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
177
+		}
178
+
179
+		// make sure dbref is safe
180
+		$this->dbref = str_replace('-', '_', sanitize_key($this->dbref));
181
+
182
+		$should_be = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->dbref)));
183
+
184
+		if ($should_be !== $classname) {
185
+			throw new EE_Error(sprintf(__('The name of the template pack instantiated class is "%s".  It should be "%s".  Make sure that the name of the template pack class matches is prepended with "EE_Messages_Template_Pack_" and appended with a sentence case iteration of the value for your template pack\'s dbref property.', 'event_espresso'), $classname, $should_be));
186
+		}
187
+
188
+		// if _base_path is not set then throw an error because a base path string is needed.
189
+		if (empty($this->_base_path)) {
190
+			throw new EE_Error(sprintf(__('The _base_path property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
191
+		}
192
+
193
+
194
+		// if _base_url is not set then throw an error because a  string is needed for variations.
195
+		if (empty($this->_base_url)) {
196
+			throw new EE_Error(sprintf(__('The _base_url property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
197
+		}
198
+
199
+
200
+		// if $supports is not set then throw an error because that effectively means this template_pack does not have any templates!
201
+		if (empty($this->_supports)) {
202
+			throw new EE_Error(sprintf(__('The supports property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
203
+		}
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * This method should be used to define the following properties:
210
+	 * - label
211
+	 * - dbref
212
+	 * - description
213
+	 * - _base_path
214
+	 * - _base_url
215
+	 * - supports
216
+	 * - variations
217
+	 *
218
+	 * @since 4.5.0
219
+	 * @return void.
220
+	 * @abstract
221
+	 */
222
+	abstract protected function _set_props();
223
+
224
+
225
+
226
+
227
+	/**
228
+	 * Wrapper for get_templates() ( @see get_templates() for documentation)
229
+	 *
230
+	 * @since 4.5.0
231
+	 *
232
+	 * @param EE_messenger    $messenger
233
+	 * @param EE_message_type $message_type
234
+	 *
235
+	 * @return array
236
+	 */
237
+	public function get_templates(EE_messenger $messenger, EE_message_type $message_type)
238
+	{
239
+		return isset($this->_templates[ $messenger->name ][ $message_type->name ]) ? $this->_templates[ $messenger->name ][ $message_type->name ] : $this->_get_templates($messenger, $message_type);
240
+	}
241
+
242
+
243
+
244
+
245
+	/**
246
+	 * This takes the incoming messenger and message type objects, uses them to get the set fields and contexts, then attempts to retrieve the templates matching those for this given template pack.
247
+	 *
248
+	 * @since 4.5.0
249
+	 *
250
+	 * @param EE_messenger    $messenger
251
+	 * @param EE_message_type $message_type
252
+	 *
253
+	 * @return array          Returns an multi-level associative array indexed by template context and field in the format:
254
+	 *                                array( 'context' => array( 'field' => 'value', 'another-field', 'value' ) );
255
+	 */
256
+	protected function _get_templates(EE_messenger $messenger, EE_message_type $message_type)
257
+	{
258
+		$templates = array();
259
+
260
+		/**
261
+		 * Retrieving the default pack for later usage of default templates for template packs that
262
+		 * are NOT the default pack ( or an extension of the default pack ).
263
+		 * We ONLY set this variable to be the default pack IF the loaded class is NOT the default
264
+		 * pack.  This prevents recursion in _get_specific_template().  The intention is that for
265
+		 * template packs that are NOT default packs, we use the default template pack to provide
266
+		 * the final fallback templates if there aren't any defined for the called template pack.
267
+		 *
268
+		 * @type EE_Messages_Template_Pack_Default | null $default_pack
269
+		 */
270
+		$default_pack = ! $this instanceof EE_Messages_Template_Pack_Default ? new EE_Messages_Template_Pack_Default() : null;
271
+
272
+		$fields = $messenger->get_template_fields();
273
+		$contexts = $message_type->get_contexts();
274
+
275
+
276
+		foreach ($contexts as $context => $details) {
277
+			foreach ($fields as $field => $field_details) {
278
+				if (empty($field_details)) {
279
+					continue;
280
+				}
281
+				/**
282
+				 * is this a field array (linked to a main field)?
283
+				 */
284
+				if ($field == 'extra') {
285
+					foreach ($field_details as $main_field => $sub_fields) {
286
+						foreach ($sub_fields as $sub_field => $sub_field_details) {
287
+							// make sure that the template_field_ref matches what the main template field is for this template group.
288
+							$template_field_ref = $sub_field == 'main' ? $main_field : $sub_field;
289
+							$templates[ $context ][ $main_field ][ $sub_field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
290
+						}
291
+					}
292
+				} else {
293
+					$templates[ $context ][ $field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
294
+				}
295
+			}
296
+		}
297
+
298
+		$templates = apply_filters('FHEE__EE_Template_Pack___get_templates__templates', $templates, $messenger, $message_type, $this);
299
+
300
+		$this->_templates[ $messenger->name ][ $message_type->name ] = $templates;
301
+		 return $templates;
302
+	}
303
+
304
+
305
+	/**
306
+	 * Utility method for retrieving a specific template matching the given parameters
307
+	 *
308
+	 * @param null | EE_Messages_Template_Pack_Default $default_pack
309
+	 * @param EE_messenger                             $messenger
310
+	 * @param EE_message_type                          $message_type
311
+	 * @param string                                   $field          The field reference for the specific template being looked up.
312
+	 * @param string                                   $context      The context reference for the specific template being looked up
313
+	 *
314
+	 * @return string          The template contents.
315
+	 */
316
+	protected function _get_specific_template($default_pack, EE_messenger $messenger, EE_message_type $message_type, $field, $context)
317
+	{
318
+
319
+		// default templates
320
+		$default_templates = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_templates($messenger, $message_type) : array();
321
+
322
+		// first we allow for the $_base_path to be filtered.  However, we assign this to a new variable so that we have the original base_path as a fallback.
323
+		$filtered_base_path = apply_filters('FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', $this->_base_path, $messenger, $message_type, $field, $context, $this);
324
+
325
+		$master_templates = $message_type->get_master_templates();
326
+		$master_templates_mt = isset($master_templates[ $messenger->name ]) ? $master_templates[ $messenger->name ] : $message_type->name;
327
+		$full_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '_' . $context . '.template.php';
328
+		$fallback_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '.template.php';
329
+		$mt_defined_full_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
330
+		$mt_defined_fallback_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
331
+		$base_defined_full_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
332
+		$base_defined_fallback_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
333
+
334
+		/**
335
+		 * Template checks are done hierarchically in the following order:
336
+		 *
337
+		 * - a match for the full messenger name, message type, context and field in the full path for the given template pack.
338
+		 * - a match for the full messenger name, message type, field in the full path for the given template pack.
339
+		 * - a match for the full messenger name, message type, field, context in the path grabbed for the related message type defined in the _master_templates property for the message type (i.e. all registration message types share the same template as the main registration message type).
340
+		 * - match for the full messenger name, message type, field for the related message type defined in the _master templates property for the message type
341
+		 * - a match for a default template matching the messenger, name, context, field (as set by the default template packs).
342
+		 * - empty string.
343
+		 */
344
+
345
+
346
+		if (is_readable($full_path)) {
347
+			$actual_path = $full_path;
348
+		} elseif (is_readable($fallback_path)) {
349
+			$actual_path = $fallback_path;
350
+		} elseif (is_readable($mt_defined_full_path)) {
351
+			$actual_path = $mt_defined_full_path;
352
+		} elseif (is_readable($mt_defined_fallback_path)) {
353
+			$actual_path = $mt_defined_fallback_path;
354
+		} elseif (is_readable($base_defined_full_path)) {
355
+			$actual_path = $base_defined_full_path;
356
+		} elseif (is_readable($base_defined_fallback_path)) {
357
+			$actual_path = $base_defined_fallback_path;
358
+		} else {
359
+			$actual_path = '';
360
+		}
361
+		if (empty($actual_path)) {
362
+			$contents = isset($default_templates[ $context ][ $field ]) ? $default_templates[ $context ][ $field ] : '';
363
+		} else {
364
+			$contents = EEH_Template::display_template($actual_path, array(), true);
365
+		}
366
+
367
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_specific_template__contents', $contents, $actual_path, $messenger, $message_type, $field, $context, $this);
368
+	}
369
+
370
+
371
+
372
+
373
+
374
+	/**
375
+	 * Return filtered _supports property.
376
+	 *
377
+	 * @since 4.5.0
378
+	 *
379
+	 * @return array
380
+	 */
381
+	public function get_supports()
382
+	{
383
+		$supports = apply_filters('FHEE__' . get_class($this) . '__get_supports', $this->_supports);
384
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_supports', $supports, $this);
385
+	}
386
+
387
+
388
+
389
+
390
+	/**
391
+	 * This simply returns the $_default_variation_labels property value.
392
+	 *
393
+	 * @since 4.5.0
394
+	 *
395
+	 * @param string $messenger if the messenger slug is returned then the default label for the specific messenger is retrieved.  If it doesn't exist then the __('Default', 'event_espresso') is returned.  If NO value is provided then whatever is set on the _default_variation_labels property is returned.
396
+	 *
397
+	 * @return array|string
398
+	 */
399
+	public function get_default_variation_labels($messenger = '')
400
+	{
401
+		$label = empty($messenger) ? $this->_default_variation_labels : array();
402
+		$label = empty($label) && ! empty($this->_default_variation_labels[ $messenger ]) ? $this->_default_variation_labels[ $messenger ] : __('Default', 'event_espresso');
403
+
404
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_default_variation_labels', $label, $this->_default_variation_labels, $messenger);
405
+	}
406
+
407
+
408
+
409
+
410
+
411
+	/**
412
+	 * This simply returns the _variations property.
413
+	 *
414
+	 * @since 4.5.0
415
+	 *
416
+	 * @param string $messenger if included then css variations matching the messenger are returned.  Otherwise, just the default variation is included.  If both message type AND messenger are empty then all variations are returned.
417
+	 * @param string $message_type if included then css variations matching the message_type are returned (must have $messenger set).  Otherwise the array of variations per message type are returned.  If message_type is provided but NOT the messenger, then just all variations for all messengers are returned.
418
+	 * @return array
419
+	 */
420
+	public function get_variations($messenger = '', $message_type = '')
421
+	{
422
+		$messenger_variations = ! empty($messenger) && isset($this->_variations[ $messenger ]) ? $this->_variations[ $messenger ] : array();
423
+
424
+		// message_type provided? IF so, then we've requested a specific set of variations, so we need to make sure we set it as empty if that's not present.
425
+		$variations = !empty($messenger) && !empty($message_type) && isset($messenger_variations[ $message_type ]) ? $messenger_variations[ $message_type ] : array();
426
+
427
+		// now let's account for the possibility we just want all the variations for a messenger (which is indicated by providing the messenger but not the message type).
428
+		$variations = empty($variations) && !empty($messenger) && empty($message_type) ? $messenger_variations : $variations;
429
+
430
+		// filter per template pack and globally.
431
+		$variations = apply_filters('FHEE__' . get_class($this) . '__get_variations', $variations, $messenger, $message_type);
432
+		$variations = apply_filters('FHEE__EE_Messages_Template_Pack__get_variations', $variations, $messenger, $message_type, $this);
433
+
434
+		// prepend the _default_variation, but ONLY if we're returning the fully validated array.
435
+		if (!empty($messenger) && !empty($message_type) && ! empty($variations)) {
436
+			$variations = array( 'default' => $this->get_default_variation_labels($messenger) ) + $variations;
437
+		}
438
+
439
+		return empty($variations) ? array( 'default' => $this->get_default_variation_labels('dft') ) : $variations;
440
+	}
441
+
442
+
443
+
444
+
445
+	/**
446
+	 * This is typically called by EE_messenger objects to get the specific css variation defined for the messenger, message_type and type (i.e. inline, wpeditor, preview etc.)
447
+	 *
448
+	 * @since 4.5.0
449
+	 *
450
+	 * @param string $messenger messenger slug
451
+	 * @param string $message_type message_type slug
452
+	 * @param string $type           variation type (i.e. inline, base, wpeditor, preview etc. //this varies per messenger).
453
+	 * @param string $variation    this should match one of the defined variations in the _variations property on this class.
454
+	 * @param string $file_extension  What type of file the variation file is (defaults to css)
455
+	 * @param bool   $url          if true then return the url otherwise path.
456
+	 * @param bool   $skip_filters This should not be set directly, its used internally to skip filters when the default template pack is called internally as the fallback.
457
+	 *
458
+	 * @return string The variation path or url (typically css reference)
459
+	 */
460
+	public function get_variation($messenger, $message_type, $type, $variation, $url = true, $file_extension = '.css', $skip_filters = false)
461
+	{
462 462
 
463
-        $base = $url ? $this->_base_url : $this->_base_path;
464
-        $base_path = $this->_base_path;
463
+		$base = $url ? $this->_base_url : $this->_base_path;
464
+		$base_path = $this->_base_path;
465 465
 
466
-        if (! $skip_filters) {
467
-            $base =  apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', $base, $messenger, $message_type, $type, $variation, $url, $file_extension, $this);
468
-            $base_path = apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path', $base_path, $messenger, $message_type, $type, $variation, false, $file_extension, $this);
469
-        }
466
+		if (! $skip_filters) {
467
+			$base =  apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', $base, $messenger, $message_type, $type, $variation, $url, $file_extension, $this);
468
+			$base_path = apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path', $base_path, $messenger, $message_type, $type, $variation, false, $file_extension, $this);
469
+		}
470 470
 
471
-        $default_pack = get_class($this) != 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : $this;
472
-
473
-        // possible variation paths considering whether message type is present or not in the file name.
474
-        $path_string = 'variations/' . $messenger . '_' . $message_type . '_'  . $type . '_' . $variation . $file_extension;
475
-        $default_path_string = 'variations/' . $messenger . '_' . $type . '_' . $variation . $file_extension;
476
-
477
-        // first see if fully validated file exists.
478
-        if (is_readable($base_path . $path_string)) {
479
-            $variation_path = $base . $path_string;
480
-        // otherwise see if default exists.
481
-        } elseif (is_readable($base_path . $default_path_string)) {
482
-            $variation_path = $base . $default_path_string;
483
-        } else {
484
-            $variation_path = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_default_variation($messenger, $message_type, $type, $url, $file_extension) : '';
485
-        }
471
+		$default_pack = get_class($this) != 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : $this;
472
+
473
+		// possible variation paths considering whether message type is present or not in the file name.
474
+		$path_string = 'variations/' . $messenger . '_' . $message_type . '_'  . $type . '_' . $variation . $file_extension;
475
+		$default_path_string = 'variations/' . $messenger . '_' . $type . '_' . $variation . $file_extension;
476
+
477
+		// first see if fully validated file exists.
478
+		if (is_readable($base_path . $path_string)) {
479
+			$variation_path = $base . $path_string;
480
+		// otherwise see if default exists.
481
+		} elseif (is_readable($base_path . $default_path_string)) {
482
+			$variation_path = $base . $default_path_string;
483
+		} else {
484
+			$variation_path = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_default_variation($messenger, $message_type, $type, $url, $file_extension) : '';
485
+		}
486 486
 
487
-        if ($skip_filters) {
488
-            return $variation_path;
489
-        }
490
-
491
-        // filter result
492
-        $variation_path = apply_filters('FHEE__' . get_class($this) . '__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url);
493
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url, $this);
494
-    }
495
-
496
-
497
-
498
-
499
-
500
-    /**
501
-     * This method is used to return the wrapper template for the given template pack.  If the given template pack does not include any wrapper templates then the default is used.
502
-     *
503
-     * @param string $messenger What messenger the wrapper is for.
504
-     * @param string $type           What type of wrapper is being returned ( for messengers that may have more than one wrapper )
505
-     *
506
-     * @return string returns the path for the requested wrapper template.
507
-     */
508
-    public function get_wrapper($messenger, $type = 'main')
509
-    {
510
-        $default_pack = get_class($this) !== 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : null;
511
-
512
-        $path_string = $this->_base_path . $messenger . '_' . $type . '_wrapper.template.php';
513
-
514
-        if (is_readable($path_string)) {
515
-            $template = $path_string;
516
-        } else {
517
-            $template = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_wrapper($messenger, $type) : '';
518
-        }
519
-
520
-        // filter
521
-        $template = apply_filters('FHEE__' . get_class($this) . '__get_wrapper', $template, $messenger, $type);
522
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_wrapper', $template, $messenger, $type, $this);
523
-    }
487
+		if ($skip_filters) {
488
+			return $variation_path;
489
+		}
490
+
491
+		// filter result
492
+		$variation_path = apply_filters('FHEE__' . get_class($this) . '__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url);
493
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url, $this);
494
+	}
495
+
496
+
497
+
498
+
499
+
500
+	/**
501
+	 * This method is used to return the wrapper template for the given template pack.  If the given template pack does not include any wrapper templates then the default is used.
502
+	 *
503
+	 * @param string $messenger What messenger the wrapper is for.
504
+	 * @param string $type           What type of wrapper is being returned ( for messengers that may have more than one wrapper )
505
+	 *
506
+	 * @return string returns the path for the requested wrapper template.
507
+	 */
508
+	public function get_wrapper($messenger, $type = 'main')
509
+	{
510
+		$default_pack = get_class($this) !== 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : null;
511
+
512
+		$path_string = $this->_base_path . $messenger . '_' . $type . '_wrapper.template.php';
513
+
514
+		if (is_readable($path_string)) {
515
+			$template = $path_string;
516
+		} else {
517
+			$template = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_wrapper($messenger, $type) : '';
518
+		}
519
+
520
+		// filter
521
+		$template = apply_filters('FHEE__' . get_class($this) . '__get_wrapper', $template, $messenger, $type);
522
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_wrapper', $template, $messenger, $type, $this);
523
+	}
524 524
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -166,20 +166,20 @@  discard block
 block discarded – undo
166 166
         // make sure required props have been set
167 167
 
168 168
         // if label is empty then throw an error because we should have it defined by now.
169
-        if (! isset($this->label)) {
169
+        if ( ! isset($this->label)) {
170 170
             throw new EE_Error(sprintf(__('The label property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
171 171
         }
172 172
 
173 173
 
174 174
         // the reference for this template pack
175
-        if (! isset($this->dbref)) {
175
+        if ( ! isset($this->dbref)) {
176 176
             throw new EE_Error(sprintf(__('The dbref property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
177 177
         }
178 178
 
179 179
         // make sure dbref is safe
180 180
         $this->dbref = str_replace('-', '_', sanitize_key($this->dbref));
181 181
 
182
-        $should_be = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->dbref)));
182
+        $should_be = 'EE_Messages_Template_Pack_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->dbref)));
183 183
 
184 184
         if ($should_be !== $classname) {
185 185
             throw new EE_Error(sprintf(__('The name of the template pack instantiated class is "%s".  It should be "%s".  Make sure that the name of the template pack class matches is prepended with "EE_Messages_Template_Pack_" and appended with a sentence case iteration of the value for your template pack\'s dbref property.', 'event_espresso'), $classname, $should_be));
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
      */
237 237
     public function get_templates(EE_messenger $messenger, EE_message_type $message_type)
238 238
     {
239
-        return isset($this->_templates[ $messenger->name ][ $message_type->name ]) ? $this->_templates[ $messenger->name ][ $message_type->name ] : $this->_get_templates($messenger, $message_type);
239
+        return isset($this->_templates[$messenger->name][$message_type->name]) ? $this->_templates[$messenger->name][$message_type->name] : $this->_get_templates($messenger, $message_type);
240 240
     }
241 241
 
242 242
 
@@ -286,18 +286,18 @@  discard block
 block discarded – undo
286 286
                         foreach ($sub_fields as $sub_field => $sub_field_details) {
287 287
                             // make sure that the template_field_ref matches what the main template field is for this template group.
288 288
                             $template_field_ref = $sub_field == 'main' ? $main_field : $sub_field;
289
-                            $templates[ $context ][ $main_field ][ $sub_field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
289
+                            $templates[$context][$main_field][$sub_field] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
290 290
                         }
291 291
                     }
292 292
                 } else {
293
-                    $templates[ $context ][ $field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
293
+                    $templates[$context][$field] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
294 294
                 }
295 295
             }
296 296
         }
297 297
 
298 298
         $templates = apply_filters('FHEE__EE_Template_Pack___get_templates__templates', $templates, $messenger, $message_type, $this);
299 299
 
300
-        $this->_templates[ $messenger->name ][ $message_type->name ] = $templates;
300
+        $this->_templates[$messenger->name][$message_type->name] = $templates;
301 301
          return $templates;
302 302
     }
303 303
 
@@ -323,13 +323,13 @@  discard block
 block discarded – undo
323 323
         $filtered_base_path = apply_filters('FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', $this->_base_path, $messenger, $message_type, $field, $context, $this);
324 324
 
325 325
         $master_templates = $message_type->get_master_templates();
326
-        $master_templates_mt = isset($master_templates[ $messenger->name ]) ? $master_templates[ $messenger->name ] : $message_type->name;
327
-        $full_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '_' . $context . '.template.php';
328
-        $fallback_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '.template.php';
329
-        $mt_defined_full_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
330
-        $mt_defined_fallback_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
331
-        $base_defined_full_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
332
-        $base_defined_fallback_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
326
+        $master_templates_mt = isset($master_templates[$messenger->name]) ? $master_templates[$messenger->name] : $message_type->name;
327
+        $full_path = $filtered_base_path.$messenger->name.'_'.$message_type->name.'_'.$field.'_'.$context.'.template.php';
328
+        $fallback_path = $filtered_base_path.$messenger->name.'_'.$message_type->name.'_'.$field.'.template.php';
329
+        $mt_defined_full_path = $filtered_base_path.$messenger->name.'_'.$master_templates_mt.'_'.$field.'_'.$context.'.template.php';
330
+        $mt_defined_fallback_path = $filtered_base_path.$messenger->name.'_'.$master_templates_mt.'_'.$field.'.template.php';
331
+        $base_defined_full_path = $this->_base_path.$messenger->name.'_'.$master_templates_mt.'_'.$field.'_'.$context.'.template.php';
332
+        $base_defined_fallback_path = $this->_base_path.$messenger->name.'_'.$master_templates_mt.'_'.$field.'.template.php';
333 333
 
334 334
         /**
335 335
          * Template checks are done hierarchically in the following order:
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
             $actual_path = '';
360 360
         }
361 361
         if (empty($actual_path)) {
362
-            $contents = isset($default_templates[ $context ][ $field ]) ? $default_templates[ $context ][ $field ] : '';
362
+            $contents = isset($default_templates[$context][$field]) ? $default_templates[$context][$field] : '';
363 363
         } else {
364 364
             $contents = EEH_Template::display_template($actual_path, array(), true);
365 365
         }
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function get_supports()
382 382
     {
383
-        $supports = apply_filters('FHEE__' . get_class($this) . '__get_supports', $this->_supports);
383
+        $supports = apply_filters('FHEE__'.get_class($this).'__get_supports', $this->_supports);
384 384
         return apply_filters('FHEE__EE_Messages_Template_Pack__get_supports', $supports, $this);
385 385
     }
386 386
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
     public function get_default_variation_labels($messenger = '')
400 400
     {
401 401
         $label = empty($messenger) ? $this->_default_variation_labels : array();
402
-        $label = empty($label) && ! empty($this->_default_variation_labels[ $messenger ]) ? $this->_default_variation_labels[ $messenger ] : __('Default', 'event_espresso');
402
+        $label = empty($label) && ! empty($this->_default_variation_labels[$messenger]) ? $this->_default_variation_labels[$messenger] : __('Default', 'event_espresso');
403 403
 
404 404
         return apply_filters('FHEE__EE_Messages_Template_Pack__get_default_variation_labels', $label, $this->_default_variation_labels, $messenger);
405 405
     }
@@ -419,24 +419,24 @@  discard block
 block discarded – undo
419 419
      */
420 420
     public function get_variations($messenger = '', $message_type = '')
421 421
     {
422
-        $messenger_variations = ! empty($messenger) && isset($this->_variations[ $messenger ]) ? $this->_variations[ $messenger ] : array();
422
+        $messenger_variations = ! empty($messenger) && isset($this->_variations[$messenger]) ? $this->_variations[$messenger] : array();
423 423
 
424 424
         // message_type provided? IF so, then we've requested a specific set of variations, so we need to make sure we set it as empty if that's not present.
425
-        $variations = !empty($messenger) && !empty($message_type) && isset($messenger_variations[ $message_type ]) ? $messenger_variations[ $message_type ] : array();
425
+        $variations = ! empty($messenger) && ! empty($message_type) && isset($messenger_variations[$message_type]) ? $messenger_variations[$message_type] : array();
426 426
 
427 427
         // now let's account for the possibility we just want all the variations for a messenger (which is indicated by providing the messenger but not the message type).
428
-        $variations = empty($variations) && !empty($messenger) && empty($message_type) ? $messenger_variations : $variations;
428
+        $variations = empty($variations) && ! empty($messenger) && empty($message_type) ? $messenger_variations : $variations;
429 429
 
430 430
         // filter per template pack and globally.
431
-        $variations = apply_filters('FHEE__' . get_class($this) . '__get_variations', $variations, $messenger, $message_type);
431
+        $variations = apply_filters('FHEE__'.get_class($this).'__get_variations', $variations, $messenger, $message_type);
432 432
         $variations = apply_filters('FHEE__EE_Messages_Template_Pack__get_variations', $variations, $messenger, $message_type, $this);
433 433
 
434 434
         // prepend the _default_variation, but ONLY if we're returning the fully validated array.
435
-        if (!empty($messenger) && !empty($message_type) && ! empty($variations)) {
436
-            $variations = array( 'default' => $this->get_default_variation_labels($messenger) ) + $variations;
435
+        if ( ! empty($messenger) && ! empty($message_type) && ! empty($variations)) {
436
+            $variations = array('default' => $this->get_default_variation_labels($messenger)) + $variations;
437 437
         }
438 438
 
439
-        return empty($variations) ? array( 'default' => $this->get_default_variation_labels('dft') ) : $variations;
439
+        return empty($variations) ? array('default' => $this->get_default_variation_labels('dft')) : $variations;
440 440
     }
441 441
 
442 442
 
@@ -463,23 +463,23 @@  discard block
 block discarded – undo
463 463
         $base = $url ? $this->_base_url : $this->_base_path;
464 464
         $base_path = $this->_base_path;
465 465
 
466
-        if (! $skip_filters) {
467
-            $base =  apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', $base, $messenger, $message_type, $type, $variation, $url, $file_extension, $this);
466
+        if ( ! $skip_filters) {
467
+            $base = apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', $base, $messenger, $message_type, $type, $variation, $url, $file_extension, $this);
468 468
             $base_path = apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path', $base_path, $messenger, $message_type, $type, $variation, false, $file_extension, $this);
469 469
         }
470 470
 
471 471
         $default_pack = get_class($this) != 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : $this;
472 472
 
473 473
         // possible variation paths considering whether message type is present or not in the file name.
474
-        $path_string = 'variations/' . $messenger . '_' . $message_type . '_'  . $type . '_' . $variation . $file_extension;
475
-        $default_path_string = 'variations/' . $messenger . '_' . $type . '_' . $variation . $file_extension;
474
+        $path_string = 'variations/'.$messenger.'_'.$message_type.'_'.$type.'_'.$variation.$file_extension;
475
+        $default_path_string = 'variations/'.$messenger.'_'.$type.'_'.$variation.$file_extension;
476 476
 
477 477
         // first see if fully validated file exists.
478
-        if (is_readable($base_path . $path_string)) {
479
-            $variation_path = $base . $path_string;
478
+        if (is_readable($base_path.$path_string)) {
479
+            $variation_path = $base.$path_string;
480 480
         // otherwise see if default exists.
481
-        } elseif (is_readable($base_path . $default_path_string)) {
482
-            $variation_path = $base . $default_path_string;
481
+        } elseif (is_readable($base_path.$default_path_string)) {
482
+            $variation_path = $base.$default_path_string;
483 483
         } else {
484 484
             $variation_path = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_default_variation($messenger, $message_type, $type, $url, $file_extension) : '';
485 485
         }
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         }
490 490
 
491 491
         // filter result
492
-        $variation_path = apply_filters('FHEE__' . get_class($this) . '__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url);
492
+        $variation_path = apply_filters('FHEE__'.get_class($this).'__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url);
493 493
         return apply_filters('FHEE__EE_Messages_Template_Pack__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url, $this);
494 494
     }
495 495
 
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
     {
510 510
         $default_pack = get_class($this) !== 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : null;
511 511
 
512
-        $path_string = $this->_base_path . $messenger . '_' . $type . '_wrapper.template.php';
512
+        $path_string = $this->_base_path.$messenger.'_'.$type.'_wrapper.template.php';
513 513
 
514 514
         if (is_readable($path_string)) {
515 515
             $template = $path_string;
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
         }
519 519
 
520 520
         // filter
521
-        $template = apply_filters('FHEE__' . get_class($this) . '__get_wrapper', $template, $messenger, $type);
521
+        $template = apply_filters('FHEE__'.get_class($this).'__get_wrapper', $template, $messenger, $type);
522 522
         return apply_filters('FHEE__EE_Messages_Template_Pack__get_wrapper', $template, $messenger, $type, $this);
523 523
     }
524 524
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_To_Generate.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -208,7 +208,7 @@
 block discarded – undo
208 208
      * generates an EE_Message using the supplied arguments and some defaults
209 209
      *
210 210
      * @param array $properties
211
-     * @return string
211
+     * @return EE_Message
212 212
      */
213 213
     protected function _generate_message($properties = array())
214 214
     {
Please login to merge, or discard this patch.
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -11,304 +11,304 @@
 block discarded – undo
11 11
 class EE_Message_To_Generate
12 12
 {
13 13
 
14
-    /**
15
-     * @type string name of EE_messenger
16
-     */
17
-    protected $_messenger_name = null;
18
-
19
-    /**
20
-     * @type string name of EE_message_type
21
-     */
22
-    protected $_message_type_name = null;
23
-
24
-    /**
25
-     * @type EE_messenger
26
-     */
27
-    protected $_messenger = null;
28
-
29
-    /**
30
-     * @type EE_message_type
31
-     */
32
-    protected $_message_type = null;
33
-
34
-    /**
35
-     * Identifier for the context the message is to be generated for.
36
-     * @type string
37
-     */
38
-    protected $_context = '';
39
-
40
-    /**
41
-     * Data that will be used to generate message.
42
-     * @type array
43
-     */
44
-    protected $_data = array();
45
-
46
-    /**
47
-     * Whether this message is for a preview or not.
48
-     * @type bool
49
-     */
50
-    protected $_preview = false;
51
-
52
-    /**
53
-     * @type EE_Message $_message
54
-     */
55
-    protected $_message = null;
56
-
57
-    /**
58
-     * This is set by the constructor to indicate whether the incoming messenger
59
-     * and message type are valid.  This can then be checked by callers to determine whether
60
-     * to generate this message or not.
61
-     * @type bool
62
-     */
63
-    protected $_valid = false;
64
-
65
-    /**
66
-     * If there are any errors (non exception errors) they get added to this array for callers to decide
67
-     * how to handle.
68
-     * @type array
69
-     */
70
-    protected $_error_msg = array();
71
-
72
-    /**
73
-     * Can be accessed via the send_now() method, this is set in the validation
74
-     * routine via the EE_messenger::send_now() method.
75
-     * @type bool
76
-     */
77
-    protected $_send_now = false;
78
-
79
-    /**
80
-     * Holds the classname for the data handler used by the current message type.
81
-     * This is set on the first call to the public `get_data_handler_class_name()` method.
82
-     * @type string
83
-     */
84
-    protected $_data_handler_class_name = '';
85
-
86
-    /**
87
-     * one of the message status constants on EEM_Message
88
-     *
89
-     * @type string
90
-     */
91
-    protected $_message_status = '';
92
-
93
-
94
-
95
-    /**
96
-     * Constructor
97
-     *
98
-     * @param string $messenger_name    Slug representing messenger
99
-     * @param string $message_type_name Slug representing message type.
100
-     * @param mixed  $data              Data used for generating message.
101
-     * @param string $context           Optional context to restrict message generated for.
102
-     * @param bool   $preview           Whether this is being used to generate a preview or not.
103
-     * @param string $status
104
-     */
105
-    public function __construct(
106
-        $messenger_name,
107
-        $message_type_name,
108
-        $data = array(),
109
-        $context = '',
110
-        $preview = false,
111
-        $status = EEM_Message::status_incomplete
112
-    ) {
113
-        $this->_messenger_name      = $messenger_name;
114
-        $this->_message_type_name   = $message_type_name;
115
-        $this->_data                = is_array($data) ? $data : array( $data );
116
-        $this->_context             = $context;
117
-        $this->_preview             = $preview;
118
-        $this->_status              = $status;
119
-        // attempt to generate message immediately
120
-        $this->_message = $this->_generate_message();
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    public function context()
129
-    {
130
-        return $this->_context;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function data()
139
-    {
140
-        return $this->_data;
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @return EE_messenger
147
-     */
148
-    public function messenger()
149
-    {
150
-        return $this->_messenger;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * @return EE_message_type
157
-     */
158
-    public function message_type()
159
-    {
160
-        return $this->_message_type;
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * @return boolean
167
-     */
168
-    public function preview()
169
-    {
170
-        return $this->_preview;
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     * @param boolean $preview
177
-     */
178
-    public function set_preview($preview)
179
-    {
180
-        $this->_preview = filter_var($preview, FILTER_VALIDATE_BOOLEAN);
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * @return bool
187
-     */
188
-    public function send_now()
189
-    {
190
-        return $this->_send_now;
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * Simply returns the state of the $_valid property.
197
-     *
198
-     * @return bool
199
-     */
200
-    public function valid()
201
-    {
202
-        return $this->_valid;
203
-    }
204
-
205
-
206
-
207
-    /**
208
-     * generates an EE_Message using the supplied arguments and some defaults
209
-     *
210
-     * @param array $properties
211
-     * @return string
212
-     */
213
-    protected function _generate_message($properties = array())
214
-    {
215
-        $message = EE_Message_Factory::create(
216
-            array_merge(
217
-                array(
218
-                    'MSG_messenger'    => $this->_messenger_name,
219
-                    'MSG_message_type' => $this->_message_type_name,
220
-                    'MSG_context'      => $this->_context,
221
-                    'STS_ID'           => $this->_status,
222
-                ),
223
-                $properties
224
-            )
225
-        );
226
-        // validate the message, and if it's good, set some properties
227
-        try {
228
-            $message->is_valid_for_sending_or_generation(true);
229
-            $this->_valid = true;
230
-            $this->_messenger = $message->messenger_object();
231
-            $this->_message_type = $message->message_type_object();
232
-            $this->_send_now = $message->send_now();
233
-        } catch (Exception $e) {
234
-            $this->_valid = false;
235
-            $this->_error_msg[] = $e->getMessage();
236
-        }
237
-        return $message;
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     *  Returns an instantiated EE_Message object from the internal data.
244
-     *
245
-     * @return EE_Message
246
-     */
247
-    public function get_EE_Message()
248
-    {
249
-        // already set ?
250
-        if ($this->_message instanceof EE_Message) {
251
-            return $this->_message;
252
-        }
253
-        // no? then let's create one
254
-        $this->_message = $this->_generate_message();
255
-        return $this->_message;
256
-    }
257
-
258
-
259
-
260
-    /**
261
-     * This returns the data_handler class name for the internal message type set.
262
-     * Note: this also verifies that the data handler class exists.  If it doesn't then $_valid is set to false
263
-     * and the data_handler_class name is set to an empty string.
264
-     *
265
-     * @param   bool    $preview    Used to indicate that the preview data handler is to be returned.
266
-     * @return  string
267
-     */
268
-    public function get_data_handler_class_name($preview = false)
269
-    {
270
-        if ($this->_data_handler_class_name === '' && $this->valid()) {
271
-            $ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data);
272
-            // make sure internal data is updated.
273
-            $this->_data = $this->_message_type->get_data();
274
-
275
-            // verify
276
-            $this->_data_handler_class_name = EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref);
277
-            if ($this->_data_handler_class_name === '') {
278
-                $this->_valid = false;
279
-            }
280
-        }
281
-        return $this->_data_handler_class_name;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * Validates the given string as a reference for an existing, accessible data handler and returns the class name
288
-     * For the handler the reference matches.
289
-     *
290
-     * @param string $data_handler_reference
291
-     * @return string
292
-     */
293
-    public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference)
294
-    {
295
-        $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data';
296
-        if (! class_exists($class_name)) {
297
-            EE_Error::add_error(
298
-                sprintf(
299
-                    __(
300
-                        'The included data handler reference (%s) does not match any valid, accessible, "EE_Messages_incoming_data" classes.  Looking for %s.',
301
-                        'event_espresso'
302
-                    ),
303
-                    $data_handler_reference,
304
-                    $class_name
305
-                ),
306
-                __FILE__,
307
-                __FUNCTION__,
308
-                __LINE__
309
-            );
310
-            $class_name = ''; // clear out class_name so caller knows this isn't valid.
311
-        }
312
-        return $class_name;
313
-    }
14
+	/**
15
+	 * @type string name of EE_messenger
16
+	 */
17
+	protected $_messenger_name = null;
18
+
19
+	/**
20
+	 * @type string name of EE_message_type
21
+	 */
22
+	protected $_message_type_name = null;
23
+
24
+	/**
25
+	 * @type EE_messenger
26
+	 */
27
+	protected $_messenger = null;
28
+
29
+	/**
30
+	 * @type EE_message_type
31
+	 */
32
+	protected $_message_type = null;
33
+
34
+	/**
35
+	 * Identifier for the context the message is to be generated for.
36
+	 * @type string
37
+	 */
38
+	protected $_context = '';
39
+
40
+	/**
41
+	 * Data that will be used to generate message.
42
+	 * @type array
43
+	 */
44
+	protected $_data = array();
45
+
46
+	/**
47
+	 * Whether this message is for a preview or not.
48
+	 * @type bool
49
+	 */
50
+	protected $_preview = false;
51
+
52
+	/**
53
+	 * @type EE_Message $_message
54
+	 */
55
+	protected $_message = null;
56
+
57
+	/**
58
+	 * This is set by the constructor to indicate whether the incoming messenger
59
+	 * and message type are valid.  This can then be checked by callers to determine whether
60
+	 * to generate this message or not.
61
+	 * @type bool
62
+	 */
63
+	protected $_valid = false;
64
+
65
+	/**
66
+	 * If there are any errors (non exception errors) they get added to this array for callers to decide
67
+	 * how to handle.
68
+	 * @type array
69
+	 */
70
+	protected $_error_msg = array();
71
+
72
+	/**
73
+	 * Can be accessed via the send_now() method, this is set in the validation
74
+	 * routine via the EE_messenger::send_now() method.
75
+	 * @type bool
76
+	 */
77
+	protected $_send_now = false;
78
+
79
+	/**
80
+	 * Holds the classname for the data handler used by the current message type.
81
+	 * This is set on the first call to the public `get_data_handler_class_name()` method.
82
+	 * @type string
83
+	 */
84
+	protected $_data_handler_class_name = '';
85
+
86
+	/**
87
+	 * one of the message status constants on EEM_Message
88
+	 *
89
+	 * @type string
90
+	 */
91
+	protected $_message_status = '';
92
+
93
+
94
+
95
+	/**
96
+	 * Constructor
97
+	 *
98
+	 * @param string $messenger_name    Slug representing messenger
99
+	 * @param string $message_type_name Slug representing message type.
100
+	 * @param mixed  $data              Data used for generating message.
101
+	 * @param string $context           Optional context to restrict message generated for.
102
+	 * @param bool   $preview           Whether this is being used to generate a preview or not.
103
+	 * @param string $status
104
+	 */
105
+	public function __construct(
106
+		$messenger_name,
107
+		$message_type_name,
108
+		$data = array(),
109
+		$context = '',
110
+		$preview = false,
111
+		$status = EEM_Message::status_incomplete
112
+	) {
113
+		$this->_messenger_name      = $messenger_name;
114
+		$this->_message_type_name   = $message_type_name;
115
+		$this->_data                = is_array($data) ? $data : array( $data );
116
+		$this->_context             = $context;
117
+		$this->_preview             = $preview;
118
+		$this->_status              = $status;
119
+		// attempt to generate message immediately
120
+		$this->_message = $this->_generate_message();
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	public function context()
129
+	{
130
+		return $this->_context;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function data()
139
+	{
140
+		return $this->_data;
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @return EE_messenger
147
+	 */
148
+	public function messenger()
149
+	{
150
+		return $this->_messenger;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * @return EE_message_type
157
+	 */
158
+	public function message_type()
159
+	{
160
+		return $this->_message_type;
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * @return boolean
167
+	 */
168
+	public function preview()
169
+	{
170
+		return $this->_preview;
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 * @param boolean $preview
177
+	 */
178
+	public function set_preview($preview)
179
+	{
180
+		$this->_preview = filter_var($preview, FILTER_VALIDATE_BOOLEAN);
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * @return bool
187
+	 */
188
+	public function send_now()
189
+	{
190
+		return $this->_send_now;
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * Simply returns the state of the $_valid property.
197
+	 *
198
+	 * @return bool
199
+	 */
200
+	public function valid()
201
+	{
202
+		return $this->_valid;
203
+	}
204
+
205
+
206
+
207
+	/**
208
+	 * generates an EE_Message using the supplied arguments and some defaults
209
+	 *
210
+	 * @param array $properties
211
+	 * @return string
212
+	 */
213
+	protected function _generate_message($properties = array())
214
+	{
215
+		$message = EE_Message_Factory::create(
216
+			array_merge(
217
+				array(
218
+					'MSG_messenger'    => $this->_messenger_name,
219
+					'MSG_message_type' => $this->_message_type_name,
220
+					'MSG_context'      => $this->_context,
221
+					'STS_ID'           => $this->_status,
222
+				),
223
+				$properties
224
+			)
225
+		);
226
+		// validate the message, and if it's good, set some properties
227
+		try {
228
+			$message->is_valid_for_sending_or_generation(true);
229
+			$this->_valid = true;
230
+			$this->_messenger = $message->messenger_object();
231
+			$this->_message_type = $message->message_type_object();
232
+			$this->_send_now = $message->send_now();
233
+		} catch (Exception $e) {
234
+			$this->_valid = false;
235
+			$this->_error_msg[] = $e->getMessage();
236
+		}
237
+		return $message;
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 *  Returns an instantiated EE_Message object from the internal data.
244
+	 *
245
+	 * @return EE_Message
246
+	 */
247
+	public function get_EE_Message()
248
+	{
249
+		// already set ?
250
+		if ($this->_message instanceof EE_Message) {
251
+			return $this->_message;
252
+		}
253
+		// no? then let's create one
254
+		$this->_message = $this->_generate_message();
255
+		return $this->_message;
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 * This returns the data_handler class name for the internal message type set.
262
+	 * Note: this also verifies that the data handler class exists.  If it doesn't then $_valid is set to false
263
+	 * and the data_handler_class name is set to an empty string.
264
+	 *
265
+	 * @param   bool    $preview    Used to indicate that the preview data handler is to be returned.
266
+	 * @return  string
267
+	 */
268
+	public function get_data_handler_class_name($preview = false)
269
+	{
270
+		if ($this->_data_handler_class_name === '' && $this->valid()) {
271
+			$ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data);
272
+			// make sure internal data is updated.
273
+			$this->_data = $this->_message_type->get_data();
274
+
275
+			// verify
276
+			$this->_data_handler_class_name = EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref);
277
+			if ($this->_data_handler_class_name === '') {
278
+				$this->_valid = false;
279
+			}
280
+		}
281
+		return $this->_data_handler_class_name;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * Validates the given string as a reference for an existing, accessible data handler and returns the class name
288
+	 * For the handler the reference matches.
289
+	 *
290
+	 * @param string $data_handler_reference
291
+	 * @return string
292
+	 */
293
+	public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference)
294
+	{
295
+		$class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data';
296
+		if (! class_exists($class_name)) {
297
+			EE_Error::add_error(
298
+				sprintf(
299
+					__(
300
+						'The included data handler reference (%s) does not match any valid, accessible, "EE_Messages_incoming_data" classes.  Looking for %s.',
301
+						'event_espresso'
302
+					),
303
+					$data_handler_reference,
304
+					$class_name
305
+				),
306
+				__FILE__,
307
+				__FUNCTION__,
308
+				__LINE__
309
+			);
310
+			$class_name = ''; // clear out class_name so caller knows this isn't valid.
311
+		}
312
+		return $class_name;
313
+	}
314 314
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     ) {
113 113
         $this->_messenger_name      = $messenger_name;
114 114
         $this->_message_type_name   = $message_type_name;
115
-        $this->_data                = is_array($data) ? $data : array( $data );
115
+        $this->_data                = is_array($data) ? $data : array($data);
116 116
         $this->_context             = $context;
117 117
         $this->_preview             = $preview;
118 118
         $this->_status              = $status;
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
      */
293 293
     public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference)
294 294
     {
295
-        $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data';
296
-        if (! class_exists($class_name)) {
295
+        $class_name = 'EE_Messages_'.$data_handler_reference.'_incoming_data';
296
+        if ( ! class_exists($class_name)) {
297 297
             EE_Error::add_error(
298 298
                 sprintf(
299 299
                     __(
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Processor.lib.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -493,7 +493,7 @@
 block discarded – undo
493 493
     /**
494 494
      * This simply loops through all active messengers and takes care of setting up the
495 495
      * EE_Message_To_Generate objects.
496
-     * @param $message_type
496
+     * @param string $message_type
497 497
      * @param $data
498 498
      *
499 499
      * @return EE_Message_To_Generate[]
Please login to merge, or discard this patch.
Indentation   +582 added lines, -582 removed lines patch added patch discarded remove patch
@@ -12,590 +12,590 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @type EE_Message_Resource_Manager $_message_resource_manager
17
-     */
18
-    protected $_message_resource_manager;
19
-
20
-    /**
21
-     * @type EE_Messages_Queue
22
-     */
23
-    protected $_queue;
24
-
25
-    /**
26
-     * @type  EE_Messages_Generator
27
-     */
28
-    protected $_generator;
29
-
30
-
31
-
32
-
33
-    /**
34
-     * constructor
35
-     *
36
-     * @param EE_Message_Resource_Manager $message_resource_manager
37
-     */
38
-    public function __construct(EE_Message_Resource_Manager $message_resource_manager)
39
-    {
40
-        $this->_message_resource_manager = $message_resource_manager;
41
-        $this->_init_queue_and_generator();
42
-    }
43
-
44
-
45
-
46
-
47
-    /**
48
-     * This method sets (or resets) the various properties for use.
49
-     *
50
-     * - $_queue = holds the messages queue
51
-     * - $_generator = holds the messages generator
52
-     */
53
-    protected function _init_queue_and_generator()
54
-    {
55
-        $this->_generator = EE_Registry::factory('EE_Messages_Generator');
56
-        $this->_queue = $this->_generator->generation_queue();
57
-    }
58
-
59
-
60
-
61
-
62
-    /**
63
-     * This returns the current set queue.
64
-     * @return EE_Messages_Queue
65
-     */
66
-    public function get_queue()
67
-    {
68
-        return $this->_queue;
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * This method can be utilized to process messages from a queue and they will be processed immediately on the same request.
75
-     * Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes client code
76
-     * has already filtered those if necessary).
77
-     *
78
-     * @param EE_Messages_Queue $queue_to_process
79
-     * @return bool  true for success false for error.
80
-     */
81
-    public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process)
82
-    {
83
-        $success = false;
84
-        $messages_to_send = array();
85
-        $messages_to_generate = array();
86
-        // loop through and setup the various messages from the queue so we know what is being processed
87
-        $queue_to_process->get_message_repository()->rewind();
88
-        foreach ($queue_to_process->get_message_repository() as $message) {
89
-            if ($message->STS_ID() === EEM_Message::status_incomplete) {
90
-                $messages_to_generate[] = $message;
91
-                continue;
92
-            }
93
-
94
-            if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
95
-                $messages_to_send[] = $message;
96
-                continue;
97
-            }
98
-        }
99
-
100
-        // do generation/sends
101
-        if ($messages_to_generate) {
102
-            $success = $this->batch_generate_from_queue($messages_to_generate, true);
103
-        }
104
-
105
-        if ($messages_to_send) {
106
-            $sent = $this->batch_send_from_queue($messages_to_send, true);
107
-            // if there was messages to generate and it failed, then we override any success value for the sending process
108
-            // otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
109
-            // Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
110
-            // all messages processing on the same request.
111
-            $success = $messages_to_generate && ! $success ? false : $sent;
112
-        }
113
-        return $success;
114
-    }
115
-
116
-
117
-    /**
118
-     * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator.
119
-     *
120
-     * @param  EE_Message[] $messages    Array of EE_Message objects (optional) to build the queue with.
121
-     * @param  bool         $clear_queue Whether to ensure a fresh queue or not.
122
-     *
123
-     * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
124
-     *                                   generated messages.
125
-     */
126
-    public function batch_generate_from_queue($messages = array(), $clear_queue = false)
127
-    {
128
-        if ($this->_build_queue_for_generation($messages, $clear_queue)) {
129
-            $new_queue = $this->_generator->generate();
130
-            if ($new_queue instanceof EE_Messages_Queue) {
131
-                // unlock queue
132
-                $this->_queue->unlock_queue();
133
-                $new_queue->initiate_request_by_priority('send');
134
-                return $new_queue;
135
-            }
136
-        }
137
-        $this->_queue->unlock_queue();
138
-        return false;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * This method preps a queue for generation.
145
-     *
146
-     * @since    4.9.0
147
-     *
148
-     * @param EE_Message[] $messages    Array of EE_Message objects to build the queue with
149
-     *
150
-     * @param   bool       $clear_queue This indicates whether the existing queue should be dumped or not.
151
-     *
152
-     * @return bool true means queue prepped, false means there was a lock so no generation please.
153
-     */
154
-    protected function _build_queue_for_generation($messages = array(), $clear_queue = false)
155
-    {
156
-
157
-        if ($clear_queue) {
158
-            $this->_init_queue_and_generator();
159
-        }
160
-
161
-        if ($messages) {
162
-            // if generation is locked then get out now because that means processing is already happening.
163
-            if ($this->_queue->is_locked()) {
164
-                return false;
165
-            }
166
-
167
-            $this->_queue->lock_queue();
168
-            $messages = is_array($messages) ? $messages : array( $messages );
169
-            foreach ($messages as $message) {
170
-                if ($message instanceof EE_Message) {
171
-                    $data = $message->all_extra_meta_array();
172
-                    $this->_queue->add($message, $data);
173
-                }
174
-            }
175
-            return true;
176
-        } else {
177
-            return $this->_queue->get_batch_to_generate();
178
-        }
179
-    }
180
-
181
-
182
-    /**
183
-     * This method preps a queue for sending.
184
-     *
185
-     * @param EE_Message[] $messages
186
-     * @param bool  $clear_queue Used to indicate whether to start with a fresh queue or not.
187
-     *
188
-     * @return bool true means queue prepped, false means there was a lock so no queue prepped.
189
-     */
190
-    protected function _build_queue_for_sending($messages, $clear_queue = false)
191
-    {
192
-        // if sending is locked then get out now because that means processing is already happening.
193
-        if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
194
-            return false;
195
-        }
196
-
197
-        $this->_queue->lock_queue(EE_Messages_Queue::action_sending);
198
-
199
-        if ($clear_queue) {
200
-            $this->_init_queue_and_generator();
201
-        }
202
-
203
-        $messages = is_array($messages) ? $messages : array( $messages );
204
-
205
-        foreach ($messages as $message) {
206
-            $this->_queue->add($message);
207
-        }
208
-        return true;
209
-    }
210
-
211
-
212
-    /**
213
-     * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute()
214
-     * to iterate and send unsent messages.
215
-     *
216
-     * @param EE_Message[] $messages    If an array of messages is sent in then use it.
217
-     *
218
-     * @param bool         $clear_queue Whether to initialize a new queue or keep the existing one.
219
-     *
220
-     * @return EE_Messages_Queue
221
-     */
222
-    public function batch_send_from_queue($messages = array(), $clear_queue = false)
223
-    {
224
-
225
-        if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
226
-            $this->_queue->execute();
227
-            $this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
228
-        } else {
229
-            // get messages to send and execute.
230
-            $this->_queue->get_to_send_batch_and_send();
231
-        }
232
-        // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed
233
-        // messages in the queue and decide how to handle at that point.
234
-        return $this->_queue;
235
-    }
236
-
237
-
238
-
239
-
240
-
241
-
242
-    /**
243
-     * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the
244
-     * EE_Message_Queue with the generated messages for the caller to work with.  Note, this does NOT save the generated
245
-     * messages in the queue, leaving it up to the caller to do so.
246
-     *
247
-     * @param EE_Message_To_Generate[] $messages_to_generate
248
-     * @return EE_Messages_Queue
249
-     */
250
-    public function generate_and_return($messages_to_generate)
251
-    {
252
-        $this->_init_queue_and_generator();
253
-        $this->_queue_for_generation_loop($messages_to_generate);
254
-        return $this->_generator->generate(false);
255
-    }
256
-
257
-
258
-
259
-
260
-    /**
261
-     * Executes the generator generate method on the current internal queue, and returns the generated queue.
262
-     * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
263
-     * @return EE_Messages_Queue
264
-     */
265
-    public function generate_queue($persist = true)
266
-    {
267
-        return $this->_generator->generate($persist);
268
-    }
15
+	/**
16
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
17
+	 */
18
+	protected $_message_resource_manager;
19
+
20
+	/**
21
+	 * @type EE_Messages_Queue
22
+	 */
23
+	protected $_queue;
24
+
25
+	/**
26
+	 * @type  EE_Messages_Generator
27
+	 */
28
+	protected $_generator;
29
+
30
+
31
+
32
+
33
+	/**
34
+	 * constructor
35
+	 *
36
+	 * @param EE_Message_Resource_Manager $message_resource_manager
37
+	 */
38
+	public function __construct(EE_Message_Resource_Manager $message_resource_manager)
39
+	{
40
+		$this->_message_resource_manager = $message_resource_manager;
41
+		$this->_init_queue_and_generator();
42
+	}
43
+
44
+
45
+
46
+
47
+	/**
48
+	 * This method sets (or resets) the various properties for use.
49
+	 *
50
+	 * - $_queue = holds the messages queue
51
+	 * - $_generator = holds the messages generator
52
+	 */
53
+	protected function _init_queue_and_generator()
54
+	{
55
+		$this->_generator = EE_Registry::factory('EE_Messages_Generator');
56
+		$this->_queue = $this->_generator->generation_queue();
57
+	}
58
+
59
+
60
+
61
+
62
+	/**
63
+	 * This returns the current set queue.
64
+	 * @return EE_Messages_Queue
65
+	 */
66
+	public function get_queue()
67
+	{
68
+		return $this->_queue;
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * This method can be utilized to process messages from a queue and they will be processed immediately on the same request.
75
+	 * Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes client code
76
+	 * has already filtered those if necessary).
77
+	 *
78
+	 * @param EE_Messages_Queue $queue_to_process
79
+	 * @return bool  true for success false for error.
80
+	 */
81
+	public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process)
82
+	{
83
+		$success = false;
84
+		$messages_to_send = array();
85
+		$messages_to_generate = array();
86
+		// loop through and setup the various messages from the queue so we know what is being processed
87
+		$queue_to_process->get_message_repository()->rewind();
88
+		foreach ($queue_to_process->get_message_repository() as $message) {
89
+			if ($message->STS_ID() === EEM_Message::status_incomplete) {
90
+				$messages_to_generate[] = $message;
91
+				continue;
92
+			}
93
+
94
+			if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
95
+				$messages_to_send[] = $message;
96
+				continue;
97
+			}
98
+		}
99
+
100
+		// do generation/sends
101
+		if ($messages_to_generate) {
102
+			$success = $this->batch_generate_from_queue($messages_to_generate, true);
103
+		}
104
+
105
+		if ($messages_to_send) {
106
+			$sent = $this->batch_send_from_queue($messages_to_send, true);
107
+			// if there was messages to generate and it failed, then we override any success value for the sending process
108
+			// otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
109
+			// Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
110
+			// all messages processing on the same request.
111
+			$success = $messages_to_generate && ! $success ? false : $sent;
112
+		}
113
+		return $success;
114
+	}
115
+
116
+
117
+	/**
118
+	 * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator.
119
+	 *
120
+	 * @param  EE_Message[] $messages    Array of EE_Message objects (optional) to build the queue with.
121
+	 * @param  bool         $clear_queue Whether to ensure a fresh queue or not.
122
+	 *
123
+	 * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
124
+	 *                                   generated messages.
125
+	 */
126
+	public function batch_generate_from_queue($messages = array(), $clear_queue = false)
127
+	{
128
+		if ($this->_build_queue_for_generation($messages, $clear_queue)) {
129
+			$new_queue = $this->_generator->generate();
130
+			if ($new_queue instanceof EE_Messages_Queue) {
131
+				// unlock queue
132
+				$this->_queue->unlock_queue();
133
+				$new_queue->initiate_request_by_priority('send');
134
+				return $new_queue;
135
+			}
136
+		}
137
+		$this->_queue->unlock_queue();
138
+		return false;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * This method preps a queue for generation.
145
+	 *
146
+	 * @since    4.9.0
147
+	 *
148
+	 * @param EE_Message[] $messages    Array of EE_Message objects to build the queue with
149
+	 *
150
+	 * @param   bool       $clear_queue This indicates whether the existing queue should be dumped or not.
151
+	 *
152
+	 * @return bool true means queue prepped, false means there was a lock so no generation please.
153
+	 */
154
+	protected function _build_queue_for_generation($messages = array(), $clear_queue = false)
155
+	{
156
+
157
+		if ($clear_queue) {
158
+			$this->_init_queue_and_generator();
159
+		}
160
+
161
+		if ($messages) {
162
+			// if generation is locked then get out now because that means processing is already happening.
163
+			if ($this->_queue->is_locked()) {
164
+				return false;
165
+			}
166
+
167
+			$this->_queue->lock_queue();
168
+			$messages = is_array($messages) ? $messages : array( $messages );
169
+			foreach ($messages as $message) {
170
+				if ($message instanceof EE_Message) {
171
+					$data = $message->all_extra_meta_array();
172
+					$this->_queue->add($message, $data);
173
+				}
174
+			}
175
+			return true;
176
+		} else {
177
+			return $this->_queue->get_batch_to_generate();
178
+		}
179
+	}
180
+
181
+
182
+	/**
183
+	 * This method preps a queue for sending.
184
+	 *
185
+	 * @param EE_Message[] $messages
186
+	 * @param bool  $clear_queue Used to indicate whether to start with a fresh queue or not.
187
+	 *
188
+	 * @return bool true means queue prepped, false means there was a lock so no queue prepped.
189
+	 */
190
+	protected function _build_queue_for_sending($messages, $clear_queue = false)
191
+	{
192
+		// if sending is locked then get out now because that means processing is already happening.
193
+		if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
194
+			return false;
195
+		}
196
+
197
+		$this->_queue->lock_queue(EE_Messages_Queue::action_sending);
198
+
199
+		if ($clear_queue) {
200
+			$this->_init_queue_and_generator();
201
+		}
202
+
203
+		$messages = is_array($messages) ? $messages : array( $messages );
204
+
205
+		foreach ($messages as $message) {
206
+			$this->_queue->add($message);
207
+		}
208
+		return true;
209
+	}
210
+
211
+
212
+	/**
213
+	 * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute()
214
+	 * to iterate and send unsent messages.
215
+	 *
216
+	 * @param EE_Message[] $messages    If an array of messages is sent in then use it.
217
+	 *
218
+	 * @param bool         $clear_queue Whether to initialize a new queue or keep the existing one.
219
+	 *
220
+	 * @return EE_Messages_Queue
221
+	 */
222
+	public function batch_send_from_queue($messages = array(), $clear_queue = false)
223
+	{
224
+
225
+		if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
226
+			$this->_queue->execute();
227
+			$this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
228
+		} else {
229
+			// get messages to send and execute.
230
+			$this->_queue->get_to_send_batch_and_send();
231
+		}
232
+		// note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed
233
+		// messages in the queue and decide how to handle at that point.
234
+		return $this->_queue;
235
+	}
236
+
237
+
238
+
239
+
240
+
241
+
242
+	/**
243
+	 * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the
244
+	 * EE_Message_Queue with the generated messages for the caller to work with.  Note, this does NOT save the generated
245
+	 * messages in the queue, leaving it up to the caller to do so.
246
+	 *
247
+	 * @param EE_Message_To_Generate[] $messages_to_generate
248
+	 * @return EE_Messages_Queue
249
+	 */
250
+	public function generate_and_return($messages_to_generate)
251
+	{
252
+		$this->_init_queue_and_generator();
253
+		$this->_queue_for_generation_loop($messages_to_generate);
254
+		return $this->_generator->generate(false);
255
+	}
256
+
257
+
258
+
259
+
260
+	/**
261
+	 * Executes the generator generate method on the current internal queue, and returns the generated queue.
262
+	 * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
263
+	 * @return EE_Messages_Queue
264
+	 */
265
+	public function generate_queue($persist = true)
266
+	{
267
+		return $this->_generator->generate($persist);
268
+	}
269 269
 
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * Queue for generation.  Note this does NOT persist to the db.  Client code should call get_message_repository()->save() if desire
275
-     * to persist.  This method is provided to client code to decide what it wants to do with queued messages for generation.
276
-     * @param EE_Message_To_Generate $message_to_generate
277
-     * @param bool                   $test_send             Whether this item is for a test send or not.
278
-     * @return  EE_Messages_Queue
279
-     */
280
-    public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false)
281
-    {
282
-        if ($message_to_generate->valid()) {
283
-            $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
284
-        }
285
-    }
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-    /**
294
-     * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue
295
-     * and then persists to storage.
296
-     *
297
-     * @param EE_Message_To_Generate[] $messages_to_generate
298
-     */
299
-    public function batch_queue_for_generation_and_persist($messages_to_generate)
300
-    {
301
-        $this->_init_queue_and_generator();
302
-        $this->_queue_for_generation_loop($messages_to_generate);
303
-        $this->_queue->save();
304
-    }
305
-
306
-
307
-
308
-
309
-
310
-
311
-    /**
312
-     * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation
313
-     * queue.  Does NOT persist to storage (unless there is an error.
314
-     * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue()
315
-     *
316
-     * @param EE_Message_To_Generate[]  $messages_to_generate
317
-     */
318
-    public function batch_queue_for_generation_no_persist($messages_to_generate)
319
-    {
320
-        $this->_init_queue_and_generator();
321
-        $this->_queue_for_generation_loop($messages_to_generate);
322
-    }
323
-
324
-
325
-
326
-
327
-    /**
328
-     * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message
329
-     * objects.
330
-     *
331
-     * @param EE_Message_To_Generate[] $messages_to_generate
332
-     */
333
-    protected function _queue_for_generation_loop($messages_to_generate)
334
-    {
335
-        // make sure is in an array.
336
-        if (! is_array($messages_to_generate)) {
337
-            $messages_to_generate = array( $messages_to_generate );
338
-        }
339
-
340
-        foreach ($messages_to_generate as $message_to_generate) {
341
-            if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
342
-                $this->queue_for_generation($message_to_generate);
343
-            }
344
-        }
345
-    }
346
-
347
-
348
-
349
-
350
-
351
-    /**
352
-     * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its
353
-     * queued for sending).
354
-     * @param  EE_Message_To_Generate[]
355
-     * @return EE_Messages_Queue
356
-     */
357
-    public function generate_and_queue_for_sending($messages_to_generate)
358
-    {
359
-        $this->_init_queue_and_generator();
360
-        $this->_queue_for_generation_loop($messages_to_generate);
361
-        return $this->_generator->generate(true);
362
-    }
363
-
364
-
365
-
366
-
367
-
368
-    /**
369
-     * Generate for preview and execute right away.
370
-     *
371
-     * @param   EE_Message_To_Generate $message_to_generate
372
-     * @param   bool                   $test_send                Whether this is a test send or not.
373
-     * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
374
-     */
375
-    public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376
-    {
377
-        if (! $message_to_generate->valid()) {
378
-            EE_Error::add_error(
379
-                __('Unable to generate preview because of invalid data', 'event_espresso'),
380
-                __FILE__,
381
-                __FUNCTION__,
382
-                __LINE__
383
-            );
384
-            return false;
385
-        }
386
-        // just make sure preview is set on the $message_to_generate (in case client forgot)
387
-        $message_to_generate->set_preview(true);
388
-        $this->_init_queue_and_generator();
389
-        $this->queue_for_generation($message_to_generate, $test_send);
390
-        $generated_queue = $this->_generator->generate(false);
391
-        if ($generated_queue->execute(false)) {
392
-            // the first queue item should be the preview
393
-            $generated_queue->get_message_repository()->rewind();
394
-            if (! $generated_queue->get_message_repository()->valid()) {
395
-                return $generated_queue;
396
-            }
397
-            return $generated_queue;
398
-        } else {
399
-            return false;
400
-        }
401
-    }
402
-
403
-
404
-    /**
405
-     * This queues for sending.
406
-     * The messenger send now method is also verified to see if sending immediately is requested.
407
-     * otherwise its just saved to the queue.
408
-     * @param EE_Message_To_Generate $message_to_generate
409
-     * @return bool true or false for success.
410
-     */
411
-    public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412
-    {
413
-        if (! $message_to_generate->valid()) {
414
-            return false;
415
-        }
416
-        $this->_init_queue_and_generator();
417
-        $message = $message_to_generate->get_EE_Message();
418
-        $this->_queue->add($message);
419
-        if ($message->send_now()) {
420
-            $this->_queue->execute(false);
421
-        } else {
422
-            $this->_queue->save();
423
-        }
424
-        return true;
425
-    }
426
-
427
-
428
-    /**
429
-     * This generates and sends from the given EE_Message_To_Generate class immediately.
430
-     * @param EE_Message_To_Generate $message_to_generate
431
-     * @return EE_Messages_Queue | null
432
-     */
433
-    public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434
-    {
435
-        if (! $message_to_generate->valid()) {
436
-            return null;
437
-        }
438
-        // is there supposed to be a sending messenger for this message?
439
-        if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
440
-            // make sure it's valid, but if it's not,
441
-            // then set the value of $sending_messenger to an EE_Error object
442
-            // so that downstream code can easily see that things went wrong.
443
-            $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger
444
-                ? $message_to_generate->sending_messenger()
445
-                : new EE_Error(
446
-                    __(
447
-                        'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.',
448
-                        'event_espresso'
449
-                    )
450
-                );
451
-        } else {
452
-            $sending_messenger = null;
453
-        }
454
-
455
-        if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
456
-            $this->_init_queue_and_generator();
457
-            $this->_queue->add($message_to_generate->get_EE_Message());
458
-            $this->_queue->execute(false, $sending_messenger);
459
-            return $this->_queue;
460
-        } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
-            $generated_queue = $this->generate_and_return(array( $message_to_generate ));
462
-            $generated_queue->execute(false, $sending_messenger);
463
-            return $generated_queue;
464
-        }
465
-        return null;
466
-    }
467
-
468
-
469
-
470
-
471
-    /**
472
-     * Creates mtg objects for all active messengers and queues for generation.
473
-     * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking
474
-     * request to complete the action if the priority for the message requires immediate action.
475
-     * @param string $message_type
476
-     * @param mixed  $data   The data being used for generation.
477
-     * @param bool   $persist   Whether to persist the queued messages to the db or not.
478
-     */
479
-    public function generate_for_all_active_messengers($message_type, $data, $persist = true)
480
-    {
481
-        $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
482
-        if ($persist) {
483
-            $this->batch_queue_for_generation_and_persist($messages_to_generate);
484
-            $this->_queue->initiate_request_by_priority();
485
-        } else {
486
-            $this->batch_queue_for_generation_no_persist($messages_to_generate);
487
-        }
488
-    }
489
-
490
-
491
-
492
-
493
-    /**
494
-     * This simply loops through all active messengers and takes care of setting up the
495
-     * EE_Message_To_Generate objects.
496
-     * @param $message_type
497
-     * @param $data
498
-     *
499
-     * @return EE_Message_To_Generate[]
500
-     */
501
-    public function setup_mtgs_for_all_active_messengers($message_type, $data)
502
-    {
503
-        $messages_to_generate = array();
504
-        foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
505
-            $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
506
-            if ($message_to_generate->valid()) {
507
-                $messages_to_generate[] = $message_to_generate;
508
-            }
509
-        }
510
-        return $messages_to_generate;
511
-    }
512
-
513
-
514
-
515
-
516
-    /**
517
-     * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database
518
-     * and send.
519
-     * @param array $message_ids
520
-     */
521
-    public function setup_messages_from_ids_and_send($message_ids)
522
-    {
523
-        $this->_init_queue_and_generator();
524
-        $messages = EEM_Message::instance()->get_all(array(
525
-            array(
526
-                'MSG_ID' => array( 'IN', $message_ids ),
527
-                'STS_ID' => array(
528
-                    'IN',
529
-                    array_merge(
530
-                        EEM_Message::instance()->stati_indicating_sent(),
531
-                        array( EEM_Message::status_retry )
532
-                    ),
533
-                ),
534
-            ),
535
-        ));
536
-        // set the Messages to resend.
537
-        foreach ($messages as $message) {
538
-            if ($message instanceof EE_Message) {
539
-                $message->set_STS_ID(EEM_Message::status_resend);
540
-                $this->_queue->add($message);
541
-            }
542
-        }
543
-
544
-        $this->_queue->initiate_request_by_priority('send');
545
-    }
546
-
547
-
548
-
549
-    /**
550
-     * This method checks for registration IDs in the request via the given key and creates the messages to generate
551
-     * objects from them, then returns the array of messages to generate objects.
552
-     * Note, this sets up registrations for the registration family of message types.
553
-     *
554
-     * @param string $registration_ids_key  This is used to indicate what represents the registration ids in the request.
555
-     *
556
-     * @return EE_Message_To_Generate[]
557
-     */
558
-    public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID')
559
-    {
560
-        EE_Registry::instance()->load_core('Request_Handler');
561
-        EE_Registry::instance()->load_helper('MSG_Template');
562
-        $regs_to_send = array();
563
-        $regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
564
-        if (empty($regIDs)) {
565
-            EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
566
-            return false;
567
-        }
568
-
569
-        // make sure is an array
570
-        $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
571
-
572
-        foreach ($regIDs as $regID) {
573
-            $reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
-            if (! $reg instanceof EE_Registration) {
575
-                EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576
-                return false;
577
-            }
578
-            $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
579
-        }
580
-
581
-        $messages_to_generate = array();
582
-
583
-        foreach ($regs_to_send as $status_group) {
584
-            foreach ($status_group as $status_id => $registrations) {
585
-                $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
-                if (! $message_type) {
587
-                    continue;
588
-                }
589
-                $messages_to_generate = array_merge(
590
-                    $messages_to_generate,
591
-                    $this->setup_mtgs_for_all_active_messengers(
592
-                        $message_type,
593
-                        array( $registrations, $status_id )
594
-                    )
595
-                );
596
-            }
597
-        }
598
-
599
-        return $messages_to_generate;
600
-    }
273
+	/**
274
+	 * Queue for generation.  Note this does NOT persist to the db.  Client code should call get_message_repository()->save() if desire
275
+	 * to persist.  This method is provided to client code to decide what it wants to do with queued messages for generation.
276
+	 * @param EE_Message_To_Generate $message_to_generate
277
+	 * @param bool                   $test_send             Whether this item is for a test send or not.
278
+	 * @return  EE_Messages_Queue
279
+	 */
280
+	public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false)
281
+	{
282
+		if ($message_to_generate->valid()) {
283
+			$this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
284
+		}
285
+	}
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+	/**
294
+	 * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue
295
+	 * and then persists to storage.
296
+	 *
297
+	 * @param EE_Message_To_Generate[] $messages_to_generate
298
+	 */
299
+	public function batch_queue_for_generation_and_persist($messages_to_generate)
300
+	{
301
+		$this->_init_queue_and_generator();
302
+		$this->_queue_for_generation_loop($messages_to_generate);
303
+		$this->_queue->save();
304
+	}
305
+
306
+
307
+
308
+
309
+
310
+
311
+	/**
312
+	 * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation
313
+	 * queue.  Does NOT persist to storage (unless there is an error.
314
+	 * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue()
315
+	 *
316
+	 * @param EE_Message_To_Generate[]  $messages_to_generate
317
+	 */
318
+	public function batch_queue_for_generation_no_persist($messages_to_generate)
319
+	{
320
+		$this->_init_queue_and_generator();
321
+		$this->_queue_for_generation_loop($messages_to_generate);
322
+	}
323
+
324
+
325
+
326
+
327
+	/**
328
+	 * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message
329
+	 * objects.
330
+	 *
331
+	 * @param EE_Message_To_Generate[] $messages_to_generate
332
+	 */
333
+	protected function _queue_for_generation_loop($messages_to_generate)
334
+	{
335
+		// make sure is in an array.
336
+		if (! is_array($messages_to_generate)) {
337
+			$messages_to_generate = array( $messages_to_generate );
338
+		}
339
+
340
+		foreach ($messages_to_generate as $message_to_generate) {
341
+			if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
342
+				$this->queue_for_generation($message_to_generate);
343
+			}
344
+		}
345
+	}
346
+
347
+
348
+
349
+
350
+
351
+	/**
352
+	 * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its
353
+	 * queued for sending).
354
+	 * @param  EE_Message_To_Generate[]
355
+	 * @return EE_Messages_Queue
356
+	 */
357
+	public function generate_and_queue_for_sending($messages_to_generate)
358
+	{
359
+		$this->_init_queue_and_generator();
360
+		$this->_queue_for_generation_loop($messages_to_generate);
361
+		return $this->_generator->generate(true);
362
+	}
363
+
364
+
365
+
366
+
367
+
368
+	/**
369
+	 * Generate for preview and execute right away.
370
+	 *
371
+	 * @param   EE_Message_To_Generate $message_to_generate
372
+	 * @param   bool                   $test_send                Whether this is a test send or not.
373
+	 * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
374
+	 */
375
+	public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376
+	{
377
+		if (! $message_to_generate->valid()) {
378
+			EE_Error::add_error(
379
+				__('Unable to generate preview because of invalid data', 'event_espresso'),
380
+				__FILE__,
381
+				__FUNCTION__,
382
+				__LINE__
383
+			);
384
+			return false;
385
+		}
386
+		// just make sure preview is set on the $message_to_generate (in case client forgot)
387
+		$message_to_generate->set_preview(true);
388
+		$this->_init_queue_and_generator();
389
+		$this->queue_for_generation($message_to_generate, $test_send);
390
+		$generated_queue = $this->_generator->generate(false);
391
+		if ($generated_queue->execute(false)) {
392
+			// the first queue item should be the preview
393
+			$generated_queue->get_message_repository()->rewind();
394
+			if (! $generated_queue->get_message_repository()->valid()) {
395
+				return $generated_queue;
396
+			}
397
+			return $generated_queue;
398
+		} else {
399
+			return false;
400
+		}
401
+	}
402
+
403
+
404
+	/**
405
+	 * This queues for sending.
406
+	 * The messenger send now method is also verified to see if sending immediately is requested.
407
+	 * otherwise its just saved to the queue.
408
+	 * @param EE_Message_To_Generate $message_to_generate
409
+	 * @return bool true or false for success.
410
+	 */
411
+	public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412
+	{
413
+		if (! $message_to_generate->valid()) {
414
+			return false;
415
+		}
416
+		$this->_init_queue_and_generator();
417
+		$message = $message_to_generate->get_EE_Message();
418
+		$this->_queue->add($message);
419
+		if ($message->send_now()) {
420
+			$this->_queue->execute(false);
421
+		} else {
422
+			$this->_queue->save();
423
+		}
424
+		return true;
425
+	}
426
+
427
+
428
+	/**
429
+	 * This generates and sends from the given EE_Message_To_Generate class immediately.
430
+	 * @param EE_Message_To_Generate $message_to_generate
431
+	 * @return EE_Messages_Queue | null
432
+	 */
433
+	public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434
+	{
435
+		if (! $message_to_generate->valid()) {
436
+			return null;
437
+		}
438
+		// is there supposed to be a sending messenger for this message?
439
+		if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
440
+			// make sure it's valid, but if it's not,
441
+			// then set the value of $sending_messenger to an EE_Error object
442
+			// so that downstream code can easily see that things went wrong.
443
+			$sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger
444
+				? $message_to_generate->sending_messenger()
445
+				: new EE_Error(
446
+					__(
447
+						'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.',
448
+						'event_espresso'
449
+					)
450
+				);
451
+		} else {
452
+			$sending_messenger = null;
453
+		}
454
+
455
+		if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
456
+			$this->_init_queue_and_generator();
457
+			$this->_queue->add($message_to_generate->get_EE_Message());
458
+			$this->_queue->execute(false, $sending_messenger);
459
+			return $this->_queue;
460
+		} elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
+			$generated_queue = $this->generate_and_return(array( $message_to_generate ));
462
+			$generated_queue->execute(false, $sending_messenger);
463
+			return $generated_queue;
464
+		}
465
+		return null;
466
+	}
467
+
468
+
469
+
470
+
471
+	/**
472
+	 * Creates mtg objects for all active messengers and queues for generation.
473
+	 * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking
474
+	 * request to complete the action if the priority for the message requires immediate action.
475
+	 * @param string $message_type
476
+	 * @param mixed  $data   The data being used for generation.
477
+	 * @param bool   $persist   Whether to persist the queued messages to the db or not.
478
+	 */
479
+	public function generate_for_all_active_messengers($message_type, $data, $persist = true)
480
+	{
481
+		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
482
+		if ($persist) {
483
+			$this->batch_queue_for_generation_and_persist($messages_to_generate);
484
+			$this->_queue->initiate_request_by_priority();
485
+		} else {
486
+			$this->batch_queue_for_generation_no_persist($messages_to_generate);
487
+		}
488
+	}
489
+
490
+
491
+
492
+
493
+	/**
494
+	 * This simply loops through all active messengers and takes care of setting up the
495
+	 * EE_Message_To_Generate objects.
496
+	 * @param $message_type
497
+	 * @param $data
498
+	 *
499
+	 * @return EE_Message_To_Generate[]
500
+	 */
501
+	public function setup_mtgs_for_all_active_messengers($message_type, $data)
502
+	{
503
+		$messages_to_generate = array();
504
+		foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
505
+			$message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
506
+			if ($message_to_generate->valid()) {
507
+				$messages_to_generate[] = $message_to_generate;
508
+			}
509
+		}
510
+		return $messages_to_generate;
511
+	}
512
+
513
+
514
+
515
+
516
+	/**
517
+	 * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database
518
+	 * and send.
519
+	 * @param array $message_ids
520
+	 */
521
+	public function setup_messages_from_ids_and_send($message_ids)
522
+	{
523
+		$this->_init_queue_and_generator();
524
+		$messages = EEM_Message::instance()->get_all(array(
525
+			array(
526
+				'MSG_ID' => array( 'IN', $message_ids ),
527
+				'STS_ID' => array(
528
+					'IN',
529
+					array_merge(
530
+						EEM_Message::instance()->stati_indicating_sent(),
531
+						array( EEM_Message::status_retry )
532
+					),
533
+				),
534
+			),
535
+		));
536
+		// set the Messages to resend.
537
+		foreach ($messages as $message) {
538
+			if ($message instanceof EE_Message) {
539
+				$message->set_STS_ID(EEM_Message::status_resend);
540
+				$this->_queue->add($message);
541
+			}
542
+		}
543
+
544
+		$this->_queue->initiate_request_by_priority('send');
545
+	}
546
+
547
+
548
+
549
+	/**
550
+	 * This method checks for registration IDs in the request via the given key and creates the messages to generate
551
+	 * objects from them, then returns the array of messages to generate objects.
552
+	 * Note, this sets up registrations for the registration family of message types.
553
+	 *
554
+	 * @param string $registration_ids_key  This is used to indicate what represents the registration ids in the request.
555
+	 *
556
+	 * @return EE_Message_To_Generate[]
557
+	 */
558
+	public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID')
559
+	{
560
+		EE_Registry::instance()->load_core('Request_Handler');
561
+		EE_Registry::instance()->load_helper('MSG_Template');
562
+		$regs_to_send = array();
563
+		$regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
564
+		if (empty($regIDs)) {
565
+			EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
566
+			return false;
567
+		}
568
+
569
+		// make sure is an array
570
+		$regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
571
+
572
+		foreach ($regIDs as $regID) {
573
+			$reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
+			if (! $reg instanceof EE_Registration) {
575
+				EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576
+				return false;
577
+			}
578
+			$regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
579
+		}
580
+
581
+		$messages_to_generate = array();
582
+
583
+		foreach ($regs_to_send as $status_group) {
584
+			foreach ($status_group as $status_id => $registrations) {
585
+				$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
+				if (! $message_type) {
587
+					continue;
588
+				}
589
+				$messages_to_generate = array_merge(
590
+					$messages_to_generate,
591
+					$this->setup_mtgs_for_all_active_messengers(
592
+						$message_type,
593
+						array( $registrations, $status_id )
594
+					)
595
+				);
596
+			}
597
+		}
598
+
599
+		return $messages_to_generate;
600
+	}
601 601
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
             }
166 166
 
167 167
             $this->_queue->lock_queue();
168
-            $messages = is_array($messages) ? $messages : array( $messages );
168
+            $messages = is_array($messages) ? $messages : array($messages);
169 169
             foreach ($messages as $message) {
170 170
                 if ($message instanceof EE_Message) {
171 171
                     $data = $message->all_extra_meta_array();
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
             $this->_init_queue_and_generator();
201 201
         }
202 202
 
203
-        $messages = is_array($messages) ? $messages : array( $messages );
203
+        $messages = is_array($messages) ? $messages : array($messages);
204 204
 
205 205
         foreach ($messages as $message) {
206 206
             $this->_queue->add($message);
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
     protected function _queue_for_generation_loop($messages_to_generate)
334 334
     {
335 335
         // make sure is in an array.
336
-        if (! is_array($messages_to_generate)) {
337
-            $messages_to_generate = array( $messages_to_generate );
336
+        if ( ! is_array($messages_to_generate)) {
337
+            $messages_to_generate = array($messages_to_generate);
338 338
         }
339 339
 
340 340
         foreach ($messages_to_generate as $message_to_generate) {
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      */
375 375
     public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376 376
     {
377
-        if (! $message_to_generate->valid()) {
377
+        if ( ! $message_to_generate->valid()) {
378 378
             EE_Error::add_error(
379 379
                 __('Unable to generate preview because of invalid data', 'event_espresso'),
380 380
                 __FILE__,
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
         if ($generated_queue->execute(false)) {
392 392
             // the first queue item should be the preview
393 393
             $generated_queue->get_message_repository()->rewind();
394
-            if (! $generated_queue->get_message_repository()->valid()) {
394
+            if ( ! $generated_queue->get_message_repository()->valid()) {
395 395
                 return $generated_queue;
396 396
             }
397 397
             return $generated_queue;
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
      */
411 411
     public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412 412
     {
413
-        if (! $message_to_generate->valid()) {
413
+        if ( ! $message_to_generate->valid()) {
414 414
             return false;
415 415
         }
416 416
         $this->_init_queue_and_generator();
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
      */
433 433
     public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434 434
     {
435
-        if (! $message_to_generate->valid()) {
435
+        if ( ! $message_to_generate->valid()) {
436 436
             return null;
437 437
         }
438 438
         // is there supposed to be a sending messenger for this message?
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
             $this->_queue->execute(false, $sending_messenger);
459 459
             return $this->_queue;
460 460
         } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
-            $generated_queue = $this->generate_and_return(array( $message_to_generate ));
461
+            $generated_queue = $this->generate_and_return(array($message_to_generate));
462 462
             $generated_queue->execute(false, $sending_messenger);
463 463
             return $generated_queue;
464 464
         }
@@ -523,12 +523,12 @@  discard block
 block discarded – undo
523 523
         $this->_init_queue_and_generator();
524 524
         $messages = EEM_Message::instance()->get_all(array(
525 525
             array(
526
-                'MSG_ID' => array( 'IN', $message_ids ),
526
+                'MSG_ID' => array('IN', $message_ids),
527 527
                 'STS_ID' => array(
528 528
                     'IN',
529 529
                     array_merge(
530 530
                         EEM_Message::instance()->stati_indicating_sent(),
531
-                        array( EEM_Message::status_retry )
531
+                        array(EEM_Message::status_retry)
532 532
                     ),
533 533
                 ),
534 534
             ),
@@ -567,15 +567,15 @@  discard block
 block discarded – undo
567 567
         }
568 568
 
569 569
         // make sure is an array
570
-        $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
570
+        $regIDs = is_array($regIDs) ? $regIDs : array($regIDs);
571 571
 
572 572
         foreach ($regIDs as $regID) {
573 573
             $reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
-            if (! $reg instanceof EE_Registration) {
574
+            if ( ! $reg instanceof EE_Registration) {
575 575
                 EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576 576
                 return false;
577 577
             }
578
-            $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
578
+            $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
579 579
         }
580 580
 
581 581
         $messages_to_generate = array();
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
         foreach ($regs_to_send as $status_group) {
584 584
             foreach ($status_group as $status_id => $registrations) {
585 585
                 $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
-                if (! $message_type) {
586
+                if ( ! $message_type) {
587 587
                     continue;
588 588
                 }
589 589
                 $messages_to_generate = array_merge(
590 590
                     $messages_to_generate,
591 591
                     $this->setup_mtgs_for_all_active_messengers(
592 592
                         $message_type,
593
-                        array( $registrations, $status_id )
593
+                        array($registrations, $status_id)
594 594
                     )
595 595
                 );
596 596
             }
Please login to merge, or discard this patch.
core/libraries/messages/EE_messenger.lib.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
     /**
504 504
      * @param $message_types
505 505
      * @param array $extra
506
-     * @return mixed|string
506
+     * @return string
507 507
      */
508 508
     protected function _get_admin_content_events_edit($message_types, $extra)
509 509
     {
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
      * All this does is set the existing test settings (in the db) for the messenger
816 816
      *
817 817
      * @access public
818
-     * @param $settings
818
+     * @param string $settings
819 819
      * @return bool success/fail
820 820
      */
821 821
     public function set_existing_test_settings($settings)
Please login to merge, or discard this patch.
Indentation   +733 added lines, -733 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]' => __('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]' => __('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 = __('Template Structure', 'event_espresso');
352
-        $this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
353
-        $this->_supports_labels->template_pack_description = __('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 = __('Template Structure', 'event_espresso');
352
+		$this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
353
+		$this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
354 354
 
355
-        $this->_supports_labels->template_variation_description = __('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 = __('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,490 +407,490 @@  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 ] = __('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
-                $edit_url_query_args = [
561
-                    'page' => 'espresso_messages',
562
-                    'action' => 'edit_message_template',
563
-                    'id' => $default_value,
564
-                    'evt_id' => $event_id
565
-                ];
566
-                $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
567
-                $create_url_query_args = [
568
-                    'page' => 'espresso_messages',
569
-                    'action' => 'add_new_message_template',
570
-                    'GRP_ID' => $default_value
571
-                ];
572
-                $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
573
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
574
-                $st_args['mt_slug'] = $mtpg->message_type();
575
-                $st_args['messenger_slug'] = $this->name;
576
-                $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');
577
-                // 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).
578
-                $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">' . __('Create New Custom', 'event_espresso') . '</a>';
579
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
580
-                $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">' . __('Edit', 'event_espresso') . '</a>' : '';
581
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
582
-            }
583
-        }
584
-
585
-        // if no selectors present then get out.
586
-        if (empty($selector_rows)) {
587
-            return '';
588
-        }
589
-
590
-        $template_args['selector_rows'] = $selector_rows;
591
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
592
-    }
593
-
594
-
595
-
596
-
597
-
598
-
599
-    /**
600
-     * get_template_fields
601
-     *
602
-     * @access public
603
-     * @return array $this->_template_fields
604
-     */
605
-    public function get_template_fields()
606
-    {
607
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
608
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
609
-        return $template_fields;
610
-    }
611
-
612
-
613
-
614
-
615
-    /** SETUP METHODS **/
616
-    /**
617
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
618
-     * @param string $item
619
-     * @param mixed $value
620
-     */
621
-    protected function _set_template_value($item, $value)
622
-    {
623
-        if (array_key_exists($item, $this->_template_fields)) {
624
-            $prop = '_' . $item;
625
-            $this->{$prop} = $value;
626
-        }
627
-    }
628
-
629
-    /**
630
-     * Sets up the message for sending.
631
-     *
632
-     * @param  EE_message $message the message object that contains details about the message.
633
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
634
-     *
635
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
636
-     *              added to EE_Error.
637
-     *              true = message sent successfully
638
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
639
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
640
-     *
641
-     * @throws SendMessageException
642
-     */
643
-    final public function send_message($message, EE_message_type $message_type)
644
-    {
645
-        try {
646
-            $this->_validate_and_setup($message);
647
-            $this->_incoming_message_type = $message_type;
648
-            $response = $this->_send_message();
649
-            if ($response instanceof WP_Error) {
650
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
651
-                $response = false;
652
-            }
653
-        } catch (\Exception $e) {
654
-            // convert to an instance of SendMessageException
655
-            throw new SendMessageException($e->getMessage());
656
-        }
657
-        return $response;
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     * Sets up and returns message preview
664
-     * @param  EE_Message $message incoming message object
665
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
666
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
667
-     * @return string          return the message html content
668
-     */
669
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
670
-    {
671
-        $this->_validate_and_setup($message);
672
-
673
-        $this->_incoming_message_type = $message_type;
674
-
675
-        if ($send) {
676
-            // are we overriding any existing template fields?
677
-            $settings = apply_filters(
678
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
679
-                $this->get_existing_test_settings(),
680
-                $this,
681
-                $send,
682
-                $message,
683
-                $message_type
684
-            );
685
-            if (! empty($settings)) {
686
-                foreach ($settings as $field => $value) {
687
-                    $this->_set_template_value($field, $value);
688
-                }
689
-            }
690
-        }
691
-
692
-        // enqueue preview js so that any links/buttons on the page are disabled.
693
-        if (! $send) {
694
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
695
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
696
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
698
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
699
-        }
700
-
701
-        return $send ? $this->_send_message() : $this->_preview();
702
-    }
703
-
704
-
705
-
706
-
707
-    /**
708
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
709
-     *
710
-     * @since 4.5.0
711
-     *
712
-     * @return void
713
-     */
714
-    public function add_preview_script()
715
-    {
716
-        // error message
717
-        EE_Registry::$i18n_js_strings['links_disabled'] = __('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');
718
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
719
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
720
-        wp_enqueue_script('ee-messages-preview-js');
721
-    }
722
-
723
-
724
-
725
-
726
-    /**
727
-     * simply validates the incoming message object and then sets up the properties for the messenger
728
-     * @param  EE_Message $message
729
-     * @throws EE_Error
730
-     */
731
-    protected function _validate_and_setup(EE_Message $message)
732
-    {
733
-        $template_pack = $message->get_template_pack();
734
-        $variation = $message->get_template_pack_variation();
735
-
736
-        // verify we have the required template pack value on the $message object.
737
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
738
-            throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
739
-        }
740
-
741
-        $this->_tmp_pack = $template_pack;
742
-
743
-        $this->_variation = $variation ? $variation : 'default';
744
-
745
-        $template_fields = $this->get_template_fields();
746
-
747
-        foreach ($template_fields as $template => $value) {
748
-            if ($template !== 'extra') {
749
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
750
-                $message_template_value = $column_value ? $column_value : null;
751
-                $this->_set_template_value($template, $message_template_value);
752
-            }
753
-        }
754
-    }
755
-
756
-
757
-
758
-    /**
759
-     * Utility method for child classes to get the contents of a template file and return
760
-     *
761
-     * We're assuming the child messenger class has already setup template args!
762
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
763
-     * @return string
764
-     * @throws \EE_Error
765
-     */
766
-    protected function _get_main_template($preview = false)
767
-    {
768
-        $type = $preview ? 'preview' : 'main';
769
-
770
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
771
-
772
-        // check file exists and is readable
773
-        if (!is_readable($wrapper_template)) {
774
-            throw new EE_Error(sprintf(__('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));
775
-        }
776
-
777
-        // add message type to template args
778
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
779
-
780
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
781
-    }
782
-
783
-
784
-
785
-    /**
786
-     * set the _test_settings_fields property
787
-     *
788
-     * @access protected
789
-     * @return void
790
-     */
791
-    protected function _set_test_settings_fields()
792
-    {
793
-        $this->_test_settings_fields = array();
794
-    }
795
-
796
-
797
-
798
-    /**
799
-     * return the _test_settings_fields property
800
-     * @return array
801
-     */
802
-    public function get_test_settings_fields()
803
-    {
804
-        return $this->_test_settings_fields;
805
-    }
806
-
807
-
808
-
809
-
810
-    /**
811
-     * This just returns any existing test settings that might be saved in the database
812
-     *
813
-     * @access public
814
-     * @return array
815
-     */
816
-    public function get_existing_test_settings()
817
-    {
818
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
819
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
820
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
821
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
822
-    }
823
-
824
-
825
-
826
-    /**
827
-     * All this does is set the existing test settings (in the db) for the messenger
828
-     *
829
-     * @access public
830
-     * @param $settings
831
-     * @return bool success/fail
832
-     */
833
-    public function set_existing_test_settings($settings)
834
-    {
835
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
836
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
837
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
838
-        $existing[ $this->name ]['test_settings'] = $settings;
839
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     * This just returns the field label for a given field setup in the _template_fields property.
846
-     *
847
-     * @since   4.3.0
848
-     *
849
-     * @param string $field The field to retrieve the label for
850
-     * @return string             The label
851
-     */
852
-    public function get_field_label($field)
853
-    {
854
-        // first let's see if the field requests is in the top level array.
855
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
856
-            return $this->_template[ $field ]['label'];
857
-        }
858
-
859
-        // 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.
860
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
861
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
862
-        }
863
-
864
-        // now it's possible this field may just be existing in any of the extra array items.
865
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
866
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
867
-                if (!is_array($subfields)) {
868
-                    continue;
869
-                }
870
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
871
-                    return $subfields[ $field ]['label'];
872
-                }
873
-            }
874
-        }
875
-
876
-        // if we made it here then there's no label set so let's just return the $field.
877
-        return $field;
878
-    }
879
-
880
-
881
-
882
-
883
-    /**
884
-     * 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).
885
-     *
886
-     * @since 4.5.0
887
-     *
888
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
889
-     *
890
-     * @return void
891
-     */
892
-    public function do_secondary_messenger_hooks($sending_messenger_name)
893
-    {
894
-        return;
895
-    }
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 ] = __('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
+				$edit_url_query_args = [
561
+					'page' => 'espresso_messages',
562
+					'action' => 'edit_message_template',
563
+					'id' => $default_value,
564
+					'evt_id' => $event_id
565
+				];
566
+				$edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
567
+				$create_url_query_args = [
568
+					'page' => 'espresso_messages',
569
+					'action' => 'add_new_message_template',
570
+					'GRP_ID' => $default_value
571
+				];
572
+				$create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
573
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
574
+				$st_args['mt_slug'] = $mtpg->message_type();
575
+				$st_args['messenger_slug'] = $this->name;
576
+				$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');
577
+				// 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).
578
+				$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">' . __('Create New Custom', 'event_espresso') . '</a>';
579
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
580
+				$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">' . __('Edit', 'event_espresso') . '</a>' : '';
581
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
582
+			}
583
+		}
584
+
585
+		// if no selectors present then get out.
586
+		if (empty($selector_rows)) {
587
+			return '';
588
+		}
589
+
590
+		$template_args['selector_rows'] = $selector_rows;
591
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
592
+	}
593
+
594
+
595
+
596
+
597
+
598
+
599
+	/**
600
+	 * get_template_fields
601
+	 *
602
+	 * @access public
603
+	 * @return array $this->_template_fields
604
+	 */
605
+	public function get_template_fields()
606
+	{
607
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
608
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
609
+		return $template_fields;
610
+	}
611
+
612
+
613
+
614
+
615
+	/** SETUP METHODS **/
616
+	/**
617
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
618
+	 * @param string $item
619
+	 * @param mixed $value
620
+	 */
621
+	protected function _set_template_value($item, $value)
622
+	{
623
+		if (array_key_exists($item, $this->_template_fields)) {
624
+			$prop = '_' . $item;
625
+			$this->{$prop} = $value;
626
+		}
627
+	}
628
+
629
+	/**
630
+	 * Sets up the message for sending.
631
+	 *
632
+	 * @param  EE_message $message the message object that contains details about the message.
633
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
634
+	 *
635
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
636
+	 *              added to EE_Error.
637
+	 *              true = message sent successfully
638
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
639
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
640
+	 *
641
+	 * @throws SendMessageException
642
+	 */
643
+	final public function send_message($message, EE_message_type $message_type)
644
+	{
645
+		try {
646
+			$this->_validate_and_setup($message);
647
+			$this->_incoming_message_type = $message_type;
648
+			$response = $this->_send_message();
649
+			if ($response instanceof WP_Error) {
650
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
651
+				$response = false;
652
+			}
653
+		} catch (\Exception $e) {
654
+			// convert to an instance of SendMessageException
655
+			throw new SendMessageException($e->getMessage());
656
+		}
657
+		return $response;
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 * Sets up and returns message preview
664
+	 * @param  EE_Message $message incoming message object
665
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
666
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
667
+	 * @return string          return the message html content
668
+	 */
669
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
670
+	{
671
+		$this->_validate_and_setup($message);
672
+
673
+		$this->_incoming_message_type = $message_type;
674
+
675
+		if ($send) {
676
+			// are we overriding any existing template fields?
677
+			$settings = apply_filters(
678
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
679
+				$this->get_existing_test_settings(),
680
+				$this,
681
+				$send,
682
+				$message,
683
+				$message_type
684
+			);
685
+			if (! empty($settings)) {
686
+				foreach ($settings as $field => $value) {
687
+					$this->_set_template_value($field, $value);
688
+				}
689
+			}
690
+		}
691
+
692
+		// enqueue preview js so that any links/buttons on the page are disabled.
693
+		if (! $send) {
694
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
695
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
696
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
698
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
699
+		}
700
+
701
+		return $send ? $this->_send_message() : $this->_preview();
702
+	}
703
+
704
+
705
+
706
+
707
+	/**
708
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
709
+	 *
710
+	 * @since 4.5.0
711
+	 *
712
+	 * @return void
713
+	 */
714
+	public function add_preview_script()
715
+	{
716
+		// error message
717
+		EE_Registry::$i18n_js_strings['links_disabled'] = __('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');
718
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
719
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
720
+		wp_enqueue_script('ee-messages-preview-js');
721
+	}
722
+
723
+
724
+
725
+
726
+	/**
727
+	 * simply validates the incoming message object and then sets up the properties for the messenger
728
+	 * @param  EE_Message $message
729
+	 * @throws EE_Error
730
+	 */
731
+	protected function _validate_and_setup(EE_Message $message)
732
+	{
733
+		$template_pack = $message->get_template_pack();
734
+		$variation = $message->get_template_pack_variation();
735
+
736
+		// verify we have the required template pack value on the $message object.
737
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
738
+			throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
739
+		}
740
+
741
+		$this->_tmp_pack = $template_pack;
742
+
743
+		$this->_variation = $variation ? $variation : 'default';
744
+
745
+		$template_fields = $this->get_template_fields();
746
+
747
+		foreach ($template_fields as $template => $value) {
748
+			if ($template !== 'extra') {
749
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
750
+				$message_template_value = $column_value ? $column_value : null;
751
+				$this->_set_template_value($template, $message_template_value);
752
+			}
753
+		}
754
+	}
755
+
756
+
757
+
758
+	/**
759
+	 * Utility method for child classes to get the contents of a template file and return
760
+	 *
761
+	 * We're assuming the child messenger class has already setup template args!
762
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
763
+	 * @return string
764
+	 * @throws \EE_Error
765
+	 */
766
+	protected function _get_main_template($preview = false)
767
+	{
768
+		$type = $preview ? 'preview' : 'main';
769
+
770
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
771
+
772
+		// check file exists and is readable
773
+		if (!is_readable($wrapper_template)) {
774
+			throw new EE_Error(sprintf(__('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));
775
+		}
776
+
777
+		// add message type to template args
778
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
779
+
780
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
781
+	}
782
+
783
+
784
+
785
+	/**
786
+	 * set the _test_settings_fields property
787
+	 *
788
+	 * @access protected
789
+	 * @return void
790
+	 */
791
+	protected function _set_test_settings_fields()
792
+	{
793
+		$this->_test_settings_fields = array();
794
+	}
795
+
796
+
797
+
798
+	/**
799
+	 * return the _test_settings_fields property
800
+	 * @return array
801
+	 */
802
+	public function get_test_settings_fields()
803
+	{
804
+		return $this->_test_settings_fields;
805
+	}
806
+
807
+
808
+
809
+
810
+	/**
811
+	 * This just returns any existing test settings that might be saved in the database
812
+	 *
813
+	 * @access public
814
+	 * @return array
815
+	 */
816
+	public function get_existing_test_settings()
817
+	{
818
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
819
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
820
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
821
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
822
+	}
823
+
824
+
825
+
826
+	/**
827
+	 * All this does is set the existing test settings (in the db) for the messenger
828
+	 *
829
+	 * @access public
830
+	 * @param $settings
831
+	 * @return bool success/fail
832
+	 */
833
+	public function set_existing_test_settings($settings)
834
+	{
835
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
836
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
837
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
838
+		$existing[ $this->name ]['test_settings'] = $settings;
839
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 * This just returns the field label for a given field setup in the _template_fields property.
846
+	 *
847
+	 * @since   4.3.0
848
+	 *
849
+	 * @param string $field The field to retrieve the label for
850
+	 * @return string             The label
851
+	 */
852
+	public function get_field_label($field)
853
+	{
854
+		// first let's see if the field requests is in the top level array.
855
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
856
+			return $this->_template[ $field ]['label'];
857
+		}
858
+
859
+		// 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.
860
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
861
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
862
+		}
863
+
864
+		// now it's possible this field may just be existing in any of the extra array items.
865
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
866
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
867
+				if (!is_array($subfields)) {
868
+					continue;
869
+				}
870
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
871
+					return $subfields[ $field ]['label'];
872
+				}
873
+			}
874
+		}
875
+
876
+		// if we made it here then there's no label set so let's just return the $field.
877
+		return $field;
878
+	}
879
+
880
+
881
+
882
+
883
+	/**
884
+	 * 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).
885
+	 *
886
+	 * @since 4.5.0
887
+	 *
888
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
889
+	 *
890
+	 * @return void
891
+	 */
892
+	public function do_secondary_messenger_hooks($sending_messenger_name)
893
+	{
894
+		return;
895
+	}
896 896
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
         $class = get_class($this);
419 419
 
420 420
         // messenger specific filter
421
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
421
+        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
422 422
 
423 423
         // all messengers filter
424 424
         $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 
442 442
         // messenger specific filter
443 443
         // messenger specific filter
444
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
+        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
445 445
 
446 446
         // all messengers filter
447 447
         $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
     {
477 477
         $class = get_class($this);
478 478
 
479
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
+        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
480 480
         $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
481 481
         return $config;
482 482
     }
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 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 516
         $event_id = isset($extra['event']) ? $extra['event'] : null;
517 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';
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 520
 
521 521
         // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
522 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 ) )
523
+            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
524 524
         );
525 525
         $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
526 526
             $event_id,
@@ -529,29 +529,29 @@  discard block
 block discarded – undo
529 529
                 'MTP_is_active' => true
530 530
             )
531 531
         );
532
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
+        $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
533 533
 
534 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 535
         foreach ($global_templates as $mtpgID => $mtpg) {
536 536
             if ($mtpg instanceof EE_Message_Template_Group) {
537 537
                 // verify this message type is supposed to show on this page
538 538
                 $mtp_obj = $mtpg->message_type_obj();
539
-                if (! $mtp_obj instanceof EE_message_type) {
539
+                if ( ! $mtp_obj instanceof EE_message_type) {
540 540
                     continue;
541 541
                 }
542 542
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
543
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
544 544
                     continue;
545 545
                 }
546 546
                 $select_values = array();
547
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
+                $select_values[$mtpgID] = __('Global', 'event_espresso');
548 548
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
549 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')) {
550
+                if ( ! $mtpg->get('MTP_is_override')) {
551 551
                     // any custom templates for this message type?
552 552
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
553 553
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
554
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
554
+                        $select_values[$cmtpgID] = $cmtpg->name();
555 555
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
556 556
                     }
557 557
                 }
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
574 574
                 $st_args['mt_slug'] = $mtpg->message_type();
575 575
                 $st_args['messenger_slug'] = $this->name;
576
-                $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');
576
+                $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');
577 577
                 // 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).
578
-                $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">' . __('Create New Custom', 'event_espresso') . '</a>';
578
+                $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">'.__('Create New Custom', 'event_espresso').'</a>';
579 579
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
580
-                $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">' . __('Edit', 'event_espresso') . '</a>' : '';
580
+                $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">'.__('Edit', 'event_espresso').'</a>' : '';
581 581
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
582 582
             }
583 583
         }
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
      */
605 605
     public function get_template_fields()
606 606
     {
607
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
607
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
608 608
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
609 609
         return $template_fields;
610 610
     }
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
     protected function _set_template_value($item, $value)
622 622
     {
623 623
         if (array_key_exists($item, $this->_template_fields)) {
624
-            $prop = '_' . $item;
624
+            $prop = '_'.$item;
625 625
             $this->{$prop} = $value;
626 626
         }
627 627
     }
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                 $message,
683 683
                 $message_type
684 684
             );
685
-            if (! empty($settings)) {
685
+            if ( ! empty($settings)) {
686 686
                 foreach ($settings as $field => $value) {
687 687
                     $this->_set_template_value($field, $value);
688 688
                 }
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
         }
691 691
 
692 692
         // enqueue preview js so that any links/buttons on the page are disabled.
693
-        if (! $send) {
693
+        if ( ! $send) {
694 694
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
695 695
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
696
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
698
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
696
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
697
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
698
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
699 699
         }
700 700
 
701 701
         return $send ? $this->_send_message() : $this->_preview();
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
     {
716 716
         // error message
717 717
         EE_Registry::$i18n_js_strings['links_disabled'] = __('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');
718
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
718
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
719 719
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
720 720
         wp_enqueue_script('ee-messages-preview-js');
721 721
     }
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
         $variation = $message->get_template_pack_variation();
735 735
 
736 736
         // verify we have the required template pack value on the $message object.
737
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
737
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
738 738
             throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
739 739
         }
740 740
 
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 
747 747
         foreach ($template_fields as $template => $value) {
748 748
             if ($template !== 'extra') {
749
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
749
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
750 750
                 $message_template_value = $column_value ? $column_value : null;
751 751
                 $this->_set_template_value($template, $message_template_value);
752 752
             }
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
771 771
 
772 772
         // check file exists and is readable
773
-        if (!is_readable($wrapper_template)) {
773
+        if ( ! is_readable($wrapper_template)) {
774 774
             throw new EE_Error(sprintf(__('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));
775 775
         }
776 776
 
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
819 819
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
820 820
         $settings = $Message_Resource_Manager->get_active_messengers_option();
821
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
821
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
822 822
     }
823 823
 
824 824
 
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
836 836
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
837 837
         $existing = $Message_Resource_Manager->get_active_messengers_option();
838
-        $existing[ $this->name ]['test_settings'] = $settings;
838
+        $existing[$this->name]['test_settings'] = $settings;
839 839
         return $Message_Resource_Manager->update_active_messengers_option($existing);
840 840
     }
841 841
 
@@ -852,23 +852,23 @@  discard block
 block discarded – undo
852 852
     public function get_field_label($field)
853 853
     {
854 854
         // first let's see if the field requests is in the top level array.
855
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
856
-            return $this->_template[ $field ]['label'];
855
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
856
+            return $this->_template[$field]['label'];
857 857
         }
858 858
 
859 859
         // 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.
860
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
861
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
860
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
861
+            return $this->_template_fields['extra'][$field]['main']['label'];
862 862
         }
863 863
 
864 864
         // now it's possible this field may just be existing in any of the extra array items.
865
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
865
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
866 866
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
867
-                if (!is_array($subfields)) {
867
+                if ( ! is_array($subfields)) {
868 868
                     continue;
869 869
                 }
870
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
871
-                    return $subfields[ $field ]['label'];
870
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
871
+                    return $subfields[$field]['label'];
872 872
                 }
873 873
             }
874 874
         }
Please login to merge, or discard this patch.
core/libraries/qtips/EE_Qtip_Config.lib.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -238,7 +238,7 @@
 block discarded – undo
238 238
      * return the _qtips property contents
239 239
      *
240 240
      * @access public
241
-     * @return EE_Qtip[]
241
+     * @return EE_Qtip
242 242
      */
243 243
     public function get_tips()
244 244
     {
Please login to merge, or discard this patch.
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -15,235 +15,235 @@  discard block
 block discarded – undo
15 15
 abstract class EE_Qtip_Config extends EE_Base
16 16
 {
17 17
 
18
-    /**
19
-     * This will hold the qtips setup array (setup by children)
20
-     *
21
-     * @access protected
22
-     * @var array
23
-     */
24
-    protected $_qtipsa;
18
+	/**
19
+	 * This will hold the qtips setup array (setup by children)
20
+	 *
21
+	 * @access protected
22
+	 * @var array
23
+	 */
24
+	protected $_qtipsa;
25 25
 
26 26
 
27
-    /**
28
-     * This holds the constructed EE_Qtip objects
29
-     *
30
-     * @access protected
31
-     * @var EE_Qtip
32
-     */
33
-    protected $_qtips;
27
+	/**
28
+	 * This holds the constructed EE_Qtip objects
29
+	 *
30
+	 * @access protected
31
+	 * @var EE_Qtip
32
+	 */
33
+	protected $_qtips;
34 34
 
35 35
 
36
-    /**
37
-     * an array of default options for instantiated qtip js objects
38
-     *
39
-     * @access protected
40
-     * @var array
41
-     */
42
-    protected $_default_options;
36
+	/**
37
+	 * an array of default options for instantiated qtip js objects
38
+	 *
39
+	 * @access protected
40
+	 * @var array
41
+	 */
42
+	protected $_default_options;
43 43
 
44 44
 
45
-    /**
46
-     * constructor
47
-     *
48
-     * @access public
49
-     */
50
-    public function __construct()
51
-    {
52
-        $this->_qtipsa = $this->_qtips = array();
53
-        $this->_set_default_options();
54
-        $this->_set_tips_array();
55
-        $this->_construct_tips();
56
-    }
45
+	/**
46
+	 * constructor
47
+	 *
48
+	 * @access public
49
+	 */
50
+	public function __construct()
51
+	{
52
+		$this->_qtipsa = $this->_qtips = array();
53
+		$this->_set_default_options();
54
+		$this->_set_tips_array();
55
+		$this->_construct_tips();
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * Children define this method and its purpose is to setup the $_qtipsa property.  The format of this property is:
61
-     *
62
-     * $qtipsa = array(
63
-     *        0 => array(
64
-     *            'content_id' => 'some_unique_id_for_referencing_content', //just the string
65
-     *            'content' => 'html/text content for the qtip',
66
-     *            'target' => '#target-element', //use the same schema as jQuery selectors.  This will match what the
67
-     *            target is for the qTip in the dom (i.e. if class then '.some-class').
68
-     *            'options' => array() //use this to override any of the default options for this specific qtip.
69
-     *        )
70
-     * );
71
-     *
72
-     * @abstract
73
-     * @access protected
74
-     * @return void
75
-     */
76
-    abstract protected function _set_tips_array();
59
+	/**
60
+	 * Children define this method and its purpose is to setup the $_qtipsa property.  The format of this property is:
61
+	 *
62
+	 * $qtipsa = array(
63
+	 *        0 => array(
64
+	 *            'content_id' => 'some_unique_id_for_referencing_content', //just the string
65
+	 *            'content' => 'html/text content for the qtip',
66
+	 *            'target' => '#target-element', //use the same schema as jQuery selectors.  This will match what the
67
+	 *            target is for the qTip in the dom (i.e. if class then '.some-class').
68
+	 *            'options' => array() //use this to override any of the default options for this specific qtip.
69
+	 *        )
70
+	 * );
71
+	 *
72
+	 * @abstract
73
+	 * @access protected
74
+	 * @return void
75
+	 */
76
+	abstract protected function _set_tips_array();
77 77
 
78 78
 
79
-    /**
80
-     * all the default options for the qtip js are defined here.  Children class can override the defaults for all the
81
-     * qtips defined in their config OR just leave it and have the parent default options apply.
82
-     *
83
-     * commented out options are there for reference so you know which can be defined by the child.
84
-     *
85
-     * Note: children do NOT have to define all these options.  Just define the ones to override.
86
-     *
87
-     * @link   http://qtip2.com/options
88
-     *
89
-     * @access protected
90
-     * @return void
91
-     */
92
-    protected function _set_default_options()
93
-    {
94
-        $this->_default_options = array(
95
-            // 'id' => 'unique_id_referncing_qtip_instance',
96
-            'prerender'      => false,
97
-            // increases page load if true,
98
-            'suppress'       => true,
99
-            // whether default browser tooltips are suppressed.
100
-            'content'        => array(
101
-                'button' => false,
102
-                // what you want for the close button text/link.
103
-                'title'  => true,
104
-                // Options: "string", true.  If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title.
105
-                'clone'  => true,
106
-                // Options: true|false.  if true then the text will be cloned from the content instead of removed from the dom.
107
-            ),
108
-            'show_only_once' => false,
109
-            // this is NOT a qtip2 library option, but is something added for EE specific use.  If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit).
110
-            'position'       => array(
111
-                'my'        => 'top left',
112
-                // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top
113
-                'at'        => 'bottom right',
114
-                // same options as above.
115
-                'target'    => 'event',
116
-                // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page.
117
-                'container' => false,
118
-                // what HTML element the tooltip is appended to (it's containing element). jquery object.  Use 'jQuery::#selector' and js will parse'
119
-                'viewport'  => true,
120
-                // @link http://qtip2.com/plugins#viewport
121
-                'adjust'    => array(
122
-                    'x'      => 0,
123
-                    // adjust position on x axis by 0 pixels.
124
-                    'y'      => 0,
125
-                    // adjust position on y axis by 0 pixels.
126
-                    'mouse'  => true,
127
-                    // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target.  False, stops following.
128
-                    'resize' => true,
129
-                    // adjust tooltip position when window is resized.
130
-                    'scroll' => true,
131
-                    // position of tooltip adjusted when window (or position.container) is scrolled.
132
-                    'method' => 'flipinvert',
133
-                    // @link http://qtip2.com/plugins#viewport
134
-                ),
135
-            ),
136
-            'show'           => array(
137
-                'event'  => 'mouseenter',
138
-                // what event triggers tooltip to be shown.  Any jQuery standard event or custom events can be used. space separated events provide multiple triggers.
139
-                'target' => false,
140
-                // options jQuery::#selector|false.  Used to indicate which html element will trigger show event.  When false, the element the qtip() method was called upon is used.
141
-                'delay'  => 90,
142
-                // time in millisecons by which to delay showing of tooltip.
143
-                'solo'   => false,
144
-                // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden)
145
-                'modal'  => array(
146
-                    'on'         => false, // does tooltip trigger modal?
147
-                    'blur'       => true, // does clicking on the dimmed background hide the tooltip and remove the dim?
148
-                    'escape'     => true, // hitting escape key hide the tooltip and cancel modal
149
-                    'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on?
150
-                ),
151
-            ),
152
-            'hide'           => array(
153
-                'event'    => 'mouseleave',
154
-                // similar as what you do for show.event.
155
-                'target'   => false,
156
-                // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used.
157
-                'delay'    => 0,
158
-                // set time in milliseconds for delaying the hide of the tooltip
159
-                'inactive' => false,
160
-                // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with)
161
-                'fixed'    => false,
162
-                // when set to true, the tooltip will not hide if moused over.
163
-                'leave'    => 'window',
164
-                // specify whether the tooltip will hide when leaving the window it's conained within.
165
-                'distance' => false,
166
-                // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip.
167
-            ),
168
-            'style'          => array(
169
-                'classes' => 'qtip-tipsy',
170
-                // Options "string", false.  A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class.
171
-                'def'     => true,
172
-                // set to false and the default qtip class does not get applied
173
-                'widget'  => false,
174
-                // whether ui-widget classes of the themeroller UI styles are applied to tooltip.
175
-                'width'   => false,
176
-                // Options: "string", integer, false.  with this you can override all applied CSS width styles for tooltip.  Can be any valid width CSS value. (does not override min/max width styles)
177
-                'height'  => false,
178
-                // same as above except applies to height.
179
-                'tip'     => array(
180
-                    'corner' => true,
181
-                    // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false.  true inherits
182
-                    'mimic'  => false,
183
-                    // see documentation @link http://qtip2.com/plugins#tips
184
-                    'border' => true,
185
-                    // Options: true, integer. determines the width of the border that surrounds the tip element.  True inherits from tooltip.
186
-                    'width'  => 6,
187
-                    // width of rendered tip in pixels in relation to the side of the tooltip the tip is on.
188
-                    'height' => 6,
189
-                    // works the same as tip.width
190
-                    'offset' => 0,
191
-                    // use to set the offset of the tip in relation to its corner position.
192
-                ),
193
-            ),
79
+	/**
80
+	 * all the default options for the qtip js are defined here.  Children class can override the defaults for all the
81
+	 * qtips defined in their config OR just leave it and have the parent default options apply.
82
+	 *
83
+	 * commented out options are there for reference so you know which can be defined by the child.
84
+	 *
85
+	 * Note: children do NOT have to define all these options.  Just define the ones to override.
86
+	 *
87
+	 * @link   http://qtip2.com/options
88
+	 *
89
+	 * @access protected
90
+	 * @return void
91
+	 */
92
+	protected function _set_default_options()
93
+	{
94
+		$this->_default_options = array(
95
+			// 'id' => 'unique_id_referncing_qtip_instance',
96
+			'prerender'      => false,
97
+			// increases page load if true,
98
+			'suppress'       => true,
99
+			// whether default browser tooltips are suppressed.
100
+			'content'        => array(
101
+				'button' => false,
102
+				// what you want for the close button text/link.
103
+				'title'  => true,
104
+				// Options: "string", true.  If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title.
105
+				'clone'  => true,
106
+				// Options: true|false.  if true then the text will be cloned from the content instead of removed from the dom.
107
+			),
108
+			'show_only_once' => false,
109
+			// this is NOT a qtip2 library option, but is something added for EE specific use.  If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit).
110
+			'position'       => array(
111
+				'my'        => 'top left',
112
+				// top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top
113
+				'at'        => 'bottom right',
114
+				// same options as above.
115
+				'target'    => 'event',
116
+				// if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page.
117
+				'container' => false,
118
+				// what HTML element the tooltip is appended to (it's containing element). jquery object.  Use 'jQuery::#selector' and js will parse'
119
+				'viewport'  => true,
120
+				// @link http://qtip2.com/plugins#viewport
121
+				'adjust'    => array(
122
+					'x'      => 0,
123
+					// adjust position on x axis by 0 pixels.
124
+					'y'      => 0,
125
+					// adjust position on y axis by 0 pixels.
126
+					'mouse'  => true,
127
+					// when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target.  False, stops following.
128
+					'resize' => true,
129
+					// adjust tooltip position when window is resized.
130
+					'scroll' => true,
131
+					// position of tooltip adjusted when window (or position.container) is scrolled.
132
+					'method' => 'flipinvert',
133
+					// @link http://qtip2.com/plugins#viewport
134
+				),
135
+			),
136
+			'show'           => array(
137
+				'event'  => 'mouseenter',
138
+				// what event triggers tooltip to be shown.  Any jQuery standard event or custom events can be used. space separated events provide multiple triggers.
139
+				'target' => false,
140
+				// options jQuery::#selector|false.  Used to indicate which html element will trigger show event.  When false, the element the qtip() method was called upon is used.
141
+				'delay'  => 90,
142
+				// time in millisecons by which to delay showing of tooltip.
143
+				'solo'   => false,
144
+				// determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden)
145
+				'modal'  => array(
146
+					'on'         => false, // does tooltip trigger modal?
147
+					'blur'       => true, // does clicking on the dimmed background hide the tooltip and remove the dim?
148
+					'escape'     => true, // hitting escape key hide the tooltip and cancel modal
149
+					'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on?
150
+				),
151
+			),
152
+			'hide'           => array(
153
+				'event'    => 'mouseleave',
154
+				// similar as what you do for show.event.
155
+				'target'   => false,
156
+				// Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used.
157
+				'delay'    => 0,
158
+				// set time in milliseconds for delaying the hide of the tooltip
159
+				'inactive' => false,
160
+				// if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with)
161
+				'fixed'    => false,
162
+				// when set to true, the tooltip will not hide if moused over.
163
+				'leave'    => 'window',
164
+				// specify whether the tooltip will hide when leaving the window it's conained within.
165
+				'distance' => false,
166
+				// if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip.
167
+			),
168
+			'style'          => array(
169
+				'classes' => 'qtip-tipsy',
170
+				// Options "string", false.  A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class.
171
+				'def'     => true,
172
+				// set to false and the default qtip class does not get applied
173
+				'widget'  => false,
174
+				// whether ui-widget classes of the themeroller UI styles are applied to tooltip.
175
+				'width'   => false,
176
+				// Options: "string", integer, false.  with this you can override all applied CSS width styles for tooltip.  Can be any valid width CSS value. (does not override min/max width styles)
177
+				'height'  => false,
178
+				// same as above except applies to height.
179
+				'tip'     => array(
180
+					'corner' => true,
181
+					// where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false.  true inherits
182
+					'mimic'  => false,
183
+					// see documentation @link http://qtip2.com/plugins#tips
184
+					'border' => true,
185
+					// Options: true, integer. determines the width of the border that surrounds the tip element.  True inherits from tooltip.
186
+					'width'  => 6,
187
+					// width of rendered tip in pixels in relation to the side of the tooltip the tip is on.
188
+					'height' => 6,
189
+					// works the same as tip.width
190
+					'offset' => 0,
191
+					// use to set the offset of the tip in relation to its corner position.
192
+				),
193
+			),
194 194
 
195
-        );
196
-    }
195
+		);
196
+	}
197 197
 
198 198
 
199
-    /**
200
-     * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to
201
-     * the $_qtips property
202
-     *
203
-     * @access protected
204
-     * @return void
205
-     */
206
-    protected function _construct_tips()
207
-    {
208
-        foreach ($this->_qtipsa as $qt) {
209
-            // make sure we have what we need.
210
-            if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
211
-                throw new EE_Error(
212
-                    sprintf(
213
-                        __(
214
-                            'There is something wrong with the _qtipsa property setup for the %s qtip config class.  The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.',
215
-                            'event_espresso'
216
-                        ),
217
-                        get_class($this),
218
-                        var_export($qt, true)
219
-                    )
220
-                );
221
-            }
199
+	/**
200
+	 * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to
201
+	 * the $_qtips property
202
+	 *
203
+	 * @access protected
204
+	 * @return void
205
+	 */
206
+	protected function _construct_tips()
207
+	{
208
+		foreach ($this->_qtipsa as $qt) {
209
+			// make sure we have what we need.
210
+			if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
211
+				throw new EE_Error(
212
+					sprintf(
213
+						__(
214
+							'There is something wrong with the _qtipsa property setup for the %s qtip config class.  The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.',
215
+							'event_espresso'
216
+						),
217
+						get_class($this),
218
+						var_export($qt, true)
219
+					)
220
+				);
221
+			}
222 222
 
223
-            // make sure the options include defaults and just override via set config.
224
-            $options_override = isset($qt['options']) ? (array) $qt['options'] : array();
225
-            $options = array_merge($this->_default_options, $options_override);
226
-            $setup = array(
227
-                'content_id' => $qt['content_id'],
228
-                'options'    => $options,
229
-                'target'     => $qt['target'],
230
-                'content'    => $qt['content'],
231
-            );
232
-            $this->_qtips[] = new EE_Qtip($setup);
233
-        }
234
-    }
223
+			// make sure the options include defaults and just override via set config.
224
+			$options_override = isset($qt['options']) ? (array) $qt['options'] : array();
225
+			$options = array_merge($this->_default_options, $options_override);
226
+			$setup = array(
227
+				'content_id' => $qt['content_id'],
228
+				'options'    => $options,
229
+				'target'     => $qt['target'],
230
+				'content'    => $qt['content'],
231
+			);
232
+			$this->_qtips[] = new EE_Qtip($setup);
233
+		}
234
+	}
235 235
 
236 236
 
237
-    /**
238
-     * return the _qtips property contents
239
-     *
240
-     * @access public
241
-     * @return EE_Qtip[]
242
-     */
243
-    public function get_tips()
244
-    {
245
-        return $this->_qtips;
246
-    }
237
+	/**
238
+	 * return the _qtips property contents
239
+	 *
240
+	 * @access public
241
+	 * @return EE_Qtip[]
242
+	 */
243
+	public function get_tips()
244
+	{
245
+		return $this->_qtips;
246
+	}
247 247
 }
248 248
 
249 249
 // class names you can use for tooltip styles
@@ -295,17 +295,17 @@  discard block
 block discarded – undo
295 295
  */
296 296
 class EE_Qtip extends EE_Base
297 297
 {
298
-    public $content_id;
299
-    public $options;
300
-    public $target;
301
-    public $content;
298
+	public $content_id;
299
+	public $options;
300
+	public $target;
301
+	public $content;
302 302
 
303
-    public function __construct($setup_array)
304
-    {
305
-        foreach ($setup_array as $prop => $value) {
306
-            if (EEH_Class_Tools::has_property($this, $prop)) {
307
-                $this->{$prop} = $value;
308
-            }
309
-        }
310
-    }
303
+	public function __construct($setup_array)
304
+	{
305
+		foreach ($setup_array as $prop => $value) {
306
+			if (EEH_Class_Tools::has_property($this, $prop)) {
307
+				$this->{$prop} = $value;
308
+			}
309
+		}
310
+	}
311 311
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -207,7 +207,7 @@
 block discarded – undo
207 207
     {
208 208
         foreach ($this->_qtipsa as $qt) {
209 209
             // make sure we have what we need.
210
-            if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
210
+            if ( ! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
211 211
                 throw new EE_Error(
212 212
                     sprintf(
213 213
                         __(
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Event_Shortcodes.lib.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -283,6 +283,7 @@
 block discarded – undo
283 283
      *
284 284
      * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
285 285
      *                            Otherwise we just return the url of the event.
286
+     * @param EE_Event $event
286 287
      * @return string
287 288
      */
288 289
     private function _get_event_link($event, $full_link = true)
Please login to merge, or discard this patch.
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -19,297 +19,297 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * Will hold the EE_Event if available
24
-     *
25
-     * @var EE_Event
26
-     */
27
-    protected $_event;
28
-
29
-
30
-    public function __construct()
31
-    {
32
-        parent::__construct();
33
-    }
34
-
35
-
36
-    protected function _init_props()
37
-    {
38
-        $this->label = __('Event Shortcodes', 'event_espresso');
39
-        $this->description = __('All shortcodes specific to event related data', 'event_espresso');
40
-        $this->_shortcodes = array(
41
-            '[EVENT_ID]'                              => __(
42
-                'Will be replaced by the event ID of an event',
43
-                'event_espresso'
44
-            ),
45
-            '[EVENT]'                                 => __('The name of the event', 'event_espresso'),
46
-            '[EVENT_NAME]'                            => __(
47
-                "This also can be used for the name of the event",
48
-                'event_espresso'
49
-            ),
50
-            '[EVENT_PHONE]'                           => __(
51
-                'The phone number for the event (usually an info number)',
52
-                'event_espresso'
53
-            ),
54
-            '[EVENT_DESCRIPTION]'                     => __('The description of the event', 'event_espresso'),
55
-            '[EVENT_EXCERPT]'                         => __(
56
-                'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.',
57
-                'event_espresso'
58
-            ),
59
-            '[EVENT_LINK]'                            => __('A link associated with the event', 'event_espresso'),
60
-            '[EVENT_URL]'                             => __(
61
-                'A link to the event set up on the host site.',
62
-                'event_espresso'
63
-            ),
64
-            '[VIRTUAL_URL]'                           => __(
65
-                'What was used for the "URL of Event" field in the Venue settings',
66
-                'event_espresso'
67
-            ),
68
-            '[VIRTUAL_PHONE]'                         => __(
69
-                'An alternate phone number for the event. Typically used as a "call-in" number',
70
-                'event_espresso'
71
-            ),
72
-            '[EVENT_IMAGE]'                           => __(
73
-                'This will parse to the Feature image for the event.',
74
-                'event_espresso'
75
-            ),
76
-            '[EVENT_IMAGE_*]'                         => sprintf(
77
-                __(
78
-                    'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.',
79
-                    'event_espresso'
80
-                ),
81
-                '<code>',
82
-                '</code>'
83
-            ),
84
-            '[EVENT_TOTAL_AVAILABLE_SPACES_*]'        => sprintf(
85
-                __(
86
-                    'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event.  There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode).  %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.',
87
-                    'event_espresso'
88
-                ),
89
-                '<code>',
90
-                '</code>'
91
-            ),
92
-            '[EVENT_TOTAL_SPOTS_TAKEN]'               => __(
93
-                'This shortcode will parse to the output the total approved registrations for this event',
94
-                'event_espresso'
95
-            ),
96
-            '[EVENT_FACEBOOK_URL]'                    => __(
97
-                'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.',
98
-                'event_espresso'
99
-            ),
100
-            '[EVENT_TWITTER_URL]'                     => __(
101
-                'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url',
102
-                'event_espresso'
103
-            ),
104
-            '[EVENT_META_*]'                          => sprintf(
105
-                __(
106
-                    'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ',
107
-                    'event_espresso'
108
-                ),
109
-                '<code>',
110
-                '</code>'
111
-            ),
112
-            '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => __(
113
-                'This parses to the url for the registration list table filtered by registrations for this event.',
114
-                'event_espresso'
115
-            ),
116
-        );
117
-    }
118
-
119
-
120
-    protected function _parser($shortcode)
121
-    {
122
-
123
-
124
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
125
-
126
-        // if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
127
-        if (empty($this->_event)) {
128
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
129
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
130
-
131
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
132
-                ? $aee->reg_obj->event() : null;
133
-        }
134
-
135
-
136
-        // If there is no event objecdt by now then get out.
137
-        if (! $this->_event instanceof EE_Event) {
138
-            return '';
139
-        }
140
-
141
-        switch ($shortcode) {
142
-            case '[EVENT_ID]':
143
-                return $this->_event->ID();
144
-                break;
145
-
146
-            case '[EVENT]':
147
-            case '[EVENT_NAME]':
148
-                return $this->_event->get('EVT_name');
149
-                break;
150
-
151
-            case '[EVENT_PHONE]':
152
-                return $this->_event->get('EVT_phone');
153
-                break;
154
-
155
-            case '[EVENT_DESCRIPTION]':
156
-                return $this->_event->get('EVT_desc');
157
-                break;
158
-
159
-            case '[EVENT_EXCERPT]':
160
-                return $this->_event->get('EVT_short_desc');
161
-                break;
162
-
163
-            case '[EVENT_LINK]':
164
-                return $this->_get_event_link($this->_event);
165
-                break;
166
-
167
-            case '[EVENT_URL]':
168
-                return $this->_get_event_link($this->_event, false);
169
-                break;
170
-
171
-            case '[VIRTUAL_URL]':
172
-                $venue = $this->_event->get_first_related('Venue');
173
-                if (empty($venue)) {
174
-                    return '';
175
-                }
176
-                return $venue->get('VNU_virtual_url');
177
-
178
-            case '[VIRTUAL_PHONE]':
179
-                $venue = $this->_event->get_first_related('Venue');
180
-                if (empty($venue)) {
181
-                    return '';
182
-                }
183
-                return $venue->get('VNU_virtual_phone');
184
-                break;
185
-
186
-            case '[EVENT_IMAGE]':
187
-                $image = $this->_event->feature_image_url(array(600, 300));
188
-                // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189
-                return ! empty($image)
190
-                    ? '<img src="' . $image . '" alt="'
191
-                      . sprintf(
192
-                          esc_attr__('%s Feature Image', 'event_espresso'),
193
-                          $this->_event->get('EVT_name')
194
-                      ) . '" />'
195
-                    : '';
196
-                break;
197
-
198
-            case '[EVENT_FACEBOOK_URL]':
199
-                $facebook_url = $this->_event->get_post_meta('event_facebook', true);
200
-                return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
201
-                    : $facebook_url;
202
-                break;
203
-
204
-            case '[EVENT_TWITTER_URL]':
205
-                $twitter_url = $this->_event->get_post_meta('event_twitter', true);
206
-                return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
207
-                    : $twitter_url;
208
-                break;
209
-
210
-            case '[EVENT_AUTHOR_EMAIL]':
211
-                $author_id = $this->_event->get('EVT_wp_user');
212
-                $user_data = get_userdata((int) $author_id);
213
-                return $user_data->user_email;
214
-                break;
215
-
216
-            case '[EVENT_TOTAL_SPOTS_TAKEN]':
217
-                return EEM_Registration::instance()->count(
218
-                    array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)),
219
-                    'REG_ID',
220
-                    true
221
-                );
222
-                break;
223
-
224
-            case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
225
-                return EEH_URL::add_query_args_and_nonce(
226
-                    array(
227
-                        'event_id' => $this->_event->ID(),
228
-                        'page'     => 'espresso_registrations',
229
-                        'action'   => 'default',
230
-                    ),
231
-                    admin_url('admin.php'),
232
-                    true
233
-                );
234
-                break;
235
-        }
236
-
237
-        if (strpos($shortcode, '[EVENT_META_*') !== false) {
238
-            // Strip the shortcode itself from $shortcode leaving any attributes set.
239
-            // Removing the * is correct here as _* is used to indiciate a dynamic shortcode.
240
-            $shortcode = str_replace('[EVENT_META_*', '', $shortcode);
241
-            $shortcode = trim(str_replace(']', '', $shortcode));
242
-            // Get any attributes set on this shortcode.
243
-            $attrs = $this->_get_shortcode_attrs($shortcode);
244
-            // The meta_key set on the shortcode should always be the first value in the array.
245
-            $meta_key = $attrs[0];
246
-            // Pull the meta value from the event post.
247
-            $event_meta = $this->_event->get_post_meta($meta_key, true);
248
-            // If we have no event_meta, just return an empty string.
249
-            if (empty($event_meta)) {
250
-                return '';
251
-            }
252
-            // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
253
-            // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254
-            if (
255
-                apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
256
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
257
-            ) {
258
-                return do_shortcode($event_meta);
259
-            }
260
-            // Still here? We just need to return the event_meta value as is.
261
-            return $event_meta;
262
-        }
263
-
264
-        if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
265
-            $attrs = $this->_get_shortcode_attrs($shortcode);
266
-            $method = empty($attrs['method']) ? 'current' : $attrs['method'];
267
-            $method = $method === 'current';
268
-            $available = $this->_event->total_available_spaces($method);
269
-            return $available === EE_INF ? '&infin;' : $available;
270
-        }
271
-
272
-        if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
273
-            $attrs = $this->_get_shortcode_attrs($shortcode);
274
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
275
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
276
-
277
-            // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
278
-            if (! empty($attrs['size'])) {
279
-                $size = explode(',', $attrs['size']);
280
-                if (count($size) === 1) {
281
-                    $size = $size[0];
282
-                }
283
-            } else {
284
-                $size = 'thumbnail';
285
-            }
286
-
287
-            $image = $this->_event->feature_image_url($size);
288
-
289
-            return ! empty($image)
290
-                ? '<img src="' . $image . '" alt="'
291
-                  . sprintf(
292
-                      esc_attr__('%s Feature Image', 'event_espresso'),
293
-                      $this->_event->get('EVT_name')
294
-                  ) . '"' . $width . $height . '/>'
295
-                : '';
296
-        }
297
-
298
-        return '';
299
-    }
300
-
301
-
302
-    /**
303
-     * returns the link to the event
304
-     *
305
-     * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
306
-     *                            Otherwise we just return the url of the event.
307
-     * @return string
308
-     */
309
-    private function _get_event_link($event, $full_link = true)
310
-    {
311
-        $url = get_permalink($event->ID());
312
-
313
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
314
-    }
22
+	/**
23
+	 * Will hold the EE_Event if available
24
+	 *
25
+	 * @var EE_Event
26
+	 */
27
+	protected $_event;
28
+
29
+
30
+	public function __construct()
31
+	{
32
+		parent::__construct();
33
+	}
34
+
35
+
36
+	protected function _init_props()
37
+	{
38
+		$this->label = __('Event Shortcodes', 'event_espresso');
39
+		$this->description = __('All shortcodes specific to event related data', 'event_espresso');
40
+		$this->_shortcodes = array(
41
+			'[EVENT_ID]'                              => __(
42
+				'Will be replaced by the event ID of an event',
43
+				'event_espresso'
44
+			),
45
+			'[EVENT]'                                 => __('The name of the event', 'event_espresso'),
46
+			'[EVENT_NAME]'                            => __(
47
+				"This also can be used for the name of the event",
48
+				'event_espresso'
49
+			),
50
+			'[EVENT_PHONE]'                           => __(
51
+				'The phone number for the event (usually an info number)',
52
+				'event_espresso'
53
+			),
54
+			'[EVENT_DESCRIPTION]'                     => __('The description of the event', 'event_espresso'),
55
+			'[EVENT_EXCERPT]'                         => __(
56
+				'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.',
57
+				'event_espresso'
58
+			),
59
+			'[EVENT_LINK]'                            => __('A link associated with the event', 'event_espresso'),
60
+			'[EVENT_URL]'                             => __(
61
+				'A link to the event set up on the host site.',
62
+				'event_espresso'
63
+			),
64
+			'[VIRTUAL_URL]'                           => __(
65
+				'What was used for the "URL of Event" field in the Venue settings',
66
+				'event_espresso'
67
+			),
68
+			'[VIRTUAL_PHONE]'                         => __(
69
+				'An alternate phone number for the event. Typically used as a "call-in" number',
70
+				'event_espresso'
71
+			),
72
+			'[EVENT_IMAGE]'                           => __(
73
+				'This will parse to the Feature image for the event.',
74
+				'event_espresso'
75
+			),
76
+			'[EVENT_IMAGE_*]'                         => sprintf(
77
+				__(
78
+					'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.',
79
+					'event_espresso'
80
+				),
81
+				'<code>',
82
+				'</code>'
83
+			),
84
+			'[EVENT_TOTAL_AVAILABLE_SPACES_*]'        => sprintf(
85
+				__(
86
+					'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event.  There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode).  %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.',
87
+					'event_espresso'
88
+				),
89
+				'<code>',
90
+				'</code>'
91
+			),
92
+			'[EVENT_TOTAL_SPOTS_TAKEN]'               => __(
93
+				'This shortcode will parse to the output the total approved registrations for this event',
94
+				'event_espresso'
95
+			),
96
+			'[EVENT_FACEBOOK_URL]'                    => __(
97
+				'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.',
98
+				'event_espresso'
99
+			),
100
+			'[EVENT_TWITTER_URL]'                     => __(
101
+				'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url',
102
+				'event_espresso'
103
+			),
104
+			'[EVENT_META_*]'                          => sprintf(
105
+				__(
106
+					'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ',
107
+					'event_espresso'
108
+				),
109
+				'<code>',
110
+				'</code>'
111
+			),
112
+			'[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => __(
113
+				'This parses to the url for the registration list table filtered by registrations for this event.',
114
+				'event_espresso'
115
+			),
116
+		);
117
+	}
118
+
119
+
120
+	protected function _parser($shortcode)
121
+	{
122
+
123
+
124
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
125
+
126
+		// if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
127
+		if (empty($this->_event)) {
128
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
129
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
130
+
131
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
132
+				? $aee->reg_obj->event() : null;
133
+		}
134
+
135
+
136
+		// If there is no event objecdt by now then get out.
137
+		if (! $this->_event instanceof EE_Event) {
138
+			return '';
139
+		}
140
+
141
+		switch ($shortcode) {
142
+			case '[EVENT_ID]':
143
+				return $this->_event->ID();
144
+				break;
145
+
146
+			case '[EVENT]':
147
+			case '[EVENT_NAME]':
148
+				return $this->_event->get('EVT_name');
149
+				break;
150
+
151
+			case '[EVENT_PHONE]':
152
+				return $this->_event->get('EVT_phone');
153
+				break;
154
+
155
+			case '[EVENT_DESCRIPTION]':
156
+				return $this->_event->get('EVT_desc');
157
+				break;
158
+
159
+			case '[EVENT_EXCERPT]':
160
+				return $this->_event->get('EVT_short_desc');
161
+				break;
162
+
163
+			case '[EVENT_LINK]':
164
+				return $this->_get_event_link($this->_event);
165
+				break;
166
+
167
+			case '[EVENT_URL]':
168
+				return $this->_get_event_link($this->_event, false);
169
+				break;
170
+
171
+			case '[VIRTUAL_URL]':
172
+				$venue = $this->_event->get_first_related('Venue');
173
+				if (empty($venue)) {
174
+					return '';
175
+				}
176
+				return $venue->get('VNU_virtual_url');
177
+
178
+			case '[VIRTUAL_PHONE]':
179
+				$venue = $this->_event->get_first_related('Venue');
180
+				if (empty($venue)) {
181
+					return '';
182
+				}
183
+				return $venue->get('VNU_virtual_phone');
184
+				break;
185
+
186
+			case '[EVENT_IMAGE]':
187
+				$image = $this->_event->feature_image_url(array(600, 300));
188
+				// @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189
+				return ! empty($image)
190
+					? '<img src="' . $image . '" alt="'
191
+					  . sprintf(
192
+						  esc_attr__('%s Feature Image', 'event_espresso'),
193
+						  $this->_event->get('EVT_name')
194
+					  ) . '" />'
195
+					: '';
196
+				break;
197
+
198
+			case '[EVENT_FACEBOOK_URL]':
199
+				$facebook_url = $this->_event->get_post_meta('event_facebook', true);
200
+				return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
201
+					: $facebook_url;
202
+				break;
203
+
204
+			case '[EVENT_TWITTER_URL]':
205
+				$twitter_url = $this->_event->get_post_meta('event_twitter', true);
206
+				return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
207
+					: $twitter_url;
208
+				break;
209
+
210
+			case '[EVENT_AUTHOR_EMAIL]':
211
+				$author_id = $this->_event->get('EVT_wp_user');
212
+				$user_data = get_userdata((int) $author_id);
213
+				return $user_data->user_email;
214
+				break;
215
+
216
+			case '[EVENT_TOTAL_SPOTS_TAKEN]':
217
+				return EEM_Registration::instance()->count(
218
+					array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)),
219
+					'REG_ID',
220
+					true
221
+				);
222
+				break;
223
+
224
+			case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
225
+				return EEH_URL::add_query_args_and_nonce(
226
+					array(
227
+						'event_id' => $this->_event->ID(),
228
+						'page'     => 'espresso_registrations',
229
+						'action'   => 'default',
230
+					),
231
+					admin_url('admin.php'),
232
+					true
233
+				);
234
+				break;
235
+		}
236
+
237
+		if (strpos($shortcode, '[EVENT_META_*') !== false) {
238
+			// Strip the shortcode itself from $shortcode leaving any attributes set.
239
+			// Removing the * is correct here as _* is used to indiciate a dynamic shortcode.
240
+			$shortcode = str_replace('[EVENT_META_*', '', $shortcode);
241
+			$shortcode = trim(str_replace(']', '', $shortcode));
242
+			// Get any attributes set on this shortcode.
243
+			$attrs = $this->_get_shortcode_attrs($shortcode);
244
+			// The meta_key set on the shortcode should always be the first value in the array.
245
+			$meta_key = $attrs[0];
246
+			// Pull the meta value from the event post.
247
+			$event_meta = $this->_event->get_post_meta($meta_key, true);
248
+			// If we have no event_meta, just return an empty string.
249
+			if (empty($event_meta)) {
250
+				return '';
251
+			}
252
+			// Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
253
+			// Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254
+			if (
255
+				apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
256
+				|| !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
257
+			) {
258
+				return do_shortcode($event_meta);
259
+			}
260
+			// Still here? We just need to return the event_meta value as is.
261
+			return $event_meta;
262
+		}
263
+
264
+		if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
265
+			$attrs = $this->_get_shortcode_attrs($shortcode);
266
+			$method = empty($attrs['method']) ? 'current' : $attrs['method'];
267
+			$method = $method === 'current';
268
+			$available = $this->_event->total_available_spaces($method);
269
+			return $available === EE_INF ? '&infin;' : $available;
270
+		}
271
+
272
+		if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
273
+			$attrs = $this->_get_shortcode_attrs($shortcode);
274
+			$width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
275
+			$height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
276
+
277
+			// Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
278
+			if (! empty($attrs['size'])) {
279
+				$size = explode(',', $attrs['size']);
280
+				if (count($size) === 1) {
281
+					$size = $size[0];
282
+				}
283
+			} else {
284
+				$size = 'thumbnail';
285
+			}
286
+
287
+			$image = $this->_event->feature_image_url($size);
288
+
289
+			return ! empty($image)
290
+				? '<img src="' . $image . '" alt="'
291
+				  . sprintf(
292
+					  esc_attr__('%s Feature Image', 'event_espresso'),
293
+					  $this->_event->get('EVT_name')
294
+				  ) . '"' . $width . $height . '/>'
295
+				: '';
296
+		}
297
+
298
+		return '';
299
+	}
300
+
301
+
302
+	/**
303
+	 * returns the link to the event
304
+	 *
305
+	 * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
306
+	 *                            Otherwise we just return the url of the event.
307
+	 * @return string
308
+	 */
309
+	private function _get_event_link($event, $full_link = true)
310
+	{
311
+		$url = get_permalink($event->ID());
312
+
313
+		return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
314
+	}
315 315
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 
136 136
         // If there is no event objecdt by now then get out.
137
-        if (! $this->_event instanceof EE_Event) {
137
+        if ( ! $this->_event instanceof EE_Event) {
138 138
             return '';
139 139
         }
140 140
 
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
                 $image = $this->_event->feature_image_url(array(600, 300));
188 188
                 // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189 189
                 return ! empty($image)
190
-                    ? '<img src="' . $image . '" alt="'
190
+                    ? '<img src="'.$image.'" alt="'
191 191
                       . sprintf(
192 192
                           esc_attr__('%s Feature Image', 'event_espresso'),
193 193
                           $this->_event->get('EVT_name')
194
-                      ) . '" />'
194
+                      ).'" />'
195 195
                     : '';
196 196
                 break;
197 197
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
             // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254 254
             if (
255 255
                 apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
256
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
256
+                || ! empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
257 257
             ) {
258 258
                 return do_shortcode($event_meta);
259 259
             }
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
 
272 272
         if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
273 273
             $attrs = $this->_get_shortcode_attrs($shortcode);
274
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
275
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
274
+            $width = empty($attrs['width']) ? '' : ' width="'.$attrs['width'].'"';
275
+            $height = empty($attrs['height']) ? '' : ' height="'.$attrs['height'].'"';
276 276
 
277 277
             // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
278
-            if (! empty($attrs['size'])) {
278
+            if ( ! empty($attrs['size'])) {
279 279
                 $size = explode(',', $attrs['size']);
280 280
                 if (count($size) === 1) {
281 281
                     $size = $size[0];
@@ -287,11 +287,11 @@  discard block
 block discarded – undo
287 287
             $image = $this->_event->feature_image_url($size);
288 288
 
289 289
             return ! empty($image)
290
-                ? '<img src="' . $image . '" alt="'
290
+                ? '<img src="'.$image.'" alt="'
291 291
                   . sprintf(
292 292
                       esc_attr__('%s Feature Image', 'event_espresso'),
293 293
                       $this->_event->get('EVT_name')
294
-                  ) . '"' . $width . $height . '/>'
294
+                  ).'"'.$width.$height.'/>'
295 295
                 : '';
296 296
         }
297 297
 
@@ -310,6 +310,6 @@  discard block
 block discarded – undo
310 310
     {
311 311
         $url = get_permalink($event->ID());
312 312
 
313
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
313
+        return $full_link ? '<a href="'.$url.'">'.$event->get('EVT_name').'</a>' : $url;
314 314
     }
315 315
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Primary_Registration_List_Shortcodes.lib.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -125,6 +125,9 @@  discard block
 block discarded – undo
125 125
     }
126 126
 
127 127
 
128
+    /**
129
+     * @param EE_Registration $reg
130
+     */
128 131
     private function _get_tickets_from_event(EE_Event $event, $reg = null)
129 132
     {
130 133
         $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
@@ -203,6 +206,9 @@  discard block
 block discarded – undo
203 206
     }
204 207
 
205 208
 
209
+    /**
210
+     * @param EE_Registration $reg
211
+     */
206 212
     private function _get_datetimes_from_event(EE_Event $event, $reg = null)
207 213
     {
208 214
         $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
Please login to merge, or discard this patch.
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -19,206 +19,206 @@
 block discarded – undo
19 19
 class EE_Primary_Registration_List_Shortcodes extends EE_Shortcodes
20 20
 {
21 21
 
22
-    public function __construct()
23
-    {
24
-        parent::__construct();
25
-    }
26
-
27
-
28
-    protected function _init_props()
29
-    {
30
-        $this->label = __('Primary Registrant List Shortcodes', 'event_espresso');
31
-        $this->description = __(
32
-            'All shortcodes specific primary registrant recipients list type data.',
33
-            'event_espresso'
34
-        );
35
-        $this->_shortcodes = array(
36
-            '[PRIMARY_REGISTRANT_TICKET_LIST]' => __(
37
-                'Will output a list of tickets that the primary registration received.',
38
-                'event_espresso'
39
-            ),
40
-            '[PRIMARY_REGISTRANT_DATETIME_LIST]' => __(
41
-                'Will output a list of datetimes that the primary registrant for the transaction has been registered for.',
42
-                'event_espresso'
43
-            ),
44
-        );
45
-    }
46
-
47
-
48
-    protected function _parser($shortcode)
49
-    {
50
-        switch ($shortcode) {
51
-            case '[PRIMARY_REGISTRANT_TICKET_LIST]':
52
-                return $this->_get_recipient_ticket_list(true);
53
-                break;
54
-
55
-            case '[PRIMARY_REGISTRANT_DATETIME_LIST]':
56
-                return $this->_get_recipient_datetime_list(true);
57
-                break;
58
-        }
59
-        return '';
60
-    }
61
-
62
-
63
-    /**
64
-     * figure out what the incoming data is and then return the appropriate parsed value
65
-     *
66
-     * @param  boolean $primary whether we're getting the primary registrant ticket_list.
67
-     * @return string
68
-     */
69
-    private function _get_recipient_ticket_list($primary = false)
70
-    {
71
-        $this->_validate_list_requirements();
72
-
73
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
74
-            return $this->_get_recipient_ticket_list_parsed($this->_data['data'], $primary);
75
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
76
-            return $this->_get_recipient_ticket_list_parsed($this->_extra_data['data'], $primary);
77
-        } else {
78
-            return '';
79
-        }
80
-    }
81
-
82
-
83
-    private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
84
-    {
85
-        $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
86
-        if (! $registration instanceof EE_Registration) {
87
-            return '';
88
-        }
89
-        // setup valid shortcodes depending on what the status of the $this->_data property is
90
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
91
-            $valid_shortcodes = array(
92
-                'ticket',
93
-                'event_list',
94
-                'attendee_list',
95
-                'datetime_list',
96
-                'registration_details',
97
-                'attendee',
98
-            );
99
-            $template = $this->_data['template'];
100
-            $tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
101
-            $data = $this->_data;
102
-        } elseif ($this->_data['data'] instanceof EE_Event) {
103
-            $valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
104
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['ticket_list'])
105
-                ? $this->_data['template']['ticket_list'] : $this->_extra_data['template']['ticket_list'];
106
-            // let's remove any existing [EVENT_LIST] shortcode from the ticket list template so that we don't get recursion.
107
-            $template = str_replace('[EVENT_LIST]', '', $template);
108
-            // data will be tickets for this event for this recipient.
109
-            $tkts = $this->_get_tickets_from_event($this->_data['data'], $registration);
110
-            $data = $this->_extra_data;
111
-        } else {
112
-            return '';
113
-        }
114
-
115
-        $tktparsed = '';
116
-        foreach ($tkts as $ticket) {
117
-            $tktparsed .= $this->_shortcode_helper->parse_ticket_list_template(
118
-                $template,
119
-                $ticket,
120
-                $valid_shortcodes,
121
-                $data
122
-            );
123
-        }
124
-        return $tktparsed;
125
-    }
126
-
127
-
128
-    private function _get_tickets_from_event(EE_Event $event, $reg = null)
129
-    {
130
-        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
131
-        ) ]['tkt_objs'] : array();
132
-
133
-        if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
134
-            $adj_tkts = array();
135
-            // return only tickets for the given attendee
136
-            foreach ($evt_tkts as $tkt) {
137
-                if (
138
-                    isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
139
-                    && $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
140
-                ) {
141
-                    $adj_tkts[] = $tkt;
142
-                }
143
-            }
144
-            $evt_tkts = $adj_tkts;
145
-        }
146
-        return $evt_tkts;
147
-    }
148
-
149
-
150
-    /**
151
-     * figure out what the incoming data is and then return the appropriate parsed value
152
-     *
153
-     * @param  boolean $primary whether we're getting the primary registrant ticket_list.
154
-     * @return string
155
-     */
156
-    private function _get_recipient_datetime_list($primary = false)
157
-    {
158
-        $this->_validate_list_requirements();
159
-
160
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
161
-            return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
162
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
163
-            return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data'], $primary);
164
-        } else {
165
-            return '';
166
-        }
167
-
168
-        return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
169
-    }
170
-
171
-
172
-    private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
173
-    {
174
-        $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
175
-        if (! $registration instanceof EE_Registration) {
176
-            return '';
177
-        }
178
-        // setup valid shortcodes depending on what the status of the $this->_data property is
179
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
180
-            $valid_shortcodes = array('datetime', 'attendee');
181
-            $template = $this->_data['template'];
182
-            $dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
183
-            $data = $this->_data;
184
-        } elseif ($this->_data['data'] instanceof EE_Event) {
185
-            $valid_shortcodes = array('datetime', 'attendee');
186
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
187
-                ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
188
-            $dtts = $this->_get_datetimes_from_event($this->_data['data'], $registration);
189
-            $data = $this->_extra_data;
190
-        } else {
191
-            return '';
192
-        }
193
-
194
-        $dtt_parsed = '';
195
-        foreach ($dtts as $datetime) {
196
-            $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
197
-                $template,
198
-                $datetime,
199
-                $valid_shortcodes,
200
-                $this->_extra_data
201
-            );
202
-        }
203
-        return $dtt_parsed;
204
-    }
205
-
206
-
207
-    private function _get_datetimes_from_event(EE_Event $event, $reg = null)
208
-    {
209
-        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
210
-        ) ]['dtt_objs'] : array();
211
-
212
-        if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
213
-            $adj_dtts = array();
214
-            // return only dtts for the given attendee
215
-            foreach ($evt_dtts as $dtt) {
216
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
217
-                    $adj_dtts[] = $dtt;
218
-                }
219
-            }
220
-            $evt_dtts = $adj_dtts;
221
-        }
222
-        return $evt_dtts;
223
-    }
22
+	public function __construct()
23
+	{
24
+		parent::__construct();
25
+	}
26
+
27
+
28
+	protected function _init_props()
29
+	{
30
+		$this->label = __('Primary Registrant List Shortcodes', 'event_espresso');
31
+		$this->description = __(
32
+			'All shortcodes specific primary registrant recipients list type data.',
33
+			'event_espresso'
34
+		);
35
+		$this->_shortcodes = array(
36
+			'[PRIMARY_REGISTRANT_TICKET_LIST]' => __(
37
+				'Will output a list of tickets that the primary registration received.',
38
+				'event_espresso'
39
+			),
40
+			'[PRIMARY_REGISTRANT_DATETIME_LIST]' => __(
41
+				'Will output a list of datetimes that the primary registrant for the transaction has been registered for.',
42
+				'event_espresso'
43
+			),
44
+		);
45
+	}
46
+
47
+
48
+	protected function _parser($shortcode)
49
+	{
50
+		switch ($shortcode) {
51
+			case '[PRIMARY_REGISTRANT_TICKET_LIST]':
52
+				return $this->_get_recipient_ticket_list(true);
53
+				break;
54
+
55
+			case '[PRIMARY_REGISTRANT_DATETIME_LIST]':
56
+				return $this->_get_recipient_datetime_list(true);
57
+				break;
58
+		}
59
+		return '';
60
+	}
61
+
62
+
63
+	/**
64
+	 * figure out what the incoming data is and then return the appropriate parsed value
65
+	 *
66
+	 * @param  boolean $primary whether we're getting the primary registrant ticket_list.
67
+	 * @return string
68
+	 */
69
+	private function _get_recipient_ticket_list($primary = false)
70
+	{
71
+		$this->_validate_list_requirements();
72
+
73
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
74
+			return $this->_get_recipient_ticket_list_parsed($this->_data['data'], $primary);
75
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
76
+			return $this->_get_recipient_ticket_list_parsed($this->_extra_data['data'], $primary);
77
+		} else {
78
+			return '';
79
+		}
80
+	}
81
+
82
+
83
+	private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
84
+	{
85
+		$registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
86
+		if (! $registration instanceof EE_Registration) {
87
+			return '';
88
+		}
89
+		// setup valid shortcodes depending on what the status of the $this->_data property is
90
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
91
+			$valid_shortcodes = array(
92
+				'ticket',
93
+				'event_list',
94
+				'attendee_list',
95
+				'datetime_list',
96
+				'registration_details',
97
+				'attendee',
98
+			);
99
+			$template = $this->_data['template'];
100
+			$tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
101
+			$data = $this->_data;
102
+		} elseif ($this->_data['data'] instanceof EE_Event) {
103
+			$valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
104
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['ticket_list'])
105
+				? $this->_data['template']['ticket_list'] : $this->_extra_data['template']['ticket_list'];
106
+			// let's remove any existing [EVENT_LIST] shortcode from the ticket list template so that we don't get recursion.
107
+			$template = str_replace('[EVENT_LIST]', '', $template);
108
+			// data will be tickets for this event for this recipient.
109
+			$tkts = $this->_get_tickets_from_event($this->_data['data'], $registration);
110
+			$data = $this->_extra_data;
111
+		} else {
112
+			return '';
113
+		}
114
+
115
+		$tktparsed = '';
116
+		foreach ($tkts as $ticket) {
117
+			$tktparsed .= $this->_shortcode_helper->parse_ticket_list_template(
118
+				$template,
119
+				$ticket,
120
+				$valid_shortcodes,
121
+				$data
122
+			);
123
+		}
124
+		return $tktparsed;
125
+	}
126
+
127
+
128
+	private function _get_tickets_from_event(EE_Event $event, $reg = null)
129
+	{
130
+		$evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
131
+		) ]['tkt_objs'] : array();
132
+
133
+		if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
134
+			$adj_tkts = array();
135
+			// return only tickets for the given attendee
136
+			foreach ($evt_tkts as $tkt) {
137
+				if (
138
+					isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
139
+					&& $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
140
+				) {
141
+					$adj_tkts[] = $tkt;
142
+				}
143
+			}
144
+			$evt_tkts = $adj_tkts;
145
+		}
146
+		return $evt_tkts;
147
+	}
148
+
149
+
150
+	/**
151
+	 * figure out what the incoming data is and then return the appropriate parsed value
152
+	 *
153
+	 * @param  boolean $primary whether we're getting the primary registrant ticket_list.
154
+	 * @return string
155
+	 */
156
+	private function _get_recipient_datetime_list($primary = false)
157
+	{
158
+		$this->_validate_list_requirements();
159
+
160
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
161
+			return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
162
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
163
+			return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data'], $primary);
164
+		} else {
165
+			return '';
166
+		}
167
+
168
+		return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
169
+	}
170
+
171
+
172
+	private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
173
+	{
174
+		$registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
175
+		if (! $registration instanceof EE_Registration) {
176
+			return '';
177
+		}
178
+		// setup valid shortcodes depending on what the status of the $this->_data property is
179
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
180
+			$valid_shortcodes = array('datetime', 'attendee');
181
+			$template = $this->_data['template'];
182
+			$dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
183
+			$data = $this->_data;
184
+		} elseif ($this->_data['data'] instanceof EE_Event) {
185
+			$valid_shortcodes = array('datetime', 'attendee');
186
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
187
+				? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
188
+			$dtts = $this->_get_datetimes_from_event($this->_data['data'], $registration);
189
+			$data = $this->_extra_data;
190
+		} else {
191
+			return '';
192
+		}
193
+
194
+		$dtt_parsed = '';
195
+		foreach ($dtts as $datetime) {
196
+			$dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
197
+				$template,
198
+				$datetime,
199
+				$valid_shortcodes,
200
+				$this->_extra_data
201
+			);
202
+		}
203
+		return $dtt_parsed;
204
+	}
205
+
206
+
207
+	private function _get_datetimes_from_event(EE_Event $event, $reg = null)
208
+	{
209
+		$evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
210
+		) ]['dtt_objs'] : array();
211
+
212
+		if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
213
+			$adj_dtts = array();
214
+			// return only dtts for the given attendee
215
+			foreach ($evt_dtts as $dtt) {
216
+				if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
217
+					$adj_dtts[] = $dtt;
218
+				}
219
+			}
220
+			$evt_dtts = $adj_dtts;
221
+		}
222
+		return $evt_dtts;
223
+	}
224 224
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
84 84
     {
85 85
         $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
86
-        if (! $registration instanceof EE_Registration) {
86
+        if ( ! $registration instanceof EE_Registration) {
87 87
             return '';
88 88
         }
89 89
         // setup valid shortcodes depending on what the status of the $this->_data property is
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
                 'attendee',
98 98
             );
99 99
             $template = $this->_data['template'];
100
-            $tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
100
+            $tkts = array($data->registrations[$registration->ID()]['tkt_obj']);
101 101
             $data = $this->_data;
102 102
         } elseif ($this->_data['data'] instanceof EE_Event) {
103 103
             $valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 
128 128
     private function _get_tickets_from_event(EE_Event $event, $reg = null)
129 129
     {
130
-        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
131
-        ) ]['tkt_objs'] : array();
130
+        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID(
131
+        )]['tkt_objs'] : array();
132 132
 
133 133
         if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
134 134
             $adj_tkts = array();
135 135
             // return only tickets for the given attendee
136 136
             foreach ($evt_tkts as $tkt) {
137 137
                 if (
138
-                    isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
139
-                    && $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
138
+                    isset($this->_extra_data['data']->registrations[$reg->ID()]['tkt_obj'])
139
+                    && $this->_extra_data['data']->registrations[$reg->ID()]['tkt_obj']->ID() == $tkt->ID()
140 140
                 ) {
141 141
                     $adj_tkts[] = $tkt;
142 142
                 }
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
     private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
173 173
     {
174 174
         $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
175
-        if (! $registration instanceof EE_Registration) {
175
+        if ( ! $registration instanceof EE_Registration) {
176 176
             return '';
177 177
         }
178 178
         // setup valid shortcodes depending on what the status of the $this->_data property is
179 179
         if ($this->_data['data'] instanceof EE_Messages_Addressee) {
180 180
             $valid_shortcodes = array('datetime', 'attendee');
181 181
             $template = $this->_data['template'];
182
-            $dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
182
+            $dtts = $data->registrations[$registration->ID()]['dtt_objs'];
183 183
             $data = $this->_data;
184 184
         } elseif ($this->_data['data'] instanceof EE_Event) {
185 185
             $valid_shortcodes = array('datetime', 'attendee');
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
 
207 207
     private function _get_datetimes_from_event(EE_Event $event, $reg = null)
208 208
     {
209
-        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
210
-        ) ]['dtt_objs'] : array();
209
+        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID(
210
+        )]['dtt_objs'] : array();
211 211
 
212 212
         if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
213 213
             $adj_dtts = array();
214 214
             // return only dtts for the given attendee
215 215
             foreach ($evt_dtts as $dtt) {
216
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
216
+                if (isset($this->_extra_data['data']->registrations[$reg->ID()]['dtt_objs'][$dtt->ID()])) {
217 217
                     $adj_dtts[] = $dtt;
218 218
                 }
219 219
             }
Please login to merge, or discard this patch.
core/services/notices/NoticeConverterInterface.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,6 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
     /**
22 22
      * @param bool $throw_exceptions
23
+     * @return void
23 24
      */
24 25
     public function setThrowExceptions($throw_exceptions);
25 26
 
@@ -37,7 +38,7 @@  discard block
 block discarded – undo
37 38
     public function process(NoticesContainerInterface $notices);
38 39
 
39 40
     /**
40
-     * @return void;
41
+     * @return void
41 42
      */
42 43
     public function clearNotices();
43 44
 }
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -13,31 +13,31 @@
 block discarded – undo
13 13
 interface NoticeConverterInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @return NoticesContainerInterface
18
-     */
19
-    public function getNotices();
16
+	/**
17
+	 * @return NoticesContainerInterface
18
+	 */
19
+	public function getNotices();
20 20
 
21
-    /**
22
-     * @param bool $throw_exceptions
23
-     */
24
-    public function setThrowExceptions($throw_exceptions);
21
+	/**
22
+	 * @param bool $throw_exceptions
23
+	 */
24
+	public function setThrowExceptions($throw_exceptions);
25 25
 
26
-    /**
27
-     * @return bool
28
-     */
29
-    public function getThrowExceptions();
26
+	/**
27
+	 * @return bool
28
+	 */
29
+	public function getThrowExceptions();
30 30
 
31
-    /**
32
-     * Converts NoticesContainerInterface objects into other format
33
-     *
34
-     * @param NoticesContainerInterface $notices
35
-     * @return
36
-     */
37
-    public function process(NoticesContainerInterface $notices);
31
+	/**
32
+	 * Converts NoticesContainerInterface objects into other format
33
+	 *
34
+	 * @param NoticesContainerInterface $notices
35
+	 * @return
36
+	 */
37
+	public function process(NoticesContainerInterface $notices);
38 38
 
39
-    /**
40
-     * @return void;
41
-     */
42
-    public function clearNotices();
39
+	/**
40
+	 * @return void;
41
+	 */
42
+	public function clearNotices();
43 43
 }
Please login to merge, or discard this patch.
modules/add_new_state/EED_Add_New_State.module.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * display_add_new_state_micro_form
232 232
      *
233 233
      * @param EE_Form_Section_Proper $question_group_reg_form
234
-     * @return string
234
+     * @return EE_Form_Section_Proper
235 235
      * @throws EE_Error
236 236
      * @throws InvalidArgumentException
237 237
      * @throws InvalidDataTypeException
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 
774 774
     /**
775 775
      * @param EE_State[] $state_options
776
-     * @return array
776
+     * @return EE_State[]
777 777
      * @throws EE_Error
778 778
      * @throws InvalidArgumentException
779 779
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +819 added lines, -819 removed lines patch added patch discarded remove patch
@@ -17,823 +17,823 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @return EED_Module|EED_Add_New_State
22
-     */
23
-    public static function instance()
24
-    {
25
-        return parent::get_instance(__CLASS__);
26
-    }
27
-
28
-
29
-    /**
30
-     * set_hooks - for hooking into EE Core, other modules, etc
31
-     *
32
-     * @return void
33
-     */
34
-    public static function set_hooks()
35
-    {
36
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
37
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
38
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
39
-        add_filter(
40
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
41
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
42
-            1,
43
-            1
44
-        );
45
-        add_filter(
46
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
47
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
48
-            1,
49
-            1
50
-        );
51
-        add_filter(
52
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
53
-            array('EED_Add_New_State', 'unset_new_state_request_params'),
54
-            10,
55
-            1
56
-        );
57
-        add_filter(
58
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
59
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
60
-            10,
61
-            5
62
-        );
63
-        add_filter(
64
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
65
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
66
-            10,
67
-            5
68
-        );
69
-        add_filter(
70
-            'FHEE__EE_State_Select_Input____construct__state_options',
71
-            array('EED_Add_New_State', 'state_options'),
72
-            10,
73
-            1
74
-        );
75
-        add_filter(
76
-            'FHEE__EE_Country_Select_Input____construct__country_options',
77
-            array('EED_Add_New_State', 'country_options'),
78
-            10,
79
-            1
80
-        );
81
-    }
82
-
83
-
84
-    /**
85
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
86
-     *
87
-     * @return void
88
-     */
89
-    public static function set_hooks_admin()
90
-    {
91
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
92
-        add_filter(
93
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
94
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
95
-            1,
96
-            1
97
-        );
98
-        add_filter(
99
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
100
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
101
-            1,
102
-            1
103
-        );
104
-        add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
105
-        add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
106
-        add_filter(
107
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
108
-            array('EED_Add_New_State', 'unset_new_state_request_params'),
109
-            10,
110
-            1
111
-        );
112
-        add_action(
113
-            'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
114
-            array('EED_Add_New_State', 'update_country_settings'),
115
-            10,
116
-            3
117
-        );
118
-        add_action(
119
-            'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
120
-            array('EED_Add_New_State', 'update_country_settings'),
121
-            10,
122
-            3
123
-        );
124
-        add_filter(
125
-            'FHEE__EE_State_Select_Input____construct__state_options',
126
-            array('EED_Add_New_State', 'state_options'),
127
-            10,
128
-            1
129
-        );
130
-        add_filter(
131
-            'FHEE__EE_Country_Select_Input____construct__country_options',
132
-            array('EED_Add_New_State', 'country_options'),
133
-            10,
134
-            1
135
-        );
136
-        add_filter(
137
-            'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
138
-            array('EED_Add_New_State', 'filter_checkout_request_params'),
139
-            10,
140
-            1
141
-        );
142
-        add_filter(
143
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
144
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
145
-            10,
146
-            5
147
-        );
148
-        add_filter(
149
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
150
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
151
-            10,
152
-            5
153
-        );
154
-    }
155
-
156
-
157
-    /**
158
-     * @return void
159
-     */
160
-    public static function set_definitions()
161
-    {
162
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
163
-        define(
164
-            'ANS_TEMPLATES_PATH',
165
-            str_replace(
166
-                '\\',
167
-                '/',
168
-                plugin_dir_path(__FILE__)
169
-            ) . 'templates/'
170
-        );
171
-    }
172
-
173
-
174
-    /**
175
-     * @param WP $WP
176
-     * @return void
177
-     */
178
-    public function run($WP)
179
-    {
180
-    }
181
-
182
-
183
-    /**
184
-     * @return void
185
-     */
186
-    public static function translate_js_strings()
187
-    {
188
-        EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
189
-            'In order to proceed, you need to select the Country that your State/Province belongs to.',
190
-            'event_espresso'
191
-        );
192
-        EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
193
-            'In order to proceed, you need to enter the name of your State/Province.',
194
-            'event_espresso'
195
-        );
196
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
197
-            'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
198
-            'event_espresso'
199
-        );
200
-        EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
201
-            'The new state was successfully saved to the database.',
202
-            'event_espresso'
203
-        );
204
-        EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
205
-            'An unknown error has occurred on the server while saving the new state to the database.',
206
-            'event_espresso'
207
-        );
208
-    }
209
-
210
-
211
-    /**
212
-     * @return void
213
-     */
214
-    public static function wp_enqueue_scripts()
215
-    {
216
-        if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217
-            wp_register_script(
218
-                'add_new_state',
219
-                ANS_ASSETS_URL . 'add_new_state.js',
220
-                array('espresso_core', 'single_page_checkout'),
221
-                EVENT_ESPRESSO_VERSION,
222
-                true
223
-            );
224
-            wp_enqueue_script('add_new_state');
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * display_add_new_state_micro_form
232
-     *
233
-     * @param EE_Form_Section_Proper $question_group_reg_form
234
-     * @return string
235
-     * @throws EE_Error
236
-     * @throws InvalidArgumentException
237
-     * @throws InvalidDataTypeException
238
-     * @throws InvalidInterfaceException
239
-     */
240
-    public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
241
-    {
242
-        // only add the 'new_state_micro_form' when displaying reg forms,
243
-        // not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
-        $action = EE_Registry::instance()->REQ->get('action', '');
245
-        // is the "state" question in this form section?
246
-        $input = $question_group_reg_form->get_subsection('state');
247
-        if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
-            // ok then all we need to do is make sure the input's HTML name is consistent
249
-            // by forcing it to set it now, like it did while getting the form for display
250
-            if ($input instanceof EE_State_Select_Input) {
251
-                $input->html_name();
252
-            }
253
-            return $question_group_reg_form;
254
-        }
255
-        // we're only doing this for state select inputs
256
-        if (
257
-            $input instanceof EE_State_Select_Input
258
-            && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
259
-        ) {
260
-            // grab any set values from the request
261
-            $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
262
-            $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
263
-            $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
264
-            $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
265
-            $country_options = array();
266
-            $countries = EEM_Country::instance()->get_all_countries();
267
-            if (! empty($countries)) {
268
-                foreach ($countries as $country) {
269
-                    if ($country instanceof EE_Country) {
270
-                        $country_options[ $country->ID() ] = $country->name();
271
-                    }
272
-                }
273
-            }
274
-            $new_state_micro_form = new EE_Form_Section_Proper(
275
-                array(
276
-                    'name'            => 'new_state_micro_form',
277
-                    'html_id'         => 'new_state_micro_form',
278
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
279
-                    'subsections'     => array(
280
-                        // add hidden input to indicate that a new state is being added
281
-                        'add_new_state'               => new EE_Hidden_Input(
282
-                            array(
283
-                                'html_name' => str_replace(
284
-                                    'state',
285
-                                    'nsmf_add_new_state',
286
-                                    $input->html_name()
287
-                                ),
288
-                                'html_id'   => str_replace(
289
-                                    'state',
290
-                                    'nsmf_add_new_state',
291
-                                    $input->html_id()
292
-                                ),
293
-                                'default'   => 0,
294
-                            )
295
-                        ),
296
-                        // add link for displaying hidden container
297
-                        'click_here_link'             => new EE_Form_Section_HTML(
298
-                            apply_filters(
299
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
300
-                                EEH_HTML::link(
301
-                                    '',
302
-                                    esc_html__('click here to add a new state/province', 'event_espresso'),
303
-                                    '',
304
-                                    'display-' . $input->html_id(),
305
-                                    'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
306
-                                    '',
307
-                                    'data-target="' . $input->html_id() . '"'
308
-                                )
309
-                            )
310
-                        ),
311
-                        // add initial html for hidden container
312
-                        'add_new_state_micro_form'    => new EE_Form_Section_HTML(
313
-                            apply_filters(
314
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
315
-                                EEH_HTML::div(
316
-                                    '',
317
-                                    $input->html_id() . '-dv',
318
-                                    'ee-form-add-new-state-dv',
319
-                                    'display: none;'
320
-                                ) .
321
-                                EEH_HTML::h6(
322
-                                    esc_html__(
323
-                                        'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
324
-                                        'event_espresso'
325
-                                    )
326
-                                ) .
327
-                                EEH_HTML::ul() .
328
-                                EEH_HTML::li(
329
-                                    esc_html__(
330
-                                        'first select the Country that your State/Province belongs to',
331
-                                        'event_espresso'
332
-                                    )
333
-                                ) .
334
-                                EEH_HTML::li(
335
-                                    esc_html__('enter the name of your State/Province', 'event_espresso')
336
-                                ) .
337
-                                EEH_HTML::li(
338
-                                    esc_html__(
339
-                                        'enter a two to six letter abbreviation for the name of your State/Province',
340
-                                        'event_espresso'
341
-                                    )
342
-                                ) .
343
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
344
-                                EEH_HTML::ulx()
345
-                            )
346
-                        ),
347
-                        // NEW STATE COUNTRY
348
-                        'new_state_country'           => new EE_Country_Select_Input(
349
-                            $country_options,
350
-                            array(
351
-                                'html_name'       => $country_name,
352
-                                'html_id'         => str_replace(
353
-                                    'state',
354
-                                    'nsmf_new_state_country',
355
-                                    $input->html_id()
356
-                                ),
357
-                                'html_class'      => $input->html_class() . ' new-state-country',
358
-                                'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
359
-                                'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
360
-                                'required'        => false,
361
-                            )
362
-                        ),
363
-                        // NEW STATE NAME
364
-                        'new_state_name'              => new EE_Text_Input(
365
-                            array(
366
-                                'html_name'       => $state_name,
367
-                                'html_id'         => str_replace(
368
-                                    'state',
369
-                                    'nsmf_new_state_name',
370
-                                    $input->html_id()
371
-                                ),
372
-                                'html_class'      => $input->html_class() . ' new-state-state',
373
-                                'html_label_text' => esc_html__(
374
-                                    'New State/Province Name',
375
-                                    'event_espresso'
376
-                                ),
377
-                                'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
378
-                                'required'        => false,
379
-                            )
380
-                        ),
381
-                        'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
382
-                        // NEW STATE NAME
383
-                        'new_state_abbrv'             => new EE_Text_Input(
384
-                            array(
385
-                                'html_name'             => $abbrv_name,
386
-                                'html_id'               => str_replace(
387
-                                    'state',
388
-                                    'nsmf_new_state_abbrv',
389
-                                    $input->html_id()
390
-                                ),
391
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
392
-                                'html_label_text'       => esc_html__(
393
-                                    'New State/Province Abbreviation',
394
-                                    'event_espresso'
395
-                                ) . ' *',
396
-                                'other_html_attributes' => 'size="24"',
397
-                                'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
398
-                                'required'              => false,
399
-                            )
400
-                        ),
401
-                        // "submit" button
402
-                        'add_new_state_submit_button' => new EE_Form_Section_HTML(
403
-                            apply_filters(
404
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
405
-                                EEH_HTML::nbsp(3) .
406
-                                EEH_HTML::link(
407
-                                    '',
408
-                                    esc_html__('ADD', 'event_espresso'),
409
-                                    '',
410
-                                    'submit-' . $new_state_submit_id,
411
-                                    'ee-form-add-new-state-submit button button-secondary',
412
-                                    '',
413
-                                    'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName() . '"'
414
-                                )
415
-                            )
416
-                        ),
417
-                        // extra info
418
-                        'add_new_state_extra'         => new EE_Form_Section_HTML(
419
-                            apply_filters(
420
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
421
-                                EEH_HTML::br(2)
422
-                                .
423
-                                EEH_HTML::div('', '', 'small-text')
424
-                                .
425
-                                EEH_HTML::strong(
426
-                                    '* ' .
427
-                                    esc_html__(
428
-                                        'Don\'t know your State/Province Abbreviation?',
429
-                                        'event_espresso'
430
-                                    )
431
-                                )
432
-                                .
433
-                                EEH_HTML::br()
434
-                                .
435
-                                sprintf(
436
-                                    esc_html__(
437
-                                        'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
438
-                                        'event_espresso'
439
-                                    ),
440
-                                    EEH_HTML::link(
441
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
442
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
443
-                                        '',
444
-                                        '',
445
-                                        'ee-form-add-new-state-wiki-lnk',
446
-                                        '',
447
-                                        'target="_blank"'
448
-                                    )
449
-                                )
450
-                                .
451
-                                EEH_HTML::divx()
452
-                                .
453
-                                EEH_HTML::br()
454
-                                .
455
-                                EEH_HTML::link(
456
-                                    '',
457
-                                    esc_html__('cancel new State/Province', 'event_espresso'),
458
-                                    '',
459
-                                    'hide-' . $input->html_id(),
460
-                                    'ee-form-cancel-new-state-lnk smaller-text',
461
-                                    '',
462
-                                    'data-target="' . $input->html_id() . '"'
463
-                                )
464
-                                .
465
-                                EEH_HTML::divx()
466
-                                .
467
-                                EEH_HTML::br()
468
-                            )
469
-                        ),
470
-                    ),
471
-                )
472
-            );
473
-            $question_group_reg_form->add_subsections(
474
-                array('new_state_micro_form' => $new_state_micro_form),
475
-                'state',
476
-                false
477
-            );
478
-        }
479
-        return $question_group_reg_form;
480
-    }
481
-
482
-
483
-    /**
484
-     * set_new_state_input_width
485
-     *
486
-     * @return int|string
487
-     * @throws EE_Error
488
-     * @throws InvalidArgumentException
489
-     * @throws InvalidDataTypeException
490
-     * @throws InvalidInterfaceException
491
-     * @throws ReflectionException
492
-     */
493
-    public static function add_new_state()
494
-    {
495
-        $REQ = EE_Registry::instance()->load_core('Request_Handler');
496
-        if (absint($REQ->get('nsmf_add_new_state')) === 1) {
497
-            EE_Registry::instance()->load_model('State');
498
-            // grab country ISO code, new state name, and new state abbreviation
499
-            $state_country = $REQ->is_set('nsmf_new_state_country')
500
-                ? sanitize_text_field($REQ->get('nsmf_new_state_country'))
501
-                : false;
502
-            $state_name = $REQ->is_set('nsmf_new_state_name')
503
-                ? sanitize_text_field($REQ->get('nsmf_new_state_name'))
504
-                : false;
505
-            $state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
506
-                ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
507
-                : false;
508
-            if ($state_country && $state_name && $state_abbr) {
509
-                $new_state = EED_Add_New_State::save_new_state_to_db(
510
-                    array(
511
-                        'CNT_ISO'    => strtoupper($state_country),
512
-                        'STA_abbrev' => strtoupper($state_abbr),
513
-                        'STA_name'   => ucwords($state_name),
514
-                        'STA_active' => false,
515
-                    )
516
-                );
517
-                if ($new_state instanceof EE_State) {
518
-                    // clean house
519
-                    EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
520
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
521
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
522
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
523
-                    // get any existing new states
524
-                    $new_states = EE_Registry::instance()->SSN->get_session_data(
525
-                        'nsmf_new_states'
526
-                    );
527
-                    $new_states[ $new_state->ID() ] = $new_state;
528
-                    EE_Registry::instance()->SSN->set_session_data(
529
-                        array('nsmf_new_states' => $new_states)
530
-                    );
531
-                    if (EE_Registry::instance()->REQ->ajax) {
532
-                        echo wp_json_encode(
533
-                            array(
534
-                                'success'      => true,
535
-                                'id'           => $new_state->ID(),
536
-                                'name'         => $new_state->name(),
537
-                                'abbrev'       => $new_state->abbrev(),
538
-                                'country_iso'  => $new_state->country_iso(),
539
-                                'country_name' => $new_state->country()->name(),
540
-                            )
541
-                        );
542
-                        exit();
543
-                    }
544
-                    return $new_state->ID();
545
-                }
546
-            } else {
547
-                $error = esc_html__(
548
-                    'A new State/Province could not be added because invalid or missing data was received.',
549
-                    'event_espresso'
550
-                );
551
-                if (EE_Registry::instance()->REQ->ajax) {
552
-                    echo wp_json_encode(array('error' => $error));
553
-                    exit();
554
-                }
555
-                EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
556
-            }
557
-        }
558
-        return false;
559
-    }
560
-
561
-
562
-    /**
563
-     * recursively drills down through request params to remove any that were added by this module
564
-     *
565
-     * @param array $request_params
566
-     * @return array
567
-     */
568
-    public static function filter_checkout_request_params($request_params)
569
-    {
570
-        foreach ($request_params as $form_section) {
571
-            if (is_array($form_section)) {
572
-                EED_Add_New_State::unset_new_state_request_params($form_section);
573
-                EED_Add_New_State::filter_checkout_request_params($form_section);
574
-            }
575
-        }
576
-        return $request_params;
577
-    }
578
-
579
-
580
-    /**
581
-     * @param array $request_params
582
-     * @return array
583
-     */
584
-    public static function unset_new_state_request_params($request_params)
585
-    {
586
-        unset(
587
-            $request_params['new_state_micro_form'],
588
-            $request_params['new_state_micro_add_new_state'],
589
-            $request_params['new_state_micro_new_state_country'],
590
-            $request_params['new_state_micro_new_state_name'],
591
-            $request_params['new_state_micro_new_state_abbrv']
592
-        );
593
-        return $request_params;
594
-    }
595
-
596
-
597
-    /**
598
-     * @param array $props_n_values
599
-     * @return bool
600
-     * @throws EE_Error
601
-     * @throws InvalidArgumentException
602
-     * @throws InvalidDataTypeException
603
-     * @throws InvalidInterfaceException
604
-     */
605
-    public static function save_new_state_to_db($props_n_values = array())
606
-    {
607
-        $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
608
-        if (! empty($existing_state)) {
609
-            return array_pop($existing_state);
610
-        }
611
-        $new_state = EE_State::new_instance($props_n_values);
612
-        if ($new_state instanceof EE_State) {
613
-            $country_settings_url = add_query_arg(
614
-                array(
615
-                    'page'    => 'espresso_general_settings',
616
-                    'action'  => 'country_settings',
617
-                    'country' => $new_state->country_iso(),
618
-                ),
619
-                admin_url('admin.php')
620
-            );
621
-            // if not non-ajax admin
622
-            new PersistentAdminNotice(
623
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
624
-                sprintf(
625
-                    esc_html__(
626
-                        'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
627
-                        'event_espresso'
628
-                    ),
629
-                    '<b>' . $new_state->name() . '</b>',
630
-                    '<b>' . $new_state->abbrev() . '</b>',
631
-                    '<b>' . $new_state->country()->name() . '</b>',
632
-                    '<a href="'
633
-                    . $country_settings_url
634
-                    . '">'
635
-                    . esc_html__(
636
-                        'Event Espresso - General Settings > Countries Tab',
637
-                        'event_espresso'
638
-                    )
639
-                    . '</a>',
640
-                    '<br />'
641
-                )
642
-            );
643
-            $new_state->save();
644
-            EEM_State::instance()->reset_cached_states();
645
-            return $new_state;
646
-        }
647
-        return false;
648
-    }
649
-
650
-
651
-    /**
652
-     * @param string $CNT_ISO
653
-     * @param string $STA_ID
654
-     * @param array  $cols_n_values
655
-     * @return void
656
-     * @throws DomainException
657
-     * @throws EE_Error
658
-     * @throws InvalidArgumentException
659
-     * @throws InvalidDataTypeException
660
-     * @throws InvalidInterfaceException
661
-     */
662
-    public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
663
-    {
664
-        if (! $CNT_ISO) {
665
-            EE_Error::add_error(
666
-                esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
667
-                __FILE__,
668
-                __FUNCTION__,
669
-                __LINE__
670
-            );
671
-        }
672
-        $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
673
-            : false;
674
-        if (! $STA_abbrev && ! empty($STA_ID)) {
675
-            $state = EEM_State::instance()->get_one_by_ID($STA_ID);
676
-            if ($state instanceof EE_State) {
677
-                $STA_abbrev = $state->abbrev();
678
-            }
679
-        }
680
-        if (! $STA_abbrev) {
681
-            EE_Error::add_error(
682
-                esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
683
-                __FILE__,
684
-                __FUNCTION__,
685
-                __LINE__
686
-            );
687
-        }
688
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
689
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
690
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
691
-        );
692
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
693
-    }
694
-
695
-
696
-    /**
697
-     * @param EE_State[]                            $state_options
698
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
699
-     * @param EE_Registration                       $registration
700
-     * @param EE_Question                           $question
701
-     * @param                                       $answer
702
-     * @return array
703
-     * @throws EE_Error
704
-     * @throws InvalidArgumentException
705
-     * @throws InvalidDataTypeException
706
-     * @throws InvalidInterfaceException
707
-     */
708
-    public static function inject_new_reg_state_into_options(
709
-        $state_options = array(),
710
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
711
-        EE_Registration $registration,
712
-        EE_Question $question,
713
-        $answer
714
-    ) {
715
-        if (
716
-            $answer instanceof EE_Answer && $question instanceof EE_Question
717
-            && $question->type() === EEM_Question::QST_type_state
718
-        ) {
719
-            $STA_ID = $answer->value();
720
-            if (! empty($STA_ID)) {
721
-                $state = EEM_State::instance()->get_one_by_ID($STA_ID);
722
-                if ($state instanceof EE_State) {
723
-                    $country = $state->country();
724
-                    if ($country instanceof EE_Country) {
725
-                        if (! isset($state_options[ $country->name() ])) {
726
-                            $state_options[ $country->name() ] = array();
727
-                        }
728
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
729
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
730
-                        }
731
-                    }
732
-                }
733
-            }
734
-        }
735
-        return $state_options;
736
-    }
737
-
738
-
739
-    /**
740
-     * @param EE_Country[]                          $country_options
741
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
742
-     * @param EE_Registration                       $registration
743
-     * @param EE_Question                           $question
744
-     * @param                                       $answer
745
-     * @return array
746
-     * @throws EE_Error
747
-     * @throws InvalidArgumentException
748
-     * @throws InvalidDataTypeException
749
-     * @throws InvalidInterfaceException
750
-     */
751
-    public static function inject_new_reg_country_into_options(
752
-        $country_options = array(),
753
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
754
-        EE_Registration $registration,
755
-        EE_Question $question,
756
-        $answer
757
-    ) {
758
-        if (
759
-            $answer instanceof EE_Answer && $question instanceof EE_Question
760
-            && $question->type()
761
-               === EEM_Question::QST_type_country
762
-        ) {
763
-            $CNT_ISO = $answer->value();
764
-            if (! empty($CNT_ISO)) {
765
-                $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
766
-                if ($country instanceof EE_Country) {
767
-                    if (! isset($country_options[ $CNT_ISO ])) {
768
-                        $country_options[ $CNT_ISO ] = $country->name();
769
-                    }
770
-                }
771
-            }
772
-        }
773
-        return $country_options;
774
-    }
775
-
776
-
777
-    /**
778
-     * @param EE_State[] $state_options
779
-     * @return array
780
-     * @throws EE_Error
781
-     * @throws InvalidArgumentException
782
-     * @throws InvalidDataTypeException
783
-     * @throws InvalidInterfaceException
784
-     */
785
-    public static function state_options($state_options = array())
786
-    {
787
-        $new_states = EED_Add_New_State::_get_new_states();
788
-        foreach ($new_states as $new_state) {
789
-            if (
790
-                $new_state instanceof EE_State
791
-                && $new_state->country() instanceof EE_Country
792
-            ) {
793
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
794
-            }
795
-        }
796
-        return $state_options;
797
-    }
798
-
799
-
800
-    /**
801
-     * @return array
802
-     * @throws InvalidArgumentException
803
-     * @throws InvalidDataTypeException
804
-     * @throws InvalidInterfaceException
805
-     */
806
-    protected static function _get_new_states()
807
-    {
808
-        $new_states = array();
809
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
810
-            $new_states = EE_Registry::instance()->SSN->get_session_data(
811
-                'nsmf_new_states'
812
-            );
813
-        }
814
-        return is_array($new_states) ? $new_states : array();
815
-    }
816
-
817
-
818
-    /**
819
-     * @param EE_Country[] $country_options
820
-     * @return array
821
-     * @throws EE_Error
822
-     * @throws InvalidArgumentException
823
-     * @throws InvalidDataTypeException
824
-     * @throws InvalidInterfaceException
825
-     */
826
-    public static function country_options($country_options = array())
827
-    {
828
-        $new_states = EED_Add_New_State::_get_new_states();
829
-        foreach ($new_states as $new_state) {
830
-            if (
831
-                $new_state instanceof EE_State
832
-                && $new_state->country() instanceof EE_Country
833
-            ) {
834
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
835
-            }
836
-        }
837
-        return $country_options;
838
-    }
20
+	/**
21
+	 * @return EED_Module|EED_Add_New_State
22
+	 */
23
+	public static function instance()
24
+	{
25
+		return parent::get_instance(__CLASS__);
26
+	}
27
+
28
+
29
+	/**
30
+	 * set_hooks - for hooking into EE Core, other modules, etc
31
+	 *
32
+	 * @return void
33
+	 */
34
+	public static function set_hooks()
35
+	{
36
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
37
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
38
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
39
+		add_filter(
40
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
41
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
42
+			1,
43
+			1
44
+		);
45
+		add_filter(
46
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
47
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
48
+			1,
49
+			1
50
+		);
51
+		add_filter(
52
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
53
+			array('EED_Add_New_State', 'unset_new_state_request_params'),
54
+			10,
55
+			1
56
+		);
57
+		add_filter(
58
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
59
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
60
+			10,
61
+			5
62
+		);
63
+		add_filter(
64
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
65
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
66
+			10,
67
+			5
68
+		);
69
+		add_filter(
70
+			'FHEE__EE_State_Select_Input____construct__state_options',
71
+			array('EED_Add_New_State', 'state_options'),
72
+			10,
73
+			1
74
+		);
75
+		add_filter(
76
+			'FHEE__EE_Country_Select_Input____construct__country_options',
77
+			array('EED_Add_New_State', 'country_options'),
78
+			10,
79
+			1
80
+		);
81
+	}
82
+
83
+
84
+	/**
85
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
86
+	 *
87
+	 * @return void
88
+	 */
89
+	public static function set_hooks_admin()
90
+	{
91
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
92
+		add_filter(
93
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
94
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
95
+			1,
96
+			1
97
+		);
98
+		add_filter(
99
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
100
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
101
+			1,
102
+			1
103
+		);
104
+		add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
105
+		add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
106
+		add_filter(
107
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
108
+			array('EED_Add_New_State', 'unset_new_state_request_params'),
109
+			10,
110
+			1
111
+		);
112
+		add_action(
113
+			'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
114
+			array('EED_Add_New_State', 'update_country_settings'),
115
+			10,
116
+			3
117
+		);
118
+		add_action(
119
+			'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
120
+			array('EED_Add_New_State', 'update_country_settings'),
121
+			10,
122
+			3
123
+		);
124
+		add_filter(
125
+			'FHEE__EE_State_Select_Input____construct__state_options',
126
+			array('EED_Add_New_State', 'state_options'),
127
+			10,
128
+			1
129
+		);
130
+		add_filter(
131
+			'FHEE__EE_Country_Select_Input____construct__country_options',
132
+			array('EED_Add_New_State', 'country_options'),
133
+			10,
134
+			1
135
+		);
136
+		add_filter(
137
+			'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
138
+			array('EED_Add_New_State', 'filter_checkout_request_params'),
139
+			10,
140
+			1
141
+		);
142
+		add_filter(
143
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
144
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
145
+			10,
146
+			5
147
+		);
148
+		add_filter(
149
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
150
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
151
+			10,
152
+			5
153
+		);
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return void
159
+	 */
160
+	public static function set_definitions()
161
+	{
162
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
163
+		define(
164
+			'ANS_TEMPLATES_PATH',
165
+			str_replace(
166
+				'\\',
167
+				'/',
168
+				plugin_dir_path(__FILE__)
169
+			) . 'templates/'
170
+		);
171
+	}
172
+
173
+
174
+	/**
175
+	 * @param WP $WP
176
+	 * @return void
177
+	 */
178
+	public function run($WP)
179
+	{
180
+	}
181
+
182
+
183
+	/**
184
+	 * @return void
185
+	 */
186
+	public static function translate_js_strings()
187
+	{
188
+		EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
189
+			'In order to proceed, you need to select the Country that your State/Province belongs to.',
190
+			'event_espresso'
191
+		);
192
+		EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
193
+			'In order to proceed, you need to enter the name of your State/Province.',
194
+			'event_espresso'
195
+		);
196
+		EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
197
+			'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
198
+			'event_espresso'
199
+		);
200
+		EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
201
+			'The new state was successfully saved to the database.',
202
+			'event_espresso'
203
+		);
204
+		EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
205
+			'An unknown error has occurred on the server while saving the new state to the database.',
206
+			'event_espresso'
207
+		);
208
+	}
209
+
210
+
211
+	/**
212
+	 * @return void
213
+	 */
214
+	public static function wp_enqueue_scripts()
215
+	{
216
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217
+			wp_register_script(
218
+				'add_new_state',
219
+				ANS_ASSETS_URL . 'add_new_state.js',
220
+				array('espresso_core', 'single_page_checkout'),
221
+				EVENT_ESPRESSO_VERSION,
222
+				true
223
+			);
224
+			wp_enqueue_script('add_new_state');
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * display_add_new_state_micro_form
232
+	 *
233
+	 * @param EE_Form_Section_Proper $question_group_reg_form
234
+	 * @return string
235
+	 * @throws EE_Error
236
+	 * @throws InvalidArgumentException
237
+	 * @throws InvalidDataTypeException
238
+	 * @throws InvalidInterfaceException
239
+	 */
240
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
241
+	{
242
+		// only add the 'new_state_micro_form' when displaying reg forms,
243
+		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
+		$action = EE_Registry::instance()->REQ->get('action', '');
245
+		// is the "state" question in this form section?
246
+		$input = $question_group_reg_form->get_subsection('state');
247
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
+			// ok then all we need to do is make sure the input's HTML name is consistent
249
+			// by forcing it to set it now, like it did while getting the form for display
250
+			if ($input instanceof EE_State_Select_Input) {
251
+				$input->html_name();
252
+			}
253
+			return $question_group_reg_form;
254
+		}
255
+		// we're only doing this for state select inputs
256
+		if (
257
+			$input instanceof EE_State_Select_Input
258
+			&& ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
259
+		) {
260
+			// grab any set values from the request
261
+			$country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
262
+			$state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
263
+			$abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
264
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
265
+			$country_options = array();
266
+			$countries = EEM_Country::instance()->get_all_countries();
267
+			if (! empty($countries)) {
268
+				foreach ($countries as $country) {
269
+					if ($country instanceof EE_Country) {
270
+						$country_options[ $country->ID() ] = $country->name();
271
+					}
272
+				}
273
+			}
274
+			$new_state_micro_form = new EE_Form_Section_Proper(
275
+				array(
276
+					'name'            => 'new_state_micro_form',
277
+					'html_id'         => 'new_state_micro_form',
278
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
279
+					'subsections'     => array(
280
+						// add hidden input to indicate that a new state is being added
281
+						'add_new_state'               => new EE_Hidden_Input(
282
+							array(
283
+								'html_name' => str_replace(
284
+									'state',
285
+									'nsmf_add_new_state',
286
+									$input->html_name()
287
+								),
288
+								'html_id'   => str_replace(
289
+									'state',
290
+									'nsmf_add_new_state',
291
+									$input->html_id()
292
+								),
293
+								'default'   => 0,
294
+							)
295
+						),
296
+						// add link for displaying hidden container
297
+						'click_here_link'             => new EE_Form_Section_HTML(
298
+							apply_filters(
299
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
300
+								EEH_HTML::link(
301
+									'',
302
+									esc_html__('click here to add a new state/province', 'event_espresso'),
303
+									'',
304
+									'display-' . $input->html_id(),
305
+									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
306
+									'',
307
+									'data-target="' . $input->html_id() . '"'
308
+								)
309
+							)
310
+						),
311
+						// add initial html for hidden container
312
+						'add_new_state_micro_form'    => new EE_Form_Section_HTML(
313
+							apply_filters(
314
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
315
+								EEH_HTML::div(
316
+									'',
317
+									$input->html_id() . '-dv',
318
+									'ee-form-add-new-state-dv',
319
+									'display: none;'
320
+								) .
321
+								EEH_HTML::h6(
322
+									esc_html__(
323
+										'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
324
+										'event_espresso'
325
+									)
326
+								) .
327
+								EEH_HTML::ul() .
328
+								EEH_HTML::li(
329
+									esc_html__(
330
+										'first select the Country that your State/Province belongs to',
331
+										'event_espresso'
332
+									)
333
+								) .
334
+								EEH_HTML::li(
335
+									esc_html__('enter the name of your State/Province', 'event_espresso')
336
+								) .
337
+								EEH_HTML::li(
338
+									esc_html__(
339
+										'enter a two to six letter abbreviation for the name of your State/Province',
340
+										'event_espresso'
341
+									)
342
+								) .
343
+								EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
344
+								EEH_HTML::ulx()
345
+							)
346
+						),
347
+						// NEW STATE COUNTRY
348
+						'new_state_country'           => new EE_Country_Select_Input(
349
+							$country_options,
350
+							array(
351
+								'html_name'       => $country_name,
352
+								'html_id'         => str_replace(
353
+									'state',
354
+									'nsmf_new_state_country',
355
+									$input->html_id()
356
+								),
357
+								'html_class'      => $input->html_class() . ' new-state-country',
358
+								'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
359
+								'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
360
+								'required'        => false,
361
+							)
362
+						),
363
+						// NEW STATE NAME
364
+						'new_state_name'              => new EE_Text_Input(
365
+							array(
366
+								'html_name'       => $state_name,
367
+								'html_id'         => str_replace(
368
+									'state',
369
+									'nsmf_new_state_name',
370
+									$input->html_id()
371
+								),
372
+								'html_class'      => $input->html_class() . ' new-state-state',
373
+								'html_label_text' => esc_html__(
374
+									'New State/Province Name',
375
+									'event_espresso'
376
+								),
377
+								'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
378
+								'required'        => false,
379
+							)
380
+						),
381
+						'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
382
+						// NEW STATE NAME
383
+						'new_state_abbrv'             => new EE_Text_Input(
384
+							array(
385
+								'html_name'             => $abbrv_name,
386
+								'html_id'               => str_replace(
387
+									'state',
388
+									'nsmf_new_state_abbrv',
389
+									$input->html_id()
390
+								),
391
+								'html_class'            => $input->html_class() . ' new-state-abbrv',
392
+								'html_label_text'       => esc_html__(
393
+									'New State/Province Abbreviation',
394
+									'event_espresso'
395
+								) . ' *',
396
+								'other_html_attributes' => 'size="24"',
397
+								'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
398
+								'required'              => false,
399
+							)
400
+						),
401
+						// "submit" button
402
+						'add_new_state_submit_button' => new EE_Form_Section_HTML(
403
+							apply_filters(
404
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
405
+								EEH_HTML::nbsp(3) .
406
+								EEH_HTML::link(
407
+									'',
408
+									esc_html__('ADD', 'event_espresso'),
409
+									'',
410
+									'submit-' . $new_state_submit_id,
411
+									'ee-form-add-new-state-submit button button-secondary',
412
+									'',
413
+									'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName() . '"'
414
+								)
415
+							)
416
+						),
417
+						// extra info
418
+						'add_new_state_extra'         => new EE_Form_Section_HTML(
419
+							apply_filters(
420
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
421
+								EEH_HTML::br(2)
422
+								.
423
+								EEH_HTML::div('', '', 'small-text')
424
+								.
425
+								EEH_HTML::strong(
426
+									'* ' .
427
+									esc_html__(
428
+										'Don\'t know your State/Province Abbreviation?',
429
+										'event_espresso'
430
+									)
431
+								)
432
+								.
433
+								EEH_HTML::br()
434
+								.
435
+								sprintf(
436
+									esc_html__(
437
+										'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
438
+										'event_espresso'
439
+									),
440
+									EEH_HTML::link(
441
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
442
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
443
+										'',
444
+										'',
445
+										'ee-form-add-new-state-wiki-lnk',
446
+										'',
447
+										'target="_blank"'
448
+									)
449
+								)
450
+								.
451
+								EEH_HTML::divx()
452
+								.
453
+								EEH_HTML::br()
454
+								.
455
+								EEH_HTML::link(
456
+									'',
457
+									esc_html__('cancel new State/Province', 'event_espresso'),
458
+									'',
459
+									'hide-' . $input->html_id(),
460
+									'ee-form-cancel-new-state-lnk smaller-text',
461
+									'',
462
+									'data-target="' . $input->html_id() . '"'
463
+								)
464
+								.
465
+								EEH_HTML::divx()
466
+								.
467
+								EEH_HTML::br()
468
+							)
469
+						),
470
+					),
471
+				)
472
+			);
473
+			$question_group_reg_form->add_subsections(
474
+				array('new_state_micro_form' => $new_state_micro_form),
475
+				'state',
476
+				false
477
+			);
478
+		}
479
+		return $question_group_reg_form;
480
+	}
481
+
482
+
483
+	/**
484
+	 * set_new_state_input_width
485
+	 *
486
+	 * @return int|string
487
+	 * @throws EE_Error
488
+	 * @throws InvalidArgumentException
489
+	 * @throws InvalidDataTypeException
490
+	 * @throws InvalidInterfaceException
491
+	 * @throws ReflectionException
492
+	 */
493
+	public static function add_new_state()
494
+	{
495
+		$REQ = EE_Registry::instance()->load_core('Request_Handler');
496
+		if (absint($REQ->get('nsmf_add_new_state')) === 1) {
497
+			EE_Registry::instance()->load_model('State');
498
+			// grab country ISO code, new state name, and new state abbreviation
499
+			$state_country = $REQ->is_set('nsmf_new_state_country')
500
+				? sanitize_text_field($REQ->get('nsmf_new_state_country'))
501
+				: false;
502
+			$state_name = $REQ->is_set('nsmf_new_state_name')
503
+				? sanitize_text_field($REQ->get('nsmf_new_state_name'))
504
+				: false;
505
+			$state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
506
+				? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
507
+				: false;
508
+			if ($state_country && $state_name && $state_abbr) {
509
+				$new_state = EED_Add_New_State::save_new_state_to_db(
510
+					array(
511
+						'CNT_ISO'    => strtoupper($state_country),
512
+						'STA_abbrev' => strtoupper($state_abbr),
513
+						'STA_name'   => ucwords($state_name),
514
+						'STA_active' => false,
515
+					)
516
+				);
517
+				if ($new_state instanceof EE_State) {
518
+					// clean house
519
+					EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
520
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
521
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
522
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
523
+					// get any existing new states
524
+					$new_states = EE_Registry::instance()->SSN->get_session_data(
525
+						'nsmf_new_states'
526
+					);
527
+					$new_states[ $new_state->ID() ] = $new_state;
528
+					EE_Registry::instance()->SSN->set_session_data(
529
+						array('nsmf_new_states' => $new_states)
530
+					);
531
+					if (EE_Registry::instance()->REQ->ajax) {
532
+						echo wp_json_encode(
533
+							array(
534
+								'success'      => true,
535
+								'id'           => $new_state->ID(),
536
+								'name'         => $new_state->name(),
537
+								'abbrev'       => $new_state->abbrev(),
538
+								'country_iso'  => $new_state->country_iso(),
539
+								'country_name' => $new_state->country()->name(),
540
+							)
541
+						);
542
+						exit();
543
+					}
544
+					return $new_state->ID();
545
+				}
546
+			} else {
547
+				$error = esc_html__(
548
+					'A new State/Province could not be added because invalid or missing data was received.',
549
+					'event_espresso'
550
+				);
551
+				if (EE_Registry::instance()->REQ->ajax) {
552
+					echo wp_json_encode(array('error' => $error));
553
+					exit();
554
+				}
555
+				EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
556
+			}
557
+		}
558
+		return false;
559
+	}
560
+
561
+
562
+	/**
563
+	 * recursively drills down through request params to remove any that were added by this module
564
+	 *
565
+	 * @param array $request_params
566
+	 * @return array
567
+	 */
568
+	public static function filter_checkout_request_params($request_params)
569
+	{
570
+		foreach ($request_params as $form_section) {
571
+			if (is_array($form_section)) {
572
+				EED_Add_New_State::unset_new_state_request_params($form_section);
573
+				EED_Add_New_State::filter_checkout_request_params($form_section);
574
+			}
575
+		}
576
+		return $request_params;
577
+	}
578
+
579
+
580
+	/**
581
+	 * @param array $request_params
582
+	 * @return array
583
+	 */
584
+	public static function unset_new_state_request_params($request_params)
585
+	{
586
+		unset(
587
+			$request_params['new_state_micro_form'],
588
+			$request_params['new_state_micro_add_new_state'],
589
+			$request_params['new_state_micro_new_state_country'],
590
+			$request_params['new_state_micro_new_state_name'],
591
+			$request_params['new_state_micro_new_state_abbrv']
592
+		);
593
+		return $request_params;
594
+	}
595
+
596
+
597
+	/**
598
+	 * @param array $props_n_values
599
+	 * @return bool
600
+	 * @throws EE_Error
601
+	 * @throws InvalidArgumentException
602
+	 * @throws InvalidDataTypeException
603
+	 * @throws InvalidInterfaceException
604
+	 */
605
+	public static function save_new_state_to_db($props_n_values = array())
606
+	{
607
+		$existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
608
+		if (! empty($existing_state)) {
609
+			return array_pop($existing_state);
610
+		}
611
+		$new_state = EE_State::new_instance($props_n_values);
612
+		if ($new_state instanceof EE_State) {
613
+			$country_settings_url = add_query_arg(
614
+				array(
615
+					'page'    => 'espresso_general_settings',
616
+					'action'  => 'country_settings',
617
+					'country' => $new_state->country_iso(),
618
+				),
619
+				admin_url('admin.php')
620
+			);
621
+			// if not non-ajax admin
622
+			new PersistentAdminNotice(
623
+				'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
624
+				sprintf(
625
+					esc_html__(
626
+						'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
627
+						'event_espresso'
628
+					),
629
+					'<b>' . $new_state->name() . '</b>',
630
+					'<b>' . $new_state->abbrev() . '</b>',
631
+					'<b>' . $new_state->country()->name() . '</b>',
632
+					'<a href="'
633
+					. $country_settings_url
634
+					. '">'
635
+					. esc_html__(
636
+						'Event Espresso - General Settings > Countries Tab',
637
+						'event_espresso'
638
+					)
639
+					. '</a>',
640
+					'<br />'
641
+				)
642
+			);
643
+			$new_state->save();
644
+			EEM_State::instance()->reset_cached_states();
645
+			return $new_state;
646
+		}
647
+		return false;
648
+	}
649
+
650
+
651
+	/**
652
+	 * @param string $CNT_ISO
653
+	 * @param string $STA_ID
654
+	 * @param array  $cols_n_values
655
+	 * @return void
656
+	 * @throws DomainException
657
+	 * @throws EE_Error
658
+	 * @throws InvalidArgumentException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws InvalidInterfaceException
661
+	 */
662
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
663
+	{
664
+		if (! $CNT_ISO) {
665
+			EE_Error::add_error(
666
+				esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
667
+				__FILE__,
668
+				__FUNCTION__,
669
+				__LINE__
670
+			);
671
+		}
672
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
673
+			: false;
674
+		if (! $STA_abbrev && ! empty($STA_ID)) {
675
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
676
+			if ($state instanceof EE_State) {
677
+				$STA_abbrev = $state->abbrev();
678
+			}
679
+		}
680
+		if (! $STA_abbrev) {
681
+			EE_Error::add_error(
682
+				esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
683
+				__FILE__,
684
+				__FUNCTION__,
685
+				__LINE__
686
+			);
687
+		}
688
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
689
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
690
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
691
+		);
692
+		$persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
693
+	}
694
+
695
+
696
+	/**
697
+	 * @param EE_State[]                            $state_options
698
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
699
+	 * @param EE_Registration                       $registration
700
+	 * @param EE_Question                           $question
701
+	 * @param                                       $answer
702
+	 * @return array
703
+	 * @throws EE_Error
704
+	 * @throws InvalidArgumentException
705
+	 * @throws InvalidDataTypeException
706
+	 * @throws InvalidInterfaceException
707
+	 */
708
+	public static function inject_new_reg_state_into_options(
709
+		$state_options = array(),
710
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
711
+		EE_Registration $registration,
712
+		EE_Question $question,
713
+		$answer
714
+	) {
715
+		if (
716
+			$answer instanceof EE_Answer && $question instanceof EE_Question
717
+			&& $question->type() === EEM_Question::QST_type_state
718
+		) {
719
+			$STA_ID = $answer->value();
720
+			if (! empty($STA_ID)) {
721
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
722
+				if ($state instanceof EE_State) {
723
+					$country = $state->country();
724
+					if ($country instanceof EE_Country) {
725
+						if (! isset($state_options[ $country->name() ])) {
726
+							$state_options[ $country->name() ] = array();
727
+						}
728
+						if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
729
+							$state_options[ $country->name() ][ $STA_ID ] = $state->name();
730
+						}
731
+					}
732
+				}
733
+			}
734
+		}
735
+		return $state_options;
736
+	}
737
+
738
+
739
+	/**
740
+	 * @param EE_Country[]                          $country_options
741
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
742
+	 * @param EE_Registration                       $registration
743
+	 * @param EE_Question                           $question
744
+	 * @param                                       $answer
745
+	 * @return array
746
+	 * @throws EE_Error
747
+	 * @throws InvalidArgumentException
748
+	 * @throws InvalidDataTypeException
749
+	 * @throws InvalidInterfaceException
750
+	 */
751
+	public static function inject_new_reg_country_into_options(
752
+		$country_options = array(),
753
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
754
+		EE_Registration $registration,
755
+		EE_Question $question,
756
+		$answer
757
+	) {
758
+		if (
759
+			$answer instanceof EE_Answer && $question instanceof EE_Question
760
+			&& $question->type()
761
+			   === EEM_Question::QST_type_country
762
+		) {
763
+			$CNT_ISO = $answer->value();
764
+			if (! empty($CNT_ISO)) {
765
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
766
+				if ($country instanceof EE_Country) {
767
+					if (! isset($country_options[ $CNT_ISO ])) {
768
+						$country_options[ $CNT_ISO ] = $country->name();
769
+					}
770
+				}
771
+			}
772
+		}
773
+		return $country_options;
774
+	}
775
+
776
+
777
+	/**
778
+	 * @param EE_State[] $state_options
779
+	 * @return array
780
+	 * @throws EE_Error
781
+	 * @throws InvalidArgumentException
782
+	 * @throws InvalidDataTypeException
783
+	 * @throws InvalidInterfaceException
784
+	 */
785
+	public static function state_options($state_options = array())
786
+	{
787
+		$new_states = EED_Add_New_State::_get_new_states();
788
+		foreach ($new_states as $new_state) {
789
+			if (
790
+				$new_state instanceof EE_State
791
+				&& $new_state->country() instanceof EE_Country
792
+			) {
793
+				$state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
794
+			}
795
+		}
796
+		return $state_options;
797
+	}
798
+
799
+
800
+	/**
801
+	 * @return array
802
+	 * @throws InvalidArgumentException
803
+	 * @throws InvalidDataTypeException
804
+	 * @throws InvalidInterfaceException
805
+	 */
806
+	protected static function _get_new_states()
807
+	{
808
+		$new_states = array();
809
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
810
+			$new_states = EE_Registry::instance()->SSN->get_session_data(
811
+				'nsmf_new_states'
812
+			);
813
+		}
814
+		return is_array($new_states) ? $new_states : array();
815
+	}
816
+
817
+
818
+	/**
819
+	 * @param EE_Country[] $country_options
820
+	 * @return array
821
+	 * @throws EE_Error
822
+	 * @throws InvalidArgumentException
823
+	 * @throws InvalidDataTypeException
824
+	 * @throws InvalidInterfaceException
825
+	 */
826
+	public static function country_options($country_options = array())
827
+	{
828
+		$new_states = EED_Add_New_State::_get_new_states();
829
+		foreach ($new_states as $new_state) {
830
+			if (
831
+				$new_state instanceof EE_State
832
+				&& $new_state->country() instanceof EE_Country
833
+			) {
834
+				$country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
835
+			}
836
+		}
837
+		return $country_options;
838
+	}
839 839
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public static function set_definitions()
161 161
     {
162
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
162
+        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
163 163
         define(
164 164
             'ANS_TEMPLATES_PATH',
165 165
             str_replace(
166 166
                 '\\',
167 167
                 '/',
168 168
                 plugin_dir_path(__FILE__)
169
-            ) . 'templates/'
169
+            ).'templates/'
170 170
         );
171 171
     }
172 172
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217 217
             wp_register_script(
218 218
                 'add_new_state',
219
-                ANS_ASSETS_URL . 'add_new_state.js',
219
+                ANS_ASSETS_URL.'add_new_state.js',
220 220
                 array('espresso_core', 'single_page_checkout'),
221 221
                 EVENT_ESPRESSO_VERSION,
222 222
                 true
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
             $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
265 265
             $country_options = array();
266 266
             $countries = EEM_Country::instance()->get_all_countries();
267
-            if (! empty($countries)) {
267
+            if ( ! empty($countries)) {
268 268
                 foreach ($countries as $country) {
269 269
                     if ($country instanceof EE_Country) {
270
-                        $country_options[ $country->ID() ] = $country->name();
270
+                        $country_options[$country->ID()] = $country->name();
271 271
                     }
272 272
                 }
273 273
             }
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
                                     '',
302 302
                                     esc_html__('click here to add a new state/province', 'event_espresso'),
303 303
                                     '',
304
-                                    'display-' . $input->html_id(),
304
+                                    'display-'.$input->html_id(),
305 305
                                     'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
306 306
                                     '',
307
-                                    'data-target="' . $input->html_id() . '"'
307
+                                    'data-target="'.$input->html_id().'"'
308 308
                                 )
309 309
                             )
310 310
                         ),
@@ -314,33 +314,33 @@  discard block
 block discarded – undo
314 314
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
315 315
                                 EEH_HTML::div(
316 316
                                     '',
317
-                                    $input->html_id() . '-dv',
317
+                                    $input->html_id().'-dv',
318 318
                                     'ee-form-add-new-state-dv',
319 319
                                     'display: none;'
320
-                                ) .
320
+                                ).
321 321
                                 EEH_HTML::h6(
322 322
                                     esc_html__(
323 323
                                         'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
324 324
                                         'event_espresso'
325 325
                                     )
326
-                                ) .
327
-                                EEH_HTML::ul() .
326
+                                ).
327
+                                EEH_HTML::ul().
328 328
                                 EEH_HTML::li(
329 329
                                     esc_html__(
330 330
                                         'first select the Country that your State/Province belongs to',
331 331
                                         'event_espresso'
332 332
                                     )
333
-                                ) .
333
+                                ).
334 334
                                 EEH_HTML::li(
335 335
                                     esc_html__('enter the name of your State/Province', 'event_espresso')
336
-                                ) .
336
+                                ).
337 337
                                 EEH_HTML::li(
338 338
                                     esc_html__(
339 339
                                         'enter a two to six letter abbreviation for the name of your State/Province',
340 340
                                         'event_espresso'
341 341
                                     )
342
-                                ) .
343
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
342
+                                ).
343
+                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')).
344 344
                                 EEH_HTML::ulx()
345 345
                             )
346 346
                         ),
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
                                     'nsmf_new_state_country',
355 355
                                     $input->html_id()
356 356
                                 ),
357
-                                'html_class'      => $input->html_class() . ' new-state-country',
357
+                                'html_class'      => $input->html_class().' new-state-country',
358 358
                                 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
359 359
                                 'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
360 360
                                 'required'        => false,
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                                     'nsmf_new_state_name',
370 370
                                     $input->html_id()
371 371
                                 ),
372
-                                'html_class'      => $input->html_class() . ' new-state-state',
372
+                                'html_class'      => $input->html_class().' new-state-state',
373 373
                                 'html_label_text' => esc_html__(
374 374
                                     'New State/Province Name',
375 375
                                     'event_espresso'
@@ -388,11 +388,11 @@  discard block
 block discarded – undo
388 388
                                     'nsmf_new_state_abbrv',
389 389
                                     $input->html_id()
390 390
                                 ),
391
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
391
+                                'html_class'            => $input->html_class().' new-state-abbrv',
392 392
                                 'html_label_text'       => esc_html__(
393 393
                                     'New State/Province Abbreviation',
394 394
                                     'event_espresso'
395
-                                ) . ' *',
395
+                                ).' *',
396 396
                                 'other_html_attributes' => 'size="24"',
397 397
                                 'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
398 398
                                 'required'              => false,
@@ -402,15 +402,15 @@  discard block
 block discarded – undo
402 402
                         'add_new_state_submit_button' => new EE_Form_Section_HTML(
403 403
                             apply_filters(
404 404
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
405
-                                EEH_HTML::nbsp(3) .
405
+                                EEH_HTML::nbsp(3).
406 406
                                 EEH_HTML::link(
407 407
                                     '',
408 408
                                     esc_html__('ADD', 'event_espresso'),
409 409
                                     '',
410
-                                    'submit-' . $new_state_submit_id,
410
+                                    'submit-'.$new_state_submit_id,
411 411
                                     'ee-form-add-new-state-submit button button-secondary',
412 412
                                     '',
413
-                                    'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName() . '"'
413
+                                    'data-target="'.$new_state_submit_id.'" data-value-field-name="'.$input->valueFieldName().'"'
414 414
                                 )
415 415
                             )
416 416
                         ),
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
                                 EEH_HTML::div('', '', 'small-text')
424 424
                                 .
425 425
                                 EEH_HTML::strong(
426
-                                    '* ' .
426
+                                    '* '.
427 427
                                     esc_html__(
428 428
                                         'Don\'t know your State/Province Abbreviation?',
429 429
                                         'event_espresso'
@@ -456,10 +456,10 @@  discard block
 block discarded – undo
456 456
                                     '',
457 457
                                     esc_html__('cancel new State/Province', 'event_espresso'),
458 458
                                     '',
459
-                                    'hide-' . $input->html_id(),
459
+                                    'hide-'.$input->html_id(),
460 460
                                     'ee-form-cancel-new-state-lnk smaller-text',
461 461
                                     '',
462
-                                    'data-target="' . $input->html_id() . '"'
462
+                                    'data-target="'.$input->html_id().'"'
463 463
                                 )
464 464
                                 .
465 465
                                 EEH_HTML::divx()
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
                     $new_states = EE_Registry::instance()->SSN->get_session_data(
525 525
                         'nsmf_new_states'
526 526
                     );
527
-                    $new_states[ $new_state->ID() ] = $new_state;
527
+                    $new_states[$new_state->ID()] = $new_state;
528 528
                     EE_Registry::instance()->SSN->set_session_data(
529 529
                         array('nsmf_new_states' => $new_states)
530 530
                     );
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
     public static function save_new_state_to_db($props_n_values = array())
606 606
     {
607 607
         $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
608
-        if (! empty($existing_state)) {
608
+        if ( ! empty($existing_state)) {
609 609
             return array_pop($existing_state);
610 610
         }
611 611
         $new_state = EE_State::new_instance($props_n_values);
@@ -620,15 +620,15 @@  discard block
 block discarded – undo
620 620
             );
621 621
             // if not non-ajax admin
622 622
             new PersistentAdminNotice(
623
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
623
+                'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(),
624 624
                 sprintf(
625 625
                     esc_html__(
626 626
                         'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
627 627
                         'event_espresso'
628 628
                     ),
629
-                    '<b>' . $new_state->name() . '</b>',
630
-                    '<b>' . $new_state->abbrev() . '</b>',
631
-                    '<b>' . $new_state->country()->name() . '</b>',
629
+                    '<b>'.$new_state->name().'</b>',
630
+                    '<b>'.$new_state->abbrev().'</b>',
631
+                    '<b>'.$new_state->country()->name().'</b>',
632 632
                     '<a href="'
633 633
                     . $country_settings_url
634 634
                     . '">'
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
      */
662 662
     public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
663 663
     {
664
-        if (! $CNT_ISO) {
664
+        if ( ! $CNT_ISO) {
665 665
             EE_Error::add_error(
666 666
                 esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
667 667
                 __FILE__,
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
         }
672 672
         $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
673 673
             : false;
674
-        if (! $STA_abbrev && ! empty($STA_ID)) {
674
+        if ( ! $STA_abbrev && ! empty($STA_ID)) {
675 675
             $state = EEM_State::instance()->get_one_by_ID($STA_ID);
676 676
             if ($state instanceof EE_State) {
677 677
                 $STA_abbrev = $state->abbrev();
678 678
             }
679 679
         }
680
-        if (! $STA_abbrev) {
680
+        if ( ! $STA_abbrev) {
681 681
             EE_Error::add_error(
682 682
                 esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
683 683
                 __FILE__,
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
         $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
690 690
             'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
691 691
         );
692
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
692
+        $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true);
693 693
     }
694 694
 
695 695
 
@@ -717,16 +717,16 @@  discard block
 block discarded – undo
717 717
             && $question->type() === EEM_Question::QST_type_state
718 718
         ) {
719 719
             $STA_ID = $answer->value();
720
-            if (! empty($STA_ID)) {
720
+            if ( ! empty($STA_ID)) {
721 721
                 $state = EEM_State::instance()->get_one_by_ID($STA_ID);
722 722
                 if ($state instanceof EE_State) {
723 723
                     $country = $state->country();
724 724
                     if ($country instanceof EE_Country) {
725
-                        if (! isset($state_options[ $country->name() ])) {
726
-                            $state_options[ $country->name() ] = array();
725
+                        if ( ! isset($state_options[$country->name()])) {
726
+                            $state_options[$country->name()] = array();
727 727
                         }
728
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
729
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
728
+                        if ( ! isset($state_options[$country->name()][$STA_ID])) {
729
+                            $state_options[$country->name()][$STA_ID] = $state->name();
730 730
                         }
731 731
                     }
732 732
                 }
@@ -761,11 +761,11 @@  discard block
 block discarded – undo
761 761
                === EEM_Question::QST_type_country
762 762
         ) {
763 763
             $CNT_ISO = $answer->value();
764
-            if (! empty($CNT_ISO)) {
764
+            if ( ! empty($CNT_ISO)) {
765 765
                 $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
766 766
                 if ($country instanceof EE_Country) {
767
-                    if (! isset($country_options[ $CNT_ISO ])) {
768
-                        $country_options[ $CNT_ISO ] = $country->name();
767
+                    if ( ! isset($country_options[$CNT_ISO])) {
768
+                        $country_options[$CNT_ISO] = $country->name();
769 769
                     }
770 770
                 }
771 771
             }
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
                 $new_state instanceof EE_State
791 791
                 && $new_state->country() instanceof EE_Country
792 792
             ) {
793
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
793
+                $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
794 794
             }
795 795
         }
796 796
         return $state_options;
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
                 $new_state instanceof EE_State
832 832
                 && $new_state->country() instanceof EE_Country
833 833
             ) {
834
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
834
+                $country_options[$new_state->country()->ID()] = $new_state->country()->name();
835 835
             }
836 836
         }
837 837
         return $country_options;
Please login to merge, or discard this patch.