| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Decides which destination warning, if any, a redirect table row should show. |
| 9 |
*/ |
| 10 |
class ABJ_404_Solution_RedirectDestinationWarningPolicy { |
| 11 |
|
| 12 |
/** |
| 13 |
* @param array<string, mixed> $row |
| 14 |
* @param mixed $rowType |
| 15 |
* @param string $rowFinalDest |
| 16 |
* @param string $destForView |
| 17 |
* @param bool $destinationIsMissing |
| 18 |
* @param array<mixed> $deadDestIds |
| 19 |
* @return array{exists: string, notExists: string, text: string, destForView: string} |
| 20 |
*/ |
| 21 |
public function resolve(array $row, $rowType, string $rowFinalDest, string $destForView, |
| 22 |
bool $destinationIsMissing, array $deadDestIds): array { |
| 23 |
$exists = ''; |
| 24 |
$notExists = 'display: none;'; |
| 25 |
$text = __("This page doesn't exist or is not published so the redirect won't work.", '404-solution'); |
| 26 |
|
| 27 |
if ($destinationIsMissing) { |
| 28 |
$exists = 'display: none;'; |
| 29 |
$notExists = ''; |
| 30 |
$text = __('Destination missing. Edit this redirect and choose a destination.', '404-solution'); |
| 31 |
if (trim((string)$destForView) === '') { |
| 32 |
$destForView = __('(Destination missing)', '404-solution'); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
if (array_key_exists('published_status', $row) && $row['published_status'] == '0') { |
| 37 |
$exists = 'display: none;'; |
| 38 |
$notExists = ''; |
| 39 |
if (trim((string)$destForView) === '') { |
| 40 |
$destForView = __('(Destination unavailable)', '404-solution'); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
$rowIdStr = is_scalar($row['id'] ?? '') ? (string)($row['id'] ?? '') : ''; |
| 45 |
if (in_array($rowIdStr, $deadDestIds, true)) { |
| 46 |
$exists = 'display: none;'; |
| 47 |
$notExists = ''; |
| 48 |
$text = __('Destination returned 404 recently, redirect suspended until destination is restored.', '404-solution'); |
| 49 |
} |
| 50 |
|
| 51 |
return array('exists' => $exists, 'notExists' => $notExists, 'text' => $text, 'destForView' => $destForView); |
| 52 |
} |
| 53 |
} |
| 54 |
|