TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 05, 2024, 02:10:48 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,178
  • Total Topics: 21,220
  • Online today: 188
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 202
  • Total: 203
  • @rjen

How to blank out number of guests online

Started by North East Man, January 29, 2022, 12:00:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tino

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.


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>';
        }
    }

North East Man

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

@rjen

change it to this


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

North East Man

Excellent - Thank you very much.  Perfect for my needs.


Richard