<?php header('Content-type: text/xml'); 
include ('config.ini.php');
?>
<rss version="2.0">
<channel>
<title><?php echo $title; ?> Wallpaper</title>
<description><?php echo $title; ?> Wallpapers added daily</description>
<link>http://wallpaper.celebritypc.com/<?php echo $url; ?>/</link>

<?php

if(ereg("\.\.", $_GET['d']))
  header ("Location: ?");

$pwidth = 186;
$pheight = 177;

function getfilesize($size) // gets file size for each image
{
  $units = array(' B', ' KB', ' MB', ' GB', ' TB');
  for ($i = 0; $size > 1024; $i++) { $size /= 1024; }
  return round($size, 2).$units[$i];
}

function this_folder_name($path){
   if (!$path){$path=$_SERVER['PHP_SELF'];}
   $current_directory = dirname($path);
   $current_directory = str_replace('\\','/',$current_directory);
   $current_directory = explode('/',$current_directory);
   $current_directory = end($current_directory);
   return $current_directory;
}

if($_GET['d']) // d variable is in URL string, used for navigating subdirectories
{
  $d = $_GET['d'].'/';
  $dd = 'd='.$_GET['d'].'&'; // for use in passing to URL strings
  $current_dir .= $d;
}

 opendir($current_dir); // open the dir to browse for images

//----------- Create list of Images

$list = array();

if ($dir = opendir('./'.$current_dir))
{
  while ($file = readdir($dir))
  {
    if (eregi('.jpg', $file)) //If file is a JPG
      $list[] = $file;
  }
    closedir($dir);
}

asort($list); // sort alpha
$numtotal = count($list); //total number of thumbs

if ($thumb)
{
  $s = 0;
  while($s < $thumb)
  {
    array_shift($list);
    $s++;
  }
}
$numremain = count($list); // total remaining thumbs in the array (folder)

foreach ($list as $pic)
{
   	$fp = $current_dir.$pic;
   	if($i < $numtotal)
   	{
	  $image = $currentdir.$pic;
	  $i_size = getfilesize(filesize($fp));
	  $i_area = getimagesize($fp);
	  $i_width = $i_area[0];
	  $i_height = $i_area[1];
	  $name = str_replace('.jpg', '', $pic);
    $pic2 = str_replace('.jpg','.htm',$pic);
echo "<item>\n";
echo "<title>".$title." Wallpaper</title>\n";
echo "<description><![CDATA[<p><a href='http://wallpaper.celebritypc.com/download-".this_folder_name($path)."/$current_dir$pic2'>";
echo "<img align=left border=0 src='http://wallpaper.celebritypc.com/".$url."/small/$d$pic' hspace=5 vspace=5 width=180 height=135 alt='".$title." Wallpaper'></a>".$title." Wallpaper added on ".date("m/d/y", filemtime($current_dir.$pic))." - $i_width x $i_height - [$i_size]</p><br clear=all />]]></description>\n";
echo "<link>http://wallpaper.celebritypc.com/download-".this_folder_name($path)."/$current_dir$pic2</link>\n";
echo "<pubDate>".date("m/d/y", filemtime($current_dir.$pic))."</pubDate>";
echo "</item>\n";  
}
  $i++;
	}
?>
</channel>
</rss>
