Not Solved Last Post: X Minute(s)/Hour(s) Ago
#1
Not Solved
Description: Small hack to display how many minute(s)/hour(s) past since the last post in forumdisplay and forumhome.

Open inc/functions.php
Add following code to bottom of the file before ?>
/**
 * Calculates how many minutes past since the given time.
 *
 * @param int The unix timestamp of the given time
 * @return string The formatted time
 */
function timeAgo($last)
{
	global $mybb, $mybbadmin, $lang;
	
	$timenow = TIME_NOW;
	$diff = $timenow - $last;
	
	if(!$offset && $offset != '0')
	{
		if($mybb->user['uid'] != 0 && array_key_exists("timezone", $mybb->user))
		{
			$offset = $mybb->user['timezone'];
			$dstcorrection = $mybb->user['dst'];
		}
		elseif(defined("IN_ADMINCP"))
		{
			$offset =  $mybbadmin['timezone'];
			$dstcorrection = $mybbadmin['dst'];
		}
		else
		{
			$offset = $mybb->settings['timezoneoffset'];
			$dstcorrection = $mybb->settings['dstcorrection'];
		}

		// If DST correction is enabled, add an additional hour to the timezone.
		if($dstcorrection == 1)
		{
			++$offset;
			if(my_substr($offset, 0, 1) != "-")
			{
				$offset = "+".$offset;
			}
		}
	}

	if($offset == "-")
	{
		$offset = 0;
	}
		
	if($last < $timenow && $diff <= 46200)
	{
		$order = $timenow - $last;
		while($order >= 60){
			$order = $order-60;
			$ordermleft++;
		}
		while($ordermleft >= 60){
			$ordermleft = $ordermleft-60;
			$orderhleft++;
		}

		if($ordermleft == 0){
			$ordermleft = "";
		} else {
			$ordermleft = "$ordermleft {$lang->minutes}";
		}
		if($orderhleft == 0){
			$orderhleft = "";
		} elseif($orderhleft == 1) {
			$orderhleft = "$orderhleft {$lang->hour}";
		} else {
			$orderhleft = "$orderhleft {$lang->hours}";
		}
		
		if(!$ordermleft || $ordermleft == 1){ $ordermleft = "1 {$lang->minute}"; }
		$actualtime = gmdate($mybb->settings['timeformat'], $last + ($offset * 3600));
		
		if($orderhleft)
		{
			$result = "<abbr title=\"$actualtime\">$orderhleft {$lang->df_ago}</abbr>";
		} else {
			$result = "<abbr title=\"$actualtime\">$ordermleft {$lang->df_ago}</abbr>";
		}
			
		return $result;
	} else {
		return gmdate($mybb->settings['timeformat'], $last + ($offset * 3600));
	}
}

Open inc/functions_forumlist.php
Find following:
$lastpost_date = my_date($mybb->settings['dateformat'], $lastpost_data['lastpost']);
$lastpost_time = my_date($mybb->settings['timeformat'], $lastpost_data['lastpost']);

Replace with following:
$lastpost_time = timeAgo($lastpost_data['lastpost']);
if(ereg($lang->minute, $lastpost_time) || ereg($lang->hour, $lastpost_time))
{
	$lastpost_date = "";
}
else
{
	$lastpost_date = my_date($mybb->settings['dateformat'], $lastpost_data['lastpost']);
}

Open forumdisplay.php
Find following:
$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);

Replace with following:
$lastposttime = timeAgo($thread['lastpost']);
if(ereg($lang->minute, $lastposttime) || ereg($lang->hour, $lastposttime))
{
	$lastpostdate = "";
}
else
{
	$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
}

Open your languages' global.lang.php file
Add following code to bottom of the file before ?>
$l['df_ago'] = "Ago";


That's all!

Screenshots:
   
   
ProPortal: A More Functional Portal.
Click here for detailed information.
Reply


Messages In This Thread
Last Post: X Minute(s)/Hour(s) Ago - by DragonFever - 2009-01-01, 12:13 PM
RE: Last Post: X Minute(s) Ago - by se0 - 2009-01-01, 03:21 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 05:46 PM
RE: Last Post: X Minute(s) Ago - by okitai - 2009-01-01, 05:52 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 05:55 PM
RE: Last Post: X Minute(s) Ago - by okitai - 2009-01-01, 06:25 PM
RE: Last Post: X Minute(s) Ago - by okitai - 2009-01-01, 10:22 PM
RE: Last Post: X Minute(s) Ago - by DragonFever - 2009-01-01, 10:08 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 10:11 PM
RE: Last Post: X Minute(s) Ago - by DragonFever - 2009-01-01, 10:29 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 10:34 PM
RE: Last Post: X Minute(s) Ago - by DragonFever - 2009-01-01, 10:36 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 10:37 PM
RE: Last Post: X Minute(s) Ago - by DragonFever - 2009-01-01, 10:41 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 10:45 PM
RE: Last Post: X Minute(s) Ago - by DragonFever - 2009-01-01, 10:49 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 10:53 PM
RE: Last Post: X Minute(s) Ago - by DragonFever - 2009-01-01, 10:57 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 11:08 PM
RE: Last Post: X Minute(s) Ago - by okitai - 2009-01-01, 11:53 PM
RE: Last Post: X Minute(s) Ago - by DragonFever - 2009-01-01, 11:56 PM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-01, 11:59 PM
RE: Last Post: X Minute(s) Ago - by DragonFever - 2009-01-02, 12:01 AM
RE: Last Post: X Minute(s) Ago - by x_Stricken_x - 2009-01-02, 12:03 AM
RE: Last Post: X Minute(s)/Hour(s) Ago - by kan3 - 2009-01-15, 08:39 PM
RE: Last Post: X Minute(s)/Hour(s) Ago - by kan3 - 2009-04-23, 09:38 AM
RE: Last Post: X Minute(s)/Hour(s) Ago - by jayy - 2014-04-04, 07:10 PM
RE: Last Post: X Minute(s)/Hour(s) Ago - by jayy - 2014-04-07, 11:34 AM
RE: Last Post: X Minute(s)/Hour(s) Ago - by jayy - 2014-04-07, 05:05 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)