Current time: 03-29-2024, 11:01 AM Hello There, Guest! (LoginRegister)


Announcement
We have the biggest collection of MyBB Plugins here on the Net. We have currently 175+ MyBB Exclusive Plugins, 80+ MyBB Compatible MyCodes and 16+ MyBB 1.4.x Themes (Some are still under construction...) Thus, we provide you the largest MyBB Stuff on the net including tutorials. Stay with us, you will find out some more to come.
Now you can easily create your own buttons set for MyBB! Click here to have a look...
*** You cannot do your registration behind any Proxies anymore! ***
Welcome Guest[3.88.185.100], connected from
Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How Many Minutes and Hours Past Since Last Post or Thread.
09-01-2009, 09:32 PM (This post was last modified: 09-01-2009 09:34 PM by ghazal.)
Post: #1
Heart How Many Minutes and Hours Past Since Last Post or Thread.
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 ?> .
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'] != && 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($offset01) != "-")
            {
                
$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:
   

Now open Your forumdisplay.php , It should look like this,

SCREENSHOT:
   

Cool... ENJOY. Cool

ghazal's signature *** Deleted by the administration ***
Visit this user's website Find all posts by this user
Quote this message in a reply
09-27-2009, 09:32 AM
Post: #2
RE: How Many Minutes and Hours Past Since Last Post or Thread.
Thank you for this wonderful tip. I may use it someday. Big Grin
Visit this user's website Find all posts by this user
Quote this message in a reply
09-29-2009, 04:01 AM
Post: #3
RE: How Many Minutes and Hours Past Since Last Post or Thread.
(09-27-2009 09:32 AM)Hero Wrote:  Thank you for this wonderful tip. I may use it someday. Big Grin

Yours welcome Smile

ghazal's signature *** Deleted by the administration ***
Visit this user's website Find all posts by this user
Quote this message in a reply
03-19-2010, 01:59 AM
Post: #4
RE: How Many Minutes and Hours Past Since Last Post or Thread.
Yah another nice tutorial

Chandy's signature
Visit this user's website Find all posts by this user
Quote this message in a reply
09-20-2010, 06:18 AM
Post: #5
RE: How Many Minutes and Hours Past Since Last Post or Thread.
very good tutorial.

Ansar Bajwa's signature
Visit this user's website Find all posts by this user
Quote this message in a reply
0 member(s) viewed this thread in the last 365 days :
Post Reply 


Was This Thread Useful ?
Please Link To Us
URL
BBCode
HTML

Forum Jump:

 
New To Site ?
Some Useful Links
  • Help

  • You Might Need To Register

  • Forum Statistics

  • Mark All Forums Read

  • Forum Staff

  • Log Out
  • Contact Us

  • Mybbcodes

  • Return to Top

  • Return to Content

  • Lite (Archive) Mode

  • RSS Syndication
  • Powered By MyBB, © 2002-2024 MyBB Group.
    Golden Crown - Designed and Published by ghazal & exdiogene of MyBBCodes.
    Hosting provided by WWWHostingServer.com