@@ -15,89 +15,89 @@ |
||
15 | 15 | class EE_PMT_Paypal_Express extends EE_PMT_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * EE_PMT_Paypal_Express constructor. |
|
20 | - */ |
|
21 | - public function __construct($pm_instance = null) |
|
22 | - { |
|
23 | - require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
24 | - $this->_gateway = new EEG_Paypal_Express(); |
|
18 | + /** |
|
19 | + * EE_PMT_Paypal_Express constructor. |
|
20 | + */ |
|
21 | + public function __construct($pm_instance = null) |
|
22 | + { |
|
23 | + require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
24 | + $this->_gateway = new EEG_Paypal_Express(); |
|
25 | 25 | |
26 | - $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
27 | - $this->_template_path = $this->file_folder() . 'templates/'; |
|
28 | - $this->_default_description = esc_html__( |
|
29 | - // @codingStandardsIgnoreStart |
|
30 | - 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
31 | - // @codingStandardsIgnoreEnd |
|
32 | - 'event_espresso' |
|
33 | - ); |
|
34 | - $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
26 | + $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
27 | + $this->_template_path = $this->file_folder() . 'templates/'; |
|
28 | + $this->_default_description = esc_html__( |
|
29 | + // @codingStandardsIgnoreStart |
|
30 | + 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
31 | + // @codingStandardsIgnoreEnd |
|
32 | + 'event_espresso' |
|
33 | + ); |
|
34 | + $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
35 | 35 | |
36 | - parent::__construct($pm_instance); |
|
37 | - } |
|
36 | + parent::__construct($pm_instance); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Adds the help tab. |
|
42 | - * |
|
43 | - * @see EE_PMT_Base::help_tabs_config() |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function help_tabs_config() |
|
47 | - { |
|
48 | - return array( |
|
49 | - $this->get_help_tab_name() => array( |
|
50 | - 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
51 | - 'filename' => 'payment_methods_overview_paypal_express' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
40 | + /** |
|
41 | + * Adds the help tab. |
|
42 | + * |
|
43 | + * @see EE_PMT_Base::help_tabs_config() |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function help_tabs_config() |
|
47 | + { |
|
48 | + return array( |
|
49 | + $this->get_help_tab_name() => array( |
|
50 | + 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
51 | + 'filename' => 'payment_methods_overview_paypal_express' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Gets the form for all the settings related to this payment method type. |
|
59 | - * |
|
60 | - * @return EE_Payment_Method_Form |
|
61 | - */ |
|
62 | - public function generate_new_settings_form() |
|
63 | - { |
|
64 | - return new SettingsForm(array(), $this->get_help_tab_link()); |
|
65 | - } |
|
57 | + /** |
|
58 | + * Gets the form for all the settings related to this payment method type. |
|
59 | + * |
|
60 | + * @return EE_Payment_Method_Form |
|
61 | + */ |
|
62 | + public function generate_new_settings_form() |
|
63 | + { |
|
64 | + return new SettingsForm(array(), $this->get_help_tab_link()); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Creates a billing form for this payment method type. |
|
70 | - * |
|
71 | - * @param \EE_Transaction $transaction |
|
72 | - * @return \EE_Billing_Info_Form |
|
73 | - */ |
|
74 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
75 | - { |
|
76 | - if ($this->_pm_instance->debug_mode()) { |
|
77 | - $form = new EE_Billing_Info_Form( |
|
78 | - $this->_pm_instance, |
|
79 | - array( |
|
80 | - 'name' => 'paypal_express_Info_Form', |
|
81 | - 'subsections' => array( |
|
82 | - 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
83 | - array( |
|
84 | - 'layout_strategy' => new EE_Template_Layout( |
|
85 | - array( |
|
86 | - 'layout_template_file' => $this->_template_path |
|
87 | - . 'paypal_express_debug_info.template.php', |
|
88 | - 'template_args' => array( |
|
89 | - 'debug_mode' => $this->_pm_instance->debug_mode() |
|
90 | - ) |
|
91 | - ) |
|
92 | - ) |
|
93 | - ) |
|
94 | - ) |
|
95 | - ) |
|
96 | - ) |
|
97 | - ); |
|
98 | - return $form; |
|
99 | - } |
|
68 | + /** |
|
69 | + * Creates a billing form for this payment method type. |
|
70 | + * |
|
71 | + * @param \EE_Transaction $transaction |
|
72 | + * @return \EE_Billing_Info_Form |
|
73 | + */ |
|
74 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
75 | + { |
|
76 | + if ($this->_pm_instance->debug_mode()) { |
|
77 | + $form = new EE_Billing_Info_Form( |
|
78 | + $this->_pm_instance, |
|
79 | + array( |
|
80 | + 'name' => 'paypal_express_Info_Form', |
|
81 | + 'subsections' => array( |
|
82 | + 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
83 | + array( |
|
84 | + 'layout_strategy' => new EE_Template_Layout( |
|
85 | + array( |
|
86 | + 'layout_template_file' => $this->_template_path |
|
87 | + . 'paypal_express_debug_info.template.php', |
|
88 | + 'template_args' => array( |
|
89 | + 'debug_mode' => $this->_pm_instance->debug_mode() |
|
90 | + ) |
|
91 | + ) |
|
92 | + ) |
|
93 | + ) |
|
94 | + ) |
|
95 | + ) |
|
96 | + ) |
|
97 | + ); |
|
98 | + return $form; |
|
99 | + } |
|
100 | 100 | |
101 | - return false; |
|
102 | - } |
|
101 | + return false; |
|
102 | + } |
|
103 | 103 | } |
@@ -20,18 +20,18 @@ |
||
20 | 20 | */ |
21 | 21 | public function __construct($pm_instance = null) |
22 | 22 | { |
23 | - require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
23 | + require_once($this->file_folder().'EEG_Paypal_Express.gateway.php'); |
|
24 | 24 | $this->_gateway = new EEG_Paypal_Express(); |
25 | 25 | |
26 | 26 | $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
27 | - $this->_template_path = $this->file_folder() . 'templates/'; |
|
27 | + $this->_template_path = $this->file_folder().'templates/'; |
|
28 | 28 | $this->_default_description = esc_html__( |
29 | 29 | // @codingStandardsIgnoreStart |
30 | 30 | 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
31 | 31 | // @codingStandardsIgnoreEnd |
32 | 32 | 'event_espresso' |
33 | 33 | ); |
34 | - $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
34 | + $this->_default_button_url = $this->file_url().'lib/paypal-express-checkout-logo-gold-160.png'; |
|
35 | 35 | |
36 | 36 | parent::__construct($pm_instance); |
37 | 37 | } |
@@ -18,332 +18,332 @@ |
||
18 | 18 | class EED_Recaptcha_Invisible extends EED_Module |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Registration_Config $config |
|
23 | - */ |
|
24 | - private static $config; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @return EED_Module|EED_Recaptcha |
|
29 | - */ |
|
30 | - public static function instance() |
|
31 | - { |
|
32 | - return parent::get_instance(__CLASS__); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @return void |
|
38 | - * @throws InvalidInterfaceException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidArgumentException |
|
41 | - */ |
|
42 | - public static function set_hooks() |
|
43 | - { |
|
44 | - EED_Recaptcha_Invisible::setProperties(); |
|
45 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
46 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
47 | - // ticket selection |
|
48 | - add_filter( |
|
49 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
50 | - array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
51 | - 10, |
|
52 | - 3 |
|
53 | - ); |
|
54 | - add_action( |
|
55 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
56 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
57 | - ); |
|
58 | - } |
|
59 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
60 | - // checkout |
|
61 | - add_action( |
|
62 | - 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
63 | - array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
64 | - ); |
|
65 | - add_filter( |
|
66 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
67 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
68 | - 10, |
|
69 | - 2 |
|
70 | - ); |
|
71 | - } |
|
72 | - add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return void |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - * @throws InvalidArgumentException |
|
82 | - */ |
|
83 | - public static function set_hooks_admin() |
|
84 | - { |
|
85 | - EED_Recaptcha_Invisible::setProperties(); |
|
86 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
87 | - add_action( |
|
88 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
89 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
90 | - ); |
|
91 | - } |
|
92 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
93 | - add_filter( |
|
94 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
95 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
96 | - 10, |
|
97 | - 2 |
|
98 | - ); |
|
99 | - } |
|
100 | - // admin settings |
|
101 | - add_action( |
|
102 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | - array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | - ); |
|
105 | - add_filter( |
|
106 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | - array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return void |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidArgumentException |
|
117 | - */ |
|
118 | - public static function setProperties() |
|
119 | - { |
|
120 | - |
|
121 | - EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return boolean |
|
127 | - */ |
|
128 | - public static function useInvisibleRecaptcha() |
|
129 | - { |
|
130 | - return EED_Recaptcha_Invisible::$config->use_captcha |
|
131 | - && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param string $form |
|
137 | - * @return boolean |
|
138 | - */ |
|
139 | - public static function protectForm($form) |
|
140 | - { |
|
141 | - return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
142 | - && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return void |
|
148 | - * @throws InvalidInterfaceException |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws InvalidArgumentException |
|
151 | - */ |
|
152 | - public static function localizeScriptVars() |
|
153 | - { |
|
154 | - /** @var \EventEspresso\core\services\request\Request $request */ |
|
155 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
156 | - // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
157 | - // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
158 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | - return; |
|
160 | - } |
|
161 | - wp_localize_script( |
|
162 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
163 | - 'eeRecaptcha', |
|
164 | - RecaptchaFactory::create()->getLocalizedVars() |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public static function assetsUrl() |
|
173 | - { |
|
174 | - return plugin_dir_url(__FILE__) . 'assets/'; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param \WP $WP |
|
180 | - */ |
|
181 | - public function run($WP) |
|
182 | - { |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param RequestInterface $request |
|
188 | - * @return bool |
|
189 | - * @throws InvalidArgumentException |
|
190 | - * @throws InvalidDataTypeException |
|
191 | - * @throws InvalidInterfaceException |
|
192 | - * @throws RuntimeException |
|
193 | - */ |
|
194 | - public static function verifyToken(RequestInterface $request) |
|
195 | - { |
|
196 | - return RecaptchaFactory::create()->verifyToken($request); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param EE_Form_Section_Proper $reg_form |
|
202 | - * @return void |
|
203 | - * @throws EE_Error |
|
204 | - * @throws InvalidArgumentException |
|
205 | - * @throws InvalidDataTypeException |
|
206 | - * @throws InvalidInterfaceException |
|
207 | - * @throws DomainException |
|
208 | - */ |
|
209 | - public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
210 | - { |
|
211 | - // do nothing if form isn't for a reg step or test has already been passed |
|
212 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | - return; |
|
214 | - } |
|
215 | - $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
216 | - if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
217 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
218 | - $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * @param EE_Form_Section_Proper $reg_form |
|
225 | - * @return bool |
|
226 | - * @throws InvalidDataTypeException |
|
227 | - * @throws InvalidInterfaceException |
|
228 | - * @throws EE_Error |
|
229 | - * @throws InvalidArgumentException |
|
230 | - */ |
|
231 | - public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
232 | - { |
|
233 | - return strpos($reg_form->name(), 'reg-step-form') !== false |
|
234 | - && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param array|null $req_data |
|
240 | - * @param EE_Form_Section_Proper $reg_form |
|
241 | - * @return array |
|
242 | - * @throws EE_Error |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - * @throws InvalidInterfaceException |
|
246 | - * @throws RuntimeException |
|
247 | - */ |
|
248 | - public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
249 | - { |
|
250 | - // do nothing if form isn't for a reg step or test has already been passed |
|
251 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | - return $req_data; |
|
253 | - } |
|
254 | - /** @var RequestInterface $request */ |
|
255 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
256 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | - if ($request->isAjax()) { |
|
258 | - $json_response = new EE_SPCO_JSON_Response(); |
|
259 | - $json_response->echoAndExit(); |
|
260 | - } |
|
261 | - EEH_URL::safeRedirectAndExit( |
|
262 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
263 | - ); |
|
264 | - } |
|
265 | - return $req_data; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @param string $html |
|
271 | - * @param EE_Event $event |
|
272 | - * @param bool $iframe |
|
273 | - * @return string |
|
274 | - * @throws EE_Error |
|
275 | - * @throws InvalidArgumentException |
|
276 | - * @throws InvalidDataTypeException |
|
277 | - * @throws InvalidInterfaceException |
|
278 | - * @throws ReflectionException |
|
279 | - * @throws DomainException |
|
280 | - */ |
|
281 | - public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
282 | - { |
|
283 | - $recaptcha = RecaptchaFactory::create(); |
|
284 | - // do nothing if test has already been passed |
|
285 | - if ($recaptcha->recaptchaPassed()) { |
|
286 | - return $html; |
|
287 | - } |
|
288 | - $html .= $recaptcha->getInputHtml( |
|
289 | - array( |
|
290 | - 'recaptcha_id' => $event->ID(), |
|
291 | - 'iframe' => $iframe, |
|
292 | - 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
293 | - ) |
|
294 | - ); |
|
295 | - return $html; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @return void |
|
301 | - * @throws InvalidArgumentException |
|
302 | - * @throws InvalidInterfaceException |
|
303 | - * @throws InvalidDataTypeException |
|
304 | - * @throws RuntimeException |
|
305 | - */ |
|
306 | - public static function processTicketSelectorForm() |
|
307 | - { |
|
308 | - // do nothing if test has already been passed |
|
309 | - if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
310 | - return; |
|
311 | - } |
|
312 | - /** @var RequestInterface $request */ |
|
313 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
314 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | - $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
|
316 | - $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
|
317 | - ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |
|
318 | - : get_permalink($event_id); |
|
319 | - EEH_URL::safeRedirectAndExit($return_url); |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @throws EE_Error |
|
326 | - * @throws InvalidArgumentException |
|
327 | - * @throws InvalidDataTypeException |
|
328 | - * @throws InvalidInterfaceException |
|
329 | - */ |
|
330 | - public static function adminSettings() |
|
331 | - { |
|
332 | - RecaptchaFactory::getAdminModule()->adminSettings(); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param EE_Registration_Config $EE_Registration_Config |
|
338 | - * @return EE_Registration_Config |
|
339 | - * @throws EE_Error |
|
340 | - * @throws InvalidArgumentException |
|
341 | - * @throws InvalidDataTypeException |
|
342 | - * @throws InvalidInterfaceException |
|
343 | - * @throws ReflectionException |
|
344 | - */ |
|
345 | - public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
346 | - { |
|
347 | - return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
348 | - } |
|
21 | + /** |
|
22 | + * @var EE_Registration_Config $config |
|
23 | + */ |
|
24 | + private static $config; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @return EED_Module|EED_Recaptcha |
|
29 | + */ |
|
30 | + public static function instance() |
|
31 | + { |
|
32 | + return parent::get_instance(__CLASS__); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + * @throws InvalidInterfaceException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidArgumentException |
|
41 | + */ |
|
42 | + public static function set_hooks() |
|
43 | + { |
|
44 | + EED_Recaptcha_Invisible::setProperties(); |
|
45 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
46 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
47 | + // ticket selection |
|
48 | + add_filter( |
|
49 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
50 | + array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
51 | + 10, |
|
52 | + 3 |
|
53 | + ); |
|
54 | + add_action( |
|
55 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
56 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
57 | + ); |
|
58 | + } |
|
59 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
60 | + // checkout |
|
61 | + add_action( |
|
62 | + 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
63 | + array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
64 | + ); |
|
65 | + add_filter( |
|
66 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
67 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
68 | + 10, |
|
69 | + 2 |
|
70 | + ); |
|
71 | + } |
|
72 | + add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + * @throws InvalidArgumentException |
|
82 | + */ |
|
83 | + public static function set_hooks_admin() |
|
84 | + { |
|
85 | + EED_Recaptcha_Invisible::setProperties(); |
|
86 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
87 | + add_action( |
|
88 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
89 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
90 | + ); |
|
91 | + } |
|
92 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
93 | + add_filter( |
|
94 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
95 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
96 | + 10, |
|
97 | + 2 |
|
98 | + ); |
|
99 | + } |
|
100 | + // admin settings |
|
101 | + add_action( |
|
102 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | + array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | + ); |
|
105 | + add_filter( |
|
106 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | + array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidArgumentException |
|
117 | + */ |
|
118 | + public static function setProperties() |
|
119 | + { |
|
120 | + |
|
121 | + EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return boolean |
|
127 | + */ |
|
128 | + public static function useInvisibleRecaptcha() |
|
129 | + { |
|
130 | + return EED_Recaptcha_Invisible::$config->use_captcha |
|
131 | + && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param string $form |
|
137 | + * @return boolean |
|
138 | + */ |
|
139 | + public static function protectForm($form) |
|
140 | + { |
|
141 | + return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
142 | + && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return void |
|
148 | + * @throws InvalidInterfaceException |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws InvalidArgumentException |
|
151 | + */ |
|
152 | + public static function localizeScriptVars() |
|
153 | + { |
|
154 | + /** @var \EventEspresso\core\services\request\Request $request */ |
|
155 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
156 | + // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
157 | + // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
158 | + if (! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | + return; |
|
160 | + } |
|
161 | + wp_localize_script( |
|
162 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
163 | + 'eeRecaptcha', |
|
164 | + RecaptchaFactory::create()->getLocalizedVars() |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public static function assetsUrl() |
|
173 | + { |
|
174 | + return plugin_dir_url(__FILE__) . 'assets/'; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param \WP $WP |
|
180 | + */ |
|
181 | + public function run($WP) |
|
182 | + { |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param RequestInterface $request |
|
188 | + * @return bool |
|
189 | + * @throws InvalidArgumentException |
|
190 | + * @throws InvalidDataTypeException |
|
191 | + * @throws InvalidInterfaceException |
|
192 | + * @throws RuntimeException |
|
193 | + */ |
|
194 | + public static function verifyToken(RequestInterface $request) |
|
195 | + { |
|
196 | + return RecaptchaFactory::create()->verifyToken($request); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param EE_Form_Section_Proper $reg_form |
|
202 | + * @return void |
|
203 | + * @throws EE_Error |
|
204 | + * @throws InvalidArgumentException |
|
205 | + * @throws InvalidDataTypeException |
|
206 | + * @throws InvalidInterfaceException |
|
207 | + * @throws DomainException |
|
208 | + */ |
|
209 | + public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
210 | + { |
|
211 | + // do nothing if form isn't for a reg step or test has already been passed |
|
212 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | + return; |
|
214 | + } |
|
215 | + $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
216 | + if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
217 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
218 | + $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * @param EE_Form_Section_Proper $reg_form |
|
225 | + * @return bool |
|
226 | + * @throws InvalidDataTypeException |
|
227 | + * @throws InvalidInterfaceException |
|
228 | + * @throws EE_Error |
|
229 | + * @throws InvalidArgumentException |
|
230 | + */ |
|
231 | + public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
232 | + { |
|
233 | + return strpos($reg_form->name(), 'reg-step-form') !== false |
|
234 | + && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param array|null $req_data |
|
240 | + * @param EE_Form_Section_Proper $reg_form |
|
241 | + * @return array |
|
242 | + * @throws EE_Error |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + * @throws InvalidInterfaceException |
|
246 | + * @throws RuntimeException |
|
247 | + */ |
|
248 | + public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
249 | + { |
|
250 | + // do nothing if form isn't for a reg step or test has already been passed |
|
251 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | + return $req_data; |
|
253 | + } |
|
254 | + /** @var RequestInterface $request */ |
|
255 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
256 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | + if ($request->isAjax()) { |
|
258 | + $json_response = new EE_SPCO_JSON_Response(); |
|
259 | + $json_response->echoAndExit(); |
|
260 | + } |
|
261 | + EEH_URL::safeRedirectAndExit( |
|
262 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
263 | + ); |
|
264 | + } |
|
265 | + return $req_data; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @param string $html |
|
271 | + * @param EE_Event $event |
|
272 | + * @param bool $iframe |
|
273 | + * @return string |
|
274 | + * @throws EE_Error |
|
275 | + * @throws InvalidArgumentException |
|
276 | + * @throws InvalidDataTypeException |
|
277 | + * @throws InvalidInterfaceException |
|
278 | + * @throws ReflectionException |
|
279 | + * @throws DomainException |
|
280 | + */ |
|
281 | + public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
282 | + { |
|
283 | + $recaptcha = RecaptchaFactory::create(); |
|
284 | + // do nothing if test has already been passed |
|
285 | + if ($recaptcha->recaptchaPassed()) { |
|
286 | + return $html; |
|
287 | + } |
|
288 | + $html .= $recaptcha->getInputHtml( |
|
289 | + array( |
|
290 | + 'recaptcha_id' => $event->ID(), |
|
291 | + 'iframe' => $iframe, |
|
292 | + 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
293 | + ) |
|
294 | + ); |
|
295 | + return $html; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @return void |
|
301 | + * @throws InvalidArgumentException |
|
302 | + * @throws InvalidInterfaceException |
|
303 | + * @throws InvalidDataTypeException |
|
304 | + * @throws RuntimeException |
|
305 | + */ |
|
306 | + public static function processTicketSelectorForm() |
|
307 | + { |
|
308 | + // do nothing if test has already been passed |
|
309 | + if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
310 | + return; |
|
311 | + } |
|
312 | + /** @var RequestInterface $request */ |
|
313 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
314 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | + $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
|
316 | + $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
|
317 | + ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |
|
318 | + : get_permalink($event_id); |
|
319 | + EEH_URL::safeRedirectAndExit($return_url); |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @throws EE_Error |
|
326 | + * @throws InvalidArgumentException |
|
327 | + * @throws InvalidDataTypeException |
|
328 | + * @throws InvalidInterfaceException |
|
329 | + */ |
|
330 | + public static function adminSettings() |
|
331 | + { |
|
332 | + RecaptchaFactory::getAdminModule()->adminSettings(); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param EE_Registration_Config $EE_Registration_Config |
|
338 | + * @return EE_Registration_Config |
|
339 | + * @throws EE_Error |
|
340 | + * @throws InvalidArgumentException |
|
341 | + * @throws InvalidDataTypeException |
|
342 | + * @throws InvalidInterfaceException |
|
343 | + * @throws ReflectionException |
|
344 | + */ |
|
345 | + public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
346 | + { |
|
347 | + return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
348 | + } |
|
349 | 349 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
156 | 156 | // Invisible Recaptcha is ONLY ever required for the frontend and admin |
157 | 157 | // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
158 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | + if ( ! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | wp_localize_script( |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public static function assetsUrl() |
173 | 173 | { |
174 | - return plugin_dir_url(__FILE__) . 'assets/'; |
|
174 | + return plugin_dir_url(__FILE__).'assets/'; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
210 | 210 | { |
211 | 211 | // do nothing if form isn't for a reg step or test has already been passed |
212 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
@@ -248,12 +248,12 @@ discard block |
||
248 | 248 | public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
249 | 249 | { |
250 | 250 | // do nothing if form isn't for a reg step or test has already been passed |
251 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | 252 | return $req_data; |
253 | 253 | } |
254 | 254 | /** @var RequestInterface $request */ |
255 | 255 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
256 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | 257 | if ($request->isAjax()) { |
258 | 258 | $json_response = new EE_SPCO_JSON_Response(); |
259 | 259 | $json_response->echoAndExit(); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | } |
312 | 312 | /** @var RequestInterface $request */ |
313 | 313 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
314 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | 315 | $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
316 | 316 | $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
317 | 317 | ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | define( |
133 | 133 | 'RECAPTCHA_BASE_PATH', |
134 | - rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/' |
|
134 | + rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/').'/' |
|
135 | 135 | ); |
136 | 136 | define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__)); |
137 | 137 | } |
@@ -184,14 +184,14 @@ discard block |
||
184 | 184 | { |
185 | 185 | wp_register_script( |
186 | 186 | 'espresso_recaptcha', |
187 | - RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js', |
|
187 | + RECAPTCHA_BASE_URL.'scripts/espresso_recaptcha.js', |
|
188 | 188 | array('single_page_checkout'), |
189 | 189 | EVENT_ESPRESSO_VERSION, |
190 | 190 | true |
191 | 191 | ); |
192 | 192 | wp_register_script( |
193 | 193 | 'google_recaptcha', |
194 | - 'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language, |
|
194 | + 'https://www.google.com/recaptcha/api.js?hl='.EED_Recaptcha::$config->recaptcha_language, |
|
195 | 195 | array('espresso_recaptcha'), |
196 | 196 | EVENT_ESPRESSO_VERSION, |
197 | 197 | true |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) { |
252 | 252 | // only display if they have NOT passed the test yet |
253 | 253 | EEH_Template::display_template( |
254 | - RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php', |
|
254 | + RECAPTCHA_BASE_PATH.'/templates/recaptcha.template.php', |
|
255 | 255 | array( |
256 | 256 | 'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey, |
257 | 257 | 'recaptcha_theme' => EED_Recaptcha::$config->recaptcha_theme, |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN); |
297 | 297 | // verify recaptcha |
298 | 298 | EED_Recaptcha::_get_recaptcha_response(); |
299 | - if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) { |
|
299 | + if ( ! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) { |
|
300 | 300 | $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response(); |
301 | 301 | EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed)); |
302 | 302 | } |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | foreach ($bypass_request_params_array as $key => $value) { |
342 | 342 | // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE, |
343 | 343 | // otherwise carry over it's value. This way, one missed setting results in no bypass |
344 | - $bypass_recaptcha = isset($_REQUEST[ $key ]) && $_REQUEST[ $key ] === $value |
|
344 | + $bypass_recaptcha = isset($_REQUEST[$key]) && $_REQUEST[$key] === $value |
|
345 | 345 | ? $bypass_recaptcha |
346 | 346 | : false; |
347 | 347 | } |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | private static function _process_recaptcha_response() |
374 | 374 | { |
375 | 375 | // verify library is loaded |
376 | - if (! class_exists('\ReCaptcha\ReCaptcha')) { |
|
377 | - require_once RECAPTCHA_BASE_PATH . '/autoload.php'; |
|
376 | + if ( ! class_exists('\ReCaptcha\ReCaptcha')) { |
|
377 | + require_once RECAPTCHA_BASE_PATH.'/autoload.php'; |
|
378 | 378 | } |
379 | 379 | // The response from reCAPTCHA |
380 | 380 | EED_Recaptcha::_get_recaptcha_response(); |
@@ -18,382 +18,382 @@ |
||
18 | 18 | class EED_Recaptcha extends EED_Module |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Registration_Config $config |
|
23 | - */ |
|
24 | - private static $config; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type bool $_not_a_robot |
|
28 | - */ |
|
29 | - private static $_not_a_robot; |
|
30 | - |
|
31 | - /** |
|
32 | - * @type string $_recaptcha_response |
|
33 | - */ |
|
34 | - private static $_recaptcha_response; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return EED_Module|EED_Recaptcha |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - return parent::get_instance(__CLASS__); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
48 | - * |
|
49 | - * @return void |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws InvalidInterfaceException |
|
52 | - * @throws InvalidDataTypeException |
|
53 | - */ |
|
54 | - public static function set_hooks() |
|
55 | - { |
|
56 | - EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration; |
|
57 | - // use_captcha ? |
|
58 | - if ( |
|
59 | - EED_Recaptcha::useRecaptcha() |
|
60 | - && EED_Recaptcha::notPaymentOptionsRevisit() |
|
61 | - ) { |
|
62 | - EED_Recaptcha::set_definitions(); |
|
63 | - EED_Recaptcha::enqueue_styles_and_scripts(); |
|
64 | - add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0); |
|
65 | - add_action( |
|
66 | - 'AHEE__before_spco_whats_next_buttons', |
|
67 | - array('EED_Recaptcha', 'display_recaptcha'), |
|
68 | - 10, |
|
69 | - 0 |
|
70 | - ); |
|
71 | - add_filter( |
|
72 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
73 | - array('EED_Recaptcha', 'not_a_robot') |
|
74 | - ); |
|
75 | - add_filter( |
|
76 | - 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', |
|
77 | - array('EED_Recaptcha', 'not_a_robot') |
|
78 | - ); |
|
79 | - add_filter( |
|
80 | - 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', |
|
81 | - array('EED_Recaptcha', 'recaptcha_response') |
|
82 | - ); |
|
83 | - add_filter( |
|
84 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
85 | - array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method') |
|
86 | - ); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
93 | - * |
|
94 | - * @return void |
|
95 | - * @throws InvalidArgumentException |
|
96 | - * @throws InvalidInterfaceException |
|
97 | - * @throws InvalidDataTypeException |
|
98 | - */ |
|
99 | - public static function set_hooks_admin() |
|
100 | - { |
|
101 | - EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration; |
|
102 | - EED_Recaptcha::set_definitions(); |
|
103 | - // use_captcha ? |
|
104 | - if ( |
|
105 | - EED_Recaptcha::useRecaptcha() |
|
106 | - && EED_Recaptcha::notPaymentOptionsRevisit() |
|
107 | - && EE_Registry::instance()->REQ->get('step', '') !== '' |
|
108 | - ) { |
|
109 | - EED_Recaptcha::enqueue_styles_and_scripts(); |
|
110 | - add_filter( |
|
111 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
112 | - array('EED_Recaptcha', 'not_a_robot') |
|
113 | - ); |
|
114 | - add_filter( |
|
115 | - 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', |
|
116 | - array('EED_Recaptcha', 'not_a_robot') |
|
117 | - ); |
|
118 | - add_filter( |
|
119 | - 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', |
|
120 | - array('EED_Recaptcha', 'recaptcha_response') |
|
121 | - ); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public static function set_definitions() |
|
130 | - { |
|
131 | - if (is_user_logged_in()) { |
|
132 | - EED_Recaptcha::$_not_a_robot = true; |
|
133 | - } |
|
134 | - define( |
|
135 | - 'RECAPTCHA_BASE_PATH', |
|
136 | - rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/' |
|
137 | - ); |
|
138 | - define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__)); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public static function set_late_hooks() |
|
146 | - { |
|
147 | - add_filter( |
|
148 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
149 | - array('EED_Recaptcha', 'not_a_robot') |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return boolean |
|
156 | - */ |
|
157 | - public static function useRecaptcha() |
|
158 | - { |
|
159 | - return EED_Recaptcha::$config->use_captcha |
|
160 | - && EED_Recaptcha::$config->recaptcha_theme !== 'invisible'; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @return boolean |
|
166 | - * @throws InvalidArgumentException |
|
167 | - * @throws InvalidInterfaceException |
|
168 | - * @throws InvalidDataTypeException |
|
169 | - */ |
|
170 | - public static function notPaymentOptionsRevisit() |
|
171 | - { |
|
172 | - return ! ( |
|
173 | - EE_Registry::instance()->REQ->get('step', '') === 'payment_options' |
|
174 | - && (bool) EE_Registry::instance()->REQ->get('revisit', false) === true |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @return void |
|
181 | - * @throws InvalidArgumentException |
|
182 | - * @throws InvalidInterfaceException |
|
183 | - * @throws InvalidDataTypeException |
|
184 | - */ |
|
185 | - public static function enqueue_styles_and_scripts() |
|
186 | - { |
|
187 | - wp_register_script( |
|
188 | - 'espresso_recaptcha', |
|
189 | - RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js', |
|
190 | - array('single_page_checkout'), |
|
191 | - EVENT_ESPRESSO_VERSION, |
|
192 | - true |
|
193 | - ); |
|
194 | - wp_register_script( |
|
195 | - 'google_recaptcha', |
|
196 | - 'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language, |
|
197 | - array('espresso_recaptcha'), |
|
198 | - EVENT_ESPRESSO_VERSION, |
|
199 | - true |
|
200 | - ); |
|
201 | - EE_Registry::$i18n_js_strings['no_SPCO_error'] = __( |
|
202 | - 'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', |
|
203 | - 'event_espresso' |
|
204 | - ); |
|
205 | - EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __( |
|
206 | - 'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.', |
|
207 | - 'event_espresso' |
|
208 | - ); |
|
209 | - EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( |
|
210 | - 'Please complete the anti-spam test before proceeding.', |
|
211 | - 'event_espresso' |
|
212 | - ); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @param \WP $WP |
|
218 | - */ |
|
219 | - public function run($WP) |
|
220 | - { |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @return boolean |
|
226 | - * @throws InvalidArgumentException |
|
227 | - * @throws InvalidInterfaceException |
|
228 | - * @throws InvalidDataTypeException |
|
229 | - */ |
|
230 | - public static function not_a_robot() |
|
231 | - { |
|
232 | - $not_a_robot = is_bool(EED_Recaptcha::$_not_a_robot) |
|
233 | - ? EED_Recaptcha::$_not_a_robot |
|
234 | - : EED_Recaptcha::recaptcha_passed(); |
|
235 | - return $not_a_robot; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * @return void |
|
241 | - * @throws DomainException |
|
242 | - * @throws InvalidArgumentException |
|
243 | - * @throws InvalidInterfaceException |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - */ |
|
246 | - public static function display_recaptcha() |
|
247 | - { |
|
248 | - // logged in means you have already passed a turing test of sorts |
|
249 | - if (is_user_logged_in()) { |
|
250 | - return; |
|
251 | - } |
|
252 | - // don't display if not using recaptcha or user is logged in |
|
253 | - if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) { |
|
254 | - // only display if they have NOT passed the test yet |
|
255 | - EEH_Template::display_template( |
|
256 | - RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php', |
|
257 | - array( |
|
258 | - 'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey, |
|
259 | - 'recaptcha_theme' => EED_Recaptcha::$config->recaptcha_theme, |
|
260 | - 'recaptcha_type' => EED_Recaptcha::$config->recaptcha_type, |
|
261 | - ) |
|
262 | - ); |
|
263 | - wp_enqueue_script('google_recaptcha'); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * @return array |
|
270 | - * @throws InvalidArgumentException |
|
271 | - * @throws InvalidInterfaceException |
|
272 | - * @throws InvalidDataTypeException |
|
273 | - */ |
|
274 | - public static function bypass_recaptcha_for_spco_load_payment_method() |
|
275 | - { |
|
276 | - return array( |
|
277 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
278 | - 'step' => 'payment_options', |
|
279 | - 'action' => 'switch_spco_billing_form', |
|
280 | - ); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @return boolean |
|
286 | - * @throws InvalidArgumentException |
|
287 | - * @throws InvalidInterfaceException |
|
288 | - * @throws InvalidDataTypeException |
|
289 | - */ |
|
290 | - public static function recaptcha_passed() |
|
291 | - { |
|
292 | - // logged in means you have already passed a turing test of sorts |
|
293 | - if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) { |
|
294 | - return true; |
|
295 | - } |
|
296 | - // was test already passed? |
|
297 | - $recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed'); |
|
298 | - $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN); |
|
299 | - // verify recaptcha |
|
300 | - EED_Recaptcha::_get_recaptcha_response(); |
|
301 | - if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) { |
|
302 | - $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response(); |
|
303 | - EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed)); |
|
304 | - } |
|
305 | - EED_Recaptcha::$_not_a_robot = $recaptcha_passed; |
|
306 | - return $recaptcha_passed; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param array $recaptcha_response |
|
312 | - * @return array |
|
313 | - */ |
|
314 | - public static function recaptcha_response($recaptcha_response = array()) |
|
315 | - { |
|
316 | - if (EED_Recaptcha::_bypass_recaptcha()) { |
|
317 | - $recaptcha_response['bypass_recaptcha'] = true; |
|
318 | - $recaptcha_response['recaptcha_passed'] = true; |
|
319 | - } else { |
|
320 | - $recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot; |
|
321 | - } |
|
322 | - return $recaptcha_response; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @return boolean |
|
328 | - */ |
|
329 | - private static function _bypass_recaptcha() |
|
330 | - { |
|
331 | - // an array of key value pairs that must match exactly with the incoming request, |
|
332 | - // in order to bypass recaptcha for the current request ONLY |
|
333 | - $bypass_request_params_array = (array) apply_filters( |
|
334 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
335 | - array() |
|
336 | - ); |
|
337 | - // does $bypass_request_params_array have any values ? |
|
338 | - if (empty($bypass_request_params_array)) { |
|
339 | - return false; |
|
340 | - } |
|
341 | - // initially set bypass to TRUE |
|
342 | - $bypass_recaptcha = true; |
|
343 | - foreach ($bypass_request_params_array as $key => $value) { |
|
344 | - // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE, |
|
345 | - // otherwise carry over it's value. This way, one missed setting results in no bypass |
|
346 | - $bypass_recaptcha = isset($_REQUEST[ $key ]) && $_REQUEST[ $key ] === $value |
|
347 | - ? $bypass_recaptcha |
|
348 | - : false; |
|
349 | - } |
|
350 | - return $bypass_recaptcha; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * @return void |
|
356 | - * @throws InvalidArgumentException |
|
357 | - * @throws InvalidInterfaceException |
|
358 | - * @throws InvalidDataTypeException |
|
359 | - */ |
|
360 | - private static function _get_recaptcha_response() |
|
361 | - { |
|
362 | - EED_Recaptcha::$_recaptcha_response = EE_Registry::instance()->REQ->get( |
|
363 | - 'g-recaptcha-response', |
|
364 | - false |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @return boolean |
|
371 | - * @throws InvalidArgumentException |
|
372 | - * @throws InvalidInterfaceException |
|
373 | - * @throws InvalidDataTypeException |
|
374 | - */ |
|
375 | - private static function _process_recaptcha_response() |
|
376 | - { |
|
377 | - // verify library is loaded |
|
378 | - if (! class_exists('\ReCaptcha\ReCaptcha')) { |
|
379 | - require_once RECAPTCHA_BASE_PATH . '/autoload.php'; |
|
380 | - } |
|
381 | - // The response from reCAPTCHA |
|
382 | - EED_Recaptcha::_get_recaptcha_response(); |
|
383 | - $recaptcha_response = EED_Recaptcha::$_recaptcha_response; |
|
384 | - // Was there a reCAPTCHA response? |
|
385 | - if ($recaptcha_response) { |
|
386 | - // if allow_url_fopen is Off, then set a different request method |
|
387 | - $request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null; |
|
388 | - $recaptcha = new ReCaptcha( |
|
389 | - EED_Recaptcha::$config->recaptcha_privatekey, |
|
390 | - $request_method |
|
391 | - ); |
|
392 | - $recaptcha_response = $recaptcha->verify( |
|
393 | - EED_Recaptcha::$_recaptcha_response, |
|
394 | - $_SERVER['REMOTE_ADDR'] |
|
395 | - ); |
|
396 | - } |
|
397 | - return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess(); |
|
398 | - } |
|
21 | + /** |
|
22 | + * @var EE_Registration_Config $config |
|
23 | + */ |
|
24 | + private static $config; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type bool $_not_a_robot |
|
28 | + */ |
|
29 | + private static $_not_a_robot; |
|
30 | + |
|
31 | + /** |
|
32 | + * @type string $_recaptcha_response |
|
33 | + */ |
|
34 | + private static $_recaptcha_response; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return EED_Module|EED_Recaptcha |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + return parent::get_instance(__CLASS__); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
48 | + * |
|
49 | + * @return void |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws InvalidInterfaceException |
|
52 | + * @throws InvalidDataTypeException |
|
53 | + */ |
|
54 | + public static function set_hooks() |
|
55 | + { |
|
56 | + EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration; |
|
57 | + // use_captcha ? |
|
58 | + if ( |
|
59 | + EED_Recaptcha::useRecaptcha() |
|
60 | + && EED_Recaptcha::notPaymentOptionsRevisit() |
|
61 | + ) { |
|
62 | + EED_Recaptcha::set_definitions(); |
|
63 | + EED_Recaptcha::enqueue_styles_and_scripts(); |
|
64 | + add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0); |
|
65 | + add_action( |
|
66 | + 'AHEE__before_spco_whats_next_buttons', |
|
67 | + array('EED_Recaptcha', 'display_recaptcha'), |
|
68 | + 10, |
|
69 | + 0 |
|
70 | + ); |
|
71 | + add_filter( |
|
72 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
73 | + array('EED_Recaptcha', 'not_a_robot') |
|
74 | + ); |
|
75 | + add_filter( |
|
76 | + 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', |
|
77 | + array('EED_Recaptcha', 'not_a_robot') |
|
78 | + ); |
|
79 | + add_filter( |
|
80 | + 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', |
|
81 | + array('EED_Recaptcha', 'recaptcha_response') |
|
82 | + ); |
|
83 | + add_filter( |
|
84 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
85 | + array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method') |
|
86 | + ); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
93 | + * |
|
94 | + * @return void |
|
95 | + * @throws InvalidArgumentException |
|
96 | + * @throws InvalidInterfaceException |
|
97 | + * @throws InvalidDataTypeException |
|
98 | + */ |
|
99 | + public static function set_hooks_admin() |
|
100 | + { |
|
101 | + EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration; |
|
102 | + EED_Recaptcha::set_definitions(); |
|
103 | + // use_captcha ? |
|
104 | + if ( |
|
105 | + EED_Recaptcha::useRecaptcha() |
|
106 | + && EED_Recaptcha::notPaymentOptionsRevisit() |
|
107 | + && EE_Registry::instance()->REQ->get('step', '') !== '' |
|
108 | + ) { |
|
109 | + EED_Recaptcha::enqueue_styles_and_scripts(); |
|
110 | + add_filter( |
|
111 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
112 | + array('EED_Recaptcha', 'not_a_robot') |
|
113 | + ); |
|
114 | + add_filter( |
|
115 | + 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', |
|
116 | + array('EED_Recaptcha', 'not_a_robot') |
|
117 | + ); |
|
118 | + add_filter( |
|
119 | + 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', |
|
120 | + array('EED_Recaptcha', 'recaptcha_response') |
|
121 | + ); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public static function set_definitions() |
|
130 | + { |
|
131 | + if (is_user_logged_in()) { |
|
132 | + EED_Recaptcha::$_not_a_robot = true; |
|
133 | + } |
|
134 | + define( |
|
135 | + 'RECAPTCHA_BASE_PATH', |
|
136 | + rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/' |
|
137 | + ); |
|
138 | + define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__)); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public static function set_late_hooks() |
|
146 | + { |
|
147 | + add_filter( |
|
148 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
149 | + array('EED_Recaptcha', 'not_a_robot') |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return boolean |
|
156 | + */ |
|
157 | + public static function useRecaptcha() |
|
158 | + { |
|
159 | + return EED_Recaptcha::$config->use_captcha |
|
160 | + && EED_Recaptcha::$config->recaptcha_theme !== 'invisible'; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @return boolean |
|
166 | + * @throws InvalidArgumentException |
|
167 | + * @throws InvalidInterfaceException |
|
168 | + * @throws InvalidDataTypeException |
|
169 | + */ |
|
170 | + public static function notPaymentOptionsRevisit() |
|
171 | + { |
|
172 | + return ! ( |
|
173 | + EE_Registry::instance()->REQ->get('step', '') === 'payment_options' |
|
174 | + && (bool) EE_Registry::instance()->REQ->get('revisit', false) === true |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @return void |
|
181 | + * @throws InvalidArgumentException |
|
182 | + * @throws InvalidInterfaceException |
|
183 | + * @throws InvalidDataTypeException |
|
184 | + */ |
|
185 | + public static function enqueue_styles_and_scripts() |
|
186 | + { |
|
187 | + wp_register_script( |
|
188 | + 'espresso_recaptcha', |
|
189 | + RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js', |
|
190 | + array('single_page_checkout'), |
|
191 | + EVENT_ESPRESSO_VERSION, |
|
192 | + true |
|
193 | + ); |
|
194 | + wp_register_script( |
|
195 | + 'google_recaptcha', |
|
196 | + 'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language, |
|
197 | + array('espresso_recaptcha'), |
|
198 | + EVENT_ESPRESSO_VERSION, |
|
199 | + true |
|
200 | + ); |
|
201 | + EE_Registry::$i18n_js_strings['no_SPCO_error'] = __( |
|
202 | + 'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', |
|
203 | + 'event_espresso' |
|
204 | + ); |
|
205 | + EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __( |
|
206 | + 'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.', |
|
207 | + 'event_espresso' |
|
208 | + ); |
|
209 | + EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( |
|
210 | + 'Please complete the anti-spam test before proceeding.', |
|
211 | + 'event_espresso' |
|
212 | + ); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @param \WP $WP |
|
218 | + */ |
|
219 | + public function run($WP) |
|
220 | + { |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @return boolean |
|
226 | + * @throws InvalidArgumentException |
|
227 | + * @throws InvalidInterfaceException |
|
228 | + * @throws InvalidDataTypeException |
|
229 | + */ |
|
230 | + public static function not_a_robot() |
|
231 | + { |
|
232 | + $not_a_robot = is_bool(EED_Recaptcha::$_not_a_robot) |
|
233 | + ? EED_Recaptcha::$_not_a_robot |
|
234 | + : EED_Recaptcha::recaptcha_passed(); |
|
235 | + return $not_a_robot; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * @return void |
|
241 | + * @throws DomainException |
|
242 | + * @throws InvalidArgumentException |
|
243 | + * @throws InvalidInterfaceException |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + */ |
|
246 | + public static function display_recaptcha() |
|
247 | + { |
|
248 | + // logged in means you have already passed a turing test of sorts |
|
249 | + if (is_user_logged_in()) { |
|
250 | + return; |
|
251 | + } |
|
252 | + // don't display if not using recaptcha or user is logged in |
|
253 | + if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) { |
|
254 | + // only display if they have NOT passed the test yet |
|
255 | + EEH_Template::display_template( |
|
256 | + RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php', |
|
257 | + array( |
|
258 | + 'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey, |
|
259 | + 'recaptcha_theme' => EED_Recaptcha::$config->recaptcha_theme, |
|
260 | + 'recaptcha_type' => EED_Recaptcha::$config->recaptcha_type, |
|
261 | + ) |
|
262 | + ); |
|
263 | + wp_enqueue_script('google_recaptcha'); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * @return array |
|
270 | + * @throws InvalidArgumentException |
|
271 | + * @throws InvalidInterfaceException |
|
272 | + * @throws InvalidDataTypeException |
|
273 | + */ |
|
274 | + public static function bypass_recaptcha_for_spco_load_payment_method() |
|
275 | + { |
|
276 | + return array( |
|
277 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
278 | + 'step' => 'payment_options', |
|
279 | + 'action' => 'switch_spco_billing_form', |
|
280 | + ); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @return boolean |
|
286 | + * @throws InvalidArgumentException |
|
287 | + * @throws InvalidInterfaceException |
|
288 | + * @throws InvalidDataTypeException |
|
289 | + */ |
|
290 | + public static function recaptcha_passed() |
|
291 | + { |
|
292 | + // logged in means you have already passed a turing test of sorts |
|
293 | + if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) { |
|
294 | + return true; |
|
295 | + } |
|
296 | + // was test already passed? |
|
297 | + $recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed'); |
|
298 | + $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN); |
|
299 | + // verify recaptcha |
|
300 | + EED_Recaptcha::_get_recaptcha_response(); |
|
301 | + if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) { |
|
302 | + $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response(); |
|
303 | + EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed)); |
|
304 | + } |
|
305 | + EED_Recaptcha::$_not_a_robot = $recaptcha_passed; |
|
306 | + return $recaptcha_passed; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param array $recaptcha_response |
|
312 | + * @return array |
|
313 | + */ |
|
314 | + public static function recaptcha_response($recaptcha_response = array()) |
|
315 | + { |
|
316 | + if (EED_Recaptcha::_bypass_recaptcha()) { |
|
317 | + $recaptcha_response['bypass_recaptcha'] = true; |
|
318 | + $recaptcha_response['recaptcha_passed'] = true; |
|
319 | + } else { |
|
320 | + $recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot; |
|
321 | + } |
|
322 | + return $recaptcha_response; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @return boolean |
|
328 | + */ |
|
329 | + private static function _bypass_recaptcha() |
|
330 | + { |
|
331 | + // an array of key value pairs that must match exactly with the incoming request, |
|
332 | + // in order to bypass recaptcha for the current request ONLY |
|
333 | + $bypass_request_params_array = (array) apply_filters( |
|
334 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
335 | + array() |
|
336 | + ); |
|
337 | + // does $bypass_request_params_array have any values ? |
|
338 | + if (empty($bypass_request_params_array)) { |
|
339 | + return false; |
|
340 | + } |
|
341 | + // initially set bypass to TRUE |
|
342 | + $bypass_recaptcha = true; |
|
343 | + foreach ($bypass_request_params_array as $key => $value) { |
|
344 | + // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE, |
|
345 | + // otherwise carry over it's value. This way, one missed setting results in no bypass |
|
346 | + $bypass_recaptcha = isset($_REQUEST[ $key ]) && $_REQUEST[ $key ] === $value |
|
347 | + ? $bypass_recaptcha |
|
348 | + : false; |
|
349 | + } |
|
350 | + return $bypass_recaptcha; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * @return void |
|
356 | + * @throws InvalidArgumentException |
|
357 | + * @throws InvalidInterfaceException |
|
358 | + * @throws InvalidDataTypeException |
|
359 | + */ |
|
360 | + private static function _get_recaptcha_response() |
|
361 | + { |
|
362 | + EED_Recaptcha::$_recaptcha_response = EE_Registry::instance()->REQ->get( |
|
363 | + 'g-recaptcha-response', |
|
364 | + false |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @return boolean |
|
371 | + * @throws InvalidArgumentException |
|
372 | + * @throws InvalidInterfaceException |
|
373 | + * @throws InvalidDataTypeException |
|
374 | + */ |
|
375 | + private static function _process_recaptcha_response() |
|
376 | + { |
|
377 | + // verify library is loaded |
|
378 | + if (! class_exists('\ReCaptcha\ReCaptcha')) { |
|
379 | + require_once RECAPTCHA_BASE_PATH . '/autoload.php'; |
|
380 | + } |
|
381 | + // The response from reCAPTCHA |
|
382 | + EED_Recaptcha::_get_recaptcha_response(); |
|
383 | + $recaptcha_response = EED_Recaptcha::$_recaptcha_response; |
|
384 | + // Was there a reCAPTCHA response? |
|
385 | + if ($recaptcha_response) { |
|
386 | + // if allow_url_fopen is Off, then set a different request method |
|
387 | + $request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null; |
|
388 | + $recaptcha = new ReCaptcha( |
|
389 | + EED_Recaptcha::$config->recaptcha_privatekey, |
|
390 | + $request_method |
|
391 | + ); |
|
392 | + $recaptcha_response = $recaptcha->verify( |
|
393 | + EED_Recaptcha::$_recaptcha_response, |
|
394 | + $_SERVER['REMOTE_ADDR'] |
|
395 | + ); |
|
396 | + } |
|
397 | + return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess(); |
|
398 | + } |
|
399 | 399 | } |
@@ -25,228 +25,228 @@ |
||
25 | 25 | { |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @return EED_Event_Single_Caff |
|
30 | - */ |
|
31 | - public static function instance() |
|
32 | - { |
|
33 | - return parent::get_instance(__CLASS__); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
39 | - * |
|
40 | - * @access public |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public static function set_hooks() |
|
44 | - { |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public static function set_hooks_admin() |
|
54 | - { |
|
55 | - self::setDefinitions(); |
|
56 | - add_action( |
|
57 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings', |
|
58 | - array('EED_Event_Single_Caff', 'load_scripts_styles'), |
|
59 | - 10 |
|
60 | - ); |
|
61 | - add_action( |
|
62 | - 'AHEE__template_settings__template__before_settings_form', |
|
63 | - array('EED_Event_Single_Caff', 'template_settings_form'), |
|
64 | - 10 |
|
65 | - ); |
|
66 | - add_filter( |
|
67 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
68 | - array('EED_Event_Single_Caff', 'update_template_settings'), |
|
69 | - 10, |
|
70 | - 2 |
|
71 | - ); |
|
72 | - // AJAX |
|
73 | - add_action( |
|
74 | - 'wp_ajax_espresso_update_event_single_order', |
|
75 | - array('EED_Event_Single_Caff', 'update_event_single_order') |
|
76 | - ); |
|
77 | - add_action( |
|
78 | - 'wp_ajax_nopriv_espresso_update_event_single_order', |
|
79 | - array('EED_Event_Single_Caff', 'update_event_single_order') |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - public static function load_scripts_styles() |
|
85 | - { |
|
86 | - add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - public static function enqueue_scripts_styles() |
|
91 | - { |
|
92 | - wp_register_style( |
|
93 | - 'eed-event-single-sortable', |
|
94 | - EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css', |
|
95 | - array(), |
|
96 | - EVENT_ESPRESSO_VERSION |
|
97 | - ); |
|
98 | - wp_enqueue_style('eed-event-single-sortable'); |
|
99 | - wp_register_script( |
|
100 | - 'eed-event-single-sortable', |
|
101 | - EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js', |
|
102 | - array('jquery-ui-sortable'), |
|
103 | - EVENT_ESPRESSO_VERSION, |
|
104 | - true |
|
105 | - ); |
|
106 | - wp_enqueue_script('eed-event-single-sortable'); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Set constants only if they haven't been set yet. |
|
112 | - */ |
|
113 | - public static function setDefinitions() |
|
114 | - { |
|
115 | - if (! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) { |
|
116 | - define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
117 | - define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * template_settings_form |
|
124 | - * |
|
125 | - * @access public |
|
126 | - * @static |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public static function template_settings_form() |
|
130 | - { |
|
131 | - $config = EE_Registry::instance()->CFG->template_settings; |
|
132 | - $config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config |
|
133 | - ? $config->EED_Event_Single : new EE_Event_Single_Config(); |
|
134 | - $config->use_sortable_display_order = isset($config->use_sortable_display_order) |
|
135 | - ? $config->use_sortable_display_order : false; |
|
136 | - $config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config); |
|
137 | - |
|
138 | - $event_single_order_array = array(); |
|
139 | - $event_single_order_array[ $config->display_order_tickets ] = 'tickets'; |
|
140 | - $event_single_order_array[ $config->display_order_datetimes ] = 'datetimes'; |
|
141 | - $event_single_order_array[ $config->display_order_event ] = 'event'; |
|
142 | - $event_single_order_array[ $config->display_order_venue ] = 'venue'; |
|
143 | - // get template parts |
|
144 | - $template_parts = EED_Event_Single::instance()->initialize_template_parts($config); |
|
145 | - // convert to array so that we can add more properties |
|
146 | - $config = get_object_vars($config); |
|
147 | - $config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts( |
|
148 | - 'event-single-sortable-js', |
|
149 | - '', |
|
150 | - 'single-sortable-li single-sortable-js' |
|
151 | - ); |
|
152 | - EEH_Template::display_template( |
|
153 | - EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php', |
|
154 | - $config |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * update_template_settings |
|
161 | - * |
|
162 | - * @param EE_Template_Config $CFG |
|
163 | - * @param array $REQ |
|
164 | - * @return EE_Template_Config |
|
165 | - */ |
|
166 | - public static function update_template_settings(EE_Template_Config $CFG, $REQ) |
|
167 | - { |
|
168 | - if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) { |
|
169 | - $CFG->EED_Event_Single = new EE_Event_Single_Config(); |
|
170 | - } |
|
171 | - $display_order_event = $CFG->EED_Event_Single->display_order_event !== null |
|
172 | - ? $CFG->EED_Event_Single->display_order_event |
|
173 | - : EED_Event_Single::EVENT_DETAILS_PRIORITY; |
|
174 | - $display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null |
|
175 | - ? $CFG->EED_Event_Single->display_order_datetimes |
|
176 | - : EED_Event_Single::EVENT_DATETIMES_PRIORITY; |
|
177 | - $display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null |
|
178 | - ? $CFG->EED_Event_Single->display_order_tickets |
|
179 | - : EED_Event_Single::EVENT_TICKETS_PRIORITY; |
|
180 | - $display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null |
|
181 | - ? $CFG->EED_Event_Single->display_order_venue |
|
182 | - : EED_Event_Single::EVENT_VENUES_PRIORITY; |
|
183 | - $CFG->EED_Event_Single = new EE_Event_Single_Config(); |
|
184 | - $CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single']) |
|
185 | - && $REQ['display_status_banner_single']; |
|
186 | - $CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue']; |
|
187 | - $CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order']) |
|
188 | - ? absint($REQ['EED_Events_Single_use_sortable_display_order']) |
|
189 | - : 0; |
|
190 | - $CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order |
|
191 | - ? $display_order_event |
|
192 | - : EED_Event_Single::EVENT_DETAILS_PRIORITY; |
|
193 | - $CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order |
|
194 | - ? $display_order_datetimes |
|
195 | - : EED_Event_Single::EVENT_DATETIMES_PRIORITY; |
|
196 | - $CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order |
|
197 | - ? $display_order_tickets |
|
198 | - : EED_Event_Single::EVENT_TICKETS_PRIORITY; |
|
199 | - $CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order |
|
200 | - ? $display_order_venue |
|
201 | - : EED_Event_Single::EVENT_VENUES_PRIORITY; |
|
202 | - do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ); |
|
203 | - return $CFG; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * update_event_single_order |
|
209 | - * |
|
210 | - * @access public |
|
211 | - * @return void |
|
212 | - */ |
|
213 | - public static function update_event_single_order() |
|
214 | - { |
|
215 | - $config_saved = false; |
|
216 | - $template_parts = sanitize_text_field($_POST['elements']); |
|
217 | - if (! empty($template_parts)) { |
|
218 | - $template_parts = explode(',', trim($template_parts, ',')); |
|
219 | - foreach ($template_parts as $key => $template_part) { |
|
220 | - $template_part = "display_order_$template_part"; |
|
221 | - $priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY; |
|
222 | - EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority; |
|
223 | - do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority); |
|
224 | - } |
|
225 | - $config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false); |
|
226 | - } |
|
227 | - if ($config_saved) { |
|
228 | - EE_Error::add_success(__('Display Order has been successfully updated.', 'event_espresso')); |
|
229 | - } else { |
|
230 | - EE_Error::add_error( |
|
231 | - __('Display Order was not updated.', 'event_espresso'), |
|
232 | - __FILE__, |
|
233 | - __FUNCTION__, |
|
234 | - __LINE__ |
|
235 | - ); |
|
236 | - } |
|
237 | - echo wp_json_encode(EE_Error::get_notices(false)); |
|
238 | - exit(); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * run - initial module setup |
|
244 | - * |
|
245 | - * @access public |
|
246 | - * @param WP $WP |
|
247 | - * @return void |
|
248 | - */ |
|
249 | - public function run($WP) |
|
250 | - { |
|
251 | - } |
|
28 | + /** |
|
29 | + * @return EED_Event_Single_Caff |
|
30 | + */ |
|
31 | + public static function instance() |
|
32 | + { |
|
33 | + return parent::get_instance(__CLASS__); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
39 | + * |
|
40 | + * @access public |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public static function set_hooks() |
|
44 | + { |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public static function set_hooks_admin() |
|
54 | + { |
|
55 | + self::setDefinitions(); |
|
56 | + add_action( |
|
57 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings', |
|
58 | + array('EED_Event_Single_Caff', 'load_scripts_styles'), |
|
59 | + 10 |
|
60 | + ); |
|
61 | + add_action( |
|
62 | + 'AHEE__template_settings__template__before_settings_form', |
|
63 | + array('EED_Event_Single_Caff', 'template_settings_form'), |
|
64 | + 10 |
|
65 | + ); |
|
66 | + add_filter( |
|
67 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
68 | + array('EED_Event_Single_Caff', 'update_template_settings'), |
|
69 | + 10, |
|
70 | + 2 |
|
71 | + ); |
|
72 | + // AJAX |
|
73 | + add_action( |
|
74 | + 'wp_ajax_espresso_update_event_single_order', |
|
75 | + array('EED_Event_Single_Caff', 'update_event_single_order') |
|
76 | + ); |
|
77 | + add_action( |
|
78 | + 'wp_ajax_nopriv_espresso_update_event_single_order', |
|
79 | + array('EED_Event_Single_Caff', 'update_event_single_order') |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + public static function load_scripts_styles() |
|
85 | + { |
|
86 | + add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + public static function enqueue_scripts_styles() |
|
91 | + { |
|
92 | + wp_register_style( |
|
93 | + 'eed-event-single-sortable', |
|
94 | + EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css', |
|
95 | + array(), |
|
96 | + EVENT_ESPRESSO_VERSION |
|
97 | + ); |
|
98 | + wp_enqueue_style('eed-event-single-sortable'); |
|
99 | + wp_register_script( |
|
100 | + 'eed-event-single-sortable', |
|
101 | + EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js', |
|
102 | + array('jquery-ui-sortable'), |
|
103 | + EVENT_ESPRESSO_VERSION, |
|
104 | + true |
|
105 | + ); |
|
106 | + wp_enqueue_script('eed-event-single-sortable'); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Set constants only if they haven't been set yet. |
|
112 | + */ |
|
113 | + public static function setDefinitions() |
|
114 | + { |
|
115 | + if (! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) { |
|
116 | + define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
117 | + define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * template_settings_form |
|
124 | + * |
|
125 | + * @access public |
|
126 | + * @static |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public static function template_settings_form() |
|
130 | + { |
|
131 | + $config = EE_Registry::instance()->CFG->template_settings; |
|
132 | + $config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config |
|
133 | + ? $config->EED_Event_Single : new EE_Event_Single_Config(); |
|
134 | + $config->use_sortable_display_order = isset($config->use_sortable_display_order) |
|
135 | + ? $config->use_sortable_display_order : false; |
|
136 | + $config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config); |
|
137 | + |
|
138 | + $event_single_order_array = array(); |
|
139 | + $event_single_order_array[ $config->display_order_tickets ] = 'tickets'; |
|
140 | + $event_single_order_array[ $config->display_order_datetimes ] = 'datetimes'; |
|
141 | + $event_single_order_array[ $config->display_order_event ] = 'event'; |
|
142 | + $event_single_order_array[ $config->display_order_venue ] = 'venue'; |
|
143 | + // get template parts |
|
144 | + $template_parts = EED_Event_Single::instance()->initialize_template_parts($config); |
|
145 | + // convert to array so that we can add more properties |
|
146 | + $config = get_object_vars($config); |
|
147 | + $config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts( |
|
148 | + 'event-single-sortable-js', |
|
149 | + '', |
|
150 | + 'single-sortable-li single-sortable-js' |
|
151 | + ); |
|
152 | + EEH_Template::display_template( |
|
153 | + EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php', |
|
154 | + $config |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * update_template_settings |
|
161 | + * |
|
162 | + * @param EE_Template_Config $CFG |
|
163 | + * @param array $REQ |
|
164 | + * @return EE_Template_Config |
|
165 | + */ |
|
166 | + public static function update_template_settings(EE_Template_Config $CFG, $REQ) |
|
167 | + { |
|
168 | + if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) { |
|
169 | + $CFG->EED_Event_Single = new EE_Event_Single_Config(); |
|
170 | + } |
|
171 | + $display_order_event = $CFG->EED_Event_Single->display_order_event !== null |
|
172 | + ? $CFG->EED_Event_Single->display_order_event |
|
173 | + : EED_Event_Single::EVENT_DETAILS_PRIORITY; |
|
174 | + $display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null |
|
175 | + ? $CFG->EED_Event_Single->display_order_datetimes |
|
176 | + : EED_Event_Single::EVENT_DATETIMES_PRIORITY; |
|
177 | + $display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null |
|
178 | + ? $CFG->EED_Event_Single->display_order_tickets |
|
179 | + : EED_Event_Single::EVENT_TICKETS_PRIORITY; |
|
180 | + $display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null |
|
181 | + ? $CFG->EED_Event_Single->display_order_venue |
|
182 | + : EED_Event_Single::EVENT_VENUES_PRIORITY; |
|
183 | + $CFG->EED_Event_Single = new EE_Event_Single_Config(); |
|
184 | + $CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single']) |
|
185 | + && $REQ['display_status_banner_single']; |
|
186 | + $CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue']; |
|
187 | + $CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order']) |
|
188 | + ? absint($REQ['EED_Events_Single_use_sortable_display_order']) |
|
189 | + : 0; |
|
190 | + $CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order |
|
191 | + ? $display_order_event |
|
192 | + : EED_Event_Single::EVENT_DETAILS_PRIORITY; |
|
193 | + $CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order |
|
194 | + ? $display_order_datetimes |
|
195 | + : EED_Event_Single::EVENT_DATETIMES_PRIORITY; |
|
196 | + $CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order |
|
197 | + ? $display_order_tickets |
|
198 | + : EED_Event_Single::EVENT_TICKETS_PRIORITY; |
|
199 | + $CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order |
|
200 | + ? $display_order_venue |
|
201 | + : EED_Event_Single::EVENT_VENUES_PRIORITY; |
|
202 | + do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ); |
|
203 | + return $CFG; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * update_event_single_order |
|
209 | + * |
|
210 | + * @access public |
|
211 | + * @return void |
|
212 | + */ |
|
213 | + public static function update_event_single_order() |
|
214 | + { |
|
215 | + $config_saved = false; |
|
216 | + $template_parts = sanitize_text_field($_POST['elements']); |
|
217 | + if (! empty($template_parts)) { |
|
218 | + $template_parts = explode(',', trim($template_parts, ',')); |
|
219 | + foreach ($template_parts as $key => $template_part) { |
|
220 | + $template_part = "display_order_$template_part"; |
|
221 | + $priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY; |
|
222 | + EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority; |
|
223 | + do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority); |
|
224 | + } |
|
225 | + $config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false); |
|
226 | + } |
|
227 | + if ($config_saved) { |
|
228 | + EE_Error::add_success(__('Display Order has been successfully updated.', 'event_espresso')); |
|
229 | + } else { |
|
230 | + EE_Error::add_error( |
|
231 | + __('Display Order was not updated.', 'event_espresso'), |
|
232 | + __FILE__, |
|
233 | + __FUNCTION__, |
|
234 | + __LINE__ |
|
235 | + ); |
|
236 | + } |
|
237 | + echo wp_json_encode(EE_Error::get_notices(false)); |
|
238 | + exit(); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * run - initial module setup |
|
244 | + * |
|
245 | + * @access public |
|
246 | + * @param WP $WP |
|
247 | + * @return void |
|
248 | + */ |
|
249 | + public function run($WP) |
|
250 | + { |
|
251 | + } |
|
252 | 252 | } |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | { |
92 | 92 | wp_register_style( |
93 | 93 | 'eed-event-single-sortable', |
94 | - EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css', |
|
94 | + EVENT_SINGLE_CAFF_ASSETS_URL.'eed_event_single_sortable.css', |
|
95 | 95 | array(), |
96 | 96 | EVENT_ESPRESSO_VERSION |
97 | 97 | ); |
98 | 98 | wp_enqueue_style('eed-event-single-sortable'); |
99 | 99 | wp_register_script( |
100 | 100 | 'eed-event-single-sortable', |
101 | - EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js', |
|
101 | + EVENT_SINGLE_CAFF_ASSETS_URL.'eed_event_single_sortable.js', |
|
102 | 102 | array('jquery-ui-sortable'), |
103 | 103 | EVENT_ESPRESSO_VERSION, |
104 | 104 | true |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public static function setDefinitions() |
114 | 114 | { |
115 | - if (! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) { |
|
116 | - define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
117 | - define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
115 | + if ( ! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) { |
|
116 | + define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates/'); |
|
117 | + define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | $config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config); |
137 | 137 | |
138 | 138 | $event_single_order_array = array(); |
139 | - $event_single_order_array[ $config->display_order_tickets ] = 'tickets'; |
|
140 | - $event_single_order_array[ $config->display_order_datetimes ] = 'datetimes'; |
|
141 | - $event_single_order_array[ $config->display_order_event ] = 'event'; |
|
142 | - $event_single_order_array[ $config->display_order_venue ] = 'venue'; |
|
139 | + $event_single_order_array[$config->display_order_tickets] = 'tickets'; |
|
140 | + $event_single_order_array[$config->display_order_datetimes] = 'datetimes'; |
|
141 | + $event_single_order_array[$config->display_order_event] = 'event'; |
|
142 | + $event_single_order_array[$config->display_order_venue] = 'venue'; |
|
143 | 143 | // get template parts |
144 | 144 | $template_parts = EED_Event_Single::instance()->initialize_template_parts($config); |
145 | 145 | // convert to array so that we can add more properties |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'single-sortable-li single-sortable-js' |
151 | 151 | ); |
152 | 152 | EEH_Template::display_template( |
153 | - EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php', |
|
153 | + EVENT_SINGLE_CAFF_TEMPLATES_PATH.'admin-event-single-settings.template.php', |
|
154 | 154 | $config |
155 | 155 | ); |
156 | 156 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public static function update_template_settings(EE_Template_Config $CFG, $REQ) |
167 | 167 | { |
168 | - if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) { |
|
168 | + if ( ! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) { |
|
169 | 169 | $CFG->EED_Event_Single = new EE_Event_Single_Config(); |
170 | 170 | } |
171 | 171 | $display_order_event = $CFG->EED_Event_Single->display_order_event !== null |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | { |
215 | 215 | $config_saved = false; |
216 | 216 | $template_parts = sanitize_text_field($_POST['elements']); |
217 | - if (! empty($template_parts)) { |
|
217 | + if ( ! empty($template_parts)) { |
|
218 | 218 | $template_parts = explode(',', trim($template_parts, ',')); |
219 | 219 | foreach ($template_parts as $key => $template_part) { |
220 | 220 | $template_part = "display_order_$template_part"; |
@@ -29,15 +29,15 @@ |
||
29 | 29 | define('PRICING_PG_SLUG', 'pricing'); |
30 | 30 | define('PRICING_LABEL', __('Pricing', 'event_espresso')); |
31 | 31 | define('PRICING_PG_NAME', ucwords(str_replace('_', '', PRICING_PG_SLUG))); |
32 | - define('PRICING_ADMIN', EE_CORE_CAF_ADMIN . 'new/' . PRICING_PG_SLUG . '/'); |
|
33 | - define('PRICING_ADMIN_URL', admin_url('admin.php?page=' . PRICING_PG_SLUG)); |
|
34 | - define('PRICING_ASSETS_PATH', PRICING_ADMIN . 'assets/'); |
|
35 | - define('PRICING_ASSETS_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . PRICING_PG_SLUG . '/assets/'); |
|
36 | - define('PRICING_TEMPLATE_PATH', PRICING_ADMIN . 'templates/'); |
|
37 | - define('PRICING_TEMPLATE_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . PRICING_PG_SLUG . '/templates/'); |
|
32 | + define('PRICING_ADMIN', EE_CORE_CAF_ADMIN.'new/'.PRICING_PG_SLUG.'/'); |
|
33 | + define('PRICING_ADMIN_URL', admin_url('admin.php?page='.PRICING_PG_SLUG)); |
|
34 | + define('PRICING_ASSETS_PATH', PRICING_ADMIN.'assets/'); |
|
35 | + define('PRICING_ASSETS_URL', EE_CORE_CAF_ADMIN_URL.'new/'.PRICING_PG_SLUG.'/assets/'); |
|
36 | + define('PRICING_TEMPLATE_PATH', PRICING_ADMIN.'templates/'); |
|
37 | + define('PRICING_TEMPLATE_URL', EE_CORE_CAF_ADMIN_URL.'new/'.PRICING_PG_SLUG.'/templates/'); |
|
38 | 38 | |
39 | 39 | parent::__construct(); |
40 | - $this->_folder_path = EE_CORE_CAF_ADMIN . 'new/' . $this->_folder_name . '/'; |
|
40 | + $this->_folder_path = EE_CORE_CAF_ADMIN.'new/'.$this->_folder_name.'/'; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 |
@@ -14,53 +14,53 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @Constructor |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
17 | + /** |
|
18 | + * @Constructor |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | 22 | |
23 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
23 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
24 | 24 | |
25 | - define('PRICING_PG_SLUG', 'pricing'); |
|
26 | - define('PRICING_LABEL', __('Pricing', 'event_espresso')); |
|
27 | - define('PRICING_PG_NAME', ucwords(str_replace('_', '', PRICING_PG_SLUG))); |
|
28 | - define('PRICING_ADMIN', EE_CORE_CAF_ADMIN . 'new/' . PRICING_PG_SLUG . '/'); |
|
29 | - define('PRICING_ADMIN_URL', admin_url('admin.php?page=' . PRICING_PG_SLUG)); |
|
30 | - define('PRICING_ASSETS_PATH', PRICING_ADMIN . 'assets/'); |
|
31 | - define('PRICING_ASSETS_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . PRICING_PG_SLUG . '/assets/'); |
|
32 | - define('PRICING_TEMPLATE_PATH', PRICING_ADMIN . 'templates/'); |
|
33 | - define('PRICING_TEMPLATE_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . PRICING_PG_SLUG . '/templates/'); |
|
25 | + define('PRICING_PG_SLUG', 'pricing'); |
|
26 | + define('PRICING_LABEL', __('Pricing', 'event_espresso')); |
|
27 | + define('PRICING_PG_NAME', ucwords(str_replace('_', '', PRICING_PG_SLUG))); |
|
28 | + define('PRICING_ADMIN', EE_CORE_CAF_ADMIN . 'new/' . PRICING_PG_SLUG . '/'); |
|
29 | + define('PRICING_ADMIN_URL', admin_url('admin.php?page=' . PRICING_PG_SLUG)); |
|
30 | + define('PRICING_ASSETS_PATH', PRICING_ADMIN . 'assets/'); |
|
31 | + define('PRICING_ASSETS_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . PRICING_PG_SLUG . '/assets/'); |
|
32 | + define('PRICING_TEMPLATE_PATH', PRICING_ADMIN . 'templates/'); |
|
33 | + define('PRICING_TEMPLATE_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . PRICING_PG_SLUG . '/templates/'); |
|
34 | 34 | |
35 | - parent::__construct(); |
|
36 | - $this->_folder_path = EE_CORE_CAF_ADMIN . 'new/' . $this->_folder_name . '/'; |
|
37 | - } |
|
35 | + parent::__construct(); |
|
36 | + $this->_folder_path = EE_CORE_CAF_ADMIN . 'new/' . $this->_folder_name . '/'; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - protected function _set_init_properties() |
|
41 | - { |
|
42 | - $this->label = PRICING_LABEL; |
|
43 | - } |
|
40 | + protected function _set_init_properties() |
|
41 | + { |
|
42 | + $this->label = PRICING_LABEL; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @return array|void |
|
48 | - * @throws EE_Error |
|
49 | - * @since $VID:$ |
|
50 | - */ |
|
51 | - protected function _set_menu_map() |
|
52 | - { |
|
53 | - $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
54 | - array( |
|
55 | - 'menu_group' => 'management', |
|
56 | - 'menu_order' => 20, |
|
57 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
58 | - 'parent_slug' => 'espresso_events', |
|
59 | - 'menu_slug' => PRICING_PG_SLUG, |
|
60 | - 'menu_label' => PRICING_LABEL, |
|
61 | - 'capability' => 'ee_read_default_prices', |
|
62 | - 'admin_init_page' => $this, |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
46 | + /** |
|
47 | + * @return array|void |
|
48 | + * @throws EE_Error |
|
49 | + * @since $VID:$ |
|
50 | + */ |
|
51 | + protected function _set_menu_map() |
|
52 | + { |
|
53 | + $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
54 | + array( |
|
55 | + 'menu_group' => 'management', |
|
56 | + 'menu_order' => 20, |
|
57 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
58 | + 'parent_slug' => 'espresso_events', |
|
59 | + 'menu_slug' => PRICING_PG_SLUG, |
|
60 | + 'menu_label' => PRICING_LABEL, |
|
61 | + 'capability' => 'ee_read_default_prices', |
|
62 | + 'admin_init_page' => $this, |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function __construct($routing = true) |
21 | 21 | { |
22 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
23 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
24 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
25 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
26 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
22 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form/'); |
|
23 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets/'); |
|
24 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/'); |
|
25 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates/'); |
|
26 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/'); |
|
27 | 27 | parent::__construct($routing); |
28 | 28 | } |
29 | 29 | |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | { |
363 | 363 | wp_register_script( |
364 | 364 | 'ee-question-sortable', |
365 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
365 | + REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js', |
|
366 | 366 | array('jquery-ui-sortable'), |
367 | 367 | EVENT_ESPRESSO_VERSION, |
368 | 368 | true |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | */ |
449 | 449 | protected function _questions_overview_list_table() |
450 | 450 | { |
451 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
451 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
452 | 452 | 'add_question', |
453 | 453 | 'add_question', |
454 | 454 | array(), |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | protected function _question_groups_overview_list_table() |
470 | 470 | { |
471 | 471 | $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
472 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
472 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
473 | 473 | 'add_question_group', |
474 | 474 | 'add_question_group', |
475 | 475 | array(), |
@@ -531,18 +531,18 @@ discard block |
||
531 | 531 | { |
532 | 532 | $success = 0; |
533 | 533 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
534 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
534 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
535 | 535 | // if array has more than one element than success message should be plural |
536 | 536 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
537 | 537 | // cycle thru bulk action checkboxes |
538 | 538 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
539 | - if (! $this->_delete_item($ID, $model)) { |
|
539 | + if ( ! $this->_delete_item($ID, $model)) { |
|
540 | 540 | $success = 0; |
541 | 541 | } |
542 | 542 | } |
543 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
543 | + } elseif ( ! empty($this->_req_data['QSG_ID'])) { |
|
544 | 544 | $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
545 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
545 | + } elseif ( ! empty($this->_req_data['QST_ID'])) { |
|
546 | 546 | $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
547 | 547 | } else { |
548 | 548 | EE_Error::add_error( |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
612 | 612 | } |
613 | 613 | // add ID to title if editing |
614 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
614 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
615 | 615 | if ($ID) { |
616 | 616 | /** @var EE_Question_Group $questionGroup */ |
617 | 617 | $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
632 | 632 | $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
633 | 633 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
634 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
634 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php', |
|
635 | 635 | $this->_template_args, |
636 | 636 | true |
637 | 637 | ); |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | // update the existing related questions |
710 | 710 | // BUT FIRST... delete the phone question from the Question_Group_Question |
711 | 711 | // if it is being added to this question group (therefore removed from the existing group) |
712 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
712 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
713 | 713 | // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
714 | 714 | EEM_Question_Group_Question::instance()->delete( |
715 | 715 | array( |
@@ -724,22 +724,22 @@ discard block |
||
724 | 724 | $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
725 | 725 | $questions = $question_group->questions(); |
726 | 726 | // make sure system phone question is added to list of questions for this group |
727 | - if (! isset($questions[ $phone_question_id ])) { |
|
728 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
727 | + if ( ! isset($questions[$phone_question_id])) { |
|
728 | + $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | foreach ($questions as $question_ID => $question) { |
732 | 732 | // first we always check for order. |
733 | - if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
733 | + if ( ! empty($this->_req_data['question_orders'][$question_ID])) { |
|
734 | 734 | // update question order |
735 | 735 | $question_group->update_question_order( |
736 | 736 | $question_ID, |
737 | - $this->_req_data['question_orders'][ $question_ID ] |
|
737 | + $this->_req_data['question_orders'][$question_ID] |
|
738 | 738 | ); |
739 | 739 | } |
740 | 740 | |
741 | 741 | // then we always check if adding or removing. |
742 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
742 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
743 | 743 | $question_group->add_question($question_ID); |
744 | 744 | } else { |
745 | 745 | // not found, remove it (but only if not a system question for the personal group |
@@ -760,8 +760,8 @@ discard block |
||
760 | 760 | if (isset($this->_req_data['questions'])) { |
761 | 761 | foreach ($this->_req_data['questions'] as $QST_ID) { |
762 | 762 | $question_group->add_question($QST_ID); |
763 | - if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
764 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
763 | + if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
764 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | } |
@@ -902,33 +902,33 @@ discard block |
||
902 | 902 | // echo "trash $trash"; |
903 | 903 | // var_dump($this->_req_data['checkbox']);die; |
904 | 904 | if (isset($this->_req_data['checkbox'])) { |
905 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
905 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
906 | 906 | // if array has more than one element than success message should be plural |
907 | 907 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
908 | 908 | // cycle thru bulk action checkboxes |
909 | 909 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
910 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
910 | + if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
911 | 911 | $success = 0; |
912 | 912 | } |
913 | 913 | } |
914 | 914 | } else { |
915 | 915 | // grab single id and delete |
916 | 916 | $ID = absint($this->_req_data['checkbox']); |
917 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
917 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
918 | 918 | $success = 0; |
919 | 919 | } |
920 | 920 | } |
921 | 921 | } else { |
922 | 922 | // delete via trash link |
923 | 923 | // grab single id and delete |
924 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
925 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
924 | + $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
925 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
926 | 926 | $success = 0; |
927 | 927 | } |
928 | 928 | } |
929 | 929 | |
930 | 930 | |
931 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
931 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; // strtolower( $model->item_name(2) ); |
|
932 | 932 | // echo "action :$action"; |
933 | 933 | // $action = 'questions' ? 'default' : $action; |
934 | 934 | if ($trash) { |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | ? (int) $this->_req_data['curpage'] |
1049 | 1049 | : null; |
1050 | 1050 | |
1051 | - if (! empty($row_ids)) { |
|
1051 | + if ( ! empty($row_ids)) { |
|
1052 | 1052 | // figure out where we start the row_id count at for the current page. |
1053 | 1053 | $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
1054 | 1054 | |
@@ -1057,7 +1057,7 @@ discard block |
||
1057 | 1057 | // Update the questions when re-ordering |
1058 | 1058 | $updated = EEM_Question_Group::instance()->update( |
1059 | 1059 | array('QSG_order' => $qsgcount), |
1060 | - array(array('QSG_ID' => $row_ids[ $i ])) |
|
1060 | + array(array('QSG_ID' => $row_ids[$i])) |
|
1061 | 1061 | ); |
1062 | 1062 | if ($updated === false) { |
1063 | 1063 | $success = false; |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | $this->_set_add_edit_form_tags('update_reg_form_settings'); |
1104 | 1104 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
1105 | 1105 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
1106 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
1106 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php', |
|
1107 | 1107 | $this->_template_args, |
1108 | 1108 | true |
1109 | 1109 | ); |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | $prev_email_validation_level = 'basic'; |
1241 | 1241 | } |
1242 | 1242 | // confirm our i18n email validation will work on the server |
1243 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1243 | + if ( ! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1244 | 1244 | // or reset email validation level to previous value |
1245 | 1245 | $email_validation_level = $prev_email_validation_level; |
1246 | 1246 | } |
@@ -1286,7 +1286,7 @@ discard block |
||
1286 | 1286 | private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
1287 | 1287 | { |
1288 | 1288 | // first check that PCRE is enabled |
1289 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1289 | + if ( ! defined('PREG_BAD_UTF8_ERROR')) { |
|
1290 | 1290 | EE_Error::add_error( |
1291 | 1291 | sprintf( |
1292 | 1292 | esc_html__( |
@@ -14,1446 +14,1446 @@ |
||
14 | 14 | class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
19 | - */ |
|
20 | - public function __construct($routing = true) |
|
21 | - { |
|
22 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
23 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
24 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
25 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
26 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
27 | - parent::__construct($routing); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - protected function _extend_page_config() |
|
35 | - { |
|
36 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
37 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
38 | - ? $this->_req_data['QST_ID'] : 0; |
|
39 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
40 | - ? $this->_req_data['QSG_ID'] : 0; |
|
41 | - |
|
42 | - $new_page_routes = array( |
|
43 | - 'question_groups' => array( |
|
44 | - 'func' => '_question_groups_overview_list_table', |
|
45 | - 'capability' => 'ee_read_question_groups', |
|
46 | - ), |
|
47 | - 'add_question' => array( |
|
48 | - 'func' => '_edit_question', |
|
49 | - 'capability' => 'ee_edit_questions', |
|
50 | - ), |
|
51 | - 'insert_question' => array( |
|
52 | - 'func' => '_insert_or_update_question', |
|
53 | - 'args' => array('new_question' => true), |
|
54 | - 'capability' => 'ee_edit_questions', |
|
55 | - 'noheader' => true, |
|
56 | - ), |
|
57 | - 'duplicate_question' => array( |
|
58 | - 'func' => '_duplicate_question', |
|
59 | - 'capability' => 'ee_edit_questions', |
|
60 | - 'noheader' => true, |
|
61 | - ), |
|
62 | - 'trash_question' => array( |
|
63 | - 'func' => '_trash_question', |
|
64 | - 'capability' => 'ee_delete_question', |
|
65 | - 'obj_id' => $qst_id, |
|
66 | - 'noheader' => true, |
|
67 | - ), |
|
68 | - |
|
69 | - 'restore_question' => array( |
|
70 | - 'func' => '_trash_or_restore_questions', |
|
71 | - 'capability' => 'ee_delete_question', |
|
72 | - 'obj_id' => $qst_id, |
|
73 | - 'args' => array('trash' => false), |
|
74 | - 'noheader' => true, |
|
75 | - ), |
|
76 | - |
|
77 | - 'delete_question' => array( |
|
78 | - 'func' => '_delete_question', |
|
79 | - 'capability' => 'ee_delete_question', |
|
80 | - 'obj_id' => $qst_id, |
|
81 | - 'noheader' => true, |
|
82 | - ), |
|
83 | - |
|
84 | - 'trash_questions' => array( |
|
85 | - 'func' => '_trash_or_restore_questions', |
|
86 | - 'capability' => 'ee_delete_questions', |
|
87 | - 'args' => array('trash' => true), |
|
88 | - 'noheader' => true, |
|
89 | - ), |
|
90 | - |
|
91 | - 'restore_questions' => array( |
|
92 | - 'func' => '_trash_or_restore_questions', |
|
93 | - 'capability' => 'ee_delete_questions', |
|
94 | - 'args' => array('trash' => false), |
|
95 | - 'noheader' => true, |
|
96 | - ), |
|
97 | - |
|
98 | - 'delete_questions' => array( |
|
99 | - 'func' => '_delete_questions', |
|
100 | - 'args' => array(), |
|
101 | - 'capability' => 'ee_delete_questions', |
|
102 | - 'noheader' => true, |
|
103 | - ), |
|
104 | - |
|
105 | - 'add_question_group' => array( |
|
106 | - 'func' => '_edit_question_group', |
|
107 | - 'capability' => 'ee_edit_question_groups', |
|
108 | - ), |
|
109 | - |
|
110 | - 'edit_question_group' => array( |
|
111 | - 'func' => '_edit_question_group', |
|
112 | - 'capability' => 'ee_edit_question_group', |
|
113 | - 'obj_id' => $qsg_id, |
|
114 | - 'args' => array('edit'), |
|
115 | - ), |
|
116 | - |
|
117 | - 'delete_question_groups' => array( |
|
118 | - 'func' => '_delete_question_groups', |
|
119 | - 'capability' => 'ee_delete_question_groups', |
|
120 | - 'noheader' => true, |
|
121 | - ), |
|
122 | - |
|
123 | - 'delete_question_group' => array( |
|
124 | - 'func' => '_delete_question_groups', |
|
125 | - 'capability' => 'ee_delete_question_group', |
|
126 | - 'obj_id' => $qsg_id, |
|
127 | - 'noheader' => true, |
|
128 | - ), |
|
129 | - |
|
130 | - 'trash_question_group' => array( |
|
131 | - 'func' => '_trash_or_restore_question_groups', |
|
132 | - 'args' => array('trash' => true), |
|
133 | - 'capability' => 'ee_delete_question_group', |
|
134 | - 'obj_id' => $qsg_id, |
|
135 | - 'noheader' => true, |
|
136 | - ), |
|
137 | - |
|
138 | - 'restore_question_group' => array( |
|
139 | - 'func' => '_trash_or_restore_question_groups', |
|
140 | - 'args' => array('trash' => false), |
|
141 | - 'capability' => 'ee_delete_question_group', |
|
142 | - 'obj_id' => $qsg_id, |
|
143 | - 'noheader' => true, |
|
144 | - ), |
|
145 | - |
|
146 | - 'insert_question_group' => array( |
|
147 | - 'func' => '_insert_or_update_question_group', |
|
148 | - 'args' => array('new_question_group' => true), |
|
149 | - 'capability' => 'ee_edit_question_groups', |
|
150 | - 'noheader' => true, |
|
151 | - ), |
|
152 | - |
|
153 | - 'update_question_group' => array( |
|
154 | - 'func' => '_insert_or_update_question_group', |
|
155 | - 'args' => array('new_question_group' => false), |
|
156 | - 'capability' => 'ee_edit_question_group', |
|
157 | - 'obj_id' => $qsg_id, |
|
158 | - 'noheader' => true, |
|
159 | - ), |
|
160 | - |
|
161 | - 'trash_question_groups' => array( |
|
162 | - 'func' => '_trash_or_restore_question_groups', |
|
163 | - 'args' => array('trash' => true), |
|
164 | - 'capability' => 'ee_delete_question_groups', |
|
165 | - 'noheader' => array('trash' => false), |
|
166 | - ), |
|
167 | - |
|
168 | - 'restore_question_groups' => array( |
|
169 | - 'func' => '_trash_or_restore_question_groups', |
|
170 | - 'args' => array('trash' => false), |
|
171 | - 'capability' => 'ee_delete_question_groups', |
|
172 | - 'noheader' => true, |
|
173 | - ), |
|
174 | - |
|
175 | - |
|
176 | - 'espresso_update_question_group_order' => array( |
|
177 | - 'func' => 'update_question_group_order', |
|
178 | - 'capability' => 'ee_edit_question_groups', |
|
179 | - 'noheader' => true, |
|
180 | - ), |
|
181 | - |
|
182 | - 'view_reg_form_settings' => array( |
|
183 | - 'func' => '_reg_form_settings', |
|
184 | - 'capability' => 'manage_options', |
|
185 | - ), |
|
186 | - |
|
187 | - 'update_reg_form_settings' => array( |
|
188 | - 'func' => '_update_reg_form_settings', |
|
189 | - 'capability' => 'manage_options', |
|
190 | - 'noheader' => true, |
|
191 | - ), |
|
192 | - ); |
|
193 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
194 | - |
|
195 | - $new_page_config = array( |
|
196 | - |
|
197 | - 'question_groups' => array( |
|
198 | - 'nav' => array( |
|
199 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
200 | - 'order' => 20, |
|
201 | - ), |
|
202 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
203 | - 'help_tabs' => array( |
|
204 | - 'registration_form_question_groups_help_tab' => array( |
|
205 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
206 | - 'filename' => 'registration_form_question_groups', |
|
207 | - ), |
|
208 | - 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
209 | - 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
210 | - 'filename' => 'registration_form_question_groups_table_column_headings', |
|
211 | - ), |
|
212 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
213 | - 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
214 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
215 | - ), |
|
216 | - ), |
|
217 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
218 | - // 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
219 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
220 | - 'require_nonce' => false, |
|
221 | - 'qtips' => array( |
|
222 | - 'EE_Registration_Form_Tips', |
|
223 | - ), |
|
224 | - ), |
|
225 | - |
|
226 | - 'add_question' => array( |
|
227 | - 'nav' => array( |
|
228 | - 'label' => esc_html__('Add Question', 'event_espresso'), |
|
229 | - 'order' => 5, |
|
230 | - 'persistent' => false, |
|
231 | - ), |
|
232 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
233 | - 'help_tabs' => array( |
|
234 | - 'registration_form_add_question_help_tab' => array( |
|
235 | - 'title' => esc_html__('Add Question', 'event_espresso'), |
|
236 | - 'filename' => 'registration_form_add_question', |
|
237 | - ), |
|
238 | - ), |
|
239 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
240 | - // 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
241 | - 'require_nonce' => false, |
|
242 | - ), |
|
243 | - |
|
244 | - 'add_question_group' => array( |
|
245 | - 'nav' => array( |
|
246 | - 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
247 | - 'order' => 5, |
|
248 | - 'persistent' => false, |
|
249 | - ), |
|
250 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
251 | - 'help_tabs' => array( |
|
252 | - 'registration_form_add_question_group_help_tab' => array( |
|
253 | - 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
254 | - 'filename' => 'registration_form_add_question_group', |
|
255 | - ), |
|
256 | - ), |
|
257 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
258 | - // 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
259 | - 'require_nonce' => false, |
|
260 | - ), |
|
261 | - |
|
262 | - 'edit_question_group' => array( |
|
263 | - 'nav' => array( |
|
264 | - 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
265 | - 'order' => 5, |
|
266 | - 'persistent' => false, |
|
267 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
268 | - array('question_group_id' => $this->_req_data['question_group_id']), |
|
269 | - $this->_current_page_view_url |
|
270 | - ) : $this->_admin_base_url, |
|
271 | - ), |
|
272 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
273 | - 'help_tabs' => array( |
|
274 | - 'registration_form_edit_question_group_help_tab' => array( |
|
275 | - 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
276 | - 'filename' => 'registration_form_edit_question_group', |
|
277 | - ), |
|
278 | - ), |
|
279 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
280 | - // 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
281 | - 'require_nonce' => false, |
|
282 | - ), |
|
283 | - |
|
284 | - 'view_reg_form_settings' => array( |
|
285 | - 'nav' => array( |
|
286 | - 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
287 | - 'order' => 40, |
|
288 | - ), |
|
289 | - 'labels' => array( |
|
290 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
291 | - ), |
|
292 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
293 | - 'help_tabs' => array( |
|
294 | - 'registration_form_reg_form_settings_help_tab' => array( |
|
295 | - 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
296 | - 'filename' => 'registration_form_reg_form_settings', |
|
297 | - ), |
|
298 | - ), |
|
299 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
300 | - // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
301 | - 'require_nonce' => false, |
|
302 | - ), |
|
303 | - |
|
304 | - ); |
|
305 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
306 | - |
|
307 | - // change the list table we're going to use so it's the NEW list table! |
|
308 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
309 | - |
|
310 | - |
|
311 | - // additional labels |
|
312 | - $new_labels = array( |
|
313 | - 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
314 | - 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
315 | - 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
316 | - 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
317 | - 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
318 | - ); |
|
319 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @return void |
|
325 | - */ |
|
326 | - protected function _ajax_hooks() |
|
327 | - { |
|
328 | - add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - public function load_scripts_styles_question_groups() |
|
336 | - { |
|
337 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * @return void |
|
343 | - */ |
|
344 | - public function load_scripts_styles_add_question_group() |
|
345 | - { |
|
346 | - $this->load_scripts_styles_forms(); |
|
347 | - $this->load_sortable_question_script(); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * @return void |
|
353 | - */ |
|
354 | - public function load_scripts_styles_edit_question_group() |
|
355 | - { |
|
356 | - $this->load_scripts_styles_forms(); |
|
357 | - $this->load_sortable_question_script(); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * registers and enqueues script for questions |
|
363 | - * |
|
364 | - * @return void |
|
365 | - */ |
|
366 | - public function load_sortable_question_script() |
|
367 | - { |
|
368 | - wp_register_script( |
|
369 | - 'ee-question-sortable', |
|
370 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
371 | - array('jquery-ui-sortable'), |
|
372 | - EVENT_ESPRESSO_VERSION, |
|
373 | - true |
|
374 | - ); |
|
375 | - wp_enqueue_script('ee-question-sortable'); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return void |
|
381 | - */ |
|
382 | - protected function _set_list_table_views_default() |
|
383 | - { |
|
384 | - $this->_views = array( |
|
385 | - 'all' => array( |
|
386 | - 'slug' => 'all', |
|
387 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
388 | - 'count' => 0, |
|
389 | - 'bulk_action' => array( |
|
390 | - 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
391 | - ), |
|
392 | - ), |
|
393 | - ); |
|
394 | - |
|
395 | - if ( |
|
396 | - EE_Registry::instance()->CAP->current_user_can( |
|
397 | - 'ee_delete_questions', |
|
398 | - 'espresso_registration_form_trash_questions' |
|
399 | - ) |
|
400 | - ) { |
|
401 | - $this->_views['trash'] = array( |
|
402 | - 'slug' => 'trash', |
|
403 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
404 | - 'count' => 0, |
|
405 | - 'bulk_action' => array( |
|
406 | - 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
407 | - 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
408 | - ), |
|
409 | - ); |
|
410 | - } |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @return void |
|
416 | - */ |
|
417 | - protected function _set_list_table_views_question_groups() |
|
418 | - { |
|
419 | - $this->_views = array( |
|
420 | - 'all' => array( |
|
421 | - 'slug' => 'all', |
|
422 | - 'label' => esc_html__('All', 'event_espresso'), |
|
423 | - 'count' => 0, |
|
424 | - 'bulk_action' => array( |
|
425 | - 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
426 | - ), |
|
427 | - ), |
|
428 | - ); |
|
429 | - |
|
430 | - if ( |
|
431 | - EE_Registry::instance()->CAP->current_user_can( |
|
432 | - 'ee_delete_question_groups', |
|
433 | - 'espresso_registration_form_trash_question_groups' |
|
434 | - ) |
|
435 | - ) { |
|
436 | - $this->_views['trash'] = array( |
|
437 | - 'slug' => 'trash', |
|
438 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
439 | - 'count' => 0, |
|
440 | - 'bulk_action' => array( |
|
441 | - 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
442 | - 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
443 | - ), |
|
444 | - ); |
|
445 | - } |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * @return void |
|
451 | - * @throws EE_Error |
|
452 | - * @throws InvalidArgumentException |
|
453 | - * @throws InvalidDataTypeException |
|
454 | - * @throws InvalidInterfaceException |
|
455 | - */ |
|
456 | - protected function _questions_overview_list_table() |
|
457 | - { |
|
458 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
459 | - 'add_question', |
|
460 | - 'add_question', |
|
461 | - array(), |
|
462 | - 'add-new-h2' |
|
463 | - ); |
|
464 | - parent::_questions_overview_list_table(); |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @return void |
|
470 | - * @throws DomainException |
|
471 | - * @throws EE_Error |
|
472 | - * @throws InvalidArgumentException |
|
473 | - * @throws InvalidDataTypeException |
|
474 | - * @throws InvalidInterfaceException |
|
475 | - */ |
|
476 | - protected function _question_groups_overview_list_table() |
|
477 | - { |
|
478 | - $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
479 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
480 | - 'add_question_group', |
|
481 | - 'add_question_group', |
|
482 | - array(), |
|
483 | - 'add-new-h2' |
|
484 | - ); |
|
485 | - $this->display_admin_list_table_page_with_sidebar(); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @return void |
|
491 | - * @throws EE_Error |
|
492 | - * @throws InvalidArgumentException |
|
493 | - * @throws InvalidDataTypeException |
|
494 | - * @throws InvalidInterfaceException |
|
495 | - */ |
|
496 | - protected function _delete_question() |
|
497 | - { |
|
498 | - $success = $this->_delete_items($this->_question_model); |
|
499 | - $this->_redirect_after_action( |
|
500 | - $success, |
|
501 | - $this->_question_model->item_name($success), |
|
502 | - 'deleted', |
|
503 | - array('action' => 'default', 'status' => 'all') |
|
504 | - ); |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * @return void |
|
510 | - * @throws EE_Error |
|
511 | - * @throws InvalidArgumentException |
|
512 | - * @throws InvalidDataTypeException |
|
513 | - * @throws InvalidInterfaceException |
|
514 | - */ |
|
515 | - protected function _delete_questions() |
|
516 | - { |
|
517 | - $success = $this->_delete_items($this->_question_model); |
|
518 | - $this->_redirect_after_action( |
|
519 | - $success, |
|
520 | - $this->_question_model->item_name($success), |
|
521 | - 'deleted permanently', |
|
522 | - array('action' => 'default', 'status' => 'trash') |
|
523 | - ); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * Performs the deletion of a single or multiple questions or question groups. |
|
529 | - * |
|
530 | - * @param EEM_Soft_Delete_Base $model |
|
531 | - * @return int number of items deleted permanently |
|
532 | - * @throws EE_Error |
|
533 | - * @throws InvalidArgumentException |
|
534 | - * @throws InvalidDataTypeException |
|
535 | - * @throws InvalidInterfaceException |
|
536 | - */ |
|
537 | - private function _delete_items(EEM_Soft_Delete_Base $model) |
|
538 | - { |
|
539 | - $success = 0; |
|
540 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
541 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
542 | - // if array has more than one element than success message should be plural |
|
543 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
544 | - // cycle thru bulk action checkboxes |
|
545 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
546 | - if (! $this->_delete_item($ID, $model)) { |
|
547 | - $success = 0; |
|
548 | - } |
|
549 | - } |
|
550 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
551 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
552 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
553 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
554 | - } else { |
|
555 | - EE_Error::add_error( |
|
556 | - sprintf( |
|
557 | - esc_html__( |
|
558 | - "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
559 | - "event_espresso" |
|
560 | - ) |
|
561 | - ), |
|
562 | - __FILE__, |
|
563 | - __FUNCTION__, |
|
564 | - __LINE__ |
|
565 | - ); |
|
566 | - } |
|
567 | - return $success; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Deletes the specified question (and its associated question options) or question group |
|
573 | - * |
|
574 | - * @param int $id |
|
575 | - * @param EEM_Soft_Delete_Base $model |
|
576 | - * @return boolean |
|
577 | - * @throws EE_Error |
|
578 | - * @throws InvalidArgumentException |
|
579 | - * @throws InvalidDataTypeException |
|
580 | - * @throws InvalidInterfaceException |
|
581 | - */ |
|
582 | - protected function _delete_item($id, $model) |
|
583 | - { |
|
584 | - if ($model instanceof EEM_Question) { |
|
585 | - EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
586 | - } |
|
587 | - return $model->delete_permanently_by_ID(absint($id)); |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - /****************************** QUESTION GROUPS ******************************/ |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * @param string $type |
|
596 | - * @return void |
|
597 | - * @throws DomainException |
|
598 | - * @throws EE_Error |
|
599 | - * @throws InvalidArgumentException |
|
600 | - * @throws InvalidDataTypeException |
|
601 | - * @throws InvalidInterfaceException |
|
602 | - */ |
|
603 | - protected function _edit_question_group($type = 'add') |
|
604 | - { |
|
605 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
606 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
607 | - ? absint($this->_req_data['QSG_ID']) |
|
608 | - : false; |
|
609 | - |
|
610 | - switch ($this->_req_action) { |
|
611 | - case 'add_question_group': |
|
612 | - $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
613 | - break; |
|
614 | - case 'edit_question_group': |
|
615 | - $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
616 | - break; |
|
617 | - default: |
|
618 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
619 | - } |
|
620 | - // add ID to title if editing |
|
621 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
622 | - if ($ID) { |
|
623 | - /** @var EE_Question_Group $questionGroup */ |
|
624 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
625 | - $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
626 | - $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
627 | - } else { |
|
628 | - /** @var EE_Question_Group $questionGroup */ |
|
629 | - $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
630 | - $questionGroup->set_order_to_latest(); |
|
631 | - $this->_set_add_edit_form_tags('insert_question_group'); |
|
632 | - } |
|
633 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
634 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
635 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
636 | - $this->_template_args['question_group'] = $questionGroup; |
|
637 | - |
|
638 | - $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
639 | - $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
640 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
641 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
642 | - $this->_template_args, |
|
643 | - true |
|
644 | - ); |
|
645 | - |
|
646 | - // the details template wrapper |
|
647 | - $this->display_admin_page_with_sidebar(); |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * @return void |
|
653 | - * @throws EE_Error |
|
654 | - * @throws InvalidArgumentException |
|
655 | - * @throws InvalidDataTypeException |
|
656 | - * @throws InvalidInterfaceException |
|
657 | - */ |
|
658 | - protected function _delete_question_groups() |
|
659 | - { |
|
660 | - $success = $this->_delete_items($this->_question_group_model); |
|
661 | - $this->_redirect_after_action( |
|
662 | - $success, |
|
663 | - $this->_question_group_model->item_name($success), |
|
664 | - 'deleted permanently', |
|
665 | - array('action' => 'question_groups', 'status' => 'trash') |
|
666 | - ); |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * @param bool $new_question_group |
|
672 | - * @throws EE_Error |
|
673 | - * @throws InvalidArgumentException |
|
674 | - * @throws InvalidDataTypeException |
|
675 | - * @throws InvalidInterfaceException |
|
676 | - */ |
|
677 | - protected function _insert_or_update_question_group($new_question_group = true) |
|
678 | - { |
|
679 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
680 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
681 | - if ($new_question_group) { |
|
682 | - // make sure identifier is unique |
|
683 | - $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
684 | - $identifier_exists = ! empty($identifier_value) |
|
685 | - ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0 |
|
686 | - : false; |
|
687 | - if ($identifier_exists) { |
|
688 | - $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
689 | - } |
|
690 | - $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
691 | - $success = $QSG_ID ? 1 : 0; |
|
692 | - if ($success === 0) { |
|
693 | - EE_Error::add_error( |
|
694 | - esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
695 | - __FILE__, |
|
696 | - __FUNCTION__, |
|
697 | - __LINE__ |
|
698 | - ); |
|
699 | - $this->_redirect_after_action( |
|
700 | - false, |
|
701 | - '', |
|
702 | - '', |
|
703 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
704 | - true |
|
705 | - ); |
|
706 | - } |
|
707 | - } else { |
|
708 | - $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
709 | - unset($set_column_values['QSG_ID']); |
|
710 | - $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
711 | - } |
|
712 | - |
|
713 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
714 | - EEM_Attendee::system_question_phone |
|
715 | - ); |
|
716 | - // update the existing related questions |
|
717 | - // BUT FIRST... delete the phone question from the Question_Group_Question |
|
718 | - // if it is being added to this question group (therefore removed from the existing group) |
|
719 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
720 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
721 | - EEM_Question_Group_Question::instance()->delete( |
|
722 | - array( |
|
723 | - array( |
|
724 | - 'QST_ID' => $phone_question_id, |
|
725 | - 'QSG_ID' => array('!=', $QSG_ID), |
|
726 | - ), |
|
727 | - ) |
|
728 | - ); |
|
729 | - } |
|
730 | - /** @type EE_Question_Group $question_group */ |
|
731 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
732 | - $questions = $question_group->questions(); |
|
733 | - // make sure system phone question is added to list of questions for this group |
|
734 | - if (! isset($questions[ $phone_question_id ])) { |
|
735 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
736 | - } |
|
737 | - |
|
738 | - foreach ($questions as $question_ID => $question) { |
|
739 | - // first we always check for order. |
|
740 | - if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
741 | - // update question order |
|
742 | - $question_group->update_question_order( |
|
743 | - $question_ID, |
|
744 | - $this->_req_data['question_orders'][ $question_ID ] |
|
745 | - ); |
|
746 | - } |
|
747 | - |
|
748 | - // then we always check if adding or removing. |
|
749 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
750 | - $question_group->add_question($question_ID); |
|
751 | - } else { |
|
752 | - // not found, remove it (but only if not a system question for the personal group |
|
753 | - // with the exception of lname system question - we allow removal of it) |
|
754 | - if ( |
|
755 | - in_array( |
|
756 | - $question->system_ID(), |
|
757 | - EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
758 | - $question_group->system_group() |
|
759 | - ) |
|
760 | - ) |
|
761 | - ) { |
|
762 | - continue; |
|
763 | - } else { |
|
764 | - $question_group->remove_question($question_ID); |
|
765 | - } |
|
766 | - } |
|
767 | - } |
|
768 | - // save new related questions |
|
769 | - if (isset($this->_req_data['questions'])) { |
|
770 | - foreach ($this->_req_data['questions'] as $QST_ID) { |
|
771 | - $question_group->add_question($QST_ID); |
|
772 | - if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
773 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
774 | - } |
|
775 | - } |
|
776 | - } |
|
777 | - |
|
778 | - if ($success !== false) { |
|
779 | - $msg = $new_question_group |
|
780 | - ? sprintf( |
|
781 | - esc_html__('The %s has been created', 'event_espresso'), |
|
782 | - $this->_question_group_model->item_name() |
|
783 | - ) |
|
784 | - : sprintf( |
|
785 | - esc_html__( |
|
786 | - 'The %s has been updated', |
|
787 | - 'event_espresso' |
|
788 | - ), |
|
789 | - $this->_question_group_model->item_name() |
|
790 | - ); |
|
791 | - EE_Error::add_success($msg); |
|
792 | - } |
|
793 | - $this->_redirect_after_action( |
|
794 | - false, |
|
795 | - '', |
|
796 | - '', |
|
797 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
798 | - true |
|
799 | - ); |
|
800 | - } |
|
801 | - |
|
802 | - |
|
803 | - /** |
|
804 | - * duplicates a question and all its question options and redirects to the new question. |
|
805 | - * |
|
806 | - * @return void |
|
807 | - * @throws EE_Error |
|
808 | - * @throws InvalidArgumentException |
|
809 | - * @throws ReflectionException |
|
810 | - * @throws InvalidDataTypeException |
|
811 | - * @throws InvalidInterfaceException |
|
812 | - */ |
|
813 | - public function _duplicate_question() |
|
814 | - { |
|
815 | - $question_ID = (int) $this->_req_data['QST_ID']; |
|
816 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
817 | - if ($question instanceof EE_Question) { |
|
818 | - $new_question = $question->duplicate(); |
|
819 | - if ($new_question instanceof EE_Question) { |
|
820 | - $this->_redirect_after_action( |
|
821 | - true, |
|
822 | - esc_html__('Question', 'event_espresso'), |
|
823 | - esc_html__('Duplicated', 'event_espresso'), |
|
824 | - array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
825 | - true |
|
826 | - ); |
|
827 | - } else { |
|
828 | - global $wpdb; |
|
829 | - EE_Error::add_error( |
|
830 | - sprintf( |
|
831 | - esc_html__( |
|
832 | - 'Could not duplicate question with ID %1$d because: %2$s', |
|
833 | - 'event_espresso' |
|
834 | - ), |
|
835 | - $question_ID, |
|
836 | - $wpdb->last_error |
|
837 | - ), |
|
838 | - __FILE__, |
|
839 | - __FUNCTION__, |
|
840 | - __LINE__ |
|
841 | - ); |
|
842 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
843 | - } |
|
844 | - } else { |
|
845 | - EE_Error::add_error( |
|
846 | - sprintf( |
|
847 | - esc_html__( |
|
848 | - 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
849 | - 'event_espresso' |
|
850 | - ), |
|
851 | - $question_ID |
|
852 | - ), |
|
853 | - __FILE__, |
|
854 | - __FUNCTION__, |
|
855 | - __LINE__ |
|
856 | - ); |
|
857 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
858 | - } |
|
859 | - } |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * @param bool $trash |
|
864 | - * @throws EE_Error |
|
865 | - */ |
|
866 | - protected function _trash_or_restore_question_groups($trash = true) |
|
867 | - { |
|
868 | - $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
869 | - } |
|
870 | - |
|
871 | - |
|
872 | - /** |
|
873 | - *_trash_question |
|
874 | - * |
|
875 | - * @return void |
|
876 | - * @throws EE_Error |
|
877 | - */ |
|
878 | - protected function _trash_question() |
|
879 | - { |
|
880 | - $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
881 | - $query_args = array('action' => 'default', 'status' => 'all'); |
|
882 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - /** |
|
887 | - * @param bool $trash |
|
888 | - * @throws EE_Error |
|
889 | - */ |
|
890 | - protected function _trash_or_restore_questions($trash = true) |
|
891 | - { |
|
892 | - $this->_trash_or_restore_items($this->_question_model, $trash); |
|
893 | - } |
|
894 | - |
|
895 | - |
|
896 | - /** |
|
897 | - * Internally used to delete or restore items, using the request data. Meant to be |
|
898 | - * flexible between question or question groups |
|
899 | - * |
|
900 | - * @param EEM_Soft_Delete_Base $model |
|
901 | - * @param boolean $trash whether to trash or restore |
|
902 | - * @throws EE_Error |
|
903 | - */ |
|
904 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
905 | - { |
|
906 | - |
|
907 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
908 | - |
|
909 | - $success = 1; |
|
910 | - // Checkboxes |
|
911 | - // echo "trash $trash"; |
|
912 | - // var_dump($this->_req_data['checkbox']);die; |
|
913 | - if (isset($this->_req_data['checkbox'])) { |
|
914 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
915 | - // if array has more than one element than success message should be plural |
|
916 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
917 | - // cycle thru bulk action checkboxes |
|
918 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
919 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
920 | - $success = 0; |
|
921 | - } |
|
922 | - } |
|
923 | - } else { |
|
924 | - // grab single id and delete |
|
925 | - $ID = absint($this->_req_data['checkbox']); |
|
926 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
927 | - $success = 0; |
|
928 | - } |
|
929 | - } |
|
930 | - } else { |
|
931 | - // delete via trash link |
|
932 | - // grab single id and delete |
|
933 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
934 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
935 | - $success = 0; |
|
936 | - } |
|
937 | - } |
|
938 | - |
|
939 | - |
|
940 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
941 | - // echo "action :$action"; |
|
942 | - // $action = 'questions' ? 'default' : $action; |
|
943 | - if ($trash) { |
|
944 | - $action_desc = 'trashed'; |
|
945 | - $status = 'trash'; |
|
946 | - } else { |
|
947 | - $action_desc = 'restored'; |
|
948 | - $status = 'all'; |
|
949 | - } |
|
950 | - $this->_redirect_after_action( |
|
951 | - $success, |
|
952 | - $model->item_name($success), |
|
953 | - $action_desc, |
|
954 | - array('action' => $action, 'status' => $status) |
|
955 | - ); |
|
956 | - } |
|
957 | - |
|
958 | - |
|
959 | - /** |
|
960 | - * @param $per_page |
|
961 | - * @param int $current_page |
|
962 | - * @param bool|false $count |
|
963 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
964 | - * @throws EE_Error |
|
965 | - * @throws InvalidArgumentException |
|
966 | - * @throws InvalidDataTypeException |
|
967 | - * @throws InvalidInterfaceException |
|
968 | - */ |
|
969 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
970 | - { |
|
971 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
972 | - |
|
973 | - if ($count) { |
|
974 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
975 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
976 | - $results = $this->_question_model->count_deleted($where); |
|
977 | - } else { |
|
978 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
979 | - $results = $this->_question_model->get_all_deleted($query_params); |
|
980 | - } |
|
981 | - return $results; |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * @param $per_page |
|
987 | - * @param int $current_page |
|
988 | - * @param bool|false $count |
|
989 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
990 | - * @throws EE_Error |
|
991 | - * @throws InvalidArgumentException |
|
992 | - * @throws InvalidDataTypeException |
|
993 | - * @throws InvalidInterfaceException |
|
994 | - */ |
|
995 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
996 | - { |
|
997 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
998 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
999 | - if ($count) { |
|
1000 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
1001 | - $results = $questionGroupModel->count($where); |
|
1002 | - } else { |
|
1003 | - $results = $questionGroupModel->get_all($query_params); |
|
1004 | - } |
|
1005 | - return $results; |
|
1006 | - } |
|
1007 | - |
|
1008 | - |
|
1009 | - /** |
|
1010 | - * @param $per_page |
|
1011 | - * @param int $current_page |
|
1012 | - * @param bool $count |
|
1013 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
1014 | - * @throws EE_Error |
|
1015 | - * @throws InvalidArgumentException |
|
1016 | - * @throws InvalidDataTypeException |
|
1017 | - * @throws InvalidInterfaceException |
|
1018 | - */ |
|
1019 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
1020 | - { |
|
1021 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
1022 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
1023 | - if ($count) { |
|
1024 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
1025 | - $query_params['limit'] = null; |
|
1026 | - $results = $questionGroupModel->count_deleted($where); |
|
1027 | - } else { |
|
1028 | - $results = $questionGroupModel->get_all_deleted($query_params); |
|
1029 | - } |
|
1030 | - return $results; |
|
1031 | - } |
|
1032 | - |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * method for performing updates to question order |
|
1036 | - * |
|
1037 | - * @return void results array |
|
1038 | - * @throws EE_Error |
|
1039 | - * @throws InvalidArgumentException |
|
1040 | - * @throws InvalidDataTypeException |
|
1041 | - * @throws InvalidInterfaceException |
|
1042 | - */ |
|
1043 | - public function update_question_group_order() |
|
1044 | - { |
|
1045 | - |
|
1046 | - $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
1047 | - |
|
1048 | - // grab our row IDs |
|
1049 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
1050 | - ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
1051 | - : array(); |
|
1052 | - |
|
1053 | - $perpage = ! empty($this->_req_data['perpage']) |
|
1054 | - ? (int) $this->_req_data['perpage'] |
|
1055 | - : null; |
|
1056 | - $curpage = ! empty($this->_req_data['curpage']) |
|
1057 | - ? (int) $this->_req_data['curpage'] |
|
1058 | - : null; |
|
1059 | - |
|
1060 | - if (! empty($row_ids)) { |
|
1061 | - // figure out where we start the row_id count at for the current page. |
|
1062 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
1063 | - |
|
1064 | - $row_count = count($row_ids); |
|
1065 | - for ($i = 0; $i < $row_count; $i++) { |
|
1066 | - // Update the questions when re-ordering |
|
1067 | - $updated = EEM_Question_Group::instance()->update( |
|
1068 | - array('QSG_order' => $qsgcount), |
|
1069 | - array(array('QSG_ID' => $row_ids[ $i ])) |
|
1070 | - ); |
|
1071 | - if ($updated === false) { |
|
1072 | - $success = false; |
|
1073 | - } |
|
1074 | - $qsgcount++; |
|
1075 | - } |
|
1076 | - } else { |
|
1077 | - $success = false; |
|
1078 | - } |
|
1079 | - |
|
1080 | - $errors = ! $success |
|
1081 | - ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
1082 | - : false; |
|
1083 | - |
|
1084 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
1085 | - die(); |
|
1086 | - } |
|
1087 | - |
|
1088 | - |
|
1089 | - |
|
1090 | - /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
1091 | - |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * @throws DomainException |
|
1095 | - * @throws EE_Error |
|
1096 | - * @throws InvalidArgumentException |
|
1097 | - * @throws InvalidDataTypeException |
|
1098 | - * @throws InvalidInterfaceException |
|
1099 | - */ |
|
1100 | - protected function _reg_form_settings() |
|
1101 | - { |
|
1102 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
1103 | - add_action( |
|
1104 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
1105 | - array($this, 'email_validation_settings_form'), |
|
1106 | - 2 |
|
1107 | - ); |
|
1108 | - add_action( |
|
1109 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
1110 | - array($this, 'copy_attendee_info_settings_form'), |
|
1111 | - 4 |
|
1112 | - ); |
|
1113 | - $this->_template_args = (array) apply_filters( |
|
1114 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
1115 | - $this->_template_args |
|
1116 | - ); |
|
1117 | - $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
1118 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1119 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1120 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
1121 | - $this->_template_args, |
|
1122 | - true |
|
1123 | - ); |
|
1124 | - $this->display_admin_page_with_sidebar(); |
|
1125 | - } |
|
1126 | - |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * @return void |
|
1130 | - * @throws EE_Error |
|
1131 | - * @throws InvalidArgumentException |
|
1132 | - * @throws ReflectionException |
|
1133 | - * @throws InvalidDataTypeException |
|
1134 | - * @throws InvalidInterfaceException |
|
1135 | - */ |
|
1136 | - protected function _update_reg_form_settings() |
|
1137 | - { |
|
1138 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
1139 | - EE_Registry::instance()->CFG->registration |
|
1140 | - ); |
|
1141 | - EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form( |
|
1142 | - EE_Registry::instance()->CFG->registration |
|
1143 | - ); |
|
1144 | - EE_Registry::instance()->CFG->registration = apply_filters( |
|
1145 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
1146 | - EE_Registry::instance()->CFG->registration |
|
1147 | - ); |
|
1148 | - $success = $this->_update_espresso_configuration( |
|
1149 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
1150 | - EE_Registry::instance()->CFG, |
|
1151 | - __FILE__, |
|
1152 | - __FUNCTION__, |
|
1153 | - __LINE__ |
|
1154 | - ); |
|
1155 | - $this->_redirect_after_action( |
|
1156 | - $success, |
|
1157 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
1158 | - 'updated', |
|
1159 | - array('action' => 'view_reg_form_settings') |
|
1160 | - ); |
|
1161 | - } |
|
1162 | - |
|
1163 | - |
|
1164 | - /** |
|
1165 | - * @return void |
|
1166 | - * @throws EE_Error |
|
1167 | - * @throws InvalidArgumentException |
|
1168 | - * @throws InvalidDataTypeException |
|
1169 | - * @throws InvalidInterfaceException |
|
1170 | - */ |
|
1171 | - public function copy_attendee_info_settings_form() |
|
1172 | - { |
|
1173 | - echo $this->_copy_attendee_info_settings_form()->get_html(); |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * _copy_attendee_info_settings_form |
|
1178 | - * |
|
1179 | - * @access protected |
|
1180 | - * @return EE_Form_Section_Proper |
|
1181 | - * @throws \EE_Error |
|
1182 | - */ |
|
1183 | - protected function _copy_attendee_info_settings_form() |
|
1184 | - { |
|
1185 | - return new EE_Form_Section_Proper( |
|
1186 | - array( |
|
1187 | - 'name' => 'copy_attendee_info_settings', |
|
1188 | - 'html_id' => 'copy_attendee_info_settings', |
|
1189 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1190 | - 'subsections' => apply_filters( |
|
1191 | - 'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections', |
|
1192 | - array( |
|
1193 | - 'copy_attendee_info_hdr' => new EE_Form_Section_HTML( |
|
1194 | - EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso')) |
|
1195 | - ), |
|
1196 | - 'copy_attendee_info' => new EE_Yes_No_Input( |
|
1197 | - array( |
|
1198 | - 'html_label_text' => esc_html__( |
|
1199 | - 'Allow copy #1 attendee info to extra attendees?', |
|
1200 | - 'event_espresso' |
|
1201 | - ), |
|
1202 | - 'html_help_text' => esc_html__( |
|
1203 | - 'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.', |
|
1204 | - 'event_espresso' |
|
1205 | - ), |
|
1206 | - 'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(), |
|
1207 | - 'required' => false, |
|
1208 | - 'display_html_label_text' => false, |
|
1209 | - ) |
|
1210 | - ), |
|
1211 | - ) |
|
1212 | - ), |
|
1213 | - ) |
|
1214 | - ); |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * @param EE_Registration_Config $EE_Registration_Config |
|
1219 | - * @return EE_Registration_Config |
|
1220 | - * @throws EE_Error |
|
1221 | - * @throws InvalidArgumentException |
|
1222 | - * @throws ReflectionException |
|
1223 | - * @throws InvalidDataTypeException |
|
1224 | - * @throws InvalidInterfaceException |
|
1225 | - */ |
|
1226 | - public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1227 | - { |
|
1228 | - $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo(); |
|
1229 | - try { |
|
1230 | - $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form(); |
|
1231 | - // if not displaying a form, then check for form submission |
|
1232 | - if ($copy_attendee_info_settings_form->was_submitted()) { |
|
1233 | - // capture form data |
|
1234 | - $copy_attendee_info_settings_form->receive_form_submission(); |
|
1235 | - // validate form data |
|
1236 | - if ($copy_attendee_info_settings_form->is_valid()) { |
|
1237 | - // grab validated data from form |
|
1238 | - $valid_data = $copy_attendee_info_settings_form->valid_data(); |
|
1239 | - if (isset($valid_data['copy_attendee_info'])) { |
|
1240 | - $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']); |
|
1241 | - } else { |
|
1242 | - EE_Error::add_error( |
|
1243 | - esc_html__( |
|
1244 | - 'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.', |
|
1245 | - 'event_espresso' |
|
1246 | - ), |
|
1247 | - __FILE__, |
|
1248 | - __FUNCTION__, |
|
1249 | - __LINE__ |
|
1250 | - ); |
|
1251 | - } |
|
1252 | - } else { |
|
1253 | - if ($copy_attendee_info_settings_form->submission_error_message() !== '') { |
|
1254 | - EE_Error::add_error( |
|
1255 | - $copy_attendee_info_settings_form->submission_error_message(), |
|
1256 | - __FILE__, |
|
1257 | - __FUNCTION__, |
|
1258 | - __LINE__ |
|
1259 | - ); |
|
1260 | - } |
|
1261 | - } |
|
1262 | - } |
|
1263 | - } catch (EE_Error $e) { |
|
1264 | - $e->get_error(); |
|
1265 | - } |
|
1266 | - return $EE_Registration_Config; |
|
1267 | - } |
|
1268 | - |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * @return void |
|
1272 | - * @throws EE_Error |
|
1273 | - * @throws InvalidArgumentException |
|
1274 | - * @throws InvalidDataTypeException |
|
1275 | - * @throws InvalidInterfaceException |
|
1276 | - */ |
|
1277 | - public function email_validation_settings_form() |
|
1278 | - { |
|
1279 | - echo $this->_email_validation_settings_form()->get_html(); |
|
1280 | - } |
|
1281 | - |
|
1282 | - |
|
1283 | - /** |
|
1284 | - * _email_validation_settings_form |
|
1285 | - * |
|
1286 | - * @access protected |
|
1287 | - * @return EE_Form_Section_Proper |
|
1288 | - * @throws \EE_Error |
|
1289 | - */ |
|
1290 | - protected function _email_validation_settings_form() |
|
1291 | - { |
|
1292 | - return new EE_Form_Section_Proper( |
|
1293 | - array( |
|
1294 | - 'name' => 'email_validation_settings', |
|
1295 | - 'html_id' => 'email_validation_settings', |
|
1296 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1297 | - 'subsections' => apply_filters( |
|
1298 | - 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
1299 | - array( |
|
1300 | - 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
1301 | - EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
1302 | - ), |
|
1303 | - 'email_validation_level' => new EE_Select_Input( |
|
1304 | - array( |
|
1305 | - 'basic' => esc_html__('Basic', 'event_espresso'), |
|
1306 | - 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
1307 | - 'i18n' => esc_html__('International', 'event_espresso'), |
|
1308 | - 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
1309 | - ), |
|
1310 | - array( |
|
1311 | - 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
1312 | - . EEH_Template::get_help_tab_link('email_validation_info'), |
|
1313 | - 'html_help_text' => esc_html__( |
|
1314 | - 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
1315 | - 'event_espresso' |
|
1316 | - ), |
|
1317 | - 'default' => isset( |
|
1318 | - EE_Registry::instance()->CFG->registration->email_validation_level |
|
1319 | - ) |
|
1320 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
1321 | - : 'wp_default', |
|
1322 | - 'required' => false, |
|
1323 | - ) |
|
1324 | - ), |
|
1325 | - ) |
|
1326 | - ), |
|
1327 | - ) |
|
1328 | - ); |
|
1329 | - } |
|
1330 | - |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * @param EE_Registration_Config $EE_Registration_Config |
|
1334 | - * @return EE_Registration_Config |
|
1335 | - * @throws EE_Error |
|
1336 | - * @throws InvalidArgumentException |
|
1337 | - * @throws ReflectionException |
|
1338 | - * @throws InvalidDataTypeException |
|
1339 | - * @throws InvalidInterfaceException |
|
1340 | - */ |
|
1341 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1342 | - { |
|
1343 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
1344 | - try { |
|
1345 | - $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
1346 | - // if not displaying a form, then check for form submission |
|
1347 | - if ($email_validation_settings_form->was_submitted()) { |
|
1348 | - // capture form data |
|
1349 | - $email_validation_settings_form->receive_form_submission(); |
|
1350 | - // validate form data |
|
1351 | - if ($email_validation_settings_form->is_valid()) { |
|
1352 | - // grab validated data from form |
|
1353 | - $valid_data = $email_validation_settings_form->valid_data(); |
|
1354 | - if (isset($valid_data['email_validation_level'])) { |
|
1355 | - $email_validation_level = $valid_data['email_validation_level']; |
|
1356 | - // now if they want to use international email addresses |
|
1357 | - if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
1358 | - // in case we need to reset their email validation level, |
|
1359 | - // make sure that the previous value wasn't already set to one of the i18n options. |
|
1360 | - if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
1361 | - // if so, then reset it back to "basic" since that is the only other option that, |
|
1362 | - // despite offering poor validation, supports i18n email addresses |
|
1363 | - $prev_email_validation_level = 'basic'; |
|
1364 | - } |
|
1365 | - // confirm our i18n email validation will work on the server |
|
1366 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1367 | - // or reset email validation level to previous value |
|
1368 | - $email_validation_level = $prev_email_validation_level; |
|
1369 | - } |
|
1370 | - } |
|
1371 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1372 | - } else { |
|
1373 | - EE_Error::add_error( |
|
1374 | - esc_html__( |
|
1375 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
1376 | - 'event_espresso' |
|
1377 | - ), |
|
1378 | - __FILE__, |
|
1379 | - __FUNCTION__, |
|
1380 | - __LINE__ |
|
1381 | - ); |
|
1382 | - } |
|
1383 | - } else { |
|
1384 | - if ($email_validation_settings_form->submission_error_message() !== '') { |
|
1385 | - EE_Error::add_error( |
|
1386 | - $email_validation_settings_form->submission_error_message(), |
|
1387 | - __FILE__, |
|
1388 | - __FUNCTION__, |
|
1389 | - __LINE__ |
|
1390 | - ); |
|
1391 | - } |
|
1392 | - } |
|
1393 | - } |
|
1394 | - } catch (EE_Error $e) { |
|
1395 | - $e->get_error(); |
|
1396 | - } |
|
1397 | - return $EE_Registration_Config; |
|
1398 | - } |
|
1399 | - |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * confirms that the server's PHP version has the PCRE module enabled, |
|
1403 | - * and that the PCRE version works with our i18n email validation |
|
1404 | - * |
|
1405 | - * @param EE_Registration_Config $EE_Registration_Config |
|
1406 | - * @param string $email_validation_level |
|
1407 | - * @return bool |
|
1408 | - */ |
|
1409 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
1410 | - { |
|
1411 | - // first check that PCRE is enabled |
|
1412 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1413 | - EE_Error::add_error( |
|
1414 | - sprintf( |
|
1415 | - esc_html__( |
|
1416 | - 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
1417 | - 'event_espresso' |
|
1418 | - ), |
|
1419 | - '<br />' |
|
1420 | - ), |
|
1421 | - __FILE__, |
|
1422 | - __FUNCTION__, |
|
1423 | - __LINE__ |
|
1424 | - ); |
|
1425 | - return false; |
|
1426 | - } else { |
|
1427 | - // PCRE support is enabled, but let's still |
|
1428 | - // perform a test to see if the server will support it. |
|
1429 | - // but first, save the updated validation level to the config, |
|
1430 | - // so that the validation strategy picks it up. |
|
1431 | - // this will get bumped back down if it doesn't work |
|
1432 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1433 | - try { |
|
1434 | - $email_validator = new EE_Email_Validation_Strategy(); |
|
1435 | - $i18n_email_address = apply_filters( |
|
1436 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
1437 | - 'jägerjü[email protected]' |
|
1438 | - ); |
|
1439 | - $email_validator->validate($i18n_email_address); |
|
1440 | - } catch (Exception $e) { |
|
1441 | - EE_Error::add_error( |
|
1442 | - sprintf( |
|
1443 | - esc_html__( |
|
1444 | - 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
1445 | - 'event_espresso' |
|
1446 | - ), |
|
1447 | - '<br />', |
|
1448 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>' |
|
1449 | - ), |
|
1450 | - __FILE__, |
|
1451 | - __FUNCTION__, |
|
1452 | - __LINE__ |
|
1453 | - ); |
|
1454 | - return false; |
|
1455 | - } |
|
1456 | - } |
|
1457 | - return true; |
|
1458 | - } |
|
17 | + /** |
|
18 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
19 | + */ |
|
20 | + public function __construct($routing = true) |
|
21 | + { |
|
22 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
23 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
24 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
25 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
26 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
27 | + parent::__construct($routing); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + protected function _extend_page_config() |
|
35 | + { |
|
36 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
37 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
38 | + ? $this->_req_data['QST_ID'] : 0; |
|
39 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
40 | + ? $this->_req_data['QSG_ID'] : 0; |
|
41 | + |
|
42 | + $new_page_routes = array( |
|
43 | + 'question_groups' => array( |
|
44 | + 'func' => '_question_groups_overview_list_table', |
|
45 | + 'capability' => 'ee_read_question_groups', |
|
46 | + ), |
|
47 | + 'add_question' => array( |
|
48 | + 'func' => '_edit_question', |
|
49 | + 'capability' => 'ee_edit_questions', |
|
50 | + ), |
|
51 | + 'insert_question' => array( |
|
52 | + 'func' => '_insert_or_update_question', |
|
53 | + 'args' => array('new_question' => true), |
|
54 | + 'capability' => 'ee_edit_questions', |
|
55 | + 'noheader' => true, |
|
56 | + ), |
|
57 | + 'duplicate_question' => array( |
|
58 | + 'func' => '_duplicate_question', |
|
59 | + 'capability' => 'ee_edit_questions', |
|
60 | + 'noheader' => true, |
|
61 | + ), |
|
62 | + 'trash_question' => array( |
|
63 | + 'func' => '_trash_question', |
|
64 | + 'capability' => 'ee_delete_question', |
|
65 | + 'obj_id' => $qst_id, |
|
66 | + 'noheader' => true, |
|
67 | + ), |
|
68 | + |
|
69 | + 'restore_question' => array( |
|
70 | + 'func' => '_trash_or_restore_questions', |
|
71 | + 'capability' => 'ee_delete_question', |
|
72 | + 'obj_id' => $qst_id, |
|
73 | + 'args' => array('trash' => false), |
|
74 | + 'noheader' => true, |
|
75 | + ), |
|
76 | + |
|
77 | + 'delete_question' => array( |
|
78 | + 'func' => '_delete_question', |
|
79 | + 'capability' => 'ee_delete_question', |
|
80 | + 'obj_id' => $qst_id, |
|
81 | + 'noheader' => true, |
|
82 | + ), |
|
83 | + |
|
84 | + 'trash_questions' => array( |
|
85 | + 'func' => '_trash_or_restore_questions', |
|
86 | + 'capability' => 'ee_delete_questions', |
|
87 | + 'args' => array('trash' => true), |
|
88 | + 'noheader' => true, |
|
89 | + ), |
|
90 | + |
|
91 | + 'restore_questions' => array( |
|
92 | + 'func' => '_trash_or_restore_questions', |
|
93 | + 'capability' => 'ee_delete_questions', |
|
94 | + 'args' => array('trash' => false), |
|
95 | + 'noheader' => true, |
|
96 | + ), |
|
97 | + |
|
98 | + 'delete_questions' => array( |
|
99 | + 'func' => '_delete_questions', |
|
100 | + 'args' => array(), |
|
101 | + 'capability' => 'ee_delete_questions', |
|
102 | + 'noheader' => true, |
|
103 | + ), |
|
104 | + |
|
105 | + 'add_question_group' => array( |
|
106 | + 'func' => '_edit_question_group', |
|
107 | + 'capability' => 'ee_edit_question_groups', |
|
108 | + ), |
|
109 | + |
|
110 | + 'edit_question_group' => array( |
|
111 | + 'func' => '_edit_question_group', |
|
112 | + 'capability' => 'ee_edit_question_group', |
|
113 | + 'obj_id' => $qsg_id, |
|
114 | + 'args' => array('edit'), |
|
115 | + ), |
|
116 | + |
|
117 | + 'delete_question_groups' => array( |
|
118 | + 'func' => '_delete_question_groups', |
|
119 | + 'capability' => 'ee_delete_question_groups', |
|
120 | + 'noheader' => true, |
|
121 | + ), |
|
122 | + |
|
123 | + 'delete_question_group' => array( |
|
124 | + 'func' => '_delete_question_groups', |
|
125 | + 'capability' => 'ee_delete_question_group', |
|
126 | + 'obj_id' => $qsg_id, |
|
127 | + 'noheader' => true, |
|
128 | + ), |
|
129 | + |
|
130 | + 'trash_question_group' => array( |
|
131 | + 'func' => '_trash_or_restore_question_groups', |
|
132 | + 'args' => array('trash' => true), |
|
133 | + 'capability' => 'ee_delete_question_group', |
|
134 | + 'obj_id' => $qsg_id, |
|
135 | + 'noheader' => true, |
|
136 | + ), |
|
137 | + |
|
138 | + 'restore_question_group' => array( |
|
139 | + 'func' => '_trash_or_restore_question_groups', |
|
140 | + 'args' => array('trash' => false), |
|
141 | + 'capability' => 'ee_delete_question_group', |
|
142 | + 'obj_id' => $qsg_id, |
|
143 | + 'noheader' => true, |
|
144 | + ), |
|
145 | + |
|
146 | + 'insert_question_group' => array( |
|
147 | + 'func' => '_insert_or_update_question_group', |
|
148 | + 'args' => array('new_question_group' => true), |
|
149 | + 'capability' => 'ee_edit_question_groups', |
|
150 | + 'noheader' => true, |
|
151 | + ), |
|
152 | + |
|
153 | + 'update_question_group' => array( |
|
154 | + 'func' => '_insert_or_update_question_group', |
|
155 | + 'args' => array('new_question_group' => false), |
|
156 | + 'capability' => 'ee_edit_question_group', |
|
157 | + 'obj_id' => $qsg_id, |
|
158 | + 'noheader' => true, |
|
159 | + ), |
|
160 | + |
|
161 | + 'trash_question_groups' => array( |
|
162 | + 'func' => '_trash_or_restore_question_groups', |
|
163 | + 'args' => array('trash' => true), |
|
164 | + 'capability' => 'ee_delete_question_groups', |
|
165 | + 'noheader' => array('trash' => false), |
|
166 | + ), |
|
167 | + |
|
168 | + 'restore_question_groups' => array( |
|
169 | + 'func' => '_trash_or_restore_question_groups', |
|
170 | + 'args' => array('trash' => false), |
|
171 | + 'capability' => 'ee_delete_question_groups', |
|
172 | + 'noheader' => true, |
|
173 | + ), |
|
174 | + |
|
175 | + |
|
176 | + 'espresso_update_question_group_order' => array( |
|
177 | + 'func' => 'update_question_group_order', |
|
178 | + 'capability' => 'ee_edit_question_groups', |
|
179 | + 'noheader' => true, |
|
180 | + ), |
|
181 | + |
|
182 | + 'view_reg_form_settings' => array( |
|
183 | + 'func' => '_reg_form_settings', |
|
184 | + 'capability' => 'manage_options', |
|
185 | + ), |
|
186 | + |
|
187 | + 'update_reg_form_settings' => array( |
|
188 | + 'func' => '_update_reg_form_settings', |
|
189 | + 'capability' => 'manage_options', |
|
190 | + 'noheader' => true, |
|
191 | + ), |
|
192 | + ); |
|
193 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
194 | + |
|
195 | + $new_page_config = array( |
|
196 | + |
|
197 | + 'question_groups' => array( |
|
198 | + 'nav' => array( |
|
199 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
200 | + 'order' => 20, |
|
201 | + ), |
|
202 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
203 | + 'help_tabs' => array( |
|
204 | + 'registration_form_question_groups_help_tab' => array( |
|
205 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
206 | + 'filename' => 'registration_form_question_groups', |
|
207 | + ), |
|
208 | + 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
209 | + 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
210 | + 'filename' => 'registration_form_question_groups_table_column_headings', |
|
211 | + ), |
|
212 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
213 | + 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
214 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
215 | + ), |
|
216 | + ), |
|
217 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
218 | + // 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
219 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
220 | + 'require_nonce' => false, |
|
221 | + 'qtips' => array( |
|
222 | + 'EE_Registration_Form_Tips', |
|
223 | + ), |
|
224 | + ), |
|
225 | + |
|
226 | + 'add_question' => array( |
|
227 | + 'nav' => array( |
|
228 | + 'label' => esc_html__('Add Question', 'event_espresso'), |
|
229 | + 'order' => 5, |
|
230 | + 'persistent' => false, |
|
231 | + ), |
|
232 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
233 | + 'help_tabs' => array( |
|
234 | + 'registration_form_add_question_help_tab' => array( |
|
235 | + 'title' => esc_html__('Add Question', 'event_espresso'), |
|
236 | + 'filename' => 'registration_form_add_question', |
|
237 | + ), |
|
238 | + ), |
|
239 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
240 | + // 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
241 | + 'require_nonce' => false, |
|
242 | + ), |
|
243 | + |
|
244 | + 'add_question_group' => array( |
|
245 | + 'nav' => array( |
|
246 | + 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
247 | + 'order' => 5, |
|
248 | + 'persistent' => false, |
|
249 | + ), |
|
250 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
251 | + 'help_tabs' => array( |
|
252 | + 'registration_form_add_question_group_help_tab' => array( |
|
253 | + 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
254 | + 'filename' => 'registration_form_add_question_group', |
|
255 | + ), |
|
256 | + ), |
|
257 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
258 | + // 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
259 | + 'require_nonce' => false, |
|
260 | + ), |
|
261 | + |
|
262 | + 'edit_question_group' => array( |
|
263 | + 'nav' => array( |
|
264 | + 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
265 | + 'order' => 5, |
|
266 | + 'persistent' => false, |
|
267 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
268 | + array('question_group_id' => $this->_req_data['question_group_id']), |
|
269 | + $this->_current_page_view_url |
|
270 | + ) : $this->_admin_base_url, |
|
271 | + ), |
|
272 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
273 | + 'help_tabs' => array( |
|
274 | + 'registration_form_edit_question_group_help_tab' => array( |
|
275 | + 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
276 | + 'filename' => 'registration_form_edit_question_group', |
|
277 | + ), |
|
278 | + ), |
|
279 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
280 | + // 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
281 | + 'require_nonce' => false, |
|
282 | + ), |
|
283 | + |
|
284 | + 'view_reg_form_settings' => array( |
|
285 | + 'nav' => array( |
|
286 | + 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
287 | + 'order' => 40, |
|
288 | + ), |
|
289 | + 'labels' => array( |
|
290 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
291 | + ), |
|
292 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
293 | + 'help_tabs' => array( |
|
294 | + 'registration_form_reg_form_settings_help_tab' => array( |
|
295 | + 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
296 | + 'filename' => 'registration_form_reg_form_settings', |
|
297 | + ), |
|
298 | + ), |
|
299 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
300 | + // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
301 | + 'require_nonce' => false, |
|
302 | + ), |
|
303 | + |
|
304 | + ); |
|
305 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
306 | + |
|
307 | + // change the list table we're going to use so it's the NEW list table! |
|
308 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
309 | + |
|
310 | + |
|
311 | + // additional labels |
|
312 | + $new_labels = array( |
|
313 | + 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
314 | + 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
315 | + 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
316 | + 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
317 | + 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
318 | + ); |
|
319 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @return void |
|
325 | + */ |
|
326 | + protected function _ajax_hooks() |
|
327 | + { |
|
328 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + public function load_scripts_styles_question_groups() |
|
336 | + { |
|
337 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * @return void |
|
343 | + */ |
|
344 | + public function load_scripts_styles_add_question_group() |
|
345 | + { |
|
346 | + $this->load_scripts_styles_forms(); |
|
347 | + $this->load_sortable_question_script(); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * @return void |
|
353 | + */ |
|
354 | + public function load_scripts_styles_edit_question_group() |
|
355 | + { |
|
356 | + $this->load_scripts_styles_forms(); |
|
357 | + $this->load_sortable_question_script(); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * registers and enqueues script for questions |
|
363 | + * |
|
364 | + * @return void |
|
365 | + */ |
|
366 | + public function load_sortable_question_script() |
|
367 | + { |
|
368 | + wp_register_script( |
|
369 | + 'ee-question-sortable', |
|
370 | + REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
371 | + array('jquery-ui-sortable'), |
|
372 | + EVENT_ESPRESSO_VERSION, |
|
373 | + true |
|
374 | + ); |
|
375 | + wp_enqueue_script('ee-question-sortable'); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return void |
|
381 | + */ |
|
382 | + protected function _set_list_table_views_default() |
|
383 | + { |
|
384 | + $this->_views = array( |
|
385 | + 'all' => array( |
|
386 | + 'slug' => 'all', |
|
387 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
388 | + 'count' => 0, |
|
389 | + 'bulk_action' => array( |
|
390 | + 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
391 | + ), |
|
392 | + ), |
|
393 | + ); |
|
394 | + |
|
395 | + if ( |
|
396 | + EE_Registry::instance()->CAP->current_user_can( |
|
397 | + 'ee_delete_questions', |
|
398 | + 'espresso_registration_form_trash_questions' |
|
399 | + ) |
|
400 | + ) { |
|
401 | + $this->_views['trash'] = array( |
|
402 | + 'slug' => 'trash', |
|
403 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
404 | + 'count' => 0, |
|
405 | + 'bulk_action' => array( |
|
406 | + 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
407 | + 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
408 | + ), |
|
409 | + ); |
|
410 | + } |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @return void |
|
416 | + */ |
|
417 | + protected function _set_list_table_views_question_groups() |
|
418 | + { |
|
419 | + $this->_views = array( |
|
420 | + 'all' => array( |
|
421 | + 'slug' => 'all', |
|
422 | + 'label' => esc_html__('All', 'event_espresso'), |
|
423 | + 'count' => 0, |
|
424 | + 'bulk_action' => array( |
|
425 | + 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
426 | + ), |
|
427 | + ), |
|
428 | + ); |
|
429 | + |
|
430 | + if ( |
|
431 | + EE_Registry::instance()->CAP->current_user_can( |
|
432 | + 'ee_delete_question_groups', |
|
433 | + 'espresso_registration_form_trash_question_groups' |
|
434 | + ) |
|
435 | + ) { |
|
436 | + $this->_views['trash'] = array( |
|
437 | + 'slug' => 'trash', |
|
438 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
439 | + 'count' => 0, |
|
440 | + 'bulk_action' => array( |
|
441 | + 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
442 | + 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
443 | + ), |
|
444 | + ); |
|
445 | + } |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * @return void |
|
451 | + * @throws EE_Error |
|
452 | + * @throws InvalidArgumentException |
|
453 | + * @throws InvalidDataTypeException |
|
454 | + * @throws InvalidInterfaceException |
|
455 | + */ |
|
456 | + protected function _questions_overview_list_table() |
|
457 | + { |
|
458 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
459 | + 'add_question', |
|
460 | + 'add_question', |
|
461 | + array(), |
|
462 | + 'add-new-h2' |
|
463 | + ); |
|
464 | + parent::_questions_overview_list_table(); |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @return void |
|
470 | + * @throws DomainException |
|
471 | + * @throws EE_Error |
|
472 | + * @throws InvalidArgumentException |
|
473 | + * @throws InvalidDataTypeException |
|
474 | + * @throws InvalidInterfaceException |
|
475 | + */ |
|
476 | + protected function _question_groups_overview_list_table() |
|
477 | + { |
|
478 | + $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
479 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
480 | + 'add_question_group', |
|
481 | + 'add_question_group', |
|
482 | + array(), |
|
483 | + 'add-new-h2' |
|
484 | + ); |
|
485 | + $this->display_admin_list_table_page_with_sidebar(); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @return void |
|
491 | + * @throws EE_Error |
|
492 | + * @throws InvalidArgumentException |
|
493 | + * @throws InvalidDataTypeException |
|
494 | + * @throws InvalidInterfaceException |
|
495 | + */ |
|
496 | + protected function _delete_question() |
|
497 | + { |
|
498 | + $success = $this->_delete_items($this->_question_model); |
|
499 | + $this->_redirect_after_action( |
|
500 | + $success, |
|
501 | + $this->_question_model->item_name($success), |
|
502 | + 'deleted', |
|
503 | + array('action' => 'default', 'status' => 'all') |
|
504 | + ); |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * @return void |
|
510 | + * @throws EE_Error |
|
511 | + * @throws InvalidArgumentException |
|
512 | + * @throws InvalidDataTypeException |
|
513 | + * @throws InvalidInterfaceException |
|
514 | + */ |
|
515 | + protected function _delete_questions() |
|
516 | + { |
|
517 | + $success = $this->_delete_items($this->_question_model); |
|
518 | + $this->_redirect_after_action( |
|
519 | + $success, |
|
520 | + $this->_question_model->item_name($success), |
|
521 | + 'deleted permanently', |
|
522 | + array('action' => 'default', 'status' => 'trash') |
|
523 | + ); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * Performs the deletion of a single or multiple questions or question groups. |
|
529 | + * |
|
530 | + * @param EEM_Soft_Delete_Base $model |
|
531 | + * @return int number of items deleted permanently |
|
532 | + * @throws EE_Error |
|
533 | + * @throws InvalidArgumentException |
|
534 | + * @throws InvalidDataTypeException |
|
535 | + * @throws InvalidInterfaceException |
|
536 | + */ |
|
537 | + private function _delete_items(EEM_Soft_Delete_Base $model) |
|
538 | + { |
|
539 | + $success = 0; |
|
540 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
541 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
542 | + // if array has more than one element than success message should be plural |
|
543 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
544 | + // cycle thru bulk action checkboxes |
|
545 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
546 | + if (! $this->_delete_item($ID, $model)) { |
|
547 | + $success = 0; |
|
548 | + } |
|
549 | + } |
|
550 | + } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
551 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
552 | + } elseif (! empty($this->_req_data['QST_ID'])) { |
|
553 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
554 | + } else { |
|
555 | + EE_Error::add_error( |
|
556 | + sprintf( |
|
557 | + esc_html__( |
|
558 | + "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
559 | + "event_espresso" |
|
560 | + ) |
|
561 | + ), |
|
562 | + __FILE__, |
|
563 | + __FUNCTION__, |
|
564 | + __LINE__ |
|
565 | + ); |
|
566 | + } |
|
567 | + return $success; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Deletes the specified question (and its associated question options) or question group |
|
573 | + * |
|
574 | + * @param int $id |
|
575 | + * @param EEM_Soft_Delete_Base $model |
|
576 | + * @return boolean |
|
577 | + * @throws EE_Error |
|
578 | + * @throws InvalidArgumentException |
|
579 | + * @throws InvalidDataTypeException |
|
580 | + * @throws InvalidInterfaceException |
|
581 | + */ |
|
582 | + protected function _delete_item($id, $model) |
|
583 | + { |
|
584 | + if ($model instanceof EEM_Question) { |
|
585 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
586 | + } |
|
587 | + return $model->delete_permanently_by_ID(absint($id)); |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + /****************************** QUESTION GROUPS ******************************/ |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * @param string $type |
|
596 | + * @return void |
|
597 | + * @throws DomainException |
|
598 | + * @throws EE_Error |
|
599 | + * @throws InvalidArgumentException |
|
600 | + * @throws InvalidDataTypeException |
|
601 | + * @throws InvalidInterfaceException |
|
602 | + */ |
|
603 | + protected function _edit_question_group($type = 'add') |
|
604 | + { |
|
605 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
606 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
607 | + ? absint($this->_req_data['QSG_ID']) |
|
608 | + : false; |
|
609 | + |
|
610 | + switch ($this->_req_action) { |
|
611 | + case 'add_question_group': |
|
612 | + $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
613 | + break; |
|
614 | + case 'edit_question_group': |
|
615 | + $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
616 | + break; |
|
617 | + default: |
|
618 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
619 | + } |
|
620 | + // add ID to title if editing |
|
621 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
622 | + if ($ID) { |
|
623 | + /** @var EE_Question_Group $questionGroup */ |
|
624 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
625 | + $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
626 | + $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
627 | + } else { |
|
628 | + /** @var EE_Question_Group $questionGroup */ |
|
629 | + $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
630 | + $questionGroup->set_order_to_latest(); |
|
631 | + $this->_set_add_edit_form_tags('insert_question_group'); |
|
632 | + } |
|
633 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
634 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
635 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
636 | + $this->_template_args['question_group'] = $questionGroup; |
|
637 | + |
|
638 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
639 | + $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
640 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
641 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
642 | + $this->_template_args, |
|
643 | + true |
|
644 | + ); |
|
645 | + |
|
646 | + // the details template wrapper |
|
647 | + $this->display_admin_page_with_sidebar(); |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * @return void |
|
653 | + * @throws EE_Error |
|
654 | + * @throws InvalidArgumentException |
|
655 | + * @throws InvalidDataTypeException |
|
656 | + * @throws InvalidInterfaceException |
|
657 | + */ |
|
658 | + protected function _delete_question_groups() |
|
659 | + { |
|
660 | + $success = $this->_delete_items($this->_question_group_model); |
|
661 | + $this->_redirect_after_action( |
|
662 | + $success, |
|
663 | + $this->_question_group_model->item_name($success), |
|
664 | + 'deleted permanently', |
|
665 | + array('action' => 'question_groups', 'status' => 'trash') |
|
666 | + ); |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * @param bool $new_question_group |
|
672 | + * @throws EE_Error |
|
673 | + * @throws InvalidArgumentException |
|
674 | + * @throws InvalidDataTypeException |
|
675 | + * @throws InvalidInterfaceException |
|
676 | + */ |
|
677 | + protected function _insert_or_update_question_group($new_question_group = true) |
|
678 | + { |
|
679 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
680 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
681 | + if ($new_question_group) { |
|
682 | + // make sure identifier is unique |
|
683 | + $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
684 | + $identifier_exists = ! empty($identifier_value) |
|
685 | + ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0 |
|
686 | + : false; |
|
687 | + if ($identifier_exists) { |
|
688 | + $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
689 | + } |
|
690 | + $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
691 | + $success = $QSG_ID ? 1 : 0; |
|
692 | + if ($success === 0) { |
|
693 | + EE_Error::add_error( |
|
694 | + esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
695 | + __FILE__, |
|
696 | + __FUNCTION__, |
|
697 | + __LINE__ |
|
698 | + ); |
|
699 | + $this->_redirect_after_action( |
|
700 | + false, |
|
701 | + '', |
|
702 | + '', |
|
703 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
704 | + true |
|
705 | + ); |
|
706 | + } |
|
707 | + } else { |
|
708 | + $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
709 | + unset($set_column_values['QSG_ID']); |
|
710 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
711 | + } |
|
712 | + |
|
713 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
714 | + EEM_Attendee::system_question_phone |
|
715 | + ); |
|
716 | + // update the existing related questions |
|
717 | + // BUT FIRST... delete the phone question from the Question_Group_Question |
|
718 | + // if it is being added to this question group (therefore removed from the existing group) |
|
719 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
720 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
721 | + EEM_Question_Group_Question::instance()->delete( |
|
722 | + array( |
|
723 | + array( |
|
724 | + 'QST_ID' => $phone_question_id, |
|
725 | + 'QSG_ID' => array('!=', $QSG_ID), |
|
726 | + ), |
|
727 | + ) |
|
728 | + ); |
|
729 | + } |
|
730 | + /** @type EE_Question_Group $question_group */ |
|
731 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
732 | + $questions = $question_group->questions(); |
|
733 | + // make sure system phone question is added to list of questions for this group |
|
734 | + if (! isset($questions[ $phone_question_id ])) { |
|
735 | + $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
736 | + } |
|
737 | + |
|
738 | + foreach ($questions as $question_ID => $question) { |
|
739 | + // first we always check for order. |
|
740 | + if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
741 | + // update question order |
|
742 | + $question_group->update_question_order( |
|
743 | + $question_ID, |
|
744 | + $this->_req_data['question_orders'][ $question_ID ] |
|
745 | + ); |
|
746 | + } |
|
747 | + |
|
748 | + // then we always check if adding or removing. |
|
749 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
750 | + $question_group->add_question($question_ID); |
|
751 | + } else { |
|
752 | + // not found, remove it (but only if not a system question for the personal group |
|
753 | + // with the exception of lname system question - we allow removal of it) |
|
754 | + if ( |
|
755 | + in_array( |
|
756 | + $question->system_ID(), |
|
757 | + EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
758 | + $question_group->system_group() |
|
759 | + ) |
|
760 | + ) |
|
761 | + ) { |
|
762 | + continue; |
|
763 | + } else { |
|
764 | + $question_group->remove_question($question_ID); |
|
765 | + } |
|
766 | + } |
|
767 | + } |
|
768 | + // save new related questions |
|
769 | + if (isset($this->_req_data['questions'])) { |
|
770 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
771 | + $question_group->add_question($QST_ID); |
|
772 | + if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
773 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
774 | + } |
|
775 | + } |
|
776 | + } |
|
777 | + |
|
778 | + if ($success !== false) { |
|
779 | + $msg = $new_question_group |
|
780 | + ? sprintf( |
|
781 | + esc_html__('The %s has been created', 'event_espresso'), |
|
782 | + $this->_question_group_model->item_name() |
|
783 | + ) |
|
784 | + : sprintf( |
|
785 | + esc_html__( |
|
786 | + 'The %s has been updated', |
|
787 | + 'event_espresso' |
|
788 | + ), |
|
789 | + $this->_question_group_model->item_name() |
|
790 | + ); |
|
791 | + EE_Error::add_success($msg); |
|
792 | + } |
|
793 | + $this->_redirect_after_action( |
|
794 | + false, |
|
795 | + '', |
|
796 | + '', |
|
797 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
798 | + true |
|
799 | + ); |
|
800 | + } |
|
801 | + |
|
802 | + |
|
803 | + /** |
|
804 | + * duplicates a question and all its question options and redirects to the new question. |
|
805 | + * |
|
806 | + * @return void |
|
807 | + * @throws EE_Error |
|
808 | + * @throws InvalidArgumentException |
|
809 | + * @throws ReflectionException |
|
810 | + * @throws InvalidDataTypeException |
|
811 | + * @throws InvalidInterfaceException |
|
812 | + */ |
|
813 | + public function _duplicate_question() |
|
814 | + { |
|
815 | + $question_ID = (int) $this->_req_data['QST_ID']; |
|
816 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
817 | + if ($question instanceof EE_Question) { |
|
818 | + $new_question = $question->duplicate(); |
|
819 | + if ($new_question instanceof EE_Question) { |
|
820 | + $this->_redirect_after_action( |
|
821 | + true, |
|
822 | + esc_html__('Question', 'event_espresso'), |
|
823 | + esc_html__('Duplicated', 'event_espresso'), |
|
824 | + array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
825 | + true |
|
826 | + ); |
|
827 | + } else { |
|
828 | + global $wpdb; |
|
829 | + EE_Error::add_error( |
|
830 | + sprintf( |
|
831 | + esc_html__( |
|
832 | + 'Could not duplicate question with ID %1$d because: %2$s', |
|
833 | + 'event_espresso' |
|
834 | + ), |
|
835 | + $question_ID, |
|
836 | + $wpdb->last_error |
|
837 | + ), |
|
838 | + __FILE__, |
|
839 | + __FUNCTION__, |
|
840 | + __LINE__ |
|
841 | + ); |
|
842 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
843 | + } |
|
844 | + } else { |
|
845 | + EE_Error::add_error( |
|
846 | + sprintf( |
|
847 | + esc_html__( |
|
848 | + 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
849 | + 'event_espresso' |
|
850 | + ), |
|
851 | + $question_ID |
|
852 | + ), |
|
853 | + __FILE__, |
|
854 | + __FUNCTION__, |
|
855 | + __LINE__ |
|
856 | + ); |
|
857 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
858 | + } |
|
859 | + } |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * @param bool $trash |
|
864 | + * @throws EE_Error |
|
865 | + */ |
|
866 | + protected function _trash_or_restore_question_groups($trash = true) |
|
867 | + { |
|
868 | + $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
869 | + } |
|
870 | + |
|
871 | + |
|
872 | + /** |
|
873 | + *_trash_question |
|
874 | + * |
|
875 | + * @return void |
|
876 | + * @throws EE_Error |
|
877 | + */ |
|
878 | + protected function _trash_question() |
|
879 | + { |
|
880 | + $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
881 | + $query_args = array('action' => 'default', 'status' => 'all'); |
|
882 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + /** |
|
887 | + * @param bool $trash |
|
888 | + * @throws EE_Error |
|
889 | + */ |
|
890 | + protected function _trash_or_restore_questions($trash = true) |
|
891 | + { |
|
892 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
893 | + } |
|
894 | + |
|
895 | + |
|
896 | + /** |
|
897 | + * Internally used to delete or restore items, using the request data. Meant to be |
|
898 | + * flexible between question or question groups |
|
899 | + * |
|
900 | + * @param EEM_Soft_Delete_Base $model |
|
901 | + * @param boolean $trash whether to trash or restore |
|
902 | + * @throws EE_Error |
|
903 | + */ |
|
904 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
905 | + { |
|
906 | + |
|
907 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
908 | + |
|
909 | + $success = 1; |
|
910 | + // Checkboxes |
|
911 | + // echo "trash $trash"; |
|
912 | + // var_dump($this->_req_data['checkbox']);die; |
|
913 | + if (isset($this->_req_data['checkbox'])) { |
|
914 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
915 | + // if array has more than one element than success message should be plural |
|
916 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
917 | + // cycle thru bulk action checkboxes |
|
918 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
919 | + if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
920 | + $success = 0; |
|
921 | + } |
|
922 | + } |
|
923 | + } else { |
|
924 | + // grab single id and delete |
|
925 | + $ID = absint($this->_req_data['checkbox']); |
|
926 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
927 | + $success = 0; |
|
928 | + } |
|
929 | + } |
|
930 | + } else { |
|
931 | + // delete via trash link |
|
932 | + // grab single id and delete |
|
933 | + $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
934 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
935 | + $success = 0; |
|
936 | + } |
|
937 | + } |
|
938 | + |
|
939 | + |
|
940 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
941 | + // echo "action :$action"; |
|
942 | + // $action = 'questions' ? 'default' : $action; |
|
943 | + if ($trash) { |
|
944 | + $action_desc = 'trashed'; |
|
945 | + $status = 'trash'; |
|
946 | + } else { |
|
947 | + $action_desc = 'restored'; |
|
948 | + $status = 'all'; |
|
949 | + } |
|
950 | + $this->_redirect_after_action( |
|
951 | + $success, |
|
952 | + $model->item_name($success), |
|
953 | + $action_desc, |
|
954 | + array('action' => $action, 'status' => $status) |
|
955 | + ); |
|
956 | + } |
|
957 | + |
|
958 | + |
|
959 | + /** |
|
960 | + * @param $per_page |
|
961 | + * @param int $current_page |
|
962 | + * @param bool|false $count |
|
963 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
964 | + * @throws EE_Error |
|
965 | + * @throws InvalidArgumentException |
|
966 | + * @throws InvalidDataTypeException |
|
967 | + * @throws InvalidInterfaceException |
|
968 | + */ |
|
969 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
970 | + { |
|
971 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
972 | + |
|
973 | + if ($count) { |
|
974 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
975 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
976 | + $results = $this->_question_model->count_deleted($where); |
|
977 | + } else { |
|
978 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
979 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
980 | + } |
|
981 | + return $results; |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * @param $per_page |
|
987 | + * @param int $current_page |
|
988 | + * @param bool|false $count |
|
989 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
990 | + * @throws EE_Error |
|
991 | + * @throws InvalidArgumentException |
|
992 | + * @throws InvalidDataTypeException |
|
993 | + * @throws InvalidInterfaceException |
|
994 | + */ |
|
995 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
996 | + { |
|
997 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
998 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
999 | + if ($count) { |
|
1000 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
1001 | + $results = $questionGroupModel->count($where); |
|
1002 | + } else { |
|
1003 | + $results = $questionGroupModel->get_all($query_params); |
|
1004 | + } |
|
1005 | + return $results; |
|
1006 | + } |
|
1007 | + |
|
1008 | + |
|
1009 | + /** |
|
1010 | + * @param $per_page |
|
1011 | + * @param int $current_page |
|
1012 | + * @param bool $count |
|
1013 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
1014 | + * @throws EE_Error |
|
1015 | + * @throws InvalidArgumentException |
|
1016 | + * @throws InvalidDataTypeException |
|
1017 | + * @throws InvalidInterfaceException |
|
1018 | + */ |
|
1019 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
1020 | + { |
|
1021 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
1022 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
1023 | + if ($count) { |
|
1024 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
1025 | + $query_params['limit'] = null; |
|
1026 | + $results = $questionGroupModel->count_deleted($where); |
|
1027 | + } else { |
|
1028 | + $results = $questionGroupModel->get_all_deleted($query_params); |
|
1029 | + } |
|
1030 | + return $results; |
|
1031 | + } |
|
1032 | + |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * method for performing updates to question order |
|
1036 | + * |
|
1037 | + * @return void results array |
|
1038 | + * @throws EE_Error |
|
1039 | + * @throws InvalidArgumentException |
|
1040 | + * @throws InvalidDataTypeException |
|
1041 | + * @throws InvalidInterfaceException |
|
1042 | + */ |
|
1043 | + public function update_question_group_order() |
|
1044 | + { |
|
1045 | + |
|
1046 | + $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
1047 | + |
|
1048 | + // grab our row IDs |
|
1049 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
1050 | + ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
1051 | + : array(); |
|
1052 | + |
|
1053 | + $perpage = ! empty($this->_req_data['perpage']) |
|
1054 | + ? (int) $this->_req_data['perpage'] |
|
1055 | + : null; |
|
1056 | + $curpage = ! empty($this->_req_data['curpage']) |
|
1057 | + ? (int) $this->_req_data['curpage'] |
|
1058 | + : null; |
|
1059 | + |
|
1060 | + if (! empty($row_ids)) { |
|
1061 | + // figure out where we start the row_id count at for the current page. |
|
1062 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
1063 | + |
|
1064 | + $row_count = count($row_ids); |
|
1065 | + for ($i = 0; $i < $row_count; $i++) { |
|
1066 | + // Update the questions when re-ordering |
|
1067 | + $updated = EEM_Question_Group::instance()->update( |
|
1068 | + array('QSG_order' => $qsgcount), |
|
1069 | + array(array('QSG_ID' => $row_ids[ $i ])) |
|
1070 | + ); |
|
1071 | + if ($updated === false) { |
|
1072 | + $success = false; |
|
1073 | + } |
|
1074 | + $qsgcount++; |
|
1075 | + } |
|
1076 | + } else { |
|
1077 | + $success = false; |
|
1078 | + } |
|
1079 | + |
|
1080 | + $errors = ! $success |
|
1081 | + ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
1082 | + : false; |
|
1083 | + |
|
1084 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
1085 | + die(); |
|
1086 | + } |
|
1087 | + |
|
1088 | + |
|
1089 | + |
|
1090 | + /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
1091 | + |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * @throws DomainException |
|
1095 | + * @throws EE_Error |
|
1096 | + * @throws InvalidArgumentException |
|
1097 | + * @throws InvalidDataTypeException |
|
1098 | + * @throws InvalidInterfaceException |
|
1099 | + */ |
|
1100 | + protected function _reg_form_settings() |
|
1101 | + { |
|
1102 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
1103 | + add_action( |
|
1104 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
1105 | + array($this, 'email_validation_settings_form'), |
|
1106 | + 2 |
|
1107 | + ); |
|
1108 | + add_action( |
|
1109 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
1110 | + array($this, 'copy_attendee_info_settings_form'), |
|
1111 | + 4 |
|
1112 | + ); |
|
1113 | + $this->_template_args = (array) apply_filters( |
|
1114 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
1115 | + $this->_template_args |
|
1116 | + ); |
|
1117 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
1118 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1119 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1120 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
1121 | + $this->_template_args, |
|
1122 | + true |
|
1123 | + ); |
|
1124 | + $this->display_admin_page_with_sidebar(); |
|
1125 | + } |
|
1126 | + |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * @return void |
|
1130 | + * @throws EE_Error |
|
1131 | + * @throws InvalidArgumentException |
|
1132 | + * @throws ReflectionException |
|
1133 | + * @throws InvalidDataTypeException |
|
1134 | + * @throws InvalidInterfaceException |
|
1135 | + */ |
|
1136 | + protected function _update_reg_form_settings() |
|
1137 | + { |
|
1138 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
1139 | + EE_Registry::instance()->CFG->registration |
|
1140 | + ); |
|
1141 | + EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form( |
|
1142 | + EE_Registry::instance()->CFG->registration |
|
1143 | + ); |
|
1144 | + EE_Registry::instance()->CFG->registration = apply_filters( |
|
1145 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
1146 | + EE_Registry::instance()->CFG->registration |
|
1147 | + ); |
|
1148 | + $success = $this->_update_espresso_configuration( |
|
1149 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
1150 | + EE_Registry::instance()->CFG, |
|
1151 | + __FILE__, |
|
1152 | + __FUNCTION__, |
|
1153 | + __LINE__ |
|
1154 | + ); |
|
1155 | + $this->_redirect_after_action( |
|
1156 | + $success, |
|
1157 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
1158 | + 'updated', |
|
1159 | + array('action' => 'view_reg_form_settings') |
|
1160 | + ); |
|
1161 | + } |
|
1162 | + |
|
1163 | + |
|
1164 | + /** |
|
1165 | + * @return void |
|
1166 | + * @throws EE_Error |
|
1167 | + * @throws InvalidArgumentException |
|
1168 | + * @throws InvalidDataTypeException |
|
1169 | + * @throws InvalidInterfaceException |
|
1170 | + */ |
|
1171 | + public function copy_attendee_info_settings_form() |
|
1172 | + { |
|
1173 | + echo $this->_copy_attendee_info_settings_form()->get_html(); |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * _copy_attendee_info_settings_form |
|
1178 | + * |
|
1179 | + * @access protected |
|
1180 | + * @return EE_Form_Section_Proper |
|
1181 | + * @throws \EE_Error |
|
1182 | + */ |
|
1183 | + protected function _copy_attendee_info_settings_form() |
|
1184 | + { |
|
1185 | + return new EE_Form_Section_Proper( |
|
1186 | + array( |
|
1187 | + 'name' => 'copy_attendee_info_settings', |
|
1188 | + 'html_id' => 'copy_attendee_info_settings', |
|
1189 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1190 | + 'subsections' => apply_filters( |
|
1191 | + 'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections', |
|
1192 | + array( |
|
1193 | + 'copy_attendee_info_hdr' => new EE_Form_Section_HTML( |
|
1194 | + EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso')) |
|
1195 | + ), |
|
1196 | + 'copy_attendee_info' => new EE_Yes_No_Input( |
|
1197 | + array( |
|
1198 | + 'html_label_text' => esc_html__( |
|
1199 | + 'Allow copy #1 attendee info to extra attendees?', |
|
1200 | + 'event_espresso' |
|
1201 | + ), |
|
1202 | + 'html_help_text' => esc_html__( |
|
1203 | + 'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.', |
|
1204 | + 'event_espresso' |
|
1205 | + ), |
|
1206 | + 'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(), |
|
1207 | + 'required' => false, |
|
1208 | + 'display_html_label_text' => false, |
|
1209 | + ) |
|
1210 | + ), |
|
1211 | + ) |
|
1212 | + ), |
|
1213 | + ) |
|
1214 | + ); |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * @param EE_Registration_Config $EE_Registration_Config |
|
1219 | + * @return EE_Registration_Config |
|
1220 | + * @throws EE_Error |
|
1221 | + * @throws InvalidArgumentException |
|
1222 | + * @throws ReflectionException |
|
1223 | + * @throws InvalidDataTypeException |
|
1224 | + * @throws InvalidInterfaceException |
|
1225 | + */ |
|
1226 | + public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1227 | + { |
|
1228 | + $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo(); |
|
1229 | + try { |
|
1230 | + $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form(); |
|
1231 | + // if not displaying a form, then check for form submission |
|
1232 | + if ($copy_attendee_info_settings_form->was_submitted()) { |
|
1233 | + // capture form data |
|
1234 | + $copy_attendee_info_settings_form->receive_form_submission(); |
|
1235 | + // validate form data |
|
1236 | + if ($copy_attendee_info_settings_form->is_valid()) { |
|
1237 | + // grab validated data from form |
|
1238 | + $valid_data = $copy_attendee_info_settings_form->valid_data(); |
|
1239 | + if (isset($valid_data['copy_attendee_info'])) { |
|
1240 | + $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']); |
|
1241 | + } else { |
|
1242 | + EE_Error::add_error( |
|
1243 | + esc_html__( |
|
1244 | + 'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.', |
|
1245 | + 'event_espresso' |
|
1246 | + ), |
|
1247 | + __FILE__, |
|
1248 | + __FUNCTION__, |
|
1249 | + __LINE__ |
|
1250 | + ); |
|
1251 | + } |
|
1252 | + } else { |
|
1253 | + if ($copy_attendee_info_settings_form->submission_error_message() !== '') { |
|
1254 | + EE_Error::add_error( |
|
1255 | + $copy_attendee_info_settings_form->submission_error_message(), |
|
1256 | + __FILE__, |
|
1257 | + __FUNCTION__, |
|
1258 | + __LINE__ |
|
1259 | + ); |
|
1260 | + } |
|
1261 | + } |
|
1262 | + } |
|
1263 | + } catch (EE_Error $e) { |
|
1264 | + $e->get_error(); |
|
1265 | + } |
|
1266 | + return $EE_Registration_Config; |
|
1267 | + } |
|
1268 | + |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * @return void |
|
1272 | + * @throws EE_Error |
|
1273 | + * @throws InvalidArgumentException |
|
1274 | + * @throws InvalidDataTypeException |
|
1275 | + * @throws InvalidInterfaceException |
|
1276 | + */ |
|
1277 | + public function email_validation_settings_form() |
|
1278 | + { |
|
1279 | + echo $this->_email_validation_settings_form()->get_html(); |
|
1280 | + } |
|
1281 | + |
|
1282 | + |
|
1283 | + /** |
|
1284 | + * _email_validation_settings_form |
|
1285 | + * |
|
1286 | + * @access protected |
|
1287 | + * @return EE_Form_Section_Proper |
|
1288 | + * @throws \EE_Error |
|
1289 | + */ |
|
1290 | + protected function _email_validation_settings_form() |
|
1291 | + { |
|
1292 | + return new EE_Form_Section_Proper( |
|
1293 | + array( |
|
1294 | + 'name' => 'email_validation_settings', |
|
1295 | + 'html_id' => 'email_validation_settings', |
|
1296 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1297 | + 'subsections' => apply_filters( |
|
1298 | + 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
1299 | + array( |
|
1300 | + 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
1301 | + EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
1302 | + ), |
|
1303 | + 'email_validation_level' => new EE_Select_Input( |
|
1304 | + array( |
|
1305 | + 'basic' => esc_html__('Basic', 'event_espresso'), |
|
1306 | + 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
1307 | + 'i18n' => esc_html__('International', 'event_espresso'), |
|
1308 | + 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
1309 | + ), |
|
1310 | + array( |
|
1311 | + 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
1312 | + . EEH_Template::get_help_tab_link('email_validation_info'), |
|
1313 | + 'html_help_text' => esc_html__( |
|
1314 | + 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
1315 | + 'event_espresso' |
|
1316 | + ), |
|
1317 | + 'default' => isset( |
|
1318 | + EE_Registry::instance()->CFG->registration->email_validation_level |
|
1319 | + ) |
|
1320 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
1321 | + : 'wp_default', |
|
1322 | + 'required' => false, |
|
1323 | + ) |
|
1324 | + ), |
|
1325 | + ) |
|
1326 | + ), |
|
1327 | + ) |
|
1328 | + ); |
|
1329 | + } |
|
1330 | + |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * @param EE_Registration_Config $EE_Registration_Config |
|
1334 | + * @return EE_Registration_Config |
|
1335 | + * @throws EE_Error |
|
1336 | + * @throws InvalidArgumentException |
|
1337 | + * @throws ReflectionException |
|
1338 | + * @throws InvalidDataTypeException |
|
1339 | + * @throws InvalidInterfaceException |
|
1340 | + */ |
|
1341 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1342 | + { |
|
1343 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
1344 | + try { |
|
1345 | + $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
1346 | + // if not displaying a form, then check for form submission |
|
1347 | + if ($email_validation_settings_form->was_submitted()) { |
|
1348 | + // capture form data |
|
1349 | + $email_validation_settings_form->receive_form_submission(); |
|
1350 | + // validate form data |
|
1351 | + if ($email_validation_settings_form->is_valid()) { |
|
1352 | + // grab validated data from form |
|
1353 | + $valid_data = $email_validation_settings_form->valid_data(); |
|
1354 | + if (isset($valid_data['email_validation_level'])) { |
|
1355 | + $email_validation_level = $valid_data['email_validation_level']; |
|
1356 | + // now if they want to use international email addresses |
|
1357 | + if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
1358 | + // in case we need to reset their email validation level, |
|
1359 | + // make sure that the previous value wasn't already set to one of the i18n options. |
|
1360 | + if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
1361 | + // if so, then reset it back to "basic" since that is the only other option that, |
|
1362 | + // despite offering poor validation, supports i18n email addresses |
|
1363 | + $prev_email_validation_level = 'basic'; |
|
1364 | + } |
|
1365 | + // confirm our i18n email validation will work on the server |
|
1366 | + if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1367 | + // or reset email validation level to previous value |
|
1368 | + $email_validation_level = $prev_email_validation_level; |
|
1369 | + } |
|
1370 | + } |
|
1371 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1372 | + } else { |
|
1373 | + EE_Error::add_error( |
|
1374 | + esc_html__( |
|
1375 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
1376 | + 'event_espresso' |
|
1377 | + ), |
|
1378 | + __FILE__, |
|
1379 | + __FUNCTION__, |
|
1380 | + __LINE__ |
|
1381 | + ); |
|
1382 | + } |
|
1383 | + } else { |
|
1384 | + if ($email_validation_settings_form->submission_error_message() !== '') { |
|
1385 | + EE_Error::add_error( |
|
1386 | + $email_validation_settings_form->submission_error_message(), |
|
1387 | + __FILE__, |
|
1388 | + __FUNCTION__, |
|
1389 | + __LINE__ |
|
1390 | + ); |
|
1391 | + } |
|
1392 | + } |
|
1393 | + } |
|
1394 | + } catch (EE_Error $e) { |
|
1395 | + $e->get_error(); |
|
1396 | + } |
|
1397 | + return $EE_Registration_Config; |
|
1398 | + } |
|
1399 | + |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * confirms that the server's PHP version has the PCRE module enabled, |
|
1403 | + * and that the PCRE version works with our i18n email validation |
|
1404 | + * |
|
1405 | + * @param EE_Registration_Config $EE_Registration_Config |
|
1406 | + * @param string $email_validation_level |
|
1407 | + * @return bool |
|
1408 | + */ |
|
1409 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
1410 | + { |
|
1411 | + // first check that PCRE is enabled |
|
1412 | + if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1413 | + EE_Error::add_error( |
|
1414 | + sprintf( |
|
1415 | + esc_html__( |
|
1416 | + 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
1417 | + 'event_espresso' |
|
1418 | + ), |
|
1419 | + '<br />' |
|
1420 | + ), |
|
1421 | + __FILE__, |
|
1422 | + __FUNCTION__, |
|
1423 | + __LINE__ |
|
1424 | + ); |
|
1425 | + return false; |
|
1426 | + } else { |
|
1427 | + // PCRE support is enabled, but let's still |
|
1428 | + // perform a test to see if the server will support it. |
|
1429 | + // but first, save the updated validation level to the config, |
|
1430 | + // so that the validation strategy picks it up. |
|
1431 | + // this will get bumped back down if it doesn't work |
|
1432 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1433 | + try { |
|
1434 | + $email_validator = new EE_Email_Validation_Strategy(); |
|
1435 | + $i18n_email_address = apply_filters( |
|
1436 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
1437 | + 'jägerjü[email protected]' |
|
1438 | + ); |
|
1439 | + $email_validator->validate($i18n_email_address); |
|
1440 | + } catch (Exception $e) { |
|
1441 | + EE_Error::add_error( |
|
1442 | + sprintf( |
|
1443 | + esc_html__( |
|
1444 | + 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
1445 | + 'event_espresso' |
|
1446 | + ), |
|
1447 | + '<br />', |
|
1448 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>' |
|
1449 | + ), |
|
1450 | + __FILE__, |
|
1451 | + __FUNCTION__, |
|
1452 | + __LINE__ |
|
1453 | + ); |
|
1454 | + return false; |
|
1455 | + } |
|
1456 | + } |
|
1457 | + return true; |
|
1458 | + } |
|
1459 | 1459 | } |
@@ -6,22 +6,22 @@ discard block |
||
6 | 6 | */ |
7 | 7 | function espresso_load_error_handling() |
8 | 8 | { |
9 | - static $error_handling_loaded = false; |
|
10 | - if ($error_handling_loaded) { |
|
11 | - return; |
|
12 | - } |
|
13 | - // load debugging tools |
|
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | - \EEH_Debug_Tools::instance(); |
|
17 | - } |
|
18 | - // load error handling |
|
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | - } else { |
|
22 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | - } |
|
24 | - $error_handling_loaded = true; |
|
9 | + static $error_handling_loaded = false; |
|
10 | + if ($error_handling_loaded) { |
|
11 | + return; |
|
12 | + } |
|
13 | + // load debugging tools |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | + \EEH_Debug_Tools::instance(); |
|
17 | + } |
|
18 | + // load error handling |
|
19 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | + } else { |
|
22 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | + } |
|
24 | + $error_handling_loaded = true; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function espresso_load_required($classname, $full_path_to_file) |
37 | 37 | { |
38 | - if (is_readable($full_path_to_file)) { |
|
39 | - require_once $full_path_to_file; |
|
40 | - } else { |
|
41 | - throw new \EE_Error( |
|
42 | - sprintf( |
|
43 | - esc_html__( |
|
44 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - $classname |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
38 | + if (is_readable($full_path_to_file)) { |
|
39 | + require_once $full_path_to_file; |
|
40 | + } else { |
|
41 | + throw new \EE_Error( |
|
42 | + sprintf( |
|
43 | + esc_html__( |
|
44 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + $classname |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | |
@@ -66,52 +66,52 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | - try { |
|
71 | - espresso_load_error_handling(); |
|
72 | - // include WordPress shims for functions introduced in later versions of WordPress |
|
73 | - espresso_load_required( |
|
74 | - '', |
|
75 | - EE_CORE . 'wordpress-shims.php' |
|
76 | - ); |
|
77 | - espresso_load_required( |
|
78 | - '', |
|
79 | - EE_CORE . 'third-party-compatibility.php' |
|
80 | - ); |
|
81 | - espresso_load_required( |
|
82 | - 'EEH_Base', |
|
83 | - EE_CORE . 'helpers/EEH_Base.helper.php' |
|
84 | - ); |
|
85 | - espresso_load_required( |
|
86 | - 'EEH_File', |
|
87 | - EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
88 | - ); |
|
89 | - espresso_load_required( |
|
90 | - 'EEH_File', |
|
91 | - EE_CORE . 'helpers/EEH_File.helper.php' |
|
92 | - ); |
|
93 | - espresso_load_required( |
|
94 | - 'EEH_Array', |
|
95 | - EE_CORE . 'helpers/EEH_Array.helper.php' |
|
96 | - ); |
|
97 | - espresso_load_required( |
|
98 | - 'EE_Base', |
|
99 | - EE_CORE . 'EE_Base.core.php' |
|
100 | - ); |
|
101 | - // instantiate and configure PSR4 autoloader |
|
102 | - espresso_load_required( |
|
103 | - 'Psr4Autoloader', |
|
104 | - EE_CORE . 'Psr4Autoloader.php' |
|
105 | - ); |
|
106 | - espresso_load_required( |
|
107 | - 'EE_Psr4AutoloaderInit', |
|
108 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
109 | - ); |
|
110 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
111 | - $AutoloaderInit->initializeAutoloader(); |
|
112 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
113 | - } catch (Exception $e) { |
|
114 | - require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
115 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
116 | - } |
|
69 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | + try { |
|
71 | + espresso_load_error_handling(); |
|
72 | + // include WordPress shims for functions introduced in later versions of WordPress |
|
73 | + espresso_load_required( |
|
74 | + '', |
|
75 | + EE_CORE . 'wordpress-shims.php' |
|
76 | + ); |
|
77 | + espresso_load_required( |
|
78 | + '', |
|
79 | + EE_CORE . 'third-party-compatibility.php' |
|
80 | + ); |
|
81 | + espresso_load_required( |
|
82 | + 'EEH_Base', |
|
83 | + EE_CORE . 'helpers/EEH_Base.helper.php' |
|
84 | + ); |
|
85 | + espresso_load_required( |
|
86 | + 'EEH_File', |
|
87 | + EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
88 | + ); |
|
89 | + espresso_load_required( |
|
90 | + 'EEH_File', |
|
91 | + EE_CORE . 'helpers/EEH_File.helper.php' |
|
92 | + ); |
|
93 | + espresso_load_required( |
|
94 | + 'EEH_Array', |
|
95 | + EE_CORE . 'helpers/EEH_Array.helper.php' |
|
96 | + ); |
|
97 | + espresso_load_required( |
|
98 | + 'EE_Base', |
|
99 | + EE_CORE . 'EE_Base.core.php' |
|
100 | + ); |
|
101 | + // instantiate and configure PSR4 autoloader |
|
102 | + espresso_load_required( |
|
103 | + 'Psr4Autoloader', |
|
104 | + EE_CORE . 'Psr4Autoloader.php' |
|
105 | + ); |
|
106 | + espresso_load_required( |
|
107 | + 'EE_Psr4AutoloaderInit', |
|
108 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
109 | + ); |
|
110 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
111 | + $AutoloaderInit->initializeAutoloader(); |
|
112 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
113 | + } catch (Exception $e) { |
|
114 | + require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
115 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
116 | + } |
|
117 | 117 | } |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | return; |
12 | 12 | } |
13 | 13 | // load debugging tools |
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
16 | 16 | \EEH_Debug_Tools::instance(); |
17 | 17 | } |
18 | 18 | // load error handling |
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
19 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE.'EE_Error.core.php'; |
|
21 | 21 | } else { |
22 | 22 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
23 | 23 | } |
@@ -66,52 +66,52 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
69 | + require_once __DIR__.'/espresso_definitions.php'; |
|
70 | 70 | try { |
71 | 71 | espresso_load_error_handling(); |
72 | 72 | // include WordPress shims for functions introduced in later versions of WordPress |
73 | 73 | espresso_load_required( |
74 | 74 | '', |
75 | - EE_CORE . 'wordpress-shims.php' |
|
75 | + EE_CORE.'wordpress-shims.php' |
|
76 | 76 | ); |
77 | 77 | espresso_load_required( |
78 | 78 | '', |
79 | - EE_CORE . 'third-party-compatibility.php' |
|
79 | + EE_CORE.'third-party-compatibility.php' |
|
80 | 80 | ); |
81 | 81 | espresso_load_required( |
82 | 82 | 'EEH_Base', |
83 | - EE_CORE . 'helpers/EEH_Base.helper.php' |
|
83 | + EE_CORE.'helpers/EEH_Base.helper.php' |
|
84 | 84 | ); |
85 | 85 | espresso_load_required( |
86 | 86 | 'EEH_File', |
87 | - EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
87 | + EE_CORE.'interfaces/EEHI_File.interface.php' |
|
88 | 88 | ); |
89 | 89 | espresso_load_required( |
90 | 90 | 'EEH_File', |
91 | - EE_CORE . 'helpers/EEH_File.helper.php' |
|
91 | + EE_CORE.'helpers/EEH_File.helper.php' |
|
92 | 92 | ); |
93 | 93 | espresso_load_required( |
94 | 94 | 'EEH_Array', |
95 | - EE_CORE . 'helpers/EEH_Array.helper.php' |
|
95 | + EE_CORE.'helpers/EEH_Array.helper.php' |
|
96 | 96 | ); |
97 | 97 | espresso_load_required( |
98 | 98 | 'EE_Base', |
99 | - EE_CORE . 'EE_Base.core.php' |
|
99 | + EE_CORE.'EE_Base.core.php' |
|
100 | 100 | ); |
101 | 101 | // instantiate and configure PSR4 autoloader |
102 | 102 | espresso_load_required( |
103 | 103 | 'Psr4Autoloader', |
104 | - EE_CORE . 'Psr4Autoloader.php' |
|
104 | + EE_CORE.'Psr4Autoloader.php' |
|
105 | 105 | ); |
106 | 106 | espresso_load_required( |
107 | 107 | 'EE_Psr4AutoloaderInit', |
108 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
108 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
109 | 109 | ); |
110 | 110 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
111 | 111 | $AutoloaderInit->initializeAutoloader(); |
112 | 112 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
113 | 113 | } catch (Exception $e) { |
114 | - require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
114 | + require_once EE_CORE.'exceptions/ExceptionStackTraceDisplay.php'; |
|
115 | 115 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
116 | 116 | } |
117 | 117 | } |
@@ -18,156 +18,156 @@ |
||
18 | 18 | class FqcnLocator extends Locator |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array $FQCNs |
|
23 | - */ |
|
24 | - protected $FQCNs = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array $namespaces |
|
28 | - */ |
|
29 | - protected $namespaces = array(); |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @access protected |
|
34 | - * @param string $namespace |
|
35 | - * @param string $namespace_base_dir |
|
36 | - * @throws InvalidDataTypeException |
|
37 | - */ |
|
38 | - protected function setNamespace($namespace, $namespace_base_dir) |
|
39 | - { |
|
40 | - if (! is_string($namespace)) { |
|
41 | - throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
|
42 | - } |
|
43 | - if (! is_string($namespace_base_dir)) { |
|
44 | - throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
|
45 | - } |
|
46 | - $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @access public |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getFQCNs() |
|
55 | - { |
|
56 | - return $this->FQCNs; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @access public |
|
62 | - * @return int |
|
63 | - */ |
|
64 | - public function count() |
|
65 | - { |
|
66 | - return count($this->FQCNs); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * given a valid namespace, will find all files that match the provided mask |
|
72 | - * |
|
73 | - * @access public |
|
74 | - * @param string|array $namespaces |
|
75 | - * @return array |
|
76 | - * @throws InvalidClassException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - */ |
|
79 | - public function locate($namespaces) |
|
80 | - { |
|
81 | - if (! (is_string($namespaces) || is_array($namespaces))) { |
|
82 | - throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
|
83 | - } |
|
84 | - foreach ((array) $namespaces as $namespace) { |
|
85 | - foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
|
86 | - $this->FQCNs[ $key ] = $file; |
|
87 | - } |
|
88 | - } |
|
89 | - return $this->FQCNs; |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * given a partial namespace, will find all files in that folder |
|
95 | - * ** PLZ NOTE ** |
|
96 | - * This assumes that all files within the specified folder should be loaded |
|
97 | - * |
|
98 | - * @access protected |
|
99 | - * @param string $partial_namespace |
|
100 | - * @return array |
|
101 | - * @throws InvalidClassException |
|
102 | - * @throws InvalidDataTypeException |
|
103 | - */ |
|
104 | - protected function findFQCNsByNamespace($partial_namespace) |
|
105 | - { |
|
106 | - $iterator = new FilesystemIterator( |
|
107 | - $this->getDirectoryFromPartialNamespace($partial_namespace) |
|
108 | - ); |
|
109 | - $iterator->setFlags(FilesystemIterator::CURRENT_AS_FILEINFO); |
|
110 | - $iterator->setFlags(FilesystemIterator::UNIX_PATHS); |
|
111 | - if (iterator_count($iterator) === 0) { |
|
112 | - return array(); |
|
113 | - } |
|
114 | - foreach ($iterator as $file) { |
|
115 | - if ($file->isFile() && $file->getExtension() === 'php') { |
|
116 | - $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
117 | - foreach ($this->namespaces as $namespace => $base_dir) { |
|
118 | - $namespace .= Psr4Autoloader::NS; |
|
119 | - if (strpos($file, $base_dir) === 0) { |
|
120 | - $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
121 | - array($base_dir, '/'), |
|
122 | - array($namespace, Psr4Autoloader::NS), |
|
123 | - $file |
|
124 | - ); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - return $this->FQCNs; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * getDirectoryFromPartialNamespace |
|
135 | - * |
|
136 | - * @access protected |
|
137 | - * @param string $partial_namespace almost fully qualified class name ? |
|
138 | - * @return string |
|
139 | - * @throws InvalidDataTypeException |
|
140 | - * @throws InvalidClassException |
|
141 | - */ |
|
142 | - protected function getDirectoryFromPartialNamespace($partial_namespace) |
|
143 | - { |
|
144 | - if (empty($partial_namespace)) { |
|
145 | - throw new InvalidClassException($partial_namespace); |
|
146 | - } |
|
147 | - // load our PSR-4 Autoloader so we can get the list of registered namespaces from it |
|
148 | - $psr4_loader = \EE_Psr4AutoloaderInit::psr4_loader(); |
|
149 | - // breakup the incoming namespace into segments so we can loop thru them |
|
150 | - $namespace_segments = explode(Psr4Autoloader::NS, trim($partial_namespace, Psr4Autoloader::NS)); |
|
151 | - // we're only interested in the Vendor and secondary base, so pull those from the array |
|
152 | - $vendor_base = array_slice($namespace_segments, 0, 2); |
|
153 | - $namespace = $prefix = null; |
|
154 | - while (! empty($vendor_base)) { |
|
155 | - $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
|
156 | - // check if there's a base directory registered for that namespace |
|
157 | - $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
158 | - if (! empty($prefix) && ! empty($prefix[0])) { |
|
159 | - // found one! |
|
160 | - break; |
|
161 | - } |
|
162 | - // remove base and try vendor only portion of namespace |
|
163 | - array_pop($vendor_base); |
|
164 | - } |
|
165 | - // nope? then the incoming namespace is invalid |
|
166 | - if (empty($prefix) || empty($prefix[0])) { |
|
167 | - throw new InvalidClassException($partial_namespace); |
|
168 | - } |
|
169 | - $this->setNamespace($namespace, $prefix[0]); |
|
170 | - // but if it's good, add that base directory to the rest of the path, and return it |
|
171 | - return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
172 | - } |
|
21 | + /** |
|
22 | + * @var array $FQCNs |
|
23 | + */ |
|
24 | + protected $FQCNs = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array $namespaces |
|
28 | + */ |
|
29 | + protected $namespaces = array(); |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @access protected |
|
34 | + * @param string $namespace |
|
35 | + * @param string $namespace_base_dir |
|
36 | + * @throws InvalidDataTypeException |
|
37 | + */ |
|
38 | + protected function setNamespace($namespace, $namespace_base_dir) |
|
39 | + { |
|
40 | + if (! is_string($namespace)) { |
|
41 | + throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
|
42 | + } |
|
43 | + if (! is_string($namespace_base_dir)) { |
|
44 | + throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
|
45 | + } |
|
46 | + $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @access public |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getFQCNs() |
|
55 | + { |
|
56 | + return $this->FQCNs; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @access public |
|
62 | + * @return int |
|
63 | + */ |
|
64 | + public function count() |
|
65 | + { |
|
66 | + return count($this->FQCNs); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * given a valid namespace, will find all files that match the provided mask |
|
72 | + * |
|
73 | + * @access public |
|
74 | + * @param string|array $namespaces |
|
75 | + * @return array |
|
76 | + * @throws InvalidClassException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + */ |
|
79 | + public function locate($namespaces) |
|
80 | + { |
|
81 | + if (! (is_string($namespaces) || is_array($namespaces))) { |
|
82 | + throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
|
83 | + } |
|
84 | + foreach ((array) $namespaces as $namespace) { |
|
85 | + foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
|
86 | + $this->FQCNs[ $key ] = $file; |
|
87 | + } |
|
88 | + } |
|
89 | + return $this->FQCNs; |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * given a partial namespace, will find all files in that folder |
|
95 | + * ** PLZ NOTE ** |
|
96 | + * This assumes that all files within the specified folder should be loaded |
|
97 | + * |
|
98 | + * @access protected |
|
99 | + * @param string $partial_namespace |
|
100 | + * @return array |
|
101 | + * @throws InvalidClassException |
|
102 | + * @throws InvalidDataTypeException |
|
103 | + */ |
|
104 | + protected function findFQCNsByNamespace($partial_namespace) |
|
105 | + { |
|
106 | + $iterator = new FilesystemIterator( |
|
107 | + $this->getDirectoryFromPartialNamespace($partial_namespace) |
|
108 | + ); |
|
109 | + $iterator->setFlags(FilesystemIterator::CURRENT_AS_FILEINFO); |
|
110 | + $iterator->setFlags(FilesystemIterator::UNIX_PATHS); |
|
111 | + if (iterator_count($iterator) === 0) { |
|
112 | + return array(); |
|
113 | + } |
|
114 | + foreach ($iterator as $file) { |
|
115 | + if ($file->isFile() && $file->getExtension() === 'php') { |
|
116 | + $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
117 | + foreach ($this->namespaces as $namespace => $base_dir) { |
|
118 | + $namespace .= Psr4Autoloader::NS; |
|
119 | + if (strpos($file, $base_dir) === 0) { |
|
120 | + $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
121 | + array($base_dir, '/'), |
|
122 | + array($namespace, Psr4Autoloader::NS), |
|
123 | + $file |
|
124 | + ); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | + return $this->FQCNs; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * getDirectoryFromPartialNamespace |
|
135 | + * |
|
136 | + * @access protected |
|
137 | + * @param string $partial_namespace almost fully qualified class name ? |
|
138 | + * @return string |
|
139 | + * @throws InvalidDataTypeException |
|
140 | + * @throws InvalidClassException |
|
141 | + */ |
|
142 | + protected function getDirectoryFromPartialNamespace($partial_namespace) |
|
143 | + { |
|
144 | + if (empty($partial_namespace)) { |
|
145 | + throw new InvalidClassException($partial_namespace); |
|
146 | + } |
|
147 | + // load our PSR-4 Autoloader so we can get the list of registered namespaces from it |
|
148 | + $psr4_loader = \EE_Psr4AutoloaderInit::psr4_loader(); |
|
149 | + // breakup the incoming namespace into segments so we can loop thru them |
|
150 | + $namespace_segments = explode(Psr4Autoloader::NS, trim($partial_namespace, Psr4Autoloader::NS)); |
|
151 | + // we're only interested in the Vendor and secondary base, so pull those from the array |
|
152 | + $vendor_base = array_slice($namespace_segments, 0, 2); |
|
153 | + $namespace = $prefix = null; |
|
154 | + while (! empty($vendor_base)) { |
|
155 | + $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
|
156 | + // check if there's a base directory registered for that namespace |
|
157 | + $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
158 | + if (! empty($prefix) && ! empty($prefix[0])) { |
|
159 | + // found one! |
|
160 | + break; |
|
161 | + } |
|
162 | + // remove base and try vendor only portion of namespace |
|
163 | + array_pop($vendor_base); |
|
164 | + } |
|
165 | + // nope? then the incoming namespace is invalid |
|
166 | + if (empty($prefix) || empty($prefix[0])) { |
|
167 | + throw new InvalidClassException($partial_namespace); |
|
168 | + } |
|
169 | + $this->setNamespace($namespace, $prefix[0]); |
|
170 | + // but if it's good, add that base directory to the rest of the path, and return it |
|
171 | + return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
172 | + } |
|
173 | 173 | } |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function setNamespace($namespace, $namespace_base_dir) |
39 | 39 | { |
40 | - if (! is_string($namespace)) { |
|
40 | + if ( ! is_string($namespace)) { |
|
41 | 41 | throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
42 | 42 | } |
43 | - if (! is_string($namespace_base_dir)) { |
|
43 | + if ( ! is_string($namespace_base_dir)) { |
|
44 | 44 | throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
45 | 45 | } |
46 | - $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
46 | + $this->namespaces[$namespace] = $namespace_base_dir; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function locate($namespaces) |
80 | 80 | { |
81 | - if (! (is_string($namespaces) || is_array($namespaces))) { |
|
81 | + if ( ! (is_string($namespaces) || is_array($namespaces))) { |
|
82 | 82 | throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
83 | 83 | } |
84 | 84 | foreach ((array) $namespaces as $namespace) { |
85 | 85 | foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
86 | - $this->FQCNs[ $key ] = $file; |
|
86 | + $this->FQCNs[$key] = $file; |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | return $this->FQCNs; |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | } |
114 | 114 | foreach ($iterator as $file) { |
115 | 115 | if ($file->isFile() && $file->getExtension() === 'php') { |
116 | - $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
116 | + $file = $file->getPath().'/'.$file->getBasename('.php'); |
|
117 | 117 | foreach ($this->namespaces as $namespace => $base_dir) { |
118 | 118 | $namespace .= Psr4Autoloader::NS; |
119 | 119 | if (strpos($file, $base_dir) === 0) { |
120 | - $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
120 | + $this->FQCNs[] = Psr4Autoloader::NS.str_replace( |
|
121 | 121 | array($base_dir, '/'), |
122 | 122 | array($namespace, Psr4Autoloader::NS), |
123 | 123 | $file |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | // we're only interested in the Vendor and secondary base, so pull those from the array |
152 | 152 | $vendor_base = array_slice($namespace_segments, 0, 2); |
153 | 153 | $namespace = $prefix = null; |
154 | - while (! empty($vendor_base)) { |
|
154 | + while ( ! empty($vendor_base)) { |
|
155 | 155 | $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
156 | 156 | // check if there's a base directory registered for that namespace |
157 | - $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
158 | - if (! empty($prefix) && ! empty($prefix[0])) { |
|
157 | + $prefix = $psr4_loader->prefixes($namespace.Psr4Autoloader::NS); |
|
158 | + if ( ! empty($prefix) && ! empty($prefix[0])) { |
|
159 | 159 | // found one! |
160 | 160 | break; |
161 | 161 | } |
@@ -168,6 +168,6 @@ discard block |
||
168 | 168 | } |
169 | 169 | $this->setNamespace($namespace, $prefix[0]); |
170 | 170 | // but if it's good, add that base directory to the rest of the path, and return it |
171 | - return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
171 | + return $prefix[0].implode('/', array_diff($namespace_segments, $vendor_base)).'/'; |
|
172 | 172 | } |
173 | 173 | } |
@@ -25,80 +25,80 @@ |
||
25 | 25 | class BootstrapRequestResponseObjects |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @type LegacyRequestInterface $legacy_request |
|
30 | - */ |
|
31 | - protected $legacy_request; |
|
28 | + /** |
|
29 | + * @type LegacyRequestInterface $legacy_request |
|
30 | + */ |
|
31 | + protected $legacy_request; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @type LoaderInterface $loader |
|
35 | - */ |
|
36 | - protected $loader; |
|
33 | + /** |
|
34 | + * @type LoaderInterface $loader |
|
35 | + */ |
|
36 | + protected $loader; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var RequestInterface $request |
|
40 | - */ |
|
41 | - protected $request; |
|
38 | + /** |
|
39 | + * @var RequestInterface $request |
|
40 | + */ |
|
41 | + protected $request; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var ResponseInterface $response |
|
45 | - */ |
|
46 | - protected $response; |
|
43 | + /** |
|
44 | + * @var ResponseInterface $response |
|
45 | + */ |
|
46 | + protected $response; |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * BootstrapRequestResponseObjects constructor. |
|
51 | - * |
|
52 | - * @param LoaderInterface $loader |
|
53 | - */ |
|
54 | - public function __construct(LoaderInterface $loader) |
|
55 | - { |
|
56 | - $this->loader = $loader; |
|
57 | - } |
|
49 | + /** |
|
50 | + * BootstrapRequestResponseObjects constructor. |
|
51 | + * |
|
52 | + * @param LoaderInterface $loader |
|
53 | + */ |
|
54 | + public function __construct(LoaderInterface $loader) |
|
55 | + { |
|
56 | + $this->loader = $loader; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function buildRequestResponse() |
|
64 | - { |
|
65 | - // load our Request and Response objects |
|
66 | - $this->request = new Request($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES); |
|
67 | - $this->response = new Response(); |
|
68 | - } |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function buildRequestResponse() |
|
64 | + { |
|
65 | + // load our Request and Response objects |
|
66 | + $this->request = new Request($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES); |
|
67 | + $this->response = new Response(); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return void |
|
73 | - * @throws InvalidArgumentException |
|
74 | - */ |
|
75 | - public function shareRequestResponse() |
|
76 | - { |
|
77 | - $this->loader->share('EventEspresso\core\services\request\Request', $this->request); |
|
78 | - $this->loader->share('EventEspresso\core\services\request\Response', $this->response); |
|
79 | - EE_Dependency_Map::instance()->setRequest($this->request); |
|
80 | - EE_Dependency_Map::instance()->setResponse($this->response); |
|
81 | - } |
|
71 | + /** |
|
72 | + * @return void |
|
73 | + * @throws InvalidArgumentException |
|
74 | + */ |
|
75 | + public function shareRequestResponse() |
|
76 | + { |
|
77 | + $this->loader->share('EventEspresso\core\services\request\Request', $this->request); |
|
78 | + $this->loader->share('EventEspresso\core\services\request\Response', $this->response); |
|
79 | + EE_Dependency_Map::instance()->setRequest($this->request); |
|
80 | + EE_Dependency_Map::instance()->setResponse($this->response); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - * @throws InvalidArgumentException |
|
87 | - * @throws EE_Error |
|
88 | - */ |
|
89 | - public function setupLegacyRequest() |
|
90 | - { |
|
91 | - espresso_load_required( |
|
92 | - 'EE_Request', |
|
93 | - EE_CORE . 'request_stack/EE_Request.core.php' |
|
94 | - ); |
|
95 | - $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
96 | - $this->legacy_request->setRequest($this->request); |
|
97 | - $this->legacy_request->admin = $this->request->isAdmin(); |
|
98 | - $this->legacy_request->ajax = $this->request->isAjax(); |
|
99 | - $this->legacy_request->front_ajax = $this->request->isFrontAjax(); |
|
100 | - EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request); |
|
101 | - $this->loader->share('EE_Request', $this->legacy_request); |
|
102 | - $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request); |
|
103 | - } |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + * @throws InvalidArgumentException |
|
87 | + * @throws EE_Error |
|
88 | + */ |
|
89 | + public function setupLegacyRequest() |
|
90 | + { |
|
91 | + espresso_load_required( |
|
92 | + 'EE_Request', |
|
93 | + EE_CORE . 'request_stack/EE_Request.core.php' |
|
94 | + ); |
|
95 | + $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
96 | + $this->legacy_request->setRequest($this->request); |
|
97 | + $this->legacy_request->admin = $this->request->isAdmin(); |
|
98 | + $this->legacy_request->ajax = $this->request->isAjax(); |
|
99 | + $this->legacy_request->front_ajax = $this->request->isFrontAjax(); |
|
100 | + EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request); |
|
101 | + $this->loader->share('EE_Request', $this->legacy_request); |
|
102 | + $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request); |
|
103 | + } |
|
104 | 104 | } |
@@ -90,7 +90,7 @@ |
||
90 | 90 | { |
91 | 91 | espresso_load_required( |
92 | 92 | 'EE_Request', |
93 | - EE_CORE . 'request_stack/EE_Request.core.php' |
|
93 | + EE_CORE.'request_stack/EE_Request.core.php' |
|
94 | 94 | ); |
95 | 95 | $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
96 | 96 | $this->legacy_request->setRequest($this->request); |