Completed
Branch BUG/11294/expired-cart-ticket-... (34806b)
by
unknown
28:42 queued 14:59
created
core/EE_Module_Request_Router.core.php 1 patch
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -17,256 +17,256 @@
 block discarded – undo
17 17
 final class EE_Module_Request_Router implements InterminableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Request $request
22
-     */
23
-    private $request;
20
+	/**
21
+	 * @var EE_Request $request
22
+	 */
23
+	private $request;
24 24
 
25
-    /**
26
-     * @var array $_previous_routes
27
-     */
28
-    private static $_previous_routes = array();
25
+	/**
26
+	 * @var array $_previous_routes
27
+	 */
28
+	private static $_previous_routes = array();
29 29
 
30
-    /**
31
-     * @var WP_Query $WP_Query
32
-     */
33
-    public $WP_Query;
30
+	/**
31
+	 * @var WP_Query $WP_Query
32
+	 */
33
+	public $WP_Query;
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * EE_Module_Request_Router constructor.
39
-     *
40
-     * @param EE_Request $request
41
-     */
42
-    public function __construct(EE_Request $request)
43
-    {
44
-        $this->request = $request;
45
-    }
37
+	/**
38
+	 * EE_Module_Request_Router constructor.
39
+	 *
40
+	 * @param EE_Request $request
41
+	 */
42
+	public function __construct(EE_Request $request)
43
+	{
44
+		$this->request = $request;
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * on the first call  to this method, it checks the EE_Request_Handler for a "route"
51
-     * on subsequent calls to this method,
52
-     * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
53
-     * and checks if the last called route has any forwarding routes registered for it
54
-     *
55
-     * @param WP_Query $WP_Query
56
-     * @return NULL|string
57
-     * @throws EE_Error
58
-     * @throws ReflectionException
59
-     */
60
-    public function get_route(WP_Query $WP_Query)
61
-    {
62
-        $this->WP_Query = $WP_Query;
63
-        // assume this if first route being called
64
-        $previous_route = false;
65
-        // but is it really ???
66
-        if (! empty(self::$_previous_routes)) {
67
-            // get last run route
68
-            $previous_routes = array_values(self::$_previous_routes);
69
-            $previous_route = array_pop($previous_routes);
70
-        }
71
-        //  has another route already been run ?
72
-        if ($previous_route) {
73
-            // check if  forwarding has been set
74
-            $current_route = $this->get_forward($previous_route);
75
-            try {
76
-                //check for recursive forwarding
77
-                if (isset(self::$_previous_routes[$current_route])) {
78
-                    throw new EE_Error(
79
-                        sprintf(
80
-                            __(
81
-                                'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
82
-                                'event_espresso'
83
-                            ),
84
-                            $current_route
85
-                        )
86
-                    );
87
-                }
88
-            } catch (EE_Error $e) {
89
-                $e->get_error();
90
-                return null;
91
-            }
92
-        } else {
93
-            // first route called
94
-            $current_route = null;
95
-            // grab all routes
96
-            $routes = EE_Config::get_routes();
97
-            foreach ($routes as $key => $route) {
98
-                // first determine if route key uses w?ldc*rds
99
-                $uses_wildcards = strpos($key, '?') !== false
100
-                                  || strpos($key, '*') !== false;
101
-                // check request for module route
102
-                $route_found = $uses_wildcards
103
-                    ? $this->request->matches($key)
104
-                    : $this->request->is_set($key);
105
-                if ($route_found) {
106
-                    $current_route = $uses_wildcards
107
-                        ? $this->request->getMatch($key)
108
-                        : $this->request->get($key);
109
-                    $current_route = sanitize_text_field($current_route);
110
-                    if ($current_route) {
111
-                        $current_route = array($key, $current_route);
112
-                        break;
113
-                    }
114
-                }
115
-            }
116
-        }
117
-        // sorry, but I can't read what you route !
118
-        if (empty($current_route)) {
119
-            return null;
120
-        }
121
-        //add route to previous routes array
122
-        self::$_previous_routes[] = $current_route;
123
-        return $current_route;
124
-    }
49
+	/**
50
+	 * on the first call  to this method, it checks the EE_Request_Handler for a "route"
51
+	 * on subsequent calls to this method,
52
+	 * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
53
+	 * and checks if the last called route has any forwarding routes registered for it
54
+	 *
55
+	 * @param WP_Query $WP_Query
56
+	 * @return NULL|string
57
+	 * @throws EE_Error
58
+	 * @throws ReflectionException
59
+	 */
60
+	public function get_route(WP_Query $WP_Query)
61
+	{
62
+		$this->WP_Query = $WP_Query;
63
+		// assume this if first route being called
64
+		$previous_route = false;
65
+		// but is it really ???
66
+		if (! empty(self::$_previous_routes)) {
67
+			// get last run route
68
+			$previous_routes = array_values(self::$_previous_routes);
69
+			$previous_route = array_pop($previous_routes);
70
+		}
71
+		//  has another route already been run ?
72
+		if ($previous_route) {
73
+			// check if  forwarding has been set
74
+			$current_route = $this->get_forward($previous_route);
75
+			try {
76
+				//check for recursive forwarding
77
+				if (isset(self::$_previous_routes[$current_route])) {
78
+					throw new EE_Error(
79
+						sprintf(
80
+							__(
81
+								'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
82
+								'event_espresso'
83
+							),
84
+							$current_route
85
+						)
86
+					);
87
+				}
88
+			} catch (EE_Error $e) {
89
+				$e->get_error();
90
+				return null;
91
+			}
92
+		} else {
93
+			// first route called
94
+			$current_route = null;
95
+			// grab all routes
96
+			$routes = EE_Config::get_routes();
97
+			foreach ($routes as $key => $route) {
98
+				// first determine if route key uses w?ldc*rds
99
+				$uses_wildcards = strpos($key, '?') !== false
100
+								  || strpos($key, '*') !== false;
101
+				// check request for module route
102
+				$route_found = $uses_wildcards
103
+					? $this->request->matches($key)
104
+					: $this->request->is_set($key);
105
+				if ($route_found) {
106
+					$current_route = $uses_wildcards
107
+						? $this->request->getMatch($key)
108
+						: $this->request->get($key);
109
+					$current_route = sanitize_text_field($current_route);
110
+					if ($current_route) {
111
+						$current_route = array($key, $current_route);
112
+						break;
113
+					}
114
+				}
115
+			}
116
+		}
117
+		// sorry, but I can't read what you route !
118
+		if (empty($current_route)) {
119
+			return null;
120
+		}
121
+		//add route to previous routes array
122
+		self::$_previous_routes[] = $current_route;
123
+		return $current_route;
124
+	}
125 125
 
126 126
 
127 127
 
128
-    /**
129
-     * this method simply takes a valid route, and resolves what module class method the route points to
130
-     *
131
-     * @param string $key
132
-     * @param string $current_route
133
-     * @return mixed EED_Module | boolean
134
-     * @throws EE_Error
135
-     * @throws ReflectionException
136
-     */
137
-    public function resolve_route($key, $current_route)
138
-    {
139
-        // get module method that route has been mapped to
140
-        $module_method = EE_Config::get_route($current_route, $key);
141
-        // verify result was returned
142
-        if (empty($module_method)) {
143
-            $msg = sprintf(
144
-                __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
145
-                $current_route
146
-            );
147
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
148
-            return false;
149
-        }
150
-        // verify that result is an array
151
-        if (! is_array($module_method)) {
152
-            $msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
153
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
-            return false;
155
-        }
156
-        // grab module name
157
-        $module_name = $module_method[0];
158
-        // verify that a class method was registered properly
159
-        if (! isset($module_method[1])) {
160
-            $msg = sprintf(
161
-                __('A class method for the %s  route has not been properly registered.', 'event_espresso'),
162
-                $current_route
163
-            );
164
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
-            return false;
166
-        }
167
-        // grab method
168
-        $method = $module_method[1];
169
-        // verify that class exists
170
-        if (! class_exists($module_name)) {
171
-            $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
172
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
173
-            return false;
174
-        }
175
-        // verify that method exists
176
-        if (! method_exists($module_name, $method)) {
177
-            $msg = sprintf(
178
-                __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route
179
-            );
180
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
181
-            return false;
182
-        }
183
-        // instantiate module and call route method
184
-        return $this->_module_router($module_name, $method);
185
-    }
128
+	/**
129
+	 * this method simply takes a valid route, and resolves what module class method the route points to
130
+	 *
131
+	 * @param string $key
132
+	 * @param string $current_route
133
+	 * @return mixed EED_Module | boolean
134
+	 * @throws EE_Error
135
+	 * @throws ReflectionException
136
+	 */
137
+	public function resolve_route($key, $current_route)
138
+	{
139
+		// get module method that route has been mapped to
140
+		$module_method = EE_Config::get_route($current_route, $key);
141
+		// verify result was returned
142
+		if (empty($module_method)) {
143
+			$msg = sprintf(
144
+				__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
145
+				$current_route
146
+			);
147
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
148
+			return false;
149
+		}
150
+		// verify that result is an array
151
+		if (! is_array($module_method)) {
152
+			$msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
153
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
+			return false;
155
+		}
156
+		// grab module name
157
+		$module_name = $module_method[0];
158
+		// verify that a class method was registered properly
159
+		if (! isset($module_method[1])) {
160
+			$msg = sprintf(
161
+				__('A class method for the %s  route has not been properly registered.', 'event_espresso'),
162
+				$current_route
163
+			);
164
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
+			return false;
166
+		}
167
+		// grab method
168
+		$method = $module_method[1];
169
+		// verify that class exists
170
+		if (! class_exists($module_name)) {
171
+			$msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
172
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
173
+			return false;
174
+		}
175
+		// verify that method exists
176
+		if (! method_exists($module_name, $method)) {
177
+			$msg = sprintf(
178
+				__('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route
179
+			);
180
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
181
+			return false;
182
+		}
183
+		// instantiate module and call route method
184
+		return $this->_module_router($module_name, $method);
185
+	}
186 186
 
187 187
 
188 188
 
189
-    /**
190
-     * this method instantiates modules and calls the method that was defined when the route was registered
191
-     *
192
-     * @param string $module_name
193
-     * @return EED_Module|object|null
194
-     * @throws ReflectionException
195
-     */
196
-    public static function module_factory($module_name)
197
-    {
198
-        if ($module_name === 'EED_Module') {
199
-            EE_Error::add_error(
200
-                sprintf(
201
-                    __(
202
-                        'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
203
-                        'event_espresso'
204
-                    ), $module_name
205
-                ), __FILE__, __FUNCTION__, __LINE__
206
-            );
207
-            return null;
208
-        }
209
-        // instantiate module class
210
-        $module = new $module_name();
211
-        // ensure that class is actually a module
212
-        if (! $module instanceof EED_Module) {
213
-            EE_Error::add_error(
214
-                sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215
-                __FILE__, __FUNCTION__, __LINE__
216
-            );
217
-            return null;
218
-        }
219
-        return $module;
220
-    }
189
+	/**
190
+	 * this method instantiates modules and calls the method that was defined when the route was registered
191
+	 *
192
+	 * @param string $module_name
193
+	 * @return EED_Module|object|null
194
+	 * @throws ReflectionException
195
+	 */
196
+	public static function module_factory($module_name)
197
+	{
198
+		if ($module_name === 'EED_Module') {
199
+			EE_Error::add_error(
200
+				sprintf(
201
+					__(
202
+						'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
203
+						'event_espresso'
204
+					), $module_name
205
+				), __FILE__, __FUNCTION__, __LINE__
206
+			);
207
+			return null;
208
+		}
209
+		// instantiate module class
210
+		$module = new $module_name();
211
+		// ensure that class is actually a module
212
+		if (! $module instanceof EED_Module) {
213
+			EE_Error::add_error(
214
+				sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215
+				__FILE__, __FUNCTION__, __LINE__
216
+			);
217
+			return null;
218
+		}
219
+		return $module;
220
+	}
221 221
 
222 222
 
223 223
 
224
-    /**
225
-     * this method instantiates modules and calls the method that was defined when the route was registered
226
-     *
227
-     * @param string $module_name
228
-     * @param string $method
229
-     * @return EED_Module|null
230
-     * @throws EE_Error
231
-     * @throws ReflectionException
232
-     */
233
-    private function _module_router($module_name, $method)
234
-    {
235
-        // instantiate module class
236
-        $module = EE_Module_Request_Router::module_factory($module_name);
237
-        if ($module instanceof EED_Module) {
238
-            // and call whatever action the route was for
239
-            try {
240
-                call_user_func(array($module, $method), $this->WP_Query);
241
-            } catch (EE_Error $e) {
242
-                $e->get_error();
243
-                return null;
244
-            }
245
-        }
246
-        return $module;
247
-    }
224
+	/**
225
+	 * this method instantiates modules and calls the method that was defined when the route was registered
226
+	 *
227
+	 * @param string $module_name
228
+	 * @param string $method
229
+	 * @return EED_Module|null
230
+	 * @throws EE_Error
231
+	 * @throws ReflectionException
232
+	 */
233
+	private function _module_router($module_name, $method)
234
+	{
235
+		// instantiate module class
236
+		$module = EE_Module_Request_Router::module_factory($module_name);
237
+		if ($module instanceof EED_Module) {
238
+			// and call whatever action the route was for
239
+			try {
240
+				call_user_func(array($module, $method), $this->WP_Query);
241
+			} catch (EE_Error $e) {
242
+				$e->get_error();
243
+				return null;
244
+			}
245
+		}
246
+		return $module;
247
+	}
248 248
 
249 249
 
250 250
 
251
-    /**
252
-     * @param $current_route
253
-     * @return string
254
-     */
255
-    public function get_forward($current_route)
256
-    {
257
-        return EE_Config::get_forward($current_route);
258
-    }
251
+	/**
252
+	 * @param $current_route
253
+	 * @return string
254
+	 */
255
+	public function get_forward($current_route)
256
+	{
257
+		return EE_Config::get_forward($current_route);
258
+	}
259 259
 
260 260
 
261 261
 
262
-    /**
263
-     * @param $current_route
264
-     * @return string
265
-     */
266
-    public function get_view($current_route)
267
-    {
268
-        return EE_Config::get_view($current_route);
269
-    }
262
+	/**
263
+	 * @param $current_route
264
+	 * @return string
265
+	 */
266
+	public function get_view($current_route)
267
+	{
268
+		return EE_Config::get_view($current_route);
269
+	}
270 270
 
271 271
 
272 272
 }
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorIframe.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use ReflectionException;
12 12
 
13 13
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
14
-    exit( 'No direct script access allowed' );
14
+	exit( 'No direct script access allowed' );
15 15
 }
16 16
 
17 17
 
@@ -28,83 +28,83 @@  discard block
 block discarded – undo
28 28
 class TicketSelectorIframe extends Iframe
29 29
 {
30 30
 
31
-    /**
32
-     * TicketSelectorIframe constructor.
33
-     *
34
-     * @throws InvalidArgumentException
35
-     * @throws InvalidInterfaceException
36
-     * @throws InvalidDataTypeException
37
-     * @throws DomainException
38
-     * @throws EE_Error
39
-     * @throws ReflectionException
40
-     */
41
-    public function __construct()
42
-    {
43
-        EE_Registry::instance()->REQ->set_espresso_page( true );
44
-        /** @type \EEM_Event $EEM_Event */
45
-        $EEM_Event = EE_Registry::instance()->load_model( 'Event' );
46
-        $event = $EEM_Event->get_one_by_ID(
47
-            EE_Registry::instance()->REQ->get( 'event', 0 )
48
-        );
49
-        $ticket_selector = new DisplayTicketSelector();
50
-        $ticket_selector->setIframe( true );
51
-        parent::__construct(
52
-            esc_html__( 'Ticket Selector', 'event_espresso' ),
53
-            $ticket_selector->display( $event )
54
-        );
55
-        $this->addStylesheets(
56
-            apply_filters(
57
-                'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
58
-                array(
59
-                    'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL
60
-                                               . 'ticket_selector_embed.css?ver='
61
-                                               . EVENT_ESPRESSO_VERSION,
62
-                    'ticket_selector'       => TICKET_SELECTOR_ASSETS_URL
63
-                                               . 'ticket_selector.css?ver='
64
-                                               . EVENT_ESPRESSO_VERSION,
65
-                ),
66
-                $this
67
-            )
68
-        );
69
-        if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) {
70
-            $this->addStylesheets( array('site_theme' => '' ) );
71
-        }
72
-        $this->addScripts(
73
-            apply_filters(
74
-                'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
75
-                array(
76
-                    'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL
77
-                                                      . 'ticket_selector_iframe_embed.js?ver='
78
-                                                      . EVENT_ESPRESSO_VERSION,
79
-                ),
80
-                $this
81
-            )
82
-        );
83
-        $js_attributes = apply_filters(
84
-            'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
85
-            array(),
86
-            $this
87
-        );
88
-        if(! empty($js_attributes)) {
89
-            $this->addScriptAttributes($js_attributes);
90
-        }
91
-        $this->addLocalizedVars(
92
-            apply_filters(
93
-                'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars',
94
-                array(
95
-                    'ticket_selector_iframe' => true,
96
-                    'EEDTicketSelectorMsg'   => __(
97
-                        'Please choose at least one ticket before continuing.',
98
-                        'event_espresso'
99
-                    ),
100
-                )
101
-            )
102
-        );
103
-        do_action(
104
-            'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
105
-            $this
106
-        );
107
-    }
31
+	/**
32
+	 * TicketSelectorIframe constructor.
33
+	 *
34
+	 * @throws InvalidArgumentException
35
+	 * @throws InvalidInterfaceException
36
+	 * @throws InvalidDataTypeException
37
+	 * @throws DomainException
38
+	 * @throws EE_Error
39
+	 * @throws ReflectionException
40
+	 */
41
+	public function __construct()
42
+	{
43
+		EE_Registry::instance()->REQ->set_espresso_page( true );
44
+		/** @type \EEM_Event $EEM_Event */
45
+		$EEM_Event = EE_Registry::instance()->load_model( 'Event' );
46
+		$event = $EEM_Event->get_one_by_ID(
47
+			EE_Registry::instance()->REQ->get( 'event', 0 )
48
+		);
49
+		$ticket_selector = new DisplayTicketSelector();
50
+		$ticket_selector->setIframe( true );
51
+		parent::__construct(
52
+			esc_html__( 'Ticket Selector', 'event_espresso' ),
53
+			$ticket_selector->display( $event )
54
+		);
55
+		$this->addStylesheets(
56
+			apply_filters(
57
+				'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
58
+				array(
59
+					'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL
60
+											   . 'ticket_selector_embed.css?ver='
61
+											   . EVENT_ESPRESSO_VERSION,
62
+					'ticket_selector'       => TICKET_SELECTOR_ASSETS_URL
63
+											   . 'ticket_selector.css?ver='
64
+											   . EVENT_ESPRESSO_VERSION,
65
+				),
66
+				$this
67
+			)
68
+		);
69
+		if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) {
70
+			$this->addStylesheets( array('site_theme' => '' ) );
71
+		}
72
+		$this->addScripts(
73
+			apply_filters(
74
+				'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
75
+				array(
76
+					'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL
77
+													  . 'ticket_selector_iframe_embed.js?ver='
78
+													  . EVENT_ESPRESSO_VERSION,
79
+				),
80
+				$this
81
+			)
82
+		);
83
+		$js_attributes = apply_filters(
84
+			'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
85
+			array(),
86
+			$this
87
+		);
88
+		if(! empty($js_attributes)) {
89
+			$this->addScriptAttributes($js_attributes);
90
+		}
91
+		$this->addLocalizedVars(
92
+			apply_filters(
93
+				'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars',
94
+				array(
95
+					'ticket_selector_iframe' => true,
96
+					'EEDTicketSelectorMsg'   => __(
97
+						'Please choose at least one ticket before continuing.',
98
+						'event_espresso'
99
+					),
100
+				)
101
+			)
102
+		);
103
+		do_action(
104
+			'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
105
+			$this
106
+		);
107
+	}
108 108
 
109 109
 }
110 110
 // End of file TicketSelectorIframe.php
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
 use InvalidArgumentException;
11 11
 use ReflectionException;
12 12
 
13
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
14
-    exit( 'No direct script access allowed' );
13
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
14
+    exit('No direct script access allowed');
15 15
 }
16 16
 
17 17
 
@@ -40,17 +40,17 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function __construct()
42 42
     {
43
-        EE_Registry::instance()->REQ->set_espresso_page( true );
43
+        EE_Registry::instance()->REQ->set_espresso_page(true);
44 44
         /** @type \EEM_Event $EEM_Event */
45
-        $EEM_Event = EE_Registry::instance()->load_model( 'Event' );
45
+        $EEM_Event = EE_Registry::instance()->load_model('Event');
46 46
         $event = $EEM_Event->get_one_by_ID(
47
-            EE_Registry::instance()->REQ->get( 'event', 0 )
47
+            EE_Registry::instance()->REQ->get('event', 0)
48 48
         );
49 49
         $ticket_selector = new DisplayTicketSelector();
50
-        $ticket_selector->setIframe( true );
50
+        $ticket_selector->setIframe(true);
51 51
         parent::__construct(
52
-            esc_html__( 'Ticket Selector', 'event_espresso' ),
53
-            $ticket_selector->display( $event )
52
+            esc_html__('Ticket Selector', 'event_espresso'),
53
+            $ticket_selector->display($event)
54 54
         );
55 55
         $this->addStylesheets(
56 56
             apply_filters(
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             )
68 68
         );
69 69
         if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) {
70
-            $this->addStylesheets( array('site_theme' => '' ) );
70
+            $this->addStylesheets(array('site_theme' => ''));
71 71
         }
72 72
         $this->addScripts(
73 73
             apply_filters(
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
             array(),
86 86
             $this
87 87
         );
88
-        if(! empty($js_attributes)) {
88
+        if ( ! empty($js_attributes)) {
89 89
             $this->addScriptAttributes($js_attributes);
90 90
         }
91 91
         $this->addLocalizedVars(
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Invisible_Recaptcha_Input.input.php 2 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -19,224 +19,224 @@
 block discarded – undo
19 19
 class EE_Invisible_Recaptcha_Input extends EE_Form_Input_Base
20 20
 {
21 21
 
22
-    const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA   = 'google_invisible_recaptcha';
23
-
24
-    const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha';
25
-
26
-    /**
27
-     * @var EE_Registration_Config $config
28
-     */
29
-    private $config;
30
-
31
-    /**
32
-     * @var string $recaptcha_id
33
-     */
34
-    private $recaptcha_id;
35
-
36
-    /**
37
-     * @var string $submit_button_id
38
-     */
39
-    private $submit_button_id;
40
-
41
-
42
-    /**
43
-     * @param array                  $input_settings
44
-     * @param EE_Registration_Config $registration_config
45
-     * @throws InvalidArgumentException
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     * @throws DomainException
49
-     */
50
-    public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null)
51
-    {
52
-        $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy());
53
-        parent::__construct($input_settings);
54
-        $registration_config    = $registration_config instanceof EE_Registration_Config
55
-            ? $registration_config
56
-            : EE_Registry::instance()->CFG->registration;
57
-        $this->config           = $registration_config;
58
-        $this->recaptcha_id     = isset($input_settings['recaptcha_id'])
59
-            ? $input_settings['recaptcha_id']
60
-            : substr(spl_object_hash($this), 8, 8);
61
-        $this->submit_button_id = isset($input_settings['submit_button_id'])
62
-            ? $input_settings['submit_button_id']
63
-            : '';
64
-        if(
65
-            isset($input_settings['localized_vars'])
66
-            && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN)
67
-        ) {
68
-            $this->addIframeAssets($input_settings['localized_vars']);
69
-        } else {
70
-            $this->registerScripts();
71
-        }
72
-    }
73
-
74
-
75
-    /**
76
-     * @return bool
77
-     */
78
-    public function useCaptcha()
79
-    {
80
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
81
-    }
82
-
83
-
84
-    /**
85
-     * @return string
86
-     */
87
-    public function badge()
88
-    {
89
-        return $this->config->recaptcha_badge;
90
-    }
91
-
92
-
93
-    /**
94
-     * @return string
95
-     */
96
-    public function language()
97
-    {
98
-        return $this->config->recaptcha_language;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return string
104
-     */
105
-    public function siteKey()
106
-    {
107
-        return $this->config->recaptcha_publickey;
108
-    }
109
-
110
-
111
-    /**
112
-     * @return string
113
-     */
114
-    public function secretKey()
115
-    {
116
-        return $this->config->recaptcha_privatekey;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    public function recaptchaId()
124
-    {
125
-        return $this->recaptcha_id;
126
-    }
127
-
128
-
129
-    /**
130
-     * @return string
131
-     */
132
-    public function submitButtonId()
133
-    {
134
-        return $this->submit_button_id;
135
-    }
136
-
137
-
138
-    /**
139
-     * @param array $localized_vars
140
-     * @throws DomainException
141
-     */
142
-    private function addIframeAssets(array $localized_vars)
143
-    {
144
-        if (! $this->useCaptcha()) {
145
-            return;
146
-        }
147
-        add_filter(
148
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
149
-            function(array $iframe_assets) {
150
-                $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] =
151
-                    EED_Recaptcha_Invisible::assetsUrl()
152
-                    . 'espresso_invisible_recaptcha.js?ver='
153
-                    . EVENT_ESPRESSO_VERSION;
154
-                $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] =
155
-                    add_query_arg(
156
-                        array(
157
-                            'onload' => 'espressoLoadRecaptcha',
158
-                            'render' => 'explicit',
159
-                            'hl'     => $this->language(),
160
-                        ),
161
-                        'https://www.google.com/recaptcha/api.js?'
162
-                    );
163
-                return $iframe_assets;
164
-            }
165
-        );
166
-        add_filter(
167
-            'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
168
-            function (array $iframe_asset_attributes)
169
-            {
170
-                $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ]
171
-                    = ' async="async" defer="defer"';
172
-                return $iframe_asset_attributes;
173
-            }
174
-        );
175
-        add_action(
176
-            'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
177
-            function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars)
178
-            {
179
-                $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha');
180
-            }
181
-        );
182
-    }
183
-
184
-
185
-    /**
186
-     * @return void
187
-     */
188
-    private function registerScripts()
189
-    {
190
-        if (! $this->useCaptcha()) {
191
-            return;
192
-        }
193
-        add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
194
-        wp_register_script(
195
-            EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
196
-            EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
197
-            array('espresso_core'),
198
-            EVENT_ESPRESSO_VERSION,
199
-            true
200
-        );
201
-        wp_register_script(
202
-            EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA,
203
-            add_query_arg(
204
-                array(
205
-                    'onload' => 'espressoLoadRecaptcha',
206
-                    'render' => 'explicit',
207
-                    'hl'     => $this->language(),
208
-                ),
209
-                'https://www.google.com/recaptcha/api.js?'
210
-            ),
211
-            array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA),
212
-            false,
213
-            true
214
-        );
215
-    }
216
-
217
-
218
-    /**
219
-     * @param string $tag
220
-     * @param string $handle
221
-     * @return string
222
-     */
223
-    public function addScriptAttributes($tag, $handle)
224
-    {
225
-        if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) {
226
-            $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag);
227
-        }
228
-        return $tag;
229
-    }
230
-
231
-
232
-    /**
233
-     * Gets the HTML for displaying the label for this form input
234
-     * according to the form section's layout strategy
235
-     *
236
-     * @return string
237
-     */
238
-    public function get_html_for_label()
239
-    {
240
-        return '';
241
-    }
22
+	const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA   = 'google_invisible_recaptcha';
23
+
24
+	const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha';
25
+
26
+	/**
27
+	 * @var EE_Registration_Config $config
28
+	 */
29
+	private $config;
30
+
31
+	/**
32
+	 * @var string $recaptcha_id
33
+	 */
34
+	private $recaptcha_id;
35
+
36
+	/**
37
+	 * @var string $submit_button_id
38
+	 */
39
+	private $submit_button_id;
40
+
41
+
42
+	/**
43
+	 * @param array                  $input_settings
44
+	 * @param EE_Registration_Config $registration_config
45
+	 * @throws InvalidArgumentException
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 * @throws DomainException
49
+	 */
50
+	public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null)
51
+	{
52
+		$this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy());
53
+		parent::__construct($input_settings);
54
+		$registration_config    = $registration_config instanceof EE_Registration_Config
55
+			? $registration_config
56
+			: EE_Registry::instance()->CFG->registration;
57
+		$this->config           = $registration_config;
58
+		$this->recaptcha_id     = isset($input_settings['recaptcha_id'])
59
+			? $input_settings['recaptcha_id']
60
+			: substr(spl_object_hash($this), 8, 8);
61
+		$this->submit_button_id = isset($input_settings['submit_button_id'])
62
+			? $input_settings['submit_button_id']
63
+			: '';
64
+		if(
65
+			isset($input_settings['localized_vars'])
66
+			&& filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN)
67
+		) {
68
+			$this->addIframeAssets($input_settings['localized_vars']);
69
+		} else {
70
+			$this->registerScripts();
71
+		}
72
+	}
73
+
74
+
75
+	/**
76
+	 * @return bool
77
+	 */
78
+	public function useCaptcha()
79
+	{
80
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
81
+	}
82
+
83
+
84
+	/**
85
+	 * @return string
86
+	 */
87
+	public function badge()
88
+	{
89
+		return $this->config->recaptcha_badge;
90
+	}
91
+
92
+
93
+	/**
94
+	 * @return string
95
+	 */
96
+	public function language()
97
+	{
98
+		return $this->config->recaptcha_language;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return string
104
+	 */
105
+	public function siteKey()
106
+	{
107
+		return $this->config->recaptcha_publickey;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return string
113
+	 */
114
+	public function secretKey()
115
+	{
116
+		return $this->config->recaptcha_privatekey;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	public function recaptchaId()
124
+	{
125
+		return $this->recaptcha_id;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @return string
131
+	 */
132
+	public function submitButtonId()
133
+	{
134
+		return $this->submit_button_id;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param array $localized_vars
140
+	 * @throws DomainException
141
+	 */
142
+	private function addIframeAssets(array $localized_vars)
143
+	{
144
+		if (! $this->useCaptcha()) {
145
+			return;
146
+		}
147
+		add_filter(
148
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
149
+			function(array $iframe_assets) {
150
+				$iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] =
151
+					EED_Recaptcha_Invisible::assetsUrl()
152
+					. 'espresso_invisible_recaptcha.js?ver='
153
+					. EVENT_ESPRESSO_VERSION;
154
+				$iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] =
155
+					add_query_arg(
156
+						array(
157
+							'onload' => 'espressoLoadRecaptcha',
158
+							'render' => 'explicit',
159
+							'hl'     => $this->language(),
160
+						),
161
+						'https://www.google.com/recaptcha/api.js?'
162
+					);
163
+				return $iframe_assets;
164
+			}
165
+		);
166
+		add_filter(
167
+			'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
168
+			function (array $iframe_asset_attributes)
169
+			{
170
+				$iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ]
171
+					= ' async="async" defer="defer"';
172
+				return $iframe_asset_attributes;
173
+			}
174
+		);
175
+		add_action(
176
+			'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
177
+			function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars)
178
+			{
179
+				$ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha');
180
+			}
181
+		);
182
+	}
183
+
184
+
185
+	/**
186
+	 * @return void
187
+	 */
188
+	private function registerScripts()
189
+	{
190
+		if (! $this->useCaptcha()) {
191
+			return;
192
+		}
193
+		add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
194
+		wp_register_script(
195
+			EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
196
+			EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
197
+			array('espresso_core'),
198
+			EVENT_ESPRESSO_VERSION,
199
+			true
200
+		);
201
+		wp_register_script(
202
+			EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA,
203
+			add_query_arg(
204
+				array(
205
+					'onload' => 'espressoLoadRecaptcha',
206
+					'render' => 'explicit',
207
+					'hl'     => $this->language(),
208
+				),
209
+				'https://www.google.com/recaptcha/api.js?'
210
+			),
211
+			array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA),
212
+			false,
213
+			true
214
+		);
215
+	}
216
+
217
+
218
+	/**
219
+	 * @param string $tag
220
+	 * @param string $handle
221
+	 * @return string
222
+	 */
223
+	public function addScriptAttributes($tag, $handle)
224
+	{
225
+		if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) {
226
+			$tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag);
227
+		}
228
+		return $tag;
229
+	}
230
+
231
+
232
+	/**
233
+	 * Gets the HTML for displaying the label for this form input
234
+	 * according to the form section's layout strategy
235
+	 *
236
+	 * @return string
237
+	 */
238
+	public function get_html_for_label()
239
+	{
240
+		return '';
241
+	}
242 242
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         $this->submit_button_id = isset($input_settings['submit_button_id'])
62 62
             ? $input_settings['submit_button_id']
63 63
             : '';
64
-        if(
64
+        if (
65 65
             isset($input_settings['localized_vars'])
66 66
             && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN)
67 67
         ) {
@@ -141,17 +141,17 @@  discard block
 block discarded – undo
141 141
      */
142 142
     private function addIframeAssets(array $localized_vars)
143 143
     {
144
-        if (! $this->useCaptcha()) {
144
+        if ( ! $this->useCaptcha()) {
145 145
             return;
146 146
         }
147 147
         add_filter(
148 148
             'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
149 149
             function(array $iframe_assets) {
150
-                $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] =
150
+                $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA] =
151 151
                     EED_Recaptcha_Invisible::assetsUrl()
152 152
                     . 'espresso_invisible_recaptcha.js?ver='
153 153
                     . EVENT_ESPRESSO_VERSION;
154
-                $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] =
154
+                $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA] =
155 155
                     add_query_arg(
156 156
                         array(
157 157
                             'onload' => 'espressoLoadRecaptcha',
@@ -165,16 +165,16 @@  discard block
 block discarded – undo
165 165
         );
166 166
         add_filter(
167 167
             'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
168
-            function (array $iframe_asset_attributes)
168
+            function(array $iframe_asset_attributes)
169 169
             {
170
-                $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ]
170
+                $iframe_asset_attributes[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA]
171 171
                     = ' async="async" defer="defer"';
172 172
                 return $iframe_asset_attributes;
173 173
             }
174 174
         );
175 175
         add_action(
176 176
             'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
177
-            function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars)
177
+            function(EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars)
178 178
             {
179 179
                 $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha');
180 180
             }
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
      */
188 188
     private function registerScripts()
189 189
     {
190
-        if (! $this->useCaptcha()) {
190
+        if ( ! $this->useCaptcha()) {
191 191
             return;
192 192
         }
193 193
         add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
194 194
         wp_register_script(
195 195
             EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
196
-            EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
196
+            EED_Recaptcha_Invisible::assetsUrl().'espresso_invisible_recaptcha.js',
197 197
             array('espresso_core'),
198 198
             EVENT_ESPRESSO_VERSION,
199 199
             true
Please login to merge, or discard this patch.
core/libraries/iframe_display/iframe_wrapper.template.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -22,17 +22,17 @@  discard block
 block discarded – undo
22 22
 <html>
23 23
 <head>
24 24
 	<title><?php echo $title; ?></title>
25
-<?php if ( $enqueue_wp_assets ) : ?>
25
+<?php if ($enqueue_wp_assets) : ?>
26 26
 	<?php wp_head(); ?>
27 27
 <?php else : ?>
28
-	<?php foreach ( $css as $url ) : ?>
29
-	<link rel="stylesheet" type="text/css" href="<?php echo $url;?>">
28
+	<?php foreach ($css as $url) : ?>
29
+	<link rel="stylesheet" type="text/css" href="<?php echo $url; ?>">
30 30
 	<?php endforeach; ?>
31 31
 	<script type="text/javascript">
32 32
 		<?php echo $eei18n; ?>
33 33
 	</script>
34
-	<?php foreach ( $header_js as $key => $url ) : ?>
35
-    <?php $header_attributes = isset($header_js_attributes[ $key ]) ? $header_js_attributes[ $key ] : ''; ?>
34
+	<?php foreach ($header_js as $key => $url) : ?>
35
+    <?php $header_attributes = isset($header_js_attributes[$key]) ? $header_js_attributes[$key] : ''; ?>
36 36
     <script type="text/javascript" src="<?php echo $url; ?>"<?php echo $header_attributes; ?>></script>
37 37
 	<?php endforeach; ?>
38 38
 <?php endif; ?>
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
     <div style="padding: 1em;">
43 43
         <?php echo $content; ?>
44 44
     </div>
45
-    <?php foreach ( $footer_js as $key => $url ) : ?>
46
-        <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[ $key ] : '';  ?>
47
-		<script type="text/javascript" src="<?php echo $url; ?>"<?php echo $footer_attributes;?>></script>
45
+    <?php foreach ($footer_js as $key => $url) : ?>
46
+        <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[$key] : ''; ?>
47
+		<script type="text/javascript" src="<?php echo $url; ?>"<?php echo $footer_attributes; ?>></script>
48 48
 	<?php endforeach; ?>
49
-<?php if ( $enqueue_wp_assets ) : ?>
49
+<?php if ($enqueue_wp_assets) : ?>
50 50
 	<?php wp_footer(); ?>
51 51
 <?php endif; ?>
52 52
 </body>
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/InvisibleRecaptcha.php 2 patches
Indentation   +237 added lines, -237 removed lines patch added patch discarded remove patch
@@ -31,241 +31,241 @@
 block discarded – undo
31 31
 class InvisibleRecaptcha
32 32
 {
33 33
 
34
-    const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
35
-
36
-    const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
37
-
38
-    /**
39
-     * @var EE_Registration_Config $config
40
-     */
41
-    private $config;
42
-
43
-    /**
44
-     * @var EE_Session $session
45
-     */
46
-    private $session;
47
-
48
-    /**
49
-     * @var boolean $recaptcha_passed
50
-     */
51
-    private $recaptcha_passed;
52
-
53
-
54
-    /**
55
-     * InvisibleRecaptcha constructor.
56
-     *
57
-     * @param EE_Registration_Config $registration_config
58
-     * @param EE_Session             $session
59
-     */
60
-    public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
61
-    {
62
-        $this->config = $registration_config;
63
-        $this->session = $session;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return boolean
69
-     */
70
-    public function useInvisibleRecaptcha()
71
-    {
72
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
73
-    }
74
-
75
-
76
-    /**
77
-     * @param array $input_settings
78
-     * @return EE_Invisible_Recaptcha_Input
79
-     * @throws InvalidDataTypeException
80
-     * @throws InvalidInterfaceException
81
-     * @throws InvalidArgumentException
82
-     * @throws DomainException
83
-     */
84
-    public function getInput(array $input_settings = array())
85
-    {
86
-        return new EE_Invisible_Recaptcha_Input(
87
-            $input_settings,
88
-            $this->config
89
-        );
90
-    }
91
-
92
-
93
-    /**
94
-     * @param array $input_settings
95
-     * @return string
96
-     * @throws EE_Error
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidInterfaceException
99
-     * @throws InvalidArgumentException
100
-     * @throws DomainException
101
-     */
102
-    public function getInputHtml(array $input_settings = array())
103
-    {
104
-        return $this->getInput($input_settings)->get_html_for_input();
105
-    }
106
-
107
-
108
-    /**
109
-     * @param EE_Form_Section_Proper $form
110
-     * @param array                  $input_settings
111
-     * @throws EE_Error
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws DomainException
116
-     */
117
-    public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
118
-    {
119
-        $form->add_subsections(
120
-            array(
121
-                'espresso_recaptcha' => $this->getInput($input_settings),
122
-            ),
123
-            null,
124
-            false
125
-        );
126
-    }
127
-
128
-
129
-    /**
130
-     * @param EE_Request $request
131
-     * @return boolean
132
-     * @throws RuntimeException
133
-     */
134
-    public function verifyToken(EE_Request $request)
135
-    {
136
-        static $previous_recaptcha_response = array();
137
-        $grecaptcha_response = $request->get('g-recaptcha-response');
138
-        // if this token has already been verified, then return previous response
139
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
140
-            return $previous_recaptcha_response[ $grecaptcha_response ];
141
-        }
142
-        // will update to true if everything passes
143
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
144
-        $response                                            = wp_safe_remote_post(
145
-            InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
146
-            array(
147
-                'body' => array(
148
-                    'secret'   => $this->config->recaptcha_privatekey,
149
-                    'response' => $grecaptcha_response,
150
-                    'remoteip' => $request->ip_address(),
151
-                ),
152
-            )
153
-        );
154
-        if ($response instanceof WP_Error) {
155
-            $this->generateError($response->get_error_messages());
156
-            return false;
157
-        }
158
-        $results = json_decode(wp_remote_retrieve_body($response), true);
159
-        if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
160
-            $errors   = array_map(
161
-                array($this, 'getErrorCode'),
162
-                $results['error-codes']
163
-            );
164
-            if(isset($results['challenge_ts'])) {
165
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
166
-            }
167
-            $this->generateError(implode(' ', $errors));
168
-        }
169
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
170
-        add_action('shutdown', array($this, 'setSessionData'));
171
-        return true;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param string $error_response
177
-     * @return void
178
-     * @throws RuntimeException
179
-     */
180
-    public function generateError($error_response = '')
181
-    {
182
-        throw new RuntimeException(
183
-            sprintf(
184
-                esc_html__(
185
-                    'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
186
-                    'event_espresso'
187
-                ),
188
-                '<br />',
189
-                current_user_can('manage_options') ? $error_response : ''
190
-            )
191
-        );
192
-    }
193
-
194
-
195
-    /**
196
-     * @param string $error_code
197
-     * @return string
198
-     */
199
-    public function getErrorCode(&$error_code)
200
-    {
201
-        $error_codes = array(
202
-            'missing-input-secret'   => 'The secret parameter is missing.',
203
-            'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
204
-            'missing-input-response' => 'The response parameter is missing.',
205
-            'invalid-input-response' => 'The response parameter is invalid or malformed.',
206
-            'bad-request'            => 'The request is invalid or malformed.',
207
-            'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
208
-        );
209
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
210
-    }
211
-
212
-
213
-    /**
214
-     * @return array
215
-     * @throws InvalidInterfaceException
216
-     * @throws InvalidDataTypeException
217
-     * @throws InvalidArgumentException
218
-     */
219
-    public function getLocalizedVars()
220
-    {
221
-        return (array) apply_filters(
222
-            'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
223
-            array(
224
-                'siteKey'          => $this->config->recaptcha_publickey,
225
-                'recaptcha_passed' => $this->recaptchaPassed(),
226
-                'wp_debug'         => WP_DEBUG,
227
-                'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
228
-            )
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * @return boolean
235
-     * @throws InvalidInterfaceException
236
-     * @throws InvalidDataTypeException
237
-     * @throws InvalidArgumentException
238
-     */
239
-    public function recaptchaPassed()
240
-    {
241
-        if ($this->recaptcha_passed !== null) {
242
-            return $this->recaptcha_passed;
243
-        }
244
-        // logged in means you have already passed a turing test of sorts
245
-        if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
246
-            $this->recaptcha_passed = true;
247
-            return $this->recaptcha_passed;
248
-        }
249
-        // was test already passed?
250
-        $this->recaptcha_passed = filter_var(
251
-            $this->session->get_session_data(
252
-                InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
253
-            ),
254
-            FILTER_VALIDATE_BOOLEAN
255
-        );
256
-        return $this->recaptcha_passed;
257
-    }
258
-
259
-
260
-    /**
261
-     * @throws InvalidArgumentException
262
-     * @throws InvalidDataTypeException
263
-     * @throws InvalidInterfaceException
264
-     */
265
-    public function setSessionData()
266
-    {
267
-        $this->session->set_session_data(
268
-            array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
269
-        );
270
-    }
34
+	const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
35
+
36
+	const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
37
+
38
+	/**
39
+	 * @var EE_Registration_Config $config
40
+	 */
41
+	private $config;
42
+
43
+	/**
44
+	 * @var EE_Session $session
45
+	 */
46
+	private $session;
47
+
48
+	/**
49
+	 * @var boolean $recaptcha_passed
50
+	 */
51
+	private $recaptcha_passed;
52
+
53
+
54
+	/**
55
+	 * InvisibleRecaptcha constructor.
56
+	 *
57
+	 * @param EE_Registration_Config $registration_config
58
+	 * @param EE_Session             $session
59
+	 */
60
+	public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
61
+	{
62
+		$this->config = $registration_config;
63
+		$this->session = $session;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return boolean
69
+	 */
70
+	public function useInvisibleRecaptcha()
71
+	{
72
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param array $input_settings
78
+	 * @return EE_Invisible_Recaptcha_Input
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws InvalidInterfaceException
81
+	 * @throws InvalidArgumentException
82
+	 * @throws DomainException
83
+	 */
84
+	public function getInput(array $input_settings = array())
85
+	{
86
+		return new EE_Invisible_Recaptcha_Input(
87
+			$input_settings,
88
+			$this->config
89
+		);
90
+	}
91
+
92
+
93
+	/**
94
+	 * @param array $input_settings
95
+	 * @return string
96
+	 * @throws EE_Error
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidInterfaceException
99
+	 * @throws InvalidArgumentException
100
+	 * @throws DomainException
101
+	 */
102
+	public function getInputHtml(array $input_settings = array())
103
+	{
104
+		return $this->getInput($input_settings)->get_html_for_input();
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param EE_Form_Section_Proper $form
110
+	 * @param array                  $input_settings
111
+	 * @throws EE_Error
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws DomainException
116
+	 */
117
+	public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
118
+	{
119
+		$form->add_subsections(
120
+			array(
121
+				'espresso_recaptcha' => $this->getInput($input_settings),
122
+			),
123
+			null,
124
+			false
125
+		);
126
+	}
127
+
128
+
129
+	/**
130
+	 * @param EE_Request $request
131
+	 * @return boolean
132
+	 * @throws RuntimeException
133
+	 */
134
+	public function verifyToken(EE_Request $request)
135
+	{
136
+		static $previous_recaptcha_response = array();
137
+		$grecaptcha_response = $request->get('g-recaptcha-response');
138
+		// if this token has already been verified, then return previous response
139
+		if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
140
+			return $previous_recaptcha_response[ $grecaptcha_response ];
141
+		}
142
+		// will update to true if everything passes
143
+		$previous_recaptcha_response[ $grecaptcha_response ] = false;
144
+		$response                                            = wp_safe_remote_post(
145
+			InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
146
+			array(
147
+				'body' => array(
148
+					'secret'   => $this->config->recaptcha_privatekey,
149
+					'response' => $grecaptcha_response,
150
+					'remoteip' => $request->ip_address(),
151
+				),
152
+			)
153
+		);
154
+		if ($response instanceof WP_Error) {
155
+			$this->generateError($response->get_error_messages());
156
+			return false;
157
+		}
158
+		$results = json_decode(wp_remote_retrieve_body($response), true);
159
+		if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
160
+			$errors   = array_map(
161
+				array($this, 'getErrorCode'),
162
+				$results['error-codes']
163
+			);
164
+			if(isset($results['challenge_ts'])) {
165
+				$errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
166
+			}
167
+			$this->generateError(implode(' ', $errors));
168
+		}
169
+		$previous_recaptcha_response[ $grecaptcha_response ] = true;
170
+		add_action('shutdown', array($this, 'setSessionData'));
171
+		return true;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param string $error_response
177
+	 * @return void
178
+	 * @throws RuntimeException
179
+	 */
180
+	public function generateError($error_response = '')
181
+	{
182
+		throw new RuntimeException(
183
+			sprintf(
184
+				esc_html__(
185
+					'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
186
+					'event_espresso'
187
+				),
188
+				'<br />',
189
+				current_user_can('manage_options') ? $error_response : ''
190
+			)
191
+		);
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param string $error_code
197
+	 * @return string
198
+	 */
199
+	public function getErrorCode(&$error_code)
200
+	{
201
+		$error_codes = array(
202
+			'missing-input-secret'   => 'The secret parameter is missing.',
203
+			'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
204
+			'missing-input-response' => 'The response parameter is missing.',
205
+			'invalid-input-response' => 'The response parameter is invalid or malformed.',
206
+			'bad-request'            => 'The request is invalid or malformed.',
207
+			'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
208
+		);
209
+		return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
210
+	}
211
+
212
+
213
+	/**
214
+	 * @return array
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws InvalidDataTypeException
217
+	 * @throws InvalidArgumentException
218
+	 */
219
+	public function getLocalizedVars()
220
+	{
221
+		return (array) apply_filters(
222
+			'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
223
+			array(
224
+				'siteKey'          => $this->config->recaptcha_publickey,
225
+				'recaptcha_passed' => $this->recaptchaPassed(),
226
+				'wp_debug'         => WP_DEBUG,
227
+				'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
228
+			)
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * @return boolean
235
+	 * @throws InvalidInterfaceException
236
+	 * @throws InvalidDataTypeException
237
+	 * @throws InvalidArgumentException
238
+	 */
239
+	public function recaptchaPassed()
240
+	{
241
+		if ($this->recaptcha_passed !== null) {
242
+			return $this->recaptcha_passed;
243
+		}
244
+		// logged in means you have already passed a turing test of sorts
245
+		if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
246
+			$this->recaptcha_passed = true;
247
+			return $this->recaptcha_passed;
248
+		}
249
+		// was test already passed?
250
+		$this->recaptcha_passed = filter_var(
251
+			$this->session->get_session_data(
252
+				InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
253
+			),
254
+			FILTER_VALIDATE_BOOLEAN
255
+		);
256
+		return $this->recaptcha_passed;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @throws InvalidArgumentException
262
+	 * @throws InvalidDataTypeException
263
+	 * @throws InvalidInterfaceException
264
+	 */
265
+	public function setSessionData()
266
+	{
267
+		$this->session->set_session_data(
268
+			array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
269
+		);
270
+	}
271 271
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
         static $previous_recaptcha_response = array();
137 137
         $grecaptcha_response = $request->get('g-recaptcha-response');
138 138
         // if this token has already been verified, then return previous response
139
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
140
-            return $previous_recaptcha_response[ $grecaptcha_response ];
139
+        if (isset($previous_recaptcha_response[$grecaptcha_response])) {
140
+            return $previous_recaptcha_response[$grecaptcha_response];
141 141
         }
142 142
         // will update to true if everything passes
143
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
143
+        $previous_recaptcha_response[$grecaptcha_response] = false;
144 144
         $response                                            = wp_safe_remote_post(
145 145
             InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
146 146
             array(
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
         }
158 158
         $results = json_decode(wp_remote_retrieve_body($response), true);
159 159
         if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
160
-            $errors   = array_map(
160
+            $errors = array_map(
161 161
                 array($this, 'getErrorCode'),
162 162
                 $results['error-codes']
163 163
             );
164
-            if(isset($results['challenge_ts'])) {
165
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
164
+            if (isset($results['challenge_ts'])) {
165
+                $errors[] = 'challenge timestamp: '.$results['challenge_ts'].'.';
166 166
             }
167 167
             $this->generateError(implode(' ', $errors));
168 168
         }
169
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
169
+        $previous_recaptcha_response[$grecaptcha_response] = true;
170 170
         add_action('shutdown', array($this, 'setSessionData'));
171 171
         return true;
172 172
     }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             'bad-request'            => 'The request is invalid or malformed.',
207 207
             'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
208 208
         );
209
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
209
+        return isset($error_codes[$error_code]) ? $error_codes[$error_code] : '';
210 210
     }
211 211
 
212 212
 
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/RecaptchaFactory.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,35 +23,35 @@
 block discarded – undo
23 23
 class RecaptchaFactory implements FactoryInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @param array $arguments
28
-     * @return InvisibleRecaptcha
29
-     * @throws InvalidDataTypeException
30
-     * @throws InvalidInterfaceException
31
-     * @throws InvalidArgumentException
32
-     */
33
-    public static function create($arguments = array())
34
-    {
35
-        return LoaderFactory::getLoader()->getShared(
36
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha',
37
-            $arguments
38
-        );
39
-    }
40
-
41
-
42
-
43
-    /**
44
-     * @param array $arguments
45
-     * @return RecaptchaAdminSettings
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     * @throws InvalidArgumentException
49
-     */
50
-    public static function getAdminModule($arguments = array())
51
-    {
52
-        return LoaderFactory::getLoader()->getShared(
53
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
54
-            $arguments
55
-        );
56
-    }
26
+	/**
27
+	 * @param array $arguments
28
+	 * @return InvisibleRecaptcha
29
+	 * @throws InvalidDataTypeException
30
+	 * @throws InvalidInterfaceException
31
+	 * @throws InvalidArgumentException
32
+	 */
33
+	public static function create($arguments = array())
34
+	{
35
+		return LoaderFactory::getLoader()->getShared(
36
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha',
37
+			$arguments
38
+		);
39
+	}
40
+
41
+
42
+
43
+	/**
44
+	 * @param array $arguments
45
+	 * @return RecaptchaAdminSettings
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 * @throws InvalidArgumentException
49
+	 */
50
+	public static function getAdminModule($arguments = array())
51
+	{
52
+		return LoaderFactory::getLoader()->getShared(
53
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
54
+			$arguments
55
+		);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_SPCO_JSON_Response.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2 2
  /**
3
- *
4
- * Class EE_SPCO_JSON_Response
5
- *
6
- * Description
7
- *
8
- * @package         Event Espresso
9
- * @subpackage    core
10
- * @author				Brent Christensen
11
- *
12
- *
13
- */
3
+  *
4
+  * Class EE_SPCO_JSON_Response
5
+  *
6
+  * Description
7
+  *
8
+  * @package         Event Espresso
9
+  * @subpackage    core
10
+  * @author				Brent Christensen
11
+  *
12
+  *
13
+  */
14 14
 class EE_SPCO_JSON_Response {
15 15
 
16 16
 	/**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
 	/**
86 86
 	 *    class constructor
87
-   */
87
+	 */
88 88
 	public function __construct(  ) {
89 89
 	}
90 90
 
@@ -271,10 +271,10 @@  discard block
 block discarded – undo
271 271
 	}
272 272
 
273 273
 
274
-    /**
275
-     * @param float $payment_amount
276
-     * @throws EE_Error
277
-     */
274
+	/**
275
+	 * @param float $payment_amount
276
+	 * @throws EE_Error
277
+	 */
278 278
 	public function set_payment_amount( $payment_amount ) {
279 279
 		$this->_payment_amount = (float)$payment_amount;
280 280
 	}
@@ -408,11 +408,11 @@  discard block
 block discarded – undo
408 408
 	}
409 409
 
410 410
 
411
-    public function echoAndExit()
412
-    {
413
-        echo $this;
414
-        exit();
415
-    }
411
+	public function echoAndExit()
412
+	{
413
+		echo $this;
414
+		exit();
415
+	}
416 416
 
417 417
 }
418 418
 // End of file EE_SPCO_JSON_Response.php
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -104,71 +104,71 @@  discard block
 block discarded – undo
104 104
 	public function __toString() {
105 105
 		$JSON_response = array();
106 106
 		// grab notices
107
-		$notices = EE_Error::get_notices( FALSE );
108
-		$this->set_attention( isset( $notices['attention'] ) ? $notices['attention'] : '' );
109
-		$this->set_errors( isset( $notices['errors'] ) ? $notices['errors'] : '' );
110
-		$this->set_success( isset( $notices['success'] ) ? $notices['success'] : '' );
107
+		$notices = EE_Error::get_notices(FALSE);
108
+		$this->set_attention(isset($notices['attention']) ? $notices['attention'] : '');
109
+		$this->set_errors(isset($notices['errors']) ? $notices['errors'] : '');
110
+		$this->set_success(isset($notices['success']) ? $notices['success'] : '');
111 111
 		// add notices to JSON response, but only if they exist
112
-		if ( $this->attention() ) {
112
+		if ($this->attention()) {
113 113
 			$JSON_response['attention'] = $this->attention();
114 114
 		}
115
-		if ( $this->errors() ) {
115
+		if ($this->errors()) {
116 116
 			$JSON_response['errors'] = $this->errors();
117 117
 		}
118
-		if ( $this->unexpected_errors() ) {
118
+		if ($this->unexpected_errors()) {
119 119
 			$JSON_response['unexpected_errors'] = $this->unexpected_errors();
120 120
 		}
121
-		if ( $this->success() ) {
121
+		if ($this->success()) {
122 122
 			$JSON_response['success'] = $this->success();
123 123
 		}
124 124
 		// but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked
125
-		if ( ! isset( $JSON_response[ 'attention' ] ) && ! isset( $JSON_response[ 'errors' ] ) && ! isset( $JSON_response[ 'success' ] ) ) {
125
+		if ( ! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) {
126 126
 			$JSON_response['success'] = null;
127 127
 		}
128 128
 		// set redirect_url, IF it exists
129
-		if ( $this->redirect_url() ) {
129
+		if ($this->redirect_url()) {
130 130
 			$JSON_response['redirect_url'] = $this->redirect_url();
131 131
 		}
132 132
 		// set registration_time_limit, IF it exists
133
-		if ( $this->registration_time_limit() ) {
133
+		if ($this->registration_time_limit()) {
134 134
 			$JSON_response['registration_time_limit'] = $this->registration_time_limit();
135 135
 		}
136 136
 		// set payment_amount, IF it exists
137
-		if ( $this->payment_amount() !== null ) {
138
-			$JSON_response[ 'payment_amount' ] = $this->payment_amount();
137
+		if ($this->payment_amount() !== null) {
138
+			$JSON_response['payment_amount'] = $this->payment_amount();
139 139
 		}
140 140
 		// grab generic return data
141 141
 		$return_data = $this->return_data();
142 142
 		// add billing form validation rules
143
-		if ( $this->validation_rules() ) {
143
+		if ($this->validation_rules()) {
144 144
 			$return_data['validation_rules'] = $this->validation_rules();
145 145
 		}
146 146
 		// set reg_step_html, IF it exists
147
-		if ( $this->reg_step_html() ) {
147
+		if ($this->reg_step_html()) {
148 148
 			$return_data['reg_step_html'] = $this->reg_step_html();
149 149
 		}
150 150
 		// set method of payment, IF it exists
151
-		if ( $this->method_of_payment() ) {
151
+		if ($this->method_of_payment()) {
152 152
 			$return_data['method_of_payment'] = $this->method_of_payment();
153 153
 		}
154 154
 		// set "plz_select_method_of_payment" message, IF it exists
155
-		if ( $this->plz_select_method_of_payment() ) {
155
+		if ($this->plz_select_method_of_payment()) {
156 156
 			$return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment();
157 157
 		}
158 158
 		// set redirect_form, IF it exists
159
-		if ( $this->redirect_form() ) {
159
+		if ($this->redirect_form()) {
160 160
 			$return_data['redirect_form'] = $this->redirect_form();
161 161
 		}
162 162
 		// and finally, add return_data array to main JSON response array, IF it contains anything
163 163
 		// why did we add some of the above properties to the return data array?
164 164
 		// because it is easier and cleaner in the Javascript to deal with this way
165
-		if ( ! empty( $return_data )) {
165
+		if ( ! empty($return_data)) {
166 166
 			$JSON_response['return_data'] = $return_data;
167 167
 		}
168 168
 		// filter final array
169
-		$JSON_response = apply_filters( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response );
169
+		$JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response);
170 170
 		// return encoded array
171
-		return (string) wp_json_encode( $JSON_response );
171
+		return (string) wp_json_encode($JSON_response);
172 172
 	}
173 173
 
174 174
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	/**
177 177
 	 * @param string $attention
178 178
 	 */
179
-	public function set_attention( $attention ) {
179
+	public function set_attention($attention) {
180 180
 		$this->_attention = $attention;
181 181
 	}
182 182
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	/**
195 195
 	 * @param string $errors
196 196
 	 */
197
-	public function set_errors( $errors ) {
197
+	public function set_errors($errors) {
198 198
 		$this->_errors = $errors;
199 199
 	}
200 200
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 	/**
222 222
 	 * @param string $unexpected_errors
223 223
 	 */
224
-	public function set_unexpected_errors( $unexpected_errors ) {
224
+	public function set_unexpected_errors($unexpected_errors) {
225 225
 		$this->_unexpected_errors = $unexpected_errors;
226 226
 	}
227 227
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	/**
231 231
 	 * @param string $success
232 232
 	 */
233
-	public function set_success( $success ) {
233
+	public function set_success($success) {
234 234
 		$this->_success = $success;
235 235
 	}
236 236
 
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 	/**
249 249
 	 * @param string $method_of_payment
250 250
 	 */
251
-	public function set_method_of_payment( $method_of_payment ) {
251
+	public function set_method_of_payment($method_of_payment) {
252 252
 		$this->_method_of_payment = $method_of_payment;
253 253
 	}
254 254
 
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
      * @param float $payment_amount
276 276
      * @throws EE_Error
277 277
      */
278
-	public function set_payment_amount( $payment_amount ) {
279
-		$this->_payment_amount = (float)$payment_amount;
278
+	public function set_payment_amount($payment_amount) {
279
+		$this->_payment_amount = (float) $payment_amount;
280 280
 	}
281 281
 
282 282
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	/**
285 285
 	 * @param string $next_step_html
286 286
 	 */
287
-	public function set_reg_step_html( $next_step_html ) {
287
+	public function set_reg_step_html($next_step_html) {
288 288
 		$this->_reg_step_html = $next_step_html;
289 289
 	}
290 290
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 	/**
303 303
 	 * @param string $redirect_form
304 304
 	 */
305
-	public function set_redirect_form( $redirect_form ) {
305
+	public function set_redirect_form($redirect_form) {
306 306
 		$this->_redirect_form = $redirect_form;
307 307
 	}
308 308
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	 * @return string
313 313
 	 */
314 314
 	public function redirect_form() {
315
-		return ! empty( $this->_redirect_form ) ? $this->_redirect_form : FALSE;
315
+		return ! empty($this->_redirect_form) ? $this->_redirect_form : FALSE;
316 316
 	}
317 317
 
318 318
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	/**
321 321
 	 * @param string $plz_select_method_of_payment
322 322
 	 */
323
-	public function set_plz_select_method_of_payment( $plz_select_method_of_payment ) {
323
+	public function set_plz_select_method_of_payment($plz_select_method_of_payment) {
324 324
 		$this->_plz_select_method_of_payment = $plz_select_method_of_payment;
325 325
 	}
326 326
 
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 	/**
339 339
 	 * @param string $redirect_url
340 340
 	 */
341
-	public function set_redirect_url( $redirect_url ) {
341
+	public function set_redirect_url($redirect_url) {
342 342
 		$this->_redirect_url = $redirect_url;
343 343
 	}
344 344
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	/**
366 366
 	 * @param string $registration_time_limit
367 367
 	 */
368
-	public function set_registration_time_limit( $registration_time_limit ) {
368
+	public function set_registration_time_limit($registration_time_limit) {
369 369
 		$this->_registration_time_limit = $registration_time_limit;
370 370
 	}
371 371
 
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
 	/**
375 375
 	 * @param array $return_data
376 376
 	 */
377
-	public function set_return_data( $return_data ) {
378
-		$this->_return_data = array_merge( $this->_return_data, $return_data );
377
+	public function set_return_data($return_data) {
378
+		$this->_return_data = array_merge($this->_return_data, $return_data);
379 379
 	}
380 380
 
381 381
 
@@ -393,8 +393,8 @@  discard block
 block discarded – undo
393 393
 	 * @param array $validation_rules
394 394
 	 */
395 395
 	public function add_validation_rules(array $validation_rules = array()) {
396
-		if ( is_array( $validation_rules ) && ! empty( $validation_rules )) {
397
-			$this->_validation_rules = array_merge( $this->_validation_rules, $validation_rules );
396
+		if (is_array($validation_rules) && ! empty($validation_rules)) {
397
+			$this->_validation_rules = array_merge($this->_validation_rules, $validation_rules);
398 398
 		}
399 399
 	}
400 400
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 	 * @return array | bool
405 405
 	 */
406 406
 	public function validation_rules() {
407
-		return ! empty( $this->_validation_rules ) ? $this->_validation_rules : FALSE;
407
+		return ! empty($this->_validation_rules) ? $this->_validation_rules : FALSE;
408 408
 	}
409 409
 
410 410
 
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 2 patches
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
             //AND we are going to make sure they're in that specified order
112 112
             $reordered_subsections = array();
113 113
             foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
114
+                if (isset($this->_subsections[$input_name])) {
115
+                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
116 116
                 }
117 117
             }
118 118
             $this->_subsections = $reordered_subsections;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         if (isset($options_array['layout_strategy'])) {
125 125
             $this->_layout_strategy = $options_array['layout_strategy'];
126 126
         }
127
-        if (! $this->_layout_strategy) {
127
+        if ( ! $this->_layout_strategy) {
128 128
             $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129 129
         }
130 130
         $this->_layout_strategy->_construct_finalize($this);
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
                 $req_data,
278 278
                 $this
279 279
             );
280
-            $this->cached_request_data = (array)$req_data;
280
+            $this->cached_request_data = (array) $req_data;
281 281
         }
282 282
         return $this->cached_request_data;
283 283
     }
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
         if ($validate) {
314 314
             $this->_validate();
315 315
             //if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
316
+            if ( ! $this->is_valid()) {
317 317
                 $this->store_submitted_form_data_in_session();
318 318
             }
319 319
         }
@@ -426,11 +426,11 @@  discard block
 block discarded – undo
426 426
     public function populate_defaults($default_data)
427 427
     {
428 428
         foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
429
+            if (isset($default_data[$subsection_name])) {
430 430
                 if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
431
+                    $subsection->set_default($default_data[$subsection_name]);
432 432
                 } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
433
+                    $subsection->populate_defaults($default_data[$subsection_name]);
434 434
                 }
435 435
             }
436 436
         }
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
      */
446 446
     public function subsection_exists($name)
447 447
     {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
448
+        return isset($this->_subsections[$name]) ? true : false;
449 449
     }
450 450
 
451 451
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
         if ($require_construction_to_be_finalized) {
468 468
             $this->ensure_construct_finalized_called();
469 469
         }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
470
+        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
471 471
     }
472 472
 
473 473
 
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
         $validatable_subsections = array();
483 483
         foreach ($this->subsections() as $name => $obj) {
484 484
             if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
485
+                $validatable_subsections[$name] = $obj;
486 486
             }
487 487
         }
488 488
         return $validatable_subsections;
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
             $name,
510 510
             $require_construction_to_be_finalized
511 511
         );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
512
+        if ( ! $subsection instanceof EE_Form_Input_Base) {
513 513
             throw new EE_Error(
514 514
                 sprintf(
515 515
                     esc_html__(
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
             $name,
547 547
             $require_construction_to_be_finalized
548 548
         );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
549
+        if ( ! $subsection instanceof EE_Form_Section_Proper) {
550 550
             throw new EE_Error(
551 551
                 sprintf(
552 552
                     esc_html__(
@@ -585,8 +585,8 @@  discard block
 block discarded – undo
585 585
      */
586 586
     public function is_valid()
587 587
     {
588
-        if($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
588
+        if ($this->is_valid === null) {
589
+            if ( ! $this->has_received_submission()) {
590 590
                 throw new EE_Error(
591 591
                     sprintf(
592 592
                         esc_html__(
@@ -596,14 +596,14 @@  discard block
 block discarded – undo
596 596
                     )
597 597
                 );
598 598
             }
599
-            if (! parent::is_valid()) {
599
+            if ( ! parent::is_valid()) {
600 600
                 $this->is_valid = false;
601 601
             } else {
602 602
                 // ok so no general errors to this entire form section.
603 603
                 // so let's check the subsections, but only set errors if that hasn't been done yet
604 604
                 $this->is_valid = true;
605 605
                 foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
606
+                    if ( ! $subsection->is_valid()) {
607 607
                         $this->is_valid = false;
608 608
                     }
609 609
                 }
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
      */
621 621
     protected function _set_default_name_if_empty()
622 622
     {
623
-        if (! $this->_name) {
623
+        if ( ! $this->_name) {
624 624
             $classname    = get_class($this);
625 625
             $default_name = str_replace('EE_', '', $classname);
626 626
             $this->_name  = $default_name;
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
     {
711 711
         wp_register_script(
712 712
             'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
713
+            EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js',
714 714
             array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715 715
             EVENT_ESPRESSO_VERSION,
716 716
             true
@@ -754,13 +754,13 @@  discard block
 block discarded – undo
754 754
         // we only want to localize vars ONCE for the entire form,
755 755
         // so if the form section doesn't have a parent, then it must be the top dog
756 756
         if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
757
+            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
758 758
                 'form_section_id'  => $this->html_id(true),
759 759
                 'validation_rules' => $this->get_jquery_validation_rules(),
760 760
                 'other_data'       => $this->get_other_js_data(),
761 761
                 'errors'           => $this->subsection_validation_errors_by_html_name(),
762 762
             );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
763
+            EE_Form_Section_Proper::$_scripts_localized = true;
764 764
         }
765 765
     }
766 766
 
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
         $inputs = array();
796 796
         foreach ($this->subsections() as $subsection) {
797 797
             if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
798
+                $inputs[$subsection->html_name()] = $subsection;
799 799
             } elseif ($subsection instanceof EE_Form_Section_Proper) {
800 800
                 $inputs += $subsection->inputs_in_subsections();
801 801
             }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
         $errors = array();
819 819
         foreach ($inputs as $form_input) {
820 820
             if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
821
+                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
822 822
             }
823 823
         }
824 824
         return $errors;
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
         $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842 842
             ? EE_Registry::instance()->CFG->registration->email_validation_level
843 843
             : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
844
+        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
845 845
         wp_enqueue_script('ee_form_section_validation');
846 846
         wp_localize_script(
847 847
             'ee_form_section_validation',
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
      */
859 859
     public function ensure_scripts_localized()
860 860
     {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
861
+        if ( ! EE_Form_Section_Proper::$_scripts_localized) {
862 862
             $this->_enqueue_and_localize_form_js();
863 863
         }
864 864
     }
@@ -954,8 +954,8 @@  discard block
 block discarded – undo
954 954
         //reset the cache of whether this form is valid or not- we're re-validating it now
955 955
         $this->is_valid = null;
956 956
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
957
+            if (method_exists($this, '_validate_'.$subsection_name)) {
958
+                call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
959 959
             }
960 960
             $subsection->_validate();
961 961
         }
@@ -973,9 +973,9 @@  discard block
 block discarded – undo
973 973
         $inputs = array();
974 974
         foreach ($this->subsections() as $subsection_name => $subsection) {
975 975
             if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
976
+                $inputs[$subsection_name] = $subsection->valid_data();
977 977
             } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
978
+                $inputs[$subsection_name] = $subsection->normalized_value();
979 979
             }
980 980
         }
981 981
         return $inputs;
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
         $inputs = array();
994 994
         foreach ($this->subsections() as $subsection_name => $subsection) {
995 995
             if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
996
+                $inputs[$subsection_name] = $subsection;
997 997
             }
998 998
         }
999 999
         return $inputs;
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
         $form_sections = array();
1012 1012
         foreach ($this->subsections() as $name => $obj) {
1013 1013
             if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1014
+                $form_sections[$name] = $obj;
1015 1015
             }
1016 1016
         }
1017 1017
         return $form_sections;
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
         $input_values = array();
1119 1119
         foreach ($this->subsections() as $subsection_name => $subsection) {
1120 1120
             if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1121
+                $input_values[$subsection_name] = $pretty
1122 1122
                     ? $subsection->pretty_value()
1123 1123
                     : $subsection->normalized_value();
1124 1124
             } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
                 if ($flatten) {
1131 1131
                     $input_values = array_merge($input_values, $subform_input_values);
1132 1132
                 } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1133
+                    $input_values[$subsection_name] = $subform_input_values;
1134 1134
                 }
1135 1135
             }
1136 1136
         }
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
             if ($subsection instanceof EE_Form_Input_Base) {
1159 1159
                 // is this input part of an array of inputs?
1160 1160
                 if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1161
+                    $full_input_name = EEH_Array::convert_array_values_to_keys(
1162 1162
                         explode(
1163 1163
                             '[',
1164 1164
                             str_replace(']', '', $subsection->html_name())
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
                     );
1168 1168
                     $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169 1169
                 } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1170
+                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1171 1171
                 }
1172 1172
             } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173 1173
                 $subform_input_values = $subsection->submitted_values($include_subforms);
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
     public function exclude(array $inputs_to_exclude = array())
1203 1203
     {
1204 1204
         foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1205
+            unset($this->_subsections[$input_to_exclude_name]);
1206 1206
         }
1207 1207
     }
1208 1208
 
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
     public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1245 1245
     {
1246 1246
         foreach ($new_subsections as $subsection_name => $subsection) {
1247
-            if (! $subsection instanceof EE_Form_Section_Base) {
1247
+            if ( ! $subsection instanceof EE_Form_Section_Base) {
1248 1248
                 EE_Error::add_error(
1249 1249
                     sprintf(
1250 1250
                         esc_html__(
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
                         $this->name()
1257 1257
                     )
1258 1258
                 );
1259
-                unset($new_subsections[ $subsection_name ]);
1259
+                unset($new_subsections[$subsection_name]);
1260 1260
             }
1261 1261
         }
1262 1262
         $this->_subsections = EEH_Array::insert_into_array(
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
      */
1281 1281
     public function has_subsection($subsection_name, $recursive = false)
1282 1282
     {
1283
-        foreach ($this->_subsections as $name => $subsection) {if(
1283
+        foreach ($this->_subsections as $name => $subsection) {if (
1284 1284
                 $name === $subsection_name
1285 1285
                 || (
1286 1286
                     $recursive
@@ -1371,7 +1371,7 @@  discard block
 block discarded – undo
1371 1371
     public function html_name_prefix()
1372 1372
     {
1373 1373
         if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1374
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1374
+            return $this->parent_section()->html_name_prefix().'['.$this->name().']';
1375 1375
         }
1376 1376
         return $this->name();
1377 1377
     }
@@ -1411,7 +1411,7 @@  discard block
 block discarded – undo
1411 1411
      */
1412 1412
     public function ensure_construct_finalized_called()
1413 1413
     {
1414
-        if (! $this->_construction_finalized) {
1414
+        if ( ! $this->_construction_finalized) {
1415 1415
             $this->_construct_finalize($this->_parent_section, $this->_name);
1416 1416
         }
1417 1417
     }
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
                 $form_section = $validation_error->get_form_section();
1485 1485
                 if ($form_section instanceof EE_Form_Input_Base) {
1486 1486
                    $label = $validation_error->get_form_section()->html_label_text();
1487
-                } elseif($form_section instanceof EE_Form_Section_Validatable) {
1487
+                } elseif ($form_section instanceof EE_Form_Section_Validatable) {
1488 1488
                     $label = $validation_error->get_form_section()->name();
1489 1489
                 } else {
1490 1490
                     $label = esc_html__('Unknown', 'event_espresso');
Please login to merge, or discard this patch.
Indentation   +1524 added lines, -1524 removed lines patch added patch discarded remove patch
@@ -14,1529 +14,1529 @@
 block discarded – undo
14 14
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
15 15
 {
16 16
 
17
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
-
19
-    /**
20
-     * Subsections
21
-     *
22
-     * @var EE_Form_Section_Validatable[]
23
-     */
24
-    protected $_subsections = array();
25
-
26
-    /**
27
-     * Strategy for laying out the form
28
-     *
29
-     * @var EE_Form_Section_Layout_Base
30
-     */
31
-    protected $_layout_strategy;
32
-
33
-    /**
34
-     * Whether or not this form has received and validated a form submission yet
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_received_submission = false;
39
-
40
-    /**
41
-     * message displayed to users upon successful form submission
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_form_submission_success_message = '';
46
-
47
-    /**
48
-     * message displayed to users upon unsuccessful form submission
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_form_submission_error_message = '';
53
-
54
-    /**
55
-     * @var array like $_REQUEST
56
-     */
57
-    protected $cached_request_data;
58
-
59
-    /**
60
-     * Stores whether this form (and its sub-sections) were found to be valid or not.
61
-     * Starts off as null, but once the form is validated, it set to either true or false
62
-     * @var boolean|null
63
-     */
64
-    protected $is_valid;
65
-
66
-    /**
67
-     * Stores all the data that will localized for form validation
68
-     *
69
-     * @var array
70
-     */
71
-    static protected $_js_localization = array();
72
-
73
-    /**
74
-     * whether or not the form's localized validation JS vars have been set
75
-     *
76
-     * @type boolean
77
-     */
78
-    static protected $_scripts_localized = false;
79
-
80
-
81
-    /**
82
-     * when constructing a proper form section, calls _construct_finalize on children
83
-     * so that they know who their parent is, and what name they've been given.
84
-     *
85
-     * @param array[] $options_array   {
86
-     * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
-     * @type          $include         string[] numerically-indexed where values are section names to be included,
88
-     *                                 and in that order. This is handy if you want
89
-     *                                 the subsections to be ordered differently than the default, and if you override
90
-     *                                 which fields are shown
91
-     * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
-     *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
-     *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
-     *                                 items from that list of inclusions)
95
-     * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
-     *                                 } @see EE_Form_Section_Validatable::__construct()
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        $options_array = (array) apply_filters(
102
-            'FHEE__EE_Form_Section_Proper___construct__options_array',
103
-            $options_array,
104
-            $this
105
-        );
106
-        //call parent first, as it may be setting the name
107
-        parent::__construct($options_array);
108
-        //if they've included subsections in the constructor, add them now
109
-        if (isset($options_array['include'])) {
110
-            //we are going to make sure we ONLY have those subsections to include
111
-            //AND we are going to make sure they're in that specified order
112
-            $reordered_subsections = array();
113
-            foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
-                }
117
-            }
118
-            $this->_subsections = $reordered_subsections;
119
-        }
120
-        if (isset($options_array['exclude'])) {
121
-            $exclude            = $options_array['exclude'];
122
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
-        }
124
-        if (isset($options_array['layout_strategy'])) {
125
-            $this->_layout_strategy = $options_array['layout_strategy'];
126
-        }
127
-        if (! $this->_layout_strategy) {
128
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
-        }
130
-        $this->_layout_strategy->_construct_finalize($this);
131
-        //ok so we are definitely going to want the forms JS,
132
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
-            //ok so they've constructed this object after when they should have.
135
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
136
-            EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
-        } else {
138
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
-        }
141
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
-        /**
143
-         * Gives other plugins a chance to hook in before construct finalize is called.
144
-         * The form probably doesn't yet have a parent form section.
145
-         * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
-         * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
-         *
149
-         * @since 4.9.32
150
-         * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
-         *                                              except maybe calling _construct_finalize has been done
152
-         * @param array                  $options_array options passed into the constructor
153
-         */
154
-        do_action(
155
-            'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
-            $this,
157
-            $options_array
158
-        );
159
-        if (isset($options_array['name'])) {
160
-            $this->_construct_finalize(null, $options_array['name']);
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Finishes construction given the parent form section and this form section's name
167
-     *
168
-     * @param EE_Form_Section_Proper $parent_form_section
169
-     * @param string                 $name
170
-     * @throws EE_Error
171
-     */
172
-    public function _construct_finalize($parent_form_section, $name)
173
-    {
174
-        parent::_construct_finalize($parent_form_section, $name);
175
-        $this->_set_default_name_if_empty();
176
-        $this->_set_default_html_id_if_empty();
177
-        foreach ($this->_subsections as $subsection_name => $subsection) {
178
-            if ($subsection instanceof EE_Form_Section_Base) {
179
-                $subsection->_construct_finalize($this, $subsection_name);
180
-            } else {
181
-                throw new EE_Error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
-                            'event_espresso'
186
-                        ),
187
-                        $subsection_name,
188
-                        get_class($this),
189
-                        $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
-                    )
191
-                );
192
-            }
193
-        }
194
-        /**
195
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
-         * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
-         * This might only happen just before displaying the form, or just before it receives form submission data.
199
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
-         * ensured it has a name, HTML IDs, etc
201
-         *
202
-         * @param EE_Form_Section_Proper      $this
203
-         * @param EE_Form_Section_Proper|null $parent_form_section
204
-         * @param string                      $name
205
-         */
206
-        do_action(
207
-            'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
-            $this,
209
-            $parent_form_section,
210
-            $name
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the layout strategy for this form section
217
-     *
218
-     * @return EE_Form_Section_Layout_Base
219
-     */
220
-    public function get_layout_strategy()
221
-    {
222
-        return $this->_layout_strategy;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the HTML for a single input for this form section according
228
-     * to the layout strategy
229
-     *
230
-     * @param EE_Form_Input_Base $input
231
-     * @return string
232
-     */
233
-    public function get_html_for_input($input)
234
-    {
235
-        return $this->_layout_strategy->layout_input($input);
236
-    }
237
-
238
-
239
-    /**
240
-     * was_submitted - checks if form inputs are present in request data
241
-     * Basically an alias for form_data_present_in() (which is used by both
242
-     * proper form sections and form inputs)
243
-     *
244
-     * @param null $form_data
245
-     * @return boolean
246
-     * @throws EE_Error
247
-     */
248
-    public function was_submitted($form_data = null)
249
-    {
250
-        return $this->form_data_present_in($form_data);
251
-    }
252
-
253
-    /**
254
-     * Gets the cached request data; but if there is none, or $req_data was set with
255
-     * something different, refresh the cache, and then return it
256
-     * @param null $req_data
257
-     * @return array
258
-     */
259
-    protected function getCachedRequest($req_data = null)
260
-    {
261
-        if ($this->cached_request_data === null
262
-            || (
263
-                $req_data !== null &&
264
-                $req_data !== $this->cached_request_data
265
-            )
266
-        ) {
267
-            $req_data = apply_filters(
268
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
-                $req_data,
270
-                $this
271
-            );
272
-            if ($req_data === null) {
273
-                $req_data = array_merge($_GET, $_POST);
274
-            }
275
-            $req_data = apply_filters(
276
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
-                $req_data,
278
-                $this
279
-            );
280
-            $this->cached_request_data = (array)$req_data;
281
-        }
282
-        return $this->cached_request_data;
283
-    }
284
-
285
-
286
-    /**
287
-     * After the form section is initially created, call this to sanitize the data in the submission
288
-     * which relates to this form section, validate it, and set it as properties on the form.
289
-     *
290
-     * @param array|null $req_data should usually be $_POST (the default).
291
-     *                             However, you CAN supply a different array.
292
-     *                             Consider using set_defaults() instead however.
293
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
294
-     *                             the inputs will have the correct name in the request data for this function
295
-     *                             to find them and populate the form with them.
296
-     *                             If you have a flat form (with only input subsections),
297
-     *                             you can supply a flat array where keys
298
-     *                             are the form input names and values are their values)
299
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
-     *                             of course, to validate that data, and set errors on the invalid values.
301
-     *                             But if the data has already been validated
302
-     *                             (eg you validated the data then stored it in the DB)
303
-     *                             you may want to skip this step.
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidInterfaceException
306
-     * @throws InvalidDataTypeException
307
-     * @throws EE_Error
308
-     */
309
-    public function receive_form_submission($req_data = null, $validate = true)
310
-    {
311
-        $req_data = $this->getCachedRequest($req_data);
312
-        $this->_normalize($req_data);
313
-        if ($validate) {
314
-            $this->_validate();
315
-            //if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
317
-                $this->store_submitted_form_data_in_session();
318
-            }
319
-        }
320
-        if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
-            $this->set_submission_error_message();
322
-        }
323
-        do_action(
324
-            'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
-            $req_data,
326
-            $this,
327
-            $validate
328
-        );
329
-    }
330
-
331
-
332
-    /**
333
-     * caches the originally submitted input values in the session
334
-     * so that they can be used to repopulate the form if it failed validation
335
-     *
336
-     * @return boolean whether or not the data was successfully stored in the session
337
-     * @throws InvalidArgumentException
338
-     * @throws InvalidInterfaceException
339
-     * @throws InvalidDataTypeException
340
-     * @throws EE_Error
341
-     */
342
-    protected function store_submitted_form_data_in_session()
343
-    {
344
-        return EE_Registry::instance()->SSN->set_session_data(
345
-            array(
346
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
-            )
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * retrieves the originally submitted input values in the session
354
-     * so that they can be used to repopulate the form if it failed validation
355
-     *
356
-     * @return array
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    protected function get_submitted_form_data_from_session()
362
-    {
363
-        $session = EE_Registry::instance()->SSN;
364
-        if ($session instanceof EE_Session) {
365
-            return $session->get_session_data(
366
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
-            );
368
-        }
369
-        return array();
370
-    }
371
-
372
-
373
-    /**
374
-     * flushed the originally submitted input values from the session
375
-     *
376
-     * @return boolean whether or not the data was successfully removed from the session
377
-     * @throws InvalidArgumentException
378
-     * @throws InvalidInterfaceException
379
-     * @throws InvalidDataTypeException
380
-     */
381
-    protected function flush_submitted_form_data_from_session()
382
-    {
383
-        return EE_Registry::instance()->SSN->reset_data(
384
-            array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Populates this form and its subsections with data from the session.
391
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
-     * validation errors when displaying too)
393
-     * Returns true if the form was populated from the session, false otherwise
394
-     *
395
-     * @return boolean
396
-     * @throws InvalidArgumentException
397
-     * @throws InvalidInterfaceException
398
-     * @throws InvalidDataTypeException
399
-     * @throws EE_Error
400
-     */
401
-    public function populate_from_session()
402
-    {
403
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
404
-        if (empty($form_data_in_session)) {
405
-            return false;
406
-        }
407
-        $this->receive_form_submission($form_data_in_session);
408
-        $this->flush_submitted_form_data_from_session();
409
-        if ($this->form_data_present_in($form_data_in_session)) {
410
-            return true;
411
-        }
412
-        return false;
413
-    }
414
-
415
-
416
-    /**
417
-     * Populates the default data for the form, given an array where keys are
418
-     * the input names, and values are their values (preferably normalized to be their
419
-     * proper PHP types, not all strings... although that should be ok too).
420
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
421
-     * the value being an array formatted in teh same way
422
-     *
423
-     * @param array $default_data
424
-     * @throws EE_Error
425
-     */
426
-    public function populate_defaults($default_data)
427
-    {
428
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
430
-                if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
432
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
434
-                }
435
-            }
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * returns true if subsection exists
442
-     *
443
-     * @param string $name
444
-     * @return boolean
445
-     */
446
-    public function subsection_exists($name)
447
-    {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
449
-    }
450
-
451
-
452
-    /**
453
-     * Gets the subsection specified by its name
454
-     *
455
-     * @param string  $name
456
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
-     *                                                      so that the inputs will be properly configured.
458
-     *                                                      However, some client code may be ok
459
-     *                                                      with construction finalize being called later
460
-     *                                                      (realizing that the subsections' html names
461
-     *                                                      might not be set yet, etc.)
462
-     * @return EE_Form_Section_Base
463
-     * @throws EE_Error
464
-     */
465
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
466
-    {
467
-        if ($require_construction_to_be_finalized) {
468
-            $this->ensure_construct_finalized_called();
469
-        }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
-    }
472
-
473
-
474
-    /**
475
-     * Gets all the validatable subsections of this form section
476
-     *
477
-     * @return EE_Form_Section_Validatable[]
478
-     * @throws EE_Error
479
-     */
480
-    public function get_validatable_subsections()
481
-    {
482
-        $validatable_subsections = array();
483
-        foreach ($this->subsections() as $name => $obj) {
484
-            if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
486
-            }
487
-        }
488
-        return $validatable_subsections;
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
-     * throw an EE_Error.
495
-     *
496
-     * @param string  $name
497
-     * @param boolean $require_construction_to_be_finalized most client code should
498
-     *                                                      leave this as TRUE so that the inputs will be properly
499
-     *                                                      configured. However, some client code may be ok with
500
-     *                                                      construction finalize being called later
501
-     *                                                      (realizing that the subsections' html names might not be
502
-     *                                                      set yet, etc.)
503
-     * @return EE_Form_Input_Base
504
-     * @throws EE_Error
505
-     */
506
-    public function get_input($name, $require_construction_to_be_finalized = true)
507
-    {
508
-        $subsection = $this->get_subsection(
509
-            $name,
510
-            $require_construction_to_be_finalized
511
-        );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
513
-            throw new EE_Error(
514
-                sprintf(
515
-                    esc_html__(
516
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
-                        'event_espresso'
518
-                    ),
519
-                    $name,
520
-                    get_class($this),
521
-                    $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
-                )
523
-            );
524
-        }
525
-        return $subsection;
526
-    }
527
-
528
-
529
-    /**
530
-     * Like get_input(), gets the proper subsection of the form given the name,
531
-     * otherwise throws an EE_Error
532
-     *
533
-     * @param string  $name
534
-     * @param boolean $require_construction_to_be_finalized most client code should
535
-     *                                                      leave this as TRUE so that the inputs will be properly
536
-     *                                                      configured. However, some client code may be ok with
537
-     *                                                      construction finalize being called later
538
-     *                                                      (realizing that the subsections' html names might not be
539
-     *                                                      set yet, etc.)
540
-     * @return EE_Form_Section_Proper
541
-     * @throws EE_Error
542
-     */
543
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
-    {
545
-        $subsection = $this->get_subsection(
546
-            $name,
547
-            $require_construction_to_be_finalized
548
-        );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
550
-            throw new EE_Error(
551
-                sprintf(
552
-                    esc_html__(
553
-                        "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
-                        'event_espresso'
555
-                    ),
556
-                    $name,
557
-                    get_class($this)
558
-                )
559
-            );
560
-        }
561
-        return $subsection;
562
-    }
563
-
564
-
565
-    /**
566
-     * Gets the value of the specified input. Should be called after receive_form_submission()
567
-     * or populate_defaults() on the form, where the normalized value on the input is set.
568
-     *
569
-     * @param string $name
570
-     * @return mixed depending on the input's type and its normalization strategy
571
-     * @throws EE_Error
572
-     */
573
-    public function get_input_value($name)
574
-    {
575
-        $input = $this->get_input($name);
576
-        return $input->normalized_value();
577
-    }
578
-
579
-
580
-    /**
581
-     * Checks if this form section itself is valid, and then checks its subsections
582
-     *
583
-     * @throws EE_Error
584
-     * @return boolean
585
-     */
586
-    public function is_valid()
587
-    {
588
-        if($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
590
-                throw new EE_Error(
591
-                    sprintf(
592
-                        esc_html__(
593
-                            'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
-                            'event_espresso'
595
-                        )
596
-                    )
597
-                );
598
-            }
599
-            if (! parent::is_valid()) {
600
-                $this->is_valid = false;
601
-            } else {
602
-                // ok so no general errors to this entire form section.
603
-                // so let's check the subsections, but only set errors if that hasn't been done yet
604
-                $this->is_valid = true;
605
-                foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
607
-                        $this->is_valid = false;
608
-                    }
609
-                }
610
-            }
611
-        }
612
-        return $this->is_valid;
613
-    }
614
-
615
-
616
-    /**
617
-     * gets the default name of this form section if none is specified
618
-     *
619
-     * @return void
620
-     */
621
-    protected function _set_default_name_if_empty()
622
-    {
623
-        if (! $this->_name) {
624
-            $classname    = get_class($this);
625
-            $default_name = str_replace('EE_', '', $classname);
626
-            $this->_name  = $default_name;
627
-        }
628
-    }
629
-
630
-
631
-    /**
632
-     * Returns the HTML for the form, except for the form opening and closing tags
633
-     * (as the form section doesn't know where you necessarily want to send the information to),
634
-     * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
-     * Not doing_it_wrong because theoretically this CAN be used properly,
637
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
-     * any CSS.
639
-     *
640
-     * @throws InvalidArgumentException
641
-     * @throws InvalidInterfaceException
642
-     * @throws InvalidDataTypeException
643
-     * @throws EE_Error
644
-     */
645
-    public function get_html_and_js()
646
-    {
647
-        $this->enqueue_js();
648
-        return $this->get_html();
649
-    }
650
-
651
-
652
-    /**
653
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
-     *
655
-     * @param bool $display_previously_submitted_data
656
-     * @return string
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidInterfaceException
659
-     * @throws InvalidDataTypeException
660
-     * @throws EE_Error
661
-     * @throws EE_Error
662
-     * @throws EE_Error
663
-     */
664
-    public function get_html($display_previously_submitted_data = true)
665
-    {
666
-        $this->ensure_construct_finalized_called();
667
-        if ($display_previously_submitted_data) {
668
-            $this->populate_from_session();
669
-        }
670
-        return $this->_form_html_filter
671
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
-            : $this->_layout_strategy->layout_form();
673
-    }
674
-
675
-
676
-    /**
677
-     * enqueues JS and CSS for the form.
678
-     * It is preferred to call this before wp_enqueue_scripts so the
679
-     * scripts and styles can be put in the header, but if called later
680
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
-     * only be in the header; but in HTML5 its ok in the body.
682
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
-     *
685
-     * @return void
686
-     * @throws EE_Error
687
-     */
688
-    public function enqueue_js()
689
-    {
690
-        $this->_enqueue_and_localize_form_js();
691
-        foreach ($this->subsections() as $subsection) {
692
-            $subsection->enqueue_js();
693
-        }
694
-    }
695
-
696
-
697
-    /**
698
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
-     * the wp_enqueue_scripts hook.
701
-     * However, registering the form js and localizing it can happen when we
702
-     * actually output the form (which is preferred, seeing how teh form's fields
703
-     * could change until it's actually outputted)
704
-     *
705
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
-     *                                                    to be triggered automatically or not
707
-     * @return void
708
-     */
709
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
-    {
711
-        wp_register_script(
712
-            'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
714
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
-            EVENT_ESPRESSO_VERSION,
716
-            true
717
-        );
718
-        wp_localize_script(
719
-            'ee_form_section_validation',
720
-            'ee_form_section_validation_init',
721
-            array('init' => $init_form_validation_automatically ? '1' : '0')
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * gets the variables used by form_section_validation.js.
728
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
-     * but before the wordpress hook wp_loaded
730
-     *
731
-     * @throws EE_Error
732
-     */
733
-    public function _enqueue_and_localize_form_js()
734
-    {
735
-        $this->ensure_construct_finalized_called();
736
-        //actually, we don't want to localize just yet. There may be other forms on the page.
737
-        //so we need to add our form section data to a static variable accessible by all form sections
738
-        //and localize it just before the footer
739
-        $this->localize_validation_rules();
740
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
-    }
743
-
744
-
745
-    /**
746
-     * add our form section data to a static variable accessible by all form sections
747
-     *
748
-     * @param bool $return_for_subsection
749
-     * @return void
750
-     * @throws EE_Error
751
-     */
752
-    public function localize_validation_rules($return_for_subsection = false)
753
-    {
754
-        // we only want to localize vars ONCE for the entire form,
755
-        // so if the form section doesn't have a parent, then it must be the top dog
756
-        if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
-                'form_section_id'  => $this->html_id(true),
759
-                'validation_rules' => $this->get_jquery_validation_rules(),
760
-                'other_data'       => $this->get_other_js_data(),
761
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
762
-            );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
764
-        }
765
-    }
766
-
767
-
768
-    /**
769
-     * Gets an array of extra data that will be useful for client-side javascript.
770
-     * This is primarily data added by inputs and forms in addition to any
771
-     * scripts they might enqueue
772
-     *
773
-     * @param array $form_other_js_data
774
-     * @return array
775
-     * @throws EE_Error
776
-     */
777
-    public function get_other_js_data($form_other_js_data = array())
778
-    {
779
-        foreach ($this->subsections() as $subsection) {
780
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
-        }
782
-        return $form_other_js_data;
783
-    }
784
-
785
-
786
-    /**
787
-     * Gets a flat array of inputs for this form section and its subsections.
788
-     * Keys are their form names, and values are the inputs themselves
789
-     *
790
-     * @return EE_Form_Input_Base
791
-     * @throws EE_Error
792
-     */
793
-    public function inputs_in_subsections()
794
-    {
795
-        $inputs = array();
796
-        foreach ($this->subsections() as $subsection) {
797
-            if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
799
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
800
-                $inputs += $subsection->inputs_in_subsections();
801
-            }
802
-        }
803
-        return $inputs;
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets a flat array of all the validation errors.
809
-     * Keys are html names (because those should be unique)
810
-     * and values are a string of all their validation errors
811
-     *
812
-     * @return string[]
813
-     * @throws EE_Error
814
-     */
815
-    public function subsection_validation_errors_by_html_name()
816
-    {
817
-        $inputs = $this->inputs();
818
-        $errors = array();
819
-        foreach ($inputs as $form_input) {
820
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
-            }
823
-        }
824
-        return $errors;
825
-    }
826
-
827
-
828
-    /**
829
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
-     * Should be setup by each form during the _enqueues_and_localize_form_js
831
-     *
832
-     * @throws InvalidArgumentException
833
-     * @throws InvalidInterfaceException
834
-     * @throws InvalidDataTypeException
835
-     */
836
-    public static function localize_script_for_all_forms()
837
-    {
838
-        //allow inputs and stuff to hook in their JS and stuff here
839
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
843
-            : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
-        wp_enqueue_script('ee_form_section_validation');
846
-        wp_localize_script(
847
-            'ee_form_section_validation',
848
-            'ee_form_section_vars',
849
-            EE_Form_Section_Proper::$_js_localization
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * ensure_scripts_localized
856
-     *
857
-     * @throws EE_Error
858
-     */
859
-    public function ensure_scripts_localized()
860
-    {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
862
-            $this->_enqueue_and_localize_form_js();
863
-        }
864
-    }
865
-
866
-
867
-    /**
868
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
869
-     * is that the key here should be the same as the custom validation rule put in the JS file
870
-     *
871
-     * @return array keys are custom validation rules, and values are internationalized strings
872
-     */
873
-    private static function _get_localized_error_messages()
874
-    {
875
-        return array(
876
-            'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
-            'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
-        );
879
-    }
880
-
881
-
882
-    /**
883
-     * @return array
884
-     */
885
-    public static function js_localization()
886
-    {
887
-        return self::$_js_localization;
888
-    }
889
-
890
-
891
-    /**
892
-     * @return void
893
-     */
894
-    public static function reset_js_localization()
895
-    {
896
-        self::$_js_localization = array();
897
-    }
898
-
899
-
900
-    /**
901
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
-     * See parent function for more...
903
-     *
904
-     * @return array
905
-     * @throws EE_Error
906
-     */
907
-    public function get_jquery_validation_rules()
908
-    {
909
-        $jquery_validation_rules = array();
910
-        foreach ($this->get_validatable_subsections() as $subsection) {
911
-            $jquery_validation_rules = array_merge(
912
-                $jquery_validation_rules,
913
-                $subsection->get_jquery_validation_rules()
914
-            );
915
-        }
916
-        return $jquery_validation_rules;
917
-    }
918
-
919
-
920
-    /**
921
-     * Sanitizes all the data and sets the sanitized value of each field
922
-     *
923
-     * @param array $req_data like $_POST
924
-     * @return void
925
-     * @throws EE_Error
926
-     */
927
-    protected function _normalize($req_data)
928
-    {
929
-        $this->_received_submission = true;
930
-        $this->_validation_errors   = array();
931
-        foreach ($this->get_validatable_subsections() as $subsection) {
932
-            try {
933
-                $subsection->_normalize($req_data);
934
-            } catch (EE_Validation_Error $e) {
935
-                $subsection->add_validation_error($e);
936
-            }
937
-        }
938
-    }
939
-
940
-
941
-    /**
942
-     * Performs validation on this form section and its subsections.
943
-     * For each subsection,
944
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
945
-     * and passes it the subsection, then calls _validate on that subsection.
946
-     * If you need to perform validation on the form as a whole (considering multiple)
947
-     * you would be best to override this _validate method,
948
-     * calling parent::_validate() first.
949
-     *
950
-     * @throws EE_Error
951
-     */
952
-    protected function _validate()
953
-    {
954
-        //reset the cache of whether this form is valid or not- we're re-validating it now
955
-        $this->is_valid = null;
956
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
-            }
960
-            $subsection->_validate();
961
-        }
962
-    }
963
-
964
-
965
-    /**
966
-     * Gets all the validated inputs for the form section
967
-     *
968
-     * @return array
969
-     * @throws EE_Error
970
-     */
971
-    public function valid_data()
972
-    {
973
-        $inputs = array();
974
-        foreach ($this->subsections() as $subsection_name => $subsection) {
975
-            if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
977
-            } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
979
-            }
980
-        }
981
-        return $inputs;
982
-    }
983
-
984
-
985
-    /**
986
-     * Gets all the inputs on this form section
987
-     *
988
-     * @return EE_Form_Input_Base[]
989
-     * @throws EE_Error
990
-     */
991
-    public function inputs()
992
-    {
993
-        $inputs = array();
994
-        foreach ($this->subsections() as $subsection_name => $subsection) {
995
-            if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
997
-            }
998
-        }
999
-        return $inputs;
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * Gets all the subsections which are a proper form
1005
-     *
1006
-     * @return EE_Form_Section_Proper[]
1007
-     * @throws EE_Error
1008
-     */
1009
-    public function subforms()
1010
-    {
1011
-        $form_sections = array();
1012
-        foreach ($this->subsections() as $name => $obj) {
1013
-            if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1015
-            }
1016
-        }
1017
-        return $form_sections;
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
-     * Consider using inputs() or subforms()
1024
-     * if you only want form inputs or proper form sections.
1025
-     *
1026
-     * @param boolean $require_construction_to_be_finalized most client code should
1027
-     *                                                      leave this as TRUE so that the inputs will be properly
1028
-     *                                                      configured. However, some client code may be ok with
1029
-     *                                                      construction finalize being called later
1030
-     *                                                      (realizing that the subsections' html names might not be
1031
-     *                                                      set yet, etc.)
1032
-     * @return EE_Form_Section_Proper[]
1033
-     * @throws EE_Error
1034
-     */
1035
-    public function subsections($require_construction_to_be_finalized = true)
1036
-    {
1037
-        if ($require_construction_to_be_finalized) {
1038
-            $this->ensure_construct_finalized_called();
1039
-        }
1040
-        return $this->_subsections;
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * Returns whether this form has any subforms or inputs
1046
-     * @return bool
1047
-     */
1048
-    public function hasSubsections()
1049
-    {
1050
-        return ! empty($this->_subsections);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * Returns a simple array where keys are input names, and values are their normalized
1056
-     * values. (Similar to calling get_input_value on inputs)
1057
-     *
1058
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
-     *                                        or just this forms' direct children inputs
1060
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
-     *                                        or allow multidimensional array
1062
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
-     *                                        with array keys being input names
1064
-     *                                        (regardless of whether they are from a subsection or not),
1065
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1066
-     *                                        where keys are always subsection names and values are either
1067
-     *                                        the input's normalized value, or an array like the top-level array
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function input_values($include_subform_inputs = false, $flatten = false)
1071
-    {
1072
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
-     * is not necessarily the value we want to display to users. This creates an array
1080
-     * where keys are the input names, and values are their display values
1081
-     *
1082
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
-     *                                        or just this forms' direct children inputs
1084
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
-     *                                        or allow multidimensional array
1086
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
-     *                                        with array keys being input names
1088
-     *                                        (regardless of whether they are from a subsection or not),
1089
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1090
-     *                                        where keys are always subsection names and values are either
1091
-     *                                        the input's normalized value, or an array like the top-level array
1092
-     * @throws EE_Error
1093
-     */
1094
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
-    {
1096
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * Gets the input values from the form
1102
-     *
1103
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
-     *                                        or just the normalized value
1105
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
-     *                                        or just this forms' direct children inputs
1107
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
-     *                                        or allow multidimensional array
1109
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
-     *                                        input names (regardless of whether they are from a subsection or not),
1111
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1112
-     *                                        where keys are always subsection names and values are either
1113
-     *                                        the input's normalized value, or an array like the top-level array
1114
-     * @throws EE_Error
1115
-     */
1116
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
-    {
1118
-        $input_values = array();
1119
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1120
-            if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1122
-                    ? $subsection->pretty_value()
1123
-                    : $subsection->normalized_value();
1124
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
-                $subform_input_values = $subsection->_input_values(
1126
-                    $pretty,
1127
-                    $include_subform_inputs,
1128
-                    $flatten
1129
-                );
1130
-                if ($flatten) {
1131
-                    $input_values = array_merge($input_values, $subform_input_values);
1132
-                } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1134
-                }
1135
-            }
1136
-        }
1137
-        return $input_values;
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Gets the originally submitted input values from the form
1143
-     *
1144
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
-     *                                   or just this forms' direct children inputs
1146
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
-     *                                   with array keys being input names
1148
-     *                                   (regardless of whether they are from a subsection or not),
1149
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1150
-     *                                   where keys are always subsection names and values are either
1151
-     *                                   the input's normalized value, or an array like the top-level array
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function submitted_values($include_subforms = false)
1155
-    {
1156
-        $submitted_values = array();
1157
-        foreach ($this->subsections() as $subsection) {
1158
-            if ($subsection instanceof EE_Form_Input_Base) {
1159
-                // is this input part of an array of inputs?
1160
-                if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
-                        explode(
1163
-                            '[',
1164
-                            str_replace(']', '', $subsection->html_name())
1165
-                        ),
1166
-                        $subsection->raw_value()
1167
-                    );
1168
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
-                } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
-                }
1172
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1174
-                $submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
-            }
1176
-        }
1177
-        return $submitted_values;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * Indicates whether or not this form has received a submission yet
1183
-     * (ie, had receive_form_submission called on it yet)
1184
-     *
1185
-     * @return boolean
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function has_received_submission()
1189
-    {
1190
-        $this->ensure_construct_finalized_called();
1191
-        return $this->_received_submission;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Equivalent to passing 'exclude' in the constructor's options array.
1197
-     * Removes the listed inputs from the form
1198
-     *
1199
-     * @param array $inputs_to_exclude values are the input names
1200
-     * @return void
1201
-     */
1202
-    public function exclude(array $inputs_to_exclude = array())
1203
-    {
1204
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1206
-        }
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
-     * @param array $inputs_to_hide
1213
-     * @throws EE_Error
1214
-     */
1215
-    public function hide(array $inputs_to_hide = array())
1216
-    {
1217
-        foreach ($inputs_to_hide as $input_to_hide) {
1218
-            $input = $this->get_input($input_to_hide);
1219
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
-        }
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * add_subsections
1226
-     * Adds the listed subsections to the form section.
1227
-     * If $subsection_name_to_target is provided,
1228
-     * then new subsections are added before or after that subsection,
1229
-     * otherwise to the start or end of the entire subsections array.
1230
-     *
1231
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
-     *                                                          where keys are their names
1233
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
-     *                                                          should be added before or after
1235
-     *                                                          IF $subsection_name_to_target is null,
1236
-     *                                                          then $new_subsections will be added to
1237
-     *                                                          the beginning or end of the entire subsections array
1238
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
-     *                                                          $subsection_name_to_target,
1240
-     *                                                          or if $subsection_name_to_target is null,
1241
-     *                                                          before or after entire subsections array
1242
-     * @return void
1243
-     * @throws EE_Error
1244
-     */
1245
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
-    {
1247
-        foreach ($new_subsections as $subsection_name => $subsection) {
1248
-            if (! $subsection instanceof EE_Form_Section_Base) {
1249
-                EE_Error::add_error(
1250
-                    sprintf(
1251
-                        esc_html__(
1252
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
-                            'event_espresso'
1254
-                        ),
1255
-                        get_class($subsection),
1256
-                        $subsection_name,
1257
-                        $this->name()
1258
-                    )
1259
-                );
1260
-                unset($new_subsections[ $subsection_name ]);
1261
-            }
1262
-        }
1263
-        $this->_subsections = EEH_Array::insert_into_array(
1264
-            $this->_subsections,
1265
-            $new_subsections,
1266
-            $subsection_name_to_target,
1267
-            $add_before
1268
-        );
1269
-        if ($this->_construction_finalized) {
1270
-            foreach ($this->_subsections as $name => $subsection) {
1271
-                $subsection->_construct_finalize($this, $name);
1272
-            }
1273
-        }
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * @param string $subsection_name
1279
-     * @param bool   $recursive
1280
-     * @return bool
1281
-     */
1282
-    public function has_subsection($subsection_name, $recursive = false)
1283
-    {
1284
-        foreach ($this->_subsections as $name => $subsection) {if(
1285
-                $name === $subsection_name
1286
-                || (
1287
-                    $recursive
1288
-                    && $subsection instanceof EE_Form_Section_Proper
1289
-                    && $subsection->has_subsection($subsection_name, $recursive)
1290
-                )
1291
-            ) {
1292
-                return true;
1293
-            }
1294
-        }
1295
-        return false;
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * Just gets all validatable subsections to clean their sensitive data
1302
-     *
1303
-     * @throws EE_Error
1304
-     */
1305
-    public function clean_sensitive_data()
1306
-    {
1307
-        foreach ($this->get_validatable_subsections() as $subsection) {
1308
-            $subsection->clean_sensitive_data();
1309
-        }
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
-     * @param string                           $form_submission_error_message
1316
-     * @param EE_Form_Section_Validatable $form_section unused
1317
-     * @throws EE_Error
1318
-     */
1319
-    public function set_submission_error_message(
1320
-        $form_submission_error_message = ''
1321
-    ) {
1322
-        $this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
-            ? $form_submission_error_message
1324
-            : $this->getAllValidationErrorsString();
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * Returns the cached error message. A default value is set for this during _validate(),
1330
-     * (called during receive_form_submission) but it can be explicitly set using
1331
-     * set_submission_error_message
1332
-     *
1333
-     * @return string
1334
-     */
1335
-    public function submission_error_message()
1336
-    {
1337
-        return $this->_form_submission_error_message;
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * Sets a message to display if the data submitted to the form was valid.
1343
-     * @param string $form_submission_success_message
1344
-     */
1345
-    public function set_submission_success_message($form_submission_success_message = '')
1346
-    {
1347
-        $this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
-            ? $form_submission_success_message
1349
-            : esc_html__('Form submitted successfully', 'event_espresso');
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * Gets a message appropriate for display when the form is correctly submitted
1355
-     * @return string
1356
-     */
1357
-    public function submission_success_message()
1358
-    {
1359
-        return $this->_form_submission_success_message;
1360
-    }
1361
-
1362
-
1363
-    /**
1364
-     * Returns the prefix that should be used on child of this form section for
1365
-     * their html names. If this form section itself has a parent, prepends ITS
1366
-     * prefix onto this form section's prefix. Used primarily by
1367
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
-     *
1369
-     * @return string
1370
-     * @throws EE_Error
1371
-     */
1372
-    public function html_name_prefix()
1373
-    {
1374
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
-        }
1377
-        return $this->name();
1378
-    }
1379
-
1380
-
1381
-    /**
1382
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1383
-     * calls it (assumes there is no parent and that we want the name to be whatever
1384
-     * was set, which is probably nothing, or the classname)
1385
-     *
1386
-     * @return string
1387
-     * @throws EE_Error
1388
-     */
1389
-    public function name()
1390
-    {
1391
-        $this->ensure_construct_finalized_called();
1392
-        return parent::name();
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * @return EE_Form_Section_Proper
1398
-     * @throws EE_Error
1399
-     */
1400
-    public function parent_section()
1401
-    {
1402
-        $this->ensure_construct_finalized_called();
1403
-        return parent::parent_section();
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * make sure construction finalized was called, otherwise children might not be ready
1409
-     *
1410
-     * @return void
1411
-     * @throws EE_Error
1412
-     */
1413
-    public function ensure_construct_finalized_called()
1414
-    {
1415
-        if (! $this->_construction_finalized) {
1416
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1417
-        }
1418
-    }
1419
-
1420
-
1421
-    /**
1422
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1423
-     * are in teh form data. If any are found, returns true. Else false
1424
-     *
1425
-     * @param array $req_data
1426
-     * @return boolean
1427
-     * @throws EE_Error
1428
-     */
1429
-    public function form_data_present_in($req_data = null)
1430
-    {
1431
-        $req_data = $this->getCachedRequest($req_data);
1432
-        foreach ($this->subsections() as $subsection) {
1433
-            if ($subsection instanceof EE_Form_Input_Base) {
1434
-                if ($subsection->form_data_present_in($req_data)) {
1435
-                    return true;
1436
-                }
1437
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
-                if ($subsection->form_data_present_in($req_data)) {
1439
-                    return true;
1440
-                }
1441
-            }
1442
-        }
1443
-        return false;
1444
-    }
1445
-
1446
-
1447
-    /**
1448
-     * Gets validation errors for this form section and subsections
1449
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
-     * gets the validation errors for ALL subsection
1451
-     *
1452
-     * @return EE_Validation_Error[]
1453
-     * @throws EE_Error
1454
-     */
1455
-    public function get_validation_errors_accumulated()
1456
-    {
1457
-        $validation_errors = $this->get_validation_errors();
1458
-        foreach ($this->get_validatable_subsections() as $subsection) {
1459
-            if ($subsection instanceof EE_Form_Section_Proper) {
1460
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
-            } else {
1462
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
-            }
1464
-            if ($validation_errors_on_this_subsection) {
1465
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
-            }
1467
-        }
1468
-        return $validation_errors;
1469
-    }
1470
-
1471
-    /**
1472
-     * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
-     * This traverses the form section tree to generate this, but you probably want to instead use
1474
-     * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
-     *
1476
-     * @return string
1477
-     * @since $VID:$
1478
-     */
1479
-    protected function getAllValidationErrorsString()
1480
-    {
1481
-        $submission_error_messages = array();
1482
-        // bad, bad, bad registrant
1483
-        foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
-            if ($validation_error instanceof EE_Validation_Error) {
1485
-                $form_section = $validation_error->get_form_section();
1486
-                if ($form_section instanceof EE_Form_Input_Base) {
1487
-                   $label = $validation_error->get_form_section()->html_label_text();
1488
-                } elseif($form_section instanceof EE_Form_Section_Validatable) {
1489
-                    $label = $validation_error->get_form_section()->name();
1490
-                } else {
1491
-                    $label = esc_html__('Unknown', 'event_espresso');
1492
-                }
1493
-                $submission_error_messages[] = sprintf(
1494
-                    __('%s : %s', 'event_espresso'),
1495
-                    $label,
1496
-                    $validation_error->getMessage()
1497
-                );
1498
-            }
1499
-        }
1500
-        return implode('<br', $submission_error_messages);
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * This isn't just the name of an input, it's a path pointing to an input. The
1506
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
-     * dot-dot-slash (../) means to ascend into the parent section.
1508
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
-     * which will be returned.
1510
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
-     * Etc
1515
-     *
1516
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
-     * @return EE_Form_Section_Base
1518
-     * @throws EE_Error
1519
-     */
1520
-    public function find_section_from_path($form_section_path)
1521
-    {
1522
-        //check if we can find the input from purely going straight up the tree
1523
-        $input = parent::find_section_from_path($form_section_path);
1524
-        if ($input instanceof EE_Form_Section_Base) {
1525
-            return $input;
1526
-        }
1527
-        $next_slash_pos = strpos($form_section_path, '/');
1528
-        if ($next_slash_pos !== false) {
1529
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
-            $subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
-        } else {
1532
-            $child_section_name = $form_section_path;
1533
-            $subpath            = '';
1534
-        }
1535
-        $child_section = $this->get_subsection($child_section_name);
1536
-        if ($child_section instanceof EE_Form_Section_Base) {
1537
-            return $child_section->find_section_from_path($subpath);
1538
-        }
1539
-        return null;
1540
-    }
17
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
+
19
+	/**
20
+	 * Subsections
21
+	 *
22
+	 * @var EE_Form_Section_Validatable[]
23
+	 */
24
+	protected $_subsections = array();
25
+
26
+	/**
27
+	 * Strategy for laying out the form
28
+	 *
29
+	 * @var EE_Form_Section_Layout_Base
30
+	 */
31
+	protected $_layout_strategy;
32
+
33
+	/**
34
+	 * Whether or not this form has received and validated a form submission yet
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_received_submission = false;
39
+
40
+	/**
41
+	 * message displayed to users upon successful form submission
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_form_submission_success_message = '';
46
+
47
+	/**
48
+	 * message displayed to users upon unsuccessful form submission
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_form_submission_error_message = '';
53
+
54
+	/**
55
+	 * @var array like $_REQUEST
56
+	 */
57
+	protected $cached_request_data;
58
+
59
+	/**
60
+	 * Stores whether this form (and its sub-sections) were found to be valid or not.
61
+	 * Starts off as null, but once the form is validated, it set to either true or false
62
+	 * @var boolean|null
63
+	 */
64
+	protected $is_valid;
65
+
66
+	/**
67
+	 * Stores all the data that will localized for form validation
68
+	 *
69
+	 * @var array
70
+	 */
71
+	static protected $_js_localization = array();
72
+
73
+	/**
74
+	 * whether or not the form's localized validation JS vars have been set
75
+	 *
76
+	 * @type boolean
77
+	 */
78
+	static protected $_scripts_localized = false;
79
+
80
+
81
+	/**
82
+	 * when constructing a proper form section, calls _construct_finalize on children
83
+	 * so that they know who their parent is, and what name they've been given.
84
+	 *
85
+	 * @param array[] $options_array   {
86
+	 * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
+	 * @type          $include         string[] numerically-indexed where values are section names to be included,
88
+	 *                                 and in that order. This is handy if you want
89
+	 *                                 the subsections to be ordered differently than the default, and if you override
90
+	 *                                 which fields are shown
91
+	 * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
+	 *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
+	 *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
+	 *                                 items from that list of inclusions)
95
+	 * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
+	 *                                 } @see EE_Form_Section_Validatable::__construct()
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		$options_array = (array) apply_filters(
102
+			'FHEE__EE_Form_Section_Proper___construct__options_array',
103
+			$options_array,
104
+			$this
105
+		);
106
+		//call parent first, as it may be setting the name
107
+		parent::__construct($options_array);
108
+		//if they've included subsections in the constructor, add them now
109
+		if (isset($options_array['include'])) {
110
+			//we are going to make sure we ONLY have those subsections to include
111
+			//AND we are going to make sure they're in that specified order
112
+			$reordered_subsections = array();
113
+			foreach ($options_array['include'] as $input_name) {
114
+				if (isset($this->_subsections[ $input_name ])) {
115
+					$reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
+				}
117
+			}
118
+			$this->_subsections = $reordered_subsections;
119
+		}
120
+		if (isset($options_array['exclude'])) {
121
+			$exclude            = $options_array['exclude'];
122
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
+		}
124
+		if (isset($options_array['layout_strategy'])) {
125
+			$this->_layout_strategy = $options_array['layout_strategy'];
126
+		}
127
+		if (! $this->_layout_strategy) {
128
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
+		}
130
+		$this->_layout_strategy->_construct_finalize($this);
131
+		//ok so we are definitely going to want the forms JS,
132
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
+			//ok so they've constructed this object after when they should have.
135
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
136
+			EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
+		} else {
138
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
+		}
141
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
+		/**
143
+		 * Gives other plugins a chance to hook in before construct finalize is called.
144
+		 * The form probably doesn't yet have a parent form section.
145
+		 * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
+		 * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
+		 *
149
+		 * @since 4.9.32
150
+		 * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
+		 *                                              except maybe calling _construct_finalize has been done
152
+		 * @param array                  $options_array options passed into the constructor
153
+		 */
154
+		do_action(
155
+			'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
+			$this,
157
+			$options_array
158
+		);
159
+		if (isset($options_array['name'])) {
160
+			$this->_construct_finalize(null, $options_array['name']);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Finishes construction given the parent form section and this form section's name
167
+	 *
168
+	 * @param EE_Form_Section_Proper $parent_form_section
169
+	 * @param string                 $name
170
+	 * @throws EE_Error
171
+	 */
172
+	public function _construct_finalize($parent_form_section, $name)
173
+	{
174
+		parent::_construct_finalize($parent_form_section, $name);
175
+		$this->_set_default_name_if_empty();
176
+		$this->_set_default_html_id_if_empty();
177
+		foreach ($this->_subsections as $subsection_name => $subsection) {
178
+			if ($subsection instanceof EE_Form_Section_Base) {
179
+				$subsection->_construct_finalize($this, $subsection_name);
180
+			} else {
181
+				throw new EE_Error(
182
+					sprintf(
183
+						esc_html__(
184
+							'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
+							'event_espresso'
186
+						),
187
+						$subsection_name,
188
+						get_class($this),
189
+						$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
+					)
191
+				);
192
+			}
193
+		}
194
+		/**
195
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
+		 * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
199
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
+		 * ensured it has a name, HTML IDs, etc
201
+		 *
202
+		 * @param EE_Form_Section_Proper      $this
203
+		 * @param EE_Form_Section_Proper|null $parent_form_section
204
+		 * @param string                      $name
205
+		 */
206
+		do_action(
207
+			'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
+			$this,
209
+			$parent_form_section,
210
+			$name
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the layout strategy for this form section
217
+	 *
218
+	 * @return EE_Form_Section_Layout_Base
219
+	 */
220
+	public function get_layout_strategy()
221
+	{
222
+		return $this->_layout_strategy;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the HTML for a single input for this form section according
228
+	 * to the layout strategy
229
+	 *
230
+	 * @param EE_Form_Input_Base $input
231
+	 * @return string
232
+	 */
233
+	public function get_html_for_input($input)
234
+	{
235
+		return $this->_layout_strategy->layout_input($input);
236
+	}
237
+
238
+
239
+	/**
240
+	 * was_submitted - checks if form inputs are present in request data
241
+	 * Basically an alias for form_data_present_in() (which is used by both
242
+	 * proper form sections and form inputs)
243
+	 *
244
+	 * @param null $form_data
245
+	 * @return boolean
246
+	 * @throws EE_Error
247
+	 */
248
+	public function was_submitted($form_data = null)
249
+	{
250
+		return $this->form_data_present_in($form_data);
251
+	}
252
+
253
+	/**
254
+	 * Gets the cached request data; but if there is none, or $req_data was set with
255
+	 * something different, refresh the cache, and then return it
256
+	 * @param null $req_data
257
+	 * @return array
258
+	 */
259
+	protected function getCachedRequest($req_data = null)
260
+	{
261
+		if ($this->cached_request_data === null
262
+			|| (
263
+				$req_data !== null &&
264
+				$req_data !== $this->cached_request_data
265
+			)
266
+		) {
267
+			$req_data = apply_filters(
268
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
+				$req_data,
270
+				$this
271
+			);
272
+			if ($req_data === null) {
273
+				$req_data = array_merge($_GET, $_POST);
274
+			}
275
+			$req_data = apply_filters(
276
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
+				$req_data,
278
+				$this
279
+			);
280
+			$this->cached_request_data = (array)$req_data;
281
+		}
282
+		return $this->cached_request_data;
283
+	}
284
+
285
+
286
+	/**
287
+	 * After the form section is initially created, call this to sanitize the data in the submission
288
+	 * which relates to this form section, validate it, and set it as properties on the form.
289
+	 *
290
+	 * @param array|null $req_data should usually be $_POST (the default).
291
+	 *                             However, you CAN supply a different array.
292
+	 *                             Consider using set_defaults() instead however.
293
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
294
+	 *                             the inputs will have the correct name in the request data for this function
295
+	 *                             to find them and populate the form with them.
296
+	 *                             If you have a flat form (with only input subsections),
297
+	 *                             you can supply a flat array where keys
298
+	 *                             are the form input names and values are their values)
299
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
+	 *                             of course, to validate that data, and set errors on the invalid values.
301
+	 *                             But if the data has already been validated
302
+	 *                             (eg you validated the data then stored it in the DB)
303
+	 *                             you may want to skip this step.
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws EE_Error
308
+	 */
309
+	public function receive_form_submission($req_data = null, $validate = true)
310
+	{
311
+		$req_data = $this->getCachedRequest($req_data);
312
+		$this->_normalize($req_data);
313
+		if ($validate) {
314
+			$this->_validate();
315
+			//if it's invalid, we're going to want to re-display so remember what they submitted
316
+			if (! $this->is_valid()) {
317
+				$this->store_submitted_form_data_in_session();
318
+			}
319
+		}
320
+		if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
+			$this->set_submission_error_message();
322
+		}
323
+		do_action(
324
+			'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
+			$req_data,
326
+			$this,
327
+			$validate
328
+		);
329
+	}
330
+
331
+
332
+	/**
333
+	 * caches the originally submitted input values in the session
334
+	 * so that they can be used to repopulate the form if it failed validation
335
+	 *
336
+	 * @return boolean whether or not the data was successfully stored in the session
337
+	 * @throws InvalidArgumentException
338
+	 * @throws InvalidInterfaceException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws EE_Error
341
+	 */
342
+	protected function store_submitted_form_data_in_session()
343
+	{
344
+		return EE_Registry::instance()->SSN->set_session_data(
345
+			array(
346
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
+			)
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * retrieves the originally submitted input values in the session
354
+	 * so that they can be used to repopulate the form if it failed validation
355
+	 *
356
+	 * @return array
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	protected function get_submitted_form_data_from_session()
362
+	{
363
+		$session = EE_Registry::instance()->SSN;
364
+		if ($session instanceof EE_Session) {
365
+			return $session->get_session_data(
366
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
+			);
368
+		}
369
+		return array();
370
+	}
371
+
372
+
373
+	/**
374
+	 * flushed the originally submitted input values from the session
375
+	 *
376
+	 * @return boolean whether or not the data was successfully removed from the session
377
+	 * @throws InvalidArgumentException
378
+	 * @throws InvalidInterfaceException
379
+	 * @throws InvalidDataTypeException
380
+	 */
381
+	protected function flush_submitted_form_data_from_session()
382
+	{
383
+		return EE_Registry::instance()->SSN->reset_data(
384
+			array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Populates this form and its subsections with data from the session.
391
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
+	 * validation errors when displaying too)
393
+	 * Returns true if the form was populated from the session, false otherwise
394
+	 *
395
+	 * @return boolean
396
+	 * @throws InvalidArgumentException
397
+	 * @throws InvalidInterfaceException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws EE_Error
400
+	 */
401
+	public function populate_from_session()
402
+	{
403
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
404
+		if (empty($form_data_in_session)) {
405
+			return false;
406
+		}
407
+		$this->receive_form_submission($form_data_in_session);
408
+		$this->flush_submitted_form_data_from_session();
409
+		if ($this->form_data_present_in($form_data_in_session)) {
410
+			return true;
411
+		}
412
+		return false;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Populates the default data for the form, given an array where keys are
418
+	 * the input names, and values are their values (preferably normalized to be their
419
+	 * proper PHP types, not all strings... although that should be ok too).
420
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
421
+	 * the value being an array formatted in teh same way
422
+	 *
423
+	 * @param array $default_data
424
+	 * @throws EE_Error
425
+	 */
426
+	public function populate_defaults($default_data)
427
+	{
428
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
+			if (isset($default_data[ $subsection_name ])) {
430
+				if ($subsection instanceof EE_Form_Input_Base) {
431
+					$subsection->set_default($default_data[ $subsection_name ]);
432
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
433
+					$subsection->populate_defaults($default_data[ $subsection_name ]);
434
+				}
435
+			}
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * returns true if subsection exists
442
+	 *
443
+	 * @param string $name
444
+	 * @return boolean
445
+	 */
446
+	public function subsection_exists($name)
447
+	{
448
+		return isset($this->_subsections[ $name ]) ? true : false;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Gets the subsection specified by its name
454
+	 *
455
+	 * @param string  $name
456
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
+	 *                                                      so that the inputs will be properly configured.
458
+	 *                                                      However, some client code may be ok
459
+	 *                                                      with construction finalize being called later
460
+	 *                                                      (realizing that the subsections' html names
461
+	 *                                                      might not be set yet, etc.)
462
+	 * @return EE_Form_Section_Base
463
+	 * @throws EE_Error
464
+	 */
465
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
466
+	{
467
+		if ($require_construction_to_be_finalized) {
468
+			$this->ensure_construct_finalized_called();
469
+		}
470
+		return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
+	}
472
+
473
+
474
+	/**
475
+	 * Gets all the validatable subsections of this form section
476
+	 *
477
+	 * @return EE_Form_Section_Validatable[]
478
+	 * @throws EE_Error
479
+	 */
480
+	public function get_validatable_subsections()
481
+	{
482
+		$validatable_subsections = array();
483
+		foreach ($this->subsections() as $name => $obj) {
484
+			if ($obj instanceof EE_Form_Section_Validatable) {
485
+				$validatable_subsections[ $name ] = $obj;
486
+			}
487
+		}
488
+		return $validatable_subsections;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
+	 * throw an EE_Error.
495
+	 *
496
+	 * @param string  $name
497
+	 * @param boolean $require_construction_to_be_finalized most client code should
498
+	 *                                                      leave this as TRUE so that the inputs will be properly
499
+	 *                                                      configured. However, some client code may be ok with
500
+	 *                                                      construction finalize being called later
501
+	 *                                                      (realizing that the subsections' html names might not be
502
+	 *                                                      set yet, etc.)
503
+	 * @return EE_Form_Input_Base
504
+	 * @throws EE_Error
505
+	 */
506
+	public function get_input($name, $require_construction_to_be_finalized = true)
507
+	{
508
+		$subsection = $this->get_subsection(
509
+			$name,
510
+			$require_construction_to_be_finalized
511
+		);
512
+		if (! $subsection instanceof EE_Form_Input_Base) {
513
+			throw new EE_Error(
514
+				sprintf(
515
+					esc_html__(
516
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
+						'event_espresso'
518
+					),
519
+					$name,
520
+					get_class($this),
521
+					$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
+				)
523
+			);
524
+		}
525
+		return $subsection;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Like get_input(), gets the proper subsection of the form given the name,
531
+	 * otherwise throws an EE_Error
532
+	 *
533
+	 * @param string  $name
534
+	 * @param boolean $require_construction_to_be_finalized most client code should
535
+	 *                                                      leave this as TRUE so that the inputs will be properly
536
+	 *                                                      configured. However, some client code may be ok with
537
+	 *                                                      construction finalize being called later
538
+	 *                                                      (realizing that the subsections' html names might not be
539
+	 *                                                      set yet, etc.)
540
+	 * @return EE_Form_Section_Proper
541
+	 * @throws EE_Error
542
+	 */
543
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
+	{
545
+		$subsection = $this->get_subsection(
546
+			$name,
547
+			$require_construction_to_be_finalized
548
+		);
549
+		if (! $subsection instanceof EE_Form_Section_Proper) {
550
+			throw new EE_Error(
551
+				sprintf(
552
+					esc_html__(
553
+						"Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
+						'event_espresso'
555
+					),
556
+					$name,
557
+					get_class($this)
558
+				)
559
+			);
560
+		}
561
+		return $subsection;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
567
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
568
+	 *
569
+	 * @param string $name
570
+	 * @return mixed depending on the input's type and its normalization strategy
571
+	 * @throws EE_Error
572
+	 */
573
+	public function get_input_value($name)
574
+	{
575
+		$input = $this->get_input($name);
576
+		return $input->normalized_value();
577
+	}
578
+
579
+
580
+	/**
581
+	 * Checks if this form section itself is valid, and then checks its subsections
582
+	 *
583
+	 * @throws EE_Error
584
+	 * @return boolean
585
+	 */
586
+	public function is_valid()
587
+	{
588
+		if($this->is_valid === null) {
589
+			if (! $this->has_received_submission()) {
590
+				throw new EE_Error(
591
+					sprintf(
592
+						esc_html__(
593
+							'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
+							'event_espresso'
595
+						)
596
+					)
597
+				);
598
+			}
599
+			if (! parent::is_valid()) {
600
+				$this->is_valid = false;
601
+			} else {
602
+				// ok so no general errors to this entire form section.
603
+				// so let's check the subsections, but only set errors if that hasn't been done yet
604
+				$this->is_valid = true;
605
+				foreach ($this->get_validatable_subsections() as $subsection) {
606
+					if (! $subsection->is_valid()) {
607
+						$this->is_valid = false;
608
+					}
609
+				}
610
+			}
611
+		}
612
+		return $this->is_valid;
613
+	}
614
+
615
+
616
+	/**
617
+	 * gets the default name of this form section if none is specified
618
+	 *
619
+	 * @return void
620
+	 */
621
+	protected function _set_default_name_if_empty()
622
+	{
623
+		if (! $this->_name) {
624
+			$classname    = get_class($this);
625
+			$default_name = str_replace('EE_', '', $classname);
626
+			$this->_name  = $default_name;
627
+		}
628
+	}
629
+
630
+
631
+	/**
632
+	 * Returns the HTML for the form, except for the form opening and closing tags
633
+	 * (as the form section doesn't know where you necessarily want to send the information to),
634
+	 * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
637
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
+	 * any CSS.
639
+	 *
640
+	 * @throws InvalidArgumentException
641
+	 * @throws InvalidInterfaceException
642
+	 * @throws InvalidDataTypeException
643
+	 * @throws EE_Error
644
+	 */
645
+	public function get_html_and_js()
646
+	{
647
+		$this->enqueue_js();
648
+		return $this->get_html();
649
+	}
650
+
651
+
652
+	/**
653
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
+	 *
655
+	 * @param bool $display_previously_submitted_data
656
+	 * @return string
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws EE_Error
661
+	 * @throws EE_Error
662
+	 * @throws EE_Error
663
+	 */
664
+	public function get_html($display_previously_submitted_data = true)
665
+	{
666
+		$this->ensure_construct_finalized_called();
667
+		if ($display_previously_submitted_data) {
668
+			$this->populate_from_session();
669
+		}
670
+		return $this->_form_html_filter
671
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
+			: $this->_layout_strategy->layout_form();
673
+	}
674
+
675
+
676
+	/**
677
+	 * enqueues JS and CSS for the form.
678
+	 * It is preferred to call this before wp_enqueue_scripts so the
679
+	 * scripts and styles can be put in the header, but if called later
680
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
+	 * only be in the header; but in HTML5 its ok in the body.
682
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
+	 *
685
+	 * @return void
686
+	 * @throws EE_Error
687
+	 */
688
+	public function enqueue_js()
689
+	{
690
+		$this->_enqueue_and_localize_form_js();
691
+		foreach ($this->subsections() as $subsection) {
692
+			$subsection->enqueue_js();
693
+		}
694
+	}
695
+
696
+
697
+	/**
698
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
+	 * the wp_enqueue_scripts hook.
701
+	 * However, registering the form js and localizing it can happen when we
702
+	 * actually output the form (which is preferred, seeing how teh form's fields
703
+	 * could change until it's actually outputted)
704
+	 *
705
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
+	 *                                                    to be triggered automatically or not
707
+	 * @return void
708
+	 */
709
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
+	{
711
+		wp_register_script(
712
+			'ee_form_section_validation',
713
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
714
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
+			EVENT_ESPRESSO_VERSION,
716
+			true
717
+		);
718
+		wp_localize_script(
719
+			'ee_form_section_validation',
720
+			'ee_form_section_validation_init',
721
+			array('init' => $init_form_validation_automatically ? '1' : '0')
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * gets the variables used by form_section_validation.js.
728
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
+	 * but before the wordpress hook wp_loaded
730
+	 *
731
+	 * @throws EE_Error
732
+	 */
733
+	public function _enqueue_and_localize_form_js()
734
+	{
735
+		$this->ensure_construct_finalized_called();
736
+		//actually, we don't want to localize just yet. There may be other forms on the page.
737
+		//so we need to add our form section data to a static variable accessible by all form sections
738
+		//and localize it just before the footer
739
+		$this->localize_validation_rules();
740
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
+	}
743
+
744
+
745
+	/**
746
+	 * add our form section data to a static variable accessible by all form sections
747
+	 *
748
+	 * @param bool $return_for_subsection
749
+	 * @return void
750
+	 * @throws EE_Error
751
+	 */
752
+	public function localize_validation_rules($return_for_subsection = false)
753
+	{
754
+		// we only want to localize vars ONCE for the entire form,
755
+		// so if the form section doesn't have a parent, then it must be the top dog
756
+		if ($return_for_subsection || ! $this->parent_section()) {
757
+			EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
+				'form_section_id'  => $this->html_id(true),
759
+				'validation_rules' => $this->get_jquery_validation_rules(),
760
+				'other_data'       => $this->get_other_js_data(),
761
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
762
+			);
763
+			EE_Form_Section_Proper::$_scripts_localized                                = true;
764
+		}
765
+	}
766
+
767
+
768
+	/**
769
+	 * Gets an array of extra data that will be useful for client-side javascript.
770
+	 * This is primarily data added by inputs and forms in addition to any
771
+	 * scripts they might enqueue
772
+	 *
773
+	 * @param array $form_other_js_data
774
+	 * @return array
775
+	 * @throws EE_Error
776
+	 */
777
+	public function get_other_js_data($form_other_js_data = array())
778
+	{
779
+		foreach ($this->subsections() as $subsection) {
780
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
+		}
782
+		return $form_other_js_data;
783
+	}
784
+
785
+
786
+	/**
787
+	 * Gets a flat array of inputs for this form section and its subsections.
788
+	 * Keys are their form names, and values are the inputs themselves
789
+	 *
790
+	 * @return EE_Form_Input_Base
791
+	 * @throws EE_Error
792
+	 */
793
+	public function inputs_in_subsections()
794
+	{
795
+		$inputs = array();
796
+		foreach ($this->subsections() as $subsection) {
797
+			if ($subsection instanceof EE_Form_Input_Base) {
798
+				$inputs[ $subsection->html_name() ] = $subsection;
799
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
800
+				$inputs += $subsection->inputs_in_subsections();
801
+			}
802
+		}
803
+		return $inputs;
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets a flat array of all the validation errors.
809
+	 * Keys are html names (because those should be unique)
810
+	 * and values are a string of all their validation errors
811
+	 *
812
+	 * @return string[]
813
+	 * @throws EE_Error
814
+	 */
815
+	public function subsection_validation_errors_by_html_name()
816
+	{
817
+		$inputs = $this->inputs();
818
+		$errors = array();
819
+		foreach ($inputs as $form_input) {
820
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
+				$errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
+			}
823
+		}
824
+		return $errors;
825
+	}
826
+
827
+
828
+	/**
829
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
831
+	 *
832
+	 * @throws InvalidArgumentException
833
+	 * @throws InvalidInterfaceException
834
+	 * @throws InvalidDataTypeException
835
+	 */
836
+	public static function localize_script_for_all_forms()
837
+	{
838
+		//allow inputs and stuff to hook in their JS and stuff here
839
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
+			? EE_Registry::instance()->CFG->registration->email_validation_level
843
+			: 'wp_default';
844
+		EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
+		wp_enqueue_script('ee_form_section_validation');
846
+		wp_localize_script(
847
+			'ee_form_section_validation',
848
+			'ee_form_section_vars',
849
+			EE_Form_Section_Proper::$_js_localization
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * ensure_scripts_localized
856
+	 *
857
+	 * @throws EE_Error
858
+	 */
859
+	public function ensure_scripts_localized()
860
+	{
861
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
862
+			$this->_enqueue_and_localize_form_js();
863
+		}
864
+	}
865
+
866
+
867
+	/**
868
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
869
+	 * is that the key here should be the same as the custom validation rule put in the JS file
870
+	 *
871
+	 * @return array keys are custom validation rules, and values are internationalized strings
872
+	 */
873
+	private static function _get_localized_error_messages()
874
+	{
875
+		return array(
876
+			'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
+			'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
+		);
879
+	}
880
+
881
+
882
+	/**
883
+	 * @return array
884
+	 */
885
+	public static function js_localization()
886
+	{
887
+		return self::$_js_localization;
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return void
893
+	 */
894
+	public static function reset_js_localization()
895
+	{
896
+		self::$_js_localization = array();
897
+	}
898
+
899
+
900
+	/**
901
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
+	 * See parent function for more...
903
+	 *
904
+	 * @return array
905
+	 * @throws EE_Error
906
+	 */
907
+	public function get_jquery_validation_rules()
908
+	{
909
+		$jquery_validation_rules = array();
910
+		foreach ($this->get_validatable_subsections() as $subsection) {
911
+			$jquery_validation_rules = array_merge(
912
+				$jquery_validation_rules,
913
+				$subsection->get_jquery_validation_rules()
914
+			);
915
+		}
916
+		return $jquery_validation_rules;
917
+	}
918
+
919
+
920
+	/**
921
+	 * Sanitizes all the data and sets the sanitized value of each field
922
+	 *
923
+	 * @param array $req_data like $_POST
924
+	 * @return void
925
+	 * @throws EE_Error
926
+	 */
927
+	protected function _normalize($req_data)
928
+	{
929
+		$this->_received_submission = true;
930
+		$this->_validation_errors   = array();
931
+		foreach ($this->get_validatable_subsections() as $subsection) {
932
+			try {
933
+				$subsection->_normalize($req_data);
934
+			} catch (EE_Validation_Error $e) {
935
+				$subsection->add_validation_error($e);
936
+			}
937
+		}
938
+	}
939
+
940
+
941
+	/**
942
+	 * Performs validation on this form section and its subsections.
943
+	 * For each subsection,
944
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
945
+	 * and passes it the subsection, then calls _validate on that subsection.
946
+	 * If you need to perform validation on the form as a whole (considering multiple)
947
+	 * you would be best to override this _validate method,
948
+	 * calling parent::_validate() first.
949
+	 *
950
+	 * @throws EE_Error
951
+	 */
952
+	protected function _validate()
953
+	{
954
+		//reset the cache of whether this form is valid or not- we're re-validating it now
955
+		$this->is_valid = null;
956
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
+			if (method_exists($this, '_validate_' . $subsection_name)) {
958
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
+			}
960
+			$subsection->_validate();
961
+		}
962
+	}
963
+
964
+
965
+	/**
966
+	 * Gets all the validated inputs for the form section
967
+	 *
968
+	 * @return array
969
+	 * @throws EE_Error
970
+	 */
971
+	public function valid_data()
972
+	{
973
+		$inputs = array();
974
+		foreach ($this->subsections() as $subsection_name => $subsection) {
975
+			if ($subsection instanceof EE_Form_Section_Proper) {
976
+				$inputs[ $subsection_name ] = $subsection->valid_data();
977
+			} elseif ($subsection instanceof EE_Form_Input_Base) {
978
+				$inputs[ $subsection_name ] = $subsection->normalized_value();
979
+			}
980
+		}
981
+		return $inputs;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Gets all the inputs on this form section
987
+	 *
988
+	 * @return EE_Form_Input_Base[]
989
+	 * @throws EE_Error
990
+	 */
991
+	public function inputs()
992
+	{
993
+		$inputs = array();
994
+		foreach ($this->subsections() as $subsection_name => $subsection) {
995
+			if ($subsection instanceof EE_Form_Input_Base) {
996
+				$inputs[ $subsection_name ] = $subsection;
997
+			}
998
+		}
999
+		return $inputs;
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * Gets all the subsections which are a proper form
1005
+	 *
1006
+	 * @return EE_Form_Section_Proper[]
1007
+	 * @throws EE_Error
1008
+	 */
1009
+	public function subforms()
1010
+	{
1011
+		$form_sections = array();
1012
+		foreach ($this->subsections() as $name => $obj) {
1013
+			if ($obj instanceof EE_Form_Section_Proper) {
1014
+				$form_sections[ $name ] = $obj;
1015
+			}
1016
+		}
1017
+		return $form_sections;
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
+	 * Consider using inputs() or subforms()
1024
+	 * if you only want form inputs or proper form sections.
1025
+	 *
1026
+	 * @param boolean $require_construction_to_be_finalized most client code should
1027
+	 *                                                      leave this as TRUE so that the inputs will be properly
1028
+	 *                                                      configured. However, some client code may be ok with
1029
+	 *                                                      construction finalize being called later
1030
+	 *                                                      (realizing that the subsections' html names might not be
1031
+	 *                                                      set yet, etc.)
1032
+	 * @return EE_Form_Section_Proper[]
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	public function subsections($require_construction_to_be_finalized = true)
1036
+	{
1037
+		if ($require_construction_to_be_finalized) {
1038
+			$this->ensure_construct_finalized_called();
1039
+		}
1040
+		return $this->_subsections;
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * Returns whether this form has any subforms or inputs
1046
+	 * @return bool
1047
+	 */
1048
+	public function hasSubsections()
1049
+	{
1050
+		return ! empty($this->_subsections);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * Returns a simple array where keys are input names, and values are their normalized
1056
+	 * values. (Similar to calling get_input_value on inputs)
1057
+	 *
1058
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
+	 *                                        or just this forms' direct children inputs
1060
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
+	 *                                        or allow multidimensional array
1062
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
+	 *                                        with array keys being input names
1064
+	 *                                        (regardless of whether they are from a subsection or not),
1065
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1066
+	 *                                        where keys are always subsection names and values are either
1067
+	 *                                        the input's normalized value, or an array like the top-level array
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function input_values($include_subform_inputs = false, $flatten = false)
1071
+	{
1072
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
+	 * is not necessarily the value we want to display to users. This creates an array
1080
+	 * where keys are the input names, and values are their display values
1081
+	 *
1082
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
+	 *                                        or just this forms' direct children inputs
1084
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
+	 *                                        or allow multidimensional array
1086
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
+	 *                                        with array keys being input names
1088
+	 *                                        (regardless of whether they are from a subsection or not),
1089
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1090
+	 *                                        where keys are always subsection names and values are either
1091
+	 *                                        the input's normalized value, or an array like the top-level array
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
+	{
1096
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * Gets the input values from the form
1102
+	 *
1103
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
+	 *                                        or just the normalized value
1105
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
+	 *                                        or just this forms' direct children inputs
1107
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
+	 *                                        or allow multidimensional array
1109
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
+	 *                                        input names (regardless of whether they are from a subsection or not),
1111
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1112
+	 *                                        where keys are always subsection names and values are either
1113
+	 *                                        the input's normalized value, or an array like the top-level array
1114
+	 * @throws EE_Error
1115
+	 */
1116
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
+	{
1118
+		$input_values = array();
1119
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1120
+			if ($subsection instanceof EE_Form_Input_Base) {
1121
+				$input_values[ $subsection_name ] = $pretty
1122
+					? $subsection->pretty_value()
1123
+					: $subsection->normalized_value();
1124
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
+				$subform_input_values = $subsection->_input_values(
1126
+					$pretty,
1127
+					$include_subform_inputs,
1128
+					$flatten
1129
+				);
1130
+				if ($flatten) {
1131
+					$input_values = array_merge($input_values, $subform_input_values);
1132
+				} else {
1133
+					$input_values[ $subsection_name ] = $subform_input_values;
1134
+				}
1135
+			}
1136
+		}
1137
+		return $input_values;
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Gets the originally submitted input values from the form
1143
+	 *
1144
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
+	 *                                   or just this forms' direct children inputs
1146
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
+	 *                                   with array keys being input names
1148
+	 *                                   (regardless of whether they are from a subsection or not),
1149
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1150
+	 *                                   where keys are always subsection names and values are either
1151
+	 *                                   the input's normalized value, or an array like the top-level array
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function submitted_values($include_subforms = false)
1155
+	{
1156
+		$submitted_values = array();
1157
+		foreach ($this->subsections() as $subsection) {
1158
+			if ($subsection instanceof EE_Form_Input_Base) {
1159
+				// is this input part of an array of inputs?
1160
+				if (strpos($subsection->html_name(), '[') !== false) {
1161
+					$full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
+						explode(
1163
+							'[',
1164
+							str_replace(']', '', $subsection->html_name())
1165
+						),
1166
+						$subsection->raw_value()
1167
+					);
1168
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
+				} else {
1170
+					$submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
+				}
1172
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1174
+				$submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
+			}
1176
+		}
1177
+		return $submitted_values;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * Indicates whether or not this form has received a submission yet
1183
+	 * (ie, had receive_form_submission called on it yet)
1184
+	 *
1185
+	 * @return boolean
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function has_received_submission()
1189
+	{
1190
+		$this->ensure_construct_finalized_called();
1191
+		return $this->_received_submission;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1197
+	 * Removes the listed inputs from the form
1198
+	 *
1199
+	 * @param array $inputs_to_exclude values are the input names
1200
+	 * @return void
1201
+	 */
1202
+	public function exclude(array $inputs_to_exclude = array())
1203
+	{
1204
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
+			unset($this->_subsections[ $input_to_exclude_name ]);
1206
+		}
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
+	 * @param array $inputs_to_hide
1213
+	 * @throws EE_Error
1214
+	 */
1215
+	public function hide(array $inputs_to_hide = array())
1216
+	{
1217
+		foreach ($inputs_to_hide as $input_to_hide) {
1218
+			$input = $this->get_input($input_to_hide);
1219
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
+		}
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * add_subsections
1226
+	 * Adds the listed subsections to the form section.
1227
+	 * If $subsection_name_to_target is provided,
1228
+	 * then new subsections are added before or after that subsection,
1229
+	 * otherwise to the start or end of the entire subsections array.
1230
+	 *
1231
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
+	 *                                                          where keys are their names
1233
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
+	 *                                                          should be added before or after
1235
+	 *                                                          IF $subsection_name_to_target is null,
1236
+	 *                                                          then $new_subsections will be added to
1237
+	 *                                                          the beginning or end of the entire subsections array
1238
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
+	 *                                                          $subsection_name_to_target,
1240
+	 *                                                          or if $subsection_name_to_target is null,
1241
+	 *                                                          before or after entire subsections array
1242
+	 * @return void
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
+	{
1247
+		foreach ($new_subsections as $subsection_name => $subsection) {
1248
+			if (! $subsection instanceof EE_Form_Section_Base) {
1249
+				EE_Error::add_error(
1250
+					sprintf(
1251
+						esc_html__(
1252
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
+							'event_espresso'
1254
+						),
1255
+						get_class($subsection),
1256
+						$subsection_name,
1257
+						$this->name()
1258
+					)
1259
+				);
1260
+				unset($new_subsections[ $subsection_name ]);
1261
+			}
1262
+		}
1263
+		$this->_subsections = EEH_Array::insert_into_array(
1264
+			$this->_subsections,
1265
+			$new_subsections,
1266
+			$subsection_name_to_target,
1267
+			$add_before
1268
+		);
1269
+		if ($this->_construction_finalized) {
1270
+			foreach ($this->_subsections as $name => $subsection) {
1271
+				$subsection->_construct_finalize($this, $name);
1272
+			}
1273
+		}
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * @param string $subsection_name
1279
+	 * @param bool   $recursive
1280
+	 * @return bool
1281
+	 */
1282
+	public function has_subsection($subsection_name, $recursive = false)
1283
+	{
1284
+		foreach ($this->_subsections as $name => $subsection) {if(
1285
+				$name === $subsection_name
1286
+				|| (
1287
+					$recursive
1288
+					&& $subsection instanceof EE_Form_Section_Proper
1289
+					&& $subsection->has_subsection($subsection_name, $recursive)
1290
+				)
1291
+			) {
1292
+				return true;
1293
+			}
1294
+		}
1295
+		return false;
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * Just gets all validatable subsections to clean their sensitive data
1302
+	 *
1303
+	 * @throws EE_Error
1304
+	 */
1305
+	public function clean_sensitive_data()
1306
+	{
1307
+		foreach ($this->get_validatable_subsections() as $subsection) {
1308
+			$subsection->clean_sensitive_data();
1309
+		}
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
+	 * @param string                           $form_submission_error_message
1316
+	 * @param EE_Form_Section_Validatable $form_section unused
1317
+	 * @throws EE_Error
1318
+	 */
1319
+	public function set_submission_error_message(
1320
+		$form_submission_error_message = ''
1321
+	) {
1322
+		$this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
+			? $form_submission_error_message
1324
+			: $this->getAllValidationErrorsString();
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Returns the cached error message. A default value is set for this during _validate(),
1330
+	 * (called during receive_form_submission) but it can be explicitly set using
1331
+	 * set_submission_error_message
1332
+	 *
1333
+	 * @return string
1334
+	 */
1335
+	public function submission_error_message()
1336
+	{
1337
+		return $this->_form_submission_error_message;
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * Sets a message to display if the data submitted to the form was valid.
1343
+	 * @param string $form_submission_success_message
1344
+	 */
1345
+	public function set_submission_success_message($form_submission_success_message = '')
1346
+	{
1347
+		$this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
+			? $form_submission_success_message
1349
+			: esc_html__('Form submitted successfully', 'event_espresso');
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * Gets a message appropriate for display when the form is correctly submitted
1355
+	 * @return string
1356
+	 */
1357
+	public function submission_success_message()
1358
+	{
1359
+		return $this->_form_submission_success_message;
1360
+	}
1361
+
1362
+
1363
+	/**
1364
+	 * Returns the prefix that should be used on child of this form section for
1365
+	 * their html names. If this form section itself has a parent, prepends ITS
1366
+	 * prefix onto this form section's prefix. Used primarily by
1367
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
+	 *
1369
+	 * @return string
1370
+	 * @throws EE_Error
1371
+	 */
1372
+	public function html_name_prefix()
1373
+	{
1374
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
+		}
1377
+		return $this->name();
1378
+	}
1379
+
1380
+
1381
+	/**
1382
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1383
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1384
+	 * was set, which is probably nothing, or the classname)
1385
+	 *
1386
+	 * @return string
1387
+	 * @throws EE_Error
1388
+	 */
1389
+	public function name()
1390
+	{
1391
+		$this->ensure_construct_finalized_called();
1392
+		return parent::name();
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * @return EE_Form_Section_Proper
1398
+	 * @throws EE_Error
1399
+	 */
1400
+	public function parent_section()
1401
+	{
1402
+		$this->ensure_construct_finalized_called();
1403
+		return parent::parent_section();
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * make sure construction finalized was called, otherwise children might not be ready
1409
+	 *
1410
+	 * @return void
1411
+	 * @throws EE_Error
1412
+	 */
1413
+	public function ensure_construct_finalized_called()
1414
+	{
1415
+		if (! $this->_construction_finalized) {
1416
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1417
+		}
1418
+	}
1419
+
1420
+
1421
+	/**
1422
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1423
+	 * are in teh form data. If any are found, returns true. Else false
1424
+	 *
1425
+	 * @param array $req_data
1426
+	 * @return boolean
1427
+	 * @throws EE_Error
1428
+	 */
1429
+	public function form_data_present_in($req_data = null)
1430
+	{
1431
+		$req_data = $this->getCachedRequest($req_data);
1432
+		foreach ($this->subsections() as $subsection) {
1433
+			if ($subsection instanceof EE_Form_Input_Base) {
1434
+				if ($subsection->form_data_present_in($req_data)) {
1435
+					return true;
1436
+				}
1437
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
+				if ($subsection->form_data_present_in($req_data)) {
1439
+					return true;
1440
+				}
1441
+			}
1442
+		}
1443
+		return false;
1444
+	}
1445
+
1446
+
1447
+	/**
1448
+	 * Gets validation errors for this form section and subsections
1449
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
+	 * gets the validation errors for ALL subsection
1451
+	 *
1452
+	 * @return EE_Validation_Error[]
1453
+	 * @throws EE_Error
1454
+	 */
1455
+	public function get_validation_errors_accumulated()
1456
+	{
1457
+		$validation_errors = $this->get_validation_errors();
1458
+		foreach ($this->get_validatable_subsections() as $subsection) {
1459
+			if ($subsection instanceof EE_Form_Section_Proper) {
1460
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
+			} else {
1462
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
+			}
1464
+			if ($validation_errors_on_this_subsection) {
1465
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
+			}
1467
+		}
1468
+		return $validation_errors;
1469
+	}
1470
+
1471
+	/**
1472
+	 * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
+	 * This traverses the form section tree to generate this, but you probably want to instead use
1474
+	 * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
+	 *
1476
+	 * @return string
1477
+	 * @since $VID:$
1478
+	 */
1479
+	protected function getAllValidationErrorsString()
1480
+	{
1481
+		$submission_error_messages = array();
1482
+		// bad, bad, bad registrant
1483
+		foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
+			if ($validation_error instanceof EE_Validation_Error) {
1485
+				$form_section = $validation_error->get_form_section();
1486
+				if ($form_section instanceof EE_Form_Input_Base) {
1487
+				   $label = $validation_error->get_form_section()->html_label_text();
1488
+				} elseif($form_section instanceof EE_Form_Section_Validatable) {
1489
+					$label = $validation_error->get_form_section()->name();
1490
+				} else {
1491
+					$label = esc_html__('Unknown', 'event_espresso');
1492
+				}
1493
+				$submission_error_messages[] = sprintf(
1494
+					__('%s : %s', 'event_espresso'),
1495
+					$label,
1496
+					$validation_error->getMessage()
1497
+				);
1498
+			}
1499
+		}
1500
+		return implode('<br', $submission_error_messages);
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1506
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
+	 * dot-dot-slash (../) means to ascend into the parent section.
1508
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
+	 * which will be returned.
1510
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
+	 * Etc
1515
+	 *
1516
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
+	 * @return EE_Form_Section_Base
1518
+	 * @throws EE_Error
1519
+	 */
1520
+	public function find_section_from_path($form_section_path)
1521
+	{
1522
+		//check if we can find the input from purely going straight up the tree
1523
+		$input = parent::find_section_from_path($form_section_path);
1524
+		if ($input instanceof EE_Form_Section_Base) {
1525
+			return $input;
1526
+		}
1527
+		$next_slash_pos = strpos($form_section_path, '/');
1528
+		if ($next_slash_pos !== false) {
1529
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
+			$subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
+		} else {
1532
+			$child_section_name = $form_section_path;
1533
+			$subpath            = '';
1534
+		}
1535
+		$child_section = $this->get_subsection($child_section_name);
1536
+		if ($child_section instanceof EE_Form_Section_Base) {
1537
+			return $child_section->find_section_from_path($subpath);
1538
+		}
1539
+		return null;
1540
+	}
1541 1541
 }
1542 1542
 
Please login to merge, or discard this patch.
core/services/request/Request.php 3 patches
Indentation   +584 added lines, -584 removed lines patch added patch discarded remove patch
@@ -20,590 +20,590 @@
 block discarded – undo
20 20
 class Request implements InterminableInterface, RequestInterface
21 21
 {
22 22
 
23
-    /**
24
-     * $_GET parameters
25
-     *
26
-     * @var array $get
27
-     */
28
-    private $get;
29
-
30
-    /**
31
-     * $_POST parameters
32
-     *
33
-     * @var array $post
34
-     */
35
-    private $post;
36
-
37
-    /**
38
-     * $_COOKIE parameters
39
-     *
40
-     * @var array $cookie
41
-     */
42
-    private $cookie;
43
-
44
-    /**
45
-     * $_SERVER parameters
46
-     *
47
-     * @var array $server
48
-     */
49
-    private $server;
50
-
51
-    /**
52
-     * $_REQUEST parameters
53
-     *
54
-     * @var array $request
55
-     */
56
-    private $request;
57
-
58
-    /**
59
-     * @var RequestTypeContextCheckerInterface
60
-     */
61
-    private $request_type;
62
-
63
-    /**
64
-     * IP address for request
65
-     *
66
-     * @var string $ip_address
67
-     */
68
-    private $ip_address;
69
-
70
-    /**
71
-     * @var string $user_agent
72
-     */
73
-    private $user_agent;
74
-
75
-    /**
76
-     * true if current user appears to be some kind of bot
77
-     *
78
-     * @var bool $is_bot
79
-     */
80
-    private $is_bot;
81
-
82
-
83
-
84
-    /**
85
-     * @param array                              $get
86
-     * @param array                              $post
87
-     * @param array                              $cookie
88
-     * @param array                              $server
89
-     */
90
-    public function __construct(array $get, array $post, array $cookie, array $server)
91
-    {
92
-        // grab request vars
93
-        $this->get        = $get;
94
-        $this->post       = $post;
95
-        $this->cookie     = $cookie;
96
-        $this->server     = $server;
97
-        $this->request    = array_merge($this->get, $this->post);
98
-        $this->ip_address = $this->visitorIp();
99
-    }
100
-
101
-
102
-    /**
103
-     * @param RequestTypeContextCheckerInterface $type
104
-     */
105
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
106
-    {
107
-        $this->request_type = $type;
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * @return array
114
-     */
115
-    public function getParams()
116
-    {
117
-        return $this->get;
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @return array
124
-     */
125
-    public function postParams()
126
-    {
127
-        return $this->post;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return array
134
-     */
135
-    public function cookieParams()
136
-    {
137
-        return $this->cookie;
138
-    }
139
-
140
-
141
-    /**
142
-     * @return array
143
-     */
144
-    public function serverParams()
145
-    {
146
-        return $this->server;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * returns contents of $_REQUEST
153
-     *
154
-     * @return array
155
-     */
156
-    public function requestParams()
157
-    {
158
-        return $this->request;
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     * @param      $key
165
-     * @param      $value
166
-     * @param bool $override_ee
167
-     * @return    void
168
-     */
169
-    public function setRequestParam($key, $value, $override_ee = false)
170
-    {
171
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
172
-        if (
173
-            $key !== 'ee'
174
-            || ($key === 'ee' && empty($this->request['ee']))
175
-            || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
176
-        ) {
177
-            $this->request[ $key ] = $value;
178
-        }
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     * returns   the value for a request param if the given key exists
185
-     *
186
-     * @param       $key
187
-     * @param null  $default
188
-     * @return mixed
189
-     */
190
-    public function getRequestParam($key, $default = null)
191
-    {
192
-        return $this->requestParameterDrillDown($key, $default, 'get');
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * check if param exists
199
-     *
200
-     * @param       $key
201
-     * @return bool
202
-     */
203
-    public function requestParamIsSet($key)
204
-    {
205
-        return $this->requestParameterDrillDown($key);
206
-    }
207
-
208
-
209
-    /**
210
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
211
-     * and return the value for the first match found
212
-     * wildcards can be either of the following:
213
-     *      ? to represent a single character of any type
214
-     *      * to represent one or more characters of any type
215
-     *
216
-     * @param string     $pattern
217
-     * @param null|mixed $default
218
-     * @return false|int
219
-     */
220
-    public function getMatch($pattern, $default = null)
221
-    {
222
-        return $this->requestParameterDrillDown($pattern, $default, 'match');
223
-    }
224
-
225
-
226
-    /**
227
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
228
-     * wildcards can be either of the following:
229
-     *      ? to represent a single character of any type
230
-     *      * to represent one or more characters of any type
231
-     * returns true if a match is found or false if not
232
-     *
233
-     * @param string $pattern
234
-     * @return false|int
235
-     */
236
-    public function matches($pattern)
237
-    {
238
-        return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
239
-    }
240
-
241
-
242
-    /**
243
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
244
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
245
-     *                                      and used to search through the current request's parameter keys
246
-     * @param array  $request_params        The array of request parameters to search through
247
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
248
-     *                                      Default is null
249
-     * @param string $return                [optional] Controls what kind of value is returned.
250
-     *                                      Options are:
251
-     *                                      'bool' will return true or false if match is found or not
252
-     *                                      'key' will return the first key found that matches the supplied pattern
253
-     *                                      'value' will return the value for the first request parameter
254
-     *                                      whose key matches the supplied pattern
255
-     *                                      Default is 'value'
256
-     * @return boolean|string
257
-     */
258
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
259
-    {
260
-        $return = in_array($return, array('bool', 'key', 'value'), true)
261
-            ? $return
262
-            : 'is_set';
263
-        // replace wildcard chars with regex chars
264
-        $pattern = str_replace(
265
-            array("\*", "\?"),
266
-            array('.*', '.'),
267
-            preg_quote($pattern, '/')
268
-        );
269
-        foreach ($request_params as $key => $request_param) {
270
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
271
-                // return value for request param
272
-                if ($return === 'value') {
273
-                    return $request_params[ $key ];
274
-                }
275
-                // or actual key or true just to indicate it was found
276
-                return $return === 'key' ? $key : true;
277
-            }
278
-        }
279
-        // match not found so return default value or false
280
-        return $return === 'value' ? $default : false;
281
-    }
282
-
283
-
284
-    /**
285
-     * the supplied key can be a simple string to represent a "top-level" request parameter
286
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
287
-     * by using square brackets to surround keys for deeper array elements.
288
-     * For example :
289
-     * if the supplied $key was: "first[second][third]"
290
-     * then this will attempt to drill down into the request parameter array to find a value.
291
-     * Given the following request parameters:
292
-     *  array(
293
-     *      'first' => array(
294
-     *          'second' => array(
295
-     *              'third' => 'has a value'
296
-     *          )
297
-     *      )
298
-     *  )
299
-     * would return true if default parameters were set
300
-     *
301
-     * @param string $callback
302
-     * @param        $key
303
-     * @param null   $default
304
-     * @param array  $request_params
305
-     * @return bool|mixed|null
306
-     */
307
-    private function requestParameterDrillDown(
308
-        $key,
309
-        $default = null,
310
-        $callback = 'is_set',
311
-        array $request_params = array()
312
-    ) {
313
-        $callback       = in_array($callback, array('is_set', 'get', 'match'), true)
314
-            ? $callback
315
-            : 'is_set';
316
-        $request_params = ! empty($request_params)
317
-            ? $request_params
318
-            : $this->request;
319
-        // does incoming key represent an array like 'first[second][third]'  ?
320
-        if (strpos($key, '[') !== false) {
321
-            // turn it into an actual array
322
-            $key  = str_replace(']', '', $key);
323
-            $keys = explode('[', $key);
324
-            $key  = array_shift($keys);
325
-            if ($callback === 'match') {
326
-                $real_key = $this->match($key, $request_params, $default, 'key');
327
-                $key      = $real_key ? $real_key : $key;
328
-            }
329
-            // check if top level key exists
330
-            if (isset($request_params[ $key ])) {
331
-                // build a new key to pass along like: 'second[third]'
332
-                // or just 'second' depending on depth of keys
333
-                $key_string = array_shift($keys);
334
-                if (! empty($keys)) {
335
-                    $key_string .= '[' . implode('][', $keys) . ']';
336
-                }
337
-                return $this->requestParameterDrillDown(
338
-                    $key_string,
339
-                    $default,
340
-                    $callback,
341
-                    $request_params[ $key ]
342
-                );
343
-            }
344
-        }
345
-        if ($callback === 'is_set') {
346
-            return isset($request_params[ $key ]);
347
-        }
348
-        if ($callback === 'match') {
349
-            return $this->match($key, $request_params, $default);
350
-        }
351
-        return isset($request_params[ $key ])
352
-            ? $request_params[ $key ]
353
-            : $default;
354
-    }
355
-
356
-
357
-    /**
358
-     * remove param
359
-     *
360
-     * @param      $key
361
-     * @param bool $unset_from_global_too
362
-     */
363
-    public function unSetRequestParam($key, $unset_from_global_too = false)
364
-    {
365
-        unset($this->request[ $key ]);
366
-        if ($unset_from_global_too) {
367
-            unset($_REQUEST[ $key ]);
368
-        }
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * @return string
375
-     */
376
-    public function ipAddress()
377
-    {
378
-        return $this->ip_address;
379
-    }
380
-
381
-
382
-    /**
383
-     * attempt to get IP address of current visitor from server
384
-     * plz see: http://stackoverflow.com/a/2031935/1475279
385
-     *
386
-     * @access public
387
-     * @return string
388
-     */
389
-    private function visitorIp()
390
-    {
391
-        $visitor_ip  = '0.0.0.0';
392
-        $server_keys = array(
393
-            'HTTP_CLIENT_IP',
394
-            'HTTP_X_FORWARDED_FOR',
395
-            'HTTP_X_FORWARDED',
396
-            'HTTP_X_CLUSTER_CLIENT_IP',
397
-            'HTTP_FORWARDED_FOR',
398
-            'HTTP_FORWARDED',
399
-            'REMOTE_ADDR',
400
-        );
401
-        foreach ($server_keys as $key) {
402
-            if (isset($this->server[ $key ])) {
403
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
404
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
405
-                        $visitor_ip = $ip;
406
-                    }
407
-                }
408
-            }
409
-        }
410
-        return $visitor_ip;
411
-    }
412
-
413
-
414
-    /**
415
-     * @return string
416
-     */
417
-    public function requestUri()
418
-    {
419
-        $request_uri = filter_input(
420
-            INPUT_SERVER,
421
-            'REQUEST_URI',
422
-            FILTER_SANITIZE_URL,
423
-            FILTER_NULL_ON_FAILURE
424
-        );
425
-        if (empty($request_uri)) {
426
-            // fallback sanitization if the above fails
427
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
428
-        }
429
-        return $request_uri;
430
-    }
431
-
432
-
433
-    /**
434
-     * @return string
435
-     */
436
-    public function userAgent()
437
-    {
438
-        return $this->user_agent;
439
-    }
440
-
441
-
442
-    /**
443
-     * @param string $user_agent
444
-     */
445
-    public function setUserAgent($user_agent = '')
446
-    {
447
-        if ($user_agent === '' || ! is_string($user_agent)) {
448
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
449
-        }
450
-        $this->user_agent = $user_agent;
451
-    }
452
-
453
-
454
-    /**
455
-     * @return bool
456
-     */
457
-    public function isBot()
458
-    {
459
-        return $this->is_bot;
460
-    }
461
-
462
-
463
-    /**
464
-     * @param bool $is_bot
465
-     */
466
-    public function setIsBot($is_bot)
467
-    {
468
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
469
-    }
470
-
471
-
472
-    /**
473
-     * @return bool
474
-     */
475
-    public function isActivation()
476
-    {
477
-        return $this->request_type->isActivation();
478
-    }
479
-
480
-
481
-    /**
482
-     * @param $is_activation
483
-     * @return bool
484
-     */
485
-    public function setIsActivation($is_activation)
486
-    {
487
-        return $this->request_type->setIsActivation($is_activation);
488
-    }
489
-
490
-
491
-    /**
492
-     * @return bool
493
-     */
494
-    public function isAdmin()
495
-    {
496
-        return $this->request_type->isAdmin();
497
-    }
498
-
499
-
500
-    /**
501
-     * @return bool
502
-     */
503
-    public function isAdminAjax()
504
-    {
505
-        return $this->request_type->isAdminAjax();
506
-    }
507
-
508
-
509
-    /**
510
-     * @return bool
511
-     */
512
-    public function isAjax()
513
-    {
514
-        return $this->request_type->isAjax();
515
-    }
516
-
517
-
518
-    /**
519
-     * @return bool
520
-     */
521
-    public function isEeAjax()
522
-    {
523
-        return $this->request_type->isEeAjax();
524
-    }
525
-
526
-
527
-    /**
528
-     * @return bool
529
-     */
530
-    public function isOtherAjax()
531
-    {
532
-        return $this->request_type->isOtherAjax();
533
-    }
534
-
535
-
536
-    /**
537
-     * @return bool
538
-     */
539
-    public function isApi()
540
-    {
541
-        return $this->request_type->isApi();
542
-    }
543
-
544
-
545
-    /**
546
-     * @return bool
547
-     */
548
-    public function isCli()
549
-    {
550
-        return $this->request_type->isCli();
551
-    }
552
-
553
-
554
-    /**
555
-     * @return bool
556
-     */
557
-    public function isCron()
558
-    {
559
-        return $this->request_type->isCron();
560
-    }
561
-
562
-
563
-    /**
564
-     * @return bool
565
-     */
566
-    public function isFeed()
567
-    {
568
-        return $this->request_type->isFeed();
569
-    }
570
-
571
-
572
-    /**
573
-     * @return bool
574
-     */
575
-    public function isFrontend()
576
-    {
577
-        return $this->request_type->isFrontend();
578
-    }
579
-
580
-
581
-    /**
582
-     * @return bool
583
-     */
584
-    public function isFrontAjax()
585
-    {
586
-        return $this->request_type->isFrontAjax();
587
-    }
588
-
589
-
590
-
591
-    /**
592
-     * @return bool
593
-     */
594
-    public function isIframe()
595
-    {
596
-        return $this->request_type->isIframe();
597
-    }
598
-
599
-
600
-    /**
601
-     * @return string
602
-     */
603
-    public function slug()
604
-    {
605
-        return $this->request_type->slug();
606
-    }
23
+	/**
24
+	 * $_GET parameters
25
+	 *
26
+	 * @var array $get
27
+	 */
28
+	private $get;
29
+
30
+	/**
31
+	 * $_POST parameters
32
+	 *
33
+	 * @var array $post
34
+	 */
35
+	private $post;
36
+
37
+	/**
38
+	 * $_COOKIE parameters
39
+	 *
40
+	 * @var array $cookie
41
+	 */
42
+	private $cookie;
43
+
44
+	/**
45
+	 * $_SERVER parameters
46
+	 *
47
+	 * @var array $server
48
+	 */
49
+	private $server;
50
+
51
+	/**
52
+	 * $_REQUEST parameters
53
+	 *
54
+	 * @var array $request
55
+	 */
56
+	private $request;
57
+
58
+	/**
59
+	 * @var RequestTypeContextCheckerInterface
60
+	 */
61
+	private $request_type;
62
+
63
+	/**
64
+	 * IP address for request
65
+	 *
66
+	 * @var string $ip_address
67
+	 */
68
+	private $ip_address;
69
+
70
+	/**
71
+	 * @var string $user_agent
72
+	 */
73
+	private $user_agent;
74
+
75
+	/**
76
+	 * true if current user appears to be some kind of bot
77
+	 *
78
+	 * @var bool $is_bot
79
+	 */
80
+	private $is_bot;
81
+
82
+
83
+
84
+	/**
85
+	 * @param array                              $get
86
+	 * @param array                              $post
87
+	 * @param array                              $cookie
88
+	 * @param array                              $server
89
+	 */
90
+	public function __construct(array $get, array $post, array $cookie, array $server)
91
+	{
92
+		// grab request vars
93
+		$this->get        = $get;
94
+		$this->post       = $post;
95
+		$this->cookie     = $cookie;
96
+		$this->server     = $server;
97
+		$this->request    = array_merge($this->get, $this->post);
98
+		$this->ip_address = $this->visitorIp();
99
+	}
100
+
101
+
102
+	/**
103
+	 * @param RequestTypeContextCheckerInterface $type
104
+	 */
105
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
106
+	{
107
+		$this->request_type = $type;
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * @return array
114
+	 */
115
+	public function getParams()
116
+	{
117
+		return $this->get;
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @return array
124
+	 */
125
+	public function postParams()
126
+	{
127
+		return $this->post;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return array
134
+	 */
135
+	public function cookieParams()
136
+	{
137
+		return $this->cookie;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @return array
143
+	 */
144
+	public function serverParams()
145
+	{
146
+		return $this->server;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * returns contents of $_REQUEST
153
+	 *
154
+	 * @return array
155
+	 */
156
+	public function requestParams()
157
+	{
158
+		return $this->request;
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 * @param      $key
165
+	 * @param      $value
166
+	 * @param bool $override_ee
167
+	 * @return    void
168
+	 */
169
+	public function setRequestParam($key, $value, $override_ee = false)
170
+	{
171
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
172
+		if (
173
+			$key !== 'ee'
174
+			|| ($key === 'ee' && empty($this->request['ee']))
175
+			|| ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
176
+		) {
177
+			$this->request[ $key ] = $value;
178
+		}
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 * returns   the value for a request param if the given key exists
185
+	 *
186
+	 * @param       $key
187
+	 * @param null  $default
188
+	 * @return mixed
189
+	 */
190
+	public function getRequestParam($key, $default = null)
191
+	{
192
+		return $this->requestParameterDrillDown($key, $default, 'get');
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * check if param exists
199
+	 *
200
+	 * @param       $key
201
+	 * @return bool
202
+	 */
203
+	public function requestParamIsSet($key)
204
+	{
205
+		return $this->requestParameterDrillDown($key);
206
+	}
207
+
208
+
209
+	/**
210
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
211
+	 * and return the value for the first match found
212
+	 * wildcards can be either of the following:
213
+	 *      ? to represent a single character of any type
214
+	 *      * to represent one or more characters of any type
215
+	 *
216
+	 * @param string     $pattern
217
+	 * @param null|mixed $default
218
+	 * @return false|int
219
+	 */
220
+	public function getMatch($pattern, $default = null)
221
+	{
222
+		return $this->requestParameterDrillDown($pattern, $default, 'match');
223
+	}
224
+
225
+
226
+	/**
227
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
228
+	 * wildcards can be either of the following:
229
+	 *      ? to represent a single character of any type
230
+	 *      * to represent one or more characters of any type
231
+	 * returns true if a match is found or false if not
232
+	 *
233
+	 * @param string $pattern
234
+	 * @return false|int
235
+	 */
236
+	public function matches($pattern)
237
+	{
238
+		return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
244
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
245
+	 *                                      and used to search through the current request's parameter keys
246
+	 * @param array  $request_params        The array of request parameters to search through
247
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
248
+	 *                                      Default is null
249
+	 * @param string $return                [optional] Controls what kind of value is returned.
250
+	 *                                      Options are:
251
+	 *                                      'bool' will return true or false if match is found or not
252
+	 *                                      'key' will return the first key found that matches the supplied pattern
253
+	 *                                      'value' will return the value for the first request parameter
254
+	 *                                      whose key matches the supplied pattern
255
+	 *                                      Default is 'value'
256
+	 * @return boolean|string
257
+	 */
258
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
259
+	{
260
+		$return = in_array($return, array('bool', 'key', 'value'), true)
261
+			? $return
262
+			: 'is_set';
263
+		// replace wildcard chars with regex chars
264
+		$pattern = str_replace(
265
+			array("\*", "\?"),
266
+			array('.*', '.'),
267
+			preg_quote($pattern, '/')
268
+		);
269
+		foreach ($request_params as $key => $request_param) {
270
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
271
+				// return value for request param
272
+				if ($return === 'value') {
273
+					return $request_params[ $key ];
274
+				}
275
+				// or actual key or true just to indicate it was found
276
+				return $return === 'key' ? $key : true;
277
+			}
278
+		}
279
+		// match not found so return default value or false
280
+		return $return === 'value' ? $default : false;
281
+	}
282
+
283
+
284
+	/**
285
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
286
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
287
+	 * by using square brackets to surround keys for deeper array elements.
288
+	 * For example :
289
+	 * if the supplied $key was: "first[second][third]"
290
+	 * then this will attempt to drill down into the request parameter array to find a value.
291
+	 * Given the following request parameters:
292
+	 *  array(
293
+	 *      'first' => array(
294
+	 *          'second' => array(
295
+	 *              'third' => 'has a value'
296
+	 *          )
297
+	 *      )
298
+	 *  )
299
+	 * would return true if default parameters were set
300
+	 *
301
+	 * @param string $callback
302
+	 * @param        $key
303
+	 * @param null   $default
304
+	 * @param array  $request_params
305
+	 * @return bool|mixed|null
306
+	 */
307
+	private function requestParameterDrillDown(
308
+		$key,
309
+		$default = null,
310
+		$callback = 'is_set',
311
+		array $request_params = array()
312
+	) {
313
+		$callback       = in_array($callback, array('is_set', 'get', 'match'), true)
314
+			? $callback
315
+			: 'is_set';
316
+		$request_params = ! empty($request_params)
317
+			? $request_params
318
+			: $this->request;
319
+		// does incoming key represent an array like 'first[second][third]'  ?
320
+		if (strpos($key, '[') !== false) {
321
+			// turn it into an actual array
322
+			$key  = str_replace(']', '', $key);
323
+			$keys = explode('[', $key);
324
+			$key  = array_shift($keys);
325
+			if ($callback === 'match') {
326
+				$real_key = $this->match($key, $request_params, $default, 'key');
327
+				$key      = $real_key ? $real_key : $key;
328
+			}
329
+			// check if top level key exists
330
+			if (isset($request_params[ $key ])) {
331
+				// build a new key to pass along like: 'second[third]'
332
+				// or just 'second' depending on depth of keys
333
+				$key_string = array_shift($keys);
334
+				if (! empty($keys)) {
335
+					$key_string .= '[' . implode('][', $keys) . ']';
336
+				}
337
+				return $this->requestParameterDrillDown(
338
+					$key_string,
339
+					$default,
340
+					$callback,
341
+					$request_params[ $key ]
342
+				);
343
+			}
344
+		}
345
+		if ($callback === 'is_set') {
346
+			return isset($request_params[ $key ]);
347
+		}
348
+		if ($callback === 'match') {
349
+			return $this->match($key, $request_params, $default);
350
+		}
351
+		return isset($request_params[ $key ])
352
+			? $request_params[ $key ]
353
+			: $default;
354
+	}
355
+
356
+
357
+	/**
358
+	 * remove param
359
+	 *
360
+	 * @param      $key
361
+	 * @param bool $unset_from_global_too
362
+	 */
363
+	public function unSetRequestParam($key, $unset_from_global_too = false)
364
+	{
365
+		unset($this->request[ $key ]);
366
+		if ($unset_from_global_too) {
367
+			unset($_REQUEST[ $key ]);
368
+		}
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * @return string
375
+	 */
376
+	public function ipAddress()
377
+	{
378
+		return $this->ip_address;
379
+	}
380
+
381
+
382
+	/**
383
+	 * attempt to get IP address of current visitor from server
384
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
385
+	 *
386
+	 * @access public
387
+	 * @return string
388
+	 */
389
+	private function visitorIp()
390
+	{
391
+		$visitor_ip  = '0.0.0.0';
392
+		$server_keys = array(
393
+			'HTTP_CLIENT_IP',
394
+			'HTTP_X_FORWARDED_FOR',
395
+			'HTTP_X_FORWARDED',
396
+			'HTTP_X_CLUSTER_CLIENT_IP',
397
+			'HTTP_FORWARDED_FOR',
398
+			'HTTP_FORWARDED',
399
+			'REMOTE_ADDR',
400
+		);
401
+		foreach ($server_keys as $key) {
402
+			if (isset($this->server[ $key ])) {
403
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
404
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
405
+						$visitor_ip = $ip;
406
+					}
407
+				}
408
+			}
409
+		}
410
+		return $visitor_ip;
411
+	}
412
+
413
+
414
+	/**
415
+	 * @return string
416
+	 */
417
+	public function requestUri()
418
+	{
419
+		$request_uri = filter_input(
420
+			INPUT_SERVER,
421
+			'REQUEST_URI',
422
+			FILTER_SANITIZE_URL,
423
+			FILTER_NULL_ON_FAILURE
424
+		);
425
+		if (empty($request_uri)) {
426
+			// fallback sanitization if the above fails
427
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
428
+		}
429
+		return $request_uri;
430
+	}
431
+
432
+
433
+	/**
434
+	 * @return string
435
+	 */
436
+	public function userAgent()
437
+	{
438
+		return $this->user_agent;
439
+	}
440
+
441
+
442
+	/**
443
+	 * @param string $user_agent
444
+	 */
445
+	public function setUserAgent($user_agent = '')
446
+	{
447
+		if ($user_agent === '' || ! is_string($user_agent)) {
448
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
449
+		}
450
+		$this->user_agent = $user_agent;
451
+	}
452
+
453
+
454
+	/**
455
+	 * @return bool
456
+	 */
457
+	public function isBot()
458
+	{
459
+		return $this->is_bot;
460
+	}
461
+
462
+
463
+	/**
464
+	 * @param bool $is_bot
465
+	 */
466
+	public function setIsBot($is_bot)
467
+	{
468
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
469
+	}
470
+
471
+
472
+	/**
473
+	 * @return bool
474
+	 */
475
+	public function isActivation()
476
+	{
477
+		return $this->request_type->isActivation();
478
+	}
479
+
480
+
481
+	/**
482
+	 * @param $is_activation
483
+	 * @return bool
484
+	 */
485
+	public function setIsActivation($is_activation)
486
+	{
487
+		return $this->request_type->setIsActivation($is_activation);
488
+	}
489
+
490
+
491
+	/**
492
+	 * @return bool
493
+	 */
494
+	public function isAdmin()
495
+	{
496
+		return $this->request_type->isAdmin();
497
+	}
498
+
499
+
500
+	/**
501
+	 * @return bool
502
+	 */
503
+	public function isAdminAjax()
504
+	{
505
+		return $this->request_type->isAdminAjax();
506
+	}
507
+
508
+
509
+	/**
510
+	 * @return bool
511
+	 */
512
+	public function isAjax()
513
+	{
514
+		return $this->request_type->isAjax();
515
+	}
516
+
517
+
518
+	/**
519
+	 * @return bool
520
+	 */
521
+	public function isEeAjax()
522
+	{
523
+		return $this->request_type->isEeAjax();
524
+	}
525
+
526
+
527
+	/**
528
+	 * @return bool
529
+	 */
530
+	public function isOtherAjax()
531
+	{
532
+		return $this->request_type->isOtherAjax();
533
+	}
534
+
535
+
536
+	/**
537
+	 * @return bool
538
+	 */
539
+	public function isApi()
540
+	{
541
+		return $this->request_type->isApi();
542
+	}
543
+
544
+
545
+	/**
546
+	 * @return bool
547
+	 */
548
+	public function isCli()
549
+	{
550
+		return $this->request_type->isCli();
551
+	}
552
+
553
+
554
+	/**
555
+	 * @return bool
556
+	 */
557
+	public function isCron()
558
+	{
559
+		return $this->request_type->isCron();
560
+	}
561
+
562
+
563
+	/**
564
+	 * @return bool
565
+	 */
566
+	public function isFeed()
567
+	{
568
+		return $this->request_type->isFeed();
569
+	}
570
+
571
+
572
+	/**
573
+	 * @return bool
574
+	 */
575
+	public function isFrontend()
576
+	{
577
+		return $this->request_type->isFrontend();
578
+	}
579
+
580
+
581
+	/**
582
+	 * @return bool
583
+	 */
584
+	public function isFrontAjax()
585
+	{
586
+		return $this->request_type->isFrontAjax();
587
+	}
588
+
589
+
590
+
591
+	/**
592
+	 * @return bool
593
+	 */
594
+	public function isIframe()
595
+	{
596
+		return $this->request_type->isIframe();
597
+	}
598
+
599
+
600
+	/**
601
+	 * @return string
602
+	 */
603
+	public function slug()
604
+	{
605
+		return $this->request_type->slug();
606
+	}
607 607
 
608 608
 
609 609
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             || ($key === 'ee' && empty($this->request['ee']))
175 175
             || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
176 176
         ) {
177
-            $this->request[ $key ] = $value;
177
+            $this->request[$key] = $value;
178 178
         }
179 179
     }
180 180
 
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
             preg_quote($pattern, '/')
268 268
         );
269 269
         foreach ($request_params as $key => $request_param) {
270
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
270
+            if (preg_match('/^'.$pattern.'$/is', $key)) {
271 271
                 // return value for request param
272 272
                 if ($return === 'value') {
273
-                    return $request_params[ $key ];
273
+                    return $request_params[$key];
274 274
                 }
275 275
                 // or actual key or true just to indicate it was found
276 276
                 return $return === 'key' ? $key : true;
@@ -327,29 +327,29 @@  discard block
 block discarded – undo
327 327
                 $key      = $real_key ? $real_key : $key;
328 328
             }
329 329
             // check if top level key exists
330
-            if (isset($request_params[ $key ])) {
330
+            if (isset($request_params[$key])) {
331 331
                 // build a new key to pass along like: 'second[third]'
332 332
                 // or just 'second' depending on depth of keys
333 333
                 $key_string = array_shift($keys);
334
-                if (! empty($keys)) {
335
-                    $key_string .= '[' . implode('][', $keys) . ']';
334
+                if ( ! empty($keys)) {
335
+                    $key_string .= '['.implode('][', $keys).']';
336 336
                 }
337 337
                 return $this->requestParameterDrillDown(
338 338
                     $key_string,
339 339
                     $default,
340 340
                     $callback,
341
-                    $request_params[ $key ]
341
+                    $request_params[$key]
342 342
                 );
343 343
             }
344 344
         }
345 345
         if ($callback === 'is_set') {
346
-            return isset($request_params[ $key ]);
346
+            return isset($request_params[$key]);
347 347
         }
348 348
         if ($callback === 'match') {
349 349
             return $this->match($key, $request_params, $default);
350 350
         }
351
-        return isset($request_params[ $key ])
352
-            ? $request_params[ $key ]
351
+        return isset($request_params[$key])
352
+            ? $request_params[$key]
353 353
             : $default;
354 354
     }
355 355
 
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
      */
363 363
     public function unSetRequestParam($key, $unset_from_global_too = false)
364 364
     {
365
-        unset($this->request[ $key ]);
365
+        unset($this->request[$key]);
366 366
         if ($unset_from_global_too) {
367
-            unset($_REQUEST[ $key ]);
367
+            unset($_REQUEST[$key]);
368 368
         }
369 369
     }
370 370
 
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
             'REMOTE_ADDR',
400 400
         );
401 401
         foreach ($server_keys as $key) {
402
-            if (isset($this->server[ $key ])) {
403
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
402
+            if (isset($this->server[$key])) {
403
+                foreach (array_map('trim', explode(',', $this->server[$key])) as $ip) {
404 404
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
405 405
                         $visitor_ip = $ip;
406 406
                     }
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      *
186 186
      * @param       $key
187 187
      * @param null  $default
188
-     * @return mixed
188
+     * @return integer
189 189
      */
190 190
     public function getRequestParam($key, $default = null)
191 191
     {
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * returns true if a match is found or false if not
232 232
      *
233 233
      * @param string $pattern
234
-     * @return false|int
234
+     * @return boolean
235 235
      */
236 236
     public function matches($pattern)
237 237
     {
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
      * would return true if default parameters were set
300 300
      *
301 301
      * @param string $callback
302
-     * @param        $key
302
+     * @param        string $key
303 303
      * @param null   $default
304 304
      * @param array  $request_params
305 305
      * @return bool|mixed|null
Please login to merge, or discard this patch.