NOTE: This version of CaRP is obsolete. This documentation is being left here for those who have not yet upgraded to the current version.
Download | Installation | Configuration | Upgrading from version 2 | Functions | Examples | Donations
Old documentation: Version 2
Examples:Amazon.com associates, use this code to easy display best sellers based on whatever search terms you want The results are cached and refreshed every 12 hours, speeding the performance of your website. Once you've finished the main setup, adding custom best seller lists all over your website will be a snap!
First, copy the two XSL templates from below and save them on your web server with the filenames indicated. NOTE: The XSL templates have been improved from their original form. If you downloaded them previously, you may want to check to be sure you have the latest templates.
Second, copy the following code and save it in a file named "amazonnewsfeed.php" in the same directory as carp.php, after changing:
<?php
$xsllist=array(
1=>'http://www.yourdomain.com/xsl/Amazon2RSS20.1.xsl',
2=>'http://www.yourdomain.com/xsl/Amazon2RSS20.xsl'
);
$devt='put_your_developer_token_here';
$busid='put_your_associates_id_here';
if (!($mi+=0)) $mi=5;
if (!($rc+=0)) $rc=1;
$q=urlencode($q);
if (!isset($cat)) $cat='books';
require_once dirname(__FILE__).'/carp.php';
CarpConf('corder','');
CarpConf('iorder','image,link,author,desc');
CarpConf('cacheinterval',720);
CarpConf('maxitems',$mi);
CarpConf('linktarget',1);
CarpConf('aidesc','');
CarpConf('ai','<br clear="all"> <br>');
CarpConf('biimage','<div style="float:left;margin-right:5px;">');
CarpConf('aiimage','</div>');
$query="http://xml.amazon.com/onca/xml3?t=$busid&dev-t=$devt&KeywordSearch=$q&mode=$cat&sort=+salesrank&offer=All&type=heavy&page=1&f=".$xsllist[$rc];
$cachefile="amazon.".md5($query).".rss";
CarpCache($query,$cachefile);
CarpShow(CarpCachePath().$cachefile);
?>Third, find an Amazon.com logo you like and upload a copy of it to your website.
Finally, copy the following code (which will be a template for adding Amazon links to your web pages) and save it on your computer, changing:<div style="width:200;height:420px;overflow:auto;margin:5px;padding:5px;background:#cccccc;"> <span style="color:#003366;font-size:16pt;font-weight:bold;">Best sellers from</span><br> <a href="http://www.amazon.com/exec/obidos/redirect?tag=moulc&path=subst/home/home.html"><img src="http://www.yourwebsite.com/img/126X32-w-logo.gif" border="0"></a><br> <?php $q='web design'; $cat='books'; $mi=5; $rc=1; include '/path/to/amazonnewsfeed.php'; ?> </div>
You've completed the main setup. Now you can add Amazon links to any page by pasting a copy of the code saved in the last step above into your web page with the following changes as needed:
That's it! Depending on whether you are using the free or commercial version of CaRP, something like the examples to the right will appear on your web page.
Amazon2RSS20.1.xsl
<?xml version="1.0" encoding="UTF-8"?>
<!--Raymond Yee (yee@uclink.berkeley.edu) , Interactive University, University of California, Berkeley 2002-07-26 -->
<!--Adapted for Amazon heavy output and RSS 2.0 by Antone Roundy -->
<!--
Raymond Yee yee@uclink.berkeley.edu Interactive University Project Amazon Lite to RSS 0.92 XSLT
Copyright (c) 2002 The Regents of the University of California
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this XSLT
style sheet for any purpose, provided that the above copyright notice
and the following two paragraphs appear in all copies of this
document.
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS DOCUMENT TYPE DEFINITION, EVEN IF THE
UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE COMPUTER
FILE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-->
<!-- trick from http://www.mycgiserver.com/~~lisali/papers/paper.htm -->
<!DOCTYPE stylesheet [
<!ENTITY nbsp "<xsl:text disable-output-escaping="yes"
xmlns:xsl= "http://www.w3.org/1999/XSL/Transform "
>&nbsp;</xsl:text>">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output encoding="UTF-8" method="xml" media-type="text/xml"/>
<xsl:template match="ProductInfo">
<rss version="2.0">
<channel>
<title>Amazon Search Results</title>
<link>http://www.amazon.com/</link>
<description>Amazon Search Results</description>
<xsl:apply-templates select="Details"/>
</channel>
</rss>
</xsl:template>
<xsl:template match="Details">
<item>
<title><xsl:value-of select="ProductName"/></title>
<link><xsl:call-template name="removeurlparams">
<xsl:with-param name="text" select="normalize-space(@url)"/>
</xsl:call-template></link>
<author><xsl:for-each select="Authors/Author">
<xsl:apply-templates/>
<xsl:if test="not(position()=last())">, </xsl:if>
</xsl:for-each></author>
<description>
<b>Amazon Price:</b> <xsl:value-of select="OurPrice"/>
<xsl:apply-templates select="Reviews/CustomerReview[1]"/>
</description>
<!-- length="1000" is not accurate, but what can we do? we don't know the size of the file -->
<xsl:choose>
<xsl:when test="contains(ImageUrlSmall,'.gif')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/gif" /></xsl:when>
<xsl:when test="contains(ImageUrlSmall,'.jpeg') or contains(ImageUrlSmall,'.jpg')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/jpeg" /></xsl:when>
<xsl:when test="contains(ImageUrlSmall,'.png')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/png" /></xsl:when>
</xsl:choose>
</item>
</xsl:template>
<xsl:template match="Reviews/CustomerReview">
<br/>
<b>Customer Review:</b> <xsl:value-of select="substring(Comment,1,300)"/><xsl:if test="string-length(Comment)>300">...</xsl:if>
</xsl:template>
<xsl:template name="removeurlparams">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text,'?')"><xsl:value-of select="substring-before($text,'?')"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Amazon2RSS20.xsl
<?xml version="1.0" encoding="UTF-8"?>
<!--Raymond Yee (yee@uclink.berkeley.edu) , Interactive University, University of California, Berkeley 2002-07-26 -->
<!--Adapted for Amazon heavy output and RSS 2.0 by Antone Roundy -->
<!--
Raymond Yee yee@uclink.berkeley.edu Interactive University Project Amazon Lite to RSS 0.92 XSLT
Copyright (c) 2002 The Regents of the University of California
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this XSLT
style sheet for any purpose, provided that the above copyright notice
and the following two paragraphs appear in all copies of this
document.
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS DOCUMENT TYPE DEFINITION, EVEN IF THE
UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE COMPUTER
FILE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-->
<!-- trick from http://www.mycgiserver.com/~~lisali/papers/paper.htm -->
<!DOCTYPE stylesheet [
<!ENTITY nbsp "<xsl:text disable-output-escaping="yes"
xmlns:xsl= "http://www.w3.org/1999/XSL/Transform "
>&nbsp;</xsl:text>">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output encoding="UTF-8" method="xml" media-type="text/xml"/>
<xsl:template match="ProductInfo">
<rss version="2.0">
<channel>
<title>Amazon Search Results</title>
<link>http://www.amazon.com/</link>
<description>Amazon Search Results</description>
<xsl:apply-templates select="Details"/>
</channel>
</rss>
</xsl:template>
<xsl:template match="Details">
<item>
<title><xsl:value-of select="ProductName"/></title>
<link><xsl:call-template name="removeurlparams">
<xsl:with-param name="text" select="normalize-space(@url)"/>
</xsl:call-template></link>
<author><xsl:for-each select="Authors/Author">
<xsl:apply-templates/>
<xsl:if test="not(position()=last())">, </xsl:if>
</xsl:for-each></author>
<description>
<b>Amazon Price:</b> <xsl:value-of select="OurPrice"/><br />
<b>Customer Reviews:</b>
<xsl:apply-templates select="Reviews/CustomerReview"/>
</description>
<!-- length="1000" is not accurate, but what can we do? we don't know the size of the file -->
<xsl:choose>
<xsl:when test="contains(ImageUrlSmall,'.gif')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/gif" /></xsl:when>
<xsl:when test="contains(ImageUrlSmall,'.jpeg') or contains(ImageUrlSmall,'.jpg')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/jpeg" /></xsl:when>
<xsl:when test="contains(ImageUrlSmall,'.png')"><enclosure url="{ImageUrlSmall}" length="1000" type="image/png" /></xsl:when>
</xsl:choose>
</item>
</xsl:template>
<xsl:template match="Reviews/CustomerReview">
<br/>&raquo; <xsl:value-of select="substring(Comment,1,200)"/><xsl:if test="string-length(Comment)>200">...</xsl:if>
<xsl:if test="not(position()=last())"><br /></xsl:if>
</xsl:template>
<xsl:template name="removeurlparams">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text,'?')"><xsl:value-of select="substring-before($text,'?')"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
CaRP commercial version:

CaRP free version:
