Staff Page last logged in

Artist

Member
Jan 12, 2014
73
5
mmZb1AW.png


Anyone know how to do that where it says "Logged in 1 minute(s) ago" ect?
 

Evilsmoothie

Mad kung-fu artist
Feb 11, 2013
446
57
Well, in my cms I'm just passing last_online from the database through this function
PHP:
function time_elapsed_string($ptime)
        {
            $etime = time() - $ptime;

            if ($etime < 1)
            {
                return '0 seconds';
            }

            $a = array( 365 * 24 * 60 * 60  =>  'year',
                         30 * 24 * 60 * 60  =>  'month',
                              24 * 60 * 60  =>  'day',
                                   60 * 60  =>  'hour',
                                        60  =>  'minute',
                                         1  =>  'second'
                        );
            $a_plural = array( 'year'   => 'years',
                               'month'  => 'months',
                               'day'    => 'days',
                               'hour'   => 'hours',
                               'minute' => 'minutes',
                               'second' => 'seconds'
                        );

            foreach ($a as $secs => $str)
            {
                $d = $etime / $secs;
                if ($d >= 1)
                {
                    $r = round($d);
                    return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago';
                }
            }
        }
Didn't write this function myself - so kudos to whoever out on the internet did.
 

Artist

Member
Jan 12, 2014
73
5
Well, in my cms I'm just passing last_online from the database through this function
PHP:
function time_elapsed_string($ptime)
        {
            $etime = time() - $ptime;

            if ($etime < 1)
            {
                return '0 seconds';
            }

            $a = array( 365 * 24 * 60 * 60  =>  'year',
                         30 * 24 * 60 * 60  =>  'month',
                              24 * 60 * 60  =>  'day',
                                   60 * 60  =>  'hour',
                                        60  =>  'minute',
                                         1  =>  'second'
                        );
            $a_plural = array( 'year'   => 'years',
                               'month'  => 'months',
                               'day'    => 'days',
                               'hour'   => 'hours',
                               'minute' => 'minutes',
                               'second' => 'seconds'
                        );

            foreach ($a as $secs => $str)
            {
                $d = $etime / $secs;
                if ($d >= 1)
                {
                    $r = round($d);
                    return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago';
                }
            }
        }
Didn't write this function myself - so kudos to whoever out on the internet did.

Thanks but where do I put this? I tried to put it on my staff page but I get a white screen.
 

Jaden

not so active
Aug 24, 2014
886
263
How Habbo does it, kinda. (MoonPHP)
PHP:
function relative_time($time)
{
    $SECOND = 1;
    $MINUTE = 60 * $SECOND;
    $HOUR = 60 * $MINUTE;
    $DAY = 24 * $HOUR;
    $MONTH = 30 * $DAY;
    $before = time() - $time;

    if ($before < 0) {
        return "not yet";
    }

    if ($before < 1 * $MINUTE) {
        //return ($before <= 1) ? "just now" : $before . " seconds ago";
        return "just now";
    }

    if ($before < 2 * $MINUTE) {
        return "1 minute ago";
    }

    if ($before < 45 * $MINUTE) {
        return floor($before / 60) . " minutes ago";
    }

    if ($before < 90 * $MINUTE) {
        return "an hour ago";
    }

    if ($before < 24 * $HOUR) {

        return (floor($before / 60 / 60) == 1 ? 'about an hour' : floor($before / 60 / 60) . ' hours') . " ago";
    }

    if ($before < 48 * $HOUR) {
        return "yesterday";
    }

    if ($before < 30 * $DAY) {
        return floor($before / 60 / 60 / 24) . " days ago";
    }

    if ($before < 12 * $MONTH) {

        $months = floor($before / 60 / 60 / 24 / 30);
        return $months <= 1 ? "one month ago" : $months . " months ago";
    } else {
        $years = floor($before / 60 / 60 / 24 / 30 / 12);
        return $years <= 1 ? "one year ago" : $years . " years ago";
    }

    return "$time";
}
 

Evilsmoothie

Mad kung-fu artist
Feb 11, 2013
446
57
In the database lol.
"lol"? Like it was obvious. Hah.. you do know that you're wrong, right? :p
Thanks but where do I put this? I tried to put it on my staff page but I get a white screen.
I'm not using rev, so I don't know where the most reasonable place to put it is, but chuck it into one of the classes and call it on the staff page where you would normally get staff members by doing time_elapsed_string(this-is-where-you-get-last-online).
 

Each

Member
Dec 20, 2013
498
184
"lol"? Like it was obvious. Hah.. you do know that you're wrong, right? :p

I'm not using rev, so I don't know where the most reasonable place to put it is, but chuck it into one of the classes and call it on the staff page where you would normally get staff members by doing time_elapsed_string(this-is-where-you-get-last-online).
You do know it was a joke?
Hah, how could you even run that ?
 

Evilsmoothie

Mad kung-fu artist
Feb 11, 2013
446
57
You do know it was a joke?
Hah, how could you even run that ?
In my view, it makes no sense to intentionally set a person in need of help on the wrong path. Don't be such an ass.
In regards to "how could you even run that", I hope Im not misinterpreting you .. but this is how
PHP:
public static function getStaff($rank)
        {
            if(DB::getInstance()->query("SELECT * FROM users WHERE rank = $rank")->count())
            {
                $oddEven = "odd";
                $getStaff = DB::getInstance()->query("SELECT * FROM users WHERE rank = $rank ORDER BY id ASC");
                foreach($getStaff->results() as $staff) {

                    if($oddEven == "#F5F5F5")
                    {
                        $oddEven = "#FFFFFF";
                    }
                    else
                    {
                        $oddEven = "#F5F5F5";
                    }

                    if($staff->online == 1)
                    {
                        $onlineStatus = "<img src='{site_url}/library/templates/tmp/images/staff/online.gif'>";
                    }
                    else
                    {
                        $onlineStatus = "<img src='{site_url}/library/templates/tmp/images/staff/offline.gif'>";
                    }

                    echo '<table width="100%" style="padding: 2px; background-color: ' . $oddEven . ';"><tbody><tr>
                    <td valign="middle" width="25">
                        <div style="width: 54px; height: 54px; margin-top:-10px; float: left; background: url(https://www.habbo.com.tr/habbo-imaging/avatarimage?figure=' . $staff->look . '&amp;gesture=sml&amp;size=m&amp;headonly=1);"></div>
                    </td>
                    <td valign="top">
                        <b style="font-size: 110%;">' . $staff->username . '</b> <font size="1"></a>' . $staff->position . '</font>
                        <br />
                        Motto: <i>' . $staff->motto . '</i><br>
                        Last seen: ' . Light::time_elapsed_string($staff->last_online) . '<br>                  
                    </td>
                    <td valign="top" style="float: right;">
                        ' . $onlineStatus . '
                    </td>
                    </tr></tbody></table>';
                }
            }
            else {
                echo '<div class="habblet box-content" style="margin-top:-5px;"><i>There are no staff members in this category.</i></div>';
            }
        }
The code isn't very pretty - but whatever. It's mine and does the job I need it to. To clearify I do <?php Light::getStaff(9); ?> on the staff page when I need to. Simple and keeps my tpls pretty and organised. On top of that it yields a very neat result
z32tBLo.png

Now that we've settled that the code works - go away unless you're going to help TS.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
@Evilsmoothie, there is literally no need for the $a_plural array there, all you need to do is replace

Code:
return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago';

with

Code:
return $r . ' ' . ($r > 1 ? ($str.'s') : $str) . ' ago';
 

Users who are viewing this thread

Top