amazonRSSwriter: create Amazon RSS feeds automatically
Saturday, January 14, 2006
This is a new script that I have created just to provide easy Amazon RSS feeds on different subjects. You can try the script here. Simply enter a word or a few words and the script will return an Amazon RSS feeds with books related to the search terms.
The whole script is here:
------------------------------------------------------
------------------------------------------------------
The whole script is here:
------------------------------------------------------
<?php
/*
Project: AmazonRSSwriter: Amazon URL RSS writer
File: amazonRSSwriter.php
Author: hombrelobo <minilobo@gmail.com>
Version: 0.50
For the latest version of the writer, questions, help, comments,
etc., please visit:
http://wolfb.com/2006/01/amazonrsswriter-create-amazon-rss.html
http://wolfb.com/
What is AmazonRSSwriter ?
Sometimes is convenient to have RSS feeds of Amazon products, to
keep track of new books in a certain topic. This script uses Amazon
services to create a simple one.
You can see it in action in:
http://wolfb.com/rss/amazonrsswriter.php
Enjoy it !!
******************************************************************************
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.
This work is hereby released into the Public Domain. To view a copy of
the public domain dedication, visit
http://creativecommons.org/licenses/publicdomain/ or send a letter to
Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
******************************************************************************
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Amazon RSS writer</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META NAME="KEYWORDS" CONTENT="Amazon, RSS, writer">
<META NAME="DESCRIPTION" CONTENT="Amazon RSS writer, create your own feeds">
<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
</head>
<body><br>
<?php
// Sends an email if the form has been submitted
if ($_POST['send'])
{
//Affiliate link code
//http://xml.amazon.com/onca/xml3?t=deustocom&dev-t=amznRss&KeywordSearch=rss&mode=books&sort=+daterank&offer=All&type=lite&page=1&f=http://xml.amazon.com/xsl/xml-rss091.xsl
$basic_link= "http://xml.amazon.com/onca/xml3?t=deustocom&dev-t=amznRss&KeywordSearch=SEARCHWORD&mode=books&sort=+daterank&offer=All&type=lite&page=1&f=http://xml.amazon.com/xsl/xml-rss091.xsl";
$term=$_POST[texto];
// First we replace all the spaces with %20
$term = preg_replace('/\ \b/i', '%20',$term);
$find = '/\SEARCHWORD\b/i';
$replacement = $term;
// Now we replace the search terms in the feed.
$content = preg_replace($find, $replacement,$basic_link);
// And now we output the feed and the subscription links:
ECHO <<<END
This is the URL of your feed:<br><br>
$content<br><br>
And you can subscribe to it here:<br><br>
<a href="$content" title="Subscribe to my feed"><img src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="border:0"/></a>
<a href="http://add.my.yahoo.com/rss?url=$content" title="RSS books in Amazon"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif" alt="" style="border:0"/></a>
<a href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=$content" title=""><img src="http://www.newsgator.com/images/ngsub1.gif" alt="Subscribe in NewsGator Online" style="border:0"/></a><br><br>
<a href="http://fusion.google.com/add?feedurl=$content"><img src="http://buttons.googlesyndication.com/fusion/add.gif" width="104" height="17" style="border:0" alt="Add to Google"/></a><br><br>
<a href="http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&a=$content"><img src="http://www.pluck.com/images/pluck/pluspluck.png"/></a><br><br>
<a href="http://www.bloglines.com/sub/$content" title="" type="application/rss+xml"><img src="http://www.bloglines.com/images/sub_modern1.gif" alt="Subscribe in Bloglines" style="border:0"/></a><br><br>
END;
}
else
{
?>
<table>
<td width="60%"align="left" valign="top">
<?php echo "Amazon RSS writer script" ?> <br><br>
<?php echo "Create your own Amazon RSS feeds easily with this script" ?> <br><br>
<?php echo "Type the search terms for the feed:" ?>
<br>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<p><?php echo "Term:" ?><br>
<textarea rows="1" name="texto" cols="56"></textarea></p>
<p><input type="submit" name="send" value="send"></p>
</form>
</td>
</table>
<a href="http://wolfb.com">hombrelobo</a>
<?php
} //end else
?>
</body></html>
------------------------------------------------------
playRSSwriter: a RSS 2.0 feed writer with support for images
Sunday, January 01, 2006
What is playRSSwriter ?
When working on creating a rss feed for our site Playlingerie.com, we realized that all the existing php writers were either for rss 1.0 or for rss 2.0 but without support for embeded images. So I created this code.
You can see it in action in:
http://feeds.feedburner.com/sexy-lingerie
Code:
------------------------------------------------------
------------------------------------------------------
When working on creating a rss feed for our site Playlingerie.com, we realized that all the existing php writers were either for rss 1.0 or for rss 2.0 but without support for embeded images. So I created this code.
You can see it in action in:
http://feeds.feedburner.com/sexy-lingerie
Code:
------------------------------------------------------
<?php
/*
Project: playRSSwriter: RSS 2.0 writer with images support
File: playRSSwriter.php
Author: hombrelobo <minilobo@gmail.com>
Version: 0.95
For the latest version of the writer, questions, help, comments,
etc., please visit:
http://wolfb.com/2006/01/playrsswriter-rss-20-feed-writer-with_01.html
What is playRSSwriter ?
When working on creating a rss feed for our site http://playlingerie.com,
we realized that all the existing php writers were either for rss 1.0 or for
rss 2.0 but without support for embeded images. So I created this code.
You can see it in action in:
http://feeds.feedburner.com/sexy-lingerie
Enjoy it !!
******************************************************************************
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.
This work is hereby released into the Public Domain. To view a copy of
the public domain dedication, visit
http://creativecommons.org/licenses/publicdomain/ or send a letter to
Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
******************************************************************************
*/
// First we start defining all the variables that we will insert in the
// xml code.
// Insert here the the title of your feed
$rss_title= "Title of your feed";
// Insert your site, in the format site.com
$rss_site= "site.com" ;
// Insert the description of your website
$rss_description= "Description of your website";
// Applicable language of the feed. For spanish, change to "es"
$rss_language="en";
// Address of the logo file. Only need to put the file name
$rss_logo="http://".$rss_site."logo.jpg";
// the feed's author email
$emailadmin="email@site.com";
// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=iso-8859-1");
$phpversion = phpversion();
//set the beginning of the xml file
ECHO <<<END
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
<channel>
<title>$rss_title</title>
<link>http://www.$rss_site</link>
<description>$rss_description</description>
<language>$rss_language-$rss_language</language>
<docs>http://backend.userland.com/rss</docs>
<generator>PHP/$phpversion</generator>
<image>
<url>$rss_logo</url>
<title>$rss_site</title>
<link>http://$rss_site/</link>
</image>
END;
// Now the variables about the individual items to appear in the feed. Here we
// take them from a MySQL database, but can also come from a included file
// Define database
$server = "localhost"; // Server
$rss_database = "name_of_the_database" ; // Database name
$db_user ="user" ; // Database user
$db_pass = "password" ; // Database password
// Open the database
$db = mysql_connect($server,$db_user,$db_pass);
mysql_select_db($rss_database,$db);
// Calculate the number of records in the table "Products"
$num_rows = mysql_num_rows(mysql_query("select * from Products"));
// Select all the records from the table "Products". You can modify the
// query to only select some records, change the order, etc.
$query = "select * from Products" ;
$result = mysql_query($query) or die("Query failed") ;
//Make a loop to create the feed for all the items selected
while ($results = mysql_fetch_array($result))
{
// Pass the database field Photo_name to the variable $photo_name
// The Photo_name has to include the relative path,
// for instance: $photo_name="images/photo1.jpg";
$photo_name = $results['Photo_name'] ;
// Pass the record URL_product to the variable $url_product. It also
// has to include the relative path, like in: "path/product1.htm"
$url_product = $results['URL_product'] ;
// Pass the record Description to the variable $description
$description = $results['Description'] ;
// Clean the description
$description = str_replace ("&","",htmlspecialchars(stripslashes($description)));
// Pass tags to describe the product
$rss_tags = $results['Product_tags'] ;
// If you don't have tags for the product, simply change to a fixed value,
// for instance put:
// $rss_tags="tag1 tag2";
// Make a short description for titles of only 75 characters
$short_description = substr($description,0,75) . "...";
$counter ++ ;
// Calculate the size of the image and resize it to a thumbnail
$photo_size= getimagesize($photo_name) ;
$photo_width = $photo_size[0] ;
$photo_height = $photo_size[1] ;
unset($height_limit,$width_limit) ;
if ($photo_height > $photo_width )
$photo_height= "90" ;
else
$photo_width = "80" ;
// Create the html for the description item. No need to modify this unless
// you want to change the look
$content="<p><a href=\"http://$rss_site/$url_product\">$description</a></p>
<p><a href=\"http://$rss_site/$url_product\" title=\"$description\"><img src=\"$photo_name\" width=\"$photo_width\" height=\"$photo_height\" alt=\"$short_description\" style=\"border: 1px solid #000000;\" /></a></p>
<p>$rss_site</p>" ;
// Escape all the descriptions
$content = preg_replace(array('/</', '/>/', '/"/'), array('<', '>', '"'), $content);
// display an item
ECHO <<<END
<item>
<title>$short_description</title>
<link>
http://$rss_site/$url_product
</link>
<description>
$content
</description>
<author>$emailadmin</author>
<media:content url="$photo_name" type="image/jpeg" height="$photo_height" width="$photo_width"/>
<media:title>$description</media:title>
<media:text type="html">
<p><a href="http://$rss_site/$url_product">$description</a></p>
<p><a href="http://$rss_site/$url_product" title="$short_description"><img src="$photo_name" width="$photo_width" height="$photo_height" alt="$short_description" style="border: 1px solid #000000;" /></a></p>
<p>$rss_site</p>
</media:text>
<media:thumbnail url="$photo_name" height="$photo_height" width="$photo_width"/>
<media:category scheme="urn:$rss_site:tags">
$rss_tags
</media:category>
</item>
END;
}
// Close the database
mysql_close();
// And end the xml file
ECHO <<<END
</channel>
</rss>
END;
// Done !! Use http://feedvalidator.org to verify that it's correct.
?>
------------------------------------------------------
Other random articles from wolfb
Powered by Stuff-a-Blog


Add to del.icio.us










