Plugin Directory

Changeset 462940


Ignore:
Timestamp:
11/15/2011 04:38:36 AM (14 years ago)
Author:
MarcusPope
Message:

Updated to version 1.2 - fixes rss content links for nonstandard feed readers like feedburner. Fixes comment links in rss2 and atom specs. Updated faq and other notes

Location:
root-relative-urls/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • root-relative-urls/trunk/readme.txt

    r457443 r462940  
    6262Unfortunately no, this plugin is designed to correct new content as it is entered via the administration panel.  It will still work with your current site,
    6363but it will not alter links you have already embedded.  Because of this inherent defect in Wordpress, this plugin would have no idea if http://example.com/ was a link
    64 to your staging environment or an external URL, especially if you are accessing the site from http://localhost/.  In the future we may implement a find/replace
    65 feature to aid the transformations, but for now this is up to you to correct existing content. See the link above from interconnectit.com for more information on that process.
     64to your staging environment or an external URL, especially if you are accessing the site from http://localhost/.
     65
     66I'm currently working with Brian DiChiara on a solution for find/replace of previous absolute urls into root-relative slashes.  You may still continue to use the link above from interconnectit.com for more information on that process, but we should have the feature included by Nov 20th, 2011.
    6667
    6768= Should I use this plugin if I only have one production site and I make all of my changes in production? =
     
    7677will need to patch a Wordpress core file - or wait until the Wordpress core team implements this fix - http://core.trac.wordpress.org/attachment/ticket/18910/ms-blogs.php.patch
    7778
    78 Until then this plugin will not work out of the box for MU installs.
     79Until then this plugin will not work out of the box for MU installs. I have discovered an approach for resolving this problem without a core hack but I will need to research it before implementing the update.  It will be a big ol nasty hack but it will work.
    7980
    8081
     
    9192== Changelog ==
    9293
     94= 1.2 =
     95
     96* Discovered an issue with wp-cron.  I've disabled the warnings for now, but I'm not really sure about the potential fallout from the http_host not properly being set in some circumstances.
     97* Updated plugin to massage rss content urls back to absolute site urls.  This shouldn't need to even happen but unfortunately feedburner and feedblitz don't follow the html spec :(  Google Reader and a bunch of others do however, so there is hope of fixing this problem on feedburner & feedblitz's end.
     98* Despite this ticket being not yet patched: http://core.trac.wordpress.org/ticket/19210  I have fixed the previous bugs related to comments_link_feed() or comment_link() functions.
     99* Found an interesting post from way back in 2003, when a woman by the name of Shirley Kaiser went through a similar pursuit to change MovableType from absolute only urls to root relative urls. 2003!!! Almost a decade ago someone else had to show an entire platform the power and flexibility of root relative urls! - (http://brainstormsandraves.com/archives/2003/09/07/relative_vs_absolute_urls/)
     100
    93101= 1.1 =
    94102* Converted plugin to be < php5.3 compatible by removing usage of function references
  • root-relative-urls/trunk/sb_root_relative_urls.php

    r457443 r462940  
    99Author: Marcus E. Pope, marcuspope
    1010Author URI: http://www.marcuspope.com
    11 Version: 1.0
     11Version: 1.2
    1212
    1313Copyright 2011 Marcus E. Pope (email : me@marcuspope.com)
     
    3535    //munges absolute urls provided to the wysiwyg editor to be root relative instead of absolute
    3636    //generally displays urls throughout the admin area as root relative instead of absolute
     37   
     38    static $massage = false;
     39   
    3740    static function add_actions($tag_arry, $func, $p = 10, $a = 1) {
    3841        //allows for multiple tags to bind to the same funciton call
     
    6063        //used in export functions or RSS feeds.  Or because they are literally checked against the domain of URLs stored
    6164        //in the database - a needless process for any website.
    62         $url = parse_url($url);
     65        $url = @parse_url($url);
    6366        $relative = ltrim(@$url['path'], '/') . (isset($url['query']) ? "?" . $url['query'] : '');
    64         return MP_WP_Root_Relative_URLS::scheme( 'http://' . $_SERVER['HTTP_HOST'] . (!empty($relative) ? '/' . $relative: '') );
     67        return MP_WP_Root_Relative_URLS::scheme( 'http://' . @$_SERVER['HTTP_HOST'] . (!empty($relative) ? '/' . $relative: '') );
    6568    }
    6669
     
    7578    }
    7679
     80    static function enable_content_massage() {
     81        //this is only called when an external feed is being called
     82        //this lets the content filter know that we should convert root relative urls back in to absolute urls since
     83        //some external sources don't understand the html spec
     84        self::$massage = true;
     85       
     86        //massage global post object
     87        global $post;
     88        $post->post_content = self::massage_external_content($post->post_content);
     89        $post->post_excerpt= self::massage_external_content($post->post_excerpt);
     90    }
     91   
     92    static function massage_external_content($a) {
     93        //Here is where we fix the root relative content urls into absolute urls using the current host name
     94        //this shouldn't be required but companies like feedburner and feedblitz don't understand the web :(
     95        if (self::$massage == true) {
     96            $a = preg_replace_callback('#(<[^>]+(?:href|src)\s*?=\s*?[\'"])(\/)#i', array("MP_WP_Root_Relative_URLS", "do_absolute_massage_cb"), $a);
     97        }
     98        return $a;
     99    }
     100   
     101    static function do_absolute_massage_cb($a) {
     102        //callback handler that does the physical insertion of absolute domain into root relative urls
     103        return $a[1] . self::scheme('http://' . @$_SERVER['HTTP_HOST'] . $a[2]);
     104    }
     105   
    77106    static function proper_root_relative_url($url) {
    78107        //This method is used for urls that can be acceptably reformatted into root-relative urls without causing issues
    79108        //related to other deficiencies in the wp core.
    80         $url = parse_url($url);
    81         return '/' . ltrim(@$url['path'], '/') . (isset($url['query']) ? "?" . $url['query'] : '');
     109       
     110        if (self::$massage) {
     111            //massage back to absolute because we're rendering a feed and the platform mixes url procurment methods between the delivery methods
     112            //despite offering _rss specific filters
     113            return MP_WP_Root_Relative_URLS::dynamic_absolute_url($url);
     114        } else {
     115            $url = @parse_url($url);
     116            return '/' . ltrim(@$url['path'], '/') . (isset($url['query']) ? "?" . $url['query'] : '');
     117        }
    82118    }
    83119
     
    152188            array(
    153189                'get_bloginfo_rss',
    154                 'the_permalink_rss'
     190                'the_permalink_rss',
     191                'get_post_comments_feed_link',
     192                'get_the_author_url',
     193                'get_comment_author_url',
     194                'get_comment_link'
    155195            ),
    156196            array(
     
    161201            2  //supply second parameter for type checking
    162202        );
    163 
     203       
     204        //Used to indicate that an atom feed is being generated so it's ok to massage the content urls for absolute format
     205        MP_WP_Root_Relative_URLS::add_actions(
     206            array(
     207                'atom_ns',
     208                'attom_comments_ns',
     209                'rss2_ns',
     210                'rss2_comments_ns',
     211                'rdf_ns'
     212            ),
     213            array(
     214                'MP_WP_Root_Relative_URLS',
     215                'enable_content_massage'
     216            )
     217        );
     218       
     219        MP_WP_Root_Relative_URLS::add_actions(
     220            array(
     221                'the_excerpt_rss',
     222                'the_content_feed',
     223            ),
     224            array(
     225                'MP_WP_Root_Relative_URLS',
     226                'massage_external_content'
     227            )
     228        );
     229       
    164230        //HACK: This plugin actually won't work for MU Sites until either of the following conditions are true:
    165231            //1. Wordpress core team publishes this patch - http://core.trac.wordpress.org/attachment/ticket/18910/ms-blogs.php.patch
Note: See TracChangeset for help on using the changeset viewer.