WordPress.org

Plugin Directory

Changeset 604463


Ignore:
Timestamp:
09/27/12 05:54:53 (19 months ago)
Author:
solarissmoke
Message:

Releasing version 0.7

Location:
wp-410/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-410/trunk/readme.txt

    r589133 r604463  
    22Contributors: solarissmoke 
    33Tags: error, gone, robots 
    4 Requires at least: 2.9 
     4Requires at least: 3.0 
    55Tested up to: 3.4 
    66Stable tag: trunk 
     
    1414The [HTTP Specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.11) defines the `410` response header for use when a resource has been permanently removed. It informs robots visiting your site that the requested content has gone, and that they should stop trying to access it. 
    1515 
    16 If you come across any bugs or have suggestions, please use the plugin support forum or contact me at [rayofsolaris.net](http://rayofsolaris.net). I can't fix it if I don't know it's broken! Please check the [FAQ](http://wordpress.org/extend/plugins/wp-410/faq/) for common issues. 
     16If you come across any bugs or have suggestions, please use the plugin support forum or [email me](http://rayofsolaris.net/contact/). I can't fix it if I don't know it's broken! Please check the [FAQ](http://wordpress.org/extend/plugins/wp-410/faq/) for common issues. 
    1717 
    1818== Frequently Asked Questions == 
     
    2323 
    2424== Changelog == 
     25 
     26= 0.7 = 
     27* Added logging of 404 errors so they can be easily added to the list of obsolete URLs. 
    2528 
    2629= 0.6.1 = 
  • wp-410/trunk/wp-410.php

    r460836 r604463  
    44Plugin URI: http://rayofsolaris.net/code/410-for-wordpress 
    55Description: Sends HTTP 410 (Gone) responses to requests for pages that no longer exist on your blog. 
    6 Version: 0.6.1 
     6Version: 0.7 
    77Author: Samir Shah 
    88Author URI: http://rayofsolaris.net/ 
     
    1414 
    1515class WP_410 { 
    16     const db_version = 3;   // DB version, since 0.2 
     16    const db_version = 4;   // DB version, since 0.2 
    1717    private $permalinks; 
    1818    private $table; 
     
    4040            gone_id SMALLINT NOT NULL AUTO_INCREMENT, 
    4141            gone_key VARCHAR(512) NOT NULL, 
    42             gone_regex VARCHAR(512) NOT NULL,  
    43             PRIMARY KEY  (gone_id) 
     42            gone_regex VARCHAR(512) NOT NULL, 
     43            is_404 SMALLINT(1) NOT NULL DEFAULT 0, 
     44            PRIMARY KEY  (gone_id), 
     45            KEY is_404 (is_404) 
    4446        );"; 
    4547 
     
    5052    private function get_links(){ 
    5153        global $wpdb; 
    52         return $wpdb->get_results( "SELECT gone_key, gone_regex FROM $this->table", OBJECT_K ); // indexed by gone_key 
    53     } 
    54      
    55     private function add_link( $key ){  // just supply the link 
     54        return $wpdb->get_results( "SELECT gone_key, gone_regex FROM $this->table WHERE is_404 = 0", OBJECT_K );    // indexed by gone_key 
     55    } 
     56     
     57    private function get_404s(){ 
     58        global $wpdb; 
     59        $links = $wpdb->get_results( "SELECT gone_key, gone_regex FROM $this->table WHERE is_404 = 1", OBJECT_K );  // indexed by gone_key 
     60        // limit how many 404s we store 
     61        if( count( $links ) > 50 ) { 
     62            $n = count( $links ) - 50; 
     63            $wpdb->query( "DELETE FROM `$this->table` WHERE is_404 = 1 ORDER BY gone_id LIMIT $n" ); 
     64            return $this->get_404s(); 
     65        } 
     66        return $links; 
     67    } 
     68     
     69    private function add_link( $key, $is_404 = false ){ // just supply the link 
    5670        global $wpdb; 
    5771        // build regex 
     
    6276        $regex = '|^' . implode( '', $parts ) . '$|i'; 
    6377         
    64         return $wpdb->insert( $this->table, array( 'gone_key' => $key, 'gone_regex' => $regex ) ); 
     78        // avoid duplicates - messy but MySQL doesn't allow url-length unique keys 
     79        if( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM `$this->table` WHERE `gone_key` = %s", $key ) ) ) 
     80            return 0; 
     81         
     82        return $wpdb->insert( $this->table, array( 'gone_key' => $key, 'gone_regex' => $regex, 'is_404' => intval( $is_404 ) ) ); 
     83    } 
     84     
     85    private function convert_404( $key ) { 
     86        global $wpdb; 
     87        return $wpdb->query( $wpdb->prepare( "UPDATE `$this->table` SET is_404 = 0 WHERE `gone_key` = %s LIMIT 1", $key ) ); 
    6588    } 
    6689     
     
    7699            return; 
    77100             
    78         $old_links = get_option( 'wp_410_links_list', array() ); 
    79         $new_links = array();    // just a simple array of links 
    80          
    81         if( 0 == $options_version ) // links were stored just as links 
    82             $new_links = array_map( 'rawurldecode', $old_links ); 
    83         elseif( 1 == $options_version ) // links were stored as array( link => regex ), We only need the link 
    84             $new_links = array_map( 'rawurldecode', array_keys( $old_links ) ); 
    85         else // moved to using the database in db_version 3 
    86             $new_links = array_keys( $old_links ); 
    87          
    88         $this->install_table(); 
    89         foreach( $new_links as $link ) 
    90             $this->add_link( $link ); 
    91  
    92         delete_option( 'wp_410_links_list' );   // remove old option 
     101        // last db change was in version 4 
     102        if( $options_version < 4 ) 
     103            $this->install_table(); 
     104         
     105        if( $options_version < 3 ) { 
     106            $old_links = get_option( 'wp_410_links_list', array() ); 
     107            $new_links = array();    // just a simple array of links 
     108             
     109            if( 0 == $options_version ) // links were stored just as links 
     110                $new_links = array_map( 'rawurldecode', $old_links ); 
     111            elseif( 1 == $options_version ) // links were stored as array( link => regex ), We only need the link 
     112                $new_links = array_map( 'rawurldecode', array_keys( $old_links ) ); 
     113            else // moved to using the database in db_version 3 
     114                $new_links = array_keys( $old_links ); 
     115             
     116            foreach( $new_links as $link ) 
     117                $this->add_link( $link ); 
     118             
     119            delete_option( 'wp_410_links_list' );   // remove old option 
     120        } 
     121         
    93122        update_option( 'wp_410_options_version', self::db_version ); 
    94123    } 
     
    100129    function settings_page() { 
    101130        $links = $this->get_links(); 
     131        $logged_404s = $this->get_404s(); 
    102132        $links_to_add = array(); 
    103133         
     
    116146            } 
    117147             
     148            if( !empty( $_POST['add_404s'] ) ) { 
     149                foreach( $_POST['add_404s'] as $link ) { 
     150                    $this->convert_404( $link ); 
     151                    $links[$link] = $link; // the value doesn't matter, we don't use it here 
     152                    unset( $logged_404s[$link] ); 
     153                } 
     154            } 
     155             
    118156            if( !empty( $_POST['old_links_to_remove'] ) ) { 
    119157                foreach( $_POST['old_links_to_remove'] as $key ) { 
     
    132170         
    133171        ksort( $links ); 
     172        ksort( $logged_404s ); 
    134173    ?> 
    135174    <style> 
     
    138177    label.invalid {color: red} 
    139178    p.invalid { background: #FFEBE8; border: 1px solid red; border-radius: 5px; padding: 5px 10px} 
     179    #wp_410_table th {font-weight: bold} 
     180    #wp_410_table tr {border-top: 1px solid #EEE} 
    140181    </style> 
    141182    <?php screen_icon(); ?> 
     
    145186    <p><strong>Note: this plugin will only return a 410 response if WordPress has not found something valid to display for the requested URL.</strong></p> 
    146187    <form action="" method="post" id="wp-gone-captcha-settings"> 
    147     <table class="form-table"><tbody> 
     188    <table id="wp_410_table" class="form-table"><tbody> 
    148189    <tr><th>Obsolete URLs</th><td> 
    149190    <?php 
     
    174215    ?> 
    175216    <p><small>If you create or update an article whose URL matches one of those above, that URL will automatically be removed from this list.</small></p> 
     217    </td></tr> 
     218    <tr><th>Recent 404 errors</th><td> 
     219     
     220    <?php 
     221    if( empty( $logged_404s ) ) { 
     222        echo '<p>This plugin will automatically log recent 404 (Page Not Found) errors on your site, and show them here, so that you can easily add them to the list above. There are currently no 404 errors reported.</p>'; 
     223    } 
     224    else { 
     225        echo '<p>Below are recent 404 (Page Not Found) errors that have occurred on your site. If you want to issue a 410 response for any of these requests, check the corresponding box.</p>'; 
     226        echo '<ul id="wp_gone_404s" class="indent">'; 
     227        foreach( array_keys( $logged_404s ) as $k ) { 
     228            $k = htmlspecialchars( $k );             
     229            echo "<li><input type='checkbox' name='add_404s[]' value='$k' id='404_$k' /> <label for='404_$k'><code>$k</code></label></li>"; 
     230        } 
     231        echo '</ul>'; 
     232    } 
     233    ?> 
    176234    </td></tr> 
    177235    <tr><th>Manually add URLs</th><td> 
     
    284342            } 
    285343        } 
     344         
     345        // no hit, log 404 
     346        $this->add_link( $req, true ); 
    286347    } 
    287348} 
Note: See TracChangeset for help on using the changeset viewer.