Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~
- RSS Feed by Sue Feng
- http://suefeng.net
- Edit to your liking
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* edit this section
- -------------------------------*/
- $limit = 5; //number of recent entries
- $title = "My blog"; //name of your site
- $feedurl = "http://mysite.com/rss.php"; //feed url
- $description = "Here's my blog on life and other ramblings. Enjoy!"; //blog description
- $language = "en-us"; //language your entries are written in ie en-us for American English
- $imgurl = "http://mysite.com/images/rss.gif"; //image url
- $siteurl = "http://mysite.com/blog"; //site url
- $imgwidth = 90; //number of pixels wide your image is
- $imgheight = 36; //number of pixels tall your image is
- $dateformat = "D, d M Y H:i:s T"; //format of the timestamp
- //this only works if your entries are linked based on id and use query strings
- $entryurl = "http://mysite.com/entry.php?id="; //the url of your blog post in query string format without the id
- // database variables
- $host = "localhost";
- $user = "username";
- $pass = "password";
- $database = "databasename";
- $blogtable = "blog"; //name of the table your blog is in
- /* okay no more variables,
- edit structure if you know what you're doing
- change row['timestamp'], row['id'], row['title'], row['entry']
- if those are not the row names you used.
- --------------------------------*/
- $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
- mysql_select_db($database, $linkID) or die("Could not find database.");
- $query = "SELECT * FROM $blogtable ORDER BY timestamp DESC LIMIT $limit";
- $resultID = mysql_query($query, $linkID) or die("Data not found.");
- header("Content-type: text/xml");
- $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
- $xml_output .= "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
- $xml_output .= "<channel>\n";
- $xml_output .= "<title>".$title."</title>\n";
- $xml_output .= "<atom:link href=\"".$feedurl."\" rel=\"self\" type=\"application/rss+xml\"/>\n";
- $xml_output .= "<link>".$blogurl."</link>\n";
- $xml_output .= "<description>".$description."</description>\n";
- $xml_output .= "<language>".$language."</language>\n";
- // optional, delete if you don't need it
- $xml_output .= "<image>\n";
- $xml_output .= "<title>".$title."</title>\n";
- $xml_output .= "<url>".$imgurl."</url>\n";
- $xml_output .= "<link>".$siteurl."</link>\n";
- $xml_output .= "<width>".$imgwidth."</width>\n";
- $xml_output .= "<height>".$imgheight."</height>\n";
- $xml_output .= "</image>\n";
- // end optional
- for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
- $row = mysql_fetch_assoc($resultID);
- $timestamp = strtotime($row['timestamp']);
- $timestamp = date($dateformat, $timestamp);
- $xml_output .= "\t<item>\n";
- $xml_output .= "\t\t<title>" . $row['title'] . "</title>\n";
- $xml_output .= "\t\t<link>".$entryurl . $row['id'] . "</link>\n";
- $xml_output .= "\t\t<pubDate>" . $timestamp . "</pubDate>\n";
- $id = $row['id'];
- $xml_output .= "<guid isPermaLink=\"false\">".$entryurl.$id."</guid>";
- // Escaping illegal characters
- $row['entry'] = str_replace("&", "&", $row['entry']);
- $row['entry'] = str_replace("\"", """, $row['entry']);
- $description = strip_tags($row['entry'], '<br />');
- $row['entry'] = str_replace("<", "<", $row['entry']);
- $row['entry'] = str_replace(">", ">", $row['entry']);
- $len = strlen($description);
- $delim = " [...]";
- $n = 200;
- if ($len > $n) {
- preg_match('/(.{' . $n . '}.*\s)\b/', $description, $matches);
- $description = rtrim($matches[1]) . $delim;
- }
- else {
- $description = $description;
- }
- $xml_output .= "\t\t<description>" . $description . "</description>\n";
- $xml_output .= "\t\t<content:encoded>" . $row['entry'] . "</content:encoded>\n";
- $xml_output .= "\t</item>\n";
- }
- $xml_output .= "</channel>";
- $xml_output .= "</rss>";
- echo $xml_output;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement