WordPress.org

Plugin Directory

source: relative-links/trunk/relative-links.php

Last change on this file was 2448, checked in by MathiasBynens, 11 years ago

ph34r my 1337 sk1llzz0rz!!1

File size: 1.5 KB
Line 
1<?php
2/*
3Plugin Name: Absolute Relative Links
4Version: 1.2
5Plugin URI: http://mathibus.com/archives/2005/02/relative-links
6Description: When activated, this plugin filters WordPress' output, removing redundant stuff from on-site links.
7Author: Mathias Bynens
8Author URI: http://mathibus.com/
9*/
10
11update_option('gzipcompression', 0);
12
13function mj_get_root($url) { // not everybody has his blog running from the root
14        while(substr_count($url, '/') > 2) { // all we need is the :// from the protocol
15                $array = explode('/', $url);
16                array_pop($array);
17                $url = implode('/', $array);
18        }
19        return $url;
20}
21
22function mj_relative_links($str) {
23        global $feed;
24        $url = mj_get_root(get_settings('siteurl'));
25/*
26        Uncomment the following line, and replace "http://mathibus.com" with
27        your untrailingslashed root URI to speed things up a little.
28        Don't forget to remove the above line saying $url = get_root(get_settings('siteurl'));
29        if you do so.
30*/
31//      $url = 'http://mathibus.com';
32        $str = str_replace("'" . $url ."/", "'/", $str);        // <a href="xtp://yoursite.com/whatever/">
33        $str = str_replace('"' . $url . '/', '"/', $str);       // <a href='xtp://yoursite.com/whatever/'>
34        $str = str_replace('"' . $url . '"', '"/"', $str);      // <a href="xtp://yoursite.com">
35        $str = str_replace("'" . $url . "'", "'/'", $str);      // <a href='xtp://yoursite.com">
36        return $str;
37}
38
39if((!strstr($_SERVER['REQUEST_URI'], $url . '/wp-admin')) && (!$feed)) ob_start('mj_relative_links'); // do not filter in feeds or in admin section
40
41?>
Note: See TracBrowser for help on using the repository browser.