<?
header('Content-Type: text/xml');
$make = $_GET['make'];
//=============================================================
$cachefile = "_cache/$make-wiper-blades.xml";
include 'includes/cachetime.php';
//$cachetime = 0;
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
    include($cachefile);
    //echo "\n<!-- generated ".date('M d @ H:i', filemtime($cachefile))." -->";
    exit;
}
ob_start(); // Start the output buffer
//=============================================================
include('includes/db.php');
$urlmake = $make;
$make = str_replace("-"," ",$make);

$sitelink = $siteurl . "/";

//find out if make should be all uppercase.
$myqueryu = "select distinct allupper from " . $tablename . " where (make = '$make') limit 1;";
$quick = mysqli_query($db,$myqueryu);
	while ($row = mysqli_fetch_assoc($quick)) {
		$allupper = ($row['allupper']);
		if ($allupper == 1) {
			$displaymake = strtoupper($make);
		} else {
			$displaymake = ucwords($make);
		}
	}

$myquery = "select distinct model from " . $tablename . " where (make = '$make') limit 100;";
//echo $myquery;
//exit;
$results = mysqli_query($db,$myquery);
$num = mysqli_num_rows($results);

$feedtitle = "$displaymake Model Wiper Blade Sizes";
$feedlink = "http://mywiperblades.com/$make-wiper-blades.xml";
$feeddescription = "Wiper Blades by Model";
$feedtimezone = "EST";
$tm=time();  // time stamp of the present time
$tm=date("D, d M Y H:i:s",$tm-1000); // generating the format
$tm=$tm. " $feedtimezone"; // added GMT but you can add your format

echo "<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>\n";
echo "<channel>\n";
echo "<atom:link href='$feedlink' rel='self' type='application/rss+xml'/>\n";
echo "<title>" . $feedtitle . "</title>\n";
echo "<link>" . $feedlink . "</link>\n";
echo "<description>" . $feeddescription . "</description>\n";
echo "<managingEditor>" . $siteemail . "(Mike)</managingEditor>\n";
echo "<generator>$keyword rss creator</generator>\n";
echo "<lastBuildDate>" . $tm . "</lastBuildDate>\n";
echo "<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";

//-----------------------------------------------------------------------

while ($row = mysqli_fetch_assoc($results)) {
	$model = strtolower($row['model']);
	$urlmodel = str_replace(" ","_",$model);
	$urlmodel = str_replace("/","~",$urlmodel);
	$url = "$urlmake/$urlmodel.htm";
	$description = "Wiper blade sizes for $displaymake $model vehicles. Select model then choose the year to find the wiper blade size.";


	echo "<item>\n";
	echo "<title>" . htmlspecialchars(ucwords($model)) . "</title>\n";
	echo "<link>" . $siteurl . "/" . $url . "</link>\n";
	echo "<description>" . htmlspecialchars($description) . "</description>\n";
	echo "<author>" . $siteemail . " (mywiperblades.com)</author>\n";
	echo "<pubDate>" . date(DATE_RFC2822) . "</pubDate>\n";
	echo "<guid>\n";
	echo $siteurl . "/" . $url;
	echo "\n</guid>\n";
	echo "</item>\n";
}

	echo "</channel>\n";
	echo "</rss>";

mysqli_close($db);

/* The code to dynamically generate the page goes here */
// Cache the output to a file
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_flush(); // Send the output to the browser
