After working with Kyle Jaebker’s Twitter Status widget I realized there was a PHP coding issue on our servers.
Kyle does a great job of outlining how to use FeedX, PHx, and a couple of custom MODx snippets to create output from your Twitter feed. Where the issue arose was with the phx:twitterdate snippet code. The DateTime function was being utilized to create a more desirable time output from the Twitter feed. The problem arose as this is labelled “experimental” in PHP 5.1.6 and is not supported by RedHat 5.3/Centos 5.3. So, the task was to mimic this function using a methodology officially supported by the latest RedHat release.
The Solution
Thank you to @swscripts for the PHP coding here. These changes apply to the phx_twitterdate.php file as provided on the Muddy Dog Paws site.
<?php
/*
* JavaScript Pretty Date
* Copyright (c) 2008 John Resig (jquery.com)
* Licensed under the MIT license.
*/
// Ported to PHP >= 5.1 by Zach Leatherman (zachleat.com)
/*
###################################
# commented out by @swscripts
$date = new DateTime($output);
$compareTo = new DateTime('now');
$diff = $compareTo->format('U') - $date->format('U');
###################################
*/
$diff = time() - strtotime($output);
$dayDiff = floor($diff / 86400);
if(is_nan($dayDiff) || $dayDiff < 0) {
return '';
}
if($dayDiff == 0) {
if($diff < 60) {
return 'Just now';
} elseif($diff < 120) {
return '1 minute ago';
} elseif($diff < 3600) {
return floor($diff/60) . ' minutes ago';
} elseif($diff < 7200) {
return '1 hour ago';
} elseif($diff < 86400) {
return floor($diff/3600) . ' hours ago';
}
} elseif($dayDiff == 1) {
return 'Yesterday';
} elseif($dayDiff < 7) {
return $dayDiff . ' days ago';
} elseif($dayDiff == 7) {
return '1 week ago';
} elseif($dayDiff < (7*6)) { // Modifications Start Here
// 6 weeks at most
return ceil($dayDiff/7) . ' weeks ago';
} elseif($dayDiff < 365) {
return ceil($dayDiff/(365/12)) . ' months ago';
} else {
$years = round($dayDiff/365);
return $years . ' year' . ($years != 1 ? 's' : '') . ' ago';
}
?>



cool…
August 28th, 2009 at 3:15 pm
Awesome – thanks for that
It's now live on http://bridesandbeauty.co.uk/
October 7th, 2009 at 12:02 pm
Love to hear it. The site looks great!
October 7th, 2009 at 12:56 pm
Awesome – thanks for that
It's now live on http://bridesandbeauty.co.uk/
October 7th, 2009 at 5:02 pm
Love to hear it. The site looks great!
October 7th, 2009 at 5:56 pm