<?php
/*Plugin Name: E2 Pipe Linker
Version: 0.5
Plugin URI: http://sugardeath.net/e2-pipe-linker-plugin/
Description: Allows one to use <a href="http://everything2.org" title="Everything2">Everything2</a> pipe links in one's posts.
Author: Tony Lademan
Author URI: http://sugardeath.net/
*/

add_filter('the_content', 'e2pipe');  //Allows plugin to catch links in post bodies
add_filter('comment_text', 'e2pipe');  //Allows plugin to catch links in comments

function escape_space($match)
{
        return preg_replace('#\ #', ' ', $match[0]) ;  //Replace the space character in the second set of single quotes if you want to change any spaces to something else (eg. %20)
}


function e2pipe($content)
{
        //To catch nonalphanumerics
        //(eg. [/dev/cake|/dev/hda]
        $content = preg_replace_callback( '#\[\W[^\]]+\|#', 'escape_space', $content);
        $content = preg_replace( '#\[(\W[^\]]+)\|([^\]]+)\]#', '<a href="http://everything2.org/?node=$1" title="$1">$2</a>', $content);
       
       
        //To catch alphanumerics
        //(eg. [Star Wars Knights of the Old Republic|KOTOR]
        $content = preg_replace_callback( '#\[\w[^\]]+\|#', 'escape_space', $content);
        $content = preg_replace( '#\[(\w[^\]]+)\|([^\]]+)\]#', '<a href="http://everything2.org/?node=$1" title="$1">$2</a>', $content);
        
        return $content;  //Sends the modified content back to Wordpress to be displayed
}

?>