All Consuming RSS feed and creates an Amazon link to it. If you pass it an associate id, it will build that into the ad too.  Once you've activated this plugin, you'll need to stick this code into your template somewhere (probably on the sidebar): <?php allconsuming_amazon('allconsuming-username', 'amazon-associateid', ad-style-number, 'div-css-style'); ?>.  Everything except the first parameter ('allconsuming-username') is optional, so you can leave them off if you want. See the plugin file for more info on the other parameters. Author: Glenn Slaven Author URI: http://blog.slaven.net.au/ Copyright 2004 Glenn Slaven (email : gdalziel@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ include_once (ABSPATH . WPINC . "/rss-functions.php"); include_once (ABSPATH . WPINC . "/class-snoopy.php"); if (!defined('ACAMAZ_CACHE_FOLDER')) { define(ACAMAZ_CACHE_FOLDER, dirname(dirname(__FILE__))); } if (!defined('ACAMAZ_CACHE_LOC')) { define(ACAMAZ_CACHE_LOC, ACAMAZ_CACHE_FOLDER.'/acamaz_cache.php'); } /** * allconsuming_amazon() * * @param mixed $username Your All Consuming username. This is the only required field. * @param string $associateid Your associate id. If you don't provide one, mine will be used. * @param string $div_class Class name for the containing div * @param integer $ad_style Which Amazon ad style to use for the keyword search ad. Not usually needed if an ASIN can be determined. 6: width = 120 height =150, 8: width = 240 height =150, 9: width = 180 height =150 * @param boolean $return Whether the function should display or return the content * @return **/ function allconsuming_amazon($username, $associateid = 'thejournal00-20', $div_class = '', $ad_style = 6, $return = false) { //The containing div, heading & link. Change to your heart's content, but leave the $base_ad_code variable in there somewhere or else nothing's going to show up! $ad_div = '

###HEADING###

###ADCODE###
My All Consuming List
'; //List of possible ad sizes, directly from the Amazon Associates 'Recommended Product Links' page. These are just the top 3 sizes, they seem the most suitable for single item display $ad_styles = array( 6 => array('width' => "120",'height' => "160"), 8 => array('width' => "120",'height' => "240"), 9 => array('width' => "180",'height' => "150") ); //Location of the All Consuming RSS Feed $url = "http://43.allconsuming.net/person/$username/rss"; //The basic construct of the Amazon ad iframe, either for the keyword search or the individual item $base_keyword_ad_code = ''; $base_individual_ad_code = ''; //Check whether update is needed. If the querystring variable 'force_refresh_acamaz' is set to true, the script will always update directly, ignoring the cache. Do NOT set this to true in a live environment as it would be considered absuive by the site owner. This is for testing purposes only. if (file_exists(ACAMAZ_CACHE_LOC) && !$_GET['force_refresh_acamaz']) { $delta = time() - filemtime(ACAMAZ_CACHE_LOC); $update = ($delta >= (24*60*60)); } else { $update = true; } //Go get the feed and do stuff with it! $content = false; if ($update && function_exists('fetch_rss') && class_exists('Snoopy')) { $rss = fetch_rss($url); if (is_array($rss->items) && count($rss->items) > 0) { //Use the Snoopy net client to pull the asin out of the allconsuming page $snoopy_url = 'http://www.slaven.net.au/webservices/?action=allconasin&url='.$rss->items[0]['link']; $client = new Snoopy(); $client->read_timeout = 3; $client->use_gzip = true; ($_GET['dieloud'] ? $client->fetch($snoopy_url) : @$client->fetch($snoopy_url)); if ($client->results) { $ad_div = str_replace('###ADCODE###', $base_individual_ad_code, $ad_div); $asin = $client->results; $title = false; } else { $ad_div = str_replace('###ADCODE###', $base_keyword_ad_code, $ad_div); if (preg_match('/.*?"(.+?)".*?/', $rss->items[0]['title'], $matches) && is_array($matches)) { $title = $matches[1]; } else { $title = false; } $asin = false; } //Create the content $content = preg_replace( array('/###DIVCLASS###/', '/###HEADING###/', '/###ASSOCIATEID###/', '/###WIDTH###/', '/###HEIGHT###/', '/###KEYWORDS###/', '/###STYLE###/', '/###ASIN###/', '/###USERNAME###/'), array($div_class, (strpos($rss->items[0]['title'], 'Consuming') === 0 ? "I'm Consuming" : "I last Consumed"), $associateid, $ad_styles[$ad_style]['width'], $ad_styles[$ad_style]['height'], $title.' '.$rss->items[0]['description'], $ad_style, $asin, $username), $ad_div ); //Check the cache location and write, or display error if (is_writable(ACAMAZ_CACHE_LOC) || (!file_exists(ACAMAZ_CACHE_LOC) && is_writable(ACAMAZ_CACHE_FOLDER))) { $write_file = @fopen(ACAMAZ_CACHE_LOC, "w"); fwrite($write_file, $content); fclose($write_file); } elseif ($_GET['dieloud']) { print "All Consuming Amazon Ad Plugin Error
The cache file location either doesn't exist or the web server doesn't have permission to write to it.
\n"; return false; } } else { if ($_GET['dieloud']) { print "All Consuming Amazon Ad Plugin Error
Sorry, the script was unable to retrieve anything from '$url'. Please check that URL to ensure it is available.
\n"; } return false; } } ob_start(); ($_GET['dieloud'] ? @include(ACAMAZ_CACHE_LOC) : include(ACAMAZ_CACHE_LOC)); $contents = ob_get_contents(); ob_end_clean(); //Display content if not $return, otherwise return the content if ($return) { return $contents; } else { return print $contents; } } //This is here to add the Magpie error function that hasn't been added into the rss-functions.php file if(!function_exists('error')) { function error ($errormsg, $lvl=E_USER_WARNING) { // append PHP's error message if track_errors enabled if ( $php_errormsg ) { $errormsg .= " ($php_errormsg)"; } if ( MAGPIE_DEBUG ) { trigger_error( $errormsg, $lvl); } else { error_log( $errormsg, 0); } $notices = E_USER_NOTICE|E_NOTICE; if ( $lvl&$notices ) { $this->WARNING = $errormsg; } else { $this->ERROR = $errormsg; } } } ?>