Topic: Move "online now" list to top of main.tpl

Currently the "online now" list only appears at the bottom of the index page. I would like it to appear towards the top of main.tpl so that is appears just above the pagination part.

can someone advice which code block to copy and where to paste it?
I've tried, believe me, I've tried sad

Thanks for any tips
Mark

Re: Move "online now" list to top of main.tpl

Create file "<FORUM_URL>/include/user/online_list.php". Place this peace of code in this file:

<?php
require_once FORUM_ROOT.'lang/'.$forum_user['language'].'/index.php';

if ($forum_config['o_users_online'] == '1')
{
    // Fetch users online info and generate strings for output
    $query_online = array(
        'SELECT'    => 'o.user_id, o.ident',
        'FROM'        => 'online AS o',
        'WHERE'        => 'o.idle=0',
        'ORDER BY'    => 'o.ident'
    );

    $result_online = $forum_db->query_build($query_online) or error(__FILE__, __LINE__);
    $num_guests = $num_users = 0;
    $users = array();

    while ($forum_user_online = $forum_db->fetch_assoc($result_online))
    {
        if ($forum_user_online['user_id'] > 1)
        {
            $users[] = ($forum_user['g_view_users'] == '1') ? '<a href="'.forum_link($forum_url['user'], $forum_user_online['user_id']).'">'.forum_htmlencode($forum_user_online['ident']).'</a>' : forum_htmlencode($forum_user_online['ident']);
            ++$num_users;
        }
        else
            ++$num_guests;
    }

    $online_info = array();
    $online_info['guests'] = ($num_guests == 0) ? $lang_index['Guests none'] : sprintf((($num_guests == 1) ? $lang_index['Guests single'] : $lang_index['Guests plural']), forum_number_format($num_guests));
    $online_info['users'] = ($num_users == 0) ? $lang_index['Users none'] : sprintf((($num_users == 1) ? $lang_index['Users single'] : $lang_index['Users plural']), forum_number_format($num_users));

?>
<div id="brd-online" class="gen-content">
    <h3 class="hn"><span><?php printf($lang_index['Currently online'], implode($lang_index['Online stats separator'], $online_info)) ?></span></h3>
<?php if (!empty($users)): ?>
    <p><?php echo implode($lang_index['Online list separator'], $users) ?></p>
<?php endif; ?>
</div>
<?php

unset($users, $online_info, $num_guests, $num_users);
}

?>

Modify main.tpl like shown below:

<div id="brd-main">
    <!-- forum_main_title -->    
    <!-- forum_include "online_list.php" -->
    <!-- forum_crumbs_top -->
    <!-- forum_main_menu -->

And the final step for you to do is to modify the css-files for sightly displaying the list of online users. wink

Re: Move "online now" list to top of main.tpl

That's' done it!
Brilliant, thanks smile

Re: Move "online now" list to top of main.tpl

Update:
How can I update the above code so that it JUST displays a list of online usernames. I don't want any other text at all, JUST a list of registered users who are online.

I spent over an hour trying to do it myself but I've given up now sad

5

Re: Move "online now" list to top of main.tpl

just comment out this line

<?php  printf($lang_index['Currently online'], implode($lang_index['Online stats separator'], $online_info)) ?>

so it looks like this

<?php // printf($lang_index['Currently online'], implode($lang_index['Online stats separator'], $online_info)) ?>

Re: Move "online now" list to top of main.tpl

Will try that now thanks smile

Re: Move "online now" list to top of main.tpl

Teva, I got a syntax error sad
Would it be more reliable for me to physically delete some code? If so which bits please?

8 (edited by Slavok 2008-12-17 16:06)

Re: Move "online now" list to top of main.tpl

This script will show only online users:

<?php
require_once FORUM_ROOT.'lang/'.$forum_user['language'].'/index.php';

if ($forum_config['o_users_online'] == '1')
{
    // Fetch users online info and generate strings for output
    $query_online = array(
        'SELECT'    => 'o.user_id, o.ident',
        'FROM'        => 'online AS o',
        'WHERE'        => 'o.idle=0',
        'ORDER BY'    => 'o.ident'
    );

    $result_online = $forum_db->query_build($query_online) or error(__FILE__, __LINE__);
    $num_guests = $num_users = 0;
    $users = array();

    while ($forum_user_online = $forum_db->fetch_assoc($result_online))
    {
        if ($forum_user_online['user_id'] > 1)
        {
            $users[] = ($forum_user['g_view_users'] == '1') ? '<a href="'.forum_link($forum_url['user'], $forum_user_online['user_id']).'">'.forum_htmlencode($forum_user_online['ident']).'</a>' : forum_htmlencode($forum_user_online['ident']);
            
        }
    }

    if (!empty($users))
    {

    ?>
    <div id="brd-online" class="gen-content">
        <p><?php echo implode($lang_index['Online list separator'], $users) ?></p>

    </div>
    <?php

    unset($users);
    
    }
}
?>