Change Amazon URLs to affiliate links

chx - April 27, 2009 - 18:15
Project:Amazon associate tools
Version:5.x-1.5
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

While writing a blogpost, I am browsing Amazon site and want to copypaste Amazon URLs into the body and get affiliate links. Well, http://drupalbin.com/9072 does it for me.

#1

MGParisi - April 27, 2009 - 18:33

Copy from DrupalBin!

?php

function affiliate_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(0 => t('Affiliate filter'));
    case 'description':
      return t('Create affiliates links from Amazon links.');
    case 'process':
      if (preg_match('|http://www.amazon.com/.*/([0-9A-Z]{10})/\S*|', $text, $m)) {
        $item_id = $m[1];
        $affiliate_id = variable_get('affiliate_id', '');
        $access_key = variable_get('access_key', '');
        $xml = simplexml_load_file("http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=$access_key&Operation=ItemLookup&ItemId=$item_id");
        $url = "http://www.amazon.com/dp/$item_id/?tag=$affiliate_id";
        $link = l($xml->Items->Item->ItemAttributes->Title, $url);
        $text = str_replace($m[0], $link, $text);
      }
      return $text;
    default:
      return $text;
  }
}

function affiliate_filter_tips() {
  return t('Changes Amazon URLs to affiliate links');
}
?>

#2

MGParisi - April 27, 2009 - 18:55
Version:5.x-1.x-dev» 5.x-1.5
Component:Code» User interface
Status:active» won't fix

Talked to EATON, will be included into the D6 project...

 
 

Drupal is a registered trademark of Dries Buytaert.