Completed
Branch dependabot/npm_and_yarn/wordpr... (563a96)
by
unknown
57:01 queued 49:08
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   +722 added lines, -722 removed lines patch added patch discarded remove patch
@@ -18,182 +18,182 @@  discard block
 block discarded – undo
18 18
 
19 19
 
20 20
 
21
-    /**
22
-     * 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.
23
-     * This property gets set by the _set_default_message_types() method.
24
-     *
25
-     * @var array
26
-     */
27
-    protected $_default_message_types = array();
21
+	/**
22
+	 * 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.
23
+	 * This property gets set by the _set_default_message_types() method.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected $_default_message_types = array();
28 28
 
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * This property holds the message types that are valid for use with this messenger.
34
-     * It gets set by the _set_valid_message_types() method.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $_valid_message_types = array();
32
+	/**
33
+	 * This property holds the message types that are valid for use with this messenger.
34
+	 * It gets set by the _set_valid_message_types() method.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $_valid_message_types = array();
39 39
 
40 40
 
41 41
 
42
-    /**
43
-     * 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.
44
-     *
45
-     * 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).
46
-     *
47
-     * Array should be in this format:
48
-     *
49
-     * array(
50
-     *  'field_name(i.e.to)' => array(
51
-     *      '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).
52
-     *      '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.
53
-     *      '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.,
54
-     *      '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.
55
-     *  )
56
-     * )
57
-     *
58
-     * @var array
59
-     */
60
-    protected $_validator_config = array();
42
+	/**
43
+	 * 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.
44
+	 *
45
+	 * 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).
46
+	 *
47
+	 * Array should be in this format:
48
+	 *
49
+	 * array(
50
+	 *  'field_name(i.e.to)' => array(
51
+	 *      '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).
52
+	 *      '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.
53
+	 *      '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.,
54
+	 *      '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.
55
+	 *  )
56
+	 * )
57
+	 *
58
+	 * @var array
59
+	 */
60
+	protected $_validator_config = array();
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
-     * @var object
67
-     */
68
-    protected $_EEM_data;
64
+	/**
65
+	 * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
+	 * @var object
67
+	 */
68
+	protected $_EEM_data;
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * this property just holds an array of the various template refs.
74
-     * @var array
75
-     */
76
-    protected $_template_fields = array();
72
+	/**
73
+	 * this property just holds an array of the various template refs.
74
+	 * @var array
75
+	 */
76
+	protected $_template_fields = array();
77 77
 
78 78
 
79 79
 
80 80
 
81
-    /**
82
-     * This holds an array of the arguments used in parsing a template for the sender.
83
-     * @var array
84
-     */
85
-    protected $_template_args = array();
81
+	/**
82
+	 * This holds an array of the arguments used in parsing a template for the sender.
83
+	 * @var array
84
+	 */
85
+	protected $_template_args = array();
86 86
 
87 87
 
88 88
 
89 89
 
90 90
 
91 91
 
92
-    /**
93
-     * 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
94
-     *
95
-     * @protected
96
-     * @var array
97
-     */
98
-    protected $_test_settings_fields = array();
92
+	/**
93
+	 * 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
94
+	 *
95
+	 * @protected
96
+	 * @var array
97
+	 */
98
+	protected $_test_settings_fields = array();
99 99
 
100 100
 
101 101
 
102 102
 
103 103
 
104 104
 
105
-    /**
106
-     * 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.
107
-     *
108
-     * @since 4.5.0
109
-     *
110
-     * @var EE_Messages_Template_Pack
111
-     */
112
-    protected $_tmp_pack;
105
+	/**
106
+	 * 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.
107
+	 *
108
+	 * @since 4.5.0
109
+	 *
110
+	 * @var EE_Messages_Template_Pack
111
+	 */
112
+	protected $_tmp_pack;
113 113
 
114 114
 
115 115
 
116 116
 
117
-    /**
118
-     * 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.
119
-     *
120
-     * @since 4.5.0
121
-     *
122
-     * @var string
123
-     */
124
-    protected $_variation;
117
+	/**
118
+	 * 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.
119
+	 *
120
+	 * @since 4.5.0
121
+	 *
122
+	 * @var string
123
+	 */
124
+	protected $_variation;
125 125
 
126 126
 
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * 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:
132
-     *
133
-     *  - template pack
134
-     *  - template variation
135
-     *
136
-     * @since 4.5.0
137
-     *
138
-     * @var stdClass
139
-     */
140
-    protected $_supports_labels;
130
+	/**
131
+	 * 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:
132
+	 *
133
+	 *  - template pack
134
+	 *  - template variation
135
+	 *
136
+	 * @since 4.5.0
137
+	 *
138
+	 * @var stdClass
139
+	 */
140
+	protected $_supports_labels;
141 141
 
142 142
 
143 143
 
144 144
 
145 145
 
146
-    /**
147
-     * 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.
148
-     *
149
-     * @var EE_message_type
150
-     */
151
-    protected $_incoming_message_type;
146
+	/**
147
+	 * 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.
148
+	 *
149
+	 * @var EE_message_type
150
+	 */
151
+	protected $_incoming_message_type;
152 152
 
153 153
 
154 154
 
155
-    /**
156
-     * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
-     *
158
-     * @var bool
159
-     */
160
-    public $activate_on_install = false;
155
+	/**
156
+	 * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
+	 *
158
+	 * @var bool
159
+	 */
160
+	public $activate_on_install = false;
161 161
 
162 162
 
163 163
 
164 164
 
165 165
 
166
-    public function __construct()
167
-    {
168
-        $this->_EEM_data = EEM_Message_Template_Group::instance();
169
-        $this->_messages_item_type = 'messenger';
166
+	public function __construct()
167
+	{
168
+		$this->_EEM_data = EEM_Message_Template_Group::instance();
169
+		$this->_messages_item_type = 'messenger';
170 170
 
171
-        parent::__construct();
171
+		parent::__construct();
172 172
 
173
-        $this->_set_test_settings_fields();
174
-        $this->_set_template_fields();
175
-        $this->_set_default_message_types();
176
-        $this->_set_valid_message_types();
177
-        $this->_set_validator_config();
173
+		$this->_set_test_settings_fields();
174
+		$this->_set_template_fields();
175
+		$this->_set_default_message_types();
176
+		$this->_set_valid_message_types();
177
+		$this->_set_validator_config();
178 178
 
179 179
 
180
-        $this->_supports_labels = new stdClass();
181
-        $this->_set_supports_labels();
182
-    }
180
+		$this->_supports_labels = new stdClass();
181
+		$this->_set_supports_labels();
182
+	}
183 183
 
184 184
 
185 185
 
186 186
 
187 187
 
188
-    /**
189
-     * _set_template_fields
190
-     * This sets up the fields that a messenger requires for the message to go out.
191
-     *
192
-     * @abstract
193
-     * @access  protected
194
-     * @return void
195
-     */
196
-    abstract protected function _set_template_fields();
188
+	/**
189
+	 * _set_template_fields
190
+	 * This sets up the fields that a messenger requires for the message to go out.
191
+	 *
192
+	 * @abstract
193
+	 * @access  protected
194
+	 * @return void
195
+	 */
196
+	abstract protected function _set_template_fields();
197 197
 
198 198
 
199 199
 
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
 
204 204
 
205 205
 
206
-    /**
207
-     * This method sets the _default_message_type property (see definition in docs attached to property)
208
-     *
209
-     * @abstract
210
-     * @access protected
211
-     * @return void
212
-     */
213
-    abstract protected function _set_default_message_types();
206
+	/**
207
+	 * This method sets the _default_message_type property (see definition in docs attached to property)
208
+	 *
209
+	 * @abstract
210
+	 * @access protected
211
+	 * @return void
212
+	 */
213
+	abstract protected function _set_default_message_types();
214 214
 
215 215
 
216 216
 
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
 
219 219
 
220 220
 
221
-    /**
222
-     * Sets the _valid_message_types property (see definition in cods attached to property)
223
-     *
224
-     * @since 4.5.0
225
-     *
226
-     * @abstract
227
-     * @return void
228
-     */
229
-    abstract protected function _set_valid_message_types();
221
+	/**
222
+	 * Sets the _valid_message_types property (see definition in cods attached to property)
223
+	 *
224
+	 * @since 4.5.0
225
+	 *
226
+	 * @abstract
227
+	 * @return void
228
+	 */
229
+	abstract protected function _set_valid_message_types();
230 230
 
231 231
 
232 232
 
@@ -234,171 +234,171 @@  discard block
 block discarded – undo
234 234
 
235 235
 
236 236
 
237
-    /**
238
-     * Child classes must declare the $_validator_config property using this method.
239
-     * See comments for $_validator_config for details on what it is used for.
240
-     *
241
-     * 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.
242
-     *
243
-     * @access protected
244
-     * @return void
245
-     */
246
-    abstract protected function _set_validator_config();
237
+	/**
238
+	 * Child classes must declare the $_validator_config property using this method.
239
+	 * See comments for $_validator_config for details on what it is used for.
240
+	 *
241
+	 * 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.
242
+	 *
243
+	 * @access protected
244
+	 * @return void
245
+	 */
246
+	abstract protected function _set_validator_config();
247 247
 
248 248
 
249 249
 
250 250
 
251 251
 
252 252
 
253
-    /**
254
-     * 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.
255
-     *
256
-     * @return bool|WP_Error
257
-     * @throw \Exception
258
-     */
259
-    abstract protected function _send_message();
253
+	/**
254
+	 * 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.
255
+	 *
256
+	 * @return bool|WP_Error
257
+	 * @throw \Exception
258
+	 */
259
+	abstract protected function _send_message();
260 260
 
261 261
 
262 262
 
263 263
 
264
-    /**
265
-     * We give you pretty previews of the messages!
266
-     * @return string html body for message content.
267
-     */
268
-    abstract protected function _preview();
264
+	/**
265
+	 * We give you pretty previews of the messages!
266
+	 * @return string html body for message content.
267
+	 */
268
+	abstract protected function _preview();
269 269
 
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
-     *
276
-     * @since 4.5.0
277
-     *
278
-     * @return void
279
-     */
280
-    public function enqueue_scripts_styles()
281
-    {
282
-        do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
-    }
273
+	/**
274
+	 * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
+	 *
276
+	 * @since 4.5.0
277
+	 *
278
+	 * @return void
279
+	 */
280
+	public function enqueue_scripts_styles()
281
+	{
282
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
+	}
284 284
 
285 285
 
286 286
 
287 287
 
288 288
 
289
-    /**
290
-     * This is used to indicate whether a messenger must be sent immediately or not.
291
-     * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
-     * away.  The PDF messenger is similar.
293
-     *
294
-     * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
-     *
296
-     * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
-     *
298
-     * @since  4.9.0
299
-     * @return bool
300
-     */
301
-    public function send_now()
302
-    {
303
-        return false;
304
-    }
289
+	/**
290
+	 * This is used to indicate whether a messenger must be sent immediately or not.
291
+	 * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
+	 * away.  The PDF messenger is similar.
293
+	 *
294
+	 * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
+	 *
296
+	 * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
+	 *
298
+	 * @since  4.9.0
299
+	 * @return bool
300
+	 */
301
+	public function send_now()
302
+	{
303
+		return false;
304
+	}
305 305
 
306 306
 
307 307
 
308 308
 
309 309
 
310
-    /**
311
-     * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
-     * Note: If the generated message is a for a preview, this value is ignored.
313
-     * @since 4.9.0
314
-     * @return bool
315
-     */
316
-    public function allow_empty_to_field()
317
-    {
318
-        return false;
319
-    }
310
+	/**
311
+	 * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
+	 * Note: If the generated message is a for a preview, this value is ignored.
313
+	 * @since 4.9.0
314
+	 * @return bool
315
+	 */
316
+	public function allow_empty_to_field()
317
+	{
318
+		return false;
319
+	}
320 320
 
321 321
 
322 322
 
323 323
 
324 324
 
325
-    /**
326
-     * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
-     * @see property definition for info on how its formatted.
328
-     *
329
-     * @since 4.5.0;
330
-     * @return void
331
-     */
332
-    protected function _set_supports_labels()
333
-    {
334
-        $this->_set_supports_labels_defaults();
335
-    }
325
+	/**
326
+	 * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
+	 * @see property definition for info on how its formatted.
328
+	 *
329
+	 * @since 4.5.0;
330
+	 * @return void
331
+	 */
332
+	protected function _set_supports_labels()
333
+	{
334
+		$this->_set_supports_labels_defaults();
335
+	}
336 336
 
337 337
 
338 338
 
339 339
 
340 340
 
341
-    /**
342
-     * Sets the defaults for the _supports_labels property.
343
-     *
344
-     * @since 4.5.0
345
-     *
346
-     * @return void
347
-     */
348
-    private function _set_supports_labels_defaults()
349
-    {
350
-        $this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
-        $this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
-        $this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
341
+	/**
342
+	 * Sets the defaults for the _supports_labels property.
343
+	 *
344
+	 * @since 4.5.0
345
+	 *
346
+	 * @return void
347
+	 */
348
+	private function _set_supports_labels_defaults()
349
+	{
350
+		$this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
+		$this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
+		$this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
353 353
 
354
-        $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');
354
+		$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 355
 
356
-        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
-    }
356
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
+	}
358 358
 
359 359
 
360 360
 
361 361
 
362 362
 
363
-    /**
364
-     * This returns the _supports_labels property.
365
-     *
366
-     * @since 4.5.0
367
-     *
368
-     * @return stdClass
369
-     */
370
-    public function get_supports_labels()
371
-    {
372
-        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
-            $this->_set_supports_labels_defaults();
374
-        }
375
-        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
-    }
363
+	/**
364
+	 * This returns the _supports_labels property.
365
+	 *
366
+	 * @since 4.5.0
367
+	 *
368
+	 * @return stdClass
369
+	 */
370
+	public function get_supports_labels()
371
+	{
372
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
+			$this->_set_supports_labels_defaults();
374
+		}
375
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
+	}
377 377
 
378 378
 
379 379
 
380 380
 
381
-    /**
382
-     * Used to retrieve a variation (typically the path/url to a css file)
383
-     *
384
-     * @since 4.5.0
385
-     *
386
-     * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
-     * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
-     * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
-     * @param string                    $type What variation type to return. Default is 'main'.
390
-     * @param string               $variation What variation for the template pack
391
-     * @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.
392
-     *
393
-     * @return string                    path or url for the requested variation.
394
-     */
395
-    public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
-    {
397
-        $this->_tmp_pack = $pack;
398
-        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
-        $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
-        return $variation_path;
401
-    }
381
+	/**
382
+	 * Used to retrieve a variation (typically the path/url to a css file)
383
+	 *
384
+	 * @since 4.5.0
385
+	 *
386
+	 * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
+	 * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
+	 * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
+	 * @param string                    $type What variation type to return. Default is 'main'.
390
+	 * @param string               $variation What variation for the template pack
391
+	 * @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.
392
+	 *
393
+	 * @return string                    path or url for the requested variation.
394
+	 */
395
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
+	{
397
+		$this->_tmp_pack = $pack;
398
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
+		return $variation_path;
401
+	}
402 402
 
403 403
 
404 404
 
@@ -406,479 +406,479 @@  discard block
 block discarded – undo
406 406
 
407 407
 
408 408
 
409
-    /**
410
-     * This just returns the default message types associated with this messenger when it is first activated.
411
-     *
412
-     * @access public
413
-     * @return array
414
-     */
415
-    public function get_default_message_types()
416
-    {
417
-        $class = get_class($this);
409
+	/**
410
+	 * This just returns the default message types associated with this messenger when it is first activated.
411
+	 *
412
+	 * @access public
413
+	 * @return array
414
+	 */
415
+	public function get_default_message_types()
416
+	{
417
+		$class = get_class($this);
418 418
 
419
-        // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
419
+		// messenger specific filter
420
+		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422
-        // all messengers filter
423
-        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
-        return $default_types;
425
-    }
422
+		// all messengers filter
423
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
+		return $default_types;
425
+	}
426 426
 
427 427
 
428 428
 
429 429
 
430
-    /**
431
-     * Returns the valid message types associated with this messenger.
432
-     *
433
-     * @since 4.5.0
434
-     *
435
-     * @return array
436
-     */
437
-    public function get_valid_message_types()
438
-    {
439
-        $class = get_class($this);
440
-
441
-        // messenger specific filter
442
-        // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
-
445
-        // all messengers filter
446
-        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
-        return $valid_types;
448
-    }
449
-
450
-
451
-
452
-
453
-
454
-    /**
455
-     * 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.
456
-     *
457
-     * @access public
458
-     * @param array $new_config Whatever is put in here will reset the _validator_config property
459
-     */
460
-    public function set_validator_config($new_config)
461
-    {
462
-        $this->_validator_config = $new_config;
463
-    }
464
-
465
-
466
-
467
-
468
-    /**
469
-     * This returns the _validator_config property
470
-     *
471
-     * @access public
472
-     * @return array
473
-     */
474
-    public function get_validator_config()
475
-    {
476
-        $class = get_class($this);
477
-
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
-        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
-        return $config;
481
-    }
482
-
483
-
484
-
485
-
486
-    /**
487
-     * 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.
488
-     *
489
-     * @param string $page the slug of the EE admin page
490
-     * @param array $message_types an array of active message type objects
491
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
-     * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
-     * @access public
494
-     * @return string content for page
495
-     */
496
-    public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
-    {
498
-        return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * @param $message_types
505
-     * @param array $extra
506
-     * @return mixed|string
507
-     */
508
-    protected function _get_admin_content_events_edit($message_types, $extra)
509
-    {
510
-        // defaults
511
-        $template_args = array();
512
-        $selector_rows = '';
513
-
514
-        // 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.
515
-        $event_id = isset($extra['event']) ? $extra['event'] : null;
516
-
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
-
520
-        // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
-        $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
-        );
524
-        $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
-            $event_id,
526
-            array(
527
-                'MTP_messenger' => $this->name,
528
-                'MTP_is_active' => true
529
-            )
530
-        );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
-
533
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
-        foreach ($global_templates as $mtpgID => $mtpg) {
535
-            if ($mtpg instanceof EE_Message_Template_Group) {
536
-                // verify this message type is supposed to show on this page
537
-                $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
539
-                    continue;
540
-                }
541
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
-                    continue;
544
-                }
545
-                $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
-                // 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.
549
-                if (! $mtpg->get('MTP_is_override')) {
550
-                    // any custom templates for this message type?
551
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
554
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
-                    }
556
-                }
557
-                // if there is no $default_value then we set it as the global
558
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
-                $create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
561
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562
-                $st_args['mt_slug'] = $mtpg->message_type();
563
-                $st_args['messenger_slug'] = $this->name;
564
-                $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');
565
-                // 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).
566
-                $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>';
567
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
-                $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>' : '';
569
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570
-            }
571
-        }
572
-
573
-        // if no selectors present then get out.
574
-        if (empty($selector_rows)) {
575
-            return '';
576
-        }
577
-
578
-        $template_args['selector_rows'] = $selector_rows;
579
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
580
-    }
581
-
582
-
583
-
584
-
585
-
586
-
587
-    /**
588
-     * get_template_fields
589
-     *
590
-     * @access public
591
-     * @return array $this->_template_fields
592
-     */
593
-    public function get_template_fields()
594
-    {
595
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
596
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597
-        return $template_fields;
598
-    }
599
-
600
-
601
-
602
-
603
-    /** SETUP METHODS **/
604
-    /**
605
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
606
-     * @param string $item
607
-     * @param mixed $value
608
-     */
609
-    protected function _set_template_value($item, $value)
610
-    {
611
-        if (array_key_exists($item, $this->_template_fields)) {
612
-            $prop = '_' . $item;
613
-            $this->{$prop}= $value;
614
-        }
615
-    }
616
-
617
-    /**
618
-     * Sets up the message for sending.
619
-     *
620
-     * @param  EE_message $message the message object that contains details about the message.
621
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
622
-     *
623
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
624
-     *              added to EE_Error.
625
-     *              true = message sent successfully
626
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
627
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
628
-     *
629
-     * @throws SendMessageException
630
-     */
631
-    final public function send_message($message, EE_message_type $message_type)
632
-    {
633
-        try {
634
-            $this->_validate_and_setup($message);
635
-            $this->_incoming_message_type = $message_type;
636
-            $response = $this->_send_message();
637
-            if ($response instanceof WP_Error) {
638
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
639
-                $response = false;
640
-            }
641
-        } catch (\Exception $e) {
642
-            // convert to an instance of SendMessageException
643
-            throw new SendMessageException($e->getMessage());
644
-        }
645
-        return $response;
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * Sets up and returns message preview
652
-     * @param  EE_Message $message incoming message object
653
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
654
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
655
-     * @return string          return the message html content
656
-     */
657
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
658
-    {
659
-        $this->_validate_and_setup($message);
660
-
661
-        $this->_incoming_message_type = $message_type;
662
-
663
-        if ($send) {
664
-            // are we overriding any existing template fields?
665
-            $settings = apply_filters(
666
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
667
-                $this->get_existing_test_settings(),
668
-                $this,
669
-                $send,
670
-                $message,
671
-                $message_type
672
-            );
673
-            if (! empty($settings)) {
674
-                foreach ($settings as $field => $value) {
675
-                    $this->_set_template_value($field, $value);
676
-                }
677
-            }
678
-        }
679
-
680
-        // enqueue preview js so that any links/buttons on the page are disabled.
681
-        if (! $send) {
682
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
687
-        }
688
-
689
-        return $send ? $this->_send_message() : $this->_preview();
690
-    }
691
-
692
-
693
-
694
-
695
-    /**
696
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
697
-     *
698
-     * @since 4.5.0
699
-     *
700
-     * @return void
701
-     */
702
-    public function add_preview_script()
703
-    {
704
-        // error message
705
-        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');
706
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
707
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708
-        wp_enqueue_script('ee-messages-preview-js');
709
-    }
710
-
711
-
712
-
713
-
714
-    /**
715
-     * simply validates the incoming message object and then sets up the properties for the messenger
716
-     * @param  EE_Message $message
717
-     * @throws EE_Error
718
-     */
719
-    protected function _validate_and_setup(EE_Message $message)
720
-    {
721
-        $template_pack = $message->get_template_pack();
722
-        $variation = $message->get_template_pack_variation();
723
-
724
-        // verify we have the required template pack value on the $message object.
725
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
726
-            throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727
-        }
728
-
729
-        $this->_tmp_pack = $template_pack;
730
-
731
-        $this->_variation = $variation ? $variation : 'default';
732
-
733
-        $template_fields = $this->get_template_fields();
734
-
735
-        foreach ($template_fields as $template => $value) {
736
-            if ($template !== 'extra') {
737
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
738
-                $message_template_value = $column_value ? $column_value : null;
739
-                $this->_set_template_value($template, $message_template_value);
740
-            }
741
-        }
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * Utility method for child classes to get the contents of a template file and return
748
-     *
749
-     * We're assuming the child messenger class has already setup template args!
750
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
751
-     * @return string
752
-     * @throws \EE_Error
753
-     */
754
-    protected function _get_main_template($preview = false)
755
-    {
756
-        $type = $preview ? 'preview' : 'main';
757
-
758
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759
-
760
-        // check file exists and is readable
761
-        if (!is_readable($wrapper_template)) {
762
-            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));
763
-        }
764
-
765
-        // add message type to template args
766
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
767
-
768
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
769
-    }
770
-
771
-
772
-
773
-    /**
774
-     * set the _test_settings_fields property
775
-     *
776
-     * @access protected
777
-     * @return void
778
-     */
779
-    protected function _set_test_settings_fields()
780
-    {
781
-        $this->_test_settings_fields = array();
782
-    }
783
-
784
-
785
-
786
-    /**
787
-     * return the _test_settings_fields property
788
-     * @return array
789
-     */
790
-    public function get_test_settings_fields()
791
-    {
792
-        return $this->_test_settings_fields;
793
-    }
794
-
795
-
796
-
797
-
798
-    /**
799
-     * This just returns any existing test settings that might be saved in the database
800
-     *
801
-     * @access public
802
-     * @return array
803
-     */
804
-    public function get_existing_test_settings()
805
-    {
806
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
809
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * All this does is set the existing test settings (in the db) for the messenger
816
-     *
817
-     * @access public
818
-     * @param $settings
819
-     * @return bool success/fail
820
-     */
821
-    public function set_existing_test_settings($settings)
822
-    {
823
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
826
-        $existing[ $this->name ]['test_settings'] = $settings;
827
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
828
-    }
829
-
830
-
831
-
832
-    /**
833
-     * This just returns the field label for a given field setup in the _template_fields property.
834
-     *
835
-     * @since   4.3.0
836
-     *
837
-     * @param string $field The field to retrieve the label for
838
-     * @return string             The label
839
-     */
840
-    public function get_field_label($field)
841
-    {
842
-        // first let's see if the field requests is in the top level array.
843
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
-            return $this->_template[ $field ]['label'];
845
-        }
846
-
847
-        // 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.
848
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
850
-        }
851
-
852
-        // now it's possible this field may just be existing in any of the extra array items.
853
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
-                if (!is_array($subfields)) {
856
-                    continue;
857
-                }
858
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
-                    return $subfields[ $field ]['label'];
860
-                }
861
-            }
862
-        }
863
-
864
-        // if we made it here then there's no label set so let's just return the $field.
865
-        return $field;
866
-    }
867
-
868
-
869
-
870
-
871
-    /**
872
-     * 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).
873
-     *
874
-     * @since 4.5.0
875
-     *
876
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
877
-     *
878
-     * @return void
879
-     */
880
-    public function do_secondary_messenger_hooks($sending_messenger_name)
881
-    {
882
-        return;
883
-    }
430
+	/**
431
+	 * Returns the valid message types associated with this messenger.
432
+	 *
433
+	 * @since 4.5.0
434
+	 *
435
+	 * @return array
436
+	 */
437
+	public function get_valid_message_types()
438
+	{
439
+		$class = get_class($this);
440
+
441
+		// messenger specific filter
442
+		// messenger specific filter
443
+		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
+
445
+		// all messengers filter
446
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
+		return $valid_types;
448
+	}
449
+
450
+
451
+
452
+
453
+
454
+	/**
455
+	 * 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.
456
+	 *
457
+	 * @access public
458
+	 * @param array $new_config Whatever is put in here will reset the _validator_config property
459
+	 */
460
+	public function set_validator_config($new_config)
461
+	{
462
+		$this->_validator_config = $new_config;
463
+	}
464
+
465
+
466
+
467
+
468
+	/**
469
+	 * This returns the _validator_config property
470
+	 *
471
+	 * @access public
472
+	 * @return array
473
+	 */
474
+	public function get_validator_config()
475
+	{
476
+		$class = get_class($this);
477
+
478
+		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
+		return $config;
481
+	}
482
+
483
+
484
+
485
+
486
+	/**
487
+	 * 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.
488
+	 *
489
+	 * @param string $page the slug of the EE admin page
490
+	 * @param array $message_types an array of active message type objects
491
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
+	 * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
+	 * @access public
494
+	 * @return string content for page
495
+	 */
496
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
+	{
498
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * @param $message_types
505
+	 * @param array $extra
506
+	 * @return mixed|string
507
+	 */
508
+	protected function _get_admin_content_events_edit($message_types, $extra)
509
+	{
510
+		// defaults
511
+		$template_args = array();
512
+		$selector_rows = '';
513
+
514
+		// 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.
515
+		$event_id = isset($extra['event']) ? $extra['event'] : null;
516
+
517
+		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
+
520
+		// array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(
522
+			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
+		);
524
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
+			$event_id,
526
+			array(
527
+				'MTP_messenger' => $this->name,
528
+				'MTP_is_active' => true
529
+			)
530
+		);
531
+		$templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
+
533
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
+		foreach ($global_templates as $mtpgID => $mtpg) {
535
+			if ($mtpg instanceof EE_Message_Template_Group) {
536
+				// verify this message type is supposed to show on this page
537
+				$mtp_obj = $mtpg->message_type_obj();
538
+				if (! $mtp_obj instanceof EE_message_type) {
539
+					continue;
540
+				}
541
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
+					continue;
544
+				}
545
+				$select_values = array();
546
+				$select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
+				// 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.
549
+				if (! $mtpg->get('MTP_is_override')) {
550
+					// any custom templates for this message type?
551
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
+						$select_values[ $cmtpgID ] = $cmtpg->name();
554
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
+					}
556
+				}
557
+				// if there is no $default_value then we set it as the global
558
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
559
+				$edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
+				$create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
561
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562
+				$st_args['mt_slug'] = $mtpg->message_type();
563
+				$st_args['messenger_slug'] = $this->name;
564
+				$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');
565
+				// 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).
566
+				$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>';
567
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
+				$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>' : '';
569
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570
+			}
571
+		}
572
+
573
+		// if no selectors present then get out.
574
+		if (empty($selector_rows)) {
575
+			return '';
576
+		}
577
+
578
+		$template_args['selector_rows'] = $selector_rows;
579
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
580
+	}
581
+
582
+
583
+
584
+
585
+
586
+
587
+	/**
588
+	 * get_template_fields
589
+	 *
590
+	 * @access public
591
+	 * @return array $this->_template_fields
592
+	 */
593
+	public function get_template_fields()
594
+	{
595
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
596
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597
+		return $template_fields;
598
+	}
599
+
600
+
601
+
602
+
603
+	/** SETUP METHODS **/
604
+	/**
605
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
606
+	 * @param string $item
607
+	 * @param mixed $value
608
+	 */
609
+	protected function _set_template_value($item, $value)
610
+	{
611
+		if (array_key_exists($item, $this->_template_fields)) {
612
+			$prop = '_' . $item;
613
+			$this->{$prop}= $value;
614
+		}
615
+	}
616
+
617
+	/**
618
+	 * Sets up the message for sending.
619
+	 *
620
+	 * @param  EE_message $message the message object that contains details about the message.
621
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
622
+	 *
623
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
624
+	 *              added to EE_Error.
625
+	 *              true = message sent successfully
626
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
627
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
628
+	 *
629
+	 * @throws SendMessageException
630
+	 */
631
+	final public function send_message($message, EE_message_type $message_type)
632
+	{
633
+		try {
634
+			$this->_validate_and_setup($message);
635
+			$this->_incoming_message_type = $message_type;
636
+			$response = $this->_send_message();
637
+			if ($response instanceof WP_Error) {
638
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
639
+				$response = false;
640
+			}
641
+		} catch (\Exception $e) {
642
+			// convert to an instance of SendMessageException
643
+			throw new SendMessageException($e->getMessage());
644
+		}
645
+		return $response;
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * Sets up and returns message preview
652
+	 * @param  EE_Message $message incoming message object
653
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
654
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
655
+	 * @return string          return the message html content
656
+	 */
657
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
658
+	{
659
+		$this->_validate_and_setup($message);
660
+
661
+		$this->_incoming_message_type = $message_type;
662
+
663
+		if ($send) {
664
+			// are we overriding any existing template fields?
665
+			$settings = apply_filters(
666
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
667
+				$this->get_existing_test_settings(),
668
+				$this,
669
+				$send,
670
+				$message,
671
+				$message_type
672
+			);
673
+			if (! empty($settings)) {
674
+				foreach ($settings as $field => $value) {
675
+					$this->_set_template_value($field, $value);
676
+				}
677
+			}
678
+		}
679
+
680
+		// enqueue preview js so that any links/buttons on the page are disabled.
681
+		if (! $send) {
682
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
687
+		}
688
+
689
+		return $send ? $this->_send_message() : $this->_preview();
690
+	}
691
+
692
+
693
+
694
+
695
+	/**
696
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
697
+	 *
698
+	 * @since 4.5.0
699
+	 *
700
+	 * @return void
701
+	 */
702
+	public function add_preview_script()
703
+	{
704
+		// error message
705
+		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');
706
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
707
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708
+		wp_enqueue_script('ee-messages-preview-js');
709
+	}
710
+
711
+
712
+
713
+
714
+	/**
715
+	 * simply validates the incoming message object and then sets up the properties for the messenger
716
+	 * @param  EE_Message $message
717
+	 * @throws EE_Error
718
+	 */
719
+	protected function _validate_and_setup(EE_Message $message)
720
+	{
721
+		$template_pack = $message->get_template_pack();
722
+		$variation = $message->get_template_pack_variation();
723
+
724
+		// verify we have the required template pack value on the $message object.
725
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
726
+			throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727
+		}
728
+
729
+		$this->_tmp_pack = $template_pack;
730
+
731
+		$this->_variation = $variation ? $variation : 'default';
732
+
733
+		$template_fields = $this->get_template_fields();
734
+
735
+		foreach ($template_fields as $template => $value) {
736
+			if ($template !== 'extra') {
737
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
738
+				$message_template_value = $column_value ? $column_value : null;
739
+				$this->_set_template_value($template, $message_template_value);
740
+			}
741
+		}
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * Utility method for child classes to get the contents of a template file and return
748
+	 *
749
+	 * We're assuming the child messenger class has already setup template args!
750
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
751
+	 * @return string
752
+	 * @throws \EE_Error
753
+	 */
754
+	protected function _get_main_template($preview = false)
755
+	{
756
+		$type = $preview ? 'preview' : 'main';
757
+
758
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759
+
760
+		// check file exists and is readable
761
+		if (!is_readable($wrapper_template)) {
762
+			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));
763
+		}
764
+
765
+		// add message type to template args
766
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
767
+
768
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
769
+	}
770
+
771
+
772
+
773
+	/**
774
+	 * set the _test_settings_fields property
775
+	 *
776
+	 * @access protected
777
+	 * @return void
778
+	 */
779
+	protected function _set_test_settings_fields()
780
+	{
781
+		$this->_test_settings_fields = array();
782
+	}
783
+
784
+
785
+
786
+	/**
787
+	 * return the _test_settings_fields property
788
+	 * @return array
789
+	 */
790
+	public function get_test_settings_fields()
791
+	{
792
+		return $this->_test_settings_fields;
793
+	}
794
+
795
+
796
+
797
+
798
+	/**
799
+	 * This just returns any existing test settings that might be saved in the database
800
+	 *
801
+	 * @access public
802
+	 * @return array
803
+	 */
804
+	public function get_existing_test_settings()
805
+	{
806
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
809
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * All this does is set the existing test settings (in the db) for the messenger
816
+	 *
817
+	 * @access public
818
+	 * @param $settings
819
+	 * @return bool success/fail
820
+	 */
821
+	public function set_existing_test_settings($settings)
822
+	{
823
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
826
+		$existing[ $this->name ]['test_settings'] = $settings;
827
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
828
+	}
829
+
830
+
831
+
832
+	/**
833
+	 * This just returns the field label for a given field setup in the _template_fields property.
834
+	 *
835
+	 * @since   4.3.0
836
+	 *
837
+	 * @param string $field The field to retrieve the label for
838
+	 * @return string             The label
839
+	 */
840
+	public function get_field_label($field)
841
+	{
842
+		// first let's see if the field requests is in the top level array.
843
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
+			return $this->_template[ $field ]['label'];
845
+		}
846
+
847
+		// 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.
848
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
850
+		}
851
+
852
+		// now it's possible this field may just be existing in any of the extra array items.
853
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
+				if (!is_array($subfields)) {
856
+					continue;
857
+				}
858
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
+					return $subfields[ $field ]['label'];
860
+				}
861
+			}
862
+		}
863
+
864
+		// if we made it here then there's no label set so let's just return the $field.
865
+		return $field;
866
+	}
867
+
868
+
869
+
870
+
871
+	/**
872
+	 * 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).
873
+	 *
874
+	 * @since 4.5.0
875
+	 *
876
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
877
+	 *
878
+	 * @return void
879
+	 */
880
+	public function do_secondary_messenger_hooks($sending_messenger_name)
881
+	{
882
+		return;
883
+	}
884 884
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
         $class = get_class($this);
418 418
 
419 419
         // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
420
+        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422 422
         // all messengers filter
423 423
         $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 
441 441
         // messenger specific filter
442 442
         // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
443
+        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444 444
 
445 445
         // all messengers filter
446 446
         $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
     {
476 476
         $class = get_class($this);
477 477
 
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
478
+        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
479 479
         $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480 480
         return $config;
481 481
     }
@@ -514,12 +514,12 @@  discard block
 block discarded – undo
514 514
         // 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.
515 515
         $event_id = isset($extra['event']) ? $extra['event'] : null;
516 516
 
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
517
+        $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+        $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
519 519
 
520 520
         // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521 521
         $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
522
+            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
523 523
         );
524 524
         $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525 525
             $event_id,
@@ -528,44 +528,44 @@  discard block
 block discarded – undo
528 528
                 'MTP_is_active' => true
529 529
             )
530 530
         );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
531
+        $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
532 532
 
533 533
         // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534 534
         foreach ($global_templates as $mtpgID => $mtpg) {
535 535
             if ($mtpg instanceof EE_Message_Template_Group) {
536 536
                 // verify this message type is supposed to show on this page
537 537
                 $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
538
+                if ( ! $mtp_obj instanceof EE_message_type) {
539 539
                     continue;
540 540
                 }
541 541
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
542
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543 543
                     continue;
544 544
                 }
545 545
                 $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
546
+                $select_values[$mtpgID] = __('Global', 'event_espresso');
547 547
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548 548
                 // 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.
549
-                if (! $mtpg->get('MTP_is_override')) {
549
+                if ( ! $mtpg->get('MTP_is_override')) {
550 550
                     // any custom templates for this message type?
551 551
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552 552
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
553
+                        $select_values[$cmtpgID] = $cmtpg->name();
554 554
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555 555
                     }
556 556
                 }
557 557
                 // if there is no $default_value then we set it as the global
558 558
                 $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
-                $create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
559
+                $edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php'));
560
+                $create_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value), admin_url('admin.php'));
561 561
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562 562
                 $st_args['mt_slug'] = $mtpg->message_type();
563 563
                 $st_args['messenger_slug'] = $this->name;
564
-                $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');
564
+                $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');
565 565
                 // 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).
566
-                $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>';
566
+                $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>';
567 567
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
-                $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>' : '';
568
+                $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>' : '';
569 569
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570 570
             }
571 571
         }
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      */
593 593
     public function get_template_fields()
594 594
     {
595
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
595
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
596 596
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597 597
         return $template_fields;
598 598
     }
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
     protected function _set_template_value($item, $value)
610 610
     {
611 611
         if (array_key_exists($item, $this->_template_fields)) {
612
-            $prop = '_' . $item;
613
-            $this->{$prop}= $value;
612
+            $prop = '_'.$item;
613
+            $this->{$prop} = $value;
614 614
         }
615 615
     }
616 616
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                 $message,
671 671
                 $message_type
672 672
             );
673
-            if (! empty($settings)) {
673
+            if ( ! empty($settings)) {
674 674
                 foreach ($settings as $field => $value) {
675 675
                     $this->_set_template_value($field, $value);
676 676
                 }
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
         }
679 679
 
680 680
         // enqueue preview js so that any links/buttons on the page are disabled.
681
-        if (! $send) {
681
+        if ( ! $send) {
682 682
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683 683
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
684
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
685
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
686
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
687 687
         }
688 688
 
689 689
         return $send ? $this->_send_message() : $this->_preview();
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
     {
704 704
         // error message
705 705
         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');
706
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
706
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
707 707
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708 708
         wp_enqueue_script('ee-messages-preview-js');
709 709
     }
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
         $variation = $message->get_template_pack_variation();
723 723
 
724 724
         // verify we have the required template pack value on the $message object.
725
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
725
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
726 726
             throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727 727
         }
728 728
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 
735 735
         foreach ($template_fields as $template => $value) {
736 736
             if ($template !== 'extra') {
737
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
737
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
738 738
                 $message_template_value = $column_value ? $column_value : null;
739 739
                 $this->_set_template_value($template, $message_template_value);
740 740
             }
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759 759
 
760 760
         // check file exists and is readable
761
-        if (!is_readable($wrapper_template)) {
761
+        if ( ! is_readable($wrapper_template)) {
762 762
             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));
763 763
         }
764 764
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807 807
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808 808
         $settings = $Message_Resource_Manager->get_active_messengers_option();
809
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
809
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
810 810
     }
811 811
 
812 812
 
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824 824
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825 825
         $existing = $Message_Resource_Manager->get_active_messengers_option();
826
-        $existing[ $this->name ]['test_settings'] = $settings;
826
+        $existing[$this->name]['test_settings'] = $settings;
827 827
         return $Message_Resource_Manager->update_active_messengers_option($existing);
828 828
     }
829 829
 
@@ -840,23 +840,23 @@  discard block
 block discarded – undo
840 840
     public function get_field_label($field)
841 841
     {
842 842
         // first let's see if the field requests is in the top level array.
843
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
-            return $this->_template[ $field ]['label'];
843
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
844
+            return $this->_template[$field]['label'];
845 845
         }
846 846
 
847 847
         // 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.
848
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
848
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
849
+            return $this->_template_fields['extra'][$field]['main']['label'];
850 850
         }
851 851
 
852 852
         // now it's possible this field may just be existing in any of the extra array items.
853
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
853
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854 854
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
-                if (!is_array($subfields)) {
855
+                if ( ! is_array($subfields)) {
856 856
                     continue;
857 857
                 }
858
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
-                    return $subfields[ $field ]['label'];
858
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
859
+                    return $subfields[$field]['label'];
860 860
                 }
861 861
             }
862 862
         }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Gateway.lib.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -500,7 +500,7 @@
 block discarded – undo
500 500
      *
501 501
      * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment)
502 502
      * @param EEI_Payment $payment
503
-     * @return type
503
+     * @return string
504 504
      */
505 505
     protected function _format_order_description(EEI_Payment $payment)
506 506
     {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     public function set_settings($settings_array)
188 188
     {
189 189
         foreach ($settings_array as $name => $value) {
190
-            $property_name = "_" . $name;
190
+            $property_name = "_".$name;
191 191
             $this->{$property_name} = $value;
192 192
         }
193 193
     }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      */
252 252
     public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter)
253 253
     {
254
-        if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) {
254
+        if ( ! $gateway_data_formatter instanceof GatewayDataFormatterInterface) {
255 255
             throw new InvalidEntityException(
256 256
                 is_object($gateway_data_formatter)
257 257
                     ? get_class($gateway_data_formatter)
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
      */
271 271
     protected function _get_gateway_formatter()
272 272
     {
273
-        if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) {
273
+        if ( ! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) {
274 274
             throw new InvalidEntityException(
275 275
                 is_object($this->_gateway_data_formatter)
276 276
                     ? get_class($this->_gateway_data_formatter)
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      */
292 292
     public function set_unsupported_character_remover(FormatterInterface $formatter)
293 293
     {
294
-        if (! $formatter instanceof FormatterInterface) {
294
+        if ( ! $formatter instanceof FormatterInterface) {
295 295
             throw new InvalidEntityException(
296 296
                 is_object($formatter)
297 297
                     ? get_class($formatter)
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      */
311 311
     protected function _get_unsupported_character_remover()
312 312
     {
313
-        if (! $this->_unsupported_character_remover instanceof FormatterInterface) {
313
+        if ( ! $this->_unsupported_character_remover instanceof FormatterInterface) {
314 314
             throw new InvalidEntityException(
315 315
                 is_object($this->_unsupported_character_remover)
316 316
                     ? get_class($this->_unsupported_character_remover)
Please login to merge, or discard this patch.
Indentation   +491 added lines, -491 removed lines patch added patch discarded remove patch
@@ -23,495 +23,495 @@
 block discarded – undo
23 23
  */
24 24
 abstract class EE_Gateway
25 25
 {
26
-    /**
27
-     * a constant used as a possible value for $_currencies_supported to indicate
28
-     * that ALL currencies are supported by this gateway
29
-     */
30
-    const all_currencies_supported = 'all_currencies_supported';
31
-    /**
32
-     * Where values are 3-letter currency codes
33
-     *
34
-     * @var array
35
-     */
36
-    protected $_currencies_supported = array();
37
-    /**
38
-     * Whether or not this gateway can support SENDING a refund request (ie, initiated by
39
-     * admin in EE's wp-admin page)
40
-     *
41
-     * @var boolean
42
-     */
43
-    protected $_supports_sending_refunds = false;
44
-
45
-    /**
46
-     * Whether or not this gateway can support RECEIVING a refund request from the payment
47
-     * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE)
48
-     *
49
-     * @var boolean
50
-     */
51
-    protected $_supports_receiving_refunds = false;
52
-    /**
53
-     * Model for querying for existing payments
54
-     *
55
-     * @var EEMI_Payment
56
-     */
57
-    protected $_pay_model;
58
-
59
-    /**
60
-     * Model used for adding to the payments log
61
-     *
62
-     * @var EEMI_Payment_Log
63
-     */
64
-    protected $_pay_log;
65
-
66
-    /**
67
-     * Used for formatting some input to gateways
68
-     *
69
-     * @var EEHI_Template
70
-     */
71
-    protected $_template;
72
-
73
-    /**
74
-     * Concrete class that implements EEHI_Money, used by most gateways
75
-     *
76
-     * @var EEHI_Money
77
-     */
78
-    protected $_money;
79
-
80
-    /**
81
-     * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree
82
-     *
83
-     * @var EEHI_Line_Item
84
-     */
85
-    protected $_line_item;
86
-
87
-    /**
88
-     * @var GatewayDataFormatterInterface
89
-     */
90
-    protected $_gateway_data_formatter;
91
-
92
-    /**
93
-     * @var FormatterInterface
94
-     */
95
-    protected $_unsupported_character_remover;
96
-
97
-    /**
98
-     * The ID of the payment method using this gateway
99
-     *
100
-     * @var int
101
-     */
102
-    protected $_ID;
103
-
104
-    /**
105
-     * @var $_debug_mode boolean whether to send requests to teh sandbox site or not
106
-     */
107
-    protected $_debug_mode;
108
-    /**
109
-     *
110
-     * @var string $_name name to show for this payment method
111
-     */
112
-    protected $_name;
113
-    /**
114
-     *
115
-     * @var string name to show fir this payment method to admin-type users
116
-     */
117
-    protected $_admin_name;
118
-
119
-    /**
120
-     * @return EE_Gateway
121
-     */
122
-    public function __construct()
123
-    {
124
-    }
125
-
126
-    /**
127
-     * We don't want to serialize models as they often have circular structures
128
-     * (eg a payment model has a reference to each payment model object; and most
129
-     * payments have a transaction, most transactions have a payment method;
130
-     * most payment methods have a payment method type; most payment method types
131
-     * have a gateway. And if a gateway serializes its models, we start at the
132
-     * beginning again)
133
-     *
134
-     * @return array
135
-     */
136
-    public function __sleep()
137
-    {
138
-        $properties = get_object_vars($this);
139
-        unset($properties['_pay_model'], $properties['_pay_log']);
140
-        return array_keys($properties);
141
-    }
142
-
143
-    /**
144
-     * Returns whether or not this gateway should support SENDING refunds
145
-     * see $_supports_sending_refunds
146
-     *
147
-     * @return boolean
148
-     */
149
-    public function supports_sending_refunds()
150
-    {
151
-        return $this->_supports_sending_refunds;
152
-    }
153
-
154
-    /**
155
-     * Returns whether or not this gateway should support RECEIVING refunds
156
-     * see $_supports_receiving_refunds
157
-     *
158
-     * @return boolean
159
-     */
160
-    public function supports_receiving_refunds()
161
-    {
162
-        return $this->_supports_receiving_refunds;
163
-    }
164
-
165
-
166
-    /**
167
-     * Tries to refund the payment specified, taking into account the extra
168
-     * refund info. Note that if the gateway's _supports_sending_refunds is false,
169
-     * this should just throw an exception.
170
-     *
171
-     * @param EE_Payment $payment
172
-     * @param array      $refund_info
173
-     * @return EE_Payment for the refund
174
-     * @throws EE_Error
175
-     */
176
-    public function do_direct_refund(EE_Payment $payment, $refund_info = null)
177
-    {
178
-        return null;
179
-    }
180
-
181
-
182
-    /**
183
-     * Sets the payment method's settings so the gateway knows where to send the request
184
-     * etc
185
-     *
186
-     * @param array $settings_array
187
-     */
188
-    public function set_settings($settings_array)
189
-    {
190
-        foreach ($settings_array as $name => $value) {
191
-            $property_name = "_" . $name;
192
-            $this->{$property_name} = $value;
193
-        }
194
-    }
195
-
196
-    /**
197
-     * See this class description
198
-     *
199
-     * @param EEMI_Payment $payment_model
200
-     */
201
-    public function set_payment_model($payment_model)
202
-    {
203
-        $this->_pay_model = $payment_model;
204
-    }
205
-
206
-    /**
207
-     * See this class description
208
-     *
209
-     * @param EEMI_Payment_Log $payment_log_model
210
-     */
211
-    public function set_payment_log($payment_log_model)
212
-    {
213
-        $this->_pay_log = $payment_log_model;
214
-    }
215
-
216
-    /**
217
-     * See this class description
218
-     *
219
-     * @param EEHI_Template $template_helper
220
-     */
221
-    public function set_template_helper($template_helper)
222
-    {
223
-        $this->_template = $template_helper;
224
-    }
225
-
226
-    /**
227
-     * See this class description
228
-     *
229
-     * @param EEHI_Line_Item $line_item_helper
230
-     */
231
-    public function set_line_item_helper($line_item_helper)
232
-    {
233
-        $this->_line_item = $line_item_helper;
234
-    }
235
-
236
-    /**
237
-     * See this class description
238
-     *
239
-     * @param EEHI_Money $money_helper
240
-     */
241
-    public function set_money_helper($money_helper)
242
-    {
243
-        $this->_money = $money_helper;
244
-    }
245
-
246
-
247
-    /**
248
-     * Sets the gateway data formatter helper
249
-     *
250
-     * @param GatewayDataFormatterInterface $gateway_data_formatter
251
-     * @throws InvalidEntityException if it's not set properly
252
-     */
253
-    public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter)
254
-    {
255
-        if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) {
256
-            throw new InvalidEntityException(
257
-                is_object($gateway_data_formatter)
258
-                    ? get_class($gateway_data_formatter)
259
-                    : esc_html__('Not an object', 'event_espresso'),
260
-                '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface'
261
-            );
262
-        }
263
-        $this->_gateway_data_formatter = $gateway_data_formatter;
264
-    }
265
-
266
-    /**
267
-     * Gets the gateway data formatter
268
-     *
269
-     * @return GatewayDataFormatterInterface
270
-     * @throws InvalidEntityException if it's not set properly
271
-     */
272
-    protected function _get_gateway_formatter()
273
-    {
274
-        if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) {
275
-            throw new InvalidEntityException(
276
-                is_object($this->_gateway_data_formatter)
277
-                    ? get_class($this->_gateway_data_formatter)
278
-                    : esc_html__('Not an object', 'event_espresso'),
279
-                '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface'
280
-            );
281
-        }
282
-        return $this->_gateway_data_formatter;
283
-    }
284
-
285
-
286
-    /**
287
-     * Sets the helper which will remove unsupported characters for most gateways
288
-     *
289
-     * @param FormatterInterface $formatter
290
-     * @return FormatterInterface
291
-     * @throws InvalidEntityException
292
-     */
293
-    public function set_unsupported_character_remover(FormatterInterface $formatter)
294
-    {
295
-        if (! $formatter instanceof FormatterInterface) {
296
-            throw new InvalidEntityException(
297
-                is_object($formatter)
298
-                    ? get_class($formatter)
299
-                    : esc_html__('Not an object', 'event_espresso'),
300
-                '\\EventEspresso\\core\\services\\formatters\\FormatterInterface'
301
-            );
302
-        }
303
-        $this->_unsupported_character_remover = $formatter;
304
-    }
305
-
306
-    /**
307
-     * Gets the helper which removes characters which gateways might not support, like emojis etc.
308
-     *
309
-     * @return FormatterInterface
310
-     * @throws InvalidEntityException
311
-     */
312
-    protected function _get_unsupported_character_remover()
313
-    {
314
-        if (! $this->_unsupported_character_remover instanceof FormatterInterface) {
315
-            throw new InvalidEntityException(
316
-                is_object($this->_unsupported_character_remover)
317
-                    ? get_class($this->_unsupported_character_remover)
318
-                    : esc_html__('Not an object', 'event_espresso'),
319
-                '\\EventEspresso\\core\\services\\formatters\\FormatterInterface'
320
-            );
321
-        }
322
-        return $this->_unsupported_character_remover;
323
-    }
324
-
325
-
326
-    /**
327
-     * @param $message
328
-     * @param $payment
329
-     */
330
-    public function log($message, $object_logged)
331
-    {
332
-        if ($object_logged instanceof EEI_Payment) {
333
-            $type = 'Payment';
334
-            $id = $object_logged->ID();
335
-        } elseif ($object_logged instanceof EEI_Transaction) {
336
-            $type = 'Transaction';
337
-            $id = $object_logged->ID();
338
-        } else {
339
-            $type = 'Payment_Method';
340
-            $id = $this->_ID;
341
-        }
342
-        // only log if we're going to store it for longer than the minimum time
343
-        $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
344
-        if ($reg_config->gateway_log_lifespan !== '1 second') {
345
-            $this->_pay_log->gateway_log($message, $id, $type);
346
-        }
347
-    }
348
-
349
-    /**
350
-     * Formats the amount so it can generally be sent to gateways
351
-     *
352
-     * @param float $amount
353
-     * @return string
354
-     * @deprecated since 4.9.31 insetad use
355
-     *             EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency()
356
-     */
357
-    public function format_currency($amount)
358
-    {
359
-        return $this->_get_gateway_formatter()->formatCurrency($amount);
360
-    }
361
-
362
-    /**
363
-     * Returns either an array of all the currency codes supported,
364
-     * or a string indicating they're all supported (EE_gateway::all_currencies_supported)
365
-     *
366
-     * @return mixed array or string
367
-     */
368
-    public function currencies_supported()
369
-    {
370
-        return $this->_currencies_supported;
371
-    }
372
-
373
-    /**
374
-     * Returns what a simple summing of items and taxes for this transaction. This
375
-     * can be used to determine if some more complex line items, like promotions,
376
-     * surcharges, or cancellations occurred (in which case we might want to forget
377
-     * about creating an itemized list of purchases and instead only send the total due)
378
-     *
379
-     * @param EE_Transaction $transaction
380
-     * @return float
381
-     */
382
-    protected function _sum_items_and_taxes(EE_Transaction $transaction)
383
-    {
384
-        $total_line_item = $transaction->total_line_item();
385
-        $total = 0;
386
-        foreach ($total_line_item->get_items() as $item_line_item) {
387
-            $total += max($item_line_item->total(), 0);
388
-        }
389
-        foreach ($total_line_item->tax_descendants() as $tax_line_item) {
390
-            $total += max($tax_line_item->total(), 0);
391
-        }
392
-        return $total;
393
-    }
394
-
395
-    /**
396
-     * Determines whether or not we can easily itemize the transaction using only
397
-     * items and taxes (ie, no promotions or surcharges or cancellations needed)
398
-     *
399
-     * @param EEI_Payment $payment
400
-     * @return boolean
401
-     */
402
-    protected function _can_easily_itemize_transaction_for(EEI_Payment $payment)
403
-    {
404
-        return $this->_money->compare_floats(
405
-            $this->_sum_items_and_taxes($payment->transaction()),
406
-            $payment->transaction()->total()
407
-        )
408
-               && $this->_money->compare_floats(
409
-                   $payment->amount(),
410
-                   $payment->transaction()->total()
411
-               );
412
-    }
413
-
414
-    /**
415
-     * Handles updating the transaction and any other related data based on the payment.
416
-     * You may be tempted to do this as part of do_direct_payment or handle_payment_update,
417
-     * but doing so on those functions might be too early. It's possible that the changes
418
-     * you make to teh transaction or registration or line items may just get overwritten
419
-     * at that point. Instead, you should store any info you need on the payment during those
420
-     * functions, and use that information at this step, which client code will decide
421
-     * for you when it should be called.
422
-     *
423
-     * @param EE_Payment $payment
424
-     * @return void
425
-     */
426
-    public function update_txn_based_on_payment($payment)
427
-    {
428
-        // maybe update the transaction or line items or registrations
429
-        // but most gateways don't need to do this, because they only update the payment
430
-    }
431
-
432
-    /**
433
-     * Gets the first event for this payment (it's possible that it could be for multiple)
434
-     *
435
-     * @param EEI_Payment $payment
436
-     * @return EEI_Event|null
437
-     * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event()
438
-     */
439
-    protected function _get_first_event_for_payment(EEI_Payment $payment)
440
-    {
441
-        return $payment->get_first_event();
442
-    }
443
-
444
-    /**
445
-     * Gets the name of the first event for which is being paid
446
-     *
447
-     * @param EEI_Payment $payment
448
-     * @return string
449
-     * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name()
450
-     */
451
-    protected function _get_first_event_name_for_payment(EEI_Payment $payment)
452
-    {
453
-        return $payment->get_first_event_name();
454
-    }
455
-
456
-    /**
457
-     * Gets the text to use for a gateway's line item name when this is a partial payment
458
-     *
459
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment)
460
-     * @param EE_Payment $payment
461
-     * @return string
462
-     */
463
-    protected function _format_partial_payment_line_item_name(EEI_Payment $payment)
464
-    {
465
-        return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment);
466
-    }
467
-
468
-    /**
469
-     * Gets the text to use for a gateway's line item description when this is a partial payment
470
-     *
471
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc()
472
-     * @param EEI_Payment $payment
473
-     * @return string
474
-     */
475
-    protected function _format_partial_payment_line_item_desc(EEI_Payment $payment)
476
-    {
477
-        return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment);
478
-    }
479
-
480
-    /**
481
-     * Gets the name to use for a line item when sending line items to the gateway
482
-     *
483
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment)
484
-     * @param EEI_Line_Item $line_item
485
-     * @param EEI_Payment   $payment
486
-     * @return string
487
-     */
488
-    protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment)
489
-    {
490
-        return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment);
491
-    }
492
-
493
-    /**
494
-     * Gets the description to use for a line item when sending line items to the gateway
495
-     *
496
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment))
497
-     * @param EEI_Line_Item $line_item
498
-     * @param EEI_Payment   $payment
499
-     * @return string
500
-     */
501
-    protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment)
502
-    {
503
-        return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment);
504
-    }
505
-
506
-    /**
507
-     * Gets the order description that should generlly be sent to gateways
508
-     *
509
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment)
510
-     * @param EEI_Payment $payment
511
-     * @return type
512
-     */
513
-    protected function _format_order_description(EEI_Payment $payment)
514
-    {
515
-        return $this->_get_gateway_formatter()->formatOrderDescription($payment);
516
-    }
26
+	/**
27
+	 * a constant used as a possible value for $_currencies_supported to indicate
28
+	 * that ALL currencies are supported by this gateway
29
+	 */
30
+	const all_currencies_supported = 'all_currencies_supported';
31
+	/**
32
+	 * Where values are 3-letter currency codes
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $_currencies_supported = array();
37
+	/**
38
+	 * Whether or not this gateway can support SENDING a refund request (ie, initiated by
39
+	 * admin in EE's wp-admin page)
40
+	 *
41
+	 * @var boolean
42
+	 */
43
+	protected $_supports_sending_refunds = false;
44
+
45
+	/**
46
+	 * Whether or not this gateway can support RECEIVING a refund request from the payment
47
+	 * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE)
48
+	 *
49
+	 * @var boolean
50
+	 */
51
+	protected $_supports_receiving_refunds = false;
52
+	/**
53
+	 * Model for querying for existing payments
54
+	 *
55
+	 * @var EEMI_Payment
56
+	 */
57
+	protected $_pay_model;
58
+
59
+	/**
60
+	 * Model used for adding to the payments log
61
+	 *
62
+	 * @var EEMI_Payment_Log
63
+	 */
64
+	protected $_pay_log;
65
+
66
+	/**
67
+	 * Used for formatting some input to gateways
68
+	 *
69
+	 * @var EEHI_Template
70
+	 */
71
+	protected $_template;
72
+
73
+	/**
74
+	 * Concrete class that implements EEHI_Money, used by most gateways
75
+	 *
76
+	 * @var EEHI_Money
77
+	 */
78
+	protected $_money;
79
+
80
+	/**
81
+	 * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree
82
+	 *
83
+	 * @var EEHI_Line_Item
84
+	 */
85
+	protected $_line_item;
86
+
87
+	/**
88
+	 * @var GatewayDataFormatterInterface
89
+	 */
90
+	protected $_gateway_data_formatter;
91
+
92
+	/**
93
+	 * @var FormatterInterface
94
+	 */
95
+	protected $_unsupported_character_remover;
96
+
97
+	/**
98
+	 * The ID of the payment method using this gateway
99
+	 *
100
+	 * @var int
101
+	 */
102
+	protected $_ID;
103
+
104
+	/**
105
+	 * @var $_debug_mode boolean whether to send requests to teh sandbox site or not
106
+	 */
107
+	protected $_debug_mode;
108
+	/**
109
+	 *
110
+	 * @var string $_name name to show for this payment method
111
+	 */
112
+	protected $_name;
113
+	/**
114
+	 *
115
+	 * @var string name to show fir this payment method to admin-type users
116
+	 */
117
+	protected $_admin_name;
118
+
119
+	/**
120
+	 * @return EE_Gateway
121
+	 */
122
+	public function __construct()
123
+	{
124
+	}
125
+
126
+	/**
127
+	 * We don't want to serialize models as they often have circular structures
128
+	 * (eg a payment model has a reference to each payment model object; and most
129
+	 * payments have a transaction, most transactions have a payment method;
130
+	 * most payment methods have a payment method type; most payment method types
131
+	 * have a gateway. And if a gateway serializes its models, we start at the
132
+	 * beginning again)
133
+	 *
134
+	 * @return array
135
+	 */
136
+	public function __sleep()
137
+	{
138
+		$properties = get_object_vars($this);
139
+		unset($properties['_pay_model'], $properties['_pay_log']);
140
+		return array_keys($properties);
141
+	}
142
+
143
+	/**
144
+	 * Returns whether or not this gateway should support SENDING refunds
145
+	 * see $_supports_sending_refunds
146
+	 *
147
+	 * @return boolean
148
+	 */
149
+	public function supports_sending_refunds()
150
+	{
151
+		return $this->_supports_sending_refunds;
152
+	}
153
+
154
+	/**
155
+	 * Returns whether or not this gateway should support RECEIVING refunds
156
+	 * see $_supports_receiving_refunds
157
+	 *
158
+	 * @return boolean
159
+	 */
160
+	public function supports_receiving_refunds()
161
+	{
162
+		return $this->_supports_receiving_refunds;
163
+	}
164
+
165
+
166
+	/**
167
+	 * Tries to refund the payment specified, taking into account the extra
168
+	 * refund info. Note that if the gateway's _supports_sending_refunds is false,
169
+	 * this should just throw an exception.
170
+	 *
171
+	 * @param EE_Payment $payment
172
+	 * @param array      $refund_info
173
+	 * @return EE_Payment for the refund
174
+	 * @throws EE_Error
175
+	 */
176
+	public function do_direct_refund(EE_Payment $payment, $refund_info = null)
177
+	{
178
+		return null;
179
+	}
180
+
181
+
182
+	/**
183
+	 * Sets the payment method's settings so the gateway knows where to send the request
184
+	 * etc
185
+	 *
186
+	 * @param array $settings_array
187
+	 */
188
+	public function set_settings($settings_array)
189
+	{
190
+		foreach ($settings_array as $name => $value) {
191
+			$property_name = "_" . $name;
192
+			$this->{$property_name} = $value;
193
+		}
194
+	}
195
+
196
+	/**
197
+	 * See this class description
198
+	 *
199
+	 * @param EEMI_Payment $payment_model
200
+	 */
201
+	public function set_payment_model($payment_model)
202
+	{
203
+		$this->_pay_model = $payment_model;
204
+	}
205
+
206
+	/**
207
+	 * See this class description
208
+	 *
209
+	 * @param EEMI_Payment_Log $payment_log_model
210
+	 */
211
+	public function set_payment_log($payment_log_model)
212
+	{
213
+		$this->_pay_log = $payment_log_model;
214
+	}
215
+
216
+	/**
217
+	 * See this class description
218
+	 *
219
+	 * @param EEHI_Template $template_helper
220
+	 */
221
+	public function set_template_helper($template_helper)
222
+	{
223
+		$this->_template = $template_helper;
224
+	}
225
+
226
+	/**
227
+	 * See this class description
228
+	 *
229
+	 * @param EEHI_Line_Item $line_item_helper
230
+	 */
231
+	public function set_line_item_helper($line_item_helper)
232
+	{
233
+		$this->_line_item = $line_item_helper;
234
+	}
235
+
236
+	/**
237
+	 * See this class description
238
+	 *
239
+	 * @param EEHI_Money $money_helper
240
+	 */
241
+	public function set_money_helper($money_helper)
242
+	{
243
+		$this->_money = $money_helper;
244
+	}
245
+
246
+
247
+	/**
248
+	 * Sets the gateway data formatter helper
249
+	 *
250
+	 * @param GatewayDataFormatterInterface $gateway_data_formatter
251
+	 * @throws InvalidEntityException if it's not set properly
252
+	 */
253
+	public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter)
254
+	{
255
+		if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) {
256
+			throw new InvalidEntityException(
257
+				is_object($gateway_data_formatter)
258
+					? get_class($gateway_data_formatter)
259
+					: esc_html__('Not an object', 'event_espresso'),
260
+				'\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface'
261
+			);
262
+		}
263
+		$this->_gateway_data_formatter = $gateway_data_formatter;
264
+	}
265
+
266
+	/**
267
+	 * Gets the gateway data formatter
268
+	 *
269
+	 * @return GatewayDataFormatterInterface
270
+	 * @throws InvalidEntityException if it's not set properly
271
+	 */
272
+	protected function _get_gateway_formatter()
273
+	{
274
+		if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) {
275
+			throw new InvalidEntityException(
276
+				is_object($this->_gateway_data_formatter)
277
+					? get_class($this->_gateway_data_formatter)
278
+					: esc_html__('Not an object', 'event_espresso'),
279
+				'\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface'
280
+			);
281
+		}
282
+		return $this->_gateway_data_formatter;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Sets the helper which will remove unsupported characters for most gateways
288
+	 *
289
+	 * @param FormatterInterface $formatter
290
+	 * @return FormatterInterface
291
+	 * @throws InvalidEntityException
292
+	 */
293
+	public function set_unsupported_character_remover(FormatterInterface $formatter)
294
+	{
295
+		if (! $formatter instanceof FormatterInterface) {
296
+			throw new InvalidEntityException(
297
+				is_object($formatter)
298
+					? get_class($formatter)
299
+					: esc_html__('Not an object', 'event_espresso'),
300
+				'\\EventEspresso\\core\\services\\formatters\\FormatterInterface'
301
+			);
302
+		}
303
+		$this->_unsupported_character_remover = $formatter;
304
+	}
305
+
306
+	/**
307
+	 * Gets the helper which removes characters which gateways might not support, like emojis etc.
308
+	 *
309
+	 * @return FormatterInterface
310
+	 * @throws InvalidEntityException
311
+	 */
312
+	protected function _get_unsupported_character_remover()
313
+	{
314
+		if (! $this->_unsupported_character_remover instanceof FormatterInterface) {
315
+			throw new InvalidEntityException(
316
+				is_object($this->_unsupported_character_remover)
317
+					? get_class($this->_unsupported_character_remover)
318
+					: esc_html__('Not an object', 'event_espresso'),
319
+				'\\EventEspresso\\core\\services\\formatters\\FormatterInterface'
320
+			);
321
+		}
322
+		return $this->_unsupported_character_remover;
323
+	}
324
+
325
+
326
+	/**
327
+	 * @param $message
328
+	 * @param $payment
329
+	 */
330
+	public function log($message, $object_logged)
331
+	{
332
+		if ($object_logged instanceof EEI_Payment) {
333
+			$type = 'Payment';
334
+			$id = $object_logged->ID();
335
+		} elseif ($object_logged instanceof EEI_Transaction) {
336
+			$type = 'Transaction';
337
+			$id = $object_logged->ID();
338
+		} else {
339
+			$type = 'Payment_Method';
340
+			$id = $this->_ID;
341
+		}
342
+		// only log if we're going to store it for longer than the minimum time
343
+		$reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
344
+		if ($reg_config->gateway_log_lifespan !== '1 second') {
345
+			$this->_pay_log->gateway_log($message, $id, $type);
346
+		}
347
+	}
348
+
349
+	/**
350
+	 * Formats the amount so it can generally be sent to gateways
351
+	 *
352
+	 * @param float $amount
353
+	 * @return string
354
+	 * @deprecated since 4.9.31 insetad use
355
+	 *             EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency()
356
+	 */
357
+	public function format_currency($amount)
358
+	{
359
+		return $this->_get_gateway_formatter()->formatCurrency($amount);
360
+	}
361
+
362
+	/**
363
+	 * Returns either an array of all the currency codes supported,
364
+	 * or a string indicating they're all supported (EE_gateway::all_currencies_supported)
365
+	 *
366
+	 * @return mixed array or string
367
+	 */
368
+	public function currencies_supported()
369
+	{
370
+		return $this->_currencies_supported;
371
+	}
372
+
373
+	/**
374
+	 * Returns what a simple summing of items and taxes for this transaction. This
375
+	 * can be used to determine if some more complex line items, like promotions,
376
+	 * surcharges, or cancellations occurred (in which case we might want to forget
377
+	 * about creating an itemized list of purchases and instead only send the total due)
378
+	 *
379
+	 * @param EE_Transaction $transaction
380
+	 * @return float
381
+	 */
382
+	protected function _sum_items_and_taxes(EE_Transaction $transaction)
383
+	{
384
+		$total_line_item = $transaction->total_line_item();
385
+		$total = 0;
386
+		foreach ($total_line_item->get_items() as $item_line_item) {
387
+			$total += max($item_line_item->total(), 0);
388
+		}
389
+		foreach ($total_line_item->tax_descendants() as $tax_line_item) {
390
+			$total += max($tax_line_item->total(), 0);
391
+		}
392
+		return $total;
393
+	}
394
+
395
+	/**
396
+	 * Determines whether or not we can easily itemize the transaction using only
397
+	 * items and taxes (ie, no promotions or surcharges or cancellations needed)
398
+	 *
399
+	 * @param EEI_Payment $payment
400
+	 * @return boolean
401
+	 */
402
+	protected function _can_easily_itemize_transaction_for(EEI_Payment $payment)
403
+	{
404
+		return $this->_money->compare_floats(
405
+			$this->_sum_items_and_taxes($payment->transaction()),
406
+			$payment->transaction()->total()
407
+		)
408
+			   && $this->_money->compare_floats(
409
+				   $payment->amount(),
410
+				   $payment->transaction()->total()
411
+			   );
412
+	}
413
+
414
+	/**
415
+	 * Handles updating the transaction and any other related data based on the payment.
416
+	 * You may be tempted to do this as part of do_direct_payment or handle_payment_update,
417
+	 * but doing so on those functions might be too early. It's possible that the changes
418
+	 * you make to teh transaction or registration or line items may just get overwritten
419
+	 * at that point. Instead, you should store any info you need on the payment during those
420
+	 * functions, and use that information at this step, which client code will decide
421
+	 * for you when it should be called.
422
+	 *
423
+	 * @param EE_Payment $payment
424
+	 * @return void
425
+	 */
426
+	public function update_txn_based_on_payment($payment)
427
+	{
428
+		// maybe update the transaction or line items or registrations
429
+		// but most gateways don't need to do this, because they only update the payment
430
+	}
431
+
432
+	/**
433
+	 * Gets the first event for this payment (it's possible that it could be for multiple)
434
+	 *
435
+	 * @param EEI_Payment $payment
436
+	 * @return EEI_Event|null
437
+	 * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event()
438
+	 */
439
+	protected function _get_first_event_for_payment(EEI_Payment $payment)
440
+	{
441
+		return $payment->get_first_event();
442
+	}
443
+
444
+	/**
445
+	 * Gets the name of the first event for which is being paid
446
+	 *
447
+	 * @param EEI_Payment $payment
448
+	 * @return string
449
+	 * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name()
450
+	 */
451
+	protected function _get_first_event_name_for_payment(EEI_Payment $payment)
452
+	{
453
+		return $payment->get_first_event_name();
454
+	}
455
+
456
+	/**
457
+	 * Gets the text to use for a gateway's line item name when this is a partial payment
458
+	 *
459
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment)
460
+	 * @param EE_Payment $payment
461
+	 * @return string
462
+	 */
463
+	protected function _format_partial_payment_line_item_name(EEI_Payment $payment)
464
+	{
465
+		return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment);
466
+	}
467
+
468
+	/**
469
+	 * Gets the text to use for a gateway's line item description when this is a partial payment
470
+	 *
471
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc()
472
+	 * @param EEI_Payment $payment
473
+	 * @return string
474
+	 */
475
+	protected function _format_partial_payment_line_item_desc(EEI_Payment $payment)
476
+	{
477
+		return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment);
478
+	}
479
+
480
+	/**
481
+	 * Gets the name to use for a line item when sending line items to the gateway
482
+	 *
483
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment)
484
+	 * @param EEI_Line_Item $line_item
485
+	 * @param EEI_Payment   $payment
486
+	 * @return string
487
+	 */
488
+	protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment)
489
+	{
490
+		return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment);
491
+	}
492
+
493
+	/**
494
+	 * Gets the description to use for a line item when sending line items to the gateway
495
+	 *
496
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment))
497
+	 * @param EEI_Line_Item $line_item
498
+	 * @param EEI_Payment   $payment
499
+	 * @return string
500
+	 */
501
+	protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment)
502
+	{
503
+		return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment);
504
+	}
505
+
506
+	/**
507
+	 * Gets the order description that should generlly be sent to gateways
508
+	 *
509
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment)
510
+	 * @param EEI_Payment $payment
511
+	 * @return type
512
+	 */
513
+	protected function _format_order_description(EEI_Payment $payment)
514
+	{
515
+		return $this->_get_gateway_formatter()->formatOrderDescription($payment);
516
+	}
517 517
 }
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.
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
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
             // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
252 252
             // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
253 253
             if (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
254
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
254
+                || ! empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
255 255
             ) {
256 256
                 return do_shortcode($event_meta);
257 257
             }
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 
270 270
         if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
271 271
             $attrs = $this->_get_shortcode_attrs($shortcode);
272
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
273
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
272
+            $width = empty($attrs['width']) ? '' : ' width="'.$attrs['width'].'"';
273
+            $height = empty($attrs['height']) ? '' : ' height="'.$attrs['height'].'"';
274 274
 
275 275
             // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
276
-            if (! empty($attrs['size'])) {
276
+            if ( ! empty($attrs['size'])) {
277 277
                 $size = explode(',', $attrs['size']);
278 278
                 if (count($size) === 1) {
279 279
                     $size = $size[0];
@@ -285,11 +285,11 @@  discard block
 block discarded – undo
285 285
             $image = $this->_event->feature_image_url($size);
286 286
 
287 287
             return ! empty($image)
288
-                ? '<img src="' . $image . '" alt="'
288
+                ? '<img src="'.$image.'" alt="'
289 289
                   . sprintf(
290 290
                       esc_attr__('%s Feature Image', 'event_espresso'),
291 291
                       $this->_event->get('EVT_name')
292
-                  ) . '"' . $width . $height . '/>'
292
+                  ).'"'.$width.$height.'/>'
293 293
                 : '';
294 294
         }
295 295
 
@@ -308,6 +308,6 @@  discard block
 block discarded – undo
308 308
     {
309 309
         $url = get_permalink($event->ID());
310 310
 
311
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
311
+        return $full_link ? '<a href="'.$url.'">'.$event->get('EVT_name').'</a>' : $url;
312 312
     }
313 313
 }
Please login to merge, or discard this patch.
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -19,296 +19,296 @@
 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 (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
255
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
256
-            ) {
257
-                return do_shortcode($event_meta);
258
-            }
259
-            // Still here? We just need to return the event_meta value as is.
260
-            return $event_meta;
261
-        }
262
-
263
-        if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
264
-            $attrs = $this->_get_shortcode_attrs($shortcode);
265
-            $method = empty($attrs['method']) ? 'current' : $attrs['method'];
266
-            $method = $method === 'current';
267
-            $available = $this->_event->total_available_spaces($method);
268
-            return $available === EE_INF ? '&infin;' : $available;
269
-        }
270
-
271
-        if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
272
-            $attrs = $this->_get_shortcode_attrs($shortcode);
273
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
274
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
275
-
276
-            // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
277
-            if (! empty($attrs['size'])) {
278
-                $size = explode(',', $attrs['size']);
279
-                if (count($size) === 1) {
280
-                    $size = $size[0];
281
-                }
282
-            } else {
283
-                $size = 'thumbnail';
284
-            }
285
-
286
-            $image = $this->_event->feature_image_url($size);
287
-
288
-            return ! empty($image)
289
-                ? '<img src="' . $image . '" alt="'
290
-                  . sprintf(
291
-                      esc_attr__('%s Feature Image', 'event_espresso'),
292
-                      $this->_event->get('EVT_name')
293
-                  ) . '"' . $width . $height . '/>'
294
-                : '';
295
-        }
296
-
297
-        return '';
298
-    }
299
-
300
-
301
-    /**
302
-     * returns the link to the event
303
-     *
304
-     * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
305
-     *                            Otherwise we just return the url of the event.
306
-     * @return string
307
-     */
308
-    private function _get_event_link($event, $full_link = true)
309
-    {
310
-        $url = get_permalink($event->ID());
311
-
312
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
313
-    }
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 (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
255
+				|| !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
256
+			) {
257
+				return do_shortcode($event_meta);
258
+			}
259
+			// Still here? We just need to return the event_meta value as is.
260
+			return $event_meta;
261
+		}
262
+
263
+		if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
264
+			$attrs = $this->_get_shortcode_attrs($shortcode);
265
+			$method = empty($attrs['method']) ? 'current' : $attrs['method'];
266
+			$method = $method === 'current';
267
+			$available = $this->_event->total_available_spaces($method);
268
+			return $available === EE_INF ? '&infin;' : $available;
269
+		}
270
+
271
+		if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
272
+			$attrs = $this->_get_shortcode_attrs($shortcode);
273
+			$width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
274
+			$height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
275
+
276
+			// Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
277
+			if (! empty($attrs['size'])) {
278
+				$size = explode(',', $attrs['size']);
279
+				if (count($size) === 1) {
280
+					$size = $size[0];
281
+				}
282
+			} else {
283
+				$size = 'thumbnail';
284
+			}
285
+
286
+			$image = $this->_event->feature_image_url($size);
287
+
288
+			return ! empty($image)
289
+				? '<img src="' . $image . '" alt="'
290
+				  . sprintf(
291
+					  esc_attr__('%s Feature Image', 'event_espresso'),
292
+					  $this->_event->get('EVT_name')
293
+				  ) . '"' . $width . $height . '/>'
294
+				: '';
295
+		}
296
+
297
+		return '';
298
+	}
299
+
300
+
301
+	/**
302
+	 * returns the link to the event
303
+	 *
304
+	 * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
305
+	 *                            Otherwise we just return the url of the event.
306
+	 * @return string
307
+	 */
308
+	private function _get_event_link($event, $full_link = true)
309
+	{
310
+		$url = get_permalink($event->ID());
311
+
312
+		return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
313
+	}
314 314
 }
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   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -19,205 +19,205 @@
 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 (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
138
-                    && $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
139
-                ) {
140
-                    $adj_tkts[] = $tkt;
141
-                }
142
-            }
143
-            $evt_tkts = $adj_tkts;
144
-        }
145
-        return $evt_tkts;
146
-    }
147
-
148
-
149
-    /**
150
-     * figure out what the incoming data is and then return the appropriate parsed value
151
-     *
152
-     * @param  boolean $primary whether we're getting the primary registrant ticket_list.
153
-     * @return string
154
-     */
155
-    private function _get_recipient_datetime_list($primary = false)
156
-    {
157
-        $this->_validate_list_requirements();
158
-
159
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
160
-            return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
161
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
162
-            return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data'], $primary);
163
-        } else {
164
-            return '';
165
-        }
166
-
167
-        return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
168
-    }
169
-
170
-
171
-    private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
172
-    {
173
-        $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
174
-        if (! $registration instanceof EE_Registration) {
175
-            return '';
176
-        }
177
-        // setup valid shortcodes depending on what the status of the $this->_data property is
178
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
179
-            $valid_shortcodes = array('datetime', 'attendee');
180
-            $template = $this->_data['template'];
181
-            $dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
182
-            $data = $this->_data;
183
-        } elseif ($this->_data['data'] instanceof EE_Event) {
184
-            $valid_shortcodes = array('datetime', 'attendee');
185
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
186
-                ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
187
-            $dtts = $this->_get_datetimes_from_event($this->_data['data'], $registration);
188
-            $data = $this->_extra_data;
189
-        } else {
190
-            return '';
191
-        }
192
-
193
-        $dtt_parsed = '';
194
-        foreach ($dtts as $datetime) {
195
-            $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
196
-                $template,
197
-                $datetime,
198
-                $valid_shortcodes,
199
-                $this->_extra_data
200
-            );
201
-        }
202
-        return $dtt_parsed;
203
-    }
204
-
205
-
206
-    private function _get_datetimes_from_event(EE_Event $event, $reg = null)
207
-    {
208
-        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
209
-        ) ]['dtt_objs'] : array();
210
-
211
-        if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
212
-            $adj_dtts = array();
213
-            // return only dtts for the given attendee
214
-            foreach ($evt_dtts as $dtt) {
215
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
216
-                    $adj_dtts[] = $dtt;
217
-                }
218
-            }
219
-            $evt_dtts = $adj_dtts;
220
-        }
221
-        return $evt_dtts;
222
-    }
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 (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
138
+					&& $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
139
+				) {
140
+					$adj_tkts[] = $tkt;
141
+				}
142
+			}
143
+			$evt_tkts = $adj_tkts;
144
+		}
145
+		return $evt_tkts;
146
+	}
147
+
148
+
149
+	/**
150
+	 * figure out what the incoming data is and then return the appropriate parsed value
151
+	 *
152
+	 * @param  boolean $primary whether we're getting the primary registrant ticket_list.
153
+	 * @return string
154
+	 */
155
+	private function _get_recipient_datetime_list($primary = false)
156
+	{
157
+		$this->_validate_list_requirements();
158
+
159
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
160
+			return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
161
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
162
+			return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data'], $primary);
163
+		} else {
164
+			return '';
165
+		}
166
+
167
+		return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
168
+	}
169
+
170
+
171
+	private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
172
+	{
173
+		$registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
174
+		if (! $registration instanceof EE_Registration) {
175
+			return '';
176
+		}
177
+		// setup valid shortcodes depending on what the status of the $this->_data property is
178
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
179
+			$valid_shortcodes = array('datetime', 'attendee');
180
+			$template = $this->_data['template'];
181
+			$dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
182
+			$data = $this->_data;
183
+		} elseif ($this->_data['data'] instanceof EE_Event) {
184
+			$valid_shortcodes = array('datetime', 'attendee');
185
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
186
+				? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
187
+			$dtts = $this->_get_datetimes_from_event($this->_data['data'], $registration);
188
+			$data = $this->_extra_data;
189
+		} else {
190
+			return '';
191
+		}
192
+
193
+		$dtt_parsed = '';
194
+		foreach ($dtts as $datetime) {
195
+			$dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
196
+				$template,
197
+				$datetime,
198
+				$valid_shortcodes,
199
+				$this->_extra_data
200
+			);
201
+		}
202
+		return $dtt_parsed;
203
+	}
204
+
205
+
206
+	private function _get_datetimes_from_event(EE_Event $event, $reg = null)
207
+	{
208
+		$evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
209
+		) ]['dtt_objs'] : array();
210
+
211
+		if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
212
+			$adj_dtts = array();
213
+			// return only dtts for the given attendee
214
+			foreach ($evt_dtts as $dtt) {
215
+				if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
216
+					$adj_dtts[] = $dtt;
217
+				}
218
+			}
219
+			$evt_dtts = $adj_dtts;
220
+		}
221
+		return $evt_dtts;
222
+	}
223 223
 }
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,15 +127,15 @@  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
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
138
-                    && $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
137
+                if (isset($this->_extra_data['data']->registrations[$reg->ID()]['tkt_obj'])
138
+                    && $this->_extra_data['data']->registrations[$reg->ID()]['tkt_obj']->ID() == $tkt->ID()
139 139
                 ) {
140 140
                     $adj_tkts[] = $tkt;
141 141
                 }
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
     private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
172 172
     {
173 173
         $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
174
-        if (! $registration instanceof EE_Registration) {
174
+        if ( ! $registration instanceof EE_Registration) {
175 175
             return '';
176 176
         }
177 177
         // setup valid shortcodes depending on what the status of the $this->_data property is
178 178
         if ($this->_data['data'] instanceof EE_Messages_Addressee) {
179 179
             $valid_shortcodes = array('datetime', 'attendee');
180 180
             $template = $this->_data['template'];
181
-            $dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
181
+            $dtts = $data->registrations[$registration->ID()]['dtt_objs'];
182 182
             $data = $this->_data;
183 183
         } elseif ($this->_data['data'] instanceof EE_Event) {
184 184
             $valid_shortcodes = array('datetime', 'attendee');
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
 
206 206
     private function _get_datetimes_from_event(EE_Event $event, $reg = null)
207 207
     {
208
-        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
209
-        ) ]['dtt_objs'] : array();
208
+        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID(
209
+        )]['dtt_objs'] : array();
210 210
 
211 211
         if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
212 212
             $adj_dtts = array();
213 213
             // return only dtts for the given attendee
214 214
             foreach ($evt_dtts as $dtt) {
215
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
215
+                if (isset($this->_extra_data['data']->registrations[$reg->ID()]['dtt_objs'][$dtt->ID()])) {
216 216
                     $adj_dtts[] = $dtt;
217 217
                 }
218 218
             }
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.