Completed
Branch dependabot/npm_and_yarn/@wordp... (e9f48b)
by
unknown
60:52 queued 52:34
created
core/libraries/messages/EE_Messenger_Collection.lib.php 2 patches
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -14,183 +14,183 @@
 block discarded – undo
14 14
 class EE_Messenger_Collection extends EE_Object_Collection
15 15
 {
16 16
 
17
-    /**
18
-     * EE_Messenger_Collection constructor.
19
-     */
20
-    public function __construct()
21
-    {
22
-        $this->interface = 'EE_messenger';
23
-    }
24
-
25
-
26
-
27
-    /**
28
-     * add
29
-     *
30
-     * attaches an object to the Collection
31
-     * and sets any supplied data associated with the current iterator entry
32
-     * by calling EE_Object_Collection::set_info()
33
-     *
34
-     * @access public
35
-     * @param object $object
36
-     * @param mixed  $info
37
-     * @return bool
38
-     */
39
-    public function add($object, $info = null)
40
-    {
41
-        $info = empty($info) && $object instanceof $this->interface ? $object->name : $info;
42
-        return parent::add($object, $info);
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * set_info
49
-     *
50
-     * Sets the data associated with an object in the Collection
51
-     * if no $info is supplied, then the spl_object_hash() is used
52
-     *
53
-     * @access public
54
-     * @param object $object
55
-     * @param mixed  $info
56
-     * @return bool
57
-     */
58
-    public function set_info($object, $info = null)
59
-    {
60
-        $info = empty($info) && $object instanceof $this->interface ? $object->name : $info;
61
-        return parent::set_info($object, $info);
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * get_by_info
68
-     *
69
-     * finds and returns an object in the Collection based on the info that was set using addObject()
70
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
71
-     *
72
-     * @access public
73
-     * @param mixed
74
-     * @return null | object
75
-     */
76
-    public function get_by_info($info)
77
-    {
78
-        return parent::get_by_info(str_replace(' ', '_', strtolower($info)));
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     * has
85
-     *
86
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
87
-     *
88
-     * @access public
89
-     * @param object $object
90
-     * @return bool
91
-     */
92
-    public function has($object)
93
-    {
94
-        return parent::has($object);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * has_by_name
101
-     *
102
-     * returns TRUE or FALSE depending on whether the supplied messenger name is within the Collection
103
-     *
104
-     * @access public
105
-     * @param string $messenger_name
106
-     * @return bool
107
-     */
108
-    public function has_by_name($messenger_name)
109
-    {
110
-        return $this->get_by_info($messenger_name) instanceof $this->interface ? true : false;
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * remove
117
-     *
118
-     * detaches an object from the Collection
119
-     *
120
-     * @access public
121
-     * @param $object
122
-     * @return bool
123
-     */
124
-    public function remove($object)
125
-    {
126
-        return parent::remove($object);
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * current
133
-     *
134
-     * current object from the Collection
135
-     *
136
-     * @access public
137
-     * @return EE_messenger
138
-     */
139
-    public function current()
140
-    {
141
-        return parent::current();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * set_current
148
-     *
149
-     * advances pointer to the provided object
150
-     *
151
-     * @access public
152
-     * @param $object
153
-     * @return void
154
-     */
155
-    public function set_current($object)
156
-    {
157
-        parent::set_current($object);
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * set_current_by_info
164
-     *
165
-     * advances pointer to the object whose info matches that which was provided
166
-     *
167
-     * @access public
168
-     * @param $info
169
-     * @return void
170
-     */
171
-    public function set_current_by_info($info)
172
-    {
173
-        parent::set_current_by_info($info);
174
-    }
175
-
176
-
177
-
178
-    /**
179
-     * show_collection_classes
180
-     *
181
-     * displays list of collection classes if WP_DEBUG is on
182
-     *
183
-     * @access public
184
-     * @return void
185
-     */
186
-    public function show_collection_classes()
187
-    {
188
-        if (WP_DEBUG) {
189
-            $this->rewind();
190
-            while ($this->valid()) {
191
-                echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : . <span style="color:#E76700">' . $this->getInfo() . '</span></h5>';
192
-                $this->next();
193
-            }
194
-        }
195
-    }
17
+	/**
18
+	 * EE_Messenger_Collection constructor.
19
+	 */
20
+	public function __construct()
21
+	{
22
+		$this->interface = 'EE_messenger';
23
+	}
24
+
25
+
26
+
27
+	/**
28
+	 * add
29
+	 *
30
+	 * attaches an object to the Collection
31
+	 * and sets any supplied data associated with the current iterator entry
32
+	 * by calling EE_Object_Collection::set_info()
33
+	 *
34
+	 * @access public
35
+	 * @param object $object
36
+	 * @param mixed  $info
37
+	 * @return bool
38
+	 */
39
+	public function add($object, $info = null)
40
+	{
41
+		$info = empty($info) && $object instanceof $this->interface ? $object->name : $info;
42
+		return parent::add($object, $info);
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * set_info
49
+	 *
50
+	 * Sets the data associated with an object in the Collection
51
+	 * if no $info is supplied, then the spl_object_hash() is used
52
+	 *
53
+	 * @access public
54
+	 * @param object $object
55
+	 * @param mixed  $info
56
+	 * @return bool
57
+	 */
58
+	public function set_info($object, $info = null)
59
+	{
60
+		$info = empty($info) && $object instanceof $this->interface ? $object->name : $info;
61
+		return parent::set_info($object, $info);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * get_by_info
68
+	 *
69
+	 * finds and returns an object in the Collection based on the info that was set using addObject()
70
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
71
+	 *
72
+	 * @access public
73
+	 * @param mixed
74
+	 * @return null | object
75
+	 */
76
+	public function get_by_info($info)
77
+	{
78
+		return parent::get_by_info(str_replace(' ', '_', strtolower($info)));
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 * has
85
+	 *
86
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
87
+	 *
88
+	 * @access public
89
+	 * @param object $object
90
+	 * @return bool
91
+	 */
92
+	public function has($object)
93
+	{
94
+		return parent::has($object);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * has_by_name
101
+	 *
102
+	 * returns TRUE or FALSE depending on whether the supplied messenger name is within the Collection
103
+	 *
104
+	 * @access public
105
+	 * @param string $messenger_name
106
+	 * @return bool
107
+	 */
108
+	public function has_by_name($messenger_name)
109
+	{
110
+		return $this->get_by_info($messenger_name) instanceof $this->interface ? true : false;
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * remove
117
+	 *
118
+	 * detaches an object from the Collection
119
+	 *
120
+	 * @access public
121
+	 * @param $object
122
+	 * @return bool
123
+	 */
124
+	public function remove($object)
125
+	{
126
+		return parent::remove($object);
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * current
133
+	 *
134
+	 * current object from the Collection
135
+	 *
136
+	 * @access public
137
+	 * @return EE_messenger
138
+	 */
139
+	public function current()
140
+	{
141
+		return parent::current();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * set_current
148
+	 *
149
+	 * advances pointer to the provided object
150
+	 *
151
+	 * @access public
152
+	 * @param $object
153
+	 * @return void
154
+	 */
155
+	public function set_current($object)
156
+	{
157
+		parent::set_current($object);
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * set_current_by_info
164
+	 *
165
+	 * advances pointer to the object whose info matches that which was provided
166
+	 *
167
+	 * @access public
168
+	 * @param $info
169
+	 * @return void
170
+	 */
171
+	public function set_current_by_info($info)
172
+	{
173
+		parent::set_current_by_info($info);
174
+	}
175
+
176
+
177
+
178
+	/**
179
+	 * show_collection_classes
180
+	 *
181
+	 * displays list of collection classes if WP_DEBUG is on
182
+	 *
183
+	 * @access public
184
+	 * @return void
185
+	 */
186
+	public function show_collection_classes()
187
+	{
188
+		if (WP_DEBUG) {
189
+			$this->rewind();
190
+			while ($this->valid()) {
191
+				echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : . <span style="color:#E76700">' . $this->getInfo() . '</span></h5>';
192
+				$this->next();
193
+			}
194
+		}
195
+	}
196 196
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -188,7 +188,7 @@
 block discarded – undo
188 188
         if (WP_DEBUG) {
189 189
             $this->rewind();
190 190
             while ($this->valid()) {
191
-                echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : . <span style="color:#E76700">' . $this->getInfo() . '</span></h5>';
191
+                echo '<h5 style="color:#2EA2CC;">'.__CLASS__.' class : . <span style="color:#E76700">'.$this->getInfo().'</span></h5>';
192 192
                 $this->next();
193 193
             }
194 194
         }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Html_messenger.class.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
                     ),
314 314
                     'ticket_line_item_no_pms' => array(
315 315
                         'input' => 'textarea',
316
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
316
+                        'label' => '[TICKET_LINE_ITEM_LIST] <br>'.__(
317 317
                             'Ticket Line Item List with no Price Modifiers',
318 318
                             'event_espresso'
319 319
                         ),
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
                     ),
328 328
                     'ticket_line_item_pms' => array(
329 329
                         'input' => 'textarea',
330
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
330
+                        'label' => '[TICKET_LINE_ITEM_LIST] <br>'.__(
331 331
                             'Ticket Line Item List with Price Modifiers',
332 332
                             'event_espresso'
333 333
                         ),
Please login to merge, or discard this patch.
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -12,548 +12,548 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * The following are the properties that this messenger requires for displaying the html
17
-     */
18
-    /**
19
-     * This is the html body generated by the template via the message type.
20
-     *
21
-     * @var string
22
-     */
23
-    protected $_content;
24
-
25
-
26
-    /**
27
-     * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
28
-     * equivalent to the "subject" of the page.
29
-     *
30
-     * @var string
31
-     */
32
-    protected $_subject;
33
-
34
-
35
-    /**
36
-     * EE_Html_messenger constructor.
37
-     */
38
-    public function __construct()
39
-    {
40
-        // set properties
41
-        $this->name = 'html';
42
-        $this->description = __('This messenger outputs a message to a browser for display.', 'event_espresso');
43
-        $this->label = array(
44
-            'singular' => __('html', 'event_espresso'),
45
-            'plural' => __('html', 'event_espresso'),
46
-        );
47
-        $this->activate_on_install = true;
48
-        // add the "powered by EE" credit link to the HTML receipt and invoice
49
-        add_filter(
50
-            'FHEE__EE_Html_messenger___send_message__main_body',
51
-            array($this, 'add_powered_by_credit_link_to_receipt_and_invoice'),
52
-            10,
53
-            3
54
-        );
55
-        parent::__construct();
56
-    }
57
-
58
-
59
-    /**
60
-     * HTML Messenger desires execution immediately.
61
-     *
62
-     * @see    parent::send_now() for documentation.
63
-     * @since  4.9.0
64
-     * @return bool
65
-     */
66
-    public function send_now()
67
-    {
68
-        return true;
69
-    }
70
-
71
-
72
-    /**
73
-     * HTML Messenger allows an empty to field.
74
-     *
75
-     * @see    parent::allow_empty_to_field() for documentation
76
-     * @since  4.9.0
77
-     * @return bool
78
-     */
79
-    public function allow_empty_to_field()
80
-    {
81
-        return true;
82
-    }
83
-
84
-
85
-    /**
86
-     * @see abstract declaration in EE_messenger for details.
87
-     */
88
-    protected function _set_admin_pages()
89
-    {
90
-        $this->admin_registered_pages = array('events_edit' => true);
91
-    }
92
-
93
-
94
-    /**
95
-     * @see abstract declaration in EE_messenger for details.
96
-     */
97
-    protected function _set_valid_shortcodes()
98
-    {
99
-        $this->_valid_shortcodes = array();
100
-    }
101
-
102
-
103
-    /**
104
-     * @see abstract declaration in EE_messenger for details.
105
-     */
106
-    protected function _set_validator_config()
107
-    {
108
-        $this->_validator_config = array(
109
-            'subject' => array(
110
-                'shortcodes' => array('organization', 'primary_registration_details', 'email', 'transaction'),
111
-            ),
112
-            'content' => array(
113
-                'shortcodes' => array(
114
-                    'organization',
115
-                    'primary_registration_list',
116
-                    'primary_registration_details',
117
-                    'email',
118
-                    'transaction',
119
-                    'event_list',
120
-                    'payment_list',
121
-                    'venue',
122
-                    'line_item_list',
123
-                    'messenger',
124
-                    'ticket_list',
125
-                ),
126
-            ),
127
-            'event_list' => array(
128
-                'shortcodes' => array(
129
-                    'event',
130
-                    'ticket_list',
131
-                    'venue',
132
-                    'primary_registration_details',
133
-                    'primary_registration_list',
134
-                    'event_author',
135
-                ),
136
-                'required' => array('[EVENT_LIST]'),
137
-            ),
138
-            'ticket_list' => array(
139
-                'shortcodes' => array(
140
-                    'attendee_list',
141
-                    'ticket',
142
-                    'datetime_list',
143
-                    'primary_registration_details',
144
-                    'line_item_list',
145
-                    'venue',
146
-                ),
147
-                'required' => array('[TICKET_LIST]'),
148
-            ),
149
-            'ticket_line_item_no_pms' => array(
150
-                'shortcodes' => array('line_item', 'ticket'),
151
-                'required' => array('[TICKET_LINE_ITEM_LIST]'),
152
-            ),
153
-            'ticket_line_item_pms' => array(
154
-                'shortcodes' => array('line_item', 'ticket', 'line_item_list'),
155
-                'required' => array('[TICKET_LINE_ITEM_LIST]'),
156
-            ),
157
-            'price_modifier_line_item_list' => array(
158
-                'shortcodes' => array('line_item'),
159
-                'required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
160
-            ),
161
-            'datetime_list' => array(
162
-                'shortcodes' => array('datetime'),
163
-                'required' => array('[DATETIME_LIST]'),
164
-            ),
165
-            'attendee_list' => array(
166
-                'shortcodes' => array('attendee'),
167
-                'required' => array('[ATTENDEE_LIST]'),
168
-            ),
169
-            'tax_line_item_list' => array(
170
-                'shortcodes' => array('line_item'),
171
-                'required' => array('[TAX_LINE_ITEM_LIST]'),
172
-            ),
173
-            'additional_line_item_list' => array(
174
-                'shortcodes' => array('line_item'),
175
-                'required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
176
-            ),
177
-            'payment_list' => array(
178
-                'shortcodes' => array('payment'),
179
-                'required' => array('[PAYMENT_LIST_*]'),
180
-            ),
181
-        );
182
-    }
183
-
184
-
185
-    /**
186
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
187
-     * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
188
-     * (i.e. swap out css files or something else).
189
-     *
190
-     * @since 4.5.0
191
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
192
-     * @return void
193
-     */
194
-    public function do_secondary_messenger_hooks($sending_messenger_name)
195
-    {
196
-        if ($sending_messenger_name === 'pdf') {
197
-            add_filter('EE_messenger__get_variation__variation', array($this, 'add_html_css'), 10, 8);
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * @param                            $variation_path
204
-     * @param \EE_Messages_Template_Pack $template_pack
205
-     * @param                            $messenger_name
206
-     * @param                            $message_type_name
207
-     * @param                            $url
208
-     * @param                            $type
209
-     * @param                            $variation
210
-     * @param                            $skip_filters
211
-     * @return string
212
-     */
213
-    public function add_html_css(
214
-        $variation_path,
215
-        EE_Messages_Template_Pack $template_pack,
216
-        $messenger_name,
217
-        $message_type_name,
218
-        $url,
219
-        $type,
220
-        $variation,
221
-        $skip_filters
222
-    ) {
223
-        $variation = $template_pack->get_variation(
224
-            $this->name,
225
-            $message_type_name,
226
-            $type,
227
-            $variation,
228
-            $url,
229
-            '.css',
230
-            $skip_filters
231
-        );
232
-        return $variation;
233
-    }
234
-
235
-
236
-    /**
237
-     * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
238
-     * messenger can add their own js.
239
-     *
240
-     * @return void.
241
-     */
242
-    public function enqueue_scripts_styles()
243
-    {
244
-        parent::enqueue_scripts_styles();
245
-        do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
246
-    }
247
-
248
-
249
-    /**
250
-     * _set_template_fields
251
-     * This sets up the fields that a messenger requires for the message to go out.
252
-     *
253
-     * @access  protected
254
-     * @return void
255
-     */
256
-    protected function _set_template_fields()
257
-    {
258
-        // any extra template fields that are NOT used by the messenger
259
-        // but will get used by a messenger field for shortcode replacement
260
-        // get added to the 'extra' key in an associated array
261
-        // indexed by the messenger field they relate to.
262
-        // This is important for the Messages_admin to know what fields to display to the user.
263
-        // Also, notice that the "values" are equal to the field type
264
-        // that messages admin will use to know what kind of field to display.
265
-        // The values ALSO have one index labeled "shortcode".
266
-        // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
267
-        // is required in order for this extra field to be displayed.
268
-        //  If the required shortcode isn't part of the shortcodes array
269
-        // then the field is not needed and will not be displayed/parsed.
270
-        $this->_template_fields = array(
271
-            'subject' => array(
272
-                'input' => 'text',
273
-                'label' => __('Page Title', 'event_espresso'),
274
-                'type' => 'string',
275
-                'required' => true,
276
-                'validation' => true,
277
-                'css_class' => 'large-text',
278
-                'format' => '%s',
279
-            ),
280
-            'content' => '',
281
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
282
-            'extra' => array(
283
-                'content' => array(
284
-                    'main' => array(
285
-                        'input' => 'wp_editor',
286
-                        'label' => __('Main Content', 'event_espresso'),
287
-                        'type' => 'string',
288
-                        'required' => true,
289
-                        'validation' => true,
290
-                        'format' => '%s',
291
-                        'rows' => '15',
292
-                    ),
293
-                    'event_list' => array(
294
-                        'input' => 'wp_editor',
295
-                        'label' => '[EVENT_LIST]',
296
-                        'type' => 'string',
297
-                        'required' => true,
298
-                        'validation' => true,
299
-                        'format' => '%s',
300
-                        'rows' => '15',
301
-                        'shortcodes_required' => array('[EVENT_LIST]'),
302
-                    ),
303
-                    'ticket_list' => array(
304
-                        'input' => 'textarea',
305
-                        'label' => '[TICKET_LIST]',
306
-                        'type' => 'string',
307
-                        'required' => true,
308
-                        'validation' => true,
309
-                        'format' => '%s',
310
-                        'css_class' => 'large-text',
311
-                        'rows' => '10',
312
-                        'shortcodes_required' => array('[TICKET_LIST]'),
313
-                    ),
314
-                    'ticket_line_item_no_pms' => array(
315
-                        'input' => 'textarea',
316
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
317
-                            'Ticket Line Item List with no Price Modifiers',
318
-                            'event_espresso'
319
-                        ),
320
-                        'type' => 'string',
321
-                        'required' => false,
322
-                        'validation' => true,
323
-                        'format' => '%s',
324
-                        'css_class' => 'large-text',
325
-                        'rows' => '5',
326
-                        'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
327
-                    ),
328
-                    'ticket_line_item_pms' => array(
329
-                        'input' => 'textarea',
330
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
331
-                            'Ticket Line Item List with Price Modifiers',
332
-                            'event_espresso'
333
-                        ),
334
-                        'type' => 'string',
335
-                        'required' => false,
336
-                        'validation' => true,
337
-                        'format' => '%s',
338
-                        'css_class' => 'large-text',
339
-                        'rows' => '5',
340
-                        'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
341
-                    ),
342
-                    'price_modifier_line_item_list' => array(
343
-                        'input' => 'textarea',
344
-                        'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
345
-                        'type' => 'string',
346
-                        'required' => false,
347
-                        'validation' => true,
348
-                        'format' => '%s',
349
-                        'css_class' => 'large-text',
350
-                        'rows' => '5',
351
-                        'shortcodes_required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
352
-                    ),
353
-                    'datetime_list' => array(
354
-                        'input' => 'textarea',
355
-                        'label' => '[DATETIME_LIST]',
356
-                        'type' => 'string',
357
-                        'required' => true,
358
-                        'validation' => true,
359
-                        'format' => '%s',
360
-                        'css_class' => 'large-text',
361
-                        'rows' => '5',
362
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
363
-                    ),
364
-                    'attendee_list' => array(
365
-                        'input' => 'textarea',
366
-                        'label' => '[ATTENDEE_LIST]',
367
-                        'type' => 'string',
368
-                        'required' => true,
369
-                        'validation' => true,
370
-                        'format' => '%s',
371
-                        'css_class' => 'large-text',
372
-                        'rows' => '5',
373
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
374
-                    ),
375
-                    'tax_line_item_list' => array(
376
-                        'input' => 'textarea',
377
-                        'label' => '[TAX_LINE_ITEM_LIST]',
378
-                        'type' => 'string',
379
-                        'required' => false,
380
-                        'validation' => true,
381
-                        'format' => '%s',
382
-                        'css_class' => 'large-text',
383
-                        'rows' => '5',
384
-                        'shortcodes_required' => array('[TAX_LINE_ITEM_LIST]'),
385
-                    ),
386
-                    'additional_line_item_list' => array(
387
-                        'input' => 'textarea',
388
-                        'label' => '[ADDITIONAL_LINE_ITEM_LIST]',
389
-                        'type' => 'string',
390
-                        'required' => false,
391
-                        'validation' => true,
392
-                        'format' => '%s',
393
-                        'css_class' => 'large-text',
394
-                        'rows' => '5',
395
-                        'shortcodes_required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
396
-                    ),
397
-                    'payment_list' => array(
398
-                        'input' => 'textarea',
399
-                        'label' => '[PAYMENT_LIST]',
400
-                        'type' => 'string',
401
-                        'required' => true,
402
-                        'validation' => true,
403
-                        'format' => '%s',
404
-                        'css_class' => 'large-text',
405
-                        'rows' => '5',
406
-                        'shortcodes_required' => array('[PAYMENT_LIST_*]'),
407
-                    ),
408
-                ),
409
-            ),
410
-        );
411
-    }
412
-
413
-
414
-    /**
415
-     * @see   definition of this method in parent
416
-     * @since 4.5.0
417
-     */
418
-    protected function _set_default_message_types()
419
-    {
420
-        $this->_default_message_types = array('receipt', 'invoice');
421
-    }
422
-
423
-
424
-    /**
425
-     * @see   definition of this method in parent
426
-     * @since 4.5.0
427
-     */
428
-    protected function _set_valid_message_types()
429
-    {
430
-        $this->_valid_message_types = array('receipt', 'invoice');
431
-    }
432
-
433
-
434
-    /**
435
-     * Displays the message in the browser.
436
-     *
437
-     * @since 4.5.0
438
-     * @return string.
439
-     */
440
-    protected function _send_message()
441
-    {
442
-        $this->_template_args = array(
443
-            'page_title' => $this->_subject,
444
-            'base_css' => $this->get_variation(
445
-                $this->_tmp_pack,
446
-                $this->_incoming_message_type->name,
447
-                true,
448
-                'base',
449
-                $this->_variation
450
-            ),
451
-            'print_css' => $this->get_variation(
452
-                $this->_tmp_pack,
453
-                $this->_incoming_message_type->name,
454
-                true,
455
-                'print',
456
-                $this->_variation
457
-            ),
458
-            'main_css' => $this->get_variation(
459
-                $this->_tmp_pack,
460
-                $this->_incoming_message_type->name,
461
-                true,
462
-                'main',
463
-                $this->_variation
464
-            ),
465
-            'main_body' => wpautop(
466
-                apply_filters(
467
-                    'FHEE__EE_Html_messenger___send_message__main_body',
468
-                    $this->_content,
469
-                    $this->_content,
470
-                    $this->_incoming_message_type
471
-                )
472
-            )
473
-        );
474
-        $this->_deregister_wp_hooks();
475
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
476
-        echo $this->_get_main_template();
477
-        exit();
478
-    }
479
-
480
-
481
-    /**
482
-     * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
483
-     * interfere with our templates.  If users want to add any custom styles or scripts they must use the
484
-     * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
485
-     *
486
-     * @since 4.5.0
487
-     * @return void
488
-     */
489
-    protected function _deregister_wp_hooks()
490
-    {
491
-        remove_all_actions('wp_head');
492
-        remove_all_actions('wp_footer');
493
-        remove_all_actions('wp_print_footer_scripts');
494
-        remove_all_actions('wp_enqueue_scripts');
495
-        global $wp_scripts, $wp_styles;
496
-        $wp_scripts = $wp_styles = array();
497
-        // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
498
-        add_action('wp_footer', 'wp_print_footer_scripts');
499
-        add_action('wp_print_footer_scripts', '_wp_footer_scripts');
500
-        add_action('wp_head', 'wp_enqueue_scripts');
501
-    }
502
-
503
-
504
-    /**
505
-     * Overwrite parent _get_main_template for display_html purposes.
506
-     *
507
-     * @since  4.5.0
508
-     * @param bool $preview
509
-     * @return string
510
-     */
511
-    protected function _get_main_template($preview = false)
512
-    {
513
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, 'main');
514
-        // include message type as a template arg
515
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
516
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
517
-    }
518
-
519
-
520
-    /**
521
-     * @return string
522
-     */
523
-    protected function _preview()
524
-    {
525
-        return $this->_send_message();
526
-    }
527
-
528
-
529
-    protected function _set_admin_settings_fields()
530
-    {
531
-    }
532
-
533
-
534
-    /**
535
-     * add the "powered by EE" credit link to the HTML receipt and invoice
536
-     *
537
-     * @param string $content
538
-     * @param string $content_again
539
-     * @param \EE_message_type $incoming_message_type
540
-     * @return string
541
-     */
542
-    public function add_powered_by_credit_link_to_receipt_and_invoice(
543
-        $content = '',
544
-        $content_again = '',
545
-        EE_message_type $incoming_message_type
546
-    ) {
547
-        if (($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
548
-            && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
549
-        ) {
550
-            $content .= \EEH_Template::powered_by_event_espresso(
551
-                'aln-cntr',
552
-                '',
553
-                array('utm_content' => 'messages_system')
554
-            )
555
-                . EEH_HTML::div(EEH_HTML::p('&nbsp;'));
556
-        }
557
-        return $content;
558
-    }
15
+	/**
16
+	 * The following are the properties that this messenger requires for displaying the html
17
+	 */
18
+	/**
19
+	 * This is the html body generated by the template via the message type.
20
+	 *
21
+	 * @var string
22
+	 */
23
+	protected $_content;
24
+
25
+
26
+	/**
27
+	 * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
28
+	 * equivalent to the "subject" of the page.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected $_subject;
33
+
34
+
35
+	/**
36
+	 * EE_Html_messenger constructor.
37
+	 */
38
+	public function __construct()
39
+	{
40
+		// set properties
41
+		$this->name = 'html';
42
+		$this->description = __('This messenger outputs a message to a browser for display.', 'event_espresso');
43
+		$this->label = array(
44
+			'singular' => __('html', 'event_espresso'),
45
+			'plural' => __('html', 'event_espresso'),
46
+		);
47
+		$this->activate_on_install = true;
48
+		// add the "powered by EE" credit link to the HTML receipt and invoice
49
+		add_filter(
50
+			'FHEE__EE_Html_messenger___send_message__main_body',
51
+			array($this, 'add_powered_by_credit_link_to_receipt_and_invoice'),
52
+			10,
53
+			3
54
+		);
55
+		parent::__construct();
56
+	}
57
+
58
+
59
+	/**
60
+	 * HTML Messenger desires execution immediately.
61
+	 *
62
+	 * @see    parent::send_now() for documentation.
63
+	 * @since  4.9.0
64
+	 * @return bool
65
+	 */
66
+	public function send_now()
67
+	{
68
+		return true;
69
+	}
70
+
71
+
72
+	/**
73
+	 * HTML Messenger allows an empty to field.
74
+	 *
75
+	 * @see    parent::allow_empty_to_field() for documentation
76
+	 * @since  4.9.0
77
+	 * @return bool
78
+	 */
79
+	public function allow_empty_to_field()
80
+	{
81
+		return true;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @see abstract declaration in EE_messenger for details.
87
+	 */
88
+	protected function _set_admin_pages()
89
+	{
90
+		$this->admin_registered_pages = array('events_edit' => true);
91
+	}
92
+
93
+
94
+	/**
95
+	 * @see abstract declaration in EE_messenger for details.
96
+	 */
97
+	protected function _set_valid_shortcodes()
98
+	{
99
+		$this->_valid_shortcodes = array();
100
+	}
101
+
102
+
103
+	/**
104
+	 * @see abstract declaration in EE_messenger for details.
105
+	 */
106
+	protected function _set_validator_config()
107
+	{
108
+		$this->_validator_config = array(
109
+			'subject' => array(
110
+				'shortcodes' => array('organization', 'primary_registration_details', 'email', 'transaction'),
111
+			),
112
+			'content' => array(
113
+				'shortcodes' => array(
114
+					'organization',
115
+					'primary_registration_list',
116
+					'primary_registration_details',
117
+					'email',
118
+					'transaction',
119
+					'event_list',
120
+					'payment_list',
121
+					'venue',
122
+					'line_item_list',
123
+					'messenger',
124
+					'ticket_list',
125
+				),
126
+			),
127
+			'event_list' => array(
128
+				'shortcodes' => array(
129
+					'event',
130
+					'ticket_list',
131
+					'venue',
132
+					'primary_registration_details',
133
+					'primary_registration_list',
134
+					'event_author',
135
+				),
136
+				'required' => array('[EVENT_LIST]'),
137
+			),
138
+			'ticket_list' => array(
139
+				'shortcodes' => array(
140
+					'attendee_list',
141
+					'ticket',
142
+					'datetime_list',
143
+					'primary_registration_details',
144
+					'line_item_list',
145
+					'venue',
146
+				),
147
+				'required' => array('[TICKET_LIST]'),
148
+			),
149
+			'ticket_line_item_no_pms' => array(
150
+				'shortcodes' => array('line_item', 'ticket'),
151
+				'required' => array('[TICKET_LINE_ITEM_LIST]'),
152
+			),
153
+			'ticket_line_item_pms' => array(
154
+				'shortcodes' => array('line_item', 'ticket', 'line_item_list'),
155
+				'required' => array('[TICKET_LINE_ITEM_LIST]'),
156
+			),
157
+			'price_modifier_line_item_list' => array(
158
+				'shortcodes' => array('line_item'),
159
+				'required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
160
+			),
161
+			'datetime_list' => array(
162
+				'shortcodes' => array('datetime'),
163
+				'required' => array('[DATETIME_LIST]'),
164
+			),
165
+			'attendee_list' => array(
166
+				'shortcodes' => array('attendee'),
167
+				'required' => array('[ATTENDEE_LIST]'),
168
+			),
169
+			'tax_line_item_list' => array(
170
+				'shortcodes' => array('line_item'),
171
+				'required' => array('[TAX_LINE_ITEM_LIST]'),
172
+			),
173
+			'additional_line_item_list' => array(
174
+				'shortcodes' => array('line_item'),
175
+				'required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
176
+			),
177
+			'payment_list' => array(
178
+				'shortcodes' => array('payment'),
179
+				'required' => array('[PAYMENT_LIST_*]'),
180
+			),
181
+		);
182
+	}
183
+
184
+
185
+	/**
186
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
187
+	 * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
188
+	 * (i.e. swap out css files or something else).
189
+	 *
190
+	 * @since 4.5.0
191
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
192
+	 * @return void
193
+	 */
194
+	public function do_secondary_messenger_hooks($sending_messenger_name)
195
+	{
196
+		if ($sending_messenger_name === 'pdf') {
197
+			add_filter('EE_messenger__get_variation__variation', array($this, 'add_html_css'), 10, 8);
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * @param                            $variation_path
204
+	 * @param \EE_Messages_Template_Pack $template_pack
205
+	 * @param                            $messenger_name
206
+	 * @param                            $message_type_name
207
+	 * @param                            $url
208
+	 * @param                            $type
209
+	 * @param                            $variation
210
+	 * @param                            $skip_filters
211
+	 * @return string
212
+	 */
213
+	public function add_html_css(
214
+		$variation_path,
215
+		EE_Messages_Template_Pack $template_pack,
216
+		$messenger_name,
217
+		$message_type_name,
218
+		$url,
219
+		$type,
220
+		$variation,
221
+		$skip_filters
222
+	) {
223
+		$variation = $template_pack->get_variation(
224
+			$this->name,
225
+			$message_type_name,
226
+			$type,
227
+			$variation,
228
+			$url,
229
+			'.css',
230
+			$skip_filters
231
+		);
232
+		return $variation;
233
+	}
234
+
235
+
236
+	/**
237
+	 * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
238
+	 * messenger can add their own js.
239
+	 *
240
+	 * @return void.
241
+	 */
242
+	public function enqueue_scripts_styles()
243
+	{
244
+		parent::enqueue_scripts_styles();
245
+		do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
246
+	}
247
+
248
+
249
+	/**
250
+	 * _set_template_fields
251
+	 * This sets up the fields that a messenger requires for the message to go out.
252
+	 *
253
+	 * @access  protected
254
+	 * @return void
255
+	 */
256
+	protected function _set_template_fields()
257
+	{
258
+		// any extra template fields that are NOT used by the messenger
259
+		// but will get used by a messenger field for shortcode replacement
260
+		// get added to the 'extra' key in an associated array
261
+		// indexed by the messenger field they relate to.
262
+		// This is important for the Messages_admin to know what fields to display to the user.
263
+		// Also, notice that the "values" are equal to the field type
264
+		// that messages admin will use to know what kind of field to display.
265
+		// The values ALSO have one index labeled "shortcode".
266
+		// The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
267
+		// is required in order for this extra field to be displayed.
268
+		//  If the required shortcode isn't part of the shortcodes array
269
+		// then the field is not needed and will not be displayed/parsed.
270
+		$this->_template_fields = array(
271
+			'subject' => array(
272
+				'input' => 'text',
273
+				'label' => __('Page Title', 'event_espresso'),
274
+				'type' => 'string',
275
+				'required' => true,
276
+				'validation' => true,
277
+				'css_class' => 'large-text',
278
+				'format' => '%s',
279
+			),
280
+			'content' => '',
281
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
282
+			'extra' => array(
283
+				'content' => array(
284
+					'main' => array(
285
+						'input' => 'wp_editor',
286
+						'label' => __('Main Content', 'event_espresso'),
287
+						'type' => 'string',
288
+						'required' => true,
289
+						'validation' => true,
290
+						'format' => '%s',
291
+						'rows' => '15',
292
+					),
293
+					'event_list' => array(
294
+						'input' => 'wp_editor',
295
+						'label' => '[EVENT_LIST]',
296
+						'type' => 'string',
297
+						'required' => true,
298
+						'validation' => true,
299
+						'format' => '%s',
300
+						'rows' => '15',
301
+						'shortcodes_required' => array('[EVENT_LIST]'),
302
+					),
303
+					'ticket_list' => array(
304
+						'input' => 'textarea',
305
+						'label' => '[TICKET_LIST]',
306
+						'type' => 'string',
307
+						'required' => true,
308
+						'validation' => true,
309
+						'format' => '%s',
310
+						'css_class' => 'large-text',
311
+						'rows' => '10',
312
+						'shortcodes_required' => array('[TICKET_LIST]'),
313
+					),
314
+					'ticket_line_item_no_pms' => array(
315
+						'input' => 'textarea',
316
+						'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
317
+							'Ticket Line Item List with no Price Modifiers',
318
+							'event_espresso'
319
+						),
320
+						'type' => 'string',
321
+						'required' => false,
322
+						'validation' => true,
323
+						'format' => '%s',
324
+						'css_class' => 'large-text',
325
+						'rows' => '5',
326
+						'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
327
+					),
328
+					'ticket_line_item_pms' => array(
329
+						'input' => 'textarea',
330
+						'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
331
+							'Ticket Line Item List with Price Modifiers',
332
+							'event_espresso'
333
+						),
334
+						'type' => 'string',
335
+						'required' => false,
336
+						'validation' => true,
337
+						'format' => '%s',
338
+						'css_class' => 'large-text',
339
+						'rows' => '5',
340
+						'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
341
+					),
342
+					'price_modifier_line_item_list' => array(
343
+						'input' => 'textarea',
344
+						'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
345
+						'type' => 'string',
346
+						'required' => false,
347
+						'validation' => true,
348
+						'format' => '%s',
349
+						'css_class' => 'large-text',
350
+						'rows' => '5',
351
+						'shortcodes_required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
352
+					),
353
+					'datetime_list' => array(
354
+						'input' => 'textarea',
355
+						'label' => '[DATETIME_LIST]',
356
+						'type' => 'string',
357
+						'required' => true,
358
+						'validation' => true,
359
+						'format' => '%s',
360
+						'css_class' => 'large-text',
361
+						'rows' => '5',
362
+						'shortcodes_required' => array('[DATETIME_LIST]'),
363
+					),
364
+					'attendee_list' => array(
365
+						'input' => 'textarea',
366
+						'label' => '[ATTENDEE_LIST]',
367
+						'type' => 'string',
368
+						'required' => true,
369
+						'validation' => true,
370
+						'format' => '%s',
371
+						'css_class' => 'large-text',
372
+						'rows' => '5',
373
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
374
+					),
375
+					'tax_line_item_list' => array(
376
+						'input' => 'textarea',
377
+						'label' => '[TAX_LINE_ITEM_LIST]',
378
+						'type' => 'string',
379
+						'required' => false,
380
+						'validation' => true,
381
+						'format' => '%s',
382
+						'css_class' => 'large-text',
383
+						'rows' => '5',
384
+						'shortcodes_required' => array('[TAX_LINE_ITEM_LIST]'),
385
+					),
386
+					'additional_line_item_list' => array(
387
+						'input' => 'textarea',
388
+						'label' => '[ADDITIONAL_LINE_ITEM_LIST]',
389
+						'type' => 'string',
390
+						'required' => false,
391
+						'validation' => true,
392
+						'format' => '%s',
393
+						'css_class' => 'large-text',
394
+						'rows' => '5',
395
+						'shortcodes_required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
396
+					),
397
+					'payment_list' => array(
398
+						'input' => 'textarea',
399
+						'label' => '[PAYMENT_LIST]',
400
+						'type' => 'string',
401
+						'required' => true,
402
+						'validation' => true,
403
+						'format' => '%s',
404
+						'css_class' => 'large-text',
405
+						'rows' => '5',
406
+						'shortcodes_required' => array('[PAYMENT_LIST_*]'),
407
+					),
408
+				),
409
+			),
410
+		);
411
+	}
412
+
413
+
414
+	/**
415
+	 * @see   definition of this method in parent
416
+	 * @since 4.5.0
417
+	 */
418
+	protected function _set_default_message_types()
419
+	{
420
+		$this->_default_message_types = array('receipt', 'invoice');
421
+	}
422
+
423
+
424
+	/**
425
+	 * @see   definition of this method in parent
426
+	 * @since 4.5.0
427
+	 */
428
+	protected function _set_valid_message_types()
429
+	{
430
+		$this->_valid_message_types = array('receipt', 'invoice');
431
+	}
432
+
433
+
434
+	/**
435
+	 * Displays the message in the browser.
436
+	 *
437
+	 * @since 4.5.0
438
+	 * @return string.
439
+	 */
440
+	protected function _send_message()
441
+	{
442
+		$this->_template_args = array(
443
+			'page_title' => $this->_subject,
444
+			'base_css' => $this->get_variation(
445
+				$this->_tmp_pack,
446
+				$this->_incoming_message_type->name,
447
+				true,
448
+				'base',
449
+				$this->_variation
450
+			),
451
+			'print_css' => $this->get_variation(
452
+				$this->_tmp_pack,
453
+				$this->_incoming_message_type->name,
454
+				true,
455
+				'print',
456
+				$this->_variation
457
+			),
458
+			'main_css' => $this->get_variation(
459
+				$this->_tmp_pack,
460
+				$this->_incoming_message_type->name,
461
+				true,
462
+				'main',
463
+				$this->_variation
464
+			),
465
+			'main_body' => wpautop(
466
+				apply_filters(
467
+					'FHEE__EE_Html_messenger___send_message__main_body',
468
+					$this->_content,
469
+					$this->_content,
470
+					$this->_incoming_message_type
471
+				)
472
+			)
473
+		);
474
+		$this->_deregister_wp_hooks();
475
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
476
+		echo $this->_get_main_template();
477
+		exit();
478
+	}
479
+
480
+
481
+	/**
482
+	 * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
483
+	 * interfere with our templates.  If users want to add any custom styles or scripts they must use the
484
+	 * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
485
+	 *
486
+	 * @since 4.5.0
487
+	 * @return void
488
+	 */
489
+	protected function _deregister_wp_hooks()
490
+	{
491
+		remove_all_actions('wp_head');
492
+		remove_all_actions('wp_footer');
493
+		remove_all_actions('wp_print_footer_scripts');
494
+		remove_all_actions('wp_enqueue_scripts');
495
+		global $wp_scripts, $wp_styles;
496
+		$wp_scripts = $wp_styles = array();
497
+		// just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
498
+		add_action('wp_footer', 'wp_print_footer_scripts');
499
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
500
+		add_action('wp_head', 'wp_enqueue_scripts');
501
+	}
502
+
503
+
504
+	/**
505
+	 * Overwrite parent _get_main_template for display_html purposes.
506
+	 *
507
+	 * @since  4.5.0
508
+	 * @param bool $preview
509
+	 * @return string
510
+	 */
511
+	protected function _get_main_template($preview = false)
512
+	{
513
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, 'main');
514
+		// include message type as a template arg
515
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
516
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
517
+	}
518
+
519
+
520
+	/**
521
+	 * @return string
522
+	 */
523
+	protected function _preview()
524
+	{
525
+		return $this->_send_message();
526
+	}
527
+
528
+
529
+	protected function _set_admin_settings_fields()
530
+	{
531
+	}
532
+
533
+
534
+	/**
535
+	 * add the "powered by EE" credit link to the HTML receipt and invoice
536
+	 *
537
+	 * @param string $content
538
+	 * @param string $content_again
539
+	 * @param \EE_message_type $incoming_message_type
540
+	 * @return string
541
+	 */
542
+	public function add_powered_by_credit_link_to_receipt_and_invoice(
543
+		$content = '',
544
+		$content_again = '',
545
+		EE_message_type $incoming_message_type
546
+	) {
547
+		if (($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
548
+			&& apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
549
+		) {
550
+			$content .= \EEH_Template::powered_by_event_espresso(
551
+				'aln-cntr',
552
+				'',
553
+				array('utm_content' => 'messages_system')
554
+			)
555
+				. EEH_HTML::div(EEH_HTML::p('&nbsp;'));
556
+		}
557
+		return $content;
558
+	}
559 559
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Data_Handler_Collection.lib.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -11,69 +11,69 @@
 block discarded – undo
11 11
 {
12 12
 
13 13
 
14
-    public function __construct()
15
-    {
16
-        $this->interface = 'EE_Messages_incoming_data';
17
-    }
14
+	public function __construct()
15
+	{
16
+		$this->interface = 'EE_Messages_incoming_data';
17
+	}
18 18
 
19 19
 
20
-    /**
21
-     * This adds the EE_Messages_incoming_data data handler object to the collection.
22
-     *
23
-     * @param EE_Messages_incoming_data  $data_handler
24
-     * @param mixed                      $data           Usually an array of data used in combination with the $data_handler
25
-     *                                                   classname to create an alternative index for retrieving data_handlers.
26
-     * @return bool
27
-     */
28
-    public function add($data_handler, $data = null)
29
-    {
30
-        $data = $data === null ? array() : (array) $data;
31
-        $info['key'] = $this->get_key(get_class($data_handler), $data);
32
-        return parent::add($data_handler, $info);
33
-    }
20
+	/**
21
+	 * This adds the EE_Messages_incoming_data data handler object to the collection.
22
+	 *
23
+	 * @param EE_Messages_incoming_data  $data_handler
24
+	 * @param mixed                      $data           Usually an array of data used in combination with the $data_handler
25
+	 *                                                   classname to create an alternative index for retrieving data_handlers.
26
+	 * @return bool
27
+	 */
28
+	public function add($data_handler, $data = null)
29
+	{
30
+		$data = $data === null ? array() : (array) $data;
31
+		$info['key'] = $this->get_key(get_class($data_handler), $data);
32
+		return parent::add($data_handler, $info);
33
+	}
34 34
     
35 35
 
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     * This returns a key for retrieving data for the given references used to generate the key.
41
-     * Data handlers are cached to the repository along with a md5() generated key using known references.
42
-     * @param string    $classname      The classname of the datahandler being checked for.
43
-     * @param mixed     $data           The data that was used to instantiate the data_handler.
44
-     *
45
-     * @return  string      md5 hash using provided info.
46
-     */
47
-    public function get_key($classname, $data)
48
-    {
49
-        return md5($classname . serialize($data));
50
-    }
39
+	/**
40
+	 * This returns a key for retrieving data for the given references used to generate the key.
41
+	 * Data handlers are cached to the repository along with a md5() generated key using known references.
42
+	 * @param string    $classname      The classname of the datahandler being checked for.
43
+	 * @param mixed     $data           The data that was used to instantiate the data_handler.
44
+	 *
45
+	 * @return  string      md5 hash using provided info.
46
+	 */
47
+	public function get_key($classname, $data)
48
+	{
49
+		return md5($classname . serialize($data));
50
+	}
51 51
 
52 52
 
53 53
 
54 54
 
55 55
 
56 56
 
57
-    /**
58
-     * This returns a saved EE_Messages_incoming_data object if there is one in the repository indexed by a key matching
59
-     * the given string.
60
-     *
61
-     * @param string  $key  @see EE_Messages_Data_Handler_Collection::get_key() to setup a key formatted for searching.
62
-     *
63
-     * @return null|EE_Messages_incoming_data
64
-     */
65
-    public function get_by_key($key)
66
-    {
67
-        $this->rewind();
68
-        while ($this->valid()) {
69
-            $data = $this->getInfo();
70
-            if (isset($data['key']) && $data['key'] === $key) {
71
-                $handler = $this->current();
72
-                $this->rewind();
73
-                return $handler;
74
-            }
75
-            $this->next();
76
-        }
77
-        return null;
78
-    }
57
+	/**
58
+	 * This returns a saved EE_Messages_incoming_data object if there is one in the repository indexed by a key matching
59
+	 * the given string.
60
+	 *
61
+	 * @param string  $key  @see EE_Messages_Data_Handler_Collection::get_key() to setup a key formatted for searching.
62
+	 *
63
+	 * @return null|EE_Messages_incoming_data
64
+	 */
65
+	public function get_by_key($key)
66
+	{
67
+		$this->rewind();
68
+		while ($this->valid()) {
69
+			$data = $this->getInfo();
70
+			if (isset($data['key']) && $data['key'] === $key) {
71
+				$handler = $this->current();
72
+				$this->rewind();
73
+				return $handler;
74
+			}
75
+			$this->next();
76
+		}
77
+		return null;
78
+	}
79 79
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
      */
47 47
     public function get_key($classname, $data)
48 48
     {
49
-        return md5($classname . serialize($data));
49
+        return md5($classname.serialize($data));
50 50
     }
51 51
 
52 52
 
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Resource_Manager.lib.php 2 patches
Indentation   +1113 added lines, -1113 removed lines patch added patch discarded remove patch
@@ -12,1117 +12,1117 @@
 block discarded – undo
12 12
 class EE_Message_Resource_Manager
13 13
 {
14 14
 
15
-    /**
16
-     * This option in the database is used to keep a record of message types that have been activated for a messenger
17
-     * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
18
-     * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
19
-     * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
20
-     * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
21
-     * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
22
-     * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
23
-     * automated process (when an add-on registering the message type deactivates, or when some other code calls the
24
-     * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
25
-     * the "force" flag is respected if that message type is later re-registered.
26
-     *
27
-     * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
28
-     *
29
-     * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
30
-     * option that got superseded by later behaviour requirements.
31
-     */
32
-    const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
33
-
34
-    /**
35
-     * @type boolean $_initialized
36
-     */
37
-    protected $_initialized = false;
38
-
39
-    /**
40
-     * @type EE_Messenger_Collection $_messenger_collection_loader
41
-     */
42
-    protected $_messenger_collection_loader;
43
-
44
-    /**
45
-     * @type EE_Message_Type_Collection $_message_type_collection_loader
46
-     */
47
-    protected $_message_type_collection_loader;
48
-
49
-    /**
50
-     * @type EEM_Message_Template_Group $_message_template_group_model
51
-     */
52
-    protected $_message_template_group_model;
53
-
54
-    /**
55
-     * @type EE_messenger[]
56
-     */
57
-    protected $_installed_messengers = array();
58
-
59
-    /**
60
-     * @type EE_message_type[]
61
-     */
62
-    protected $_installed_message_types = array();
63
-
64
-    /**
65
-     * Array of active messengers.
66
-     * Format is this:
67
-     * array(
68
-     *      'messenger_name' => EE_messenger
69
-     * )
70
-     *
71
-     * @type EE_messenger[]
72
-     */
73
-    protected $_active_messengers = array();
74
-
75
-    /**
76
-     * Formatted array of active message types grouped per messenger.
77
-     * Format is this:
78
-     * array(
79
-     *      'messenger_name' => array(
80
-     *          'settings' => array(
81
-     *              '{messenger_name}-message_types' => array(
82
-     *                  'message_type_name' => array() //variable array of settings corresponding to message type.
83
-     *              )
84
-     *          )
85
-     *      )
86
-     * )
87
-     *
88
-     * @type array
89
-     */
90
-    protected $_active_message_types = array();
91
-
92
-
93
-    /**
94
-     * This holds the array of messengers and their corresponding message types that have
95
-     * been activated on a site at some point.  This is an important record that helps the messages system
96
-     * not accidentally reactivate something that was intentionally deactivated by a user.
97
-     *
98
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
99
-     *
100
-     * @type array
101
-     */
102
-    protected $_has_activated_messengers_and_message_types = array();
103
-
104
-    /**
105
-     * An array of unique message type contexts across all active message types.
106
-     * The array will be indexed by either 'slugs' or 'all'.
107
-     * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
108
-     * slug. array(
109
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
110
-     * );
111
-     * The all index returns an array in this format:
112
-     * array(
113
-     *      'message_type_name' => array(
114
-     *          'context_slug' => array(
115
-     *              'label' => 'localized label for context',
116
-     *              'description' => 'localized description for context'
117
-     *          )
118
-     *      )
119
-     * );
120
-     *
121
-     * @type array
122
-     */
123
-    protected $_contexts = array();
124
-
125
-
126
-    /**
127
-     * EE_Message_Resource_Manager constructor.
128
-     *
129
-     * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
130
-     * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
131
-     * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
132
-     */
133
-    public function __construct(
134
-        EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
135
-        EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
136
-        EEM_Message_Template_Group $Message_Template_Group_Model
137
-    ) {
138
-        $this->_messenger_collection_loader    = $Messenger_Collection_Loader;
139
-        $this->_message_type_collection_loader = $Message_Type_Collection_Loader;
140
-        $this->_message_template_group_model   = $Message_Template_Group_Model;
141
-    }
142
-
143
-
144
-    /**
145
-     * @return void
146
-     */
147
-    protected function _initialize_collections()
148
-    {
149
-        if ($this->_initialized) {
150
-            return;
151
-        }
152
-        $this->_initialized = true;
153
-        $this->_messenger_collection_loader->load_messengers_from_folder();
154
-        $this->_message_type_collection_loader->load_message_types_from_folder();
155
-        $this->get_has_activated_messengers_option(true);
156
-        $this->_set_active_messengers_and_message_types();
157
-    }
158
-
159
-
160
-    /**
161
-     * @return EE_Messenger_Collection
162
-     */
163
-    public function messenger_collection()
164
-    {
165
-        $this->_initialize_collections();
166
-        return $this->_messenger_collection_loader->messenger_collection();
167
-    }
168
-
169
-
170
-    /**
171
-     * @return EE_messenger[]
172
-     */
173
-    public function active_messengers()
174
-    {
175
-        $this->_initialize_collections();
176
-        return $this->_active_messengers;
177
-    }
178
-
179
-
180
-    /**
181
-     * @param string $messenger_name
182
-     * @return \EE_messenger
183
-     */
184
-    public function get_messenger($messenger_name)
185
-    {
186
-        return $this->messenger_collection()->get_by_info($messenger_name);
187
-    }
188
-
189
-
190
-    /**
191
-     * This returns the corresponding EE_messenger object for the given string if it is active.
192
-     *
193
-     * @param string $messenger
194
-     * @return EE_messenger | null
195
-     */
196
-    public function get_active_messenger($messenger)
197
-    {
198
-        $this->_initialize_collections();
199
-        return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null;
200
-    }
201
-
202
-
203
-    /**
204
-     * @return \EE_messenger[]
205
-     */
206
-    public function installed_messengers()
207
-    {
208
-        if (empty($this->_installed_messengers)) {
209
-            $this->_installed_messengers = array();
210
-            $this->messenger_collection()->rewind();
211
-            while ($this->messenger_collection()->valid()) {
212
-                $this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current();
213
-                $this->messenger_collection()->next();
214
-            }
215
-        }
216
-        return $this->_installed_messengers;
217
-    }
218
-
219
-
220
-    /**
221
-     * @param string $messenger_name
222
-     * @return \EE_messenger
223
-     * @throws \EE_Error
224
-     */
225
-    public function valid_messenger($messenger_name)
226
-    {
227
-        $messenger = $this->get_messenger($messenger_name);
228
-        if ($messenger instanceof EE_messenger) {
229
-            return $messenger;
230
-        }
231
-        throw new EE_Error(
232
-            sprintf(
233
-                __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
234
-                $messenger_name
235
-            )
236
-        );
237
-    }
238
-
239
-
240
-    /**
241
-     * @return EE_Message_Type_Collection
242
-     */
243
-    public function message_type_collection()
244
-    {
245
-        $this->_initialize_collections();
246
-        return $this->_message_type_collection_loader->message_type_collection();
247
-    }
248
-
249
-
250
-    /**
251
-     * @return array
252
-     */
253
-    public function active_message_types()
254
-    {
255
-        $this->_initialize_collections();
256
-        return $this->_active_message_types;
257
-    }
258
-
259
-
260
-    /**
261
-     * @param string $message_type_name
262
-     * @return \EE_message_type
263
-     */
264
-    public function get_message_type($message_type_name)
265
-    {
266
-        return $this->message_type_collection()->get_by_info($message_type_name);
267
-    }
268
-
269
-
270
-    /**
271
-     * This returns the EE_message_type from the active message types array ( if present );
272
-     *
273
-     * @param string $messenger_name
274
-     * @param string $message_type_name
275
-     * @return \EE_message_type|null
276
-     */
277
-    public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
278
-    {
279
-        return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
280
-            ? $this->get_message_type($message_type_name)
281
-            : null;
282
-    }
283
-
284
-
285
-    /**
286
-     * Returns whether the given message type is active for the given messenger.
287
-     *
288
-     * @param string $messenger_name
289
-     * @param string $message_type_name
290
-     * @return bool
291
-     */
292
-    public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
293
-    {
294
-        $this->_initialize_collections();
295
-        return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
296
-    }
297
-
298
-
299
-    /**
300
-     * Returns whether the given messenger is active.
301
-     *
302
-     * @param string $messenger_name the name of the messenger to check if active.
303
-     * @return bool
304
-     */
305
-    public function is_messenger_active($messenger_name)
306
-    {
307
-        $this->_initialize_collections();
308
-        return ! empty($this->_active_message_types[ $messenger_name ]);
309
-    }
310
-
311
-
312
-    /**
313
-     * This returns any settings that might be on a message type for a messenger
314
-     *
315
-     * @param string $messenger_name    The slug of the messenger
316
-     * @param string $message_type_name The slug of the message type getting the settings for.
317
-     * @return array
318
-     */
319
-    public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
320
-    {
321
-        $settings = array();
322
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
323
-            $settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'])
324
-                ? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']
325
-                : array();
326
-        }
327
-        return $settings;
328
-    }
329
-
330
-
331
-    /**
332
-     * Returns whether the given messenger name has active message types on it.
333
-     * Infers whether the messenger is active or not as well.
334
-     *
335
-     * @param string $messenger_name
336
-     * @return bool
337
-     */
338
-    public function messenger_has_active_message_types($messenger_name)
339
-    {
340
-        $this->_initialize_collections();
341
-        return
342
-            ! empty($this->_active_message_types[ $messenger_name ])
343
-            && ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]);
344
-    }
345
-
346
-
347
-    /**
348
-     * This checks the _active_message_types property for any active message types
349
-     * that are present for the given messenger and returns them.
350
-     *
351
-     * @since 4.9.0
352
-     * @param string $messenger_name The messenger being checked
353
-     * @return EE_message_type[]|array    (empty array if no active_message_types)
354
-     */
355
-    public function get_active_message_types_for_messenger($messenger_name)
356
-    {
357
-        $message_types = array();
358
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
359
-            return $message_types;
360
-        }
361
-        $installed_message_types = $this->installed_message_types();
362
-        foreach ($installed_message_types as $message_type_name => $message_type) {
363
-            if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
364
-                $message_types[ $message_type_name ] = $message_type;
365
-            }
366
-        }
367
-        return $message_types;
368
-    }
369
-
370
-
371
-    /**
372
-     * This does NOT return the _active_message_types property but
373
-     * simply returns an array of active message type names from that property.
374
-     * (The _active_message_types property is indexed by messenger and active message_types per messenger).
375
-     *
376
-     * @return array message_type references (string)
377
-     */
378
-    public function list_of_active_message_types()
379
-    {
380
-        $active_message_type_names = array();
381
-        $this->_initialize_collections();
382
-        foreach ($this->_active_message_types as $messenger => $messenger_settings) {
383
-            if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) {
384
-                continue;
385
-            }
386
-            foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) {
387
-                if (! in_array($message_type_name, $active_message_type_names)) {
388
-                    $active_message_type_names[] = $message_type_name;
389
-                }
390
-            }
391
-        }
392
-        return $active_message_type_names;
393
-    }
394
-
395
-
396
-    /**
397
-     * Same as list_of_active_message_types() except this returns actual EE_message_type objects
398
-     *
399
-     * @since 4.9.0
400
-     * @return \EE_message_type[]
401
-     */
402
-    public function get_active_message_type_objects()
403
-    {
404
-        $active_message_types      = array();
405
-        $installed_message_types   = $this->installed_message_types();
406
-        $active_message_type_names = $this->list_of_active_message_types();
407
-        foreach ($active_message_type_names as $active_message_type_name) {
408
-            if (isset($installed_message_types[ $active_message_type_name ])) {
409
-                $active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ];
410
-            }
411
-        }
412
-        return $active_message_types;
413
-    }
414
-
415
-
416
-    /**
417
-     * @return \EE_message_type[]
418
-     */
419
-    public function installed_message_types()
420
-    {
421
-        if (empty($this->_installed_message_types)) {
422
-            $this->message_type_collection()->rewind();
423
-            while ($this->message_type_collection()->valid()) {
424
-                $this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current();
425
-                $this->message_type_collection()->next();
426
-            }
427
-        }
428
-        return $this->_installed_message_types;
429
-    }
430
-
431
-
432
-    /**
433
-     * @param string $message_type_name
434
-     * @return \EE_message_type
435
-     * @throws \EE_Error
436
-     */
437
-    public function valid_message_type($message_type_name)
438
-    {
439
-        $message_type = $this->get_message_type($message_type_name);
440
-        if ($message_type instanceof EE_message_type) {
441
-            return $message_type;
442
-        }
443
-        throw new EE_Error(
444
-            sprintf(
445
-                __('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
446
-                $message_type_name
447
-            )
448
-        );
449
-    }
450
-
451
-
452
-    /**
453
-     * valid_message_type_for_messenger
454
-     *
455
-     * @param EE_messenger $messenger
456
-     * @param string       $message_type_name
457
-     * @return boolean
458
-     * @throws \EE_Error
459
-     */
460
-    public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
461
-    {
462
-        $valid_message_types = $messenger->get_valid_message_types();
463
-        if (! in_array($message_type_name, $valid_message_types)) {
464
-            throw new EE_Error(
465
-                sprintf(
466
-                    __(
467
-                        'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
468
-                        'event_espresso'
469
-                    ),
470
-                    $message_type_name,
471
-                    __METHOD__,
472
-                    $messenger->name
473
-                )
474
-            );
475
-        }
476
-        return true;
477
-    }
478
-
479
-
480
-    /**
481
-     * Used to return active messengers array stored in the wp options table.
482
-     * If no value is present in the option then an empty array is returned.
483
-     *
484
-     * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
485
-     *                          property and pull directly from the db.  Otherwise whatever is currently on the
486
-     *                          $_active_message_types property is pulled.
487
-     * @return array
488
-     */
489
-    public function get_active_messengers_option($reset = false)
490
-    {
491
-        if ($reset) {
492
-            $this->_active_message_types = get_option('ee_active_messengers', array());
493
-        }
494
-        return $this->_active_message_types;
495
-    }
496
-
497
-
498
-    /**
499
-     * Used to update the active messengers array stored in the wp options table.
500
-     *
501
-     * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
502
-     *                                         representing this data is used.
503
-     * @return bool FALSE if not updated, TRUE if updated.
504
-     */
505
-    public function update_active_messengers_option($active_messenger_settings = array())
506
-    {
507
-        $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
508
-        // make sure _active_message_types is updated (this is the internal cache for the settings).
509
-        $this->_active_message_types = $active_messenger_settings;
510
-        return update_option('ee_active_messengers', $active_messenger_settings);
511
-    }
512
-
513
-
514
-    /**
515
-     * Used to return has activated message types for messengers array stored in the wp options table.
516
-     * If no value is present in the option then an empty array is returned.
517
-     * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
518
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
519
-     *
520
-     * @param   bool $reset Used to indicate that any cached value should be ignored.
521
-     * @return array
522
-     */
523
-    public function get_has_activated_messengers_option($reset = false)
524
-    {
525
-        if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
526
-            $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
527
-        }
528
-        return $this->_has_activated_messengers_and_message_types;
529
-    }
530
-
531
-
532
-    /**
533
-     * Used to update the has activated option in the db.
534
-     *
535
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
536
-     *
537
-     * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
538
-     *                                        representing this data is used.
539
-     * @return bool FALSE if not updated, TRUE if updated.
540
-     */
541
-    public function update_has_activated_messengers_option($has_activated_messengers = array())
542
-    {
543
-        // make sure the option has been retrieved from first so we don't overwrite it accidentally.
544
-        if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
545
-            $this->get_has_activated_messengers_option();
546
-        }
547
-        $has_activated_messengers = empty($has_activated_messengers)
548
-            ? $this->_has_activated_messengers_and_message_types
549
-            : $has_activated_messengers;
550
-        return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
551
-    }
552
-
553
-
554
-    /**
555
-     * wrapper for _set_active_messengers_and_message_types()
556
-     */
557
-    public function reset_active_messengers_and_message_types()
558
-    {
559
-        $this->_set_active_messengers_and_message_types();
560
-    }
561
-
562
-
563
-    /**
564
-     * Generate list of active messengers and message types from collection.
565
-     * This sets up the active messengers from what is present in the database.
566
-     */
567
-    protected function _set_active_messengers_and_message_types()
568
-    {
569
-        // echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
570
-        // list of activated messengers as set via the admin
571
-        // note calling `get_active_messengers_options` also initializes the _active_message_types property.
572
-        $this->get_active_messengers_option(true);
573
-        $this->ensure_messengers_are_active(array(), false, true);
574
-        $this->update_active_messengers_option();
575
-        $this->update_has_activated_messengers_option();
576
-    }
577
-
578
-
579
-    /**
580
-     * Ensures that the specified messenger is currently active.
581
-     * If not, activates it and its default message types.
582
-     *
583
-     * @param string $messenger_name
584
-     * @param bool   $update_option Whether to update the option in the db or not.
585
-     * @return boolean true if either already active or successfully activated.
586
-     */
587
-    public function ensure_messenger_is_active($messenger_name, $update_option = true)
588
-    {
589
-        if (! isset($this->_active_messengers[ $messenger_name ])) {
590
-            try {
591
-                $this->activate_messenger($messenger_name, array(), $update_option);
592
-            } catch (EE_Error $e) {
593
-                EE_Error::add_error(
594
-                    $e->getMessage(),
595
-                    __FILE__,
596
-                    __FUNCTION__,
597
-                    __LINE__
598
-                );
599
-                return false;
600
-            }
601
-        }
602
-        return true;
603
-    }
604
-
605
-
606
-    /**
607
-     * This ensures the given array of messenger names is active in the system.
608
-     * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
609
-     * it will automatically activate the default message types for the messenger if its not active.
610
-     *
611
-     * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
612
-     *                                (default) then will attempt to set the active messengers from the
613
-     *                                activated_messengers option
614
-     *                                (stored in $_active_message_types property).
615
-     * @param bool  $update_option    Whether to update the related active messengers option.
616
-     * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
617
-     *                                set to true and a messenger is indicated as active, but is NOT installed, then it
618
-     *                                will automatically be deactivated.
619
-     */
620
-    public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
621
-    {
622
-        $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
623
-
624
-        $not_installed = array();
625
-        foreach ($messenger_names as $messenger_name) {
626
-            if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
627
-                $not_installed[] = $messenger_name;
628
-                $this->deactivate_messenger($messenger_name);
629
-                continue;
630
-            }
631
-            $this->ensure_messenger_is_active($messenger_name, $update_option);
632
-        }
633
-
634
-        if (! empty($not_installed)) {
635
-            EE_Error::add_error(
636
-                sprintf(
637
-                    __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
638
-                    '<br />',
639
-                    implode(', ', $not_installed)
640
-                ),
641
-                __FILE__,
642
-                __FUNCTION__,
643
-                __LINE__
644
-            );
645
-        }
646
-    }
647
-
648
-
649
-    /**
650
-     * Ensures that the specified message type for the given messenger is currently active, if not activates it.
651
-     * This ALSO ensures that the given messenger is active as well!
652
-     *
653
-     * @param string $message_type_name message type name.
654
-     * @param        $messenger_name
655
-     * @param bool   $update_option     Whether to update the option in the db or not.
656
-     * @return bool  Returns true if already is active or if was activated successfully.
657
-     * @throws \EE_Error
658
-     */
659
-    public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
660
-    {
661
-        // grab the messenger to work with.
662
-        $messenger = $this->valid_messenger($messenger_name);
663
-        if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
664
-            // ensure messenger is active (that's an inherent coupling between active message types and the
665
-            // messenger they are being activated for.
666
-            try {
667
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
668
-                    // all is good so let's just get it active
669
-                    $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
670
-                }
671
-            } catch (EE_Error $e) {
672
-                EE_Error::add_error(
673
-                    $e->getMessage(),
674
-                    __FILE__,
675
-                    __FUNCTION__,
676
-                    __LINE__
677
-                );
678
-                return false;
679
-            }
680
-        }
681
-        return true;
682
-    }
683
-
684
-
685
-    /**
686
-     * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
687
-     * messenger are active in one go.
688
-     *
689
-     * @param array  $message_type_names Array of message type names to ensure are active.
690
-     * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
691
-     * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
692
-     */
693
-    public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
694
-    {
695
-        $message_type_names = (array) $message_type_names;
696
-        foreach ($message_type_names as $message_type_name) {
697
-            // note, intentionally not updating option here because we're in a loop.
698
-            // We'll follow the instructions of the incoming $update_option argument after the loop.
699
-            $this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
700
-        }
701
-        if ($update_option) {
702
-            $this->update_active_messengers_option();
703
-            $this->update_has_activated_messengers_option();
704
-        }
705
-    }
706
-
707
-
708
-    /**
709
-     * Activates the specified messenger.
710
-     *
711
-     * @param string $messenger_name
712
-     * @param array  $message_type_names        An array of message type names to activate with this messenger.
713
-     *                                          If included we do NOT setup the default message types
714
-     *                                          (assuming they are already setup.)
715
-     * @param bool   $update_active_messengers_option
716
-     * @return array of generated templates
717
-     * @throws \EE_Error
718
-     */
719
-    public function activate_messenger(
720
-        $messenger_name,
721
-        $message_type_names = array(),
722
-        $update_active_messengers_option = true
723
-    ) {
724
-        $templates = array();
725
-        // grab the messenger to work with.
726
-        $messenger = $this->messenger_collection()->get_by_info($messenger_name);
727
-        // it's inactive. Activate it.
728
-        if ($messenger instanceof EE_messenger) {
729
-            $this->_active_messengers[ $messenger->name ] = $messenger;
730
-            // activate incoming message types set to be activated with messenger.
731
-            $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
732
-            // setup any initial settings for the messenger if necessary.
733
-            $this->add_settings_for_messenger($messenger->name);
734
-            if ($update_active_messengers_option) {
735
-                $this->update_active_messengers_option();
736
-                $this->update_has_activated_messengers_option();
737
-            }
738
-            // generate new templates if necessary and ensure all related templates that are already in the database are
739
-            // marked active.  Note, this will also deactivate a message type for a messenger if the template
740
-            // cannot be successfully created during its attempt (only happens for global template attempts).
741
-            if (! empty($message_type_names)) {
742
-                $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
743
-                EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
744
-            }
745
-        }
746
-        return $templates;
747
-    }
748
-
749
-
750
-    /**
751
-     * Activates given message types for the given EE_messenger object.
752
-     * Note: (very important) This method does not persist the activation to the database.
753
-     * See code implementing this method in this class for examples of how to persist.
754
-     *
755
-     * @param \EE_messenger $messenger
756
-     * @param  array        $message_type_names
757
-     * @return array
758
-     */
759
-    protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
760
-    {
761
-        // If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
762
-        // things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
763
-        // So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
764
-        // only override _active_message_types when an explicit array of $message_type_names has been provided.
765
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ])
766
-            ? $messenger->get_default_message_types()
767
-            : (array) $message_type_names;
768
-
769
-        // now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
770
-        if (! isset($this->_active_message_types[ $messenger->name ])) {
771
-            $this->_active_message_types[ $messenger->name ]['settings'] = array();
772
-        }
773
-
774
-        if ($message_type_names) {
775
-            // cycle thru message types
776
-            foreach ($message_type_names as $message_type_name) {
777
-                // only register the message type as active IF it isn't already active
778
-                // and if its actually installed.
779
-                if (! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
780
-                ) {
781
-                    $this->add_settings_for_message_type($messenger->name, $message_type_name);
782
-                    $this->_set_messenger_has_activated_message_type(
783
-                        $messenger,
784
-                        $message_type_name
785
-                    );
786
-                }
787
-            }
788
-        }
789
-        return $message_type_names;
790
-    }
791
-
792
-
793
-    /**
794
-     * add_settings_for_message_type
795
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
796
-     * $this->update_active_messengers_option to persist.
797
-     *
798
-     * @param  string $messenger_name    The name of the messenger adding the settings for
799
-     * @param  string $message_type_name The name of the message type adding the settings for
800
-     * @param  array  $new_settings      Any new settings being set for the message type and messenger
801
-     */
802
-    public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
803
-    {
804
-        // get installed message type from collection
805
-        $message_type      = $this->message_type_collection()->get_by_info($message_type_name);
806
-        $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
807
-        // we need to setup any initial settings for message types
808
-        if ($message_type instanceof EE_message_type) {
809
-            $default_settings = $message_type->get_admin_settings_fields();
810
-            foreach ($default_settings as $field => $values) {
811
-                if (isset($new_settings[ $field ])) {
812
-                    $existing_settings[ $field ] = $new_settings[ $field ];
813
-                    continue;
814
-                }
815
-                if (! isset($existing_settings[ $field ])) {
816
-                    $existing_settings[ $field ] = $values['default'];
817
-                }
818
-            }
819
-        }
820
-        $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings;
821
-    }
822
-
823
-
824
-    /**
825
-     * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
826
-     * and message type.
827
-     *
828
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
829
-     *
830
-     * @access protected
831
-     * @param \EE_messenger $messenger
832
-     * @param string        $message_type_name
833
-     */
834
-    protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
835
-    {
836
-
837
-        // if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
838
-        if (empty($this->_has_activated_messengers_and_message_types)) {
839
-            $this->get_has_activated_messengers_option();
840
-        }
841
-
842
-        // make sure this messenger has a record in the has_activated array
843
-        if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
844
-            $this->_has_activated_messengers_and_message_types[ $messenger->name ] = array();
845
-        }
846
-        // check if message type has already been added
847
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
848
-            $this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name;
849
-        }
850
-    }
851
-
852
-
853
-    /**
854
-     * add_settings_for_messenger
855
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
856
-     * $this->update_active_messengers_option to persist.
857
-     *
858
-     * @param string $messenger_name The name of the messenger the settings is being added for.
859
-     * @param array  $new_settings   An array of settings to update the existing settings.
860
-     */
861
-    public function add_settings_for_messenger($messenger_name, $new_settings = array())
862
-    {
863
-        $messenger = $this->get_messenger($messenger_name);
864
-        if ($messenger instanceof EE_messenger) {
865
-            $msgr_settings = $messenger->get_admin_settings_fields();
866
-            if (! empty($msgr_settings)) {
867
-                foreach ($msgr_settings as $field => $value) {
868
-                    // is there a new setting for this?
869
-                    if (isset($new_settings[ $field ])) {
870
-                        $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ];
871
-                        continue;
872
-                    }
873
-                    // only set the default if it isn't already set.
874
-                    if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) {
875
-                        $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value;
876
-                    }
877
-                }
878
-            }
879
-        }
880
-    }
881
-
882
-
883
-    /**
884
-     * deactivate_messenger
885
-     *
886
-     * @param  string|EE_messenger $messenger_name name of messenger
887
-     * @return void
888
-     */
889
-    public function deactivate_messenger($messenger_name)
890
-    {
891
-        $this->_initialize_collections();
892
-        if ($messenger_name instanceof EE_messenger) {
893
-            $messenger_name = $messenger_name->name;
894
-        }
895
-        unset($this->_active_messengers[ $messenger_name ]);
896
-        unset($this->_active_message_types[ $messenger_name ]);
897
-        $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
898
-        $this->update_active_messengers_option();
899
-    }
900
-
901
-
902
-    /**
903
-     * Deactivates a message type (note this will deactivate across all messenger's it is active on.
904
-     *
905
-     * @param  string $message_type_name     name of message type being deactivated
906
-     * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
907
-     *                                       type.  However, this can be overridden if we don't want this set (usually when
908
-     *                                       this is called as a part of deregistration of a custom message type)
909
-     */
910
-    public function deactivate_message_type($message_type_name, $set_has_active_record = true)
911
-    {
912
-        $this->_initialize_collections();
913
-        if ($message_type_name instanceof EE_message_type) {
914
-            $message_type_name = $message_type_name->name;
915
-        }
916
-        foreach ($this->_active_message_types as $messenger_name => $settings) {
917
-            unset(
918
-                $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]
919
-            );
920
-
921
-            // we always record (even on deactivation) that a message type has been activated because there should at
922
-            // least be a record in the "has_activated" option that it WAS active at one point.
923
-            if ($set_has_active_record) {
924
-                $messenger = $this->get_messenger($messenger_name);
925
-                $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
926
-            }
927
-        }
928
-        $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
929
-        $this->update_active_messengers_option();
930
-        $this->update_has_activated_messengers_option();
931
-    }
932
-
933
-
934
-    /**
935
-     * Deactivates a message type for a specific messenger as opposed to all messengers.
936
-     *
937
-     * @param string $message_type_name Name of message type being deactivated.
938
-     * @param string $messenger_name    Name of messenger the message type is being deactivated for.
939
-     */
940
-    public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
941
-    {
942
-        $this->_initialize_collections();
943
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
944
-            unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
945
-        }
946
-        $this->_message_template_group_model->deactivate_message_template_groups_for(
947
-            array($messenger_name),
948
-            array($message_type_name)
949
-        );
950
-        $this->update_active_messengers_option();
951
-    }
952
-
953
-
954
-    /**
955
-     * Used to verify if a message can be sent for the given messenger and message type
956
-     * and that it is a generating messenger (used for generating message templates).
957
-     *
958
-     * @param EE_messenger    $messenger    messenger used in trigger
959
-     * @param EE_message_type $message_type message type used in trigger
960
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
961
-     */
962
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
963
-    {
964
-        // get the $messengers the message type says it can be used with.
965
-        foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
966
-            if ($messenger->name === $generating_messenger
967
-                && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
968
-            ) {
969
-                return true;
970
-            }
971
-        }
972
-        return false;
973
-    }
974
-
975
-
976
-    /**
977
-     * This returns all the contexts that are registered by all message types.
978
-     * If $slugs_only is true,
979
-     * then just an array indexed by unique context slugs with the latest label representation for that slug.
980
-     * array(
981
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
982
-     * );
983
-     * If $slugs_only is false, then the format is:
984
-     * array(
985
-     *      'message_type_name' => array(
986
-     *          'context_slug' => array(
987
-     *              'label' => 'localized label for context',
988
-     *              'description' => 'localized description for context'
989
-     *          )
990
-     *      )
991
-     * );
992
-     * Keep in mind that although different message types may share the same context slugs,
993
-     * it is possible that the context is described differently by the message type.
994
-     *
995
-     * @since 4.9.0
996
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
997
-     *                           or all contexts indexed by message type.
998
-     * @return array
999
-     */
1000
-    public function get_all_contexts($slugs_only = true)
1001
-    {
1002
-        $key = $slugs_only ? 'slugs' : 'all';
1003
-        // check if contexts has been setup yet.
1004
-        if (empty($this->_contexts[ $key ])) {
1005
-            // So let's get all active message type objects and loop through to get all unique contexts
1006
-            foreach ($this->get_active_message_type_objects() as $message_type) {
1007
-                if ($message_type instanceof EE_message_type) {
1008
-                    $message_type_contexts = $message_type->get_contexts();
1009
-                    if ($slugs_only) {
1010
-                        foreach ($message_type_contexts as $context => $context_details) {
1011
-                            $this->_contexts[ $key ][ $context ] = $context_details['label'];
1012
-                        }
1013
-                    } else {
1014
-                        $this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts;
1015
-                    }
1016
-                }
1017
-            }
1018
-        }
1019
-        return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array();
1020
-    }
1021
-
1022
-
1023
-    /**
1024
-     * This checks the internal record of what message types are considered "active" and verifies that
1025
-     * there is an installed class definition for that message type.  If the active message type does not have a
1026
-     * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1027
-     * any related message templates will be inactivated as well.
1028
-     *
1029
-     * @return bool   true means all active message types are valid, false means at least one message type was
1030
-     *                deactivated.
1031
-     */
1032
-    public function validate_active_message_types_are_installed()
1033
-    {
1034
-        $list_of_active_message_type_names = $this->list_of_active_message_types();
1035
-        $installed_message_types           = $this->installed_message_types();
1036
-        $all_message_types_valid           = true;
1037
-        // loop through list of active message types and verify they are installed.
1038
-        foreach ($list_of_active_message_type_names as $message_type_name) {
1039
-            if (! isset($installed_message_types[ $message_type_name ])) {
1040
-                $this->remove_message_type_has_been_activated_from_all_messengers(
1041
-                    $message_type_name,
1042
-                    true
1043
-                );
1044
-                $this->deactivate_message_type($message_type_name, false);
1045
-                $all_message_types_valid = false;
1046
-            }
1047
-        }
1048
-        return $all_message_types_valid;
1049
-    }
1050
-
1051
-
1052
-    /**
1053
-     * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1054
-     * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1055
-     * to attempt automatically reactivating message types that should be activated by default or not.
1056
-     *
1057
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1058
-     *
1059
-     * @param $message_type_name
1060
-     * @param $messenger_name
1061
-     * @return bool
1062
-     */
1063
-    public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1064
-    {
1065
-        $has_activated = $this->get_has_activated_messengers_option();
1066
-        return isset($has_activated[ $messenger_name ])
1067
-               && in_array($message_type_name, $has_activated[ $messenger_name ]);
1068
-    }
1069
-
1070
-
1071
-    /**
1072
-     * This method unsets a message type from the given messenger has activated option.
1073
-     *
1074
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1075
-     *
1076
-     * @param string $message_type_name
1077
-     * @param string $messenger_name
1078
-     * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1079
-     *                                        If it is currently active, then remove.  Otherwise leave it alone.
1080
-     */
1081
-    public function remove_message_type_has_been_activated_for_messenger(
1082
-        $message_type_name,
1083
-        $messenger_name,
1084
-        $consider_current_state = false
1085
-    ) {
1086
-        if ($consider_current_state
1087
-            && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1088
-        ) {
1089
-            // when consider current state is true, this means we don't want to change anything on the "has_activated"
1090
-            // record if the message type is currently active for this messenger.  This is used when we want to retain
1091
-            // the record for user initiated inactivations of the message type.
1092
-            return;
1093
-        }
1094
-        $has_activated = $this->get_has_activated_messengers_option();
1095
-        $key_for_message_type = isset($has_activated[ $messenger_name ])
1096
-            ? array_search($message_type_name, $has_activated[ $messenger_name ], true)
1097
-            : false;
1098
-        if ($key_for_message_type !== false) {
1099
-            unset($has_activated[ $messenger_name ][ $key_for_message_type ]);
1100
-            $this->update_has_activated_messengers_option($has_activated);
1101
-            // reset the internal cached property
1102
-            $this->get_has_activated_messengers_option(true);
1103
-        }
1104
-    }
1105
-
1106
-
1107
-    /**
1108
-     * Removes a message type active record from all messengers it is attached to.
1109
-     *
1110
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1111
-     *
1112
-     * @param      $message_type_name
1113
-     * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1114
-     *                                      If it is currently active, then remove.  Otherwise leave it alone.
1115
-     */
1116
-    public function remove_message_type_has_been_activated_from_all_messengers(
1117
-        $message_type_name,
1118
-        $consider_current_state = false
1119
-    ) {
1120
-        foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1121
-            $this->remove_message_type_has_been_activated_for_messenger(
1122
-                $message_type_name,
1123
-                $messenger_name,
1124
-                $consider_current_state
1125
-            );
1126
-        }
1127
-    }
15
+	/**
16
+	 * This option in the database is used to keep a record of message types that have been activated for a messenger
17
+	 * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
18
+	 * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
19
+	 * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
20
+	 * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
21
+	 * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
22
+	 * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
23
+	 * automated process (when an add-on registering the message type deactivates, or when some other code calls the
24
+	 * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
25
+	 * the "force" flag is respected if that message type is later re-registered.
26
+	 *
27
+	 * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
28
+	 *
29
+	 * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
30
+	 * option that got superseded by later behaviour requirements.
31
+	 */
32
+	const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
33
+
34
+	/**
35
+	 * @type boolean $_initialized
36
+	 */
37
+	protected $_initialized = false;
38
+
39
+	/**
40
+	 * @type EE_Messenger_Collection $_messenger_collection_loader
41
+	 */
42
+	protected $_messenger_collection_loader;
43
+
44
+	/**
45
+	 * @type EE_Message_Type_Collection $_message_type_collection_loader
46
+	 */
47
+	protected $_message_type_collection_loader;
48
+
49
+	/**
50
+	 * @type EEM_Message_Template_Group $_message_template_group_model
51
+	 */
52
+	protected $_message_template_group_model;
53
+
54
+	/**
55
+	 * @type EE_messenger[]
56
+	 */
57
+	protected $_installed_messengers = array();
58
+
59
+	/**
60
+	 * @type EE_message_type[]
61
+	 */
62
+	protected $_installed_message_types = array();
63
+
64
+	/**
65
+	 * Array of active messengers.
66
+	 * Format is this:
67
+	 * array(
68
+	 *      'messenger_name' => EE_messenger
69
+	 * )
70
+	 *
71
+	 * @type EE_messenger[]
72
+	 */
73
+	protected $_active_messengers = array();
74
+
75
+	/**
76
+	 * Formatted array of active message types grouped per messenger.
77
+	 * Format is this:
78
+	 * array(
79
+	 *      'messenger_name' => array(
80
+	 *          'settings' => array(
81
+	 *              '{messenger_name}-message_types' => array(
82
+	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
83
+	 *              )
84
+	 *          )
85
+	 *      )
86
+	 * )
87
+	 *
88
+	 * @type array
89
+	 */
90
+	protected $_active_message_types = array();
91
+
92
+
93
+	/**
94
+	 * This holds the array of messengers and their corresponding message types that have
95
+	 * been activated on a site at some point.  This is an important record that helps the messages system
96
+	 * not accidentally reactivate something that was intentionally deactivated by a user.
97
+	 *
98
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
99
+	 *
100
+	 * @type array
101
+	 */
102
+	protected $_has_activated_messengers_and_message_types = array();
103
+
104
+	/**
105
+	 * An array of unique message type contexts across all active message types.
106
+	 * The array will be indexed by either 'slugs' or 'all'.
107
+	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
108
+	 * slug. array(
109
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
110
+	 * );
111
+	 * The all index returns an array in this format:
112
+	 * array(
113
+	 *      'message_type_name' => array(
114
+	 *          'context_slug' => array(
115
+	 *              'label' => 'localized label for context',
116
+	 *              'description' => 'localized description for context'
117
+	 *          )
118
+	 *      )
119
+	 * );
120
+	 *
121
+	 * @type array
122
+	 */
123
+	protected $_contexts = array();
124
+
125
+
126
+	/**
127
+	 * EE_Message_Resource_Manager constructor.
128
+	 *
129
+	 * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
130
+	 * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
131
+	 * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
132
+	 */
133
+	public function __construct(
134
+		EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
135
+		EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
136
+		EEM_Message_Template_Group $Message_Template_Group_Model
137
+	) {
138
+		$this->_messenger_collection_loader    = $Messenger_Collection_Loader;
139
+		$this->_message_type_collection_loader = $Message_Type_Collection_Loader;
140
+		$this->_message_template_group_model   = $Message_Template_Group_Model;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @return void
146
+	 */
147
+	protected function _initialize_collections()
148
+	{
149
+		if ($this->_initialized) {
150
+			return;
151
+		}
152
+		$this->_initialized = true;
153
+		$this->_messenger_collection_loader->load_messengers_from_folder();
154
+		$this->_message_type_collection_loader->load_message_types_from_folder();
155
+		$this->get_has_activated_messengers_option(true);
156
+		$this->_set_active_messengers_and_message_types();
157
+	}
158
+
159
+
160
+	/**
161
+	 * @return EE_Messenger_Collection
162
+	 */
163
+	public function messenger_collection()
164
+	{
165
+		$this->_initialize_collections();
166
+		return $this->_messenger_collection_loader->messenger_collection();
167
+	}
168
+
169
+
170
+	/**
171
+	 * @return EE_messenger[]
172
+	 */
173
+	public function active_messengers()
174
+	{
175
+		$this->_initialize_collections();
176
+		return $this->_active_messengers;
177
+	}
178
+
179
+
180
+	/**
181
+	 * @param string $messenger_name
182
+	 * @return \EE_messenger
183
+	 */
184
+	public function get_messenger($messenger_name)
185
+	{
186
+		return $this->messenger_collection()->get_by_info($messenger_name);
187
+	}
188
+
189
+
190
+	/**
191
+	 * This returns the corresponding EE_messenger object for the given string if it is active.
192
+	 *
193
+	 * @param string $messenger
194
+	 * @return EE_messenger | null
195
+	 */
196
+	public function get_active_messenger($messenger)
197
+	{
198
+		$this->_initialize_collections();
199
+		return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null;
200
+	}
201
+
202
+
203
+	/**
204
+	 * @return \EE_messenger[]
205
+	 */
206
+	public function installed_messengers()
207
+	{
208
+		if (empty($this->_installed_messengers)) {
209
+			$this->_installed_messengers = array();
210
+			$this->messenger_collection()->rewind();
211
+			while ($this->messenger_collection()->valid()) {
212
+				$this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current();
213
+				$this->messenger_collection()->next();
214
+			}
215
+		}
216
+		return $this->_installed_messengers;
217
+	}
218
+
219
+
220
+	/**
221
+	 * @param string $messenger_name
222
+	 * @return \EE_messenger
223
+	 * @throws \EE_Error
224
+	 */
225
+	public function valid_messenger($messenger_name)
226
+	{
227
+		$messenger = $this->get_messenger($messenger_name);
228
+		if ($messenger instanceof EE_messenger) {
229
+			return $messenger;
230
+		}
231
+		throw new EE_Error(
232
+			sprintf(
233
+				__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
234
+				$messenger_name
235
+			)
236
+		);
237
+	}
238
+
239
+
240
+	/**
241
+	 * @return EE_Message_Type_Collection
242
+	 */
243
+	public function message_type_collection()
244
+	{
245
+		$this->_initialize_collections();
246
+		return $this->_message_type_collection_loader->message_type_collection();
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return array
252
+	 */
253
+	public function active_message_types()
254
+	{
255
+		$this->_initialize_collections();
256
+		return $this->_active_message_types;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @param string $message_type_name
262
+	 * @return \EE_message_type
263
+	 */
264
+	public function get_message_type($message_type_name)
265
+	{
266
+		return $this->message_type_collection()->get_by_info($message_type_name);
267
+	}
268
+
269
+
270
+	/**
271
+	 * This returns the EE_message_type from the active message types array ( if present );
272
+	 *
273
+	 * @param string $messenger_name
274
+	 * @param string $message_type_name
275
+	 * @return \EE_message_type|null
276
+	 */
277
+	public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
278
+	{
279
+		return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
280
+			? $this->get_message_type($message_type_name)
281
+			: null;
282
+	}
283
+
284
+
285
+	/**
286
+	 * Returns whether the given message type is active for the given messenger.
287
+	 *
288
+	 * @param string $messenger_name
289
+	 * @param string $message_type_name
290
+	 * @return bool
291
+	 */
292
+	public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
293
+	{
294
+		$this->_initialize_collections();
295
+		return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
296
+	}
297
+
298
+
299
+	/**
300
+	 * Returns whether the given messenger is active.
301
+	 *
302
+	 * @param string $messenger_name the name of the messenger to check if active.
303
+	 * @return bool
304
+	 */
305
+	public function is_messenger_active($messenger_name)
306
+	{
307
+		$this->_initialize_collections();
308
+		return ! empty($this->_active_message_types[ $messenger_name ]);
309
+	}
310
+
311
+
312
+	/**
313
+	 * This returns any settings that might be on a message type for a messenger
314
+	 *
315
+	 * @param string $messenger_name    The slug of the messenger
316
+	 * @param string $message_type_name The slug of the message type getting the settings for.
317
+	 * @return array
318
+	 */
319
+	public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
320
+	{
321
+		$settings = array();
322
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
323
+			$settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'])
324
+				? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']
325
+				: array();
326
+		}
327
+		return $settings;
328
+	}
329
+
330
+
331
+	/**
332
+	 * Returns whether the given messenger name has active message types on it.
333
+	 * Infers whether the messenger is active or not as well.
334
+	 *
335
+	 * @param string $messenger_name
336
+	 * @return bool
337
+	 */
338
+	public function messenger_has_active_message_types($messenger_name)
339
+	{
340
+		$this->_initialize_collections();
341
+		return
342
+			! empty($this->_active_message_types[ $messenger_name ])
343
+			&& ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]);
344
+	}
345
+
346
+
347
+	/**
348
+	 * This checks the _active_message_types property for any active message types
349
+	 * that are present for the given messenger and returns them.
350
+	 *
351
+	 * @since 4.9.0
352
+	 * @param string $messenger_name The messenger being checked
353
+	 * @return EE_message_type[]|array    (empty array if no active_message_types)
354
+	 */
355
+	public function get_active_message_types_for_messenger($messenger_name)
356
+	{
357
+		$message_types = array();
358
+		if (! $this->messenger_has_active_message_types($messenger_name)) {
359
+			return $message_types;
360
+		}
361
+		$installed_message_types = $this->installed_message_types();
362
+		foreach ($installed_message_types as $message_type_name => $message_type) {
363
+			if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
364
+				$message_types[ $message_type_name ] = $message_type;
365
+			}
366
+		}
367
+		return $message_types;
368
+	}
369
+
370
+
371
+	/**
372
+	 * This does NOT return the _active_message_types property but
373
+	 * simply returns an array of active message type names from that property.
374
+	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
375
+	 *
376
+	 * @return array message_type references (string)
377
+	 */
378
+	public function list_of_active_message_types()
379
+	{
380
+		$active_message_type_names = array();
381
+		$this->_initialize_collections();
382
+		foreach ($this->_active_message_types as $messenger => $messenger_settings) {
383
+			if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) {
384
+				continue;
385
+			}
386
+			foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) {
387
+				if (! in_array($message_type_name, $active_message_type_names)) {
388
+					$active_message_type_names[] = $message_type_name;
389
+				}
390
+			}
391
+		}
392
+		return $active_message_type_names;
393
+	}
394
+
395
+
396
+	/**
397
+	 * Same as list_of_active_message_types() except this returns actual EE_message_type objects
398
+	 *
399
+	 * @since 4.9.0
400
+	 * @return \EE_message_type[]
401
+	 */
402
+	public function get_active_message_type_objects()
403
+	{
404
+		$active_message_types      = array();
405
+		$installed_message_types   = $this->installed_message_types();
406
+		$active_message_type_names = $this->list_of_active_message_types();
407
+		foreach ($active_message_type_names as $active_message_type_name) {
408
+			if (isset($installed_message_types[ $active_message_type_name ])) {
409
+				$active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ];
410
+			}
411
+		}
412
+		return $active_message_types;
413
+	}
414
+
415
+
416
+	/**
417
+	 * @return \EE_message_type[]
418
+	 */
419
+	public function installed_message_types()
420
+	{
421
+		if (empty($this->_installed_message_types)) {
422
+			$this->message_type_collection()->rewind();
423
+			while ($this->message_type_collection()->valid()) {
424
+				$this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current();
425
+				$this->message_type_collection()->next();
426
+			}
427
+		}
428
+		return $this->_installed_message_types;
429
+	}
430
+
431
+
432
+	/**
433
+	 * @param string $message_type_name
434
+	 * @return \EE_message_type
435
+	 * @throws \EE_Error
436
+	 */
437
+	public function valid_message_type($message_type_name)
438
+	{
439
+		$message_type = $this->get_message_type($message_type_name);
440
+		if ($message_type instanceof EE_message_type) {
441
+			return $message_type;
442
+		}
443
+		throw new EE_Error(
444
+			sprintf(
445
+				__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
446
+				$message_type_name
447
+			)
448
+		);
449
+	}
450
+
451
+
452
+	/**
453
+	 * valid_message_type_for_messenger
454
+	 *
455
+	 * @param EE_messenger $messenger
456
+	 * @param string       $message_type_name
457
+	 * @return boolean
458
+	 * @throws \EE_Error
459
+	 */
460
+	public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
461
+	{
462
+		$valid_message_types = $messenger->get_valid_message_types();
463
+		if (! in_array($message_type_name, $valid_message_types)) {
464
+			throw new EE_Error(
465
+				sprintf(
466
+					__(
467
+						'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
468
+						'event_espresso'
469
+					),
470
+					$message_type_name,
471
+					__METHOD__,
472
+					$messenger->name
473
+				)
474
+			);
475
+		}
476
+		return true;
477
+	}
478
+
479
+
480
+	/**
481
+	 * Used to return active messengers array stored in the wp options table.
482
+	 * If no value is present in the option then an empty array is returned.
483
+	 *
484
+	 * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
485
+	 *                          property and pull directly from the db.  Otherwise whatever is currently on the
486
+	 *                          $_active_message_types property is pulled.
487
+	 * @return array
488
+	 */
489
+	public function get_active_messengers_option($reset = false)
490
+	{
491
+		if ($reset) {
492
+			$this->_active_message_types = get_option('ee_active_messengers', array());
493
+		}
494
+		return $this->_active_message_types;
495
+	}
496
+
497
+
498
+	/**
499
+	 * Used to update the active messengers array stored in the wp options table.
500
+	 *
501
+	 * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
502
+	 *                                         representing this data is used.
503
+	 * @return bool FALSE if not updated, TRUE if updated.
504
+	 */
505
+	public function update_active_messengers_option($active_messenger_settings = array())
506
+	{
507
+		$active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
508
+		// make sure _active_message_types is updated (this is the internal cache for the settings).
509
+		$this->_active_message_types = $active_messenger_settings;
510
+		return update_option('ee_active_messengers', $active_messenger_settings);
511
+	}
512
+
513
+
514
+	/**
515
+	 * Used to return has activated message types for messengers array stored in the wp options table.
516
+	 * If no value is present in the option then an empty array is returned.
517
+	 * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
518
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
519
+	 *
520
+	 * @param   bool $reset Used to indicate that any cached value should be ignored.
521
+	 * @return array
522
+	 */
523
+	public function get_has_activated_messengers_option($reset = false)
524
+	{
525
+		if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
526
+			$this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
527
+		}
528
+		return $this->_has_activated_messengers_and_message_types;
529
+	}
530
+
531
+
532
+	/**
533
+	 * Used to update the has activated option in the db.
534
+	 *
535
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
536
+	 *
537
+	 * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
538
+	 *                                        representing this data is used.
539
+	 * @return bool FALSE if not updated, TRUE if updated.
540
+	 */
541
+	public function update_has_activated_messengers_option($has_activated_messengers = array())
542
+	{
543
+		// make sure the option has been retrieved from first so we don't overwrite it accidentally.
544
+		if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
545
+			$this->get_has_activated_messengers_option();
546
+		}
547
+		$has_activated_messengers = empty($has_activated_messengers)
548
+			? $this->_has_activated_messengers_and_message_types
549
+			: $has_activated_messengers;
550
+		return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
551
+	}
552
+
553
+
554
+	/**
555
+	 * wrapper for _set_active_messengers_and_message_types()
556
+	 */
557
+	public function reset_active_messengers_and_message_types()
558
+	{
559
+		$this->_set_active_messengers_and_message_types();
560
+	}
561
+
562
+
563
+	/**
564
+	 * Generate list of active messengers and message types from collection.
565
+	 * This sets up the active messengers from what is present in the database.
566
+	 */
567
+	protected function _set_active_messengers_and_message_types()
568
+	{
569
+		// echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
570
+		// list of activated messengers as set via the admin
571
+		// note calling `get_active_messengers_options` also initializes the _active_message_types property.
572
+		$this->get_active_messengers_option(true);
573
+		$this->ensure_messengers_are_active(array(), false, true);
574
+		$this->update_active_messengers_option();
575
+		$this->update_has_activated_messengers_option();
576
+	}
577
+
578
+
579
+	/**
580
+	 * Ensures that the specified messenger is currently active.
581
+	 * If not, activates it and its default message types.
582
+	 *
583
+	 * @param string $messenger_name
584
+	 * @param bool   $update_option Whether to update the option in the db or not.
585
+	 * @return boolean true if either already active or successfully activated.
586
+	 */
587
+	public function ensure_messenger_is_active($messenger_name, $update_option = true)
588
+	{
589
+		if (! isset($this->_active_messengers[ $messenger_name ])) {
590
+			try {
591
+				$this->activate_messenger($messenger_name, array(), $update_option);
592
+			} catch (EE_Error $e) {
593
+				EE_Error::add_error(
594
+					$e->getMessage(),
595
+					__FILE__,
596
+					__FUNCTION__,
597
+					__LINE__
598
+				);
599
+				return false;
600
+			}
601
+		}
602
+		return true;
603
+	}
604
+
605
+
606
+	/**
607
+	 * This ensures the given array of messenger names is active in the system.
608
+	 * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
609
+	 * it will automatically activate the default message types for the messenger if its not active.
610
+	 *
611
+	 * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
612
+	 *                                (default) then will attempt to set the active messengers from the
613
+	 *                                activated_messengers option
614
+	 *                                (stored in $_active_message_types property).
615
+	 * @param bool  $update_option    Whether to update the related active messengers option.
616
+	 * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
617
+	 *                                set to true and a messenger is indicated as active, but is NOT installed, then it
618
+	 *                                will automatically be deactivated.
619
+	 */
620
+	public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
621
+	{
622
+		$messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
623
+
624
+		$not_installed = array();
625
+		foreach ($messenger_names as $messenger_name) {
626
+			if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
627
+				$not_installed[] = $messenger_name;
628
+				$this->deactivate_messenger($messenger_name);
629
+				continue;
630
+			}
631
+			$this->ensure_messenger_is_active($messenger_name, $update_option);
632
+		}
633
+
634
+		if (! empty($not_installed)) {
635
+			EE_Error::add_error(
636
+				sprintf(
637
+					__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
638
+					'<br />',
639
+					implode(', ', $not_installed)
640
+				),
641
+				__FILE__,
642
+				__FUNCTION__,
643
+				__LINE__
644
+			);
645
+		}
646
+	}
647
+
648
+
649
+	/**
650
+	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
651
+	 * This ALSO ensures that the given messenger is active as well!
652
+	 *
653
+	 * @param string $message_type_name message type name.
654
+	 * @param        $messenger_name
655
+	 * @param bool   $update_option     Whether to update the option in the db or not.
656
+	 * @return bool  Returns true if already is active or if was activated successfully.
657
+	 * @throws \EE_Error
658
+	 */
659
+	public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
660
+	{
661
+		// grab the messenger to work with.
662
+		$messenger = $this->valid_messenger($messenger_name);
663
+		if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
664
+			// ensure messenger is active (that's an inherent coupling between active message types and the
665
+			// messenger they are being activated for.
666
+			try {
667
+				if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
668
+					// all is good so let's just get it active
669
+					$this->activate_messenger($messenger_name, array($message_type_name), $update_option);
670
+				}
671
+			} catch (EE_Error $e) {
672
+				EE_Error::add_error(
673
+					$e->getMessage(),
674
+					__FILE__,
675
+					__FUNCTION__,
676
+					__LINE__
677
+				);
678
+				return false;
679
+			}
680
+		}
681
+		return true;
682
+	}
683
+
684
+
685
+	/**
686
+	 * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
687
+	 * messenger are active in one go.
688
+	 *
689
+	 * @param array  $message_type_names Array of message type names to ensure are active.
690
+	 * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
691
+	 * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
692
+	 */
693
+	public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
694
+	{
695
+		$message_type_names = (array) $message_type_names;
696
+		foreach ($message_type_names as $message_type_name) {
697
+			// note, intentionally not updating option here because we're in a loop.
698
+			// We'll follow the instructions of the incoming $update_option argument after the loop.
699
+			$this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
700
+		}
701
+		if ($update_option) {
702
+			$this->update_active_messengers_option();
703
+			$this->update_has_activated_messengers_option();
704
+		}
705
+	}
706
+
707
+
708
+	/**
709
+	 * Activates the specified messenger.
710
+	 *
711
+	 * @param string $messenger_name
712
+	 * @param array  $message_type_names        An array of message type names to activate with this messenger.
713
+	 *                                          If included we do NOT setup the default message types
714
+	 *                                          (assuming they are already setup.)
715
+	 * @param bool   $update_active_messengers_option
716
+	 * @return array of generated templates
717
+	 * @throws \EE_Error
718
+	 */
719
+	public function activate_messenger(
720
+		$messenger_name,
721
+		$message_type_names = array(),
722
+		$update_active_messengers_option = true
723
+	) {
724
+		$templates = array();
725
+		// grab the messenger to work with.
726
+		$messenger = $this->messenger_collection()->get_by_info($messenger_name);
727
+		// it's inactive. Activate it.
728
+		if ($messenger instanceof EE_messenger) {
729
+			$this->_active_messengers[ $messenger->name ] = $messenger;
730
+			// activate incoming message types set to be activated with messenger.
731
+			$message_type_names = $this->_activate_message_types($messenger, $message_type_names);
732
+			// setup any initial settings for the messenger if necessary.
733
+			$this->add_settings_for_messenger($messenger->name);
734
+			if ($update_active_messengers_option) {
735
+				$this->update_active_messengers_option();
736
+				$this->update_has_activated_messengers_option();
737
+			}
738
+			// generate new templates if necessary and ensure all related templates that are already in the database are
739
+			// marked active.  Note, this will also deactivate a message type for a messenger if the template
740
+			// cannot be successfully created during its attempt (only happens for global template attempts).
741
+			if (! empty($message_type_names)) {
742
+				$templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
743
+				EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
744
+			}
745
+		}
746
+		return $templates;
747
+	}
748
+
749
+
750
+	/**
751
+	 * Activates given message types for the given EE_messenger object.
752
+	 * Note: (very important) This method does not persist the activation to the database.
753
+	 * See code implementing this method in this class for examples of how to persist.
754
+	 *
755
+	 * @param \EE_messenger $messenger
756
+	 * @param  array        $message_type_names
757
+	 * @return array
758
+	 */
759
+	protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
760
+	{
761
+		// If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
762
+		// things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
763
+		// So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
764
+		// only override _active_message_types when an explicit array of $message_type_names has been provided.
765
+		$message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ])
766
+			? $messenger->get_default_message_types()
767
+			: (array) $message_type_names;
768
+
769
+		// now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
770
+		if (! isset($this->_active_message_types[ $messenger->name ])) {
771
+			$this->_active_message_types[ $messenger->name ]['settings'] = array();
772
+		}
773
+
774
+		if ($message_type_names) {
775
+			// cycle thru message types
776
+			foreach ($message_type_names as $message_type_name) {
777
+				// only register the message type as active IF it isn't already active
778
+				// and if its actually installed.
779
+				if (! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
780
+				) {
781
+					$this->add_settings_for_message_type($messenger->name, $message_type_name);
782
+					$this->_set_messenger_has_activated_message_type(
783
+						$messenger,
784
+						$message_type_name
785
+					);
786
+				}
787
+			}
788
+		}
789
+		return $message_type_names;
790
+	}
791
+
792
+
793
+	/**
794
+	 * add_settings_for_message_type
795
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
796
+	 * $this->update_active_messengers_option to persist.
797
+	 *
798
+	 * @param  string $messenger_name    The name of the messenger adding the settings for
799
+	 * @param  string $message_type_name The name of the message type adding the settings for
800
+	 * @param  array  $new_settings      Any new settings being set for the message type and messenger
801
+	 */
802
+	public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
803
+	{
804
+		// get installed message type from collection
805
+		$message_type      = $this->message_type_collection()->get_by_info($message_type_name);
806
+		$existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
807
+		// we need to setup any initial settings for message types
808
+		if ($message_type instanceof EE_message_type) {
809
+			$default_settings = $message_type->get_admin_settings_fields();
810
+			foreach ($default_settings as $field => $values) {
811
+				if (isset($new_settings[ $field ])) {
812
+					$existing_settings[ $field ] = $new_settings[ $field ];
813
+					continue;
814
+				}
815
+				if (! isset($existing_settings[ $field ])) {
816
+					$existing_settings[ $field ] = $values['default'];
817
+				}
818
+			}
819
+		}
820
+		$this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings;
821
+	}
822
+
823
+
824
+	/**
825
+	 * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
826
+	 * and message type.
827
+	 *
828
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
829
+	 *
830
+	 * @access protected
831
+	 * @param \EE_messenger $messenger
832
+	 * @param string        $message_type_name
833
+	 */
834
+	protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
835
+	{
836
+
837
+		// if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
838
+		if (empty($this->_has_activated_messengers_and_message_types)) {
839
+			$this->get_has_activated_messengers_option();
840
+		}
841
+
842
+		// make sure this messenger has a record in the has_activated array
843
+		if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
844
+			$this->_has_activated_messengers_and_message_types[ $messenger->name ] = array();
845
+		}
846
+		// check if message type has already been added
847
+		if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
848
+			$this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name;
849
+		}
850
+	}
851
+
852
+
853
+	/**
854
+	 * add_settings_for_messenger
855
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
856
+	 * $this->update_active_messengers_option to persist.
857
+	 *
858
+	 * @param string $messenger_name The name of the messenger the settings is being added for.
859
+	 * @param array  $new_settings   An array of settings to update the existing settings.
860
+	 */
861
+	public function add_settings_for_messenger($messenger_name, $new_settings = array())
862
+	{
863
+		$messenger = $this->get_messenger($messenger_name);
864
+		if ($messenger instanceof EE_messenger) {
865
+			$msgr_settings = $messenger->get_admin_settings_fields();
866
+			if (! empty($msgr_settings)) {
867
+				foreach ($msgr_settings as $field => $value) {
868
+					// is there a new setting for this?
869
+					if (isset($new_settings[ $field ])) {
870
+						$this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ];
871
+						continue;
872
+					}
873
+					// only set the default if it isn't already set.
874
+					if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) {
875
+						$this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value;
876
+					}
877
+				}
878
+			}
879
+		}
880
+	}
881
+
882
+
883
+	/**
884
+	 * deactivate_messenger
885
+	 *
886
+	 * @param  string|EE_messenger $messenger_name name of messenger
887
+	 * @return void
888
+	 */
889
+	public function deactivate_messenger($messenger_name)
890
+	{
891
+		$this->_initialize_collections();
892
+		if ($messenger_name instanceof EE_messenger) {
893
+			$messenger_name = $messenger_name->name;
894
+		}
895
+		unset($this->_active_messengers[ $messenger_name ]);
896
+		unset($this->_active_message_types[ $messenger_name ]);
897
+		$this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
898
+		$this->update_active_messengers_option();
899
+	}
900
+
901
+
902
+	/**
903
+	 * Deactivates a message type (note this will deactivate across all messenger's it is active on.
904
+	 *
905
+	 * @param  string $message_type_name     name of message type being deactivated
906
+	 * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
907
+	 *                                       type.  However, this can be overridden if we don't want this set (usually when
908
+	 *                                       this is called as a part of deregistration of a custom message type)
909
+	 */
910
+	public function deactivate_message_type($message_type_name, $set_has_active_record = true)
911
+	{
912
+		$this->_initialize_collections();
913
+		if ($message_type_name instanceof EE_message_type) {
914
+			$message_type_name = $message_type_name->name;
915
+		}
916
+		foreach ($this->_active_message_types as $messenger_name => $settings) {
917
+			unset(
918
+				$this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]
919
+			);
920
+
921
+			// we always record (even on deactivation) that a message type has been activated because there should at
922
+			// least be a record in the "has_activated" option that it WAS active at one point.
923
+			if ($set_has_active_record) {
924
+				$messenger = $this->get_messenger($messenger_name);
925
+				$this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
926
+			}
927
+		}
928
+		$this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
929
+		$this->update_active_messengers_option();
930
+		$this->update_has_activated_messengers_option();
931
+	}
932
+
933
+
934
+	/**
935
+	 * Deactivates a message type for a specific messenger as opposed to all messengers.
936
+	 *
937
+	 * @param string $message_type_name Name of message type being deactivated.
938
+	 * @param string $messenger_name    Name of messenger the message type is being deactivated for.
939
+	 */
940
+	public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
941
+	{
942
+		$this->_initialize_collections();
943
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
944
+			unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
945
+		}
946
+		$this->_message_template_group_model->deactivate_message_template_groups_for(
947
+			array($messenger_name),
948
+			array($message_type_name)
949
+		);
950
+		$this->update_active_messengers_option();
951
+	}
952
+
953
+
954
+	/**
955
+	 * Used to verify if a message can be sent for the given messenger and message type
956
+	 * and that it is a generating messenger (used for generating message templates).
957
+	 *
958
+	 * @param EE_messenger    $messenger    messenger used in trigger
959
+	 * @param EE_message_type $message_type message type used in trigger
960
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
961
+	 */
962
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
963
+	{
964
+		// get the $messengers the message type says it can be used with.
965
+		foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
966
+			if ($messenger->name === $generating_messenger
967
+				&& $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
968
+			) {
969
+				return true;
970
+			}
971
+		}
972
+		return false;
973
+	}
974
+
975
+
976
+	/**
977
+	 * This returns all the contexts that are registered by all message types.
978
+	 * If $slugs_only is true,
979
+	 * then just an array indexed by unique context slugs with the latest label representation for that slug.
980
+	 * array(
981
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
982
+	 * );
983
+	 * If $slugs_only is false, then the format is:
984
+	 * array(
985
+	 *      'message_type_name' => array(
986
+	 *          'context_slug' => array(
987
+	 *              'label' => 'localized label for context',
988
+	 *              'description' => 'localized description for context'
989
+	 *          )
990
+	 *      )
991
+	 * );
992
+	 * Keep in mind that although different message types may share the same context slugs,
993
+	 * it is possible that the context is described differently by the message type.
994
+	 *
995
+	 * @since 4.9.0
996
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
997
+	 *                           or all contexts indexed by message type.
998
+	 * @return array
999
+	 */
1000
+	public function get_all_contexts($slugs_only = true)
1001
+	{
1002
+		$key = $slugs_only ? 'slugs' : 'all';
1003
+		// check if contexts has been setup yet.
1004
+		if (empty($this->_contexts[ $key ])) {
1005
+			// So let's get all active message type objects and loop through to get all unique contexts
1006
+			foreach ($this->get_active_message_type_objects() as $message_type) {
1007
+				if ($message_type instanceof EE_message_type) {
1008
+					$message_type_contexts = $message_type->get_contexts();
1009
+					if ($slugs_only) {
1010
+						foreach ($message_type_contexts as $context => $context_details) {
1011
+							$this->_contexts[ $key ][ $context ] = $context_details['label'];
1012
+						}
1013
+					} else {
1014
+						$this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts;
1015
+					}
1016
+				}
1017
+			}
1018
+		}
1019
+		return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array();
1020
+	}
1021
+
1022
+
1023
+	/**
1024
+	 * This checks the internal record of what message types are considered "active" and verifies that
1025
+	 * there is an installed class definition for that message type.  If the active message type does not have a
1026
+	 * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1027
+	 * any related message templates will be inactivated as well.
1028
+	 *
1029
+	 * @return bool   true means all active message types are valid, false means at least one message type was
1030
+	 *                deactivated.
1031
+	 */
1032
+	public function validate_active_message_types_are_installed()
1033
+	{
1034
+		$list_of_active_message_type_names = $this->list_of_active_message_types();
1035
+		$installed_message_types           = $this->installed_message_types();
1036
+		$all_message_types_valid           = true;
1037
+		// loop through list of active message types and verify they are installed.
1038
+		foreach ($list_of_active_message_type_names as $message_type_name) {
1039
+			if (! isset($installed_message_types[ $message_type_name ])) {
1040
+				$this->remove_message_type_has_been_activated_from_all_messengers(
1041
+					$message_type_name,
1042
+					true
1043
+				);
1044
+				$this->deactivate_message_type($message_type_name, false);
1045
+				$all_message_types_valid = false;
1046
+			}
1047
+		}
1048
+		return $all_message_types_valid;
1049
+	}
1050
+
1051
+
1052
+	/**
1053
+	 * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1054
+	 * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1055
+	 * to attempt automatically reactivating message types that should be activated by default or not.
1056
+	 *
1057
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1058
+	 *
1059
+	 * @param $message_type_name
1060
+	 * @param $messenger_name
1061
+	 * @return bool
1062
+	 */
1063
+	public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1064
+	{
1065
+		$has_activated = $this->get_has_activated_messengers_option();
1066
+		return isset($has_activated[ $messenger_name ])
1067
+			   && in_array($message_type_name, $has_activated[ $messenger_name ]);
1068
+	}
1069
+
1070
+
1071
+	/**
1072
+	 * This method unsets a message type from the given messenger has activated option.
1073
+	 *
1074
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1075
+	 *
1076
+	 * @param string $message_type_name
1077
+	 * @param string $messenger_name
1078
+	 * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1079
+	 *                                        If it is currently active, then remove.  Otherwise leave it alone.
1080
+	 */
1081
+	public function remove_message_type_has_been_activated_for_messenger(
1082
+		$message_type_name,
1083
+		$messenger_name,
1084
+		$consider_current_state = false
1085
+	) {
1086
+		if ($consider_current_state
1087
+			&& ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1088
+		) {
1089
+			// when consider current state is true, this means we don't want to change anything on the "has_activated"
1090
+			// record if the message type is currently active for this messenger.  This is used when we want to retain
1091
+			// the record for user initiated inactivations of the message type.
1092
+			return;
1093
+		}
1094
+		$has_activated = $this->get_has_activated_messengers_option();
1095
+		$key_for_message_type = isset($has_activated[ $messenger_name ])
1096
+			? array_search($message_type_name, $has_activated[ $messenger_name ], true)
1097
+			: false;
1098
+		if ($key_for_message_type !== false) {
1099
+			unset($has_activated[ $messenger_name ][ $key_for_message_type ]);
1100
+			$this->update_has_activated_messengers_option($has_activated);
1101
+			// reset the internal cached property
1102
+			$this->get_has_activated_messengers_option(true);
1103
+		}
1104
+	}
1105
+
1106
+
1107
+	/**
1108
+	 * Removes a message type active record from all messengers it is attached to.
1109
+	 *
1110
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1111
+	 *
1112
+	 * @param      $message_type_name
1113
+	 * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1114
+	 *                                      If it is currently active, then remove.  Otherwise leave it alone.
1115
+	 */
1116
+	public function remove_message_type_has_been_activated_from_all_messengers(
1117
+		$message_type_name,
1118
+		$consider_current_state = false
1119
+	) {
1120
+		foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1121
+			$this->remove_message_type_has_been_activated_for_messenger(
1122
+				$message_type_name,
1123
+				$messenger_name,
1124
+				$consider_current_state
1125
+			);
1126
+		}
1127
+	}
1128 1128
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
     public function get_active_messenger($messenger)
197 197
     {
198 198
         $this->_initialize_collections();
199
-        return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null;
199
+        return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
200 200
     }
201 201
 
202 202
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
             $this->_installed_messengers = array();
210 210
             $this->messenger_collection()->rewind();
211 211
             while ($this->messenger_collection()->valid()) {
212
-                $this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current();
212
+                $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
213 213
                 $this->messenger_collection()->next();
214 214
             }
215 215
         }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
293 293
     {
294 294
         $this->_initialize_collections();
295
-        return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
295
+        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
296 296
     }
297 297
 
298 298
 
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
     public function is_messenger_active($messenger_name)
306 306
     {
307 307
         $this->_initialize_collections();
308
-        return ! empty($this->_active_message_types[ $messenger_name ]);
308
+        return ! empty($this->_active_message_types[$messenger_name]);
309 309
     }
310 310
 
311 311
 
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
     {
321 321
         $settings = array();
322 322
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
323
-            $settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'])
324
-                ? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']
323
+            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'])
324
+                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']
325 325
                 : array();
326 326
         }
327 327
         return $settings;
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
     {
340 340
         $this->_initialize_collections();
341 341
         return
342
-            ! empty($this->_active_message_types[ $messenger_name ])
343
-            && ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]);
342
+            ! empty($this->_active_message_types[$messenger_name])
343
+            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']);
344 344
     }
345 345
 
346 346
 
@@ -355,13 +355,13 @@  discard block
 block discarded – undo
355 355
     public function get_active_message_types_for_messenger($messenger_name)
356 356
     {
357 357
         $message_types = array();
358
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
358
+        if ( ! $this->messenger_has_active_message_types($messenger_name)) {
359 359
             return $message_types;
360 360
         }
361 361
         $installed_message_types = $this->installed_message_types();
362 362
         foreach ($installed_message_types as $message_type_name => $message_type) {
363 363
             if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
364
-                $message_types[ $message_type_name ] = $message_type;
364
+                $message_types[$message_type_name] = $message_type;
365 365
             }
366 366
         }
367 367
         return $message_types;
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
         $active_message_type_names = array();
381 381
         $this->_initialize_collections();
382 382
         foreach ($this->_active_message_types as $messenger => $messenger_settings) {
383
-            if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) {
383
+            if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) {
384 384
                 continue;
385 385
             }
386
-            foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) {
387
-                if (! in_array($message_type_name, $active_message_type_names)) {
386
+            foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) {
387
+                if ( ! in_array($message_type_name, $active_message_type_names)) {
388 388
                     $active_message_type_names[] = $message_type_name;
389 389
                 }
390 390
             }
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
         $installed_message_types   = $this->installed_message_types();
406 406
         $active_message_type_names = $this->list_of_active_message_types();
407 407
         foreach ($active_message_type_names as $active_message_type_name) {
408
-            if (isset($installed_message_types[ $active_message_type_name ])) {
409
-                $active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ];
408
+            if (isset($installed_message_types[$active_message_type_name])) {
409
+                $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
410 410
             }
411 411
         }
412 412
         return $active_message_types;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
         if (empty($this->_installed_message_types)) {
422 422
             $this->message_type_collection()->rewind();
423 423
             while ($this->message_type_collection()->valid()) {
424
-                $this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current();
424
+                $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
425 425
                 $this->message_type_collection()->next();
426 426
             }
427 427
         }
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
     public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
461 461
     {
462 462
         $valid_message_types = $messenger->get_valid_message_types();
463
-        if (! in_array($message_type_name, $valid_message_types)) {
463
+        if ( ! in_array($message_type_name, $valid_message_types)) {
464 464
             throw new EE_Error(
465 465
                 sprintf(
466 466
                     __(
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
      */
587 587
     public function ensure_messenger_is_active($messenger_name, $update_option = true)
588 588
     {
589
-        if (! isset($this->_active_messengers[ $messenger_name ])) {
589
+        if ( ! isset($this->_active_messengers[$messenger_name])) {
590 590
             try {
591 591
                 $this->activate_messenger($messenger_name, array(), $update_option);
592 592
             } catch (EE_Error $e) {
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
             $this->ensure_messenger_is_active($messenger_name, $update_option);
632 632
         }
633 633
 
634
-        if (! empty($not_installed)) {
634
+        if ( ! empty($not_installed)) {
635 635
             EE_Error::add_error(
636 636
                 sprintf(
637 637
                     __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
             // ensure messenger is active (that's an inherent coupling between active message types and the
665 665
             // messenger they are being activated for.
666 666
             try {
667
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
667
+                if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
668 668
                     // all is good so let's just get it active
669 669
                     $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
670 670
                 }
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
         $messenger = $this->messenger_collection()->get_by_info($messenger_name);
727 727
         // it's inactive. Activate it.
728 728
         if ($messenger instanceof EE_messenger) {
729
-            $this->_active_messengers[ $messenger->name ] = $messenger;
729
+            $this->_active_messengers[$messenger->name] = $messenger;
730 730
             // activate incoming message types set to be activated with messenger.
731 731
             $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
732 732
             // setup any initial settings for the messenger if necessary.
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
             // generate new templates if necessary and ensure all related templates that are already in the database are
739 739
             // marked active.  Note, this will also deactivate a message type for a messenger if the template
740 740
             // cannot be successfully created during its attempt (only happens for global template attempts).
741
-            if (! empty($message_type_names)) {
741
+            if ( ! empty($message_type_names)) {
742 742
                 $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
743 743
                 EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
744 744
             }
@@ -762,13 +762,13 @@  discard block
 block discarded – undo
762 762
         // things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
763 763
         // So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
764 764
         // only override _active_message_types when an explicit array of $message_type_names has been provided.
765
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ])
765
+        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
766 766
             ? $messenger->get_default_message_types()
767 767
             : (array) $message_type_names;
768 768
 
769 769
         // now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
770
-        if (! isset($this->_active_message_types[ $messenger->name ])) {
771
-            $this->_active_message_types[ $messenger->name ]['settings'] = array();
770
+        if ( ! isset($this->_active_message_types[$messenger->name])) {
771
+            $this->_active_message_types[$messenger->name]['settings'] = array();
772 772
         }
773 773
 
774 774
         if ($message_type_names) {
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
             foreach ($message_type_names as $message_type_name) {
777 777
                 // only register the message type as active IF it isn't already active
778 778
                 // and if its actually installed.
779
-                if (! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
779
+                if ( ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
780 780
                 ) {
781 781
                     $this->add_settings_for_message_type($messenger->name, $message_type_name);
782 782
                     $this->_set_messenger_has_activated_message_type(
@@ -808,16 +808,16 @@  discard block
 block discarded – undo
808 808
         if ($message_type instanceof EE_message_type) {
809 809
             $default_settings = $message_type->get_admin_settings_fields();
810 810
             foreach ($default_settings as $field => $values) {
811
-                if (isset($new_settings[ $field ])) {
812
-                    $existing_settings[ $field ] = $new_settings[ $field ];
811
+                if (isset($new_settings[$field])) {
812
+                    $existing_settings[$field] = $new_settings[$field];
813 813
                     continue;
814 814
                 }
815
-                if (! isset($existing_settings[ $field ])) {
816
-                    $existing_settings[ $field ] = $values['default'];
815
+                if ( ! isset($existing_settings[$field])) {
816
+                    $existing_settings[$field] = $values['default'];
817 817
                 }
818 818
             }
819 819
         }
820
-        $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings;
820
+        $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings;
821 821
     }
822 822
 
823 823
 
@@ -840,12 +840,12 @@  discard block
 block discarded – undo
840 840
         }
841 841
 
842 842
         // make sure this messenger has a record in the has_activated array
843
-        if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
844
-            $this->_has_activated_messengers_and_message_types[ $messenger->name ] = array();
843
+        if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
844
+            $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
845 845
         }
846 846
         // check if message type has already been added
847
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
848
-            $this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name;
847
+        if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
+            $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
849 849
         }
850 850
     }
851 851
 
@@ -863,16 +863,16 @@  discard block
 block discarded – undo
863 863
         $messenger = $this->get_messenger($messenger_name);
864 864
         if ($messenger instanceof EE_messenger) {
865 865
             $msgr_settings = $messenger->get_admin_settings_fields();
866
-            if (! empty($msgr_settings)) {
866
+            if ( ! empty($msgr_settings)) {
867 867
                 foreach ($msgr_settings as $field => $value) {
868 868
                     // is there a new setting for this?
869
-                    if (isset($new_settings[ $field ])) {
870
-                        $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ];
869
+                    if (isset($new_settings[$field])) {
870
+                        $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
871 871
                         continue;
872 872
                     }
873 873
                     // only set the default if it isn't already set.
874
-                    if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) {
875
-                        $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value;
874
+                    if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
875
+                        $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
876 876
                     }
877 877
                 }
878 878
             }
@@ -892,8 +892,8 @@  discard block
 block discarded – undo
892 892
         if ($messenger_name instanceof EE_messenger) {
893 893
             $messenger_name = $messenger_name->name;
894 894
         }
895
-        unset($this->_active_messengers[ $messenger_name ]);
896
-        unset($this->_active_message_types[ $messenger_name ]);
895
+        unset($this->_active_messengers[$messenger_name]);
896
+        unset($this->_active_message_types[$messenger_name]);
897 897
         $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
898 898
         $this->update_active_messengers_option();
899 899
     }
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
         }
916 916
         foreach ($this->_active_message_types as $messenger_name => $settings) {
917 917
             unset(
918
-                $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]
918
+                $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]
919 919
             );
920 920
 
921 921
             // we always record (even on deactivation) that a message type has been activated because there should at
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
     {
942 942
         $this->_initialize_collections();
943 943
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
944
-            unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
944
+            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
945 945
         }
946 946
         $this->_message_template_group_model->deactivate_message_template_groups_for(
947 947
             array($messenger_name),
@@ -1001,22 +1001,22 @@  discard block
 block discarded – undo
1001 1001
     {
1002 1002
         $key = $slugs_only ? 'slugs' : 'all';
1003 1003
         // check if contexts has been setup yet.
1004
-        if (empty($this->_contexts[ $key ])) {
1004
+        if (empty($this->_contexts[$key])) {
1005 1005
             // So let's get all active message type objects and loop through to get all unique contexts
1006 1006
             foreach ($this->get_active_message_type_objects() as $message_type) {
1007 1007
                 if ($message_type instanceof EE_message_type) {
1008 1008
                     $message_type_contexts = $message_type->get_contexts();
1009 1009
                     if ($slugs_only) {
1010 1010
                         foreach ($message_type_contexts as $context => $context_details) {
1011
-                            $this->_contexts[ $key ][ $context ] = $context_details['label'];
1011
+                            $this->_contexts[$key][$context] = $context_details['label'];
1012 1012
                         }
1013 1013
                     } else {
1014
-                        $this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts;
1014
+                        $this->_contexts[$key][$message_type->name] = $message_type_contexts;
1015 1015
                     }
1016 1016
                 }
1017 1017
             }
1018 1018
         }
1019
-        return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array();
1019
+        return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1020 1020
     }
1021 1021
 
1022 1022
 
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
         $all_message_types_valid           = true;
1037 1037
         // loop through list of active message types and verify they are installed.
1038 1038
         foreach ($list_of_active_message_type_names as $message_type_name) {
1039
-            if (! isset($installed_message_types[ $message_type_name ])) {
1039
+            if ( ! isset($installed_message_types[$message_type_name])) {
1040 1040
                 $this->remove_message_type_has_been_activated_from_all_messengers(
1041 1041
                     $message_type_name,
1042 1042
                     true
@@ -1063,8 +1063,8 @@  discard block
 block discarded – undo
1063 1063
     public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1064 1064
     {
1065 1065
         $has_activated = $this->get_has_activated_messengers_option();
1066
-        return isset($has_activated[ $messenger_name ])
1067
-               && in_array($message_type_name, $has_activated[ $messenger_name ]);
1066
+        return isset($has_activated[$messenger_name])
1067
+               && in_array($message_type_name, $has_activated[$messenger_name]);
1068 1068
     }
1069 1069
 
1070 1070
 
@@ -1092,11 +1092,11 @@  discard block
 block discarded – undo
1092 1092
             return;
1093 1093
         }
1094 1094
         $has_activated = $this->get_has_activated_messengers_option();
1095
-        $key_for_message_type = isset($has_activated[ $messenger_name ])
1096
-            ? array_search($message_type_name, $has_activated[ $messenger_name ], true)
1095
+        $key_for_message_type = isset($has_activated[$messenger_name])
1096
+            ? array_search($message_type_name, $has_activated[$messenger_name], true)
1097 1097
             : false;
1098 1098
         if ($key_for_message_type !== false) {
1099
-            unset($has_activated[ $messenger_name ][ $key_for_message_type ]);
1099
+            unset($has_activated[$messenger_name][$key_for_message_type]);
1100 1100
             $this->update_has_activated_messengers_option($has_activated);
1101 1101
             // reset the internal cached property
1102 1102
             $this->get_has_activated_messengers_option(true);
Please login to merge, or discard this patch.
core/libraries/messages/EE_Payment_Base_message_type.lib.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -15,67 +15,67 @@
 block discarded – undo
15 15
 
16 16
 
17 17
 
18
-    /**
19
-     * @see parent::get_priority() for documentation.
20
-     * @return int
21
-     */
22
-    public function get_priority()
23
-    {
24
-        return EEM_Message::priority_high;
25
-    }
18
+	/**
19
+	 * @see parent::get_priority() for documentation.
20
+	 * @return int
21
+	 */
22
+	public function get_priority()
23
+	{
24
+		return EEM_Message::priority_high;
25
+	}
26 26
 
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * see abstract declaration in parent class for details.
32
-     */
33
-    protected function _set_admin_pages()
34
-    {
35
-        $this->admin_registered_pages = array(
36
-            'events_edit' => true
37
-            );
38
-    }
30
+	/**
31
+	 * see abstract declaration in parent class for details.
32
+	 */
33
+	protected function _set_admin_pages()
34
+	{
35
+		$this->admin_registered_pages = array(
36
+			'events_edit' => true
37
+			);
38
+	}
39 39
 
40 40
 
41 41
 
42
-    protected function _set_data_handler()
43
-    {
44
-        $this->_data_handler = 'Gateways';
45
-    }
42
+	protected function _set_data_handler()
43
+	{
44
+		$this->_data_handler = 'Gateways';
45
+	}
46 46
 
47 47
 
48 48
 
49 49
 
50
-    protected function _get_data_for_context($context, EE_Registration $registration, $id)
51
-    {
50
+	protected function _get_data_for_context($context, EE_Registration $registration, $id)
51
+	{
52 52
 
53
-        // use the registration to get the transaction.
54
-        $transaction = $registration->transaction();
53
+		// use the registration to get the transaction.
54
+		$transaction = $registration->transaction();
55 55
 
56
-        // bail early if no transaction
57
-        if (! $transaction instanceof EE_Transaction) {
58
-            throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
59
-        }
56
+		// bail early if no transaction
57
+		if (! $transaction instanceof EE_Transaction) {
58
+			throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
59
+		}
60 60
 
61
-        $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
61
+		$payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
62 62
 
63
-        return array( $transaction, $payment );
64
-    }
63
+		return array( $transaction, $payment );
64
+	}
65 65
 
66 66
 
67 67
 
68
-    protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
69
-    {
70
-        // this is just a test
71
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
72
-    }
68
+	protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
69
+	{
70
+		// this is just a test
71
+		return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
72
+	}
73 73
 
74
-    /**
75
-     * This message type doesn't need any settings so we are just setting to empty array.
76
-     */
77
-    protected function _set_admin_settings_fields()
78
-    {
79
-        $this->_admin_settings_fields = array();
80
-    }
74
+	/**
75
+	 * This message type doesn't need any settings so we are just setting to empty array.
76
+	 */
77
+	protected function _set_admin_settings_fields()
78
+	{
79
+		$this->_admin_settings_fields = array();
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
         $transaction = $registration->transaction();
55 55
 
56 56
         // bail early if no transaction
57
-        if (! $transaction instanceof EE_Transaction) {
57
+        if ( ! $transaction instanceof EE_Transaction) {
58 58
             throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
59 59
         }
60 60
 
61
-        $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
61
+        $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0;
62 62
 
63
-        return array( $transaction, $payment );
63
+        return array($transaction, $payment);
64 64
     }
65 65
 
66 66
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
69 69
     {
70 70
         // this is just a test
71
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
71
+        return $this->name.' Message Type for '.$messenger->name.' Messenger ';
72 72
     }
73 73
 
74 74
     /**
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Type_Collection_Loader.lib.php 2 patches
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -15,105 +15,105 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @type EE_Message_Type_Collection $_message_type_collection
20
-     */
21
-    protected $_message_type_collection = null;
22
-
23
-
24
-
25
-    /**
26
-     * EE_Message_Type_Collection_Loader constructor.
27
-     *
28
-     * @param EE_Message_Type_Collection $message_types
29
-     */
30
-    public function __construct(EE_Message_Type_Collection $message_types)
31
-    {
32
-        $this->set_message_type_collection($message_types);
33
-    }
34
-
35
-
36
-
37
-    /**
38
-     * @return EE_Message_Type_Collection
39
-     */
40
-    public function message_type_collection()
41
-    {
42
-        return $this->_message_type_collection;
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * @param mixed $message_types
49
-     */
50
-    public function set_message_type_collection(EE_Message_Type_Collection $message_types)
51
-    {
52
-        $this->_message_type_collection = $message_types;
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * load_message_types
59
-     * globs the supplied filepath and adds any found
60
-     *
61
-     * @param  string $folder
62
-     * @throws \EE_Error
63
-     */
64
-    public function load_message_types_from_folder($folder = '')
65
-    {
66
-        // make sure autoloaders are set (fail-safe)
67
-        EED_Messages::set_autoloaders();
68
-        $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages' . DS . 'message_type';
69
-        $folder .= $folder[ strlen($folder) - 1 ] != DS ? DS : '';
70
-        // get all the files in that folder that end in ".class.php
71
-        $filepaths = apply_filters(
72
-            'FHEE__EE_messages__get_installed__messagetype_files',
73
-            glob($folder . '*.class.php')
74
-        );
75
-        if (empty($filepaths)) {
76
-            return;
77
-        }
78
-        foreach ((array) $filepaths as $file_path) {
79
-            // extract filename from path
80
-            $file_path = basename($file_path);
81
-            // now remove any file extensions
82
-            $message_type_class_name = substr($file_path, 0, strpos($file_path, '.'));
83
-
84
-            // if this class name doesn't represent a message type class, then we just skip.
85
-            if (strpos(strtolower($message_type_class_name), 'message_type') === false) {
86
-                continue;
87
-            }
88
-
89
-            if (! class_exists($message_type_class_name)) {
90
-                throw new EE_Error(
91
-                    sprintf(
92
-                        __('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'),
93
-                        $message_type_class_name,
94
-                        $file_path
95
-                    )
96
-                );
97
-            }
98
-
99
-            $this->_load_message_type(new $message_type_class_name);
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     * Loads the given message type into the message type collection if it doesn't already exist.
106
-     * @param EE_message_type $message_type
107
-     * @return bool
108
-     */
109
-    protected function _load_message_type(EE_message_type $message_type)
110
-    {
111
-        if ($this->message_type_collection()->has_by_name($message_type->name)) {
112
-            return true;
113
-        }
114
-        return $this->message_type_collection()->add(
115
-            $message_type,
116
-            $message_type->name
117
-        );
118
-    }
18
+	/**
19
+	 * @type EE_Message_Type_Collection $_message_type_collection
20
+	 */
21
+	protected $_message_type_collection = null;
22
+
23
+
24
+
25
+	/**
26
+	 * EE_Message_Type_Collection_Loader constructor.
27
+	 *
28
+	 * @param EE_Message_Type_Collection $message_types
29
+	 */
30
+	public function __construct(EE_Message_Type_Collection $message_types)
31
+	{
32
+		$this->set_message_type_collection($message_types);
33
+	}
34
+
35
+
36
+
37
+	/**
38
+	 * @return EE_Message_Type_Collection
39
+	 */
40
+	public function message_type_collection()
41
+	{
42
+		return $this->_message_type_collection;
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * @param mixed $message_types
49
+	 */
50
+	public function set_message_type_collection(EE_Message_Type_Collection $message_types)
51
+	{
52
+		$this->_message_type_collection = $message_types;
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * load_message_types
59
+	 * globs the supplied filepath and adds any found
60
+	 *
61
+	 * @param  string $folder
62
+	 * @throws \EE_Error
63
+	 */
64
+	public function load_message_types_from_folder($folder = '')
65
+	{
66
+		// make sure autoloaders are set (fail-safe)
67
+		EED_Messages::set_autoloaders();
68
+		$folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages' . DS . 'message_type';
69
+		$folder .= $folder[ strlen($folder) - 1 ] != DS ? DS : '';
70
+		// get all the files in that folder that end in ".class.php
71
+		$filepaths = apply_filters(
72
+			'FHEE__EE_messages__get_installed__messagetype_files',
73
+			glob($folder . '*.class.php')
74
+		);
75
+		if (empty($filepaths)) {
76
+			return;
77
+		}
78
+		foreach ((array) $filepaths as $file_path) {
79
+			// extract filename from path
80
+			$file_path = basename($file_path);
81
+			// now remove any file extensions
82
+			$message_type_class_name = substr($file_path, 0, strpos($file_path, '.'));
83
+
84
+			// if this class name doesn't represent a message type class, then we just skip.
85
+			if (strpos(strtolower($message_type_class_name), 'message_type') === false) {
86
+				continue;
87
+			}
88
+
89
+			if (! class_exists($message_type_class_name)) {
90
+				throw new EE_Error(
91
+					sprintf(
92
+						__('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'),
93
+						$message_type_class_name,
94
+						$file_path
95
+					)
96
+				);
97
+			}
98
+
99
+			$this->_load_message_type(new $message_type_class_name);
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 * Loads the given message type into the message type collection if it doesn't already exist.
106
+	 * @param EE_message_type $message_type
107
+	 * @return bool
108
+	 */
109
+	protected function _load_message_type(EE_message_type $message_type)
110
+	{
111
+		if ($this->message_type_collection()->has_by_name($message_type->name)) {
112
+			return true;
113
+		}
114
+		return $this->message_type_collection()->add(
115
+			$message_type,
116
+			$message_type->name
117
+		);
118
+	}
119 119
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
     {
66 66
         // make sure autoloaders are set (fail-safe)
67 67
         EED_Messages::set_autoloaders();
68
-        $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages' . DS . 'message_type';
69
-        $folder .= $folder[ strlen($folder) - 1 ] != DS ? DS : '';
68
+        $folder = ! empty($folder) ? $folder : EE_LIBRARIES.'messages'.DS.'message_type';
69
+        $folder .= $folder[strlen($folder) - 1] != DS ? DS : '';
70 70
         // get all the files in that folder that end in ".class.php
71 71
         $filepaths = apply_filters(
72 72
             'FHEE__EE_messages__get_installed__messagetype_files',
73
-            glob($folder . '*.class.php')
73
+            glob($folder.'*.class.php')
74 74
         );
75 75
         if (empty($filepaths)) {
76 76
             return;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                 continue;
87 87
             }
88 88
 
89
-            if (! class_exists($message_type_class_name)) {
89
+            if ( ! class_exists($message_type_class_name)) {
90 90
                 throw new EE_Error(
91 91
                     sprintf(
92 92
                         __('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'),
Please login to merge, or discard this patch.
core/libraries/messages/EE_Registration_Base_message_type.lib.php 2 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -14,126 +14,126 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * @see parent::get_priority() for documentation.
19
-     * @return int
20
-     */
21
-    public function get_priority()
22
-    {
23
-        return EEM_Message::priority_medium;
24
-    }
25
-
26
-
27
-
28
-    protected function _set_admin_pages()
29
-    {
30
-        $this->admin_registered_pages = array(
31
-            'events_edit' => true
32
-            );
33
-    }
34
-
35
-
36
-    protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
37
-    {
38
-        // this is just a test
39
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
40
-    }
41
-
42
-
43
-
44
-
45
-    protected function _set_data_handler()
46
-    {
47
-        if (is_array($this->_data)) {
48
-            $data_type = reset($this->_data);
49
-
50
-            if (is_array($data_type)) {
51
-                // grab the first item and see if its a registration.
52
-                $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type);
53
-                if ($maybe_reg instanceof EE_Registration) {
54
-                    // is $data_type itself just an array of registrations?
55
-                    if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
56
-                        $regs = $data_type;
57
-                    } else {
58
-                        $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
59
-                    }
60
-
61
-                    foreach ($regs as $reg) {
62
-                        if ($reg instanceof EE_Registration) {
63
-                            $this->_regs_for_sending[] = $reg->ID();
64
-                        }
65
-                    }
66
-                    $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
67
-                    $this->_data_handler = 'Gateways';
68
-                } else {
69
-                    $this->_data_handler = 'Gateways';
70
-                }
71
-            } else {
72
-                $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways';
73
-            }
74
-        } else {
75
-            $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways';
76
-        }
77
-
78
-        $this->_single_message = $this->_data_handler == 'REG' ? true : false;
79
-    }
80
-
81
-
82
-
83
-    protected function _get_data_for_context($context, EE_Registration $registration, $id)
84
-    {
85
-        if ($context  == 'admin') {
86
-            // use the registration to get the transaction.
87
-            $transaction = $registration->transaction();
88
-
89
-            // bail early if no transaction
90
-            if (! $transaction instanceof EE_Transaction) {
91
-                throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
92
-            }
93
-
94
-            $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
95
-            return array( $transaction, $payment );
96
-        } else {
97
-            return $registration;
98
-        }
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     * Setup admin settings for this message type.
105
-     */
106
-    protected function _set_admin_settings_fields()
107
-    {
108
-        $this->_admin_settings_fields = array();
109
-    }
110
-
111
-
112
-
113
-
114
-
115
-    /**
116
-     * returns an array of addressee objects for event_admins
117
-     *
118
-     * @access protected
119
-     * @return array array of EE_Messages_Addressee objects
120
-     */
121
-    protected function _admin_addressees()
122
-    {
123
-        if ($this->_single_message) {
124
-            return array();
125
-        }
126
-        return parent::_admin_addressees();
127
-    }
128
-
129
-
130
-
131
-    protected function _primary_attendee_addressees()
132
-    {
133
-        if ($this->_single_message) {
134
-            return array();
135
-        }
136
-
137
-        return parent::_primary_attendee_addressees();
138
-    }
17
+	/**
18
+	 * @see parent::get_priority() for documentation.
19
+	 * @return int
20
+	 */
21
+	public function get_priority()
22
+	{
23
+		return EEM_Message::priority_medium;
24
+	}
25
+
26
+
27
+
28
+	protected function _set_admin_pages()
29
+	{
30
+		$this->admin_registered_pages = array(
31
+			'events_edit' => true
32
+			);
33
+	}
34
+
35
+
36
+	protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
37
+	{
38
+		// this is just a test
39
+		return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
40
+	}
41
+
42
+
43
+
44
+
45
+	protected function _set_data_handler()
46
+	{
47
+		if (is_array($this->_data)) {
48
+			$data_type = reset($this->_data);
49
+
50
+			if (is_array($data_type)) {
51
+				// grab the first item and see if its a registration.
52
+				$maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type);
53
+				if ($maybe_reg instanceof EE_Registration) {
54
+					// is $data_type itself just an array of registrations?
55
+					if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
56
+						$regs = $data_type;
57
+					} else {
58
+						$regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
59
+					}
60
+
61
+					foreach ($regs as $reg) {
62
+						if ($reg instanceof EE_Registration) {
63
+							$this->_regs_for_sending[] = $reg->ID();
64
+						}
65
+					}
66
+					$this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
67
+					$this->_data_handler = 'Gateways';
68
+				} else {
69
+					$this->_data_handler = 'Gateways';
70
+				}
71
+			} else {
72
+				$this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways';
73
+			}
74
+		} else {
75
+			$this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways';
76
+		}
77
+
78
+		$this->_single_message = $this->_data_handler == 'REG' ? true : false;
79
+	}
80
+
81
+
82
+
83
+	protected function _get_data_for_context($context, EE_Registration $registration, $id)
84
+	{
85
+		if ($context  == 'admin') {
86
+			// use the registration to get the transaction.
87
+			$transaction = $registration->transaction();
88
+
89
+			// bail early if no transaction
90
+			if (! $transaction instanceof EE_Transaction) {
91
+				throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
92
+			}
93
+
94
+			$payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
95
+			return array( $transaction, $payment );
96
+		} else {
97
+			return $registration;
98
+		}
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 * Setup admin settings for this message type.
105
+	 */
106
+	protected function _set_admin_settings_fields()
107
+	{
108
+		$this->_admin_settings_fields = array();
109
+	}
110
+
111
+
112
+
113
+
114
+
115
+	/**
116
+	 * returns an array of addressee objects for event_admins
117
+	 *
118
+	 * @access protected
119
+	 * @return array array of EE_Messages_Addressee objects
120
+	 */
121
+	protected function _admin_addressees()
122
+	{
123
+		if ($this->_single_message) {
124
+			return array();
125
+		}
126
+		return parent::_admin_addressees();
127
+	}
128
+
129
+
130
+
131
+	protected function _primary_attendee_addressees()
132
+	{
133
+		if ($this->_single_message) {
134
+			return array();
135
+		}
136
+
137
+		return parent::_primary_attendee_addressees();
138
+	}
139 139
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
37 37
     {
38 38
         // this is just a test
39
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
39
+        return $this->name.' Message Type for '.$messenger->name.' Messenger ';
40 40
     }
41 41
 
42 42
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
                     if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
56 56
                         $regs = $data_type;
57 57
                     } else {
58
-                        $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
58
+                        $regs = is_array($data_type[0]) ? $data_type[0] : array($maybe_reg);
59 59
                     }
60 60
 
61 61
                     foreach ($regs as $reg) {
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                             $this->_regs_for_sending[] = $reg->ID();
64 64
                         }
65 65
                     }
66
-                    $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
66
+                    $this->_data = isset($this->_data[1]) ? array($maybe_reg->transaction(), null, $this->_data[1]) : array($maybe_reg->transaction());
67 67
                     $this->_data_handler = 'Gateways';
68 68
                 } else {
69 69
                     $this->_data_handler = 'Gateways';
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
 
83 83
     protected function _get_data_for_context($context, EE_Registration $registration, $id)
84 84
     {
85
-        if ($context  == 'admin') {
85
+        if ($context == 'admin') {
86 86
             // use the registration to get the transaction.
87 87
             $transaction = $registration->transaction();
88 88
 
89 89
             // bail early if no transaction
90
-            if (! $transaction instanceof EE_Transaction) {
90
+            if ( ! $transaction instanceof EE_Transaction) {
91 91
                 throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
92 92
             }
93 93
 
94
-            $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
95
-            return array( $transaction, $payment );
94
+            $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0;
95
+            return array($transaction, $payment);
96 96
         } else {
97 97
             return $registration;
98 98
         }
Please login to merge, or discard this patch.
libraries/messages/message_type/EE_Payment_Refund_message_type.class.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -15,50 +15,50 @@
 block discarded – undo
15 15
 class EE_Payment_Refund_message_type extends EE_Payment_Base_message_type
16 16
 {
17 17
 
18
-    public function __construct()
19
-    {
18
+	public function __construct()
19
+	{
20 20
 
21
-        // setup type details for reference
22
-        $this->name = 'payment_refund';
23
-        $this->description = __('This message type is used for all payment notification messages that go out for refunds.', 'event_espresso');
24
-        $this->label = array(
25
-            'singular' => __('refund issued', 'event_espresso'),
26
-            'plural' => __('refunds issued', 'event_espresso')
27
-            );
21
+		// setup type details for reference
22
+		$this->name = 'payment_refund';
23
+		$this->description = __('This message type is used for all payment notification messages that go out for refunds.', 'event_espresso');
24
+		$this->label = array(
25
+			'singular' => __('refund issued', 'event_espresso'),
26
+			'plural' => __('refunds issued', 'event_espresso')
27
+			);
28 28
 
29
-        $this->_master_templates = array(
30
-            'email' => 'payment'
31
-            );
29
+		$this->_master_templates = array(
30
+			'email' => 'payment'
31
+			);
32 32
 
33
-        parent::__construct();
34
-    }
33
+		parent::__construct();
34
+	}
35 35
 
36 36
 
37 37
 
38
-    /**
39
-     * _set_contexts
40
-     * This sets up the contexts associated with the message_type
41
-     *
42
-     * @access  protected
43
-     * @return  void
44
-     */
45
-    protected function _set_contexts()
46
-    {
47
-        $this->_context_label = array(
48
-            'label' => __('recipient', 'event_espresso'),
49
-            'plural' => __('recipients', 'event_espresso'),
50
-            'description' => __('Recipient\'s are who will receive the template.  You may want different payment details sent out depending on who the recipient is', 'event_espresso')
51
-            );
38
+	/**
39
+	 * _set_contexts
40
+	 * This sets up the contexts associated with the message_type
41
+	 *
42
+	 * @access  protected
43
+	 * @return  void
44
+	 */
45
+	protected function _set_contexts()
46
+	{
47
+		$this->_context_label = array(
48
+			'label' => __('recipient', 'event_espresso'),
49
+			'plural' => __('recipients', 'event_espresso'),
50
+			'description' => __('Recipient\'s are who will receive the template.  You may want different payment details sent out depending on who the recipient is', 'event_espresso')
51
+			);
52 52
 
53
-        $this->_contexts = array(
54
-            'admin' => array(
55
-                'label' => __('Event Admin', 'event_espresso'),
56
-                'description' => __('This template is what event administrators will receive on a successful refund.', 'event_espresso')
57
-                ),
58
-            'primary_attendee' => array(
59
-                'label' => __('Primary Registrant', 'event_espresso'),
60
-                'description' => __('This template is what the primary registrant (the person who made the main registration) will receive on successful refund.', 'event_espresso')
61
-                )
62
-            );
63
-    }
53
+		$this->_contexts = array(
54
+			'admin' => array(
55
+				'label' => __('Event Admin', 'event_espresso'),
56
+				'description' => __('This template is what event administrators will receive on a successful refund.', 'event_espresso')
57
+				),
58
+			'primary_attendee' => array(
59
+				'label' => __('Primary Registrant', 'event_espresso'),
60
+				'description' => __('This template is what the primary registrant (the person who made the main registration) will receive on successful refund.', 'event_espresso')
61
+				)
62
+			);
63
+	}
64 64
 }
Please login to merge, or discard this patch.
core/libraries/messages/message_type/EE_Registration_message_type.class.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -14,48 +14,48 @@
 block discarded – undo
14 14
 class EE_Registration_message_type extends EE_Registration_Base_message_type
15 15
 {
16 16
 
17
-    public function __construct()
18
-    {
19
-        $this->name = 'registration';
20
-        $this->description = __('This message type is for messages sent to attendees when their registration is approved.', 'event_espresso');
21
-        $this->label = array(
22
-            'singular' => __('registration approved', 'event_espresso'),
23
-            'plural' => __('registrations approved', 'event_espresso')
24
-            );
17
+	public function __construct()
18
+	{
19
+		$this->name = 'registration';
20
+		$this->description = __('This message type is for messages sent to attendees when their registration is approved.', 'event_espresso');
21
+		$this->label = array(
22
+			'singular' => __('registration approved', 'event_espresso'),
23
+			'plural' => __('registrations approved', 'event_espresso')
24
+			);
25 25
 
26
-        parent::__construct();
27
-    }
26
+		parent::__construct();
27
+	}
28 28
 
29 29
 
30 30
 
31
-    /**
32
-     * _set_contexts
33
-     * This sets up the contexts associated with the message_type
34
-     *
35
-     * @access  protected
36
-     * @return  void
37
-     */
38
-    protected function _set_contexts()
39
-    {
40
-        $this->_context_label = array(
41
-            'label' => __('recipient', 'event_espresso'),
42
-            'plural' => __('recipients', 'event_espresso'),
43
-            'description' => __('Recipient\'s are who will receive the template.  You may want different registration details sent out depending on who the recipient is', 'event_espresso')
44
-            );
31
+	/**
32
+	 * _set_contexts
33
+	 * This sets up the contexts associated with the message_type
34
+	 *
35
+	 * @access  protected
36
+	 * @return  void
37
+	 */
38
+	protected function _set_contexts()
39
+	{
40
+		$this->_context_label = array(
41
+			'label' => __('recipient', 'event_espresso'),
42
+			'plural' => __('recipients', 'event_espresso'),
43
+			'description' => __('Recipient\'s are who will receive the template.  You may want different registration details sent out depending on who the recipient is', 'event_espresso')
44
+			);
45 45
 
46
-        $this->_contexts = array(
47
-            'admin' => array(
48
-                'label' => __('Event Admin', 'event_espresso'),
49
-                'description' => __('This template is what event administrators will receive with an approved registration', 'event_espresso')
50
-                ),
51
-            'primary_attendee' => array(
52
-                'label' => __('Primary Registrant', 'event_espresso'),
53
-                'description' => __('This template is what the primary registrant (the person who completed the initial transaction) will receive with approved registration', 'event_espresso')
54
-                ),
55
-            'attendee' => array(
56
-                'label' => __('Registrant', 'event_espresso'),
57
-                'description' => __('This template is what each registrant for the event will receive when their registration is approved.', 'event_espresso')
58
-                )
59
-            );
60
-    }
46
+		$this->_contexts = array(
47
+			'admin' => array(
48
+				'label' => __('Event Admin', 'event_espresso'),
49
+				'description' => __('This template is what event administrators will receive with an approved registration', 'event_espresso')
50
+				),
51
+			'primary_attendee' => array(
52
+				'label' => __('Primary Registrant', 'event_espresso'),
53
+				'description' => __('This template is what the primary registrant (the person who completed the initial transaction) will receive with approved registration', 'event_espresso')
54
+				),
55
+			'attendee' => array(
56
+				'label' => __('Registrant', 'event_espresso'),
57
+				'description' => __('This template is what each registrant for the event will receive when their registration is approved.', 'event_espresso')
58
+				)
59
+			);
60
+	}
61 61
 }
Please login to merge, or discard this patch.