PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / admin / actions / StatusLinkActionHandler.php

StatusLinkActionHandler.php in 404 Solution 4.3.0, at includes/admin/actions/StatusLinkActionHandler.php

73 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Handles captured-row status link actions such as ignore and organize later.
9 */
10 class ABJ_404_Solution_StatusLinkActionHandler {
11
12 /** @var ABJ_404_Solution_PluginLogicAdminActions */
13 private $parent;
14
15 public function __construct(ABJ_404_Solution_PluginLogicAdminActions $parent) {
16 $this->parent = $parent;
17 }
18
19 /** @return string */
20 public function handleIgnoreAction(): string {
21 return $this->handleStatusUpdate('ignore', 'abj404_ignore404', ABJ404_STATUS_IGNORED, 'ignore', 'ignored');
22 }
23
24 /** @return string */
25 public function handleLaterAction(): string {
26 return $this->handleStatusUpdate('later', 'abj404_organizeLater', ABJ404_STATUS_LATER, 'organize later', 'organize later');
27 }
28
29 /**
30 * @param string $paramName The $_GET parameter name.
31 * @param string $nonceAction The nonce action name.
32 * @param int $activeStatus The status constant to use when action=1.
33 * @param string $errorActionName Action name for error messages.
34 * @param string $successActionName Action name for success messages.
35 * @return string
36 */
37 private function handleStatusUpdate($paramName, $nonceAction, $activeStatus, $errorActionName, $successActionName): string {
38 if (!isset($_GET[$paramName])) {
39 return '';
40 }
41
42 if (!is_admin() || !$this->parent->verifyLinkNonce($nonceAction)) {
43 return '';
44 }
45
46 $operation = isset($_GET[$paramName]) && is_scalar($_GET[$paramName]) ? trim((string)$_GET[$paramName]) : '';
47 if ($operation !== '0' && $operation !== '1') {
48 $this->parent->getLogger()->debugMessage("Unexpected {$errorActionName} operation: " .
49 esc_html($operation));
50 return sprintf(__('Error: Bad %s operation specified.', '404-solution'), $errorActionName);
51 }
52
53 $id = isset($_GET['id']) && is_scalar($_GET['id']) ? (string)$_GET['id'] : '';
54 if ($id === '' || !$this->parent->getFunctions()->regexMatch('[0-9]+', $id)) {
55 return '';
56 }
57
58 $newstatus = $operation === '1' ? $activeStatus : ABJ404_STATUS_CAPTURED;
59 $message = $this->parent->getRedirectsRepo()->updateRedirectTypeStatus(absint($id), (string)$newstatus);
60 if ($message == '') {
61 if ($newstatus == ABJ404_STATUS_CAPTURED) {
62 return sprintf(__('Removed 404 URL from %s list successfully!', '404-solution'), $successActionName);
63 }
64 return sprintf(__('404 URL marked as %s successfully!', '404-solution'), $successActionName);
65 }
66
67 if ($newstatus == ABJ404_STATUS_CAPTURED) {
68 return sprintf(__('Error: unable to remove URL from %s list', '404-solution'), $successActionName);
69 }
70 return sprintf(__('Error: unable to mark URL as %s', '404-solution'), $successActionName);
71 }
72 }
73