<?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="iso-8859-1"?>';

?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<?php

echo "<url>
<loc>".$clienturl."</loc>
<priority>1.0</priority>
</url>";


 if ($clienttype==="blog") {







				for ( $counter = $lastKey; $counter >= 0; $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="', '"');

if(strpos($link, "/id") === false){
} else {

$newlink = explode("/", $link);


$link = "/".ltrim($newlink['1'],"/id")."/".$newlink['3'];

}


$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 "<url>\n";
// echo "<title>".$title."</title>\n";
echo "<loc>".$link."</loc>\n";
// echo "<pubDate>".$curdated."</pubDate>\n";
// echo "<guid>".$link."</guid>\n";
echo "<priority>0.7</priority>\n";

// echo "<description><![CDATA[<img src=\"".$image."\" width=\"400\"><br>\n".$description."]]></description>\n";
echo "</url>\n";




}


				}



} else {



	for ( $counter = $lastKey; $counter >= 0; $counter--) {



	$blogfile = $dir[$counter];





// $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 "<url>\n";
echo "<loc>".$link."</loc>\n";
echo "<priority>0.7</priority>\n";
echo "</url>\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);
}


?>










</urlset>