groups = $groups;
$this->current_group = $current_group;
//Set parent defaults
parent::__construct( array(
'singular' => 'item', //singular name of the listed records
'plural' => 'items', //plural name of the listed records
'ajax' => false //does this table support ajax?
) );
}
function get_columns(){
$columns = array(
'cb' => '', //Render a checkbox instead of text
'type' => __( 'Type', 'redirection' ),
'url' => __( 'URL', 'redirection' ),
'hits' => __( 'Hits', 'redirection' ),
'last_access' => __( 'Last Access', 'redirection' ),
);
return $columns;
}
function column_type( $item ) {
return esc_html( $item->type() );
}
function column_last_access( $item ) {
if ( $item->last_access == 0 )
return '—';
return date_i18n( get_option( 'date_format' ), $item->last_access );
}
function column_hits( $item ) {
return esc_html( number_format_i18n( $item->last_count, 0 ) );
}
function column_url( $item ) {
$actions = array(
'edit' => sprintf( ''.__( 'Edit', 'redirection' ).'', 'red_redirect_edit', wp_create_nonce( 'red-edit_'.$item->get_id() ), $item->get_id() ),
'delete' => sprintf( ''.__( 'Delete', 'redirection' ).'', 'delete', $item->get_id() ),
);
$before = $after = '';
if ( $item->is_enabled() )
$actions['disable'] = sprintf( ''.__( 'Disable', 'redirection' ).'', 'disable', $item->get_id() );
else {
$actions['enable'] = sprintf( ''.__( 'Enable', 'redirection' ).'', 'enable', $item->get_id() );
$before = '';
$after = '';
}
$title = $item->url;
if ( $item->title )
$title = $item->title;
return sprintf( '%1$s %2$s', $before.''.esc_html( $title ).''.$after, $this->row_actions( $actions ) );
}
function column_cb($item){
return sprintf(
'',
/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
/*$2%s*/ $item->id //The value of the checkbox should be the record's id
);
}
function get_row( $item ) {
ob_start();
$this->single_row( $item );
$output = ob_get_contents();
ob_end_clean();
return $output;
}
function get_sortable_columns() {
$sortable_columns = array(
'url' => array( 'url', false),
);
return $sortable_columns;
}
function get_bulk_actions() {
$actions = array(
'delete' => __( 'Delete', 'redirection' ),
'enable' => __( 'Enable', 'redirection' ),
'disable' => __( 'Disable', 'redirection' ),
'reset' => __( 'Reset Hits', 'redirection' ),
);
return $actions;
}
function process_bulk_action() {
if ( !isset( $_POST['item'] ) )
return;
if ( in_array( $this->current_action(), array( 'reset', 'enable', 'disable', 'delete' ) ) ) {
$redirections = array();
foreach( (array)$_POST['item'] AS $id ) {
$redirect = Red_Item::get_by_id( intval( $id ) );
if ( $redirect )
$redirections[] = $redirect;
}
array_map( array( &$this, 'process_action_items' ), $redirections );
Red_Module::flush( $this->current_group->module_id );
}
}
function process_action_items( $item ) {
if ( $this->current_action() == 'reset' )
$item->reset();
elseif ( $this->current_action() == 'enable' )
$item->enable();
elseif ( $this->current_action() == 'disable' )
$item->disable();
elseif ( $this->current_action() == 'delete' )
$item->delete();
}
function extra_tablenav( $which ) {
if ( $which == 'bottom' )
return;
?>
'post-query-submit' ) ); ?>
get_option( 'per_page', 'option' ) ) {
$per_page = intval( get_user_meta( $current_user->ID, $screen->get_option( 'per_page', 'option' ), true ) );
if ( $per_page === 0 )
$per_page = 25;
}
$columns = $this->get_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, array(), $sortable );
// Process any stuff
$this->process_bulk_action();
$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
$order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
if ( !in_array( $orderby, array_keys( $sortable ) ) )
$orderby = 'id';
if ( !in_array( $order, array( 'asc', 'desc' ) ) )
$order = 'desc';
$where = array();
if ( isset( $_GET['s'] ) )
$where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( $_GET['s'] ).'%' );
if ( isset( $_REQUEST['id'] ) )
$where[] = $wpdb->prepare( "group_id=%d", intval( $_REQUEST['id'] ) );
$where_cond = "";
if ( count( $where ) > 0 )
$where_cond = " WHERE ".implode( ' AND ', $where );
$table = $wpdb->prefix.'redirection_items';
$rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
$this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
$this->items = array();
foreach ( (array)$rows AS $row ) {
$this->items[] = new Red_Item( $row );
}
$this->set_pagination_args( array(
'total_items' => $this->total_items,
'per_page' => $per_page,
'total_pages' => ceil( $this->total_items / $per_page )
) );
}
}
class Redirection_Group_Table extends WP_List_Table {
private $modules;
private $current_module;
function __construct( $modules, $current_module ) {
$this->modules = $modules;
$this->current_module = $current_module;
//Set parent defaults
parent::__construct( array(
'singular' => 'item', //singular name of the listed records
'plural' => 'items', //plural name of the listed records
'ajax' => false //does this table support ajax?
) );
}
function get_columns(){
$columns = array(
'cb' => '', //Render a checkbox instead of text
'name' => __( 'Name', 'redirection' ),
'redirects' => __( 'Redirects', 'redirection' ),
);
return $columns;
}
function column_name( $item ) {
$actions = array(
'edit' => sprintf( ''.__( 'Edit', 'redirection' ).'', 'red_group_edit', wp_create_nonce( 'red-edit_'.$item->get_id() ), $item->get_id() ),
'delete' => sprintf( ''.__( 'Delete', 'redirection' ).'', 'delete', $item->get_id() ),
'view' => ''.__( 'View Redirects', 'redirection' ).'',
);
$after = $before = '';
if ( $item->is_disabled() ) {
$before = '';
$after = '';
}
return sprintf( '%1$s %2$s', $before.esc_html( $item->get_name() ).$after, $this->row_actions( $actions ) );
}
function column_redirects( $item ) {
return esc_html( $item->get_item_count() );
}
function column_cb($item){
return sprintf(
'',
/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
/*$2%s*/ $item->id //The value of the checkbox should be the record's id
);
}
function get_sortable_columns() {
$sortable_columns = array(
'name' => array( 'name', false ),
);
return $sortable_columns;
}
function get_bulk_actions() {
$actions = array(
'delete' => __( 'Delete', 'redirection' ),
);
return $actions;
}
function process_bulk_action() {
if ( !isset( $_POST['item'] ) )
return;
if ( in_array( $this->current_action(), array( 'delete' ) ) ) {
$groups = array();
foreach( (array)$_POST['item'] AS $id ) {
$redirect = Red_Group::get( intval( $id ) );
if ( $redirect )
$groups[] = $redirect;
}
array_map( array( &$this, 'delete_item' ), $groups );
}
}
function delete_item( $item ) {
$item->delete();
}
function extra_tablenav( $which ) {
if ( $which == 'bottom' )
return;
?>
'post-query-submit' ) ); ?>
ID, $screen->get_option( 'per_page', 'option' ), true );
$per_page = $per_page ? $per_page : 25;
$columns = $this->get_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, array(), $sortable );
// Process any stuff
$this->process_bulk_action();
$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
$order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
if ( !in_array( $orderby, array_keys( $sortable ) ) )
$orderby = $wpdb->prefix.'redirection_groups.name';
if ( !in_array( $order, array( 'asc', 'desc' ) ) )
$order = 'desc';
$where = array();
if ( isset( $_GET['s'] ) )
$where[] = $wpdb->prepare( 'name LIKE %s', '%'.like_escape( $_GET['s'] ).'%' );
if ( isset( $_REQUEST['id'] ) )
$where[] = $wpdb->prepare( "module_id=%d", intval( $_REQUEST['id'] ) );
$where_cond = "";
if ( count( $where ) > 0 )
$where_cond = " WHERE ".implode( ' AND ', $where );
$table = $wpdb->prefix.'redirection_groups';
$rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
$this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
$this->items = array();
foreach ( (array)$rows AS $row ) {
$this->items[] = new Red_Group( $row );
}
$this->set_pagination_args( array(
'total_items' => $this->total_items,
'per_page' => $per_page,
'total_pages' => ceil( $this->total_items / $per_page )
) );
}
}
class Redirection_Log_Table extends WP_List_Table {
const REFERRER_MAX = 120;
const TARGET_MAX = 80;
private $lookup;
function __construct( $options ) {
$this->lookup = $options['lookup'];
//Set parent defaults
parent::__construct( array(
'singular' => 'item', //singular name of the listed records
'plural' => 'items', //plural name of the listed records
'ajax' => false //does this table support ajax?
) );
}
function column_created( $item ) {
$actions = array();
if ( $item->sent_to == '' ) {
$actions['add'] = ''.__( 'Add redirect', 'redirection' ).'';
}
return sprintf( '%1$s %2$s', date_i18n( get_option( 'date_format' ), $item->created ).' '.gmdate( get_option( 'time_format' ), $item->created ), $this->row_actions( $actions ) );
}
function column_ip( $item ) {
return ''.esc_html( $item->ip ).'';
}
function column_url( $item ) {
$actions = array(
'target' => esc_html( substr( $item->sent_to, 0, self::TARGET_MAX ) ),
);
return sprintf( '%1$s %2$s', ''.esc_html( $item->show_url( $item->url ) ).'', $this->row_actions( $actions ) );
}
function column_referrer( $item ) {
$actions = array(
'agent' => esc_html( substr( $item->agent, 0, self::REFERRER_MAX ) ),
);
return sprintf( '%1$s %2$s', ''.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'', $this->row_actions( $actions ) );
}
function column_cb($item){
return sprintf(
'',
/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
/*$2%s*/ $item->id //The value of the checkbox should be the record's id
);
}
function get_columns(){
$columns = array(
'cb' => '', //Render a checkbox instead of text
'created' => __( 'Date', 'redirection' ),
'url' => __( 'Source URL', 'redirection' ),
'referrer' => __( 'Referrer', 'redirection' ),
'ip' => __( 'IP', 'redirection' ),
);
return $columns;
}
function get_sortable_columns() {
$sortable_columns = array(
'created' => array( 'id', true ),
'url' => array( 'url', false),
'referrer' => array( 'referrer', false ),
'ip' => array( 'item_id', false ),
);
return $sortable_columns;
}
function get_bulk_actions() {
$actions = array(
'delete' => __( 'Delete', 'redirection' )
);
return $actions;
}
function process_bulk_action() {
if ( 'delete' === $this->current_action() ) {
foreach( $_POST['item'] AS $id ) {
RE_Log::delete( intval( $id ) );
}
}
}
function prepare_items( $type = '', $id = 0 ) {
global $wpdb, $current_user;
$screen = get_current_screen();
$per_page = get_user_meta( $current_user->ID, $screen->get_option( 'per_page', 'option' ), true );
$per_page = $per_page ? $per_page : 25;
$columns = $this->get_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, array(), $sortable );
// Process any stuff
$this->process_bulk_action();
$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
$order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
if ( !in_array( $orderby, array_keys( $sortable ) ) )
$orderby = 'id';
if ( !in_array( $order, array( 'asc', 'desc' ) ) )
$order = 'desc';
$where = array();
if ( isset( $_GET['s'] ) )
$where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( $_GET['s'] ).'%' );
$where_cond = "";
if ( count( $where ) > 0 )
$where_cond = " WHERE ".implode( ' AND ', $where );
$table = $wpdb->prefix.'redirection_logs';
$rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
$total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
$this->items = array();
foreach ( (array)$rows AS $row ) {
$this->items[] = new RE_Log( $row );
}
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page )
) );
}
}
class Redirection_404_Table extends WP_List_Table {
private $lookup;
function __construct( $options ) {
$this->lookup = $options['lookup'];
//Set parent defaults
parent::__construct( array(
'singular' => 'item', //singular name of the listed records
'plural' => 'items', //plural name of the listed records
'ajax' => false //does this table support ajax?
) );
}
function column_created( $item ) {
$actions['add'] = ''.__( 'Add redirect', 'redirection' ).'';
return sprintf( '%1$s%2$s', date_i18n( get_option( 'date_format' ), $item->created ).'
'.gmdate( get_option( 'time_format' ), $item->created ), $this->row_actions( $actions ) );
}
function column_ip( $item ) {
$actions['add'] = ''.__( 'Show only this IP', 'redirection' ).'';
return sprintf( '%1$s %2$s', ''.long2ip( $item->ip ).'', $this->row_actions( $actions ) );
}
function column_url( $item ) {
return ''.esc_html( $item->show_url( $item->url ) ).'';
}
function column_referrer( $item ) {
$actions = array(
'agent' => esc_html( $item->agent ),
);
return sprintf( '%1$s %2$s', ''.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'', $this->row_actions( $actions ) );
}
function column_cb($item){
return sprintf(
'',
/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
/*$2%s*/ $item->id //The value of the checkbox should be the record's id
);
}
function get_columns(){
$columns = array(
'cb' => '', //Render a checkbox instead of text
'created' => __( 'Date', 'redirection' ),
'url' => __( 'Source URL', 'redirection' ),
'referrer' => __( 'Referrer', 'redirection' ),
'ip' => __( 'IP', 'redirection' ),
);
return $columns;
}
function get_sortable_columns() {
$sortable_columns = array(
'created' => array( 'id', true ),
'url' => array( 'url', false),
'referrer' => array( 'referrer', false ),
);
return $sortable_columns;
}
function get_bulk_actions() {
$actions = array(
'delete' => __( 'Delete', 'redirection' )
);
return $actions;
}
function process_bulk_action() {
if ( 'delete' === $this->current_action() ) {
foreach( $_POST['item'] AS $id ) {
RE_404::delete( intval( $id ) );
}
}
}
function prepare_items( $restrict_by_ip = false ) {
global $wpdb, $current_user;
$screen = get_current_screen();
$per_page = get_user_meta( $current_user->ID, $screen->get_option( 'per_page', 'option' ), true );
$per_page = $per_page ? $per_page : 25;
$columns = $this->get_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, array(), $sortable );
// Process any stuff
$this->process_bulk_action();
$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
$order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
if ( !in_array( $orderby, array_keys( $sortable ) ) )
$orderby = 'id';
if ( !in_array( $order, array( 'asc', 'desc' ) ) )
$order = 'desc';
$where = array();
if ( isset( $_GET['s'] ) )
$where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( $_GET['s'] ).'%' );
if ( $restrict_by_ip !== false )
$where[] = $wpdb->prepare( 'ip=INET_ATON(%s)', $restrict_by_ip );
$where_cond = "";
if ( count( $where ) > 0 )
$where_cond = " WHERE ".implode( ' AND ', $where );
$table = $wpdb->prefix.'redirection_404';
$rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
$total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
$this->items = array();
foreach ( (array)$rows AS $row ) {
$this->items[] = new RE_Log( $row );
}
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page )
) );
}
}
class Redirection_Module_Table extends WP_List_Table {
private $token = false;
function __construct( $token ) {
$this->token = $token;
//Set parent defaults
parent::__construct( array(
'singular' => 'item', //singular name of the listed records
'plural' => 'items', //plural name of the listed records
'ajax' => false //does this table support ajax?
) );
}
function get_columns() {
$columns = array(
'moduletype' => __( 'Type', 'redirection' ),
'name' => __( 'Name', 'redirection' ),
'groups' => __( 'Groups', 'redirection' ),
'hits' => __( 'Hits', 'redirection' ),
);
return $columns;
}
function column_groups( $item ) {
return esc_html( $item->groups() );
}
function column_hits( $item ) {
return esc_html( number_format_i18n( $item->hits(), 0 ) );
}
function column_moduletype( $item ) {
return esc_html( $item->get_type_string() );
}
function column_name( $item ) {
$actions['edit'] = sprintf( ''.__( 'Edit', 'redirection' ).'', 'red_module_edit', wp_create_nonce( 'red_edit-'.$item->get_id() ), $item->get_id() );
if ( $this->token ) {
if ( $item->get_type() === 'wp' ) {
$actions['rss'] = sprintf( 'RSS', '?page=redirection.php&token='.$this->token.'&sub=rss&module='.intval( $item->get_id() ) );
}
$actions['htaccess'] = sprintf( '.htaccess', '?page=redirection.php&token='.$this->token.'&sub=apache&module='.intval( $item->get_id() ) );
$actions['csv'] = sprintf( 'CSV', '?page=redirection.php&token='.$this->token.'&sub=csv&module='.intval( $item->get_id() ) );
}
return ''.esc_html( $item->get_name() ).''.$this->row_actions( $actions );
}
function prepare_items( $type = '', $id = 0 ) {
global $wpdb;
$table = $wpdb->prefix.'redirection_modules';
$rows = $wpdb->get_results( "SELECT * FROM {$table}" );
$this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" );
$columns = $this->get_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, array(), $sortable );
$this->items = array();
foreach ( (array)$rows AS $row ) {
$this->items[] = Red_Module::new_item( $row );
}
$this->set_pagination_args( array(
'total_items' => $this->total_items,
'per_page' => 100,
'total_pages' => ceil( $this->total_items / 100 )
) );
}
}