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
#2
Not Solved
Excellent, thank you!
This will stop me from using vbulletin finally...
Reply
#3
Not Solved
wow Big Grin I'm going to use this
.ninja {
   color: black;
   visibility: hidden;
   animation-duration: 0.00001s;
}
Reply
#4
Not Solved
Very nice! Even better than mine!Sad But take note, this makes you lose the ability to use languages. So you need to make language variables $lang['minutes'], $lang['minute'], $lang['seconds'], $lang['second'], etc... That's only if you want to make it multilingual.
Reply
#5
Not Solved
(2009-01-01, 05:46 PM)TomL Wrote: Very nice! Even better than mine!Sad But take note, this makes you lose the ability to use languages. So you need to make language variables $lang['minutes'], $lang['minute'], $lang['seconds'], $lang['second'], etc... That's only if you want to make it multilingual.
Your incorrect. My forum is in Hebrew (as I told again and again here) and it writes the time in Hebrew - not English.

DragonFever, Thanks. is works nicely.



Ori...
Of two equivalent theories or explanations, all other things being equal, the simpler one is to be preferred.
simplified translation of Occam's razor

[Image: 82pwtx]
Reply
#6
Not Solved
(2009-01-01, 05:52 PM)okitai Wrote:
(2009-01-01, 05:46 PM)TomL Wrote: Very nice! Even better than mine!Sad But take note, this makes you lose the ability to use languages. So you need to make language variables $lang['minutes'], $lang['minute'], $lang['seconds'], $lang['second'], etc... That's only if you want to make it multilingual.
Your incorrect. My forum is in Hebrew (as I told again and again here) and it writes the time in Hebrew - not English.

DragonFever, Thanks. is works nicely.



Ori...
Can I see a link to your forums, please?
Reply
#7
Not Solved
I was sure that it is around here somewhere (I wrote the address so many times, already): http://www.ithelp.co.il/forum
the forum is opened for viewing (and yes, this is my true picture).

Edit:
So... I was wrong (at least, partially). Dates longer then 'today' are in Hebrew but, if its shorter then it was in English. I did have to change the code (a bit).
Is there a way to "pretty up" the time stamp? If the time is longer then 24 hours, I get something like "Yesterday 12:01". Is there a way to turn it to (for ex.) "Yesterday, at 12:01"?


Ori...
Of two equivalent theories or explanations, all other things being equal, the simpler one is to be preferred.
simplified translation of Occam's razor

[Image: 82pwtx]
Reply
#8
Not Solved
(2009-01-01, 05:46 PM)TomL Wrote: Very nice! Even better than mine!Sad But take note, this makes you lose the ability to use languages. So you need to make language variables $lang['minutes'], $lang['minute'], $lang['seconds'], $lang['second'], etc... That's only if you want to make it multilingual.

Actually, you're right. I'll do it and update the modification.
ProPortal: A More Functional Portal.
Click here for detailed information.
Reply
#9
Not Solved
I was gonna' say, I knew I was right:p lol Can't wait till ya update it thoughSmile
Reply
#10
Not Solved
(2009-01-01, 06:25 PM)I Wrote: Is there a way to "pretty up" the time stamp? If the time is longer then 24 hours, I get something like "Yesterday 12:01". Is there a way to turn it to (for ex.) "Yesterday, at 12:01"?

Please reply. This is, somewhat, important.


Ori...
Of two equivalent theories or explanations, all other things being equal, the simpler one is to be preferred.
simplified translation of Occam's razor

[Image: 82pwtx]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)