PluginProbe
Docket Cache – Object Cache Accelerator / 24.07.03
Docket Cache – Object Cache Accelerator v24.07.03
26.04.05 trunk 22.07.01 22.07.02 22.07.03 22.07.04 22.07.05 23.08.01 23.08.02 24.07.01 24.07.02 24.07.03 24.07.04 24.07.05 24.07.06 24.07.07 26.04.03 26.04.04
docket-cache / includes / src / ReqAction.php

ReqAction.php in Docket Cache – Object Cache Accelerator 24.07.03, at includes/src/ReqAction.php

938 lines 43.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Docket Cache.
4 *
5 * @author Nawawi Jamili
6 * @license MIT
7 *
8 * @see https://github.com/nawawi/docket-cache
9 */
10
11 namespace Nawawi\DocketCache;
12
13 \defined('ABSPATH') || exit;
14
15 final class ReqAction
16 {
17 private $pt;
18
19 public function __construct(Plugin $pt)
20 {
21 $this->pt = $pt;
22 }
23
24 public function register()
25 {
26 add_action(
27 'load-'.$this->pt->get_screen(),
28 function () {
29 $this->parse_action();
30 $this->screen_notice();
31 }
32 );
33 }
34
35 private function exit_failed($param)
36 {
37 $args = [
38 'message' => 'docket-action-failed',
39 ];
40
41 if (!empty($param['idx'])) {
42 $args['idx'] = sanitize_text_field($param['idx']);
43 }
44
45 if (!empty($param['adx'])) {
46 $args['adx'] = sanitize_text_field($param['adx']);
47 }
48
49 $query = add_query_arg($args, $this->pt->get_page());
50 wp_safe_redirect(network_admin_url($query));
51 }
52
53 /**
54 * action_token.
55 */
56 private function action_token()
57 {
58 $keys = [
59 'docket-enable-occache',
60 'docket-disable-occache',
61 'docket-flush-occache',
62 'docket-update-dropino',
63 'docket-dismiss-dropino',
64 'docket-flush-oclog',
65 'docket-flush-ocfile',
66 'docket-flush-opcache',
67 'docket-flush-menucache',
68 'docket-flush-transient',
69 'docket-flush-advcpost',
70 'docket-flush-ocprecache',
71 'docket-flush-mocache',
72 'docket-connect-cronbot',
73 'docket-disconnect-cronbot',
74 'docket-pong-cronbot',
75 'docket-runevent-cronbot',
76 'docket-runeventnow-cronbot',
77 'docket-runeventuno-cronbot',
78 'docket-selectsite-cronbot',
79 'docket-rungc',
80 'docket-runtime',
81 'docket-configreset',
82 'docket-cleanuppost',
83 ];
84
85 $keys = apply_filters('docketcache/filter/reqaction/token', $keys);
86
87 foreach ($this->pt->co()->keys() as $key) {
88 $keys[] = 'docket-default-'.$key;
89 $keys[] = 'docket-enable-'.$key;
90 $keys[] = 'docket-disable-'.$key;
91 $keys[] = 'docket-save-'.$key;
92 }
93
94 return array_unique($keys);
95 }
96
97 private function run_action($action, $param, &$option_name = '', &$option_value = '')
98 {
99 $response = '';
100
101 $action_filter = apply_filters('docketcache/filter/reqaction/runaction', $action, $param, $option_name, $option_value);
102 if (!empty($action_filter) && \is_object($action_filter)) {
103 $response = $action_filter->response;
104 $option_name = $action_filter->option_name;
105 $option_value = $action_filter->option_value;
106 }
107
108 switch ($action) {
109 case 'docket-flush-occache':
110 $is_timeout = false;
111 $result = $this->pt->flush_cache(true, $is_timeout);
112 $response = $is_timeout ? 'docket-occache-flushed-warn' : 'docket-occache-flushed';
113 $this->pt->co()->lookup_set('occacheflushed', $result);
114
115 do_action('docketcache/action/flush/objectcache', $result);
116 break;
117 case 'docket-enable-occache':
118 $result = $this->pt->cx()->install(true);
119 $response = $result ? 'docket-occache-enabled' : 'docket-occache-enabled-failed';
120 do_action('docketcache/action/enable/objectcache', $result);
121 break;
122
123 case 'docket-disable-occache':
124 $result = $this->pt->cx()->uninstall();
125 $response = $result ? 'docket-occache-disabled' : 'docket-occache-disabled-failed';
126 do_action('docketcache/action/disable/objectcache', $result);
127 break;
128
129 case 'docket-update-dropino':
130 $result = $this->pt->cx()->install(true);
131 $response = $result ? 'docket-dropino-updated' : 'docket-dropino-updated-failed';
132 do_action('docketcache/action/update/objectcache', $result);
133 break;
134
135 case 'docket-dismiss-dropino':
136 $result = $this->pt->co()->save('objectcacheoff', 'enable');
137 $response = $result ? 'docket-occache-disabled' : 'docket-occache-disabled-failed';
138 do_action('docketcache/action/dismiss/objectcache', $result);
139 break;
140
141 case 'docket-flush-oclog':
142 $result = $this->pt->flush_log();
143 $response = $result ? 'docket-log-flushed' : 'docket-log-flushed-failed';
144 do_action('docketcache/action/flush/log/objectcache', $result);
145 break;
146
147 case 'docket-flush-ocfile':
148 $result = $this->pt->flush_fcache($filename);
149 $response = $result ? 'docket-file-flushed' : 'docket-file-flushed-failed';
150 do_action('docketcache/action/flush/file/objectcache', $result, $filename);
151 break;
152 case 'docket-flush-opcache':
153 if (!$this->pt->opcache_function_exists('opcache_reset')) {
154 $result = false;
155 $response = 'docket-opcache-flushed-noreset-warn';
156 } else {
157 if ($this->pt->co()->lockexp('preload_lock_opcache_reset')) {
158 $result = false;
159 $response = 'docket-opcache-flushed-lock-warn';
160 } else {
161 if ($this->pt->co()->lockproc('opcache_reset', time() + 30)) {
162 $result = false;
163 $response = 'docket-opcache-flushed-warn';
164 } else {
165 $result = $this->pt->opcache_reset();
166 $response = $result ? 'docket-opcache-flushed' : 'docket-opcache-flushed-failed';
167 }
168 }
169 }
170
171 do_action('docketcache/action/flush/opcache', $result);
172 break;
173 case 'docket-flush-menucache':
174 $result = 0;
175 $ok = true;
176 if (\function_exists('wp_cache_flush_group') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
177 $result = wp_cache_flush_group('docketcache-menu');
178 $this->pt->co()->lookup_set('menucacheflushed', $result);
179 $response = 'docket-menucache-flushed';
180 } else {
181 $response = 'docket-menucache-flushed-failed';
182 $ok = false;
183 }
184
185 do_action('docketcache/action/flush/file/menucache', $ok, $result);
186 break;
187 case 'docket-flush-mocache':
188 $result = 0;
189 $ok = true;
190 if (\function_exists('wp_cache_flush_group') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
191 $result = wp_cache_flush_group('docketcache-mo');
192 $this->pt->co()->lookup_set('mocacheflushed', $result);
193 $response = 'docket-mocache-flushed';
194 } else {
195 $response = 'docket-mocache-flushed-failed';
196 $ok = false;
197 }
198
199 do_action('docketcache/action/flush/file/mocache', $ok, $result);
200 break;
201 case 'docket-flush-ocprecache':
202 $result = 0;
203 $ok = true;
204 if (\function_exists('wp_cache_flush_group') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
205 $result = wp_cache_flush_group('docketcache-precache');
206 $this->pt->co()->lookup_set('ocprecacheflushed', $result);
207 $response = 'docket-ocprecache-flushed';
208 } else {
209 $response = 'docket-ocprecache-flushed-failed';
210 $ok = false;
211 }
212
213 do_action('docketcache/action/flush/file/ocprecache', $ok, $result);
214 break;
215 case 'docket-flush-advcpost':
216 $result = 0;
217 $ok = true;
218 if (\function_exists('wp_cache_flush_group_match') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
219 $result = wp_cache_flush_group_match('docketcache-post');
220 $this->pt->co()->lookup_set('advcpostflushed', $result);
221 $response = 'docket-advcpost-flushed';
222 } else {
223 $response = 'docket-advcpost-flushed-failed';
224 $ok = false;
225 }
226
227 do_action('docketcache/action/flush/file/advcpost', $ok, $result);
228 break;
229 case 'docket-flush-transient':
230 $result = 0;
231 $ok = true;
232 if (\function_exists('wp_cache_flush_group') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
233 $result = wp_cache_flush_group(['transient', 'site-transient']);
234 $this->pt->co()->lookup_set('transientflushed', $result);
235 $response = 'docket-transient-flushed';
236 } else {
237 $response = 'docket-transient-flushed-failed';
238 $ok = false;
239 }
240
241 do_action('docketcache/action/flush/file/transient', $ok, $result);
242 break;
243 case 'docket-connect-cronbot':
244 $result = apply_filters('docketcache/filter/active/cronbot', true);
245 $response = $result ? 'docket-cronbot-connect' : 'docket-cronbot-connect-failed';
246 do_action('docketcache/action/connect/cronbot', $result);
247 break;
248 case 'docket-disconnect-cronbot':
249 $result = apply_filters('docketcache/filter/active/cronbot', false);
250 $response = $result ? 'docket-cronbot-disconnect' : 'docket-cronbot-disconnect-failed';
251 do_action('docketcache/action/disconnect/cronbot', $result);
252 break;
253 case 'docket-pong-cronbot':
254 $result = apply_filters('docketcache/filter/check/cronbot', false);
255 $response = $result ? 'docket-cronbot-pong' : 'docket-cronbot-pong-failed';
256 do_action('docketcache/action/pong/cronbot', $result);
257 break;
258 case 'docket-runevent-cronbot':
259 $response = 'docket-cronbot-runevent-failed';
260 $result = apply_filters('docketcache/filter/runevent/cronbot', false);
261 if (false !== $result) {
262 $this->pt->co()->lookup_set('cronbotrun', $result);
263 $response = 'docket-cronbot-runevent';
264 }
265
266 do_action('docketcache/action/runevent/cronbot', $result);
267 break;
268 case 'docket-runeventnow-cronbot':
269 $response = 'docket-cronbot-runevent-failed';
270 $result = apply_filters('docketcache/filter/runevent/cronbot', true);
271 if (false !== $result) {
272 $this->pt->co()->lookup_set('cronbotrun', $result);
273 $response = 'docket-cronbot-runevent';
274 }
275
276 do_action('docketcache/action/runeventnow/cronbot', $result);
277 break;
278 case 'docket-runeventuno-cronbot':
279 $response = 'docket-cronbot-runevent-failed';
280 $result = apply_filters('docketcache/filter/runevent/cronbot', $param);
281 if (false !== $result) {
282 $this->pt->co()->lookup_set('cronbotrun', $result);
283 $response = 'docket-cronbot-runevent';
284 }
285
286 do_action('docketcache/action/runeventuno/cronbot', $result);
287 break;
288 case 'docket-selectsite-cronbot':
289 if (isset($param['nv'])) {
290 $nv = sanitize_text_field($param['nv']);
291 if (!is_numeric($nv)) {
292 do_action('docketcache/action/switchsite', false, $nv);
293 break;
294 }
295
296 $this->pt->set_cron_siteid($nv);
297
298 $response = 'docket-cronbot-selectsite';
299
300 $is_switch = $this->pt->switch_cron_site();
301
302 @Crawler::fetch_admin(admin_url('/'));
303
304 if ($is_switch) {
305 restore_current_blog();
306 }
307
308 do_action('docketcache/action/switchsite', true, $nv);
309 }
310 break;
311 case 'docket-rungc':
312 $ok = false;
313 $response = 'docket-gcrun-failed';
314 $result = apply_filters('docketcache/filter/garbagecollector', true);
315 if (!empty($result) && \is_object($result)) {
316 if ($result->is_locked) {
317 $response = 'docket-gcrun-warn';
318 } else {
319 $this->pt->co()->lookup_set('gcrun', (array) $result);
320 $response = 'docket-gcrun';
321 }
322
323 $ok = true;
324 }
325
326 do_action('docketcache/action/garbagecollector', $ok, $result);
327 break;
328 case 'docket-runtime':
329 if (!empty($param['adr'])) {
330 $result = WpConfig::runtime_remove();
331 } else {
332 $result = WpConfig::runtime_install();
333 }
334 $response = $result ? 'docket-runtimeok' : 'docket-runtimeok-failed';
335 do_action('docketcache/action/updatewpconfig', $result);
336 break;
337 case 'docket-configreset':
338 $result = $this->pt->co()->reset();
339 $response = $result ? 'docket-configresetok' : 'docket-configresetok-failed';
340 do_action('docketcache/action/configreset', $result);
341 break;
342 case 'docket-cleanuppost':
343 if ($this->pt->co()->lockproc('cleanuppost_check', time() + 20)) {
344 $result = false;
345 $response = 'docket-cleanuppostok-warn';
346 } else {
347 $ok = false;
348 $response = 'docket-cleanuppostok-failed';
349 $result = $this->pt->cleanuppost();
350 if (!empty($result) && \is_object($result)) {
351 $this->pt->co()->lookup_set('cleanuppost', (array) $result);
352 $response = 'docket-cleanuppostok';
353 $ok = true;
354 }
355
356 do_action('docketcache/action/cleanuppost', $ok, $result);
357 }
358 break;
359 }
360
361 if (empty($response) && preg_match('@^docket-(default|enable|disable|save)-([a-z_]+)$@', $action, $mm)) {
362 $nk = $mm[1];
363 $nx = $mm[2];
364 if (\in_array($nx, $this->pt->co()->keys())) {
365 $option_name = $nx;
366 $ok = false;
367 $nv = '';
368 if ('save' === $nk && isset($param['nv'])) {
369 $nv = sanitize_text_field($param['nv']);
370 if (is_numeric($nv)) {
371 $nv = (int) $nv;
372 }
373
374 if (WpConfig::is_runtimeconst($nx) && WpConfig::is_runtimefalse()) {
375 $ok = false;
376 $response = 'docket-option-rtm-warn';
377 } elseif (WpConfig::has($nx)) {
378 $ok = false;
379 $response = 'docket-option-wpf-warn';
380 } else {
381 // storage options
382 if ('maxsize_disk' === $nx) {
383 $nvo = $nv;
384 switch ($nv) {
385 case '1G':
386 $nv = 1073741824;
387 break;
388 case '2G':
389 $nv = 2147483648;
390 break;
391 default:
392 $nv = 524288000; // 500M
393 }
394 } elseif ('maxfile' === $nx) {
395 switch ($nv) {
396 case '100K':
397 $nv = 100000;
398 break;
399 case '200K':
400 $nv = 200000;
401 break;
402 default:
403 $nv = 50000; // 50K
404 }
405 }
406
407 if (WpConfig::has($nx)) {
408 $response = 'docket-option-wpf-warn';
409 $this->pt->co()->save($nx, 'default');
410 } else {
411 $ok = $this->pt->co()->save($nx, $nv);
412 if (isset($nvo)) {
413 $nv = $nvo;
414 }
415
416 $response = $ok ? 'docket-option-save' : 'docket-option-failed';
417 }
418 }
419
420 $option_value = $nv;
421 } else {
422 if (WpConfig::has($nx)) {
423 $response = 'docket-option-wpf-warn';
424 $this->pt->co()->save($nx, 'default');
425 } else {
426 $okmsg = 'default' === $nk ? 'docket-option-default' : 'docket-option-'.$nk;
427 $ok = $this->pt->co()->save($nx, $nk);
428 $response = $ok ? $okmsg : 'docket-option-failed';
429 }
430 }
431
432 if ($ok) {
433 if ('wooaddtochartcrawling' === $nx && 'enable' == $nk && 'docket-option-wpf-warn' !== $response) {
434 $robotsfile = wp_normalize_path(ABSPATH).'robots.txt';
435 if (@is_file($robotsfile)) {
436 $response = 'docket-option-rbt-warn';
437 }
438 clearstatcache();
439 }
440 }
441
442 do_action(
443 'docketcache/action/option',
444 $ok,
445 [
446 'key' => $nx,
447 'value' => $nv,
448 'name' => $nk,
449 'action' => $action,
450 'response' => $response,
451 ]
452 );
453 }
454 }
455
456 return $response;
457 }
458
459 private function parse_action()
460 {
461 $param = [];
462 if (empty($_REQUEST) || !\is_array($_REQUEST) || !isset($_REQUEST['_wpnonce'], $_REQUEST['action'])) {
463 return;
464 }
465
466 $param = $_REQUEST;
467
468 $action = sanitize_text_field($param['action']);
469
470 if (\in_array($action, $this->action_token())) {
471 if (!wp_verify_nonce($param['_wpnonce'], $action)) {
472 $this->exit_failed($param);
473 exit;
474 }
475
476 $option_name = '';
477 $option_value = '';
478 $response = $this->run_action($action, $param, $option_name, $option_value);
479
480 if (!empty($response)) {
481 $args = [
482 'message' => $response,
483 ];
484
485 if (!empty($param['idx'])) {
486 $args['idx'] = sanitize_text_field($param['idx']);
487
488 if (!empty($param['adx'])) {
489 $args['adx'] = sanitize_text_field($param['adx']);
490 }
491
492 if (!empty($param['quiet']) && 1 === (int) $param['quiet']) {
493 $args['message'] = '';
494 }
495
496 if (!empty($option_name)) {
497 $args['nx'] = $option_name;
498 }
499
500 if (!empty($option_value)) {
501 $args['nv'] = $option_value;
502 }
503 }
504
505 $query = add_query_arg($args, $this->pt->get_page());
506 wp_safe_redirect(network_admin_url($query));
507 exit;
508 }
509 }
510 }
511
512 // see: View::action_notice()
513 private function screen_notice()
514 {
515 if (isset($_GET['message'])) {
516 $token = sanitize_text_field($_GET['message']);
517 $this->pt->token = $token;
518
519 $this->pt->notice = '';
520 $this->pt->inruntime = false;
521
522 $kx = '';
523
524 $option_name = esc_html__('Option', 'docket-cache');
525 if (!empty($_GET['nx'])) {
526 $kx = sanitize_text_field($_GET['nx']);
527 $nx = $this->pt->co()->keys($kx);
528 if (!empty($nx)) {
529 $option_name = $nx;
530
531 if (WpConfig::is_runtimeconst($kx)) {
532 $this->pt->inruntime = true;
533 }
534 }
535 }
536
537 $option_value = '';
538 if (!empty($_GET['nv'])) {
539 $nv = sanitize_text_field($_GET['nv']);
540 if (!empty($nv)) {
541 $option_value = $nv;
542 }
543 }
544
545 $notice_filter = apply_filters('docketcache/filter/reqaction/screennotice', $token, $option_name, $option_value, $kx);
546 if (!empty($notice_filter) && \is_string($notice_filter) && $notice_filter !== $token) {
547 $this->pt->notice = $notice_filter;
548
549 return;
550 }
551
552 switch ($token) {
553 case 'docket-occache-enabled':
554 $this->pt->notice = esc_html__('Object cache enabled.', 'docket-cache');
555 $this->pt->co()->save('objectcacheoff', 'default');
556 break;
557 case 'docket-occache-enabled-failed':
558 $this->pt->notice = esc_html__('Object cache could not be enabled.', 'docket-cache');
559 break;
560 case 'docket-occache-disabled':
561 $this->pt->notice = esc_html__('Object cache disabled.', 'docket-cache');
562 $this->pt->co()->save('objectcacheoff', 'enable');
563 break;
564 case 'docket-occache-disabled-failed':
565 $this->pt->notice = esc_html__('Object cache could not be disabled.', 'docket-cache');
566 break;
567 case 'docket-occache-flushed':
568 $total = $this->pt->co()->lookup_get('occacheflushed', true);
569 if (empty($total)) {
570 $total = 0;
571 }
572
573 if ($total > 0) {
574 $clmsg = esc_html__('Object cache was flushed.', 'docket-cache');
575 $clmsg .= '<div class="gc"><ul>';
576 $clmsg .= '<li><span>'.esc_html__('Total cache flushed', 'docket-cache').'</span>'.$total.'</li>';
577 $clmsg .= '</ul>';
578 $clmsg .= '</div>';
579 $this->pt->notice = $clmsg;
580 } else {
581 $this->pt->notice = esc_html__('The cache is empty, no cache needs to be flushed.', 'docket-cache');
582 }
583
584 break;
585 case 'docket-occache-flushed-warn':
586 $total = $this->pt->co()->lookup_get('occacheflushed', true);
587 if (empty($total)) {
588 $total = 0;
589 }
590
591 $cachedir = $this->pt->sanitize_rootpath($this->pt->cache_path);
592
593 /* translators: %d = seconds */
594 $clmsg = sprintf(esc_html__('Process aborted. The object cache is not fully flushed. The maximum execution time of %d seconds was exceeded.', 'docket-cache'), (int) \ini_get('max_execution_time'));
595 $clmsg .= '<div class="gc"><ul>';
596 $clmsg .= '<li><span class="single">'.esc_html__('Total cache flushed', 'docket-cache').'</span>: '.$total.'</li>';
597 $clmsg .= '<li><span class="bulllist">'.esc_html__('Alternatively, you may try to flush the cache by doing:', 'docket-cache');
598 $clmsg .= '<br>&bull; '.esc_html__('Hit the "Disable Object Cache" button.', 'docket-cache');
599 $clmsg .= '<br>&bull; '.esc_html__('Hit the "Flush Object Cache" button repeatedly until fully flushed.', 'docket-cache');
600 $clmsg .= '<br>&bull; '.esc_html__('Or run the WP-CLI command "wp cache flush".', 'docket-cache');
601
602 /* translators: %s = cache path */
603 $clmsg .= '<br>&bull; '.sprintf(esc_html__('Or manually remove the cache directory: %s', 'docket-cache'), $cachedir);
604 $clmsg .= '</span></li>';
605 $clmsg .= '</ul>';
606 $clmsg .= '</div>';
607 $this->pt->notice .= $clmsg;
608
609 break;
610 case 'docket-dropino-updated':
611 $this->pt->notice = esc_html__('Updated object cache Drop-In and enabled Docket object cache.', 'docket-cache');
612 break;
613 case 'docket-dropino-updated-failed':
614 $this->pt->notice = esc_html__('Object cache Drop-In could not be updated.', 'docket-cache');
615 break;
616 case 'docket-log-flushed':
617 $this->pt->notice = esc_html__('Cache log was flushed.', 'docket-cache');
618 break;
619 case 'docket-log-flushed-failed':
620 $this->pt->notice = esc_html__('Cache log could not be flushed.', 'docket-cache');
621 break;
622 case 'docket-file-flushed':
623 $this->pt->notice = esc_html__('Cache file was flushed.', 'docket-cache');
624 break;
625 case 'docket-file-flushed-failed':
626 $this->pt->notice = esc_html__('Cache file could not be flushed.', 'docket-cache');
627 break;
628 case 'docket-opcache-flushed':
629 $this->pt->notice = esc_html__('OPcache was flushed.', 'docket-cache');
630 break;
631 case 'docket-opcache-flushed-failed':
632 $this->pt->notice = esc_html__('OPcache could not be flushed.', 'docket-cache');
633 break;
634 case 'docket-opcache-flushed-warn':
635 $this->pt->notice = esc_html__('OPcache already flushed. Try again in a few seconds.', 'docket-cache');
636 break;
637 case 'docket-opcache-flushed-noreset-warn':
638 $this->pt->notice = esc_html__('OPcache could not be flushed, opcache_reset function disabled in PHP configuration.', 'docket-cache');
639 break;
640 case 'docket-opcache-flushed-lock-warn':
641 $this->pt->notice = esc_html__('Process locked. Flushing OPcache is in process. Try again in a few seconds.', 'docket-cache');
642 break;
643 case 'docket-cronbot-connect':
644 $this->pt->notice = esc_html__('Cronbot connected.', 'docket-cache');
645 break;
646 case 'docket-cronbot-connect-failed':
647 $msg = $this->pt->co()->lookup_get('cronboterror', true);
648 $errmsg = !empty($msg) ? ': '.$msg : '.';
649 /* translators: %s = error message */
650 $this->pt->notice = sprintf(esc_html__('Cronbot failed to connect%s', 'docket-cache'), $errmsg);
651 unset($msg, $errmsg);
652 break;
653 case 'docket-cronbot-disconnect':
654 $this->pt->notice = esc_html__('Cronbot disconnected.', 'docket-cache');
655 break;
656 case 'docket-cronbot-disconnect-failed':
657 $this->pt->notice = esc_html__('Cronbot failed to disconnect.', 'docket-cache');
658 break;
659 case 'docket-cronbot-pong':
660 case 'docket-cronbot-pong-failed':
661 $endpoint = parse_url($this->pt->cronbot_endpoint, \PHP_URL_HOST);
662 $errmsg = $this->pt->co()->lookup_get('cronboterror', true);
663 if (!empty($errmsg)) {
664 /* translators: %1$s: cronbot endpoint, %2$s = error message */
665 $this->pt->notice = sprintf(esc_html__('Pong from %1$s: %2$s.', 'docket-cache'), $endpoint, $errmsg);
666 } else {
667 /* translators: %s: cronbot endpoint */
668 $this->pt->notice = sprintf(esc_html__('Pong from %s : connected.', 'docket-cache'), $endpoint);
669 }
670 break;
671 case 'docket-cronbot-runevent':
672 $this->pt->notice = esc_html__('Running cron successful.', 'docket-cache');
673 $msg = $this->pt->co()->lookup_get('cronbotrun', true);
674
675 if (!empty($msg) && \is_array($msg)) {
676 $wmsg = '';
677 if (!empty($msg['wpcron_msg'])) {
678 $wmsg = $msg['wpcron_msg'];
679 }
680
681 if ($msg['wpcron_return'] > 1 && !empty($wmsg)) {
682 $this->pt->notice = $wmsg;
683 $this->pt->token = $this->pt->token.'-failed';
684 } else {
685 if (!empty($wmsg) && empty($msg['wpcron_event'])) {
686 $this->pt->notice = $wmsg;
687 } else {
688 if (!empty($msg['wpcron_uno'])) {
689 /* translators: %s = event hook */
690 $this->pt->notice = sprintf(esc_html__('Executed the %s event successful', 'docket-cache'), $msg['wpcron_uno']);
691 } else {
692 /* translators: %d = cron event */
693 $this->pt->notice = sprintf(esc_html__('Executed a total of %d cron events', 'docket-cache'), $msg['wpcron_event']);
694 }
695 }
696 }
697 }
698 unset($msg, $wmsg);
699
700 break;
701 case 'docket-cronbot-runevent-failed':
702 $this->pt->notice = esc_html__('Failed to run cron.', 'docket-cache');
703 break;
704 case 'docket-cronbot-selectsite':
705 $this->pt->notice = '';
706 break;
707 case 'docket-option-enable':
708 /* translators: %s = option name */
709 $this->pt->notice = sprintf(esc_html__('%s. Enabled.', 'docket-cache'), $option_name);
710 break;
711 case 'docket-option-disable':
712 /* translators: %s = option name */
713 $this->pt->notice = sprintf(esc_html__('%s. Disabled.', 'docket-cache'), $option_name);
714 break;
715 case 'docket-option-save':
716 if (!empty($option_value)) {
717 $noticewpconfig = '';
718 if ($this->pt->inruntime) {
719 $noticewpconfig = WpConfig::notice_filter($option_name, $option_value, $kx);
720 }
721
722 if (!empty($noticewpconfig)) {
723 $this->pt->notice = $noticewpconfig;
724 } else {
725 if ('default' === $option_value) {
726 /* translators: %s = option name */
727 $this->pt->notice = sprintf(esc_html__('%s resets to default.', 'docket-cache'), $option_name);
728 } else {
729 /* translators: %1$s = option name, %2$s = option_value */
730 $this->pt->notice = sprintf(esc_html__('%1$s set to %2$s.', 'docket-cache'), $option_name, $option_value);
731 }
732 }
733 } else {
734 /* translators: %s = option name */
735 $this->pt->notice = sprintf(esc_html__('%s updated.', 'docket-cache'), $option_name);
736 }
737 break;
738 case 'docket-option-default':
739 /* translators: %s = option name */
740 $this->pt->notice = sprintf(esc_html__('%s resets to default.', 'docket-cache'), $option_name);
741 break;
742 case 'docket-option-failed':
743 /* translators: %s = option name */
744 $this->pt->notice = sprintf(esc_html__('Failed to update option %s.', 'docket-cache'), $option_name);
745 break;
746 case 'docket-option-wpf-warn':
747 /* translators: %s = option name */
748 $this->pt->notice = sprintf(esc_html__('%s constant already defined or exists in wp-config.php file. This update has no effects.', 'docket-cache'), $option_name);
749 break;
750 case 'docket-option-rbt-warn':
751 $this->pt->notice = esc_html__('The physical robots.txt file exists. This update only works with the WordPress robots.txt virtual file.', 'docket-cache');
752 break;
753 case 'docket-option-rtm-warn':
754 /* translators: %s = option name */
755 $this->pt->notice = sprintf(esc_html__('%s requires runtime code to be installed. This update has no effects.', 'docket-cache'), $option_name);
756 break;
757 case 'docket-action-failed':
758 $this->pt->notice = esc_html__('Failed to execute the action request. Please try again.', 'docket-cache');
759 break;
760 case 'docket-gcrun':
761 $this->pt->notice = esc_html__('Executing the garbage collector successful', 'docket-cache');
762 $msg = $this->pt->co()->lookup_get('gcrun', true);
763 if (!empty($msg) && \is_array($msg)) {
764 $collect = (object) $msg;
765
766 $gcmsg = '<div class="gc"><ul>';
767 $gcmsg .= '<li><span>'.esc_html__('Cache MaxTTL', 'docket-cache').'</span>'.$collect->cache_maxttl.'</li>';
768 $gcmsg .= '<li><span>'.esc_html__('Cache File Limit', 'docket-cache').'</span>'.$collect->cache_maxfile.'</li>';
769 $gcmsg .= '<li><span>'.esc_html__('Cache Disk Limit', 'docket-cache').'</span>'.$this->pt->normalize_size($collect->cache_maxdisk).'</li>';
770 $gcmsg .= '<li><span>'.esc_html__('Cleanup Cache MaxTTL', 'docket-cache').'</span>'.$collect->cleanup_maxttl.'</li>';
771 $gcmsg .= '<li><span>'.esc_html__('Cleanup Cache File Limit', 'docket-cache').'</span>'.$collect->cleanup_maxfile.'</li>';
772 $gcmsg .= '<li><span>'.esc_html__('Cleanup Cache Disk Limit', 'docket-cache').'</span>'.$collect->cleanup_maxdisk.'</li>';
773
774 if ($collect->cleanup_expire > 0) {
775 $gcmsg .= '<li><span>'.esc_html__('Cleanup Cache Expire', 'docket-cache').'</span>'.$collect->cleanup_expire.'</li>';
776 }
777
778 if ($this->pt->get_precache_maxfile() > 0 && $collect->cleanup_precache_maxfile > 0) {
779 $gcmsg .= '<li><span>'.esc_html__('Cleanup Precache Limit', 'docket-cache').'</span>'.$collect->cleanup_precache_maxfile.'</li>';
780 }
781
782 if ($this->pt->cf()->is_dctrue('FLUSH_STALECACHE') && $collect->cleanup_stalecache > 0) {
783 $gcmsg .= '<li><span>'.esc_html__('Cleanup Stale Cache', 'docket-cache').'</span>'.$collect->cleanup_stalecache.'</li>';
784 }
785
786 $gcmsg .= '<li><span>'.esc_html__('Total Cache Cleanup', 'docket-cache').'</span>'.$collect->cache_cleanup.'</li>';
787 $gcmsg .= '<li><span>'.esc_html__('Total Cache Ignored', 'docket-cache').'</span>'.$collect->cache_ignore.'</li>';
788 $gcmsg .= '<li><span>'.esc_html__('Total Cache File', 'docket-cache').'</span>'.$collect->cache_file.'</li>';
789 $gcmsg .= '</ul></div>';
790
791 $this->pt->notice .= $gcmsg;
792 }
793 unset($msg, $gcmsg);
794 break;
795 case 'docket-gcrun-failed':
796 $this->pt->notice = esc_html__('Failed to run the garbage collector.', 'docket-cache');
797 $this->pt->co()->lookup_delete('gcrun');
798 break;
799 case 'docket-gcrun-warn':
800 $this->pt->notice = esc_html__('Process locked. The garbage collector is in process. Try again in a few seconds.', 'docket-cache');
801 $this->pt->co()->lookup_delete('gcrun');
802 break;
803 case 'docket-runtimeok':
804 $this->pt->notice = esc_html__('Updating wp-config.php file successful.', 'docket-cache');
805 break;
806 case 'docket-runtimeok-failed':
807 $this->pt->notice = esc_html__('Failed to update wp-config.php file.', 'docket-cache');
808 break;
809 case 'docket-configresetok':
810 $this->pt->notice = esc_html__('Reset all configuration successful.', 'docket-cache');
811 break;
812 case 'docket-configresetok-failed':
813 $this->pt->notice = esc_html__('Failed to reset configuration.', 'docket-cache');
814 break;
815 case 'docket-cleanuppostok':
816 $this->pt->notice = esc_html__('Cleanup Post successful', 'docket-cache');
817 $msg = $this->pt->co()->lookup_get('cleanuppost', true);
818 if (!empty($msg) && \is_array($msg)) {
819 $collect = (object) $msg;
820
821 $clmsg = '<div class="gc"><ul>';
822 $clmsg .= '<li><span>'.esc_html__('Revisions', 'docket-cache').'</span>'.$collect->revision.'</li>';
823 $clmsg .= '<li><span>'.esc_html__('Auto Drafts', 'docket-cache').'</span>'.$collect->autodraft.'</li>';
824 $clmsg .= '<li><span>'.esc_html__('Trash Bin', 'docket-cache').'</span>'.$collect->trashbin.'</li>';
825 $clmsg .= '</ul>';
826
827 if (isset($collect->site) && is_multisite() && $this->pt->get_current_select_siteid() <= 0) {
828 /* translators: %d = sites */
829 $clmsg .= '<p>'.sprintf(esc_html__('For %d sites', 'docket-cache'), $collect->site).'</p>';
830 }
831
832 $clmsg .= '</div>';
833
834 $this->pt->notice .= $clmsg;
835 }
836 unset($msg, $clmsg);
837 break;
838 case 'docket-cleanuppostok-failed':
839 $this->pt->notice = esc_html__('Failed to cleanup Post.', 'docket-cache');
840 break;
841 case 'docket-cleanuppostok-warn':
842 $this->pt->notice = esc_html__('Post already cleanup. Try again in a few seconds.', 'docket-cache');
843 break;
844 case 'docket-menucache-flushed':
845 $this->pt->notice = esc_html__('Menu cache was flushed.', 'docket-cache');
846 $total = $this->pt->co()->lookup_get('menucacheflushed', true);
847 if (empty($total)) {
848 $total = 0;
849 }
850
851 $clmsg = '<div class="gc"><ul>';
852 $clmsg .= '<li><span>'.esc_html__('Total cache flushed', 'docket-cache').'</span>'.$total.'</li>';
853 $clmsg .= '</ul>';
854 $clmsg .= '</div>';
855
856 $this->pt->notice .= $clmsg;
857 unset($total, $clmsg);
858 break;
859 case 'docket-menucache-flushed-failed':
860 $this->pt->notice = esc_html__('Menu cache could not be flushed. Docket Cache object-cache.php Drop-in is inactive.', 'docket-cache');
861 break;
862 case 'docket-mocache-flushed':
863 $this->pt->notice = esc_html__('Translation cache was flushed.', 'docket-cache');
864 $total = $this->pt->co()->lookup_get('mocacheflushed', true);
865 if (empty($total)) {
866 $total = 0;
867 }
868
869 $clmsg = '<div class="gc"><ul>';
870 $clmsg .= '<li><span>'.esc_html__('Total cache flushed', 'docket-cache').'</span>'.$total.'</li>';
871 $clmsg .= '</ul>';
872 $clmsg .= '</div>';
873
874 $this->pt->notice .= $clmsg;
875 unset($total, $clmsg);
876 break;
877 case 'docket-mocache-flushed-failed':
878 $this->pt->notice = esc_html__('Translation cache could not be flushed. Docket Cache object-cache.php Drop-in is inactive.', 'docket-cache');
879 break;
880 case 'docket-ocprecache-flushed':
881 $this->pt->notice = esc_html__('Object Precache was flushed.', 'docket-cache');
882 $total = $this->pt->co()->lookup_get('ocprecacheflushed', true);
883 if (empty($total)) {
884 $total = 0;
885 }
886
887 $clmsg = '<div class="gc"><ul>';
888 $clmsg .= '<li><span>'.esc_html__('Total cache flushed', 'docket-cache').'</span>'.$total.'</li>';
889 $clmsg .= '</ul>';
890 $clmsg .= '</div>';
891
892 $this->pt->notice .= $clmsg;
893 unset($total, $clmsg);
894 break;
895 case 'docket-ocprecache-flushed-failed':
896 $this->pt->notice = esc_html__('Object Precache could not be flushed. Docket Cache object-cache.php Drop-in is inactive.', 'docket-cache');
897 break;
898 case 'docket-advcpost-flushed':
899 $this->pt->notice = esc_html__('Advanced Post Cache was flushed.', 'docket-cache');
900 $total = $this->pt->co()->lookup_get('advcpostflushed', true);
901 if (empty($total)) {
902 $total = 0;
903 }
904
905 $clmsg = '<div class="gc"><ul>';
906 $clmsg .= '<li><span>'.esc_html__('Total cache flushed', 'docket-cache').'</span>'.$total.'</li>';
907 $clmsg .= '</ul>';
908 $clmsg .= '</div>';
909
910 $this->pt->notice .= $clmsg;
911 unset($total, $clmsg);
912 break;
913 case 'docket-advcpost-flushed-failed':
914 $this->pt->notice = esc_html__('Advanced Post Cache could not be flushed. Docket Cache object-cache.php Drop-in is inactive.', 'docket-cache');
915 break;
916 case 'docket-transient-flushed':
917 $this->pt->notice = esc_html__('Transient cache was flushed.', 'docket-cache');
918 $total = $this->pt->co()->lookup_get('transientflushed', true);
919 if (empty($total)) {
920 $total = 0;
921 }
922
923 $clmsg = '<div class="gc"><ul>';
924 $clmsg .= '<li><span>'.esc_html__('Total cache flushed', 'docket-cache').'</span>'.$total.'</li>';
925 $clmsg .= '</ul>';
926 $clmsg .= '</div>';
927
928 $this->pt->notice .= $clmsg;
929 unset($total, $clmsg);
930 break;
931 case 'docket-transient-flushed-failed':
932 $this->pt->notice = esc_html__('Transient cache could not be flushed. Docket Cache object-cache.php Drop-in is inactive.', 'docket-cache');
933 break;
934 }
935 }
936 }
937 }
938