| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Presents the Simple Mode options page. |
| 9 |
*/ |
| 10 |
class ABJ_404_Solution_View_SimpleSettings extends ABJ_404_Solution_ViewComponent { |
| 11 |
|
| 12 |
/** |
| 13 |
* Echo the Simple Mode options page. |
| 14 |
* @param array<string, mixed> $options The plugin options |
| 15 |
* @return void |
| 16 |
*/ |
| 17 |
function echoSimpleModeOptions($options) { |
| 18 |
$behaviorTilesHtml = $this->optionsPresenter->getBehaviorTilesHTML($options); |
| 19 |
|
| 20 |
$selectedAutoRedirects = $this->optionsPresenter->getCheckedAttr($options, 'auto_redirects'); |
| 21 |
$selectedCapture404 = $this->optionsPresenter->getCheckedAttr($options, 'capture_404'); |
| 22 |
$selectedDefaultRedirect301 = ($options['default_redirect'] == '301') ? 'selected' : ''; |
| 23 |
$selectedDefaultRedirect302 = ($options['default_redirect'] == '302') ? 'selected' : ''; |
| 24 |
$selectedDefaultRedirect307 = ($options['default_redirect'] == '307') ? 'selected' : ''; |
| 25 |
$selectedDefaultRedirect308 = ($options['default_redirect'] == '308') ? 'selected' : ''; |
| 26 |
|
| 27 |
$selectedThemeDefault = ($options['admin_theme'] == 'default') ? 'selected' : ''; |
| 28 |
$selectedThemeCalm = ($options['admin_theme'] == 'calm') ? 'selected' : ''; |
| 29 |
$selectedThemeMono = ($options['admin_theme'] == 'mono') ? 'selected' : ''; |
| 30 |
$selectedThemeNeon = ($options['admin_theme'] == 'neon') ? 'selected' : ''; |
| 31 |
$selectedThemeObsidian = ($options['admin_theme'] == 'obsidian') ? 'selected' : ''; |
| 32 |
|
| 33 |
$notifyFrequency = isset($options['admin_notification_frequency']) ? (string)(is_scalar($options['admin_notification_frequency']) ? $options['admin_notification_frequency'] : 'instant') : 'instant'; |
| 34 |
$selectedNotifyInstant = ($notifyFrequency === 'instant') ? 'selected' : ''; |
| 35 |
$selectedNotifyDaily = ($notifyFrequency === 'daily') ? 'selected' : ''; |
| 36 |
$selectedNotifyWeekly = ($notifyFrequency === 'weekly') ? 'selected' : ''; |
| 37 |
$selectedNotifyNever = ($notifyFrequency === 'never') ? 'selected' : ''; |
| 38 |
|
| 39 |
$html = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . "/html/adminOptionsSimple.html"); |
| 40 |
$html = $this->f->str_replace('{behaviorTiles}', $behaviorTilesHtml, $html); |
| 41 |
$html = $this->f->str_replace('{selectedAutoRedirects}', $selectedAutoRedirects, $html); |
| 42 |
$html = $this->f->str_replace('{selectedCapture404}', $selectedCapture404, $html); |
| 43 |
$html = $this->f->str_replace('{selectedDefaultRedirect301}', $selectedDefaultRedirect301, $html); |
| 44 |
$html = $this->f->str_replace('{selectedDefaultRedirect302}', $selectedDefaultRedirect302, $html); |
| 45 |
$html = $this->f->str_replace('{selectedDefaultRedirect307}', $selectedDefaultRedirect307, $html); |
| 46 |
$html = $this->f->str_replace('{selectedDefaultRedirect308}', $selectedDefaultRedirect308, $html); |
| 47 |
|
| 48 |
$html = $this->f->str_replace('{capture_deletion}', esc_attr($this->optionsPresenter->optStr($options, 'capture_deletion')), $html); |
| 49 |
$html = $this->f->str_replace('{admin_notification}', esc_attr($this->optionsPresenter->optStr($options, 'admin_notification')), $html); |
| 50 |
$html = $this->f->str_replace('{maximum_log_disk_usage}', esc_attr($this->optionsPresenter->optStr($options, 'maximum_log_disk_usage')), $html); |
| 51 |
|
| 52 |
$html = $this->f->str_replace('{selectedThemeDefault}', $selectedThemeDefault, $html); |
| 53 |
$html = $this->f->str_replace('{selectedThemeCalm}', $selectedThemeCalm, $html); |
| 54 |
$html = $this->f->str_replace('{selectedThemeMono}', $selectedThemeMono, $html); |
| 55 |
$html = $this->f->str_replace('{selectedThemeNeon}', $selectedThemeNeon, $html); |
| 56 |
$html = $this->f->str_replace('{selectedThemeObsidian}', $selectedThemeObsidian, $html); |
| 57 |
$html = $this->f->str_replace('{theme_default}', __('Default (Follows WordPress)', '404-solution'), $html); |
| 58 |
|
| 59 |
$html = $this->f->str_replace('{Core Settings}', __('Core Settings', '404-solution'), $html); |
| 60 |
$html = $this->f->str_replace('{404 Capture}', __('404 Capture', '404-solution'), $html); |
| 61 |
$html = $this->f->str_replace('{Maintenance}', __('Maintenance', '404-solution'), $html); |
| 62 |
$html = $this->f->str_replace('{Default 404 destination}', __('Default 404 destination', '404-solution'), $html); |
| 63 |
$html = $this->f->str_replace('{Where to send visitors when a 404 error occurs}', __('Where to send visitors when a 404 error occurs', '404-solution'), $html); |
| 64 |
$html = $this->f->str_replace('{Create automatic redirects}', __('Create automatic redirects', '404-solution'), $html); |
| 65 |
$html = $this->f->str_replace( |
| 66 |
'{Automatically redirect 404s to similar pages that score at least %1$s out of 100. To change that number, switch to Advanced Mode and look for %2$s in the System section.}', |
| 67 |
sprintf( |
| 68 |
/* translators: 1: the configured minimum match score, e.g. 90. 2: the localized label of the Minimum match score setting, so it matches the Advanced Mode screen exactly. */ |
| 69 |
__('Automatically redirect 404s to similar pages that score at least %1$s out of 100. To change that number, switch to Advanced Mode and look for %2$s in the System section.', '404-solution'), |
| 70 |
esc_html($this->getMinimumMatchScoreForDisplay($options)), |
| 71 |
esc_html(__('Minimum match score', '404-solution')) |
| 72 |
), |
| 73 |
$html |
| 74 |
); |
| 75 |
$html = $this->f->str_replace('{Redirect type}', __('Redirect type', '404-solution'), $html); |
| 76 |
$html = $this->f->str_replace('{Permanent 301}', __('Permanent 301', '404-solution'), $html); |
| 77 |
$html = $this->f->str_replace('{Temporary 302}', __('Temporary 302', '404-solution'), $html); |
| 78 |
$html = $this->f->str_replace('{301 for SEO, 302 for temporary changes}', __('301 for SEO, 302 for temporary changes', '404-solution'), $html); |
| 79 |
$html = $this->f->str_replace('{Collect incoming 404 URLs}', __('Collect incoming 404 URLs', '404-solution'), $html); |
| 80 |
$html = $this->f->str_replace('{Log 404 errors so you can review and fix them}', __('Log 404 errors so you can review and fix them', '404-solution'), $html); |
| 81 |
$html = $this->f->str_replace('{Delete captured URLs after}', __('Delete captured URLs after', '404-solution'), $html); |
| 82 |
$html = $this->f->str_replace('{days}', __('days', '404-solution'), $html); |
| 83 |
$html = $this->f->str_replace('{Auto-remove old 404 records (0 to keep forever)}', __('Auto-remove old 404 records (0 to keep forever)', '404-solution'), $html); |
| 84 |
$html = $this->f->str_replace('{Notify me when captured URLs exceed}', __('Notify me when captured URLs exceed', '404-solution'), $html); |
| 85 |
$html = $this->f->str_replace('{URLs}', __('URLs', '404-solution'), $html); |
| 86 |
$html = $this->f->str_replace('{Show admin notice when 404 count gets high (0 to disable)}', __('Show admin notice when 404 count gets high (0 to disable)', '404-solution'), $html); |
| 87 |
$html = $this->f->str_replace('{Maximum log storage}', __('Maximum log storage', '404-solution'), $html); |
| 88 |
$html = $this->f->str_replace('{Oldest logs are deleted when this limit is reached}', __('Oldest logs are deleted when this limit is reached', '404-solution'), $html); |
| 89 |
$html = $this->f->str_replace('{Admin theme}', __('Admin theme', '404-solution'), $html); |
| 90 |
$html = $this->f->str_replace('{Calm Ops (Light)}', __('Calm Ops (Light)', '404-solution'), $html); |
| 91 |
$html = $this->f->str_replace('{Monochrome Minimal (Light)}', __('Monochrome Minimal (Light)', '404-solution'), $html); |
| 92 |
$html = $this->f->str_replace('{Neon Slate (Dark)}', __('Neon Slate (Dark)', '404-solution'), $html); |
| 93 |
$html = $this->f->str_replace('{Obsidian Blue (Dark)}', __('Obsidian Blue (Dark)', '404-solution'), $html); |
| 94 |
$html = $this->f->str_replace('{Save Settings}', __('Save Settings', '404-solution'), $html); |
| 95 |
$html = $this->f->str_replace('{Need more control?}', __('Need more control?', '404-solution'), $html); |
| 96 |
$html = $this->f->str_replace('{Switch to Advanced Mode}', __('Switch to Advanced Mode', '404-solution'), $html); |
| 97 |
$html = $this->f->str_replace('{for 30+ additional options.}', __('for 30+ additional options.', '404-solution'), $html); |
| 98 |
|
| 99 |
$html = $this->f->str_replace('{selectedNotifyInstant}', $selectedNotifyInstant, $html); |
| 100 |
$html = $this->f->str_replace('{selectedNotifyDaily}', $selectedNotifyDaily, $html); |
| 101 |
$html = $this->f->str_replace('{selectedNotifyWeekly}', $selectedNotifyWeekly, $html); |
| 102 |
$html = $this->f->str_replace('{selectedNotifyNever}', $selectedNotifyNever, $html); |
| 103 |
$html = $this->f->str_replace('{Email notification frequency}', __('Email notification frequency', '404-solution'), $html); |
| 104 |
$html = $this->f->str_replace('{Instant (when threshold exceeded)}', __('Instant (when threshold exceeded)', '404-solution'), $html); |
| 105 |
$html = $this->f->str_replace('{Daily digest}', __('Daily digest', '404-solution'), $html); |
| 106 |
$html = $this->f->str_replace('{Weekly digest}', __('Weekly digest', '404-solution'), $html); |
| 107 |
$html = $this->f->str_replace('{Never}', __('Never', '404-solution'), $html); |
| 108 |
$html = $this->f->str_replace('{Choose how often to receive email notifications about captured 404s.}', __('Choose how often to receive email notifications about captured 404s.', '404-solution'), $html); |
| 109 |
$html = $this->f->str_replace('{Temporary 307 (preserve method)}', __('Temporary 307 (preserve method)', '404-solution'), $html); |
| 110 |
$html = $this->f->str_replace('{Permanent 308 (preserve method)}', __('Permanent 308 (preserve method)', '404-solution'), $html); |
| 111 |
|
| 112 |
echo $html; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* The minimum match score to name in the Simple Mode help text. |
| 117 |
* |
| 118 |
* Simple Mode does not render the auto_score field itself (it lives in |
| 119 |
* Advanced Mode > System), so the help text is the only place a simple-mode |
| 120 |
* admin can learn what the bar currently is. Always report the value the |
| 121 |
* matcher will actually apply rather than the shipped 90, so an admin who |
| 122 |
* already changed it is not told the wrong number. |
| 123 |
* |
| 124 |
* Delegates to MinimumAutoRedirectScore so this screen and the admin-only |
| 125 |
* note on the front-end suggestions page can never quote different numbers |
| 126 |
* for the same setting. |
| 127 |
* |
| 128 |
* @param array<string, mixed> $options The plugin options. |
| 129 |
* @return string The configured score, or the shipped default when the |
| 130 |
* stored value is missing, blank, or not a number. |
| 131 |
*/ |
| 132 |
private function getMinimumMatchScoreForDisplay($options) { |
| 133 |
return ABJ_404_Solution_MinimumAutoRedirectScore::forDisplay($options); |
| 134 |
} |
| 135 |
} |
| 136 |
|