Completed
Pull Request — master (#331)
by Darren
16:18
created
caffeinated/modules/recaptcha_invisible/InvisibleRecaptcha.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -27,241 +27,241 @@
 block discarded – undo
27 27
 class InvisibleRecaptcha
28 28
 {
29 29
 
30
-    const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
30
+	const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
31 31
 
32
-    const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
32
+	const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
33 33
 
34
-    /**
35
-     * @var EE_Registration_Config $config
36
-     */
37
-    private $config;
34
+	/**
35
+	 * @var EE_Registration_Config $config
36
+	 */
37
+	private $config;
38 38
 
39
-    /**
40
-     * @var EE_Session $session
41
-     */
42
-    private $session;
39
+	/**
40
+	 * @var EE_Session $session
41
+	 */
42
+	private $session;
43 43
 
44
-    /**
45
-     * @var boolean $recaptcha_passed
46
-     */
47
-    private $recaptcha_passed;
44
+	/**
45
+	 * @var boolean $recaptcha_passed
46
+	 */
47
+	private $recaptcha_passed;
48 48
 
49 49
 
50
-    /**
51
-     * InvisibleRecaptcha constructor.
52
-     *
53
-     * @param EE_Registration_Config $registration_config
54
-     * @param EE_Session             $session
55
-     */
56
-    public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
57
-    {
58
-        $this->config = $registration_config;
59
-        $this->session = $session;
60
-    }
50
+	/**
51
+	 * InvisibleRecaptcha constructor.
52
+	 *
53
+	 * @param EE_Registration_Config $registration_config
54
+	 * @param EE_Session             $session
55
+	 */
56
+	public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
57
+	{
58
+		$this->config = $registration_config;
59
+		$this->session = $session;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @return boolean
65
-     */
66
-    public function useInvisibleRecaptcha()
67
-    {
68
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
69
-    }
63
+	/**
64
+	 * @return boolean
65
+	 */
66
+	public function useInvisibleRecaptcha()
67
+	{
68
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * @param array $input_settings
74
-     * @return EE_Invisible_Recaptcha_Input
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws InvalidArgumentException
78
-     * @throws DomainException
79
-     */
80
-    public function getInput(array $input_settings = array())
81
-    {
82
-        return new EE_Invisible_Recaptcha_Input(
83
-            $input_settings,
84
-            $this->config
85
-        );
86
-    }
72
+	/**
73
+	 * @param array $input_settings
74
+	 * @return EE_Invisible_Recaptcha_Input
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws InvalidArgumentException
78
+	 * @throws DomainException
79
+	 */
80
+	public function getInput(array $input_settings = array())
81
+	{
82
+		return new EE_Invisible_Recaptcha_Input(
83
+			$input_settings,
84
+			$this->config
85
+		);
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * @param array $input_settings
91
-     * @return string
92
-     * @throws EE_Error
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     * @throws InvalidArgumentException
96
-     * @throws DomainException
97
-     */
98
-    public function getInputHtml(array $input_settings = array())
99
-    {
100
-        return $this->getInput($input_settings)->get_html_for_input();
101
-    }
89
+	/**
90
+	 * @param array $input_settings
91
+	 * @return string
92
+	 * @throws EE_Error
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws InvalidArgumentException
96
+	 * @throws DomainException
97
+	 */
98
+	public function getInputHtml(array $input_settings = array())
99
+	{
100
+		return $this->getInput($input_settings)->get_html_for_input();
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * @param EE_Form_Section_Proper $form
106
-     * @param array                  $input_settings
107
-     * @throws EE_Error
108
-     * @throws InvalidArgumentException
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidInterfaceException
111
-     * @throws DomainException
112
-     */
113
-    public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
114
-    {
115
-        $form->add_subsections(
116
-            array(
117
-                'espresso_recaptcha' => $this->getInput($input_settings),
118
-            ),
119
-            null,
120
-            false
121
-        );
122
-    }
104
+	/**
105
+	 * @param EE_Form_Section_Proper $form
106
+	 * @param array                  $input_settings
107
+	 * @throws EE_Error
108
+	 * @throws InvalidArgumentException
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidInterfaceException
111
+	 * @throws DomainException
112
+	 */
113
+	public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
114
+	{
115
+		$form->add_subsections(
116
+			array(
117
+				'espresso_recaptcha' => $this->getInput($input_settings),
118
+			),
119
+			null,
120
+			false
121
+		);
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * @param EE_Request $request
127
-     * @return boolean
128
-     * @throws RuntimeException
129
-     */
130
-    public function verifyToken(EE_Request $request)
131
-    {
132
-        static $previous_recaptcha_response = array();
133
-        $grecaptcha_response = $request->get('g-recaptcha-response');
134
-        // if this token has already been verified, then return previous response
135
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
136
-            return $previous_recaptcha_response[ $grecaptcha_response ];
137
-        }
138
-        // will update to true if everything passes
139
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
140
-        $response                                            = wp_safe_remote_post(
141
-            InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
142
-            array(
143
-                'body' => array(
144
-                    'secret'   => $this->config->recaptcha_privatekey,
145
-                    'response' => $grecaptcha_response,
146
-                    'remoteip' => $request->ip_address(),
147
-                ),
148
-            )
149
-        );
150
-        if ($response instanceof WP_Error) {
151
-            $this->generateError($response->get_error_messages());
152
-            return false;
153
-        }
154
-        $results = json_decode(wp_remote_retrieve_body($response), true);
155
-        if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
156
-            $errors   = array_map(
157
-                array($this, 'getErrorCode'),
158
-                $results['error-codes']
159
-            );
160
-            if (isset($results['challenge_ts'])) {
161
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
162
-            }
163
-            $this->generateError(implode(' ', $errors));
164
-        }
165
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
166
-        add_action('shutdown', array($this, 'setSessionData'));
167
-        return true;
168
-    }
125
+	/**
126
+	 * @param EE_Request $request
127
+	 * @return boolean
128
+	 * @throws RuntimeException
129
+	 */
130
+	public function verifyToken(EE_Request $request)
131
+	{
132
+		static $previous_recaptcha_response = array();
133
+		$grecaptcha_response = $request->get('g-recaptcha-response');
134
+		// if this token has already been verified, then return previous response
135
+		if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
136
+			return $previous_recaptcha_response[ $grecaptcha_response ];
137
+		}
138
+		// will update to true if everything passes
139
+		$previous_recaptcha_response[ $grecaptcha_response ] = false;
140
+		$response                                            = wp_safe_remote_post(
141
+			InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
142
+			array(
143
+				'body' => array(
144
+					'secret'   => $this->config->recaptcha_privatekey,
145
+					'response' => $grecaptcha_response,
146
+					'remoteip' => $request->ip_address(),
147
+				),
148
+			)
149
+		);
150
+		if ($response instanceof WP_Error) {
151
+			$this->generateError($response->get_error_messages());
152
+			return false;
153
+		}
154
+		$results = json_decode(wp_remote_retrieve_body($response), true);
155
+		if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
156
+			$errors   = array_map(
157
+				array($this, 'getErrorCode'),
158
+				$results['error-codes']
159
+			);
160
+			if (isset($results['challenge_ts'])) {
161
+				$errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
162
+			}
163
+			$this->generateError(implode(' ', $errors));
164
+		}
165
+		$previous_recaptcha_response[ $grecaptcha_response ] = true;
166
+		add_action('shutdown', array($this, 'setSessionData'));
167
+		return true;
168
+	}
169 169
 
170 170
 
171
-    /**
172
-     * @param string $error_response
173
-     * @return void
174
-     * @throws RuntimeException
175
-     */
176
-    public function generateError($error_response = '')
177
-    {
178
-        throw new RuntimeException(
179
-            sprintf(
180
-                esc_html__(
181
-                    'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
182
-                    'event_espresso'
183
-                ),
184
-                '<br />',
185
-                current_user_can('manage_options') ? $error_response : ''
186
-            )
187
-        );
188
-    }
171
+	/**
172
+	 * @param string $error_response
173
+	 * @return void
174
+	 * @throws RuntimeException
175
+	 */
176
+	public function generateError($error_response = '')
177
+	{
178
+		throw new RuntimeException(
179
+			sprintf(
180
+				esc_html__(
181
+					'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
182
+					'event_espresso'
183
+				),
184
+				'<br />',
185
+				current_user_can('manage_options') ? $error_response : ''
186
+			)
187
+		);
188
+	}
189 189
 
190 190
 
191
-    /**
192
-     * @param string $error_code
193
-     * @return string
194
-     */
195
-    public function getErrorCode(&$error_code)
196
-    {
197
-        $error_codes = array(
198
-            'missing-input-secret'   => 'The secret parameter is missing.',
199
-            'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
200
-            'missing-input-response' => 'The response parameter is missing.',
201
-            'invalid-input-response' => 'The response parameter is invalid or malformed.',
202
-            'bad-request'            => 'The request is invalid or malformed.',
203
-            'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
204
-        );
205
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
206
-    }
191
+	/**
192
+	 * @param string $error_code
193
+	 * @return string
194
+	 */
195
+	public function getErrorCode(&$error_code)
196
+	{
197
+		$error_codes = array(
198
+			'missing-input-secret'   => 'The secret parameter is missing.',
199
+			'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
200
+			'missing-input-response' => 'The response parameter is missing.',
201
+			'invalid-input-response' => 'The response parameter is invalid or malformed.',
202
+			'bad-request'            => 'The request is invalid or malformed.',
203
+			'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
204
+		);
205
+		return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
206
+	}
207 207
 
208 208
 
209
-    /**
210
-     * @return array
211
-     * @throws InvalidInterfaceException
212
-     * @throws InvalidDataTypeException
213
-     * @throws InvalidArgumentException
214
-     */
215
-    public function getLocalizedVars()
216
-    {
217
-        return (array) apply_filters(
218
-            'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
219
-            array(
220
-                'siteKey'          => $this->config->recaptcha_publickey,
221
-                'recaptcha_passed' => $this->recaptchaPassed(),
222
-                'wp_debug'         => WP_DEBUG,
223
-                'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
224
-            )
225
-        );
226
-    }
209
+	/**
210
+	 * @return array
211
+	 * @throws InvalidInterfaceException
212
+	 * @throws InvalidDataTypeException
213
+	 * @throws InvalidArgumentException
214
+	 */
215
+	public function getLocalizedVars()
216
+	{
217
+		return (array) apply_filters(
218
+			'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
219
+			array(
220
+				'siteKey'          => $this->config->recaptcha_publickey,
221
+				'recaptcha_passed' => $this->recaptchaPassed(),
222
+				'wp_debug'         => WP_DEBUG,
223
+				'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
224
+			)
225
+		);
226
+	}
227 227
 
228 228
 
229
-    /**
230
-     * @return boolean
231
-     * @throws InvalidInterfaceException
232
-     * @throws InvalidDataTypeException
233
-     * @throws InvalidArgumentException
234
-     */
235
-    public function recaptchaPassed()
236
-    {
237
-        if ($this->recaptcha_passed !== null) {
238
-            return $this->recaptcha_passed;
239
-        }
240
-        // logged in means you have already passed a turing test of sorts
241
-        if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
242
-            $this->recaptcha_passed = true;
243
-            return $this->recaptcha_passed;
244
-        }
245
-        // was test already passed?
246
-        $this->recaptcha_passed = filter_var(
247
-            $this->session->get_session_data(
248
-                InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
249
-            ),
250
-            FILTER_VALIDATE_BOOLEAN
251
-        );
252
-        return $this->recaptcha_passed;
253
-    }
229
+	/**
230
+	 * @return boolean
231
+	 * @throws InvalidInterfaceException
232
+	 * @throws InvalidDataTypeException
233
+	 * @throws InvalidArgumentException
234
+	 */
235
+	public function recaptchaPassed()
236
+	{
237
+		if ($this->recaptcha_passed !== null) {
238
+			return $this->recaptcha_passed;
239
+		}
240
+		// logged in means you have already passed a turing test of sorts
241
+		if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
242
+			$this->recaptcha_passed = true;
243
+			return $this->recaptcha_passed;
244
+		}
245
+		// was test already passed?
246
+		$this->recaptcha_passed = filter_var(
247
+			$this->session->get_session_data(
248
+				InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
249
+			),
250
+			FILTER_VALIDATE_BOOLEAN
251
+		);
252
+		return $this->recaptcha_passed;
253
+	}
254 254
 
255 255
 
256
-    /**
257
-     * @throws InvalidArgumentException
258
-     * @throws InvalidDataTypeException
259
-     * @throws InvalidInterfaceException
260
-     */
261
-    public function setSessionData()
262
-    {
263
-        $this->session->set_session_data(
264
-            array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
265
-        );
266
-    }
256
+	/**
257
+	 * @throws InvalidArgumentException
258
+	 * @throws InvalidDataTypeException
259
+	 * @throws InvalidInterfaceException
260
+	 */
261
+	public function setSessionData()
262
+	{
263
+		$this->session->set_session_data(
264
+			array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
265
+		);
266
+	}
267 267
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
         static $previous_recaptcha_response = array();
133 133
         $grecaptcha_response = $request->get('g-recaptcha-response');
134 134
         // if this token has already been verified, then return previous response
135
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
136
-            return $previous_recaptcha_response[ $grecaptcha_response ];
135
+        if (isset($previous_recaptcha_response[$grecaptcha_response])) {
136
+            return $previous_recaptcha_response[$grecaptcha_response];
137 137
         }
138 138
         // will update to true if everything passes
139
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
139
+        $previous_recaptcha_response[$grecaptcha_response] = false;
140 140
         $response                                            = wp_safe_remote_post(
141 141
             InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
142 142
             array(
@@ -153,16 +153,16 @@  discard block
 block discarded – undo
153 153
         }
154 154
         $results = json_decode(wp_remote_retrieve_body($response), true);
155 155
         if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
156
-            $errors   = array_map(
156
+            $errors = array_map(
157 157
                 array($this, 'getErrorCode'),
158 158
                 $results['error-codes']
159 159
             );
160 160
             if (isset($results['challenge_ts'])) {
161
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
161
+                $errors[] = 'challenge timestamp: '.$results['challenge_ts'].'.';
162 162
             }
163 163
             $this->generateError(implode(' ', $errors));
164 164
         }
165
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
165
+        $previous_recaptcha_response[$grecaptcha_response] = true;
166 166
         add_action('shutdown', array($this, 'setSessionData'));
167 167
         return true;
168 168
     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             'bad-request'            => 'The request is invalid or malformed.',
203 203
             'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
204 204
         );
205
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
205
+        return isset($error_codes[$error_code]) ? $error_codes[$error_code] : '';
206 206
     }
207 207
 
208 208
 
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/RecaptchaFactory.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -19,35 +19,35 @@
 block discarded – undo
19 19
 class RecaptchaFactory implements FactoryInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @param array $arguments
24
-     * @return InvisibleRecaptcha
25
-     * @throws InvalidDataTypeException
26
-     * @throws InvalidInterfaceException
27
-     * @throws InvalidArgumentException
28
-     */
29
-    public static function create($arguments = array())
30
-    {
31
-        return LoaderFactory::getLoader()->getShared(
32
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha',
33
-            $arguments
34
-        );
35
-    }
22
+	/**
23
+	 * @param array $arguments
24
+	 * @return InvisibleRecaptcha
25
+	 * @throws InvalidDataTypeException
26
+	 * @throws InvalidInterfaceException
27
+	 * @throws InvalidArgumentException
28
+	 */
29
+	public static function create($arguments = array())
30
+	{
31
+		return LoaderFactory::getLoader()->getShared(
32
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha',
33
+			$arguments
34
+		);
35
+	}
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     * @param array $arguments
41
-     * @return RecaptchaAdminSettings
42
-     * @throws InvalidDataTypeException
43
-     * @throws InvalidInterfaceException
44
-     * @throws InvalidArgumentException
45
-     */
46
-    public static function getAdminModule($arguments = array())
47
-    {
48
-        return LoaderFactory::getLoader()->getShared(
49
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
50
-            $arguments
51
-        );
52
-    }
39
+	/**
40
+	 * @param array $arguments
41
+	 * @return RecaptchaAdminSettings
42
+	 * @throws InvalidDataTypeException
43
+	 * @throws InvalidInterfaceException
44
+	 * @throws InvalidArgumentException
45
+	 */
46
+	public static function getAdminModule($arguments = array())
47
+	{
48
+		return LoaderFactory::getLoader()->getShared(
49
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
50
+			$arguments
51
+		);
52
+	}
53 53
 }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/RecaptchaAdminSettings.php 1 patch
Indentation   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -31,361 +31,361 @@
 block discarded – undo
31 31
 class RecaptchaAdminSettings
32 32
 {
33 33
 
34
-    /**
35
-     * @var EE_Registration_Config $config
36
-     */
37
-    private $config;
34
+	/**
35
+	 * @var EE_Registration_Config $config
36
+	 */
37
+	private $config;
38 38
 
39 39
 
40
-    /**
41
-     * RecaptchaAdminSettings constructor.
42
-     *
43
-     * @param EE_Registration_Config $registration_config
44
-     */
45
-    public function __construct(EE_Registration_Config $registration_config)
46
-    {
47
-        $this->config = $registration_config;
48
-    }
40
+	/**
41
+	 * RecaptchaAdminSettings constructor.
42
+	 *
43
+	 * @param EE_Registration_Config $registration_config
44
+	 */
45
+	public function __construct(EE_Registration_Config $registration_config)
46
+	{
47
+		$this->config = $registration_config;
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @throws InvalidArgumentException
53
-     * @throws InvalidInterfaceException
54
-     * @throws InvalidDataTypeException
55
-     * @throws EE_Error
56
-     */
57
-    public function adminSettings()
58
-    {
59
-        echo $this->settingsForm()->get_html_and_js();
60
-    }
51
+	/**
52
+	 * @throws InvalidArgumentException
53
+	 * @throws InvalidInterfaceException
54
+	 * @throws InvalidDataTypeException
55
+	 * @throws EE_Error
56
+	 */
57
+	public function adminSettings()
58
+	{
59
+		echo $this->settingsForm()->get_html_and_js();
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @return EE_Form_Section_Proper
65
-     * @throws EE_Error
66
-     */
67
-    protected function settingsForm()
68
-    {
69
-        return new EE_Form_Section_Proper(
70
-            array(
71
-                'name'            => 'recaptcha_settings_form',
72
-                'html_id'         => 'recaptcha_settings_form',
73
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
74
-                'subsections'     => apply_filters(
75
-                    'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections',
76
-                    array(
77
-                        'main_settings_hdr'       => new EE_Form_Section_HTML(
78
-                            EEH_HTML::h2(
79
-                                esc_html__('reCAPTCHA Anti-spam Settings', 'event_espresso')
80
-                                . EEH_Template::get_help_tab_link('recaptcha_info')
81
-                            )
82
-                        ),
83
-                        'main_settings'           => $this->mainSettings(),
84
-                        'appearance_settings_hdr' => new EE_Form_Section_HTML(
85
-                            EEH_HTML::h2(esc_html__('reCAPTCHA Appearance', 'event_espresso'))
86
-                        ),
87
-                        'appearance_settings'     => $this->appearanceSettings(),
88
-                        'required_fields_note'    => new EE_Form_Section_HTML(
89
-                            EEH_HTML::p(
90
-                                esc_html__('All fields marked with a * are required fields', 'event_espresso'),
91
-                                '',
92
-                                'grey-text'
93
-                            )
94
-                        ),
95
-                    )
96
-                ),
97
-            )
98
-        );
99
-    }
63
+	/**
64
+	 * @return EE_Form_Section_Proper
65
+	 * @throws EE_Error
66
+	 */
67
+	protected function settingsForm()
68
+	{
69
+		return new EE_Form_Section_Proper(
70
+			array(
71
+				'name'            => 'recaptcha_settings_form',
72
+				'html_id'         => 'recaptcha_settings_form',
73
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
74
+				'subsections'     => apply_filters(
75
+					'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections',
76
+					array(
77
+						'main_settings_hdr'       => new EE_Form_Section_HTML(
78
+							EEH_HTML::h2(
79
+								esc_html__('reCAPTCHA Anti-spam Settings', 'event_espresso')
80
+								. EEH_Template::get_help_tab_link('recaptcha_info')
81
+							)
82
+						),
83
+						'main_settings'           => $this->mainSettings(),
84
+						'appearance_settings_hdr' => new EE_Form_Section_HTML(
85
+							EEH_HTML::h2(esc_html__('reCAPTCHA Appearance', 'event_espresso'))
86
+						),
87
+						'appearance_settings'     => $this->appearanceSettings(),
88
+						'required_fields_note'    => new EE_Form_Section_HTML(
89
+							EEH_HTML::p(
90
+								esc_html__('All fields marked with a * are required fields', 'event_espresso'),
91
+								'',
92
+								'grey-text'
93
+							)
94
+						),
95
+					)
96
+				),
97
+			)
98
+		);
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * @return EE_Form_Section_Proper
104
-     * @throws EE_Error
105
-     */
106
-    protected function mainSettings()
107
-    {
108
-        return new EE_Form_Section_Proper(
109
-            array(
110
-                'name'            => 'recaptcha_settings_tbl',
111
-                'html_id'         => 'recaptcha_settings_tbl',
112
-                'html_class'      => 'form-table',
113
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
114
-                'subsections'     => apply_filters(
115
-                    'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections',
116
-                    array(
117
-                        'use_captcha'          => new EE_Yes_No_Input(
118
-                            array(
119
-                                'html_label_text'         => esc_html__('Use reCAPTCHA', 'event_espresso'),
120
-                                'html_help_text'          => sprintf(
121
-                                    esc_html__(
122
-                                        'reCAPTCHA is a free service that  protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.',
123
-                                        'event_espresso'
124
-                                    ),
125
-                                    '<a href="https://www.google.com/recaptcha/intro/index.html">',
126
-                                    '</a>'
127
-                                ),
128
-                                'default'                 => $this->config->use_captcha !== null
129
-                                    ? $this->config->use_captcha : false,
130
-                                'display_html_label_text' => false,
131
-                            )
132
-                        ),
133
-                        'recaptcha_publickey'  => new EE_Text_Input(
134
-                            array(
135
-                                'html_label_text' => esc_html__('Site Key', 'event_espresso'),
136
-                                'html_help_text'  => esc_html__(
137
-                                    'The site key is used to display the widget on your site.',
138
-                                    'event_espresso'
139
-                                ),
140
-                                'default'         => $this->config->recaptcha_publickey !== null
141
-                                    ? stripslashes($this->config->recaptcha_publickey) : '',
142
-                            )
143
-                        ),
144
-                        'recaptcha_privatekey' => new EE_Text_Input(
145
-                            array(
146
-                                'html_label_text' => esc_html__('Secret Key', 'event_espresso'),
147
-                                'html_help_text'  => esc_html__(
148
-                                    'The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.',
149
-                                    'event_espresso'
150
-                                ),
151
-                                'default'         => $this->config->recaptcha_privatekey !== null
152
-                                    ? stripslashes($this->config->recaptcha_privatekey)
153
-                                    : '',
154
-                            )
155
-                        ),
156
-                        'recaptcha_protected_forms' => new EE_Checkbox_Multi_Input(
157
-                            array(
158
-                                'ticket_selector'   => esc_html__('Ticket Selector', 'event_espresso'),
159
-                                'registration_form' => esc_html__('Registration Form', 'event_espresso'),
160
-                            ),
161
-                            array(
162
-                                'html_label_text'         => esc_html__(
163
-                                    'Invisible reCAPTCHA Protection',
164
-                                    'event_espresso'
165
-                                ),
166
-                                'html_help_text'          => esc_html__(
167
-                                    'Select which Event Espresso forms you would like to enable Invisible reCAPTCHA on.',
168
-                                    'event_espresso'
169
-                                ),
170
-                                'default'                 => is_array($this->config->recaptcha_protected_forms)
171
-                                    ? $this->config->recaptcha_protected_forms
172
-                                    : array(),
173
-                                'display_html_label_text' => false,
174
-                            )
175
-                        ),
176
-                    )
177
-                ),
178
-            )
179
-        );
180
-    }
102
+	/**
103
+	 * @return EE_Form_Section_Proper
104
+	 * @throws EE_Error
105
+	 */
106
+	protected function mainSettings()
107
+	{
108
+		return new EE_Form_Section_Proper(
109
+			array(
110
+				'name'            => 'recaptcha_settings_tbl',
111
+				'html_id'         => 'recaptcha_settings_tbl',
112
+				'html_class'      => 'form-table',
113
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
114
+				'subsections'     => apply_filters(
115
+					'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections',
116
+					array(
117
+						'use_captcha'          => new EE_Yes_No_Input(
118
+							array(
119
+								'html_label_text'         => esc_html__('Use reCAPTCHA', 'event_espresso'),
120
+								'html_help_text'          => sprintf(
121
+									esc_html__(
122
+										'reCAPTCHA is a free service that  protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.',
123
+										'event_espresso'
124
+									),
125
+									'<a href="https://www.google.com/recaptcha/intro/index.html">',
126
+									'</a>'
127
+								),
128
+								'default'                 => $this->config->use_captcha !== null
129
+									? $this->config->use_captcha : false,
130
+								'display_html_label_text' => false,
131
+							)
132
+						),
133
+						'recaptcha_publickey'  => new EE_Text_Input(
134
+							array(
135
+								'html_label_text' => esc_html__('Site Key', 'event_espresso'),
136
+								'html_help_text'  => esc_html__(
137
+									'The site key is used to display the widget on your site.',
138
+									'event_espresso'
139
+								),
140
+								'default'         => $this->config->recaptcha_publickey !== null
141
+									? stripslashes($this->config->recaptcha_publickey) : '',
142
+							)
143
+						),
144
+						'recaptcha_privatekey' => new EE_Text_Input(
145
+							array(
146
+								'html_label_text' => esc_html__('Secret Key', 'event_espresso'),
147
+								'html_help_text'  => esc_html__(
148
+									'The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.',
149
+									'event_espresso'
150
+								),
151
+								'default'         => $this->config->recaptcha_privatekey !== null
152
+									? stripslashes($this->config->recaptcha_privatekey)
153
+									: '',
154
+							)
155
+						),
156
+						'recaptcha_protected_forms' => new EE_Checkbox_Multi_Input(
157
+							array(
158
+								'ticket_selector'   => esc_html__('Ticket Selector', 'event_espresso'),
159
+								'registration_form' => esc_html__('Registration Form', 'event_espresso'),
160
+							),
161
+							array(
162
+								'html_label_text'         => esc_html__(
163
+									'Invisible reCAPTCHA Protection',
164
+									'event_espresso'
165
+								),
166
+								'html_help_text'          => esc_html__(
167
+									'Select which Event Espresso forms you would like to enable Invisible reCAPTCHA on.',
168
+									'event_espresso'
169
+								),
170
+								'default'                 => is_array($this->config->recaptcha_protected_forms)
171
+									? $this->config->recaptcha_protected_forms
172
+									: array(),
173
+								'display_html_label_text' => false,
174
+							)
175
+						),
176
+					)
177
+				),
178
+			)
179
+		);
180
+	}
181 181
 
182 182
 
183
-    /**
184
-     * @return EE_Form_Section_Proper
185
-     * @throws EE_Error
186
-     */
187
-    protected function appearanceSettings()
188
-    {
189
-        return new EE_Form_Section_Proper(
190
-            array(
191
-                'name'            => 'recaptcha_appearance_settings_tbl',
192
-                'html_id'         => 'recaptcha_appearance_settings_tbl',
193
-                'html_class'      => 'form-table',
194
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
195
-                'subsections'     => apply_filters(
196
-                    'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections',
197
-                    array(
198
-                        'recaptcha_theme'    => new EE_Radio_Button_Input(
199
-                            array(
200
-                                'invisible' => esc_html__('Invisible', 'event_espresso'),
201
-                                'light'     => esc_html__('Light', 'event_espresso'),
202
-                                'dark'      => esc_html__('Dark', 'event_espresso'),
203
-                            ),
204
-                            array(
205
-                                'html_label_text'         => esc_html__('Theme', 'event_espresso'),
206
-                                'html_help_text'          => esc_html__(
207
-                                    'The color theme of the widget.',
208
-                                    'event_espresso'
209
-                                ),
210
-                                'default'                 => $this->config->recaptcha_theme !== null
211
-                                    ? $this->config->recaptcha_theme
212
-                                    : 'invisible',
213
-                                'display_html_label_text' => false,
214
-                            )
215
-                        ),
216
-                        'recaptcha_badge'     => new EE_Radio_Button_Input(
217
-                            array(
218
-                                'bottomleft' => esc_html__('Bottom Left', 'event_espresso'),
219
-                                'bottomright' => esc_html__('Bottom Right', 'event_espresso'),
220
-                                'inline' => esc_html__('Inline', 'event_espresso'),
221
-                            ),
222
-                            array(
223
-                                'html_label_text'         => esc_html__(
224
-                                    'Invisible reCAPTCHA Badge Position',
225
-                                    'event_espresso'
226
-                                ),
227
-                                'html_help_text'          => esc_html__(
228
-                                    'If using Invisible reCAPTCHA, then this determines the position of the reCAPTCHA badge. "Bottom Left" and "Bottom Right" both will float at the bottom of the screen. "Inline" appears beside the submit button but allows you to control the CSS.',
229
-                                    'event_espresso'
230
-                                ),
231
-                                'default'                 => $this->config->recaptcha_badge !== null
232
-                                    ? $this->config->recaptcha_badge
233
-                                    : 'bottomleft',
234
-                                'display_html_label_text' => false,
235
-                            )
236
-                        ),
237
-                        'recaptcha_type'     => new EE_Radio_Button_Input(
238
-                            array(
239
-                                'image' => esc_html__('Image', 'event_espresso'),
240
-                                'audio' => esc_html__('Audio', 'event_espresso'),
241
-                            ),
242
-                            array(
243
-                                'html_label_text'         => esc_html__('Type', 'event_espresso'),
244
-                                'html_help_text'          => esc_html__(
245
-                                    'The type of CAPTCHA to serve.',
246
-                                    'event_espresso'
247
-                                ),
248
-                                'default'                 => $this->config->recaptcha_type !== null
249
-                                    ? $this->config->recaptcha_type
250
-                                    : 'image',
251
-                                'display_html_label_text' => false,
252
-                            )
253
-                        ),
254
-                        'recaptcha_language' => new EE_Select_Input(
255
-                            array(
256
-                                'ar'     => esc_html__('Arabic', 'event_espresso'),
257
-                                'bg'     => esc_html__('Bulgarian', 'event_espresso'),
258
-                                'ca'     => esc_html__('Catalan', 'event_espresso'),
259
-                                'zh-CN'  => esc_html__('Chinese (Simplified)', 'event_espresso'),
260
-                                'zh-TW'  => esc_html__('Chinese (Traditional)	', 'event_espresso'),
261
-                                'hr'     => esc_html__('Croatian', 'event_espresso'),
262
-                                'cs'     => esc_html__('Czech', 'event_espresso'),
263
-                                'da'     => esc_html__('Danish', 'event_espresso'),
264
-                                'nl'     => esc_html__('Dutch', 'event_espresso'),
265
-                                'en-GB'  => esc_html__('English (UK)', 'event_espresso'),
266
-                                'en'     => esc_html__('English (US)', 'event_espresso'),
267
-                                'fil'    => esc_html__('Filipino', 'event_espresso'),
268
-                                'fi'     => esc_html__('Finnish', 'event_espresso'),
269
-                                'fr'     => esc_html__('French', 'event_espresso'),
270
-                                'fr-CA'  => esc_html__('French (Canadian)', 'event_espresso'),
271
-                                'de'     => esc_html__('German', 'event_espresso'),
272
-                                'de-AT'  => esc_html__('German (Austria)', 'event_espresso'),
273
-                                'de-CH'  => esc_html__('German (Switzerland)', 'event_espresso'),
274
-                                'el'     => esc_html__('Greek', 'event_espresso'),
275
-                                'iw'     => esc_html__('Hebrew', 'event_espresso'),
276
-                                'hi'     => esc_html__('Hindi', 'event_espresso'),
277
-                                'hu'     => esc_html__('Hungarian', 'event_espresso'),
278
-                                'id'     => esc_html__('Indonesian', 'event_espresso'),
279
-                                'it'     => esc_html__('Italian', 'event_espresso'),
280
-                                'ja'     => esc_html__('Japanese', 'event_espresso'),
281
-                                'ko'     => esc_html__('Korean', 'event_espresso'),
282
-                                'lv'     => esc_html__('Latvian', 'event_espresso'),
283
-                                'lt'     => esc_html__('Lithuanian', 'event_espresso'),
284
-                                'no'     => esc_html__('Norwegian', 'event_espresso'),
285
-                                'fa'     => esc_html__('Persian', 'event_espresso'),
286
-                                'pl'     => esc_html__('Polish', 'event_espresso'),
287
-                                'pt'     => esc_html__('Portuguese', 'event_espresso'),
288
-                                'pt-BR'  => esc_html__('Portuguese (Brazil)', 'event_espresso'),
289
-                                'pt-PT'  => esc_html__('Portuguese (Portugal)', 'event_espresso'),
290
-                                'ro'     => esc_html__('Romanian', 'event_espresso'),
291
-                                'ru'     => esc_html__('Russian', 'event_espresso'),
292
-                                'sr'     => esc_html__('Serbian', 'event_espresso'),
293
-                                'sk'     => esc_html__('Slovak', 'event_espresso'),
294
-                                'sl'     => esc_html__('Slovenian', 'event_espresso'),
295
-                                'es'     => esc_html__('Spanish', 'event_espresso'),
296
-                                'es-419' => esc_html__('Spanish (Latin America)', 'event_espresso'),
297
-                                'sv'     => esc_html__('Swedish', 'event_espresso'),
298
-                                'th'     => esc_html__('Thai', 'event_espresso'),
299
-                                'tr'     => esc_html__('Turkish', 'event_espresso'),
300
-                                'uk'     => esc_html__('Ukrainian', 'event_espresso'),
301
-                                'vi'     => esc_html__('Vietnamese', 'event_espresso'),
302
-                            ),
303
-                            array(
304
-                                'html_label_text' => esc_html__('Language', 'event_espresso'),
305
-                                'html_help_text'  => esc_html__(
306
-                                    'Forces the widget to render in a specific language.',
307
-                                    'event_espresso'
308
-                                ),
309
-                                'default'         => $this->config->recaptcha_language !== null
310
-                                    ? $this->config->recaptcha_language : 'en',
311
-                            )
312
-                        ),
313
-                    )
314
-                ),
315
-            )
316
-        );
317
-    }
183
+	/**
184
+	 * @return EE_Form_Section_Proper
185
+	 * @throws EE_Error
186
+	 */
187
+	protected function appearanceSettings()
188
+	{
189
+		return new EE_Form_Section_Proper(
190
+			array(
191
+				'name'            => 'recaptcha_appearance_settings_tbl',
192
+				'html_id'         => 'recaptcha_appearance_settings_tbl',
193
+				'html_class'      => 'form-table',
194
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
195
+				'subsections'     => apply_filters(
196
+					'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections',
197
+					array(
198
+						'recaptcha_theme'    => new EE_Radio_Button_Input(
199
+							array(
200
+								'invisible' => esc_html__('Invisible', 'event_espresso'),
201
+								'light'     => esc_html__('Light', 'event_espresso'),
202
+								'dark'      => esc_html__('Dark', 'event_espresso'),
203
+							),
204
+							array(
205
+								'html_label_text'         => esc_html__('Theme', 'event_espresso'),
206
+								'html_help_text'          => esc_html__(
207
+									'The color theme of the widget.',
208
+									'event_espresso'
209
+								),
210
+								'default'                 => $this->config->recaptcha_theme !== null
211
+									? $this->config->recaptcha_theme
212
+									: 'invisible',
213
+								'display_html_label_text' => false,
214
+							)
215
+						),
216
+						'recaptcha_badge'     => new EE_Radio_Button_Input(
217
+							array(
218
+								'bottomleft' => esc_html__('Bottom Left', 'event_espresso'),
219
+								'bottomright' => esc_html__('Bottom Right', 'event_espresso'),
220
+								'inline' => esc_html__('Inline', 'event_espresso'),
221
+							),
222
+							array(
223
+								'html_label_text'         => esc_html__(
224
+									'Invisible reCAPTCHA Badge Position',
225
+									'event_espresso'
226
+								),
227
+								'html_help_text'          => esc_html__(
228
+									'If using Invisible reCAPTCHA, then this determines the position of the reCAPTCHA badge. "Bottom Left" and "Bottom Right" both will float at the bottom of the screen. "Inline" appears beside the submit button but allows you to control the CSS.',
229
+									'event_espresso'
230
+								),
231
+								'default'                 => $this->config->recaptcha_badge !== null
232
+									? $this->config->recaptcha_badge
233
+									: 'bottomleft',
234
+								'display_html_label_text' => false,
235
+							)
236
+						),
237
+						'recaptcha_type'     => new EE_Radio_Button_Input(
238
+							array(
239
+								'image' => esc_html__('Image', 'event_espresso'),
240
+								'audio' => esc_html__('Audio', 'event_espresso'),
241
+							),
242
+							array(
243
+								'html_label_text'         => esc_html__('Type', 'event_espresso'),
244
+								'html_help_text'          => esc_html__(
245
+									'The type of CAPTCHA to serve.',
246
+									'event_espresso'
247
+								),
248
+								'default'                 => $this->config->recaptcha_type !== null
249
+									? $this->config->recaptcha_type
250
+									: 'image',
251
+								'display_html_label_text' => false,
252
+							)
253
+						),
254
+						'recaptcha_language' => new EE_Select_Input(
255
+							array(
256
+								'ar'     => esc_html__('Arabic', 'event_espresso'),
257
+								'bg'     => esc_html__('Bulgarian', 'event_espresso'),
258
+								'ca'     => esc_html__('Catalan', 'event_espresso'),
259
+								'zh-CN'  => esc_html__('Chinese (Simplified)', 'event_espresso'),
260
+								'zh-TW'  => esc_html__('Chinese (Traditional)	', 'event_espresso'),
261
+								'hr'     => esc_html__('Croatian', 'event_espresso'),
262
+								'cs'     => esc_html__('Czech', 'event_espresso'),
263
+								'da'     => esc_html__('Danish', 'event_espresso'),
264
+								'nl'     => esc_html__('Dutch', 'event_espresso'),
265
+								'en-GB'  => esc_html__('English (UK)', 'event_espresso'),
266
+								'en'     => esc_html__('English (US)', 'event_espresso'),
267
+								'fil'    => esc_html__('Filipino', 'event_espresso'),
268
+								'fi'     => esc_html__('Finnish', 'event_espresso'),
269
+								'fr'     => esc_html__('French', 'event_espresso'),
270
+								'fr-CA'  => esc_html__('French (Canadian)', 'event_espresso'),
271
+								'de'     => esc_html__('German', 'event_espresso'),
272
+								'de-AT'  => esc_html__('German (Austria)', 'event_espresso'),
273
+								'de-CH'  => esc_html__('German (Switzerland)', 'event_espresso'),
274
+								'el'     => esc_html__('Greek', 'event_espresso'),
275
+								'iw'     => esc_html__('Hebrew', 'event_espresso'),
276
+								'hi'     => esc_html__('Hindi', 'event_espresso'),
277
+								'hu'     => esc_html__('Hungarian', 'event_espresso'),
278
+								'id'     => esc_html__('Indonesian', 'event_espresso'),
279
+								'it'     => esc_html__('Italian', 'event_espresso'),
280
+								'ja'     => esc_html__('Japanese', 'event_espresso'),
281
+								'ko'     => esc_html__('Korean', 'event_espresso'),
282
+								'lv'     => esc_html__('Latvian', 'event_espresso'),
283
+								'lt'     => esc_html__('Lithuanian', 'event_espresso'),
284
+								'no'     => esc_html__('Norwegian', 'event_espresso'),
285
+								'fa'     => esc_html__('Persian', 'event_espresso'),
286
+								'pl'     => esc_html__('Polish', 'event_espresso'),
287
+								'pt'     => esc_html__('Portuguese', 'event_espresso'),
288
+								'pt-BR'  => esc_html__('Portuguese (Brazil)', 'event_espresso'),
289
+								'pt-PT'  => esc_html__('Portuguese (Portugal)', 'event_espresso'),
290
+								'ro'     => esc_html__('Romanian', 'event_espresso'),
291
+								'ru'     => esc_html__('Russian', 'event_espresso'),
292
+								'sr'     => esc_html__('Serbian', 'event_espresso'),
293
+								'sk'     => esc_html__('Slovak', 'event_espresso'),
294
+								'sl'     => esc_html__('Slovenian', 'event_espresso'),
295
+								'es'     => esc_html__('Spanish', 'event_espresso'),
296
+								'es-419' => esc_html__('Spanish (Latin America)', 'event_espresso'),
297
+								'sv'     => esc_html__('Swedish', 'event_espresso'),
298
+								'th'     => esc_html__('Thai', 'event_espresso'),
299
+								'tr'     => esc_html__('Turkish', 'event_espresso'),
300
+								'uk'     => esc_html__('Ukrainian', 'event_espresso'),
301
+								'vi'     => esc_html__('Vietnamese', 'event_espresso'),
302
+							),
303
+							array(
304
+								'html_label_text' => esc_html__('Language', 'event_espresso'),
305
+								'html_help_text'  => esc_html__(
306
+									'Forces the widget to render in a specific language.',
307
+									'event_espresso'
308
+								),
309
+								'default'         => $this->config->recaptcha_language !== null
310
+									? $this->config->recaptcha_language : 'en',
311
+							)
312
+						),
313
+					)
314
+				),
315
+			)
316
+		);
317
+	}
318 318
 
319 319
 
320
-    /**
321
-     * @param EE_Registration_Config $EE_Registration_Config
322
-     * @return EE_Registration_Config
323
-     * @throws InvalidArgumentException
324
-     * @throws InvalidInterfaceException
325
-     * @throws InvalidDataTypeException
326
-     * @throws EE_Error
327
-     * @throws ReflectionException
328
-     */
329
-    public function updateAdminSettings(EE_Registration_Config $EE_Registration_Config)
330
-    {
331
-        try {
332
-            $recaptcha_settings_form = $this->settingsForm();
333
-            // if not displaying a form, then check for form submission
334
-            if ($recaptcha_settings_form->was_submitted()) {
335
-                // capture form data
336
-                $recaptcha_settings_form->receive_form_submission();
337
-                // validate form data
338
-                if ($recaptcha_settings_form->is_valid()) {
339
-                    // grab validated data from form
340
-                    $valid_data = $recaptcha_settings_form->valid_data();
341
-                    // user proofing recaptcha:  If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message.
342
-                    if ($valid_data['main_settings']['use_captcha']
343
-                        && (
344
-                            ! $EE_Registration_Config->use_captcha
345
-                            && (
346
-                                empty($valid_data['main_settings']['recaptcha_publickey'])
347
-                                || empty($valid_data['main_settings']['recaptcha_privatekey'])
348
-                            )
349
-                        )
350
-                        && apply_filters(
351
-                            'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys',
352
-                            true,
353
-                            $EE_Registration_Config
354
-                        )
355
-                    ) {
356
-                        $valid_data['main_settings']['use_captcha'] = false;
357
-                        EE_Error::add_error(
358
-                            esc_html__(
359
-                                'The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.',
360
-                                'event_espresso'
361
-                            ),
362
-                            __FILE__,
363
-                            __FUNCTION__,
364
-                            __LINE__
365
-                        );
366
-                    }
367
-                    $EE_Registration_Config->use_captcha          = $valid_data['main_settings']['use_captcha'];
368
-                    $EE_Registration_Config->recaptcha_publickey  = $valid_data['main_settings']['recaptcha_publickey'];
369
-                    $EE_Registration_Config->recaptcha_protected_forms = $valid_data['main_settings']['recaptcha_protected_forms'];
370
-                    $EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey'];
371
-                    $EE_Registration_Config->recaptcha_type       = $valid_data['appearance_settings']['recaptcha_type'];
372
-                    $EE_Registration_Config->recaptcha_theme      = $valid_data['appearance_settings']['recaptcha_theme'];
373
-                    $EE_Registration_Config->recaptcha_badge      = $valid_data['appearance_settings']['recaptcha_badge'];
374
-                    $EE_Registration_Config->recaptcha_language   = $valid_data['appearance_settings']['recaptcha_language'];
375
-                } else {
376
-                    if ($recaptcha_settings_form->submission_error_message() !== '') {
377
-                        EE_Error::add_error(
378
-                            $recaptcha_settings_form->submission_error_message(),
379
-                            __FILE__,
380
-                            __FUNCTION__,
381
-                            __LINE__
382
-                        );
383
-                    }
384
-                }
385
-            }
386
-        } catch (EE_Error $e) {
387
-            $e->get_error();
388
-        }
389
-        return $EE_Registration_Config;
390
-    }
320
+	/**
321
+	 * @param EE_Registration_Config $EE_Registration_Config
322
+	 * @return EE_Registration_Config
323
+	 * @throws InvalidArgumentException
324
+	 * @throws InvalidInterfaceException
325
+	 * @throws InvalidDataTypeException
326
+	 * @throws EE_Error
327
+	 * @throws ReflectionException
328
+	 */
329
+	public function updateAdminSettings(EE_Registration_Config $EE_Registration_Config)
330
+	{
331
+		try {
332
+			$recaptcha_settings_form = $this->settingsForm();
333
+			// if not displaying a form, then check for form submission
334
+			if ($recaptcha_settings_form->was_submitted()) {
335
+				// capture form data
336
+				$recaptcha_settings_form->receive_form_submission();
337
+				// validate form data
338
+				if ($recaptcha_settings_form->is_valid()) {
339
+					// grab validated data from form
340
+					$valid_data = $recaptcha_settings_form->valid_data();
341
+					// user proofing recaptcha:  If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message.
342
+					if ($valid_data['main_settings']['use_captcha']
343
+						&& (
344
+							! $EE_Registration_Config->use_captcha
345
+							&& (
346
+								empty($valid_data['main_settings']['recaptcha_publickey'])
347
+								|| empty($valid_data['main_settings']['recaptcha_privatekey'])
348
+							)
349
+						)
350
+						&& apply_filters(
351
+							'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys',
352
+							true,
353
+							$EE_Registration_Config
354
+						)
355
+					) {
356
+						$valid_data['main_settings']['use_captcha'] = false;
357
+						EE_Error::add_error(
358
+							esc_html__(
359
+								'The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.',
360
+								'event_espresso'
361
+							),
362
+							__FILE__,
363
+							__FUNCTION__,
364
+							__LINE__
365
+						);
366
+					}
367
+					$EE_Registration_Config->use_captcha          = $valid_data['main_settings']['use_captcha'];
368
+					$EE_Registration_Config->recaptcha_publickey  = $valid_data['main_settings']['recaptcha_publickey'];
369
+					$EE_Registration_Config->recaptcha_protected_forms = $valid_data['main_settings']['recaptcha_protected_forms'];
370
+					$EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey'];
371
+					$EE_Registration_Config->recaptcha_type       = $valid_data['appearance_settings']['recaptcha_type'];
372
+					$EE_Registration_Config->recaptcha_theme      = $valid_data['appearance_settings']['recaptcha_theme'];
373
+					$EE_Registration_Config->recaptcha_badge      = $valid_data['appearance_settings']['recaptcha_badge'];
374
+					$EE_Registration_Config->recaptcha_language   = $valid_data['appearance_settings']['recaptcha_language'];
375
+				} else {
376
+					if ($recaptcha_settings_form->submission_error_message() !== '') {
377
+						EE_Error::add_error(
378
+							$recaptcha_settings_form->submission_error_message(),
379
+							__FILE__,
380
+							__FUNCTION__,
381
+							__LINE__
382
+						);
383
+					}
384
+				}
385
+			}
386
+		} catch (EE_Error $e) {
387
+			$e->get_error();
388
+		}
389
+		return $EE_Registration_Config;
390
+	}
391 391
 }
Please login to merge, or discard this patch.
core/domain/CaffeinatedInterface.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@
 block discarded – undo
12 12
  */
13 13
 interface CaffeinatedInterface
14 14
 {
15
-    /**
16
-     * Used to indicate when functionality is caffeinated or not.
17
-     * @return bool
18
-     */
19
-    public function isCaffeinated();
15
+	/**
16
+	 * Used to indicate when functionality is caffeinated or not.
17
+	 * @return bool
18
+	 */
19
+	public function isCaffeinated();
20 20
 }
Please login to merge, or discard this patch.
core/domain/services/admin/PluginUpsells.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -17,47 +17,47 @@  discard block
 block discarded – undo
17 17
 class PluginUpsells
18 18
 {
19 19
 
20
-    /**
21
-     * @var DomainInterface
22
-     */
23
-    private $domain;
20
+	/**
21
+	 * @var DomainInterface
22
+	 */
23
+	private $domain;
24 24
 
25 25
 
26
-    /**
27
-     * PluginUpsells constructor.
28
-     *
29
-     * @param DomainInterface $domain
30
-     */
31
-    public function __construct(DomainInterface $domain)
32
-    {
33
-        $this->domain = $domain;
34
-    }
26
+	/**
27
+	 * PluginUpsells constructor.
28
+	 *
29
+	 * @param DomainInterface $domain
30
+	 */
31
+	public function __construct(DomainInterface $domain)
32
+	{
33
+		$this->domain = $domain;
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * Hook in various upsells for the decaf version of EE.
39
-     */
40
-    public function decafUpsells()
41
-    {
42
-        if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) {
43
-            add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10, 3);
44
-        }
45
-    }
37
+	/**
38
+	 * Hook in various upsells for the decaf version of EE.
39
+	 */
40
+	public function decafUpsells()
41
+	{
42
+		if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) {
43
+			add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10, 3);
44
+		}
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Callback for `after_plugin_row` to add upsell info
50
-     *
51
-     * @param string $plugin_file
52
-     * @param array  $plugin_data
53
-     * @param string $status
54
-     * @throws DomainException
55
-     */
56
-    public function doPremiumUpsell($plugin_file, $plugin_data, $status)
57
-    {
58
-        if ($plugin_file === $this->domain->pluginBasename()) {
59
-            list($button_text, $button_url, $upsell_text) = $this->getAfterPluginRowDetails();
60
-            echo '<tr class="plugin-update-tr ee-upsell-plugin-list-table active">
48
+	/**
49
+	 * Callback for `after_plugin_row` to add upsell info
50
+	 *
51
+	 * @param string $plugin_file
52
+	 * @param array  $plugin_data
53
+	 * @param string $status
54
+	 * @throws DomainException
55
+	 */
56
+	public function doPremiumUpsell($plugin_file, $plugin_data, $status)
57
+	{
58
+		if ($plugin_file === $this->domain->pluginBasename()) {
59
+			list($button_text, $button_url, $upsell_text) = $this->getAfterPluginRowDetails();
60
+			echo '<tr class="plugin-update-tr ee-upsell-plugin-list-table active">
61 61
                 <td colspan="3" class="plugin-update colspanchange">
62 62
                     <div class="notice inline notice-alt">
63 63
                         <div class="ee-upsell-container">
@@ -74,27 +74,27 @@  discard block
 block discarded – undo
74 74
                     </div>
75 75
                 </td>
76 76
               </tr>';
77
-        }
78
-    }
77
+		}
78
+	}
79 79
 
80
-    /**
81
-     * Provide the details used for the upsell container.
82
-     *
83
-     * @return array
84
-     */
85
-    protected function getAfterPluginRowDetails()
86
-    {
87
-        return array(
88
-            esc_html__('Upgrade for Support', 'event_espresso'),
89
-            'https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link" class="button button-primary',
90
-            sprintf(
91
-                esc_html__(
92
-                    'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s! Don\'t have an Event Espresso support license key? Support the project and buy one today!',
93
-                    'event_espresso'
94
-                ),
95
-                '<strong>',
96
-                '</strong>'
97
-            ),
98
-        );
99
-    }
80
+	/**
81
+	 * Provide the details used for the upsell container.
82
+	 *
83
+	 * @return array
84
+	 */
85
+	protected function getAfterPluginRowDetails()
86
+	{
87
+		return array(
88
+			esc_html__('Upgrade for Support', 'event_espresso'),
89
+			'https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link" class="button button-primary',
90
+			sprintf(
91
+				esc_html__(
92
+					'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s! Don\'t have an Event Espresso support license key? Support the project and buy one today!',
93
+					'event_espresso'
94
+				),
95
+				'<strong>',
96
+				'</strong>'
97
+			),
98
+		);
99
+	}
100 100
 }
Please login to merge, or discard this patch.
core/domain/values/session/SessionLifespan.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -20,98 +20,98 @@
 block discarded – undo
20 20
 class SessionLifespan
21 21
 {
22 22
 
23
-    /**
24
-     * how long an EE session lasts in seconds
25
-     * default session lifespan of 1 hour (for not so instant IPNs)
26
-     *
27
-     * @var int $lifespan
28
-     */
29
-    private $lifespan;
30
-
31
-
32
-    /**
33
-     * SessionLifespan constructor.
34
-     *
35
-     * @param int $lifespan
36
-     * @throws DomainException
37
-     */
38
-    public function __construct($lifespan = 0)
39
-    {
40
-        $lifespan = absint($lifespan);
41
-        $lifespan = $lifespan > 0 ? $lifespan : (int) HOUR_IN_SECONDS;
42
-        $this->setLifespan($lifespan);
43
-    }
44
-
45
-
46
-    /**
47
-     * @param int $lifespan
48
-     * @throws DomainException
49
-     */
50
-    protected function setLifespan($lifespan)
51
-    {
52
-        if ($lifespan < 60) {
53
-            throw new DomainException(
54
-                esc_html__(
55
-                    'The session lifespan needs to be at least 60 seconds, and even that is extremely short',
56
-                    'event_espresso'
57
-                )
58
-            );
59
-        }
60
-        $this->lifespan = apply_filters(
61
-            'FHEE__EventEspresso_core_domain_values_session_SessionLifespan__setLifespan___lifespan',
62
-            // apply legacy filter for now but add doing it wrong notice in future
63
-            apply_filters(
64
-                'FHEE__EE_Session__construct___lifespan',
65
-                $lifespan
66
-            )
67
-        ) + 1;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return int
73
-     */
74
-    public function inSeconds()
75
-    {
76
-        return $this->lifespan;
77
-    }
78
-
79
-
80
-    /**
81
-     * @param string $separator
82
-     * @return string
83
-     */
84
-    public function inHoursMinutesSeconds($separator = ':')
85
-    {
86
-        return sprintf(
87
-            '%02d%s%02d%s%02d',
88
-            floor($this->lifespan / 3600),
89
-            $separator,
90
-            ($this->lifespan / 60) % 60,
91
-            $separator,
92
-            $this->lifespan % 60
93
-        );
94
-    }
95
-
96
-
97
-    /**
98
-     * Returns a timestamp for when the session would expire based on this lifespan
99
-     *
100
-     * @param bool $utc If true, displays expiration in UTC
101
-     *                  If false, displays expiration in local time
102
-     * @return int
103
-     */
104
-    public function expiration($utc = true)
105
-    {
106
-        return (int) current_time('timestamp', $utc) - $this->lifespan;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return string
112
-     */
113
-    public function __toString()
114
-    {
115
-        return (string) $this->inSeconds();
116
-    }
23
+	/**
24
+	 * how long an EE session lasts in seconds
25
+	 * default session lifespan of 1 hour (for not so instant IPNs)
26
+	 *
27
+	 * @var int $lifespan
28
+	 */
29
+	private $lifespan;
30
+
31
+
32
+	/**
33
+	 * SessionLifespan constructor.
34
+	 *
35
+	 * @param int $lifespan
36
+	 * @throws DomainException
37
+	 */
38
+	public function __construct($lifespan = 0)
39
+	{
40
+		$lifespan = absint($lifespan);
41
+		$lifespan = $lifespan > 0 ? $lifespan : (int) HOUR_IN_SECONDS;
42
+		$this->setLifespan($lifespan);
43
+	}
44
+
45
+
46
+	/**
47
+	 * @param int $lifespan
48
+	 * @throws DomainException
49
+	 */
50
+	protected function setLifespan($lifespan)
51
+	{
52
+		if ($lifespan < 60) {
53
+			throw new DomainException(
54
+				esc_html__(
55
+					'The session lifespan needs to be at least 60 seconds, and even that is extremely short',
56
+					'event_espresso'
57
+				)
58
+			);
59
+		}
60
+		$this->lifespan = apply_filters(
61
+			'FHEE__EventEspresso_core_domain_values_session_SessionLifespan__setLifespan___lifespan',
62
+			// apply legacy filter for now but add doing it wrong notice in future
63
+			apply_filters(
64
+				'FHEE__EE_Session__construct___lifespan',
65
+				$lifespan
66
+			)
67
+		) + 1;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return int
73
+	 */
74
+	public function inSeconds()
75
+	{
76
+		return $this->lifespan;
77
+	}
78
+
79
+
80
+	/**
81
+	 * @param string $separator
82
+	 * @return string
83
+	 */
84
+	public function inHoursMinutesSeconds($separator = ':')
85
+	{
86
+		return sprintf(
87
+			'%02d%s%02d%s%02d',
88
+			floor($this->lifespan / 3600),
89
+			$separator,
90
+			($this->lifespan / 60) % 60,
91
+			$separator,
92
+			$this->lifespan % 60
93
+		);
94
+	}
95
+
96
+
97
+	/**
98
+	 * Returns a timestamp for when the session would expire based on this lifespan
99
+	 *
100
+	 * @param bool $utc If true, displays expiration in UTC
101
+	 *                  If false, displays expiration in local time
102
+	 * @return int
103
+	 */
104
+	public function expiration($utc = true)
105
+	{
106
+		return (int) current_time('timestamp', $utc) - $this->lifespan;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return string
112
+	 */
113
+	public function __toString()
114
+	{
115
+		return (string) $this->inSeconds();
116
+	}
117 117
 }
Please login to merge, or discard this patch.
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Indentation   +710 added lines, -710 removed lines patch added patch discarded remove patch
@@ -33,717 +33,717 @@
 block discarded – undo
33 33
 class DisplayTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * event that ticket selector is being generated for
38
-     *
39
-     * @access protected
40
-     * @var EE_Event $event
41
-     */
42
-    protected $event;
43
-
44
-    /**
45
-     * Used to flag when the ticket selector is being called from an external iframe.
46
-     *
47
-     * @var bool $iframe
48
-     */
49
-    protected $iframe = false;
50
-
51
-    /**
52
-     * max attendees that can register for event at one time
53
-     *
54
-     * @var int $max_attendees
55
-     */
56
-    private $max_attendees = EE_INF;
57
-
58
-    /**
59
-     * @var string $date_format
60
-     */
61
-    private $date_format;
62
-
63
-    /**
64
-     * @var string $time_format
65
-     */
66
-    private $time_format;
67
-
68
-    /**
69
-     * @var boolean $display_full_ui
70
-     */
71
-    private $display_full_ui;
72
-
73
-
74
-    /**
75
-     * DisplayTicketSelector constructor.
76
-     *
77
-     * @param bool $iframe
78
-     */
79
-    public function __construct($iframe = false)
80
-    {
81
-        $this->iframe = $iframe;
82
-        $this->date_format = apply_filters(
83
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
84
-            get_option('date_format')
85
-        );
86
-        $this->time_format = apply_filters(
87
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
88
-            get_option('time_format')
89
-        );
90
-    }
91
-
92
-
93
-    /**
94
-     * @return bool
95
-     */
96
-    public function isIframe()
97
-    {
98
-        return $this->iframe;
99
-    }
100
-
101
-
102
-    /**
103
-     * @param boolean $iframe
104
-     */
105
-    public function setIframe($iframe = true)
106
-    {
107
-        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
108
-    }
109
-
110
-
111
-    /**
112
-     * finds and sets the \EE_Event object for use throughout class
113
-     *
114
-     * @param mixed $event
115
-     * @return bool
116
-     * @throws EE_Error
117
-     * @throws InvalidDataTypeException
118
-     * @throws InvalidInterfaceException
119
-     * @throws InvalidArgumentException
120
-     */
121
-    protected function setEvent($event = null)
122
-    {
123
-        if ($event === null) {
124
-            global $post;
125
-            $event = $post;
126
-        }
127
-        if ($event instanceof EE_Event) {
128
-            $this->event = $event;
129
-        } elseif ($event instanceof WP_Post) {
130
-            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
131
-                $this->event = $event->EE_Event;
132
-            } elseif ($event->post_type === 'espresso_events') {
133
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
134
-                $this->event = $event->EE_Event;
135
-            }
136
-        } else {
137
-            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
-            $dev_msg = $user_msg . __(
139
-                'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140
-                'event_espresso'
141
-            );
142
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
143
-            return false;
144
-        }
145
-        return true;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return int
151
-     */
152
-    public function getMaxAttendees()
153
-    {
154
-        return $this->max_attendees;
155
-    }
156
-
157
-
158
-    /**
159
-     * @param int $max_attendees
160
-     */
161
-    public function setMaxAttendees($max_attendees)
162
-    {
163
-        $this->max_attendees = absint(
164
-            apply_filters(
165
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
166
-                $max_attendees
167
-            )
168
-        );
169
-    }
170
-
171
-
172
-    /**
173
-     * Returns whether or not the full ticket selector should be shown or not.
174
-     * Currently, it displays on the frontend (including ajax requests) but not the backend
175
-     *
176
-     * @return bool
177
-     */
178
-    private function display_full_ui()
179
-    {
180
-        if ($this->display_full_ui === null) {
181
-            $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
182
-        }
183
-        return $this->display_full_ui;
184
-    }
185
-
186
-
187
-    /**
188
-     * creates buttons for selecting number of attendees for an event
189
-     *
190
-     * @param WP_Post|int $event
191
-     * @param bool        $view_details
192
-     * @return string
193
-     * @throws EE_Error
194
-     * @throws InvalidArgumentException
195
-     * @throws InvalidDataTypeException
196
-     * @throws InvalidInterfaceException
197
-     */
198
-    public function display($event = null, $view_details = false)
199
-    {
200
-        // reset filter for displaying submit button
201
-        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202
-        // poke and prod incoming event till it tells us what it is
203
-        if (! $this->setEvent($event)) {
204
-            return false;
205
-        }
206
-        // begin gathering template arguments by getting event status
207
-        $template_args = array('event_status' => $this->event->get_active_status());
208
-        if ($this->activeEventAndShowTicketSelector(
209
-            $event,
210
-            $template_args['event_status'],
211
-            $view_details
212
-        )) {
213
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
214
-        }
215
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
216
-        $this->setMaxAttendees($this->event->additional_limit());
217
-        if ($this->getMaxAttendees() < 1) {
218
-            return $this->ticketSalesClosedMessage();
219
-        }
220
-        // is the event expired ?
221
-        $template_args['event_is_expired'] = $this->event->is_expired();
222
-        if ($template_args['event_is_expired']) {
223
-            return $this->expiredEventMessage();
224
-        }
225
-        // get all tickets for this event ordered by the datetime
226
-        $tickets = $this->getTickets();
227
-        if (count($tickets) < 1) {
228
-            return $this->noTicketAvailableMessage();
229
-        }
230
-        // redirecting to another site for registration ??
231
-        $external_url = (string) $this->event->external_url();
232
-        // if redirecting to another site for registration, then we don't load the TS
233
-        $ticket_selector = $external_url
234
-            ? $this->externalEventRegistration()
235
-            : $this->loadTicketSelector($tickets, $template_args);
236
-        // now set up the form (but not for the admin)
237
-        $ticket_selector = $this->display_full_ui()
238
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
239
-            : $ticket_selector;
240
-        // submit button and form close tag
241
-        $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
242
-        return $ticket_selector;
243
-    }
244
-
245
-
246
-    /**
247
-     * displayTicketSelector
248
-     * examines the event properties and determines whether a Ticket Selector should be displayed
249
-     *
250
-     * @param WP_Post|int $event
251
-     * @param string      $_event_active_status
252
-     * @param bool        $view_details
253
-     * @return bool
254
-     * @throws EE_Error
255
-     */
256
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
257
-    {
258
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
259
-        return $this->display_full_ui()
260
-               && (
261
-                   ! $this->event->display_ticket_selector()
262
-                   || $view_details
263
-                   || post_password_required($event_post)
264
-                   || (
265
-                       $_event_active_status !== EE_Datetime::active
266
-                       && $_event_active_status !== EE_Datetime::upcoming
267
-                       && $_event_active_status !== EE_Datetime::sold_out
268
-                       && ! (
269
-                           $_event_active_status === EE_Datetime::inactive
270
-                           && is_user_logged_in()
271
-                       )
272
-                   )
273
-               );
274
-    }
275
-
276
-
277
-    /**
278
-     * noTicketAvailableMessage
279
-     * notice displayed if event is expired
280
-     *
281
-     * @return string
282
-     * @throws EE_Error
283
-     */
284
-    protected function expiredEventMessage()
285
-    {
286
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
287
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
288
-            'event_espresso'
289
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
290
-    }
291
-
292
-
293
-    /**
294
-     * noTicketAvailableMessage
295
-     * notice displayed if event has no more tickets available
296
-     *
297
-     * @return string
298
-     * @throws EE_Error
299
-     */
300
-    protected function noTicketAvailableMessage()
301
-    {
302
-        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
303
-        if (current_user_can('edit_post', $this->event->ID())) {
304
-            $no_ticket_available_msg .= sprintf(
305
-                esc_html__(
306
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
307
-                    'event_espresso'
308
-                ),
309
-                '<div class="ee-attention" style="text-align: left;"><b>',
310
-                '</b><br />',
311
-                '<span class="edit-link"><a class="post-edit-link" href="'
312
-                . get_edit_post_link($this->event->ID())
313
-                . '">',
314
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
315
-            );
316
-        }
317
-        return '
36
+	/**
37
+	 * event that ticket selector is being generated for
38
+	 *
39
+	 * @access protected
40
+	 * @var EE_Event $event
41
+	 */
42
+	protected $event;
43
+
44
+	/**
45
+	 * Used to flag when the ticket selector is being called from an external iframe.
46
+	 *
47
+	 * @var bool $iframe
48
+	 */
49
+	protected $iframe = false;
50
+
51
+	/**
52
+	 * max attendees that can register for event at one time
53
+	 *
54
+	 * @var int $max_attendees
55
+	 */
56
+	private $max_attendees = EE_INF;
57
+
58
+	/**
59
+	 * @var string $date_format
60
+	 */
61
+	private $date_format;
62
+
63
+	/**
64
+	 * @var string $time_format
65
+	 */
66
+	private $time_format;
67
+
68
+	/**
69
+	 * @var boolean $display_full_ui
70
+	 */
71
+	private $display_full_ui;
72
+
73
+
74
+	/**
75
+	 * DisplayTicketSelector constructor.
76
+	 *
77
+	 * @param bool $iframe
78
+	 */
79
+	public function __construct($iframe = false)
80
+	{
81
+		$this->iframe = $iframe;
82
+		$this->date_format = apply_filters(
83
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
84
+			get_option('date_format')
85
+		);
86
+		$this->time_format = apply_filters(
87
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
88
+			get_option('time_format')
89
+		);
90
+	}
91
+
92
+
93
+	/**
94
+	 * @return bool
95
+	 */
96
+	public function isIframe()
97
+	{
98
+		return $this->iframe;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @param boolean $iframe
104
+	 */
105
+	public function setIframe($iframe = true)
106
+	{
107
+		$this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
108
+	}
109
+
110
+
111
+	/**
112
+	 * finds and sets the \EE_Event object for use throughout class
113
+	 *
114
+	 * @param mixed $event
115
+	 * @return bool
116
+	 * @throws EE_Error
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws InvalidInterfaceException
119
+	 * @throws InvalidArgumentException
120
+	 */
121
+	protected function setEvent($event = null)
122
+	{
123
+		if ($event === null) {
124
+			global $post;
125
+			$event = $post;
126
+		}
127
+		if ($event instanceof EE_Event) {
128
+			$this->event = $event;
129
+		} elseif ($event instanceof WP_Post) {
130
+			if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
131
+				$this->event = $event->EE_Event;
132
+			} elseif ($event->post_type === 'espresso_events') {
133
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
134
+				$this->event = $event->EE_Event;
135
+			}
136
+		} else {
137
+			$user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
+			$dev_msg = $user_msg . __(
139
+				'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140
+				'event_espresso'
141
+			);
142
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
143
+			return false;
144
+		}
145
+		return true;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return int
151
+	 */
152
+	public function getMaxAttendees()
153
+	{
154
+		return $this->max_attendees;
155
+	}
156
+
157
+
158
+	/**
159
+	 * @param int $max_attendees
160
+	 */
161
+	public function setMaxAttendees($max_attendees)
162
+	{
163
+		$this->max_attendees = absint(
164
+			apply_filters(
165
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
166
+				$max_attendees
167
+			)
168
+		);
169
+	}
170
+
171
+
172
+	/**
173
+	 * Returns whether or not the full ticket selector should be shown or not.
174
+	 * Currently, it displays on the frontend (including ajax requests) but not the backend
175
+	 *
176
+	 * @return bool
177
+	 */
178
+	private function display_full_ui()
179
+	{
180
+		if ($this->display_full_ui === null) {
181
+			$this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
182
+		}
183
+		return $this->display_full_ui;
184
+	}
185
+
186
+
187
+	/**
188
+	 * creates buttons for selecting number of attendees for an event
189
+	 *
190
+	 * @param WP_Post|int $event
191
+	 * @param bool        $view_details
192
+	 * @return string
193
+	 * @throws EE_Error
194
+	 * @throws InvalidArgumentException
195
+	 * @throws InvalidDataTypeException
196
+	 * @throws InvalidInterfaceException
197
+	 */
198
+	public function display($event = null, $view_details = false)
199
+	{
200
+		// reset filter for displaying submit button
201
+		remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202
+		// poke and prod incoming event till it tells us what it is
203
+		if (! $this->setEvent($event)) {
204
+			return false;
205
+		}
206
+		// begin gathering template arguments by getting event status
207
+		$template_args = array('event_status' => $this->event->get_active_status());
208
+		if ($this->activeEventAndShowTicketSelector(
209
+			$event,
210
+			$template_args['event_status'],
211
+			$view_details
212
+		)) {
213
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
214
+		}
215
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
216
+		$this->setMaxAttendees($this->event->additional_limit());
217
+		if ($this->getMaxAttendees() < 1) {
218
+			return $this->ticketSalesClosedMessage();
219
+		}
220
+		// is the event expired ?
221
+		$template_args['event_is_expired'] = $this->event->is_expired();
222
+		if ($template_args['event_is_expired']) {
223
+			return $this->expiredEventMessage();
224
+		}
225
+		// get all tickets for this event ordered by the datetime
226
+		$tickets = $this->getTickets();
227
+		if (count($tickets) < 1) {
228
+			return $this->noTicketAvailableMessage();
229
+		}
230
+		// redirecting to another site for registration ??
231
+		$external_url = (string) $this->event->external_url();
232
+		// if redirecting to another site for registration, then we don't load the TS
233
+		$ticket_selector = $external_url
234
+			? $this->externalEventRegistration()
235
+			: $this->loadTicketSelector($tickets, $template_args);
236
+		// now set up the form (but not for the admin)
237
+		$ticket_selector = $this->display_full_ui()
238
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
239
+			: $ticket_selector;
240
+		// submit button and form close tag
241
+		$ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
242
+		return $ticket_selector;
243
+	}
244
+
245
+
246
+	/**
247
+	 * displayTicketSelector
248
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
249
+	 *
250
+	 * @param WP_Post|int $event
251
+	 * @param string      $_event_active_status
252
+	 * @param bool        $view_details
253
+	 * @return bool
254
+	 * @throws EE_Error
255
+	 */
256
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
257
+	{
258
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
259
+		return $this->display_full_ui()
260
+			   && (
261
+				   ! $this->event->display_ticket_selector()
262
+				   || $view_details
263
+				   || post_password_required($event_post)
264
+				   || (
265
+					   $_event_active_status !== EE_Datetime::active
266
+					   && $_event_active_status !== EE_Datetime::upcoming
267
+					   && $_event_active_status !== EE_Datetime::sold_out
268
+					   && ! (
269
+						   $_event_active_status === EE_Datetime::inactive
270
+						   && is_user_logged_in()
271
+					   )
272
+				   )
273
+			   );
274
+	}
275
+
276
+
277
+	/**
278
+	 * noTicketAvailableMessage
279
+	 * notice displayed if event is expired
280
+	 *
281
+	 * @return string
282
+	 * @throws EE_Error
283
+	 */
284
+	protected function expiredEventMessage()
285
+	{
286
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
287
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
288
+			'event_espresso'
289
+		) . '</span></div><!-- .ee-event-expired-notice -->';
290
+	}
291
+
292
+
293
+	/**
294
+	 * noTicketAvailableMessage
295
+	 * notice displayed if event has no more tickets available
296
+	 *
297
+	 * @return string
298
+	 * @throws EE_Error
299
+	 */
300
+	protected function noTicketAvailableMessage()
301
+	{
302
+		$no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
303
+		if (current_user_can('edit_post', $this->event->ID())) {
304
+			$no_ticket_available_msg .= sprintf(
305
+				esc_html__(
306
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
307
+					'event_espresso'
308
+				),
309
+				'<div class="ee-attention" style="text-align: left;"><b>',
310
+				'</b><br />',
311
+				'<span class="edit-link"><a class="post-edit-link" href="'
312
+				. get_edit_post_link($this->event->ID())
313
+				. '">',
314
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
315
+			);
316
+		}
317
+		return '
318 318
             <div class="ee-event-expired-notice">
319 319
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
320 320
             </div><!-- .ee-event-expired-notice -->';
321
-    }
322
-
323
-
324
-    /**
325
-     * ticketSalesClosed
326
-     * notice displayed if event ticket sales are turned off
327
-     *
328
-     * @return string
329
-     * @throws EE_Error
330
-     */
331
-    protected function ticketSalesClosedMessage()
332
-    {
333
-        $sales_closed_msg = esc_html__(
334
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
335
-            'event_espresso'
336
-        );
337
-        if (current_user_can('edit_post', $this->event->ID())) {
338
-            $sales_closed_msg .= sprintf(
339
-                esc_html__(
340
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
341
-                    'event_espresso'
342
-                ),
343
-                '<div class="ee-attention" style="text-align: left;"><b>',
344
-                '</b><br />',
345
-                '<span class="edit-link"><a class="post-edit-link" href="'
346
-                . get_edit_post_link($this->event->ID())
347
-                . '">',
348
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
349
-            );
350
-        }
351
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
352
-    }
353
-
354
-
355
-    /**
356
-     * getTickets
357
-     *
358
-     * @return \EE_Base_Class[]|\EE_Ticket[]
359
-     * @throws EE_Error
360
-     * @throws InvalidDataTypeException
361
-     * @throws InvalidInterfaceException
362
-     * @throws InvalidArgumentException
363
-     */
364
-    protected function getTickets()
365
-    {
366
-        $ticket_query_args = array(
367
-            array('Datetime.EVT_ID' => $this->event->ID()),
368
-            'order_by' => array(
369
-                'TKT_order'              => 'ASC',
370
-                'TKT_required'           => 'DESC',
371
-                'TKT_start_date'         => 'ASC',
372
-                'TKT_end_date'           => 'ASC',
373
-                'Datetime.DTT_EVT_start' => 'DESC',
374
-            ),
375
-        );
376
-        if (! (
377
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
378
-            && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
379
-        )) {
380
-            // use the correct applicable time query depending on what version of core is being run.
381
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
382
-                ? time()
383
-                : current_time('timestamp');
384
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
385
-        }
386
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
387
-    }
388
-
389
-
390
-    /**
391
-     * loadTicketSelector
392
-     * begins to assemble template arguments
393
-     * and decides whether to load a "simple" ticket selector, or the standard
394
-     *
395
-     * @param \EE_Ticket[] $tickets
396
-     * @param array        $template_args
397
-     * @return string
398
-     * @throws EE_Error
399
-     */
400
-    protected function loadTicketSelector(array $tickets, array $template_args)
401
-    {
402
-        $template_args['event'] = $this->event;
403
-        $template_args['EVT_ID'] = $this->event->ID();
404
-        $template_args['event_is_expired'] = $this->event->is_expired();
405
-        $template_args['max_atndz'] = $this->getMaxAttendees();
406
-        $template_args['date_format'] = $this->date_format;
407
-        $template_args['time_format'] = $this->time_format;
408
-        /**
409
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
410
-         *
411
-         * @since 4.9.13
412
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
413
-         * @param int $EVT_ID The Event ID
414
-         */
415
-        $template_args['anchor_id'] = apply_filters(
416
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
417
-            '#tkt-slctr-tbl-' . $this->event->ID(),
418
-            $this->event->ID()
419
-        );
420
-        $template_args['tickets'] = $tickets;
421
-        $template_args['ticket_count'] = count($tickets);
422
-        $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
423
-        return $ticket_selector instanceof TicketSelectorSimple
424
-            ? $ticket_selector
425
-            : new TicketSelectorStandard(
426
-                $this->event,
427
-                $tickets,
428
-                $this->getMaxAttendees(),
429
-                $template_args,
430
-                $this->date_format,
431
-                $this->time_format
432
-            );
433
-    }
434
-
435
-
436
-    /**
437
-     * simpleTicketSelector
438
-     * there's one ticket, and max attendees is set to one,
439
-     * so if the event is free, then this is a "simple" ticket selector
440
-     * a.k.a. "Dude Where's my Ticket Selector?"
441
-     *
442
-     * @param \EE_Ticket[] $tickets
443
-     * @param array        $template_args
444
-     * @return string
445
-     * @throws EE_Error
446
-     */
447
-    protected function simpleTicketSelector($tickets, array $template_args)
448
-    {
449
-        // if there is only ONE ticket with a max qty of ONE
450
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
451
-            return '';
452
-        }
453
-        /** @var \EE_Ticket $ticket */
454
-        $ticket = reset($tickets);
455
-        // if the ticket is free... then not much need for the ticket selector
456
-        if (apply_filters(
457
-            'FHEE__ticket_selector_chart_template__hide_ticket_selector',
458
-            $ticket->is_free(),
459
-            $this->event->ID()
460
-        )) {
461
-            return new TicketSelectorSimple(
462
-                $this->event,
463
-                $ticket,
464
-                $this->getMaxAttendees(),
465
-                $template_args
466
-            );
467
-        }
468
-        return '';
469
-    }
470
-
471
-
472
-    /**
473
-     * externalEventRegistration
474
-     *
475
-     * @return string
476
-     */
477
-    public function externalEventRegistration()
478
-    {
479
-        // if not we still need to trigger the display of the submit button
480
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
481
-        // display notice to admin that registration is external
482
-        return $this->display_full_ui()
483
-            ? esc_html__(
484
-                'Registration is at an external URL for this event.',
485
-                'event_espresso'
486
-            )
487
-            : '';
488
-    }
489
-
490
-
491
-    /**
492
-     * formOpen
493
-     *
494
-     * @param        int    $ID
495
-     * @param        string $external_url
496
-     * @return        string
497
-     */
498
-    public function formOpen($ID = 0, $external_url = '')
499
-    {
500
-        // if redirecting, we don't need any anything else
501
-        if ($external_url) {
502
-            $html = '<form method="GET" ';
503
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
504
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
505
-            // open link in new window ?
506
-            $html .= apply_filters(
507
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
508
-                $this->isIframe(),
509
-                $this
510
-            )
511
-                ? ' target="_blank"'
512
-                : '';
513
-            $html .= '>';
514
-            $query_args = EEH_URL::get_query_string($external_url);
515
-            foreach ((array) $query_args as $query_arg => $value) {
516
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
517
-            }
518
-            return $html;
519
-        }
520
-        // if there is no submit button, then don't start building a form
521
-        // because the "View Details" button will build its own form
522
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
523
-            return '';
524
-        }
525
-        $checkout_url = EEH_Event_View::event_link_url($ID);
526
-        if (! $checkout_url) {
527
-            EE_Error::add_error(
528
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
529
-                __FILE__,
530
-                __FUNCTION__,
531
-                __LINE__
532
-            );
533
-        }
534
-        // set no cache headers and constants
535
-        EE_System::do_not_cache();
536
-        $html = '<form method="POST" ';
537
-        $html .= 'action="' . $checkout_url . '" ';
538
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
539
-        $html .= $this->iframe ? ' target="_blank"' : '';
540
-        $html .= '>';
541
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
542
-        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
543
-        return $html;
544
-    }
545
-
546
-
547
-    /**
548
-     * displaySubmitButton
549
-     *
550
-     * @param  string $external_url
551
-     * @return string
552
-     * @throws EE_Error
553
-     */
554
-    public function displaySubmitButton($external_url = '')
555
-    {
556
-        $html = '';
557
-        if ($this->display_full_ui()) {
558
-            // standard TS displayed with submit button, ie: "Register Now"
559
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
560
-                $html .= $this->displayRegisterNowButton();
561
-                $html .= empty($external_url)
562
-                    ? $this->ticketSelectorEndDiv()
563
-                    : $this->clearTicketSelector();
564
-                $html .= '<br/>' . $this->formClose();
565
-            } elseif ($this->getMaxAttendees() === 1) {
566
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
567
-                if ($this->event->is_sold_out()) {
568
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
569
-                    $html .= apply_filters(
570
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
571
-                        sprintf(
572
-                            __(
573
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
574
-                                'event_espresso'
575
-                            ),
576
-                            '<p class="no-ticket-selector-msg clear-float">',
577
-                            $this->event->name(),
578
-                            '</p>',
579
-                            '<br />'
580
-                        ),
581
-                        $this->event
582
-                    );
583
-                    if (apply_filters(
584
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
585
-                        false,
586
-                        $this->event
587
-                    )) {
588
-                        $html .= $this->displayRegisterNowButton();
589
-                    }
590
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
591
-                    $html .= $this->ticketSelectorEndDiv();
592
-                } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
593
-                          && ! is_single()
594
-                ) {
595
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
596
-                    // but no tickets are available, so display event's "View Details" button.
597
-                    // it is being viewed via somewhere other than a single post
598
-                    $html .= $this->displayViewDetailsButton(true);
599
-                } else {
600
-                    $html .= $this->ticketSelectorEndDiv();
601
-                }
602
-            } elseif (is_archive()) {
603
-                // event list, no tickets available so display event's "View Details" button
604
-                $html .= $this->ticketSelectorEndDiv();
605
-                $html .= $this->displayViewDetailsButton();
606
-            } else {
607
-                if (apply_filters(
608
-                    'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
609
-                    false,
610
-                    $this->event
611
-                )) {
612
-                    $html .= $this->displayRegisterNowButton();
613
-                }
614
-                // no submit or view details button, and no additional content
615
-                $html .= $this->ticketSelectorEndDiv();
616
-            }
617
-            if (! $this->iframe && ! is_archive()) {
618
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
619
-            }
620
-        }
621
-        return apply_filters(
622
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
623
-            $html,
624
-            $this->event,
625
-            $this
626
-        );
627
-    }
628
-
629
-
630
-    /**
631
-     * @return string
632
-     * @throws EE_Error
633
-     */
634
-    public function displayRegisterNowButton()
635
-    {
636
-        $btn_text = apply_filters(
637
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
638
-            __('Register Now', 'event_espresso'),
639
-            $this->event
640
-        );
641
-        $external_url = $this->event->external_url();
642
-        $html = EEH_HTML::div(
643
-            '',
644
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
645
-            'ticket-selector-submit-btn-wrap'
646
-        );
647
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
648
-        $html .= ' class="ticket-selector-submit-btn ';
649
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
650
-        $html .= ' type="submit" value="' . $btn_text . '" />';
651
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
652
-        $html .= apply_filters(
653
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
654
-            '',
655
-            $this->event,
656
-            $this->iframe
657
-        );
658
-        return $html;
659
-    }
660
-
661
-
662
-    /**
663
-     * displayViewDetailsButton
664
-     *
665
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
666
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
667
-     *                    either because they are sold out, expired, or not yet on sale.
668
-     *                    In this case, we need to close the form BEFORE adding any closing divs
669
-     * @return string
670
-     * @throws EE_Error
671
-     */
672
-    public function displayViewDetailsButton($DWMTS = false)
673
-    {
674
-        if (! $this->event->get_permalink()) {
675
-            EE_Error::add_error(
676
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
677
-                __FILE__,
678
-                __FUNCTION__,
679
-                __LINE__
680
-            );
681
-        }
682
-        $view_details_btn = '<form method="POST" action="';
683
-        $view_details_btn .= apply_filters(
684
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
685
-            $this->event->get_permalink(),
686
-            $this->event
687
-        );
688
-        $view_details_btn .= '"';
689
-        // open link in new window ?
690
-        $view_details_btn .= apply_filters(
691
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
692
-            $this->isIframe(),
693
-            $this
694
-        )
695
-            ? ' target="_blank"'
696
-            : '';
697
-        $view_details_btn .= '>';
698
-        $btn_text = apply_filters(
699
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
700
-            esc_html__('View Details', 'event_espresso'),
701
-            $this->event
702
-        );
703
-        $view_details_btn .= '<input id="ticket-selector-submit-'
704
-                             . $this->event->ID()
705
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
706
-                             . $btn_text
707
-                             . '" />';
708
-        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
709
-        if ($DWMTS) {
710
-            $view_details_btn .= $this->formClose();
711
-            $view_details_btn .= $this->ticketSelectorEndDiv();
712
-            $view_details_btn .= '<br/>';
713
-        } else {
714
-            $view_details_btn .= $this->clearTicketSelector();
715
-            $view_details_btn .= '<br/>';
716
-            $view_details_btn .= $this->formClose();
717
-        }
718
-        return $view_details_btn;
719
-    }
720
-
721
-
722
-    /**
723
-     * @return string
724
-     */
725
-    public function ticketSelectorEndDiv()
726
-    {
727
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
728
-    }
729
-
730
-
731
-    /**
732
-     * @return string
733
-     */
734
-    public function clearTicketSelector()
735
-    {
736
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
737
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
738
-    }
739
-
740
-
741
-    /**
742
-     * @access        public
743
-     * @return        string
744
-     */
745
-    public function formClose()
746
-    {
747
-        return '</form>';
748
-    }
321
+	}
322
+
323
+
324
+	/**
325
+	 * ticketSalesClosed
326
+	 * notice displayed if event ticket sales are turned off
327
+	 *
328
+	 * @return string
329
+	 * @throws EE_Error
330
+	 */
331
+	protected function ticketSalesClosedMessage()
332
+	{
333
+		$sales_closed_msg = esc_html__(
334
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
335
+			'event_espresso'
336
+		);
337
+		if (current_user_can('edit_post', $this->event->ID())) {
338
+			$sales_closed_msg .= sprintf(
339
+				esc_html__(
340
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
341
+					'event_espresso'
342
+				),
343
+				'<div class="ee-attention" style="text-align: left;"><b>',
344
+				'</b><br />',
345
+				'<span class="edit-link"><a class="post-edit-link" href="'
346
+				. get_edit_post_link($this->event->ID())
347
+				. '">',
348
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
349
+			);
350
+		}
351
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
352
+	}
353
+
354
+
355
+	/**
356
+	 * getTickets
357
+	 *
358
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
359
+	 * @throws EE_Error
360
+	 * @throws InvalidDataTypeException
361
+	 * @throws InvalidInterfaceException
362
+	 * @throws InvalidArgumentException
363
+	 */
364
+	protected function getTickets()
365
+	{
366
+		$ticket_query_args = array(
367
+			array('Datetime.EVT_ID' => $this->event->ID()),
368
+			'order_by' => array(
369
+				'TKT_order'              => 'ASC',
370
+				'TKT_required'           => 'DESC',
371
+				'TKT_start_date'         => 'ASC',
372
+				'TKT_end_date'           => 'ASC',
373
+				'Datetime.DTT_EVT_start' => 'DESC',
374
+			),
375
+		);
376
+		if (! (
377
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
378
+			&& EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
379
+		)) {
380
+			// use the correct applicable time query depending on what version of core is being run.
381
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query')
382
+				? time()
383
+				: current_time('timestamp');
384
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
385
+		}
386
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
387
+	}
388
+
389
+
390
+	/**
391
+	 * loadTicketSelector
392
+	 * begins to assemble template arguments
393
+	 * and decides whether to load a "simple" ticket selector, or the standard
394
+	 *
395
+	 * @param \EE_Ticket[] $tickets
396
+	 * @param array        $template_args
397
+	 * @return string
398
+	 * @throws EE_Error
399
+	 */
400
+	protected function loadTicketSelector(array $tickets, array $template_args)
401
+	{
402
+		$template_args['event'] = $this->event;
403
+		$template_args['EVT_ID'] = $this->event->ID();
404
+		$template_args['event_is_expired'] = $this->event->is_expired();
405
+		$template_args['max_atndz'] = $this->getMaxAttendees();
406
+		$template_args['date_format'] = $this->date_format;
407
+		$template_args['time_format'] = $this->time_format;
408
+		/**
409
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
410
+		 *
411
+		 * @since 4.9.13
412
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
413
+		 * @param int $EVT_ID The Event ID
414
+		 */
415
+		$template_args['anchor_id'] = apply_filters(
416
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
417
+			'#tkt-slctr-tbl-' . $this->event->ID(),
418
+			$this->event->ID()
419
+		);
420
+		$template_args['tickets'] = $tickets;
421
+		$template_args['ticket_count'] = count($tickets);
422
+		$ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
423
+		return $ticket_selector instanceof TicketSelectorSimple
424
+			? $ticket_selector
425
+			: new TicketSelectorStandard(
426
+				$this->event,
427
+				$tickets,
428
+				$this->getMaxAttendees(),
429
+				$template_args,
430
+				$this->date_format,
431
+				$this->time_format
432
+			);
433
+	}
434
+
435
+
436
+	/**
437
+	 * simpleTicketSelector
438
+	 * there's one ticket, and max attendees is set to one,
439
+	 * so if the event is free, then this is a "simple" ticket selector
440
+	 * a.k.a. "Dude Where's my Ticket Selector?"
441
+	 *
442
+	 * @param \EE_Ticket[] $tickets
443
+	 * @param array        $template_args
444
+	 * @return string
445
+	 * @throws EE_Error
446
+	 */
447
+	protected function simpleTicketSelector($tickets, array $template_args)
448
+	{
449
+		// if there is only ONE ticket with a max qty of ONE
450
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
451
+			return '';
452
+		}
453
+		/** @var \EE_Ticket $ticket */
454
+		$ticket = reset($tickets);
455
+		// if the ticket is free... then not much need for the ticket selector
456
+		if (apply_filters(
457
+			'FHEE__ticket_selector_chart_template__hide_ticket_selector',
458
+			$ticket->is_free(),
459
+			$this->event->ID()
460
+		)) {
461
+			return new TicketSelectorSimple(
462
+				$this->event,
463
+				$ticket,
464
+				$this->getMaxAttendees(),
465
+				$template_args
466
+			);
467
+		}
468
+		return '';
469
+	}
470
+
471
+
472
+	/**
473
+	 * externalEventRegistration
474
+	 *
475
+	 * @return string
476
+	 */
477
+	public function externalEventRegistration()
478
+	{
479
+		// if not we still need to trigger the display of the submit button
480
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
481
+		// display notice to admin that registration is external
482
+		return $this->display_full_ui()
483
+			? esc_html__(
484
+				'Registration is at an external URL for this event.',
485
+				'event_espresso'
486
+			)
487
+			: '';
488
+	}
489
+
490
+
491
+	/**
492
+	 * formOpen
493
+	 *
494
+	 * @param        int    $ID
495
+	 * @param        string $external_url
496
+	 * @return        string
497
+	 */
498
+	public function formOpen($ID = 0, $external_url = '')
499
+	{
500
+		// if redirecting, we don't need any anything else
501
+		if ($external_url) {
502
+			$html = '<form method="GET" ';
503
+			$html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
504
+			$html .= 'name="ticket-selector-form-' . $ID . '"';
505
+			// open link in new window ?
506
+			$html .= apply_filters(
507
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
508
+				$this->isIframe(),
509
+				$this
510
+			)
511
+				? ' target="_blank"'
512
+				: '';
513
+			$html .= '>';
514
+			$query_args = EEH_URL::get_query_string($external_url);
515
+			foreach ((array) $query_args as $query_arg => $value) {
516
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
517
+			}
518
+			return $html;
519
+		}
520
+		// if there is no submit button, then don't start building a form
521
+		// because the "View Details" button will build its own form
522
+		if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
523
+			return '';
524
+		}
525
+		$checkout_url = EEH_Event_View::event_link_url($ID);
526
+		if (! $checkout_url) {
527
+			EE_Error::add_error(
528
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
529
+				__FILE__,
530
+				__FUNCTION__,
531
+				__LINE__
532
+			);
533
+		}
534
+		// set no cache headers and constants
535
+		EE_System::do_not_cache();
536
+		$html = '<form method="POST" ';
537
+		$html .= 'action="' . $checkout_url . '" ';
538
+		$html .= 'name="ticket-selector-form-' . $ID . '"';
539
+		$html .= $this->iframe ? ' target="_blank"' : '';
540
+		$html .= '>';
541
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
542
+		$html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
543
+		return $html;
544
+	}
545
+
546
+
547
+	/**
548
+	 * displaySubmitButton
549
+	 *
550
+	 * @param  string $external_url
551
+	 * @return string
552
+	 * @throws EE_Error
553
+	 */
554
+	public function displaySubmitButton($external_url = '')
555
+	{
556
+		$html = '';
557
+		if ($this->display_full_ui()) {
558
+			// standard TS displayed with submit button, ie: "Register Now"
559
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
560
+				$html .= $this->displayRegisterNowButton();
561
+				$html .= empty($external_url)
562
+					? $this->ticketSelectorEndDiv()
563
+					: $this->clearTicketSelector();
564
+				$html .= '<br/>' . $this->formClose();
565
+			} elseif ($this->getMaxAttendees() === 1) {
566
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
567
+				if ($this->event->is_sold_out()) {
568
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
569
+					$html .= apply_filters(
570
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
571
+						sprintf(
572
+							__(
573
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
574
+								'event_espresso'
575
+							),
576
+							'<p class="no-ticket-selector-msg clear-float">',
577
+							$this->event->name(),
578
+							'</p>',
579
+							'<br />'
580
+						),
581
+						$this->event
582
+					);
583
+					if (apply_filters(
584
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
585
+						false,
586
+						$this->event
587
+					)) {
588
+						$html .= $this->displayRegisterNowButton();
589
+					}
590
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
591
+					$html .= $this->ticketSelectorEndDiv();
592
+				} elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
593
+						  && ! is_single()
594
+				) {
595
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
596
+					// but no tickets are available, so display event's "View Details" button.
597
+					// it is being viewed via somewhere other than a single post
598
+					$html .= $this->displayViewDetailsButton(true);
599
+				} else {
600
+					$html .= $this->ticketSelectorEndDiv();
601
+				}
602
+			} elseif (is_archive()) {
603
+				// event list, no tickets available so display event's "View Details" button
604
+				$html .= $this->ticketSelectorEndDiv();
605
+				$html .= $this->displayViewDetailsButton();
606
+			} else {
607
+				if (apply_filters(
608
+					'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
609
+					false,
610
+					$this->event
611
+				)) {
612
+					$html .= $this->displayRegisterNowButton();
613
+				}
614
+				// no submit or view details button, and no additional content
615
+				$html .= $this->ticketSelectorEndDiv();
616
+			}
617
+			if (! $this->iframe && ! is_archive()) {
618
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
619
+			}
620
+		}
621
+		return apply_filters(
622
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
623
+			$html,
624
+			$this->event,
625
+			$this
626
+		);
627
+	}
628
+
629
+
630
+	/**
631
+	 * @return string
632
+	 * @throws EE_Error
633
+	 */
634
+	public function displayRegisterNowButton()
635
+	{
636
+		$btn_text = apply_filters(
637
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
638
+			__('Register Now', 'event_espresso'),
639
+			$this->event
640
+		);
641
+		$external_url = $this->event->external_url();
642
+		$html = EEH_HTML::div(
643
+			'',
644
+			'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
645
+			'ticket-selector-submit-btn-wrap'
646
+		);
647
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
648
+		$html .= ' class="ticket-selector-submit-btn ';
649
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
650
+		$html .= ' type="submit" value="' . $btn_text . '" />';
651
+		$html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
652
+		$html .= apply_filters(
653
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
654
+			'',
655
+			$this->event,
656
+			$this->iframe
657
+		);
658
+		return $html;
659
+	}
660
+
661
+
662
+	/**
663
+	 * displayViewDetailsButton
664
+	 *
665
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
666
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
667
+	 *                    either because they are sold out, expired, or not yet on sale.
668
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
669
+	 * @return string
670
+	 * @throws EE_Error
671
+	 */
672
+	public function displayViewDetailsButton($DWMTS = false)
673
+	{
674
+		if (! $this->event->get_permalink()) {
675
+			EE_Error::add_error(
676
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
677
+				__FILE__,
678
+				__FUNCTION__,
679
+				__LINE__
680
+			);
681
+		}
682
+		$view_details_btn = '<form method="POST" action="';
683
+		$view_details_btn .= apply_filters(
684
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
685
+			$this->event->get_permalink(),
686
+			$this->event
687
+		);
688
+		$view_details_btn .= '"';
689
+		// open link in new window ?
690
+		$view_details_btn .= apply_filters(
691
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
692
+			$this->isIframe(),
693
+			$this
694
+		)
695
+			? ' target="_blank"'
696
+			: '';
697
+		$view_details_btn .= '>';
698
+		$btn_text = apply_filters(
699
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
700
+			esc_html__('View Details', 'event_espresso'),
701
+			$this->event
702
+		);
703
+		$view_details_btn .= '<input id="ticket-selector-submit-'
704
+							 . $this->event->ID()
705
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
706
+							 . $btn_text
707
+							 . '" />';
708
+		$view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
709
+		if ($DWMTS) {
710
+			$view_details_btn .= $this->formClose();
711
+			$view_details_btn .= $this->ticketSelectorEndDiv();
712
+			$view_details_btn .= '<br/>';
713
+		} else {
714
+			$view_details_btn .= $this->clearTicketSelector();
715
+			$view_details_btn .= '<br/>';
716
+			$view_details_btn .= $this->formClose();
717
+		}
718
+		return $view_details_btn;
719
+	}
720
+
721
+
722
+	/**
723
+	 * @return string
724
+	 */
725
+	public function ticketSelectorEndDiv()
726
+	{
727
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
728
+	}
729
+
730
+
731
+	/**
732
+	 * @return string
733
+	 */
734
+	public function clearTicketSelector()
735
+	{
736
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
737
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
738
+	}
739
+
740
+
741
+	/**
742
+	 * @access        public
743
+	 * @return        string
744
+	 */
745
+	public function formClose()
746
+	{
747
+		return '</form>';
748
+	}
749 749
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
             }
136 136
         } else {
137 137
             $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
-            $dev_msg = $user_msg . __(
138
+            $dev_msg = $user_msg.__(
139 139
                 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140 140
                 'event_espresso'
141 141
             );
142
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
142
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
143 143
             return false;
144 144
         }
145 145
         return true;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         // reset filter for displaying submit button
201 201
         remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202 202
         // poke and prod incoming event till it tells us what it is
203
-        if (! $this->setEvent($event)) {
203
+        if ( ! $this->setEvent($event)) {
204 204
             return false;
205 205
         }
206 206
         // begin gathering template arguments by getting event status
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
             : $this->loadTicketSelector($tickets, $template_args);
236 236
         // now set up the form (but not for the admin)
237 237
         $ticket_selector = $this->display_full_ui()
238
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
238
+            ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector
239 239
             : $ticket_selector;
240 240
         // submit button and form close tag
241 241
         $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
      */
284 284
     protected function expiredEventMessage()
285 285
     {
286
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
286
+        return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(
287 287
             'We\'re sorry, but all tickets sales have ended because the event is expired.',
288 288
             'event_espresso'
289
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
289
+        ).'</span></div><!-- .ee-event-expired-notice -->';
290 290
     }
291 291
 
292 292
 
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
         }
317 317
         return '
318 318
             <div class="ee-event-expired-notice">
319
-                <span class="important-notice">' . $no_ticket_available_msg . '</span>
319
+                <span class="important-notice">' . $no_ticket_available_msg.'</span>
320 320
             </div><!-- .ee-event-expired-notice -->';
321 321
     }
322 322
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
                 '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
349 349
             );
350 350
         }
351
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
351
+        return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
352 352
     }
353 353
 
354 354
 
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
                 'Datetime.DTT_EVT_start' => 'DESC',
374 374
             ),
375 375
         );
376
-        if (! (
376
+        if ( ! (
377 377
             EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
378 378
             && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
379 379
         )) {
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
          */
415 415
         $template_args['anchor_id'] = apply_filters(
416 416
             'FHEE__EE_Ticket_Selector__redirect_anchor_id',
417
-            '#tkt-slctr-tbl-' . $this->event->ID(),
417
+            '#tkt-slctr-tbl-'.$this->event->ID(),
418 418
             $this->event->ID()
419 419
         );
420 420
         $template_args['tickets'] = $tickets;
@@ -500,8 +500,8 @@  discard block
 block discarded – undo
500 500
         // if redirecting, we don't need any anything else
501 501
         if ($external_url) {
502 502
             $html = '<form method="GET" ';
503
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
504
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
503
+            $html .= 'action="'.EEH_URL::refactor_url($external_url).'" ';
504
+            $html .= 'name="ticket-selector-form-'.$ID.'"';
505 505
             // open link in new window ?
506 506
             $html .= apply_filters(
507 507
                 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
@@ -513,17 +513,17 @@  discard block
 block discarded – undo
513 513
             $html .= '>';
514 514
             $query_args = EEH_URL::get_query_string($external_url);
515 515
             foreach ((array) $query_args as $query_arg => $value) {
516
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
516
+                $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';
517 517
             }
518 518
             return $html;
519 519
         }
520 520
         // if there is no submit button, then don't start building a form
521 521
         // because the "View Details" button will build its own form
522
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
522
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
523 523
             return '';
524 524
         }
525 525
         $checkout_url = EEH_Event_View::event_link_url($ID);
526
-        if (! $checkout_url) {
526
+        if ( ! $checkout_url) {
527 527
             EE_Error::add_error(
528 528
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
529 529
                 __FILE__,
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
         // set no cache headers and constants
535 535
         EE_System::do_not_cache();
536 536
         $html = '<form method="POST" ';
537
-        $html .= 'action="' . $checkout_url . '" ';
538
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
537
+        $html .= 'action="'.$checkout_url.'" ';
538
+        $html .= 'name="ticket-selector-form-'.$ID.'"';
539 539
         $html .= $this->iframe ? ' target="_blank"' : '';
540 540
         $html .= '>';
541 541
         $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
                 $html .= empty($external_url)
562 562
                     ? $this->ticketSelectorEndDiv()
563 563
                     : $this->clearTicketSelector();
564
-                $html .= '<br/>' . $this->formClose();
564
+                $html .= '<br/>'.$this->formClose();
565 565
             } elseif ($this->getMaxAttendees() === 1) {
566 566
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
567 567
                 if ($this->event->is_sold_out()) {
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
                 // no submit or view details button, and no additional content
615 615
                 $html .= $this->ticketSelectorEndDiv();
616 616
             }
617
-            if (! $this->iframe && ! is_archive()) {
617
+            if ( ! $this->iframe && ! is_archive()) {
618 618
                 $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
619 619
             }
620 620
         }
@@ -641,14 +641,14 @@  discard block
 block discarded – undo
641 641
         $external_url = $this->event->external_url();
642 642
         $html = EEH_HTML::div(
643 643
             '',
644
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
644
+            'ticket-selector-submit-'.$this->event->ID().'-btn-wrap',
645 645
             'ticket-selector-submit-btn-wrap'
646 646
         );
647
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
647
+        $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
648 648
         $html .= ' class="ticket-selector-submit-btn ';
649 649
         $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
650
-        $html .= ' type="submit" value="' . $btn_text . '" />';
651
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
650
+        $html .= ' type="submit" value="'.$btn_text.'" />';
651
+        $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->';
652 652
         $html .= apply_filters(
653 653
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
654 654
             '',
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      */
672 672
     public function displayViewDetailsButton($DWMTS = false)
673 673
     {
674
-        if (! $this->event->get_permalink()) {
674
+        if ( ! $this->event->get_permalink()) {
675 675
             EE_Error::add_error(
676 676
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
677 677
                 __FILE__,
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
      */
725 725
     public function ticketSelectorEndDiv()
726 726
     {
727
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
727
+        return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->';
728 728
     }
729 729
 
730 730
 
Please login to merge, or discard this patch.
core/services/Benchmark.php 2 patches
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -15,324 +15,324 @@
 block discarded – undo
15 15
 class Benchmark
16 16
 {
17 17
 
18
-    /**
19
-     * @var string $output
20
-     */
21
-    private static $output;
22
-
23
-    /**
24
-     * @var array $start_times array containing the start time for the timers
25
-     */
26
-    private static $start_times;
27
-
28
-    /**
29
-     * @var array $times array containing all the timer'd times, which can be outputted via show_times()
30
-     */
31
-    private static $times = array();
32
-
33
-    /**
34
-     * @var array $memory_usage
35
-     */
36
-    protected static $memory_usage = array();
37
-
38
-
39
-    /**
40
-     * @param string $output
41
-     * @param bool   $formatted
42
-     */
43
-    public static function addOutput($output, $formatted = true)
44
-    {
45
-        Benchmark::$output .= $formatted
46
-            ? "<br />{$output}"
47
-            : "\n{$output}";
48
-    }
49
-
50
-
51
-    /**
52
-     * @return void
53
-     */
54
-    public static function resetOutput()
55
-    {
56
-        Benchmark::$output = '';
57
-    }
58
-
59
-    /**
60
-     * whether to benchmark code or not
61
-     */
62
-    public static function doNotRun()
63
-    {
64
-        return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
65
-    }
66
-
67
-
68
-    /**
69
-     * resetTimes
70
-     */
71
-    public static function resetTimes()
72
-    {
73
-        Benchmark::$times = array();
74
-    }
75
-
76
-
77
-    /**
78
-     * Add Benchmark::startTimer() before a block of code you want to measure the performance of
79
-     *
80
-     * @param null $timer_name
81
-     */
82
-    public static function startTimer($timer_name = null)
83
-    {
84
-        if (Benchmark::doNotRun()) {
85
-            return;
86
-        }
87
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
88
-        Benchmark::$start_times[ $timer_name ] = microtime(true);
89
-    }
90
-
91
-
92
-    /**
93
-     * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
94
-     *
95
-     * @param string $timer_name
96
-     */
97
-    public static function stopTimer($timer_name = '')
98
-    {
99
-        if (Benchmark::doNotRun()) {
100
-            return;
101
-        }
102
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
103
-        if (isset(Benchmark::$start_times[ $timer_name ])) {
104
-            $start_time = Benchmark::$start_times[ $timer_name ];
105
-            unset(Benchmark::$start_times[ $timer_name ]);
106
-        } else {
107
-            $start_time = array_pop(Benchmark::$start_times);
108
-        }
109
-        Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8);
110
-    }
111
-
112
-
113
-    /**
114
-     * Measure the memory usage by PHP so far.
115
-     *
116
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
117
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
118
-     * @param bool    $formatted
119
-     * @return void
120
-     */
121
-    public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
122
-    {
123
-        if (Benchmark::doNotRun()) {
124
-            return;
125
-        }
126
-        $memory_used = Benchmark::convert(memory_get_usage(true));
127
-        Benchmark::$memory_usage[ $label ] = $memory_used;
128
-        if ($output_now) {
129
-            echo $formatted
130
-                ? "<br>{$label} : {$memory_used}"
131
-                : "\n {$label} : {$memory_used}";
132
-        }
133
-    }
134
-
135
-
136
-    /**
137
-     * will display the benchmarking results at shutdown
138
-     *
139
-     * @param bool $formatted
140
-     * @return void
141
-     */
142
-    public static function displayResultsAtShutdown($formatted = true)
143
-    {
144
-        Benchmark::resetOutput();
145
-        add_action(
146
-            'shutdown',
147
-            function () use ($formatted) {
148
-                Benchmark::displayResults(true, $formatted);
149
-            },
150
-            999999
151
-        );
152
-    }
153
-
154
-
155
-    /**
156
-     * will display the benchmarking results at shutdown
157
-     *
158
-     * @param string $filepath
159
-     * @param bool   $formatted
160
-     * @param bool   $append
161
-     * @return void
162
-     */
163
-    public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
164
-    {
165
-        Benchmark::resetOutput();
166
-        add_action(
167
-            'shutdown',
168
-            function () use ($filepath, $formatted, $append) {
169
-                Benchmark::writeResultsToFile($filepath, $formatted, $append);
170
-            },
171
-            999999
172
-        );
173
-    }
174
-
175
-
176
-    /**
177
-     * @param bool $formatted
178
-     * @return string
179
-     */
180
-    private static function generateResults($formatted = true)
181
-    {
182
-        if (Benchmark::doNotRun()) {
183
-            return '';
184
-        }
185
-        if (! empty(Benchmark::$times)) {
186
-            $total = 0;
187
-            Benchmark::$output .= $formatted
188
-                ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
189
-                : '';
190
-            foreach (Benchmark::$times as $timer_name => $total_time) {
191
-                Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
192
-                Benchmark::$output .= $formatted ? '<br />' : "\n";
193
-                $total += $total_time;
194
-            }
195
-            if ($formatted) {
196
-                Benchmark::$output .= '<br />';
197
-                Benchmark::$output .= '<h4>TOTAL TIME</h4>';
198
-                Benchmark::$output .= Benchmark::formatTime('', $total, $formatted);
199
-                Benchmark::$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
200
-                Benchmark::$output .= '<br />';
201
-                Benchmark::$output .= '<h5>Performance scale (from best to worse)</h5>';
202
-                Benchmark::$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
203
-                Benchmark::$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
204
-                Benchmark::$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
205
-                Benchmark::$output .= '<span style="color:gold">Ruh Oh</span><br />';
206
-                Benchmark::$output .= '<span style="color:darkorange">Zoinks!</span><br />';
207
-                Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
208
-            }
209
-        }
210
-        if (! empty(Benchmark::$memory_usage)) {
211
-            Benchmark::$output .= $formatted
212
-                ? '<h5>Memory</h5>'
213
-                : "\nMemory";
214
-            foreach (Benchmark::$memory_usage as $label => $memory_usage) {
215
-                Benchmark::$output .= $formatted
216
-                    ? "<br />{$memory_usage} : {$label}"
217
-                    : "\n{$memory_usage} : {$label}";
218
-            }
219
-        }
220
-        if (empty(Benchmark::$output)) {
221
-            return '';
222
-        }
223
-        Benchmark::$output = $formatted
224
-            ? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
225
-              . (is_admin()
226
-                ? ' margin:2em 2em 2em 180px;'
227
-                : ' margin:2em;')
228
-              . ' padding:2em;">'
229
-              . '<h4>BENCHMARKING</h4>'
230
-              . Benchmark::$output
231
-              . '</div>'
232
-            : Benchmark::$output;
233
-        return Benchmark::$output;
234
-    }
235
-
236
-
237
-    /**
238
-     * @param bool $echo
239
-     * @param bool $formatted
240
-     * @return string
241
-     */
242
-    public static function displayResults($echo = true, $formatted = true)
243
-    {
244
-        $results = Benchmark::generateResults($formatted);
245
-        if ($echo) {
246
-            echo $results;
247
-            $results = '';
248
-        }
249
-        return $results;
250
-    }
251
-
252
-
253
-    /**
254
-     * @param string $filepath
255
-     * @param bool   $formatted
256
-     * @param bool   $append
257
-     * @throws EE_Error
258
-     */
259
-    public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
260
-    {
261
-        $filepath = ! empty($filepath) && is_readable(dirname($filepath))
262
-            ? $filepath
263
-            : '';
264
-        if (empty($filepath)) {
265
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
266
-        }
267
-        EEH_File::ensure_file_exists_and_is_writable($filepath);
268
-        file_put_contents(
269
-            $filepath,
270
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
271
-            $append ? FILE_APPEND | LOCK_EX : LOCK_EX
272
-        );
273
-    }
274
-
275
-
276
-    /**
277
-     * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
278
-     *
279
-     * @param int $size
280
-     * @return string
281
-     */
282
-    public static function convert($size)
283
-    {
284
-        $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
285
-        return round(
286
-            $size / pow(1024, $i = floor(log($size, 1024))),
287
-            2
288
-        ) . ' ' . $unit[ absint($i) ];
289
-    }
290
-
291
-
292
-    /**
293
-     * @param string $timer_name
294
-     * @param float  $total_time
295
-     * @param bool   $formatted
296
-     * @return string
297
-     */
298
-    public static function formatTime($timer_name, $total_time, $formatted = true)
299
-    {
300
-        $total_time *= 1000;
301
-        switch ($total_time) {
302
-            case $total_time > 12500:
303
-                $color = 'red';
304
-                $bold = 'bold';
305
-                break;
306
-            case $total_time > 2500:
307
-                $color = 'darkorange';
308
-                $bold = 'bold';
309
-                break;
310
-            case $total_time > 500:
311
-                $color = 'gold';
312
-                $bold = 'bold';
313
-                break;
314
-            case $total_time > 100:
315
-                $color = 'limegreen';
316
-                $bold = 'normal';
317
-                break;
318
-            case $total_time > 20:
319
-                $color = 'deepskyblue';
320
-                $bold = 'normal';
321
-                break;
322
-            default:
323
-                $color = 'mediumpurple';
324
-                $bold = 'normal';
325
-                break;
326
-        }
327
-        return $formatted
328
-            ? '<span style="min-width: 10px; margin:0 1em; color:'
329
-              . $color
330
-              . '; font-weight:'
331
-              . $bold
332
-              . '; font-size:1.2em;">'
333
-              . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
334
-              . '</span> '
335
-              . $timer_name
336
-            : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
337
-    }
18
+	/**
19
+	 * @var string $output
20
+	 */
21
+	private static $output;
22
+
23
+	/**
24
+	 * @var array $start_times array containing the start time for the timers
25
+	 */
26
+	private static $start_times;
27
+
28
+	/**
29
+	 * @var array $times array containing all the timer'd times, which can be outputted via show_times()
30
+	 */
31
+	private static $times = array();
32
+
33
+	/**
34
+	 * @var array $memory_usage
35
+	 */
36
+	protected static $memory_usage = array();
37
+
38
+
39
+	/**
40
+	 * @param string $output
41
+	 * @param bool   $formatted
42
+	 */
43
+	public static function addOutput($output, $formatted = true)
44
+	{
45
+		Benchmark::$output .= $formatted
46
+			? "<br />{$output}"
47
+			: "\n{$output}";
48
+	}
49
+
50
+
51
+	/**
52
+	 * @return void
53
+	 */
54
+	public static function resetOutput()
55
+	{
56
+		Benchmark::$output = '';
57
+	}
58
+
59
+	/**
60
+	 * whether to benchmark code or not
61
+	 */
62
+	public static function doNotRun()
63
+	{
64
+		return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
65
+	}
66
+
67
+
68
+	/**
69
+	 * resetTimes
70
+	 */
71
+	public static function resetTimes()
72
+	{
73
+		Benchmark::$times = array();
74
+	}
75
+
76
+
77
+	/**
78
+	 * Add Benchmark::startTimer() before a block of code you want to measure the performance of
79
+	 *
80
+	 * @param null $timer_name
81
+	 */
82
+	public static function startTimer($timer_name = null)
83
+	{
84
+		if (Benchmark::doNotRun()) {
85
+			return;
86
+		}
87
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
88
+		Benchmark::$start_times[ $timer_name ] = microtime(true);
89
+	}
90
+
91
+
92
+	/**
93
+	 * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
94
+	 *
95
+	 * @param string $timer_name
96
+	 */
97
+	public static function stopTimer($timer_name = '')
98
+	{
99
+		if (Benchmark::doNotRun()) {
100
+			return;
101
+		}
102
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
103
+		if (isset(Benchmark::$start_times[ $timer_name ])) {
104
+			$start_time = Benchmark::$start_times[ $timer_name ];
105
+			unset(Benchmark::$start_times[ $timer_name ]);
106
+		} else {
107
+			$start_time = array_pop(Benchmark::$start_times);
108
+		}
109
+		Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8);
110
+	}
111
+
112
+
113
+	/**
114
+	 * Measure the memory usage by PHP so far.
115
+	 *
116
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
117
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
118
+	 * @param bool    $formatted
119
+	 * @return void
120
+	 */
121
+	public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
122
+	{
123
+		if (Benchmark::doNotRun()) {
124
+			return;
125
+		}
126
+		$memory_used = Benchmark::convert(memory_get_usage(true));
127
+		Benchmark::$memory_usage[ $label ] = $memory_used;
128
+		if ($output_now) {
129
+			echo $formatted
130
+				? "<br>{$label} : {$memory_used}"
131
+				: "\n {$label} : {$memory_used}";
132
+		}
133
+	}
134
+
135
+
136
+	/**
137
+	 * will display the benchmarking results at shutdown
138
+	 *
139
+	 * @param bool $formatted
140
+	 * @return void
141
+	 */
142
+	public static function displayResultsAtShutdown($formatted = true)
143
+	{
144
+		Benchmark::resetOutput();
145
+		add_action(
146
+			'shutdown',
147
+			function () use ($formatted) {
148
+				Benchmark::displayResults(true, $formatted);
149
+			},
150
+			999999
151
+		);
152
+	}
153
+
154
+
155
+	/**
156
+	 * will display the benchmarking results at shutdown
157
+	 *
158
+	 * @param string $filepath
159
+	 * @param bool   $formatted
160
+	 * @param bool   $append
161
+	 * @return void
162
+	 */
163
+	public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
164
+	{
165
+		Benchmark::resetOutput();
166
+		add_action(
167
+			'shutdown',
168
+			function () use ($filepath, $formatted, $append) {
169
+				Benchmark::writeResultsToFile($filepath, $formatted, $append);
170
+			},
171
+			999999
172
+		);
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param bool $formatted
178
+	 * @return string
179
+	 */
180
+	private static function generateResults($formatted = true)
181
+	{
182
+		if (Benchmark::doNotRun()) {
183
+			return '';
184
+		}
185
+		if (! empty(Benchmark::$times)) {
186
+			$total = 0;
187
+			Benchmark::$output .= $formatted
188
+				? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
189
+				: '';
190
+			foreach (Benchmark::$times as $timer_name => $total_time) {
191
+				Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
192
+				Benchmark::$output .= $formatted ? '<br />' : "\n";
193
+				$total += $total_time;
194
+			}
195
+			if ($formatted) {
196
+				Benchmark::$output .= '<br />';
197
+				Benchmark::$output .= '<h4>TOTAL TIME</h4>';
198
+				Benchmark::$output .= Benchmark::formatTime('', $total, $formatted);
199
+				Benchmark::$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
200
+				Benchmark::$output .= '<br />';
201
+				Benchmark::$output .= '<h5>Performance scale (from best to worse)</h5>';
202
+				Benchmark::$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
203
+				Benchmark::$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
204
+				Benchmark::$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
205
+				Benchmark::$output .= '<span style="color:gold">Ruh Oh</span><br />';
206
+				Benchmark::$output .= '<span style="color:darkorange">Zoinks!</span><br />';
207
+				Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
208
+			}
209
+		}
210
+		if (! empty(Benchmark::$memory_usage)) {
211
+			Benchmark::$output .= $formatted
212
+				? '<h5>Memory</h5>'
213
+				: "\nMemory";
214
+			foreach (Benchmark::$memory_usage as $label => $memory_usage) {
215
+				Benchmark::$output .= $formatted
216
+					? "<br />{$memory_usage} : {$label}"
217
+					: "\n{$memory_usage} : {$label}";
218
+			}
219
+		}
220
+		if (empty(Benchmark::$output)) {
221
+			return '';
222
+		}
223
+		Benchmark::$output = $formatted
224
+			? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
225
+			  . (is_admin()
226
+				? ' margin:2em 2em 2em 180px;'
227
+				: ' margin:2em;')
228
+			  . ' padding:2em;">'
229
+			  . '<h4>BENCHMARKING</h4>'
230
+			  . Benchmark::$output
231
+			  . '</div>'
232
+			: Benchmark::$output;
233
+		return Benchmark::$output;
234
+	}
235
+
236
+
237
+	/**
238
+	 * @param bool $echo
239
+	 * @param bool $formatted
240
+	 * @return string
241
+	 */
242
+	public static function displayResults($echo = true, $formatted = true)
243
+	{
244
+		$results = Benchmark::generateResults($formatted);
245
+		if ($echo) {
246
+			echo $results;
247
+			$results = '';
248
+		}
249
+		return $results;
250
+	}
251
+
252
+
253
+	/**
254
+	 * @param string $filepath
255
+	 * @param bool   $formatted
256
+	 * @param bool   $append
257
+	 * @throws EE_Error
258
+	 */
259
+	public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
260
+	{
261
+		$filepath = ! empty($filepath) && is_readable(dirname($filepath))
262
+			? $filepath
263
+			: '';
264
+		if (empty($filepath)) {
265
+			$filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
266
+		}
267
+		EEH_File::ensure_file_exists_and_is_writable($filepath);
268
+		file_put_contents(
269
+			$filepath,
270
+			"\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
271
+			$append ? FILE_APPEND | LOCK_EX : LOCK_EX
272
+		);
273
+	}
274
+
275
+
276
+	/**
277
+	 * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
278
+	 *
279
+	 * @param int $size
280
+	 * @return string
281
+	 */
282
+	public static function convert($size)
283
+	{
284
+		$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
285
+		return round(
286
+			$size / pow(1024, $i = floor(log($size, 1024))),
287
+			2
288
+		) . ' ' . $unit[ absint($i) ];
289
+	}
290
+
291
+
292
+	/**
293
+	 * @param string $timer_name
294
+	 * @param float  $total_time
295
+	 * @param bool   $formatted
296
+	 * @return string
297
+	 */
298
+	public static function formatTime($timer_name, $total_time, $formatted = true)
299
+	{
300
+		$total_time *= 1000;
301
+		switch ($total_time) {
302
+			case $total_time > 12500:
303
+				$color = 'red';
304
+				$bold = 'bold';
305
+				break;
306
+			case $total_time > 2500:
307
+				$color = 'darkorange';
308
+				$bold = 'bold';
309
+				break;
310
+			case $total_time > 500:
311
+				$color = 'gold';
312
+				$bold = 'bold';
313
+				break;
314
+			case $total_time > 100:
315
+				$color = 'limegreen';
316
+				$bold = 'normal';
317
+				break;
318
+			case $total_time > 20:
319
+				$color = 'deepskyblue';
320
+				$bold = 'normal';
321
+				break;
322
+			default:
323
+				$color = 'mediumpurple';
324
+				$bold = 'normal';
325
+				break;
326
+		}
327
+		return $formatted
328
+			? '<span style="min-width: 10px; margin:0 1em; color:'
329
+			  . $color
330
+			  . '; font-weight:'
331
+			  . $bold
332
+			  . '; font-size:1.2em;">'
333
+			  . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
334
+			  . '</span> '
335
+			  . $timer_name
336
+			: str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
337
+	}
338 338
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
             return;
86 86
         }
87 87
         $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
88
-        Benchmark::$start_times[ $timer_name ] = microtime(true);
88
+        Benchmark::$start_times[$timer_name] = microtime(true);
89 89
     }
90 90
 
91 91
 
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
             return;
101 101
         }
102 102
         $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
103
-        if (isset(Benchmark::$start_times[ $timer_name ])) {
104
-            $start_time = Benchmark::$start_times[ $timer_name ];
105
-            unset(Benchmark::$start_times[ $timer_name ]);
103
+        if (isset(Benchmark::$start_times[$timer_name])) {
104
+            $start_time = Benchmark::$start_times[$timer_name];
105
+            unset(Benchmark::$start_times[$timer_name]);
106 106
         } else {
107 107
             $start_time = array_pop(Benchmark::$start_times);
108 108
         }
109
-        Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8);
109
+        Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
110 110
     }
111 111
 
112 112
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             return;
125 125
         }
126 126
         $memory_used = Benchmark::convert(memory_get_usage(true));
127
-        Benchmark::$memory_usage[ $label ] = $memory_used;
127
+        Benchmark::$memory_usage[$label] = $memory_used;
128 128
         if ($output_now) {
129 129
             echo $formatted
130 130
                 ? "<br>{$label} : {$memory_used}"
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         Benchmark::resetOutput();
145 145
         add_action(
146 146
             'shutdown',
147
-            function () use ($formatted) {
147
+            function() use ($formatted) {
148 148
                 Benchmark::displayResults(true, $formatted);
149 149
             },
150 150
             999999
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
         Benchmark::resetOutput();
166 166
         add_action(
167 167
             'shutdown',
168
-            function () use ($filepath, $formatted, $append) {
168
+            function() use ($filepath, $formatted, $append) {
169 169
                 Benchmark::writeResultsToFile($filepath, $formatted, $append);
170 170
             },
171 171
             999999
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         if (Benchmark::doNotRun()) {
183 183
             return '';
184 184
         }
185
-        if (! empty(Benchmark::$times)) {
185
+        if ( ! empty(Benchmark::$times)) {
186 186
             $total = 0;
187 187
             Benchmark::$output .= $formatted
188 188
                 ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
                 Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
208 208
             }
209 209
         }
210
-        if (! empty(Benchmark::$memory_usage)) {
210
+        if ( ! empty(Benchmark::$memory_usage)) {
211 211
             Benchmark::$output .= $formatted
212 212
                 ? '<h5>Memory</h5>'
213 213
                 : "\nMemory";
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
             ? $filepath
263 263
             : '';
264 264
         if (empty($filepath)) {
265
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
265
+            $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html';
266 266
         }
267 267
         EEH_File::ensure_file_exists_and_is_writable($filepath);
268 268
         file_put_contents(
269 269
             $filepath,
270
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
270
+            "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted),
271 271
             $append ? FILE_APPEND | LOCK_EX : LOCK_EX
272 272
         );
273 273
     }
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
         return round(
286 286
             $size / pow(1024, $i = floor(log($size, 1024))),
287 287
             2
288
-        ) . ' ' . $unit[ absint($i) ];
288
+        ).' '.$unit[absint($i)];
289 289
     }
290 290
 
291 291
 
Please login to merge, or discard this patch.
core/services/request/Request.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             || ($key === 'ee' && empty($this->request['ee']))
164 164
             || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
165 165
         ) {
166
-            $this->request[ $key ] = $value;
166
+            $this->request[$key] = $value;
167 167
         }
168 168
     }
169 169
 
@@ -254,10 +254,10 @@  discard block
 block discarded – undo
254 254
             preg_quote($pattern, '/')
255 255
         );
256 256
         foreach ($request_params as $key => $request_param) {
257
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
257
+            if (preg_match('/^'.$pattern.'$/is', $key)) {
258 258
                 // return value for request param
259 259
                 if ($return === 'value') {
260
-                    return $request_params[ $key ];
260
+                    return $request_params[$key];
261 261
                 }
262 262
                 // or actual key or true just to indicate it was found
263 263
                 return $return === 'key' ? $key : true;
@@ -314,29 +314,29 @@  discard block
 block discarded – undo
314 314
                 $key = $real_key ? $real_key : $key;
315 315
             }
316 316
             // check if top level key exists
317
-            if (isset($request_params[ $key ])) {
317
+            if (isset($request_params[$key])) {
318 318
                 // build a new key to pass along like: 'second[third]'
319 319
                 // or just 'second' depending on depth of keys
320 320
                 $key_string = array_shift($keys);
321
-                if (! empty($keys)) {
322
-                    $key_string .= '[' . implode('][', $keys) . ']';
321
+                if ( ! empty($keys)) {
322
+                    $key_string .= '['.implode('][', $keys).']';
323 323
                 }
324 324
                 return $this->requestParameterDrillDown(
325 325
                     $key_string,
326 326
                     $default,
327 327
                     $callback,
328
-                    $request_params[ $key ]
328
+                    $request_params[$key]
329 329
                 );
330 330
             }
331 331
         }
332 332
         if ($callback === 'is_set') {
333
-            return isset($request_params[ $key ]);
333
+            return isset($request_params[$key]);
334 334
         }
335 335
         if ($callback === 'match') {
336 336
             return $this->match($key, $request_params, $default);
337 337
         }
338
-        return isset($request_params[ $key ])
339
-            ? $request_params[ $key ]
338
+        return isset($request_params[$key])
339
+            ? $request_params[$key]
340 340
             : $default;
341 341
     }
342 342
 
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
      */
350 350
     public function unSetRequestParam($key, $unset_from_global_too = false)
351 351
     {
352
-        unset($this->request[ $key ]);
352
+        unset($this->request[$key]);
353 353
         if ($unset_from_global_too) {
354
-            unset($_REQUEST[ $key ]);
354
+            unset($_REQUEST[$key]);
355 355
         }
356 356
     }
357 357
 
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
             'REMOTE_ADDR',
386 386
         );
387 387
         foreach ($server_keys as $key) {
388
-            if (isset($this->server[ $key ])) {
389
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
388
+            if (isset($this->server[$key])) {
389
+                foreach (array_map('trim', explode(',', $this->server[$key])) as $ip) {
390 390
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
391 391
                         $visitor_ip = $ip;
392 392
                     }
Please login to merge, or discard this patch.
Indentation   +573 added lines, -573 removed lines patch added patch discarded remove patch
@@ -17,577 +17,577 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_GET parameters
22
-     *
23
-     * @var array $get
24
-     */
25
-    private $get;
26
-
27
-    /**
28
-     * $_POST parameters
29
-     *
30
-     * @var array $post
31
-     */
32
-    private $post;
33
-
34
-    /**
35
-     * $_COOKIE parameters
36
-     *
37
-     * @var array $cookie
38
-     */
39
-    private $cookie;
40
-
41
-    /**
42
-     * $_SERVER parameters
43
-     *
44
-     * @var array $server
45
-     */
46
-    private $server;
47
-
48
-    /**
49
-     * $_REQUEST parameters
50
-     *
51
-     * @var array $request
52
-     */
53
-    private $request;
54
-
55
-    /**
56
-     * @var RequestTypeContextCheckerInterface
57
-     */
58
-    private $request_type;
59
-
60
-    /**
61
-     * IP address for request
62
-     *
63
-     * @var string $ip_address
64
-     */
65
-    private $ip_address;
66
-
67
-    /**
68
-     * @var string $user_agent
69
-     */
70
-    private $user_agent;
71
-
72
-    /**
73
-     * true if current user appears to be some kind of bot
74
-     *
75
-     * @var bool $is_bot
76
-     */
77
-    private $is_bot;
78
-
79
-
80
-    /**
81
-     * @param array $get
82
-     * @param array $post
83
-     * @param array $cookie
84
-     * @param array $server
85
-     */
86
-    public function __construct(array $get, array $post, array $cookie, array $server)
87
-    {
88
-        // grab request vars
89
-        $this->get = $get;
90
-        $this->post = $post;
91
-        $this->cookie = $cookie;
92
-        $this->server = $server;
93
-        $this->request = array_merge($this->get, $this->post);
94
-        $this->ip_address = $this->visitorIp();
95
-    }
96
-
97
-
98
-    /**
99
-     * @param RequestTypeContextCheckerInterface $type
100
-     */
101
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
102
-    {
103
-        $this->request_type = $type;
104
-    }
105
-
106
-
107
-    /**
108
-     * @return array
109
-     */
110
-    public function getParams()
111
-    {
112
-        return $this->get;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return array
118
-     */
119
-    public function postParams()
120
-    {
121
-        return $this->post;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return array
127
-     */
128
-    public function cookieParams()
129
-    {
130
-        return $this->cookie;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return array
136
-     */
137
-    public function serverParams()
138
-    {
139
-        return $this->server;
140
-    }
141
-
142
-
143
-    /**
144
-     * returns contents of $_REQUEST
145
-     *
146
-     * @return array
147
-     */
148
-    public function requestParams()
149
-    {
150
-        return $this->request;
151
-    }
152
-
153
-
154
-    /**
155
-     * @param      $key
156
-     * @param      $value
157
-     * @param bool $override_ee
158
-     * @return    void
159
-     */
160
-    public function setRequestParam($key, $value, $override_ee = false)
161
-    {
162
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
163
-        if ($key !== 'ee'
164
-            || ($key === 'ee' && empty($this->request['ee']))
165
-            || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
166
-        ) {
167
-            $this->request[ $key ] = $value;
168
-        }
169
-    }
170
-
171
-
172
-    /**
173
-     * returns   the value for a request param if the given key exists
174
-     *
175
-     * @param       $key
176
-     * @param null  $default
177
-     * @return mixed
178
-     */
179
-    public function getRequestParam($key, $default = null)
180
-    {
181
-        return $this->requestParameterDrillDown($key, $default, 'get');
182
-    }
183
-
184
-
185
-    /**
186
-     * check if param exists
187
-     *
188
-     * @param       $key
189
-     * @return bool
190
-     */
191
-    public function requestParamIsSet($key)
192
-    {
193
-        return $this->requestParameterDrillDown($key);
194
-    }
195
-
196
-
197
-    /**
198
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
199
-     * and return the value for the first match found
200
-     * wildcards can be either of the following:
201
-     *      ? to represent a single character of any type
202
-     *      * to represent one or more characters of any type
203
-     *
204
-     * @param string     $pattern
205
-     * @param null|mixed $default
206
-     * @return false|int
207
-     */
208
-    public function getMatch($pattern, $default = null)
209
-    {
210
-        return $this->requestParameterDrillDown($pattern, $default, 'match');
211
-    }
212
-
213
-
214
-    /**
215
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
216
-     * wildcards can be either of the following:
217
-     *      ? to represent a single character of any type
218
-     *      * to represent one or more characters of any type
219
-     * returns true if a match is found or false if not
220
-     *
221
-     * @param string $pattern
222
-     * @return false|int
223
-     */
224
-    public function matches($pattern)
225
-    {
226
-        return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
227
-    }
228
-
229
-
230
-    /**
231
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
232
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
233
-     *                                      and used to search through the current request's parameter keys
234
-     * @param array  $request_params        The array of request parameters to search through
235
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
236
-     *                                      Default is null
237
-     * @param string $return                [optional] Controls what kind of value is returned.
238
-     *                                      Options are:
239
-     *                                      'bool' will return true or false if match is found or not
240
-     *                                      'key' will return the first key found that matches the supplied pattern
241
-     *                                      'value' will return the value for the first request parameter
242
-     *                                      whose key matches the supplied pattern
243
-     *                                      Default is 'value'
244
-     * @return boolean|string
245
-     */
246
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
247
-    {
248
-        $return = in_array($return, array('bool', 'key', 'value'), true)
249
-            ? $return
250
-            : 'is_set';
251
-        // replace wildcard chars with regex chars
252
-        $pattern = str_replace(
253
-            array("\*", "\?"),
254
-            array('.*', '.'),
255
-            preg_quote($pattern, '/')
256
-        );
257
-        foreach ($request_params as $key => $request_param) {
258
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
259
-                // return value for request param
260
-                if ($return === 'value') {
261
-                    return $request_params[ $key ];
262
-                }
263
-                // or actual key or true just to indicate it was found
264
-                return $return === 'key' ? $key : true;
265
-            }
266
-        }
267
-        // match not found so return default value or false
268
-        return $return === 'value' ? $default : false;
269
-    }
270
-
271
-
272
-    /**
273
-     * the supplied key can be a simple string to represent a "top-level" request parameter
274
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
275
-     * by using square brackets to surround keys for deeper array elements.
276
-     * For example :
277
-     * if the supplied $key was: "first[second][third]"
278
-     * then this will attempt to drill down into the request parameter array to find a value.
279
-     * Given the following request parameters:
280
-     *  array(
281
-     *      'first' => array(
282
-     *          'second' => array(
283
-     *              'third' => 'has a value'
284
-     *          )
285
-     *      )
286
-     *  )
287
-     * would return true if default parameters were set
288
-     *
289
-     * @param string $callback
290
-     * @param        $key
291
-     * @param null   $default
292
-     * @param array  $request_params
293
-     * @return bool|mixed|null
294
-     */
295
-    private function requestParameterDrillDown(
296
-        $key,
297
-        $default = null,
298
-        $callback = 'is_set',
299
-        array $request_params = array()
300
-    ) {
301
-        $callback = in_array($callback, array('is_set', 'get', 'match'), true)
302
-            ? $callback
303
-            : 'is_set';
304
-        $request_params = ! empty($request_params)
305
-            ? $request_params
306
-            : $this->request;
307
-        // does incoming key represent an array like 'first[second][third]'  ?
308
-        if (strpos($key, '[') !== false) {
309
-            // turn it into an actual array
310
-            $key = str_replace(']', '', $key);
311
-            $keys = explode('[', $key);
312
-            $key = array_shift($keys);
313
-            if ($callback === 'match') {
314
-                $real_key = $this->match($key, $request_params, $default, 'key');
315
-                $key = $real_key ? $real_key : $key;
316
-            }
317
-            // check if top level key exists
318
-            if (isset($request_params[ $key ])) {
319
-                // build a new key to pass along like: 'second[third]'
320
-                // or just 'second' depending on depth of keys
321
-                $key_string = array_shift($keys);
322
-                if (! empty($keys)) {
323
-                    $key_string .= '[' . implode('][', $keys) . ']';
324
-                }
325
-                return $this->requestParameterDrillDown(
326
-                    $key_string,
327
-                    $default,
328
-                    $callback,
329
-                    $request_params[ $key ]
330
-                );
331
-            }
332
-        }
333
-        if ($callback === 'is_set') {
334
-            return isset($request_params[ $key ]);
335
-        }
336
-        if ($callback === 'match') {
337
-            return $this->match($key, $request_params, $default);
338
-        }
339
-        return isset($request_params[ $key ])
340
-            ? $request_params[ $key ]
341
-            : $default;
342
-    }
343
-
344
-
345
-    /**
346
-     * remove param
347
-     *
348
-     * @param      $key
349
-     * @param bool $unset_from_global_too
350
-     */
351
-    public function unSetRequestParam($key, $unset_from_global_too = false)
352
-    {
353
-        unset($this->request[ $key ]);
354
-        if ($unset_from_global_too) {
355
-            unset($_REQUEST[ $key ]);
356
-        }
357
-    }
358
-
359
-
360
-    /**
361
-     * @return string
362
-     */
363
-    public function ipAddress()
364
-    {
365
-        return $this->ip_address;
366
-    }
367
-
368
-
369
-    /**
370
-     * attempt to get IP address of current visitor from server
371
-     * plz see: http://stackoverflow.com/a/2031935/1475279
372
-     *
373
-     * @access public
374
-     * @return string
375
-     */
376
-    private function visitorIp()
377
-    {
378
-        $visitor_ip = '0.0.0.0';
379
-        $server_keys = array(
380
-            'HTTP_CLIENT_IP',
381
-            'HTTP_X_FORWARDED_FOR',
382
-            'HTTP_X_FORWARDED',
383
-            'HTTP_X_CLUSTER_CLIENT_IP',
384
-            'HTTP_FORWARDED_FOR',
385
-            'HTTP_FORWARDED',
386
-            'REMOTE_ADDR',
387
-        );
388
-        foreach ($server_keys as $key) {
389
-            if (isset($this->server[ $key ])) {
390
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
391
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
392
-                        $visitor_ip = $ip;
393
-                    }
394
-                }
395
-            }
396
-        }
397
-        return $visitor_ip;
398
-    }
399
-
400
-
401
-    /**
402
-     * @return string
403
-     */
404
-    public function requestUri()
405
-    {
406
-        $request_uri = filter_input(
407
-            INPUT_SERVER,
408
-            'REQUEST_URI',
409
-            FILTER_SANITIZE_URL,
410
-            FILTER_NULL_ON_FAILURE
411
-        );
412
-        if (empty($request_uri)) {
413
-            // fallback sanitization if the above fails
414
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
415
-        }
416
-        return $request_uri;
417
-    }
418
-
419
-
420
-    /**
421
-     * @return string
422
-     */
423
-    public function userAgent()
424
-    {
425
-        return $this->user_agent;
426
-    }
427
-
428
-
429
-    /**
430
-     * @param string $user_agent
431
-     */
432
-    public function setUserAgent($user_agent = '')
433
-    {
434
-        if ($user_agent === '' || ! is_string($user_agent)) {
435
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
436
-        }
437
-        $this->user_agent = $user_agent;
438
-    }
439
-
440
-
441
-    /**
442
-     * @return bool
443
-     */
444
-    public function isBot()
445
-    {
446
-        return $this->is_bot;
447
-    }
448
-
449
-
450
-    /**
451
-     * @param bool $is_bot
452
-     */
453
-    public function setIsBot($is_bot)
454
-    {
455
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
456
-    }
457
-
458
-
459
-    /**
460
-     * @return bool
461
-     */
462
-    public function isActivation()
463
-    {
464
-        return $this->request_type->isActivation();
465
-    }
466
-
467
-
468
-    /**
469
-     * @param $is_activation
470
-     * @return bool
471
-     */
472
-    public function setIsActivation($is_activation)
473
-    {
474
-        return $this->request_type->setIsActivation($is_activation);
475
-    }
476
-
477
-
478
-    /**
479
-     * @return bool
480
-     */
481
-    public function isAdmin()
482
-    {
483
-        return $this->request_type->isAdmin();
484
-    }
485
-
486
-
487
-    /**
488
-     * @return bool
489
-     */
490
-    public function isAdminAjax()
491
-    {
492
-        return $this->request_type->isAdminAjax();
493
-    }
494
-
495
-
496
-    /**
497
-     * @return bool
498
-     */
499
-    public function isAjax()
500
-    {
501
-        return $this->request_type->isAjax();
502
-    }
503
-
504
-
505
-    /**
506
-     * @return bool
507
-     */
508
-    public function isEeAjax()
509
-    {
510
-        return $this->request_type->isEeAjax();
511
-    }
512
-
513
-
514
-    /**
515
-     * @return bool
516
-     */
517
-    public function isOtherAjax()
518
-    {
519
-        return $this->request_type->isOtherAjax();
520
-    }
521
-
522
-
523
-    /**
524
-     * @return bool
525
-     */
526
-    public function isApi()
527
-    {
528
-        return $this->request_type->isApi();
529
-    }
530
-
531
-
532
-    /**
533
-     * @return bool
534
-     */
535
-    public function isCli()
536
-    {
537
-        return $this->request_type->isCli();
538
-    }
539
-
540
-
541
-    /**
542
-     * @return bool
543
-     */
544
-    public function isCron()
545
-    {
546
-        return $this->request_type->isCron();
547
-    }
548
-
549
-
550
-    /**
551
-     * @return bool
552
-     */
553
-    public function isFeed()
554
-    {
555
-        return $this->request_type->isFeed();
556
-    }
557
-
558
-
559
-    /**
560
-     * @return bool
561
-     */
562
-    public function isFrontend()
563
-    {
564
-        return $this->request_type->isFrontend();
565
-    }
566
-
567
-
568
-    /**
569
-     * @return bool
570
-     */
571
-    public function isFrontAjax()
572
-    {
573
-        return $this->request_type->isFrontAjax();
574
-    }
575
-
576
-
577
-    /**
578
-     * @return bool
579
-     */
580
-    public function isIframe()
581
-    {
582
-        return $this->request_type->isIframe();
583
-    }
584
-
585
-
586
-    /**
587
-     * @return string
588
-     */
589
-    public function slug()
590
-    {
591
-        return $this->request_type->slug();
592
-    }
20
+	/**
21
+	 * $_GET parameters
22
+	 *
23
+	 * @var array $get
24
+	 */
25
+	private $get;
26
+
27
+	/**
28
+	 * $_POST parameters
29
+	 *
30
+	 * @var array $post
31
+	 */
32
+	private $post;
33
+
34
+	/**
35
+	 * $_COOKIE parameters
36
+	 *
37
+	 * @var array $cookie
38
+	 */
39
+	private $cookie;
40
+
41
+	/**
42
+	 * $_SERVER parameters
43
+	 *
44
+	 * @var array $server
45
+	 */
46
+	private $server;
47
+
48
+	/**
49
+	 * $_REQUEST parameters
50
+	 *
51
+	 * @var array $request
52
+	 */
53
+	private $request;
54
+
55
+	/**
56
+	 * @var RequestTypeContextCheckerInterface
57
+	 */
58
+	private $request_type;
59
+
60
+	/**
61
+	 * IP address for request
62
+	 *
63
+	 * @var string $ip_address
64
+	 */
65
+	private $ip_address;
66
+
67
+	/**
68
+	 * @var string $user_agent
69
+	 */
70
+	private $user_agent;
71
+
72
+	/**
73
+	 * true if current user appears to be some kind of bot
74
+	 *
75
+	 * @var bool $is_bot
76
+	 */
77
+	private $is_bot;
78
+
79
+
80
+	/**
81
+	 * @param array $get
82
+	 * @param array $post
83
+	 * @param array $cookie
84
+	 * @param array $server
85
+	 */
86
+	public function __construct(array $get, array $post, array $cookie, array $server)
87
+	{
88
+		// grab request vars
89
+		$this->get = $get;
90
+		$this->post = $post;
91
+		$this->cookie = $cookie;
92
+		$this->server = $server;
93
+		$this->request = array_merge($this->get, $this->post);
94
+		$this->ip_address = $this->visitorIp();
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param RequestTypeContextCheckerInterface $type
100
+	 */
101
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
102
+	{
103
+		$this->request_type = $type;
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function getParams()
111
+	{
112
+		return $this->get;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return array
118
+	 */
119
+	public function postParams()
120
+	{
121
+		return $this->post;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function cookieParams()
129
+	{
130
+		return $this->cookie;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return array
136
+	 */
137
+	public function serverParams()
138
+	{
139
+		return $this->server;
140
+	}
141
+
142
+
143
+	/**
144
+	 * returns contents of $_REQUEST
145
+	 *
146
+	 * @return array
147
+	 */
148
+	public function requestParams()
149
+	{
150
+		return $this->request;
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param      $key
156
+	 * @param      $value
157
+	 * @param bool $override_ee
158
+	 * @return    void
159
+	 */
160
+	public function setRequestParam($key, $value, $override_ee = false)
161
+	{
162
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
163
+		if ($key !== 'ee'
164
+			|| ($key === 'ee' && empty($this->request['ee']))
165
+			|| ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
166
+		) {
167
+			$this->request[ $key ] = $value;
168
+		}
169
+	}
170
+
171
+
172
+	/**
173
+	 * returns   the value for a request param if the given key exists
174
+	 *
175
+	 * @param       $key
176
+	 * @param null  $default
177
+	 * @return mixed
178
+	 */
179
+	public function getRequestParam($key, $default = null)
180
+	{
181
+		return $this->requestParameterDrillDown($key, $default, 'get');
182
+	}
183
+
184
+
185
+	/**
186
+	 * check if param exists
187
+	 *
188
+	 * @param       $key
189
+	 * @return bool
190
+	 */
191
+	public function requestParamIsSet($key)
192
+	{
193
+		return $this->requestParameterDrillDown($key);
194
+	}
195
+
196
+
197
+	/**
198
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
199
+	 * and return the value for the first match found
200
+	 * wildcards can be either of the following:
201
+	 *      ? to represent a single character of any type
202
+	 *      * to represent one or more characters of any type
203
+	 *
204
+	 * @param string     $pattern
205
+	 * @param null|mixed $default
206
+	 * @return false|int
207
+	 */
208
+	public function getMatch($pattern, $default = null)
209
+	{
210
+		return $this->requestParameterDrillDown($pattern, $default, 'match');
211
+	}
212
+
213
+
214
+	/**
215
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
216
+	 * wildcards can be either of the following:
217
+	 *      ? to represent a single character of any type
218
+	 *      * to represent one or more characters of any type
219
+	 * returns true if a match is found or false if not
220
+	 *
221
+	 * @param string $pattern
222
+	 * @return false|int
223
+	 */
224
+	public function matches($pattern)
225
+	{
226
+		return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
227
+	}
228
+
229
+
230
+	/**
231
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
232
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
233
+	 *                                      and used to search through the current request's parameter keys
234
+	 * @param array  $request_params        The array of request parameters to search through
235
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
236
+	 *                                      Default is null
237
+	 * @param string $return                [optional] Controls what kind of value is returned.
238
+	 *                                      Options are:
239
+	 *                                      'bool' will return true or false if match is found or not
240
+	 *                                      'key' will return the first key found that matches the supplied pattern
241
+	 *                                      'value' will return the value for the first request parameter
242
+	 *                                      whose key matches the supplied pattern
243
+	 *                                      Default is 'value'
244
+	 * @return boolean|string
245
+	 */
246
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
247
+	{
248
+		$return = in_array($return, array('bool', 'key', 'value'), true)
249
+			? $return
250
+			: 'is_set';
251
+		// replace wildcard chars with regex chars
252
+		$pattern = str_replace(
253
+			array("\*", "\?"),
254
+			array('.*', '.'),
255
+			preg_quote($pattern, '/')
256
+		);
257
+		foreach ($request_params as $key => $request_param) {
258
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
259
+				// return value for request param
260
+				if ($return === 'value') {
261
+					return $request_params[ $key ];
262
+				}
263
+				// or actual key or true just to indicate it was found
264
+				return $return === 'key' ? $key : true;
265
+			}
266
+		}
267
+		// match not found so return default value or false
268
+		return $return === 'value' ? $default : false;
269
+	}
270
+
271
+
272
+	/**
273
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
274
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
275
+	 * by using square brackets to surround keys for deeper array elements.
276
+	 * For example :
277
+	 * if the supplied $key was: "first[second][third]"
278
+	 * then this will attempt to drill down into the request parameter array to find a value.
279
+	 * Given the following request parameters:
280
+	 *  array(
281
+	 *      'first' => array(
282
+	 *          'second' => array(
283
+	 *              'third' => 'has a value'
284
+	 *          )
285
+	 *      )
286
+	 *  )
287
+	 * would return true if default parameters were set
288
+	 *
289
+	 * @param string $callback
290
+	 * @param        $key
291
+	 * @param null   $default
292
+	 * @param array  $request_params
293
+	 * @return bool|mixed|null
294
+	 */
295
+	private function requestParameterDrillDown(
296
+		$key,
297
+		$default = null,
298
+		$callback = 'is_set',
299
+		array $request_params = array()
300
+	) {
301
+		$callback = in_array($callback, array('is_set', 'get', 'match'), true)
302
+			? $callback
303
+			: 'is_set';
304
+		$request_params = ! empty($request_params)
305
+			? $request_params
306
+			: $this->request;
307
+		// does incoming key represent an array like 'first[second][third]'  ?
308
+		if (strpos($key, '[') !== false) {
309
+			// turn it into an actual array
310
+			$key = str_replace(']', '', $key);
311
+			$keys = explode('[', $key);
312
+			$key = array_shift($keys);
313
+			if ($callback === 'match') {
314
+				$real_key = $this->match($key, $request_params, $default, 'key');
315
+				$key = $real_key ? $real_key : $key;
316
+			}
317
+			// check if top level key exists
318
+			if (isset($request_params[ $key ])) {
319
+				// build a new key to pass along like: 'second[third]'
320
+				// or just 'second' depending on depth of keys
321
+				$key_string = array_shift($keys);
322
+				if (! empty($keys)) {
323
+					$key_string .= '[' . implode('][', $keys) . ']';
324
+				}
325
+				return $this->requestParameterDrillDown(
326
+					$key_string,
327
+					$default,
328
+					$callback,
329
+					$request_params[ $key ]
330
+				);
331
+			}
332
+		}
333
+		if ($callback === 'is_set') {
334
+			return isset($request_params[ $key ]);
335
+		}
336
+		if ($callback === 'match') {
337
+			return $this->match($key, $request_params, $default);
338
+		}
339
+		return isset($request_params[ $key ])
340
+			? $request_params[ $key ]
341
+			: $default;
342
+	}
343
+
344
+
345
+	/**
346
+	 * remove param
347
+	 *
348
+	 * @param      $key
349
+	 * @param bool $unset_from_global_too
350
+	 */
351
+	public function unSetRequestParam($key, $unset_from_global_too = false)
352
+	{
353
+		unset($this->request[ $key ]);
354
+		if ($unset_from_global_too) {
355
+			unset($_REQUEST[ $key ]);
356
+		}
357
+	}
358
+
359
+
360
+	/**
361
+	 * @return string
362
+	 */
363
+	public function ipAddress()
364
+	{
365
+		return $this->ip_address;
366
+	}
367
+
368
+
369
+	/**
370
+	 * attempt to get IP address of current visitor from server
371
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
372
+	 *
373
+	 * @access public
374
+	 * @return string
375
+	 */
376
+	private function visitorIp()
377
+	{
378
+		$visitor_ip = '0.0.0.0';
379
+		$server_keys = array(
380
+			'HTTP_CLIENT_IP',
381
+			'HTTP_X_FORWARDED_FOR',
382
+			'HTTP_X_FORWARDED',
383
+			'HTTP_X_CLUSTER_CLIENT_IP',
384
+			'HTTP_FORWARDED_FOR',
385
+			'HTTP_FORWARDED',
386
+			'REMOTE_ADDR',
387
+		);
388
+		foreach ($server_keys as $key) {
389
+			if (isset($this->server[ $key ])) {
390
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
391
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
392
+						$visitor_ip = $ip;
393
+					}
394
+				}
395
+			}
396
+		}
397
+		return $visitor_ip;
398
+	}
399
+
400
+
401
+	/**
402
+	 * @return string
403
+	 */
404
+	public function requestUri()
405
+	{
406
+		$request_uri = filter_input(
407
+			INPUT_SERVER,
408
+			'REQUEST_URI',
409
+			FILTER_SANITIZE_URL,
410
+			FILTER_NULL_ON_FAILURE
411
+		);
412
+		if (empty($request_uri)) {
413
+			// fallback sanitization if the above fails
414
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
415
+		}
416
+		return $request_uri;
417
+	}
418
+
419
+
420
+	/**
421
+	 * @return string
422
+	 */
423
+	public function userAgent()
424
+	{
425
+		return $this->user_agent;
426
+	}
427
+
428
+
429
+	/**
430
+	 * @param string $user_agent
431
+	 */
432
+	public function setUserAgent($user_agent = '')
433
+	{
434
+		if ($user_agent === '' || ! is_string($user_agent)) {
435
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
436
+		}
437
+		$this->user_agent = $user_agent;
438
+	}
439
+
440
+
441
+	/**
442
+	 * @return bool
443
+	 */
444
+	public function isBot()
445
+	{
446
+		return $this->is_bot;
447
+	}
448
+
449
+
450
+	/**
451
+	 * @param bool $is_bot
452
+	 */
453
+	public function setIsBot($is_bot)
454
+	{
455
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
456
+	}
457
+
458
+
459
+	/**
460
+	 * @return bool
461
+	 */
462
+	public function isActivation()
463
+	{
464
+		return $this->request_type->isActivation();
465
+	}
466
+
467
+
468
+	/**
469
+	 * @param $is_activation
470
+	 * @return bool
471
+	 */
472
+	public function setIsActivation($is_activation)
473
+	{
474
+		return $this->request_type->setIsActivation($is_activation);
475
+	}
476
+
477
+
478
+	/**
479
+	 * @return bool
480
+	 */
481
+	public function isAdmin()
482
+	{
483
+		return $this->request_type->isAdmin();
484
+	}
485
+
486
+
487
+	/**
488
+	 * @return bool
489
+	 */
490
+	public function isAdminAjax()
491
+	{
492
+		return $this->request_type->isAdminAjax();
493
+	}
494
+
495
+
496
+	/**
497
+	 * @return bool
498
+	 */
499
+	public function isAjax()
500
+	{
501
+		return $this->request_type->isAjax();
502
+	}
503
+
504
+
505
+	/**
506
+	 * @return bool
507
+	 */
508
+	public function isEeAjax()
509
+	{
510
+		return $this->request_type->isEeAjax();
511
+	}
512
+
513
+
514
+	/**
515
+	 * @return bool
516
+	 */
517
+	public function isOtherAjax()
518
+	{
519
+		return $this->request_type->isOtherAjax();
520
+	}
521
+
522
+
523
+	/**
524
+	 * @return bool
525
+	 */
526
+	public function isApi()
527
+	{
528
+		return $this->request_type->isApi();
529
+	}
530
+
531
+
532
+	/**
533
+	 * @return bool
534
+	 */
535
+	public function isCli()
536
+	{
537
+		return $this->request_type->isCli();
538
+	}
539
+
540
+
541
+	/**
542
+	 * @return bool
543
+	 */
544
+	public function isCron()
545
+	{
546
+		return $this->request_type->isCron();
547
+	}
548
+
549
+
550
+	/**
551
+	 * @return bool
552
+	 */
553
+	public function isFeed()
554
+	{
555
+		return $this->request_type->isFeed();
556
+	}
557
+
558
+
559
+	/**
560
+	 * @return bool
561
+	 */
562
+	public function isFrontend()
563
+	{
564
+		return $this->request_type->isFrontend();
565
+	}
566
+
567
+
568
+	/**
569
+	 * @return bool
570
+	 */
571
+	public function isFrontAjax()
572
+	{
573
+		return $this->request_type->isFrontAjax();
574
+	}
575
+
576
+
577
+	/**
578
+	 * @return bool
579
+	 */
580
+	public function isIframe()
581
+	{
582
+		return $this->request_type->isIframe();
583
+	}
584
+
585
+
586
+	/**
587
+	 * @return string
588
+	 */
589
+	public function slug()
590
+	{
591
+		return $this->request_type->slug();
592
+	}
593 593
 }
Please login to merge, or discard this patch.