= $options['admin_notification'] ) { $pageName .= " " . esc_html( $captured ) . ""; $pos = strpos( $menu[80][0], 'update-plugins' ); if ( $pos === false ) { $menu[80][0] = $menu[80][0] . " 1"; } } } add_options_page( '404 Redirected', $pageName, 'manage_options', 'wbz404_redirected', 'wbz404_adminPage' ); } add_action( 'admin_menu', 'wbz404_addAdminPage' ); function wbz404_dashboardNotification() { global $pagenow; if ( current_user_can( 'manage_options' ) ) { if ( ( isset( $_GET['page'] ) && $_GET['page'] == "wbz404_redirected" ) || ( $pagenow == 'index.php' && ( !( isset( $_GET['page'] ) ) ) ) ) { $options = wbz404_getOptions(); if ( isset( $options['admin_notification'] ) && $options['admin_notification'] != '0' ) { $captured = wbz404_capturedCount(); if ( $captured >= $options['admin_notification'] ) { echo "

" . esc_html( __( '404 Redirected', '404-redirected' ) ) . ": " . __( 'There are ' . esc_html( $captured ) . ' captured 404 URLs that need to be processed.', '404-redirected' ) . "

"; } } } } } add_action( 'admin_notices', 'wbz404_dashboardNotification' ); function wbz404_postbox( $id, $title, $content ) { echo "
"; echo "

" . esc_html( $title ) . "

"; echo "
" . $content /* Can't escape here, as contains forms */ . "
"; echo "
"; } function wbz404_capturedCount() { global $wpdb; $query = "select count(id) from " . $wpdb->prefix . "wbz404_redirects where status = " . esc_sql( WBZ404_CAPTURED ); $captured = $wpdb->get_col( $query, 0 ); if ( count( $captured ) == 0 ) { $captured[0] = 0; } return $captured[0]; } function wbz404_updateOptions() { $message=""; $options = wbz404_getOptions(); if ( $_POST['default_redirect'] == "301" || $_POST['default_redirect'] == "302" ) { $options['default_redirect'] = $_POST['default_redirect']; } else { $message.= __( 'Error: Invalid value specified for default redirect type', '404-redirected' ) . ".
"; } if ( $_POST['capture_404'] == "1" ) { $options['capture_404'] = '1'; } else { $options['capture_404'] = '0'; } if ( preg_match( '/^[0-9]+$/', $_POST['admin_notification'] ) == 1 ) { $options['admin_notification'] = $_POST['admin_notification']; } if ( preg_match( '/^[0-9]+$/', $_POST['capture_deletion'] )==1 && $_POST['capture_deletion'] >= 0 ) { $options['capture_deletion'] = $_POST['capture_deletion']; } else { $message.= __( 'Collected URL deletion value must be a number greater or equal to zero', '404-redirected' ) . ".
"; } if ( preg_match( '/^[0-9]+$/', $_POST['manual_deletion'] )==1 && $_POST['manual_deletion'] >= 0 ) { $options['manual_deletion'] = $_POST['manual_deletion']; } else { $message.= __( 'Manual redirect deletion value must be a number greater or equal to zero', '404-redirected' ) . ".
"; } if ( $_POST['remove_matches'] == "1" ) { $options['remove_matches'] = '1'; } else { $options['remove_matches'] = '0'; } if ( $_POST['display_suggest'] == "1" ) { $options['display_suggest'] = '1'; } else { $options['display_suggest'] = '0'; } if ( $_POST['suggest_cats'] == "1" ) { $options['suggest_cats'] = '1'; } else { $options['suggest_cats'] = '0'; } if ( $_POST['suggest_tags'] == "1" ) { $options['suggest_tags'] = '1'; } else { $options['suggest_tags'] = '0'; } if ( preg_match( '/^[0-9]+$/', $_POST['suggest_minscore'] ) == 1 && $_POST['suggest_minscore'] >= 0 && $_POST['suggest_minscore'] <= 99 ) { $options['suggest_minscore'] = $_POST['suggest_minscore']; } else { $message.= __( 'Suggestion minimum score value must be a number between 1 and 99', '404-redirected' ) . ".
"; } if ( preg_match( '/^[0-9]+$/', $_POST['suggest_max'] ) == 1 && $_POST['suggest_max'] >= 1 ) { $options['suggest_max'] = $_POST['suggest_max']; } else { $message.= __( 'Maximum number of suggest value must be a number greater or equal to 1', '404-redirected' ) . ".
"; } $options['suggest_title'] = $_POST['suggest_title']; $options['suggest_before'] = $_POST['suggest_before']; $options['suggest_after'] = $_POST['suggest_after']; $options['suggest_entrybefore'] = $_POST['suggest_entrybefore']; $options['suggest_entryafter'] = $_POST['suggest_entryafter']; $options['suggest_noresults'] = $_POST['suggest_noresults']; if ( $_POST['auto_redirects'] == "1" ) { $options['auto_redirects'] = '1'; } else { $options['auto_redirects'] = '0'; } if ( $_POST['auto_cats'] == "1" ) { $options['auto_cats'] = '1'; } else { $options['auto_cats'] = '0'; } if ( $_POST['auto_tags'] == "1" ) { $options['auto_tags'] = '1'; } else { $options['auto_tags'] = '0'; } if ( preg_match( '/^[0-9]+$/', $_POST['auto_score'] ) == 1 && $_POST['auto_score'] >= 0 && $_POST['auto_score'] <= 99 ) { $options['auto_score'] = $_POST['auto_score']; } else { $message .= __( 'Auto match score value must be a number between 0 and 99', '404-redirected' ) . ".
"; } if ( preg_match( '/^[0-9]+$/', $_POST['auto_deletion'] )==1 && $_POST['auto_deletion'] >= 0 ) { $options['auto_deletion'] = $_POST['auto_deletion']; } else { $message.= __( 'Auto redirect deletion value must be a number greater or equal to zero', '404-redirected' ) . ".
"; } if ( $_POST['force_permalinks'] == "1" ) { $options['force_permalinks'] = '1'; } else { $options['force_permalinks'] = '0'; } /** * Crude sanitization of inputted data. */ foreach ( $options as $key => $option ) { $new_key = wp_kses_post( $key ); $new_option = wp_kses_post( $option ); $new_options[$new_key] = $new_option; } update_option( 'wbz404_settings', $new_options ); return $message; } function wbz404_getTableOptions() { $tableOptions = array(); if ( !isset( $_POST['filter'] ) ) { if ( !isset( $_GET['filter'] ) ) { if ( isset( $_GET['subpage'] ) && $_GET['subpage'] == 'wbz404_captured' ) { $tableOptions['filter'] = WBZ404_CAPTURED; } else { $tableOptions['filter'] = '0'; } } else { $tableOptions['filter'] = $_GET['filter']; } } else { $tableOptions['filter'] = $_POST['filter']; } if ( !isset( $_GET['orderby'] ) ) { if ( isset( $_GET['subpage'] ) && $_GET['subpage'] == "wbz404_logs" ) { $tableOptions['orderby'] = "timestamp"; } else { $tableOptions['orderby'] = "url"; } } else { $tableOptions['orderby'] = $_GET['orderby']; } if ( !isset( $_GET['order'] ) ) { if ( $tableOptions['orderby'] == "created" || $tableOptions['orderby'] == "lastused" || $tableOptions['orderby'] == "timestamp" ) { $tableOptions['order'] = "DESC"; } else { $tableOptions['order'] = "ASC"; } } else { $tableOptions['order'] = $_GET['order']; } if ( !isset( $_GET['paged'] ) ) { $tableOptions['paged'] = 1; } else { $tableOptions['paged'] = $_GET['paged']; } if ( !isset( $_GET['perpage'] ) ) { $tableOptions['perpage'] = 25; } else { $tableOptions['perpage'] = $_GET['perpage']; } if ( isset( $_GET['subpage'] ) && $_GET['subpage'] == "wbz404_logs" ) { if ( isset( $_GET['id'] ) && preg_match( '/[0-9]+/', $_GET['id'] ) ) { $tableOptions['logsid'] = $_GET['id']; } else { $tableOptions['logsid'] = 0; } } return $tableOptions; } function wbz404_getRecordCount( $types = array(), $trashed = 0 ) { global $wpdb; $records = 0; if ( count( $types )>=1 ) { $query = "select count(id) from " . $wpdb->prefix . "wbz404_redirects where 1 and ("; $x=0; foreach ( $types as $type ) { if ( $x >= 1 ) { $query.=" or "; } $query .= "status = " . $type; $x++; } $query.=")"; $query .= " and disabled = " . $trashed; $row = $wpdb->get_row( $query, ARRAY_N ); $records = $row[0]; } return $records; } function wbz404_getLogsCount( $id ) { global $wpdb; $records = 0; $query = "select count(id) from " . $wpdb->prefix . "wbz404_logs where 1 "; if ( $id != 0 ) { $query .= "and redirect_id = " . $id; } $row = $wpdb->get_row( $query, ARRAY_N ); $records = $row[0]; return $records; } function wbz404_getRecords( $sub, $tableOptions, $limitEnforced = 1 ) { global $wpdb; $rows = array(); $redirects = $wpdb->prefix . "wbz404_redirects"; $logs = $wpdb->prefix . "wbz404_logs"; $query = "select " . $redirects . ".id, " . $redirects . ".url, " . $redirects . ".status, " . $redirects . ".type, " . $redirects . ".final_dest, " . $redirects . ".code, " . $redirects . ".timestamp"; $query .= ", count(" . $logs . ".id) as hits from " . $redirects . " "; $query .= " left outer join " . $logs . " on " . $redirects . ".id = " . $logs . ".redirect_id "; $query .= " where 1 and ("; if ( $tableOptions['filter'] == 0 || $tableOptions['filter'] == -1 ) { if ( $sub == "redirects" ) { $query .= "status = " . WBZ404_MANUAL . " or status = " . WBZ404_AUTO; } else if ( $sub == "captured" ) { $query .= "status = " . WBZ404_CAPTURED . " or status = " . WBZ404_IGNORED; } } else { $query.="status = " . $tableOptions['filter']; } $query .= ") "; if ( $tableOptions['filter'] != -1 ) { $query .= "and disabled = 0 "; } else { $query .= "and disabled = 1 "; } $query .= "group by " . $redirects . ".id "; $query .= "order by " . $tableOptions['orderby'] . " " . $tableOptions['order'] . " "; if ( $limitEnforced == 1 ) { $start = ( $tableOptions['paged'] - 1 ) * $tableOptions['perpage']; $query .= "limit " . $start . ", " . $tableOptions['perpage']; } $rows = $wpdb->get_results( $query, ARRAY_A ); return $rows; } function wbz404_getLogRecords( $tableOptions ) { global $wpdb; $rows = array(); $logs = $wpdb->prefix . "wbz404_logs"; $redirects = $wpdb->prefix . "wbz404_redirects"; $query = "select " . $logs . ".redirect_id, " . $logs . ".timestamp, " . $logs . ".remote_host, " . $logs . ".referrer, " . $logs . ".action, " . $redirects . ".url from " . $logs; $query .= " left outer join " . $redirects . " on " . $logs . ".redirect_id = " . $redirects . ".id where 1 "; if ( $tableOptions['logsid'] != 0 ) { $query .= " and redirect_id = " . $tableOptions['logsid'] . " "; } $query .= "order by " . $tableOptions['orderby'] . " " . $tableOptions['order'] . " "; $start = ( $tableOptions['paged'] - 1 ) * $tableOptions['perpage']; $query .= "limit " . $start . ", " . $tableOptions['perpage']; $rows = $wpdb->get_results( $query, ARRAY_A ); return $rows; } function wbz404_drawFilters( $sub, $tableOptions ) { if ( count( $tableOptions ) == 0 ) { $tableOptions = wbz404_getTableOptions(); } echo ""; } function wbz404_drawPaginationLinks( $sub, $tableOptions ) { $url = "?page=wbz404_redirected"; if ( $sub == "captured" ) { $url .= "&subpage=wbz404_captured"; } else if ( $sub == "logs" ) { $url .= "&subpage=wbz404_logs&id=" . $tableOptions['logsid']; } $url .= "&orderby=" . $tableOptions['orderby']; $url .= "&order=" . $tableOptions['order']; if ( $tableOptions['filter'] == 0 ) { if ( $sub == "redirects" ) { $types = array( WBZ404_MANUAL, WBZ404_AUTO ); } else { $types = array( WBZ404_CAPTURED, WBZ404_IGNORED ); } } else { $types = array( $tableOptions['filter'] ); $url .= "&filter=" . $tableOptions['filter']; } if ( $sub != "logs" ) { $num_records = wbz404_getRecordCount( $types ); } else { $num_records = wbz404_getLogsCount( $tableOptions['logsid'] ); } $total_pages = ceil( $num_records / $tableOptions['perpage'] ); if ( $total_pages == 0 ) { $total_pages = 1; } echo "
"; echo "" . $num_records . " " . __( 'items', '404-redirected' ) . ""; echo ""; $class = ""; if ( $tableOptions['paged'] == 1 ) { $class=" disabled"; } $firsturl = $url; echo "«"; $class = ""; if ( $tableOptions['paged'] == 1 ) { $class=" disabled"; $prevurl = $url; } else { $prev = $tableOptions['paged'] -1; $prevurl = $url . "&paged=" . $prev; } echo ""; echo " "; echo __( 'Page', '404-redirected' ) . " " . $tableOptions['paged'] . " " . __( 'of', '404-redirected' ) . " " . esc_html( $total_pages ); echo " "; $class = ""; if ( $tableOptions['paged'] + 1 > $total_pages ) { $class=" disabled"; if ( $tableOptions['paged'] == 1 ) { $nexturl = $url; } else { $nexturl = $url . "&paged=" . $tableOptions['paged']; } } else { $next = $tableOptions['paged'] + 1; $nexturl = $url . "&paged=" . $next; } echo ""; $class = ""; if ( $tableOptions['paged'] + 1 > $total_pages ) { $class=" disabled"; if ( $tableOptions['paged'] == 1 ) { $lasturl = $url; } else { $lasturl = $url . "&paged=" . $tableOptions['paged']; } } else { $lasturl = $url . "&paged=" . $total_pages; } echo "»"; echo ""; echo "
"; } function wbz404_buildTableColumns( $sub, $tableOptions, $columns ) { echo ""; if ( $sub == "captured" && $tableOptions['filter'] != '-1' ) { $cbinfo = "class=\"manage-column column-cb check-column\""; } 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=wbz404_redirected"; if ( $sub == "captured" ) { $url .= "&subpage=wbz404_captured"; } else if ( $sub == "logs" ) { $url .= "&subpage=wbz404_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 ""; } function wbz404_getRedirectHits( $id ) { global $wpdb; $query = "select count(id) from " . $wpdb->prefix . "wbz404_logs where redirect_id = " . esc_sql(); $row = $wpdb->get_col( $query ); return $row[0]; } function wbz404_getRedirectLastUsed( $id ) { global $wpdb; $query = "select timestamp from " . $wpdb->prefix . "wbz404_logs where redirect_id = " . esc_sql( $id ) . " order by timestamp desc"; $row = $wpdb->get_col( $query ); if ( isset( $row[0] ) ) { return $row[0]; } else { return; } } function wbz404_addAdminRedirect() { global $wpdb; $messasge = ""; if ( $_POST['url'] != "" ) { if ( substr( $_POST['url'], 0, 1 ) != "/" ) { $message .= __( 'Error: URL must start with /', '404-redirected' ) . "
"; } } else { $message .= __( 'Error: URL is a required field.', '404-redirected' ) . "
"; } if ( $_POST['dest'] == "EXTERNAL" ) { if ( $_POST['external'] == "" ) { $message .= __( 'Error: You selected external URL but did not enter a URL.', '404-redirected' ) . "
"; } else { if ( substr( $_POST['external'], 0, 7 ) != "http://" && substr( $_POST['external'], 0, 8 ) != "https://" && substr( $_POST['external'], 0, 6 ) != "ftp://" ) { $message .= __( 'Error: External URL\'s must start with http://, https://, or ftp://', '404-redirected' ) . "
"; } } } if ( $message == "" ) { $type = ""; $dest = ""; if ( $_POST['dest'] == "EXTERNAL" ) { $type = WBZ404_EXTERNAL; $dest = esc_sql( $_POST['external'] ); } else { $info = explode( "|", $_POST['dest'] ); if ( count( $info )==2 ) { $dest = $info[0]; if ( $info[1] == "POST" ) { $type = WBZ404_POST; } else if ( $info[1] == "CAT" ) { $type = WBZ404_CAT; } else if ( $info[1] == "TAG" ) { $type = WBZ404_TAG; } } } if ( $type != "" && $dest != "" ) { wbz404_setupRedirect( esc_sql( $_POST['url'] ), WBZ404_MANUAL, $type, $dest, esc_sql( $_POST['code'] ), 0 ); $_POST['url'] = ""; $_POST['code'] = ""; $_POST['external'] = ""; $_POST['dest'] = ""; } else { $message .= __( 'Error: Data not formatted properly.', '404-redirected' ) . "
"; } } return $message; } function wbz404_editRedirectData() { global $wpdb; $message = ""; if ( $_POST['url'] != "" ) { if ( substr( $_POST['url'], 0, 1 ) != "/" ) { $message .= __( 'Error: URL must start with /', '404-redirected' ) . "
"; } } else { $message .= __( 'Error: URL is a required field.', '404-redirected' ) . "
"; } if ( $_POST['dest'] == "EXTERNAL" ) { if ( $_POST['external'] == "" ) { $message .= __( 'Error: You selected external URL but did not enter a URL.', '404-redirected' ) . "
"; } else { if ( substr( $_POST['external'], 0, 7 ) != "http://" && substr( $_POST['external'], 0, 8 ) != "https://" && substr( $_POST['external'], 0, 6 ) != "ftp://" ) { $message .= __( 'Error: External URL\'s must start with http://, https://, or ftp://', '404-redirected' ) . "
"; } } } if ( $message == "" ) { $type = ""; $dest = ""; if ( $_POST['dest'] === "" . WBZ404_EXTERNAL ) { $type = WBZ404_EXTERNAL; $dest = esc_sql( $_POST['external'] ); } else { $info = explode( "|", $_POST['dest'] ); if ( count( $info )==2 ) { $dest = $info[0]; if ( $info[1] == WBZ404_POST ) { $type = WBZ404_POST; } else if ( $info[1] == WBZ404_CAT ) { $type = WBZ404_CAT; } else if ( $info[1] == WBZ404_TAG ) { $type = WBZ404_TAG; } } } if ( $type != "" && $dest != "" ) { $wpdb->update( $wpdb->prefix . "wbz404_redirects", array( 'url' => esc_url( $_POST['url'] ), 'status' => WBZ404_MANUAL, 'type' => esc_html( $type ), 'final_dest' => esc_html( $dest ), 'code' => esc_html( $_POST['code'] ) ), array ( 'id' => absint( $_POST['id'] ) ), array( '%s', '%d', '%d', '%s', '%d' ), array( '%d' ) ); $_POST['url'] = ""; $_POST['code'] = ""; $_POST['external'] = ""; $_POST['dest'] = ""; } else { $message .= __( 'Error: Data not formatted properly.', '404-redirected' ) . "
"; } } return $message; } function wbz404_setTrash( $id, $trash ) { global $wpdb; $result = false; if ( preg_match( '/[0-9]+/', $id ) ) { $result = $wpdb->update( $wpdb->prefix . "wbz404_redirects", array( 'disabled' => esc_html( $trash ) ), array ( 'id' => absint( $id ) ), array ( '%d' ), array ( '%d' ) ); } if ( $result == false ) { $message = __( 'Error: Unknown Database Error!', '404-redirected' ); } return $message; } function wbz404_setIgnore( $id, $newstatus ) { global $wpdb; $result = false; if ( preg_match( '/[0-9]+/', $id ) ) { $result = $wpdb->update( $wpdb->prefix . "wbz404_redirects", array( 'status' => esc_html( $newstatus ) ), array ( 'id' => absint( $id ) ), array ( '%d' ), array ( '%d' ) ); } if ( $result == false ) { $message = __( 'Error: Unknown Database Error!', '404-redirected' ); } return $message; } function wbz404_adminHeader( $sub = 'list', $message = '' ) { if ( $sub == "options" ) { $header = " " . __( 'Options', '404-redirected' ); } else if ( $sub == "logs" ) { $header = " " . __( 'Logs', '404-redirected' ); } else if ( $sub == "stats" ) { $header = " " . __( 'Stats', '404-redirected' ); } else if ( $sub == "edit" ) { $header = ": " . __( 'Edit Redirect', '404-redirected' ); } else if ( $sub == "redirects" ) { $header = ""; } else { $header = ""; } echo "
"; if ( $sub == "options" ) { echo "
"; } else { echo "
"; } echo "

" . __( '404 Redirected', '404-redirected' ) . esc_html( $header ) . "

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

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

"; } echo __( 'by', '404-redirected' ) . " Redirectioner
"; echo __( 'Version', '404-redirected' ) . ": " . WBZ404_VERSION . " | "; echo "" . __( 'Plugin Home Page', '404-redirected' ) . " | "; echo "
"; $class=""; if ( $sub == "redirects" ) { $class="nav-tab-active"; } echo "" . __( 'Page Redirects', '404-redirected' ) . ""; $class=""; if ( $sub == "captured" ) { $class="nav-tab-active"; } echo "" . __( 'Captured 404 URLs', '404-redirected' ) . ""; $class=""; if ( $sub == "logs" ) { $class="nav-tab-active"; } echo "" . __( 'Logs', '404-redirected' ) . ""; $class=""; if ( $sub == "stats" ) { $class="nav-tab-active"; } echo "" . __( 'Stats', '404-redirected' ) . ""; $class=""; if ( $sub == "tools" ) { $class="nav-tab-active"; } echo "" . __( 'Tools', '404-redirected' ) . ""; $class=""; if ( $sub == "options" ) { $class="nav-tab-active"; } echo "" . __( 'Options', '404-redirected' ) . ""; echo "
"; } function wbz404_adminFooter() { echo "
"; echo "
"; echo "Credits:
"; echo "" . __( '404 Redirected' ) . " "; echo __( 'is released under the GNU GPL version 2 License.', '404-redirected' ); echo "
"; echo "
"; } function wbz404_emptyTrash( $sub ) { $tableOptions = wbz404_getTableOptions(); $rows = wbz404_getRecords( $sub, $tableOptions, 0 ); foreach ( $rows as $row ) { wbz404_cleanRedirect( $row['id'] ); } } function wbz404_bulkProcess( $action, $ids ) { $message = ""; if ( $action == "bulkignore" || $action == "bulkcaptured" ) { if ( $action == "bulkignore" ) { $status = WBZ404_IGNORED; } else { $status = WBZ404_CAPTURED; } $count = 0; foreach ( $ids as $id ) { $s = wbz404_setIgnore( $id, $status ); if ( $s == "" ) { $count++; } } if ( $action == "bulkignore" ) { $message = $count . " " . __( 'URLs marked as ignored.', '404-redirected' ); } else { $message = $count . " " . __( 'URLs marked as captured.', '404-redirected'); } } else { $count = 0; foreach ( $ids as $id ) { $s = wbz404_setTrash( $id, 1 ); if ( $s == "" ) { $count ++; } } $message = $count . " " . __( 'URLs moved to trash', '404-redirected' ); } return $message; } function wbz404_adminPage() { $sub=""; $message=""; //Handle Post Actions if ( isset( $_POST['action'] ) ) { $action = $_POST['action']; } else { $action = ""; } if ( $action == "updateOptions" ) { if ( check_admin_referer( 'wbz404UpdateOptions' ) && is_admin() ) { $sub="wbz404_options"; $message=wbz404_updateOptions(); if ( $message == "" ) { $message = __( 'Options Saved Successfully!', '404-redirected' ); } else { $message .= __( 'Some options were not saved successfully.', '404-redirected' ); } } } else if ( $action == "addRedirect" ) { if ( check_admin_referer( 'wbz404addRedirect' ) && is_admin() ) { $message=wbz404_addAdminRedirect(); if ( $message == "" ) { $message = __( 'New Redirect Added Successfully!', '404-redirected' ); } else { $message .= __( 'Error: unable to add new redirect successfully.', '404-redirected' ); } } } else if ( $action == "emptyRedirectTrash" ) { if ( check_admin_referer( 'wbz404_emptyRedirectTrash' ) && is_admin() ) { wbz404_emptyTrash( 'redirects' ); $message = __( 'All trashed URLs have been deleted!', '404-redirected' ); } } else if ( $action == "emptyCapturedTrash" ) { if ( check_admin_referer( 'wbz404_emptyCapturedTrash' ) && is_admin() ) { wbz404_emptyTrash( 'captured' ); $message = __( 'All trashed URLs have been deleted!', '404-redirected' ); } } else if ( $action == "bulkignore" || $action == "bulkcaptured" || $action == "bulktrash" ) { if ( check_admin_referer( 'wbz404_capturedBulkAction' ) && is_admin() ) { $message = wbz404_bulkProcess( $action, $_POST['idnum'] ); } } else if ( $action == "purgeRedirects" ) { if ( check_admin_referer( 'wbz404_purgeRedirects' ) && is_admin() ) { $message = wbz404_purgeRedirects(); } } // Handle Trash Functionality if ( isset( $_GET['trash'] ) ) { if ( check_admin_referer( 'wbz404_trashRedirect' ) && is_admin() ) { $trash = ""; if ( $_GET['trash'] == 0 ) { $trash = 0; } else if ( $_GET['trash'] == 1 ) { $trash = 1; } if ( $trash == 0 || $trash == 1 ) { $message = wbz404_setTrash( $_GET['id'], $trash ); if ( $message == "" ) { if ( $trash == 1 ) { $message = __( 'Redirect moved to trash successfully!', '404-redirected' ); } else { $message = __( 'Redirect restored from trash successfully!', '404-redirected' ); } } else { if ( $trash == 1 ) { $message = __( 'Error: Unable to move redirect to trash.', '404-redirected' ); } else { $message = __( 'Error: Unable to move redirect from trash.', '404-redirected' ); } } } } } //Handle Delete Functionality if ( isset( $_GET['remove'] ) && $_GET['remove'] == 1 ) { if ( check_admin_referer( 'wbz404_removeRedirect' ) && is_admin() ) { if ( preg_match( '/[0-9]+/', $_GET['id'] ) ) { $sanitize_id = absint( $_GET['id'] ); wbz404_cleanRedirect( $sanitize_id ); $message = __( 'Redirect Removed Successfully!', '404-redirected' ); } } } //Handle Ignore Functionality if ( isset( $_GET['ignore'] ) ) { if ( check_admin_referer( 'wbz404_ignore404' ) && is_admin() ) { if ( $_GET['ignore'] == 0 || $_GET['ignore'] == 1 ) { if ( preg_match( '/[0-9]+/', $_GET['id'] ) ) { if ( $_GET['ignore'] == 1 ) { $newstatus = WBZ404_IGNORED; } else { $newstatus = WBZ404_CAPTURED; } $message = wbz404_setIgnore( $_GET['id'], $newstatus ); if ( $message == "" ) { if ( $newstatus == WBZ404_CAPTURED ) { $message = __( 'Removed 404 URL from ignored list successfully!', '404-redirected' ); } else { $message = __( '404 URL marked as ignored successfully!', '404-redirected' ); } } else { if ( $newstatus == WBZ404_CAPTURED ) { $message = __( 'Error: unable to remove URL from ignored list', '404-redirected' ); } else { $message = __( 'Error: unable to mark URL as ignored', '404-redirected' ); } } } } } } //Handle edit posts if ( isset( $_POST['action'] ) && $_POST['action'] == "editRedirect" ) { if ( isset( $_POST['id'] ) && preg_match( '/[0-9]+/', $_POST['id'] ) ) { if ( check_admin_referer( 'wbz404editRedirect' ) && is_admin() ) { $message = wbz404_editRedirectData(); if ( $message == "" ) { $message .= __( 'Redirect Information Updated Successfully!', '404-redirected' ); $sub = "redirects"; } else { $message .= __( 'Error: Unable to update redirect data.', '404-redirected' ); } } } } // Deal With Page Tabs if ( $sub == "" ) { if ( isset( $_GET['subpage'] ) ) { $sub = strtolower( $_GET['subpage'] ); } else { $sub = ""; } } if ( $sub == "wbz404_options" ) { $sub = "options"; } else if ( $sub == "wbz404_captured" ) { $sub = "captured"; } else if ( $sub == "wbz404_logs" ) { $sub = "logs"; } else if ( $sub == "wbz404_edit" ) { $sub = "edit"; } else if ( $sub == "wbz404_stats" ) { $sub = "stats"; } else if ( $sub == "wbz404_tools" ) { $sub = "tools"; } else { $sub = "redirects"; } wbz404_adminHeader( $sub, $message ); if ( $sub == "redirects" ) { wbz404_adminRedirectsPage(); } else if ( $sub == "captured" ) { wbz404_adminCapturedPage(); } else if ( $sub == "options" ) { wbz404_adminOptionsPage(); } else if ( $sub == "logs" ) { wbz404_adminLogsPage(); } else if ( $sub == "edit" ) { wbz404_adminEditPage(); } else if ( $sub == "stats" ) { wbz404_adminStatsPage(); } else if ( $sub == "tools" ) { wbz404_adminToolsPage(); } else { echo __( 'Invalid Sub Page ID', '404-redirected' ); } wbz404_adminFooter(); } function wbz404_getStatsCount( $query='' ) { global $wpdb; $results = 0; if ( $query != '' ) { $row = $wpdb->get_col( $query ); $results = $row[0]; } return $results; } function wbz404_adminStatsPage() { global $wpdb; $sub = "stats"; $redirects = $wpdb->prefix . "wbz404_redirects"; $logs = $wpdb->prefix . "wbz404_logs"; $hr = "style=\"border: 0px; margin-bottom: 0px; padding-bottom: 4px; border-bottom: 1px dotted #DEDEDE;\""; echo "
"; echo "
"; echo "
"; $query = "select count(id) from $redirects where disabled = 0 and code = 301 and status = " . WBZ404_AUTO; $auto301 = wbz404_getStatsCount( $query ); $query = "select count(id) from $redirects where disabled = 0 and code = 302 and status = " . WBZ404_AUTO; $auto302 = wbz404_getStatsCount( $query ); $query = "select count(id) from $redirects where disabled = 0 and code = 301 and status = " . WBZ404_MANUAL; $manual301 = wbz404_getStatsCount( $query ); $query = "select count(id) from $redirects where disabled = 0 and code = 302 and status = " . WBZ404_MANUAL; $manual302 = wbz404_getStatsCount( $query ); $query = "select count(id) from $redirects where disabled = 1 and (status = " . WBZ404_AUTO . " or status = " . WBZ404_MANUAL . ")"; $trashed = wbz404_getStatsCount( $query ); $total = $auto301 + $auto302 + $manual301 + $manual302 + $trashed; $content = ""; $content .= "

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

"; $content .= "

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

"; wbz404_postbox( "wbz404-redirectStats", __( 'Redirects', '404-redirected' ), $content ); $query = "select count(id) from $redirects where disabled = 0 and status = " . WBZ404_CAPTURED; $captured = wbz404_getStatsCount( $query ); $query = "select count(id) from $redirects where disabled = 0 and status = " . WBZ404_IGNORED; $ignored = wbz404_getStatsCount( $query ); $query = "select count(id) from $redirects where disabled = 1 and (status = " . WBZ404_CAPTURED . " or status = " . WBZ404_IGNORED . ")"; $trashed = wbz404_getStatsCount( $query ); $total = $captured + $ignored + $trashed; $content = ""; $content .= "

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

"; $content .= "

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

"; wbz404_postbox( "wbz404-capturedStats", __( 'Captured URLs', '404-redirected' ), $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 = '404'"; $disp404 = wbz404_getStatsCount( $query ); $query = "select count(distinct redirect_id) from $logs where timestamp >= $ts and action = '404'"; $distinct404 = wbz404_getStatsCount( $query ); $query = "select count(distinct remote_host) from $logs where timestamp >= $ts and action = '404'"; $visitors404 = wbz404_getStatsCount( $query ); $query = "select count(distinct referrer) from $logs where timestamp >= $ts and action = '404'"; $refer404 = wbz404_getStatsCount( $query ); $query = "select count(id) from $logs where timestamp >= $ts and action != '404'"; $redirected = wbz404_getStatsCount( $query ); $query = "select count(distinct redirect_id) from $logs where timestamp >= $ts and action != '404'"; $distinctredirected = wbz404_getStatsCount( $query ); $query = "select count(distinct remote_host) from $logs where timestamp >= $ts and action != '404'"; $distinctvisitors = wbz404_getStatsCount( $query ); $query = "select count(distinct referrer) from $logs where timestamp >= $ts and action != '404'"; $distinctrefer = wbz404_getStatsCount( $query ); $content = ""; $content .= "

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

"; wbz404_postbox( "wbz404-stats" . $x, __( $title ), $content ); } echo "
"; echo "
"; echo "
"; } function wbz404_adminLogsPage() { global $wpdb; $sub = "logs"; $tableOptions = wbz404_getTableOptions(); // Sanitizing unchecked table options foreach ( $tableOptions as $key => $value ) { $key = wp_kses_post( $key ); $tableOptions[$key] = wp_kses_post( $value ); } $url = "?page=wbz404_redirected&subpage=wbz404_logs"; $redirects = array(); $query = "select id, url from " . $wpdb->prefix . "wbz404_redirects order by url"; $rows = $wpdb->get_results( $query, ARRAY_A ); foreach ( $rows as $row ) { $redirects[$row['id']]['id'] = absint( $row['id'] ); $redirects[$row['id']]['url'] = esc_url( $row['url'] ); } 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 "
"; wbz404_drawPaginationLinks( $sub, $tableOptions ); echo "
"; echo ""; echo ""; wbz404_buildTableColumns( $sub, $tableOptions, $columns ); echo ""; echo ""; wbz404_buildTableColumns( $sub, $tableOptions, $columns ); echo ""; echo ""; $rows = wbz404_getLogRecords( $tableOptions ); $displayed = 0; $y=1; $timezone = get_option( 'timezone_string' ); if ( '' == $timezone ) { $timezone = 'UTC'; } date_default_timezone_set( $timezone ); foreach ( $rows as $row ) { $class = ""; if ( $y == 0 ) { $class=" class=\"alternate\""; $y++; } else { $y=0; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $displayed++; } if ( $displayed == 0 ) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo ""; echo "
" . esc_html( $redirects[$row['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-redirected' ); } else { echo __( 'Redirect to', '404-redirected' ) . " "; echo "" . esc_html( $row['action'] ) . ""; } echo "" . esc_html( date( 'Y/m/d h:i:s A', $row['timestamp'] ) ) . "
" . __( 'No Results To Display', '404-redirected' ) . "
"; echo "
"; wbz404_drawPaginationLinks( $sub, $tableOptions ); echo "
"; } function wbz404_adminOptionsPage() { $options = wbz404_getOptions(); $url = "?page=wbz404_redirected"; //General Options $action = "wbz404UpdateOptions"; $link = wp_nonce_url( $url, $action ); echo "
"; echo "
"; echo "
"; echo "
"; echo ""; $content = "

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

"; $content .= "

" . __( 'Default redirect type', '404-redirected' ) . ": "; $content .= "

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

" . __( 'Collect incoming 404 URLs', '404-redirected' ) . ":

"; $content .= "

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

"; $content .= "

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

"; $content .= "

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

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

" . __( 'Remove redirect upon matching permalink', '404-redirected' ) . ":
"; $content .= __( '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-redirected' ) . "

"; wbz404_postbox( "wbz404-generaloptions", __( 'General Settings', '404-redirected' ), $content ); // Suggested Alternatives Options $selected = ""; if ( $options['display_suggest'] == '1' ) { $selected = " checked"; } $content = "

" . __( 'Turn on 404 suggestions', '404-redirected' ) . ":
"; $content .= __( 'Activates the 404 page suggestions function. Only works if the code is in your 404 page template.', '404-redirected' ) . "

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

" . __( 'Allow category suggestions', '404-redirected' ) . ":
"; $selected = ""; if ( $options['suggest_tags'] == '1' ) { $selected = " checked"; } $content .= "

" . __( 'Allow tag suggestions', '404-redirected' ) . ":
"; $content .= "

" . __( 'Minimum score of suggestions to display', '404-redirected' ) . ":

" ; $content .= "

" . __( 'Maximum number of suggestions to display', '404-redirected' ) . ":

"; $content .= "

" . __( 'Page suggestions title', '404-redirected' ) . ":

"; $content .= "

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

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

" . __( 'Display if no suggestion results', '404-redirected' ) . ": "; $content .= ""; wbz404_postbox( "wbz404-suggestoptions", __( '404 Page Suggestions', '404-redirected' ), $content ); $selected = ""; if ( $options['auto_redirects'] == '1' ) { $selected = " checked"; } $content = "

" . __( 'Create automatic redirects', '404-redirected' ) . ":
"; $content .= __( 'Automatically creates redirects based on best possible suggested page.', '404-redirected' ) . "

"; $content .= "

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

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

" . __( 'Create automatic redirects for categories', '404-redirected' ) . ":

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

" . __( 'Create automatic redirects for tags', '404-redirected' ) . ":

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

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

"; $content .= "

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

"; wbz404_postbox( "wbz404-autooptions", __( 'Automatic Redirects', '404-redirected' ), $content ); echo ""; echo "
"; echo "
"; echo "
"; echo "
"; } function wbz404_adminRedirectsPage() { global $wpdb; $sub = "redirects"; $options = wbz404_getOptions(); $tableOptions = wbz404_getTableOptions(); // Sanitizing unchecked table options foreach ( $tableOptions as $key => $value ) { $key = wp_kses_post( $key ); $tableOptions[$key] = wp_kses_post( $value ); } wbz404_drawFilters( $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 "
"; wbz404_drawPaginationLinks( $sub, $tableOptions ); if ( $tableOptions['filter'] == '-1' ) { echo "
"; $eturl = "?page=wbz404_redirected&filter=-1"; $trashaction = "wbz404_emptyRedirectTrash"; $eturl = wp_nonce_url( $eturl, $trashaction ); echo "
"; echo ""; echo ""; echo "
"; echo "
"; } echo "
"; echo ""; echo ""; wbz404_buildTableColumns( $sub, $tableOptions, $columns ); echo ""; echo ""; wbz404_buildTableColumns( $sub, $tableOptions, $columns ); echo ""; echo ""; $rows = wbz404_getRecords( $sub, $tableOptions ); $displayed = 0; $y=1; foreach ( $rows as $row ) { $displayed++; $status = ""; if ( $row['status'] == WBZ404_MANUAL ) { $status = __( 'Manual', '404-redirected' ); } else if ( $row['status'] == WBZ404_AUTO ) { $status = __( 'Automatic', '404-redirected' ); } $type = ""; $dest = ""; $link = ""; $title = __( 'Visit', '404-redirected' ) . " "; if ( $row['type'] == WBZ404_EXTERNAL ) { $type = __( 'External', '404-redirected' ); $dest = $row['final_dest']; $link = $row['final_dest']; $title .= $row['final_dest']; } else if ( $row['type'] == WBZ404_POST ) { $type = __( 'Post/Page', '404-redirected' ); $permalink = wbz404_permalinkInfo( $row['final_dest'] . "|POST", 0 ); $dest = $permalink['title']; $link = $permalink['link']; $title .= $permalink['title']; } else if ( $row['type'] == WBZ404_CAT ) { $type = __( 'Category', '404-redirected' ); $permalink = wbz404_permalinkInfo( $row['final_dest'] . "|CAT", 0 ); $dest = $permalink['title']; $link = $permalink['link']; $title .= __( 'Category:', '404-redirected' ) . " " . $permalink['title']; } else if ( $row['type'] == WBZ404_TAG ) { $type = __( 'Tag', '404-redirected' ); $permalink = wbz404_permalinkInfo( $row['final_dest'] . "|TAG", 0 ); $dest = $permalink['title']; $link = $permalink['link']; $title .= __( 'Tag:', '404-redirected' ) . " " . $permalink['title']; } $hits = $row['hits']; $last_used = wbz404_getRedirectLastUsed( $row['id'] ); if ( $last_used != 0 ) { $last = date( "Y/m/d h:i:s A", $last_used ); } else { $last = __( 'Never Used', '404-redirected' ); } $editlink = "?page=wbz404_redirected&subpage=wbz404_edit&id=" . absint( $row['id'] ); $logslink = "?page=wbz404_redirected&subpage=wbz404_logs&id=" . absint( $row['id'] ); $trashlink = "?page=wbz404_redirected&id=" . absint( $row['id'] ); $deletelink = "?page=wbz404_redirected&remove=1&id=" . absint( $row['id'] ); if ( $tableOptions['filter'] == -1 ) { $trashlink .= "&trash=0"; $trashtitle = __( 'Restore', '404-redirected' ); } else { $trashlink .= "&trash=1"; $trashtitle = __( 'Trash', '404-redirected' ); } 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 = "wbz404_trashRedirect"; $trashlink = wp_nonce_url( $trashlink, $trashaction ); if ( $tableOptions['filter'] == -1 ) { $deleteaction = "wbz404_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-redirected' ) . ""; } 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-redirected' ) . "
"; echo "
"; wbz404_drawPaginationLinks( $sub, $tableOptions ); echo "
"; if ( $tableOptions['filter'] != -1 ) { echo "

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

"; $url = "?page=wbz404_redirected"; if ( !( $tableOptions['orderby'] == "url" && $tableOptions['order'] == "ASC" ) ) { $url .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; } if ( $tableOptions['filter'] != 0 ) { $url .= "&filter=" . $tableOptions['filter']; } $action = "wbz404addRedirect"; $link = wp_nonce_url( $url, $action ); echo "
"; echo ""; if ( isset( $_POST['url'] ) ) { $postedURL = $_POST['url']; } else { $postedURL = ""; } echo " (" . __( 'Required', '404-redirected' ) . ")
"; echo "
"; if ( isset( $_POST['external'] ) ) { $postedExternal = $_POST['external']; } else { $postedExternal = ""; } echo " (" . __( 'Required if Redirect to is set to External Page', '404-redirected' ) . ")
"; echo "
"; echo ""; echo "
"; } } function wbz404_adminCapturedPage() { $sub = "captured"; $options = wbz404_getOptions(); $tableOptions = wbz404_getTableOptions(); wbz404_drawFilters( $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 "
"; wbz404_drawPaginationLinks( $sub, $tableOptions ); if ( $tableOptions['filter'] == '-1' ) { echo "
"; $eturl = "?page=wbz404_redirected&subpage=wbz404_captured&filter=-1"; $trashaction = "wbz404_emptyCapturedTrash"; $eturl = wp_nonce_url( $eturl, $trashaction ); echo "
"; echo ""; echo ""; echo "
"; echo "
"; } else { echo "
"; $url = "?page=wbz404_redirected&subpage=wbz404_captured"; if ( $tableOptions['filter'] != 0 ) { $url .= "&filter=" . $tableOptions['filter']; } if ( !( $tableOptions['orderby'] == "url" && $tableOptions['order'] == "ASC" ) ) { $url .= "&orderby=" . $tableOptions['orderby'] . "&order=" . $tableOptions['order']; } $bulkaction = "wbz404_capturedBulkAction"; $url = wp_nonce_url( $url, $bulkaction ); echo "
"; echo ""; echo ""; echo "
"; } echo "
"; echo ""; echo ""; wbz404_buildTableColumns( $sub, $tableOptions, $columns ); echo ""; echo ""; wbz404_buildTableColumns( $sub, $tableOptions, $columns ); echo ""; echo ""; $rows = wbz404_getRecords( $sub, $tableOptions ); $displayed = 0; $y=1; foreach ( $rows as $row ) { $displayed++; $hits = $row['hits']; $last_used = wbz404_getRedirectLastUsed( $row['id'] ); if ( $last_used != 0 ) { $last = date( "Y/m/d h:i:s A", $last_used ); } else { $last = __( 'Never Used', '404-redirected' ); } $editlink = "?page=wbz404_redirected&subpage=wbz404_edit&id=" . $row['id']; $logslink = "?page=wbz404_redirected&subpage=wbz404_logs&id=" . $row['id']; $trashlink = "?page=wbz404_redirected&&subpage=wbz404_captured&id=" . $row['id']; $ignorelink = "?page=wbz404_redirected&&subpage=wbz404_captured&id=" . $row['id']; $deletelink = "?page=wbz404_redirected&subpage=wbz404_captured&remove=1&id=" . $row['id']; if ( $tableOptions['filter'] == -1 ) { $trashlink .= "&trash=0"; $trashtitle = __( 'Restore', '404-redirected' ); } else { $trashlink .= "&trash=1"; $trashtitle = __( 'Trash', '404-redirected' ); } if ( $tableOptions['filter'] == WBZ404_IGNORED ) { $ignorelink .= "&ignore=0"; $ignoretitle = __( 'Remove Ignore Status', '404-redirected' ); } else { $ignorelink .= "&ignore=1"; $ignoretitle = __( 'Ignore 404 Error', '404-redirected' ); } 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 = "wbz404_trashRedirect"; $trashlink = wp_nonce_url( $trashlink, $trashaction ); if ( $tableOptions['filter'] == -1 ) { $deleteaction = "wbz404_removeRedirect"; $deletelink = wp_nonce_url( $deletelink, $deleteaction ); } $ignoreaction = "wbz404_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-redirected' ) . ""; echo " | "; } echo "" . esc_html( $trashtitle ) . ""; echo " | "; echo "" . __( 'View Logs', '404-redirected' ) . ""; if ( $tableOptions['filter'] != -1 ) { echo " | "; echo "" . esc_html( $ignoretitle ) . ""; } else { echo " | "; echo "" . __( 'Delete Permanently', '404-redirected' ) . ""; } 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-redirected' ) . "
"; echo "
"; if ( $tableOptions['filter'] != '-1' ) { echo ""; } wbz404_drawPaginationLinks( $sub, $tableOptions ); echo "
"; } function wbz404_adminEditPage() { global $wpdb; $sub = "edit"; if ( ! ( isset( $_GET['id'] ) && preg_match( '/[0-9]+/', $_GET['id'] ) ) ) { if ( ! ( isset( $_POST['id'] ) && preg_match( '/[0-9]+/', $_POST['id'] ) ) ) { echo "Error: Invalid ID Number"; return; } else { $recnum = absint( $_POST['id'] ); } } else { $recnum = absint( $_GET['id'] ); } $query = "select id, url, type, final_dest, code from " . $wpdb->prefix . "wbz404_redirects where 1 "; $query .= "and id = " . esc_sql( $recnum ); $redirect = $wpdb->get_row( $query, ARRAY_A ); if ( ! ( $redirect == null ) ) { echo "

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

"; $url = "?page=wbz404_redirected&subpage=wbz404_edit"; $action = "wbz404editRedirect"; $link = wp_nonce_url( $url, $action ); echo "
"; echo ""; echo ""; echo " (" . __( 'Required', '404-redirected' ) . ")
"; echo "
"; $final = ""; if ( $redirect['type'] == WBZ404_EXTERNAL ) { $final = $redirect['final_dest']; } echo " (" . __( 'Required if Redirect to is set to External Page', '404-redirected' ) . ")
"; echo "
"; echo ""; echo "
"; } else { echo "Error: Invalid ID Number!"; } } function wbz404_AdminToolsPage() { $sub = "tools"; $hr = "style=\"border: 0px; margin-bottom: 0px; padding-bottom: 4px; border-bottom: 1px dotted #DEDEDE;\""; $url = "?page=wbz404_redirected&subpage=wbz404_tools"; $action = "wbz404_purgeRedirects"; $link = wp_nonce_url( $url, $action ); echo "
"; echo "
"; echo "
"; $content = ""; $content .= "
"; $content .= ""; $content .= "

"; $content .= "

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

    "; $content .= "
  • "; $content .= "
  • "; $content .= "
  • "; $content .= "
  • "; $content .= "
"; $content .= "" . __( 'Sanity Check', '404-redirected' ) . "
"; $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-redirected' ) . "
"; $content .= "
"; $content .= " " . __( 'I understand the above statement, I know what I am doing... blah blah blah. Just delete the records!', '404-redirected' ) . "
"; $content .= "
"; $content .= ""; $content .= "

"; $content .= "
"; wbz404_postbox( "wbz404-purgeRedirects", __( 'Purge Options', '404-redirected' ), $content ); echo "
"; } function wbz404_purgeRedirects() { global $wpdb; $message = ""; $redirects = $wpdb->prefix . "wbz404_redirects"; $logs = $wpdb->prefix . "wbz404_logs"; $sanity = $_POST['sanity']; if ( $sanity == "1" ) { if ( isset( $_POST['types'] ) && '' != $_POST['types'] ) { $type = $_POST['types']; if ( is_array( $type ) ) { $types = ""; $x=0; for ( $i=0; $i < count( $type ); $i++ ) { if ( preg_match( '/[0-9]+/', $type[$i] ) ) { if ( $x > 0 ) { $types .= ","; } $types .= $type[$i]; $x++; } } if ( $types != "" ) { $purge = $_POST['purgetype']; if ( $purge == "logs" || $purge == "redirects" ) { $query = "delete from " . esc_html( $logs ) . " where redirect_id in (select id from " . esc_html( $redirects ) . " where status in (" . esc_html( $types ) . "))"; $logcount = $wpdb->query( $query ); $message = $logcount . " " . __( 'Log entries were purged.', '404-redirected' ); if ( $purge == "redirects" ) { $query = "delete from " . esc_html( $redirects ) . " where status in (" . esc_html( $types ) . ")"; $count = $wpdb->query( $query ); $message .= "
"; $message .= $count . " " . __( 'Redirect entries were purged.', '404-redirected' ); } } else { $message = __( 'Error: An invalid purge type was selected. Exiting.', '404-redirected' ); } } else { $message = __( 'Error: No valid redirect types were selected. Exiting.', '404-redirected' ); } } else { $message = __( 'An unknown error has occurred.', '404-redirected' ); } } else { $message = __( 'Error: No redirect types were selected. No purges will be done.', '404-redirected' ); } } else { $message = __( 'Error: You didn\'t check the I understand checkbox. No purging of records for you!', '404-redirected' ); } return $message; }