Plugin Directory

Changeset 543833


Ignore:
Timestamp:
05/13/2012 05:32:31 PM (14 years ago)
Author:
johnny5
Message:
  • Remove 404 module and move 404 logs into a seperate option
  • Add Danish translation, thanks to Rasmus Himmelstrup
Location:
redirection/trunk
Files:
2 added
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • redirection/trunk/models/database.php

    r537877 r543833  
    1717
    1818class RE_Database {
     19    function get_charset() {
     20        global $wpdb;
     21
     22        $charset_collate = '';
     23        if ( ! empty($wpdb->charset) )
     24            $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
     25
     26        if ( ! empty($wpdb->collate) )
     27            $charset_collate .= " COLLATE $wpdb->collate";
     28
     29        return $charset_collate;
     30    }
     31
    1932    function install() {
    2033        global $wpdb;
     34
     35        $charset_collate = $this->get_charset();
    2136
    2237        $create = array(
     
    4156                KEY `group_idpos` (`group_id`,`position`),
    4257              KEY `group` (`group_id`)
    43             )",
     58            ) $charset_collate",
    4459
    4560            "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_groups`(
     
    5368                KEY `module_id` (`module_id`),
    5469            KEY `status` (`status`)
    55             )",
     70            ) $charset_collate",
    5671
    5772            "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_logs`(
     
    7287              KEY `group_id` (`group_id`),
    7388              KEY `module_id` (`module_id`)
    74             )",
     89            ) $charset_collate",
    7590
    7691            "CREATE TABLE `{$wpdb->prefix}redirection_modules`(
     
    8297              KEY `name` (`name`),
    8398              KEY `type` (`type`)
    84             )",
     99            ) $charset_collate",
     100
     101            "CREATE TABLE `{$wpdb->prefix}redirection_404` (
     102              `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
     103              `created` datetime NOT NULL,
     104              `url` varchar(255) NOT NULL DEFAULT '',
     105              `agent` varchar(255) DEFAULT NULL,
     106              `referrer` varchar(255) DEFAULT NULL,
     107              `ip` int(10) unsigned NOT NULL,
     108              PRIMARY KEY (`id`),
     109              KEY `created` (`created`),
     110              KEY `url` (`url`),
     111              KEY `ip` (`ip`),
     112              KEY `referrer` (`referrer`)
     113            ) $charset_collate;"
    85114        );
    86115
     
    132161            if ( version_compare( $current, '2.2' ) == -1 )
    133162                $this->upgrade_to_220();
     163
     164            if ( version_compare( $current, '2.3.1' ) == -1 )
     165                $this->upgrade_to_231();
     166
     167            $success = true;
    134168        }
    135169
     
    139173        $wpdb->hide_errors();
    140174        return $success;
     175    }
     176
     177    function upgrade_to_231() {
     178        global $wpdb;
     179
     180        $charset_collate = $this->get_charset();
     181
     182        $wpdb->query( "DELETE FROM {$wpdb->prefix}redirection_modules WHERE type='404'" );
     183        $wpdb->query( "UPDATE {$wpdb->prefix}redirection_groups SET module_id=1 WHERE module_id=3" );
     184
     185        $wpdb->query( "CREATE TABLE `{$wpdb->prefix}redirection_404` (
     186              `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
     187              `created` datetime NOT NULL,
     188              `url` varchar(255) NOT NULL DEFAULT '',
     189              `agent` varchar(255) DEFAULT NULL,
     190              `referrer` varchar(255) DEFAULT NULL,
     191              `ip` int(10) unsigned NOT NULL,
     192              PRIMARY KEY (`id`),
     193              KEY `created` (`created`),
     194              KEY `url` (`url`),
     195              KEY `ip` (`ip`,`id`)
     196              KEY `referrer` (`referrer`)
     197            ) $charset_collate;" );
    141198    }
    142199
     
    197254        $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_groups;" );
    198255        $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_modules;" );
     256        $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_404;" );
    199257
    200258        delete_option( 'redirection_lookup' );
  • redirection/trunk/models/log.php

    r540923 r543833  
    4747    }
    4848
    49     function create ($url, $target, $agent, $ip, $referrer, $extra = array() ) {
     49    function create( $url, $target, $agent, $ip, $referrer, $extra = array()) {
    5050        global $wpdb, $redirection;
    5151
    5252        $insert = array(
    53             'url'            => urldecode( $url ),
    54             'sent_to'        => $target,
    55             'created'        => current_time( 'mysql' ),
    56             'agent'          => $agent,
    57             'ip'             => $ip,
    58             'referrer'       => $referrer,
    59             'redirection_id' => isset( $extra['redirect_id'] ) ? $extra['redirect_id'] : 0,
    60             'module_id'      => isset( $extra['module_id'] ) ? $extra['module_id'] : 0,
    61             'group_id'       => isset( $extra['group_id'] ) ? $extra['group_id'] : 0,
     53            'url'     => urldecode( $url ),
     54            'created' => current_time( 'mysql' ),
     55            'ip'      => $ip,
    6256        );
    6357
     58        if ( !empty( $agent ) )
     59            $insert['agent'] = $agent;
     60
     61        if ( !empty( $referrer ) )
     62            $insert['referrer'] = $referrer;
     63
     64        $insert['sent_to']        = $target;
     65        $insert['redirection_id'] = isset( $extra['redirect_id'] ) ? $extra['redirect_id'] : 0;
     66        $insert['module_id']      = isset( $extra['module_id'] ) ? $extra['module_id'] : 0;
     67        $insert['group_id']       = isset( $extra['group_id'] ) ? $extra['group_id'] : 0;
     68
    6469        $wpdb->insert( $wpdb->prefix.'redirection_logs', $insert );
    65 
    66         // Expire old entries
    67         $options = $redirection->get_options();
    68         if ( $options['expire'] != 0 )
    69             $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_logs WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY)", $options['expire'] ) );
    7070    }
    7171
     
    117117}
    118118
     119class RE_404 {
     120    var $id;
     121    var $created;
     122    var $url;
     123    var $agent;
     124    var $referrer;
     125    var $ip;
     126
     127    function RE_404( $values ) {
     128        foreach ( $values AS $key => $value ) {
     129            $this->$key = $value;
     130         }
     131
     132        $this->created = mysql2date ('U', $this->created);
     133    }
     134
     135    function get_by_id( $id ) {
     136        global $wpdb;
     137
     138        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}redirection_404 WHERE id=%d", $id ) );
     139        if ( $row )
     140            return new RE_404( $row );
     141        return false;
     142    }
     143
     144    function create( $url, $agent, $ip, $referrer ) {
     145        global $wpdb, $redirection;
     146
     147        $insert = array(
     148            'url'     => urldecode( $url ),
     149            'created' => current_time( 'mysql' ),
     150            'ip'      => ip2long( $ip ),
     151        );
     152
     153        if ( !empty( $agent ) )
     154            $insert['agent'] = $agent;
     155
     156        if ( !empty( $referrer ) )
     157            $insert['referrer'] = $referrer;
     158
     159        $wpdb->insert( $wpdb->prefix.'redirection_404', $insert );
     160    }
     161
     162    function delete( $id ) {
     163        global $wpdb;
     164
     165        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_404 WHERE id=%d", $id ) );
     166    }
     167
     168    function delete_all() {
     169        global $wpdb;
     170
     171        $where = array();
     172        if ( isset( $_POST['s'] ) )
     173            $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$_POST['s'].'%' );
     174
     175        $where_cond = "";
     176        if ( count( $where ) > 0 )
     177            $where_cond = " WHERE ".implode( ' AND ', $where );
     178
     179        $wpdb->query( "DELETE FROM {$wpdb->prefix}redirection_404 ".$where_cond );
     180    }
     181}
     182
  • redirection/trunk/models/module.php

    r537877 r543833  
    160160            'apache' => __( 'Apache', 'redirection' ),
    161161            'wp'     => __( 'WordPress', 'redirection' ),
    162             '404'    => __( '404 Errors', 'redirection' ),
    163162         );
    164163    }
     
    168167            'apache' => array( 'Apache_Module',    'apache.php' ),
    169168            'wp'     => array( 'WordPress_Module', 'wordpress.php' ),
    170             '404'    => array( 'Error404_Module',  '404.php' )
    171169         );
    172170
  • redirection/trunk/models/pager.php

    r540923 r543833  
    55
    66class Redirection_Log_Table extends WP_List_Table {
    7     function __construct(){
    8         global $status, $page;
    9 
     7    function __construct() {
    108        //Set parent defaults
    119        parent::__construct( array(
     
    9492
    9593        $per_page     = 25;
    96         $hidden       = array();
    9794        $columns      = $this->get_columns();
    9895        $sortable     = $this->get_sortable_columns();
    9996        $current_page = $this->get_pagenum();
    10097
    101         $this->_column_headers = array( $columns, $hidden, $sortable );
     98        $this->_column_headers = array( $columns, array(), $sortable );
    10299
    103100        // Process any stuff
     
    105102
    106103        $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'happened_at';
    107         $order   = ( ! empty($_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
     104        $order   = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
    108105
    109106        if ( !in_array( $orderby, array_keys( $this->get_sortable_columns() ) ) )
     
    122119
    123120        if ( isset( $_POST['s'] ) )
    124             $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$_POST['s'].'%' );
     121            $where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( stripslashes( $_POST['s'] ) ).'%' );
    125122
    126123        $where_cond = "";
     
    128125            $where_cond = " WHERE ".implode( ' AND ', $where );
    129126
    130         $rows        = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}redirection_logs FORCE INDEX(created) ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", $this->get_pagenum() - 1, $per_page ) );
    131         $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_logs".$where_cond );
    132 
    133         $data = array ();
     127        $table = $wpdb->prefix.'redirection_logs';
     128
     129        $rows        = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", $this->get_pagenum() - 1, $per_page ) );
     130        $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
     131
     132        $this->items = array();
    134133        foreach ( (array)$rows AS $row ) {
    135             $data[] = new RE_Log( $row );
    136         }
    137 
    138         $this->items = $data;
     134            $this->items[] = new RE_Log( $row );
     135        }
    139136
    140137        $this->set_pagination_args( array(
     
    146143}
    147144
     145class Redirection_404_Table extends WP_List_Table {
     146    function __construct() {
     147        //Set parent defaults
     148        parent::__construct( array(
     149            'singular'  => 'item',     //singular name of the listed records
     150            'plural'    => 'items',    //plural name of the listed records
     151            'ajax'      => false        //does this table support ajax?
     152        ) );
     153    }
     154
     155    function column_created( $item ) {
     156        $actions['add'] = '<a href="'.esc_url( $item->url ).'" class="add-log">'.__( 'Add redirect', 'redirection' ).'</a>';
     157
     158        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 ) );
     159    }
     160
     161    function column_ip( $item ) {
     162        $actions['add'] = '<a href="'.admin_url( 'tools.php?page=redirection.php&sub=404s&ip='.esc_attr( long2ip( $item->ip ) ) ).'">'.__( 'Show only this IP', 'redirection' ).'</a>';
     163
     164        return sprintf( '%1$s %2$s', '<a href="http://urbangiraffe.com/map/?ip='.esc_attr( long2ip( $item->ip ) ).'&amp;from=redirection">'.long2ip( $item->ip ).'</a>', $this->row_actions( $actions ) );
     165    }
     166
     167    function column_url( $item ) {
     168        return '<a href="'.esc_url( $item->url ).'">'.esc_html( $item->show_url( $item->url ) ).'</a>';
     169    }
     170
     171    function column_referrer( $item ) {
     172        $actions = array(
     173            'agent' => esc_html( $item->agent ),
     174        );
     175
     176        return sprintf( '%1$s %2$s', '<a href="'.esc_url( $item->referrer ).'">'.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'</a>', $this->row_actions( $actions ) );
     177    }
     178
     179    function column_cb($item){
     180        return sprintf(
     181            '<input type="checkbox" name="%1$s[]" value="%2$s" />',
     182            /*$1%s*/ $this->_args['singular'],  //Let's simply repurpose the table's singular label ("movie")
     183            /*$2%s*/ $item->id                //The value of the checkbox should be the record's id
     184        );
     185    }
     186
     187    function get_columns(){
     188        $columns = array(
     189            'cb'       => '<input type="checkbox" />', //Render a checkbox instead of text
     190            'created'  => __( 'Date', 'redirection' ),
     191            'url'      => __( 'Source URL', 'redirection' ),
     192            'referrer' => __( 'Referrer', 'redirection' ),
     193            'ip'       => __( 'IP', 'redirection' ),
     194        );
     195        return $columns;
     196    }
     197
     198    function get_sortable_columns() {
     199        $sortable_columns = array(
     200            'created'  => array( 'id', true ),
     201            'url'      => array( 'url', false),
     202            'referrer' => array( 'referrer', false ),
     203        );
     204        return $sortable_columns;
     205    }
     206
     207    function get_bulk_actions() {
     208        $actions = array(
     209            'delete' => __( 'Delete', 'redirection' )
     210        );
     211        return $actions;
     212    }
     213
     214    function process_bulk_action() {
     215        if ( 'delete' === $this->current_action() ) {
     216            foreach( $_POST['item'] AS $id ) {
     217                RE_404::delete( intval( $id ) );
     218            }
     219        }
     220    }
     221
     222    function prepare_items( $restrict_by_ip = false ) {
     223        global $wpdb;
     224
     225        $per_page     = 25;
     226        $columns      = $this->get_columns();
     227        $sortable     = $this->get_sortable_columns();
     228        $current_page = $this->get_pagenum();
     229
     230        $this->_column_headers = array( $columns, array(), $sortable );
     231
     232        // Process any stuff
     233        $this->process_bulk_action();
     234
     235        $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
     236        $order   = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
     237
     238        if ( !in_array( $orderby, array_keys( $sortable ) ) )
     239            $orderby = 'id';
     240
     241        if ( !in_array( $order, array( 'asc', 'desc' ) ) )
     242            $order = 'desc';
     243
     244        $where = array();
     245        if ( isset( $_POST['s'] ) )
     246            $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$_POST['s'].'%' );
     247
     248        if ( $restrict_by_ip !== false )
     249            $where[] = $wpdb->prepare( 'ip=INET_ATON(%s)', $restrict_by_ip );
     250
     251        $where_cond = "";
     252        if ( count( $where ) > 0 )
     253            $where_cond = " WHERE ".implode( ' AND ', $where );
     254
     255        $table = $wpdb->prefix.'redirection_404';
     256
     257        $rows        = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", $this->get_pagenum() - 1, $per_page ) );
     258        $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
     259
     260        $this->items = array();
     261        foreach ( (array)$rows AS $row ) {
     262            $this->items[] = new RE_Log( $row );
     263        }
     264
     265        $this->set_pagination_args( array(
     266            'total_items' => $total_items,
     267            'per_page'    => $per_page,
     268            'total_pages' => ceil( $total_items / $per_page )
     269        ) );
     270    }
     271}
    148272
    149273class RE_Pager
  • redirection/trunk/readme.txt

    r540923 r543833  
    5656* Belarusian, thanks to Alexander Ovsov
    5757* Czech, thanks to Martin Jurica
     58* Danish, thanks to Rasmus Himmelstrup
    5859
    5960== Installation ==
     
    8990
    9091== Changelog ==
     92
     93= 2.3.0 =
     94* Remove 404 module and move 404 logs into a seperate option
     95* Add Danish translation, thanks to Rasmus Himmelstrup
    9196
    9297= 2.2.14 =
  • redirection/trunk/redirection.php

    r540976 r543833  
    44Plugin URI: http://urbangiraffe.com/plugins/redirection/
    55Description: Manage all your 301 redirects and monitor 404 errors
    6 Version: 2.2.14
     6Version: 2.3.1
    77Author: John Godley
    88Author URI: http://urbangiraffe.com
     
    2929include dirname( __FILE__ ).'/models/monitor.php';
    3030include dirname( __FILE__ ).'/modules/wordpress.php';
    31 include dirname( __FILE__ ).'/modules/404.php';
    32 
    33 define( 'REDIRECTION_VERSION', '2.2' );
     31
     32define( 'REDIRECTION_VERSION', '2.3.1' );
    3433
    3534if ( class_exists( 'Redirection' ) )
     
    6261            $this->wp = new WordPress_Module();
    6362            $this->wp->start();
    64 
    65             $this->error = new Error404_Module();
    66             $this->error->start();
    6763        }
    6864
    6965        $this->monitor = new Red_Monitor( $this->get_options() );
     66        $this->add_action ('template_redirect' );
    7067    }
    7168
     
    113110            'type'         => 1,
    114111            'progress'     => '<img src="'.plugin_dir_url( __FILE__ ).'/images/progress.gif" alt="loading" width="50" height="16"/>',
    115           'are_you_sure' => __( 'Are you sure?', 'redirection' ),
     112            'are_you_sure' => __( 'Are you sure?', 'redirection' ),
    116113            'none_select'  => __( 'No items have been selected', 'redirection' )
    117114        ) );
     
    119116
    120117    function admin_menu() {
    121     add_management_page( __( "Redirection", 'redirection' ), __( "Redirection", 'redirection' ), "administrator", basename( __FILE__ ), array( &$this, "admin_screen" ) );
     118        add_management_page( __( "Redirection", 'redirection' ), __( "Redirection", 'redirection' ), "administrator", basename( __FILE__ ), array( &$this, "admin_screen" ) );
     119    }
     120
     121    function expire_logs() {
     122        global $wpdb;
     123
     124        // Expire old entries
     125        $options = $redirection->get_options();
     126        if ( $options['expire'] != 0 ) {
     127            $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_logs WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY) LIMIT 1000", $options['expire'] ) );
     128            $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_404 WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY) LIMIT 1000", $options['expire'] ) );
     129        }
    122130    }
    123131
    124132    function admin_screen() {
    125       $this->update();
     133        $this->update();
     134        $this->expire_logs();
    126135
    127136        // Decide what to do
     
    133142            if ( $_GET['sub'] == 'log' )
    134143                return $this->admin_screen_log();
    135           elseif ( $_GET['sub'] == 'options' )
    136             return $this->admin_screen_options();
    137           elseif ( $_GET['sub'] == 'process' )
    138             return $this->admin_screen_process();
    139           elseif ( $_GET['sub'] == 'groups' )
     144            elseif ( $_GET['sub'] == '404s' )
     145                return $this->admin_screen_404();
     146            elseif ( $_GET['sub'] == 'options' )
     147                return $this->admin_screen_options();
     148            elseif ( $_GET['sub'] == 'process' )
     149                return $this->admin_screen_process();
     150            elseif ( $_GET['sub'] == 'groups' )
    140151                return $this->admin_groups( isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0 );
    141152            elseif ( $_GET['sub'] == 'modules' )
    142153                return $this->admin_screen_modules();
    143154            elseif ( $_GET['sub'] == 'support' )
    144                 return $this->render_admin('support');
     155                return $this->render_admin('support', array( 'options' => $this->get_options() ) );
    145156        }
    146157
     
    149160
    150161    function admin_screen_modules() {
    151         if ( isset( $_POST['create'] ) && check_admin_referer( 'redirection-module_add' ) ) {
    152             $data = stripslashes_deep( $_POST );
    153 
    154             if ( ( $module = Red_Module::create( $data ) ) ) {
    155                 $moduleid = 0;
    156                 if ( isset( $_POST['module'] ) )
    157                     $moduleid = intval( $_POST['module'] );
    158 
    159                 $this->render_message( __( 'Your module was successfully created', 'redirection' ) );
    160                 Red_Module::flush( $moduleid );
    161             }
    162             else
    163                 $this->render_error( __( 'Your module was not created - did you provide a name?', 'redirection' ) );
    164         }
    165 
    166         $options = $this->get_options();
    167         $this->render_admin( 'module_list', array( 'modules' => Red_Module::get_all(), 'module_types' => Red_Module::get_types(), 'token' => $options['token'] ) );
     162        $options = $this->get_options();
     163        $this->render_admin( 'module_list', array( 'options' => $this->get_options(), 'modules' => Red_Module::get_all(), 'module_types' => Red_Module::get_types(), 'token' => $options['token'] ) );
    168164    }
    169165
     
    279275
    280276        $options = $this->get_options();
    281         $this->render_admin( 'log', array( 'table' => $table, 'lookup' => $options['lookup'] ) );
     277        $this->render_admin( 'log', array( 'options' => $options, 'table' => $table, 'lookup' => $options['lookup'] ) );
     278    }
     279
     280    function admin_screen_404() {
     281        include dirname( __FILE__ ).'/models/pager.php';
     282
     283        if ( isset( $_POST['deleteall'] ) && check_admin_referer( 'redirection-process_logs' ) ) {
     284            RE_404::delete_all();
     285            $this->render_message( __( 'Your logs have been deleted', 'redirection' ) );
     286        }
     287
     288        $table = new Redirection_404_Table();
     289        $table->prepare_items( isset( $_GET['ip'] ) ? $_GET['ip'] : false );
     290
     291        $options = $this->get_options();
     292        $this->render_admin( 'log', array( 'options' => $options, 'table' => $table, 'lookup' => $options['lookup'] ) );
    282293    }
    283294
     
    300311        $items = Red_Group::get_all( $module, $pager );
    301312
    302         $this->render_admin( 'group_list', array( 'groups' => $items, 'pager' => $pager, 'modules' => Red_Module::get_for_select(), 'module' => Red_Module::get( $module ) ) );
     313        $this->render_admin( 'group_list', array( 'options' => $this->get_options(), 'groups' => $items, 'pager' => $pager, 'modules' => Red_Module::get_for_select(), 'module' => Red_Module::get( $module ) ) );
    303314    }
    304315
     
    312323        $items = Red_Item::get_by_group( $group, $pager );
    313324
    314     $this->render_admin( 'item_list', array( 'items' => $items, 'pager' => $pager, 'group' => Red_Group::get( $group ), 'groups' => Red_Group::get_for_select(), 'date_format' => get_option( 'date_format' ) ) );
     325        $this->render_admin( 'item_list', array( 'options' => $this->get_options(), 'items' => $items, 'pager' => $pager, 'group' => Red_Group::get( $group ), 'groups' => Red_Group::get_for_select(), 'date_format' => get_option( 'date_format' ) ) );
    315326    }
    316327
     
    328339            $readme = file_get_contents( dirname( __FILE__ ).'/readme.txt' );
    329340
    330             $start = strpos( $readme, __( 'Redirection is available in' ) );
     341            $start = strpos( $readme, 'Redirection is available in' );
    331342            $end   = strpos( $readme, '==', $start );
    332343            if ( $start !== false && $end !== false ) {
     
    341352        return $locales;
    342353    }
     354
     355    /**
     356     * Matches 404s
     357     * @return [type] [description]
     358     */
     359    function template_redirect() {
     360        if ( is_404() ) {
     361            $options = $this->get_options();
     362
     363            if ( $options['log_404s'] ) {
     364                $log = RE_404::create( red_get_url(), red_user_agent(), red_ip(), red_http_referrer() );
     365            }
     366        }
     367    }
     368}
     369
     370function red_get_url() {
     371    if ( isset( $_SERVER['REQUEST_URI'] ) )
     372        return $_SERVER['REQUEST_URI'];
     373    return '';
     374}
     375
     376function red_user_agent() {
     377    if ( isset( $_SERVER['HTTP_USER_AGENT'] ) )
     378        return $_SERVER['HTTP_USER_AGENT'];
     379    return false;
     380}
     381
     382function red_http_referrer() {
     383    if ( isset( $_SERVER['HTTP_REFERER'] ) )
     384        return $_SERVER['HTTP_REFERER'];
     385    return false;
     386}
     387
     388function red_ip() {
     389    if ( isset( $_SERVER['REMOTE_ADDR'] ) )
     390      return $_SERVER['REMOTE_ADDR'];
     391    elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
     392      return $_SERVER['HTTP_X_FORWARDED_FOR'];
     393    return '';
    343394}
    344395
  • redirection/trunk/view/admin/group_list.php

    r539832 r543833  
    66    <h2><?php _e( 'Groups for module', 'redirection' ); ?>: <a href="edit.php?page=redirection.php&amp;sub=modules"><?php echo esc_html( $module->name  ) ?></a></h2>
    77
    8     <?php $this->render_admin( 'submenu'  ); ?>
     8    <?php $this->render_admin( 'submenu', array( 'options' => $options ) ); ?>
    99
    1010    <div id="pager" class="pager">
  • redirection/trunk/view/admin/item_list.php

    r539832 r543833  
    88
    99        <?php if ( $group ) : ?>
    10         <a href="<?php echo $this->base (); ?>?page=redirection.php&amp;sub=groups&amp;id=<?php echo $group->module_id ?>">
     10        <a href="<?php echo admin_url( 'tools.php?page=redirection.php' ); ?>&amp;sub=groups&amp;id=<?php echo $group->module_id ?>">
    1111            <?php echo esc_html( $group->name ); ?>
    1212        </a>
     
    1414    </h2>
    1515
    16     <?php $this->render_admin( 'submenu' ); ?>
     16    <?php $this->render_admin( 'submenu', array( 'options' => $options ) ); ?>
    1717
    1818    <div id="pager" class="pager">
  • redirection/trunk/view/admin/log.php

    r540923 r543833  
    66    <h2><?php _e ('Redirection Log', 'redirection'); ?></h2>
    77
    8     <?php $this->render_admin( 'submenu' ); ?>
     8    <?php $this->render_admin( 'submenu', array( 'options' => $options ) ); ?>
    99
    1010    <form method="POST" action="">
  • redirection/trunk/view/admin/module_list.php

    r539832 r543833  
    66    <h2><?php _e( 'Modules', 'redirection' ); ?></h2>
    77
    8     <?php $this->render_admin( 'submenu'  ); ?>
     8    <?php $this->render_admin( 'submenu', array( 'options' => $options ) ); ?>
    99
    1010    <?php if ( count( $modules ) > 0 ) : ?>
     
    3131</div>
    3232
    33 <div class="wrap">
    34     <h2><?php _e( 'Add Module', 'redirection' ); ?></h2>
    35     <p><?php _e( 'A module is a controlling element that determines how redirections are handled.  Elements in a WordPress module are handled by WordPress, elements in an Apache module are handled by <code>.htaccess</code>, and elements in a 404 module affect how 404 errors are logged.', 'redirection' ); ?></p>
    36 
    37     <form action="" method="post" accept-charset="utf-8">
    38         <?php wp_nonce_field( 'redirection-module_add' ); ?>
    39 
    40         <table class="edit" summary="modules">
    41             <tr>
    42                 <th width="100"><?php _e( 'Name', 'redirection' ); ?>:</th>
    43                 <td><input size="40" type="text" name="name" value=""/></td>
    44             </tr>
    45             <tr>
    46                 <th width="100"><?php _e( 'Type', 'redirection' ); ?>:</th>
    47                 <td>
    48                     <select name="type">
    49                         <?php echo $this->select( $module_types ); ?>
    50                     </select>
    51                 </td>
    52             </tr>
    53             <tr>
    54                 <td></td>
    55                 <td><input class="button-primary" type="submit" name="create" value="<?php _e( 'Create', 'redirection' ); ?>"/></td>
    56             </tr>
    57         </table>
    58     </form>
    59 </div>
    60 
    6133<script type="text/javascript">
    6234jQuery(document ).ready( function() {
  • redirection/trunk/view/admin/options.php

    r540976 r543833  
    55
    66  <h2><?php _e( 'Options', 'redirection' ) ?></h2>
    7     <?php $this->render_admin( 'submenu'  ); ?>
     7    <?php $this->render_admin( 'submenu', array( 'options' => $options ) ); ?>
    88
    99  <form method="post" action="" style="clear: both">
  • redirection/trunk/view/admin/submenu.php

    r421720 r543833  
    22
    33<ul class="subsubsub">
    4   <li>
    5         <a <?php if ( !isset( $_GET['sub'] ) ) echo 'class="current"'; ?>href="?page=redirection.php<?php if ( isset( $_GET['id'] ) ) echo '&amp;id='.intval( $_GET['id'] ) ?>">
     4    <li>
     5        <a <?php if ( !isset( $_GET['sub'] ) ) echo 'class="current"'; ?> href="<?php echo admin_url( 'tools.php?page=redirection.php' ); ?><?php if ( isset( $_GET['id'] ) ) echo '&amp;id='.intval( $_GET['id'] ) ?>">
    66            <?php _e( 'Redirects', 'redirection' ); ?>
    77        </a> |
    88    </li>
    9   <li>
    10         <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'groups' ) echo 'class="current"'; ?>href="?page=redirection.php&amp;sub=groups<?php if ( isset( $_GET['id'] ) ) echo '&amp;id='.intval( $_GET['id'] ) ?>">
     9    <li>
     10        <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'groups' ) echo 'class="current"'; ?> href="<?php echo admin_url( 'tools.php?page=redirection.php' ); ?>&amp;sub=groups<?php if ( isset( $_GET['id'] ) ) echo '&amp;id='.intval( $_GET['id'] ) ?>">
    1111            <?php _e( 'Groups', 'redirection' ); ?>
    1212        </a> |
    1313    </li>
    14   <li>
    15         <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'modules' ) echo 'class="current"'; ?>href="?page=redirection.php&amp;sub=modules">
     14    <li>
     15        <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'modules' ) echo 'class="current"'; ?> href="<?php echo admin_url( 'tools.php?page=redirection.php' ); ?>&amp;sub=modules">
    1616            <?php _e( 'Modules', 'redirection' ); ?>
    1717        </a> |
    1818    </li>
    19   <li>
    20         <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'log' ) echo 'class="current"'; ?>href="?page=redirection.php&amp;sub=log">
     19
     20    <?php if ( isset( $options['log_redirections'] ) && $options['log_redirections'] ) : ?>
     21    <li>
     22        <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'log' ) echo 'class="current"'; ?> href="<?php echo admin_url( 'tools.php?page=redirection.php' ); ?>&amp;sub=log">
    2123            <?php _e( 'Log', 'redirection' ); ?>
    2224        </a> |
    2325    </li>
    24   <li>
    25         <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'options' ) echo 'class="current"'; ?>href="?page=redirection.php&amp;sub=options">
     26    <?php endif; ?>
     27
     28    <?php if ( isset( $options['log_404s'] ) && $options['log_404s'] ) : ?>
     29    <li>
     30        <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == '404s' ) echo 'class="current"'; ?> href="<?php echo admin_url( 'tools.php?page=redirection.php' ); ?>&amp;sub=404s">
     31            <?php if ( isset( $_GET['ip'] ) ) : ?>
     32                <?php printf( __( '404s from %s', 'redirection' ), long2ip( ip2long( $_GET['ip'] ) ) ); ?>
     33            <?php else : ?>
     34                <?php _e( '404s', 'redirection' ); ?>
     35            <?php endif; ?>
     36        </a> |
     37    </li>
     38    <?php endif; ?>
     39
     40    <li>
     41        <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'options' ) echo 'class="current"'; ?> href="<?php echo admin_url( 'tools.php?page=redirection.php' ); ?>&amp;sub=options">
    2642            <?php _e( 'Options', 'redirection' ); ?>
    2743        </a> |
    2844    </li>
    29   <li>
    30         <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'support' ) echo 'class="current"'; ?>href="?page=redirection.php&amp;sub=support">
     45    <li>
     46        <a <?php if ( isset( $_GET['sub'] ) && $_GET['sub'] == 'support' ) echo 'class="current"'; ?> href="<?php echo admin_url( 'tools.php?page=redirection.php' ); ?>&amp;sub=support">
    3147            <?php _e( 'Support', 'redirection' ); ?>
    3248        </a>
  • redirection/trunk/view/admin/support.php

    r537877 r543833  
    44
    55    <h2><?php _e ('Redirection Support', 'redirection'); ?></h2>
    6     <?php $this->render_admin( 'submenu'  ); ?>
     6    <?php $this->render_admin( 'submenu', array( 'options' => $options ) ); ?>
    77
    88    <p style="clear: both">
Note: See TracChangeset for help on using the changeset viewer.