Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 12, 2022, 09:23:55 AM

Login with username, password and session length
Members
  • Total Members: 3842
  • Latest: Kokoro
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 50
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 39
Total: 39

Author Topic: How to blank out number of guests online  (Read 751 times)

0 Members and 1 Guest are viewing this topic.

Offline tino

  • Developer
  • *
  • Posts: 2613
Re: How to blank out number of guests online
« Reply #10 on: January 30, 2022, 10:45:38 AM »
If you want it as a php block (so no code edit's) and it won't get overwritten next time you update it's below.

Code: [Select]
global $txt, $scripturl;

    $whos = tpo_whosOnline();

    echo '<div>' . $whos['num_users_online'] .' ' , $whos['num_users_online'] == 1 ? $txt['user'] : $txt['users'] , '</div>';

    if(isset($whos['users_online']) && count($whos['users_online']) > 0) {
        $ids = array();
        $names = array();
        $times = array();
        foreach($whos['users_online'] as $w => $wh) {
            // For reasons historical, SMF produces the timestamp as
            // the timestamp followed by the user's name, so let's fix it.
            $timestamp = (int) strtr($w, array($wh['username'] => ''));
            $ids[] = $wh['id'];
            $names[$wh['id']] = $wh['name'];
            $times[$wh['id']] = timeformat($timestamp);
        }   
        $avy = progetAvatars($ids);
        foreach($avy as $a => $av) {
            echo '<a class="tp_avatar_single2" title="'.$names[$a].'" href="' . $scripturl . '?action=profile;u='.$a.'">' . $av . '</a>';
        }
    }

Offline North East Man

  • Jr. Member
  • **
  • Posts: 13
Re: How to blank out number of guests online
« Reply #11 on: February 01, 2022, 09:58:28 AM »
Hi again,

The PHP Box is a great idea - works very well without having to alter the base code.  If I wanted to have the same functionality where I can click on the online title and be shown an extended list of who is online and what pages they are viewing, which code would I have to add to the PHP block?

I’m very appreciative of the help on this issue.


Richard

Offline @rjen

  • Support Team
  • *
  • Posts: 3285
    • FJR-club Nederland
Re: How to blank out number of guests online
« Reply #12 on: February 01, 2022, 12:22:14 PM »
change it to this

Code: [Select]
global $txt, $scripturl;

    $whos = tpo_whosOnline();

    echo '<div><a href="/index.php?action=who;start=0;show=members;sort=user;asc">' . $whos['num_users_online'] .' ' , $whos['num_users_online'] == 1 ? $txt['user'] : $txt['users'] , '</a></div>';

    if(isset($whos['users_online']) && count($whos['users_online']) > 0) {
        $ids = array();
        $names = array();
        $times = array();
        foreach($whos['users_online'] as $w => $wh) {
            // For reasons historical, SMF produces the timestamp as
            // the timestamp followed by the user's name, so let's fix it.
            $timestamp = (int) strtr($w, array($wh['username'] => ''));
            $ids[] = $wh['id'];
            $names[$wh['id']] = $wh['name'];
            $times[$wh['id']] = timeformat($timestamp);
        }   
        $avy = progetAvatars($ids);
        foreach($avy as $a => $av) {
            echo '<a class="tp_avatar_single2" title="'.$names[$a].'" href="' . $scripturl . '?action=profile;u='.$a.'">' . $av . '</a>';
        }
    }
Running Latest TP on SMF2.1 at: www.fjr-club.nl

Testing TP on SMF2.0
Testing TP on SMF2.1 (latest Github)
Want to check what php version I am testing on? See: PHP Info

Offline North East Man

  • Jr. Member
  • **
  • Posts: 13
Re: How to blank out number of guests online
« Reply #13 on: February 01, 2022, 02:59:32 PM »
Excellent - Thank you very much.  Perfect for my needs.


Richard