Hidden_Gamma |
03-19-2009 05:57 PM |
Quote:
Originally Posted by buro9
(Post 1541380)
I've got this working for .co.uk
You can easily add .ca, .de or any two level .tld like .co.uk to this by adding:
$associate_id_ and then the .tld with the . replaced by _
$associate_id_co_uk is the UK one.
And of course add the bit in the preg_match to work with this.
Code for the file is thus:
PHP Code:
<?php function amazon_links($text) { $associate_id_co_uk = 'buro9-21'; // or leave empty $associate_id_com = 'buro9-20'; // or leave empty
$replace_targt_urls = true; // true or false
$replace_src = array(); $replace_str = array();
// check for [url="amazon-link"]some text[/url] if(preg_match_all("/\[url\=(?:\")?(http:\/\/(?:[A-z0-9\.]+)?amazon\.(co\.uk|com)\/(?:.+))(?:\")?](.+)\[\/url\]/iU", $text, $out)) { for($i=0;$i<count($out[1]);$i++) { $associate_id = ${'associate_id_'.str_replace('.','_',$out[2][$i])}; $out[4][$i] = $out[1][$i];
if($associate_id && !empty($associate_id)) { // Look for an asin number if(preg_match("/\/[A-Z0-9]{10}(\/)?/", $out[1][$i], $asin) && strpos($out[1][$i], '/review') === false) { if(substr($asin[0], -1) != '/') { $asin[0] .= '/'; } $out[1][$i] = 'http://www.amazon.'.$out[2][$i].'/exec/obidos/ASIN'.$asin[0].'ref=nosim/'.$associate_id; } else { $target_url = $out[1][$i]; if($replace_targt_urls) { $target_url = preg_replace('/ref\=([a-z0-9\-]{3,})\-([0-9]{2})/iU', 'ref='.$associate_id, $target_url); $target_url = preg_replace('/tag\=([a-z0-9\-]{3,})\-([0-9]{2})/iU', 'tag='.$associate_id, $target_url); }
$out[1][$i] = 'http://www.amazon.'.$out[2][$i].'/exec/obidos/redirect?link_code=ur2&camp=1789&tag='.$associate_id.'&creative=9325&path='.urlencode($target_url); }
$replace_src[] = '[url="'.$out[4][$i].'"]'; $replace_str[] = '[url="'.$out[1][$i].'"]';
$replace_src[] = '[url='.$out[4][$i].']'; $replace_str[] = '[url='.$out[1][$i].']';
$replace_src[] = '[url="'.$out[4][$i].'"]'; $replace_str[] = '[url="'.$out[1][$i].'"]';
$replace_src[] = '[url='.$out[4][$i].']'; $replace_str[] = '[url='.$out[1][$i].']'; } } } unset($out); // check for [url]amazon-link[/url] if(preg_match_all("/\[url\](http:\/\/(?:[A-z0-9\.]+)?amazon\.(co\.uk|com)\/(?:.+))\[\/url\]/iU", $text, $out)) { for($i=0;$i<count($out[1]);$i++) { $associate_id = ${'associate_id_'.str_replace('.','_',$out[2][$i])}; $out[4][$i] = $out[1][$i];
if($associate_id && !empty($associate_id)) { // Look for an asin number if(preg_match("/\/[A-Z0-9]{10}(\/)?/", $out[1][$i], $asin) && strpos($out[1][$i], '/review') === false) { if(substr($asin[0], -1) != '/') { $asin[0] .= '/'; } $out[1][$i] = 'http://www.amazon.'.$out[2][$i].'/exec/obidos/ASIN'.$asin[0].'ref=nosim/'.$associate_id; } else { $target_url = $out[1][$i]; if($replace_targt_urls) { $target_url = preg_replace('/ref\=([a-z0-9\-]{3,})\-([0-9]{2})/iU', 'ref='.$associate_id, $target_url); $target_url = preg_replace('/tag\=([a-z0-9\-]{3,})\-([0-9]{2})/iU', 'tag='.$associate_id, $target_url); }
$out[1][$i] = 'http://www.amazon.'.$out[2][$i].'/exec/obidos/redirect?link_code=ur2&camp=1789&tag='.$associate_id.'&creative=9325&path='.urlencode($target_url); }
$displayed_link = $out[4][$i]; if(strlen($displayed_link) > 55) { $displayed_link = substr($displayed_link, 0, 36).'...'.substr($displayed_link, -14); }
$replace_src[] = '[url]'.$out[4][$i].'[/url]'; $replace_str[] = '[url="'.$out[1][$i].'"]'.$displayed_link."[/url]";
$replace_src[] = '[url]'.$out[4][$i].'[/url]'; $replace_str[] = '[url="'.$out[1][$i].'"]'.$displayed_link."[/url]"; } } } unset($out);
// replace the message if(isset($replace_src[0])) { $text = str_replace($replace_src, $replace_str, $text); } unset($replace_src, $replace_str);
return $text; } ?>
Thanks for the great hack.
|
Can someone tell me what exactly I am supposed to write into the preg_match section to get this hack to work for my multilevel domain affiliate links if I am using more than one? I have affiliate IDs for .co.uk and .co.jp, but I don't really understand how to write in more than one according to this example, I also can't seem to figure out where I am supposed to put my .de domain in the preg_match section.
Also, I seemed to have discoveed that on my forum (running 3.8.1 PL1) that this plugin will only add the affiliate ID to URLs if they are added raw, but if an Amazon URL is added to text, like this, for example: I Love Lucy, it won't add the Afilliate ID.
Thanks for any help. I really hope this plugin can be updated.
|