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 / view / View_SettingsSections.php

View_SettingsSections.php in 404 Solution 4.3.0, at includes/view/View_SettingsSections.php

259 lines 17.8 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 * Presents advanced and general settings section templates.
9 */
10 class ABJ_404_Solution_View_SettingsSections extends ABJ_404_Solution_ViewComponent {
11
12 /** @param array<string, mixed> $options */
13 function getAdminOptionsPageAutoRedirects(array $options): string {
14 $options = $this->optionsPresenter->normalizeOptionsForView($options);
15
16 $spaces = esc_html("&nbsp;&nbsp;&nbsp;");
17 $content = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . "/html/adminOptionsDefault404Destination.html");
18 $content = $this->f->str_replace(
19 array('{default_404_destination_label}', '{behavior_tiles_html}'),
20 array(esc_html__('Default 404 destination', '404-solution'), $this->optionsPresenter->getBehaviorTilesHTML($options)),
21 $content
22 );
23
24 $selectedAutoRedirects = $this->optionsPresenter->getCheckedAttr($options, 'auto_redirects');
25 $selectedAutoSlugs = $this->optionsPresenter->getCheckedAttr($options, 'auto_slugs');
26 $selectedAutoCats = $this->optionsPresenter->getCheckedAttr($options, 'auto_cats');
27 $selectedAutoTags = $this->optionsPresenter->getCheckedAttr($options, 'auto_tags');
28 $selectedAutoTrashRedirect = $this->optionsPresenter->getCheckedAttr($options, 'auto_trash_redirect');
29
30 $html = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . "/html/adminOptionsAutoRedirects.html");
31 $html = $this->f->str_replace('{selectedAutoRedirects}', $selectedAutoRedirects, $html);
32 $html = $this->f->str_replace('{selectedAutoSlugs}', $selectedAutoSlugs, $html);
33 $html = $this->f->str_replace('{selectedAutoCats}', $selectedAutoCats, $html);
34 $html = $this->f->str_replace('{selectedAutoTags}', $selectedAutoTags, $html);
35 $html = $this->f->str_replace('{selectedAutoTrashRedirect}', $selectedAutoTrashRedirect, $html);
36 $html = $this->f->str_replace('{auto_deletion}', esc_attr($this->optionsPresenter->optStr($options, 'auto_deletion')), $html);
37 $html = $this->f->str_replace('{auto_302_expiration_days}', esc_attr($this->optionsPresenter->optStr($options, 'auto_302_expiration_days')), $html);
38 $html = $this->f->str_replace('{spaces}', $spaces, $html);
39 $html = $this->f->doNormalReplacements($html);
40 $content .= $html;
41
42 return $content;
43 }
44
45 /** @param array<string, mixed> $options */
46 function getAdminOptionsPageAdvancedContent(array $options): string {
47 $options = $this->optionsPresenter->normalizeOptionsForView($options);
48 $allPostTypesTemp = $this->viewReadService->getAllPostTypes();
49 $allPostTypes = esc_html(implode(', ', $allPostTypesTemp));
50
51 $html = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . "/html/settingsAdvancedContent.html");
52
53 $html = $this->f->str_replace('{recognized_post_types}',
54 str_replace('\\n', "\n", wp_kses_post($this->optionsPresenter->optStr($options, 'recognized_post_types'))), $html);
55 $html = $this->f->str_replace('{all_post_types}', $allPostTypes, $html);
56 $html = $this->f->str_replace('{recognized_categories}',
57 str_replace('\\n', "\n", wp_kses_post($this->optionsPresenter->optStr($options, 'recognized_categories'))), $html);
58 $html = $this->f->str_replace('{folders_files_ignore}',
59 str_replace('\\n', "\n", wp_kses_post($this->optionsPresenter->optStr($options, 'folders_files_ignore'))), $html);
60 $html = $this->f->str_replace('{suggest_regex_exclusions}',
61 str_replace('\\n', "\n", esc_textarea($this->optionsPresenter->optStr($options, 'suggest_regex_exclusions'))), $html);
62
63 $html = $this->f->str_replace('{add-exclude-page-data-url}',
64 "admin-ajax.php?action=echoRedirectToPages&includeDefault404Page=false&includeSpecial=false&nonce=" . wp_create_nonce('abj404_ajax'), $html);
65 $html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}',
66 __('(Type a page name)', '404-solution'), $html);
67 $html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}',
68 __('(A page has been selected.)', '404-solution'), $html);
69 $html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_CUSTOM_STRING}',
70 __('(A custom string has been entered.)', '404-solution'), $html);
71 $html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}',
72 __('(An external URL will be used.)', '404-solution'), $html);
73 $html = $this->f->str_replace('{loaded-excluded-pages}',
74 urlencode($this->optionsPresenter->optStr($options, 'excludePages[]')), $html);
75 $html = $this->f->doNormalReplacements($html);
76
77 return $html;
78 }
79
80 /** @param array<string, mixed> $options */
81 function getAdminOptionsPageAdvancedLogging(array $options): string {
82 $options = $this->optionsPresenter->normalizeOptionsForView($options);
83 $selectedLogRawIPs = $this->optionsPresenter->getCheckedAttr($options, 'log_raw_ips');
84 $selectedDebugLogging = $this->optionsPresenter->getCheckedAttr($options, 'debug_mode');
85
86 $debugExplanation = __('<a>View</a> the debug file.', '404-solution');
87 $debugLogLink = '?page=' . ABJ404_PP . '&subpage=abj404_debugfile';
88 $debugExplanation = $this->f->str_replace('<a>', '<a href="' . $debugLogLink . '" target="_blank" >', $debugExplanation);
89
90 $kbFileSize = $this->logger->getDebugFileSize() / 1024;
91 $kbFileSizePretty = number_format($kbFileSize, 2, ".", ",");
92 $mbFileSize = $this->logger->getDebugFileSize() / 1024 / 1000;
93 $mbFileSizePretty = number_format($mbFileSize, 2, ".", ",");
94 $debugFileSize = sprintf(__('Debug file size: %1$s KB (%2$s MB).', '404-solution'),
95 $kbFileSizePretty, $mbFileSizePretty);
96
97 $html = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . "/html/settingsAdvancedLogging.html");
98 $html = $this->f->str_replace('checked="log_raw_ips"', $selectedLogRawIPs, $html);
99 $html = $this->f->str_replace('checked="debug_mode"', $selectedDebugLogging, $html);
100 $html = $this->f->str_replace('{<a>View</a> the debug file.}', $debugExplanation, $html);
101 $html = $this->f->str_replace('{Debug file size: %s KB.}', $debugFileSize, $html);
102 $html = $this->f->str_replace('{ignore_dontprocess}',
103 str_replace('\\n', "\n", wp_kses_post($this->optionsPresenter->optStr($options, 'ignore_dontprocess'))), $html);
104 $html = $this->f->str_replace('{ignore_doprocess}',
105 str_replace('\\n', "\n", wp_kses_post($this->optionsPresenter->optStr($options, 'ignore_doprocess'))), $html);
106 $html = $this->f->doNormalReplacements($html);
107
108 return $html;
109 }
110
111 /** @param array<string, mixed> $options */
112 function getAdminOptionsPageAdvancedSystem(array $options): string {
113 $options = $this->optionsPresenter->normalizeOptionsForView($options);
114 $selectedRedirectAllRequests = $this->optionsPresenter->getCheckedAttr($options, 'redirect_all_requests');
115
116 $hideRedirectAllRequests = "false";
117 if (array_key_exists('disallow-redirect-all-requests', $options)
118 && $options['disallow-redirect-all-requests'] == '1') {
119 $hideRedirectAllRequests = "true";
120 }
121
122 $html = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . "/html/settingsAdvancedSystem.html");
123 $html = $this->f->str_replace('{DATABASE_VERSION}', esc_html($this->optionsPresenter->optStr($options, 'DB_VERSION')), $html);
124 $html = $this->f->str_replace('checked="redirect_all_requests"', $selectedRedirectAllRequests, $html);
125 $html = $this->f->str_replace('{disallow-redirect-all-requests}', $hideRedirectAllRequests, $html);
126 $html = $this->f->str_replace('{OPTION_MIN_AUTO_SCORE}', esc_attr($this->optionsPresenter->optStr($options, 'auto_score')), $html);
127 $html = $this->f->str_replace('{OPTION_AUTO_SCORE_TITLE}', esc_attr($this->optionsPresenter->optStr($options, 'auto_score_title')), $html);
128 $html = $this->f->str_replace('{OPTION_AUTO_SCORE_CATEGORY_TAG}', esc_attr($this->optionsPresenter->optStr($options, 'auto_score_category_tag')), $html);
129 $html = $this->f->str_replace('{OPTION_AUTO_SCORE_CONTENT}', esc_attr($this->optionsPresenter->optStr($options, 'auto_score_content')), $html);
130 $html = $this->f->str_replace('{OPTION_TEMPLATE_REDIRECT_PRIORITY}', esc_attr($this->optionsPresenter->optStr($options, 'template_redirect_priority')), $html);
131 $html = $this->f->str_replace('{days_wait_before_major_update}', esc_attr($this->optionsPresenter->optStr($options, 'days_wait_before_major_update')), $html);
132
133 $pluginAdminUsersRaw2 = $options['plugin_admin_users'];
134 if (is_array($pluginAdminUsersRaw2)) {
135 $pluginAdminUsers = implode("\n", $pluginAdminUsersRaw2);
136 } else {
137 $pluginAdminUsers = is_string($pluginAdminUsersRaw2) ? $pluginAdminUsersRaw2 : '';
138 }
139 $pluginAdminUsers = str_replace('\\n', "\n", wp_kses_post($pluginAdminUsers));
140 $html = $this->f->str_replace('{plugin_admin_users}', wp_kses_post($pluginAdminUsers), $html);
141 $html = $this->f->doNormalReplacements($html);
142
143 return $html;
144 }
145
146 /** @param array<string, mixed> $options */
147 function getAdminOptionsPageGeneralSettings(array $options): string {
148 $options = $this->optionsPresenter->normalizeOptionsForView($options);
149
150 $selectedDefaultRedirect301 = ($options['default_redirect'] == '301') ? ' selected' : '';
151 $selectedDefaultRedirect302 = ($options['default_redirect'] == '302') ? ' selected' : '';
152 $selectedDefaultRedirect307 = ($options['default_redirect'] == '307') ? ' selected' : '';
153 $selectedDefaultRedirect308 = ($options['default_redirect'] == '308') ? ' selected' : '';
154
155 $selectedCapture404 = $this->optionsPresenter->getCheckedAttr($options, 'capture_404');
156 $selectedSendErrorLogs = $this->optionsPresenter->getCheckedAttr($options, 'send_error_logs');
157
158 $selectedUnderSettings = "";
159 $selecteSsettingsLevel = "";
160 if ($options['menuLocation'] == 'settingsLevel') {
161 $selecteSsettingsLevel = " selected";
162 } else {
163 $selectedUnderSettings = " selected";
164 }
165
166 $adminTheme = isset($options['admin_theme']) ? $options['admin_theme'] : 'default';
167 $selectedThemeDefault = ($adminTheme == 'default') ? " selected" : "";
168 $selectedThemeCalm = ($adminTheme == 'calm') ? " selected" : "";
169 $selectedThemeMono = ($adminTheme == 'mono') ? " selected" : "";
170 $selectedThemeNeon = ($adminTheme == 'neon') ? " selected" : "";
171 $selectedThemeObsidian = ($adminTheme == 'obsidian') ? " selected" : "";
172 $themeDefault = __('Default', '404-solution');
173
174 $pluginLanguage = isset($options['plugin_language_override']) ? $options['plugin_language_override'] : '';
175 $selectedLanguageDefault = ($pluginLanguage == '') ? " selected" : "";
176 $selectedLanguageEnUS = ($pluginLanguage == 'en_US') ? " selected" : "";
177 $selectedLanguageDeDE = ($pluginLanguage == 'de_DE') ? " selected" : "";
178 $selectedLanguageEsES = ($pluginLanguage == 'es_ES') ? " selected" : "";
179 $selectedLanguageFrFR = ($pluginLanguage == 'fr_FR') ? " selected" : "";
180 $selectedLanguageItIT = ($pluginLanguage == 'it_IT') ? " selected" : "";
181 $selectedLanguagePtBR = ($pluginLanguage == 'pt_BR') ? " selected" : "";
182 $selectedLanguageNlNL = ($pluginLanguage == 'nl_NL') ? " selected" : "";
183 $selectedLanguageRuRU = ($pluginLanguage == 'ru_RU') ? " selected" : "";
184 $selectedLanguageJa = ($pluginLanguage == 'ja') ? " selected" : "";
185 $selectedLanguageZhCN = ($pluginLanguage == 'zh_CN') ? " selected" : "";
186 $selectedLanguageIdID = ($pluginLanguage == 'id_ID') ? " selected" : "";
187 $selectedLanguageSvSE = ($pluginLanguage == 'sv_SE') ? " selected" : "";
188 $disableAutoDarkMode = isset($options['disable_auto_dark_mode']) && $options['disable_auto_dark_mode'] == '1';
189 $disableAutoDarkModeChecked = $disableAutoDarkMode ? " checked" : "";
190
191 $logSizeBytes = $this->viewReadService->getLogDiskUsage();
192 $logSizeMB = round($logSizeBytes / (1024 * 1000), 2);
193 $totalLogLines = $this->viewReadService->getLogsCount(0);
194
195 $timeToDisplay = $this->statsRepository->getEarliestLogTimestamp();
196 $earliestLogDate = 'N/A';
197 if ($timeToDisplay >= 0) {
198 $earliestLogDate = date('Y/m/d', $timeToDisplay) . ' ' . date('h:i:s', $timeToDisplay) . '&nbsp;' .
199 date('A', $timeToDisplay);
200 }
201
202 $selectedRemoveMatches = $this->optionsPresenter->getCheckedAttr($options, 'remove_matches');
203 $notifyFrequency = isset($options['admin_notification_frequency']) ? (string)(is_scalar($options['admin_notification_frequency']) ? $options['admin_notification_frequency'] : 'instant') : 'instant';
204 $selectedNotifyInstant = ($notifyFrequency === 'instant') ? ' selected' : '';
205 $selectedNotifyDaily = ($notifyFrequency === 'daily') ? ' selected' : '';
206 $selectedNotifyWeekly = ($notifyFrequency === 'weekly') ? ' selected' : '';
207
208 $html = ABJ_404_Solution_FileSystemService::readFileContents(dirname(__DIR__) . "/html/adminOptionsGeneral.html");
209 $html = $this->f->str_replace('{selectedSendErrorLogs}', $selectedSendErrorLogs, $html);
210 $html = $this->f->str_replace('{selectedDefaultRedirect301}', $selectedDefaultRedirect301, $html);
211 $html = $this->f->str_replace('{selectedDefaultRedirect302}', $selectedDefaultRedirect302, $html);
212 $html = $this->f->str_replace('{selectedDefaultRedirect307}', $selectedDefaultRedirect307, $html);
213 $html = $this->f->str_replace('{selectedDefaultRedirect308}', $selectedDefaultRedirect308, $html);
214 $html = $this->f->str_replace('{selectedCapture404}', $selectedCapture404, $html);
215 $html = $this->f->str_replace('{admin_notification}', esc_attr($this->optionsPresenter->optStr($options, 'admin_notification')), $html);
216 $html = $this->f->str_replace('{capture_deletion}', esc_attr($this->optionsPresenter->optStr($options, 'capture_deletion')), $html);
217 $html = $this->f->str_replace('{manual_deletion}', esc_attr($this->optionsPresenter->optStr($options, 'manual_deletion')), $html);
218 $html = $this->f->str_replace('{maximum_log_disk_usage}', esc_attr($this->optionsPresenter->optStr($options, 'maximum_log_disk_usage')), $html);
219 $html = $this->f->str_replace('{logCurrentSizeDiskUsage}', (string)$logSizeMB, $html);
220 $html = $this->f->str_replace('{logCurrentRowCount}', (string)$totalLogLines, $html);
221 $html = $this->f->str_replace('{earliestLogDate}', $earliestLogDate, $html);
222 $html = $this->f->str_replace('{selectedRemoveMatches}', $selectedRemoveMatches, $html);
223 $html = $this->f->str_replace('{selectedUnderSettings}', $selectedUnderSettings, $html);
224 $html = $this->f->str_replace('{selecteSsettingsLevel}', $selecteSsettingsLevel, $html);
225 $html = $this->f->str_replace('{selectedThemeDefault}', $selectedThemeDefault, $html);
226 $html = $this->f->str_replace('{selectedThemeCalm}', $selectedThemeCalm, $html);
227 $html = $this->f->str_replace('{selectedThemeMono}', $selectedThemeMono, $html);
228 $html = $this->f->str_replace('{selectedThemeNeon}', $selectedThemeNeon, $html);
229 $html = $this->f->str_replace('{selectedThemeObsidian}', $selectedThemeObsidian, $html);
230 $html = $this->f->str_replace('{theme_default}', $themeDefault, $html);
231 $html = $this->f->str_replace('{selectedLanguageDefault}', $selectedLanguageDefault, $html);
232 $html = $this->f->str_replace('{selectedLanguageEnUS}', $selectedLanguageEnUS, $html);
233 $html = $this->f->str_replace('{selectedLanguageDeDE}', $selectedLanguageDeDE, $html);
234 $html = $this->f->str_replace('{selectedLanguageEsES}', $selectedLanguageEsES, $html);
235 $html = $this->f->str_replace('{selectedLanguageFrFR}', $selectedLanguageFrFR, $html);
236 $html = $this->f->str_replace('{selectedLanguageItIT}', $selectedLanguageItIT, $html);
237 $html = $this->f->str_replace('{selectedLanguagePtBR}', $selectedLanguagePtBR, $html);
238 $html = $this->f->str_replace('{selectedLanguageNlNL}', $selectedLanguageNlNL, $html);
239 $html = $this->f->str_replace('{selectedLanguageRuRU}', $selectedLanguageRuRU, $html);
240 $html = $this->f->str_replace('{selectedLanguageJa}', $selectedLanguageJa, $html);
241 $html = $this->f->str_replace('{selectedLanguageZhCN}', $selectedLanguageZhCN, $html);
242 $html = $this->f->str_replace('{selectedLanguageIdID}', $selectedLanguageIdID, $html);
243 $html = $this->f->str_replace('{selectedLanguageSvSE}', $selectedLanguageSvSE, $html);
244 $html = $this->f->str_replace('{disableAutoDarkModeChecked}', $disableAutoDarkModeChecked, $html);
245 $html = $this->f->str_replace('{admin_notification_email}', esc_attr($this->optionsPresenter->optStr($options, 'admin_notification_email')), $html);
246 $adminEmail = get_option('admin_email');
247 $html = $this->f->str_replace('{default_wordpress_admin_email}', is_string($adminEmail) ? $adminEmail : '', $html);
248 $html = $this->f->str_replace('{PHP_VERSION}', PHP_VERSION, $html);
249 $html = $this->f->str_replace('{selectedNotifyInstant}', $selectedNotifyInstant, $html);
250 $html = $this->f->str_replace('{selectedNotifyDaily}', $selectedNotifyDaily, $html);
251 $html = $this->f->str_replace('{selectedNotifyWeekly}', $selectedNotifyWeekly, $html);
252 $selectedAutoTrashJunk = $this->optionsPresenter->getCheckedAttr($options, 'auto_trash_junk_urls');
253 $html = $this->f->str_replace('{selectedAutoTrashJunk}', $selectedAutoTrashJunk, $html);
254 $html = $this->f->doNormalReplacements($html);
255
256 return $html;
257 }
258 }
259