Completed
Branch FET/custom-qr-code-requirement... (1b6fa1)
by
unknown
12:38 queued 10:55
created
validators/email/EE_Messages_Email_Registration_Validator.class.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    public function __construct($fields, $context)
19
-    {
20
-        $this->_m_name = 'email';
21
-        $this->_mt_name = 'registration';
18
+	public function __construct($fields, $context)
19
+	{
20
+		$this->_m_name = 'email';
21
+		$this->_mt_name = 'registration';
22 22
 
23
-        parent::__construct($fields, $context);
24
-    }
23
+		parent::__construct($fields, $context);
24
+	}
25 25
 
26
-    /**
27
-     * custom validator (restricting what was originally set by the messenger)
28
-     */
29
-    protected function _modify_validator()
30
-    {
31
-        $new_config = $this->_messenger->get_validator_config();
32
-        // modify just event_list
33
-        $new_config['event_list'] = array(
34
-            'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list'),
35
-            'required' => array('[EVENT_LIST]')
36
-            );
37
-        $this->_messenger->set_validator_config($new_config);
26
+	/**
27
+	 * custom validator (restricting what was originally set by the messenger)
28
+	 */
29
+	protected function _modify_validator()
30
+	{
31
+		$new_config = $this->_messenger->get_validator_config();
32
+		// modify just event_list
33
+		$new_config['event_list'] = array(
34
+			'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list'),
35
+			'required' => array('[EVENT_LIST]')
36
+			);
37
+		$this->_messenger->set_validator_config($new_config);
38 38
 
39
-        if ($this->_context != 'admin') {
40
-            $this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
41
-        }
39
+		if ($this->_context != 'admin') {
40
+			$this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
41
+		}
42 42
 
43
-        $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
44
-    }
43
+		$this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
44
+	}
45 45
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
         $this->_messenger->set_validator_config($new_config);
39 39
 
40 40
         if ($this->_context != 'admin') {
41
-            $this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
41
+            $this->_valid_shortcodes_modifier[$this->_context]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
42 42
         }
43 43
 
44 44
         $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
Please login to merge, or discard this patch.
email/EE_Messages_Email_Not_Approved_Registration_Validator.class.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    public function __construct($fields, $context)
19
-    {
20
-        $this->_m_name = 'email';
21
-        $this->_mt_name = 'not_approved_registration';
18
+	public function __construct($fields, $context)
19
+	{
20
+		$this->_m_name = 'email';
21
+		$this->_mt_name = 'not_approved_registration';
22 22
 
23
-        parent::__construct($fields, $context);
24
-    }
23
+		parent::__construct($fields, $context);
24
+	}
25 25
 
26
-    /**
27
-     * custom validator (restricting what was originally set by the messenger)
28
-     */
29
-    protected function _modify_validator()
30
-    {
31
-        $new_config = $this->_messenger->get_validator_config();
32
-        $new_config['event_list'] = array(
33
-            'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list'),
34
-            'required' => array('[EVENT_LIST]')
35
-            );
36
-        $this->_messenger->set_validator_config($new_config);
26
+	/**
27
+	 * custom validator (restricting what was originally set by the messenger)
28
+	 */
29
+	protected function _modify_validator()
30
+	{
31
+		$new_config = $this->_messenger->get_validator_config();
32
+		$new_config['event_list'] = array(
33
+			'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list'),
34
+			'required' => array('[EVENT_LIST]')
35
+			);
36
+		$this->_messenger->set_validator_config($new_config);
37 37
 
38
-        if ($this->_context != 'admin') {
39
-            $this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
40
-        }
38
+		if ($this->_context != 'admin') {
39
+			$this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
40
+		}
41 41
 
42
-        $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
43
-    }
42
+		$this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
         $this->_messenger->set_validator_config($new_config);
39 39
 
40 40
         if ($this->_context != 'admin') {
41
-            $this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
41
+            $this->_valid_shortcodes_modifier[$this->_context]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
42 42
         }
43 43
 
44 44
         $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
Please login to merge, or discard this patch.
validators/email/EE_Messages_Email_Pending_Approval_Validator.class.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    public function __construct($fields, $context)
19
-    {
20
-        $this->_m_name = 'email';
21
-        $this->_mt_name = 'pending_approval';
18
+	public function __construct($fields, $context)
19
+	{
20
+		$this->_m_name = 'email';
21
+		$this->_mt_name = 'pending_approval';
22 22
 
23
-        parent::__construct($fields, $context);
24
-    }
23
+		parent::__construct($fields, $context);
24
+	}
25 25
 
26
-    /**
27
-     * custom validator (restricting what was originally set by the messenger)
28
-     */
29
-    protected function _modify_validator()
30
-    {
31
-        $new_config = $this->_messenger->get_validator_config();
32
-        // modify just event_list
33
-        $new_config['event_list'] = array(
34
-            'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list'),
35
-            'required' => array('[EVENT_LIST]')
36
-            );
37
-        $this->_messenger->set_validator_config($new_config);
26
+	/**
27
+	 * custom validator (restricting what was originally set by the messenger)
28
+	 */
29
+	protected function _modify_validator()
30
+	{
31
+		$new_config = $this->_messenger->get_validator_config();
32
+		// modify just event_list
33
+		$new_config['event_list'] = array(
34
+			'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list'),
35
+			'required' => array('[EVENT_LIST]')
36
+			);
37
+		$this->_messenger->set_validator_config($new_config);
38 38
 
39
-        if ($this->_context != 'admin') {
40
-            $this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
41
-        }
39
+		if ($this->_context != 'admin') {
40
+			$this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
41
+		}
42 42
 
43
-        $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
44
-    }
43
+		$this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
44
+	}
45 45
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
         $this->_messenger->set_validator_config($new_config);
39 39
 
40 40
         if ($this->_context != 'admin') {
41
-            $this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
41
+            $this->_valid_shortcodes_modifier[$this->_context]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
42 42
         }
43 43
 
44 44
         $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
Please login to merge, or discard this patch.
messages/validators/email/EE_Messages_Email_Payment_Validator.class.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -15,37 +15,37 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    public function __construct($fields, $context)
19
-    {
20
-        $this->_m_name = 'email';
21
-        $this->_mt_name = 'payment';
22
-
23
-        parent::__construct($fields, $context);
24
-    }
25
-
26
-    /**
27
-     * at this point no custom validation needed for this messenger/message_type combo.
28
-     */
29
-    protected function _modify_validator()
30
-    {
31
-        $new_config = $this->_messenger->get_validator_config();
32
-
33
-        // modify just event_list
34
-        $new_config['event_list'] = array(
35
-            'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization','recipient_details', 'recipient_list', 'event_author', 'primary_registration_details', 'primary_registration_list')
36
-            );
37
-        $new_config['ticket_list'] = array(
38
-            'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'recipient_details', 'transaction')
39
-            );
40
-        $new_config['content'] = array(
41
-            'shortcodes' => array('event_list','attendee_list', 'ticket_list', 'organization', 'recipient_details', 'recipient_list', 'transaction', 'primary_registration_details', 'primary_registration_list', 'messenger')
42
-            );
43
-        $this->_messenger->set_validator_config($new_config);
44
-
45
-        if ($this->_context != 'admin') {
46
-            $this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
47
-        }
48
-
49
-        $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
50
-    }
18
+	public function __construct($fields, $context)
19
+	{
20
+		$this->_m_name = 'email';
21
+		$this->_mt_name = 'payment';
22
+
23
+		parent::__construct($fields, $context);
24
+	}
25
+
26
+	/**
27
+	 * at this point no custom validation needed for this messenger/message_type combo.
28
+	 */
29
+	protected function _modify_validator()
30
+	{
31
+		$new_config = $this->_messenger->get_validator_config();
32
+
33
+		// modify just event_list
34
+		$new_config['event_list'] = array(
35
+			'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization','recipient_details', 'recipient_list', 'event_author', 'primary_registration_details', 'primary_registration_list')
36
+			);
37
+		$new_config['ticket_list'] = array(
38
+			'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'recipient_details', 'transaction')
39
+			);
40
+		$new_config['content'] = array(
41
+			'shortcodes' => array('event_list','attendee_list', 'ticket_list', 'organization', 'recipient_details', 'recipient_list', 'transaction', 'primary_registration_details', 'primary_registration_list', 'messenger')
42
+			);
43
+		$this->_messenger->set_validator_config($new_config);
44
+
45
+		if ($this->_context != 'admin') {
46
+			$this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
47
+		}
48
+
49
+		$this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
50
+	}
51 51
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,18 +32,18 @@
 block discarded – undo
32 32
 
33 33
         // modify just event_list
34 34
         $new_config['event_list'] = array(
35
-            'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization','recipient_details', 'recipient_list', 'event_author', 'primary_registration_details', 'primary_registration_list')
35
+            'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'recipient_details', 'recipient_list', 'event_author', 'primary_registration_details', 'primary_registration_list')
36 36
             );
37 37
         $new_config['ticket_list'] = array(
38 38
             'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'recipient_details', 'transaction')
39 39
             );
40 40
         $new_config['content'] = array(
41
-            'shortcodes' => array('event_list','attendee_list', 'ticket_list', 'organization', 'recipient_details', 'recipient_list', 'transaction', 'primary_registration_details', 'primary_registration_list', 'messenger')
41
+            'shortcodes' => array('event_list', 'attendee_list', 'ticket_list', 'organization', 'recipient_details', 'recipient_list', 'transaction', 'primary_registration_details', 'primary_registration_list', 'messenger')
42 42
             );
43 43
         $this->_messenger->set_validator_config($new_config);
44 44
 
45 45
         if ($this->_context != 'admin') {
46
-            $this->_valid_shortcodes_modifier[ $this->_context ]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
46
+            $this->_valid_shortcodes_modifier[$this->_context]['event_list'] = array('event', 'attendee_list', 'ticket_list', 'datetime_list', 'venue', 'organization', 'event_author', 'primary_registration_details', 'primary_registration_list', 'recipient_details', 'recipient_list');
47 47
         }
48 48
 
49 49
         $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]');
Please login to merge, or discard this patch.
core/libraries/messages/validators/EE_Messages_Validator.core.php 2 patches
Indentation   +622 added lines, -622 removed lines patch added patch discarded remove patch
@@ -18,626 +18,626 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * These properties just hold the name for the Messenger and Message Type (defined by child classes).
23
-     * These are used for retrieving objects etc.
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_m_name;
28
-    protected $_mt_name;
29
-
30
-
31
-    /**
32
-     * This will hold any error messages from the validation process.
33
-     * The _errors property holds an associative array of error messages
34
-     * listing the field as the key and the message as the value.
35
-     *
36
-     * @var array()
37
-     */
38
-    private $_errors = array();
39
-
40
-
41
-    /**
42
-     * holds an array of fields being validated
43
-     *
44
-     * @var array
45
-     */
46
-    protected $_fields;
47
-
48
-
49
-    /**
50
-     * this will hold the incoming context
51
-     *
52
-     * @var string
53
-     */
54
-    protected $_context;
55
-
56
-
57
-    /**
58
-     * this holds an array of fields and the relevant validation information
59
-     * that the incoming fields data get validated against.
60
-     * This gets setup in the _set_props() method.
61
-     *
62
-     * @var array
63
-     */
64
-    protected $_validators;
65
-
66
-
67
-    /**
68
-     * holds the messenger object
69
-     *
70
-     * @var object
71
-     */
72
-    protected $_messenger;
73
-
74
-
75
-    /**
76
-     * holds the message type object
77
-     *
78
-     * @var object
79
-     */
80
-    protected $_message_type;
81
-
82
-
83
-    /**
84
-     * will hold any valid_shortcode modifications made by the _modify_validator() method.
85
-     *
86
-     * @var array
87
-     */
88
-    protected $_valid_shortcodes_modifier;
89
-
90
-
91
-    /**
92
-     * There may be times where a message type wants to include a shortcode group but exclude specific
93
-     * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
94
-     * they will not be allowed.
95
-     * Array should be indexed by field and values are an array of specific shortcodes to exclude.
96
-     *
97
-     * @var array
98
-     */
99
-    protected $_specific_shortcode_excludes = array();
100
-
101
-
102
-    /**
103
-     * Runs the validator using the incoming fields array as the fields/values to check.
104
-     *
105
-     * @param array $fields The fields sent by the EEM object.
106
-     * @param       $context
107
-     * @throws EE_Error
108
-     * @throws ReflectionException
109
-     */
110
-    public function __construct($fields, $context)
111
-    {
112
-        // check that _m_name and _mt_name have been set by child class otherwise we get out.
113
-        if (empty($this->_m_name) || empty($this->_mt_name)) {
114
-            throw new EE_Error(
115
-                esc_html__(
116
-                    'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
117
-                    'event_espresso'
118
-                )
119
-            );
120
-        }
121
-        $this->_fields  = $fields;
122
-        $this->_context = $context;
123
-
124
-        // load messenger and message_type objects and the related shortcode objects.
125
-        $this->_load_objects();
126
-
127
-
128
-        // modify any messenger/message_type specific validation instructions.  This is what child classes define.
129
-        $this->_modify_validator();
130
-
131
-
132
-        // let's set validators property
133
-        $this->_set_validators();
134
-    }
135
-
136
-
137
-    /**
138
-     * Child classes instantiate this and use it to modify the _validator_config array property
139
-     * for the messenger using messengers set_validate_config() method.
140
-     * This is so we can specify specific validation instructions for a messenger/message_type combo
141
-     * that aren't handled by the defaults setup in the messenger.
142
-     *
143
-     * @abstract
144
-     * @access protected
145
-     * @return void
146
-     */
147
-    abstract protected function _modify_validator();
148
-
149
-
150
-    /**
151
-     * loads all objects used by validator
152
-     *
153
-     * @access private
154
-     * @throws \EE_Error
155
-     */
156
-    private function _load_objects()
157
-    {
158
-        // load messenger
159
-        $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
160
-        $messenger = str_replace(' ', '_', $messenger);
161
-        $messenger = 'EE_' . $messenger . '_messenger';
162
-
163
-        if (! class_exists($messenger)) {
164
-            throw new EE_Error(
165
-                sprintf(
166
-                    esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
167
-                    $this->_m_name
168
-                )
169
-            );
170
-        }
171
-
172
-        $this->_messenger = new $messenger();
173
-
174
-        // load message type
175
-        $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
176
-        $message_type = str_replace(' ', '_', $message_type);
177
-        $message_type = 'EE_' . $message_type . '_message_type';
178
-
179
-        if (! class_exists($message_type)) {
180
-            throw new EE_Error(
181
-                sprintf(
182
-                    esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
183
-                    $this->_mt_name
184
-                )
185
-            );
186
-        }
187
-
188
-        $this->_message_type = new $message_type();
189
-    }
190
-
191
-
192
-    /**
193
-     * used to set the $_validators property
194
-     *
195
-     * @access private
196
-     * @return void
197
-     * @throws ReflectionException
198
-     */
199
-    private function _set_validators()
200
-    {
201
-        // let's get all valid shortcodes from mt and message type
202
-        // (messenger will have its set in the _validator_config property for the messenger)
203
-        $mt_codes = $this->_message_type->get_valid_shortcodes();
204
-
205
-
206
-        // get messenger validator_config
207
-        $msgr_validator = $this->_messenger->get_validator_config();
208
-
209
-
210
-        // we only want the valid shortcodes for the given context!
211
-        $context  = $this->_context;
212
-        $mt_codes = $mt_codes[ $context ];
213
-
214
-        // in this first loop we're just getting all shortcode group indexes from the msgr_validator
215
-        // into a single array (so we can get the appropriate shortcode objects for the groups)
216
-        $shortcode_groups = $mt_codes;
217
-        $groups_per_field = array();
218
-
219
-        foreach ($msgr_validator as $field => $config) {
220
-            if (empty($config) || ! isset($config['shortcodes'])) {
221
-                continue;
222
-            }  //Nothing to see here.
223
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
224
-            $shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
225
-        }
226
-
227
-        $shortcode_groups = array_unique($shortcode_groups);
228
-
229
-        // okay now we've got our groups.
230
-        // Let's get the codes from the objects into an array indexed by group for easy retrieval later.
231
-        $codes_from_objs = array();
232
-
233
-        foreach ($shortcode_groups as $group) {
234
-            $ref       = ucwords(str_replace('_', ' ', $group));
235
-            $ref       = str_replace(' ', '_', $ref);
236
-            $classname = 'EE_' . $ref . '_Shortcodes';
237
-            if (class_exists($classname)) {
238
-                $a                       = new ReflectionClass($classname);
239
-                $obj                     = $a->newInstance();
240
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
241
-            }
242
-        }
243
-
244
-
245
-        // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
246
-        $final_mt_codes = array();
247
-        foreach ($mt_codes as $group) {
248
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
249
-        }
250
-
251
-        $mt_codes = $final_mt_codes;
252
-
253
-
254
-        // k now in this next loop we're going to loop through $msgr_validator again
255
-        // and setup the _validators property from the data we've setup so far.
256
-        foreach ($msgr_validator as $field => $config) {
257
-            // if required shortcode is not in our list of codes for the given field, then we skip this field.
258
-            $required = isset($config['required'])
259
-                ? array_intersect($config['required'], array_keys($mt_codes))
260
-                : true;
261
-            if (empty($required)) {
262
-                continue;
263
-            }
264
-
265
-            // If we have an override then we use it to indicate the codes we want.
266
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
267
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
268
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
269
-                    $codes_from_objs
270
-                );
271
-            } //if we have specific shortcodes for a field then we need to use them
272
-            elseif (isset($groups_per_field[ $field ])) {
273
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
274
-                    $groups_per_field[ $field ],
275
-                    $codes_from_objs
276
-                );
277
-            } //if empty config then we're assuming we're just going to use the shortcodes from the message type context
278
-            elseif (empty($config)) {
279
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
280
-            } //if we have specific shortcodes then we need to use them
281
-            elseif (isset($config['specific_shortcodes'])) {
282
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
283
-            } //otherwise the shortcodes are what is set by the messenger for that field
284
-            else {
285
-                foreach ($config['shortcodes'] as $group) {
286
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
-                        : $codes_from_objs[ $group ];
289
-                }
290
-            }
291
-
292
-            // now let's just make sure that any excluded specific shortcodes are removed.
293
-            $specific_excludes = $this->get_specific_shortcode_excludes();
294
-            if (isset($specific_excludes[ $field ])) {
295
-                foreach ($specific_excludes[ $field ] as $sex) {
296
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
298
-                    }
299
-                }
300
-            }
301
-
302
-            // hey! don't forget to include the type if present!
303
-            $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
304
-        }
305
-    }
306
-
307
-
308
-    /**
309
-     * This just returns the validators property that contains information
310
-     * about the various shortcodes and their availability with each field
311
-     *
312
-     * @return array
313
-     */
314
-    public function get_validators()
315
-    {
316
-        return $this->_validators;
317
-    }
318
-
319
-
320
-    /**
321
-     * This simply returns the specific shortcode_excludes property that is set.
322
-     *
323
-     * @since 4.5.0
324
-     * @return array
325
-     */
326
-    public function get_specific_shortcode_excludes()
327
-    {
328
-        // specific validator filter
329
-        $shortcode_excludes = apply_filters(
330
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
331
-            $this->_specific_shortcode_excludes,
332
-            $this->_context
333
-        );
334
-        // global filter
335
-        return apply_filters(
336
-            'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
337
-            $shortcode_excludes,
338
-            $this->_context,
339
-            $this
340
-        );
341
-    }
342
-
343
-
344
-    /**
345
-     * This is the main method that handles validation
346
-     * What it does is loop through the _fields (the ones that get validated)
347
-     * and checks them against the shortcodes array for the field and the 'type' indicated by the
348
-     *
349
-     * @access public
350
-     * @return mixed (bool|array)  if errors present we return the array otherwise true
351
-     */
352
-    public function validate()
353
-    {
354
-        // some defaults
355
-        $template_fields = $this->_messenger->get_template_fields();
356
-        // loop through the fields and check!
357
-        foreach ($this->_fields as $field => $value) {
358
-            $this->_errors[ $field ] = array();
359
-            $err_msg               = '';
360
-            $field_label           = '';
361
-            // if field is not present in the _validators array then we continue
362
-            if (! isset($this->_validators[ $field ])) {
363
-                unset($this->_errors[ $field ]);
364
-                continue;
365
-            }
366
-
367
-            // get the translated field label!
368
-            // first check if it's in the main fields list
369
-            if (isset($template_fields[ $field ])) {
370
-                if (empty($template_fields[ $field ])) {
371
-                    $field_label = $field;
372
-                } //most likely the field is found in the 'extra' array.
373
-                else {
374
-                    $field_label = $template_fields[ $field ]['label'];
375
-                }
376
-            }
377
-
378
-            // if field label is empty OR is equal to the current field
379
-            // then we need to loop through the 'extra' fields in the template_fields config (if present)
380
-            if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
381
-                foreach ($template_fields['extra'] as $main_field => $secondary_field) {
382
-                    foreach ($secondary_field as $name => $values) {
383
-                        if ($name === $field) {
384
-                            $field_label = $values['label'];
385
-                        }
386
-
387
-                        // if we've got a 'main' secondary field, let's see if that matches what field we're on
388
-                        // which means it contains the label for this field.
389
-                        if ($name === 'main' && $main_field === $field_label) {
390
-                            $field_label = $values['label'];
391
-                        }
392
-                    }
393
-                }
394
-            }
395
-
396
-            // field is present. Let's validate shortcodes first (but only if shortcodes present).
397
-            if (isset($this->_validators[ $field ]['shortcodes'])
398
-                && ! empty($this->_validators[ $field ]['shortcodes'])
399
-            ) {
400
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
401
-                // if true then that means there is a returned error message
402
-                // that we'll need to add to the _errors array for this field.
403
-                if ($invalid_shortcodes) {
404
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
405
-                    $err_msg = sprintf(
406
-                        esc_html__(
407
-                            '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
408
-                            'event_espresso'
409
-                        ),
410
-                        '<strong>' . $field_label . '</strong>',
411
-                        $invalid_shortcodes,
412
-                        '<p>',
413
-                        '</p >'
414
-                    );
415
-                    $err_msg .= sprintf(
416
-                        esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
417
-                        implode(', ', $v_s),
418
-                        '<strong>',
419
-                        '</strong>'
420
-                    );
421
-                }
422
-            }
423
-
424
-            // if there's a "type" to be validated then let's do that too.
425
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
426
-                switch ($this->_validators[ $field ]['type']) {
427
-                    case 'number':
428
-                        if (! is_numeric($value)) {
429
-                            $err_msg .= sprintf(
430
-                                esc_html__(
431
-                                    '%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
432
-                                    'event_espresso'
433
-                                ),
434
-                                $field_label,
435
-                                $value,
436
-                                '<p>',
437
-                                '</p >'
438
-                            );
439
-                        }
440
-                        break;
441
-                    case 'email':
442
-                        $valid_email = $this->_validate_email($value);
443
-                        if (! $valid_email) {
444
-                            $err_msg .= htmlentities(
445
-                                sprintf(
446
-                                    esc_html__(
447
-                                        'The %1$s field has at least one string that is not a valid email address record.  Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.',
448
-                                        'event_espresso'
449
-                                    ),
450
-                                    $field_label
451
-                                )
452
-                            );
453
-                        }
454
-                        break;
455
-                    default:
456
-                        break;
457
-                }
458
-            }
459
-
460
-            // if $err_msg isn't empty let's setup the _errors array for this field.
461
-            if (! empty($err_msg)) {
462
-                $this->_errors[ $field ]['msg'] = $err_msg;
463
-            } else {
464
-                unset($this->_errors[ $field ]);
465
-            }
466
-        }
467
-
468
-        // if we have ANY errors, then we want to make sure we return the values
469
-        // for ALL the fields so the user doesn't have to retype them all.
470
-        if (! empty($this->_errors)) {
471
-            foreach ($this->_fields as $field => $value) {
472
-                $this->_errors[ $field ]['value'] = stripslashes($value);
473
-            }
474
-        }
475
-
476
-        // return any errors or just TRUE if everything validates
477
-        return empty($this->_errors) ? true : $this->_errors;
478
-    }
479
-
480
-
481
-    /**
482
-     * Reassembles and returns an array of valid shortcodes
483
-     * given the array of groups and array of shortcodes indexed by group.
484
-     *
485
-     * @param  array $groups          array of shortcode groups that we want shortcodes for
486
-     * @param  array $codes_from_objs All the codes available.
487
-     * @return array                   an array of actual shortcodes (that will be used for validation).
488
-     */
489
-    private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
490
-    {
491
-        $shortcodes = array();
492
-        foreach ($groups as $group) {
493
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
494
-        }
495
-        return $shortcodes;
496
-    }
497
-
498
-
499
-    /**
500
-     * Validates a string against a list of accepted shortcodes
501
-     * This function takes in an array of shortcodes
502
-     * and makes sure that the given string ONLY contains shortcodes in that array.
503
-     *
504
-     * @param  string $value            string to evaluate
505
-     * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
506
-     * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
507
-     */
508
-    protected function _invalid_shortcodes($value, $valid_shortcodes)
509
-    {
510
-        // first we need to go through the string and get the shortcodes in the string
511
-        preg_match_all('/(\[.+?\])/', $value, $matches);
512
-        $incoming_shortcodes = (array) $matches[0];
513
-
514
-        // get a diff of the shortcodes in the string vs the valid shortcodes
515
-        $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
516
-
517
-        // we need to account for custom codes so let's loop through the diff and remove any of those type of codes
518
-        foreach ($diff as $ind => $code) {
519
-            if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
520
-                // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
521
-                $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
522
-                // does this exist in the $valid_shortcodes?  If so then unset.
523
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
524
-                    unset($diff[ $ind ]);
525
-                }
526
-            }
527
-        }
528
-
529
-        if (empty($diff)) {
530
-            return false;
531
-        } //there is no diff, we have no invalid shortcodes, so return
532
-
533
-        // made it here? then let's assemble the error message
534
-        $invalid_shortcodes = implode('</strong>,<strong>', $diff);
535
-        $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
536
-        return $invalid_shortcodes;
537
-    }
538
-
539
-
540
-    /**
541
-     * Validates an incoming string and makes sure we have valid emails in the string.
542
-     *
543
-     * @param  string $value incoming value to validate
544
-     * @return bool        true if the string validates, false if it doesn't
545
-     */
546
-    protected function _validate_email($value)
547
-    {
548
-        $validate = true;
549
-        $or_val   = $value;
550
-
551
-        // empty strings will validate because this is how a message template
552
-        // for a particular context can be "turned off" (if there is no email then no message)
553
-        if (empty($value)) {
554
-            return $validate;
555
-        }
556
-
557
-        // first determine if there ARE any shortcodes.
558
-        // If there are shortcodes and then later we find that there were no other valid emails
559
-        // but the field isn't empty...
560
-        // that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
561
-        $has_shortcodes = preg_match('/(\[.+?\])/', $value);
562
-
563
-        // first we need to strip out all the shortcodes!
564
-        $value = preg_replace('/(\[.+?\])/', '', $value);
565
-
566
-        // if original value is not empty and new value is, then we've parsed out a shortcode
567
-        // and we now have an empty string which DOES validate.
568
-        // We also validate complete empty field for email because
569
-        // its possible that this message is being "turned off" for a particular context
570
-
571
-
572
-        if (! empty($or_val) && empty($value)) {
573
-            return $validate;
574
-        }
575
-
576
-        // trim any commas from beginning and end of string ( after whitespace trimmed );
577
-        $value = trim(trim($value), ',');
578
-
579
-
580
-        // next we need to split up the string if its comma delimited.
581
-        $emails = explode(',', $value);
582
-        $empty  = false; // used to indicate that there is an empty comma.
583
-        // now let's loop through the emails and do our checks
584
-        foreach ($emails as $email) {
585
-            if (empty($email)) {
586
-                $empty = true;
587
-                continue;
588
-            }
589
-
590
-            // trim whitespace
591
-            $email = trim($email);
592
-            // either its of type "[email protected]", or its of type "fname lname <[email protected]>"
593
-            if (is_email($email)) {
594
-                continue;
595
-            }
596
-            $matches  = array();
597
-            $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false;
598
-            if ($validate && is_email($matches[2])) {
599
-                continue;
600
-            }
601
-            return false;
602
-        }
603
-
604
-        $validate = $empty && ! $has_shortcodes ? false : $validate;
605
-
606
-        return $validate;
607
-    }
608
-
609
-
610
-    /**
611
-     * Magic getter
612
-     * Using this to provide back compat with add-ons referencing deprecated properties.
613
-     *
614
-     * @param string $property Property being requested
615
-     * @throws Exception
616
-     * @return mixed
617
-     */
618
-    public function __get($property)
619
-    {
620
-        $expected_properties_map = array(
621
-            /**
622
-             * @deprecated 4.9.0
623
-             */
624
-            '_MSGR'   => '_messenger',
625
-            /**
626
-             * @deprecated 4.9.0
627
-             */
628
-            '_MSGTYP' => '_message_type',
629
-        );
630
-
631
-        if (isset($expected_properties_map[ $property ])) {
632
-            return $this->{$expected_properties_map[ $property ]};
633
-        }
634
-
635
-        throw new Exception(
636
-            sprintf(
637
-                esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
638
-                $property,
639
-                get_class($this)
640
-            )
641
-        );
642
-    }
21
+	/**
22
+	 * These properties just hold the name for the Messenger and Message Type (defined by child classes).
23
+	 * These are used for retrieving objects etc.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_m_name;
28
+	protected $_mt_name;
29
+
30
+
31
+	/**
32
+	 * This will hold any error messages from the validation process.
33
+	 * The _errors property holds an associative array of error messages
34
+	 * listing the field as the key and the message as the value.
35
+	 *
36
+	 * @var array()
37
+	 */
38
+	private $_errors = array();
39
+
40
+
41
+	/**
42
+	 * holds an array of fields being validated
43
+	 *
44
+	 * @var array
45
+	 */
46
+	protected $_fields;
47
+
48
+
49
+	/**
50
+	 * this will hold the incoming context
51
+	 *
52
+	 * @var string
53
+	 */
54
+	protected $_context;
55
+
56
+
57
+	/**
58
+	 * this holds an array of fields and the relevant validation information
59
+	 * that the incoming fields data get validated against.
60
+	 * This gets setup in the _set_props() method.
61
+	 *
62
+	 * @var array
63
+	 */
64
+	protected $_validators;
65
+
66
+
67
+	/**
68
+	 * holds the messenger object
69
+	 *
70
+	 * @var object
71
+	 */
72
+	protected $_messenger;
73
+
74
+
75
+	/**
76
+	 * holds the message type object
77
+	 *
78
+	 * @var object
79
+	 */
80
+	protected $_message_type;
81
+
82
+
83
+	/**
84
+	 * will hold any valid_shortcode modifications made by the _modify_validator() method.
85
+	 *
86
+	 * @var array
87
+	 */
88
+	protected $_valid_shortcodes_modifier;
89
+
90
+
91
+	/**
92
+	 * There may be times where a message type wants to include a shortcode group but exclude specific
93
+	 * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
94
+	 * they will not be allowed.
95
+	 * Array should be indexed by field and values are an array of specific shortcodes to exclude.
96
+	 *
97
+	 * @var array
98
+	 */
99
+	protected $_specific_shortcode_excludes = array();
100
+
101
+
102
+	/**
103
+	 * Runs the validator using the incoming fields array as the fields/values to check.
104
+	 *
105
+	 * @param array $fields The fields sent by the EEM object.
106
+	 * @param       $context
107
+	 * @throws EE_Error
108
+	 * @throws ReflectionException
109
+	 */
110
+	public function __construct($fields, $context)
111
+	{
112
+		// check that _m_name and _mt_name have been set by child class otherwise we get out.
113
+		if (empty($this->_m_name) || empty($this->_mt_name)) {
114
+			throw new EE_Error(
115
+				esc_html__(
116
+					'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
117
+					'event_espresso'
118
+				)
119
+			);
120
+		}
121
+		$this->_fields  = $fields;
122
+		$this->_context = $context;
123
+
124
+		// load messenger and message_type objects and the related shortcode objects.
125
+		$this->_load_objects();
126
+
127
+
128
+		// modify any messenger/message_type specific validation instructions.  This is what child classes define.
129
+		$this->_modify_validator();
130
+
131
+
132
+		// let's set validators property
133
+		$this->_set_validators();
134
+	}
135
+
136
+
137
+	/**
138
+	 * Child classes instantiate this and use it to modify the _validator_config array property
139
+	 * for the messenger using messengers set_validate_config() method.
140
+	 * This is so we can specify specific validation instructions for a messenger/message_type combo
141
+	 * that aren't handled by the defaults setup in the messenger.
142
+	 *
143
+	 * @abstract
144
+	 * @access protected
145
+	 * @return void
146
+	 */
147
+	abstract protected function _modify_validator();
148
+
149
+
150
+	/**
151
+	 * loads all objects used by validator
152
+	 *
153
+	 * @access private
154
+	 * @throws \EE_Error
155
+	 */
156
+	private function _load_objects()
157
+	{
158
+		// load messenger
159
+		$messenger = ucwords(str_replace('_', ' ', $this->_m_name));
160
+		$messenger = str_replace(' ', '_', $messenger);
161
+		$messenger = 'EE_' . $messenger . '_messenger';
162
+
163
+		if (! class_exists($messenger)) {
164
+			throw new EE_Error(
165
+				sprintf(
166
+					esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
167
+					$this->_m_name
168
+				)
169
+			);
170
+		}
171
+
172
+		$this->_messenger = new $messenger();
173
+
174
+		// load message type
175
+		$message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
176
+		$message_type = str_replace(' ', '_', $message_type);
177
+		$message_type = 'EE_' . $message_type . '_message_type';
178
+
179
+		if (! class_exists($message_type)) {
180
+			throw new EE_Error(
181
+				sprintf(
182
+					esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
183
+					$this->_mt_name
184
+				)
185
+			);
186
+		}
187
+
188
+		$this->_message_type = new $message_type();
189
+	}
190
+
191
+
192
+	/**
193
+	 * used to set the $_validators property
194
+	 *
195
+	 * @access private
196
+	 * @return void
197
+	 * @throws ReflectionException
198
+	 */
199
+	private function _set_validators()
200
+	{
201
+		// let's get all valid shortcodes from mt and message type
202
+		// (messenger will have its set in the _validator_config property for the messenger)
203
+		$mt_codes = $this->_message_type->get_valid_shortcodes();
204
+
205
+
206
+		// get messenger validator_config
207
+		$msgr_validator = $this->_messenger->get_validator_config();
208
+
209
+
210
+		// we only want the valid shortcodes for the given context!
211
+		$context  = $this->_context;
212
+		$mt_codes = $mt_codes[ $context ];
213
+
214
+		// in this first loop we're just getting all shortcode group indexes from the msgr_validator
215
+		// into a single array (so we can get the appropriate shortcode objects for the groups)
216
+		$shortcode_groups = $mt_codes;
217
+		$groups_per_field = array();
218
+
219
+		foreach ($msgr_validator as $field => $config) {
220
+			if (empty($config) || ! isset($config['shortcodes'])) {
221
+				continue;
222
+			}  //Nothing to see here.
223
+			$groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
224
+			$shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
225
+		}
226
+
227
+		$shortcode_groups = array_unique($shortcode_groups);
228
+
229
+		// okay now we've got our groups.
230
+		// Let's get the codes from the objects into an array indexed by group for easy retrieval later.
231
+		$codes_from_objs = array();
232
+
233
+		foreach ($shortcode_groups as $group) {
234
+			$ref       = ucwords(str_replace('_', ' ', $group));
235
+			$ref       = str_replace(' ', '_', $ref);
236
+			$classname = 'EE_' . $ref . '_Shortcodes';
237
+			if (class_exists($classname)) {
238
+				$a                       = new ReflectionClass($classname);
239
+				$obj                     = $a->newInstance();
240
+				$codes_from_objs[ $group ] = $obj->get_shortcodes();
241
+			}
242
+		}
243
+
244
+
245
+		// let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
246
+		$final_mt_codes = array();
247
+		foreach ($mt_codes as $group) {
248
+			$final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
249
+		}
250
+
251
+		$mt_codes = $final_mt_codes;
252
+
253
+
254
+		// k now in this next loop we're going to loop through $msgr_validator again
255
+		// and setup the _validators property from the data we've setup so far.
256
+		foreach ($msgr_validator as $field => $config) {
257
+			// if required shortcode is not in our list of codes for the given field, then we skip this field.
258
+			$required = isset($config['required'])
259
+				? array_intersect($config['required'], array_keys($mt_codes))
260
+				: true;
261
+			if (empty($required)) {
262
+				continue;
263
+			}
264
+
265
+			// If we have an override then we use it to indicate the codes we want.
266
+			if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
267
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
268
+					$this->_valid_shortcodes_modifier[ $context ][ $field ],
269
+					$codes_from_objs
270
+				);
271
+			} //if we have specific shortcodes for a field then we need to use them
272
+			elseif (isset($groups_per_field[ $field ])) {
273
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
274
+					$groups_per_field[ $field ],
275
+					$codes_from_objs
276
+				);
277
+			} //if empty config then we're assuming we're just going to use the shortcodes from the message type context
278
+			elseif (empty($config)) {
279
+				$this->_validators[ $field ]['shortcodes'] = $mt_codes;
280
+			} //if we have specific shortcodes then we need to use them
281
+			elseif (isset($config['specific_shortcodes'])) {
282
+				$this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
283
+			} //otherwise the shortcodes are what is set by the messenger for that field
284
+			else {
285
+				foreach ($config['shortcodes'] as $group) {
286
+					$this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
+						? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
+						: $codes_from_objs[ $group ];
289
+				}
290
+			}
291
+
292
+			// now let's just make sure that any excluded specific shortcodes are removed.
293
+			$specific_excludes = $this->get_specific_shortcode_excludes();
294
+			if (isset($specific_excludes[ $field ])) {
295
+				foreach ($specific_excludes[ $field ] as $sex) {
296
+					if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
+						unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
298
+					}
299
+				}
300
+			}
301
+
302
+			// hey! don't forget to include the type if present!
303
+			$this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
304
+		}
305
+	}
306
+
307
+
308
+	/**
309
+	 * This just returns the validators property that contains information
310
+	 * about the various shortcodes and their availability with each field
311
+	 *
312
+	 * @return array
313
+	 */
314
+	public function get_validators()
315
+	{
316
+		return $this->_validators;
317
+	}
318
+
319
+
320
+	/**
321
+	 * This simply returns the specific shortcode_excludes property that is set.
322
+	 *
323
+	 * @since 4.5.0
324
+	 * @return array
325
+	 */
326
+	public function get_specific_shortcode_excludes()
327
+	{
328
+		// specific validator filter
329
+		$shortcode_excludes = apply_filters(
330
+			'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
331
+			$this->_specific_shortcode_excludes,
332
+			$this->_context
333
+		);
334
+		// global filter
335
+		return apply_filters(
336
+			'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
337
+			$shortcode_excludes,
338
+			$this->_context,
339
+			$this
340
+		);
341
+	}
342
+
343
+
344
+	/**
345
+	 * This is the main method that handles validation
346
+	 * What it does is loop through the _fields (the ones that get validated)
347
+	 * and checks them against the shortcodes array for the field and the 'type' indicated by the
348
+	 *
349
+	 * @access public
350
+	 * @return mixed (bool|array)  if errors present we return the array otherwise true
351
+	 */
352
+	public function validate()
353
+	{
354
+		// some defaults
355
+		$template_fields = $this->_messenger->get_template_fields();
356
+		// loop through the fields and check!
357
+		foreach ($this->_fields as $field => $value) {
358
+			$this->_errors[ $field ] = array();
359
+			$err_msg               = '';
360
+			$field_label           = '';
361
+			// if field is not present in the _validators array then we continue
362
+			if (! isset($this->_validators[ $field ])) {
363
+				unset($this->_errors[ $field ]);
364
+				continue;
365
+			}
366
+
367
+			// get the translated field label!
368
+			// first check if it's in the main fields list
369
+			if (isset($template_fields[ $field ])) {
370
+				if (empty($template_fields[ $field ])) {
371
+					$field_label = $field;
372
+				} //most likely the field is found in the 'extra' array.
373
+				else {
374
+					$field_label = $template_fields[ $field ]['label'];
375
+				}
376
+			}
377
+
378
+			// if field label is empty OR is equal to the current field
379
+			// then we need to loop through the 'extra' fields in the template_fields config (if present)
380
+			if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
381
+				foreach ($template_fields['extra'] as $main_field => $secondary_field) {
382
+					foreach ($secondary_field as $name => $values) {
383
+						if ($name === $field) {
384
+							$field_label = $values['label'];
385
+						}
386
+
387
+						// if we've got a 'main' secondary field, let's see if that matches what field we're on
388
+						// which means it contains the label for this field.
389
+						if ($name === 'main' && $main_field === $field_label) {
390
+							$field_label = $values['label'];
391
+						}
392
+					}
393
+				}
394
+			}
395
+
396
+			// field is present. Let's validate shortcodes first (but only if shortcodes present).
397
+			if (isset($this->_validators[ $field ]['shortcodes'])
398
+				&& ! empty($this->_validators[ $field ]['shortcodes'])
399
+			) {
400
+				$invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
401
+				// if true then that means there is a returned error message
402
+				// that we'll need to add to the _errors array for this field.
403
+				if ($invalid_shortcodes) {
404
+					$v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
405
+					$err_msg = sprintf(
406
+						esc_html__(
407
+							'%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
408
+							'event_espresso'
409
+						),
410
+						'<strong>' . $field_label . '</strong>',
411
+						$invalid_shortcodes,
412
+						'<p>',
413
+						'</p >'
414
+					);
415
+					$err_msg .= sprintf(
416
+						esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
417
+						implode(', ', $v_s),
418
+						'<strong>',
419
+						'</strong>'
420
+					);
421
+				}
422
+			}
423
+
424
+			// if there's a "type" to be validated then let's do that too.
425
+			if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
426
+				switch ($this->_validators[ $field ]['type']) {
427
+					case 'number':
428
+						if (! is_numeric($value)) {
429
+							$err_msg .= sprintf(
430
+								esc_html__(
431
+									'%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
432
+									'event_espresso'
433
+								),
434
+								$field_label,
435
+								$value,
436
+								'<p>',
437
+								'</p >'
438
+							);
439
+						}
440
+						break;
441
+					case 'email':
442
+						$valid_email = $this->_validate_email($value);
443
+						if (! $valid_email) {
444
+							$err_msg .= htmlentities(
445
+								sprintf(
446
+									esc_html__(
447
+										'The %1$s field has at least one string that is not a valid email address record.  Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.',
448
+										'event_espresso'
449
+									),
450
+									$field_label
451
+								)
452
+							);
453
+						}
454
+						break;
455
+					default:
456
+						break;
457
+				}
458
+			}
459
+
460
+			// if $err_msg isn't empty let's setup the _errors array for this field.
461
+			if (! empty($err_msg)) {
462
+				$this->_errors[ $field ]['msg'] = $err_msg;
463
+			} else {
464
+				unset($this->_errors[ $field ]);
465
+			}
466
+		}
467
+
468
+		// if we have ANY errors, then we want to make sure we return the values
469
+		// for ALL the fields so the user doesn't have to retype them all.
470
+		if (! empty($this->_errors)) {
471
+			foreach ($this->_fields as $field => $value) {
472
+				$this->_errors[ $field ]['value'] = stripslashes($value);
473
+			}
474
+		}
475
+
476
+		// return any errors or just TRUE if everything validates
477
+		return empty($this->_errors) ? true : $this->_errors;
478
+	}
479
+
480
+
481
+	/**
482
+	 * Reassembles and returns an array of valid shortcodes
483
+	 * given the array of groups and array of shortcodes indexed by group.
484
+	 *
485
+	 * @param  array $groups          array of shortcode groups that we want shortcodes for
486
+	 * @param  array $codes_from_objs All the codes available.
487
+	 * @return array                   an array of actual shortcodes (that will be used for validation).
488
+	 */
489
+	private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
490
+	{
491
+		$shortcodes = array();
492
+		foreach ($groups as $group) {
493
+			$shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
494
+		}
495
+		return $shortcodes;
496
+	}
497
+
498
+
499
+	/**
500
+	 * Validates a string against a list of accepted shortcodes
501
+	 * This function takes in an array of shortcodes
502
+	 * and makes sure that the given string ONLY contains shortcodes in that array.
503
+	 *
504
+	 * @param  string $value            string to evaluate
505
+	 * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
506
+	 * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
507
+	 */
508
+	protected function _invalid_shortcodes($value, $valid_shortcodes)
509
+	{
510
+		// first we need to go through the string and get the shortcodes in the string
511
+		preg_match_all('/(\[.+?\])/', $value, $matches);
512
+		$incoming_shortcodes = (array) $matches[0];
513
+
514
+		// get a diff of the shortcodes in the string vs the valid shortcodes
515
+		$diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
516
+
517
+		// we need to account for custom codes so let's loop through the diff and remove any of those type of codes
518
+		foreach ($diff as $ind => $code) {
519
+			if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
520
+				// strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
521
+				$dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
522
+				// does this exist in the $valid_shortcodes?  If so then unset.
523
+				if (isset($valid_shortcodes[ $dynamic_sc ])) {
524
+					unset($diff[ $ind ]);
525
+				}
526
+			}
527
+		}
528
+
529
+		if (empty($diff)) {
530
+			return false;
531
+		} //there is no diff, we have no invalid shortcodes, so return
532
+
533
+		// made it here? then let's assemble the error message
534
+		$invalid_shortcodes = implode('</strong>,<strong>', $diff);
535
+		$invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
536
+		return $invalid_shortcodes;
537
+	}
538
+
539
+
540
+	/**
541
+	 * Validates an incoming string and makes sure we have valid emails in the string.
542
+	 *
543
+	 * @param  string $value incoming value to validate
544
+	 * @return bool        true if the string validates, false if it doesn't
545
+	 */
546
+	protected function _validate_email($value)
547
+	{
548
+		$validate = true;
549
+		$or_val   = $value;
550
+
551
+		// empty strings will validate because this is how a message template
552
+		// for a particular context can be "turned off" (if there is no email then no message)
553
+		if (empty($value)) {
554
+			return $validate;
555
+		}
556
+
557
+		// first determine if there ARE any shortcodes.
558
+		// If there are shortcodes and then later we find that there were no other valid emails
559
+		// but the field isn't empty...
560
+		// that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
561
+		$has_shortcodes = preg_match('/(\[.+?\])/', $value);
562
+
563
+		// first we need to strip out all the shortcodes!
564
+		$value = preg_replace('/(\[.+?\])/', '', $value);
565
+
566
+		// if original value is not empty and new value is, then we've parsed out a shortcode
567
+		// and we now have an empty string which DOES validate.
568
+		// We also validate complete empty field for email because
569
+		// its possible that this message is being "turned off" for a particular context
570
+
571
+
572
+		if (! empty($or_val) && empty($value)) {
573
+			return $validate;
574
+		}
575
+
576
+		// trim any commas from beginning and end of string ( after whitespace trimmed );
577
+		$value = trim(trim($value), ',');
578
+
579
+
580
+		// next we need to split up the string if its comma delimited.
581
+		$emails = explode(',', $value);
582
+		$empty  = false; // used to indicate that there is an empty comma.
583
+		// now let's loop through the emails and do our checks
584
+		foreach ($emails as $email) {
585
+			if (empty($email)) {
586
+				$empty = true;
587
+				continue;
588
+			}
589
+
590
+			// trim whitespace
591
+			$email = trim($email);
592
+			// either its of type "[email protected]", or its of type "fname lname <[email protected]>"
593
+			if (is_email($email)) {
594
+				continue;
595
+			}
596
+			$matches  = array();
597
+			$validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false;
598
+			if ($validate && is_email($matches[2])) {
599
+				continue;
600
+			}
601
+			return false;
602
+		}
603
+
604
+		$validate = $empty && ! $has_shortcodes ? false : $validate;
605
+
606
+		return $validate;
607
+	}
608
+
609
+
610
+	/**
611
+	 * Magic getter
612
+	 * Using this to provide back compat with add-ons referencing deprecated properties.
613
+	 *
614
+	 * @param string $property Property being requested
615
+	 * @throws Exception
616
+	 * @return mixed
617
+	 */
618
+	public function __get($property)
619
+	{
620
+		$expected_properties_map = array(
621
+			/**
622
+			 * @deprecated 4.9.0
623
+			 */
624
+			'_MSGR'   => '_messenger',
625
+			/**
626
+			 * @deprecated 4.9.0
627
+			 */
628
+			'_MSGTYP' => '_message_type',
629
+		);
630
+
631
+		if (isset($expected_properties_map[ $property ])) {
632
+			return $this->{$expected_properties_map[ $property ]};
633
+		}
634
+
635
+		throw new Exception(
636
+			sprintf(
637
+				esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
638
+				$property,
639
+				get_class($this)
640
+			)
641
+		);
642
+	}
643 643
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
         // load messenger
159 159
         $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
160 160
         $messenger = str_replace(' ', '_', $messenger);
161
-        $messenger = 'EE_' . $messenger . '_messenger';
161
+        $messenger = 'EE_'.$messenger.'_messenger';
162 162
 
163
-        if (! class_exists($messenger)) {
163
+        if ( ! class_exists($messenger)) {
164 164
             throw new EE_Error(
165 165
                 sprintf(
166 166
                     esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
         // load message type
175 175
         $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
176 176
         $message_type = str_replace(' ', '_', $message_type);
177
-        $message_type = 'EE_' . $message_type . '_message_type';
177
+        $message_type = 'EE_'.$message_type.'_message_type';
178 178
 
179
-        if (! class_exists($message_type)) {
179
+        if ( ! class_exists($message_type)) {
180 180
             throw new EE_Error(
181 181
                 sprintf(
182 182
                     esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
         // we only want the valid shortcodes for the given context!
211 211
         $context  = $this->_context;
212
-        $mt_codes = $mt_codes[ $context ];
212
+        $mt_codes = $mt_codes[$context];
213 213
 
214 214
         // in this first loop we're just getting all shortcode group indexes from the msgr_validator
215 215
         // into a single array (so we can get the appropriate shortcode objects for the groups)
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
             if (empty($config) || ! isset($config['shortcodes'])) {
221 221
                 continue;
222 222
             }  //Nothing to see here.
223
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
224
-            $shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
223
+            $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes);
224
+            $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups);
225 225
         }
226 226
 
227 227
         $shortcode_groups = array_unique($shortcode_groups);
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
         foreach ($shortcode_groups as $group) {
234 234
             $ref       = ucwords(str_replace('_', ' ', $group));
235 235
             $ref       = str_replace(' ', '_', $ref);
236
-            $classname = 'EE_' . $ref . '_Shortcodes';
236
+            $classname = 'EE_'.$ref.'_Shortcodes';
237 237
             if (class_exists($classname)) {
238 238
                 $a                       = new ReflectionClass($classname);
239 239
                 $obj                     = $a->newInstance();
240
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
240
+                $codes_from_objs[$group] = $obj->get_shortcodes();
241 241
             }
242 242
         }
243 243
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
         // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
246 246
         $final_mt_codes = array();
247 247
         foreach ($mt_codes as $group) {
248
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
248
+            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]);
249 249
         }
250 250
 
251 251
         $mt_codes = $final_mt_codes;
@@ -263,44 +263,44 @@  discard block
 block discarded – undo
263 263
             }
264 264
 
265 265
             // If we have an override then we use it to indicate the codes we want.
266
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
267
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
268
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
266
+            if (isset($this->_valid_shortcodes_modifier[$context][$field])) {
267
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
268
+                    $this->_valid_shortcodes_modifier[$context][$field],
269 269
                     $codes_from_objs
270 270
                 );
271 271
             } //if we have specific shortcodes for a field then we need to use them
272
-            elseif (isset($groups_per_field[ $field ])) {
273
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
274
-                    $groups_per_field[ $field ],
272
+            elseif (isset($groups_per_field[$field])) {
273
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
274
+                    $groups_per_field[$field],
275 275
                     $codes_from_objs
276 276
                 );
277 277
             } //if empty config then we're assuming we're just going to use the shortcodes from the message type context
278 278
             elseif (empty($config)) {
279
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
279
+                $this->_validators[$field]['shortcodes'] = $mt_codes;
280 280
             } //if we have specific shortcodes then we need to use them
281 281
             elseif (isset($config['specific_shortcodes'])) {
282
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
282
+                $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes'];
283 283
             } //otherwise the shortcodes are what is set by the messenger for that field
284 284
             else {
285 285
                 foreach ($config['shortcodes'] as $group) {
286
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
-                        : $codes_from_objs[ $group ];
286
+                    $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes'])
287
+                        ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group])
288
+                        : $codes_from_objs[$group];
289 289
                 }
290 290
             }
291 291
 
292 292
             // now let's just make sure that any excluded specific shortcodes are removed.
293 293
             $specific_excludes = $this->get_specific_shortcode_excludes();
294
-            if (isset($specific_excludes[ $field ])) {
295
-                foreach ($specific_excludes[ $field ] as $sex) {
296
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
294
+            if (isset($specific_excludes[$field])) {
295
+                foreach ($specific_excludes[$field] as $sex) {
296
+                    if (isset($this->_validators[$field]['shortcodes'][$sex])) {
297
+                        unset($this->_validators[$field]['shortcodes'][$sex]);
298 298
                     }
299 299
                 }
300 300
             }
301 301
 
302 302
             // hey! don't forget to include the type if present!
303
-            $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
303
+            $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : null;
304 304
         }
305 305
     }
306 306
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     {
328 328
         // specific validator filter
329 329
         $shortcode_excludes = apply_filters(
330
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
330
+            'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;',
331 331
             $this->_specific_shortcode_excludes,
332 332
             $this->_context
333 333
         );
@@ -355,23 +355,23 @@  discard block
 block discarded – undo
355 355
         $template_fields = $this->_messenger->get_template_fields();
356 356
         // loop through the fields and check!
357 357
         foreach ($this->_fields as $field => $value) {
358
-            $this->_errors[ $field ] = array();
358
+            $this->_errors[$field] = array();
359 359
             $err_msg               = '';
360 360
             $field_label           = '';
361 361
             // if field is not present in the _validators array then we continue
362
-            if (! isset($this->_validators[ $field ])) {
363
-                unset($this->_errors[ $field ]);
362
+            if ( ! isset($this->_validators[$field])) {
363
+                unset($this->_errors[$field]);
364 364
                 continue;
365 365
             }
366 366
 
367 367
             // get the translated field label!
368 368
             // first check if it's in the main fields list
369
-            if (isset($template_fields[ $field ])) {
370
-                if (empty($template_fields[ $field ])) {
369
+            if (isset($template_fields[$field])) {
370
+                if (empty($template_fields[$field])) {
371 371
                     $field_label = $field;
372 372
                 } //most likely the field is found in the 'extra' array.
373 373
                 else {
374
-                    $field_label = $template_fields[ $field ]['label'];
374
+                    $field_label = $template_fields[$field]['label'];
375 375
                 }
376 376
             }
377 377
 
@@ -394,20 +394,20 @@  discard block
 block discarded – undo
394 394
             }
395 395
 
396 396
             // field is present. Let's validate shortcodes first (but only if shortcodes present).
397
-            if (isset($this->_validators[ $field ]['shortcodes'])
398
-                && ! empty($this->_validators[ $field ]['shortcodes'])
397
+            if (isset($this->_validators[$field]['shortcodes'])
398
+                && ! empty($this->_validators[$field]['shortcodes'])
399 399
             ) {
400
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
400
+                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']);
401 401
                 // if true then that means there is a returned error message
402 402
                 // that we'll need to add to the _errors array for this field.
403 403
                 if ($invalid_shortcodes) {
404
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
404
+                    $v_s     = array_keys($this->_validators[$field]['shortcodes']);
405 405
                     $err_msg = sprintf(
406 406
                         esc_html__(
407 407
                             '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
408 408
                             'event_espresso'
409 409
                         ),
410
-                        '<strong>' . $field_label . '</strong>',
410
+                        '<strong>'.$field_label.'</strong>',
411 411
                         $invalid_shortcodes,
412 412
                         '<p>',
413 413
                         '</p >'
@@ -422,10 +422,10 @@  discard block
 block discarded – undo
422 422
             }
423 423
 
424 424
             // if there's a "type" to be validated then let's do that too.
425
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
426
-                switch ($this->_validators[ $field ]['type']) {
425
+            if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) {
426
+                switch ($this->_validators[$field]['type']) {
427 427
                     case 'number':
428
-                        if (! is_numeric($value)) {
428
+                        if ( ! is_numeric($value)) {
429 429
                             $err_msg .= sprintf(
430 430
                                 esc_html__(
431 431
                                     '%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
                         break;
441 441
                     case 'email':
442 442
                         $valid_email = $this->_validate_email($value);
443
-                        if (! $valid_email) {
443
+                        if ( ! $valid_email) {
444 444
                             $err_msg .= htmlentities(
445 445
                                 sprintf(
446 446
                                     esc_html__(
@@ -458,18 +458,18 @@  discard block
 block discarded – undo
458 458
             }
459 459
 
460 460
             // if $err_msg isn't empty let's setup the _errors array for this field.
461
-            if (! empty($err_msg)) {
462
-                $this->_errors[ $field ]['msg'] = $err_msg;
461
+            if ( ! empty($err_msg)) {
462
+                $this->_errors[$field]['msg'] = $err_msg;
463 463
             } else {
464
-                unset($this->_errors[ $field ]);
464
+                unset($this->_errors[$field]);
465 465
             }
466 466
         }
467 467
 
468 468
         // if we have ANY errors, then we want to make sure we return the values
469 469
         // for ALL the fields so the user doesn't have to retype them all.
470
-        if (! empty($this->_errors)) {
470
+        if ( ! empty($this->_errors)) {
471 471
             foreach ($this->_fields as $field => $value) {
472
-                $this->_errors[ $field ]['value'] = stripslashes($value);
472
+                $this->_errors[$field]['value'] = stripslashes($value);
473 473
             }
474 474
         }
475 475
 
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
     {
491 491
         $shortcodes = array();
492 492
         foreach ($groups as $group) {
493
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
493
+            $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]);
494 494
         }
495 495
         return $shortcodes;
496 496
     }
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
                 // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
521 521
                 $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
522 522
                 // does this exist in the $valid_shortcodes?  If so then unset.
523
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
524
-                    unset($diff[ $ind ]);
523
+                if (isset($valid_shortcodes[$dynamic_sc])) {
524
+                    unset($diff[$ind]);
525 525
                 }
526 526
             }
527 527
         }
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 
533 533
         // made it here? then let's assemble the error message
534 534
         $invalid_shortcodes = implode('</strong>,<strong>', $diff);
535
-        $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
535
+        $invalid_shortcodes = '<strong>'.$invalid_shortcodes.'</strong>';
536 536
         return $invalid_shortcodes;
537 537
     }
538 538
 
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
         // its possible that this message is being "turned off" for a particular context
570 570
 
571 571
 
572
-        if (! empty($or_val) && empty($value)) {
572
+        if ( ! empty($or_val) && empty($value)) {
573 573
             return $validate;
574 574
         }
575 575
 
@@ -628,8 +628,8 @@  discard block
 block discarded – undo
628 628
             '_MSGTYP' => '_message_type',
629 629
         );
630 630
 
631
-        if (isset($expected_properties_map[ $property ])) {
632
-            return $this->{$expected_properties_map[ $property ]};
631
+        if (isset($expected_properties_map[$property])) {
632
+            return $this->{$expected_properties_map[$property]};
633 633
         }
634 634
 
635 635
         throw new Exception(
Please login to merge, or discard this patch.
messages/validators/html/EE_Messages_Html_Invoice_Validator.class.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -16,21 +16,21 @@
 block discarded – undo
16 16
 class EE_Messages_Html_Invoice_Validator extends EE_Messages_Validator
17 17
 {
18 18
 
19
-    public function __construct($fields, $context)
20
-    {
21
-        $this->_m_name = 'html';
22
-        $this->_mt_name = 'invoice';
19
+	public function __construct($fields, $context)
20
+	{
21
+		$this->_m_name = 'html';
22
+		$this->_mt_name = 'invoice';
23 23
 
24
-        parent::__construct($fields, $context);
25
-    }
24
+		parent::__construct($fields, $context);
25
+	}
26 26
 
27
-    /**
28
-     * custom validator (restricting what was originally set by the messenger).
29
-     * Note nothing is currently done for this messenger and message type.
30
-     */
31
-    protected function _modify_validator()
32
-    {
33
-        $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_HTML_URL]');
34
-        return;
35
-    }
27
+	/**
28
+	 * custom validator (restricting what was originally set by the messenger).
29
+	 * Note nothing is currently done for this messenger and message type.
30
+	 */
31
+	protected function _modify_validator()
32
+	{
33
+		$this->_specific_shortcode_excludes['content'] = array('[DISPLAY_HTML_URL]');
34
+		return;
35
+	}
36 36
 }
Please login to merge, or discard this patch.
messages/validators/html/EE_Messages_Html_Receipt_Validator.class.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -16,21 +16,21 @@
 block discarded – undo
16 16
 class EE_Messages_Html_Receipt_Validator extends EE_Messages_Validator
17 17
 {
18 18
 
19
-    public function __construct($fields, $context)
20
-    {
21
-        $this->_m_name = 'html';
22
-        $this->_mt_name = 'receipt';
19
+	public function __construct($fields, $context)
20
+	{
21
+		$this->_m_name = 'html';
22
+		$this->_mt_name = 'receipt';
23 23
 
24
-        parent::__construct($fields, $context);
25
-    }
24
+		parent::__construct($fields, $context);
25
+	}
26 26
 
27
-    /**
28
-     * custom validator (restricting what was originally set by the messenger).
29
-     * Note nothing is currently done for this messenger and message type.
30
-     */
31
-    protected function _modify_validator()
32
-    {
33
-        $this->_specific_shortcode_excludes['content'] = array('[DISPLAY_HTML_URL]');
34
-        return;
35
-    }
27
+	/**
28
+	 * custom validator (restricting what was originally set by the messenger).
29
+	 * Note nothing is currently done for this messenger and message type.
30
+	 */
31
+	protected function _modify_validator()
32
+	{
33
+		$this->_specific_shortcode_excludes['content'] = array('[DISPLAY_HTML_URL]');
34
+		return;
35
+	}
36 36
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Base.lib.php 2 patches
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -14,44 +14,44 @@  discard block
 block discarded – undo
14 14
 abstract class EE_Messages_Base extends EE_Base
15 15
 {
16 16
 
17
-    /** DETAILS PROPERTIES **/
18
-    /**
19
-     * The following are used to hold details on the type for reference (i.e. on admin screens)
20
-     * and also used by the EE_message_type object to figure out where to get template data.
21
-     */
22
-    public $name;
23
-    public $description;
24
-    protected $_messages_item_type; // messenger OR message_type?
25
-
26
-
27
-    /**
28
-     * This is an array describing the ui facing labels
29
-     * that will be used whenever the messenger is referenced in the ui
30
-     *
31
-     * array(
32
-     *  'singular' => __('something'),
33
-     *  'plural' => __('somethings')
34
-     * )
35
-     *
36
-     * @var array
37
-     */
38
-    public $label;
39
-
40
-
41
-
42
-
43
-    /**
44
-     * This property when set will hold the slugs of all EE admin pages that we will need to retrieve fields for
45
-     * (and used to determine which callback method to call from the child class)
46
-     *
47
-     * structure should be
48
-     * array(
49
-     * 'page_action' => true
50
-     * )
51
-     *
17
+	/** DETAILS PROPERTIES **/
18
+	/**
19
+	 * The following are used to hold details on the type for reference (i.e. on admin screens)
20
+	 * and also used by the EE_message_type object to figure out where to get template data.
21
+	 */
22
+	public $name;
23
+	public $description;
24
+	protected $_messages_item_type; // messenger OR message_type?
25
+
26
+
27
+	/**
28
+	 * This is an array describing the ui facing labels
29
+	 * that will be used whenever the messenger is referenced in the ui
30
+	 *
31
+	 * array(
32
+	 *  'singular' => __('something'),
33
+	 *  'plural' => __('somethings')
34
+	 * )
35
+	 *
36
+	 * @var array
37
+	 */
38
+	public $label;
39
+
40
+
41
+
42
+
43
+	/**
44
+	 * This property when set will hold the slugs of all EE admin pages that we will need to retrieve fields for
45
+	 * (and used to determine which callback method to call from the child class)
46
+	 *
47
+	 * structure should be
48
+	 * array(
49
+	 * 'page_action' => true
50
+	 * )
51
+	 *
52 52
 *@var array
53
-     */
54
-    public $admin_registered_pages = array();
53
+	 */
54
+	public $admin_registered_pages = array();
55 55
 
56 56
 
57 57
 
@@ -60,264 +60,264 @@  discard block
 block discarded – undo
60 60
 
61 61
 
62 62
 
63
-    /**
64
-     * this property holds any specific fields for holding any settings related to a messenger (if any needed)
65
-     * @var array
66
-     */
67
-    protected $_admin_settings_fields = array();
63
+	/**
64
+	 * this property holds any specific fields for holding any settings related to a messenger (if any needed)
65
+	 * @var array
66
+	 */
67
+	protected $_admin_settings_fields = array();
68 68
 
69 69
 
70 70
 
71 71
 
72 72
 
73
-    /**
74
-     * this property will hold any existing settings that may have been set in the admin.
75
-     * @var array
76
-     */
77
-    protected $_existing_admin_settings = array();
73
+	/**
74
+	 * this property will hold any existing settings that may have been set in the admin.
75
+	 * @var array
76
+	 */
77
+	protected $_existing_admin_settings = array();
78 78
 
79 79
 
80 80
 
81 81
 
82 82
 
83
-    /**
84
-     * this property will hold an array of valid shortcodes for this message type and messengers.
85
-     * #For Message Types:
86
-     * This is an array of strings that correspond to defined EE_Shortcode libraries and per context.
87
-     * For example:
88
-     * array( 'admin' => array('transaction', 'event', 'attendee') )
89
-     * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php'
90
-     * for the admin context;
91
-     *
92
-     *
93
-     * #For Messengers:
94
-     * For example:
95
-     * array('subject' => array('transaction', 'event', 'attendee'))
96
-     * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php'
97
-     * for the 'subject' field;
98
-     * NOTE:  by default, with messengers, if the valid shortcodes for a field is left blank,
99
-     * that field will inherit whatever are set as valid shortcodes by message_type.
100
-     * This is so messenger can set specific valid codes for fields and leave other
101
-     * valid shortcodes up to the message type matched with the messenger.
102
-     *
103
-     * @access protected
104
-     * @var array
105
-     */
106
-    protected $_valid_shortcodes = array();
83
+	/**
84
+	 * this property will hold an array of valid shortcodes for this message type and messengers.
85
+	 * #For Message Types:
86
+	 * This is an array of strings that correspond to defined EE_Shortcode libraries and per context.
87
+	 * For example:
88
+	 * array( 'admin' => array('transaction', 'event', 'attendee') )
89
+	 * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php'
90
+	 * for the admin context;
91
+	 *
92
+	 *
93
+	 * #For Messengers:
94
+	 * For example:
95
+	 * array('subject' => array('transaction', 'event', 'attendee'))
96
+	 * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php'
97
+	 * for the 'subject' field;
98
+	 * NOTE:  by default, with messengers, if the valid shortcodes for a field is left blank,
99
+	 * that field will inherit whatever are set as valid shortcodes by message_type.
100
+	 * This is so messenger can set specific valid codes for fields and leave other
101
+	 * valid shortcodes up to the message type matched with the messenger.
102
+	 *
103
+	 * @access protected
104
+	 * @var array
105
+	 */
106
+	protected $_valid_shortcodes = array();
107 107
 
108 108
 
109 109
 
110 110
 
111 111
 
112
-    public function __construct()
113
-    {
114
-        $this->_set_admin_settings_fields();
115
-        $this->_set_valid_shortcodes();
116
-        $this->_set_admin_pages();
117
-    }
112
+	public function __construct()
113
+	{
114
+		$this->_set_admin_settings_fields();
115
+		$this->_set_valid_shortcodes();
116
+		$this->_set_admin_pages();
117
+	}
118 118
 
119 119
 
120 120
 
121 121
 
122 122
 
123
-    /**
124
-     * sets the _admin_settings_fields property which needs to be defined by child classes.
125
-     * You will want to set the _admin_settings_fields properties as a multi-dimensional array with the following format
126
-     * array(
127
-     *      {field_name - also used for setting index} => array(
128
-     *          'field_type' => {type of field: 'text', 'textarea', 'checkbox'},
129
-     *          'value_type' => {type of value: 'string', 'int', 'array', 'bool'},
130
-     *          'required' => {bool, required or not},
131
-     *          'validation' => {bool, true if we want validation, false if not},
132
-     *          'format' => {%d, or %s},
133
-     *          'label' => {label for the field, make sure it's localized},
134
-     *          'default' => {default value for the setting}
135
-     *      ),
136
-     * );
137
-     *
138
-     * @abstract
139
-     * @access protected
140
-     * @return void
141
-     */
142
-    abstract protected function _set_admin_settings_fields();
123
+	/**
124
+	 * sets the _admin_settings_fields property which needs to be defined by child classes.
125
+	 * You will want to set the _admin_settings_fields properties as a multi-dimensional array with the following format
126
+	 * array(
127
+	 *      {field_name - also used for setting index} => array(
128
+	 *          'field_type' => {type of field: 'text', 'textarea', 'checkbox'},
129
+	 *          'value_type' => {type of value: 'string', 'int', 'array', 'bool'},
130
+	 *          'required' => {bool, required or not},
131
+	 *          'validation' => {bool, true if we want validation, false if not},
132
+	 *          'format' => {%d, or %s},
133
+	 *          'label' => {label for the field, make sure it's localized},
134
+	 *          'default' => {default value for the setting}
135
+	 *      ),
136
+	 * );
137
+	 *
138
+	 * @abstract
139
+	 * @access protected
140
+	 * @return void
141
+	 */
142
+	abstract protected function _set_admin_settings_fields();
143 143
 
144 144
 
145 145
 
146 146
 
147 147
 
148
-    /**
149
-     * sets any properties on whether a message type or messenger interface shows up on a ee administration page.
150
-     * Child classes have to define this method but don't necessarily have to set the flags
151
-     * as they will be set to false by default.
152
-     *
153
-     * Child classes use this method to set the `_admin_registered_page` property.
154
-     * That property is to indicate what EE admin pages we have a corresponding callback for in the child class
155
-     * so Message Type/messenger fields/content is included on that admin page.
156
-     *
157
-     * @abstract
158
-     * @access protected
159
-     * @return void
160
-     */
161
-    abstract protected function _set_admin_pages();
148
+	/**
149
+	 * sets any properties on whether a message type or messenger interface shows up on a ee administration page.
150
+	 * Child classes have to define this method but don't necessarily have to set the flags
151
+	 * as they will be set to false by default.
152
+	 *
153
+	 * Child classes use this method to set the `_admin_registered_page` property.
154
+	 * That property is to indicate what EE admin pages we have a corresponding callback for in the child class
155
+	 * so Message Type/messenger fields/content is included on that admin page.
156
+	 *
157
+	 * @abstract
158
+	 * @access protected
159
+	 * @return void
160
+	 */
161
+	abstract protected function _set_admin_pages();
162 162
 
163 163
 
164 164
 
165 165
 
166 166
 
167
-    /**
168
-     * Child classes must declare the $_valid_shortcodes property using this method.
169
-     * See comments for $_valid_shortcodes property for details on what it is used for.
170
-     *
171
-     * @access protected
172
-     * @return void
173
-     */
174
-    abstract protected function _set_valid_shortcodes();
167
+	/**
168
+	 * Child classes must declare the $_valid_shortcodes property using this method.
169
+	 * See comments for $_valid_shortcodes property for details on what it is used for.
170
+	 *
171
+	 * @access protected
172
+	 * @return void
173
+	 */
174
+	abstract protected function _set_valid_shortcodes();
175 175
 
176 176
 
177 177
 
178
-    /**
179
-     * sets the _existing_admin_settings property can be overridden by child classes.
180
-     * We do this so we only do database calls if needed.
181
-     *
182
-     * @access protected
183
-     * @param string $messenger
184
-     */
185
-    protected function _set_existing_admin_settings($messenger = '')
186
-    {
187
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
188
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
189
-        $active_messengers = $Message_Resource_Manager->get_active_messengers_option();
190
-        $settings_to_use = $active_messengers;
191
-
192
-        /**
193
-         * This determines what will be used for the getting the settings.
194
-         */
195
-        if (! empty($messenger)
196
-            && $Message_Resource_Manager->is_message_type_active_for_messenger($messenger, $this->name)
197
-        ) {
198
-            $settings_to_use = $active_messengers[ $messenger ]['settings'][ $messenger . '-message_types' ];
199
-        }
200
-
201
-        $this->_existing_admin_settings = isset($settings_to_use[ $this->name ]['settings'])
202
-            ? $settings_to_use[ $this->name ]['settings']
203
-            : null;
204
-    }
205
-
206
-
207
-
208
-
209
-
210
-
211
-    /**
212
-     * get_existing_admin_settings
213
-     * (if needed) sets and returns the _existing_admin_settings property.
214
-     *
215
-     * @access public
216
-     * @param string $messenger
217
-     * @return array          settings
218
-     */
219
-    public function get_existing_admin_settings($messenger = '')
220
-    {
221
-        // if admin_settings property empty lets try setting it.
222
-        if (method_exists($this, '_set_existing_admin_settings') && empty($this->_existing_admin_settings)) {
223
-            $this->_set_existing_admin_settings($messenger);
224
-        }
225
-        return property_exists($this, '_existing_admin_settings')
226
-            ? $this->_existing_admin_settings
227
-            : null;
228
-    }
229
-
230
-
231
-
232
-
233
-
234
-
235
-    /**
236
-     * This returns the array of valid shortcodes for a message type or messenger as set by the child in the $_valid_shortcode property.
237
-     * @return array   an array of valid shortcodes.
238
-     */
239
-    public function get_valid_shortcodes()
240
-    {
241
-        $valid_shortcodes = apply_filters(
242
-            'FHEE__' . get_class($this) . '__get_valid_shortcodes',
243
-            $this->_valid_shortcodes,
244
-            $this
245
-        );
246
-        // The below filter applies to ALL messengers and message types so use with care!
247
-        $valid_shortcodes = apply_filters('FHEE__EE_Messages_Base__get_valid_shortcodes', $valid_shortcodes, $this);
248
-        return $valid_shortcodes;
249
-    }
250
-
251
-
252
-
253
-
254
-    /**
255
-     * getter that returns the protected admin_settings_fields property
256
-     *
257
-     * @access public
258
-     * @return array admin settings fields
259
-     */
260
-    public function get_admin_settings_fields()
261
-    {
262
-        return $this->_admin_settings_fields;
263
-    }
264
-
265
-
266
-
267
-
268
-
269
-    /**
270
-     * this public method accepts a page slug (for an EE_admin page)
271
-     * and will return the response from the child class callback function
272
-     * if that page is registered via the `_admin_registered_page` property set by the child class.
273
-     *
274
-     * @param string $page the slug of the EE admin page
275
-     * @param array $actives an array of active message type (or messenger) objects.
276
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
277
-     * @param array $extra This is just an extra argument that can be used
278
-     *                     to pass additional data for setting up page content.
279
-     * @access protected
280
-     * @return string $content for page.
281
-     */
282
-    protected function _get_admin_page_content($page, $action, $extra, $actives)
283
-    {
284
-        // we can also further refine the context by action (if present).
285
-        if (!empty($action)) {
286
-            $page = $page . '_' . $action;
287
-        }
288
-
289
-        if (!isset($this->admin_registered_pages[ $page ])) {
290
-            // todo: a place to throw an exception?
291
-            // We need to indicate there is no registered page so this function is not being called correctly.
292
-            return false;
293
-        }
294
-        // k made it here so let's call the method
295
-        $content = call_user_func_array(
296
-            array( $this, '_get_admin_content_' . $page ),
297
-            array( $actives, $extra )
298
-        );
299
-        if ($content === false) {
300
-            // todo this needs to be an exception once we've got exceptions in place.
301
-            return false;
302
-        }
303
-        return $content;
304
-    }
305
-
306
-
307
-    /**
308
-     * Allows a message type to specifically exclude template fields for the provided messenger.
309
-     * Filtered so this can be programmatically altered as well.
310
-     * @param string $messenger_name name of messenger
311
-     * @return array
312
-     */
313
-    public function excludedFieldsForMessenger($messenger_name)
314
-    {
315
-        return apply_filters(
316
-            'FHEE__EE_Messages_Base__excludedFieldForMessenger',
317
-            array(),
318
-            $messenger_name,
319
-            $this->name,
320
-            $this
321
-        );
322
-    }
178
+	/**
179
+	 * sets the _existing_admin_settings property can be overridden by child classes.
180
+	 * We do this so we only do database calls if needed.
181
+	 *
182
+	 * @access protected
183
+	 * @param string $messenger
184
+	 */
185
+	protected function _set_existing_admin_settings($messenger = '')
186
+	{
187
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
188
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
189
+		$active_messengers = $Message_Resource_Manager->get_active_messengers_option();
190
+		$settings_to_use = $active_messengers;
191
+
192
+		/**
193
+		 * This determines what will be used for the getting the settings.
194
+		 */
195
+		if (! empty($messenger)
196
+			&& $Message_Resource_Manager->is_message_type_active_for_messenger($messenger, $this->name)
197
+		) {
198
+			$settings_to_use = $active_messengers[ $messenger ]['settings'][ $messenger . '-message_types' ];
199
+		}
200
+
201
+		$this->_existing_admin_settings = isset($settings_to_use[ $this->name ]['settings'])
202
+			? $settings_to_use[ $this->name ]['settings']
203
+			: null;
204
+	}
205
+
206
+
207
+
208
+
209
+
210
+
211
+	/**
212
+	 * get_existing_admin_settings
213
+	 * (if needed) sets and returns the _existing_admin_settings property.
214
+	 *
215
+	 * @access public
216
+	 * @param string $messenger
217
+	 * @return array          settings
218
+	 */
219
+	public function get_existing_admin_settings($messenger = '')
220
+	{
221
+		// if admin_settings property empty lets try setting it.
222
+		if (method_exists($this, '_set_existing_admin_settings') && empty($this->_existing_admin_settings)) {
223
+			$this->_set_existing_admin_settings($messenger);
224
+		}
225
+		return property_exists($this, '_existing_admin_settings')
226
+			? $this->_existing_admin_settings
227
+			: null;
228
+	}
229
+
230
+
231
+
232
+
233
+
234
+
235
+	/**
236
+	 * This returns the array of valid shortcodes for a message type or messenger as set by the child in the $_valid_shortcode property.
237
+	 * @return array   an array of valid shortcodes.
238
+	 */
239
+	public function get_valid_shortcodes()
240
+	{
241
+		$valid_shortcodes = apply_filters(
242
+			'FHEE__' . get_class($this) . '__get_valid_shortcodes',
243
+			$this->_valid_shortcodes,
244
+			$this
245
+		);
246
+		// The below filter applies to ALL messengers and message types so use with care!
247
+		$valid_shortcodes = apply_filters('FHEE__EE_Messages_Base__get_valid_shortcodes', $valid_shortcodes, $this);
248
+		return $valid_shortcodes;
249
+	}
250
+
251
+
252
+
253
+
254
+	/**
255
+	 * getter that returns the protected admin_settings_fields property
256
+	 *
257
+	 * @access public
258
+	 * @return array admin settings fields
259
+	 */
260
+	public function get_admin_settings_fields()
261
+	{
262
+		return $this->_admin_settings_fields;
263
+	}
264
+
265
+
266
+
267
+
268
+
269
+	/**
270
+	 * this public method accepts a page slug (for an EE_admin page)
271
+	 * and will return the response from the child class callback function
272
+	 * if that page is registered via the `_admin_registered_page` property set by the child class.
273
+	 *
274
+	 * @param string $page the slug of the EE admin page
275
+	 * @param array $actives an array of active message type (or messenger) objects.
276
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
277
+	 * @param array $extra This is just an extra argument that can be used
278
+	 *                     to pass additional data for setting up page content.
279
+	 * @access protected
280
+	 * @return string $content for page.
281
+	 */
282
+	protected function _get_admin_page_content($page, $action, $extra, $actives)
283
+	{
284
+		// we can also further refine the context by action (if present).
285
+		if (!empty($action)) {
286
+			$page = $page . '_' . $action;
287
+		}
288
+
289
+		if (!isset($this->admin_registered_pages[ $page ])) {
290
+			// todo: a place to throw an exception?
291
+			// We need to indicate there is no registered page so this function is not being called correctly.
292
+			return false;
293
+		}
294
+		// k made it here so let's call the method
295
+		$content = call_user_func_array(
296
+			array( $this, '_get_admin_content_' . $page ),
297
+			array( $actives, $extra )
298
+		);
299
+		if ($content === false) {
300
+			// todo this needs to be an exception once we've got exceptions in place.
301
+			return false;
302
+		}
303
+		return $content;
304
+	}
305
+
306
+
307
+	/**
308
+	 * Allows a message type to specifically exclude template fields for the provided messenger.
309
+	 * Filtered so this can be programmatically altered as well.
310
+	 * @param string $messenger_name name of messenger
311
+	 * @return array
312
+	 */
313
+	public function excludedFieldsForMessenger($messenger_name)
314
+	{
315
+		return apply_filters(
316
+			'FHEE__EE_Messages_Base__excludedFieldForMessenger',
317
+			array(),
318
+			$messenger_name,
319
+			$this->name,
320
+			$this
321
+		);
322
+	}
323 323
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -192,14 +192,14 @@  discard block
 block discarded – undo
192 192
         /**
193 193
          * This determines what will be used for the getting the settings.
194 194
          */
195
-        if (! empty($messenger)
195
+        if ( ! empty($messenger)
196 196
             && $Message_Resource_Manager->is_message_type_active_for_messenger($messenger, $this->name)
197 197
         ) {
198
-            $settings_to_use = $active_messengers[ $messenger ]['settings'][ $messenger . '-message_types' ];
198
+            $settings_to_use = $active_messengers[$messenger]['settings'][$messenger.'-message_types'];
199 199
         }
200 200
 
201
-        $this->_existing_admin_settings = isset($settings_to_use[ $this->name ]['settings'])
202
-            ? $settings_to_use[ $this->name ]['settings']
201
+        $this->_existing_admin_settings = isset($settings_to_use[$this->name]['settings'])
202
+            ? $settings_to_use[$this->name]['settings']
203 203
             : null;
204 204
     }
205 205
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
     public function get_valid_shortcodes()
240 240
     {
241 241
         $valid_shortcodes = apply_filters(
242
-            'FHEE__' . get_class($this) . '__get_valid_shortcodes',
242
+            'FHEE__'.get_class($this).'__get_valid_shortcodes',
243 243
             $this->_valid_shortcodes,
244 244
             $this
245 245
         );
@@ -282,19 +282,19 @@  discard block
 block discarded – undo
282 282
     protected function _get_admin_page_content($page, $action, $extra, $actives)
283 283
     {
284 284
         // we can also further refine the context by action (if present).
285
-        if (!empty($action)) {
286
-            $page = $page . '_' . $action;
285
+        if ( ! empty($action)) {
286
+            $page = $page.'_'.$action;
287 287
         }
288 288
 
289
-        if (!isset($this->admin_registered_pages[ $page ])) {
289
+        if ( ! isset($this->admin_registered_pages[$page])) {
290 290
             // todo: a place to throw an exception?
291 291
             // We need to indicate there is no registered page so this function is not being called correctly.
292 292
             return false;
293 293
         }
294 294
         // k made it here so let's call the method
295 295
         $content = call_user_func_array(
296
-            array( $this, '_get_admin_content_' . $page ),
297
-            array( $actives, $extra )
296
+            array($this, '_get_admin_content_'.$page),
297
+            array($actives, $extra)
298 298
         );
299 299
         if ($content === false) {
300 300
             // todo this needs to be an exception once we've got exceptions in place.
Please login to merge, or discard this patch.
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.