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 -- much faster than doing it with PHP once you get a large filelist. exec("ls -tr1 ".$_SERVER["DOCUMENT_ROOT"].'/'.$basedir.$microblogdir." |head -1", $cmd_out); if(!empty($cmd_out[0])) { $oldtime = $oldtime = DateTime::createFromFormat('m.d.y', $cmd_out[0], new DateTimeZone($timezone)); } $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(!empty($_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)) { $todaysnews = ""; //Set it to be something empty to prevent logspam $yesterday = clone $today;//This may look strange, but it'll make sense later $tomorrow = clone $today; $tomorrow->add(new DateInterval('P1D')); $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, glob will return empty if nothing is in dir $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'); if(!empty($_GET['fwd']) && $_GET['fwd']) {//Check whether we are traversing forward or backward in time $today = clone $tomorrow; } else { //Default to going back $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 (!empty($json->title) && !empty($json->url) && !empty($json->poster)) { $out = '

'.$json->title.'

'; if(!empty($json->image)) { $out .= ''; } if(!empty($json->audio)) { $out .= ''; } if(!empty($json->video)) { $out .= ''; } if(!empty($json->comment)) { $out .= $json->comment; } $out .= '
'; echo $out; } #Note that if nothing works out here, I'm just opting not to show anything. if ($editable) { $id=basename($i); $editblock = " [Edit]
"; if(is_null($json)) { $editblock .= ""; } else { $editblock .= ' Title:
URL:
Image:
Audio:
Video:
Comments: '; } $editblock .= "

"; echo $editblock; } } echo "Older Entries\n"; } if ($tmrw) { echo "Newer Entries\n"; } } ?>