%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 (preg_match('/^[0-9,]+/', $abj404dao->getPostOrGetSanitize('ids_multiple'))) { $recnums_multiple = preg_split('@,@', $abj404dao->getPostOrGetSanitize('ids_multiple'), NULL, PREG_SPLIT_NO_EMPTY); } else { echo __('Error: No ID(s) found for edit request.', '404-solution'); ABJ_404_Solution_Functions::errorMessage("No ID(s) found in GET or POST data for edit request."); return; } echo "

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

"; $url = "?page=abj404_solution&subpage=abj404_edit"; $link = wp_nonce_url($url, "abj404editRedirect"); 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: " . esc_html(implode(',', $recnums_multiple)) . ")"; ABJ_404_Solution_Functions::debugMessage("Error: Invalid ID Numbers! (ids: " . esc_html(implode(',', $recnums_multiple)) . ")"); return; } echo ""; echo ' \n"; echo '
' . "\n"; echo "
    ' . "\n"; foreach ($redirects_multiple as $redirect) { echo "
  • " . $redirect['url'] . "
  • \n"; } echo '
' . "\n"; echo "
\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 . ")"; ABJ_404_Solution_Functions::debugMessage("Error: Invalid ID Number(s) specified! (id: " + $recnum . ", ids: " . $recnums_multiple . ")"); return; } echo "
"; $final = ""; if ($redirect['type'] == ABJ404_EXTERNAL) { $final = $redirect['final_dest']; } echo " (" . __('Required if Redirect to is set to External Page', '404-solution') . ")
"; echo "
"; echo ""; echo "
"; } /** This is a supporting method for the echoAdminEditRedirectPage() method. * @global type $abj404dao */ function echoAdminEditRedirectPageSelects($redirect) { global $abj404dao; $pagesRows = get_pages(); foreach ($pagesRows as $prow) { $id = $prow->ID; $theTitle = $prow->post_title; $thisval = $id . "|" . ABJ404_POST; $parent = $prow->post_parent; while ($parent != 0) { $abj404dao->getPostParent($parent); if (!( $prow == NULL )) { $theTitle = get_the_title($prow->id) . " » " . $theTitle; $parent = $prow->post_parent; } else { break; } } $selected = ""; if ($redirect['type'] == ABJ404_POST && $redirect['final_dest'] == $id) { $selected = " selected"; } echo "\n"; } $cats = get_categories('hierarchical=0'); foreach ($cats as $cat) { $id = $cat->term_id; $theTitle = $cat->name; $thisval = $id . "|" . ABJ404_CAT; $selected = ""; if ($redirect['type'] == ABJ404_CAT && $redirect['final_dest'] == $id) { $selected = " selected"; } echo ""; } $tags = get_tags('hierarchical=0'); foreach ($tags as $tag) { $id = $tag->term_id; $theTitle = $tag->name; $thisval = $id . "|" . ABJ404_TAG; $selected = ""; if ($redirect['type'] == ABJ404_TAG && $redirect['final_dest'] == $id) { $selected = " selected"; } echo ""; } } /** * @global type $abj404dao */ function echoAdminCapturedURLsPage() { global $abj404dao; global $abj404logic; $sub = "captured"; $tableOptions = $abj404logic->getTableOptions(); $this->echoTabFilters($sub, $tableOptions); $columns['url']['title'] = "URL"; $columns['url']['orderby'] = "url"; $columns['url']['width'] = "50%"; $columns['hits']['title'] = "Hits"; $columns['hits']['orderby'] = "hits"; $columns['hits']['width'] = "10%"; $columns['timestamp']['title'] = "Created"; $columns['timestamp']['orderby'] = "timestamp"; $columns['timestamp']['width'] = "20%"; $columns['last_used']['title'] = "Last Used"; $columns['last_used']['orderby'] = ""; $columns['last_used']['width'] = "20%"; $timezone = get_option('timezone_string'); if ('' == $timezone) { $timezone = 'UTC'; } date_default_timezone_set($timezone); echo "
"; $this->echoPaginationLinks($sub, $tableOptions); if ($tableOptions['filter'] == '-1') { echo "
"; $eturl = "?page=abj404_solution&subpage=abj404_captured&filter=-1"; $trashaction = "abj404_emptyCapturedTrash"; $eturl = wp_nonce_url($eturl, $trashaction); echo "
"; echo ""; echo ""; echo "
"; echo "
"; } else { echo "
"; $url = "?page=abj404_solution&subpage=abj404_captured"; if ($tableOptions['filter'] != 0) { $url .= "&filter=" . $tableOptions['filter']; } if (!( $tableOptions['orderby'] == "url" && $tableOptions['order'] == "ASC" )) { $url .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; } $bulkaction = "abj404_bulkProcess"; // is there a way to use the "; if ($tableOptions['filter'] != ABJ404_IGNORED) { echo ""; } else { echo ""; } echo ""; echo ""; echo ""; echo ""; echo "
"; } echo "
"; echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $rows = $abj404dao->getRedirects($sub, $tableOptions); $displayed = 0; $y = 1; foreach ($rows as $row) { $displayed++; $hits = $row['hits']; $last_used = $abj404dao->getRedirectLastUsed($row['id']); if ($last_used != 0) { $last = date("Y/m/d h:i:s A", $last_used); } else { $last = __('Never Used', '404-solution'); } $editlink = "?page=abj404_solution&subpage=abj404_edit&id=" . $row['id']; $logslink = "?page=abj404_solution&subpage=abj404_logs&id=" . $row['id']; $trashlink = "?page=abj404_solution&&subpage=abj404_captured&id=" . $row['id']; $ignorelink = "?page=abj404_solution&&subpage=abj404_captured&id=" . $row['id']; $deletelink = "?page=abj404_solution&subpage=abj404_captured&remove=1&id=" . $row['id']; if ($tableOptions['filter'] == -1) { $trashlink .= "&trash=0"; $trashtitle = __('Restore', '404-solution'); } else { $trashlink .= "&trash=1"; $trashtitle = __('Trash', '404-solution'); } if ($tableOptions['filter'] == ABJ404_IGNORED) { $ignorelink .= "&ignore=0"; $ignoretitle = __('Remove Ignore Status', '404-solution'); } else { $ignorelink .= "&ignore=1"; $ignoretitle = __('Ignore 404 Error', '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']; } $trashaction = "abj404_trashRedirect"; $trashlink = wp_nonce_url($trashlink, $trashaction); if ($tableOptions['filter'] == -1) { $deleteaction = "abj404_removeRedirect"; $deletelink = wp_nonce_url($deletelink, $deleteaction); } $ignoreaction = "abj404_ignore404"; $ignorelink = wp_nonce_url($ignorelink, $ignoreaction); $class = ""; if ($y == 0) { $class = " class=\"alternate\""; $y++; } else { $y = 0; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } if ($displayed == 0) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo ""; echo "
"; if ($tableOptions['filter'] != '-1') { echo ""; } echo ""; echo "" . esc_html($row['url']) . ""; echo "
"; if ($tableOptions['filter'] != -1) { echo "" . __('Edit', '404-solution') . ""; echo " | "; } echo "" . esc_html($trashtitle) . ""; echo " | "; echo "" . __('View Logs', '404-solution') . ""; if ($tableOptions['filter'] != -1) { echo " | "; echo "" . esc_html($ignoretitle) . ""; } else { echo " | "; echo "" . __('Delete Permanently', '404-solution') . ""; } echo "
"; echo "
" . esc_html($hits) . "" . esc_html(date("Y/m/d h:i:s A", $row['timestamp'])) . "" . esc_html($last) . "
" . __('No Records To Display', '404-solution') . "
"; echo "
"; if ($tableOptions['filter'] != '-1') { echo ""; } $this->echoPaginationLinks($sub, $tableOptions); echo "
"; } /** * @global type $abj404dao * @global type $abj404logic */ function echoAdminRedirectsPage() { global $abj404dao; global $abj404logic; $sub = "redirects"; $options = $abj404logic->getOptions(); $tableOptions = $abj404logic->getTableOptions(); // Sanitizing unchecked table options foreach ($tableOptions as $key => $value) { $key = wp_kses_post($key); $tableOptions[$key] = wp_kses_post($value); } $this->echoTabFilters($sub, $tableOptions); $columns['url']['title'] = "URL"; $columns['url']['orderby'] = "url"; $columns['url']['width'] = "25%"; $columns['status']['title'] = "Status"; $columns['status']['orderby'] = "status"; $columns['status']['width'] = "5%"; $columns['type']['title'] = "Type"; $columns['type']['orderby'] = "type"; $columns['type']['width'] = "10%"; $columns['dest']['title'] = "Destination"; $columns['dest']['orderby'] = "final_dest"; $columns['dest']['width'] = "25%"; $columns['code']['title'] = "Redirect"; $columns['code']['orderby'] = "code"; $columns['code']['width'] = "5%"; $columns['hits']['title'] = "Hits"; $columns['hits']['orderby'] = "hits"; $columns['hits']['width'] = "10%"; $columns['timestamp']['title'] = "Created"; $columns['timestamp']['orderby'] = "timestamp"; $columns['timestamp']['width'] = "10%"; $columns['last_used']['title'] = "Last Used"; $columns['last_used']['orderby'] = ""; $columns['last_used']['width'] = "10%"; $timezone = get_option('timezone_string'); if ('' == $timezone) { $timezone = 'UTC'; } date_default_timezone_set($timezone); echo "
"; $this->echoPaginationLinks($sub, $tableOptions); if ($tableOptions['filter'] == '-1') { echo "
"; $eturl = "?page=abj404_solution&filter=-1"; $trashaction = "abj404_emptyRedirectTrash"; $eturl = wp_nonce_url($eturl, $trashaction); echo "
"; echo ""; echo ""; echo "
"; echo "
"; } echo "
"; echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $rows = $abj404dao->getRedirects($sub, $tableOptions); $displayed = 0; $y = 1; foreach ($rows as $row) { $displayed++; $status = ""; if ($row['status'] == ABJ404_MANUAL) { $status = __('Manual', '404-solution'); } else if ($row['status'] == ABJ404_AUTO) { $status = __('Automatic', '404-solution'); } $type = ""; $dest = ""; $link = ""; $title = __('Visit', '404-solution') . " "; if ($row['type'] == ABJ404_EXTERNAL) { $type = __('External', '404-solution'); $dest = $row['final_dest']; $link = $row['final_dest']; $title .= $row['final_dest']; } else if ($row['type'] == ABJ404_POST) { $type = __('Post/Page', '404-solution'); $permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($row['final_dest'] . "|POST", 0); $dest = $permalink['title']; $link = $permalink['link']; $title .= $permalink['title']; } else if ($row['type'] == ABJ404_CAT) { $type = __('Category', '404-solution'); $permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($row['final_dest'] . "|CAT", 0); $dest = $permalink['title']; $link = $permalink['link']; $title .= __('Category:', '404-solution') . " " . $permalink['title']; } else if ($row['type'] == ABJ404_TAG) { $type = __('Tag', '404-solution'); $permalink = ABJ_404_Solution_Functions::permalinkInfoToArray($row['final_dest'] . "|TAG", 0); $dest = $permalink['title']; $link = $permalink['link']; $title .= __('Tag:', '404-solution') . " " . $permalink['title']; } $hits = $row['hits']; $last_used = $abj404dao->getRedirectLastUsed($row['id']); if ($last_used != 0) { $last = date("Y/m/d h:i:s A", $last_used); } else { $last = __('Never Used', '404-solution'); } $editlink = "?page=abj404_solution&subpage=abj404_edit&id=" . absint($row['id']); $logslink = "?page=abj404_solution&subpage=abj404_logs&id=" . absint($row['id']); $trashlink = "?page=abj404_solution&id=" . absint($row['id']); $deletelink = "?page=abj404_solution&remove=1&id=" . absint($row['id']); if ($tableOptions['filter'] == -1) { $trashlink .= "&trash=0"; $trashtitle = __('Restore', '404-solution'); } else { $trashlink .= "&trash=1"; $trashtitle = __('Trash', '404-solution'); } if (!( $tableOptions['orderby'] == "url" && $tableOptions['order'] == "ASC" )) { $trashlink .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; $deletelink .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; } if ($tableOptions['filter'] != 0) { $trashlink .= "&filter=" . $tableOptions['filter']; $deletelink .= "&filter=" . $tableOptions['filter']; } $trashaction = "abj404_trashRedirect"; $trashlink = wp_nonce_url($trashlink, $trashaction); if ($tableOptions['filter'] == -1) { $deleteaction = "abj404_removeRedirect"; $deletelink = wp_nonce_url($deletelink, $deleteaction); } $class = ""; if ($y == 0) { $class = " class=\"alternate\""; $y++; } else { $y = 0; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } if ($displayed == 0) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo ""; echo "
"; echo "" . esc_html($row['url']) . ""; echo "
"; if ($tableOptions['filter'] != -1) { echo "" . __('Edit') . ""; echo " | "; } echo "" . esc_html($trashtitle) . ""; echo " | "; echo "" . __('View Logs') . ""; if ($tableOptions['filter'] == -1) { echo " | "; echo "" . __('Delete Permanently', '404-solution') . ""; } echo "
"; echo "
" . esc_html($status) . "" . esc_html($type) . "" . esc_html($dest) . "" . esc_html($row['code']) . "" . esc_html($hits) . "" . esc_html(date("Y/m/d h:i:s A", $row['timestamp'])) . "" . esc_html($last) . "
" . __('No Records To Display', '404-solution') . "
"; echo "
"; $this->echoPaginationLinks($sub, $tableOptions); echo "
"; if ($tableOptions['filter'] != -1) { echo "

" . __('Add Manual Redirect', '404-solution') . "

"; $url = "?page=abj404_solution"; if (!( $tableOptions['orderby'] == "url" && $tableOptions['order'] == "ASC" )) { $url .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; } if ($tableOptions['filter'] != 0) { $url .= "&filter=" . $tableOptions['filter']; } $action = "abj404addRedirect"; $link = wp_nonce_url($url, $action); echo "
"; echo ""; $urlPlaceholder = parse_url(get_home_url(), PHP_URL_PATH) . "/example"; if (isset($_POST['url']) && $_POST['url'] != '') { $postedURL = esc_url($_POST['url']); } else { $postedURL = $urlPlaceholder; } echo " (" . __('Required', '404-solution') . ")
"; echo "
"; $postedExternal = esc_url(@$_POST['external']); echo " (" . __('Required if Redirect to is set to External Page', '404-solution') . ")
"; echo "
"; echo ""; echo "
"; } } /** * @global type $abj404dao * @global type $wpdb * @param type $options * @return string */ function getAdminOptionsPageAutoRedirects($options) { global $abj404dao; $spaces = esc_html("   "); $content = ""; $selected = ""; global $wpdb; $content .= "
"; $selectedAutoRedirects = ""; if ($options['auto_redirects'] == '1') { $selectedAutoRedirects = " checked"; } $content .= "


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

"; $content .= "


"; $content .= $spaces . __('Only create an automatic redirect if the suggested page has a score above the specified number', '404-solution') . "

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

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

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


"; $content .= $spaces . __('Creates auto redirects for any url resolving to a post/page that doesn\'t match the current permalinks', '404-solution') . "

"; $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; } /** * @param type $options * @return string */ function getAdminOptionsPage404Suggestions($options) { // Suggested Alternatives Options $selectedDisplaySuggest = ""; if ($options['display_suggest'] == '1') { $selectedDisplaySuggest = " checked"; } $spaces = esc_html("   "); $content = "


"; $content .= $spaces . __('Activates the 404 page suggestions function. Only works if the code is in your 404 page template.', '404-solution'); $content .= "
" . $spaces . "Code: " . esc_html("suggestions(); } ?>") . "

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


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


"; $content .= "

" ; $content .= "

"; $content .= "

"; $content .= "

" . __('Display Before/After page suggestions', '404-solution') . ": "; $content .= " / "; $content .= ""; $content .= "

" . __('Display Before/After each suggested entry', '404-solution') . ": "; $content .= " / "; $content .= ""; $content .= "

"; $content .= ""; return $content; } /** * @param type $options * @return string */ function getAdminOptionsPageGeneralSettings($options) { $spaces = esc_html("   "); $content = "

" . __('DB Version Number', '404-solution') . ": " . esc_html($options['DB_VERSION']) . "

"; $content .= "

"; $content .= "

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

"; $content .= "

" . __('Captured URLs (0 Disables Notification)', '404-solution') . "
"; $content .= $spaces . __('Display WordPress admin notifications when number of captured URLs goes above specified level', '404-solution') . "

"; $content .= "

" . __('Days (0 Disables Auto Delete)', '404-solution') . "
"; $content .= $spaces . __('Automatically removes 404 URLs that have been captured if they haven\'t been used for the specified amount of time.', '404-solution') . "

"; $content .= "

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

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


"; $content .= $spaces . __('Checks each redirect for a new matching permalink before user is redirected. If a new page permalink is found matching the redirected URL then the redirect will be deleted.', '404-solution') . "

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

"; return $content; } /** * @global type $abj404dao */ function echoAdminLogsPage() { global $abj404dao; global $abj404logic; $sub = "logs"; $tableOptions = $abj404logic->getTableOptions(); // Sanitizing unchecked table options foreach ($tableOptions as $key => $value) { $key = wp_kses_post($key); $tableOptions[$key] = wp_kses_post($value); } $redirects = array(); $redirectsFound = 0; $rows = $abj404dao->getRedirectsAll(); foreach ($rows as $row) { $redirects[$row['id']]['id'] = absint($row['id']); $redirects[$row['id']]['url'] = esc_url($row['url']); $redirectsFound++; } ABJ_404_Solution_Functions::debugMessage($redirectsFound . " redirects found for logs page select option."); echo "
"; echo "
"; echo ""; echo ""; echo " "; echo "
"; echo ""; echo "
"; $columns['url']['title'] = "URL"; $columns['url']['orderby'] = "url"; $columns['url']['width'] = "25%"; $columns['host']['title'] = "IP Address"; $columns['host']['orderby'] = "remote_host"; $columns['host']['width'] = "10%"; $columns['refer']['title'] = "Referrer"; $columns['refer']['orderby'] = "referrer"; $columns['refer']['width'] = "25%"; $columns['dest']['title'] = "Action Taken"; $columns['dest']['orderby'] = "action"; $columns['dest']['width'] = "25%"; $columns['timestamp']['title'] = "Date"; $columns['timestamp']['orderby'] = "timestamp"; $columns['timestamp']['width'] = "15%"; echo "
"; $this->echoPaginationLinks($sub, $tableOptions); echo "
"; echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $this->echoTableColumns($sub, $tableOptions, $columns); echo ""; echo ""; $rows = $abj404dao->getLogRecords($tableOptions); $redirectsDisplayed = 0; $y = 1; $timezone = get_option('timezone_string'); if ('' == $timezone) { $timezone = 'UTC'; } date_default_timezone_set($timezone); foreach ($rows as $row) { $redirect_id = $row['redirect_id']; if (empty($redirect_id)) { // delete the redirect. it only exists in the logs due to an error. $abj404dao->deleteRedirect($redirect_id); ABJ_404_Solution_Functions::debugMessage("Deleted reference to nonexistent redirect from logs table. ID: " . $redirect_id); continue; } $class = ""; if ($y == 0) { $class = " class=\"alternate\""; $y++; } else { $y = 0; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $redirectsDisplayed++; } ABJ_404_Solution_Functions::debugMessage($redirectsDisplayed . " log records displayed on the page."); if ($redirectsDisplayed == 0) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo ""; echo "
" . esc_html($redirects[$redirect_id]['url']) . "" . 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 __('Redirect to', '404-solution') . " "; echo "" . esc_html($row['action']) . ""; } echo "" . esc_html(date('Y/m/d h:i:s A', $row['timestamp'])) . "
" . __('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 ""; if ($sub == "captured" && $tableOptions['filter'] != '-1') { $cbinfo = "class=\"manage-column column-cb check-column\" style=\"vertical-align: middle; padding-bottom: 6px;\""; } else { $cbinfo = "style=\"width: 1px;\""; } echo ""; if ($sub == "captured" && $tableOptions['filter'] != '-1') { 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'] == "lastused") { $class .= " asc"; $sortorder = "DESC"; } else { $class .= " desc"; $sortorder = "ASC"; } } else { $class = ""; $nolink = 1; } } $url = "?page=abj404_solution"; if ($sub == "captured") { $url .= "&subpage=abj404_captured"; } else if ($sub == "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; $url = "?page=abj404_solution"; if ($sub == "captured") { $url .= "&subpage=abj404_captured"; } else if ($sub == "logs") { $url .= "&subpage=abj404_logs&id=" . $tableOptions['logsid']; } $url .= "&orderby=" . $tableOptions['orderby']; $url .= "&order=" . $tableOptions['order']; if ($tableOptions['filter'] == 0 || $tableOptions['filter'] == -1) { if ($sub == "redirects") { $types = array(ABJ404_MANUAL, ABJ404_AUTO); } else { $types = array(ABJ404_CAPTURED, ABJ404_IGNORED); } } else { $types = array($tableOptions['filter']); $url .= "&filter=" . $tableOptions['filter']; } if ($sub == "logs") { $num_records = $abj404dao->getLogsCount($tableOptions['logsid']); } else { // -1 means Trash. we should create a constant for this value... if ($tableOptions['filter'] == -1) { $num_records = $abj404dao->getRecordCount($types, 1); } else { $num_records = $abj404dao->getRecordCount($types); } } if (ABJ_404_Solution_Functions::isDebug()) { ABJ_404_Solution_Functions::debugMessage(esc_html($num_records) . " total log records found. Table options: " . wp_kses(json_encode($tableOptions), array())); } $total_pages = ceil($num_records / $tableOptions['perpage']); if ($total_pages == 0) { $total_pages = 1; } echo "
"; $itemsText = sprintf( _n( '%s item', '%s items', $num_records, '404-solution'), $num_records); echo "" . " " . $itemsText . ""; echo ""; $classFirstPage = ""; if ($tableOptions['paged'] == 1) { $classFirstPage = " disabled"; } $firsturl = $url; echo "«"; $classPreviousPage = ""; if ($tableOptions['paged'] == 1) { $classPreviousPage = " disabled"; $prevurl = $url; } else { $prev = $tableOptions['paged'] - 1; $prevurl = $url . "&paged=" . $prev; } echo ""; echo " "; echo __('Page', '404-solution') . " " . $tableOptions['paged'] . " " . __('of', '404-solution') . " " . esc_html($total_pages); echo " "; $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; } echo ""; $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; } echo "»"; echo ""; echo "
"; } /** Output the filters for a tab. * @global type $abj404dao * @param type $sub * @param type $tableOptions */ function echoTabFilters($sub, $tableOptions) { global $abj404dao; global $abj404logic; if (count($tableOptions) == 0) { $tableOptions = $abj404logic->getTableOptions(); } echo ""; echo "
    "; $url = "?page=abj404_solution"; if ($sub == "captured") { $url .= "&subpage=abj404_captured"; } else if ($sub == "redirects") { $url .= "&subpage=abj404_redirects"; } else { ABJ_404_Solution_Functions::errorMessage("Unexpected sub page: " + $sub); } $url .= "&orderby=" . sanitize_text_field($tableOptions['orderby']); $url .= "&order=" . sanitize_text_field($tableOptions['order']); if ($sub == "redirects") { $types = array(ABJ404_MANUAL, ABJ404_AUTO); } else { $types = array(ABJ404_CAPTURED, ABJ404_IGNORED); } $class = ""; if ($tableOptions['filter'] == 0) { $class = " class=\"current\""; } if ($sub != "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\""; } if ($type == ABJ404_MANUAL) { $title = "Manual Redirects"; } else if ($type == ABJ404_AUTO) { $title = "Automatic Redirects"; } else if ($type == ABJ404_CAPTURED) { $title = "Captured URLs"; } else if ($type == ABJ404_IGNORED) { $title = "Ignored 404s"; } else { ABJ_404_Solution_Functions::errorMessage("Unrecognized redirect type in View: " . esc_html($type)); } echo "
  • "; if ($sub != "captured" || $type != ABJ404_CAPTURED) { echo " | "; } echo "" . ( $title ); echo " (" . esc_html($abj404dao->getRecordCount(array($type))) . ")"; echo ""; echo "
  • "; } $trashurl = $url . "&filter=-1"; $class = ""; if ($tableOptions['filter'] == -1) { $class = " class=\"current\""; } echo "
  • | "; echo "" . __('Trash', '404-solution'); echo " (" . esc_html($abj404dao->getRecordCount($types, 1)) . ")"; echo ""; echo "
  • "; echo "
"; echo "
"; } }