Firstly, I’m not a programmer so I’m sure there may well be better ways to do this, please feel free to post improvements!
OK, I’ve attached the Twitter TPL, just drop that into your FeedX tpl directory.
Then you need to set-up two snippets:
Call the first one "phx:str2twit" and paste the following:
<?php
$twit = substr($output, 12);
return $twit;
?>
In the above code you need to edit the number "12" to correspond to the length of your Twitter username as this code cuts it from your updates.
Call the second one "phx:str2timesince" and paste the following:
<?php
if (!function_exists('timeSince'))
{
function timeSince($timestamp)
{
if ($timestamp >= time())
{
$timeago = '0 seconds ago';
return $timeago;
}
$seconds = time()-$timestamp;
$units = array(
'year' => 31556926,
'month' => 2629743,
'day' => 86400,
'hour' => 3600,
'minute' => 60,
// 'second' => 1
);
$timeago = '';
foreach ($units as $key => $val)
{
if ($seconds >= $val)
{
$results = floor($seconds/$val);
$seconds = ($seconds-($results*$val));
$timeago .= ($results >= 2) ? $results . ' ' . $key . 's, ' : $results . ' ' . $key . ', ';
}
}
return rtrim($timeago, ', ') . ' ago';
}
}
// Correct Time
function pubDate_to_timestamp($time){
//Thu, 21 Aug 2008 01:14:36 PDT
//=> date("D, j M Y H:i:s T");
$time = explode(' ', $time);
$chrono = explode(':', $time[4]);
$month = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5,
'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10,
'Nov' => 11, 'Dec' => 12);
$mktime = mktime($chrono[0], $chrono[1], $chrono[2], $month[$time[2]], $time[1], $time[3], $time[5]);
return $mktime;
}
$twitime = pubDate_to_timestamp($output);
return timeSince($twitime);
?>
I found the above code here:
http://wiki.modxcms.com/index.php/PHx/CustomModifiers#phx:timesince
Then the snippet call to drop into your page (replacing the URL with the correct one for your Twitter account):
[!FeedX? &url=`http://twitter.com/statuses/user_timeline/123456789.rss` &cacheTime=`600` &maxElements=`ITEM(1)` &preset=`twitter` !]
All done.