function isMileyLegal($datetime = false, $rss = false) { global $legalage; if (!$datetime) { $datetime = currentDateTime(); } $id = $datetime->format('Ymd'); $timestamp1 = $datetime->format('U'); $timestamp2 = $legalage->format('U'); $legal = dateComp($timestamp1, $timestamp2); switch ($legal) { case 1: $title = "NO"; $descr = "Miley will be legal in "; break; case 2: $title = "YES"; $descr = "Miley has been legal for "; break; case 3: $title = "YES"; $descr = "Miley became legal today!"; $result = array($id, $title, $descr); break; default: return false; } list($y, $m, $d, $h, $i, $s, $e) = dateDiff($timestamp1, $timestamp2); if ($rss) { $d++; } $short = $descr . ($y == 0 ? "" : "{$y} year" . ($y == 1 ? "" : "s") . ", ") . ($m == 0 ? "" : "{$m} month" . ($m == 1 ? "" : "s") . ", ") . ($d == 0 ? "" : "{$d} day" . ($d == 1 ? "" : "s") . ", "); $long = $short . ($h == 0 ? "" : "{$h} hour" . ($h == 1 ? "" : "s") . ", ") . ($i == 0 ? "" : "{$i} minute" . ($i == 1 ? "" : "s") . ", "); $descr = $rss ? $short : $long; if (strrpos($descr, ",") !== false) { $descr = substr_replace($descr, ".", strrpos($descr, ",")); } if (strrpos($descr, ",") !== false) { $descr = substr_replace($descr, " and", strrpos($descr, ","), 1); } $result = array($id, $title, $descr); return $result; }
<?php include_once 'legal.php'; header('Content-type: application/rss+xml'); echo '<?xml version="1.0"?>' . "\n"; echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n"; echo "\t<channel>\n"; echo "\t\t<title>Is Miley legal?</title>\n"; echo "\t\t<link>http://www.ismileylegal.com/</link>\n"; echo "\t\t<description>Is Miley Cyrus of legal age in Australia?</description>\n"; echo "\t\t<language>en-us</language>\n"; echo "\t\t" . '<atom:link href="http://www.ismileylegal.com/rss.xml" rel="self" type="application/rss+xml" />' . "\n"; $today = currentDateTime(); $checkdate = createDateTime($today->format('Y'), $today->format('m'), $today->format('d'), 6, 0, 0); for ($x = 0; $x < 20; $x++, $checkdate->modify("-1 day")) { list($id, $title, $descr) = isMileyLegal($checkdate, true); echo "\t\t\n"; echo "\t\t<item>\n"; echo "\t\t\t<title>{$title}</title>\n"; echo "\t\t\t<description>{$descr}</description>\n"; echo "\t\t\t<link>http://www.ismileylegal.com/#{$id}</link>\n"; echo "\t\t\t<guid>http://www.ismileylegal.com/#{$id}</guid>\n"; echo "\t\t\t<pubDate>" . $checkdate->format("r") . "</pubDate>\n"; echo "\t\t</item>\n"; } echo "\t\t\n"; echo "\t</channel>\n"; echo "</rss>";