";
$abj404view->echoPostBox("abj404-importRedirects", __('Import', '404-solution'), $html);
// ------------------------------------
$url = "?page=" . ABJ404_PP . "&subpage=abj404_tools";
$link = wp_nonce_url($url, "abj404_purgeRedirects");
// read the html content.
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/toolsPurgeForm.html");
// do special replacements
$html = $this->f->str_replace('{toolsPurgeFormActionLink}', $link, $html);
// constants and translations.
$html = $this->f->doNormalReplacements($html);
echo "
";
// ------------------------------------
$link = wp_nonce_url("?page=" . ABJ404_PP . "&subpage=abj404_tools", "abj404_runMaintenance");
$link .= '&manually_fired=true';
// read the html content.
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/toolsEtcForm.html");
// do special replacements
$html = $this->f->str_replace('{toolsMaintenanceFormActionLink}', $link, $html);
// constants and translations.
$html = $this->f->doNormalReplacements($html);
echo "
";
// ------------------------------------
// Cache management tools
$ngramLink = wp_nonce_url("?page=" . ABJ404_PP . "&subpage=abj404_tools", "abj404_rebuildNgramCache");
$spellingLink = wp_nonce_url("?page=" . ABJ404_PP . "&subpage=abj404_tools", "abj404_clearSpellingCache");
// read the html content.
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/toolsCacheForm.html");
// do special replacements
$html = $this->f->str_replace('{toolsNgramCacheFormActionLink}', $ngramLink, $html);
$html = $this->f->str_replace('{toolsSpellingCacheFormActionLink}', $spellingLink, $html);
// constants and translations.
$html = $this->f->doNormalReplacements($html);
echo "
";
}
function echoAdminOptionsPage() {
global $abj404view;
global $abj404viewSuggestions;
// If globals are not set, use sensible defaults
if ($abj404view === null) {
$abj404view = $this;
}
$options = $this->logic->getOptions();
if (!is_array($options)) {
$options = [];
}
// if the current URL does not match the chosen menuLocation then redirect to the correct URL
$urlParts = parse_url(urldecode($_SERVER['REQUEST_URI']));
$currentURL = $urlParts['path'];
if (is_array($options) && isset($options['menuLocation']) &&
$options['menuLocation'] == 'settingsLevel') {
if ($this->f->strpos($currentURL, 'options-general.php') !== false) {
// the option changed and we're at the wrong URL now, so we redirect to the correct one.
$this->logic->forceRedirect(admin_url() . "admin.php?page=" .
ABJ404_PP . '&subpage=abj404_options');
}
} else if ($this->f->strpos($currentURL, 'admin.php') !== false) {
// if the current URL has admin.php then the URLs don't match and we need to reload.
$this->logic->forceRedirect(admin_url() . "options-general.php?page=" .
ABJ404_PP . '&subpage=abj404_options');
}
//General Options
echo "
";
}
/**
* @global type $abj404dao
* @global type $abj404logic
*/
function echoAdminEditRedirectPage() {
$options = $this->logic->getOptions();
// this line assures that text will appear below the page tabs at the top.
echo "
";
echo "
" . __('Redirect Details', '404-solution') . " ";
$link = wp_nonce_url("?page=" . ABJ404_PP . "&subpage=abj404_edit", "abj404editRedirect");
echo '
";
}
function echoRedirectDestinationOptionsOthers($dest, $rows) {
$content = array();
$rowCounter = 0;
$currentPostType = '';
foreach ($rows as $row) {
$rowCounter++;
$id = $row->id;
$theTitle = get_the_title($id);
$thisval = $id . "|" . ABJ404_TYPE_POST;
$selected = "";
if ($thisval == $dest) {
$selected = " selected";
}
$_REQUEST[ABJ404_PP]['debug_info'] = 'Before row: ' . $rowCounter . ', Title: ' . $theTitle .
', Post type: ' . $row->post_type;
if ($row->post_type != $currentPostType) {
if ($currentPostType != '') {
$content[] = "\n" . '' . "\n";
}
$content[] = "\n" . '
' . "\n";
$currentPostType = $row->post_type;
}
// this is split in this ridiculous way to help me figure out how to resolve a memory issue.
// (https://wordpress.org/support/topic/options-tab-is-not-loading/)
$content[] = "\n ";
// insert some spaces for child pages.
for ($i = 0; $i < $row->depth; $i++) {
$content[] = " ";
}
$content[] = __(ucwords($row->post_type), '404-solution');
$content[] = ": ";
$content[] = esc_html($theTitle);
$content[] = " ";
$_REQUEST[ABJ404_PP]['debug_info'] = 'After row: ' . $rowCounter . ', Title: ' . $theTitle .
', Post type: ' . $row->post_type;
}
$content[] = "\n" . ' ' . "\n";
$_REQUEST[ABJ404_PP]['debug_info'] = 'Cleared after building redirect destination page list.';
return implode('', $content);
}
function echoRedirectDestinationOptionsCatsTags($dest) {
$content = "";
$content .= "\n" . '
' . "\n";
$customTagsEtc = array();
// categories ---------------------------------------------
$cats = $this->dao->getPublishedCategories();
foreach ($cats as $cat) {
$taxonomy = $cat->taxonomy;
if ($taxonomy != 'category') {
continue;
}
$id = $cat->term_id;
$theTitle = $cat->name;
$thisval = $id . "|" . ABJ404_TYPE_CAT;
$selected = "";
if ($thisval == $dest) {
$selected = " selected";
}
$content .= "\n" . __('Category', '404-solution') . ": " . $theTitle . " ";
}
$content .= "\n" . ' ' . "\n";
$customTagsEtc = $this->logic->getMapOfCustomCategories($cats);
// tags ---------------------------------------------
$content .= "\n" . '
' . "\n";
$tags = $this->dao->getPublishedTags();
foreach ($tags as $tag) {
$id = $tag->term_id;
$theTitle = $tag->name;
$thisval = $id . "|" . ABJ404_TYPE_TAG;
$selected = "";
if ($thisval == $dest) {
$selected = " selected";
}
$content .= "\n" . __('Tag', '404-solution') . ": " . $theTitle . " ";
}
$content .= "\n" . ' ' . "\n";
// custom ---------------------------------------------
foreach ($customTagsEtc as $taxonomy => $catRow) {
$content .= "\n" . '
' . "\n";
foreach ($catRow as $cat) {
$id = $cat->term_id;
$theTitle = $cat->name;
$thisval = $id . "|" . ABJ404_TYPE_CAT;
$selected = "";
if ($thisval == $dest) {
$selected = " selected";
}
$content .= "\n" . __('Custom', '404-solution') . ": " . $theTitle . " ";
}
$content .= "\n" . ' ' . "\n";
}
return $content;
}
/**
* @global type $abj404dao
*/
function echoAdminCapturedURLsPage() {
$sub = 'abj404_captured';
$tableOptions = $this->logic->getTableOptions($sub);
$timezone = get_option('timezone_string');
if ('' == $timezone) {
$timezone = 'UTC';
}
date_default_timezone_set($timezone);
echo $this->getTabFilters($sub, $tableOptions);
echo "
";
echo $this->getPaginationLinks($sub);
// bulk operations dropdown -------------
$bulkOptions = array();
if ($tableOptions['filter'] != ABJ404_STATUS_CAPTURED) {
$bulkOptions[] = '{Mark as Captured} ';
}
if ($tableOptions['filter'] != ABJ404_STATUS_IGNORED) {
$bulkOptions[] = '{Mark as Ignored} ';
}
if ($tableOptions['filter'] != ABJ404_STATUS_LATER) {
$bulkOptions[] = '{Organize Later} ';
}
if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) {
$bulkOptions[] = '{Move to Trash} ';
}
$bulkOptions[] = '{Create a Redirect} ';
$allBulkOptions = implode("\n", $bulkOptions);
$url = $this->getBulkOperationsFormURL($sub, $tableOptions);
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/bulkOperationsDropdown.html");
$html = $this->f->str_replace('{action_url}', $url, $html);
$html = $this->f->str_replace('{bulkOptions}', $allBulkOptions, $html);
$html = $this->f->doNormalReplacements($html);
echo $html;
// empty trash button -------------
if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) {
$eturl = "?page=" . ABJ404_PP . "&subpage=abj404_captured&filter=" . ABJ404_TRASH_FILTER .
"&subpage=abj404_captured";
$eturl = wp_nonce_url($eturl, 'abj404_bulkProcess');
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/emptyTrashButton.html");
$html = $this->f->str_replace('{action_url}', $eturl, $html);
$html = $this->f->str_replace('{action_value}', 'emptyCapturedTrash', $html);
$html = $this->f->doNormalReplacements($html);
echo $html;
}
// ----------
echo "
";
echo $this->getCapturedURLSPageTable($sub);
echo "
";
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/bulkOperationsDropdown2.html");
$html = $this->f->str_replace('{action_url}', $url, $html);
$html = $this->f->str_replace('{bulkOptions}', $allBulkOptions, $html);
$html = $this->f->doNormalReplacements($html);
echo $html;
echo $this->getPaginationLinks($sub, false);
echo "
";
}
function getCapturedURLSPageTable($sub) {
$tableOptions = $this->logic->getTableOptions($sub);
// ----------------------------------------------
// these are used for a GET request so they're not translated.
$columns = array();
$columns['url']['title'] = __('URL', '404-solution');
$columns['url']['orderby'] = "url";
$columns['url']['width'] = "48%";
$columns['hits']['title'] = __('Hits', '404-solution');
$columns['hits']['orderby'] = "logshits";
$columns['hits']['width'] = "7%";
$columns['hits']['title_attr'] = __('Changes may not be updated immediately when ordering by this column', '404-solution');
$columns['timestamp']['title'] = __('Created', '404-solution');
$columns['timestamp']['orderby'] = "timestamp";
$columns['timestamp']['width'] = "20%";
$columns['last_used']['title'] = __('Last Used', '404-solution');
$columns['last_used']['orderby'] = "last_used";
$columns['last_used']['width'] = "20%";
$columns['last_used']['title_attr'] = __('Changes may not be updated immediately when ordering by this column', '404-solution');
$html = "
";
$html .= "";
$html .= $this->getTableColumns($sub, $columns);
$html .= " ";
$html .= "";
$html .= $this->getTableColumns($sub, $columns);
$html .= " ";
$html .= "";
$rows = $this->dao->getRedirectsForView($sub, $tableOptions);
$displayed = 0;
$y = 1;
foreach ($rows as $row) {
$displayed++;
$hits = $row['logshits'];
$last_used = $row['last_used'];
if ($last_used != 0) {
$last = date("Y/m/d h:i:s A", abs(intval($last_used)));
} else {
$last = __('Never Used', '404-solution');
}
// Build action links using helper method
$links = $this->buildTableActionLinks($row, $sub, $tableOptions, true);
extract($links);
$class = "";
if ($y == 0) {
$class = "alternate";
$y++;
} else {
$y = 0;
$class = "normal-non-alternate";
}
// ------------------------
$rowActions = array();
if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) {
$rowActions[] = '{Edit} ';
}
$rowActions[] = '{trashtitle} ';
if ($row['logsid'] > 0) {
$rowActions[] = '{View Logs} ';
} else {
$rowActions[] = '{(No logs)} ';
}
if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) {
$rowActions[] = '{Delete Permanently} ';
} else {
$rowActions[] = '{ignoreTitle} ';
$rowActions[] = '{laterTitle} ';
}
$allRowActions = implode("\n | ", $rowActions);
// Build full URL with WordPress base path for subdirectory installations
$fullVisitorURL = esc_url(home_url($row['url']));
$tempHtml = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/tableRowCapturedURLs.html");
$tempHtml = $this->f->str_replace('{rowActions}', $allRowActions, $tempHtml);
$tempHtml = $this->f->str_replace('{rowid}', $row['id'], $tempHtml);
$tempHtml = $this->f->str_replace('{rowClass}', $class, $tempHtml);
$tempHtml = $this->f->str_replace('{editLink}', $fullVisitorURL, $tempHtml);
$tempHtml = $this->f->str_replace('{logsLink}', $logslink, $tempHtml);
$tempHtml = $this->f->str_replace('{trashLink}', $trashlink, $tempHtml);
$tempHtml = $this->f->str_replace('{ajaxTrashLink}', $ajaxTrashLink, $tempHtml);
$tempHtml = $this->f->str_replace('{trashtitle}', $trashtitle, $tempHtml);
$tempHtml = $this->f->str_replace('{ignoreLink}', $ignorelink, $tempHtml);
$tempHtml = $this->f->str_replace('{ignoreTitle}', $ignoretitle, $tempHtml);
$tempHtml = $this->f->str_replace('{laterLink}', $laterlink, $tempHtml);
$tempHtml = $this->f->str_replace('{laterTitle}', $latertitle, $tempHtml);
$tempHtml = $this->f->str_replace('{deleteLink}', $deletelink, $tempHtml);
$tempHtml = $this->f->str_replace('{url}', esc_html($row['url']), $tempHtml);
$tempHtml = $this->f->str_replace('{hits}', esc_html($hits), $tempHtml);
$tempHtml = $this->f->str_replace('{created_date}',
esc_html(date("Y/m/d h:i:s A", abs(intval($row['timestamp'])))), $tempHtml);
$tempHtml = $this->f->str_replace('{last_used_date}', esc_html($last), $tempHtml);
$tempHtml = $this->f->doNormalReplacements($tempHtml);
$html .= $tempHtml;
}
if ($displayed == 0) {
$html .= "";
$html .= " ";
$html .= "" . __('No Captured 404 Records To Display', '404-solution') . " ";
$html .= " ";
$html .= " ";
}
$html .= " ";
$html .= "
";
return $html;
}
/**
* @global type $abj404dao
* @global type $abj404logic
*/
function echoAdminRedirectsPage() {
$sub = 'abj404_redirects';
$tableOptions = $this->logic->getTableOptions($sub);
// Sanitizing unchecked table options
$tableOptions = $this->logic->sanitizePostData($tableOptions);
echo $this->getTabFilters($sub, $tableOptions);
$timezone = get_option('timezone_string');
if ('' == $timezone) {
$timezone = 'UTC';
}
date_default_timezone_set($timezone);
echo "
";
if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) {
$htmlTop = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/paginationLinksTop.html");
echo $this->f->doNormalReplacements($htmlTop);
}
echo $this->getPaginationLinks($sub);
// bulk operations dropdown -------------
$bulkOptions = array();
if ($tableOptions['filter'] != ABJ404_STATUS_AUTO) {
$bulkOptions[] = '
{Edit Redirects} ';
}
if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) {
$bulkOptions[] = '
{Move to Trash} ';
}
if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) {
$bulkOptions[] = '
{Restore Redirects} ';
$bulkOptions[] = '
{Delete Permanently} ';
}
$allBulkOptions = implode("\n", $bulkOptions);
$url = $this->getBulkOperationsFormURL($sub, $tableOptions);
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/bulkOperationsDropdown.html");
$html = $this->f->str_replace('{action_url}', $url, $html);
$html = $this->f->str_replace('{bulkOptions}', $allBulkOptions, $html);
$html = $this->f->doNormalReplacements($html);
echo $html;
// ------------------ empty trash button
if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) {
echo "
";
$eturl = "?page=" . ABJ404_PP . "&filter=" . ABJ404_TRASH_FILTER . "&subpage=" . $sub;
$eturl = wp_nonce_url($eturl, "abj404_bulkProcess");
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/emptyTrashButton.html");
$html = $this->f->str_replace('{action_url}', $eturl, $html);
$html = $this->f->str_replace('{action_value}', 'emptyRedirectTrash', $html);
$html = $this->f->doNormalReplacements($html);
echo $html;
echo "
";
}
echo "
";
echo $this->getAdminRedirectsPageTable($sub);
echo "
";
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/bulkOperationsDropdown2.html");
$html = $this->f->str_replace('{action_url}', $url, $html);
$html = $this->f->str_replace('{bulkOptions}', $allBulkOptions, $html);
$html = $this->f->doNormalReplacements($html);
echo $html;
echo $this->getPaginationLinks($sub, false);
echo "
";
// don't show the "add manual redirect" form on the trash page.
if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) {
$this->echoAddManualRedirect($tableOptions);
}
}
function getBulkOperationsFormURL($sub, $tableOptions) {
$url = "?page=" . ABJ404_PP . "&subpage=" . $sub;
if ($tableOptions['filter'] != 0) {
$url .= "&filter=" . $tableOptions['filter'];
}
if (!( $tableOptions['orderby'] == "url" && $tableOptions['order'] == "ASC" )) {
$url .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order'];
}
$url = wp_nonce_url($url, 'abj404_bulkProcess');
return $url;
}
function getAdminRedirectsPageTable($sub) {
$tableOptions = $this->logic->getTableOptions($sub);
// these are used for a GET request so they're not translated.
$columns = array();
$columns['url']['title'] = __('URL', '404-solution');
$columns['url']['orderby'] = "url";
$columns['url']['width'] = "25%";
$columns['status']['title'] = __('Status', '404-solution');
$columns['status']['orderby'] = "status";
$columns['status']['width'] = "5%";
$columns['type']['title'] = __('Type', '404-solution');
$columns['type']['orderby'] = "type";
$columns['type']['width'] = "10%";
$columns['dest']['title'] = __('Destination', '404-solution');;
$columns['dest']['orderby'] = "final_dest";
$columns['dest']['width'] = "22%";
$columns['code']['title'] = __('Redirect', '404-solution');
$columns['code']['orderby'] = "code";
$columns['code']['width'] = "5%";
$columns['hits']['title'] = __('Hits', '404-solution');
$columns['hits']['orderby'] = "logshits";
$columns['hits']['width'] = "7%";
$columns['hits']['title_attr'] = __('Changes may not be updated immediately when ordering by this column', '404-solution');
$columns['timestamp']['title'] = __('Created', '404-solution');;
$columns['timestamp']['orderby'] = "timestamp";
$columns['timestamp']['width'] = "10%";
$columns['last_used']['title'] = __('Last Used', '404-solution');;
$columns['last_used']['orderby'] = "last_used";
$columns['last_used']['width'] = "10%";
$columns['last_used']['title_attr'] = __('Changes may not be updated immediately when ordering by this column', '404-solution');
$html = "
";
$html .= $this->getTableColumns($sub, $columns);
$html .= " ";
$html .= $this->getTableColumns($sub, $columns);
$html .= " ";
$rows = $this->dao->getRedirectsForView($sub, $tableOptions);
$displayed = 0;
$y = 1;
foreach ($rows as $row) {
$displayed++;
$statusTitle = '';
if ($row['status'] == ABJ404_STATUS_MANUAL) {
$statusTitle = __('Manually created', '404-solution');
} else if ($row['status'] == ABJ404_STATUS_AUTO) {
$statusTitle = __('Automatically created', '404-solution');
} else if ($row['status'] == ABJ404_STATUS_REGEX) {
$statusTitle = __('Regular Expression (Manually Created)', '404-solution');
} else {
$statusTitle = __('Unknown', '404-solution');
}
$link = "";
$title = __('Visit', '404-solution') . " ";
if ($row['type'] == ABJ404_TYPE_EXTERNAL) {
$link = $row['final_dest'];
$title .= $row['final_dest'];
} else if ($row['type'] == ABJ404_TYPE_CAT) {
$permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($row['final_dest'] . "|" . ABJ404_TYPE_CAT, 0);
$link = $permalink['link'];
$title .= __('Category:', '404-solution') . " " . $permalink['title'];
} else if ($row['type'] == ABJ404_TYPE_TAG) {
$permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($row['final_dest'] . "|" . ABJ404_TYPE_TAG, 0);
$link = $permalink['link'];
$title .= __('Tag:', '404-solution') . " " . $permalink['title'];
} else if ($row['type'] == ABJ404_TYPE_HOME) {
$permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($row['final_dest'] . "|" . ABJ404_TYPE_HOME, 0);
$link = $permalink['link'];
$title .= __('Home Page:', '404-solution') . " " . $permalink['title'];
} else if ($row['type'] == ABJ404_TYPE_POST) {
$permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($row['final_dest'] . "|" . ABJ404_TYPE_POST, 0);
$link = $permalink['link'];
$title .= $permalink['title'];
} else if ($row['type'] == ABJ404_TYPE_404_DISPLAYED) {
$permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($row['final_dest'] . "|" . ABJ404_TYPE_404_DISPLAYED, 0);
// for custom 404 page use the link
$link = $permalink['link'];
$title .= $permalink['title'];
// for the normal 404 page just use #
if ($row['final_dest'] == '0') {
$link = '';
}
} else {
$this->logger->errorMessage("Unexpected row type while displaying table: " . $row['type']);
}
if ($link != '') {
$link = "href='$link'";
}
$hits = $row['logshits'];
$last_used = $row['last_used'];
if ($last_used != 0) {
$last = date("Y/m/d h:i:s A", abs(intval($last_used)));
} else {
$last = __('Never Used', '404-solution');
}
// Build action links using helper method
$links = $this->buildTableActionLinks($row, $sub, $tableOptions, false);
extract($links);
$class = "";
if ($y == 0) {
$class = "alternate";
$y++;
} else {
$y = 0;
$class = "normal-non-alternate";
}
// make the entire row red if the destination doesn't exist or is unpublished.
$destinationDoesNotExistClass = '';
if (array_key_exists('published_status', $row)) {
if ($row['published_status'] == '0') {
$destinationDoesNotExistClass = ' destination-does-not-exist';
}
}
$class = $class . $destinationDoesNotExistClass;
// -------------------------------------------
if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) {
$editlinkHTML = '{Edit} | ';
} else {
$editlinkHTML = '';
}
if ($row['logsid'] > 0) {
$logslinkHTML = '{View Logs} ';
} else {
$logslinkHTML = '{(No logs)} ';
}
if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) {
$deletePermanentlyHTML = '| {Delete Permanently} ';
} else {
$deletePermanentlyHTML = '';
}
$destinationExists = '';
$destinationDoesNotExist = 'display: none;';
if (array_key_exists('published_status', $row)) {
if ($row['published_status'] == '0') {
$destinationExists = 'display: none;';
$destinationDoesNotExist = '';
}
}
// Build full URL with WordPress base path for subdirectory installations
$fullVisitorURL = esc_url(home_url($row['url']));
$htmlTemp = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/tableRowPageRedirects.html");
$htmlTemp = $this->f->str_replace('{rowid}', $row['id'], $htmlTemp);
$htmlTemp = $this->f->str_replace('{rowClass}', $class, $htmlTemp);
$htmlTemp = $this->f->str_replace('{editLink}', $fullVisitorURL, $htmlTemp);
$htmlTemp = $this->f->str_replace('{rowURL}', esc_html($row['url']), $htmlTemp);
$htmlTemp = $this->f->str_replace('{editlinkHTML}', $editlinkHTML, $htmlTemp);
$htmlTemp = $this->f->str_replace('{logslinkHTML}', $logslinkHTML, $htmlTemp);
$htmlTemp = $this->f->str_replace('{deletePermanentlyHTML}', $deletePermanentlyHTML, $htmlTemp);
$htmlTemp = $this->f->str_replace('{link}', $link, $htmlTemp);
$htmlTemp = $this->f->str_replace('{title}', $title, $htmlTemp);
$htmlTemp = $this->f->str_replace('{dest}', $row['dest_for_view'], $htmlTemp);
$htmlTemp = $this->f->str_replace('{destination-exists}', $destinationExists, $htmlTemp);
$htmlTemp = $this->f->str_replace('{destination-does-not-exist}', $destinationDoesNotExist, $htmlTemp);
$htmlTemp = $this->f->str_replace('{status}', $row['status_for_view'], $htmlTemp);
$htmlTemp = $this->f->str_replace('{statusTitle}', $statusTitle, $htmlTemp);
$htmlTemp = $this->f->str_replace('{type}', $row['type_for_view'], $htmlTemp);
$htmlTemp = $this->f->str_replace('{rowCode}', $row['code'], $htmlTemp);
$htmlTemp = $this->f->str_replace('{hits}', $hits, $htmlTemp);
$htmlTemp = $this->f->str_replace('{logsLink}', $logslink, $htmlTemp);
$htmlTemp = $this->f->str_replace('{trashLink}', $trashlink, $htmlTemp);
$htmlTemp = $this->f->str_replace('{ajaxTrashLink}', $ajaxTrashLink, $htmlTemp);
$htmlTemp = $this->f->str_replace('{trashtitle}', $trashtitle, $htmlTemp);
$htmlTemp = $this->f->str_replace('{deletelink}', $deletelink, $htmlTemp);
$htmlTemp = $this->f->str_replace('{hits}', esc_html($hits), $htmlTemp);
$htmlTemp = $this->f->str_replace('{created_date}',
esc_html(date("Y/m/d h:i:s A", abs(intval($row['timestamp'])))), $htmlTemp);
$htmlTemp = $this->f->str_replace('{last_used_date}', esc_html($last), $htmlTemp);
$htmlTemp = $this->f->doNormalReplacements($htmlTemp);
$html .= $htmlTemp;
}
if ($displayed == 0) {
$html .= "\n" .
" " .
"" .
__('No Redirect Records To Display', '404-solution') . " " .
" " .
" ";
}
$html .= "
";
return $html;
}
function echoAddManualRedirect($tableOptions) {
$options = $this->logic->getOptions();
$url = "?page=" . ABJ404_PP;
if (!( $tableOptions['orderby'] == "url" && $tableOptions['order'] == "ASC" )) {
$url .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order'];
}
if ($tableOptions['filter'] != 0) {
$url .= "&filter=" . $tableOptions['filter'];
}
$link = wp_nonce_url($url, "abj404addRedirect");
$urlPlaceholder = parse_url(get_home_url(), PHP_URL_PATH) . "/example";
if (isset($_POST['url']) && $_POST['url'] != '') {
$postedURL = esc_url($_POST['url']);
} else {
$postedURL = $urlPlaceholder;
}
$selected301 = "";
$selected302 = "";
if ($options['default_redirect'] == '301') {
$selected301 = " selected ";
} else {
$selected302 = " selected ";
}
// read the html content.
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/addManualRedirectTop.html");
$html .= ABJ_404_Solution_Functions::readFileContents(__DIR__ .
"/html/addManualRedirectPageSearchDropdown.html");
$html = $this->f->str_replace('{redirect_to_label}', __('Redirect to', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}',
__('(Type a page name or an external URL)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}',
__('(A page has been selected.)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_CUSTOM_STRING}',
__('(A custom string has been entered.)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}',
__('(An external URL will be used.)', '404-solution'), $html);
$html = $this->f->str_replace('{REDIRECT_TO_USER_FIELD_WARNING}', '', $html);
$html = $this->f->str_replace('{redirectPageTitle}', '', $html);
$html = $this->f->str_replace('{pageIDAndType}', '', $html);
$html = $this->f->str_replace('{redirectPageTitle}', '', $html);
$html = $this->f->str_replace('{data-url}',
"admin-ajax.php?action=echoRedirectToPages&includeDefault404Page=true&includeSpecial=true&nonce=" . wp_create_nonce('abj404_ajax'), $html);
$html .= ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/addManualRedirectBottom.html");
$html = $this->f->str_replace('{addManualRedirectAction}', $link, $html);
$html = $this->f->str_replace('{urlPlaceholder}', esc_attr($urlPlaceholder), $html);
$html = $this->f->str_replace('{postedURL}', esc_attr($postedURL), $html);
$html = $this->f->str_replace('{301selected}', $selected301, $html);
$html = $this->f->str_replace('{302selected}', $selected302, $html);
// constants and translations.
$html = $this->f->doNormalReplacements($html);
echo $html;
}
/** This is used both to add and to edit a redirect.
* @param string $destination
* @param string $codeselected
* @param string $label
*/
function echoEditRedirect($destination, $codeselected, $label) {
echo "\r\n
" . __('Redirect Type', '404-solution') .
": ";
$codes = array(301, 302);
foreach ($codes as $code) {
$selected = "";
if ($code == $codeselected) {
$selected = " selected";
}
$title = ($code == 301) ? '301 Permanent Redirect' : '302 Temporary Redirect';
echo "" . esc_html($title) . " ";
}
echo " ";
echo "
";
}
function echoRedirectDestinationOptionsDefaults($currentlySelected) {
$content = "";
$content .= "\n" . '
' . "\n";
$selected = "";
if ($currentlySelected == ABJ404_TYPE_EXTERNAL) {
$selected = " selected";
}
$content .= "\n" .
__('External Page', '404-solution') . " ";
if ($currentlySelected == ABJ404_TYPE_HOME) {
$selected = " selected";
} else {
$selected = "";
}
$content .= "\n" .
__('Home Page', '404-solution') . " ";
$content .= "\n" . ' ' . "\n";
return $content;
}
/**
* @global type $abj404dao
* @global type $wpdb
* @param array $options
* @return string
*/
function getAdminOptionsPageAutoRedirects($options) {
$spaces = esc_html(" ");
$content = "";
$userSelectedDefault404Page = (array_key_exists('dest404page', $options) &&
isset($options['dest404page']) ? $options['dest404page'] : null);
$urlDestination = (array_key_exists('dest404pageURL', $options) &&
isset($options['dest404pageURL']) ? $options['dest404pageURL'] : null);
$pageMissingWarning = "";
if ($userSelectedDefault404Page != null) {
$permalink =
ABJ_404_Solution_Functions::permalinkInfoToArray($userSelectedDefault404Page, 0);
if (!in_array($permalink['status'], array('publish', 'published'))) {
$pageMissingWarning = __("(The specified page doesn't exist. " .
"Please update this setting.)", '404-solution');
}
}
$pageTitle = $this->logic->getPageTitleFromIDAndType($userSelectedDefault404Page, $urlDestination);
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ .
"/html/addManualRedirectPageSearchDropdown.html");
$html = $this->f->str_replace('{redirect_to_label}', __('Redirect all unhandled 404s to', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}',
__('(Type a page name or an external URL)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}',
__('(A page has been selected.)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_CUSTOM_STRING}',
__('(A custom string has been entered.)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}',
__('(An external URL will be used.)', '404-solution'), $html);
$html = $this->f->str_replace('{REDIRECT_TO_USER_FIELD_WARNING}', $pageMissingWarning, $html);
$html = $this->f->str_replace('{redirectPageTitle}', $pageTitle, $html);
$html = $this->f->str_replace('{pageIDAndType}', $userSelectedDefault404Page, $html);
$html = $this->f->str_replace('{redirectPageTitle}', $pageTitle, $html);
$html = $this->f->str_replace('{data-url}',
"admin-ajax.php?action=echoRedirectToPages&includeDefault404Page=true&includeSpecial=true&nonce=" . wp_create_nonce('abj404_ajax'), $html);
$html = $this->f->doNormalReplacements($html);
$content .= $html;
// -----------------------------------------------
// Load auto redirects options template
$selectedAutoRedirects = $this->getCheckedAttr($options, 'auto_redirects');
$selectedAutoCats = $this->getCheckedAttr($options, 'auto_cats');
$selectedAutoTags = $this->getCheckedAttr($options, 'auto_tags');
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/adminOptionsAutoRedirects.html");
$html = $this->f->str_replace('{selectedAutoRedirects}', $selectedAutoRedirects, $html);
$html = $this->f->str_replace('{selectedAutoCats}', $selectedAutoCats, $html);
$html = $this->f->str_replace('{selectedAutoTags}', $selectedAutoTags, $html);
$html = $this->f->str_replace('{auto_deletion}', esc_attr($options['auto_deletion']), $html);
$html = $this->f->str_replace('{spaces}', $spaces, $html);
$html = $this->f->doNormalReplacements($html);
$content .= $html;
return $content;
}
function getAdminOptionsPageAdvancedSettings($options) {
// Only allow redirecting all requests on trusted sites because someone will break
// their website and complain to me about it and I don't want to hear that because I have
// other things to do besides deal with people that don't listen to warnings about things
// that will break their website.
$hideRedirectAllRequests = 'true';
$serverName = array_key_exists('SERVER_NAME', $_SERVER) ? $_SERVER['SERVER_NAME'] : (array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : '(not found)');
if (in_array($serverName, $GLOBALS['abj404_whitelist'])) {
$hideRedirectAllRequests = 'false';
}
$selectedDebugLogging = $this->getCheckedAttr($options, 'debug_mode');
$selectedRedirectAllRequests = $this->getCheckedAttr($options, 'redirect_all_requests');
$selectedLogRawIPs = $this->getCheckedAttr($options, 'log_raw_ips');
$debugExplanation = __('
View the debug file.', '404-solution');
$debugLogLink = $this->logic->getDebugLogFileLink();
$debugExplanation = $this->f->str_replace('
', ' ', $debugExplanation);
$kbFileSize = $this->logger->getDebugFileSize() / 1024;
$kbFileSizePretty = number_format($kbFileSize, 2, ".", ",");
$mbFileSize = $this->logger->getDebugFileSize() / 1024 / 1000;
$mbFileSizePretty = number_format($mbFileSize, 2, ".", ",");
/* Translators: 1: The file size in KB. 2: The file size in MB. */
$debugFileSize = sprintf(__('Debug file size: %1$s KB (%2$s MB).', '404-solution'),
$kbFileSizePretty, $mbFileSizePretty);
$allPostTypesTemp = $this->dao->getAllPostTypes();
// Ensure we have an array before imploding
$allPostTypes = is_array($allPostTypesTemp) ? esc_html(implode(', ', $allPostTypesTemp)) : '';
// ----
// read the html content.
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/settingsAdvanced.html");
$html = $this->f->str_replace('{DATABASE_VERSION}', esc_html($options['DB_VERSION']), $html);
$html = $this->f->str_replace('checked="debug_mode"', $selectedDebugLogging, $html);
$html = $this->f->str_replace('checked="redirect_all_requests"', $selectedRedirectAllRequests, $html);
$html = $this->f->str_replace('checked="log_raw_ips"', $selectedLogRawIPs, $html);
$html = $this->f->str_replace('{ View the debug file.}', $debugExplanation, $html);
$html = $this->f->str_replace('{Debug file size: %s KB.}', $debugFileSize, $html);
$html = $this->f->str_replace('{ignore_dontprocess}',
str_replace('\\n', "\n", wp_kses_post($options['ignore_dontprocess'])), $html);
$html = $this->f->str_replace('{ignore_doprocess}',
str_replace('\\n', "\n", wp_kses_post($options['ignore_doprocess'])), $html);
$html = $this->f->str_replace('{recognized_post_types}',
str_replace('\\n', "\n", wp_kses_post($options['recognized_post_types'])), $html);
$html = $this->f->str_replace('{all_post_types}', $allPostTypes, $html);
$html = $this->f->str_replace('{days_wait_before_major_update}', $options['days_wait_before_major_update'], $html);
$html = $this->f->str_replace('{recognized_categories}',
str_replace('\\n', "\n", wp_kses_post($options['recognized_categories'])), $html);
$html = $this->f->str_replace('{folders_files_ignore}',
str_replace('\\n', "\n", wp_kses_post($options['folders_files_ignore'])), $html);
$html = $this->f->str_replace('{suggest_regex_exclusions}',
str_replace('\\n', "\n", esc_textarea($options['suggest_regex_exclusions'])), $html); // Use esc_textarea for textareas
// Handle plugin_admin_users - convert array to string first before sanitization
$pluginAdminUsers = $options['plugin_admin_users'];
if (is_array($pluginAdminUsers)) {
$pluginAdminUsers = implode("\n", $pluginAdminUsers);
}
$pluginAdminUsers = str_replace('\\n', "\n", wp_kses_post($pluginAdminUsers));
$html = $this->f->str_replace('{plugin_admin_users}', wp_kses_post($pluginAdminUsers), $html);
$html = $this->f->str_replace('{OPTION_MIN_AUTO_SCORE}', esc_attr($options['auto_score']), $html);
$html = $this->f->str_replace('{OPTION_TEMPLATE_REDIRECT_PRIORITY}', esc_attr($options['template_redirect_priority']), $html);
$html = $this->f->str_replace('{disallow-redirect-all-requests}', $hideRedirectAllRequests, $html);
$html = $this->f->str_replace('{add-exclude-page-data-url}',
"admin-ajax.php?action=echoRedirectToPages&includeDefault404Page=false&includeSpecial=false&nonce=" . wp_create_nonce('abj404_ajax'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}',
__('(Type a page name)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}',
__('(A page has been selected.)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_CUSTOM_STRING}',
__('(A custom string has been entered.)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}',
__('(An external URL will be used.)', '404-solution'), $html);
$html = $this->f->str_replace('{loaded-excluded-pages}',
urlencode($options['excludePages[]']), $html);
// constants and translations.
$html = $this->f->doNormalReplacements($html);
// ------------------
return $html;
}
/**
* Get the HTML content for the Content & URL Filtering section
* @param array $options
* @return string
*/
function getAdminOptionsPageAdvancedContent($options) {
$allPostTypesTemp = $this->dao->getAllPostTypes();
// Ensure we have an array before imploding
$allPostTypes = is_array($allPostTypesTemp) ? esc_html(implode(', ', $allPostTypesTemp)) : '';
// Read the html content
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/settingsAdvancedContent.html");
$html = $this->f->str_replace('{recognized_post_types}',
str_replace('\\n', "\n", wp_kses_post($options['recognized_post_types'])), $html);
$html = $this->f->str_replace('{all_post_types}', $allPostTypes, $html);
$html = $this->f->str_replace('{recognized_categories}',
str_replace('\\n', "\n", wp_kses_post($options['recognized_categories'])), $html);
$html = $this->f->str_replace('{folders_files_ignore}',
str_replace('\\n', "\n", wp_kses_post($options['folders_files_ignore'])), $html);
$html = $this->f->str_replace('{suggest_regex_exclusions}',
str_replace('\\n', "\n", esc_textarea($options['suggest_regex_exclusions'])), $html);
$html = $this->f->str_replace('{add-exclude-page-data-url}',
"admin-ajax.php?action=echoRedirectToPages&includeDefault404Page=false&includeSpecial=false&nonce=" . wp_create_nonce('abj404_ajax'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}',
__('(Type a page name)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}',
__('(A page has been selected.)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_CUSTOM_STRING}',
__('(A custom string has been entered.)', '404-solution'), $html);
$html = $this->f->str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}',
__('(An external URL will be used.)', '404-solution'), $html);
$html = $this->f->str_replace('{loaded-excluded-pages}',
urlencode($options['excludePages[]']), $html);
// Constants and translations
$html = $this->f->doNormalReplacements($html);
return $html;
}
/**
* Get the HTML content for the Logging & Privacy section
* @param array $options
* @return string
*/
function getAdminOptionsPageAdvancedLogging($options) {
$selectedLogRawIPs = $this->getCheckedAttr($options, 'log_raw_ips');
$selectedDebugLogging = $this->getCheckedAttr($options, 'debug_mode');
$debugExplanation = __('
View the debug file.', '404-solution');
$debugLogLink = $this->logic->getDebugLogFileLink();
$debugExplanation = $this->f->str_replace('
', ' ', $debugExplanation);
$kbFileSize = $this->logger->getDebugFileSize() / 1024;
$kbFileSizePretty = number_format($kbFileSize, 2, ".", ",");
$mbFileSize = $this->logger->getDebugFileSize() / 1024 / 1000;
$mbFileSizePretty = number_format($mbFileSize, 2, ".", ",");
/* Translators: 1: The file size in KB. 2: The file size in MB. */
$debugFileSize = sprintf(__('Debug file size: %1$s KB (%2$s MB).', '404-solution'),
$kbFileSizePretty, $mbFileSizePretty);
// Read the html content
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/settingsAdvancedLogging.html");
$html = $this->f->str_replace('checked="log_raw_ips"', $selectedLogRawIPs, $html);
$html = $this->f->str_replace('checked="debug_mode"', $selectedDebugLogging, $html);
$html = $this->f->str_replace('{ View the debug file.}', $debugExplanation, $html);
$html = $this->f->str_replace('{Debug file size: %s KB.}', $debugFileSize, $html);
$html = $this->f->str_replace('{ignore_dontprocess}',
str_replace('\\n', "\n", wp_kses_post($options['ignore_dontprocess'])), $html);
$html = $this->f->str_replace('{ignore_doprocess}',
str_replace('\\n', "\n", wp_kses_post($options['ignore_doprocess'])), $html);
// Constants and translations
$html = $this->f->doNormalReplacements($html);
return $html;
}
/**
* Get the HTML content for the Advanced Configuration section
* @param array $options
* @return string
*/
function getAdminOptionsPageAdvancedSystem($options) {
$selectedRedirectAllRequests = $this->getCheckedAttr($options, 'redirect_all_requests');
$hideRedirectAllRequests = "false";
if (array_key_exists('disallow-redirect-all-requests', $options)
&& $options['disallow-redirect-all-requests'] == '1') {
$hideRedirectAllRequests = "true";
}
// Read the html content
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/settingsAdvancedSystem.html");
$html = $this->f->str_replace('{DATABASE_VERSION}', esc_html($options['DB_VERSION']), $html);
$html = $this->f->str_replace('checked="redirect_all_requests"', $selectedRedirectAllRequests, $html);
$html = $this->f->str_replace('{disallow-redirect-all-requests}', $hideRedirectAllRequests, $html);
$html = $this->f->str_replace('{OPTION_MIN_AUTO_SCORE}', esc_attr($options['auto_score']), $html);
$html = $this->f->str_replace('{OPTION_TEMPLATE_REDIRECT_PRIORITY}', esc_attr($options['template_redirect_priority']), $html);
$html = $this->f->str_replace('{days_wait_before_major_update}', $options['days_wait_before_major_update'], $html);
// Handle plugin_admin_users - convert array to string first before sanitization
$pluginAdminUsers = $options['plugin_admin_users'];
if (is_array($pluginAdminUsers)) {
$pluginAdminUsers = implode("\n", $pluginAdminUsers);
}
$pluginAdminUsers = str_replace('\\n', "\n", wp_kses_post($pluginAdminUsers));
$html = $this->f->str_replace('{plugin_admin_users}', wp_kses_post($pluginAdminUsers), $html);
// Constants and translations
$html = $this->f->doNormalReplacements($html);
return $html;
}
/**
* @param array $options
* @return string
*/
function getAdminOptionsPageGeneralSettings($options) {
$selectedDefaultRedirect301 = "";
if ($options['default_redirect'] == '301') {
$selectedDefaultRedirect301 = " selected";
}
$selectedDefaultRedirect302 = "";
if ($options['default_redirect'] == '302') {
$selectedDefaultRedirect302 = " selected";
}
$selectedCapture404 = $this->getCheckedAttr($options, 'capture_404');
$selectedSendErrorLogs = $this->getCheckedAttr($options, 'send_error_logs');
$selectedUnderSettings = "";
$selecteSsettingsLevel = "";
if ($options['menuLocation'] == 'settingsLevel') {
$selecteSsettingsLevel = " selected";
} else {
$selectedUnderSettings = " selected";
}
// Theme selection
$adminTheme = isset($options['admin_theme']) ? $options['admin_theme'] : 'default';
$selectedThemeDefault = ($adminTheme == 'default') ? " selected" : "";
$selectedThemeCalm = ($adminTheme == 'calm') ? " selected" : "";
$selectedThemeMono = ($adminTheme == 'mono') ? " selected" : "";
$selectedThemeNeon = ($adminTheme == 'neon') ? " selected" : "";
$selectedThemeObsidian = ($adminTheme == 'obsidian') ? " selected" : "";
// Theme name translations
$themeDefault = __('Default', '404-solution');
// Language override selection
$pluginLanguage = isset($options['plugin_language_override']) ? $options['plugin_language_override'] : '';
$selectedLanguageDefault = ($pluginLanguage == '') ? " selected" : "";
$selectedLanguageEnUS = ($pluginLanguage == 'en_US') ? " selected" : "";
$selectedLanguageDeDE = ($pluginLanguage == 'de_DE') ? " selected" : "";
$selectedLanguageEsES = ($pluginLanguage == 'es_ES') ? " selected" : "";
$selectedLanguageFrFR = ($pluginLanguage == 'fr_FR') ? " selected" : "";
$selectedLanguageItIT = ($pluginLanguage == 'it_IT') ? " selected" : "";
$selectedLanguagePtBR = ($pluginLanguage == 'pt_BR') ? " selected" : "";
$selectedLanguageNlNL = ($pluginLanguage == 'nl_NL') ? " selected" : "";
$selectedLanguageRuRU = ($pluginLanguage == 'ru_RU') ? " selected" : "";
$selectedLanguageJa = ($pluginLanguage == 'ja') ? " selected" : "";
$selectedLanguageZhCN = ($pluginLanguage == 'zh_CN') ? " selected" : "";
$selectedLanguageIdID = ($pluginLanguage == 'id_ID') ? " selected" : "";
$selectedLanguageSvSE = ($pluginLanguage == 'sv_SE') ? " selected" : "";
// Auto dark mode detection checkbox
$disableAutoDarkMode = isset($options['disable_auto_dark_mode']) && $options['disable_auto_dark_mode'] == '1';
$disableAutoDarkModeChecked = $disableAutoDarkMode ? " checked" : "";
$logSizeBytes = $this->dao->getLogDiskUsage();
$logSizeMB = round($logSizeBytes / (1024 * 1000), 2);
$totalLogLines = $this->dao->getLogsCount(0);
$timeToDisplay = $this->dao->getEarliestLogTimestamp();
$earliestLogDate = 'N/A';
if ($timeToDisplay >= 0) {
$earliestLogDate = date('Y/m/d', $timeToDisplay) . ' ' . date('h:i:s', $timeToDisplay) . ' ' .
date('A', $timeToDisplay);
}
$selectedRemoveMatches = $this->getCheckedAttr($options, 'remove_matches');
$html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/adminOptionsGeneral.html");
$html = $this->f->str_replace('{selectedSendErrorLogs}', $selectedSendErrorLogs, $html);
$html = $this->f->str_replace('{selectedDefaultRedirect301}', $selectedDefaultRedirect301, $html);
$html = $this->f->str_replace('{selectedDefaultRedirect302}', $selectedDefaultRedirect302, $html);
$html = $this->f->str_replace('{selectedCapture404}', $selectedCapture404, $html);
$html = $this->f->str_replace('{admin_notification}', $options['admin_notification'], $html);
$html = $this->f->str_replace('{capture_deletion}', $options['capture_deletion'], $html);
$html = $this->f->str_replace('{manual_deletion}', $options['manual_deletion'], $html);
$html = $this->f->str_replace('{maximum_log_disk_usage}', $options['maximum_log_disk_usage'], $html);
$html = $this->f->str_replace('{logCurrentSizeDiskUsage}', $logSizeMB, $html);
$html = $this->f->str_replace('{logCurrentRowCount}', $totalLogLines, $html);
$html = $this->f->str_replace('{earliestLogDate}', $earliestLogDate, $html);
$html = $this->f->str_replace('{selectedRemoveMatches}', $selectedRemoveMatches, $html);
$html = $this->f->str_replace('{selectedUnderSettings}', $selectedUnderSettings, $html);
$html = $this->f->str_replace('{selecteSsettingsLevel}', $selecteSsettingsLevel, $html);
$html = $this->f->str_replace('{selectedThemeDefault}', $selectedThemeDefault, $html);
$html = $this->f->str_replace('{selectedThemeCalm}', $selectedThemeCalm, $html);
$html = $this->f->str_replace('{selectedThemeMono}', $selectedThemeMono, $html);
$html = $this->f->str_replace('{selectedThemeNeon}', $selectedThemeNeon, $html);
$html = $this->f->str_replace('{selectedThemeObsidian}', $selectedThemeObsidian, $html);
$html = $this->f->str_replace('{theme_default}', $themeDefault, $html);
$html = $this->f->str_replace('{selectedLanguageDefault}', $selectedLanguageDefault, $html);
$html = $this->f->str_replace('{selectedLanguageEnUS}', $selectedLanguageEnUS, $html);
$html = $this->f->str_replace('{selectedLanguageDeDE}', $selectedLanguageDeDE, $html);
$html = $this->f->str_replace('{selectedLanguageEsES}', $selectedLanguageEsES, $html);
$html = $this->f->str_replace('{selectedLanguageFrFR}', $selectedLanguageFrFR, $html);
$html = $this->f->str_replace('{selectedLanguageItIT}', $selectedLanguageItIT, $html);
$html = $this->f->str_replace('{selectedLanguagePtBR}', $selectedLanguagePtBR, $html);
$html = $this->f->str_replace('{selectedLanguageNlNL}', $selectedLanguageNlNL, $html);
$html = $this->f->str_replace('{selectedLanguageRuRU}', $selectedLanguageRuRU, $html);
$html = $this->f->str_replace('{selectedLanguageJa}', $selectedLanguageJa, $html);
$html = $this->f->str_replace('{selectedLanguageZhCN}', $selectedLanguageZhCN, $html);
$html = $this->f->str_replace('{selectedLanguageIdID}', $selectedLanguageIdID, $html);
$html = $this->f->str_replace('{selectedLanguageSvSE}', $selectedLanguageSvSE, $html);
$html = $this->f->str_replace('{disableAutoDarkModeChecked}', $disableAutoDarkModeChecked, $html);
$html = $this->f->str_replace('{admin_notification_email}', $options['admin_notification_email'], $html);
$html = $this->f->str_replace('{default_wordpress_admin_email}', get_option('admin_email'), $html);
$html = $this->f->str_replace('{PHP_VERSION}', PHP_VERSION, $html);
// constants and translations.
$html = $this->f->doNormalReplacements($html);
return $html;
}
/**
* @global type $abj404dao
*/
function echoAdminLogsPage() {
$sub = 'abj404_logs';
$tableOptions = $this->logic->getTableOptions($sub);
// Sanitizing unchecked table options
$tableOptions = $this->logic->sanitizePostData($tableOptions);
echo "
";
echo '
";
echo "
";
echo $this->getPaginationLinks($sub);
echo "
";
echo $this->getAdminLogsPageTable($sub);
echo "
";
echo $this->getPaginationLinks($sub, false);
echo "
";
}
function getAdminLogsPageTable($sub) {
$tableOptions = $this->logic->getTableOptions($sub);
$columns = array();
$columns['url']['title'] = __('URL', '404-solution');
$columns['url']['orderby'] = "url";
$columns['url']['width'] = "25%";
$columns['host']['title'] = __('IP Address', '404-solution');
$columns['host']['orderby'] = "remote_host";
$columns['host']['width'] = "12%";
$columns['refer']['title'] = __('Referrer', '404-solution');
$columns['refer']['orderby'] = "referrer";
$columns['refer']['width'] = "25%";
$columns['dest']['title'] = __('Action Taken', '404-solution');
$columns['dest']['orderby'] = "action";
$columns['dest']['width'] = "25%";
$columns['timestamp']['title'] = __('Date', '404-solution');
$columns['timestamp']['orderby'] = "timestamp";
$columns['timestamp']['width'] = "15%";
$columns['username']['title'] = __('User', '404-solution');
$columns['username']['orderby'] = "username";
$columns['username']['width'] = "10%";
$html = "
";
$html .= "";
$html .= $this->getTableColumns($sub, $columns);
$html .= " ";
$html .= "";
$html .= $this->getTableColumns($sub, $columns);
$html .= " ";
$html .= "";
$timezone = get_option('timezone_string');
if ('' == $timezone) {
$timezone = 'UTC';
}
date_default_timezone_set($timezone);
$rows = $this->dao->getLogRecords($tableOptions);
$logRecordsDisplayed = 0;
$y = 1;
foreach ($rows as $row) {
$class = "";
if ($y == 0) {
$class = " class=\"alternate\"";
$y++;
} else {
$y = 0;
$class = ' class="normal-non-alternate"';
}
$html .= "";
$html .= " ";
$html .= "" . esc_html($row['url']);
if ($row['url_detail'] != null && trim($row['url_detail']) != '') {
$html .= ' (' . esc_html(trim($row['url_detail'])) . ')';
}
$html .= " ";
$html .= "" . esc_html($row['remote_host']) . " ";
$html .= "";
if ($row['referrer'] != "") {
$html .= "" . esc_html($row['referrer']) . " ";
} else {
$html .= " ";
}
$html .= " ";
$html .= "";
if (trim($row['action']) == "404" || trim($row['action']) == "http://404") {
$html .= __('Displayed 404 Page', '404-solution');
} else {
$html .= __('Redirected to', '404-solution') . " ";
$html .= "" . esc_html($row['action']) . " ";
}
$html .= " ";
$timeToDisplay = abs(intval($row['timestamp']));
$html .= "" . date('Y/m/d', $timeToDisplay) . ' ' . date('h:i:s', $timeToDisplay) . ' ' .
date('A', $timeToDisplay) . " ";
$html .= "" . esc_html($row['username']) . " ";
$html .= " ";
$html .= " ";
$logRecordsDisplayed++;
}
$this->logger->debugMessage($logRecordsDisplayed . " log records displayed on the page.");
if ($logRecordsDisplayed == 0) {
$html .= "";
$html .= " ";
$html .= "" . __('No Results To Display', '404-solution') . " ";
$html .= " ";
$html .= " ";
}
$html .= " ";
$html .= "
";
return $html;
}
/**
* @param string $sub
* @param array $tableOptions
* @param array $columns
*/
function getTableColumns($sub, $columns) {
$tableOptions = $this->logic->getTableOptions($sub);
$html = "
";
$cbinfo = 'class="manage-column column-cb check-column" style="{cb-info-style}"';
$cbinfoStyle = 'vertical-align: middle; padding-bottom: 6px;';
if ($sub == 'abj404_logs') {
$cbinfoStyle .= ' width: 0px;';
}
$cbinfo = $this->f->str_replace('{cb-info-style}', $cbinfoStyle, $cbinfo);
$html .= "";
if ($sub != 'abj404_logs') {
$html .= " ";
}
$html .= " ";
foreach ($columns as $column) {
// Skip invalid column definitions (e.g., string instead of array)
if (!is_array($column)) {
continue;
}
$style = "";
if (isset($column['width']) && $column['width'] != "") {
$style = " style=\"width: " . esc_attr($column['width']) . ";\" ";
}
$nolink = 0;
$sortorder = "";
$orderby = isset($column['orderby']) ? $column['orderby'] : '';
if ($tableOptions['orderby'] == $orderby) {
$thClass = " sorted";
if ($tableOptions['order'] == "ASC") {
$thClass .= " asc";
$sortorder = "DESC";
} else {
$thClass .= " desc";
$sortorder = "ASC";
}
} else {
if ($orderby != "") {
$thClass = " sortable";
if ($orderby == "timestamp" ||
$orderby == "last_used" ||
$orderby == "logshits") {
$thClass .= " asc";
$sortorder = "DESC";
} else {
$thClass .= " desc";
$sortorder = "ASC";
}
} else {
$thClass = "";
$nolink = 1;
}
}
$url = "?page=" . ABJ404_PP;
if ($sub == 'abj404_captured') {
$url .= "&subpage=abj404_captured";
} else if ($sub == 'abj404_logs') {
$url .= "&subpage=abj404_logs&id=" . $tableOptions['logsid'];
}
if ($tableOptions['filter'] != 0) {
$url .= "&filter=" . $tableOptions['filter'];
}
$url .= "&orderby=" . $orderby . "&order=" . $sortorder;
$cssTooltip = '';
$title_attr = '';
if (array_key_exists('title_attr', $column)) {
$title_attr = $column['title_attr'];
$cssTooltip = '' . $title_attr . ' ' . "\n";
$thClass .= ' lefty-tooltip';
}
$html .= " \n";
$html .= $cssTooltip;
$title = isset($column['title']) ? $column['title'] : '';
if ($nolink == 1) {
$html .= $title;
} else {
$html .= "";
$html .= '";
$html .= " ";
$html .= " ";
}
$html .= " ";
}
$html .= " ";
$html .= " ";
return $html;
}
/**
* @global type $abj404dao
* @param string $sub
* @param array $tableOptions
*/
function getPaginationLinks($sub, $showSearchFilter = true) {
$tableOptions = $this->logic->getTableOptions($sub);
$url = "?page=" . ABJ404_PP;
if ($sub == 'abj404_captured') {
$url .= "&subpage=abj404_captured";
} else if ($sub == 'abj404_logs') {
$url .= "&subpage=abj404_logs&id=" . $tableOptions['logsid'];
}
$url .= "&orderby=" . $tableOptions['orderby'];
$url .= "&order=" . $tableOptions['order'];
$url .= "&filter=" . $tableOptions['filter'];
if ($sub == 'abj404_logs') {
$num_records = $this->dao->getLogsCount($tableOptions['logsid']);
} else {
$num_records = $this->dao->getRedirectsForViewCount($sub, $tableOptions);
}
// Ensure perpage is never 0 to prevent division by zero
$perpage = isset($tableOptions['perpage']) ? absint($tableOptions['perpage']) : ABJ404_OPTION_MIN_PERPAGE;
if ($perpage == 0) {
$perpage = ABJ404_OPTION_MIN_PERPAGE;
}
// Ensure paged is a valid integer
$paged = isset($tableOptions['paged']) ? absint($tableOptions['paged']) : 1;
if ($paged == 0) {
$paged = 1;
}
$total_pages = ceil($num_records / $perpage);
if ($total_pages == 0) {
$total_pages = 1;
}
$firsturl = $url;
if ($paged == 1) {
$prevurl = $url;
} else {
$prev = $paged - 1;
$prevurl = $url . "&paged=" . $prev;
}
if ($paged + 1 > $total_pages) {
if ($paged == 1) {
$nexturl = $url;
} else {
$nexturl = $url . "&paged=" . $paged;
}
} else {
$next = $paged + 1;
$nexturl = $url . "&paged=" . $next;
}
if ($paged + 1 > $total_pages) {
if ($paged == 1) {
$lasturl = $url;
} else {
$lasturl = $url . "&paged=" . $paged;
}
} else {
$lasturl = $url . "&paged=" . $total_pages;
}
// ------------
$start = (($paged - 1) * $perpage) + 1;
$end = min($start + $perpage - 1, $num_records);
/* Translators: 1: Starting number, 2: Ending number, 3: Total count. */
$currentlyShowingText = sprintf(__('%1$s - %2$s of %3$s', '404-solution'), $start, $end, $num_records);
$currentPageText = __('Page', '404-solution') . " " . $paged . " " . __('of', '404-solution') . " " . esc_html($total_pages);
$showRowsText = __('Rows per page:', '404-solution');
$showRowsLink = wp_nonce_url($url . '&action=changeItemsPerRow', "abj404_importRedirects");
$ajaxPaginationLink = "admin-ajax.php?action=ajaxUpdatePaginationLinks&subpage=" . $sub .
"&nonce=" . wp_create_nonce('abj404_updatePaginationLink');
$searchFilterControl = '\n\n";
$oneBigFormActionURL = $this->getBulkOperationsFormURL($sub, $tableOptions);
$html .= '