Plugin For Masking Affiliate Links wp

Status
Not open for further replies.

jerxs

New member
Jun 24, 2006
1,804
24
0
North East PA
Does anyone know of a plugin for wordpress for masking links ??? Im looking a few different scripts, but they are all stand alone, was wodering if there was something made for wordpress, something that integrates into the backend of WP.
 


PHP:
<?php
/*
Plugin Name: Link Cloaker
Plugin URI: www.hunkwear.com
Description: Cloaks Affiliate Links
Version: 0.1
Author: Lerchmo
*/

define('CART_DIR','cart');

redirect_function($_SERVER['REQUEST_URI']);

function cloak_function($text)
{
    global $wpdb;
    preg_match_all('/http:\/\/(.*?)"/',$text,$matches);
    $links = $matches[0];
    foreach($links as $link)
    {
        $link = str_replace('"','',$link);
        $link = mysql_real_escape_string($link);
        $sql = "SELECT link_id FROM $wpdb->links where link_url like '$link'";
        $results = $wpdb->get_results($sql);
        if($results[0])
        {
            $id = $results[0]->link_id;
        }
        else
        {
            $sql = "INSERT INTO $wpdb->links(`link_url`) values('$link')";
            $wpdb->query($sql);
            $id = mysql_insert_id();
        }
        
        $alink = str_replace('/','\/',$link);
        $text = preg_replace("/$alink/",'http://'.$_SERVER['SERVER_NAME'].'/'.CART_DIR.'/'.$id,$text);
        
    }
    
    
    return $text;
}
function redirect_function($get)
{
    global $wpdb;
    $parts = explode('/',$get);
    $category = $parts[1];
    $link = mysql_real_escape_string($parts[2]);
    if($category == CART_DIR)
    {
        $sql = "SELECT * FROM $wpdb->links where link_id = '$link'";
        $results = $wpdb->get_results($sql);
        $link = $results[0]->link_url;
        if($link)
        {
        ?>
        <html>
            <head>
                <title>Redirecting..</title>
                <meta http-equiv="Refresh" content="0;url=<?=$link?>">
            </head>
            <body></body>
        
        </html>
        <?
        exit;
        }
        
    }

}

add_filter('the_content','cloak_function');
//add_action('publish_post', 'cloak_function');
?>
cloaks ALL links, funny cause I just made it for my shit.
need mod rewrite turned on.
 
Also found another, I was looking in to using shortURL before I made this post, which Kieron recommended in a post the other day, I wasnt sure how it would work with WP, but what I didnt notice is the author of ShortURL also made a version of ShortURL in plugin form for Wordpress.

Harley Quine

Ill have to try Lerch's and the above ....

Jer
 
Status
Not open for further replies.