Completed
Branch BUG/fix-ee-rest-debug-headers (1355bc)
by
unknown
03:29 queued 18s
created
payment_methods/Aim/help_tabs/payment_methods_overview_aim.help_tab.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@  discard block
 block discarded – undo
6 6
 </p>
7 7
 <p>
8 8
     <?php
9
-    printf(
10
-        esc_html__(
11
-            'See %1$shere%2$s for list of currencies supported by Authorize.net AIM.',
12
-            'event_espresso'
13
-        ),
14
-        "<a href='https://support.authorize.net/s/article/Which-Currencies-Does-Authorize-Net-Support/' target='_blank' rel='noopener noreferrer'>",
15
-        "</a>"
16
-    );
17
-    ?>
9
+	printf(
10
+		esc_html__(
11
+			'See %1$shere%2$s for list of currencies supported by Authorize.net AIM.',
12
+			'event_espresso'
13
+		),
14
+		"<a href='https://support.authorize.net/s/article/Which-Currencies-Does-Authorize-Net-Support/' target='_blank' rel='noopener noreferrer'>",
15
+		"</a>"
16
+	);
17
+	?>
18 18
 </p>
19 19
 <p>
20 20
     <strong><?php esc_html_e('Authorize.net AIM Settings', 'event_espresso'); ?></strong>
@@ -24,70 +24,70 @@  discard block
 block discarded – undo
24 24
         <strong><?php esc_html_e('Authorize.net API Login ID', 'event_espresso'); ?></strong>
25 25
         <br/>
26 26
         <?php
27
-        printf(
28
-            esc_html__(
29
-                'Enter your API Login ID for Authorize.net. Learn how to find your %1$sAPI Login%2$s ID.',
30
-                'event_espresso'
31
-            ),
32
-            '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">',
33
-            '</a>'
34
-        );
35
-        ?>
27
+		printf(
28
+			esc_html__(
29
+				'Enter your API Login ID for Authorize.net. Learn how to find your %1$sAPI Login%2$s ID.',
30
+				'event_espresso'
31
+			),
32
+			'<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">',
33
+			'</a>'
34
+		);
35
+		?>
36 36
     </li>
37 37
     <li>
38 38
         <strong><?php esc_html_e('Authorize.net Transaction Key', 'event_espresso'); ?></strong>
39 39
         <br/>
40 40
         <?php
41
-        printf(
42
-            esc_html__(
43
-                'Enter your Transaction Key for Authorize.net. Learn how to find your %1$sTransaction Key%2$s.',
44
-                'event_espresso'
45
-            ),
46
-            '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">',
47
-            '</a>'
48
-        );
49
-        ?>
41
+		printf(
42
+			esc_html__(
43
+				'Enter your Transaction Key for Authorize.net. Learn how to find your %1$sTransaction Key%2$s.',
44
+				'event_espresso'
45
+			),
46
+			'<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">',
47
+			'</a>'
48
+		);
49
+		?>
50 50
     </li>
51 51
     <li>
52 52
         <strong>
53 53
             <?php esc_html_e(
54
-                'Is this an account on the Authorize.net development server?',
55
-                'event_espresso'
56
-            ); ?>
54
+				'Is this an account on the Authorize.net development server?',
55
+				'event_espresso'
56
+			); ?>
57 57
         </strong>
58 58
         <br/>
59 59
         <?php esc_html_e(
60
-            'Specify whether this is a live/production account or a test account on the Authorize.net development server.',
61
-            'event_espresso'
62
-        ); ?>
60
+			'Specify whether this is a live/production account or a test account on the Authorize.net development server.',
61
+			'event_espresso'
62
+		); ?>
63 63
     </li>
64 64
     <li>
65 65
         <strong><?php esc_html_e('Do you want to submit a test transaction?', 'event_espresso'); ?></strong>
66 66
         <br/>
67 67
         <?php esc_html_e(
68
-            'Specify if you want to test the Authorize.net AIM payment gateway by submitting a test transaction. Be sure to turn this setting off when you are done testing.',
69
-            'event_espresso'
70
-        ); ?>
68
+			'Specify if you want to test the Authorize.net AIM payment gateway by submitting a test transaction. Be sure to turn this setting off when you are done testing.',
69
+			'event_espresso'
70
+		); ?>
71 71
     </li>
72 72
     <li>
73 73
         <strong><?php esc_html_e('Excluded and Required Payment Form Fields', 'event_espresso'); ?></strong>
74 74
         <br/>
75 75
         <?php esc_html_e(
76
-            'By logging into Authorize.net, you can change which payment fields are required by Authorize.net when processing payments. These settings affect both the Advanced Integration Method (AIM, this) and the Simple Integration Method (SIM, different). The payment method settings "Excluded Payment Form Fields" and "Required Payment Form Fields" allow you to change the billing form in Event Espresso to reflect your payment form settings in Authorize.net.',
77
-            'event_espresso'
78
-        ); ?>
76
+			'By logging into Authorize.net, you can change which payment fields are required by Authorize.net when processing payments. These settings affect both the Advanced Integration Method (AIM, this) and the Simple Integration Method (SIM, different). The payment method settings "Excluded Payment Form Fields" and "Required Payment Form Fields" allow you to change the billing form in Event Espresso to reflect your payment form settings in Authorize.net.',
77
+			'event_espresso'
78
+		); ?>
79 79
         <br>
80 80
         <?php printf(
81
-            esc_html__(
82
-                'To change your payment form settings in Authorize.net, %1$slog in to authorize.net%2$s, go to %3$sAccount then Payment Form%2$s, then %4$sForm Fields%2$s. It will look similar to %5$sthis%2$s. If you make a field required in Authorize.net, you should also make it required in Event Espresso. If it isn\'t required in Authorize.net, and you want to simplify the billing form in Event Espresso, you can exclude it from the Event Espresso Form too.',
83
-                'event_espresso'
84
-            ),
85
-            '<a href="http://authorize.net" target="_blank" rel="noopener noreferrer">',
86
-            '</a>',
87
-            '<a href="https://monosnap.com/file/nebVteOkEXcdDIos88SojStWOifP23" target="_blank" rel="noopener noreferrer">',
88
-            '<a href="https://monosnap.com/file/WyxGJtev87TcDmdGBEZ2oi1xaBIQAm" target="_blank" rel="noopener noreferrer">',
89
-            '<a href="https://monosnap.com/image/DbCJNfEesWXeSNUs1wLIpGYODFw52m" target="_blank" rel="noopener noreferrer">'
90
-        ); ?>
81
+			esc_html__(
82
+				'To change your payment form settings in Authorize.net, %1$slog in to authorize.net%2$s, go to %3$sAccount then Payment Form%2$s, then %4$sForm Fields%2$s. It will look similar to %5$sthis%2$s. If you make a field required in Authorize.net, you should also make it required in Event Espresso. If it isn\'t required in Authorize.net, and you want to simplify the billing form in Event Espresso, you can exclude it from the Event Espresso Form too.',
83
+				'event_espresso'
84
+			),
85
+			'<a href="http://authorize.net" target="_blank" rel="noopener noreferrer">',
86
+			'</a>',
87
+			'<a href="https://monosnap.com/file/nebVteOkEXcdDIos88SojStWOifP23" target="_blank" rel="noopener noreferrer">',
88
+			'<a href="https://monosnap.com/file/WyxGJtev87TcDmdGBEZ2oi1xaBIQAm" target="_blank" rel="noopener noreferrer">',
89
+			'<a href="https://monosnap.com/image/DbCJNfEesWXeSNUs1wLIpGYODFw52m" target="_blank" rel="noopener noreferrer">'
90
+		); ?>
91 91
     </li>
92 92
     <li>
93 93
         <strong><?php esc_html_e('Button Image URL', 'event_espresso'); ?></strong>
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
     <li>
98 98
         <strong><?php esc_html_e('Note About Special Characters', 'event_espresso'); ?></strong>
99 99
         <?php
100
-        esc_html_e(
101
-            'If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.',
102
-            'event_espresso'
103
-        );
104
-        ?>
100
+		esc_html_e(
101
+			'If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.',
102
+			'event_espresso'
103
+		);
104
+		?>
105 105
     </li>
106 106
 </ul>
107 107
\ No newline at end of file
Please login to merge, or discard this patch.
caffeinated/brewing_regular.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 use EventEspresso\core\services\database\TableAnalysis;
13 13
 
14 14
 // defined some new constants related to caffeinated folder
15
-define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/');
16
-define('EE_CAF_CORE', EE_CAFF_PATH . 'core/');
17
-define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries/');
18
-define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods/');
15
+define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/');
16
+define('EE_CAF_CORE', EE_CAFF_PATH.'core/');
17
+define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries/');
18
+define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods/');
19 19
 
20 20
 
21 21
 /**
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
         add_filter('FHEE__EE_Registry__load_helper__helper_paths', [$this, 'caf_helper_paths'], 10);
66 66
         add_filter(
67 67
             'AHEE__EE_System__load_core_configuration__complete',
68
-            function () {
68
+            function() {
69 69
                 EE_Register_Payment_Method::register(
70 70
                     'caffeinated_payment_methods',
71 71
                     [
72
-                        'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR),
72
+                        'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR),
73 73
                     ]
74 74
                 );
75 75
             }
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function caf_helper_paths($paths)
126 126
     {
127
-        $paths[] = EE_CAF_CORE . 'helpers/';
127
+        $paths[] = EE_CAF_CORE.'helpers/';
128 128
         return $paths;
129 129
     }
130 130
 
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
         global $wpdb;
146 146
         // use same method of getting creator id as the version introducing the change
147 147
         $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
148
-        $price_type_table   = $wpdb->prefix . "esp_price_type";
149
-        $price_table        = $wpdb->prefix . "esp_price";
148
+        $price_type_table   = $wpdb->prefix."esp_price_type";
149
+        $price_table        = $wpdb->prefix."esp_price";
150 150
         if ($this->_get_table_analysis()->tableExists($price_type_table)) {
151 151
             $SQL                  =
152
-                'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types
152
+                'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; // include trashed price types
153 153
             $tax_price_type_count = $wpdb->get_var($SQL);
154 154
             if ($tax_price_type_count <= 1) {
155 155
                 $wpdb->insert(
@@ -163,11 +163,11 @@  discard block
 block discarded – undo
163 163
                         'PRT_wp_user'    => $default_creator_id,
164 164
                     ],
165 165
                     [
166
-                        '%s',// PRT_name
167
-                        '%d',// PBT_id
168
-                        '%d',// PRT_is_percent
169
-                        '%d',// PRT_order
170
-                        '%d',// PRT_deleted
166
+                        '%s', // PRT_name
167
+                        '%d', // PBT_id
168
+                        '%d', // PRT_is_percent
169
+                        '%d', // PRT_order
170
+                        '%d', // PRT_deleted
171 171
                         '%d', // PRT_wp_user
172 172
                     ]
173 173
                 );
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
                         'PRT_wp_user'    => $default_creator_id,
184 184
                     ],
185 185
                     [
186
-                        '%s',// PRT_name
187
-                        '%d',// PBT_id
188
-                        '%d',// PRT_is_percent
189
-                        '%d',// PRT_order
190
-                        '%d',// PRT_deleted
186
+                        '%s', // PRT_name
187
+                        '%d', // PBT_id
188
+                        '%d', // PRT_is_percent
189
+                        '%d', // PRT_order
190
+                        '%d', // PRT_deleted
191 191
                         '%d' // PRT_wp_user
192 192
                     ]
193 193
                 );
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
                             'PRC_wp_user'    => $default_creator_id,
208 208
                         ],
209 209
                         [
210
-                            '%d',// PRT_id
211
-                            '%f',// PRC_amount
212
-                            '%s',// PRC_name
213
-                            '%s',// PRC_desc
214
-                            '%d',// PRC_is_default
215
-                            '%d',// PRC_overrides
216
-                            '%d',// PRC_deleted
217
-                            '%d',// PRC_order
218
-                            '%d',// PRC_parent
210
+                            '%d', // PRT_id
211
+                            '%f', // PRC_amount
212
+                            '%s', // PRC_name
213
+                            '%s', // PRC_desc
214
+                            '%d', // PRC_is_default
215
+                            '%d', // PRC_overrides
216
+                            '%d', // PRC_deleted
217
+                            '%d', // PRC_order
218
+                            '%d', // PRC_parent
219 219
                             '%d' // PRC_wp_user
220 220
                         ]
221 221
                     );
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function caffeinated_modules_to_register($modules_to_register = [])
236 236
     {
237
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
238
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules/*', GLOB_ONLYDIR);
237
+        if (is_readable(EE_CAFF_PATH.'modules')) {
238
+            $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules/*', GLOB_ONLYDIR);
239 239
             if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
240 240
                 $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
241 241
             }
Please login to merge, or discard this patch.
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -27,323 +27,323 @@
 block discarded – undo
27 27
  */
28 28
 class EE_Brewing_Regular extends EE_BASE implements InterminableInterface
29 29
 {
30
-    /**
31
-     * @var TableAnalysis $table_analysis
32
-     */
33
-    protected $_table_analysis;
34
-
35
-
36
-    /**
37
-     * EE_Brewing_Regular constructor.
38
-     *
39
-     * @param TableAnalysis $table_analysis
40
-     */
41
-    public function __construct(TableAnalysis $table_analysis)
42
-    {
43
-        $this->_table_analysis = $table_analysis;
44
-        if (defined('EE_CAFF_PATH')) {
45
-            $this->setInitializationHooks();
46
-            $this->setApiRegistrationHooks();
47
-            $this->setSwitchHooks();
48
-            $this->setDefaultFilterHooks();
49
-            // caffeinated constructed
50
-            do_action('AHEE__EE_Brewing_Regular__construct__complete');
51
-        }
52
-    }
53
-
54
-
55
-    /**
56
-     * Various hooks used for extending features via registration of modules or extensions.
57
-     */
58
-    private function setApiRegistrationHooks()
59
-    {
60
-        add_filter(
61
-            'FHEE__EE_Config__register_modules__modules_to_register',
62
-            [$this, 'caffeinated_modules_to_register']
63
-        );
64
-        add_filter('FHEE__EE_Registry__load_helper__helper_paths', [$this, 'caf_helper_paths'], 10);
65
-        add_filter(
66
-            'AHEE__EE_System__load_core_configuration__complete',
67
-            function () {
68
-                EE_Register_Payment_Method::register(
69
-                    'caffeinated_payment_methods',
70
-                    [
71
-                        'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR),
72
-                    ]
73
-                );
74
-            }
75
-        );
76
-    }
77
-
78
-
79
-    /**
80
-     * Various hooks used for modifying initialization or activation processes.
81
-     */
82
-    private function setInitializationHooks()
83
-    {
84
-        // activation
85
-        add_action('AHEE__EEH_Activation__initialize_db_content', [$this, 'initialize_caf_db_content']);
86
-        // load caff init
87
-        add_action('AHEE__EE_System__set_hooks_for_core', [$this, 'caffeinated_init']);
88
-        // load caff scripts
89
-        add_action('wp_enqueue_scripts', [$this, 'enqueue_caffeinated_scripts'], 10);
90
-    }
91
-
92
-
93
-    /**
94
-     * Various hooks used for switch (on/off) type filters.
95
-     */
96
-    private function setSwitchHooks()
97
-    {
98
-        // remove the "powered by" credit link from receipts and invoices
99
-        add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
100
-        // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
101
-        add_filter('FHEE__ee_show_affiliate_links', '__return_false');
102
-    }
103
-
104
-
105
-    /**
106
-     * Various filters for affecting default configuration values in the caffeinated
107
-     * context.
108
-     */
109
-    private function setDefaultFilterHooks()
110
-    {
111
-        add_filter(
112
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
113
-            '__return_true'
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
120
-     *
121
-     * @param array $paths original helper paths array
122
-     * @return array             new array of paths
123
-     */
124
-    public function caf_helper_paths($paths)
125
-    {
126
-        $paths[] = EE_CAF_CORE . 'helpers/';
127
-        return $paths;
128
-    }
129
-
130
-
131
-    /**
132
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
133
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
134
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
135
-     * This action should only be called when EE 4.x.0.P is initially activated.
136
-     * Right now the only CAF content are these global prices. If there's more in the future, then
137
-     * we should probably create a caf file to contain it all instead just a function like this.
138
-     * Right now, we ASSUME the only price types in the system are default ones
139
-     *
140
-     * @global wpdb $wpdb
141
-     */
142
-    public function initialize_caf_db_content()
143
-    {
144
-        global $wpdb;
145
-        // use same method of getting creator id as the version introducing the change
146
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
147
-        $price_type_table   = $wpdb->prefix . "esp_price_type";
148
-        $price_table        = $wpdb->prefix . "esp_price";
149
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
150
-            $SQL                  =
151
-                'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types
152
-            $tax_price_type_count = $wpdb->get_var($SQL);
153
-            if ($tax_price_type_count <= 1) {
154
-                $wpdb->insert(
155
-                    $price_type_table,
156
-                    [
157
-                        'PRT_name'       => esc_html__("Regional Tax", "event_espresso"),
158
-                        'PBT_ID'         => 4,
159
-                        'PRT_is_percent' => true,
160
-                        'PRT_order'      => 60,
161
-                        'PRT_deleted'    => false,
162
-                        'PRT_wp_user'    => $default_creator_id,
163
-                    ],
164
-                    [
165
-                        '%s',// PRT_name
166
-                        '%d',// PBT_id
167
-                        '%d',// PRT_is_percent
168
-                        '%d',// PRT_order
169
-                        '%d',// PRT_deleted
170
-                        '%d', // PRT_wp_user
171
-                    ]
172
-                );
173
-                // federal tax
174
-                $result = $wpdb->insert(
175
-                    $price_type_table,
176
-                    [
177
-                        'PRT_name'       => esc_html__("Federal Tax", "event_espresso"),
178
-                        'PBT_ID'         => 4,
179
-                        'PRT_is_percent' => true,
180
-                        'PRT_order'      => 70,
181
-                        'PRT_deleted'    => false,
182
-                        'PRT_wp_user'    => $default_creator_id,
183
-                    ],
184
-                    [
185
-                        '%s',// PRT_name
186
-                        '%d',// PBT_id
187
-                        '%d',// PRT_is_percent
188
-                        '%d',// PRT_order
189
-                        '%d',// PRT_deleted
190
-                        '%d' // PRT_wp_user
191
-                    ]
192
-                );
193
-                if ($result) {
194
-                    $wpdb->insert(
195
-                        $price_table,
196
-                        [
197
-                            'PRT_ID'         => $wpdb->insert_id,
198
-                            'PRC_amount'     => 15.00,
199
-                            'PRC_name'       => esc_html__("Sales Tax", "event_espresso"),
200
-                            'PRC_desc'       => '',
201
-                            'PRC_is_default' => true,
202
-                            'PRC_overrides'  => null,
203
-                            'PRC_deleted'    => false,
204
-                            'PRC_order'      => 50,
205
-                            'PRC_parent'     => null,
206
-                            'PRC_wp_user'    => $default_creator_id,
207
-                        ],
208
-                        [
209
-                            '%d',// PRT_id
210
-                            '%f',// PRC_amount
211
-                            '%s',// PRC_name
212
-                            '%s',// PRC_desc
213
-                            '%d',// PRC_is_default
214
-                            '%d',// PRC_overrides
215
-                            '%d',// PRC_deleted
216
-                            '%d',// PRC_order
217
-                            '%d',// PRC_parent
218
-                            '%d' // PRC_wp_user
219
-                        ]
220
-                    );
221
-                }
222
-            }
223
-        }
224
-    }
225
-
226
-
227
-    /**
228
-     *    caffeinated_modules_to_register
229
-     *
230
-     * @access public
231
-     * @param array $modules_to_register
232
-     * @return array
233
-     */
234
-    public function caffeinated_modules_to_register($modules_to_register = [])
235
-    {
236
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
237
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules/*', GLOB_ONLYDIR);
238
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
239
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
240
-            }
241
-        }
242
-        return $modules_to_register;
243
-    }
244
-
245
-
246
-    /**
247
-     * @throws EE_Error
248
-     * @throws InvalidArgumentException
249
-     * @throws ReflectionException
250
-     * @throws InvalidDataTypeException
251
-     * @throws InvalidInterfaceException
252
-     */
253
-    public function caffeinated_init()
254
-    {
255
-        // Custom Post Type hooks
256
-        add_filter(
257
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
258
-            [$this, 'filter_taxonomies']
259
-        );
260
-        add_filter(
261
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes',
262
-            [$this, 'filter_cpts']
263
-        );
264
-        add_filter(
265
-            'FHEE__EE_Admin__get_extra_nav_menu_pages_items',
266
-            [$this, 'nav_metabox_items']
267
-        );
268
-        EE_Registry::instance()->load_file(
269
-            EE_CAFF_PATH,
270
-            'EE_Caf_Messages',
271
-            'class',
272
-            [],
273
-            false
274
-        );
275
-        // caffeinated_init__complete hook
276
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
277
-    }
278
-
279
-
280
-    public function enqueue_caffeinated_scripts()
281
-    {
282
-        // sound of crickets...
283
-    }
284
-
285
-
286
-    /**
287
-     * callbacks below here
288
-     *
289
-     * @param array $taxonomy_array
290
-     * @return array
291
-     */
292
-    public function filter_taxonomies(array $taxonomy_array)
293
-    {
294
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
295
-        return $taxonomy_array;
296
-    }
297
-
298
-
299
-    /**
300
-     * @param array $cpt_array
301
-     * @return mixed
302
-     */
303
-    public function filter_cpts(array $cpt_array)
304
-    {
305
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
306
-        return $cpt_array;
307
-    }
308
-
309
-
310
-    /**
311
-     * @param array $menuitems
312
-     * @return array
313
-     */
314
-    public function nav_metabox_items(array $menuitems)
315
-    {
316
-        $menuitems[] = [
317
-            'title'       => esc_html__('Venue List', 'event_espresso'),
318
-            'url'         => get_post_type_archive_link('espresso_venues'),
319
-            'description' => esc_html__('Archive page for all venues.', 'event_espresso'),
320
-        ];
321
-        return $menuitems;
322
-    }
323
-
324
-
325
-    /**
326
-     * Gets the injected table analyzer, or throws an exception
327
-     *
328
-     * @return TableAnalysis
329
-     * @throws \EE_Error
330
-     */
331
-    protected function _get_table_analysis()
332
-    {
333
-        if ($this->_table_analysis instanceof TableAnalysis) {
334
-            return $this->_table_analysis;
335
-        } else {
336
-            throw new \EE_Error(
337
-                sprintf(
338
-                    esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
339
-                    get_class($this)
340
-                )
341
-            );
342
-        }
343
-    }
30
+	/**
31
+	 * @var TableAnalysis $table_analysis
32
+	 */
33
+	protected $_table_analysis;
34
+
35
+
36
+	/**
37
+	 * EE_Brewing_Regular constructor.
38
+	 *
39
+	 * @param TableAnalysis $table_analysis
40
+	 */
41
+	public function __construct(TableAnalysis $table_analysis)
42
+	{
43
+		$this->_table_analysis = $table_analysis;
44
+		if (defined('EE_CAFF_PATH')) {
45
+			$this->setInitializationHooks();
46
+			$this->setApiRegistrationHooks();
47
+			$this->setSwitchHooks();
48
+			$this->setDefaultFilterHooks();
49
+			// caffeinated constructed
50
+			do_action('AHEE__EE_Brewing_Regular__construct__complete');
51
+		}
52
+	}
53
+
54
+
55
+	/**
56
+	 * Various hooks used for extending features via registration of modules or extensions.
57
+	 */
58
+	private function setApiRegistrationHooks()
59
+	{
60
+		add_filter(
61
+			'FHEE__EE_Config__register_modules__modules_to_register',
62
+			[$this, 'caffeinated_modules_to_register']
63
+		);
64
+		add_filter('FHEE__EE_Registry__load_helper__helper_paths', [$this, 'caf_helper_paths'], 10);
65
+		add_filter(
66
+			'AHEE__EE_System__load_core_configuration__complete',
67
+			function () {
68
+				EE_Register_Payment_Method::register(
69
+					'caffeinated_payment_methods',
70
+					[
71
+						'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR),
72
+					]
73
+				);
74
+			}
75
+		);
76
+	}
77
+
78
+
79
+	/**
80
+	 * Various hooks used for modifying initialization or activation processes.
81
+	 */
82
+	private function setInitializationHooks()
83
+	{
84
+		// activation
85
+		add_action('AHEE__EEH_Activation__initialize_db_content', [$this, 'initialize_caf_db_content']);
86
+		// load caff init
87
+		add_action('AHEE__EE_System__set_hooks_for_core', [$this, 'caffeinated_init']);
88
+		// load caff scripts
89
+		add_action('wp_enqueue_scripts', [$this, 'enqueue_caffeinated_scripts'], 10);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Various hooks used for switch (on/off) type filters.
95
+	 */
96
+	private function setSwitchHooks()
97
+	{
98
+		// remove the "powered by" credit link from receipts and invoices
99
+		add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
100
+		// seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
101
+		add_filter('FHEE__ee_show_affiliate_links', '__return_false');
102
+	}
103
+
104
+
105
+	/**
106
+	 * Various filters for affecting default configuration values in the caffeinated
107
+	 * context.
108
+	 */
109
+	private function setDefaultFilterHooks()
110
+	{
111
+		add_filter(
112
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
113
+			'__return_true'
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
120
+	 *
121
+	 * @param array $paths original helper paths array
122
+	 * @return array             new array of paths
123
+	 */
124
+	public function caf_helper_paths($paths)
125
+	{
126
+		$paths[] = EE_CAF_CORE . 'helpers/';
127
+		return $paths;
128
+	}
129
+
130
+
131
+	/**
132
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
133
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
134
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
135
+	 * This action should only be called when EE 4.x.0.P is initially activated.
136
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
137
+	 * we should probably create a caf file to contain it all instead just a function like this.
138
+	 * Right now, we ASSUME the only price types in the system are default ones
139
+	 *
140
+	 * @global wpdb $wpdb
141
+	 */
142
+	public function initialize_caf_db_content()
143
+	{
144
+		global $wpdb;
145
+		// use same method of getting creator id as the version introducing the change
146
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
147
+		$price_type_table   = $wpdb->prefix . "esp_price_type";
148
+		$price_table        = $wpdb->prefix . "esp_price";
149
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
150
+			$SQL                  =
151
+				'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types
152
+			$tax_price_type_count = $wpdb->get_var($SQL);
153
+			if ($tax_price_type_count <= 1) {
154
+				$wpdb->insert(
155
+					$price_type_table,
156
+					[
157
+						'PRT_name'       => esc_html__("Regional Tax", "event_espresso"),
158
+						'PBT_ID'         => 4,
159
+						'PRT_is_percent' => true,
160
+						'PRT_order'      => 60,
161
+						'PRT_deleted'    => false,
162
+						'PRT_wp_user'    => $default_creator_id,
163
+					],
164
+					[
165
+						'%s',// PRT_name
166
+						'%d',// PBT_id
167
+						'%d',// PRT_is_percent
168
+						'%d',// PRT_order
169
+						'%d',// PRT_deleted
170
+						'%d', // PRT_wp_user
171
+					]
172
+				);
173
+				// federal tax
174
+				$result = $wpdb->insert(
175
+					$price_type_table,
176
+					[
177
+						'PRT_name'       => esc_html__("Federal Tax", "event_espresso"),
178
+						'PBT_ID'         => 4,
179
+						'PRT_is_percent' => true,
180
+						'PRT_order'      => 70,
181
+						'PRT_deleted'    => false,
182
+						'PRT_wp_user'    => $default_creator_id,
183
+					],
184
+					[
185
+						'%s',// PRT_name
186
+						'%d',// PBT_id
187
+						'%d',// PRT_is_percent
188
+						'%d',// PRT_order
189
+						'%d',// PRT_deleted
190
+						'%d' // PRT_wp_user
191
+					]
192
+				);
193
+				if ($result) {
194
+					$wpdb->insert(
195
+						$price_table,
196
+						[
197
+							'PRT_ID'         => $wpdb->insert_id,
198
+							'PRC_amount'     => 15.00,
199
+							'PRC_name'       => esc_html__("Sales Tax", "event_espresso"),
200
+							'PRC_desc'       => '',
201
+							'PRC_is_default' => true,
202
+							'PRC_overrides'  => null,
203
+							'PRC_deleted'    => false,
204
+							'PRC_order'      => 50,
205
+							'PRC_parent'     => null,
206
+							'PRC_wp_user'    => $default_creator_id,
207
+						],
208
+						[
209
+							'%d',// PRT_id
210
+							'%f',// PRC_amount
211
+							'%s',// PRC_name
212
+							'%s',// PRC_desc
213
+							'%d',// PRC_is_default
214
+							'%d',// PRC_overrides
215
+							'%d',// PRC_deleted
216
+							'%d',// PRC_order
217
+							'%d',// PRC_parent
218
+							'%d' // PRC_wp_user
219
+						]
220
+					);
221
+				}
222
+			}
223
+		}
224
+	}
225
+
226
+
227
+	/**
228
+	 *    caffeinated_modules_to_register
229
+	 *
230
+	 * @access public
231
+	 * @param array $modules_to_register
232
+	 * @return array
233
+	 */
234
+	public function caffeinated_modules_to_register($modules_to_register = [])
235
+	{
236
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
237
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules/*', GLOB_ONLYDIR);
238
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
239
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
240
+			}
241
+		}
242
+		return $modules_to_register;
243
+	}
244
+
245
+
246
+	/**
247
+	 * @throws EE_Error
248
+	 * @throws InvalidArgumentException
249
+	 * @throws ReflectionException
250
+	 * @throws InvalidDataTypeException
251
+	 * @throws InvalidInterfaceException
252
+	 */
253
+	public function caffeinated_init()
254
+	{
255
+		// Custom Post Type hooks
256
+		add_filter(
257
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
258
+			[$this, 'filter_taxonomies']
259
+		);
260
+		add_filter(
261
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes',
262
+			[$this, 'filter_cpts']
263
+		);
264
+		add_filter(
265
+			'FHEE__EE_Admin__get_extra_nav_menu_pages_items',
266
+			[$this, 'nav_metabox_items']
267
+		);
268
+		EE_Registry::instance()->load_file(
269
+			EE_CAFF_PATH,
270
+			'EE_Caf_Messages',
271
+			'class',
272
+			[],
273
+			false
274
+		);
275
+		// caffeinated_init__complete hook
276
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
277
+	}
278
+
279
+
280
+	public function enqueue_caffeinated_scripts()
281
+	{
282
+		// sound of crickets...
283
+	}
284
+
285
+
286
+	/**
287
+	 * callbacks below here
288
+	 *
289
+	 * @param array $taxonomy_array
290
+	 * @return array
291
+	 */
292
+	public function filter_taxonomies(array $taxonomy_array)
293
+	{
294
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
295
+		return $taxonomy_array;
296
+	}
297
+
298
+
299
+	/**
300
+	 * @param array $cpt_array
301
+	 * @return mixed
302
+	 */
303
+	public function filter_cpts(array $cpt_array)
304
+	{
305
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
306
+		return $cpt_array;
307
+	}
308
+
309
+
310
+	/**
311
+	 * @param array $menuitems
312
+	 * @return array
313
+	 */
314
+	public function nav_metabox_items(array $menuitems)
315
+	{
316
+		$menuitems[] = [
317
+			'title'       => esc_html__('Venue List', 'event_espresso'),
318
+			'url'         => get_post_type_archive_link('espresso_venues'),
319
+			'description' => esc_html__('Archive page for all venues.', 'event_espresso'),
320
+		];
321
+		return $menuitems;
322
+	}
323
+
324
+
325
+	/**
326
+	 * Gets the injected table analyzer, or throws an exception
327
+	 *
328
+	 * @return TableAnalysis
329
+	 * @throws \EE_Error
330
+	 */
331
+	protected function _get_table_analysis()
332
+	{
333
+		if ($this->_table_analysis instanceof TableAnalysis) {
334
+			return $this->_table_analysis;
335
+		} else {
336
+			throw new \EE_Error(
337
+				sprintf(
338
+					esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
339
+					get_class($this)
340
+				)
341
+			);
342
+		}
343
+	}
344 344
 }
345 345
 
346 346
 
347 347
 $brewing = new EE_Brewing_Regular(
348
-    EE_Registry::instance()->create('TableAnalysis', [], true)
348
+	EE_Registry::instance()->create('TableAnalysis', [], true)
349 349
 );
Please login to merge, or discard this patch.
core/libraries/messages/validators/EE_Messages_Validator.core.php 2 patches
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
         // load messenger
157 157
         $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
158 158
         $messenger = str_replace(' ', '_', $messenger);
159
-        $messenger = 'EE_' . $messenger . '_messenger';
159
+        $messenger = 'EE_'.$messenger.'_messenger';
160 160
 
161
-        if (! class_exists($messenger)) {
161
+        if ( ! class_exists($messenger)) {
162 162
             throw new EE_Error(
163 163
                 sprintf(
164 164
                     esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
         // load message type
173 173
         $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
174 174
         $message_type = str_replace(' ', '_', $message_type);
175
-        $message_type = 'EE_' . $message_type . '_message_type';
175
+        $message_type = 'EE_'.$message_type.'_message_type';
176 176
 
177
-        if (! class_exists($message_type)) {
177
+        if ( ! class_exists($message_type)) {
178 178
             throw new EE_Error(
179 179
                 sprintf(
180 180
                     esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 
207 207
         // we only want the valid shortcodes for the given context!
208 208
         $context  = $this->_context;
209
-        $mt_codes = $mt_codes[ $context ];
209
+        $mt_codes = $mt_codes[$context];
210 210
 
211 211
         // in this first loop we're just getting all shortcode group indexes from the msgr_validator
212 212
         // into a single array (so we can get the appropriate shortcode objects for the groups)
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
             if (empty($config) || ! isset($config['shortcodes'])) {
218 218
                 continue;
219 219
             }  //Nothing to see here.
220
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
220
+            $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes);
221 221
             $shortcode_groups           = array_merge($config['shortcodes'], $shortcode_groups);
222 222
         }
223 223
 
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
         foreach ($shortcode_groups as $group) {
231 231
             $ref       = ucwords(str_replace('_', ' ', $group));
232 232
             $ref       = str_replace(' ', '_', $ref);
233
-            $classname = 'EE_' . $ref . '_Shortcodes';
233
+            $classname = 'EE_'.$ref.'_Shortcodes';
234 234
             if (class_exists($classname)) {
235 235
                 $a                         = new ReflectionClass($classname);
236 236
                 $obj                       = $a->newInstance();
237
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
237
+                $codes_from_objs[$group] = $obj->get_shortcodes();
238 238
             }
239 239
         }
240 240
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
243 243
         $final_mt_codes = [];
244 244
         foreach ($mt_codes as $group) {
245
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
245
+            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]);
246 246
         }
247 247
 
248 248
         $mt_codes = $final_mt_codes;
@@ -260,44 +260,44 @@  discard block
 block discarded – undo
260 260
             }
261 261
 
262 262
             // If we have an override then we use it to indicate the codes we want.
263
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
264
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
265
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
263
+            if (isset($this->_valid_shortcodes_modifier[$context][$field])) {
264
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
265
+                    $this->_valid_shortcodes_modifier[$context][$field],
266 266
                     $codes_from_objs
267 267
                 );
268
-            } elseif (isset($groups_per_field[ $field ])) {
268
+            } elseif (isset($groups_per_field[$field])) {
269 269
                 // we have specific shortcodes for a field so we need to use them
270
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
271
-                    $groups_per_field[ $field ],
270
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
271
+                    $groups_per_field[$field],
272 272
                     $codes_from_objs
273 273
                 );
274 274
             } elseif (empty($config)) {
275 275
                 // no config so we're assuming we're just going to use the shortcodes from the message type context
276
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
276
+                $this->_validators[$field]['shortcodes'] = $mt_codes;
277 277
             } elseif (isset($config['specific_shortcodes'])) {
278 278
                 // we have specific shortcodes so we need to use them
279
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
279
+                $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes'];
280 280
             } else {
281 281
                 // otherwise the shortcodes are what is set by the messenger for that field
282 282
                 foreach ($config['shortcodes'] as $group) {
283
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
284
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
285
-                        : $codes_from_objs[ $group ];
283
+                    $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes'])
284
+                        ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group])
285
+                        : $codes_from_objs[$group];
286 286
                 }
287 287
             }
288 288
 
289 289
             // now let's just make sure that any excluded specific shortcodes are removed.
290 290
             $specific_excludes = $this->get_specific_shortcode_excludes();
291
-            if (isset($specific_excludes[ $field ])) {
292
-                foreach ($specific_excludes[ $field ] as $sex) {
293
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
294
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
291
+            if (isset($specific_excludes[$field])) {
292
+                foreach ($specific_excludes[$field] as $sex) {
293
+                    if (isset($this->_validators[$field]['shortcodes'][$sex])) {
294
+                        unset($this->_validators[$field]['shortcodes'][$sex]);
295 295
                     }
296 296
                 }
297 297
             }
298 298
 
299 299
             // hey! don't forget to include the type if present!
300
-            $this->_validators[ $field ]['type'] =
300
+            $this->_validators[$field]['type'] =
301 301
                 isset($config['type'])
302 302
                     ? $config['type']
303 303
                     : null;
@@ -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
         );
@@ -354,21 +354,21 @@  discard block
 block discarded – undo
354 354
         $template_fields = $this->_messenger->get_template_fields();
355 355
         // loop through the fields and check!
356 356
         foreach ($this->_fields as $field => $value) {
357
-            $this->_errors[ $field ] = [];
357
+            $this->_errors[$field] = [];
358 358
             $err_msg                 = '';
359 359
             $field_label             = '';
360 360
             // if field is not present in the _validators array then we continue
361
-            if (! isset($this->_validators[ $field ])) {
362
-                unset($this->_errors[ $field ]);
361
+            if ( ! isset($this->_validators[$field])) {
362
+                unset($this->_errors[$field]);
363 363
                 continue;
364 364
             }
365 365
 
366 366
             // get the translated field label!
367 367
             // first check if it's in the main fields list
368
-            if (isset($template_fields[ $field ])) {
368
+            if (isset($template_fields[$field])) {
369 369
                 // most likely the field is found in the 'extra' array.
370
-                $field_label = ! empty($template_fields[ $field ])
371
-                    ? $template_fields[ $field ]['label']
370
+                $field_label = ! empty($template_fields[$field])
371
+                    ? $template_fields[$field]['label']
372 372
                     : $field;
373 373
             }
374 374
 
@@ -392,20 +392,20 @@  discard block
 block discarded – undo
392 392
 
393 393
             // field is present. Let's validate shortcodes first (but only if shortcodes present).
394 394
             if (
395
-                isset($this->_validators[ $field ]['shortcodes'])
396
-                && ! empty($this->_validators[ $field ]['shortcodes'])
395
+                isset($this->_validators[$field]['shortcodes'])
396
+                && ! empty($this->_validators[$field]['shortcodes'])
397 397
             ) {
398
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
398
+                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']);
399 399
                 // if true then that means there is a returned error message
400 400
                 // that we'll need to add to the _errors array for this field.
401 401
                 if ($invalid_shortcodes) {
402
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
402
+                    $v_s     = array_keys($this->_validators[$field]['shortcodes']);
403 403
                     $err_msg = sprintf(
404 404
                         esc_html__(
405 405
                             '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
406 406
                             'event_espresso'
407 407
                         ),
408
-                        '<strong>' . $field_label . '</strong>',
408
+                        '<strong>'.$field_label.'</strong>',
409 409
                         $invalid_shortcodes,
410 410
                         '<p>',
411 411
                         '</p >'
@@ -420,10 +420,10 @@  discard block
 block discarded – undo
420 420
             }
421 421
 
422 422
             // if there's a "type" to be validated then let's do that too.
423
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
424
-                switch ($this->_validators[ $field ]['type']) {
423
+            if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) {
424
+                switch ($this->_validators[$field]['type']) {
425 425
                     case 'number':
426
-                        if (! is_numeric($value)) {
426
+                        if ( ! is_numeric($value)) {
427 427
                             $err_msg .= sprintf(
428 428
                                 esc_html__(
429 429
                                     '%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',
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
                         break;
439 439
                     case 'email':
440 440
                         $valid_email = $this->_validate_email($value);
441
-                        if (! $valid_email) {
441
+                        if ( ! $valid_email) {
442 442
                             $err_msg .= htmlentities(
443 443
                                 sprintf(
444 444
                                     esc_html__(
@@ -456,18 +456,18 @@  discard block
 block discarded – undo
456 456
             }
457 457
 
458 458
             // if $err_msg isn't empty let's setup the _errors array for this field.
459
-            if (! empty($err_msg)) {
460
-                $this->_errors[ $field ]['msg'] = $err_msg;
459
+            if ( ! empty($err_msg)) {
460
+                $this->_errors[$field]['msg'] = $err_msg;
461 461
             } else {
462
-                unset($this->_errors[ $field ]);
462
+                unset($this->_errors[$field]);
463 463
             }
464 464
         }
465 465
 
466 466
         // if we have ANY errors, then we want to make sure we return the values
467 467
         // for ALL the fields so the user doesn't have to retype them all.
468
-        if (! empty($this->_errors)) {
468
+        if ( ! empty($this->_errors)) {
469 469
             foreach ($this->_fields as $field => $value) {
470
-                $this->_errors[ $field ]['value'] = stripslashes($value);
470
+                $this->_errors[$field]['value'] = stripslashes($value);
471 471
             }
472 472
         }
473 473
 
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
     {
491 491
         $shortcodes = [];
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
-        return '<strong>' . $invalid_shortcodes . '</strong>';
535
+        return '<strong>'.$invalid_shortcodes.'</strong>';
536 536
     }
537 537
 
538 538
 
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
         // its possible that this message is being "turned off" for a particular context
569 569
 
570 570
 
571
-        if (! empty($or_val) && empty($value)) {
571
+        if ( ! empty($or_val) && empty($value)) {
572 572
             return $validate;
573 573
         }
574 574
 
@@ -627,8 +627,8 @@  discard block
 block discarded – undo
627 627
             '_MSGTYP' => '_message_type',
628 628
         ];
629 629
 
630
-        if (isset($expected_properties_map[ $property ])) {
631
-            return $this->{$expected_properties_map[ $property ]};
630
+        if (isset($expected_properties_map[$property])) {
631
+            return $this->{$expected_properties_map[$property]};
632 632
         }
633 633
 
634 634
         throw new Exception(
Please login to merge, or discard this patch.
Indentation   +622 added lines, -622 removed lines patch added patch discarded remove patch
@@ -15,626 +15,626 @@
 block discarded – undo
15 15
  */
16 16
 abstract class EE_Messages_Validator extends EE_Base
17 17
 {
18
-    /**
19
-     * These properties just hold the name for the Messenger and Message Type (defined by child classes).
20
-     * These are used for retrieving objects etc.
21
-     *
22
-     * @var string
23
-     */
24
-    protected $_m_name;
25
-
26
-    protected $_mt_name;
27
-
28
-
29
-    /**
30
-     * This will hold any error messages from the validation process.
31
-     * The _errors property holds an associative array of error messages
32
-     * listing the field as the key and the message as the value.
33
-     *
34
-     * @var array()
35
-     */
36
-    private $_errors = [];
37
-
38
-
39
-    /**
40
-     * holds an array of fields being validated
41
-     *
42
-     * @var array
43
-     */
44
-    protected $_fields;
45
-
46
-
47
-    /**
48
-     * this will hold the incoming context
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_context;
53
-
54
-
55
-    /**
56
-     * this holds an array of fields and the relevant validation information
57
-     * that the incoming fields data get validated against.
58
-     * This gets setup in the _set_props() method.
59
-     *
60
-     * @var array
61
-     */
62
-    protected $_validators;
63
-
64
-
65
-    /**
66
-     * holds the messenger object
67
-     *
68
-     * @var object
69
-     */
70
-    protected $_messenger;
71
-
72
-
73
-    /**
74
-     * holds the message type object
75
-     *
76
-     * @var object
77
-     */
78
-    protected $_message_type;
79
-
80
-
81
-    /**
82
-     * will hold any valid_shortcode modifications made by the _modify_validator() method.
83
-     *
84
-     * @var array
85
-     */
86
-    protected $_valid_shortcodes_modifier;
87
-
88
-
89
-    /**
90
-     * There may be times where a message type wants to include a shortcode group but exclude specific
91
-     * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
92
-     * they will not be allowed.
93
-     * Array should be indexed by field and values are an array of specific shortcodes to exclude.
94
-     *
95
-     * @var array
96
-     */
97
-    protected $_specific_shortcode_excludes = [];
98
-
99
-
100
-    /**
101
-     * Runs the validator using the incoming fields array as the fields/values to check.
102
-     *
103
-     * @param array $fields The fields sent by the EEM object.
104
-     * @param       $context
105
-     * @throws EE_Error
106
-     * @throws ReflectionException
107
-     */
108
-    public function __construct($fields, $context)
109
-    {
110
-        // check that _m_name and _mt_name have been set by child class otherwise we get out.
111
-        if (empty($this->_m_name) || empty($this->_mt_name)) {
112
-            throw new EE_Error(
113
-                esc_html__(
114
-                    'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
115
-                    'event_espresso'
116
-                )
117
-            );
118
-        }
119
-        $this->_fields  = $fields;
120
-        $this->_context = $context;
121
-
122
-        // load messenger and message_type objects and the related shortcode objects.
123
-        $this->_load_objects();
124
-
125
-
126
-        // modify any messenger/message_type specific validation instructions.  This is what child classes define.
127
-        $this->_modify_validator();
128
-
129
-
130
-        // let's set validators property
131
-        $this->_set_validators();
132
-    }
133
-
134
-
135
-    /**
136
-     * Child classes instantiate this and use it to modify the _validator_config array property
137
-     * for the messenger using messengers set_validate_config() method.
138
-     * This is so we can specify specific validation instructions for a messenger/message_type combo
139
-     * that aren't handled by the defaults setup in the messenger.
140
-     *
141
-     * @abstract
142
-     * @return void
143
-     */
144
-    abstract protected function _modify_validator();
145
-
146
-
147
-    /**
148
-     * loads all objects used by validator
149
-     *
150
-     * @throws EE_Error
151
-     */
152
-    private function _load_objects()
153
-    {
154
-        // load messenger
155
-        $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
156
-        $messenger = str_replace(' ', '_', $messenger);
157
-        $messenger = 'EE_' . $messenger . '_messenger';
158
-
159
-        if (! class_exists($messenger)) {
160
-            throw new EE_Error(
161
-                sprintf(
162
-                    esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
163
-                    $this->_m_name
164
-                )
165
-            );
166
-        }
167
-
168
-        $this->_messenger = new $messenger();
169
-
170
-        // load message type
171
-        $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
172
-        $message_type = str_replace(' ', '_', $message_type);
173
-        $message_type = 'EE_' . $message_type . '_message_type';
174
-
175
-        if (! class_exists($message_type)) {
176
-            throw new EE_Error(
177
-                sprintf(
178
-                    esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
179
-                    $this->_mt_name
180
-                )
181
-            );
182
-        }
183
-
184
-        $this->_message_type = new $message_type();
185
-    }
186
-
187
-
188
-    /**
189
-     * used to set the $_validators property
190
-     *
191
-     * @return void
192
-     * @throws ReflectionException
193
-     */
194
-    private function _set_validators()
195
-    {
196
-        // let's get all valid shortcodes from mt and message type
197
-        // (messenger will have its set in the _validator_config property for the messenger)
198
-        $mt_codes = $this->_message_type->get_valid_shortcodes();
199
-
200
-
201
-        // get messenger validator_config
202
-        $msgr_validator = $this->_messenger->get_validator_config();
203
-
204
-
205
-        // we only want the valid shortcodes for the given context!
206
-        $context  = $this->_context;
207
-        $mt_codes = $mt_codes[ $context ];
208
-
209
-        // in this first loop we're just getting all shortcode group indexes from the msgr_validator
210
-        // into a single array (so we can get the appropriate shortcode objects for the groups)
211
-        $shortcode_groups = $mt_codes;
212
-        $groups_per_field = [];
213
-
214
-        foreach ($msgr_validator as $field => $config) {
215
-            if (empty($config) || ! isset($config['shortcodes'])) {
216
-                continue;
217
-            }  //Nothing to see here.
218
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
219
-            $shortcode_groups           = array_merge($config['shortcodes'], $shortcode_groups);
220
-        }
221
-
222
-        $shortcode_groups = array_unique($shortcode_groups);
223
-
224
-        // okay now we've got our groups.
225
-        // Let's get the codes from the objects into an array indexed by group for easy retrieval later.
226
-        $codes_from_objs = [];
227
-
228
-        foreach ($shortcode_groups as $group) {
229
-            $ref       = ucwords(str_replace('_', ' ', $group));
230
-            $ref       = str_replace(' ', '_', $ref);
231
-            $classname = 'EE_' . $ref . '_Shortcodes';
232
-            if (class_exists($classname)) {
233
-                $a                         = new ReflectionClass($classname);
234
-                $obj                       = $a->newInstance();
235
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
236
-            }
237
-        }
238
-
239
-
240
-        // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
241
-        $final_mt_codes = [];
242
-        foreach ($mt_codes as $group) {
243
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
244
-        }
245
-
246
-        $mt_codes = $final_mt_codes;
247
-
248
-
249
-        // k now in this next loop we're going to loop through $msgr_validator again
250
-        // and setup the _validators property from the data we've setup so far.
251
-        foreach ($msgr_validator as $field => $config) {
252
-            // if required shortcode is not in our list of codes for the given field, then we skip this field.
253
-            $required = isset($config['required'])
254
-                ? array_intersect($config['required'], array_keys($mt_codes))
255
-                : true;
256
-            if (empty($required)) {
257
-                continue;
258
-            }
259
-
260
-            // If we have an override then we use it to indicate the codes we want.
261
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
262
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
263
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
264
-                    $codes_from_objs
265
-                );
266
-            } elseif (isset($groups_per_field[ $field ])) {
267
-                // we have specific shortcodes for a field so we need to use them
268
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
269
-                    $groups_per_field[ $field ],
270
-                    $codes_from_objs
271
-                );
272
-            } elseif (empty($config)) {
273
-                // no config so we're assuming we're just going to use the shortcodes from the message type context
274
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
275
-            } elseif (isset($config['specific_shortcodes'])) {
276
-                // we have specific shortcodes so we need to use them
277
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
278
-            } else {
279
-                // otherwise the shortcodes are what is set by the messenger for that field
280
-                foreach ($config['shortcodes'] as $group) {
281
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
282
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
283
-                        : $codes_from_objs[ $group ];
284
-                }
285
-            }
286
-
287
-            // now let's just make sure that any excluded specific shortcodes are removed.
288
-            $specific_excludes = $this->get_specific_shortcode_excludes();
289
-            if (isset($specific_excludes[ $field ])) {
290
-                foreach ($specific_excludes[ $field ] as $sex) {
291
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
292
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
293
-                    }
294
-                }
295
-            }
296
-
297
-            // hey! don't forget to include the type if present!
298
-            $this->_validators[ $field ]['type'] =
299
-                isset($config['type'])
300
-                    ? $config['type']
301
-                    : null;
302
-        }
303
-    }
304
-
305
-
306
-    /**
307
-     * This just returns the validators property that contains information
308
-     * about the various shortcodes and their availability with each field
309
-     *
310
-     * @return array
311
-     */
312
-    public function get_validators()
313
-    {
314
-        return $this->_validators;
315
-    }
316
-
317
-
318
-    /**
319
-     * This simply returns the specific shortcode_excludes property that is set.
320
-     *
321
-     * @return array
322
-     * @since 4.5.0
323
-     */
324
-    public function get_specific_shortcode_excludes()
325
-    {
326
-        // specific validator filter
327
-        $shortcode_excludes = apply_filters(
328
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
329
-            $this->_specific_shortcode_excludes,
330
-            $this->_context
331
-        );
332
-        // global filter
333
-        return apply_filters(
334
-            'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
335
-            $shortcode_excludes,
336
-            $this->_context,
337
-            $this
338
-        );
339
-    }
340
-
341
-
342
-    /**
343
-     * This is the main method that handles validation
344
-     * What it does is loop through the _fields (the ones that get validated)
345
-     * and checks them against the shortcodes array for the field and the 'type' indicated by the
346
-     *
347
-     * @return array|bool if errors present we return the array otherwise true
348
-     */
349
-    public function validate()
350
-    {
351
-        // some defaults
352
-        $template_fields = $this->_messenger->get_template_fields();
353
-        // loop through the fields and check!
354
-        foreach ($this->_fields as $field => $value) {
355
-            $this->_errors[ $field ] = [];
356
-            $err_msg                 = '';
357
-            $field_label             = '';
358
-            // if field is not present in the _validators array then we continue
359
-            if (! isset($this->_validators[ $field ])) {
360
-                unset($this->_errors[ $field ]);
361
-                continue;
362
-            }
363
-
364
-            // get the translated field label!
365
-            // first check if it's in the main fields list
366
-            if (isset($template_fields[ $field ])) {
367
-                // most likely the field is found in the 'extra' array.
368
-                $field_label = ! empty($template_fields[ $field ])
369
-                    ? $template_fields[ $field ]['label']
370
-                    : $field;
371
-            }
372
-
373
-            // if field label is empty OR is equal to the current field
374
-            // then we need to loop through the 'extra' fields in the template_fields config (if present)
375
-            if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
376
-                foreach ($template_fields['extra'] as $main_field => $secondary_field) {
377
-                    foreach ($secondary_field as $name => $values) {
378
-                        if ($name === $field) {
379
-                            $field_label = $values['label'];
380
-                        }
381
-
382
-                        // if we've got a 'main' secondary field, let's see if that matches what field we're on
383
-                        // which means it contains the label for this field.
384
-                        if ($name === 'main' && $main_field === $field_label) {
385
-                            $field_label = $values['label'];
386
-                        }
387
-                    }
388
-                }
389
-            }
390
-
391
-            // field is present. Let's validate shortcodes first (but only if shortcodes present).
392
-            if (
393
-                isset($this->_validators[ $field ]['shortcodes'])
394
-                && ! empty($this->_validators[ $field ]['shortcodes'])
395
-            ) {
396
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
397
-                // if true then that means there is a returned error message
398
-                // that we'll need to add to the _errors array for this field.
399
-                if ($invalid_shortcodes) {
400
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
401
-                    $err_msg = sprintf(
402
-                        esc_html__(
403
-                            '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
404
-                            'event_espresso'
405
-                        ),
406
-                        '<strong>' . $field_label . '</strong>',
407
-                        $invalid_shortcodes,
408
-                        '<p>',
409
-                        '</p >'
410
-                    );
411
-                    $err_msg .= sprintf(
412
-                        esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
413
-                        implode(', ', $v_s),
414
-                        '<strong>',
415
-                        '</strong>'
416
-                    );
417
-                }
418
-            }
419
-
420
-            // if there's a "type" to be validated then let's do that too.
421
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
422
-                switch ($this->_validators[ $field ]['type']) {
423
-                    case 'number':
424
-                        if (! is_numeric($value)) {
425
-                            $err_msg .= sprintf(
426
-                                esc_html__(
427
-                                    '%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',
428
-                                    'event_espresso'
429
-                                ),
430
-                                $field_label,
431
-                                $value,
432
-                                '<p>',
433
-                                '</p >'
434
-                            );
435
-                        }
436
-                        break;
437
-                    case 'email':
438
-                        $valid_email = $this->_validate_email($value);
439
-                        if (! $valid_email) {
440
-                            $err_msg .= htmlentities(
441
-                                sprintf(
442
-                                    esc_html__(
443
-                                        '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.',
444
-                                        'event_espresso'
445
-                                    ),
446
-                                    $field_label
447
-                                )
448
-                            );
449
-                        }
450
-                        break;
451
-                    default:
452
-                        break;
453
-                }
454
-            }
455
-
456
-            // if $err_msg isn't empty let's setup the _errors array for this field.
457
-            if (! empty($err_msg)) {
458
-                $this->_errors[ $field ]['msg'] = $err_msg;
459
-            } else {
460
-                unset($this->_errors[ $field ]);
461
-            }
462
-        }
463
-
464
-        // if we have ANY errors, then we want to make sure we return the values
465
-        // for ALL the fields so the user doesn't have to retype them all.
466
-        if (! empty($this->_errors)) {
467
-            foreach ($this->_fields as $field => $value) {
468
-                $this->_errors[ $field ]['value'] = stripslashes($value);
469
-            }
470
-        }
471
-
472
-        // return any errors or just TRUE if everything validates
473
-        return empty($this->_errors)
474
-            ? true
475
-            : $this->_errors;
476
-    }
477
-
478
-
479
-    /**
480
-     * Reassembles and returns an array of valid shortcodes
481
-     * given the array of groups and array of shortcodes indexed by group.
482
-     *
483
-     * @param array $groups          array of shortcode groups that we want shortcodes for
484
-     * @param array $codes_from_objs All the codes available.
485
-     * @return array                   an array of actual shortcodes (that will be used for validation).
486
-     */
487
-    private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
488
-    {
489
-        $shortcodes = [];
490
-        foreach ($groups as $group) {
491
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
492
-        }
493
-        return $shortcodes;
494
-    }
495
-
496
-
497
-    /**
498
-     * Validates a string against a list of accepted shortcodes
499
-     * This function takes in an array of shortcodes
500
-     * and makes sure that the given string ONLY contains shortcodes in that array.
501
-     *
502
-     * @param string $value            string to evaluate
503
-     * @param array  $valid_shortcodes array of shortcodes that are acceptable.
504
-     * @return bool|string  return either a list of invalid shortcodes OR false if the shortcodes validate.
505
-     */
506
-    protected function _invalid_shortcodes($value, $valid_shortcodes)
507
-    {
508
-        // first we need to go through the string and get the shortcodes in the string
509
-        preg_match_all('/(\[.+?\])/', $value, $matches);
510
-        $incoming_shortcodes = (array) $matches[0];
511
-
512
-        // get a diff of the shortcodes in the string vs the valid shortcodes
513
-        $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
514
-
515
-        // we need to account for custom codes so let's loop through the diff and remove any of those type of codes
516
-        foreach ($diff as $ind => $code) {
517
-            if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
518
-                // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
519
-                $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
520
-                // does this exist in the $valid_shortcodes?  If so then unset.
521
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
522
-                    unset($diff[ $ind ]);
523
-                }
524
-            }
525
-        }
526
-
527
-        if (empty($diff)) {
528
-            return false;
529
-        } //there is no diff, we have no invalid shortcodes, so return
530
-
531
-        // made it here? then let's assemble the error message
532
-        $invalid_shortcodes = implode('</strong>,<strong>', $diff);
533
-        return '<strong>' . $invalid_shortcodes . '</strong>';
534
-    }
535
-
536
-
537
-    /**
538
-     * Validates an incoming string and makes sure we have valid emails in the string.
539
-     *
540
-     * @param string $value incoming value to validate
541
-     * @return bool        true if the string validates, false if it doesn't
542
-     */
543
-    protected function _validate_email($value)
544
-    {
545
-        $validate = true;
546
-        $or_val   = $value;
547
-
548
-        // empty strings will validate because this is how a message template
549
-        // for a particular context can be "turned off" (if there is no email then no message)
550
-        if (empty($value)) {
551
-            return $validate;
552
-        }
553
-
554
-        // first determine if there ARE any shortcodes.
555
-        // If there are shortcodes and then later we find that there were no other valid emails
556
-        // but the field isn't empty...
557
-        // that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
558
-        $has_shortcodes = preg_match('/(\[.+?\])/', $value);
559
-
560
-        // first we need to strip out all the shortcodes!
561
-        $value = preg_replace('/(\[.+?\])/', '', $value);
562
-
563
-        // if original value is not empty and new value is, then we've parsed out a shortcode
564
-        // and we now have an empty string which DOES validate.
565
-        // We also validate complete empty field for email because
566
-        // its possible that this message is being "turned off" for a particular context
567
-
568
-
569
-        if (! empty($or_val) && empty($value)) {
570
-            return $validate;
571
-        }
572
-
573
-        // trim any commas from beginning and end of string ( after whitespace trimmed );
574
-        $value = trim(trim($value), ',');
575
-
576
-
577
-        // next we need to split up the string if its comma delimited.
578
-        $emails = explode(',', $value);
579
-        $empty  = false; // used to indicate that there is an empty comma.
580
-        // now let's loop through the emails and do our checks
581
-        foreach ($emails as $email) {
582
-            if (empty($email)) {
583
-                $empty = true;
584
-                continue;
585
-            }
586
-
587
-            // trim whitespace
588
-            $email = trim($email);
589
-            // either its of type "[email protected]", or its of type "fname lname <[email protected]>"
590
-            if (is_email($email)) {
591
-                continue;
592
-            }
593
-            $matches  = [];
594
-            $validate = (bool) preg_match('/(.*)<(.+)>/', $email, $matches);
595
-            if ($validate && is_email($matches[2])) {
596
-                continue;
597
-            }
598
-            return false;
599
-        }
600
-
601
-        return $empty && ! $has_shortcodes
602
-            ? false
603
-            : $validate;
604
-    }
605
-
606
-
607
-    /**
608
-     * Magic getter
609
-     * Using this to provide back compat with add-ons referencing deprecated properties.
610
-     *
611
-     * @param string $property Property being requested
612
-     * @return mixed
613
-     * @throws Exception
614
-     */
615
-    public function __get($property)
616
-    {
617
-        $expected_properties_map = [
618
-            /**
619
-             * @deprecated 4.9.0
620
-             */
621
-            '_MSGR'   => '_messenger',
622
-            /**
623
-             * @deprecated 4.9.0
624
-             */
625
-            '_MSGTYP' => '_message_type',
626
-        ];
627
-
628
-        if (isset($expected_properties_map[ $property ])) {
629
-            return $this->{$expected_properties_map[ $property ]};
630
-        }
631
-
632
-        throw new Exception(
633
-            sprintf(
634
-                esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
635
-                $property,
636
-                get_class($this)
637
-            )
638
-        );
639
-    }
18
+	/**
19
+	 * These properties just hold the name for the Messenger and Message Type (defined by child classes).
20
+	 * These are used for retrieving objects etc.
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $_m_name;
25
+
26
+	protected $_mt_name;
27
+
28
+
29
+	/**
30
+	 * This will hold any error messages from the validation process.
31
+	 * The _errors property holds an associative array of error messages
32
+	 * listing the field as the key and the message as the value.
33
+	 *
34
+	 * @var array()
35
+	 */
36
+	private $_errors = [];
37
+
38
+
39
+	/**
40
+	 * holds an array of fields being validated
41
+	 *
42
+	 * @var array
43
+	 */
44
+	protected $_fields;
45
+
46
+
47
+	/**
48
+	 * this will hold the incoming context
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_context;
53
+
54
+
55
+	/**
56
+	 * this holds an array of fields and the relevant validation information
57
+	 * that the incoming fields data get validated against.
58
+	 * This gets setup in the _set_props() method.
59
+	 *
60
+	 * @var array
61
+	 */
62
+	protected $_validators;
63
+
64
+
65
+	/**
66
+	 * holds the messenger object
67
+	 *
68
+	 * @var object
69
+	 */
70
+	protected $_messenger;
71
+
72
+
73
+	/**
74
+	 * holds the message type object
75
+	 *
76
+	 * @var object
77
+	 */
78
+	protected $_message_type;
79
+
80
+
81
+	/**
82
+	 * will hold any valid_shortcode modifications made by the _modify_validator() method.
83
+	 *
84
+	 * @var array
85
+	 */
86
+	protected $_valid_shortcodes_modifier;
87
+
88
+
89
+	/**
90
+	 * There may be times where a message type wants to include a shortcode group but exclude specific
91
+	 * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
92
+	 * they will not be allowed.
93
+	 * Array should be indexed by field and values are an array of specific shortcodes to exclude.
94
+	 *
95
+	 * @var array
96
+	 */
97
+	protected $_specific_shortcode_excludes = [];
98
+
99
+
100
+	/**
101
+	 * Runs the validator using the incoming fields array as the fields/values to check.
102
+	 *
103
+	 * @param array $fields The fields sent by the EEM object.
104
+	 * @param       $context
105
+	 * @throws EE_Error
106
+	 * @throws ReflectionException
107
+	 */
108
+	public function __construct($fields, $context)
109
+	{
110
+		// check that _m_name and _mt_name have been set by child class otherwise we get out.
111
+		if (empty($this->_m_name) || empty($this->_mt_name)) {
112
+			throw new EE_Error(
113
+				esc_html__(
114
+					'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
115
+					'event_espresso'
116
+				)
117
+			);
118
+		}
119
+		$this->_fields  = $fields;
120
+		$this->_context = $context;
121
+
122
+		// load messenger and message_type objects and the related shortcode objects.
123
+		$this->_load_objects();
124
+
125
+
126
+		// modify any messenger/message_type specific validation instructions.  This is what child classes define.
127
+		$this->_modify_validator();
128
+
129
+
130
+		// let's set validators property
131
+		$this->_set_validators();
132
+	}
133
+
134
+
135
+	/**
136
+	 * Child classes instantiate this and use it to modify the _validator_config array property
137
+	 * for the messenger using messengers set_validate_config() method.
138
+	 * This is so we can specify specific validation instructions for a messenger/message_type combo
139
+	 * that aren't handled by the defaults setup in the messenger.
140
+	 *
141
+	 * @abstract
142
+	 * @return void
143
+	 */
144
+	abstract protected function _modify_validator();
145
+
146
+
147
+	/**
148
+	 * loads all objects used by validator
149
+	 *
150
+	 * @throws EE_Error
151
+	 */
152
+	private function _load_objects()
153
+	{
154
+		// load messenger
155
+		$messenger = ucwords(str_replace('_', ' ', $this->_m_name));
156
+		$messenger = str_replace(' ', '_', $messenger);
157
+		$messenger = 'EE_' . $messenger . '_messenger';
158
+
159
+		if (! class_exists($messenger)) {
160
+			throw new EE_Error(
161
+				sprintf(
162
+					esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
163
+					$this->_m_name
164
+				)
165
+			);
166
+		}
167
+
168
+		$this->_messenger = new $messenger();
169
+
170
+		// load message type
171
+		$message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
172
+		$message_type = str_replace(' ', '_', $message_type);
173
+		$message_type = 'EE_' . $message_type . '_message_type';
174
+
175
+		if (! class_exists($message_type)) {
176
+			throw new EE_Error(
177
+				sprintf(
178
+					esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
179
+					$this->_mt_name
180
+				)
181
+			);
182
+		}
183
+
184
+		$this->_message_type = new $message_type();
185
+	}
186
+
187
+
188
+	/**
189
+	 * used to set the $_validators property
190
+	 *
191
+	 * @return void
192
+	 * @throws ReflectionException
193
+	 */
194
+	private function _set_validators()
195
+	{
196
+		// let's get all valid shortcodes from mt and message type
197
+		// (messenger will have its set in the _validator_config property for the messenger)
198
+		$mt_codes = $this->_message_type->get_valid_shortcodes();
199
+
200
+
201
+		// get messenger validator_config
202
+		$msgr_validator = $this->_messenger->get_validator_config();
203
+
204
+
205
+		// we only want the valid shortcodes for the given context!
206
+		$context  = $this->_context;
207
+		$mt_codes = $mt_codes[ $context ];
208
+
209
+		// in this first loop we're just getting all shortcode group indexes from the msgr_validator
210
+		// into a single array (so we can get the appropriate shortcode objects for the groups)
211
+		$shortcode_groups = $mt_codes;
212
+		$groups_per_field = [];
213
+
214
+		foreach ($msgr_validator as $field => $config) {
215
+			if (empty($config) || ! isset($config['shortcodes'])) {
216
+				continue;
217
+			}  //Nothing to see here.
218
+			$groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
219
+			$shortcode_groups           = array_merge($config['shortcodes'], $shortcode_groups);
220
+		}
221
+
222
+		$shortcode_groups = array_unique($shortcode_groups);
223
+
224
+		// okay now we've got our groups.
225
+		// Let's get the codes from the objects into an array indexed by group for easy retrieval later.
226
+		$codes_from_objs = [];
227
+
228
+		foreach ($shortcode_groups as $group) {
229
+			$ref       = ucwords(str_replace('_', ' ', $group));
230
+			$ref       = str_replace(' ', '_', $ref);
231
+			$classname = 'EE_' . $ref . '_Shortcodes';
232
+			if (class_exists($classname)) {
233
+				$a                         = new ReflectionClass($classname);
234
+				$obj                       = $a->newInstance();
235
+				$codes_from_objs[ $group ] = $obj->get_shortcodes();
236
+			}
237
+		}
238
+
239
+
240
+		// let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
241
+		$final_mt_codes = [];
242
+		foreach ($mt_codes as $group) {
243
+			$final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
244
+		}
245
+
246
+		$mt_codes = $final_mt_codes;
247
+
248
+
249
+		// k now in this next loop we're going to loop through $msgr_validator again
250
+		// and setup the _validators property from the data we've setup so far.
251
+		foreach ($msgr_validator as $field => $config) {
252
+			// if required shortcode is not in our list of codes for the given field, then we skip this field.
253
+			$required = isset($config['required'])
254
+				? array_intersect($config['required'], array_keys($mt_codes))
255
+				: true;
256
+			if (empty($required)) {
257
+				continue;
258
+			}
259
+
260
+			// If we have an override then we use it to indicate the codes we want.
261
+			if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
262
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
263
+					$this->_valid_shortcodes_modifier[ $context ][ $field ],
264
+					$codes_from_objs
265
+				);
266
+			} elseif (isset($groups_per_field[ $field ])) {
267
+				// we have specific shortcodes for a field so we need to use them
268
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
269
+					$groups_per_field[ $field ],
270
+					$codes_from_objs
271
+				);
272
+			} elseif (empty($config)) {
273
+				// no config so we're assuming we're just going to use the shortcodes from the message type context
274
+				$this->_validators[ $field ]['shortcodes'] = $mt_codes;
275
+			} elseif (isset($config['specific_shortcodes'])) {
276
+				// we have specific shortcodes so we need to use them
277
+				$this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
278
+			} else {
279
+				// otherwise the shortcodes are what is set by the messenger for that field
280
+				foreach ($config['shortcodes'] as $group) {
281
+					$this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
282
+						? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
283
+						: $codes_from_objs[ $group ];
284
+				}
285
+			}
286
+
287
+			// now let's just make sure that any excluded specific shortcodes are removed.
288
+			$specific_excludes = $this->get_specific_shortcode_excludes();
289
+			if (isset($specific_excludes[ $field ])) {
290
+				foreach ($specific_excludes[ $field ] as $sex) {
291
+					if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
292
+						unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
293
+					}
294
+				}
295
+			}
296
+
297
+			// hey! don't forget to include the type if present!
298
+			$this->_validators[ $field ]['type'] =
299
+				isset($config['type'])
300
+					? $config['type']
301
+					: null;
302
+		}
303
+	}
304
+
305
+
306
+	/**
307
+	 * This just returns the validators property that contains information
308
+	 * about the various shortcodes and their availability with each field
309
+	 *
310
+	 * @return array
311
+	 */
312
+	public function get_validators()
313
+	{
314
+		return $this->_validators;
315
+	}
316
+
317
+
318
+	/**
319
+	 * This simply returns the specific shortcode_excludes property that is set.
320
+	 *
321
+	 * @return array
322
+	 * @since 4.5.0
323
+	 */
324
+	public function get_specific_shortcode_excludes()
325
+	{
326
+		// specific validator filter
327
+		$shortcode_excludes = apply_filters(
328
+			'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
329
+			$this->_specific_shortcode_excludes,
330
+			$this->_context
331
+		);
332
+		// global filter
333
+		return apply_filters(
334
+			'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
335
+			$shortcode_excludes,
336
+			$this->_context,
337
+			$this
338
+		);
339
+	}
340
+
341
+
342
+	/**
343
+	 * This is the main method that handles validation
344
+	 * What it does is loop through the _fields (the ones that get validated)
345
+	 * and checks them against the shortcodes array for the field and the 'type' indicated by the
346
+	 *
347
+	 * @return array|bool if errors present we return the array otherwise true
348
+	 */
349
+	public function validate()
350
+	{
351
+		// some defaults
352
+		$template_fields = $this->_messenger->get_template_fields();
353
+		// loop through the fields and check!
354
+		foreach ($this->_fields as $field => $value) {
355
+			$this->_errors[ $field ] = [];
356
+			$err_msg                 = '';
357
+			$field_label             = '';
358
+			// if field is not present in the _validators array then we continue
359
+			if (! isset($this->_validators[ $field ])) {
360
+				unset($this->_errors[ $field ]);
361
+				continue;
362
+			}
363
+
364
+			// get the translated field label!
365
+			// first check if it's in the main fields list
366
+			if (isset($template_fields[ $field ])) {
367
+				// most likely the field is found in the 'extra' array.
368
+				$field_label = ! empty($template_fields[ $field ])
369
+					? $template_fields[ $field ]['label']
370
+					: $field;
371
+			}
372
+
373
+			// if field label is empty OR is equal to the current field
374
+			// then we need to loop through the 'extra' fields in the template_fields config (if present)
375
+			if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
376
+				foreach ($template_fields['extra'] as $main_field => $secondary_field) {
377
+					foreach ($secondary_field as $name => $values) {
378
+						if ($name === $field) {
379
+							$field_label = $values['label'];
380
+						}
381
+
382
+						// if we've got a 'main' secondary field, let's see if that matches what field we're on
383
+						// which means it contains the label for this field.
384
+						if ($name === 'main' && $main_field === $field_label) {
385
+							$field_label = $values['label'];
386
+						}
387
+					}
388
+				}
389
+			}
390
+
391
+			// field is present. Let's validate shortcodes first (but only if shortcodes present).
392
+			if (
393
+				isset($this->_validators[ $field ]['shortcodes'])
394
+				&& ! empty($this->_validators[ $field ]['shortcodes'])
395
+			) {
396
+				$invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
397
+				// if true then that means there is a returned error message
398
+				// that we'll need to add to the _errors array for this field.
399
+				if ($invalid_shortcodes) {
400
+					$v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
401
+					$err_msg = sprintf(
402
+						esc_html__(
403
+							'%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
404
+							'event_espresso'
405
+						),
406
+						'<strong>' . $field_label . '</strong>',
407
+						$invalid_shortcodes,
408
+						'<p>',
409
+						'</p >'
410
+					);
411
+					$err_msg .= sprintf(
412
+						esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
413
+						implode(', ', $v_s),
414
+						'<strong>',
415
+						'</strong>'
416
+					);
417
+				}
418
+			}
419
+
420
+			// if there's a "type" to be validated then let's do that too.
421
+			if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
422
+				switch ($this->_validators[ $field ]['type']) {
423
+					case 'number':
424
+						if (! is_numeric($value)) {
425
+							$err_msg .= sprintf(
426
+								esc_html__(
427
+									'%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',
428
+									'event_espresso'
429
+								),
430
+								$field_label,
431
+								$value,
432
+								'<p>',
433
+								'</p >'
434
+							);
435
+						}
436
+						break;
437
+					case 'email':
438
+						$valid_email = $this->_validate_email($value);
439
+						if (! $valid_email) {
440
+							$err_msg .= htmlentities(
441
+								sprintf(
442
+									esc_html__(
443
+										'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.',
444
+										'event_espresso'
445
+									),
446
+									$field_label
447
+								)
448
+							);
449
+						}
450
+						break;
451
+					default:
452
+						break;
453
+				}
454
+			}
455
+
456
+			// if $err_msg isn't empty let's setup the _errors array for this field.
457
+			if (! empty($err_msg)) {
458
+				$this->_errors[ $field ]['msg'] = $err_msg;
459
+			} else {
460
+				unset($this->_errors[ $field ]);
461
+			}
462
+		}
463
+
464
+		// if we have ANY errors, then we want to make sure we return the values
465
+		// for ALL the fields so the user doesn't have to retype them all.
466
+		if (! empty($this->_errors)) {
467
+			foreach ($this->_fields as $field => $value) {
468
+				$this->_errors[ $field ]['value'] = stripslashes($value);
469
+			}
470
+		}
471
+
472
+		// return any errors or just TRUE if everything validates
473
+		return empty($this->_errors)
474
+			? true
475
+			: $this->_errors;
476
+	}
477
+
478
+
479
+	/**
480
+	 * Reassembles and returns an array of valid shortcodes
481
+	 * given the array of groups and array of shortcodes indexed by group.
482
+	 *
483
+	 * @param array $groups          array of shortcode groups that we want shortcodes for
484
+	 * @param array $codes_from_objs All the codes available.
485
+	 * @return array                   an array of actual shortcodes (that will be used for validation).
486
+	 */
487
+	private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
488
+	{
489
+		$shortcodes = [];
490
+		foreach ($groups as $group) {
491
+			$shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
492
+		}
493
+		return $shortcodes;
494
+	}
495
+
496
+
497
+	/**
498
+	 * Validates a string against a list of accepted shortcodes
499
+	 * This function takes in an array of shortcodes
500
+	 * and makes sure that the given string ONLY contains shortcodes in that array.
501
+	 *
502
+	 * @param string $value            string to evaluate
503
+	 * @param array  $valid_shortcodes array of shortcodes that are acceptable.
504
+	 * @return bool|string  return either a list of invalid shortcodes OR false if the shortcodes validate.
505
+	 */
506
+	protected function _invalid_shortcodes($value, $valid_shortcodes)
507
+	{
508
+		// first we need to go through the string and get the shortcodes in the string
509
+		preg_match_all('/(\[.+?\])/', $value, $matches);
510
+		$incoming_shortcodes = (array) $matches[0];
511
+
512
+		// get a diff of the shortcodes in the string vs the valid shortcodes
513
+		$diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
514
+
515
+		// we need to account for custom codes so let's loop through the diff and remove any of those type of codes
516
+		foreach ($diff as $ind => $code) {
517
+			if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
518
+				// strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
519
+				$dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
520
+				// does this exist in the $valid_shortcodes?  If so then unset.
521
+				if (isset($valid_shortcodes[ $dynamic_sc ])) {
522
+					unset($diff[ $ind ]);
523
+				}
524
+			}
525
+		}
526
+
527
+		if (empty($diff)) {
528
+			return false;
529
+		} //there is no diff, we have no invalid shortcodes, so return
530
+
531
+		// made it here? then let's assemble the error message
532
+		$invalid_shortcodes = implode('</strong>,<strong>', $diff);
533
+		return '<strong>' . $invalid_shortcodes . '</strong>';
534
+	}
535
+
536
+
537
+	/**
538
+	 * Validates an incoming string and makes sure we have valid emails in the string.
539
+	 *
540
+	 * @param string $value incoming value to validate
541
+	 * @return bool        true if the string validates, false if it doesn't
542
+	 */
543
+	protected function _validate_email($value)
544
+	{
545
+		$validate = true;
546
+		$or_val   = $value;
547
+
548
+		// empty strings will validate because this is how a message template
549
+		// for a particular context can be "turned off" (if there is no email then no message)
550
+		if (empty($value)) {
551
+			return $validate;
552
+		}
553
+
554
+		// first determine if there ARE any shortcodes.
555
+		// If there are shortcodes and then later we find that there were no other valid emails
556
+		// but the field isn't empty...
557
+		// that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
558
+		$has_shortcodes = preg_match('/(\[.+?\])/', $value);
559
+
560
+		// first we need to strip out all the shortcodes!
561
+		$value = preg_replace('/(\[.+?\])/', '', $value);
562
+
563
+		// if original value is not empty and new value is, then we've parsed out a shortcode
564
+		// and we now have an empty string which DOES validate.
565
+		// We also validate complete empty field for email because
566
+		// its possible that this message is being "turned off" for a particular context
567
+
568
+
569
+		if (! empty($or_val) && empty($value)) {
570
+			return $validate;
571
+		}
572
+
573
+		// trim any commas from beginning and end of string ( after whitespace trimmed );
574
+		$value = trim(trim($value), ',');
575
+
576
+
577
+		// next we need to split up the string if its comma delimited.
578
+		$emails = explode(',', $value);
579
+		$empty  = false; // used to indicate that there is an empty comma.
580
+		// now let's loop through the emails and do our checks
581
+		foreach ($emails as $email) {
582
+			if (empty($email)) {
583
+				$empty = true;
584
+				continue;
585
+			}
586
+
587
+			// trim whitespace
588
+			$email = trim($email);
589
+			// either its of type "[email protected]", or its of type "fname lname <[email protected]>"
590
+			if (is_email($email)) {
591
+				continue;
592
+			}
593
+			$matches  = [];
594
+			$validate = (bool) preg_match('/(.*)<(.+)>/', $email, $matches);
595
+			if ($validate && is_email($matches[2])) {
596
+				continue;
597
+			}
598
+			return false;
599
+		}
600
+
601
+		return $empty && ! $has_shortcodes
602
+			? false
603
+			: $validate;
604
+	}
605
+
606
+
607
+	/**
608
+	 * Magic getter
609
+	 * Using this to provide back compat with add-ons referencing deprecated properties.
610
+	 *
611
+	 * @param string $property Property being requested
612
+	 * @return mixed
613
+	 * @throws Exception
614
+	 */
615
+	public function __get($property)
616
+	{
617
+		$expected_properties_map = [
618
+			/**
619
+			 * @deprecated 4.9.0
620
+			 */
621
+			'_MSGR'   => '_messenger',
622
+			/**
623
+			 * @deprecated 4.9.0
624
+			 */
625
+			'_MSGTYP' => '_message_type',
626
+		];
627
+
628
+		if (isset($expected_properties_map[ $property ])) {
629
+			return $this->{$expected_properties_map[ $property ]};
630
+		}
631
+
632
+		throw new Exception(
633
+			sprintf(
634
+				esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
635
+				$property,
636
+				get_class($this)
637
+			)
638
+		);
639
+	}
640 640
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/ModelDataTranslator.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         ) {
70 70
             $new_value_maybe_array = [];
71 71
             foreach ($original_value_maybe_array as $array_key => $array_item) {
72
-                $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
72
+                $new_value_maybe_array[$array_key] = ModelDataTranslator::prepareFieldValueFromJson(
73 73
                     $field_obj,
74 74
                     $array_item,
75 75
                     $requested_version,
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         if (is_array($original_value_maybe_array)) {
104 104
             $new_value = [];
105 105
             foreach ($original_value_maybe_array as $key => $value) {
106
-                $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
106
+                $new_value[$key] = ModelDataTranslator::prepareFieldValuesForJson(
107 107
                     $field_obj,
108 108
                     $value,
109 109
                     $request_version
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
                 '0',
245 245
                 STR_PAD_LEFT
246 246
             );
247
-        return $original_timestamp . $offset_sign . $offset_string;
247
+        return $original_timestamp.$offset_sign.$offset_string;
248 248
     }
249 249
 
250 250
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
                     // first, check if its a MySQL timestamp in GMT
324 324
                     $datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
325 325
                 }
326
-                if (! $datetime_obj instanceof DateTime) {
326
+                if ( ! $datetime_obj instanceof DateTime) {
327 327
                     // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
328 328
                     $datetime_obj = $field_obj->prepare_for_set($original_value);
329 329
                 }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
                         $original_value,
350 350
                         $field_obj->get_name(),
351 351
                         $field_obj->get_model_name(),
352
-                        $field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
352
+                        $field_obj->get_time_format().' '.$field_obj->get_time_format()
353 353
                     )
354 354
                 );
355 355
             }
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
         }
364 364
         // are we about to send an object? just don't. We have no good way to represent it in JSON.
365 365
         // can't just check using is_object() because that missed PHP incomplete objects
366
-        if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
366
+        if ( ! ModelDataTranslator::isRepresentableInJson($new_value)) {
367 367
             $new_value = [
368 368
                 'error_code'    => 'php_object_not_return',
369 369
                 'error_message' => esc_html__(
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
             if ($query_param_meta->getField() instanceof EE_Model_Field_Base) {
415 415
                 $translated_value = $query_param_meta->determineConditionsQueryParameterValue();
416 416
                 if (
417
-                    (isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ])
417
+                    (isset($query_param_for_models[$query_param_meta->getQueryParamKey()])
418 418
                      && $query_param_meta->isGmtField())
419 419
                     || $translated_value === null
420 420
                 ) {
@@ -423,11 +423,11 @@  discard block
 block discarded – undo
423 423
                     // OR we couldn't create a translated value from their input
424 424
                     continue;
425 425
                 }
426
-                $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value;
426
+                $query_param_for_models[$query_param_meta->getQueryParamKey()] = $translated_value;
427 427
             } else {
428 428
                 $nested_query_params = $query_param_meta->determineNestedConditionQueryParameters();
429 429
                 if ($nested_query_params) {
430
-                    $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params;
430
+                    $query_param_for_models[$query_param_meta->getQueryParamKey()] = $nested_query_params;
431 431
                 }
432 432
             }
433 433
         }
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      */
458 458
     public static function removeGmtFromFieldName($field_name)
459 459
     {
460
-        if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
460
+        if ( ! ModelDataTranslator::isGmtDateFieldName($field_name)) {
461 461
             return $field_name;
462 462
         }
463 463
         $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
     {
501 501
         $new_array = [];
502 502
         foreach ($field_names as $key => $field_name) {
503
-            $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
503
+            $new_array[$key] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
504 504
         }
505 505
         return $new_array;
506 506
     }
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
     {
518 518
         $new_array = [];
519 519
         foreach ($field_names_as_keys as $field_name => $value) {
520
-            $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
520
+            $new_array[ModelDataTranslator::prepareFieldNameFromJson($field_name)] = $value;
521 521
         }
522 522
         return $new_array;
523 523
     }
@@ -613,10 +613,10 @@  discard block
 block discarded – undo
613 613
                         $requested_version
614 614
                     );
615 615
                 }
616
-                $query_param_for_models[ $query_param_key ] = $translated_value;
616
+                $query_param_for_models[$query_param_key] = $translated_value;
617 617
             } else {
618 618
                 // so it's not for a field, assume it's a logic query param key
619
-                $query_param_for_models[ $query_param_key ] =
619
+                $query_param_for_models[$query_param_key] =
620 620
                     ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
621 621
                         $query_param_value,
622 622
                         $model,
@@ -668,11 +668,11 @@  discard block
 block discarded – undo
668 668
             );
669 669
         }
670 670
         $number_of_parts       = count($query_param_parts);
671
-        $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
671
+        $last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
672 672
         $field_name            = $last_query_param_part;
673 673
         if ($number_of_parts !== 1) {
674 674
             // the last part is the column name, and there are only 2parts. therefore...
675
-            $model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
675
+            $model = EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
676 676
         }
677 677
         try {
678 678
             return $model->field_settings_for($field_name, false);
Please login to merge, or discard this patch.
Indentation   +656 added lines, -656 removed lines patch added patch discarded remove patch
@@ -38,660 +38,660 @@
 block discarded – undo
38 38
  */
39 39
 class ModelDataTranslator
40 40
 {
41
-    /**
42
-     * We used to use -1 for infinity in the rest api, but that's ambiguous for
43
-     * fields that COULD contain -1; so we use null
44
-     */
45
-    const EE_INF_IN_REST = null;
46
-
47
-
48
-    /**
49
-     * Prepares a possible array of input values from JSON for use by the models
50
-     *
51
-     * @param EE_Model_Field_Base $field_obj
52
-     * @param mixed               $original_value_maybe_array
53
-     * @param string              $requested_version
54
-     * @param string              $timezone_string treat values as being in this timezone
55
-     * @return mixed
56
-     * @throws RestException
57
-     * @throws EE_Error
58
-     */
59
-    public static function prepareFieldValuesFromJson(
60
-        $field_obj,
61
-        $original_value_maybe_array,
62
-        $requested_version,
63
-        $timezone_string = 'UTC'
64
-    ) {
65
-        if (
66
-            is_array($original_value_maybe_array)
67
-            && ! $field_obj instanceof EE_Serialized_Text_Field
68
-        ) {
69
-            $new_value_maybe_array = [];
70
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
71
-                $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
72
-                    $field_obj,
73
-                    $array_item,
74
-                    $requested_version,
75
-                    $timezone_string
76
-                );
77
-            }
78
-        } else {
79
-            $new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson(
80
-                $field_obj,
81
-                $original_value_maybe_array,
82
-                $requested_version,
83
-                $timezone_string
84
-            );
85
-        }
86
-        return $new_value_maybe_array;
87
-    }
88
-
89
-
90
-    /**
91
-     * Prepares an array of field values FOR use in JSON/REST API
92
-     *
93
-     * @param EE_Model_Field_Base $field_obj
94
-     * @param mixed               $original_value_maybe_array
95
-     * @param string              $request_version (eg 4.8.36)
96
-     * @return array
97
-     * @throws EE_Error
98
-     * @throws EE_Error
99
-     */
100
-    public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version)
101
-    {
102
-        if (is_array($original_value_maybe_array)) {
103
-            $new_value = [];
104
-            foreach ($original_value_maybe_array as $key => $value) {
105
-                $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
106
-                    $field_obj,
107
-                    $value,
108
-                    $request_version
109
-                );
110
-            }
111
-        } else {
112
-            $new_value = ModelDataTranslator::prepareFieldValueForJson(
113
-                $field_obj,
114
-                $original_value_maybe_array,
115
-                $request_version
116
-            );
117
-        }
118
-        return $new_value;
119
-    }
120
-
121
-
122
-    /**
123
-     * Prepares incoming data from the json or request parameters for the models'
124
-     * "$query_params".
125
-     *
126
-     * @param EE_Model_Field_Base $field_obj
127
-     * @param mixed               $original_value
128
-     * @param string              $requested_version
129
-     * @param string              $timezone_string treat values as being in this timezone
130
-     * @return mixed
131
-     * @throws RestException
132
-     * @throws DomainException
133
-     * @throws EE_Error
134
-     */
135
-    public static function prepareFieldValueFromJson(
136
-        $field_obj,
137
-        $original_value,
138
-        $requested_version,
139
-        $timezone_string = 'UTC'
140
-    ) {
141
-        // check if they accidentally submitted an error value. If so throw an exception
142
-        if (
143
-            is_array($original_value)
144
-            && isset($original_value['error_code'], $original_value['error_message'])
145
-        ) {
146
-            throw new RestException(
147
-                'rest_submitted_error_value',
148
-                sprintf(
149
-                    esc_html__(
150
-                        'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.',
151
-                        'event_espresso'
152
-                    ),
153
-                    $field_obj->get_name()
154
-                ),
155
-                [
156
-                    'status' => 400,
157
-                ]
158
-            );
159
-        }
160
-        // double-check for serialized PHP. We never accept serialized PHP. No way Jose.
161
-        ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
162
-        $timezone_string =
163
-            $timezone_string !== ''
164
-                ? $timezone_string
165
-                : get_option('timezone_string', '');
166
-        // walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No
167
-        // way Jose.
168
-        ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
169
-        if (
170
-            $field_obj instanceof EE_Infinite_Integer_Field
171
-            && in_array($original_value, [null, ''], true)
172
-        ) {
173
-            $new_value = EE_INF;
174
-        } elseif ($field_obj instanceof EE_Datetime_Field) {
175
-            $new_value = rest_parse_date(
176
-                self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string)
177
-            );
178
-            if ($new_value === false) {
179
-                throw new RestException(
180
-                    'invalid_format_for_timestamp',
181
-                    sprintf(
182
-                        esc_html__(
183
-                            'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format.  The timestamp provided (%3$s) is not that format.',
184
-                            'event_espresso'
185
-                        ),
186
-                        'RFC3339',
187
-                        'ISO8601',
188
-                        $original_value
189
-                    ),
190
-                    [
191
-                        'status' => 400,
192
-                    ]
193
-                );
194
-            }
195
-        } elseif ($field_obj instanceof EE_Boolean_Field) {
196
-            // Interpreted the strings "false", "true", "on", "off" appropriately.
197
-            $new_value = filter_var($original_value, FILTER_VALIDATE_BOOLEAN);
198
-        } else {
199
-            $new_value = $original_value;
200
-        }
201
-        return $new_value;
202
-    }
203
-
204
-
205
-    /**
206
-     * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone
207
-     * information via details obtained from the host site.
208
-     *
209
-     * @param string            $original_timestamp
210
-     * @param EE_Datetime_Field $datetime_field
211
-     * @param                   $timezone_string
212
-     * @return string
213
-     * @throws DomainException
214
-     */
215
-    private static function getTimestampWithTimezoneOffset(
216
-        $original_timestamp,
217
-        EE_Datetime_Field $datetime_field,
218
-        $timezone_string
219
-    ) {
220
-        // already have timezone information?
221
-        if (preg_match('/Z|([+-])(\d{2}:\d{2})/', $original_timestamp)) {
222
-            // yes, we're ignoring the timezone.
223
-            return $original_timestamp;
224
-        }
225
-        // need to append timezone
226
-        list($offset_sign, $offset_secs) = self::parseTimezoneOffset(
227
-            $datetime_field->get_timezone_offset(
228
-                new DateTimeZone($timezone_string),
229
-                $original_timestamp
230
-            )
231
-        );
232
-        $offset_string =
233
-            str_pad(
234
-                floor($offset_secs / HOUR_IN_SECONDS),
235
-                2,
236
-                '0',
237
-                STR_PAD_LEFT
238
-            )
239
-            . ':'
240
-            . str_pad(
241
-                ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
242
-                2,
243
-                '0',
244
-                STR_PAD_LEFT
245
-            );
246
-        return $original_timestamp . $offset_sign . $offset_string;
247
-    }
248
-
249
-
250
-    /**
251
-     * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't
252
-     * think that can happen). If $data is an array, recurses into its keys and values
253
-     *
254
-     * @param mixed $data
255
-     * @return void
256
-     * @throws RestException
257
-     */
258
-    public static function throwExceptionIfContainsSerializedData($data)
259
-    {
260
-        if (is_array($data)) {
261
-            foreach ($data as $key => $value) {
262
-                ModelDataTranslator::throwExceptionIfContainsSerializedData($key);
263
-                ModelDataTranslator::throwExceptionIfContainsSerializedData($value);
264
-            }
265
-        } else {
266
-            if (is_serialized($data) || is_object($data)) {
267
-                throw new RestException(
268
-                    'serialized_data_submission_prohibited',
269
-                    esc_html__(
270
-                    // @codingStandardsIgnoreStart
271
-                        'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.',
272
-                        // @codingStandardsIgnoreEnd
273
-                        'event_espresso'
274
-                    )
275
-                );
276
-            }
277
-        }
278
-    }
279
-
280
-
281
-    /**
282
-     * determines what's going on with them timezone strings
283
-     *
284
-     * @param int $timezone_offset
285
-     * @return array
286
-     */
287
-    private static function parseTimezoneOffset($timezone_offset)
288
-    {
289
-        $first_char = substr((string) $timezone_offset, 0, 1);
290
-        if ($first_char === '+' || $first_char === '-') {
291
-            $offset_sign = $first_char;
292
-            $offset_secs = substr((string) $timezone_offset, 1);
293
-        } else {
294
-            $offset_sign = '+';
295
-            $offset_secs = $timezone_offset;
296
-        }
297
-        return [$offset_sign, $offset_secs];
298
-    }
299
-
300
-
301
-    /**
302
-     * Prepares a field's value for display in the API
303
-     *
304
-     * @param EE_Model_Field_Base $field_obj
305
-     * @param mixed               $original_value
306
-     * @param string              $requested_version
307
-     * @return mixed
308
-     * @throws EE_Error
309
-     * @throws EE_Error
310
-     */
311
-    public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version)
312
-    {
313
-        if ($original_value === EE_INF) {
314
-            $new_value = ModelDataTranslator::EE_INF_IN_REST;
315
-        } elseif ($field_obj instanceof EE_Datetime_Field) {
316
-            if (is_string($original_value)) {
317
-                // did they submit a string of a unix timestamp?
318
-                if (is_numeric($original_value)) {
319
-                    $datetime_obj = new DateTime();
320
-                    $datetime_obj->setTimestamp((int) $original_value);
321
-                } else {
322
-                    // first, check if its a MySQL timestamp in GMT
323
-                    $datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
324
-                }
325
-                if (! $datetime_obj instanceof DateTime) {
326
-                    // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
327
-                    $datetime_obj = $field_obj->prepare_for_set($original_value);
328
-                }
329
-                $original_value = $datetime_obj;
330
-            }
331
-            if ($original_value instanceof DateTime) {
332
-                $new_value = $original_value->format('Y-m-d H:i:s');
333
-            } elseif (is_int($original_value) || is_float($original_value)) {
334
-                $new_value = date('Y-m-d H:i:s', $original_value);
335
-            } elseif ($original_value === null || $original_value === '') {
336
-                $new_value = null;
337
-            } else {
338
-                // so it's not a datetime object, unix timestamp (as string or int),
339
-                // MySQL timestamp, or even a string in the field object's format. So no idea what it is
340
-                throw new EE_Error(
341
-                    sprintf(
342
-                        esc_html__(
343
-                        // @codingStandardsIgnoreStart
344
-                            'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".',
345
-                            // @codingStandardsIgnoreEnd
346
-                            'event_espresso'
347
-                        ),
348
-                        $original_value,
349
-                        $field_obj->get_name(),
350
-                        $field_obj->get_model_name(),
351
-                        $field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
352
-                    )
353
-                );
354
-            }
355
-            if ($new_value !== null) {
356
-                // phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
357
-                $new_value = mysql_to_rfc3339($new_value);
358
-                // phpcs:enable
359
-            }
360
-        } else {
361
-            $new_value = $original_value;
362
-        }
363
-        // are we about to send an object? just don't. We have no good way to represent it in JSON.
364
-        // can't just check using is_object() because that missed PHP incomplete objects
365
-        if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
366
-            $new_value = [
367
-                'error_code'    => 'php_object_not_return',
368
-                'error_message' => esc_html__(
369
-                    'The value of this field in the database is a PHP object, which can\'t be represented in JSON.',
370
-                    'event_espresso'
371
-                ),
372
-            ];
373
-        }
374
-        return apply_filters(
375
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
376
-            $new_value,
377
-            $field_obj,
378
-            $original_value,
379
-            $requested_version
380
-        );
381
-    }
382
-
383
-
384
-    /**
385
-     * Prepares condition-query-parameters (like what's in where and having) from
386
-     * the format expected in the API to use in the models
387
-     *
388
-     * @param array    $inputted_query_params_of_this_type
389
-     * @param EEM_Base $model
390
-     * @param string   $requested_version
391
-     * @param boolean  $writing whether this data will be written to the DB, or if we're just building a query.
392
-     *                          If we're writing to the DB, we don't expect any operators, or any logic query
393
-     *                          parameters, and we also won't accept serialized data unless the current user has
394
-     *                          unfiltered_html.
395
-     * @return array
396
-     * @throws DomainException
397
-     * @throws EE_Error
398
-     * @throws RestException
399
-     * @throws InvalidDataTypeException
400
-     * @throws InvalidInterfaceException
401
-     * @throws InvalidArgumentException
402
-     */
403
-    public static function prepareConditionsQueryParamsForModels(
404
-        $inputted_query_params_of_this_type,
405
-        EEM_Base $model,
406
-        $requested_version,
407
-        $writing = false
408
-    ) {
409
-        $query_param_for_models = [];
410
-        $context                = new RestIncomingQueryParamContext($model, $requested_version, $writing);
411
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
412
-            $query_param_meta = new RestIncomingQueryParamMetadata($query_param_key, $query_param_value, $context);
413
-            if ($query_param_meta->getField() instanceof EE_Model_Field_Base) {
414
-                $translated_value = $query_param_meta->determineConditionsQueryParameterValue();
415
-                if (
416
-                    (isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ])
417
-                     && $query_param_meta->isGmtField())
418
-                    || $translated_value === null
419
-                ) {
420
-                    // they have already provided a non-gmt field, ignore the gmt one. That's what WP core
421
-                    // currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954
422
-                    // OR we couldn't create a translated value from their input
423
-                    continue;
424
-                }
425
-                $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value;
426
-            } else {
427
-                $nested_query_params = $query_param_meta->determineNestedConditionQueryParameters();
428
-                if ($nested_query_params) {
429
-                    $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params;
430
-                }
431
-            }
432
-        }
433
-        return $query_param_for_models;
434
-    }
435
-
436
-
437
-    /**
438
-     * Mostly checks if the last 4 characters are "_gmt", indicating its a
439
-     * gmt date field name
440
-     *
441
-     * @param string $field_name
442
-     * @return boolean
443
-     */
444
-    public static function isGmtDateFieldName($field_name)
445
-    {
446
-        $field_name = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name);
447
-        return substr($field_name, -4, 4) === '_gmt';
448
-    }
449
-
450
-
451
-    /**
452
-     * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
453
-     *
454
-     * @param string $field_name
455
-     * @return string
456
-     */
457
-    public static function removeGmtFromFieldName($field_name)
458
-    {
459
-        if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
460
-            return $field_name;
461
-        }
462
-        $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
463
-            $field_name
464
-        );
465
-        $query_param_sans_gmt_and_sans_stars = substr(
466
-            $query_param_sans_stars,
467
-            0,
468
-            strrpos(
469
-                $field_name,
470
-                '_gmt'
471
-            )
472
-        );
473
-        return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
474
-    }
475
-
476
-
477
-    /**
478
-     * Takes a field name from the REST API and prepares it for the model querying
479
-     *
480
-     * @param string $field_name
481
-     * @return string
482
-     */
483
-    public static function prepareFieldNameFromJson($field_name)
484
-    {
485
-        if (ModelDataTranslator::isGmtDateFieldName($field_name)) {
486
-            return ModelDataTranslator::removeGmtFromFieldName($field_name);
487
-        }
488
-        return $field_name;
489
-    }
490
-
491
-
492
-    /**
493
-     * Takes array of field names from REST API and prepares for models
494
-     *
495
-     * @param array $field_names
496
-     * @return array of field names (possibly include model prefixes)
497
-     */
498
-    public static function prepareFieldNamesFromJson(array $field_names)
499
-    {
500
-        $new_array = [];
501
-        foreach ($field_names as $key => $field_name) {
502
-            $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
503
-        }
504
-        return $new_array;
505
-    }
506
-
507
-
508
-    /**
509
-     * Takes array where array keys are field names (possibly with model path prefixes)
510
-     * from the REST API and prepares them for model querying
511
-     *
512
-     * @param array $field_names_as_keys
513
-     * @return array
514
-     */
515
-    public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys)
516
-    {
517
-        $new_array = [];
518
-        foreach ($field_names_as_keys as $field_name => $value) {
519
-            $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
520
-        }
521
-        return $new_array;
522
-    }
523
-
524
-
525
-    /**
526
-     * Prepares an array of model query params for use in the REST API
527
-     *
528
-     * @param array    $model_query_params
529
-     * @param EEM_Base $model
530
-     * @param string   $requested_version  eg "4.8.36". If null is provided, defaults to the latest release of the EE4
531
-     *                                     REST API
532
-     * @return array which can be passed into the EE4 REST API when querying a model resource
533
-     * @throws EE_Error
534
-     * @throws ReflectionException
535
-     */
536
-    public static function prepareQueryParamsForRestApi(
537
-        array $model_query_params,
538
-        EEM_Base $model,
539
-        $requested_version = null
540
-    ) {
541
-        if ($requested_version === null) {
542
-            $requested_version = EED_Core_Rest_Api::latest_rest_api_version();
543
-        }
544
-        $rest_query_params = $model_query_params;
545
-        if (isset($model_query_params[0])) {
546
-            $rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
547
-                $model_query_params[0],
548
-                $model,
549
-                $requested_version
550
-            );
551
-            unset($rest_query_params[0]);
552
-        }
553
-        if (isset($model_query_params['having'])) {
554
-            $rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
555
-                $model_query_params['having'],
556
-                $model,
557
-                $requested_version
558
-            );
559
-        }
560
-        return apply_filters(
561
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
562
-            $rest_query_params,
563
-            $model_query_params,
564
-            $model,
565
-            $requested_version
566
-        );
567
-    }
568
-
569
-
570
-    /**
571
-     * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
572
-     *
573
-     * @param array    $inputted_query_params_of_this_type  eg like the "where" or "having" conditions query params
574
-     * @param EEM_Base $model
575
-     * @param string   $requested_version                   eg "4.8.36"
576
-     * @return array ready for use in the rest api query params
577
-     * @throws EE_Error
578
-     * @throws RestException if somehow a PHP object were in the query params' values,*@throws
579
-     * @throws ReflectionException
580
-     *                                                      ReflectionException
581
-     *                                                      (which would be really unusual)
582
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
583
-     */
584
-    public static function prepareConditionsQueryParamsForRestApi(
585
-        $inputted_query_params_of_this_type,
586
-        EEM_Base $model,
587
-        $requested_version
588
-    ) {
589
-        $query_param_for_models = [];
590
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
591
-            $field = ModelDataTranslator::deduceFieldFromQueryParam(
592
-                ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key),
593
-                $model
594
-            );
595
-            if ($field instanceof EE_Model_Field_Base) {
596
-                // did they specify an operator?
597
-                if (is_array($query_param_value)) {
598
-                    $op               = $query_param_value[0];
599
-                    $translated_value = [$op];
600
-                    if (isset($query_param_value[1])) {
601
-                        $value               = $query_param_value[1];
602
-                        $translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson(
603
-                            $field,
604
-                            $value,
605
-                            $requested_version
606
-                        );
607
-                    }
608
-                } else {
609
-                    $translated_value = ModelDataTranslator::prepareFieldValueForJson(
610
-                        $field,
611
-                        $query_param_value,
612
-                        $requested_version
613
-                    );
614
-                }
615
-                $query_param_for_models[ $query_param_key ] = $translated_value;
616
-            } else {
617
-                // so it's not for a field, assume it's a logic query param key
618
-                $query_param_for_models[ $query_param_key ] =
619
-                    ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
620
-                        $query_param_value,
621
-                        $model,
622
-                        $requested_version
623
-                    );
624
-            }
625
-        }
626
-        return $query_param_for_models;
627
-    }
628
-
629
-
630
-    /**
631
-     * @param $condition_query_param_key
632
-     * @return string
633
-     */
634
-    public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key)
635
-    {
636
-        $pos_of_star = strpos($condition_query_param_key, '*');
637
-        if ($pos_of_star === false) {
638
-            return $condition_query_param_key;
639
-        }
640
-        return substr($condition_query_param_key, 0, $pos_of_star);
641
-    }
642
-
643
-
644
-    /**
645
-     * Takes the input parameter and finds the model field that it indicates.
646
-     *
647
-     * @param string   $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
648
-     * @param EEM_Base $model
649
-     * @return EE_Model_Field_Base
650
-     * @throws EE_Error
651
-     * @throws ReflectionException
652
-     */
653
-    public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model)
654
-    {
655
-        // ok, now proceed with deducing which part is the model's name, and which is the field's name
656
-        // which will help us find the database table and column
657
-        $query_param_parts = explode('.', $query_param_name);
658
-        if (empty($query_param_parts)) {
659
-            throw new EE_Error(
660
-                sprintf(
661
-                    esc_html__(
662
-                        '_extract_column_name is empty when trying to extract column and table name from %s',
663
-                        'event_espresso'
664
-                    ),
665
-                    $query_param_name
666
-                )
667
-            );
668
-        }
669
-        $number_of_parts       = count($query_param_parts);
670
-        $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
671
-        $field_name            = $last_query_param_part;
672
-        if ($number_of_parts !== 1) {
673
-            // the last part is the column name, and there are only 2parts. therefore...
674
-            $model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
675
-        }
676
-        try {
677
-            return $model->field_settings_for($field_name, false);
678
-        } catch (EE_Error $e) {
679
-            return null;
680
-        }
681
-    }
682
-
683
-
684
-    /**
685
-     * Returns true if $data can be easily represented in JSON.
686
-     * Basically, objects and resources can't be represented in JSON easily.
687
-     *
688
-     * @param mixed $data
689
-     * @return bool
690
-     */
691
-    protected static function isRepresentableInJson($data)
692
-    {
693
-        return is_scalar($data)
694
-               || is_array($data)
695
-               || is_null($data);
696
-    }
41
+	/**
42
+	 * We used to use -1 for infinity in the rest api, but that's ambiguous for
43
+	 * fields that COULD contain -1; so we use null
44
+	 */
45
+	const EE_INF_IN_REST = null;
46
+
47
+
48
+	/**
49
+	 * Prepares a possible array of input values from JSON for use by the models
50
+	 *
51
+	 * @param EE_Model_Field_Base $field_obj
52
+	 * @param mixed               $original_value_maybe_array
53
+	 * @param string              $requested_version
54
+	 * @param string              $timezone_string treat values as being in this timezone
55
+	 * @return mixed
56
+	 * @throws RestException
57
+	 * @throws EE_Error
58
+	 */
59
+	public static function prepareFieldValuesFromJson(
60
+		$field_obj,
61
+		$original_value_maybe_array,
62
+		$requested_version,
63
+		$timezone_string = 'UTC'
64
+	) {
65
+		if (
66
+			is_array($original_value_maybe_array)
67
+			&& ! $field_obj instanceof EE_Serialized_Text_Field
68
+		) {
69
+			$new_value_maybe_array = [];
70
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
71
+				$new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
72
+					$field_obj,
73
+					$array_item,
74
+					$requested_version,
75
+					$timezone_string
76
+				);
77
+			}
78
+		} else {
79
+			$new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson(
80
+				$field_obj,
81
+				$original_value_maybe_array,
82
+				$requested_version,
83
+				$timezone_string
84
+			);
85
+		}
86
+		return $new_value_maybe_array;
87
+	}
88
+
89
+
90
+	/**
91
+	 * Prepares an array of field values FOR use in JSON/REST API
92
+	 *
93
+	 * @param EE_Model_Field_Base $field_obj
94
+	 * @param mixed               $original_value_maybe_array
95
+	 * @param string              $request_version (eg 4.8.36)
96
+	 * @return array
97
+	 * @throws EE_Error
98
+	 * @throws EE_Error
99
+	 */
100
+	public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version)
101
+	{
102
+		if (is_array($original_value_maybe_array)) {
103
+			$new_value = [];
104
+			foreach ($original_value_maybe_array as $key => $value) {
105
+				$new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
106
+					$field_obj,
107
+					$value,
108
+					$request_version
109
+				);
110
+			}
111
+		} else {
112
+			$new_value = ModelDataTranslator::prepareFieldValueForJson(
113
+				$field_obj,
114
+				$original_value_maybe_array,
115
+				$request_version
116
+			);
117
+		}
118
+		return $new_value;
119
+	}
120
+
121
+
122
+	/**
123
+	 * Prepares incoming data from the json or request parameters for the models'
124
+	 * "$query_params".
125
+	 *
126
+	 * @param EE_Model_Field_Base $field_obj
127
+	 * @param mixed               $original_value
128
+	 * @param string              $requested_version
129
+	 * @param string              $timezone_string treat values as being in this timezone
130
+	 * @return mixed
131
+	 * @throws RestException
132
+	 * @throws DomainException
133
+	 * @throws EE_Error
134
+	 */
135
+	public static function prepareFieldValueFromJson(
136
+		$field_obj,
137
+		$original_value,
138
+		$requested_version,
139
+		$timezone_string = 'UTC'
140
+	) {
141
+		// check if they accidentally submitted an error value. If so throw an exception
142
+		if (
143
+			is_array($original_value)
144
+			&& isset($original_value['error_code'], $original_value['error_message'])
145
+		) {
146
+			throw new RestException(
147
+				'rest_submitted_error_value',
148
+				sprintf(
149
+					esc_html__(
150
+						'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.',
151
+						'event_espresso'
152
+					),
153
+					$field_obj->get_name()
154
+				),
155
+				[
156
+					'status' => 400,
157
+				]
158
+			);
159
+		}
160
+		// double-check for serialized PHP. We never accept serialized PHP. No way Jose.
161
+		ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
162
+		$timezone_string =
163
+			$timezone_string !== ''
164
+				? $timezone_string
165
+				: get_option('timezone_string', '');
166
+		// walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No
167
+		// way Jose.
168
+		ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
169
+		if (
170
+			$field_obj instanceof EE_Infinite_Integer_Field
171
+			&& in_array($original_value, [null, ''], true)
172
+		) {
173
+			$new_value = EE_INF;
174
+		} elseif ($field_obj instanceof EE_Datetime_Field) {
175
+			$new_value = rest_parse_date(
176
+				self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string)
177
+			);
178
+			if ($new_value === false) {
179
+				throw new RestException(
180
+					'invalid_format_for_timestamp',
181
+					sprintf(
182
+						esc_html__(
183
+							'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format.  The timestamp provided (%3$s) is not that format.',
184
+							'event_espresso'
185
+						),
186
+						'RFC3339',
187
+						'ISO8601',
188
+						$original_value
189
+					),
190
+					[
191
+						'status' => 400,
192
+					]
193
+				);
194
+			}
195
+		} elseif ($field_obj instanceof EE_Boolean_Field) {
196
+			// Interpreted the strings "false", "true", "on", "off" appropriately.
197
+			$new_value = filter_var($original_value, FILTER_VALIDATE_BOOLEAN);
198
+		} else {
199
+			$new_value = $original_value;
200
+		}
201
+		return $new_value;
202
+	}
203
+
204
+
205
+	/**
206
+	 * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone
207
+	 * information via details obtained from the host site.
208
+	 *
209
+	 * @param string            $original_timestamp
210
+	 * @param EE_Datetime_Field $datetime_field
211
+	 * @param                   $timezone_string
212
+	 * @return string
213
+	 * @throws DomainException
214
+	 */
215
+	private static function getTimestampWithTimezoneOffset(
216
+		$original_timestamp,
217
+		EE_Datetime_Field $datetime_field,
218
+		$timezone_string
219
+	) {
220
+		// already have timezone information?
221
+		if (preg_match('/Z|([+-])(\d{2}:\d{2})/', $original_timestamp)) {
222
+			// yes, we're ignoring the timezone.
223
+			return $original_timestamp;
224
+		}
225
+		// need to append timezone
226
+		list($offset_sign, $offset_secs) = self::parseTimezoneOffset(
227
+			$datetime_field->get_timezone_offset(
228
+				new DateTimeZone($timezone_string),
229
+				$original_timestamp
230
+			)
231
+		);
232
+		$offset_string =
233
+			str_pad(
234
+				floor($offset_secs / HOUR_IN_SECONDS),
235
+				2,
236
+				'0',
237
+				STR_PAD_LEFT
238
+			)
239
+			. ':'
240
+			. str_pad(
241
+				($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
242
+				2,
243
+				'0',
244
+				STR_PAD_LEFT
245
+			);
246
+		return $original_timestamp . $offset_sign . $offset_string;
247
+	}
248
+
249
+
250
+	/**
251
+	 * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't
252
+	 * think that can happen). If $data is an array, recurses into its keys and values
253
+	 *
254
+	 * @param mixed $data
255
+	 * @return void
256
+	 * @throws RestException
257
+	 */
258
+	public static function throwExceptionIfContainsSerializedData($data)
259
+	{
260
+		if (is_array($data)) {
261
+			foreach ($data as $key => $value) {
262
+				ModelDataTranslator::throwExceptionIfContainsSerializedData($key);
263
+				ModelDataTranslator::throwExceptionIfContainsSerializedData($value);
264
+			}
265
+		} else {
266
+			if (is_serialized($data) || is_object($data)) {
267
+				throw new RestException(
268
+					'serialized_data_submission_prohibited',
269
+					esc_html__(
270
+					// @codingStandardsIgnoreStart
271
+						'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.',
272
+						// @codingStandardsIgnoreEnd
273
+						'event_espresso'
274
+					)
275
+				);
276
+			}
277
+		}
278
+	}
279
+
280
+
281
+	/**
282
+	 * determines what's going on with them timezone strings
283
+	 *
284
+	 * @param int $timezone_offset
285
+	 * @return array
286
+	 */
287
+	private static function parseTimezoneOffset($timezone_offset)
288
+	{
289
+		$first_char = substr((string) $timezone_offset, 0, 1);
290
+		if ($first_char === '+' || $first_char === '-') {
291
+			$offset_sign = $first_char;
292
+			$offset_secs = substr((string) $timezone_offset, 1);
293
+		} else {
294
+			$offset_sign = '+';
295
+			$offset_secs = $timezone_offset;
296
+		}
297
+		return [$offset_sign, $offset_secs];
298
+	}
299
+
300
+
301
+	/**
302
+	 * Prepares a field's value for display in the API
303
+	 *
304
+	 * @param EE_Model_Field_Base $field_obj
305
+	 * @param mixed               $original_value
306
+	 * @param string              $requested_version
307
+	 * @return mixed
308
+	 * @throws EE_Error
309
+	 * @throws EE_Error
310
+	 */
311
+	public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version)
312
+	{
313
+		if ($original_value === EE_INF) {
314
+			$new_value = ModelDataTranslator::EE_INF_IN_REST;
315
+		} elseif ($field_obj instanceof EE_Datetime_Field) {
316
+			if (is_string($original_value)) {
317
+				// did they submit a string of a unix timestamp?
318
+				if (is_numeric($original_value)) {
319
+					$datetime_obj = new DateTime();
320
+					$datetime_obj->setTimestamp((int) $original_value);
321
+				} else {
322
+					// first, check if its a MySQL timestamp in GMT
323
+					$datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
324
+				}
325
+				if (! $datetime_obj instanceof DateTime) {
326
+					// so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
327
+					$datetime_obj = $field_obj->prepare_for_set($original_value);
328
+				}
329
+				$original_value = $datetime_obj;
330
+			}
331
+			if ($original_value instanceof DateTime) {
332
+				$new_value = $original_value->format('Y-m-d H:i:s');
333
+			} elseif (is_int($original_value) || is_float($original_value)) {
334
+				$new_value = date('Y-m-d H:i:s', $original_value);
335
+			} elseif ($original_value === null || $original_value === '') {
336
+				$new_value = null;
337
+			} else {
338
+				// so it's not a datetime object, unix timestamp (as string or int),
339
+				// MySQL timestamp, or even a string in the field object's format. So no idea what it is
340
+				throw new EE_Error(
341
+					sprintf(
342
+						esc_html__(
343
+						// @codingStandardsIgnoreStart
344
+							'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".',
345
+							// @codingStandardsIgnoreEnd
346
+							'event_espresso'
347
+						),
348
+						$original_value,
349
+						$field_obj->get_name(),
350
+						$field_obj->get_model_name(),
351
+						$field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
352
+					)
353
+				);
354
+			}
355
+			if ($new_value !== null) {
356
+				// phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
357
+				$new_value = mysql_to_rfc3339($new_value);
358
+				// phpcs:enable
359
+			}
360
+		} else {
361
+			$new_value = $original_value;
362
+		}
363
+		// are we about to send an object? just don't. We have no good way to represent it in JSON.
364
+		// can't just check using is_object() because that missed PHP incomplete objects
365
+		if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
366
+			$new_value = [
367
+				'error_code'    => 'php_object_not_return',
368
+				'error_message' => esc_html__(
369
+					'The value of this field in the database is a PHP object, which can\'t be represented in JSON.',
370
+					'event_espresso'
371
+				),
372
+			];
373
+		}
374
+		return apply_filters(
375
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
376
+			$new_value,
377
+			$field_obj,
378
+			$original_value,
379
+			$requested_version
380
+		);
381
+	}
382
+
383
+
384
+	/**
385
+	 * Prepares condition-query-parameters (like what's in where and having) from
386
+	 * the format expected in the API to use in the models
387
+	 *
388
+	 * @param array    $inputted_query_params_of_this_type
389
+	 * @param EEM_Base $model
390
+	 * @param string   $requested_version
391
+	 * @param boolean  $writing whether this data will be written to the DB, or if we're just building a query.
392
+	 *                          If we're writing to the DB, we don't expect any operators, or any logic query
393
+	 *                          parameters, and we also won't accept serialized data unless the current user has
394
+	 *                          unfiltered_html.
395
+	 * @return array
396
+	 * @throws DomainException
397
+	 * @throws EE_Error
398
+	 * @throws RestException
399
+	 * @throws InvalidDataTypeException
400
+	 * @throws InvalidInterfaceException
401
+	 * @throws InvalidArgumentException
402
+	 */
403
+	public static function prepareConditionsQueryParamsForModels(
404
+		$inputted_query_params_of_this_type,
405
+		EEM_Base $model,
406
+		$requested_version,
407
+		$writing = false
408
+	) {
409
+		$query_param_for_models = [];
410
+		$context                = new RestIncomingQueryParamContext($model, $requested_version, $writing);
411
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
412
+			$query_param_meta = new RestIncomingQueryParamMetadata($query_param_key, $query_param_value, $context);
413
+			if ($query_param_meta->getField() instanceof EE_Model_Field_Base) {
414
+				$translated_value = $query_param_meta->determineConditionsQueryParameterValue();
415
+				if (
416
+					(isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ])
417
+					 && $query_param_meta->isGmtField())
418
+					|| $translated_value === null
419
+				) {
420
+					// they have already provided a non-gmt field, ignore the gmt one. That's what WP core
421
+					// currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954
422
+					// OR we couldn't create a translated value from their input
423
+					continue;
424
+				}
425
+				$query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value;
426
+			} else {
427
+				$nested_query_params = $query_param_meta->determineNestedConditionQueryParameters();
428
+				if ($nested_query_params) {
429
+					$query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params;
430
+				}
431
+			}
432
+		}
433
+		return $query_param_for_models;
434
+	}
435
+
436
+
437
+	/**
438
+	 * Mostly checks if the last 4 characters are "_gmt", indicating its a
439
+	 * gmt date field name
440
+	 *
441
+	 * @param string $field_name
442
+	 * @return boolean
443
+	 */
444
+	public static function isGmtDateFieldName($field_name)
445
+	{
446
+		$field_name = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name);
447
+		return substr($field_name, -4, 4) === '_gmt';
448
+	}
449
+
450
+
451
+	/**
452
+	 * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
453
+	 *
454
+	 * @param string $field_name
455
+	 * @return string
456
+	 */
457
+	public static function removeGmtFromFieldName($field_name)
458
+	{
459
+		if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
460
+			return $field_name;
461
+		}
462
+		$query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
463
+			$field_name
464
+		);
465
+		$query_param_sans_gmt_and_sans_stars = substr(
466
+			$query_param_sans_stars,
467
+			0,
468
+			strrpos(
469
+				$field_name,
470
+				'_gmt'
471
+			)
472
+		);
473
+		return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
474
+	}
475
+
476
+
477
+	/**
478
+	 * Takes a field name from the REST API and prepares it for the model querying
479
+	 *
480
+	 * @param string $field_name
481
+	 * @return string
482
+	 */
483
+	public static function prepareFieldNameFromJson($field_name)
484
+	{
485
+		if (ModelDataTranslator::isGmtDateFieldName($field_name)) {
486
+			return ModelDataTranslator::removeGmtFromFieldName($field_name);
487
+		}
488
+		return $field_name;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Takes array of field names from REST API and prepares for models
494
+	 *
495
+	 * @param array $field_names
496
+	 * @return array of field names (possibly include model prefixes)
497
+	 */
498
+	public static function prepareFieldNamesFromJson(array $field_names)
499
+	{
500
+		$new_array = [];
501
+		foreach ($field_names as $key => $field_name) {
502
+			$new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
503
+		}
504
+		return $new_array;
505
+	}
506
+
507
+
508
+	/**
509
+	 * Takes array where array keys are field names (possibly with model path prefixes)
510
+	 * from the REST API and prepares them for model querying
511
+	 *
512
+	 * @param array $field_names_as_keys
513
+	 * @return array
514
+	 */
515
+	public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys)
516
+	{
517
+		$new_array = [];
518
+		foreach ($field_names_as_keys as $field_name => $value) {
519
+			$new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
520
+		}
521
+		return $new_array;
522
+	}
523
+
524
+
525
+	/**
526
+	 * Prepares an array of model query params for use in the REST API
527
+	 *
528
+	 * @param array    $model_query_params
529
+	 * @param EEM_Base $model
530
+	 * @param string   $requested_version  eg "4.8.36". If null is provided, defaults to the latest release of the EE4
531
+	 *                                     REST API
532
+	 * @return array which can be passed into the EE4 REST API when querying a model resource
533
+	 * @throws EE_Error
534
+	 * @throws ReflectionException
535
+	 */
536
+	public static function prepareQueryParamsForRestApi(
537
+		array $model_query_params,
538
+		EEM_Base $model,
539
+		$requested_version = null
540
+	) {
541
+		if ($requested_version === null) {
542
+			$requested_version = EED_Core_Rest_Api::latest_rest_api_version();
543
+		}
544
+		$rest_query_params = $model_query_params;
545
+		if (isset($model_query_params[0])) {
546
+			$rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
547
+				$model_query_params[0],
548
+				$model,
549
+				$requested_version
550
+			);
551
+			unset($rest_query_params[0]);
552
+		}
553
+		if (isset($model_query_params['having'])) {
554
+			$rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
555
+				$model_query_params['having'],
556
+				$model,
557
+				$requested_version
558
+			);
559
+		}
560
+		return apply_filters(
561
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
562
+			$rest_query_params,
563
+			$model_query_params,
564
+			$model,
565
+			$requested_version
566
+		);
567
+	}
568
+
569
+
570
+	/**
571
+	 * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
572
+	 *
573
+	 * @param array    $inputted_query_params_of_this_type  eg like the "where" or "having" conditions query params
574
+	 * @param EEM_Base $model
575
+	 * @param string   $requested_version                   eg "4.8.36"
576
+	 * @return array ready for use in the rest api query params
577
+	 * @throws EE_Error
578
+	 * @throws RestException if somehow a PHP object were in the query params' values,*@throws
579
+	 * @throws ReflectionException
580
+	 *                                                      ReflectionException
581
+	 *                                                      (which would be really unusual)
582
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
583
+	 */
584
+	public static function prepareConditionsQueryParamsForRestApi(
585
+		$inputted_query_params_of_this_type,
586
+		EEM_Base $model,
587
+		$requested_version
588
+	) {
589
+		$query_param_for_models = [];
590
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
591
+			$field = ModelDataTranslator::deduceFieldFromQueryParam(
592
+				ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key),
593
+				$model
594
+			);
595
+			if ($field instanceof EE_Model_Field_Base) {
596
+				// did they specify an operator?
597
+				if (is_array($query_param_value)) {
598
+					$op               = $query_param_value[0];
599
+					$translated_value = [$op];
600
+					if (isset($query_param_value[1])) {
601
+						$value               = $query_param_value[1];
602
+						$translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson(
603
+							$field,
604
+							$value,
605
+							$requested_version
606
+						);
607
+					}
608
+				} else {
609
+					$translated_value = ModelDataTranslator::prepareFieldValueForJson(
610
+						$field,
611
+						$query_param_value,
612
+						$requested_version
613
+					);
614
+				}
615
+				$query_param_for_models[ $query_param_key ] = $translated_value;
616
+			} else {
617
+				// so it's not for a field, assume it's a logic query param key
618
+				$query_param_for_models[ $query_param_key ] =
619
+					ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
620
+						$query_param_value,
621
+						$model,
622
+						$requested_version
623
+					);
624
+			}
625
+		}
626
+		return $query_param_for_models;
627
+	}
628
+
629
+
630
+	/**
631
+	 * @param $condition_query_param_key
632
+	 * @return string
633
+	 */
634
+	public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key)
635
+	{
636
+		$pos_of_star = strpos($condition_query_param_key, '*');
637
+		if ($pos_of_star === false) {
638
+			return $condition_query_param_key;
639
+		}
640
+		return substr($condition_query_param_key, 0, $pos_of_star);
641
+	}
642
+
643
+
644
+	/**
645
+	 * Takes the input parameter and finds the model field that it indicates.
646
+	 *
647
+	 * @param string   $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
648
+	 * @param EEM_Base $model
649
+	 * @return EE_Model_Field_Base
650
+	 * @throws EE_Error
651
+	 * @throws ReflectionException
652
+	 */
653
+	public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model)
654
+	{
655
+		// ok, now proceed with deducing which part is the model's name, and which is the field's name
656
+		// which will help us find the database table and column
657
+		$query_param_parts = explode('.', $query_param_name);
658
+		if (empty($query_param_parts)) {
659
+			throw new EE_Error(
660
+				sprintf(
661
+					esc_html__(
662
+						'_extract_column_name is empty when trying to extract column and table name from %s',
663
+						'event_espresso'
664
+					),
665
+					$query_param_name
666
+				)
667
+			);
668
+		}
669
+		$number_of_parts       = count($query_param_parts);
670
+		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
671
+		$field_name            = $last_query_param_part;
672
+		if ($number_of_parts !== 1) {
673
+			// the last part is the column name, and there are only 2parts. therefore...
674
+			$model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
675
+		}
676
+		try {
677
+			return $model->field_settings_for($field_name, false);
678
+		} catch (EE_Error $e) {
679
+			return null;
680
+		}
681
+	}
682
+
683
+
684
+	/**
685
+	 * Returns true if $data can be easily represented in JSON.
686
+	 * Basically, objects and resources can't be represented in JSON easily.
687
+	 *
688
+	 * @param mixed $data
689
+	 * @return bool
690
+	 */
691
+	protected static function isRepresentableInJson($data)
692
+	{
693
+		return is_scalar($data)
694
+			   || is_array($data)
695
+			   || is_null($data);
696
+	}
697 697
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Attendee_Shortcodes.lib.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             ? null
115 115
             : $this->_data;
116 116
 
117
-        if (! $registration instanceof EE_Registration) {
117
+        if ( ! $registration instanceof EE_Registration) {
118 118
             // let's attempt to get the txn_id for the error message.
119 119
             $txn_id  = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction
120 120
                 ? $this->_extra->txn->ID()
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
         }
132 132
 
133 133
         // attendee obj for this registration
134
-        $attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj'])
135
-            ? $this->_extra->registrations[ $registration->ID() ]['att_obj']
134
+        $attendee = isset($this->_extra->registrations[$registration->ID()]['att_obj'])
135
+            ? $this->_extra->registrations[$registration->ID()]['att_obj']
136 136
             : null;
137 137
 
138
-        if (! $attendee instanceof EE_Attendee) {
139
-            $msg     = esc_html__(
138
+        if ( ! $attendee instanceof EE_Attendee) {
139
+            $msg = esc_html__(
140 140
                 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.',
141 141
                 'event_espresso'
142 142
             );
Please login to merge, or discard this patch.
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -15,192 +15,192 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Attendee_Shortcodes extends EE_Shortcodes
17 17
 {
18
-    /**
19
-     * hold all extra data.
20
-     *
21
-     * @var array
22
-     */
23
-    protected $_extra;
24
-
25
-
26
-    /**
27
-     * EE_Attendee_Shortcodes constructor.
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct();
32
-    }
33
-
34
-
35
-    protected function _init_props()
36
-    {
37
-        $this->label       = esc_html__('Attendee Shortcodes', 'event_espresso');
38
-        $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso');
39
-        $this->_shortcodes = [
40
-            '[FNAME]'                          => esc_html__('First Name of an attendee.', 'event_espresso'),
41
-            '[LNAME]'                          => esc_html__('Last Name of an attendee.', 'event_espresso'),
42
-            '[ATTENDEE_EMAIL]'                 => esc_html__('Email address for the attendee.', 'event_espresso'),
43
-            '[EDIT_ATTENDEE_LINK]'             => esc_html__(
44
-                'Edit Registration Link (typically you\'d only use this for messages going to event administrators)',
45
-                'event_espresso'
46
-            ),
47
-            '[REGISTRATION_ID]'                => esc_html__(
48
-                'Unique Registration ID for the registration',
49
-                'event_espresso'
50
-            ),
51
-            '[REGISTRATION_CODE]'              => esc_html__(
52
-                'Unique Registration Code for the registration',
53
-                'event_espresso'
54
-            ),
55
-            '[REGISTRATION_STATUS_ID]'         => esc_html__(
56
-                'Parses to the registration status for the attendee',
57
-                'event_espresso'
58
-            ),
59
-            '[REGISTRATION_STATUS_LABEL]'      => esc_html__(
60
-                'Parses to the status label for the registrant',
61
-                'event_espresso'
62
-            ),
63
-            '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__(
64
-                'Parses to the total amount paid for this registration.',
65
-                'event_espresso'
66
-            ),
67
-            '[FRONTEND_EDIT_REG_LINK]'         => esc_html__(
68
-                'Generates a link for the given registration to edit this registration details on the frontend.',
69
-                'event_espresso'
70
-            ),
71
-            '[PHONE_NUMBER]'                   => esc_html__(
72
-                'The Phone Number for the Registration.',
73
-                'event_espresso'
74
-            ),
75
-            '[ADDRESS]'                        => esc_html__('The Address for the Registration', 'event_espresso'),
76
-            '[ADDRESS2]'                       => esc_html__(
77
-                'Whatever was in the address 2 field for the registration.',
78
-                'event_espresso'
79
-            ),
80
-            '[CITY]'                           => esc_html__('The city for the registration.', 'event_espresso'),
81
-            '[ZIP_PC]'                         => esc_html__(
82
-                'The ZIP (or Postal) Code for the Registration.',
83
-                'event_espresso'
84
-            ),
85
-            '[ADDRESS_STATE]'                  => esc_html__(
86
-                'The state/province for the registration.',
87
-                'event_espresso'
88
-            ),
89
-            '[COUNTRY]'                        => esc_html__('The country for the registration.', 'event_espresso'),
90
-        ];
91
-    }
92
-
93
-
94
-    /**
95
-     * handles shortcode parsing
96
-     *
97
-     * @access protected
98
-     * @param string $shortcode the shortcode to be parsed.
99
-     * @return string
100
-     * @throws EE_Error
101
-     * @throws ReflectionException
102
-     */
103
-    protected function _parser($shortcode)
104
-    {
105
-
106
-
107
-        $this->_extra = ! empty($this->_extra_data) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
108
-            ? $this->_extra_data['data']
109
-            : null;
110
-
111
-        // incoming object should only be a registration object.
112
-        $registration = ! $this->_data instanceof EE_Registration
113
-            ? null
114
-            : $this->_data;
115
-
116
-        if (! $registration instanceof EE_Registration) {
117
-            // let's attempt to get the txn_id for the error message.
118
-            $txn_id  = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction
119
-                ? $this->_extra->txn->ID()
120
-                : esc_html__('Unknown', 'event_espresso');
121
-            $msg     = esc_html__(
122
-                'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.',
123
-                'event_espresso'
124
-            );
125
-            $dev_msg = sprintf(
126
-                esc_html__('The transaction ID for this request is: %s', 'event_espresso'),
127
-                $txn_id
128
-            );
129
-            throw new EE_Error("{$msg}||{$msg} {$dev_msg}");
130
-        }
131
-
132
-        // attendee obj for this registration
133
-        $attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj'])
134
-            ? $this->_extra->registrations[ $registration->ID() ]['att_obj']
135
-            : null;
136
-
137
-        if (! $attendee instanceof EE_Attendee) {
138
-            $msg     = esc_html__(
139
-                'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.',
140
-                'event_espresso'
141
-            );
142
-            $dev_msg = sprintf(
143
-                esc_html__('The registration ID for this request is: %s', 'event_espresso'),
144
-                $registration->ID()
145
-            );
146
-            throw new EE_Error("{$msg}||{$msg} {$dev_msg}");
147
-        }
148
-
149
-        switch ($shortcode) {
150
-            case '[FNAME]':
151
-                return $attendee->fname();
152
-
153
-            case '[LNAME]':
154
-                return $attendee->lname();
155
-
156
-            case '[ATTENDEE_EMAIL]':
157
-                return $attendee->email();
158
-
159
-            case '[EDIT_ATTENDEE_LINK]':
160
-                return $registration->get_admin_edit_url();
161
-
162
-            case '[REGISTRATION_CODE]':
163
-                return $registration->reg_code();
164
-
165
-            case '[REGISTRATION_ID]':
166
-                return $registration->ID();
167
-
168
-            case '[FRONTEND_EDIT_REG_LINK]':
169
-                return $registration->edit_attendee_information_url();
170
-
171
-            case '[PHONE_NUMBER]':
172
-                return $attendee->phone();
173
-
174
-            case '[ADDRESS]':
175
-                return $attendee->address();
176
-
177
-            case '[ADDRESS2]':
178
-                return $attendee->address2();
179
-
180
-            case '[CITY]':
181
-                return $attendee->city();
182
-
183
-            case '[ZIP_PC]':
184
-                return $attendee->zip();
185
-
186
-            case '[ADDRESS_STATE]':
187
-                $state_obj = $attendee->state_obj();
188
-                return $state_obj instanceof EE_State ? $state_obj->name() : '';
189
-
190
-            case '[COUNTRY]':
191
-                $country_obj = $attendee->country_obj();
192
-                return $country_obj instanceof EE_Country ? $country_obj->name() : '';
193
-
194
-            case '[REGISTRATION_STATUS_ID]':
195
-                return $registration->status_ID();
196
-
197
-            case '[REGISTRATION_STATUS_LABEL]':
198
-                return $registration->pretty_status();
199
-
200
-            case '[REGISTRATION_TOTAL_AMOUNT_PAID]':
201
-                return $registration->pretty_paid();
202
-        }
203
-
204
-        return '';
205
-    }
18
+	/**
19
+	 * hold all extra data.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	protected $_extra;
24
+
25
+
26
+	/**
27
+	 * EE_Attendee_Shortcodes constructor.
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct();
32
+	}
33
+
34
+
35
+	protected function _init_props()
36
+	{
37
+		$this->label       = esc_html__('Attendee Shortcodes', 'event_espresso');
38
+		$this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso');
39
+		$this->_shortcodes = [
40
+			'[FNAME]'                          => esc_html__('First Name of an attendee.', 'event_espresso'),
41
+			'[LNAME]'                          => esc_html__('Last Name of an attendee.', 'event_espresso'),
42
+			'[ATTENDEE_EMAIL]'                 => esc_html__('Email address for the attendee.', 'event_espresso'),
43
+			'[EDIT_ATTENDEE_LINK]'             => esc_html__(
44
+				'Edit Registration Link (typically you\'d only use this for messages going to event administrators)',
45
+				'event_espresso'
46
+			),
47
+			'[REGISTRATION_ID]'                => esc_html__(
48
+				'Unique Registration ID for the registration',
49
+				'event_espresso'
50
+			),
51
+			'[REGISTRATION_CODE]'              => esc_html__(
52
+				'Unique Registration Code for the registration',
53
+				'event_espresso'
54
+			),
55
+			'[REGISTRATION_STATUS_ID]'         => esc_html__(
56
+				'Parses to the registration status for the attendee',
57
+				'event_espresso'
58
+			),
59
+			'[REGISTRATION_STATUS_LABEL]'      => esc_html__(
60
+				'Parses to the status label for the registrant',
61
+				'event_espresso'
62
+			),
63
+			'[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__(
64
+				'Parses to the total amount paid for this registration.',
65
+				'event_espresso'
66
+			),
67
+			'[FRONTEND_EDIT_REG_LINK]'         => esc_html__(
68
+				'Generates a link for the given registration to edit this registration details on the frontend.',
69
+				'event_espresso'
70
+			),
71
+			'[PHONE_NUMBER]'                   => esc_html__(
72
+				'The Phone Number for the Registration.',
73
+				'event_espresso'
74
+			),
75
+			'[ADDRESS]'                        => esc_html__('The Address for the Registration', 'event_espresso'),
76
+			'[ADDRESS2]'                       => esc_html__(
77
+				'Whatever was in the address 2 field for the registration.',
78
+				'event_espresso'
79
+			),
80
+			'[CITY]'                           => esc_html__('The city for the registration.', 'event_espresso'),
81
+			'[ZIP_PC]'                         => esc_html__(
82
+				'The ZIP (or Postal) Code for the Registration.',
83
+				'event_espresso'
84
+			),
85
+			'[ADDRESS_STATE]'                  => esc_html__(
86
+				'The state/province for the registration.',
87
+				'event_espresso'
88
+			),
89
+			'[COUNTRY]'                        => esc_html__('The country for the registration.', 'event_espresso'),
90
+		];
91
+	}
92
+
93
+
94
+	/**
95
+	 * handles shortcode parsing
96
+	 *
97
+	 * @access protected
98
+	 * @param string $shortcode the shortcode to be parsed.
99
+	 * @return string
100
+	 * @throws EE_Error
101
+	 * @throws ReflectionException
102
+	 */
103
+	protected function _parser($shortcode)
104
+	{
105
+
106
+
107
+		$this->_extra = ! empty($this->_extra_data) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
108
+			? $this->_extra_data['data']
109
+			: null;
110
+
111
+		// incoming object should only be a registration object.
112
+		$registration = ! $this->_data instanceof EE_Registration
113
+			? null
114
+			: $this->_data;
115
+
116
+		if (! $registration instanceof EE_Registration) {
117
+			// let's attempt to get the txn_id for the error message.
118
+			$txn_id  = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction
119
+				? $this->_extra->txn->ID()
120
+				: esc_html__('Unknown', 'event_espresso');
121
+			$msg     = esc_html__(
122
+				'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.',
123
+				'event_espresso'
124
+			);
125
+			$dev_msg = sprintf(
126
+				esc_html__('The transaction ID for this request is: %s', 'event_espresso'),
127
+				$txn_id
128
+			);
129
+			throw new EE_Error("{$msg}||{$msg} {$dev_msg}");
130
+		}
131
+
132
+		// attendee obj for this registration
133
+		$attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj'])
134
+			? $this->_extra->registrations[ $registration->ID() ]['att_obj']
135
+			: null;
136
+
137
+		if (! $attendee instanceof EE_Attendee) {
138
+			$msg     = esc_html__(
139
+				'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.',
140
+				'event_espresso'
141
+			);
142
+			$dev_msg = sprintf(
143
+				esc_html__('The registration ID for this request is: %s', 'event_espresso'),
144
+				$registration->ID()
145
+			);
146
+			throw new EE_Error("{$msg}||{$msg} {$dev_msg}");
147
+		}
148
+
149
+		switch ($shortcode) {
150
+			case '[FNAME]':
151
+				return $attendee->fname();
152
+
153
+			case '[LNAME]':
154
+				return $attendee->lname();
155
+
156
+			case '[ATTENDEE_EMAIL]':
157
+				return $attendee->email();
158
+
159
+			case '[EDIT_ATTENDEE_LINK]':
160
+				return $registration->get_admin_edit_url();
161
+
162
+			case '[REGISTRATION_CODE]':
163
+				return $registration->reg_code();
164
+
165
+			case '[REGISTRATION_ID]':
166
+				return $registration->ID();
167
+
168
+			case '[FRONTEND_EDIT_REG_LINK]':
169
+				return $registration->edit_attendee_information_url();
170
+
171
+			case '[PHONE_NUMBER]':
172
+				return $attendee->phone();
173
+
174
+			case '[ADDRESS]':
175
+				return $attendee->address();
176
+
177
+			case '[ADDRESS2]':
178
+				return $attendee->address2();
179
+
180
+			case '[CITY]':
181
+				return $attendee->city();
182
+
183
+			case '[ZIP_PC]':
184
+				return $attendee->zip();
185
+
186
+			case '[ADDRESS_STATE]':
187
+				$state_obj = $attendee->state_obj();
188
+				return $state_obj instanceof EE_State ? $state_obj->name() : '';
189
+
190
+			case '[COUNTRY]':
191
+				$country_obj = $attendee->country_obj();
192
+				return $country_obj instanceof EE_Country ? $country_obj->name() : '';
193
+
194
+			case '[REGISTRATION_STATUS_ID]':
195
+				return $registration->status_ID();
196
+
197
+			case '[REGISTRATION_STATUS_LABEL]':
198
+				return $registration->pretty_status();
199
+
200
+			case '[REGISTRATION_TOTAL_AMOUNT_PAID]':
201
+				return $registration->pretty_paid();
202
+		}
203
+
204
+		return '';
205
+	}
206 206
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Attendee_List_Shortcodes.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         $att_result    = '';
160 160
         $registrations =
161 161
             isset($this->_extra_data['data']->tickets)
162
-                ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs']
162
+                ? $this->_extra_data['data']->tickets[$ticket->ID()]['reg_objs']
163 163
                 : [];
164 164
 
165 165
         // each attendee in this case should be an attendee object.
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     private function _get_registrations_from_event(EE_Event $event)
186 186
     {
187 187
         return isset($this->_extra_data['data']->events)
188
-            ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs']
188
+            ? $this->_extra_data['data']->events[$event->ID()]['reg_objs']
189 189
             : [];
190 190
     }
191 191
 }
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -18,173 +18,173 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Attendee_List_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    public function __construct()
22
-    {
23
-        parent::__construct();
24
-    }
25
-
26
-
27
-    protected function _init_props()
28
-    {
29
-        $this->label       = esc_html__('Attendee List Shortcodes', 'event_espresso');
30
-        $this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso');
31
-        $this->_shortcodes = [
32
-            '[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'),
33
-        ];
34
-    }
35
-
36
-
37
-    /**
38
-     * @param string $shortcode
39
-     * @return string
40
-     * @throws EE_Error
41
-     * @throws ReflectionException
42
-     */
43
-    protected function _parser($shortcode)
44
-    {
45
-        switch ($shortcode) {
46
-            case '[ATTENDEE_LIST]':
47
-                return $this->_get_attendee_list();
48
-        }
49
-        return '';
50
-    }
51
-
52
-
53
-    /**
54
-     * figure out what the incoming data is and then return the appropriate parsed value.
55
-     *
56
-     * @return string
57
-     * @throws EE_Error
58
-     * @throws ReflectionException
59
-     */
60
-    private function _get_attendee_list()
61
-    {
62
-        $this->_validate_list_requirements();
63
-
64
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
65
-            return $this->_get_attendee_list_for_main();
66
-        }
67
-        if ($this->_data['data'] instanceof EE_Event) {
68
-            return $this->_get_attendee_list_for_event();
69
-        }
70
-        if ($this->_data['data'] instanceof EE_Ticket) {
71
-            return $this->_get_registration_list_for_ticket();
72
-        }
73
-        // prevent recursive loop
74
-        return '';
75
-    }
76
-
77
-
78
-    /**
79
-     * This returns the parsed attendee list for main template;
80
-     */
81
-    private function _get_attendee_list_for_main()
82
-    {
83
-        $valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details'];
84
-        $template         = $this->_data['template'];
85
-        $data             = $this->_data['data'];
86
-        $attendees        = '';
87
-
88
-
89
-        // now we need to loop through the attendee list and send data to the EE_Parser helper.
90
-        foreach ($data->reg_objs as $registration) {
91
-            $attendees .= $this->_shortcode_helper->parse_attendee_list_template(
92
-                $template,
93
-                $registration,
94
-                $valid_shortcodes,
95
-                $this->_extra_data
96
-            );
97
-        }
98
-
99
-        return $attendees;
100
-    }
101
-
102
-
103
-    /**
104
-     * return parsed list of attendees for an event
105
-     *
106
-     * @return string
107
-     * @throws EE_Error
108
-     * @throws ReflectionException
109
-     */
110
-    private function _get_attendee_list_for_event()
111
-    {
112
-        $valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details'];
113
-        $template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
114
-            ? $this->_data['template']['attendee_list']
115
-            : $this->_extra_data['template']['attendee_list'];
116
-        $event            = $this->_data['data'];
117
-
118
-        // let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion.
119
-        $template = str_replace('[EVENT_LIST]', '', $template);
120
-
121
-        // here we're setting up the attendees for the attendee_list template for THIS event.
122
-        $att_result    = '';
123
-        $registrations = $this->_get_registrations_from_event($event);
124
-
125
-        // each attendee in this case should be an attendee object.
126
-        foreach ($registrations as $registration) {
127
-            $att_result .= $this->_shortcode_helper->parse_attendee_list_template(
128
-                $template,
129
-                $registration,
130
-                $valid_shortcodes,
131
-                $this->_extra_data
132
-            );
133
-        }
134
-
135
-        return $att_result;
136
-    }
137
-
138
-
139
-    /**
140
-     * return parsed list of attendees for a ticket
141
-     *
142
-     * @return string
143
-     */
144
-    private function _get_registration_list_for_ticket()
145
-    {
146
-        $valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details'];
147
-        $template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
148
-            ? $this->_data['template']['attendee_list']
149
-            : $this->_extra_data['template']['attendee_list'];
150
-        $ticket           = $this->_data['data'];
151
-
152
-        // let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion.
153
-        $template = str_replace('[TICKET_LIST]', '', $template);
154
-        $template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template);
155
-        $template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template);
156
-
157
-        // here we're setting up the attendees for the attendee_list template for THIS ticket.
158
-        $att_result    = '';
159
-        $registrations =
160
-            isset($this->_extra_data['data']->tickets)
161
-                ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs']
162
-                : [];
163
-
164
-        // each attendee in this case should be an attendee object.
165
-        foreach ($registrations as $registration) {
166
-            $att_result .= $this->_shortcode_helper->parse_attendee_list_template(
167
-                $template,
168
-                $registration,
169
-                $valid_shortcodes,
170
-                $this->_extra_data
171
-            );
172
-        }
173
-
174
-        return $att_result;
175
-    }
176
-
177
-
178
-    /**
179
-     * @param EE_Event $event
180
-     * @return array|mixed
181
-     * @throws EE_Error
182
-     * @throws ReflectionException
183
-     */
184
-    private function _get_registrations_from_event(EE_Event $event)
185
-    {
186
-        return isset($this->_extra_data['data']->events)
187
-            ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs']
188
-            : [];
189
-    }
21
+	public function __construct()
22
+	{
23
+		parent::__construct();
24
+	}
25
+
26
+
27
+	protected function _init_props()
28
+	{
29
+		$this->label       = esc_html__('Attendee List Shortcodes', 'event_espresso');
30
+		$this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso');
31
+		$this->_shortcodes = [
32
+			'[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'),
33
+		];
34
+	}
35
+
36
+
37
+	/**
38
+	 * @param string $shortcode
39
+	 * @return string
40
+	 * @throws EE_Error
41
+	 * @throws ReflectionException
42
+	 */
43
+	protected function _parser($shortcode)
44
+	{
45
+		switch ($shortcode) {
46
+			case '[ATTENDEE_LIST]':
47
+				return $this->_get_attendee_list();
48
+		}
49
+		return '';
50
+	}
51
+
52
+
53
+	/**
54
+	 * figure out what the incoming data is and then return the appropriate parsed value.
55
+	 *
56
+	 * @return string
57
+	 * @throws EE_Error
58
+	 * @throws ReflectionException
59
+	 */
60
+	private function _get_attendee_list()
61
+	{
62
+		$this->_validate_list_requirements();
63
+
64
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
65
+			return $this->_get_attendee_list_for_main();
66
+		}
67
+		if ($this->_data['data'] instanceof EE_Event) {
68
+			return $this->_get_attendee_list_for_event();
69
+		}
70
+		if ($this->_data['data'] instanceof EE_Ticket) {
71
+			return $this->_get_registration_list_for_ticket();
72
+		}
73
+		// prevent recursive loop
74
+		return '';
75
+	}
76
+
77
+
78
+	/**
79
+	 * This returns the parsed attendee list for main template;
80
+	 */
81
+	private function _get_attendee_list_for_main()
82
+	{
83
+		$valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details'];
84
+		$template         = $this->_data['template'];
85
+		$data             = $this->_data['data'];
86
+		$attendees        = '';
87
+
88
+
89
+		// now we need to loop through the attendee list and send data to the EE_Parser helper.
90
+		foreach ($data->reg_objs as $registration) {
91
+			$attendees .= $this->_shortcode_helper->parse_attendee_list_template(
92
+				$template,
93
+				$registration,
94
+				$valid_shortcodes,
95
+				$this->_extra_data
96
+			);
97
+		}
98
+
99
+		return $attendees;
100
+	}
101
+
102
+
103
+	/**
104
+	 * return parsed list of attendees for an event
105
+	 *
106
+	 * @return string
107
+	 * @throws EE_Error
108
+	 * @throws ReflectionException
109
+	 */
110
+	private function _get_attendee_list_for_event()
111
+	{
112
+		$valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details'];
113
+		$template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
114
+			? $this->_data['template']['attendee_list']
115
+			: $this->_extra_data['template']['attendee_list'];
116
+		$event            = $this->_data['data'];
117
+
118
+		// let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion.
119
+		$template = str_replace('[EVENT_LIST]', '', $template);
120
+
121
+		// here we're setting up the attendees for the attendee_list template for THIS event.
122
+		$att_result    = '';
123
+		$registrations = $this->_get_registrations_from_event($event);
124
+
125
+		// each attendee in this case should be an attendee object.
126
+		foreach ($registrations as $registration) {
127
+			$att_result .= $this->_shortcode_helper->parse_attendee_list_template(
128
+				$template,
129
+				$registration,
130
+				$valid_shortcodes,
131
+				$this->_extra_data
132
+			);
133
+		}
134
+
135
+		return $att_result;
136
+	}
137
+
138
+
139
+	/**
140
+	 * return parsed list of attendees for a ticket
141
+	 *
142
+	 * @return string
143
+	 */
144
+	private function _get_registration_list_for_ticket()
145
+	{
146
+		$valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details'];
147
+		$template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
148
+			? $this->_data['template']['attendee_list']
149
+			: $this->_extra_data['template']['attendee_list'];
150
+		$ticket           = $this->_data['data'];
151
+
152
+		// let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion.
153
+		$template = str_replace('[TICKET_LIST]', '', $template);
154
+		$template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template);
155
+		$template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template);
156
+
157
+		// here we're setting up the attendees for the attendee_list template for THIS ticket.
158
+		$att_result    = '';
159
+		$registrations =
160
+			isset($this->_extra_data['data']->tickets)
161
+				? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs']
162
+				: [];
163
+
164
+		// each attendee in this case should be an attendee object.
165
+		foreach ($registrations as $registration) {
166
+			$att_result .= $this->_shortcode_helper->parse_attendee_list_template(
167
+				$template,
168
+				$registration,
169
+				$valid_shortcodes,
170
+				$this->_extra_data
171
+			);
172
+		}
173
+
174
+		return $att_result;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @param EE_Event $event
180
+	 * @return array|mixed
181
+	 * @throws EE_Error
182
+	 * @throws ReflectionException
183
+	 */
184
+	private function _get_registrations_from_event(EE_Event $event)
185
+	{
186
+		return isset($this->_extra_data['data']->events)
187
+			? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs']
188
+			: [];
189
+	}
190 190
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Menu_Group.core.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,6 +39,6 @@
 block discarded – undo
39 39
 
40 40
     private function _group_link()
41 41
     {
42
-        return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
42
+        return '<span class="ee_menu_group"  onclick="return false;">'.$this->menu_label.'</span>';
43 43
     }
44 44
 }
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -13,31 +13,31 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Admin_Page_Menu_Group extends EE_Admin_Page_Menu_Map
15 15
 {
16
-    /**
17
-     * @throws EE_Error
18
-     */
19
-    public function __construct($menu_args = [])
20
-    {
21
-        $required = ['menu_label', 'menu_slug', 'menu_order', 'parent_slug'];
22
-        parent::__construct($menu_args, $required);
23
-    }
16
+	/**
17
+	 * @throws EE_Error
18
+	 */
19
+	public function __construct($menu_args = [])
20
+	{
21
+		$required = ['menu_label', 'menu_slug', 'menu_order', 'parent_slug'];
22
+		parent::__construct($menu_args, $required);
23
+	}
24 24
 
25 25
 
26
-    protected function _add_menu_page()
27
-    {
28
-        return add_submenu_page(
29
-            $this->parent_slug,
30
-            $this->menu_label,
31
-            $this->_group_link(),
32
-            $this->capability,
33
-            $this->menu_slug,
34
-            '__return_false'
35
-        );
36
-    }
26
+	protected function _add_menu_page()
27
+	{
28
+		return add_submenu_page(
29
+			$this->parent_slug,
30
+			$this->menu_label,
31
+			$this->_group_link(),
32
+			$this->capability,
33
+			$this->menu_slug,
34
+			'__return_false'
35
+		);
36
+	}
37 37
 
38 38
 
39
-    private function _group_link()
40
-    {
41
-        return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
42
-    }
39
+	private function _group_link()
40
+	{
41
+		return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
42
+	}
43 43
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Main_Menu.core.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
             $this->icon_url,
71 71
             $this->position
72 72
         );
73
-        if (! empty($this->subtitle)) {
73
+        if ( ! empty($this->subtitle)) {
74 74
             add_submenu_page(
75 75
                 $this->parent_slug,
76 76
                 $this->subtitle,
Please login to merge, or discard this patch.
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -9,76 +9,76 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Admin_Page_Main_Menu extends EE_Admin_Page_Menu_Map
11 11
 {
12
-    /**
13
-     * If included int incoming params, then this class will also register a Sub Menue Admin page with a different
14
-     * subtitle than the main menu item.
15
-     *
16
-     * @since 4.4.0
17
-     *
18
-     * @var string
19
-     */
20
-    public $subtitle;
12
+	/**
13
+	 * If included int incoming params, then this class will also register a Sub Menue Admin page with a different
14
+	 * subtitle than the main menu item.
15
+	 *
16
+	 * @since 4.4.0
17
+	 *
18
+	 * @var string
19
+	 */
20
+	public $subtitle;
21 21
 
22
-    /**
23
-     * The page to a icon used for this menu.
24
-     *
25
-     * @since  4.4.0
26
-     * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
27
-     *        for what can be set for this property.
28
-     * @var string
29
-     */
30
-    public $icon_url;
22
+	/**
23
+	 * The page to a icon used for this menu.
24
+	 *
25
+	 * @since  4.4.0
26
+	 * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
27
+	 *        for what can be set for this property.
28
+	 * @var string
29
+	 */
30
+	public $icon_url;
31 31
 
32 32
 
33
-    /**
34
-     * What position in the main menu order for the WP admin menu this menu item
35
-     * should show.
36
-     *
37
-     * @since  4.4.0
38
-     * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
39
-     *        for what can be set for this property.
40
-     * @var integer
41
-     */
42
-    public $position;
33
+	/**
34
+	 * What position in the main menu order for the WP admin menu this menu item
35
+	 * should show.
36
+	 *
37
+	 * @since  4.4.0
38
+	 * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
39
+	 *        for what can be set for this property.
40
+	 * @var integer
41
+	 */
42
+	public $position;
43 43
 
44 44
 
45
-    /**
46
-     * @throws EE_Error
47
-     */
48
-    public function __construct($menu_args)
49
-    {
50
-        $required = ['menu_label', 'parent_slug', 'menu_slug', 'menu_group', 'menu_order', 'admin_init_page'];
45
+	/**
46
+	 * @throws EE_Error
47
+	 */
48
+	public function __construct($menu_args)
49
+	{
50
+		$required = ['menu_label', 'parent_slug', 'menu_slug', 'menu_group', 'menu_order', 'admin_init_page'];
51 51
 
52
-        parent::__construct($menu_args, $required);
52
+		parent::__construct($menu_args, $required);
53 53
 
54
-        $this->position = ! empty($this->position) ? (int) $this->position : $this->position;
55
-    }
54
+		$this->position = ! empty($this->position) ? (int) $this->position : $this->position;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Uses the proper WP utility for registering a menu page for the main WP pages.
60
-     */
61
-    protected function _add_menu_page()
62
-    {
63
-        $main = add_menu_page(
64
-            $this->title,
65
-            $this->menu_label,
66
-            $this->capability,
67
-            $this->parent_slug,
68
-            $this->menu_callback,
69
-            $this->icon_url,
70
-            $this->position
71
-        );
72
-        if (! empty($this->subtitle)) {
73
-            add_submenu_page(
74
-                $this->parent_slug,
75
-                $this->subtitle,
76
-                $this->subtitle,
77
-                $this->capability,
78
-                $this->menu_slug,
79
-                $this->menu_callback
80
-            );
81
-        }
82
-        return $main;
83
-    }
58
+	/**
59
+	 * Uses the proper WP utility for registering a menu page for the main WP pages.
60
+	 */
61
+	protected function _add_menu_page()
62
+	{
63
+		$main = add_menu_page(
64
+			$this->title,
65
+			$this->menu_label,
66
+			$this->capability,
67
+			$this->parent_slug,
68
+			$this->menu_callback,
69
+			$this->icon_url,
70
+			$this->position
71
+		);
72
+		if (! empty($this->subtitle)) {
73
+			add_submenu_page(
74
+				$this->parent_slug,
75
+				$this->subtitle,
76
+				$this->subtitle,
77
+				$this->capability,
78
+				$this->menu_slug,
79
+				$this->menu_callback
80
+			);
81
+		}
82
+		return $main;
83
+	}
84 84
 }
Please login to merge, or discard this patch.
core/domain/services/admin/privacy/policy/privacy_policy.template.php 2 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -7,10 +7,10 @@  discard block
 block discarded – undo
7 7
 ?>
8 8
 <h2><?php esc_html_e('Event Registration Data', 'event_espresso'); ?></h2>
9 9
 <p><?php
10
-    esc_html_e(
11
-        'We collect information about you during event registration. This information may include but is not limited to:',
12
-        'event_espresso'
13
-    ); ?></p>
10
+	esc_html_e(
11
+		'We collect information about you during event registration. This information may include but is not limited to:',
12
+		'event_espresso'
13
+	); ?></p>
14 14
 <ul>
15 15
     <li><?php esc_html_e('Your names', 'event_espresso'); ?></li>
16 16
     <li><?php esc_html_e('Billing address', 'event_espresso'); ?></li>
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
     <li><?php esc_html_e('Email address', 'event_espresso'); ?></li>
19 19
     <li><?php esc_html_e('Phone number', 'event_espresso'); ?></li>
20 20
     <li><?php
21
-        esc_html_e(
22
-            'Location and traffic data (including partial IP address and browser type)',
23
-            'event_espresso'
24
-        ); ?>
21
+		esc_html_e(
22
+			'Location and traffic data (including partial IP address and browser type)',
23
+			'event_espresso'
24
+		); ?>
25 25
     </li>
26 26
     <li><?php
27
-        esc_html_e(
28
-            'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase',
29
-            'event_espresso'
30
-        ); ?>
27
+		esc_html_e(
28
+			'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase',
29
+			'event_espresso'
30
+		); ?>
31 31
     </li>
32 32
 </ul>
33 33
 
@@ -36,101 +36,101 @@  discard block
 block discarded – undo
36 36
     <li><?php esc_html_e('Send you important account/purchase/service information.', 'event_espresso'); ?></li>
37 37
     <li><?php esc_html_e('Respond to your queries, refund requests, or complaints.', 'event_espresso'); ?></li>
38 38
     <li><?php
39
-        esc_html_e(
40
-            'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.',
41
-            'event_espresso'
42
-        ); ?></li>
39
+		esc_html_e(
40
+			'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.',
41
+			'event_espresso'
42
+		); ?></li>
43 43
     <li><?php
44
-        esc_html_e(
45
-            'Set up and administer your account, provide technical and customer support, and to verify your identity.',
46
-            'event_espresso'
47
-        ); ?></li>
44
+		esc_html_e(
45
+			'Set up and administer your account, provide technical and customer support, and to verify your identity.',
46
+			'event_espresso'
47
+		); ?></li>
48 48
 </ul>
49 49
 
50 50
 <?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?>
51 51
     <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2>
52 52
     <?php
53
-    // if onsite or offsite payment methods are active
54
-    if (! empty($active_onsite_payment_methods)) { ?>
53
+	// if onsite or offsite payment methods are active
54
+	if (! empty($active_onsite_payment_methods)) { ?>
55 55
         <p><?php
56
-            esc_html_e(
57
-                'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.',
58
-                'event_espresso'
59
-            ); ?></p>
56
+			esc_html_e(
57
+				'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.',
58
+				'event_espresso'
59
+			); ?></p>
60 60
         <p><?php
61
-            printf(
62
-                esc_html_x(
63
-                    'Please see the privacy policy of %1$s.',
64
-                    'Please see the privacy policy of PayPal Pro',
65
-                    'event_espresso'
66
-                ),
67
-                implode(
68
-                    ', ',
69
-                    array_merge(
70
-                        $active_onsite_payment_methods,
71
-                        $active_offsite_payment_methods
72
-                    )
73
-                )
74
-            ); ?></p>
61
+			printf(
62
+				esc_html_x(
63
+					'Please see the privacy policy of %1$s.',
64
+					'Please see the privacy policy of PayPal Pro',
65
+					'event_espresso'
66
+				),
67
+				implode(
68
+					', ',
69
+					array_merge(
70
+						$active_onsite_payment_methods,
71
+						$active_offsite_payment_methods
72
+					)
73
+				)
74
+			); ?></p>
75 75
         <p><?php
76
-            esc_html_e(
77
-                'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).',
78
-                'event_espresso'
79
-            ); ?></p>
76
+			esc_html_e(
77
+				'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).',
78
+				'event_espresso'
79
+			); ?></p>
80 80
     <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?>
81 81
         <p><?php
82
-            printf(
83
-                esc_html_x(
84
-                    'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.',
85
-                    'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.',
86
-                    'event_espresso'
87
-                ),
88
-                implode(', ', $active_offsite_payment_methods)
89
-            ); ?></p>
82
+			printf(
83
+				esc_html_x(
84
+					'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.',
85
+					'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.',
86
+					'event_espresso'
87
+				),
88
+				implode(', ', $active_offsite_payment_methods)
89
+			); ?></p>
90 90
     <?php } ?>
91 91
     <h2><?php esc_html_e('Payment Logging', 'event_espresso'); ?></h2>
92 92
     <p><?php
93
-        esc_html_e(
94
-            'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.',
95
-            'event_espresso'
96
-        ); ?></p>
93
+		esc_html_e(
94
+			'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.',
95
+			'event_espresso'
96
+		); ?></p>
97 97
 <?php } ?>
98 98
 
99 99
 <h2><?php esc_html_e('Event Registration Cookies', 'event_espresso'); ?></h2>
100 100
 <p><?php
101
-    printf(
102
-        esc_html_x(
103
-            'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.',
104
-            'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.',
105
-            'event_espresso'
106
-        ),
107
-        $session_lifespan
108
-    ); ?></p>
101
+	printf(
102
+		esc_html_x(
103
+			'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.',
104
+			'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.',
105
+			'event_espresso'
106
+		),
107
+		$session_lifespan
108
+	); ?></p>
109 109
 
110 110
 <h2><?php esc_html_e('Email History Data', 'event_espresso'); ?></h2>
111 111
 <p><?php
112
-    esc_html_e(
113
-        'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.',
114
-        'event_espresso'
115
-    ); ?></p>
112
+	esc_html_e(
113
+		'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.',
114
+		'event_espresso'
115
+	); ?></p>
116 116
 
117 117
 <h2><?php esc_html_e('Event Check-In Record', 'event_espresso'); ?></h2>
118 118
 <p><?php
119
-    esc_html_e(
120
-        'When you attend an event, an event manager may record the time you check in or out of the event.',
121
-        'event_espresso'
122
-    ); ?></p>
119
+	esc_html_e(
120
+		'When you attend an event, an event manager may record the time you check in or out of the event.',
121
+		'event_espresso'
122
+	); ?></p>
123 123
 
124 124
 <h2><?php esc_html_e('Event Registration Data Retention', 'event_espresso'); ?></h2>
125 125
 <p><?php
126
-    esc_html_e(
127
-        'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.',
128
-        'event_espresso'
129
-    ); ?></p>
126
+	esc_html_e(
127
+		'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.',
128
+		'event_espresso'
129
+	); ?></p>
130 130
 
131 131
 <h2><?php esc_html_e('Event Registration Data Erasure and Export', 'event_espresso'); ?></h2>
132 132
 <p><?php
133
-    esc_html_e(
134
-        'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.',
135
-        'event_espresso'
136
-    ); ?></p>
133
+	esc_html_e(
134
+		'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.',
135
+		'event_espresso'
136
+	); ?></p>
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
         ); ?></li>
48 48
 </ul>
49 49
 
50
-<?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?>
50
+<?php if ( ! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?>
51 51
     <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2>
52 52
     <?php
53 53
     // if onsite or offsite payment methods are active
54
-    if (! empty($active_onsite_payment_methods)) { ?>
54
+    if ( ! empty($active_onsite_payment_methods)) { ?>
55 55
         <p><?php
56 56
             esc_html_e(
57 57
                 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.',
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
                 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).',
78 78
                 'event_espresso'
79 79
             ); ?></p>
80
-    <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?>
80
+    <?php } elseif ( ! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?>
81 81
         <p><?php
82 82
             printf(
83 83
                 esc_html_x(
Please login to merge, or discard this patch.