<?PHP

@include 'clientcfg.php';

$dir = glob("date*.php");
sort($dir);


$keys = array_keys($dir);
$lastKey = end($keys);

$datefile = $dir[$lastKey];

$date = str_replace("date", "", $datefile);
$date = str_replace(".php", "", $date);


$lastdated = date('D, d M Y H:i:s O', strtotime($date));



function getcount($id) {

$localcount = "cstorage/count".$id.".txt";

	if (file_exists($localcount)) {
		$fil = fopen($localcount, r);
		$dat = fread($fil, filesize($localcount));
		$count = $dat;
		fclose($fil);
	} else {
		$count = '0';
	}


return $count;

}




function array_in_array($needle, $haystack) {
  foreach ($haystack as $key => $value) {

//  echo "<br>datefile:". $needle;



//  echo "<br>value:". $value;

   if ($needle === $value)
     return $key;
  }
  return false;
}




echo '<?xml version="1.0" encoding="UTF-8"?>';

?>





<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
>

<channel>
<atom:link href="<? echo $clienturl; ?>/rss.xml" rel="self" type="application/rss+xml" />
<title><? echo $clientname; ?></title>
<link><? echo $clienturl; ?></link>
<description><? echo $clientdescription; ?></description>
<lastBuildDate><? echo $lastdated; ?></lastBuildDate>
<ttl>20</ttl>





<?php


 if ($clienttype==="blog") {







				for ( $counter = $lastKey; $counter >= $lastKey-9; $counter--) {



				$blogfile = $dir[$counter];


	if (file_exists($blogfile)) {
						$fil = fopen($blogfile, r);
						$dat = fread($fil, filesize($blogfile));
						fclose($fil);
	}


$date = str_replace("date", "", $blogfile);
$date = str_replace(".php", "", $date);


// $curdated = date('M.j', strtotime($date));
$curdated = date('D, d M Y H:i:s O', strtotime($date));


$description = get_string_between($dat, '<p class="vidlistdesc">', '</p>');

$title = get_string_between($dat, 'title="', '"');

$link = get_string_between($dat, '<a href="', '"');
$link = $clienturl.$link;
$image = get_string_between($dat, '<img src="<? echo $clientbase."', '" ?>"');
$image = $clientbase.$image;


$title = str_replace("&", "&amp;", $title);
$description = str_replace("&", "&amp;", $description);
$link = str_replace("&", "&amp;", $link);


echo "<item>\n";
echo "<title>".$title."</title>\n";
echo "<link>".$link."</link>\n";
echo "<pubDate>".$curdated."</pubDate>\n";
echo "<guid>".$link."</guid>\n";

echo "<description><![CDATA[<img src=\"".$image."\" width=\"400\"><br>\n".$description."]]></description>\n";
echo "</item>\n\n\n";







				}



} else {



$blogfile = $dir[$lastKey];


	if (file_exists($blogfile)) {
						$fil = fopen($blogfile, r);
						$dat = fread($fil, filesize($blogfile));
						fclose($fil);
	}




$date = str_replace("date", "", $blogfile);
$date = str_replace(".php", "", $date);
// $curdated = date('M.j', strtotime($date));
$curdated = date('D, d M Y H:i:s O', strtotime($date));


$datpieces = explode("<li>", $dat);



foreach($datpieces as $dat) {



$description = get_string_between($dat, '<p class="vidlistdesc">', '</p>');

$description = strip_tags($description);

$title = get_string_between($dat, 'title="', '"');

$link = get_string_between($dat, '<a href="', '"');
$link = $clienturl.$link;
$image = get_string_between($dat, '<img src="<? echo $clientbase."', '" ?>"');
$image = $clientbase.$image;


$title = str_replace("&", "&amp;", $title);
$description = str_replace("&", "&amp;", $description);
$link = str_replace("&", "&amp;", $link);


if ($title!='') {

echo "<item>\n";
echo "<title>".$title."</title>\n";
echo "<link>".$link."</link>\n";
echo "<pubDate>".$curdated."</pubDate>\n";
echo "<guid>".$link."</guid>\n";

echo "<description><![CDATA[<img src=\"".$image."\" width=\"100\"><br>\n".$description."]]></description>\n";
echo "</item>\n\n\n";

}

}







}



function get_string_between($string, $start, $end){
	$ini = strpos($string,$start);
	if ($ini == 0) return null;
	$ini += strlen($start);
	$len = strpos($string,$end,$ini) - $ini;
	return substr($string,$ini,$len);
}


?>










</channel>
</rss>