09-01-2009, 09:32 PM
Name: How Many Minutes and Hours Past Since Last Post or Thread.
Description: It will show that how many minutes or hours OR both past since there was a post or thread was made. The result will be shown on Index.php file (i.e. homepage) and Forumdisplay.php file.
Coding: So lets start coding.
Open inc/functions.php
Add following code to the bottom of this file before ?> .
and save the file,
Now open .inc/functions_forumlist.php and about 1/3rd of its bottom, find this code.
FOUND... ! okay, Just replace it with the following,
and save the file,
Now open forumdisplay.php and about 1/3rd to its bottom, find the following code,
FOUND... ??? Okays, lets replace it with the following code,
and save the file,
Now go to .inc/languages/english/ and open global.lang.php file and add the following code before ?>
FINISHED. . . !
Now refresh your index (homepage) , It should look like this,
SCREENSHOT:
[attachment=158]
Now open Your forumdisplay.php , It should look like this,
SCREENSHOT:
[attachment=157]
Cool... ENJOY.
Description: It will show that how many minutes or hours OR both past since there was a post or thread was made. The result will be shown on Index.php file (i.e. homepage) and Forumdisplay.php file.
Coding: So lets start coding.
Open inc/functions.php
Add following code to the bottom of this file before ?> .
PHP Code:[Highlight]
/**
* 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));
}
}
and save the file,
Now open .inc/functions_forumlist.php and about 1/3rd of its bottom, find this code.
PHP Code:[Highlight]
$lastpost_date = my_date($mybb->settings['dateformat'],
$lastpost_data['lastpost']);
$lastpost_time = my_date($mybb->settings['timeformat'], $lastpost_data['lastpost']);
FOUND... ! okay, Just replace it with the following,
PHP Code:[Highlight]
$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']);
}
and save the file,
Now open forumdisplay.php and about 1/3rd to its bottom, find the following code,
PHP Code:[Highlight]
$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
FOUND... ??? Okays, lets replace it with the following code,
PHP Code:[Highlight]
$lastposttime = timeAgo($thread['lastpost']);
if(ereg($lang->minute, $lastposttime) || ereg($lang->hour, $lastposttime))
{
$lastpostdate = "";
}
else
{
$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
}
and save the file,
Now go to .inc/languages/english/ and open global.lang.php file and add the following code before ?>
PHP Code:[Highlight]
$l['df_ago'] = "Ago";
FINISHED. . . !
Now refresh your index (homepage) , It should look like this,
SCREENSHOT:
[attachment=158]
Now open Your forumdisplay.php , It should look like this,
SCREENSHOT:
[attachment=157]
Cool... ENJOY.