function switchMenu(obj) { var el = document.getElementById(obj); if ( el.style.display != 'none' ) { el.style.display = 'none'; } else { el.style.display = ''; } } \n"; } echo '

'.$microblogtitle; //Set important times - $tdtime is today's date, $oldtime is the oldest known date a tCMS install had nuze for - defaults to today then searches microblog dir for entries to set date $tdtime = new DateTime(null, new DateTimeZone($timezone)); $oldtime = clone $tdtime; //limit results of directory read to first entry function &oldtimer($timezone, $basedir, $microblogdir) { if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].'/'.$basedir.$microblogdir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $oldtime = DateTime::createFromFormat('m.d.y', $entry, new DateTimeZone ($timezone)); closedir($handle); return($oldtime); } } } }; $oldtime = &oldtimer($timezone, $basedir, $microblogdir); $oldtime->sub(new DateInterval('P1D')); //$today and $tmrw refer to times relative to what is passed by GET params - $today is the date requested by GET, $tmrw is bool designating whether $today is something other than $tdtime //error indicates whether you supplied a bogus GET param for date. $tmrw = 0; $error = 0; $today = clone $tdtime; if ($_GET["date"] != "") { $today = DateTime::createFromFormat('m.d.y', $_GET["date"], new DateTimeZone ($timezone)); //Catch bogus input, set $tmwr to TRUE if $today was set to something other than today's date if (!filter_var($_GET["date"],FILTER_VALIDATE_REGEXP,array('options' => array('regexp' => "/^(0[1-9]|1[012])[.](0[1-9]|[12][0-9]|3[01])[.]\d\d/")))) { echo "

That's a funny looking date you provided there, mister.\n"; $error=1; } else if ($today > $tdtime) { //catch if day supplied by GET is IN THE FUTURE echo "

Welcome to the future
\n"; $error=1; } else if ($today < $tdtime) { $tmrw = 1; } } //Catch if day in question has no news - If not, display day before (or before that if still no news. $oldtime used here to tell when to stop looping back) if (!$error) { while (empty($todaysnews)) { $yesterday = clone $today; $yesterday->sub(new DateInterval('P1D')); //Detect if We're at the end of postings if ($yesterday < $oldtime) { echo " (".$today->format('m.d.y')."):


"; echo "For me, it was a beginning, but for you it is the end of the road.

\n"; if ($oldtime != $tdtime) { $tomorrow = clone $oldtime; $tomorrow->add(new DateInterval('P1D')); $tomorrow = $tomorrow->format('m.d.y'); } $todaysnews = "end"; } if ($todaysnews != "end") { //Get news from directory if any exists for that day $todaysnews = glob($_SERVER["DOCUMENT_ROOT"].'/'.$basedir.$microblogdir.$today->format('m.d.y')."/*"); //Set display date for today's news, set $today to be yesterday in order to get while loop to recurse correctly $realtime = $today->format('m.d.y'); $today = clone $yesterday; //Finish by setting times for Yesterday and Tomorrow so that they can be used in links below $tomorrow = clone $yesterday; $tomorrow->add(new DateInterval('P2D')); $tomorrow = $tomorrow->format('m.d.y'); $yesterday = $yesterday->format('m.d.y'); } } if ($todaysnews != "end") { echo " (".$realtime."):


\n"; foreach ($todaysnews as $i) { $fh = fopen($i,'r'); $fc = fread($fh,10000); //If a microblog item is more than 1kb, you are doing something wrong. fclose($fh); $json = json_decode($fc); if(is_null($json)) { echo $fc; } elseif (isset($json->title) && isset($json->url) && isset($json->poster)) { $out = '

'; $out = $out.''.$json->title.''; $out = $out.'

'; if(isset($json->image)) { $out = $out.''; } if(isset($json->audio)) { $out = $out.''; } if(isset($json->video)) { $out = $out.''; } if(isset($json->comment)) { $out = $out.$json->comment; } $out = $out.'
'; echo $out; } #Note that if nothing works out here, I'm just opting not to show anything. if ($editable) { $id=basename($i); echo " [Edit]

"; } echo "\n"; } echo "Yesterday's News\n"; } if ($tmrw) { echo "Tomorrow's News\n"; } } ?>