@@ -19,524 +19,524 @@ |
||
19 | 19 | */ |
20 | 20 | class EE_Maintenance_Mode implements ResettableInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
24 | - * STATUS_OFF means the site is NOT in maintenance mode (so everything's normal) |
|
25 | - */ |
|
26 | - public const STATUS_OFF = 0; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * STATUS_PUBLIC_ONLY means that the site's frontend EE code should be completely disabled |
|
31 | - * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
32 | - */ |
|
33 | - public const STATUS_PUBLIC_ONLY = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * STATUS_FULL_SITE means the frontend AND EE backend code are disabled. The only system running |
|
37 | - * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
38 | - * migration scripts before taking the site out of maintenance mode |
|
39 | - */ |
|
40 | - public const STATUS_FULL_SITE = 2; |
|
41 | - |
|
42 | - /** |
|
43 | - * the name of the option which stores the current level of maintenance mode |
|
44 | - */ |
|
45 | - private const OPTION_NAME = 'ee_maintenance_mode'; |
|
46 | - |
|
47 | - |
|
48 | - protected LoaderInterface $loader; |
|
49 | - |
|
50 | - private RequestInterface $request; |
|
51 | - |
|
52 | - private static ?EE_Maintenance_Mode $_instance = null; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var int |
|
56 | - * @since 5.0.12.p |
|
57 | - */ |
|
58 | - private int $status; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var int |
|
62 | - * @since 5.0.12.p |
|
63 | - */ |
|
64 | - private int $admin_status; |
|
65 | - |
|
66 | - /** |
|
67 | - * true if current_user_can('administrator') |
|
68 | - * |
|
69 | - * @var bool |
|
70 | - * @since 5.0.12.p |
|
71 | - */ |
|
72 | - private bool $current_user_is_admin; |
|
73 | - |
|
74 | - /** |
|
75 | - * used to control updates to the WP options setting in the database |
|
76 | - * |
|
77 | - * @var bool |
|
78 | - * @since 5.0.12.p |
|
79 | - */ |
|
80 | - private bool $update_db; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @singleton method used to instantiate class object |
|
85 | - * @param LoaderInterface|null $loader |
|
86 | - * @param RequestInterface|null $request |
|
87 | - * @return EE_Maintenance_Mode|null |
|
88 | - */ |
|
89 | - public static function instance( |
|
90 | - ?LoaderInterface $loader = null, |
|
91 | - ?RequestInterface $request = null |
|
92 | - ): ?EE_Maintenance_Mode { |
|
93 | - // check if class object is instantiated |
|
94 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
95 | - self::$_instance = new EE_Maintenance_Mode($loader, $request); |
|
96 | - } |
|
97 | - return self::$_instance; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Resets maintenance mode (mostly just re-checks whether we should be in maintenance mode) |
|
103 | - * |
|
104 | - * @return EE_Maintenance_Mode|null |
|
105 | - * @throws EE_Error |
|
106 | - */ |
|
107 | - public static function reset(): ?EE_Maintenance_Mode |
|
108 | - { |
|
109 | - self::instance()->set_maintenance_mode_if_db_old(); |
|
110 | - self::instance()->initialize(); |
|
111 | - return self::instance(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - *private constructor to prevent direct creation |
|
117 | - */ |
|
118 | - private function __construct(LoaderInterface $loader, RequestInterface $request) |
|
119 | - { |
|
120 | - $this->loader = $loader; |
|
121 | - $this->request = $request; |
|
122 | - $this->initialize(); |
|
123 | - |
|
124 | - // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
125 | - add_action('wp_enqueue_scripts', [$this, 'load_assets_required_for_m_mode']); |
|
126 | - // shut 'er down for maintenance ? |
|
127 | - add_filter('the_content', [$this, 'the_content'], 2); |
|
128 | - // redirect ee menus to maintenance page |
|
129 | - add_action('admin_page_access_denied', [$this, 'redirect_to_maintenance']); |
|
130 | - // add powered by EE msg |
|
131 | - add_action('shutdown', [$this, 'display_maintenance_mode_notice']); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - private function initialize(): void |
|
136 | - { |
|
137 | - $this->current_user_is_admin = current_user_can('administrator'); |
|
138 | - // now make sure the status is set correctly everywhere |
|
139 | - // (but don't update the db else we'll get into an infinite loop of updates) |
|
140 | - $this->update_db = false; |
|
141 | - $this->set_maintenance_level($this->loadStatusFromDatabase()); |
|
142 | - $this->update_db = true; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - private function loadStatusFromDatabase(): int |
|
147 | - { |
|
148 | - return (int) get_option(EE_Maintenance_Mode::OPTION_NAME, EE_Maintenance_Mode::STATUS_OFF); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * changes the maintenance mode level to reflect whether the current user is an admin or not. |
|
154 | - * Determines whether we're in maintenance mode and what level. However, while the site |
|
155 | - * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
156 | - * to them as if the site isn't in maintenance mode. |
|
157 | - * EE_Maintenance_Mode::STATUS_OFF => not in maintenance mode (in normal mode) |
|
158 | - * EE_Maintenance_Mode::STATUS_PUBLIC_ONLY=> frontend-only maintenance mode |
|
159 | - * EE_Maintenance_Mode::STATUS_FULL_SITE => frontend and backend maintenance mode |
|
160 | - * |
|
161 | - * @param int $status |
|
162 | - * @return void |
|
163 | - * @since 5.0.12.p |
|
164 | - */ |
|
165 | - private function setAdminStatus(int $status) |
|
166 | - { |
|
167 | - if ( |
|
168 | - $status === EE_Maintenance_Mode::STATUS_PUBLIC_ONLY |
|
169 | - && $this->current_user_is_admin |
|
170 | - && ($this->request->isAjax() || ! $this->request->isAdmin()) |
|
171 | - ) { |
|
172 | - $status = EE_Maintenance_Mode::STATUS_OFF; |
|
173 | - } |
|
174 | - $this->admin_status = $status; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - public function real_level(): int |
|
179 | - { |
|
180 | - return $this->status; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return int |
|
186 | - */ |
|
187 | - public function level(): int |
|
188 | - { |
|
189 | - return $this->admin_status; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Determines if we need to put EE in maintenance mode because the database needs updating |
|
195 | - * |
|
196 | - * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
197 | - * @throws EE_Error |
|
198 | - */ |
|
199 | - public function set_maintenance_mode_if_db_old(): bool |
|
200 | - { |
|
201 | - /** @var EE_Data_Migration_Manager $data_migration_manager */ |
|
202 | - $data_migration_manager = $this->loader->getShared(EE_Data_Migration_Manager::class); |
|
203 | - $scripts_that_should_run = $data_migration_manager->check_for_applicable_data_migration_scripts(); |
|
204 | - if (! empty($scripts_that_should_run)) { // && $this->status !== EE_Maintenance_Mode::STATUS_FULL_SITE |
|
205 | - $this->activateFullSiteMaintenanceMode(); |
|
206 | - return true; |
|
207 | - } |
|
208 | - if ($this->status === EE_Maintenance_Mode::STATUS_FULL_SITE) { |
|
209 | - // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
210 | - // then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
211 | - $this->deactivateMaintenanceMode(); |
|
212 | - } |
|
213 | - return false; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Updates the maintenance level on the site |
|
219 | - * |
|
220 | - * @param int $level |
|
221 | - * @return void |
|
222 | - */ |
|
223 | - public function set_maintenance_level(int $level): void |
|
224 | - { |
|
225 | - switch ($level) { |
|
226 | - case EE_Maintenance_Mode::STATUS_OFF: |
|
227 | - $this->deactivateMaintenanceMode(); |
|
228 | - return; |
|
229 | - case EE_Maintenance_Mode::STATUS_PUBLIC_ONLY: |
|
230 | - $this->activatePublicOnlyMaintenanceMode(); |
|
231 | - return; |
|
232 | - case EE_Maintenance_Mode::STATUS_FULL_SITE: |
|
233 | - $this->activateFullSiteMaintenanceMode(); |
|
234 | - return; |
|
235 | - } |
|
236 | - throw new DomainException( |
|
237 | - sprintf( |
|
238 | - esc_html__( |
|
239 | - '"%1$s" is not valid a EE maintenance mode level. Please choose from one of the following: %2$s', |
|
240 | - 'event_espresso' |
|
241 | - ), |
|
242 | - $level, |
|
243 | - 'EE_Maintenance_Mode::STATUS_OFF, EE_Maintenance_Mode::STATUS_PUBLIC_ONLY, EE_Maintenance_Mode::STATUS_FULL_SITE', |
|
244 | - ) |
|
245 | - ); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * sets database status to online |
|
251 | - * sets maintenance mode status to public only, unless current user is an admin, then maintenance mode is disabled |
|
252 | - * |
|
253 | - * @return void |
|
254 | - * @since 5.0.12.p |
|
255 | - */ |
|
256 | - public function activatePublicOnlyMaintenanceMode() |
|
257 | - { |
|
258 | - DbStatus::setOnline(); |
|
259 | - // disable maintenance mode for admins, otherwise enable public only maintenance mode |
|
260 | - if ($this->current_user_is_admin) { |
|
261 | - MaintenanceStatus::disableMaintenanceMode(); |
|
262 | - } else { |
|
263 | - MaintenanceStatus::setPublicOnlyMaintenanceMode(); |
|
264 | - } |
|
265 | - $this->updateMaintenaceModeStatus(EE_Maintenance_Mode::STATUS_PUBLIC_ONLY); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * sets database status to offline |
|
271 | - * sets maintenance mode status to full site |
|
272 | - * |
|
273 | - * @return void |
|
274 | - * @since 5.0.12.p |
|
275 | - */ |
|
276 | - public function activateFullSiteMaintenanceMode() |
|
277 | - { |
|
278 | - DbStatus::setOffline(); |
|
279 | - MaintenanceStatus::setFullSiteMaintenanceMode(); |
|
280 | - $this->updateMaintenaceModeStatus(EE_Maintenance_Mode::STATUS_FULL_SITE); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * sets database status to online |
|
286 | - * turns maintenance mode off |
|
287 | - * |
|
288 | - * @return void |
|
289 | - * @since 5.0.12.p |
|
290 | - */ |
|
291 | - public function deactivateMaintenanceMode() |
|
292 | - { |
|
293 | - DbStatus::setOnline(); |
|
294 | - MaintenanceStatus::disableMaintenanceMode(); |
|
295 | - $this->updateMaintenaceModeStatus(EE_Maintenance_Mode::STATUS_OFF); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - private function updateMaintenaceModeStatus(int $status) |
|
300 | - { |
|
301 | - $this->status = $status; |
|
302 | - $this->setAdminStatus($status); |
|
303 | - if (! $this->update_db) { |
|
304 | - return; |
|
305 | - } |
|
306 | - do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $status); |
|
307 | - update_option(EE_Maintenance_Mode::OPTION_NAME, $status); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
313 | - * |
|
314 | - * @return bool |
|
315 | - */ |
|
316 | - public static function disable_frontend_for_maintenance(): bool |
|
317 | - { |
|
318 | - return ! is_admin() && MaintenanceStatus::isNotDisabled(); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @return void |
|
324 | - */ |
|
325 | - public function load_assets_required_for_m_mode(): void |
|
326 | - { |
|
327 | - if ( |
|
328 | - $this->status === EE_Maintenance_Mode::STATUS_FULL_SITE |
|
329 | - && ! wp_script_is('espresso_core') |
|
330 | - ) { |
|
331 | - wp_register_style( |
|
332 | - 'espresso_default', |
|
333 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
334 | - ['dashicons'], |
|
335 | - EVENT_ESPRESSO_VERSION |
|
336 | - ); |
|
337 | - wp_enqueue_style('espresso_default'); |
|
338 | - wp_register_script( |
|
339 | - 'espresso_core', |
|
340 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
341 | - ['jquery'], |
|
342 | - EVENT_ESPRESSO_VERSION, |
|
343 | - true |
|
344 | - ); |
|
345 | - wp_enqueue_script('espresso_core'); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * replacement EE CPT template that displays message notifying site visitors |
|
352 | - * that EE has been temporarily placed into maintenance mode |
|
353 | - * does NOT get called on non-EE-CPT requests |
|
354 | - * |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public static function template_include(): string |
|
358 | - { |
|
359 | - // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
|
360 | - return get_template_directory() . '/index.php'; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * displays message notifying site visitors that EE has been temporarily |
|
366 | - * placed into maintenance mode when post_type != EE CPT |
|
367 | - * |
|
368 | - * @param string $the_content |
|
369 | - * @return string |
|
370 | - */ |
|
371 | - public function the_content(?string $the_content): ?string |
|
372 | - { |
|
373 | - // check if M-mode is engaged and for EE shortcode |
|
374 | - if ($this->admin_status && strpos((string)$the_content, '[ESPRESSO_') !== false) { |
|
375 | - // this can eventually be moved to a template, or edited via admin. But for now... |
|
376 | - $the_content = sprintf( |
|
377 | - esc_html__( |
|
378 | - '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
379 | - 'event_espresso' |
|
380 | - ), |
|
381 | - '<h3>', |
|
382 | - '</h3><p>', |
|
383 | - '</p>' |
|
384 | - ); |
|
385 | - } |
|
386 | - return $the_content; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
392 | - */ |
|
393 | - public function display_maintenance_mode_notice() |
|
394 | - { |
|
395 | - if ( |
|
396 | - ! $this->current_user_is_admin |
|
397 | - || $this->status === EE_Maintenance_Mode::STATUS_OFF |
|
398 | - || $this->request->isAdmin() |
|
399 | - || $this->request->isAjax() |
|
400 | - || ! did_action('AHEE__EE_System__load_core_configuration__complete') |
|
401 | - ) { |
|
402 | - return; |
|
403 | - } |
|
404 | - /** @var CurrentPage $current_page */ |
|
405 | - $current_page = $this->loader->getShared(CurrentPage::class); |
|
406 | - if ($current_page->isEspressoPage()) { |
|
407 | - printf( |
|
408 | - esc_html__( |
|
409 | - '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
410 | - 'event_espresso' |
|
411 | - ), |
|
412 | - '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
413 | - '"><span class="dashicons dashicons-no"></span></a><p>', |
|
414 | - ' » <a href="' . add_query_arg( |
|
415 | - ['page' => 'espresso_maintenance_settings'], |
|
416 | - admin_url('admin.php') |
|
417 | - ) . '">', |
|
418 | - '</a></p></div>' |
|
419 | - ); |
|
420 | - } |
|
421 | - } |
|
422 | - // espresso-notices important-notice ee-attention |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * Redirects EE admin menu requests to the maintenance page |
|
427 | - */ |
|
428 | - public function redirect_to_maintenance() |
|
429 | - { |
|
430 | - global $pagenow; |
|
431 | - $page = $this->request->getRequestParam('page', '', DataType::STRING); |
|
432 | - if ( |
|
433 | - $pagenow == 'admin.php' |
|
434 | - && $page !== 'espresso_maintenance_settings' |
|
435 | - && strpos($page, 'espresso_') !== false |
|
436 | - && $this->status == EE_Maintenance_Mode::STATUS_FULL_SITE |
|
437 | - ) { |
|
438 | - EEH_URL::safeRedirectAndExit('admin.php?page=espresso_maintenance_settings'); |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * override magic methods |
|
445 | - */ |
|
446 | - final public function __destruct() |
|
447 | - { |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - final public function __call($a, $b) |
|
452 | - { |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - final public function __get($a) |
|
457 | - { |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - final public function __set($a, $b) |
|
462 | - { |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - final public function __isset($a) |
|
467 | - { |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - final public function __unset($a) |
|
472 | - { |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - final public function __sleep() |
|
477 | - { |
|
478 | - return []; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - final public function __wakeup() |
|
483 | - { |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - final public function __invoke() |
|
488 | - { |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - final public static function __set_state($a = null) |
|
493 | - { |
|
494 | - return EE_Maintenance_Mode::instance(); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - final public function __clone() |
|
499 | - { |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - final public static function __callStatic($a, $b) |
|
504 | - { |
|
505 | - } |
|
22 | + /** |
|
23 | + * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
24 | + * STATUS_OFF means the site is NOT in maintenance mode (so everything's normal) |
|
25 | + */ |
|
26 | + public const STATUS_OFF = 0; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * STATUS_PUBLIC_ONLY means that the site's frontend EE code should be completely disabled |
|
31 | + * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
32 | + */ |
|
33 | + public const STATUS_PUBLIC_ONLY = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * STATUS_FULL_SITE means the frontend AND EE backend code are disabled. The only system running |
|
37 | + * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
38 | + * migration scripts before taking the site out of maintenance mode |
|
39 | + */ |
|
40 | + public const STATUS_FULL_SITE = 2; |
|
41 | + |
|
42 | + /** |
|
43 | + * the name of the option which stores the current level of maintenance mode |
|
44 | + */ |
|
45 | + private const OPTION_NAME = 'ee_maintenance_mode'; |
|
46 | + |
|
47 | + |
|
48 | + protected LoaderInterface $loader; |
|
49 | + |
|
50 | + private RequestInterface $request; |
|
51 | + |
|
52 | + private static ?EE_Maintenance_Mode $_instance = null; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var int |
|
56 | + * @since 5.0.12.p |
|
57 | + */ |
|
58 | + private int $status; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var int |
|
62 | + * @since 5.0.12.p |
|
63 | + */ |
|
64 | + private int $admin_status; |
|
65 | + |
|
66 | + /** |
|
67 | + * true if current_user_can('administrator') |
|
68 | + * |
|
69 | + * @var bool |
|
70 | + * @since 5.0.12.p |
|
71 | + */ |
|
72 | + private bool $current_user_is_admin; |
|
73 | + |
|
74 | + /** |
|
75 | + * used to control updates to the WP options setting in the database |
|
76 | + * |
|
77 | + * @var bool |
|
78 | + * @since 5.0.12.p |
|
79 | + */ |
|
80 | + private bool $update_db; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @singleton method used to instantiate class object |
|
85 | + * @param LoaderInterface|null $loader |
|
86 | + * @param RequestInterface|null $request |
|
87 | + * @return EE_Maintenance_Mode|null |
|
88 | + */ |
|
89 | + public static function instance( |
|
90 | + ?LoaderInterface $loader = null, |
|
91 | + ?RequestInterface $request = null |
|
92 | + ): ?EE_Maintenance_Mode { |
|
93 | + // check if class object is instantiated |
|
94 | + if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
95 | + self::$_instance = new EE_Maintenance_Mode($loader, $request); |
|
96 | + } |
|
97 | + return self::$_instance; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Resets maintenance mode (mostly just re-checks whether we should be in maintenance mode) |
|
103 | + * |
|
104 | + * @return EE_Maintenance_Mode|null |
|
105 | + * @throws EE_Error |
|
106 | + */ |
|
107 | + public static function reset(): ?EE_Maintenance_Mode |
|
108 | + { |
|
109 | + self::instance()->set_maintenance_mode_if_db_old(); |
|
110 | + self::instance()->initialize(); |
|
111 | + return self::instance(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + *private constructor to prevent direct creation |
|
117 | + */ |
|
118 | + private function __construct(LoaderInterface $loader, RequestInterface $request) |
|
119 | + { |
|
120 | + $this->loader = $loader; |
|
121 | + $this->request = $request; |
|
122 | + $this->initialize(); |
|
123 | + |
|
124 | + // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
125 | + add_action('wp_enqueue_scripts', [$this, 'load_assets_required_for_m_mode']); |
|
126 | + // shut 'er down for maintenance ? |
|
127 | + add_filter('the_content', [$this, 'the_content'], 2); |
|
128 | + // redirect ee menus to maintenance page |
|
129 | + add_action('admin_page_access_denied', [$this, 'redirect_to_maintenance']); |
|
130 | + // add powered by EE msg |
|
131 | + add_action('shutdown', [$this, 'display_maintenance_mode_notice']); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + private function initialize(): void |
|
136 | + { |
|
137 | + $this->current_user_is_admin = current_user_can('administrator'); |
|
138 | + // now make sure the status is set correctly everywhere |
|
139 | + // (but don't update the db else we'll get into an infinite loop of updates) |
|
140 | + $this->update_db = false; |
|
141 | + $this->set_maintenance_level($this->loadStatusFromDatabase()); |
|
142 | + $this->update_db = true; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + private function loadStatusFromDatabase(): int |
|
147 | + { |
|
148 | + return (int) get_option(EE_Maintenance_Mode::OPTION_NAME, EE_Maintenance_Mode::STATUS_OFF); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * changes the maintenance mode level to reflect whether the current user is an admin or not. |
|
154 | + * Determines whether we're in maintenance mode and what level. However, while the site |
|
155 | + * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
156 | + * to them as if the site isn't in maintenance mode. |
|
157 | + * EE_Maintenance_Mode::STATUS_OFF => not in maintenance mode (in normal mode) |
|
158 | + * EE_Maintenance_Mode::STATUS_PUBLIC_ONLY=> frontend-only maintenance mode |
|
159 | + * EE_Maintenance_Mode::STATUS_FULL_SITE => frontend and backend maintenance mode |
|
160 | + * |
|
161 | + * @param int $status |
|
162 | + * @return void |
|
163 | + * @since 5.0.12.p |
|
164 | + */ |
|
165 | + private function setAdminStatus(int $status) |
|
166 | + { |
|
167 | + if ( |
|
168 | + $status === EE_Maintenance_Mode::STATUS_PUBLIC_ONLY |
|
169 | + && $this->current_user_is_admin |
|
170 | + && ($this->request->isAjax() || ! $this->request->isAdmin()) |
|
171 | + ) { |
|
172 | + $status = EE_Maintenance_Mode::STATUS_OFF; |
|
173 | + } |
|
174 | + $this->admin_status = $status; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + public function real_level(): int |
|
179 | + { |
|
180 | + return $this->status; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return int |
|
186 | + */ |
|
187 | + public function level(): int |
|
188 | + { |
|
189 | + return $this->admin_status; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Determines if we need to put EE in maintenance mode because the database needs updating |
|
195 | + * |
|
196 | + * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
197 | + * @throws EE_Error |
|
198 | + */ |
|
199 | + public function set_maintenance_mode_if_db_old(): bool |
|
200 | + { |
|
201 | + /** @var EE_Data_Migration_Manager $data_migration_manager */ |
|
202 | + $data_migration_manager = $this->loader->getShared(EE_Data_Migration_Manager::class); |
|
203 | + $scripts_that_should_run = $data_migration_manager->check_for_applicable_data_migration_scripts(); |
|
204 | + if (! empty($scripts_that_should_run)) { // && $this->status !== EE_Maintenance_Mode::STATUS_FULL_SITE |
|
205 | + $this->activateFullSiteMaintenanceMode(); |
|
206 | + return true; |
|
207 | + } |
|
208 | + if ($this->status === EE_Maintenance_Mode::STATUS_FULL_SITE) { |
|
209 | + // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
210 | + // then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
211 | + $this->deactivateMaintenanceMode(); |
|
212 | + } |
|
213 | + return false; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Updates the maintenance level on the site |
|
219 | + * |
|
220 | + * @param int $level |
|
221 | + * @return void |
|
222 | + */ |
|
223 | + public function set_maintenance_level(int $level): void |
|
224 | + { |
|
225 | + switch ($level) { |
|
226 | + case EE_Maintenance_Mode::STATUS_OFF: |
|
227 | + $this->deactivateMaintenanceMode(); |
|
228 | + return; |
|
229 | + case EE_Maintenance_Mode::STATUS_PUBLIC_ONLY: |
|
230 | + $this->activatePublicOnlyMaintenanceMode(); |
|
231 | + return; |
|
232 | + case EE_Maintenance_Mode::STATUS_FULL_SITE: |
|
233 | + $this->activateFullSiteMaintenanceMode(); |
|
234 | + return; |
|
235 | + } |
|
236 | + throw new DomainException( |
|
237 | + sprintf( |
|
238 | + esc_html__( |
|
239 | + '"%1$s" is not valid a EE maintenance mode level. Please choose from one of the following: %2$s', |
|
240 | + 'event_espresso' |
|
241 | + ), |
|
242 | + $level, |
|
243 | + 'EE_Maintenance_Mode::STATUS_OFF, EE_Maintenance_Mode::STATUS_PUBLIC_ONLY, EE_Maintenance_Mode::STATUS_FULL_SITE', |
|
244 | + ) |
|
245 | + ); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * sets database status to online |
|
251 | + * sets maintenance mode status to public only, unless current user is an admin, then maintenance mode is disabled |
|
252 | + * |
|
253 | + * @return void |
|
254 | + * @since 5.0.12.p |
|
255 | + */ |
|
256 | + public function activatePublicOnlyMaintenanceMode() |
|
257 | + { |
|
258 | + DbStatus::setOnline(); |
|
259 | + // disable maintenance mode for admins, otherwise enable public only maintenance mode |
|
260 | + if ($this->current_user_is_admin) { |
|
261 | + MaintenanceStatus::disableMaintenanceMode(); |
|
262 | + } else { |
|
263 | + MaintenanceStatus::setPublicOnlyMaintenanceMode(); |
|
264 | + } |
|
265 | + $this->updateMaintenaceModeStatus(EE_Maintenance_Mode::STATUS_PUBLIC_ONLY); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * sets database status to offline |
|
271 | + * sets maintenance mode status to full site |
|
272 | + * |
|
273 | + * @return void |
|
274 | + * @since 5.0.12.p |
|
275 | + */ |
|
276 | + public function activateFullSiteMaintenanceMode() |
|
277 | + { |
|
278 | + DbStatus::setOffline(); |
|
279 | + MaintenanceStatus::setFullSiteMaintenanceMode(); |
|
280 | + $this->updateMaintenaceModeStatus(EE_Maintenance_Mode::STATUS_FULL_SITE); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * sets database status to online |
|
286 | + * turns maintenance mode off |
|
287 | + * |
|
288 | + * @return void |
|
289 | + * @since 5.0.12.p |
|
290 | + */ |
|
291 | + public function deactivateMaintenanceMode() |
|
292 | + { |
|
293 | + DbStatus::setOnline(); |
|
294 | + MaintenanceStatus::disableMaintenanceMode(); |
|
295 | + $this->updateMaintenaceModeStatus(EE_Maintenance_Mode::STATUS_OFF); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + private function updateMaintenaceModeStatus(int $status) |
|
300 | + { |
|
301 | + $this->status = $status; |
|
302 | + $this->setAdminStatus($status); |
|
303 | + if (! $this->update_db) { |
|
304 | + return; |
|
305 | + } |
|
306 | + do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $status); |
|
307 | + update_option(EE_Maintenance_Mode::OPTION_NAME, $status); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
313 | + * |
|
314 | + * @return bool |
|
315 | + */ |
|
316 | + public static function disable_frontend_for_maintenance(): bool |
|
317 | + { |
|
318 | + return ! is_admin() && MaintenanceStatus::isNotDisabled(); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @return void |
|
324 | + */ |
|
325 | + public function load_assets_required_for_m_mode(): void |
|
326 | + { |
|
327 | + if ( |
|
328 | + $this->status === EE_Maintenance_Mode::STATUS_FULL_SITE |
|
329 | + && ! wp_script_is('espresso_core') |
|
330 | + ) { |
|
331 | + wp_register_style( |
|
332 | + 'espresso_default', |
|
333 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
334 | + ['dashicons'], |
|
335 | + EVENT_ESPRESSO_VERSION |
|
336 | + ); |
|
337 | + wp_enqueue_style('espresso_default'); |
|
338 | + wp_register_script( |
|
339 | + 'espresso_core', |
|
340 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
341 | + ['jquery'], |
|
342 | + EVENT_ESPRESSO_VERSION, |
|
343 | + true |
|
344 | + ); |
|
345 | + wp_enqueue_script('espresso_core'); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * replacement EE CPT template that displays message notifying site visitors |
|
352 | + * that EE has been temporarily placed into maintenance mode |
|
353 | + * does NOT get called on non-EE-CPT requests |
|
354 | + * |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public static function template_include(): string |
|
358 | + { |
|
359 | + // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
|
360 | + return get_template_directory() . '/index.php'; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * displays message notifying site visitors that EE has been temporarily |
|
366 | + * placed into maintenance mode when post_type != EE CPT |
|
367 | + * |
|
368 | + * @param string $the_content |
|
369 | + * @return string |
|
370 | + */ |
|
371 | + public function the_content(?string $the_content): ?string |
|
372 | + { |
|
373 | + // check if M-mode is engaged and for EE shortcode |
|
374 | + if ($this->admin_status && strpos((string)$the_content, '[ESPRESSO_') !== false) { |
|
375 | + // this can eventually be moved to a template, or edited via admin. But for now... |
|
376 | + $the_content = sprintf( |
|
377 | + esc_html__( |
|
378 | + '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
379 | + 'event_espresso' |
|
380 | + ), |
|
381 | + '<h3>', |
|
382 | + '</h3><p>', |
|
383 | + '</p>' |
|
384 | + ); |
|
385 | + } |
|
386 | + return $the_content; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
392 | + */ |
|
393 | + public function display_maintenance_mode_notice() |
|
394 | + { |
|
395 | + if ( |
|
396 | + ! $this->current_user_is_admin |
|
397 | + || $this->status === EE_Maintenance_Mode::STATUS_OFF |
|
398 | + || $this->request->isAdmin() |
|
399 | + || $this->request->isAjax() |
|
400 | + || ! did_action('AHEE__EE_System__load_core_configuration__complete') |
|
401 | + ) { |
|
402 | + return; |
|
403 | + } |
|
404 | + /** @var CurrentPage $current_page */ |
|
405 | + $current_page = $this->loader->getShared(CurrentPage::class); |
|
406 | + if ($current_page->isEspressoPage()) { |
|
407 | + printf( |
|
408 | + esc_html__( |
|
409 | + '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
410 | + 'event_espresso' |
|
411 | + ), |
|
412 | + '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
413 | + '"><span class="dashicons dashicons-no"></span></a><p>', |
|
414 | + ' » <a href="' . add_query_arg( |
|
415 | + ['page' => 'espresso_maintenance_settings'], |
|
416 | + admin_url('admin.php') |
|
417 | + ) . '">', |
|
418 | + '</a></p></div>' |
|
419 | + ); |
|
420 | + } |
|
421 | + } |
|
422 | + // espresso-notices important-notice ee-attention |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * Redirects EE admin menu requests to the maintenance page |
|
427 | + */ |
|
428 | + public function redirect_to_maintenance() |
|
429 | + { |
|
430 | + global $pagenow; |
|
431 | + $page = $this->request->getRequestParam('page', '', DataType::STRING); |
|
432 | + if ( |
|
433 | + $pagenow == 'admin.php' |
|
434 | + && $page !== 'espresso_maintenance_settings' |
|
435 | + && strpos($page, 'espresso_') !== false |
|
436 | + && $this->status == EE_Maintenance_Mode::STATUS_FULL_SITE |
|
437 | + ) { |
|
438 | + EEH_URL::safeRedirectAndExit('admin.php?page=espresso_maintenance_settings'); |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * override magic methods |
|
445 | + */ |
|
446 | + final public function __destruct() |
|
447 | + { |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + final public function __call($a, $b) |
|
452 | + { |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + final public function __get($a) |
|
457 | + { |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + final public function __set($a, $b) |
|
462 | + { |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + final public function __isset($a) |
|
467 | + { |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + final public function __unset($a) |
|
472 | + { |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + final public function __sleep() |
|
477 | + { |
|
478 | + return []; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + final public function __wakeup() |
|
483 | + { |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + final public function __invoke() |
|
488 | + { |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + final public static function __set_state($a = null) |
|
493 | + { |
|
494 | + return EE_Maintenance_Mode::instance(); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + final public function __clone() |
|
499 | + { |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + final public static function __callStatic($a, $b) |
|
504 | + { |
|
505 | + } |
|
506 | 506 | |
507 | 507 | |
508 | - /************************ @DEPRECATED ********************** */ |
|
508 | + /************************ @DEPRECATED ********************** */ |
|
509 | 509 | |
510 | - /** |
|
511 | - * @depecated 5.0.12.p |
|
512 | - */ |
|
513 | - const level_0_not_in_maintenance = 0; |
|
510 | + /** |
|
511 | + * @depecated 5.0.12.p |
|
512 | + */ |
|
513 | + const level_0_not_in_maintenance = 0; |
|
514 | 514 | |
515 | - /** |
|
516 | - * @depecated 5.0.12.p |
|
517 | - */ |
|
518 | - const level_1_frontend_only_maintenance = 1; |
|
515 | + /** |
|
516 | + * @depecated 5.0.12.p |
|
517 | + */ |
|
518 | + const level_1_frontend_only_maintenance = 1; |
|
519 | 519 | |
520 | - /** |
|
521 | - * @depecated 5.0.12.p |
|
522 | - */ |
|
523 | - const level_2_complete_maintenance = 2; |
|
520 | + /** |
|
521 | + * @depecated 5.0.12.p |
|
522 | + */ |
|
523 | + const level_2_complete_maintenance = 2; |
|
524 | 524 | |
525 | - /** |
|
526 | - * @depecated 5.0.12.p |
|
527 | - */ |
|
528 | - const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
525 | + /** |
|
526 | + * @depecated 5.0.12.p |
|
527 | + */ |
|
528 | + const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
529 | 529 | |
530 | 530 | |
531 | - /** |
|
532 | - * Returns whether the models reportedly are able to run queries or not |
|
533 | - * (ie, if the system thinks their tables are present and up-to-date). |
|
534 | - * |
|
535 | - * @return boolean |
|
536 | - * @depecated 5.0.12.p |
|
537 | - */ |
|
538 | - public function models_can_query(): bool |
|
539 | - { |
|
540 | - return DbStatus::isOnline(); |
|
541 | - } |
|
531 | + /** |
|
532 | + * Returns whether the models reportedly are able to run queries or not |
|
533 | + * (ie, if the system thinks their tables are present and up-to-date). |
|
534 | + * |
|
535 | + * @return boolean |
|
536 | + * @depecated 5.0.12.p |
|
537 | + */ |
|
538 | + public function models_can_query(): bool |
|
539 | + { |
|
540 | + return DbStatus::isOnline(); |
|
541 | + } |
|
542 | 542 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | ?RequestInterface $request = null |
92 | 92 | ): ?EE_Maintenance_Mode { |
93 | 93 | // check if class object is instantiated |
94 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
94 | + if ( ! self::$_instance instanceof EE_Maintenance_Mode) { |
|
95 | 95 | self::$_instance = new EE_Maintenance_Mode($loader, $request); |
96 | 96 | } |
97 | 97 | return self::$_instance; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | /** @var EE_Data_Migration_Manager $data_migration_manager */ |
202 | 202 | $data_migration_manager = $this->loader->getShared(EE_Data_Migration_Manager::class); |
203 | 203 | $scripts_that_should_run = $data_migration_manager->check_for_applicable_data_migration_scripts(); |
204 | - if (! empty($scripts_that_should_run)) { // && $this->status !== EE_Maintenance_Mode::STATUS_FULL_SITE |
|
204 | + if ( ! empty($scripts_that_should_run)) { // && $this->status !== EE_Maintenance_Mode::STATUS_FULL_SITE |
|
205 | 205 | $this->activateFullSiteMaintenanceMode(); |
206 | 206 | return true; |
207 | 207 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | { |
301 | 301 | $this->status = $status; |
302 | 302 | $this->setAdminStatus($status); |
303 | - if (! $this->update_db) { |
|
303 | + if ( ! $this->update_db) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | 306 | do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $status); |
@@ -330,14 +330,14 @@ discard block |
||
330 | 330 | ) { |
331 | 331 | wp_register_style( |
332 | 332 | 'espresso_default', |
333 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
333 | + EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
334 | 334 | ['dashicons'], |
335 | 335 | EVENT_ESPRESSO_VERSION |
336 | 336 | ); |
337 | 337 | wp_enqueue_style('espresso_default'); |
338 | 338 | wp_register_script( |
339 | 339 | 'espresso_core', |
340 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
340 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
341 | 341 | ['jquery'], |
342 | 342 | EVENT_ESPRESSO_VERSION, |
343 | 343 | true |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | public static function template_include(): string |
358 | 358 | { |
359 | 359 | // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
360 | - return get_template_directory() . '/index.php'; |
|
360 | + return get_template_directory().'/index.php'; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | public function the_content(?string $the_content): ?string |
372 | 372 | { |
373 | 373 | // check if M-mode is engaged and for EE shortcode |
374 | - if ($this->admin_status && strpos((string)$the_content, '[ESPRESSO_') !== false) { |
|
374 | + if ($this->admin_status && strpos((string) $the_content, '[ESPRESSO_') !== false) { |
|
375 | 375 | // this can eventually be moved to a template, or edited via admin. But for now... |
376 | 376 | $the_content = sprintf( |
377 | 377 | esc_html__( |
@@ -411,10 +411,10 @@ discard block |
||
411 | 411 | ), |
412 | 412 | '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
413 | 413 | '"><span class="dashicons dashicons-no"></span></a><p>', |
414 | - ' » <a href="' . add_query_arg( |
|
414 | + ' » <a href="'.add_query_arg( |
|
415 | 415 | ['page' => 'espresso_maintenance_settings'], |
416 | 416 | admin_url('admin.php') |
417 | - ) . '">', |
|
417 | + ).'">', |
|
418 | 418 | '</a></p></div>' |
419 | 419 | ); |
420 | 420 | } |
@@ -23,417 +23,417 @@ |
||
23 | 23 | */ |
24 | 24 | class QueryBuilder |
25 | 25 | { |
26 | - protected RequestInterface $request; |
|
27 | - |
|
28 | - protected EEM_Registration $registration_model; |
|
29 | - |
|
30 | - protected array $filters; |
|
31 | - |
|
32 | - protected string $view; |
|
33 | - |
|
34 | - protected array $where_params; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * QueryBuilder constructor. |
|
39 | - * |
|
40 | - * @param RequestInterface $request |
|
41 | - * @param EEM_Registration $registration_model |
|
42 | - * @param array $extra_request_params |
|
43 | - */ |
|
44 | - public function __construct( |
|
45 | - RequestInterface $request, |
|
46 | - EEM_Registration $registration_model, |
|
47 | - array $extra_request_params = [] |
|
48 | - ) { |
|
49 | - $this->request = $request; |
|
50 | - $this->filters = $this->request->getRequestParam('filters', [], DataType::STRING, true); |
|
51 | - $this->registration_model = $registration_model; |
|
52 | - foreach ($extra_request_params as $key => $value) { |
|
53 | - if (! $this->request->requestParamIsSet($key)) { |
|
54 | - $this->request->setRequestParam($key, $value); |
|
55 | - } |
|
56 | - } |
|
57 | - $this->view = $this->request->getRequestParam('status', ''); |
|
58 | - $this->where_params = []; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Sets up the where conditions for the registrations query. |
|
64 | - * |
|
65 | - * @param int $per_page |
|
66 | - * @param bool $count_query |
|
67 | - * @return array |
|
68 | - * @throws EE_Error |
|
69 | - * @throws InvalidArgumentException |
|
70 | - * @throws InvalidDataTypeException |
|
71 | - * @throws InvalidInterfaceException |
|
72 | - */ |
|
73 | - public function getQueryParams(int $per_page = 10, bool $count_query = false): array |
|
74 | - { |
|
75 | - $query_params = [ |
|
76 | - 0 => $this->getWhereClause(), |
|
77 | - 'caps' => EEM_Base::caps_read_admin, |
|
78 | - 'default_where_conditions' => 'this_model_only', |
|
79 | - ]; |
|
80 | - if (! $count_query) { |
|
81 | - $query_params = array_merge( |
|
82 | - $query_params, |
|
83 | - $this->getOrderbyClause(), |
|
84 | - $this->getLimitClause($per_page) |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - return $query_params; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Sets up the where conditions for the registrations query. |
|
94 | - * |
|
95 | - * @return array |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - */ |
|
101 | - protected function getWhereClause(): array |
|
102 | - { |
|
103 | - $this->addAttendeeIdToWhereConditions(); |
|
104 | - $this->addEventIdToWhereConditions(); |
|
105 | - $this->addCategoryIdToWhereConditions(); |
|
106 | - $this->addDatetimeIdToWhereConditions(); |
|
107 | - $this->addTicketIdToWhereConditions(); |
|
108 | - $this->addRegistrationStatusToWhereConditions(); |
|
109 | - $this->addDateToWhereConditions(); |
|
110 | - $this->addSearchToWhereConditions(); |
|
111 | - return apply_filters( |
|
112 | - 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
113 | - $this->where_params, |
|
114 | - $this->request->requestParams() |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters. |
|
121 | - */ |
|
122 | - protected function addAttendeeIdToWhereConditions() |
|
123 | - { |
|
124 | - $ATT_ID = $this->request->getRequestParam('attendee_id'); |
|
125 | - $ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID, 'int'); |
|
126 | - if ($ATT_ID) { |
|
127 | - $this->where_params['ATT_ID'] = $ATT_ID; |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters. |
|
134 | - */ |
|
135 | - protected function addEventIdToWhereConditions() |
|
136 | - { |
|
137 | - $EVT_ID = $this->request->getRequestParam('event_id'); |
|
138 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, 'int'); |
|
139 | - if ($EVT_ID) { |
|
140 | - $this->where_params['EVT_ID'] = $EVT_ID; |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
147 | - */ |
|
148 | - protected function addCategoryIdToWhereConditions() |
|
149 | - { |
|
150 | - $EVT_CAT = $this->request->getRequestParam('EVT_CAT', 0, DataType::INTEGER); |
|
151 | - $EVT_CAT = $this->filters['EVT_CAT'] ?? $EVT_CAT; |
|
152 | - $EVT_CAT = (int) $EVT_CAT; |
|
153 | - if ($EVT_CAT > 0) { |
|
154 | - $this->where_params['Event.Term_Taxonomy.term_id'] = $EVT_CAT; |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
161 | - */ |
|
162 | - protected function addDatetimeIdToWhereConditions() |
|
163 | - { |
|
164 | - // first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value |
|
165 | - $DTT_ID = $this->request->getRequestParam('datetime_id'); |
|
166 | - $DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID, DataType::INTEGER); |
|
167 | - $DTT_ID = $this->filters['datetime_id'] ?? $DTT_ID; |
|
168 | - $DTT_ID = (int) $DTT_ID; |
|
169 | - |
|
170 | - if ($DTT_ID) { |
|
171 | - $this->where_params['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Adds the ticket ID if it exists in the request to the where conditions for the registrations query. |
|
178 | - */ |
|
179 | - protected function addTicketIdToWhereConditions() |
|
180 | - { |
|
181 | - // first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value |
|
182 | - $TKT_ID = $this->request->getRequestParam('ticket_id'); |
|
183 | - $TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID, DataType::INTEGER); |
|
184 | - $TKT_ID = $this->filters['ticket_id'] ?? $TKT_ID; |
|
185 | - $TKT_ID = (int) $TKT_ID; |
|
186 | - |
|
187 | - if ($TKT_ID) { |
|
188 | - $this->where_params['TKT_ID'] = $TKT_ID; |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Adds the correct registration status to the where conditions for the registrations query. |
|
195 | - * If filtering by registration status, then we show registrations matching that status. |
|
196 | - * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
|
197 | - * UNLESS viewing trashed registrations. |
|
198 | - */ |
|
199 | - protected function addRegistrationStatusToWhereConditions() |
|
200 | - { |
|
201 | - $registration_status = $this->request->getRequestParam('_reg_status'); |
|
202 | - $registration_status = $this->filters['_reg_status'] ?? $registration_status; |
|
203 | - if ($registration_status) { |
|
204 | - $this->where_params['STS_ID'] = sanitize_text_field($registration_status); |
|
205 | - return; |
|
206 | - } |
|
207 | - // make sure we exclude incomplete registrations, but only if not trashed. |
|
208 | - if ($this->view === 'trash') { |
|
209 | - $this->where_params['REG_deleted'] = true; |
|
210 | - return; |
|
211 | - } |
|
212 | - $this->where_params['STS_ID'] = $this->view === 'incomplete' |
|
213 | - ? RegStatus::INCOMPLETE |
|
214 | - : ['!=', RegStatus::INCOMPLETE]; |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Adds any provided date restraints to the where conditions for the registrations query. |
|
220 | - * |
|
221 | - * @throws EE_Error |
|
222 | - * @throws InvalidArgumentException |
|
223 | - * @throws InvalidDataTypeException |
|
224 | - * @throws InvalidInterfaceException |
|
225 | - */ |
|
226 | - protected function addDateToWhereConditions() |
|
227 | - { |
|
228 | - $current_time = current_time('timestamp'); |
|
229 | - $timezone_string = EEH_DTT_Helper::get_timezone(); |
|
230 | - if ($this->view === 'today') { |
|
231 | - $now = date('Y-m-d', $current_time); |
|
232 | - $this->where_params['REG_date'] = [ |
|
233 | - 'BETWEEN', |
|
234 | - [ |
|
235 | - $this->registration_model->convert_datetime_for_query( |
|
236 | - 'REG_date', |
|
237 | - $now . ' 00:00:00', |
|
238 | - 'Y-m-d H:i:s', |
|
239 | - $timezone_string |
|
240 | - ), |
|
241 | - $this->registration_model->convert_datetime_for_query( |
|
242 | - 'REG_date', |
|
243 | - $now . ' 23:59:59', |
|
244 | - 'Y-m-d H:i:s', |
|
245 | - $timezone_string |
|
246 | - ), |
|
247 | - ], |
|
248 | - ]; |
|
249 | - return; |
|
250 | - } |
|
251 | - if ($this->view === 'yesterday') { |
|
252 | - $yesterday = date('Y-m-d', $current_time - DAY_IN_SECONDS); |
|
253 | - $this->where_params['REG_date'] = [ |
|
254 | - 'BETWEEN', |
|
255 | - [ |
|
256 | - $this->registration_model->convert_datetime_for_query( |
|
257 | - 'REG_date', |
|
258 | - $yesterday . ' 00:00:00', |
|
259 | - 'Y-m-d H:i:s', |
|
260 | - $timezone_string |
|
261 | - ), |
|
262 | - $this->registration_model->convert_datetime_for_query( |
|
263 | - 'REG_date', |
|
264 | - $yesterday . ' 23:59:59', |
|
265 | - 'Y-m-d H:i:s', |
|
266 | - $timezone_string |
|
267 | - ), |
|
268 | - ], |
|
269 | - ]; |
|
270 | - return; |
|
271 | - } |
|
272 | - if ($this->view === 'month') { |
|
273 | - $current_year_and_month = date('Y-m', $current_time); |
|
274 | - $days_this_month = date('t', $current_time); |
|
275 | - $this->where_params['REG_date'] = [ |
|
276 | - 'BETWEEN', |
|
277 | - [ |
|
278 | - $this->registration_model->convert_datetime_for_query( |
|
279 | - 'REG_date', |
|
280 | - $current_year_and_month . '-01 00:00:00', |
|
281 | - 'Y-m-d H:i:s', |
|
282 | - $timezone_string |
|
283 | - ), |
|
284 | - $this->registration_model->convert_datetime_for_query( |
|
285 | - 'REG_date', |
|
286 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
287 | - 'Y-m-d H:i:s', |
|
288 | - $timezone_string |
|
289 | - ), |
|
290 | - ], |
|
291 | - ]; |
|
292 | - return; |
|
293 | - } |
|
294 | - $month_range = $this->request->getRequestParam('month_range'); |
|
295 | - $month_range = $this->filters['month_range'] ?? $month_range; |
|
296 | - if ($month_range) { |
|
297 | - $month_range = sanitize_text_field($month_range); |
|
298 | - $pieces = explode(' ', $month_range, 3); |
|
299 | - $month_requested = ! empty($pieces[0]) |
|
300 | - ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
301 | - : ''; |
|
302 | - $year_requested = ! empty($pieces[1]) |
|
303 | - ? $pieces[1] |
|
304 | - : ''; |
|
305 | - // if there is not a month or year then we can't go further |
|
306 | - if ($month_requested && $year_requested) { |
|
307 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
308 | - $this->where_params['REG_date'] = [ |
|
309 | - 'BETWEEN', |
|
310 | - [ |
|
311 | - $this->registration_model->convert_datetime_for_query( |
|
312 | - 'REG_date', |
|
313 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
314 | - 'Y-m-d H:i:s', |
|
315 | - $timezone_string |
|
316 | - ), |
|
317 | - $this->registration_model->convert_datetime_for_query( |
|
318 | - 'REG_date', |
|
319 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
320 | - 'Y-m-d H:i:s', |
|
321 | - $timezone_string |
|
322 | - ), |
|
323 | - ], |
|
324 | - ]; |
|
325 | - } |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Adds any provided search restraints to the where conditions for the registrations query |
|
332 | - */ |
|
333 | - protected function addSearchToWhereConditions() |
|
334 | - { |
|
335 | - $search = $this->request->getRequestParam('s'); |
|
336 | - if ($search) { |
|
337 | - $search_string = '%' . sanitize_text_field($search) . '%'; |
|
338 | - $this->where_params['OR*search_conditions'] = [ |
|
339 | - 'Event.EVT_name' => ['LIKE', $search_string], |
|
340 | - 'Event.EVT_desc' => ['LIKE', $search_string], |
|
341 | - 'Event.EVT_short_desc' => ['LIKE', $search_string], |
|
342 | - 'Attendee.ATT_full_name' => ['LIKE', $search_string], |
|
343 | - 'Attendee.ATT_fname' => ['LIKE', $search_string], |
|
344 | - 'Attendee.ATT_lname' => ['LIKE', $search_string], |
|
345 | - 'Attendee.ATT_short_bio' => ['LIKE', $search_string], |
|
346 | - 'Attendee.ATT_email' => ['LIKE', $search_string], |
|
347 | - 'Attendee.ATT_address' => ['LIKE', $search_string], |
|
348 | - 'Attendee.ATT_address2' => ['LIKE', $search_string], |
|
349 | - 'Attendee.ATT_city' => ['LIKE', $search_string], |
|
350 | - 'REG_ID' => ['LIKE', $search_string], |
|
351 | - 'REG_final_price' => ['LIKE', $search_string], |
|
352 | - 'REG_code' => ['LIKE', $search_string], |
|
353 | - 'REG_count' => ['LIKE', $search_string], |
|
354 | - 'REG_group_size' => ['LIKE', $search_string], |
|
355 | - 'Ticket.TKT_name' => ['LIKE', $search_string], |
|
356 | - 'Ticket.TKT_description' => ['LIKE', $search_string], |
|
357 | - 'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string], |
|
358 | - ]; |
|
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * Sets up the orderby for the registrations query. |
|
365 | - * |
|
366 | - * @return array |
|
367 | - */ |
|
368 | - protected function getOrderbyClause(): array |
|
369 | - { |
|
370 | - $orderby_field = $this->request->getRequestParam('orderby'); |
|
371 | - $orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date'; |
|
372 | - switch ($orderby_field) { |
|
373 | - case '_REG_ID': |
|
374 | - $orderby = ['REG_ID']; |
|
375 | - break; |
|
376 | - case '_Reg_status': |
|
377 | - $orderby = ['STS_ID']; |
|
378 | - break; |
|
379 | - case 'ATT_fname': |
|
380 | - $orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname']; |
|
381 | - break; |
|
382 | - case 'ATT_lname': |
|
383 | - $orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname']; |
|
384 | - break; |
|
385 | - case 'event_name': |
|
386 | - $orderby = ['Event.EVT_name']; |
|
387 | - break; |
|
388 | - case 'DTT_EVT_start': |
|
389 | - $orderby = ['Event.Datetime.DTT_EVT_start']; |
|
390 | - break; |
|
391 | - case '_REG_date': |
|
392 | - $orderby = ['REG_date']; |
|
393 | - break; |
|
394 | - default: |
|
395 | - $orderby = [$orderby_field]; |
|
396 | - break; |
|
397 | - } |
|
398 | - $order = $this->request->getRequestParam('order'); |
|
399 | - $order = $order ? sanitize_text_field($order) : 'DESC'; |
|
400 | - |
|
401 | - $orderby = array_combine( |
|
402 | - $orderby, |
|
403 | - array_fill(0, count($orderby), $order) |
|
404 | - ); |
|
405 | - // always add REG_count to the orderby array |
|
406 | - $orderby['REG_count'] = 'ASC'; |
|
407 | - // because there are many registrations with the same date, define |
|
408 | - // a secondary way to order them, otherwise MySQL seems to be a bit random |
|
409 | - if (empty($orderby['REG_ID'])) { |
|
410 | - $orderby['REG_ID'] = $order; |
|
411 | - } |
|
412 | - |
|
413 | - $orderby = apply_filters( |
|
414 | - 'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query', |
|
415 | - $orderby, |
|
416 | - $this->request->requestParams() |
|
417 | - ); |
|
418 | - return ['order_by' => $orderby]; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Sets up the limit for the registrations query. |
|
424 | - * |
|
425 | - * @param int $per_page |
|
426 | - * @return array |
|
427 | - */ |
|
428 | - protected function getLimitClause(int $per_page): array |
|
429 | - { |
|
430 | - $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
431 | - $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
432 | - // -1 means return all results so get out if that's set. |
|
433 | - if ($per_page === -1) { |
|
434 | - return []; |
|
435 | - } |
|
436 | - $offset = ($current_page - 1) * $per_page; |
|
437 | - return ['limit' => [$offset, $per_page]]; |
|
438 | - } |
|
26 | + protected RequestInterface $request; |
|
27 | + |
|
28 | + protected EEM_Registration $registration_model; |
|
29 | + |
|
30 | + protected array $filters; |
|
31 | + |
|
32 | + protected string $view; |
|
33 | + |
|
34 | + protected array $where_params; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * QueryBuilder constructor. |
|
39 | + * |
|
40 | + * @param RequestInterface $request |
|
41 | + * @param EEM_Registration $registration_model |
|
42 | + * @param array $extra_request_params |
|
43 | + */ |
|
44 | + public function __construct( |
|
45 | + RequestInterface $request, |
|
46 | + EEM_Registration $registration_model, |
|
47 | + array $extra_request_params = [] |
|
48 | + ) { |
|
49 | + $this->request = $request; |
|
50 | + $this->filters = $this->request->getRequestParam('filters', [], DataType::STRING, true); |
|
51 | + $this->registration_model = $registration_model; |
|
52 | + foreach ($extra_request_params as $key => $value) { |
|
53 | + if (! $this->request->requestParamIsSet($key)) { |
|
54 | + $this->request->setRequestParam($key, $value); |
|
55 | + } |
|
56 | + } |
|
57 | + $this->view = $this->request->getRequestParam('status', ''); |
|
58 | + $this->where_params = []; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Sets up the where conditions for the registrations query. |
|
64 | + * |
|
65 | + * @param int $per_page |
|
66 | + * @param bool $count_query |
|
67 | + * @return array |
|
68 | + * @throws EE_Error |
|
69 | + * @throws InvalidArgumentException |
|
70 | + * @throws InvalidDataTypeException |
|
71 | + * @throws InvalidInterfaceException |
|
72 | + */ |
|
73 | + public function getQueryParams(int $per_page = 10, bool $count_query = false): array |
|
74 | + { |
|
75 | + $query_params = [ |
|
76 | + 0 => $this->getWhereClause(), |
|
77 | + 'caps' => EEM_Base::caps_read_admin, |
|
78 | + 'default_where_conditions' => 'this_model_only', |
|
79 | + ]; |
|
80 | + if (! $count_query) { |
|
81 | + $query_params = array_merge( |
|
82 | + $query_params, |
|
83 | + $this->getOrderbyClause(), |
|
84 | + $this->getLimitClause($per_page) |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + return $query_params; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Sets up the where conditions for the registrations query. |
|
94 | + * |
|
95 | + * @return array |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + */ |
|
101 | + protected function getWhereClause(): array |
|
102 | + { |
|
103 | + $this->addAttendeeIdToWhereConditions(); |
|
104 | + $this->addEventIdToWhereConditions(); |
|
105 | + $this->addCategoryIdToWhereConditions(); |
|
106 | + $this->addDatetimeIdToWhereConditions(); |
|
107 | + $this->addTicketIdToWhereConditions(); |
|
108 | + $this->addRegistrationStatusToWhereConditions(); |
|
109 | + $this->addDateToWhereConditions(); |
|
110 | + $this->addSearchToWhereConditions(); |
|
111 | + return apply_filters( |
|
112 | + 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
113 | + $this->where_params, |
|
114 | + $this->request->requestParams() |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters. |
|
121 | + */ |
|
122 | + protected function addAttendeeIdToWhereConditions() |
|
123 | + { |
|
124 | + $ATT_ID = $this->request->getRequestParam('attendee_id'); |
|
125 | + $ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID, 'int'); |
|
126 | + if ($ATT_ID) { |
|
127 | + $this->where_params['ATT_ID'] = $ATT_ID; |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters. |
|
134 | + */ |
|
135 | + protected function addEventIdToWhereConditions() |
|
136 | + { |
|
137 | + $EVT_ID = $this->request->getRequestParam('event_id'); |
|
138 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, 'int'); |
|
139 | + if ($EVT_ID) { |
|
140 | + $this->where_params['EVT_ID'] = $EVT_ID; |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
147 | + */ |
|
148 | + protected function addCategoryIdToWhereConditions() |
|
149 | + { |
|
150 | + $EVT_CAT = $this->request->getRequestParam('EVT_CAT', 0, DataType::INTEGER); |
|
151 | + $EVT_CAT = $this->filters['EVT_CAT'] ?? $EVT_CAT; |
|
152 | + $EVT_CAT = (int) $EVT_CAT; |
|
153 | + if ($EVT_CAT > 0) { |
|
154 | + $this->where_params['Event.Term_Taxonomy.term_id'] = $EVT_CAT; |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
161 | + */ |
|
162 | + protected function addDatetimeIdToWhereConditions() |
|
163 | + { |
|
164 | + // first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value |
|
165 | + $DTT_ID = $this->request->getRequestParam('datetime_id'); |
|
166 | + $DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID, DataType::INTEGER); |
|
167 | + $DTT_ID = $this->filters['datetime_id'] ?? $DTT_ID; |
|
168 | + $DTT_ID = (int) $DTT_ID; |
|
169 | + |
|
170 | + if ($DTT_ID) { |
|
171 | + $this->where_params['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Adds the ticket ID if it exists in the request to the where conditions for the registrations query. |
|
178 | + */ |
|
179 | + protected function addTicketIdToWhereConditions() |
|
180 | + { |
|
181 | + // first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value |
|
182 | + $TKT_ID = $this->request->getRequestParam('ticket_id'); |
|
183 | + $TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID, DataType::INTEGER); |
|
184 | + $TKT_ID = $this->filters['ticket_id'] ?? $TKT_ID; |
|
185 | + $TKT_ID = (int) $TKT_ID; |
|
186 | + |
|
187 | + if ($TKT_ID) { |
|
188 | + $this->where_params['TKT_ID'] = $TKT_ID; |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Adds the correct registration status to the where conditions for the registrations query. |
|
195 | + * If filtering by registration status, then we show registrations matching that status. |
|
196 | + * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
|
197 | + * UNLESS viewing trashed registrations. |
|
198 | + */ |
|
199 | + protected function addRegistrationStatusToWhereConditions() |
|
200 | + { |
|
201 | + $registration_status = $this->request->getRequestParam('_reg_status'); |
|
202 | + $registration_status = $this->filters['_reg_status'] ?? $registration_status; |
|
203 | + if ($registration_status) { |
|
204 | + $this->where_params['STS_ID'] = sanitize_text_field($registration_status); |
|
205 | + return; |
|
206 | + } |
|
207 | + // make sure we exclude incomplete registrations, but only if not trashed. |
|
208 | + if ($this->view === 'trash') { |
|
209 | + $this->where_params['REG_deleted'] = true; |
|
210 | + return; |
|
211 | + } |
|
212 | + $this->where_params['STS_ID'] = $this->view === 'incomplete' |
|
213 | + ? RegStatus::INCOMPLETE |
|
214 | + : ['!=', RegStatus::INCOMPLETE]; |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Adds any provided date restraints to the where conditions for the registrations query. |
|
220 | + * |
|
221 | + * @throws EE_Error |
|
222 | + * @throws InvalidArgumentException |
|
223 | + * @throws InvalidDataTypeException |
|
224 | + * @throws InvalidInterfaceException |
|
225 | + */ |
|
226 | + protected function addDateToWhereConditions() |
|
227 | + { |
|
228 | + $current_time = current_time('timestamp'); |
|
229 | + $timezone_string = EEH_DTT_Helper::get_timezone(); |
|
230 | + if ($this->view === 'today') { |
|
231 | + $now = date('Y-m-d', $current_time); |
|
232 | + $this->where_params['REG_date'] = [ |
|
233 | + 'BETWEEN', |
|
234 | + [ |
|
235 | + $this->registration_model->convert_datetime_for_query( |
|
236 | + 'REG_date', |
|
237 | + $now . ' 00:00:00', |
|
238 | + 'Y-m-d H:i:s', |
|
239 | + $timezone_string |
|
240 | + ), |
|
241 | + $this->registration_model->convert_datetime_for_query( |
|
242 | + 'REG_date', |
|
243 | + $now . ' 23:59:59', |
|
244 | + 'Y-m-d H:i:s', |
|
245 | + $timezone_string |
|
246 | + ), |
|
247 | + ], |
|
248 | + ]; |
|
249 | + return; |
|
250 | + } |
|
251 | + if ($this->view === 'yesterday') { |
|
252 | + $yesterday = date('Y-m-d', $current_time - DAY_IN_SECONDS); |
|
253 | + $this->where_params['REG_date'] = [ |
|
254 | + 'BETWEEN', |
|
255 | + [ |
|
256 | + $this->registration_model->convert_datetime_for_query( |
|
257 | + 'REG_date', |
|
258 | + $yesterday . ' 00:00:00', |
|
259 | + 'Y-m-d H:i:s', |
|
260 | + $timezone_string |
|
261 | + ), |
|
262 | + $this->registration_model->convert_datetime_for_query( |
|
263 | + 'REG_date', |
|
264 | + $yesterday . ' 23:59:59', |
|
265 | + 'Y-m-d H:i:s', |
|
266 | + $timezone_string |
|
267 | + ), |
|
268 | + ], |
|
269 | + ]; |
|
270 | + return; |
|
271 | + } |
|
272 | + if ($this->view === 'month') { |
|
273 | + $current_year_and_month = date('Y-m', $current_time); |
|
274 | + $days_this_month = date('t', $current_time); |
|
275 | + $this->where_params['REG_date'] = [ |
|
276 | + 'BETWEEN', |
|
277 | + [ |
|
278 | + $this->registration_model->convert_datetime_for_query( |
|
279 | + 'REG_date', |
|
280 | + $current_year_and_month . '-01 00:00:00', |
|
281 | + 'Y-m-d H:i:s', |
|
282 | + $timezone_string |
|
283 | + ), |
|
284 | + $this->registration_model->convert_datetime_for_query( |
|
285 | + 'REG_date', |
|
286 | + $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
287 | + 'Y-m-d H:i:s', |
|
288 | + $timezone_string |
|
289 | + ), |
|
290 | + ], |
|
291 | + ]; |
|
292 | + return; |
|
293 | + } |
|
294 | + $month_range = $this->request->getRequestParam('month_range'); |
|
295 | + $month_range = $this->filters['month_range'] ?? $month_range; |
|
296 | + if ($month_range) { |
|
297 | + $month_range = sanitize_text_field($month_range); |
|
298 | + $pieces = explode(' ', $month_range, 3); |
|
299 | + $month_requested = ! empty($pieces[0]) |
|
300 | + ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
301 | + : ''; |
|
302 | + $year_requested = ! empty($pieces[1]) |
|
303 | + ? $pieces[1] |
|
304 | + : ''; |
|
305 | + // if there is not a month or year then we can't go further |
|
306 | + if ($month_requested && $year_requested) { |
|
307 | + $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
308 | + $this->where_params['REG_date'] = [ |
|
309 | + 'BETWEEN', |
|
310 | + [ |
|
311 | + $this->registration_model->convert_datetime_for_query( |
|
312 | + 'REG_date', |
|
313 | + $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
314 | + 'Y-m-d H:i:s', |
|
315 | + $timezone_string |
|
316 | + ), |
|
317 | + $this->registration_model->convert_datetime_for_query( |
|
318 | + 'REG_date', |
|
319 | + $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
320 | + 'Y-m-d H:i:s', |
|
321 | + $timezone_string |
|
322 | + ), |
|
323 | + ], |
|
324 | + ]; |
|
325 | + } |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Adds any provided search restraints to the where conditions for the registrations query |
|
332 | + */ |
|
333 | + protected function addSearchToWhereConditions() |
|
334 | + { |
|
335 | + $search = $this->request->getRequestParam('s'); |
|
336 | + if ($search) { |
|
337 | + $search_string = '%' . sanitize_text_field($search) . '%'; |
|
338 | + $this->where_params['OR*search_conditions'] = [ |
|
339 | + 'Event.EVT_name' => ['LIKE', $search_string], |
|
340 | + 'Event.EVT_desc' => ['LIKE', $search_string], |
|
341 | + 'Event.EVT_short_desc' => ['LIKE', $search_string], |
|
342 | + 'Attendee.ATT_full_name' => ['LIKE', $search_string], |
|
343 | + 'Attendee.ATT_fname' => ['LIKE', $search_string], |
|
344 | + 'Attendee.ATT_lname' => ['LIKE', $search_string], |
|
345 | + 'Attendee.ATT_short_bio' => ['LIKE', $search_string], |
|
346 | + 'Attendee.ATT_email' => ['LIKE', $search_string], |
|
347 | + 'Attendee.ATT_address' => ['LIKE', $search_string], |
|
348 | + 'Attendee.ATT_address2' => ['LIKE', $search_string], |
|
349 | + 'Attendee.ATT_city' => ['LIKE', $search_string], |
|
350 | + 'REG_ID' => ['LIKE', $search_string], |
|
351 | + 'REG_final_price' => ['LIKE', $search_string], |
|
352 | + 'REG_code' => ['LIKE', $search_string], |
|
353 | + 'REG_count' => ['LIKE', $search_string], |
|
354 | + 'REG_group_size' => ['LIKE', $search_string], |
|
355 | + 'Ticket.TKT_name' => ['LIKE', $search_string], |
|
356 | + 'Ticket.TKT_description' => ['LIKE', $search_string], |
|
357 | + 'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string], |
|
358 | + ]; |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * Sets up the orderby for the registrations query. |
|
365 | + * |
|
366 | + * @return array |
|
367 | + */ |
|
368 | + protected function getOrderbyClause(): array |
|
369 | + { |
|
370 | + $orderby_field = $this->request->getRequestParam('orderby'); |
|
371 | + $orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date'; |
|
372 | + switch ($orderby_field) { |
|
373 | + case '_REG_ID': |
|
374 | + $orderby = ['REG_ID']; |
|
375 | + break; |
|
376 | + case '_Reg_status': |
|
377 | + $orderby = ['STS_ID']; |
|
378 | + break; |
|
379 | + case 'ATT_fname': |
|
380 | + $orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname']; |
|
381 | + break; |
|
382 | + case 'ATT_lname': |
|
383 | + $orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname']; |
|
384 | + break; |
|
385 | + case 'event_name': |
|
386 | + $orderby = ['Event.EVT_name']; |
|
387 | + break; |
|
388 | + case 'DTT_EVT_start': |
|
389 | + $orderby = ['Event.Datetime.DTT_EVT_start']; |
|
390 | + break; |
|
391 | + case '_REG_date': |
|
392 | + $orderby = ['REG_date']; |
|
393 | + break; |
|
394 | + default: |
|
395 | + $orderby = [$orderby_field]; |
|
396 | + break; |
|
397 | + } |
|
398 | + $order = $this->request->getRequestParam('order'); |
|
399 | + $order = $order ? sanitize_text_field($order) : 'DESC'; |
|
400 | + |
|
401 | + $orderby = array_combine( |
|
402 | + $orderby, |
|
403 | + array_fill(0, count($orderby), $order) |
|
404 | + ); |
|
405 | + // always add REG_count to the orderby array |
|
406 | + $orderby['REG_count'] = 'ASC'; |
|
407 | + // because there are many registrations with the same date, define |
|
408 | + // a secondary way to order them, otherwise MySQL seems to be a bit random |
|
409 | + if (empty($orderby['REG_ID'])) { |
|
410 | + $orderby['REG_ID'] = $order; |
|
411 | + } |
|
412 | + |
|
413 | + $orderby = apply_filters( |
|
414 | + 'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query', |
|
415 | + $orderby, |
|
416 | + $this->request->requestParams() |
|
417 | + ); |
|
418 | + return ['order_by' => $orderby]; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Sets up the limit for the registrations query. |
|
424 | + * |
|
425 | + * @param int $per_page |
|
426 | + * @return array |
|
427 | + */ |
|
428 | + protected function getLimitClause(int $per_page): array |
|
429 | + { |
|
430 | + $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
431 | + $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
432 | + // -1 means return all results so get out if that's set. |
|
433 | + if ($per_page === -1) { |
|
434 | + return []; |
|
435 | + } |
|
436 | + $offset = ($current_page - 1) * $per_page; |
|
437 | + return ['limit' => [$offset, $per_page]]; |
|
438 | + } |
|
439 | 439 | } |
@@ -15,233 +15,233 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Attendee_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - /** |
|
19 | - * hold all extra data. |
|
20 | - * |
|
21 | - * @var array|stdClass|null |
|
22 | - */ |
|
23 | - protected $_extra; |
|
24 | - |
|
25 | - |
|
26 | - protected function _init_props() |
|
27 | - { |
|
28 | - $this->label = esc_html__('Attendee Shortcodes', 'event_espresso'); |
|
29 | - $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso'); |
|
30 | - $this->_shortcodes = [ |
|
31 | - '[FNAME]' => esc_html__('First Name of an attendee.', 'event_espresso'), |
|
32 | - '[LNAME]' => esc_html__('Last Name of an attendee.', 'event_espresso'), |
|
33 | - '[ATTENDEE_EMAIL]' => esc_html__('Email address for the attendee.', 'event_espresso'), |
|
34 | - '[EDIT_ATTENDEE_LINK]' => esc_html__( |
|
35 | - 'Edit Registration Link (typically you\'d only use this for messages going to event administrators)', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - '[REGISTRATION_ID]' => esc_html__( |
|
39 | - 'Unique Registration ID for the registration', |
|
40 | - 'event_espresso' |
|
41 | - ), |
|
42 | - '[REGISTRATION_CODE]' => esc_html__( |
|
43 | - 'Unique Registration Code for the registration', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '[REGISTRATION_STATUS_ID]' => esc_html__( |
|
47 | - 'Parses to the registration status for the attendee', |
|
48 | - 'event_espresso' |
|
49 | - ), |
|
50 | - '[REGISTRATION_STATUS_LABEL]' => esc_html__( |
|
51 | - 'Parses to the status label for the registrant', |
|
52 | - 'event_espresso' |
|
53 | - ), |
|
54 | - '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__( |
|
55 | - 'Parses to the total amount paid for this registration.', |
|
56 | - 'event_espresso' |
|
57 | - ), |
|
58 | - '[FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
59 | - 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
60 | - 'event_espresso' |
|
61 | - ), |
|
62 | - '[PHONE_NUMBER]' => esc_html__( |
|
63 | - 'The Phone Number for the Registration.', |
|
64 | - 'event_espresso' |
|
65 | - ), |
|
66 | - '[ADDRESS]' => esc_html__('The Address for the Registration', 'event_espresso'), |
|
67 | - '[ADDRESS2]' => esc_html__( |
|
68 | - 'Whatever was in the address 2 field for the registration.', |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - '[CITY]' => esc_html__('The city for the registration.', 'event_espresso'), |
|
72 | - '[ZIP_PC]' => esc_html__( |
|
73 | - 'The ZIP (or Postal) Code for the Registration.', |
|
74 | - 'event_espresso' |
|
75 | - ), |
|
76 | - '[ADDRESS_STATE]' => esc_html__( |
|
77 | - 'The state/province for the registration.', |
|
78 | - 'event_espresso' |
|
79 | - ), |
|
80 | - '[COUNTRY]' => esc_html__('The country for the registration.', 'event_espresso'), |
|
81 | - ]; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * handles shortcode parsing |
|
87 | - * |
|
88 | - * @param string $shortcode the shortcode to be parsed. |
|
89 | - * @return string |
|
90 | - * @throws EE_Error |
|
91 | - * @throws ReflectionException |
|
92 | - */ |
|
93 | - protected function _parser($shortcode) |
|
94 | - { |
|
95 | - $this->_extra = isset($this->_extra_data['data']) |
|
96 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
97 | - ? $this->_extra_data['data'] |
|
98 | - : null; |
|
99 | - |
|
100 | - $registration = $this->getRegistration(); |
|
101 | - $attendee = $this->getAttendee($registration); |
|
102 | - |
|
103 | - switch ($shortcode) { |
|
104 | - case '[FNAME]': |
|
105 | - return $attendee->fname(); |
|
106 | - |
|
107 | - case '[LNAME]': |
|
108 | - return $attendee->lname(); |
|
109 | - |
|
110 | - case '[ATTENDEE_EMAIL]': |
|
111 | - return $attendee->email(); |
|
112 | - |
|
113 | - case '[EDIT_ATTENDEE_LINK]': |
|
114 | - return $registration->get_admin_edit_url(); |
|
115 | - |
|
116 | - case '[REGISTRATION_CODE]': |
|
117 | - return $registration->reg_code(); |
|
118 | - |
|
119 | - case '[REGISTRATION_ID]': |
|
120 | - return $registration->ID(); |
|
121 | - |
|
122 | - case '[FRONTEND_EDIT_REG_LINK]': |
|
123 | - return $registration->edit_attendee_information_url(); |
|
124 | - |
|
125 | - case '[PHONE_NUMBER]': |
|
126 | - return $attendee->phone(); |
|
127 | - |
|
128 | - case '[ADDRESS]': |
|
129 | - return $attendee->address(); |
|
130 | - |
|
131 | - case '[ADDRESS2]': |
|
132 | - return $attendee->address2(); |
|
133 | - |
|
134 | - case '[CITY]': |
|
135 | - return $attendee->city(); |
|
136 | - |
|
137 | - case '[ZIP_PC]': |
|
138 | - return $attendee->zip(); |
|
139 | - |
|
140 | - case '[ADDRESS_STATE]': |
|
141 | - $state_obj = $attendee->state_obj(); |
|
142 | - return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
143 | - |
|
144 | - case '[COUNTRY]': |
|
145 | - $country_obj = $attendee->country_obj(); |
|
146 | - return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
147 | - |
|
148 | - case '[REGISTRATION_STATUS_ID]': |
|
149 | - return $registration->status_ID(); |
|
150 | - |
|
151 | - case '[REGISTRATION_STATUS_LABEL]': |
|
152 | - return $registration->pretty_status(); |
|
153 | - |
|
154 | - case '[REGISTRATION_TOTAL_AMOUNT_PAID]': |
|
155 | - return $registration->pretty_paid(); |
|
156 | - } |
|
157 | - |
|
158 | - return apply_filters( |
|
159 | - 'FHEE__EE_Attendee_Shortcodes__parsed', |
|
160 | - '', |
|
161 | - $shortcode, |
|
162 | - $registration, |
|
163 | - $attendee, |
|
164 | - $this->_data, |
|
165 | - $this->_extra_data, |
|
166 | - $this |
|
167 | - ); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return EE_Registration |
|
173 | - * @throws EE_Error |
|
174 | - * @since 5.0.20.p |
|
175 | - */ |
|
176 | - private function getRegistration(): EE_Registration |
|
177 | - { |
|
178 | - // incoming object should only be a registration object. |
|
179 | - if ($this->_data instanceof EE_Registration) { |
|
180 | - return $this->_data; |
|
181 | - } |
|
182 | - // look for registration in _data |
|
183 | - if ($this->_data instanceof EE_Messages_Addressee) { |
|
184 | - if ($this->_data->reg_obj instanceof EE_Registration) { |
|
185 | - return $this->_data->reg_obj; |
|
186 | - } |
|
187 | - if ($this->_data->primary_reg_obj instanceof EE_Registration) { |
|
188 | - return $this->_data->primary_reg_obj; |
|
189 | - } |
|
190 | - } |
|
191 | - // look for registration in _extra |
|
192 | - if ($this->_extra instanceof EE_Messages_Addressee) { |
|
193 | - if ($this->_extra->reg_obj instanceof EE_Registration) { |
|
194 | - return $this->_extra->reg_obj; |
|
195 | - } |
|
196 | - if ($this->_extra->primary_reg_obj instanceof EE_Registration) { |
|
197 | - return $this->_extra->primary_reg_obj; |
|
198 | - } |
|
199 | - } |
|
200 | - // let's attempt to get the txn_id for the error message. |
|
201 | - $txn_id = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction |
|
202 | - ? $this->_extra->txn->ID() |
|
203 | - : esc_html__('Unknown', 'event_espresso'); |
|
204 | - $msg = esc_html__( |
|
205 | - 'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.', |
|
206 | - 'event_espresso' |
|
207 | - ); |
|
208 | - $dev_msg = sprintf( |
|
209 | - esc_html__('The transaction ID for this request is: %s', 'event_espresso'), |
|
210 | - $txn_id |
|
211 | - ); |
|
212 | - throw new EE_Error("$msg||$msg $dev_msg"); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @param EE_Registration $registration |
|
218 | - * @return EE_Attendee |
|
219 | - * @throws EE_Error |
|
220 | - * @throws ReflectionException |
|
221 | - * @since 5.0.20.p |
|
222 | - */ |
|
223 | - private function getAttendee(EE_Registration $registration): EE_Attendee |
|
224 | - { |
|
225 | - $attendee = $registration->attendee(); |
|
226 | - if ($attendee instanceof EE_Attendee) { |
|
227 | - return $attendee; |
|
228 | - } |
|
229 | - // attendee obj for this registration |
|
230 | - if ( |
|
231 | - isset($this->_extra->registrations[ $registration->ID() ]['att_obj']) |
|
232 | - && $this->_extra->registrations[ $registration->ID() ]['att_obj'] instanceof EE_Attendee |
|
233 | - ) { |
|
234 | - return $this->_extra->registrations[ $registration->ID() ]['att_obj']; |
|
235 | - } |
|
236 | - |
|
237 | - $msg = esc_html__( |
|
238 | - 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', |
|
239 | - 'event_espresso' |
|
240 | - ); |
|
241 | - $dev_msg = sprintf( |
|
242 | - esc_html__('The registration ID for this request is: %s', 'event_espresso'), |
|
243 | - $registration->ID() |
|
244 | - ); |
|
245 | - throw new EE_Error("$msg||$msg $dev_msg"); |
|
246 | - } |
|
18 | + /** |
|
19 | + * hold all extra data. |
|
20 | + * |
|
21 | + * @var array|stdClass|null |
|
22 | + */ |
|
23 | + protected $_extra; |
|
24 | + |
|
25 | + |
|
26 | + protected function _init_props() |
|
27 | + { |
|
28 | + $this->label = esc_html__('Attendee Shortcodes', 'event_espresso'); |
|
29 | + $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso'); |
|
30 | + $this->_shortcodes = [ |
|
31 | + '[FNAME]' => esc_html__('First Name of an attendee.', 'event_espresso'), |
|
32 | + '[LNAME]' => esc_html__('Last Name of an attendee.', 'event_espresso'), |
|
33 | + '[ATTENDEE_EMAIL]' => esc_html__('Email address for the attendee.', 'event_espresso'), |
|
34 | + '[EDIT_ATTENDEE_LINK]' => esc_html__( |
|
35 | + 'Edit Registration Link (typically you\'d only use this for messages going to event administrators)', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + '[REGISTRATION_ID]' => esc_html__( |
|
39 | + 'Unique Registration ID for the registration', |
|
40 | + 'event_espresso' |
|
41 | + ), |
|
42 | + '[REGISTRATION_CODE]' => esc_html__( |
|
43 | + 'Unique Registration Code for the registration', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '[REGISTRATION_STATUS_ID]' => esc_html__( |
|
47 | + 'Parses to the registration status for the attendee', |
|
48 | + 'event_espresso' |
|
49 | + ), |
|
50 | + '[REGISTRATION_STATUS_LABEL]' => esc_html__( |
|
51 | + 'Parses to the status label for the registrant', |
|
52 | + 'event_espresso' |
|
53 | + ), |
|
54 | + '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__( |
|
55 | + 'Parses to the total amount paid for this registration.', |
|
56 | + 'event_espresso' |
|
57 | + ), |
|
58 | + '[FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
59 | + 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
60 | + 'event_espresso' |
|
61 | + ), |
|
62 | + '[PHONE_NUMBER]' => esc_html__( |
|
63 | + 'The Phone Number for the Registration.', |
|
64 | + 'event_espresso' |
|
65 | + ), |
|
66 | + '[ADDRESS]' => esc_html__('The Address for the Registration', 'event_espresso'), |
|
67 | + '[ADDRESS2]' => esc_html__( |
|
68 | + 'Whatever was in the address 2 field for the registration.', |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + '[CITY]' => esc_html__('The city for the registration.', 'event_espresso'), |
|
72 | + '[ZIP_PC]' => esc_html__( |
|
73 | + 'The ZIP (or Postal) Code for the Registration.', |
|
74 | + 'event_espresso' |
|
75 | + ), |
|
76 | + '[ADDRESS_STATE]' => esc_html__( |
|
77 | + 'The state/province for the registration.', |
|
78 | + 'event_espresso' |
|
79 | + ), |
|
80 | + '[COUNTRY]' => esc_html__('The country for the registration.', 'event_espresso'), |
|
81 | + ]; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * handles shortcode parsing |
|
87 | + * |
|
88 | + * @param string $shortcode the shortcode to be parsed. |
|
89 | + * @return string |
|
90 | + * @throws EE_Error |
|
91 | + * @throws ReflectionException |
|
92 | + */ |
|
93 | + protected function _parser($shortcode) |
|
94 | + { |
|
95 | + $this->_extra = isset($this->_extra_data['data']) |
|
96 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
97 | + ? $this->_extra_data['data'] |
|
98 | + : null; |
|
99 | + |
|
100 | + $registration = $this->getRegistration(); |
|
101 | + $attendee = $this->getAttendee($registration); |
|
102 | + |
|
103 | + switch ($shortcode) { |
|
104 | + case '[FNAME]': |
|
105 | + return $attendee->fname(); |
|
106 | + |
|
107 | + case '[LNAME]': |
|
108 | + return $attendee->lname(); |
|
109 | + |
|
110 | + case '[ATTENDEE_EMAIL]': |
|
111 | + return $attendee->email(); |
|
112 | + |
|
113 | + case '[EDIT_ATTENDEE_LINK]': |
|
114 | + return $registration->get_admin_edit_url(); |
|
115 | + |
|
116 | + case '[REGISTRATION_CODE]': |
|
117 | + return $registration->reg_code(); |
|
118 | + |
|
119 | + case '[REGISTRATION_ID]': |
|
120 | + return $registration->ID(); |
|
121 | + |
|
122 | + case '[FRONTEND_EDIT_REG_LINK]': |
|
123 | + return $registration->edit_attendee_information_url(); |
|
124 | + |
|
125 | + case '[PHONE_NUMBER]': |
|
126 | + return $attendee->phone(); |
|
127 | + |
|
128 | + case '[ADDRESS]': |
|
129 | + return $attendee->address(); |
|
130 | + |
|
131 | + case '[ADDRESS2]': |
|
132 | + return $attendee->address2(); |
|
133 | + |
|
134 | + case '[CITY]': |
|
135 | + return $attendee->city(); |
|
136 | + |
|
137 | + case '[ZIP_PC]': |
|
138 | + return $attendee->zip(); |
|
139 | + |
|
140 | + case '[ADDRESS_STATE]': |
|
141 | + $state_obj = $attendee->state_obj(); |
|
142 | + return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
143 | + |
|
144 | + case '[COUNTRY]': |
|
145 | + $country_obj = $attendee->country_obj(); |
|
146 | + return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
147 | + |
|
148 | + case '[REGISTRATION_STATUS_ID]': |
|
149 | + return $registration->status_ID(); |
|
150 | + |
|
151 | + case '[REGISTRATION_STATUS_LABEL]': |
|
152 | + return $registration->pretty_status(); |
|
153 | + |
|
154 | + case '[REGISTRATION_TOTAL_AMOUNT_PAID]': |
|
155 | + return $registration->pretty_paid(); |
|
156 | + } |
|
157 | + |
|
158 | + return apply_filters( |
|
159 | + 'FHEE__EE_Attendee_Shortcodes__parsed', |
|
160 | + '', |
|
161 | + $shortcode, |
|
162 | + $registration, |
|
163 | + $attendee, |
|
164 | + $this->_data, |
|
165 | + $this->_extra_data, |
|
166 | + $this |
|
167 | + ); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return EE_Registration |
|
173 | + * @throws EE_Error |
|
174 | + * @since 5.0.20.p |
|
175 | + */ |
|
176 | + private function getRegistration(): EE_Registration |
|
177 | + { |
|
178 | + // incoming object should only be a registration object. |
|
179 | + if ($this->_data instanceof EE_Registration) { |
|
180 | + return $this->_data; |
|
181 | + } |
|
182 | + // look for registration in _data |
|
183 | + if ($this->_data instanceof EE_Messages_Addressee) { |
|
184 | + if ($this->_data->reg_obj instanceof EE_Registration) { |
|
185 | + return $this->_data->reg_obj; |
|
186 | + } |
|
187 | + if ($this->_data->primary_reg_obj instanceof EE_Registration) { |
|
188 | + return $this->_data->primary_reg_obj; |
|
189 | + } |
|
190 | + } |
|
191 | + // look for registration in _extra |
|
192 | + if ($this->_extra instanceof EE_Messages_Addressee) { |
|
193 | + if ($this->_extra->reg_obj instanceof EE_Registration) { |
|
194 | + return $this->_extra->reg_obj; |
|
195 | + } |
|
196 | + if ($this->_extra->primary_reg_obj instanceof EE_Registration) { |
|
197 | + return $this->_extra->primary_reg_obj; |
|
198 | + } |
|
199 | + } |
|
200 | + // let's attempt to get the txn_id for the error message. |
|
201 | + $txn_id = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction |
|
202 | + ? $this->_extra->txn->ID() |
|
203 | + : esc_html__('Unknown', 'event_espresso'); |
|
204 | + $msg = esc_html__( |
|
205 | + 'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.', |
|
206 | + 'event_espresso' |
|
207 | + ); |
|
208 | + $dev_msg = sprintf( |
|
209 | + esc_html__('The transaction ID for this request is: %s', 'event_espresso'), |
|
210 | + $txn_id |
|
211 | + ); |
|
212 | + throw new EE_Error("$msg||$msg $dev_msg"); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @param EE_Registration $registration |
|
218 | + * @return EE_Attendee |
|
219 | + * @throws EE_Error |
|
220 | + * @throws ReflectionException |
|
221 | + * @since 5.0.20.p |
|
222 | + */ |
|
223 | + private function getAttendee(EE_Registration $registration): EE_Attendee |
|
224 | + { |
|
225 | + $attendee = $registration->attendee(); |
|
226 | + if ($attendee instanceof EE_Attendee) { |
|
227 | + return $attendee; |
|
228 | + } |
|
229 | + // attendee obj for this registration |
|
230 | + if ( |
|
231 | + isset($this->_extra->registrations[ $registration->ID() ]['att_obj']) |
|
232 | + && $this->_extra->registrations[ $registration->ID() ]['att_obj'] instanceof EE_Attendee |
|
233 | + ) { |
|
234 | + return $this->_extra->registrations[ $registration->ID() ]['att_obj']; |
|
235 | + } |
|
236 | + |
|
237 | + $msg = esc_html__( |
|
238 | + 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', |
|
239 | + 'event_espresso' |
|
240 | + ); |
|
241 | + $dev_msg = sprintf( |
|
242 | + esc_html__('The registration ID for this request is: %s', 'event_espresso'), |
|
243 | + $registration->ID() |
|
244 | + ); |
|
245 | + throw new EE_Error("$msg||$msg $dev_msg"); |
|
246 | + } |
|
247 | 247 | } |
@@ -10,88 +10,88 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Select_Display_Strategy extends EE_Display_Strategy_Base |
12 | 12 | { |
13 | - /** |
|
14 | - * @return string of html to display the field |
|
15 | - * @throws EE_Error |
|
16 | - */ |
|
17 | - public function display(): string |
|
18 | - { |
|
19 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
20 | - throw new EE_Error( |
|
21 | - esc_html__( |
|
22 | - 'Cannot use Select Display Strategy with an input that doesn\'t have options', |
|
23 | - 'event_espresso' |
|
24 | - ) |
|
25 | - ); |
|
26 | - } |
|
13 | + /** |
|
14 | + * @return string of html to display the field |
|
15 | + * @throws EE_Error |
|
16 | + */ |
|
17 | + public function display(): string |
|
18 | + { |
|
19 | + if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
20 | + throw new EE_Error( |
|
21 | + esc_html__( |
|
22 | + 'Cannot use Select Display Strategy with an input that doesn\'t have options', |
|
23 | + 'event_espresso' |
|
24 | + ) |
|
25 | + ); |
|
26 | + } |
|
27 | 27 | |
28 | - $html = EEH_HTML::nl(0, 'select'); |
|
29 | - $html .= '<select'; |
|
30 | - $html .= $this->_attributes_string( |
|
31 | - $this->_standard_attributes_array() |
|
32 | - ); |
|
33 | - $html .= $this->dataAttributesString($this->_input->dataAttributes()); |
|
34 | - $html .= '>'; |
|
28 | + $html = EEH_HTML::nl(0, 'select'); |
|
29 | + $html .= '<select'; |
|
30 | + $html .= $this->_attributes_string( |
|
31 | + $this->_standard_attributes_array() |
|
32 | + ); |
|
33 | + $html .= $this->dataAttributesString($this->_input->dataAttributes()); |
|
34 | + $html .= '>'; |
|
35 | 35 | |
36 | - if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
37 | - EEH_HTML::indent(1, 'optgroup'); |
|
38 | - foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
39 | - if (! empty($opt_group_label)) { |
|
40 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
41 | - } |
|
42 | - EEH_HTML::indent(1, 'option'); |
|
43 | - $html .= $this->_display_options($opt_group); |
|
44 | - EEH_HTML::indent(-1, 'option'); |
|
45 | - if (! empty($opt_group_label)) { |
|
46 | - $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
47 | - } |
|
48 | - } |
|
49 | - EEH_HTML::indent(-1, 'optgroup'); |
|
50 | - } else { |
|
51 | - $html .= $this->_display_options($this->_input->options()); |
|
52 | - } |
|
36 | + if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
37 | + EEH_HTML::indent(1, 'optgroup'); |
|
38 | + foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
39 | + if (! empty($opt_group_label)) { |
|
40 | + $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
41 | + } |
|
42 | + EEH_HTML::indent(1, 'option'); |
|
43 | + $html .= $this->_display_options($opt_group); |
|
44 | + EEH_HTML::indent(-1, 'option'); |
|
45 | + if (! empty($opt_group_label)) { |
|
46 | + $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
47 | + } |
|
48 | + } |
|
49 | + EEH_HTML::indent(-1, 'optgroup'); |
|
50 | + } else { |
|
51 | + $html .= $this->_display_options($this->_input->options()); |
|
52 | + } |
|
53 | 53 | |
54 | - $html .= EEH_HTML::nl(0, 'select') . '</select>'; |
|
55 | - return $html; |
|
56 | - } |
|
54 | + $html .= EEH_HTML::nl(0, 'select') . '</select>'; |
|
55 | + return $html; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Displays a flat list of options as option tags |
|
61 | - * |
|
62 | - * @param array $options |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - protected function _display_options(array $options): string |
|
66 | - { |
|
67 | - $html = ''; |
|
68 | - EEH_HTML::indent(1, 'option'); |
|
69 | - foreach ($options as $value => $display_text) { |
|
70 | - if (! $value && ! $display_text) { |
|
71 | - $html = "<option></option>"; |
|
72 | - continue; |
|
73 | - } |
|
74 | - // even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
75 | - // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
76 | - $value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
77 | - $selected = $this->_check_if_option_selected($value) ? ' selected' : ''; |
|
78 | - $value = esc_attr($value); |
|
79 | - $html .= EEH_HTML::nl(0, 'option'); |
|
80 | - $html .= "<option value=\"$value\"$selected>$display_text</option>"; |
|
81 | - } |
|
82 | - EEH_HTML::indent(-1, 'option'); |
|
83 | - return $html; |
|
84 | - } |
|
59 | + /** |
|
60 | + * Displays a flat list of options as option tags |
|
61 | + * |
|
62 | + * @param array $options |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + protected function _display_options(array $options): string |
|
66 | + { |
|
67 | + $html = ''; |
|
68 | + EEH_HTML::indent(1, 'option'); |
|
69 | + foreach ($options as $value => $display_text) { |
|
70 | + if (! $value && ! $display_text) { |
|
71 | + $html = "<option></option>"; |
|
72 | + continue; |
|
73 | + } |
|
74 | + // even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
75 | + // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
76 | + $value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
77 | + $selected = $this->_check_if_option_selected($value) ? ' selected' : ''; |
|
78 | + $value = esc_attr($value); |
|
79 | + $html .= EEH_HTML::nl(0, 'option'); |
|
80 | + $html .= "<option value=\"$value\"$selected>$display_text</option>"; |
|
81 | + } |
|
82 | + EEH_HTML::indent(-1, 'option'); |
|
83 | + return $html; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * Checks if that value is the one selected |
|
89 | - * |
|
90 | - * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - protected function _check_if_option_selected($option_value): bool |
|
94 | - { |
|
95 | - return $option_value === $this->_input->raw_value(); |
|
96 | - } |
|
87 | + /** |
|
88 | + * Checks if that value is the one selected |
|
89 | + * |
|
90 | + * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + protected function _check_if_option_selected($option_value): bool |
|
94 | + { |
|
95 | + return $option_value === $this->_input->raw_value(); |
|
96 | + } |
|
97 | 97 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | public function display(): string |
18 | 18 | { |
19 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
19 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
20 | 20 | throw new EE_Error( |
21 | 21 | esc_html__( |
22 | 22 | 'Cannot use Select Display Strategy with an input that doesn\'t have options', |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
37 | 37 | EEH_HTML::indent(1, 'optgroup'); |
38 | 38 | foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
39 | - if (! empty($opt_group_label)) { |
|
40 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
39 | + if ( ! empty($opt_group_label)) { |
|
40 | + $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">'; |
|
41 | 41 | } |
42 | 42 | EEH_HTML::indent(1, 'option'); |
43 | 43 | $html .= $this->_display_options($opt_group); |
44 | 44 | EEH_HTML::indent(-1, 'option'); |
45 | - if (! empty($opt_group_label)) { |
|
46 | - $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
45 | + if ( ! empty($opt_group_label)) { |
|
46 | + $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>'; |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | EEH_HTML::indent(-1, 'optgroup'); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $html .= $this->_display_options($this->_input->options()); |
52 | 52 | } |
53 | 53 | |
54 | - $html .= EEH_HTML::nl(0, 'select') . '</select>'; |
|
54 | + $html .= EEH_HTML::nl(0, 'select').'</select>'; |
|
55 | 55 | return $html; |
56 | 56 | } |
57 | 57 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $html = ''; |
68 | 68 | EEH_HTML::indent(1, 'option'); |
69 | 69 | foreach ($options as $value => $display_text) { |
70 | - if (! $value && ! $display_text) { |
|
70 | + if ( ! $value && ! $display_text) { |
|
71 | 71 | $html = "<option></option>"; |
72 | 72 | continue; |
73 | 73 | } |
@@ -13,302 +13,302 @@ |
||
13 | 13 | */ |
14 | 14 | class EEH_URL |
15 | 15 | { |
16 | - const CONTEXT_NONE = 0; |
|
16 | + const CONTEXT_NONE = 0; |
|
17 | 17 | |
18 | - const CONTEXT_OUTPUT = 1; |
|
18 | + const CONTEXT_OUTPUT = 1; |
|
19 | 19 | |
20 | - const CONTEXT_RAW = 2; |
|
20 | + const CONTEXT_RAW = 2; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * _add_query_arg |
|
25 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
26 | - * |
|
27 | - * @param array $args |
|
28 | - * @param string $url |
|
29 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
30 | - * @param int $context |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public static function add_query_args_and_nonce( |
|
34 | - array $args = [], |
|
35 | - string $url = '', |
|
36 | - bool $exclude_nonce = false, |
|
37 | - int $context = EEH_URL::CONTEXT_NONE |
|
38 | - ): string { |
|
39 | - // check that an action exists and add nonce |
|
40 | - if (! $exclude_nonce) { |
|
41 | - if (! empty($args['action'])) { |
|
42 | - $args = array_merge( |
|
43 | - $args, |
|
44 | - [ |
|
45 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce'), |
|
46 | - ] |
|
47 | - ); |
|
48 | - } else { |
|
49 | - $args = array_merge( |
|
50 | - $args, |
|
51 | - [ |
|
52 | - 'action' => 'default', |
|
53 | - 'default_nonce' => wp_create_nonce('default_nonce'), |
|
54 | - ] |
|
55 | - ); |
|
56 | - } |
|
57 | - } |
|
23 | + /** |
|
24 | + * _add_query_arg |
|
25 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
26 | + * |
|
27 | + * @param array $args |
|
28 | + * @param string $url |
|
29 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
30 | + * @param int $context |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public static function add_query_args_and_nonce( |
|
34 | + array $args = [], |
|
35 | + string $url = '', |
|
36 | + bool $exclude_nonce = false, |
|
37 | + int $context = EEH_URL::CONTEXT_NONE |
|
38 | + ): string { |
|
39 | + // check that an action exists and add nonce |
|
40 | + if (! $exclude_nonce) { |
|
41 | + if (! empty($args['action'])) { |
|
42 | + $args = array_merge( |
|
43 | + $args, |
|
44 | + [ |
|
45 | + $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce'), |
|
46 | + ] |
|
47 | + ); |
|
48 | + } else { |
|
49 | + $args = array_merge( |
|
50 | + $args, |
|
51 | + [ |
|
52 | + 'action' => 'default', |
|
53 | + 'default_nonce' => wp_create_nonce('default_nonce'), |
|
54 | + ] |
|
55 | + ); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - $action = EEH_URL::getRequest()->getRequestParam('action', ''); |
|
60 | - // finally, let's always add a return address (if present) :) |
|
61 | - if ($action !== '') { |
|
62 | - $args['return'] = $action; |
|
63 | - } |
|
59 | + $action = EEH_URL::getRequest()->getRequestParam('action', ''); |
|
60 | + // finally, let's always add a return address (if present) :) |
|
61 | + if ($action !== '') { |
|
62 | + $args['return'] = $action; |
|
63 | + } |
|
64 | 64 | |
65 | - $url = add_query_arg($args, $url); |
|
66 | - if ($context === EEH_URL::CONTEXT_OUTPUT) { |
|
67 | - return esc_url($url); |
|
68 | - } |
|
69 | - if ($context === EEH_URL::CONTEXT_RAW) { |
|
70 | - return esc_url_raw($url); |
|
71 | - } |
|
72 | - return $url; |
|
73 | - } |
|
65 | + $url = add_query_arg($args, $url); |
|
66 | + if ($context === EEH_URL::CONTEXT_OUTPUT) { |
|
67 | + return esc_url($url); |
|
68 | + } |
|
69 | + if ($context === EEH_URL::CONTEXT_RAW) { |
|
70 | + return esc_url_raw($url); |
|
71 | + } |
|
72 | + return $url; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Returns whether not the remote file exists. |
|
78 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
79 | - * |
|
80 | - * @param string $url |
|
81 | - * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
82 | - * @return boolean |
|
83 | - */ |
|
84 | - public static function remote_file_exists(string $url, array $args = []): bool |
|
85 | - { |
|
86 | - $results = wp_remote_request( |
|
87 | - $url, |
|
88 | - array_merge( |
|
89 | - [ |
|
90 | - 'method' => 'GET', |
|
91 | - 'redirection' => 1, |
|
92 | - ], |
|
93 | - $args |
|
94 | - ) |
|
95 | - ); |
|
96 | - return ! $results instanceof WP_Error |
|
97 | - && isset($results['response']['code']) |
|
98 | - && $results['response']['code'] == '200'; |
|
99 | - } |
|
76 | + /** |
|
77 | + * Returns whether not the remote file exists. |
|
78 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
79 | + * |
|
80 | + * @param string $url |
|
81 | + * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
82 | + * @return boolean |
|
83 | + */ |
|
84 | + public static function remote_file_exists(string $url, array $args = []): bool |
|
85 | + { |
|
86 | + $results = wp_remote_request( |
|
87 | + $url, |
|
88 | + array_merge( |
|
89 | + [ |
|
90 | + 'method' => 'GET', |
|
91 | + 'redirection' => 1, |
|
92 | + ], |
|
93 | + $args |
|
94 | + ) |
|
95 | + ); |
|
96 | + return ! $results instanceof WP_Error |
|
97 | + && isset($results['response']['code']) |
|
98 | + && $results['response']['code'] == '200'; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * refactor_url |
|
104 | - * primarily used for removing the query string from a URL |
|
105 | - * |
|
106 | - * @param string $url |
|
107 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
108 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public static function refactor_url( |
|
112 | - string $url = '', |
|
113 | - bool $remove_query = true, |
|
114 | - bool $base_url_only = false |
|
115 | - ): string { |
|
116 | - // break apart incoming URL |
|
117 | - $url_bits = parse_url($url); |
|
118 | - // HTTP or HTTPS ? |
|
119 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'https://'; |
|
120 | - // domain |
|
121 | - $host = $url_bits['host'] ?? ''; |
|
122 | - // if only the base URL is requested, then return that now |
|
123 | - if ($base_url_only) { |
|
124 | - return $scheme . $host; |
|
125 | - } |
|
126 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
127 | - $user = $url_bits['user'] ?? ''; |
|
128 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
129 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
130 | - $path = $url_bits['path'] ?? ''; |
|
131 | - // if the query string is not required, then return what we have so far |
|
132 | - if ($remove_query) { |
|
133 | - return $scheme . $user . $pass . $host . $port . $path; |
|
134 | - } |
|
135 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
136 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
137 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
138 | - } |
|
102 | + /** |
|
103 | + * refactor_url |
|
104 | + * primarily used for removing the query string from a URL |
|
105 | + * |
|
106 | + * @param string $url |
|
107 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
108 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public static function refactor_url( |
|
112 | + string $url = '', |
|
113 | + bool $remove_query = true, |
|
114 | + bool $base_url_only = false |
|
115 | + ): string { |
|
116 | + // break apart incoming URL |
|
117 | + $url_bits = parse_url($url); |
|
118 | + // HTTP or HTTPS ? |
|
119 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'https://'; |
|
120 | + // domain |
|
121 | + $host = $url_bits['host'] ?? ''; |
|
122 | + // if only the base URL is requested, then return that now |
|
123 | + if ($base_url_only) { |
|
124 | + return $scheme . $host; |
|
125 | + } |
|
126 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
127 | + $user = $url_bits['user'] ?? ''; |
|
128 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
129 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
130 | + $path = $url_bits['path'] ?? ''; |
|
131 | + // if the query string is not required, then return what we have so far |
|
132 | + if ($remove_query) { |
|
133 | + return $scheme . $user . $pass . $host . $port . $path; |
|
134 | + } |
|
135 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
136 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
137 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
138 | + } |
|
139 | 139 | |
140 | 140 | |
141 | - /** |
|
142 | - * get_query_string |
|
143 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
144 | - * |
|
145 | - * @param string $url |
|
146 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
147 | - * simply return the query string |
|
148 | - * @return string|array |
|
149 | - */ |
|
150 | - public static function get_query_string(string $url = '', bool $as_array = true) |
|
151 | - { |
|
152 | - // decode, then break apart incoming URL |
|
153 | - $url_bits = parse_url(html_entity_decode($url)); |
|
154 | - // grab query string from URL |
|
155 | - $query = $url_bits['query'] ?? ''; |
|
156 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
157 | - if (! $as_array) { |
|
158 | - return $query; |
|
159 | - } |
|
160 | - // if no query string exists then just return an empty array now |
|
161 | - if (empty($query)) { |
|
162 | - return []; |
|
163 | - } |
|
164 | - // empty array to hold results |
|
165 | - $query_params = []; |
|
166 | - // now break apart the query string into separate params |
|
167 | - $query = explode('&', $query); |
|
168 | - // loop thru our query params |
|
169 | - foreach ($query as $query_args) { |
|
170 | - // break apart the key value pairs |
|
171 | - $query_args = explode('=', $query_args); |
|
172 | - if ($query_args) { |
|
173 | - // and add to our results array |
|
174 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
175 | - } |
|
176 | - } |
|
177 | - return $query_params; |
|
178 | - } |
|
141 | + /** |
|
142 | + * get_query_string |
|
143 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
144 | + * |
|
145 | + * @param string $url |
|
146 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
147 | + * simply return the query string |
|
148 | + * @return string|array |
|
149 | + */ |
|
150 | + public static function get_query_string(string $url = '', bool $as_array = true) |
|
151 | + { |
|
152 | + // decode, then break apart incoming URL |
|
153 | + $url_bits = parse_url(html_entity_decode($url)); |
|
154 | + // grab query string from URL |
|
155 | + $query = $url_bits['query'] ?? ''; |
|
156 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
157 | + if (! $as_array) { |
|
158 | + return $query; |
|
159 | + } |
|
160 | + // if no query string exists then just return an empty array now |
|
161 | + if (empty($query)) { |
|
162 | + return []; |
|
163 | + } |
|
164 | + // empty array to hold results |
|
165 | + $query_params = []; |
|
166 | + // now break apart the query string into separate params |
|
167 | + $query = explode('&', $query); |
|
168 | + // loop thru our query params |
|
169 | + foreach ($query as $query_args) { |
|
170 | + // break apart the key value pairs |
|
171 | + $query_args = explode('=', $query_args); |
|
172 | + if ($query_args) { |
|
173 | + // and add to our results array |
|
174 | + $query_params[ $query_args[0] ] = $query_args[1]; |
|
175 | + } |
|
176 | + } |
|
177 | + return $query_params; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | |
181 | - /** |
|
182 | - * prevent_prefetching |
|
183 | - * |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - public static function prevent_prefetching() |
|
187 | - { |
|
188 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
189 | - // with the registration process |
|
190 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
191 | - } |
|
181 | + /** |
|
182 | + * prevent_prefetching |
|
183 | + * |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + public static function prevent_prefetching() |
|
187 | + { |
|
188 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
189 | + // with the registration process |
|
190 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
191 | + } |
|
192 | 192 | |
193 | 193 | |
194 | - /** |
|
195 | - * This generates a unique site-specific string. |
|
196 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
197 | - * urls. |
|
198 | - * |
|
199 | - * @param string $prefix Use this to prefix the string with something. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function generate_unique_token(string $prefix = ''): string |
|
203 | - { |
|
204 | - $token = md5(uniqid() . mt_rand()); |
|
205 | - return $prefix ? $prefix . '_' . $token : $token; |
|
206 | - } |
|
194 | + /** |
|
195 | + * This generates a unique site-specific string. |
|
196 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
197 | + * urls. |
|
198 | + * |
|
199 | + * @param string $prefix Use this to prefix the string with something. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function generate_unique_token(string $prefix = ''): string |
|
203 | + { |
|
204 | + $token = md5(uniqid() . mt_rand()); |
|
205 | + return $prefix ? $prefix . '_' . $token : $token; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * filter_input_server_url |
|
211 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
212 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
213 | - * |
|
214 | - * @param string $server_variable |
|
215 | - * @return string |
|
216 | - */ |
|
217 | - public static function filter_input_server_url(string $server_variable = 'REQUEST_URI'): string |
|
218 | - { |
|
219 | - $URL = ''; |
|
220 | - $server_variables = [ |
|
221 | - 'REQUEST_URI' => 1, |
|
222 | - 'HTTP_HOST' => 1, |
|
223 | - 'PHP_SELF' => 1, |
|
224 | - ]; |
|
225 | - $server_variable = strtoupper($server_variable); |
|
226 | - // whitelist INPUT_SERVER var |
|
227 | - if (isset($server_variables[ $server_variable ])) { |
|
228 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
229 | - if (empty($URL) || $URL !== $_SERVER[ $server_variable ]) { |
|
230 | - // fallback sanitization if the above fails or URL has changed after filtering |
|
231 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
232 | - } |
|
233 | - } |
|
234 | - return $URL; |
|
235 | - } |
|
209 | + /** |
|
210 | + * filter_input_server_url |
|
211 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
212 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
213 | + * |
|
214 | + * @param string $server_variable |
|
215 | + * @return string |
|
216 | + */ |
|
217 | + public static function filter_input_server_url(string $server_variable = 'REQUEST_URI'): string |
|
218 | + { |
|
219 | + $URL = ''; |
|
220 | + $server_variables = [ |
|
221 | + 'REQUEST_URI' => 1, |
|
222 | + 'HTTP_HOST' => 1, |
|
223 | + 'PHP_SELF' => 1, |
|
224 | + ]; |
|
225 | + $server_variable = strtoupper($server_variable); |
|
226 | + // whitelist INPUT_SERVER var |
|
227 | + if (isset($server_variables[ $server_variable ])) { |
|
228 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
229 | + if (empty($URL) || $URL !== $_SERVER[ $server_variable ]) { |
|
230 | + // fallback sanitization if the above fails or URL has changed after filtering |
|
231 | + $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
232 | + } |
|
233 | + } |
|
234 | + return $URL; |
|
235 | + } |
|
236 | 236 | |
237 | 237 | |
238 | - /** |
|
239 | - * Gets the current page's full URL. |
|
240 | - * |
|
241 | - * @return string |
|
242 | - */ |
|
243 | - public static function current_url(): string |
|
244 | - { |
|
245 | - $url = ''; |
|
246 | - if ( |
|
247 | - EEH_URL::getRequest()->serverParamIsSet('HTTP_HOST') |
|
248 | - && EEH_URL::getRequest()->serverParamIsSet('REQUEST_URI') |
|
249 | - ) { |
|
250 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
251 | - $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
252 | - $url .= EEH_URL::filter_input_server_url(); |
|
253 | - } |
|
254 | - return $url; |
|
255 | - } |
|
238 | + /** |
|
239 | + * Gets the current page's full URL. |
|
240 | + * |
|
241 | + * @return string |
|
242 | + */ |
|
243 | + public static function current_url(): string |
|
244 | + { |
|
245 | + $url = ''; |
|
246 | + if ( |
|
247 | + EEH_URL::getRequest()->serverParamIsSet('HTTP_HOST') |
|
248 | + && EEH_URL::getRequest()->serverParamIsSet('REQUEST_URI') |
|
249 | + ) { |
|
250 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
251 | + $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
252 | + $url .= EEH_URL::filter_input_server_url(); |
|
253 | + } |
|
254 | + return $url; |
|
255 | + } |
|
256 | 256 | |
257 | 257 | |
258 | - /** |
|
259 | - * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
260 | - * |
|
261 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
262 | - * @return string |
|
263 | - * @since 4.9.46.rc.029 |
|
264 | - */ |
|
265 | - public static function current_url_without_query_paramaters(array $query_parameters): string |
|
266 | - { |
|
267 | - return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
268 | - } |
|
258 | + /** |
|
259 | + * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
260 | + * |
|
261 | + * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
262 | + * @return string |
|
263 | + * @since 4.9.46.rc.029 |
|
264 | + */ |
|
265 | + public static function current_url_without_query_paramaters(array $query_parameters): string |
|
266 | + { |
|
267 | + return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
268 | + } |
|
269 | 269 | |
270 | 270 | |
271 | - /** |
|
272 | - * @param string $location |
|
273 | - * @param int $status |
|
274 | - * @param string $exit_notice |
|
275 | - */ |
|
276 | - public static function safeRedirectAndExit(string $location, int $status = 302, string $exit_notice = '') |
|
277 | - { |
|
278 | - EE_Error::get_notices(false, true); |
|
279 | - wp_safe_redirect($location, $status); |
|
280 | - exit($exit_notice); |
|
281 | - } |
|
271 | + /** |
|
272 | + * @param string $location |
|
273 | + * @param int $status |
|
274 | + * @param string $exit_notice |
|
275 | + */ |
|
276 | + public static function safeRedirectAndExit(string $location, int $status = 302, string $exit_notice = '') |
|
277 | + { |
|
278 | + EE_Error::get_notices(false, true); |
|
279 | + wp_safe_redirect($location, $status); |
|
280 | + exit($exit_notice); |
|
281 | + } |
|
282 | 282 | |
283 | 283 | |
284 | - /** |
|
285 | - * Slugifies text for usage in a URL. |
|
286 | - * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
287 | - * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
288 | - * |
|
289 | - * @param string $text |
|
290 | - * @param string $fallback |
|
291 | - * @return string which can be used in a URL |
|
292 | - * @since 4.9.66.p |
|
293 | - */ |
|
294 | - public static function slugify(string $text, string $fallback): string |
|
295 | - { |
|
296 | - // url decode after sanitizing title to restore unicode characters, |
|
297 | - // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
298 | - return urldecode(sanitize_title($text, $fallback)); |
|
299 | - } |
|
284 | + /** |
|
285 | + * Slugifies text for usage in a URL. |
|
286 | + * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
287 | + * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
288 | + * |
|
289 | + * @param string $text |
|
290 | + * @param string $fallback |
|
291 | + * @return string which can be used in a URL |
|
292 | + * @since 4.9.66.p |
|
293 | + */ |
|
294 | + public static function slugify(string $text, string $fallback): string |
|
295 | + { |
|
296 | + // url decode after sanitizing title to restore unicode characters, |
|
297 | + // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
298 | + return urldecode(sanitize_title($text, $fallback)); |
|
299 | + } |
|
300 | 300 | |
301 | 301 | |
302 | - /** |
|
303 | - * @return RequestInterface |
|
304 | - * @since 4.10.14.p |
|
305 | - */ |
|
306 | - protected static function getRequest(): RequestInterface |
|
307 | - { |
|
308 | - static $request; |
|
309 | - if (! $request instanceof RequestInterface) { |
|
310 | - $request = LoaderFactory::getShared(RequestInterface::class); |
|
311 | - } |
|
312 | - return $request; |
|
313 | - } |
|
302 | + /** |
|
303 | + * @return RequestInterface |
|
304 | + * @since 4.10.14.p |
|
305 | + */ |
|
306 | + protected static function getRequest(): RequestInterface |
|
307 | + { |
|
308 | + static $request; |
|
309 | + if (! $request instanceof RequestInterface) { |
|
310 | + $request = LoaderFactory::getShared(RequestInterface::class); |
|
311 | + } |
|
312 | + return $request; |
|
313 | + } |
|
314 | 314 | } |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | int $context = EEH_URL::CONTEXT_NONE |
38 | 38 | ): string { |
39 | 39 | // check that an action exists and add nonce |
40 | - if (! $exclude_nonce) { |
|
41 | - if (! empty($args['action'])) { |
|
40 | + if ( ! $exclude_nonce) { |
|
41 | + if ( ! empty($args['action'])) { |
|
42 | 42 | $args = array_merge( |
43 | 43 | $args, |
44 | 44 | [ |
45 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce'), |
|
45 | + $args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce'), |
|
46 | 46 | ] |
47 | 47 | ); |
48 | 48 | } else { |
@@ -116,25 +116,25 @@ discard block |
||
116 | 116 | // break apart incoming URL |
117 | 117 | $url_bits = parse_url($url); |
118 | 118 | // HTTP or HTTPS ? |
119 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'https://'; |
|
119 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'https://'; |
|
120 | 120 | // domain |
121 | 121 | $host = $url_bits['host'] ?? ''; |
122 | 122 | // if only the base URL is requested, then return that now |
123 | 123 | if ($base_url_only) { |
124 | - return $scheme . $host; |
|
124 | + return $scheme.$host; |
|
125 | 125 | } |
126 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
126 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
127 | 127 | $user = $url_bits['user'] ?? ''; |
128 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
129 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
128 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
129 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
130 | 130 | $path = $url_bits['path'] ?? ''; |
131 | 131 | // if the query string is not required, then return what we have so far |
132 | 132 | if ($remove_query) { |
133 | - return $scheme . $user . $pass . $host . $port . $path; |
|
133 | + return $scheme.$user.$pass.$host.$port.$path; |
|
134 | 134 | } |
135 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
136 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
137 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
135 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
136 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
137 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | // grab query string from URL |
155 | 155 | $query = $url_bits['query'] ?? ''; |
156 | 156 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
157 | - if (! $as_array) { |
|
157 | + if ( ! $as_array) { |
|
158 | 158 | return $query; |
159 | 159 | } |
160 | 160 | // if no query string exists then just return an empty array now |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $query_args = explode('=', $query_args); |
172 | 172 | if ($query_args) { |
173 | 173 | // and add to our results array |
174 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
174 | + $query_params[$query_args[0]] = $query_args[1]; |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | return $query_params; |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public static function generate_unique_token(string $prefix = ''): string |
203 | 203 | { |
204 | - $token = md5(uniqid() . mt_rand()); |
|
205 | - return $prefix ? $prefix . '_' . $token : $token; |
|
204 | + $token = md5(uniqid().mt_rand()); |
|
205 | + return $prefix ? $prefix.'_'.$token : $token; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | 'HTTP_HOST' => 1, |
223 | 223 | 'PHP_SELF' => 1, |
224 | 224 | ]; |
225 | - $server_variable = strtoupper($server_variable); |
|
225 | + $server_variable = strtoupper($server_variable); |
|
226 | 226 | // whitelist INPUT_SERVER var |
227 | - if (isset($server_variables[ $server_variable ])) { |
|
227 | + if (isset($server_variables[$server_variable])) { |
|
228 | 228 | $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
229 | - if (empty($URL) || $URL !== $_SERVER[ $server_variable ]) { |
|
229 | + if (empty($URL) || $URL !== $_SERVER[$server_variable]) { |
|
230 | 230 | // fallback sanitization if the above fails or URL has changed after filtering |
231 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
231 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | return $URL; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | protected static function getRequest(): RequestInterface |
307 | 307 | { |
308 | 308 | static $request; |
309 | - if (! $request instanceof RequestInterface) { |
|
309 | + if ( ! $request instanceof RequestInterface) { |
|
310 | 310 | $request = LoaderFactory::getShared(RequestInterface::class); |
311 | 311 | } |
312 | 312 | return $request; |