@@ -4,49 +4,49 @@ |
||
4 | 4 | |
5 | 5 | class RequestSanitizer |
6 | 6 | { |
7 | - /** |
|
8 | - * Will sanitize the supplied request parameter based on the specified data type |
|
9 | - * |
|
10 | - * @param mixed $param the supplied request parameter |
|
11 | - * @param string $type the specified data type (default: "string") |
|
12 | - * valid values: "bool", "float", "int", "key", "url", or "string" |
|
13 | - * @param bool $is_array if true, then $param will be treated as an array of $type |
|
14 | - * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator |
|
15 | - * @return array|bool|float|int|string |
|
16 | - * @since 4.10.14.p |
|
17 | - */ |
|
18 | - public function clean($param, $type = 'string', $is_array = false, $delimiter = '') |
|
19 | - { |
|
20 | - if ($delimiter !== '' && is_string($param)) { |
|
21 | - $param = explode($delimiter, $param); |
|
22 | - // unset the delimiter else this function will recurse forever when we loop over the array of results |
|
23 | - $delimiter = ''; |
|
24 | - } |
|
25 | - // check if we are getting an improperly typed array and correct |
|
26 | - $is_array = $is_array || is_array($param); |
|
27 | - if ($is_array) { |
|
28 | - $values = []; |
|
29 | - foreach ((array) $param as $key => $value) { |
|
30 | - $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); |
|
31 | - } |
|
32 | - return $values; |
|
33 | - } |
|
34 | - switch ($type) { |
|
35 | - case 'bool': |
|
36 | - return filter_var($param, FILTER_VALIDATE_BOOLEAN); |
|
37 | - case 'float': |
|
38 | - return (float) $param; |
|
39 | - case 'fqcn': |
|
40 | - return preg_replace('[^\\\w\d]', '', $param); |
|
41 | - case 'int': |
|
42 | - return (int) $param; |
|
43 | - case 'key': |
|
44 | - return sanitize_key($param); |
|
45 | - case 'url': |
|
46 | - return esc_url_raw($param); |
|
47 | - case 'string': |
|
48 | - default: |
|
49 | - return sanitize_text_field($param); |
|
50 | - } |
|
51 | - } |
|
7 | + /** |
|
8 | + * Will sanitize the supplied request parameter based on the specified data type |
|
9 | + * |
|
10 | + * @param mixed $param the supplied request parameter |
|
11 | + * @param string $type the specified data type (default: "string") |
|
12 | + * valid values: "bool", "float", "int", "key", "url", or "string" |
|
13 | + * @param bool $is_array if true, then $param will be treated as an array of $type |
|
14 | + * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator |
|
15 | + * @return array|bool|float|int|string |
|
16 | + * @since 4.10.14.p |
|
17 | + */ |
|
18 | + public function clean($param, $type = 'string', $is_array = false, $delimiter = '') |
|
19 | + { |
|
20 | + if ($delimiter !== '' && is_string($param)) { |
|
21 | + $param = explode($delimiter, $param); |
|
22 | + // unset the delimiter else this function will recurse forever when we loop over the array of results |
|
23 | + $delimiter = ''; |
|
24 | + } |
|
25 | + // check if we are getting an improperly typed array and correct |
|
26 | + $is_array = $is_array || is_array($param); |
|
27 | + if ($is_array) { |
|
28 | + $values = []; |
|
29 | + foreach ((array) $param as $key => $value) { |
|
30 | + $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); |
|
31 | + } |
|
32 | + return $values; |
|
33 | + } |
|
34 | + switch ($type) { |
|
35 | + case 'bool': |
|
36 | + return filter_var($param, FILTER_VALIDATE_BOOLEAN); |
|
37 | + case 'float': |
|
38 | + return (float) $param; |
|
39 | + case 'fqcn': |
|
40 | + return preg_replace('[^\\\w\d]', '', $param); |
|
41 | + case 'int': |
|
42 | + return (int) $param; |
|
43 | + case 'key': |
|
44 | + return sanitize_key($param); |
|
45 | + case 'url': |
|
46 | + return esc_url_raw($param); |
|
47 | + case 'string': |
|
48 | + default: |
|
49 | + return sanitize_text_field($param); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -33,525 +33,525 @@ |
||
33 | 33 | class ProcessTicketSelector |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var EE_Cart $cart |
|
38 | - */ |
|
39 | - private $cart; |
|
36 | + /** |
|
37 | + * @var EE_Cart $cart |
|
38 | + */ |
|
39 | + private $cart; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var EE_Core_Config $core_config |
|
43 | - */ |
|
44 | - private $core_config; |
|
41 | + /** |
|
42 | + * @var EE_Core_Config $core_config |
|
43 | + */ |
|
44 | + private $core_config; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var RequestInterface $request |
|
48 | - */ |
|
49 | - private $request; |
|
46 | + /** |
|
47 | + * @var RequestInterface $request |
|
48 | + */ |
|
49 | + private $request; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var EE_Session $session |
|
53 | - */ |
|
54 | - private $session; |
|
51 | + /** |
|
52 | + * @var EE_Session $session |
|
53 | + */ |
|
54 | + private $session; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @var EEM_Ticket $ticket_model |
|
58 | - */ |
|
59 | - private $ticket_model; |
|
56 | + /** |
|
57 | + * @var EEM_Ticket $ticket_model |
|
58 | + */ |
|
59 | + private $ticket_model; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @var TicketDatetimeAvailabilityTracker $tracker |
|
63 | - */ |
|
64 | - private $tracker; |
|
61 | + /** |
|
62 | + * @var TicketDatetimeAvailabilityTracker $tracker |
|
63 | + */ |
|
64 | + private $tracker; |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * ProcessTicketSelector constructor. |
|
69 | - * NOTE: PLZ use the Loader to instantiate this class if need be |
|
70 | - * so that all dependencies get injected correctly (which will happen automatically) |
|
71 | - * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
72 | - * |
|
73 | - * @param EE_Core_Config $core_config |
|
74 | - * @param RequestInterface $request |
|
75 | - * @param EE_Session $session |
|
76 | - * @param EEM_Ticket $ticket_model |
|
77 | - * @param TicketDatetimeAvailabilityTracker $tracker |
|
78 | - * @throws InvalidArgumentException |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - * @throws InvalidInterfaceException |
|
81 | - */ |
|
82 | - public function __construct( |
|
83 | - EE_Core_Config $core_config = null, |
|
84 | - RequestInterface $request = null, |
|
85 | - EE_Session $session = null, |
|
86 | - EEM_Ticket $ticket_model = null, |
|
87 | - TicketDatetimeAvailabilityTracker $tracker = null |
|
88 | - ) { |
|
89 | - $loader = LoaderFactory::getLoader(); |
|
90 | - $this->core_config = $core_config instanceof EE_Core_Config |
|
91 | - ? $core_config |
|
92 | - : $loader->getShared('EE_Core_Config'); |
|
93 | - $this->request = $request instanceof RequestInterface |
|
94 | - ? $request |
|
95 | - : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
96 | - $this->session = $session instanceof EE_Session |
|
97 | - ? $session |
|
98 | - : $loader->getShared('EE_Session'); |
|
99 | - $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
100 | - ? $ticket_model |
|
101 | - : $loader->getShared('EEM_Ticket'); |
|
102 | - $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
103 | - ? $tracker |
|
104 | - : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
105 | - } |
|
67 | + /** |
|
68 | + * ProcessTicketSelector constructor. |
|
69 | + * NOTE: PLZ use the Loader to instantiate this class if need be |
|
70 | + * so that all dependencies get injected correctly (which will happen automatically) |
|
71 | + * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
72 | + * |
|
73 | + * @param EE_Core_Config $core_config |
|
74 | + * @param RequestInterface $request |
|
75 | + * @param EE_Session $session |
|
76 | + * @param EEM_Ticket $ticket_model |
|
77 | + * @param TicketDatetimeAvailabilityTracker $tracker |
|
78 | + * @throws InvalidArgumentException |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + * @throws InvalidInterfaceException |
|
81 | + */ |
|
82 | + public function __construct( |
|
83 | + EE_Core_Config $core_config = null, |
|
84 | + RequestInterface $request = null, |
|
85 | + EE_Session $session = null, |
|
86 | + EEM_Ticket $ticket_model = null, |
|
87 | + TicketDatetimeAvailabilityTracker $tracker = null |
|
88 | + ) { |
|
89 | + $loader = LoaderFactory::getLoader(); |
|
90 | + $this->core_config = $core_config instanceof EE_Core_Config |
|
91 | + ? $core_config |
|
92 | + : $loader->getShared('EE_Core_Config'); |
|
93 | + $this->request = $request instanceof RequestInterface |
|
94 | + ? $request |
|
95 | + : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
96 | + $this->session = $session instanceof EE_Session |
|
97 | + ? $session |
|
98 | + : $loader->getShared('EE_Session'); |
|
99 | + $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
100 | + ? $ticket_model |
|
101 | + : $loader->getShared('EEM_Ticket'); |
|
102 | + $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
103 | + ? $tracker |
|
104 | + : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * cancelTicketSelections |
|
110 | - * |
|
111 | - * @return bool |
|
112 | - * @throws EE_Error |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws ReflectionException |
|
117 | - */ |
|
118 | - public function cancelTicketSelections() |
|
119 | - { |
|
120 | - // check nonce |
|
121 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
122 | - return false; |
|
123 | - } |
|
124 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
125 | - if ($this->request->requestParamIsSet('event_id')) { |
|
126 | - EEH_URL::safeRedirectAndExit( |
|
127 | - EEH_Event_View::event_link_url( |
|
128 | - $this->request->getRequestParam('event_id', 0, 'int') |
|
129 | - ) |
|
130 | - ); |
|
131 | - } |
|
132 | - EEH_URL::safeRedirectAndExit( |
|
133 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
134 | - ); |
|
135 | - return true; |
|
136 | - } |
|
108 | + /** |
|
109 | + * cancelTicketSelections |
|
110 | + * |
|
111 | + * @return bool |
|
112 | + * @throws EE_Error |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws ReflectionException |
|
117 | + */ |
|
118 | + public function cancelTicketSelections() |
|
119 | + { |
|
120 | + // check nonce |
|
121 | + if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
122 | + return false; |
|
123 | + } |
|
124 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
125 | + if ($this->request->requestParamIsSet('event_id')) { |
|
126 | + EEH_URL::safeRedirectAndExit( |
|
127 | + EEH_Event_View::event_link_url( |
|
128 | + $this->request->getRequestParam('event_id', 0, 'int') |
|
129 | + ) |
|
130 | + ); |
|
131 | + } |
|
132 | + EEH_URL::safeRedirectAndExit( |
|
133 | + site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
134 | + ); |
|
135 | + return true; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * processTicketSelectorNonce |
|
141 | - * |
|
142 | - * @param string $nonce_name |
|
143 | - * @param string $id |
|
144 | - * @return bool |
|
145 | - */ |
|
146 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
147 | - { |
|
148 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
149 | - if ( |
|
150 | - ! $this->request->isAdmin() |
|
151 | - && ( |
|
152 | - ! $this->request->requestParamIsSet($nonce_name_with_id) |
|
153 | - || ! wp_verify_nonce( |
|
154 | - $this->request->getRequestParam($nonce_name_with_id), |
|
155 | - $nonce_name |
|
156 | - ) |
|
157 | - ) |
|
158 | - ) { |
|
159 | - EE_Error::add_error( |
|
160 | - sprintf( |
|
161 | - esc_html__( |
|
162 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
163 | - 'event_espresso' |
|
164 | - ), |
|
165 | - '<br/>' |
|
166 | - ), |
|
167 | - __FILE__, |
|
168 | - __FUNCTION__, |
|
169 | - __LINE__ |
|
170 | - ); |
|
171 | - return false; |
|
172 | - } |
|
173 | - return true; |
|
174 | - } |
|
139 | + /** |
|
140 | + * processTicketSelectorNonce |
|
141 | + * |
|
142 | + * @param string $nonce_name |
|
143 | + * @param string $id |
|
144 | + * @return bool |
|
145 | + */ |
|
146 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
147 | + { |
|
148 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
149 | + if ( |
|
150 | + ! $this->request->isAdmin() |
|
151 | + && ( |
|
152 | + ! $this->request->requestParamIsSet($nonce_name_with_id) |
|
153 | + || ! wp_verify_nonce( |
|
154 | + $this->request->getRequestParam($nonce_name_with_id), |
|
155 | + $nonce_name |
|
156 | + ) |
|
157 | + ) |
|
158 | + ) { |
|
159 | + EE_Error::add_error( |
|
160 | + sprintf( |
|
161 | + esc_html__( |
|
162 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
163 | + 'event_espresso' |
|
164 | + ), |
|
165 | + '<br/>' |
|
166 | + ), |
|
167 | + __FILE__, |
|
168 | + __FUNCTION__, |
|
169 | + __LINE__ |
|
170 | + ); |
|
171 | + return false; |
|
172 | + } |
|
173 | + return true; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * process_ticket_selections |
|
179 | - * |
|
180 | - * @return bool |
|
181 | - * @throws EE_Error |
|
182 | - * @throws InvalidArgumentException |
|
183 | - * @throws InvalidDataTypeException |
|
184 | - * @throws InvalidInterfaceException |
|
185 | - * @throws ReflectionException |
|
186 | - */ |
|
187 | - public function processTicketSelections() |
|
188 | - { |
|
189 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
190 | - if ($this->request->isBot()) { |
|
191 | - EEH_URL::safeRedirectAndExit( |
|
192 | - apply_filters( |
|
193 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
194 | - site_url() |
|
195 | - ) |
|
196 | - ); |
|
197 | - } |
|
198 | - // do we have an event id? |
|
199 | - $id = $this->getEventId(); |
|
200 | - // we should really only have 1 registration in the works now |
|
201 | - // (ie, no MER) so unless otherwise requested, clear the session |
|
202 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
203 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
204 | - } |
|
205 | - // validate/sanitize/filter data |
|
206 | - $valid = apply_filters( |
|
207 | - 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
208 | - $this->validatePostData($id) |
|
209 | - ); |
|
210 | - // check total tickets ordered vs max number of attendees that can register |
|
211 | - if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { |
|
212 | - $this->maxAttendeesViolation($valid); |
|
213 | - } else { |
|
214 | - // all data appears to be valid |
|
215 | - if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
216 | - return true; |
|
217 | - } |
|
218 | - } |
|
219 | - // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
220 | - // at this point, just return if registration is being made from admin |
|
221 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
222 | - return false; |
|
223 | - } |
|
224 | - if ($valid['return_url']) { |
|
225 | - EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
226 | - } |
|
227 | - if ($id) { |
|
228 | - EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
229 | - } |
|
230 | - echo EE_Error::get_notices(); // already escaped |
|
231 | - return false; |
|
232 | - } |
|
177 | + /** |
|
178 | + * process_ticket_selections |
|
179 | + * |
|
180 | + * @return bool |
|
181 | + * @throws EE_Error |
|
182 | + * @throws InvalidArgumentException |
|
183 | + * @throws InvalidDataTypeException |
|
184 | + * @throws InvalidInterfaceException |
|
185 | + * @throws ReflectionException |
|
186 | + */ |
|
187 | + public function processTicketSelections() |
|
188 | + { |
|
189 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
190 | + if ($this->request->isBot()) { |
|
191 | + EEH_URL::safeRedirectAndExit( |
|
192 | + apply_filters( |
|
193 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
194 | + site_url() |
|
195 | + ) |
|
196 | + ); |
|
197 | + } |
|
198 | + // do we have an event id? |
|
199 | + $id = $this->getEventId(); |
|
200 | + // we should really only have 1 registration in the works now |
|
201 | + // (ie, no MER) so unless otherwise requested, clear the session |
|
202 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
203 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
204 | + } |
|
205 | + // validate/sanitize/filter data |
|
206 | + $valid = apply_filters( |
|
207 | + 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
208 | + $this->validatePostData($id) |
|
209 | + ); |
|
210 | + // check total tickets ordered vs max number of attendees that can register |
|
211 | + if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { |
|
212 | + $this->maxAttendeesViolation($valid); |
|
213 | + } else { |
|
214 | + // all data appears to be valid |
|
215 | + if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
216 | + return true; |
|
217 | + } |
|
218 | + } |
|
219 | + // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
220 | + // at this point, just return if registration is being made from admin |
|
221 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
222 | + return false; |
|
223 | + } |
|
224 | + if ($valid['return_url']) { |
|
225 | + EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
226 | + } |
|
227 | + if ($id) { |
|
228 | + EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
229 | + } |
|
230 | + echo EE_Error::get_notices(); // already escaped |
|
231 | + return false; |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - /** |
|
236 | - * @return int |
|
237 | - */ |
|
238 | - private function getEventId() |
|
239 | - { |
|
240 | - // do we have an event id? |
|
241 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
242 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
243 | - EE_Error::add_error( |
|
244 | - sprintf( |
|
245 | - esc_html__( |
|
246 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - '<br/>' |
|
250 | - ), |
|
251 | - __FILE__, |
|
252 | - __FUNCTION__, |
|
253 | - __LINE__ |
|
254 | - ); |
|
255 | - } |
|
256 | - // if event id is valid |
|
257 | - return $this->request->getRequestParam('tkt-slctr-event-id', 0, 'int'); |
|
258 | - } |
|
235 | + /** |
|
236 | + * @return int |
|
237 | + */ |
|
238 | + private function getEventId() |
|
239 | + { |
|
240 | + // do we have an event id? |
|
241 | + if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
242 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
243 | + EE_Error::add_error( |
|
244 | + sprintf( |
|
245 | + esc_html__( |
|
246 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + '<br/>' |
|
250 | + ), |
|
251 | + __FILE__, |
|
252 | + __FUNCTION__, |
|
253 | + __LINE__ |
|
254 | + ); |
|
255 | + } |
|
256 | + // if event id is valid |
|
257 | + return $this->request->getRequestParam('tkt-slctr-event-id', 0, 'int'); |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * validate_post_data |
|
263 | - * |
|
264 | - * @param int $id |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - private function validatePostData($id = 0) |
|
268 | - { |
|
269 | - if (! $id) { |
|
270 | - EE_Error::add_error( |
|
271 | - esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
272 | - __FILE__, |
|
273 | - __FUNCTION__, |
|
274 | - __LINE__ |
|
275 | - ); |
|
276 | - return array(); |
|
277 | - } |
|
278 | - // start with an empty array() |
|
279 | - $valid_data = array(); |
|
280 | - // grab valid id |
|
281 | - $valid_data['id'] = $id; |
|
282 | - // array of other form names |
|
283 | - $inputs_to_clean = array( |
|
284 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
285 | - 'rows' => 'tkt-slctr-rows-', |
|
286 | - 'qty' => 'tkt-slctr-qty-', |
|
287 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
288 | - 'return_url' => 'tkt-slctr-return-url-', |
|
289 | - ); |
|
290 | - // let's track the total number of tickets ordered.' |
|
291 | - $valid_data['total_tickets'] = 0; |
|
292 | - // cycle through $inputs_to_clean array |
|
293 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
294 | - $input_key = "{$input_to_clean}{$id}"; |
|
295 | - // check for POST data |
|
296 | - if ($this->request->requestParamIsSet($input_key)) { |
|
297 | - switch ($what) { |
|
298 | - // integers |
|
299 | - case 'event_id': |
|
300 | - case 'rows': |
|
301 | - case 'max_atndz': |
|
302 | - $valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int'); |
|
303 | - break; |
|
304 | - // arrays of integers |
|
305 | - case 'qty': |
|
306 | - $max_atndz = $valid_data['max_atndz'] ?? $this->request->getRequestParam($input_key, 0, 'int'); |
|
307 | - /** @var array $row_qty */ |
|
308 | - $row_qty = $max_atndz !== 1 |
|
309 | - ? $this->request->getRequestParam($input_key, [], 'int', true, '-') |
|
310 | - : $this->request->getRequestParam($input_key); |
|
311 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
312 | - if (! is_array($row_qty)) { |
|
313 | - /** @var string $row_qty */ |
|
314 | - // get number of rows |
|
315 | - $rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int'); |
|
316 | - // explode integers by the dash |
|
317 | - $row_qty = explode('-', $row_qty); |
|
318 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
319 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
320 | - $row_qty = array($row => $qty); |
|
321 | - for ($x = 1; $x <= $rows; $x++) { |
|
322 | - if (! isset($row_qty[ $x ])) { |
|
323 | - $row_qty[ $x ] = 0; |
|
324 | - } |
|
325 | - } |
|
326 | - } |
|
327 | - ksort($row_qty); |
|
328 | - // cycle thru values |
|
329 | - foreach ($row_qty as $qty) { |
|
330 | - $qty = absint($qty); |
|
331 | - // sanitize as integers |
|
332 | - $valid_data[ $what ][] = $qty; |
|
333 | - $valid_data['total_tickets'] += $qty; |
|
334 | - } |
|
335 | - break; |
|
336 | - // array of integers |
|
337 | - case 'ticket_id': |
|
338 | - $ticket_ids = (array) $this->request->getRequestParam($input_key, [], 'int', true); |
|
339 | - // cycle thru values |
|
340 | - foreach ($ticket_ids as $key => $value) { |
|
341 | - // allow only integers |
|
342 | - $valid_data[ $what ][ $key ] = absint($value); |
|
343 | - } |
|
344 | - break; |
|
345 | - case 'return_url': |
|
346 | - // grab and sanitize return-url |
|
347 | - $input_value = $this->request->getRequestParam($input_key, '', 'url'); |
|
348 | - // was the request coming from an iframe ? if so, then: |
|
349 | - if (strpos($input_value, 'event_list=iframe')) { |
|
350 | - // get anchor fragment |
|
351 | - $input_value = explode('#', $input_value); |
|
352 | - $input_value = end($input_value); |
|
353 | - // use event list url instead, but append anchor |
|
354 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
355 | - } |
|
356 | - $valid_data[ $what ] = $input_value; |
|
357 | - break; |
|
358 | - } // end switch $what |
|
359 | - } |
|
360 | - } // end foreach $inputs_to_clean |
|
361 | - return $valid_data; |
|
362 | - } |
|
261 | + /** |
|
262 | + * validate_post_data |
|
263 | + * |
|
264 | + * @param int $id |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + private function validatePostData($id = 0) |
|
268 | + { |
|
269 | + if (! $id) { |
|
270 | + EE_Error::add_error( |
|
271 | + esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
272 | + __FILE__, |
|
273 | + __FUNCTION__, |
|
274 | + __LINE__ |
|
275 | + ); |
|
276 | + return array(); |
|
277 | + } |
|
278 | + // start with an empty array() |
|
279 | + $valid_data = array(); |
|
280 | + // grab valid id |
|
281 | + $valid_data['id'] = $id; |
|
282 | + // array of other form names |
|
283 | + $inputs_to_clean = array( |
|
284 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
285 | + 'rows' => 'tkt-slctr-rows-', |
|
286 | + 'qty' => 'tkt-slctr-qty-', |
|
287 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
288 | + 'return_url' => 'tkt-slctr-return-url-', |
|
289 | + ); |
|
290 | + // let's track the total number of tickets ordered.' |
|
291 | + $valid_data['total_tickets'] = 0; |
|
292 | + // cycle through $inputs_to_clean array |
|
293 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
294 | + $input_key = "{$input_to_clean}{$id}"; |
|
295 | + // check for POST data |
|
296 | + if ($this->request->requestParamIsSet($input_key)) { |
|
297 | + switch ($what) { |
|
298 | + // integers |
|
299 | + case 'event_id': |
|
300 | + case 'rows': |
|
301 | + case 'max_atndz': |
|
302 | + $valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int'); |
|
303 | + break; |
|
304 | + // arrays of integers |
|
305 | + case 'qty': |
|
306 | + $max_atndz = $valid_data['max_atndz'] ?? $this->request->getRequestParam($input_key, 0, 'int'); |
|
307 | + /** @var array $row_qty */ |
|
308 | + $row_qty = $max_atndz !== 1 |
|
309 | + ? $this->request->getRequestParam($input_key, [], 'int', true, '-') |
|
310 | + : $this->request->getRequestParam($input_key); |
|
311 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
312 | + if (! is_array($row_qty)) { |
|
313 | + /** @var string $row_qty */ |
|
314 | + // get number of rows |
|
315 | + $rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int'); |
|
316 | + // explode integers by the dash |
|
317 | + $row_qty = explode('-', $row_qty); |
|
318 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
319 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
320 | + $row_qty = array($row => $qty); |
|
321 | + for ($x = 1; $x <= $rows; $x++) { |
|
322 | + if (! isset($row_qty[ $x ])) { |
|
323 | + $row_qty[ $x ] = 0; |
|
324 | + } |
|
325 | + } |
|
326 | + } |
|
327 | + ksort($row_qty); |
|
328 | + // cycle thru values |
|
329 | + foreach ($row_qty as $qty) { |
|
330 | + $qty = absint($qty); |
|
331 | + // sanitize as integers |
|
332 | + $valid_data[ $what ][] = $qty; |
|
333 | + $valid_data['total_tickets'] += $qty; |
|
334 | + } |
|
335 | + break; |
|
336 | + // array of integers |
|
337 | + case 'ticket_id': |
|
338 | + $ticket_ids = (array) $this->request->getRequestParam($input_key, [], 'int', true); |
|
339 | + // cycle thru values |
|
340 | + foreach ($ticket_ids as $key => $value) { |
|
341 | + // allow only integers |
|
342 | + $valid_data[ $what ][ $key ] = absint($value); |
|
343 | + } |
|
344 | + break; |
|
345 | + case 'return_url': |
|
346 | + // grab and sanitize return-url |
|
347 | + $input_value = $this->request->getRequestParam($input_key, '', 'url'); |
|
348 | + // was the request coming from an iframe ? if so, then: |
|
349 | + if (strpos($input_value, 'event_list=iframe')) { |
|
350 | + // get anchor fragment |
|
351 | + $input_value = explode('#', $input_value); |
|
352 | + $input_value = end($input_value); |
|
353 | + // use event list url instead, but append anchor |
|
354 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
355 | + } |
|
356 | + $valid_data[ $what ] = $input_value; |
|
357 | + break; |
|
358 | + } // end switch $what |
|
359 | + } |
|
360 | + } // end foreach $inputs_to_clean |
|
361 | + return $valid_data; |
|
362 | + } |
|
363 | 363 | |
364 | 364 | |
365 | - /** |
|
366 | - * @param array $valid |
|
367 | - */ |
|
368 | - private function maxAttendeesViolation(array $valid) |
|
369 | - { |
|
370 | - // ordering too many tickets !!! |
|
371 | - $total_tickets_string = esc_html( |
|
372 | - _n( |
|
373 | - 'You have attempted to purchase %s ticket.', |
|
374 | - 'You have attempted to purchase %s tickets.', |
|
375 | - $valid['total_tickets'], |
|
376 | - 'event_espresso' |
|
377 | - ) |
|
378 | - ); |
|
379 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
380 | - // dev only message |
|
381 | - $max_attendees_string = esc_html( |
|
382 | - _n( |
|
383 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
384 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
385 | - $valid['max_atndz'], |
|
386 | - 'event_espresso' |
|
387 | - ) |
|
388 | - ); |
|
389 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
390 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
391 | - } |
|
365 | + /** |
|
366 | + * @param array $valid |
|
367 | + */ |
|
368 | + private function maxAttendeesViolation(array $valid) |
|
369 | + { |
|
370 | + // ordering too many tickets !!! |
|
371 | + $total_tickets_string = esc_html( |
|
372 | + _n( |
|
373 | + 'You have attempted to purchase %s ticket.', |
|
374 | + 'You have attempted to purchase %s tickets.', |
|
375 | + $valid['total_tickets'], |
|
376 | + 'event_espresso' |
|
377 | + ) |
|
378 | + ); |
|
379 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
380 | + // dev only message |
|
381 | + $max_attendees_string = esc_html( |
|
382 | + _n( |
|
383 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
384 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
385 | + $valid['max_atndz'], |
|
386 | + 'event_espresso' |
|
387 | + ) |
|
388 | + ); |
|
389 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
390 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
391 | + } |
|
392 | 392 | |
393 | 393 | |
394 | - /** |
|
395 | - * @param array $valid |
|
396 | - * @return int |
|
397 | - * @throws EE_Error |
|
398 | - * @throws InvalidArgumentException |
|
399 | - * @throws InvalidDataTypeException |
|
400 | - * @throws InvalidInterfaceException |
|
401 | - */ |
|
402 | - private function addTicketsToCart(array $valid) |
|
403 | - { |
|
404 | - $tickets_added = 0; |
|
405 | - $tickets_selected = false; |
|
406 | - if (! empty($valid) && $valid['total_tickets'] > 0) { |
|
407 | - // load cart using factory because we don't want to do so until actually needed |
|
408 | - $this->cart = CartFactory::getCart(); |
|
409 | - // if the user is an admin that can edit registrations, |
|
410 | - // then we'll also allow them to add any tickets, even if they are expired |
|
411 | - $current_user_is_admin = current_user_can('ee_edit_registrations'); |
|
412 | - // cycle thru the number of data rows sent from the event listing |
|
413 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
414 | - // does this row actually contain a ticket quantity? |
|
415 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
416 | - // YES we have a ticket quantity |
|
417 | - $tickets_selected = true; |
|
418 | - $valid_ticket = false; |
|
419 | - if (isset($valid['ticket_id'][ $x ])) { |
|
420 | - // get ticket via the ticket id we put in the form |
|
421 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
422 | - if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { |
|
423 | - $valid_ticket = true; |
|
424 | - $tickets_added += $this->addTicketToCart( |
|
425 | - $ticket, |
|
426 | - $valid['qty'][ $x ] |
|
427 | - ); |
|
428 | - } |
|
429 | - } |
|
430 | - if ($valid_ticket !== true) { |
|
431 | - // nothing added to cart retrieved |
|
432 | - EE_Error::add_error( |
|
433 | - sprintf( |
|
434 | - esc_html__( |
|
435 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
436 | - 'event_espresso' |
|
437 | - ), |
|
438 | - '<br/>' |
|
439 | - ), |
|
440 | - __FILE__, |
|
441 | - __FUNCTION__, |
|
442 | - __LINE__ |
|
443 | - ); |
|
444 | - } |
|
445 | - if (EE_Error::has_error()) { |
|
446 | - break; |
|
447 | - } |
|
448 | - } |
|
449 | - } |
|
450 | - } |
|
451 | - do_action( |
|
452 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
453 | - $this->cart, |
|
454 | - $this |
|
455 | - ); |
|
456 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
457 | - // no ticket quantities were selected |
|
458 | - EE_Error::add_error( |
|
459 | - esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
460 | - __FILE__, |
|
461 | - __FUNCTION__, |
|
462 | - __LINE__ |
|
463 | - ); |
|
464 | - } |
|
465 | - return $tickets_added; |
|
466 | - } |
|
394 | + /** |
|
395 | + * @param array $valid |
|
396 | + * @return int |
|
397 | + * @throws EE_Error |
|
398 | + * @throws InvalidArgumentException |
|
399 | + * @throws InvalidDataTypeException |
|
400 | + * @throws InvalidInterfaceException |
|
401 | + */ |
|
402 | + private function addTicketsToCart(array $valid) |
|
403 | + { |
|
404 | + $tickets_added = 0; |
|
405 | + $tickets_selected = false; |
|
406 | + if (! empty($valid) && $valid['total_tickets'] > 0) { |
|
407 | + // load cart using factory because we don't want to do so until actually needed |
|
408 | + $this->cart = CartFactory::getCart(); |
|
409 | + // if the user is an admin that can edit registrations, |
|
410 | + // then we'll also allow them to add any tickets, even if they are expired |
|
411 | + $current_user_is_admin = current_user_can('ee_edit_registrations'); |
|
412 | + // cycle thru the number of data rows sent from the event listing |
|
413 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
414 | + // does this row actually contain a ticket quantity? |
|
415 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
416 | + // YES we have a ticket quantity |
|
417 | + $tickets_selected = true; |
|
418 | + $valid_ticket = false; |
|
419 | + if (isset($valid['ticket_id'][ $x ])) { |
|
420 | + // get ticket via the ticket id we put in the form |
|
421 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
422 | + if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { |
|
423 | + $valid_ticket = true; |
|
424 | + $tickets_added += $this->addTicketToCart( |
|
425 | + $ticket, |
|
426 | + $valid['qty'][ $x ] |
|
427 | + ); |
|
428 | + } |
|
429 | + } |
|
430 | + if ($valid_ticket !== true) { |
|
431 | + // nothing added to cart retrieved |
|
432 | + EE_Error::add_error( |
|
433 | + sprintf( |
|
434 | + esc_html__( |
|
435 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
436 | + 'event_espresso' |
|
437 | + ), |
|
438 | + '<br/>' |
|
439 | + ), |
|
440 | + __FILE__, |
|
441 | + __FUNCTION__, |
|
442 | + __LINE__ |
|
443 | + ); |
|
444 | + } |
|
445 | + if (EE_Error::has_error()) { |
|
446 | + break; |
|
447 | + } |
|
448 | + } |
|
449 | + } |
|
450 | + } |
|
451 | + do_action( |
|
452 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
453 | + $this->cart, |
|
454 | + $this |
|
455 | + ); |
|
456 | + if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
457 | + // no ticket quantities were selected |
|
458 | + EE_Error::add_error( |
|
459 | + esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
460 | + __FILE__, |
|
461 | + __FUNCTION__, |
|
462 | + __LINE__ |
|
463 | + ); |
|
464 | + } |
|
465 | + return $tickets_added; |
|
466 | + } |
|
467 | 467 | |
468 | 468 | |
469 | - /** |
|
470 | - * adds a ticket to the cart |
|
471 | - * |
|
472 | - * @param EE_Ticket $ticket |
|
473 | - * @param int $qty |
|
474 | - * @return bool TRUE on success, FALSE on fail |
|
475 | - * @throws InvalidArgumentException |
|
476 | - * @throws InvalidInterfaceException |
|
477 | - * @throws InvalidDataTypeException |
|
478 | - * @throws EE_Error |
|
479 | - */ |
|
480 | - private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
481 | - { |
|
482 | - // get the number of spaces left for this datetime ticket |
|
483 | - $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
484 | - // compare available spaces against the number of tickets being purchased |
|
485 | - if ($available_spaces >= $qty) { |
|
486 | - // allow addons to prevent a ticket from being added to cart |
|
487 | - if ( |
|
488 | - ! apply_filters( |
|
489 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
490 | - true, |
|
491 | - $ticket, |
|
492 | - $qty, |
|
493 | - $available_spaces |
|
494 | - ) |
|
495 | - ) { |
|
496 | - return false; |
|
497 | - } |
|
498 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
499 | - // add event to cart |
|
500 | - if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
501 | - $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
502 | - return true; |
|
503 | - } |
|
504 | - return false; |
|
505 | - } |
|
506 | - $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
507 | - return false; |
|
508 | - } |
|
469 | + /** |
|
470 | + * adds a ticket to the cart |
|
471 | + * |
|
472 | + * @param EE_Ticket $ticket |
|
473 | + * @param int $qty |
|
474 | + * @return bool TRUE on success, FALSE on fail |
|
475 | + * @throws InvalidArgumentException |
|
476 | + * @throws InvalidInterfaceException |
|
477 | + * @throws InvalidDataTypeException |
|
478 | + * @throws EE_Error |
|
479 | + */ |
|
480 | + private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
481 | + { |
|
482 | + // get the number of spaces left for this datetime ticket |
|
483 | + $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
484 | + // compare available spaces against the number of tickets being purchased |
|
485 | + if ($available_spaces >= $qty) { |
|
486 | + // allow addons to prevent a ticket from being added to cart |
|
487 | + if ( |
|
488 | + ! apply_filters( |
|
489 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
490 | + true, |
|
491 | + $ticket, |
|
492 | + $qty, |
|
493 | + $available_spaces |
|
494 | + ) |
|
495 | + ) { |
|
496 | + return false; |
|
497 | + } |
|
498 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
499 | + // add event to cart |
|
500 | + if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
501 | + $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
502 | + return true; |
|
503 | + } |
|
504 | + return false; |
|
505 | + } |
|
506 | + $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
507 | + return false; |
|
508 | + } |
|
509 | 509 | |
510 | 510 | |
511 | - /** |
|
512 | - * @param $tickets_added |
|
513 | - * @return bool |
|
514 | - * @throws InvalidInterfaceException |
|
515 | - * @throws InvalidDataTypeException |
|
516 | - * @throws EE_Error |
|
517 | - * @throws InvalidArgumentException |
|
518 | - */ |
|
519 | - private function processSuccessfulCart($tickets_added) |
|
520 | - { |
|
521 | - // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
522 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
523 | - // make sure cart is loaded |
|
524 | - if (! $this->cart instanceof EE_Cart) { |
|
525 | - $this->cart = CartFactory::getCart(); |
|
526 | - } |
|
527 | - do_action( |
|
528 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
529 | - $this->cart, |
|
530 | - $this |
|
531 | - ); |
|
532 | - $this->cart->recalculate_all_cart_totals(); |
|
533 | - $this->cart->save_cart(false); |
|
534 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
535 | - // just return TRUE for registrations being made from admin |
|
536 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
537 | - return true; |
|
538 | - } |
|
539 | - EEH_URL::safeRedirectAndExit( |
|
540 | - apply_filters( |
|
541 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
542 | - $this->core_config->reg_page_url() |
|
543 | - ) |
|
544 | - ); |
|
545 | - } |
|
546 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
547 | - // nothing added to cart |
|
548 | - EE_Error::add_attention( |
|
549 | - esc_html__('No tickets were added for the event', 'event_espresso'), |
|
550 | - __FILE__, |
|
551 | - __FUNCTION__, |
|
552 | - __LINE__ |
|
553 | - ); |
|
554 | - } |
|
555 | - return false; |
|
556 | - } |
|
511 | + /** |
|
512 | + * @param $tickets_added |
|
513 | + * @return bool |
|
514 | + * @throws InvalidInterfaceException |
|
515 | + * @throws InvalidDataTypeException |
|
516 | + * @throws EE_Error |
|
517 | + * @throws InvalidArgumentException |
|
518 | + */ |
|
519 | + private function processSuccessfulCart($tickets_added) |
|
520 | + { |
|
521 | + // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
522 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
523 | + // make sure cart is loaded |
|
524 | + if (! $this->cart instanceof EE_Cart) { |
|
525 | + $this->cart = CartFactory::getCart(); |
|
526 | + } |
|
527 | + do_action( |
|
528 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
529 | + $this->cart, |
|
530 | + $this |
|
531 | + ); |
|
532 | + $this->cart->recalculate_all_cart_totals(); |
|
533 | + $this->cart->save_cart(false); |
|
534 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
535 | + // just return TRUE for registrations being made from admin |
|
536 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
537 | + return true; |
|
538 | + } |
|
539 | + EEH_URL::safeRedirectAndExit( |
|
540 | + apply_filters( |
|
541 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
542 | + $this->core_config->reg_page_url() |
|
543 | + ) |
|
544 | + ); |
|
545 | + } |
|
546 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
547 | + // nothing added to cart |
|
548 | + EE_Error::add_attention( |
|
549 | + esc_html__('No tickets were added for the event', 'event_espresso'), |
|
550 | + __FILE__, |
|
551 | + __FUNCTION__, |
|
552 | + __LINE__ |
|
553 | + ); |
|
554 | + } |
|
555 | + return false; |
|
556 | + } |
|
557 | 557 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | public function cancelTicketSelections() |
119 | 119 | { |
120 | 120 | // check nonce |
121 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
121 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | $this->session->clear_session(__CLASS__, __FUNCTION__); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | ); |
131 | 131 | } |
132 | 132 | EEH_URL::safeRedirectAndExit( |
133 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
133 | + site_url('/'.$this->core_config->event_cpt_slug.'/') |
|
134 | 134 | ); |
135 | 135 | return true; |
136 | 136 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $this->validatePostData($id) |
209 | 209 | ); |
210 | 210 | // check total tickets ordered vs max number of attendees that can register |
211 | - if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { |
|
211 | + if ( ! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { |
|
212 | 212 | $this->maxAttendeesViolation($valid); |
213 | 213 | } else { |
214 | 214 | // all data appears to be valid |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | private function getEventId() |
239 | 239 | { |
240 | 240 | // do we have an event id? |
241 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
241 | + if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
242 | 242 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
243 | 243 | EE_Error::add_error( |
244 | 244 | sprintf( |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | */ |
267 | 267 | private function validatePostData($id = 0) |
268 | 268 | { |
269 | - if (! $id) { |
|
269 | + if ( ! $id) { |
|
270 | 270 | EE_Error::add_error( |
271 | 271 | esc_html__('The event id provided was not valid.', 'event_espresso'), |
272 | 272 | __FILE__, |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | case 'event_id': |
300 | 300 | case 'rows': |
301 | 301 | case 'max_atndz': |
302 | - $valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int'); |
|
302 | + $valid_data[$what] = $this->request->getRequestParam($input_key, 0, 'int'); |
|
303 | 303 | break; |
304 | 304 | // arrays of integers |
305 | 305 | case 'qty': |
@@ -309,18 +309,18 @@ discard block |
||
309 | 309 | ? $this->request->getRequestParam($input_key, [], 'int', true, '-') |
310 | 310 | : $this->request->getRequestParam($input_key); |
311 | 311 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
312 | - if (! is_array($row_qty)) { |
|
312 | + if ( ! is_array($row_qty)) { |
|
313 | 313 | /** @var string $row_qty */ |
314 | 314 | // get number of rows |
315 | - $rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int'); |
|
315 | + $rows = $this->request->getRequestParam('tkt-slctr-rows-'.$id, 1, 'int'); |
|
316 | 316 | // explode integers by the dash |
317 | 317 | $row_qty = explode('-', $row_qty); |
318 | 318 | $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
319 | 319 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
320 | 320 | $row_qty = array($row => $qty); |
321 | 321 | for ($x = 1; $x <= $rows; $x++) { |
322 | - if (! isset($row_qty[ $x ])) { |
|
323 | - $row_qty[ $x ] = 0; |
|
322 | + if ( ! isset($row_qty[$x])) { |
|
323 | + $row_qty[$x] = 0; |
|
324 | 324 | } |
325 | 325 | } |
326 | 326 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | foreach ($row_qty as $qty) { |
330 | 330 | $qty = absint($qty); |
331 | 331 | // sanitize as integers |
332 | - $valid_data[ $what ][] = $qty; |
|
332 | + $valid_data[$what][] = $qty; |
|
333 | 333 | $valid_data['total_tickets'] += $qty; |
334 | 334 | } |
335 | 335 | break; |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | // cycle thru values |
340 | 340 | foreach ($ticket_ids as $key => $value) { |
341 | 341 | // allow only integers |
342 | - $valid_data[ $what ][ $key ] = absint($value); |
|
342 | + $valid_data[$what][$key] = absint($value); |
|
343 | 343 | } |
344 | 344 | break; |
345 | 345 | case 'return_url': |
@@ -351,9 +351,9 @@ discard block |
||
351 | 351 | $input_value = explode('#', $input_value); |
352 | 352 | $input_value = end($input_value); |
353 | 353 | // use event list url instead, but append anchor |
354 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
354 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
355 | 355 | } |
356 | - $valid_data[ $what ] = $input_value; |
|
356 | + $valid_data[$what] = $input_value; |
|
357 | 357 | break; |
358 | 358 | } // end switch $what |
359 | 359 | } |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | ) |
388 | 388 | ); |
389 | 389 | $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
390 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
390 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | { |
404 | 404 | $tickets_added = 0; |
405 | 405 | $tickets_selected = false; |
406 | - if (! empty($valid) && $valid['total_tickets'] > 0) { |
|
406 | + if ( ! empty($valid) && $valid['total_tickets'] > 0) { |
|
407 | 407 | // load cart using factory because we don't want to do so until actually needed |
408 | 408 | $this->cart = CartFactory::getCart(); |
409 | 409 | // if the user is an admin that can edit registrations, |
@@ -412,18 +412,18 @@ discard block |
||
412 | 412 | // cycle thru the number of data rows sent from the event listing |
413 | 413 | for ($x = 0; $x < $valid['rows']; $x++) { |
414 | 414 | // does this row actually contain a ticket quantity? |
415 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
415 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
416 | 416 | // YES we have a ticket quantity |
417 | 417 | $tickets_selected = true; |
418 | 418 | $valid_ticket = false; |
419 | - if (isset($valid['ticket_id'][ $x ])) { |
|
419 | + if (isset($valid['ticket_id'][$x])) { |
|
420 | 420 | // get ticket via the ticket id we put in the form |
421 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
421 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]); |
|
422 | 422 | if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { |
423 | 423 | $valid_ticket = true; |
424 | 424 | $tickets_added += $this->addTicketToCart( |
425 | 425 | $ticket, |
426 | - $valid['qty'][ $x ] |
|
426 | + $valid['qty'][$x] |
|
427 | 427 | ); |
428 | 428 | } |
429 | 429 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | $this->cart, |
454 | 454 | $this |
455 | 455 | ); |
456 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
456 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
457 | 457 | // no ticket quantities were selected |
458 | 458 | EE_Error::add_error( |
459 | 459 | esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
522 | 522 | if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
523 | 523 | // make sure cart is loaded |
524 | - if (! $this->cart instanceof EE_Cart) { |
|
524 | + if ( ! $this->cart instanceof EE_Cart) { |
|
525 | 525 | $this->cart = CartFactory::getCart(); |
526 | 526 | } |
527 | 527 | do_action( |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | ) |
544 | 544 | ); |
545 | 545 | } |
546 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
546 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
547 | 547 | // nothing added to cart |
548 | 548 | EE_Error::add_attention( |
549 | 549 | esc_html__('No tickets were added for the event', 'event_espresso'), |