Posted By

hasantayyar on 07/11/09


Tagged

php rss


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

hasantayyar
techdetours


AutoRSS


 / Published in: PHP
 

URL: http://www.phpclasses.org/browse/file/27304.html

When you have many image files that you want to make available on the Web, it useful to drop them in a single directory and let your users know when new images are available.

This class provides a solution that lets your users be aware of new files by subscribing to RSS feeds.

  1. <?php /* CLASS AUTORSS V 1.0 Autor : Roberto Aleman Email : ventics@gmail.com
  2. This class is to automatic read and show  the files in a directory as rss 2.0 version,
  3. only configure the config.php file with de globals vars and xml and rss versions,
  4. the directory path and put config, callfile and autorss in directory to show at rss channel.
  5. i apply to read a folder of images and show images gallery to rss channel with feedreader. Enjoy!!
  6. GENERAL PUBLIC LICENCE , GPL */
  7. class autorss
  8. {
  9.     public function show($document_type,$path,$xmlversion,$encoding,$rssversion,$atomversion,$title,$homelink,$description,$language,$lastupdate,$callfile,$generator,$permalink,$category)
  10.     {
  11.         header($document_type)// define document type header
  12.         $dir=getcwd()// get directory where is script
  13.         $dr=@opendir($dir)//asign path to $dr var
  14.         if(!$dr){
  15.             echo "<error/>"//if error, stop! and exit!
  16.             exit;
  17.         return;
  18.         }
  19.         else
  20.         { //begin write xml file whith vars
  21. echo "<?xml version='".$xmlversion."' encoding='".$encoding."'?>
  22. <rss version='".$rssversion."' xmlns:atom='".$atomversion."'>
  23. <channel>
  24. <atom:link href='".$path."' rel='self' type='application/rss xml'/>
  25. <title>".$title."</title>
  26. <link>".$homelink."</link>
  27. <description>".$description."</description>
  28. <language>".$language."</language>
  29. <lastBuildDate>".$lastupdate."</lastBuildDate>
  30. <generator>".$generator."</generator>";
  31.             while (($archivo = readdir($dr)) !== false)
  32.         {
  33.                 if($archivo!="autorss.php" AND $archivo!="." AND $archivo!=".." AND $archivo!="error_log" AND $archivo!=$callfile )
  34.                 {
  35.                 clearstatcache() ;
  36.                         $info = lstat($archivo);
  37.  
  38. echo "
  39. <item>
  40. <title>".$path.$archivo."</title>
  41. <link>".$path.$archivo."</link>
  42. <pubDate>".date('r' ,$info[9])."</pubDate>
  43. <description><![CDATA[<img src=".$path.$archivo."></img><br/>File Size :".$info[7]." Bytes, Modified:".date('r',$info[9])."]]></description>
  44. <guid isPermaLink='".$permalink."'>".$path.$archivo."</guid>
  45. <category domain='".$path."'>".$category."</category>
  46. </item>";
  47.                 }
  48.         }
  49. echo "</channel></rss>";
  50.             closedir($dr);
  51.             return;
  52.         }
  53.     }
  54. }
  55. ?>

Report this snippet  

You need to login to post a comment.