%s captured 404 URL that needs to be processed.', 'There are %s captured 404 URLs to be processed.', $captured, '404-solution'), $captured); $capturedMessage = str_replace("", "", $capturedMessage); $capturedMessage = str_replace("", "", $capturedMessage); return '

' . PLUGIN_NAME . ": " . $capturedMessage . "

"; } /** Do an action like trash/delete/ignore/edit and display a page like stats/logs/redirects/options. * @global type $abj404view * @global type $abj404logic */ static function handleMainAdminPageActionAndDisplay() { global $abj404view; global $abj404logic; global $abj404logging; global $abj404dao; try { $action = $abj404dao->getPostOrGetSanitize('action'); if (!is_admin() || !current_user_can('administrator')) { $abj404logging->logUserCapabilities("handleMainAdminPageActionAndDisplay (" . esc_html($action == '' ? '(none)' : $action) . ")"); return; } $sub = ""; // -------------------------------------------------------------------- // Handle Post Actions $abj404logging->debugMessage("Processing request for action: " . esc_html($action == '' ? '(none)' : $action)); // this should really not pass things by reference so it can be more object oriented (encapsulation etc). $message = ""; $message .= $abj404logic->handlePluginAction($action, $sub); $message .= $abj404logic->hanldeTrashAction(); $message .= $abj404logic->handleDeleteAction(); $message .= $abj404logic->handleIgnoreAction(); $message .= $abj404logic->handleLaterAction(); $message .= $abj404logic->handleActionEdit($sub, $action); $message .= $abj404logic->handleActionDeleteLog(); $message .= $abj404logic->handleActionImportRedirects(); $message .= $abj404logic->handleActionChangeItemsPerRow(); // -------------------------------------------------------------------- // Output the correct page. $abj404view->echoChosenAdminTab($action, $sub, $message); } catch (Exception $e) { $abj404logging->errorMessage("Caught exception: " . stripcslashes(wp_kses_post(json_encode($e)))); throw $e; } } /** Display the chosen admin page. * @global type $abj404view * @param type $sub * @param type $message */ function echoChosenAdminTab($action, $sub, $message) { global $abj404view; global $abj404logging; global $abj404dao; // Deal With Page Tabs if ($sub == "") { $sub = mb_strtolower($abj404dao->getPostOrGetSanitize('subpage')); } if ($sub == "") { $sub = 'abj404_redirects'; $abj404logging->debugMessage('No tab selected. Displaying the "redirects" tab.'); } $abj404logging->debugMessage("Displaying sub page: " . esc_html($sub == '' ? '(none)' : $sub)); $abj404view->outputAdminHeaderTabs($sub, $message); if (($action == 'editRedirect') || ($sub == 'abj404_edit')) { $abj404view->echoAdminEditRedirectPage(); } else if ($sub == 'abj404_redirects') { $abj404view->echoAdminRedirectsPage(); } else if ($sub == 'abj404_captured') { $abj404view->echoAdminCapturedURLsPage(); } else if ($sub == "abj404_options") { $abj404view->echoAdminOptionsPage(); } else if ($sub == 'abj404_logs') { $abj404view->echoAdminLogsPage(); } else if ($sub == 'abj404_stats') { $abj404view->outputAdminStatsPage(); } else if ($sub == 'abj404_tools') { $abj404view->echoAdminToolsPage(); } else if ($sub == 'abj404_debugfile') { $abj404view->echoAdminDebugFile(); } else { $abj404logging->debugMessage('No tab selected. Displaying the "redirects" tab.'); $abj404view->echoAdminRedirectsPage(); } $abj404view->echoAdminFooter(); } /** Echo the text that appears at the bottom of each admin page. */ function echoAdminFooter() { // read the html content. $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/adminFooter.html"); // constants and translations. $html = $this->doNormalReplacements($html); echo $html; } /** Output the tabs at the top of the plugin page. * @param type $sub * @param type $message */ function outputAdminHeaderTabs($sub = 'list', $message = '') { ABJ_404_Solution_WPNotices::echoAdminNotices(); if ($sub == "abj404_options") { $header = " " . __('Options', '404-solution'); } else if ($sub == 'abj404_logs') { $header = " " . __('Logs', '404-solution'); } else if ($sub == 'abj404_stats') { $header = " " . __('Stats', '404-solution'); } else if ($sub == 'abj404_edit') { $header = ": " . __('Edit Redirect', '404-solution'); } else if ($sub == 'abj404_redirects') { $header = ""; } else { $header = ""; } echo "
"; if ($sub == "abj404_options") { echo "\n
"; } else { echo "\n
"; } echo "\n

" . PLUGIN_NAME . esc_html($header) . "

"; if ($message != "") { $allowed_tags = array( 'br' => array(), 'em' => array(), 'strong' => array(), ); if ((strlen($message) >= 6) && (substr(mb_strtolower($message), 0, 6) == 'error:')) { $cssClasses = 'notice notice-error'; } else { $cssClasses = 'notice notice-success'; } echo '

' . wp_kses($message, $allowed_tags) . "

\n"; } $class = ""; if ($sub == 'abj404_redirects') { $class = "nav-tab-active"; } echo "\n" . __('Page Redirects', '404-solution') . ""; $class = ""; if ($sub == 'abj404_captured') { $class = "nav-tab-active"; } echo "\n" . __('Captured 404 URLs', '404-solution') . ""; $class = ""; if ($sub == 'abj404_logs') { $class = "nav-tab-active"; } echo "\n" . __('Logs', '404-solution') . ""; $class = ""; if ($sub == 'abj404_stats') { $class = "nav-tab-active"; } echo "\n" . __('Stats', '404-solution') . ""; $class = ""; if ($sub == 'abj404_tools') { $class = "nav-tab-active"; } echo "\n" . __('Tools', '404-solution') . ""; $class = ""; if ($sub == "abj404_options") { $class = "nav-tab-active"; } echo "\n" . __('Options', '404-solution') . ""; echo "
"; } /** This outputs a box with a title and some content in it. * It's used on the Stats, Options and Tools page (for example). * @param type $id * @param type $title * @param type $content */ function echoPostBox($id, $title, $content) { echo "
"; echo "

" . esc_html($title) . "

"; echo "
" . $content /* Can't escape here, as contains forms */ . "
"; echo "
"; } /** Output the stats page. * @global type $wpdb * @global type $abj404dao */ function outputAdminStatsPage() { global $wpdb; global $abj404dao; global $abj404view; $redirects = $wpdb->prefix . "abj404_redirects"; $logs = $wpdb->prefix . "abj404_logsv2"; $hr = "style=\"border: 0px; margin-bottom: 0px; padding-bottom: 4px; border-bottom: 1px dotted #DEDEDE;\""; $query = "select count(id) from $redirects where disabled = 0 and code = 301 and status = %d"; // . ABJ404_STATUS_AUTO; $auto301 = $abj404dao->getStatsCount($query, array(ABJ404_STATUS_AUTO)); $query = "select count(id) from $redirects where disabled = 0 and code = 302 and status = %d"; // . ABJ404_STATUS_AUTO; $auto302 = $abj404dao->getStatsCount($query, array(ABJ404_STATUS_AUTO)); $query = "select count(id) from $redirects where disabled = 0 and code = 301 and status = %d"; // . ABJ404_STATUS_MANUAL; $manual301 = $abj404dao->getStatsCount($query, array(ABJ404_STATUS_MANUAL)); $query = "select count(id) from $redirects where disabled = 0 and code = 302 and status = %d"; // . ABJ404_STATUS_MANUAL; $manual302 = $abj404dao->getStatsCount($query, array(ABJ404_STATUS_MANUAL)); $query = "select count(id) from $redirects where disabled = 1 and (status = %d or status = %d)"; $trashed = $abj404dao->getStatsCount($query, array(ABJ404_STATUS_AUTO, ABJ404_STATUS_MANUAL)); $total = $auto301 + $auto302 + $manual301 + $manual302 + $trashed; echo "
"; echo "
"; echo "
"; $content = ""; $content .= "

"; $content .= "" . __('Automatic 301 Redirects', '404-solution') . ": " . esc_html($auto301) . "
"; $content .= "" . __('Automatic 302 Redirects', '404-solution') . ": " . esc_html($auto302) . "
"; $content .= "" . __('Manual 301 Redirects', '404-solution') . ": " . esc_html($manual301) . "
"; $content .= "" . __('Manual 302 Redirects', '404-solution') . ": " . esc_html($manual302) . "
"; $content .= "" . __('Trashed Redirects', '404-solution') . ": " . esc_html($trashed) . "

"; $content .= "

"; $content .= "" . __('Total Redirects', '404-solution') . ": " . esc_html($total); $content .= "

"; $abj404view->echoPostBox("abj404-redirectStats", __('Redirects', '404-solution'), $content); // ------------------------------------------- $query = "select count(id) from $redirects where disabled = 0 and status = %d"; // . ABJ404_STATUS_CAPTURED; $captured = $abj404dao->getStatsCount($query, array(ABJ404_STATUS_CAPTURED)); $query = "select count(id) from $redirects where disabled = 0 and status in (%d, %d)"; // . ABJ404_STATUS_IGNORED; $ignored = $abj404dao->getStatsCount($query, array(ABJ404_STATUS_IGNORED, ABJ404_STATUS_LATER)); $query = "select count(id) from $redirects where disabled = 1 and (status in (%d, %d, %d) )"; $trashed = $abj404dao->getStatsCount($query, array(ABJ404_STATUS_CAPTURED, ABJ404_STATUS_IGNORED, ABJ404_STATUS_LATER)); $total = $captured + $ignored + $trashed; $content = ""; $content .= "

"; $content .= "" . __('Captured URLs', '404-solution') . ": " . esc_html($captured) . "
"; $content .= "" . __('Ignored 404 URLs', '404-solution') . ": " . esc_html($ignored) . "
"; $content .= "" . __('Trashed URLs', '404-solution') . ": " . esc_html($trashed) . "

"; $content .= "

"; $content .= "" . __('Total URLs', '404-solution') . ": " . esc_html($total); $content .= "

"; $abj404view->echoPostBox("abj404-capturedStats", __('Captured URLs', '404-solution'), $content); echo "
"; echo "
"; echo "
"; // ------------------------------------------- echo "
"; echo "
"; echo "
"; $today = mktime(0, 0, 0, abs(intval(date('m'))), abs(intval(date('d'))), abs(intval(date('Y')))); $firstm = mktime(0, 0, 0, abs(intval(date('m'))), 1, abs(intval(date('Y')))); $firsty = mktime(0, 0, 0, 1, 1, abs(intval(date('Y')))); for ($x = 0; $x <= 3; $x++) { if ($x == 0) { $title = "Today's Stats"; $ts = $today; } else if ($x == 1) { $title = "This Month"; $ts = $firstm; } else if ($x == 2) { $title = "This Year"; $ts = $firsty; } else if ($x == 3) { $title = "All Stats"; $ts = 0; } $query = "select count(id) from $logs where timestamp >= $ts and dest_url = %s"; $disp404 = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct requested_url) from $logs where timestamp >= $ts and dest_url = %s"; $distinct404 = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct user_ip) from $logs where timestamp >= $ts and dest_url = %s"; $visitors404 = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct referrer) from $logs where timestamp >= $ts and dest_url = %s"; $refer404 = $abj404dao->getStatsCount($query, array("404")); $query = "select count(id) from $logs where timestamp >= $ts and dest_url != %s"; $redirected = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct requested_url) from $logs where timestamp >= $ts and dest_url != %s"; $distinctredirected = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct user_ip) from $logs where timestamp >= $ts and dest_url != %s"; $distinctvisitors = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct referrer) from $logs where timestamp >= $ts and dest_url != %s"; $distinctrefer = $abj404dao->getStatsCount($query, array("404")); $content = ""; $content .= "

"; $content .= "" . __('Page Not Found Displayed', '404-solution') . ": " . esc_html($disp404) . "
"; $content .= "" . __('Unique Page Not Found URLs', '404-solution') . ": " . esc_html($distinct404) . "
"; $content .= "" . __('Unique Page Not Found Visitors', '404-solution') . ": " . esc_html($visitors404) . "
"; $content .= "" . __('Unique Page Not Found Referrers', '404-solution') . ": " . esc_html($refer404) . "
"; $content .= "" . __('Hits Redirected', '404-solution') . ": " . esc_html($redirected) . "
"; $content .= "" . __('Unique URLs Redirected', '404-solution') . ": " . esc_html($distinctredirected) . "
"; $content .= "" . __('Unique Redirected Visitors', '404-solution') . ": " . esc_html($distinctvisitors) . "
"; $content .= "" . __('Unique Redirected Referrers', '404-solution') . ": " . esc_html($distinctrefer) . "
"; $content .= "

"; $abj404view->echoPostBox("abj404-stats" . $x, __($title), $content); } echo "
"; echo "
"; echo "
"; } function echoAdminDebugFile() { global $abj404logging; if (current_user_can('administrator')) { echo "
"; // read the file and replace new lines with
. if (file_exists($abj404logging->getDebugFilePath())) { $linesRead = 0; $handle = null; try { if ($handle = fopen($abj404logging->getDebugFilePath(), "r")) { // read the file one line at a time. while (($line = fgets($handle)) !== false) { $linesRead++; echo nl2br(esc_html($line)); if ($linesRead > 1000000) { echo "

Read " . $linesRead . " lines. Download debug file to see more."; break; } } } else { $this->errorMessage("Error reading debug file (3).", $e); } } catch (Exception $e) { $this->errorMessage("Error reading debug file. (4)", $e); } if ($handle != null) { fclose($handle); } } else { echo nl2br(__('(The file does not exist.)', '404-solution')); } } else { echo "Non-admin request to view debug file."; $abj404logging->errorMessage("Non-admin request to view debug file."); } } /** Display the tools page. * @global type $abj404view */ function echoAdminToolsPage() { global $abj404view; global $abj404dao; global $wpdb; $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 = str_replace('{toolsPurgeFormActionLink}', $link, $html); // constants and translations. $html = $this->doNormalReplacements($html); echo "
"; echo "
"; echo "
"; $abj404view->echoPostBox("abj404-purgeRedirects", __('Purge Options', '404-solution'), $html); echo "
"; // ------------------------------------ $results = $abj404dao->queryAndGetResults("SHOW TABLES LIKE '" . $wpdb->prefix . 'wbz404_redirects' . "'"); $url = "?page=" . ABJ404_PP . "&subpage=abj404_tools"; $link = wp_nonce_url($url, "abj404_importRedirects"); if (empty($results['rows'])) { $html = __('(No Redirectioner table found.)', '404-solution'); } else { // read the html content. $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/toolsImportFormRed.html"); // do special replacements $html = str_replace('{toolsImportFormActionLink}', $link, $html); // constants and translations. $html = $this->doNormalReplacements($html); } echo "
"; echo "
"; echo "
"; $abj404view->echoPostBox("abj404-purgeRedirects", __('Import Options', '404-solution'), $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 = str_replace('{toolsMaintenanceFormActionLink}', $link, $html); // constants and translations. $html = $this->doNormalReplacements($html); echo "
"; echo "
"; echo "
"; $abj404view->echoPostBox("abj404-purgeRedirects", __('Etcetera', '404-solution'), $html); echo "
"; } /** Replace constants and translations. * @param type $text * @return type */ function doNormalReplacements($text) { global $wpdb; // known strings that do not exist in the translation file. $knownReplacements = array( '{ABJ404_STATUS_AUTO}' => ABJ404_STATUS_AUTO, '{ABJ404_STATUS_MANUAL}' => ABJ404_STATUS_MANUAL, '{ABJ404_STATUS_CAPTURED}' => ABJ404_STATUS_CAPTURED, '{ABJ404_STATUS_IGNORED}' => ABJ404_STATUS_IGNORED, '{ABJ404_STATUS_LATER}' => ABJ404_STATUS_LATER, '{ABJ404_TYPE_404_DISPLAYED}' => ABJ404_TYPE_404_DISPLAYED, '{ABJ404_TYPE_POST}' => ABJ404_TYPE_POST, '{ABJ404_TYPE_CAT}' => ABJ404_TYPE_CAT, '{ABJ404_TYPE_TAG}' => ABJ404_TYPE_TAG, '{ABJ404_TYPE_EXTERNAL}' => ABJ404_TYPE_EXTERNAL, '{ABJ404_TYPE_HOME}' => ABJ404_TYPE_HOME, '{ABJ404_HOME_URL}' => ABJ404_HOME_URL, '{PLUGIN_NAME}' => PLUGIN_NAME, '{ABJ404_VERSION}' => ABJ404_VERSION, '{PHP_VERSION}' => phpversion(), '{WP_VERSION}' => get_bloginfo('version'), '{MYSQL_VERSION}' => $wpdb->db_version(), '{ABJ404_MAX_AJAX_DROPDOWN_SIZE}' => ABJ404_MAX_AJAX_DROPDOWN_SIZE, '{WP_MEMORY_LIMIT}' => WP_MEMORY_LIMIT, ); // replace known strings that do not exist in the translation file. $text = str_replace(array_keys($knownReplacements), array_values($knownReplacements), $text); // Find the strings to replace in the content. $re = '/\{(.+?)\}/x'; preg_match_all($re, $text, $stringsToReplace, PREG_PATTERN_ORDER); // Iterate through each string to replace. foreach ($stringsToReplace[1] as $stringToReplace) { $text = str_replace('{' . $stringToReplace . '}', __($stringToReplace, '404-solution'), $text); } return $text; } function echoAdminOptionsPage() { global $abj404logic; global $abj404view; global $abj404viewSuggestions; $options = $abj404logic->getOptions(); // if the current URL does not match the chosen menuLocation then redirect to the correct URL $urlParts = parse_url(urldecode(esc_url($_SERVER['REQUEST_URI']))); $currentURL = $urlParts['path']; if (array_key_exists('menuLocation', $options) && isset($options['menuLocation']) && $options['menuLocation'] == 'settingsLevel') { if (mb_strpos($currentURL, 'options-general.php') != false) { // the option changed and we're at the wrong URL now, so we redirect to the correct one. $abj404logic->forceRedirect(admin_url() . "admin.php?page=" . ABJ404_PP . '&subpage=abj404_options'); } } else if (mb_strpos($currentURL, 'admin.php') != false) { // if the current URL has admin.php then the URLs don't match and we need to reload. $abj404logic->forceRedirect(admin_url() . "options-general.php?page=" . ABJ404_PP . '&subpage=abj404_options'); } //General Options $link = wp_nonce_url("?page=" . ABJ404_PP . '&subpage=abj404_options', "abj404UpdateOptions"); echo "
"; echo "
"; echo "
"; echo "
"; echo ""; $contentAutomaticRedirects = $abj404view->getAdminOptionsPageAutoRedirects($options); $abj404view->echoPostBox("abj404-autooptions", __('Automatic Redirects', '404-solution'), $contentAutomaticRedirects); $contentGeneralSettings = $abj404view->getAdminOptionsPageGeneralSettings($options); $abj404view->echoPostBox("abj404-generaloptions", __('General Settings', '404-solution'), $contentGeneralSettings); $contentAdvancedSettings = $abj404view->getAdminOptionsPageAdvancedSettings($options); $abj404view->echoPostBox("abj404-advancedoptions", __('Advanced Settings (Etc)', '404-solution'), $contentAdvancedSettings); $content404PageSuggestions = $abj404viewSuggestions->getAdminOptionsPage404Suggestions($options); $abj404view->echoPostBox("abj404-suggestoptions", __('404 Page Suggestions', '404-solution'), $content404PageSuggestions); echo ""; echo "
"; echo "
"; echo "
"; echo "
"; } /** * @global type $abj404dao * @global type $abj404logic * @return type */ function echoAdminEditRedirectPage() { global $abj404dao; global $abj404logic; global $abj404logging; $options = $abj404logic->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 "
"; echo ""; $recnum = null; if (array_key_exists('id', $_GET) && isset($_GET['id']) && preg_match('/[0-9]+/', $_GET['id'])) { $abj404logging->debugMessage("Edit redirect page. GET ID: " . wp_kses_post(json_encode($_GET['id']))); $recnum = absint($_GET['id']); } else if (array_key_exists('id', $_POST) && isset($_POST['id']) && preg_match('/[0-9]+/', $_POST['id'])) { $abj404logging->debugMessage("Edit redirect page. POST ID: " . wp_kses_post(json_encode($_POST['id']))); $recnum = absint($_POST['id']); } else if ($abj404dao->getPostOrGetSanitize('idnum') !== null) { $recnums_multiple = array_map('absint', $abj404dao->getPostOrGetSanitize('idnum')); $abj404logging->debugMessage("Edit redirect page. ids_multiple: " . wp_kses_post(json_encode($recnums_multiple))); } else { echo __('Error: No ID(s) found for edit request.', '404-solution'); $abj404logging->debugMessage("No ID(s) found in GET or POST data for edit request."); return; } // Decide whether we're editing one or multiple redirects. // If we're editing only one then set the ID to that one value. if ($recnum != null) { $recnumAsArray = array(); $recnumAsArray[] = $recnum; $redirects_multiple = $abj404dao->getRedirectsByIDs($recnumAsArray); if (count($redirects_multiple) == 0) { echo "Error: Invalid ID Number! (id: " . esc_html($recnum) . ")"; $abj404logging->errorMessage("Error: Invalid ID Number! (id: " . esc_html($recnum) . ")"); return; } $redirect = reset($redirects_multiple); $isRegexChecked = ''; if ($redirect['status'] == ABJ404_STATUS_REGEX) { $isRegexChecked = ' checked '; } echo ""; echo " "; echo " (" . __('Required', '404-solution') . ")
\n\n"; echo "\n\n" . '      ' . "\n"; $html = ' ' . "\n"; $html .= 'doNormalReplacements($html); echo $html; } else if ($recnums_multiple != null) { $redirects_multiple = $abj404dao->getRedirectsByIDs($recnums_multiple); if ($redirects_multiple == null) { echo "Error: Invalid ID Numbers! (ids: " . esc_html(implode(',', $recnums_multiple)) . ")"; $abj404logging->debugMessage("Error: Invalid ID Numbers! (ids: " . esc_html(implode(',', $recnums_multiple)) . ")"); return; } echo "\n" . ''; echo "\n" . ' '; echo "\n" . '
'; echo "\n" . '' . "\n" . '
    '; foreach ($redirects_multiple as $redirect) { echo "\n
  • " . esc_html($redirect['url']) . "
  • \n"; } echo "\n" . '
'; echo "\n
\n"; // here we set the variable to the first value returned because it's used to set default values // in the form data. $redirect = reset($redirects_multiple); } else { echo "Error: Invalid ID Number(s) specified! (id: " . $recnum . ", ids: " . $recnums_multiple . ")"; $abj404logging->debugMessage("Error: Invalid ID Number(s) specified! (id: " . $recnum . ", ids: " . $recnums_multiple . ")"); return; } $final = ""; $pageIDAndType = ""; if ($redirect['type'] == ABJ404_TYPE_EXTERNAL) { $final = $redirect['final_dest']; $pageIDAndType = ABJ404_TYPE_EXTERNAL . "|" . ABJ404_TYPE_EXTERNAL; } else if ($redirect['final_dest'] != 0) { // if a destination has been specified then let's fill it in. $pageIDAndType = $redirect['final_dest'] . "|" . $redirect['type']; } if ($redirect['code'] == "") { $codeSelected = $options['default_redirect']; } else { $codeSelected = $redirect['code']; } $pageTitle = $abj404logic->getPageTitleFromIDAndType($pageIDAndType, $redirect['final_dest']); $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/addManualRedirectPageSearchDropdown.html"); $html = str_replace('{redirect_to_label}', __('Redirect to', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}', __('(Type a page name or an external URL)', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}', __('(A page has been selected.)', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}', __('(An external URL will be used.)', '404-solution'), $html); $html = str_replace('{redirectPageTitle}', $pageTitle, $html); $html = str_replace('{pageIDAndType}', $pageIDAndType, $html); $html = str_replace('{data-url}', "admin-ajax.php?action=echoRedirectToPages&includeDefault404Page=false", $html); $html = $this->doNormalReplacements($html); echo $html; $this->echoEditRedirect($final, $codeSelected, __('Update Redirect', '404-solution')); 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 "; $_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) { global $abj404dao; global $abj404logic; $content = ""; $content .= "\n" . '' . "\n"; $customTagsEtc = array(); // categories --------------------------------------------- $cats = $abj404dao->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"; } $content .= "\n" . '' . "\n"; $customTagsEtc = $abj404logic->getMapOfCustomCategories($cats); // tags --------------------------------------------- $content .= "\n" . '' . "\n"; $tags = $abj404dao->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"; } $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"; } $content .= "\n" . '' . "\n"; } return $content; } /** * @global type $abj404dao */ function echoAdminCapturedURLsPage() { global $abj404dao; global $abj404logic; $sub = 'abj404_captured'; $nonceValue = "abj404_bulkProcess"; $tableOptions = $abj404logic->getTableOptions($sub); $timezone = get_option('timezone_string'); if ('' == $timezone) { $timezone = 'UTC'; } date_default_timezone_set($timezone); $this->echoTabFilters($sub, $tableOptions); echo "
"; $this->echoPaginationLinks($sub, $tableOptions); // bulk operations dropdown ------------- $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, $nonceValue); $bulkOptions = array(); if ($tableOptions['filter'] != ABJ404_STATUS_CAPTURED) { $bulkOptions[] = ''; } if ($tableOptions['filter'] != ABJ404_STATUS_IGNORED) { $bulkOptions[] = ''; } if ($tableOptions['filter'] != ABJ404_STATUS_LATER) { $bulkOptions[] = ''; } if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) { $bulkOptions[] = ''; } $bulkOptions[] = ''; $allBulkOptions = implode("\n", $bulkOptions); $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/bulkOperationsDropdown.html"); $html = str_replace('{action_url}', $url, $html); $html = str_replace('{bulkOptions}', $allBulkOptions, $html); $html = $this->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, $nonceValue); $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/emptyTrashButton.html"); $html = str_replace('{action_url}', $eturl, $html); $html = $this->doNormalReplacements($html); echo $html; } // ---------- echo "
"; // these are used for a GET request so they're not translated. $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['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%"; echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $rows = $abj404dao->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'); } $editlink = "?page=" . ABJ404_PP . "&subpage=abj404_edit&id=" . $row['id']; $logslink = "?page=" . ABJ404_PP . "&subpage=abj404_logs&id=" . $row['logsid']; $trashlink = "?page=" . ABJ404_PP . "&&subpage=abj404_captured&id=" . $row['id']; $ajaxTrashLink = "admin-ajax.php?action=trashLink" . "&id=" . absint($row['id']); $ignorelink = "?page=" . ABJ404_PP . "&&subpage=abj404_captured&id=" . $row['id']; $laterlink = "?page=" . ABJ404_PP . "&&subpage=abj404_captured&id=" . $row['id']; $deletelink = "?page=" . ABJ404_PP . "&subpage=abj404_captured&remove=1&id=" . $row['id']; if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) { $trashlink .= "&trash=0"; $ajaxTrashLink .= "&trash=0"; $trashtitle = __('Restore', '404-solution'); } else { $trashlink .= "&trash=1"; $ajaxTrashLink .= "&trash=1"; $trashtitle = __('Trash', '404-solution'); } $ignoretitle = ""; if ($tableOptions['filter'] == ABJ404_STATUS_IGNORED) { $ignorelink .= "&ignore=0"; $ignoretitle = __('Remove Ignore Status', '404-solution'); } else if ($tableOptions['filter'] == ABJ404_STATUS_CAPTURED || $tableOptions['filter'] == ABJ404_STATUS_LATER) { $ignorelink .= "&ignore=1"; $ignoretitle = __('Ignore 404 Error', '404-solution'); } if ($tableOptions['filter'] == ABJ404_STATUS_LATER) { $laterlink .= "&later=0"; $latertitle = __('Remove Later Status', '404-solution'); } else if ($tableOptions['filter'] == ABJ404_STATUS_CAPTURED || $tableOptions['filter'] == ABJ404_STATUS_IGNORED) { $laterlink .= "&later=1"; $latertitle = __('Organize Later', '404-solution'); } if (!( $tableOptions['orderby'] == "url" && $tableOptions['order'] == "ASC" )) { $trashlink .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; $ignorelink .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; $deletelink .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; } if ($tableOptions['filter'] != 0) { $trashlink .= "&filter=" . $tableOptions['filter']; $ignorelink .= "&filter=" . $tableOptions['filter']; $deletelink .= "&filter=" . $tableOptions['filter']; $laterlink .= "&filter=" . $tableOptions['filter']; } $trashlink = wp_nonce_url($trashlink, "abj404_trashRedirect"); $ajaxTrashLink = wp_nonce_url($ajaxTrashLink, "abj404_ajaxTrash"); if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) { $deletelink = wp_nonce_url($deletelink, "abj404_removeRedirect"); } $ignorelink = wp_nonce_url($ignorelink, "abj404_ignore404"); $laterlink = wp_nonce_url($laterlink, "abj404_organizeLater"); $class = ""; if ($y == 0) { $class = " class=\"alternate\""; $y++; } else { $y = 0; } // ------------------------ $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[] = '{Organize Later}'; } $allRowActions = implode("\n | ", $rowActions); $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/tableRowCapturedURLs.html"); $html = str_replace('{rowActions}', $allRowActions, $html); $html = str_replace('{rowid}', $row['id'], $html); $html = str_replace('{editLink}', $editlink, $html); $html = str_replace('{logsLink}', $logslink, $html); $html = str_replace('{trashLink}', $trashlink, $html); $html = str_replace('{ajaxTrashLink}', $ajaxTrashLink, $html); $html = str_replace('{trashtitle}', $trashtitle, $html); $html = str_replace('{ignoreLink}', $ignorelink, $html); $html = str_replace('{ignoreTitle}', $ignoretitle, $html); $html = str_replace('{laterLink}', $laterlink, $html); $html = str_replace('{deleteLink}', $deletelink, $html); $html = str_replace('{url}', esc_html($row['url']), $html); $html = str_replace('{hits}', esc_html($hits), $html); $html = str_replace('{created_date}', esc_html(date("Y/m/d h:i:s A", abs(intval($row['timestamp'])))), $html); $html = str_replace('{last_used_date}', esc_html($last), $html); $html = $this->doNormalReplacements($html); echo $html; } if ($displayed == 0) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo ""; echo "
" . __('No Records To Display', '404-solution') . "
"; echo "
"; if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) { echo ""; } $this->echoPaginationLinks($sub, $tableOptions); echo "
"; // make sure the "apply" button is only enabled if at least one checkbox is selected $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/enableDisableApplyButton.js"); $html = str_replace('{altText}', __('Choose at least one URL', '404-solution'), $html); $html = $this->doNormalReplacements($html); echo $html; } /** * @global type $abj404dao * @global type $abj404logic */ function echoAdminRedirectsPage() { global $abj404dao; global $abj404logic; global $abj404logging; $sub = 'abj404_redirects'; $nonceValue = "abj404_bulkProcess"; $tableOptions = $abj404logic->getTableOptions($sub); // Sanitizing unchecked table options foreach ($tableOptions as $key => $value) { $key = wp_kses_post($key); $tableOptions[$key] = wp_kses_post($value); } $this->echoTabFilters($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->doNormalReplacements($htmlTop); } $this->echoPaginationLinks($sub, $tableOptions); // bulk operations dropdown ------------- $bulkOptions = array(); if ($tableOptions['filter'] != ABJ404_STATUS_AUTO) { $bulkOptions[] = ''; } if ($tableOptions['filter'] != ABJ404_TRASH_FILTER) { $bulkOptions[] = ''; } if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) { $bulkOptions[] = ''; $bulkOptions[] = ''; } $allBulkOptions = implode("\n", $bulkOptions); $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']; } // is there a way to use the "; $codes = array(301, 302); foreach ($codes as $code) { $selected = ""; if ($code == $codeselected) { $selected = " selected"; } $title = ($code == 301) ? '301 Permanent Redirect' : '302 Temporary Redirect'; echo ""; } echo "
"; echo ""; } function echoRedirectDestinationOptionsDefaults($currentlySelected) { $content = ""; $content .= "\n" . '' . "\n"; $selected = ""; if ($currentlySelected == ABJ404_TYPE_EXTERNAL) { $selected = " selected"; } $content .= "\n"; if ($currentlySelected == ABJ404_TYPE_HOME) { $selected = " selected"; } else { $selected = ""; } $content .= "\n"; $content .= "\n" . '' . "\n"; return $content; } /** * @global type $abj404dao * @global type $wpdb * @param type $options * @return string */ function getAdminOptionsPageAutoRedirects($options) { global $abj404logic; $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); $pageTitle = $abj404logic->getPageTitleFromIDAndType($userSelectedDefault404Page, $urlDestination); $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/addManualRedirectPageSearchDropdown.html"); $html = str_replace('{redirect_to_label}', __('Redirect all unhandled 404s to', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}', __('(Type a page name or an external URL)', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}', __('(A page has been selected.)', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}', __('(An external URL will be used.)', '404-solution'), $html); $html = str_replace('{redirectPageTitle}', $pageTitle, $html); $html = str_replace('{pageIDAndType}', $userSelectedDefault404Page, $html); $html = str_replace('{redirectPageTitle}', $pageTitle, $html); $html = str_replace('{data-url}', "admin-ajax.php?action=echoRedirectToPages&includeDefault404Page=true", $html); $html = $this->doNormalReplacements($html); $content .= $html; // ----------------------------------------------- $selectedAutoRedirects = ""; if ($options['auto_redirects'] == '1') { $selectedAutoRedirects = " checked"; } $content .= "


"; $content .= $spaces . __('Automatically creates redirects based on best possible suggested page.', '404-solution') . "

"; $selectedAutoCats = ""; if ($options['auto_cats'] == '1') { $selectedAutoCats = " checked"; } $content .= "

"; $selectedAutoTags = ""; if ($options['auto_tags'] == '1') { $selectedAutoTags = " checked"; } $content .= "

"; $content .= "

" . __('Days (0 Disables Auto Delete)', '404-solution') . "
"; $content .= $spaces . __('Removes auto created redirects if they haven\'t been used for the specified amount of time.', '404-solution') . "

"; return $content; } function getAdminOptionsPageAdvancedSettings($options) { global $abj404logging; global $abj404logic; global $abj404dao; $selectedDebugLogging = ""; if (array_key_exists('debug_mode', $options) && $options['debug_mode'] == '1') { $selectedDebugLogging = " checked"; } $selectedLogRawIPs = ''; if (array_key_exists('log_raw_ips', $options) && $options['log_raw_ips'] == '1') { $selectedLogRawIPs = " checked"; } $debugExplanation = __('View the debug file.', '404-solution'); $debugLogLink = $abj404logic->getDebugLogFileLink(); $debugExplanation = str_replace('', '', $debugExplanation); $kbFileSize = $abj404logging->getDebugFileSize() / 1024; $kbFileSizePretty = number_format($kbFileSize, 2, ".", ","); $mbFileSize = $abj404logging->getDebugFileSize() / 1024 / 1000; $mbFileSizePretty = number_format($mbFileSize, 2, ".", ","); $debugFileSize = sprintf(__("Debug file size: %s KB (%s MB).", '404-solution'), $kbFileSizePretty, $mbFileSizePretty); $allPostTypesTemp = $abj404dao->getAllPostTypes(); $allPostTypes = esc_html(implode(', ', $allPostTypesTemp)); // ---- // read the html content. $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/settingsAdvanced.html"); $html = str_replace('{DATABASE_VERSION}', esc_html($options['DB_VERSION']), $html); $html = str_replace('checked="debug_mode"', $selectedDebugLogging, $html); $html = str_replace('checked="log_raw_ips"', $selectedLogRawIPs, $html); $html = str_replace('{View the debug file.}', $debugExplanation, $html); $html = str_replace('{Debug file size: %s KB.}', $debugFileSize, $html); $html = str_replace('{ignore_dontprocess}', wp_kses_post($options['ignore_dontprocess']), $html); $html = str_replace('{ignore_doprocess}', wp_kses_post($options['ignore_doprocess']), $html); $html = str_replace('{recognized_post_types}', wp_kses_post($options['recognized_post_types']), $html); $html = str_replace('{all_post_types}', $allPostTypes, $html); $html = str_replace('{days_wait_before_major_update}', $options['days_wait_before_major_update'], $html); $html = str_replace('{recognized_categories}', wp_kses_post($options['recognized_categories']), $html); $html = str_replace('{folders_files_ignore}', wp_kses_post($options['folders_files_ignore']), $html); $html = str_replace('{OPTION_MIN_AUTO_SCORE}', esc_attr($options['auto_score']), $html); // constants and translations. $html = $this->doNormalReplacements($html); // ------------------ return $html; } /** * @param type $options * @return string */ function getAdminOptionsPageGeneralSettings($options) { global $abj404logging; global $abj404dao; global $abj404ip2Location; $selectedDefaultRedirect301 = ""; if ($options['default_redirect'] == '301') { $selectedDefaultRedirect301 = " selected"; } $selectedDefaultRedirect302 = ""; if ($options['default_redirect'] == '302') { $selectedDefaultRedirect302 = " selected"; } $selectedCapture404 = ""; if ($options['capture_404'] == '1') { $selectedCapture404 = " checked"; } $selectedSendErrorLogs = ""; if ($options['send_error_logs'] == '1') { $selectedSendErrorLogs = " checked"; } $selectedUnderSettings = ""; $selecteSsettingsLevel = ""; if ($options['menuLocation'] == 'settingsLevel') { $selecteSsettingsLevel = " selected"; } else { $selectedUnderSettings = " selected"; } $logSizeBytes = $abj404dao->getLogDiskUsage(); $logSizeMB = round($logSizeBytes / (1024 * 1000), 2); $totalLogLines = $abj404dao->getLogsCount(0); $logSize = sprintf(__("Current approximate log disk usage: %s MB (%s rows).", '404-solution'), $logSizeMB, $totalLogLines); $timeToDisplay = $abj404dao->getEarliestLogTimestamp(); $earliestLogDate = date('Y/m/d', $timeToDisplay) . ' ' . date('h:i:s', $timeToDisplay) . ' ' . date('A', $timeToDisplay); $logSize .= ' ' . sprintf(__("Earliest log date: %s.", '404-solution'), $earliestLogDate) . ' '; $selectedRemoveMatches = ""; if ($options['remove_matches'] == '1') { $selectedRemoveMatches = " checked"; } $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/adminOptionsGeneral.html"); $html = str_replace('{selectedSendErrorLogs}', $selectedSendErrorLogs, $html); $html = str_replace('{selectedDefaultRedirect301}', $selectedDefaultRedirect301, $html); $html = str_replace('{selectedDefaultRedirect302}', $selectedDefaultRedirect302, $html); $html = str_replace('{selectedCapture404}', $selectedCapture404, $html); $html = str_replace('{admin_notification}', $options['admin_notification'], $html); $html = str_replace('{capture_deletion}', $options['capture_deletion'], $html); $html = str_replace('{manual_deletion}', $options['manual_deletion'], $html); $html = str_replace('{maximum_log_disk_usage}', $options['maximum_log_disk_usage'], $html); $html = str_replace('{logCurrentSizeDiskUsage}', $logSizeMB, $html); $html = str_replace('{logCurrentRowCount}', $totalLogLines, $html); $html = str_replace('{earliestLogDate}', $earliestLogDate, $html); $html = str_replace('{selectedRemoveMatches}', $selectedRemoveMatches, $html); $html = str_replace('{selectedUnderSettings}', $selectedUnderSettings, $html); $html = str_replace('{selecteSsettingsLevel}', $selecteSsettingsLevel, $html); $html = str_replace('{admin_notification_email}', $options['admin_notification_email'], $html); $html = str_replace('{default_wordpress_admin_email}', get_option('admin_email'), $html); $html = str_replace('{PHP_VERSION}', PHP_VERSION, $html); // constants and translations. $html = $this->doNormalReplacements($html); return $html; } /** * @global type $abj404dao */ function echoAdminLogsPage() { global $abj404dao; global $abj404logic; global $abj404logging; global $abj404ip2Location; $sub = 'abj404_logs'; $tableOptions = $abj404logic->getTableOptions($sub); $options = $abj404logic->getOptions(true); // Sanitizing unchecked table options foreach ($tableOptions as $key => $value) { $key = wp_kses_post($key); $tableOptions[$key] = wp_kses_post($value); } echo "


"; echo "
"; echo ''; echo ""; // ----------------- dropdown search box. begin. $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/viewLogsForSearchBox.html"); $redirectPageTitle = $abj404dao->getPostOrGetSanitize('redirect_to_data_field_title'); $pageIDAndType = $abj404dao->getPostOrGetSanitize('redirect_to_data_field_id'); $html = str_replace('{redirect_to_label}', __('View logs for', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_EMPTY}', __('(Begin typing a URL)', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_PAGE}', __('(A page has been selected.)', '404-solution'), $html); $html = str_replace('{TOOLTIP_POPUP_EXPLANATION_URL}', __('(Please choose from the dropdown list instead of typing your own URL.)', '404-solution'), $html); $html = str_replace('{pageIDAndType}', $pageIDAndType, $html); $html = str_replace('{redirectPageTitle}', $redirectPageTitle, $html); $html = str_replace('{data-url}', "admin-ajax.php?action=echoViewLogsFor", $html); $html = $this->doNormalReplacements($html); echo $html; // ----------------- dropdown search box. end. echo "
"; $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%"; echo "
"; $this->echoPaginationLinks($sub, $tableOptions); echo "
"; echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $timezone = get_option('timezone_string'); if ('' == $timezone) { $timezone = 'UTC'; } date_default_timezone_set($timezone); $logslink = wp_nonce_url("?page=" . ABJ404_PP . "&subpage=abj404_logs&action=runMaintenance", "abj404_runMaintenance"); $logslink .= '&manually_fired=true'; $rows = $abj404dao->getLogRecords($tableOptions); $logRecordsDisplayed = 0; $y = 1; foreach ($rows as $row) { $class = ""; if ($y == 0) { $class = " class=\"alternate\""; $y++; } else { $y = 0; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $timeToDisplay = abs(intval($row['timestamp'])); echo ""; echo ""; echo ""; echo ""; $logRecordsDisplayed++; } $abj404logging->debugMessage($logRecordsDisplayed . " log records displayed on the page."); if ($logRecordsDisplayed == 0) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo ""; echo "
" . esc_html($row['url']); if (trim($row['url_detail']) != '') { echo ' (' . esc_html(trim($row['url_detail'])) . ')'; } echo "" . esc_html($row['remote_host']) . ""; if ($row['referrer'] != "") { echo "" . esc_html($row['referrer']) . ""; } else { echo " "; } echo ""; if ($row['action'] == "404") { echo __('Displayed 404 Page', '404-solution'); } else { echo __('Redirected to', '404-solution') . " "; echo "" . esc_html($row['action']) . ""; } echo "" . date('Y/m/d', $timeToDisplay) . ' ' . date('h:i:s', $timeToDisplay) . ' ' . date('A', $timeToDisplay) . "" . esc_html($row['username']) . "
" . __('No Results To Display', '404-solution') . "
"; echo "
"; $this->echoPaginationLinks($sub, $tableOptions); echo "
"; } /** * @param type $sub * @param type $tableOptions * @param type $columns */ function echoTableColumns($sub, $tableOptions, $columns) { echo ""; $cbinfo = "class=\"manage-column column-cb check-column\" style=\"vertical-align: middle; padding-bottom: 6px;\""; echo ""; echo ""; echo ""; foreach ($columns as $column) { $style = ""; if ($column['width'] != "") { $style = " style=\"width: " . esc_attr($column['width']) . ";\" "; } $nolink = 0; $sortorder = ""; if ($tableOptions['orderby'] == $column['orderby']) { $class = " sorted"; if ($tableOptions['order'] == "ASC") { $class .= " asc"; $sortorder = "DESC"; } else { $class .= " desc"; $sortorder = "ASC"; } } else { if ($column['orderby'] != "") { $class = " sortable"; if ($column['orderby'] == "timestamp" || $column['orderby'] == "last_used") { $class .= " asc"; $sortorder = "DESC"; } else { $class .= " desc"; $sortorder = "ASC"; } } else { $class = ""; $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=" . $column['orderby'] . "&order=" . $sortorder; echo ""; if ($nolink == 1) { echo $column['title']; } else { echo ""; echo "" . esc_html($column['title']) . ""; echo ""; echo ""; } echo ""; } echo ""; echo ""; } /** * @global type $abj404dao * @param type $sub * @param type $tableOptions */ function echoPaginationLinks($sub, $tableOptions) { global $abj404dao; global $abj404logging; global $abj404_redirect_types; global $abj404_captured_types; $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']; if ($tableOptions['filter'] == 0 || $tableOptions['filter'] == ABJ404_TRASH_FILTER) { if ($sub == 'abj404_redirects') { $types = $abj404_redirect_types; } else if ($sub == 'abj404_captured') { $types = $abj404_captured_types; } else { $abj404logging->debugMessage("Unexpected sub type for pagination links: " . $sub); $types = $abj404_captured_types; } } else { // if "manual redirects" are being shown then also include regex redirects. if ($tableOptions['filter'] == ABJ404_STATUS_MANUAL) { $types = array($tableOptions['filter'], ABJ404_STATUS_REGEX); } else { $types = array($tableOptions['filter']); } } $url .= "&filter=" . $tableOptions['filter']; if ($sub == 'abj404_logs') { $num_records = $abj404dao->getLogsCount($tableOptions['logsid']); } else { if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) { $num_records = $abj404dao->getRecordCount($types, 1); } else { $num_records = $abj404dao->getRecordCount($types); } } $total_pages = ceil($num_records / $tableOptions['perpage']); if ($total_pages == 0) { $total_pages = 1; } $classFirstPage = ""; if ($tableOptions['paged'] == 1) { $classFirstPage = " disabled"; } $firsturl = $url; $classPreviousPage = ""; if ($tableOptions['paged'] == 1) { $classPreviousPage = " disabled"; $prevurl = $url; } else { $prev = $tableOptions['paged'] - 1; $prevurl = $url . "&paged=" . $prev; } $classNextPage = ""; if ($tableOptions['paged'] + 1 > $total_pages) { $classNextPage = " disabled"; if ($tableOptions['paged'] == 1) { $nexturl = $url; } else { $nexturl = $url . "&paged=" . $tableOptions['paged']; } } else { $next = $tableOptions['paged'] + 1; $nexturl = $url . "&paged=" . $next; } $classLastPage = ""; if ($tableOptions['paged'] + 1 > $total_pages) { $classLastPage = " disabled"; if ($tableOptions['paged'] == 1) { $lasturl = $url; } else { $lasturl = $url . "&paged=" . $tableOptions['paged']; } } else { $lasturl = $url . "&paged=" . $total_pages; } // ------------ $start = ( absint(sanitize_text_field($tableOptions['paged']) - 1)) * absint(sanitize_text_field($tableOptions['perpage'])) + 1; $end = min($start + absint(sanitize_text_field($tableOptions['perpage'])) - 1, $num_records); $currentlyShowingText = sprintf(__('%s - %s of %s', '404-solution'), $start, $end, $num_records); $currentPageText = __('Page', '404-solution') . " " . $tableOptions['paged'] . " " . __('of', '404-solution') . " " . esc_html($total_pages); $showRowsText = __('Rows per page:', '404-solution'); $showRowsLink = wp_nonce_url($url . '&action=changeItemsPerRow', "abj404_importRedirects"); // read the html content. $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/paginationLinks.html"); // do special replacements $html = str_replace(' value="' . $tableOptions['perpage'] . '"', ' value="' . $tableOptions['perpage'] . '" selected', $html); $html = str_replace('{changeItemsPerPage}', $showRowsLink, $html); $html = str_replace('{TEXT_BEFORE_LINKS}', $currentlyShowingText, $html); $html = str_replace('{TEXT_SHOW_ROWS}', $showRowsText, $html); $html = str_replace('{LINK_FIRST_PAGE}', esc_url($firsturl), $html); $html = str_replace('{LINK_PREVIOUS_PAGE}', esc_url($prevurl), $html); $html = str_replace('{TEXT_CURRENT_PAGE}', $currentPageText, $html); $html = str_replace('{LINK_NEXT_PAGE}', esc_url($nexturl), $html); $html = str_replace('{LINK_LAST_PAGE}', esc_url($lasturl), $html); // constants and translations. $html = $this->doNormalReplacements($html); echo $html; } /** Output the filters for a tab. * @global type $abj404dao * @param type $sub * @param type $tableOptions */ function echoTabFilters($sub, $tableOptions) { global $abj404dao; global $abj404logic; global $abj404logging; global $abj404_redirect_types; global $abj404_captured_types; if (count($tableOptions) == 0) { $tableOptions = $abj404logic->getTableOptions(); } $url = "?page=" . ABJ404_PP; if ($sub == 'abj404_captured') { $url .= "&subpage=abj404_captured"; } else if ($sub == 'abj404_redirects') { $url .= "&subpage=abj404_redirects"; } else { $abj404logging->errorMessage("Unexpected sub page: " . $sub); } $url .= "&orderby=" . sanitize_text_field($tableOptions['orderby']); $url .= "&order=" . sanitize_text_field($tableOptions['order']); if ($sub == 'abj404_redirects') { $types = $abj404_redirect_types; } else if ($sub == 'abj404_captured') { $types = $abj404_captured_types; } else { $abj404logging->debugMessage("Unexpected sub type for tab filter: " . $sub); $types = $abj404_captured_types; } $class = ""; if ($tableOptions['filter'] == 0) { $class = " class=\"current\""; } echo ""; echo "
    "; if ($sub != 'abj404_captured') { echo "
  • "; echo "" . __('All', '404-solution'); echo " (" . esc_html($abj404dao->getRecordCount($types)) . ")"; echo ""; echo "
  • "; } foreach ($types as $type) { $thisurl = $url . "&filter=" . $type; $class = ""; if ($tableOptions['filter'] == $type) { $class = " class=\"current\""; } $recordCount = 0; if ($type == ABJ404_STATUS_MANUAL) { $title = "Manual Redirects"; $recordCount = $abj404dao->getRecordCount(array($type, ABJ404_STATUS_REGEX)); } else if ($type == ABJ404_STATUS_AUTO) { $title = "Automatic Redirects"; $recordCount = $abj404dao->getRecordCount(array($type)); } else if ($type == ABJ404_STATUS_CAPTURED) { $title = "Captured URLs"; $recordCount = $abj404dao->getRecordCount(array($type)); } else if ($type == ABJ404_STATUS_IGNORED) { $title = "Ignored 404s"; $recordCount = $abj404dao->getRecordCount(array($type)); } else if ($type == ABJ404_STATUS_LATER) { $title = "Organize Later"; $recordCount = $abj404dao->getRecordCount(array($type)); } else if ($type == ABJ404_STATUS_REGEX) { // don't include a tab here because these are included in the manual redirects. continue; } else { $abj404logging->errorMessage("Unrecognized redirect type in View: " . esc_html($type)); } echo "
  • "; if ($sub != 'abj404_captured' || $type != ABJ404_STATUS_CAPTURED) { echo " | "; } echo "" . ( $title ); echo " (" . esc_html($recordCount) . ")"; echo ""; echo "
  • "; } $trashurl = $url . "&filter=" . ABJ404_TRASH_FILTER; $class = ""; if ($tableOptions['filter'] == ABJ404_TRASH_FILTER) { $class = " class=\"current\""; } echo "
  • | "; echo "" . __('Trash', '404-solution'); echo " (" . esc_html($abj404dao->getRecordCount($types, 1)) . ")"; echo ""; echo "
  • "; echo "
"; echo ""; } }