This class can be used to generate a RSS feed from files pf a directory.
It can read the list of files available in a given server directory and generates an RSS 2.0 feed with the list of files.
The base URL for the files and other details are configurable options.
index.php
<?php
/* Class AutoRSS v 1.0
Autor : Roberto Aleman
Email : ventics@gmail.com
General Public Licence , GPL */
// call to auto rss class
require_once("autorss.php");
//create new object
$newrss = new autorss();
/* example of use and orden of vars :
$document_type : document type, default : Content-type:text/xml
$path: absolute path of your folder, example path : http://ventics.com/autorss/
$xmlversion : XML file version , default : 1.0
$encoding : encondig : default :utf-8
$rssversion : RSS version, default : 2.0
$atomversion : ATOM version , default : http://www.w3.org/2005/Atom
$title: Title of your RSS autoengine channel : example: CLASS AUTORSS
$homelink: Link os your RSS autoengine channerl: example: http://www.ventics.com/autorss/
$description: description about your autoengine channel : example : CLASS AUTORSS TEST by ROBERTO ALEMAN
$language: language of xml file definition , ISO format is require, example: en-us
$lastupdate: Date of last update xml file autoengine, example : Sun, 31 May 2009 09:41:01 GMT
$callfile: file to calle autorss class, example : index.php
$generator: channel generator
$permalink: if permalink? true or false
$category: category of each file
change log :
22/06/09: Add tags : generator in channel definition and pubDate, isPermalink, category domain in item definition
and add lstat option to get info about file, where:
$info[7], size in bytes
$info[9], 9 mtime last modified (Unix time)
*/
//send parameters and engine rss
$newrss->show("Content-type:text/xml","http://localhost/autorss/", "1.0","utf-8","2.0","http://www.w3.org/2005/Atom","CLASS AUTORSS","http://localhost/autorss/","CLASS AUTORSS TEST by ROBERTO ALEMAN","en-us","Sun, 31 May 2009 09:41:01 GMT","index.php","CLASS AUTORSS","true","My Pics");
?>
autorss.php
<?php
/* CLASS AUTORSS V 1.0 Autor : Roberto Aleman Email : ventics@gmail.com
This class is to automatic read and show the files in a directory as rss 2.0 version,
only configure the config.php file with de globals vars and xml and rss versions,
the directory path and put config, callfile and autorss in directory to show at rss channel.
i apply to read a folder of images and show images gallery to rss channel with feedreader. Enjoy!!
GENERAL PUBLIC LICENCE , GPL */
class autorss
{
public function show($document_type,$path,$xmlversion,$encoding,$rssversion,$atomversion,$title,$homelink,$description,$language,$lastupdate,$callfile,$generator,$permalink,$category)
{
header($document_type); // define document type header
$dir=getcwd(); // get directory where is script
$dr=@opendir($dir); //asign path to $dr var
if(!$dr){
echo "<error/>"; //if error, stop! and exit!
exit;
return;
}
else
{ //begin write xml file whith vars
echo "<?xml version='".$xmlversion."' encoding='".$encoding."'?>
<rss version='".$rssversion."' xmlns:atom='".$atomversion."'>
<channel>
<atom:link href='".$path."' rel='self' type='application/rss+xml'/>
<title>".$title."</title>
<link>".$homelink."</link>
<description>".$description."</description>
<language>".$language."</language>
<lastBuildDate>".$lastupdate."</lastBuildDate>
<generator>".$generator."</generator>";
while (($archivo = readdir($dr)) !== false){
if($archivo!="autorss.php" AND $archivo!="." AND $archivo!=".." AND $archivo!="error_log" AND $archivo!=$callfile ) {
clearstatcache() ;
$info = lstat($archivo);
echo "
<item>
<title>".$path.$archivo."</title>
<link>".$path.$archivo."</link>
<pubDate>".date('r' ,$info[9])."</pubDate>
<description><![CDATA[<img src=".$path.$archivo."></img><br/>File Size :".$info[7]." Bytes, Modified:".date('r',$info[9])."]]></description>
<guid isPermaLink='".$permalink."'>".$path.$archivo."</guid>
<category domain='".$path."'>".$category."</category>
</item>";
}
}
echo "</channel></rss>";
closedir($dr);
return;
}
}
}
?>