PHP RSS Family Photo Subscription Feed

I have just put the finishing touches on this. It is a php-based RSS feed. If you don't know what that is, you might want to stop reading here. Otherwise, I'm writing this to share with anyone who cares. What I've done is written a php file that searches in a directory for photos and builds an rss file out of the entries. The code sorts the images based on their modified date, such that the most recent entries appear first. I use this modified date in the <pubDate> tag on the RSS, as well.

The file is called rss.php:

PHP:
  1. function searchdir ( $path , $maxdepth = -1 , $mode = "FULL" , $d = 0 )
  2. {
  3. if ( substr ( $path , strlen ( $path ) - 1 ) != '/' ) { $path .= '/' ; }
  4. $dirlist = array () ;
  5. if ( $mode != "FILES" ) { $dirlist[] = $path ; }
  6. if ( $handle = opendir ( $path ) )
  7. {
  8. while ( false !== ( $file = readdir ( $handle ) ) )
  9. {
  10. if ( $file != '.' && $file != '..' )
  11. {
  12. $file = $path . $file ;
  13. if ( ! is_dir ( $file ) ) { if ( $mode != "DIRS" ) {
  14. $dirlist[$file] =date ("Ymd H:i:s", filectime($file));
  15.  
  16. } }
  17.  
  18. elseif ( $d>=0 && ($d <$maxdepth || $maxdepth <0) )
  19. {
  20. $result = searchdir ( $file . '/' , $maxdepth , $mode , $d + 1 ) ;
  21. $dirlist = array_merge ( $dirlist , $result ) ;
  22. }
  23. }
  24. }
  25. closedir ( $handle ) ;
  26. }
  27. if ( $d == 0 ) { arsort($dirlist);}//natcasesort ( $dirlist ) ; }
  28. return ( $dirlist ) ;
  29. }
  30. function makeDate($dateIn) {
  31. $year = substr($dateIn, 0, 4);
  32. $month = substr($dateIn, 4, 2);
  33. $day = substr($dateIn, 6, 2);
  34. $hour = substr($timestamp, 8, 2);
  35. $min = substr($timestamp, 10, 2);
  36. $sec = substr($timestamp, 12, 2);
  37. return date('D, d M Y H:i:s O', mktime($hour, $min, $sec, $month, $day, $year));
  38. }
  39. $imglist = searchdir('/home/sroberso/public_html/family/',-1,'FILES',0);
  40.  
  41. header('Content-Type: application/xml');
  42. ?>
  43. <link />http://family.robersonsoftware.com/ Check out the latest pictures of our family.
  44. en-us Wed, 25 Oct 2006 00:00:00 -0500 Wed, 01 Nov 2006 00:00:00 -0600
  45. Weblog Editor 2.0
  46. scottroberson@tempinbox.com
  47. scottroberson@tempinbox.com
  48. //$counter = 0;
  49. foreach ($imglist as $img=>$time) {if (strpos($img,"sm.jpg")>0) {
  50. $img = str_replace("'","'",$img);
  51. $img = str_replace("(","(",$img);
  52. $img = str_replace(")",")",$img);
  53. $img = str_replace(" ","%20",$img);
  54. $imgsm = substr($img,strlen('/home/sroberso/public_html/family/'));
  55. $imglg = str_replace("_sm","",$imgsm);
  56. //$counter++;
  57. echo "\n";
  58. echo "\t\n";
  59. echo "\t
  60. <link />http://family.robersonsoftware.com/".$imglg."\n";
  61. echo "\t".'&lt;a xhref="http://family.robersonsoftware.com/'.$imglg.'" mce_href="http://family.robersonsoftware.com/'.$imglg.'"  border="0" title="View Pic"&gt;&lt;img xsrc="'.$imgsm.'" mce_src="'.$imgsm.'"  border="0" /&gt;&lt;/a&gt;'."\n";
  62. echo "\t".''."\n";
  63. echo "\t ".makeDate($time)."\n";
  64. echo "\n";
  65. }
  66. }
  67. ?>

Leave a Reply