WordPress.org

Plugin Directory

Changeset 393936


Ignore:
Timestamp:
06/06/11 18:30:37 (3 years ago)
Author:
GeertDD
Message:

Version 2.0

Location:
speedy-page-redirect/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • speedy-page-redirect/trunk/readme.txt

    r382594 r393936  
    1212This plugin adds a meta box to your page and post screens. You can enter a new destination URL to which the page will be redirected. 
    1313 
    14 **Features** 
    15  
     14= Features = 
    1615* Choose between permanent and temporary redirects. 
    1716* Support for custom post types out of the box. 
     
    3130== Changelog == 
    3231 
     32= 0.2 = 
     33* Relative URLs are now supported (start with a slash). 
     34* Entering a protocol only is considered empty input. 
     35 
    3336= 0.1 = 
    34 * First version. 
     37* Initial release. 
  • speedy-page-redirect/trunk/speedy-page-redirect.php

    r382483 r393936  
    44Plugin URI: http://wordpress.org/extend/plugins/speedy-page-redirect/ 
    55Description: Redirect pages and posts to other locations. 
    6 Version: 0.1 
     6Version: 0.2 
    77Author: Geert De Deckere 
    88Author URI: http://www.geertdedeckere.be/ 
     
    2626*/ 
    2727 
     28// Start your engines! 
     29new GDD_Speedy_Page_Redirect; 
     30 
    2831class GDD_Speedy_Page_Redirect { 
    2932 
     
    3336     * @var string 
    3437     */ 
    35     const VERSION = '0.1'; 
     38    const VERSION = '0.2'; 
    3639 
    3740    /** 
     
    185188        echo '<p>'; 
    186189        echo '<label for="gdd_spr_url">'.__('Destination URL:', 'page-redirect').'</label> '; 
    187         echo '<input id="gdd_spr_url" name="gdd_spr_url" type="text" value="'.esc_url($values['url']).'" size="50" style="width:80%">'; 
     190        echo '<input id="gdd_spr_url" name="gdd_spr_url" type="text" value="'.esc_url($values['url_raw']).'" size="50" style="width:80%">'; 
    188191        echo '</p>'; 
    189192 
     
    220223        $url = (isset($_POST['gdd_spr_url'])) ? trim((string) $_POST['gdd_spr_url']) : ''; 
    221224 
    222         // A URL was entered 
    223         if ($url !== '' && $url !== 'http://') 
     225        // A URL was entered (standalone protocols like "http://" are considered emtpy) 
     226        if ($url !== '' && ! preg_match('~^[-a-z0-9+.]++://$~i', $url)) 
    224227        { 
    225228            // Prepare data array to store in the database 
     
    260263        $post_id = (isset($post->ID)) ? $post->ID : $post; 
    261264 
    262         // If redirection data is found, only return the destination URL in case of a permanent redirect 
    263         if (($data = $this->get_post_data($post_id)) && $data['status'] == 301) 
    264             return $data['url']; 
    265  
    266         // Return the original URL 
    267         return $url; 
     265        // No redirection data found 
     266        if ( ! $data = $this->get_post_data($post_id)) 
     267            return $url; 
     268 
     269        // Only hard-code the destionation URL in case of a permanent redirect 
     270        if ($data['status'] != 301) 
     271            return $url; 
     272 
     273        // Return the destination URL 
     274        return $data['url']; 
    268275    } 
    269276 
     
    325332            foreach ($rows as $row) 
    326333            { 
     334                // Unserialize data 
     335                $data = unserialize($row->meta_value); 
     336 
     337                // Store the originally saved URL as raw_url 
     338                $data['url_raw'] = $data['url']; 
     339 
     340                // Generate the full URL in case a relative URL is stored in the database 
     341                if (substr($data['url'], 0, 1) === '/') 
     342                { 
     343                    $data['url'] = trailingslashit(get_bloginfo('url')).ltrim($data['url'], '/'); 
     344                } 
     345 
    327346                // Cache redirection data in object property 
    328                 $this->data[$blog_id][(int) $row->post_id] = unserialize($row->meta_value); 
     347                $this->data[$blog_id][(int) $row->post_id] = $data; 
    329348            } 
    330349        } 
     
    335354 
    336355} 
    337  
    338 // Start your engines! 
    339 new GDD_Speedy_Page_Redirect; 
Note: See TracChangeset for help on using the changeset viewer.