Topic: Online Users Sidebar mod not showing up all the time...
hello all..
i'm redesigning my site & forums. my forum is integrated (albeit somewhat of a hack) into my Joomla template:
http://joomla.arcadefire.net is the site (url is temp)
and
http://forumsv2.arcadefire.net/index.php is the forums
if you register and check it out, you should see where i have built a sidebar w/ the stats on the lefthand side.
for some reason, the Online user list disappears on ocassion, yet always displays in the bottom section (i'm hoping to remove this one once i figure out what's wrong w/ the sidebar one).
any idea why that would be?
here's my code for the sidebar in functions.php:
//
// Generate the whos online block
//
function generate_whosonline()
{
global $pun_config, $lang_common, $pun_user, $db;
if ($pun_user['is_guest'])
{
require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
return 'Welcome Guest!<br />
Please login<br />
<form id="login" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
<input type="hidden" name="form_sent" value="1" />
<input type="hidden" name="redirect_url" value="index.php" />
<label><strong>Username</strong><br /><input type="text" name="req_username" size="13" maxlength="25" tabindex="1" /><br /></label>
<label><strong>Password</strong><br /><input type="password" name="req_password" size="13" maxlength="16" tabindex="2" /><br /></label>
<p><a href="register.php" tabindex="4">'.$lang_login['Not registered'].'</a><br />
<a href="login.php?action=forget" tabindex="5">'.$lang_login['Forgotten pass'].'</a></p>
<p><input type="submit" name="login" value="Login" tabindex="3" /></p>
</form>';
}
else
{
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error());
$stats['last_user'] = $db->fetch_assoc($result);
$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
if ($pun_config['o_users_online'] == '1')
{
// Fetch users online info and generate strings for output
$num_guests = 0;
$users = array();
$online = array();
$result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
while ($pun_user_online = $db->fetch_assoc($result))
{
if ($pun_user_online['user_id'] > 1)
$users[] = "\n\t\t\t\t".'<a href="profile.php?id='.$pun_user_online['user_id'].'">'.pun_htmlspecialchars($pun_user_online['ident']).'</a><br />';
else
++$num_guests;
}
$num_users = count($users);
$online[] = "\t\t\t\t".$lang_index['Users online'].': <strong>'.$num_users.'</strong><br />'."\n\t\t\t\t".$lang_index['Guests online'].': <strong>'.$num_guests.'</strong>'."\n\t\t\t"."\n";
if ($num_users > 0 && $num_users < 10)
$online[] = "\t\t\t"."\n\t\t\t\t".'<br /><br /><strong>'.$lang_index['Online'].': </strong><br />'."\t\t\t\t".implode($users)."\n";
else
$online[] = "\t\t\t".'<div class="clearer"></div>'."\n";
}
return 'Welcome <strong>'.$pun_user['username'].'</strong> (<strong><font size=1><a href="login.php?action=out&id='.$pun_user['id'].'">'.$lang_common['Logout'].'</a></font></strong>)<br />
'.$lang_common['Last visit'].': <strong>'.format_time($pun_user['last_visit']).'</strong><br /><br />
'.implode($online,'').'<br />
Newest Member: <strong><a href="'.$pun_config['o_base_url'].'/profile.php?id='.$stats['last_user']['id'].'">'.pun_htmlspecialchars($stats['last_user']['username']).'</strong></a><br />
Total Users: <strong>'.$stats['total_users'].'</strong><br />
Topics: <strong>'.$stats['total_topics'].'</strong><br />
Posts: <strong>'.$stats['total_posts'].'</strong><br />';
}
}
header.php:
// START SUBST - <pun_online>
$tpl_main = str_replace('<pun_online>','<div id="leftsidebar">'."\n\t\t\t". generate_whosonline()."\n\t\t".'</div>', $tpl_main);
// END SUBST - <pun_online>
and then i call it from the sidebar in main.tpl with this:
<div class="moduletable">
<h3>Menu</h3>
<pun_sidestatus>
<pun_online>
</div>
it shows the rest of the sidebar stuff (total users, last registered, time, etc.), but the Online users list only shows sometimes for some reason