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

" . esc_html(__('404 Solution', '404-solution')) . ": " . $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() { if (!is_admin() || !current_user_can('administrator')) { return; } global $abj404view; global $abj404logic; $sub = ""; // -------------------------------------------------------------------- // Handle Post Actions $action = sanitize_text_field(@$_POST['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->handleEditAction($sub); // -------------------------------------------------------------------- // Output the correct page. $abj404view->echoChosenAdminTab($sub, $message); } /** Display the chosen admin page. * @global type $abj404view * @param type $sub * @param type $message */ function echoChosenAdminTab($sub, $message) { global $abj404view; // Deal With Page Tabs if ($sub == "") { $sub = strtolower(sanitize_text_field(@$_GET['subpage'])); } if ($sub == "abj404_options") { $sub = "options"; } else if ($sub == "abj404_captured") { $sub = "captured"; } else if ($sub == "abj404_logs") { $sub = "logs"; } else if ($sub == "abj404_edit") { $sub = "edit"; } else if ($sub == "abj404_stats") { $sub = "stats"; } else if ($sub == "abj404_tools") { $sub = "tools"; } else if ($sub == "abj404_redirects") { $sub = "redirects"; } else { // default page when clicking the settigns submenu. $sub = "redirects"; } $abj404view->outputAdminHeaderTabs($sub, $message); if ($sub == "redirects") { $abj404view->echoAdminRedirectsPage(); } else if ($sub == "captured") { $abj404view->echoAdminCapturedURLsPage(); } else if ($sub == "options") { $abj404view->echoAdminOptionsPage(); } else if ($sub == "logs") { $abj404view->echoAdminLogsPage(); } else if ($sub == "edit") { $abj404view->echoAdminEditRedirectPage(); } else if ($sub == "stats") { $abj404view->outputAdminStatsPage(); } else if ($sub == "tools") { $abj404view->echoAdminToolsPage(); } else { echo __('Invalid Sub Page ID', '404-solution') . " (" + esc_html($sub) . ")"; ABJ_404_Solution_Functions::debugMessage("Invalid sub page ID: " + esc_html($sub)); } $abj404view->echoAdminFooter(); } /** Echo the text that appears at the bottom of each admin page. */ function echoAdminFooter() { echo "
"; echo "
"; echo "
Credits:
"; echo "" . __('404 Solution') . " "; echo __('is maintained by', '404-solution'); echo " "; echo "Aaron J. | "; echo __('Version', '404-solution') . ": " . ABJ404_VERSION; echo "
"; echo ""; } /** Output the tabs at the top of the plugin page. * @param type $sub * @param type $message */ function outputAdminHeaderTabs($sub = 'list', $message = '') { if ($sub == "options") { $header = " " . __('Options', '404-solution'); } else if ($sub == "logs") { $header = " " . __('Logs', '404-solution'); } else if ($sub == "stats") { $header = " " . __('Stats', '404-solution'); } else if ($sub == "edit") { $header = ": " . __('Edit Redirect', '404-solution'); } else if ($sub == "redirects") { $header = ""; } else { $header = ""; } echo "
"; if ($sub == "options") { echo "
"; } else { echo "
"; } echo "

" . __('404 Solution', '404-solution') . esc_html($header) . "

"; if ($message != "") { $allowed_tags = [ 'br' => [], 'em' => [], 'strong' => [], ]; echo "

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

"; } $class = ""; if ($sub == "redirects") { $class = "nav-tab-active"; } echo "" . __('Page Redirects', '404-solution') . ""; $class = ""; if ($sub == "captured") { $class = "nav-tab-active"; } echo "" . __('Captured 404 URLs', '404-solution') . ""; $class = ""; if ($sub == "logs") { $class = "nav-tab-active"; } echo "" . __('Logs', '404-solution') . ""; $class = ""; if ($sub == "stats") { $class = "nav-tab-active"; } echo "" . __('Stats', '404-solution') . ""; $class = ""; if ($sub == "tools") { $class = "nav-tab-active"; } echo "" . __('Tools', '404-solution') . ""; $class = ""; if ($sub == "options") { $class = "nav-tab-active"; } echo "" . __('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_logs"; $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_AUTO; $auto301 = $abj404dao->getStatsCount($query, array(ABJ404_AUTO)); $query = "select count(id) from $redirects where disabled = 0 and code = 302 and status = %d"; // . ABJ404_AUTO; $auto302 = $abj404dao->getStatsCount($query, array(ABJ404_AUTO)); $query = "select count(id) from $redirects where disabled = 0 and code = 301 and status = %d"; // . ABJ404_MANUAL; $manual301 = $abj404dao->getStatsCount($query, array(ABJ404_MANUAL)); $query = "select count(id) from $redirects where disabled = 0 and code = 302 and status = %d"; // . ABJ404_MANUAL; $manual302 = $abj404dao->getStatsCount($query, array(ABJ404_MANUAL)); $query = "select count(id) from $redirects where disabled = 1 and (status = %d or status = %d)"; $trashed = $abj404dao->getStatsCount($query, array(ABJ404_AUTO, ABJ404_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_CAPTURED; $captured = $abj404dao->getStatsCount($query, array(ABJ404_CAPTURED)); $query = "select count(id) from $redirects where disabled = 0 and status = %d"; // . ABJ404_IGNORED; $ignored = $abj404dao->getStatsCount($query, array(ABJ404_IGNORED)); $query = "select count(id) from $redirects where disabled = 1 and (status = %d or status = %d)"; $trashed = $abj404dao->getStatsCount($query, array(ABJ404_CAPTURED, ABJ404_IGNORED)); $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, date('m'), date('d'), date('Y')); $firstm = mktime(0, 0, 0, date('m'), 1, date('Y')); $firsty = mktime(0, 0, 0, 1, 1, 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 action = %s"; $disp404 = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct redirect_id) from $logs where timestamp >= $ts and action = %s"; $distinct404 = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct remote_host) from $logs where timestamp >= $ts and action = %s"; $visitors404 = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct referrer) from $logs where timestamp >= $ts and action = %s"; $refer404 = $abj404dao->getStatsCount($query, array("404")); $query = "select count(id) from $logs where timestamp >= $ts and action != %s"; $redirected = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct redirect_id) from $logs where timestamp >= $ts and action != %s"; $distinctredirected = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct remote_host) from $logs where timestamp >= $ts and action != %s"; $distinctvisitors = $abj404dao->getStatsCount($query, array("404")); $query = "select count(distinct referrer) from $logs where timestamp >= $ts and action != %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 "
"; } /** Display the tools page. * @global type $abj404view */ function echoAdminToolsPage() { global $abj404view; $sub = "tools"; $hr = "style=\"border: 0px; margin-bottom: 0px; padding-bottom: 4px; border-bottom: 1px dotted #DEDEDE;\""; $url = "?page=abj404_solution&subpage=abj404_tools"; $action = "abj404_purgeRedirects"; $link = wp_nonce_url($url, $action); echo "
"; echo "
"; echo "
"; $content = ""; $content .= "
"; $content .= ""; $content .= "

"; $content .= "

"; $content .= "" . __('Redirect Types', '404-solution') . ":
"; $content .= "

    "; $content .= "
  • "; $content .= "
  • "; $content .= "
  • "; $content .= "
  • "; $content .= "
"; $content .= "" . __('Sanity Check', '404-solution') . "
"; $content .= __('Using the purge options will delete logs and redirects matching the boxes selected above. This action is not reversible. Hopefully you know what you\'re doing.', '404-solution') . "
"; $content .= "
"; $content .= " " . __('I understand the above statement, I know what I am doing... blah blah blah. Just delete the records!', '404-solution') . "
"; $content .= "
"; $content .= ""; $content .= "

"; $content .= "
"; $abj404view->echoPostBox("abj404-purgeRedirects", __('Purge Options', '404-solution'), $content); echo "
"; } function echoAdminOptionsPage() { global $abj404logic; global $abj404view; $options = $abj404logic->getOptions(); $url = "?page=abj404_solution"; //General Options $action = "abj404UpdateOptions"; $link = wp_nonce_url($url, $action); 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); $content404PageSuggestions = $abj404view->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; $options = $abj404logic->getOptions(); // this line assures that text will appear below the page tabs at the top. echo "
"; $recnum = null; if (isset($_GET['id']) && preg_match('/[0-9]+/', $_GET['id'])) { $recnum = absint($_GET['id']); } else if (isset($_POST['id']) && preg_match('/[0-9]+/', $_POST['id'])) { $recnum = absint($_POST['id']); } else if (isset($_POST['ids_multiple']) && preg_match('/[0-9,]+/', $_POST['id'])) { $recnums_multiple = preg_split('@,@', $_POST['ids_multiple'], NULL, PREG_SPLIT_NO_EMPTY); } else { echo __('Error: No ID found for edit request.', '404-solution'); ABJ_404_Solution_Functions::errorMessage("No ID found in GET or POST data for edit request."); return; } echo "

" . __('Redirect Details', '404-solution') . "

"; $url = "?page=abj404_solution&subpage=abj404_edit"; $action = "abj404editRedirect"; $link = wp_nonce_url($url, $action); echo "
"; echo ""; // 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) { $redirect = $abj404dao->getRedirectByID($recnum); if ($redirect == null) { echo "Error: Invalid ID Number! (id: " + $recnum . ")"; ABJ_404_Solution_Functions::debugMessage("Error: Invalid ID Number! (id: " + $recnum . ")"); return; } echo ""; echo " "; echo " (" . __('Required', '404-solution') . ")
"; } else if ($recnums_multiple != null) { $redirects_multiple = $abj404dao->getRedirectsByIDs($recnums_multiple); if ($redirects_multiple == null) { echo "Error: Invalid ID Numbers! (ids: " + $recnums_multiple . ")"; ABJ_404_Solution_Functions::debugMessage("Error: Invalid ID Numbers! (ids: " + $recnums_multiple . ")"); return; } echo ""; echo " "; echo "