Padgoi
09-11-2007, 05:03 AM
Ok, so the following script is a modification to an IPB board. It's supposed to display how many users are currently viewing a topic from forum view. The modification is working somewhat, however, when displaying how many users are viewing a topic, it says, "%s members viewing" instead of showing the actual number. Any help would be appreciated.
//-----------------------------------------
// How many users are viewing this?
//-----------------------------------------
if( $this->ipsclass->vars['ma23-usersviewing_enable'] &&
strstr( ',' . $this->ipsclass->vars['ma23-usersviewing_perms'] . ',', ',' . $this->ipsclass->member['mgroup'] . ',') &&
strstr( ',' . $this->ipsclass->vars['ma23-usersviewing_forums'] . ',', ',' . $this->forum['id'] . ',' ) &&
$topic['state'] != 'link'
)
{
$cut_off = ($this->ipsclass->vars['au_cutoff'] != "") ? $this->ipsclass->vars['au_cutoff'] * 60 : 900;
$time = time() - $cut_off;
$this->ipsclass->DB->simple_construct( array( 'select' => 's.member_id, s.member_name, s.member_group, s.id, s.login_type, s.location, s.running_time',
'from' => 'sessions s',
'where' => "s.location_1_type='topic' AND s.location_1_id={$topic['tid']}
AND s.running_time > {$time} AND s.in_error=0"
) );
$this->ipsclass->DB->simple_exec();
if( $this->ipsclass->DB->get_num_rows() > 0 )
{
$ar_time = time();
$cached = array();
$active = array( 'guests' => 0, 'anon' => 0, 'members' => 0 );
$rows = array( $ar_time => array( 'login_type' => substr($this->ipsclass->member['login_anonymous'],0, 1),
'running_time' => $ar_time,
'id' => 0,
'location' => 'st',
'member_id' => $this->ipsclass->member['id'],
'member_name' => $this->ipsclass->member['members_display_name'],
'member_group' => $this->ipsclass->member['mgroup']
) );
while ($r = $this->ipsclass->DB->fetch_row() )
{
$rows[ $r['running_time'].'.'.$r['id'] ] = $r;
}
krsort( $rows );
//-----------------------------------------
// PRINT...
//-----------------------------------------
foreach( $rows as $result )
{
$last_date = $this->ipsclass->get_time( $result['running_time'] );
if ($result['member_id'] == 0)
{
$active['guests']++;
}
else
{
if (empty( $cached[ $result['member_id'] ] ) )
{
$cached[ $result['member_id'] ] = 1;
if ($result['login_type'] == 1)
{
$active['anon']++;
}
else
{
$active['members']++;
}
}
}
}
$total = $active['anon'] + $active['guests'] + $active['members'];
$this->ipsclass->lang['usersviewing_prefix'] = sprintf( $this->ipsclass->lang['usersviewing_prefix'], $active['members'], $active['guests'], $active['anon'] );
$this->ipsclass->lang['usersviewing'] = sprintf( $this->ipsclass->lang['usersviewing'], $this->ipsclass->lang['usersviewing_prefix'], $total );
}
else
{
$this->ipsclass->lang['usersviewing_prefix'] = '';
$this->ipsclass->lang['usersviewing'] = '';
}
}
else
{
$this->ipsclass->lang['usersviewing_prefix'] = '';
$this->ipsclass->lang['usersviewing'] = '';
}
unset( $rows, $cached, $active );
//-----------------------------------------
// How many users are viewing this?
//-----------------------------------------
if( $this->ipsclass->vars['ma23-usersviewing_enable'] &&
strstr( ',' . $this->ipsclass->vars['ma23-usersviewing_perms'] . ',', ',' . $this->ipsclass->member['mgroup'] . ',') &&
strstr( ',' . $this->ipsclass->vars['ma23-usersviewing_forums'] . ',', ',' . $this->forum['id'] . ',' ) &&
$topic['state'] != 'link'
)
{
$cut_off = ($this->ipsclass->vars['au_cutoff'] != "") ? $this->ipsclass->vars['au_cutoff'] * 60 : 900;
$time = time() - $cut_off;
$this->ipsclass->DB->simple_construct( array( 'select' => 's.member_id, s.member_name, s.member_group, s.id, s.login_type, s.location, s.running_time',
'from' => 'sessions s',
'where' => "s.location_1_type='topic' AND s.location_1_id={$topic['tid']}
AND s.running_time > {$time} AND s.in_error=0"
) );
$this->ipsclass->DB->simple_exec();
if( $this->ipsclass->DB->get_num_rows() > 0 )
{
$ar_time = time();
$cached = array();
$active = array( 'guests' => 0, 'anon' => 0, 'members' => 0 );
$rows = array( $ar_time => array( 'login_type' => substr($this->ipsclass->member['login_anonymous'],0, 1),
'running_time' => $ar_time,
'id' => 0,
'location' => 'st',
'member_id' => $this->ipsclass->member['id'],
'member_name' => $this->ipsclass->member['members_display_name'],
'member_group' => $this->ipsclass->member['mgroup']
) );
while ($r = $this->ipsclass->DB->fetch_row() )
{
$rows[ $r['running_time'].'.'.$r['id'] ] = $r;
}
krsort( $rows );
//-----------------------------------------
// PRINT...
//-----------------------------------------
foreach( $rows as $result )
{
$last_date = $this->ipsclass->get_time( $result['running_time'] );
if ($result['member_id'] == 0)
{
$active['guests']++;
}
else
{
if (empty( $cached[ $result['member_id'] ] ) )
{
$cached[ $result['member_id'] ] = 1;
if ($result['login_type'] == 1)
{
$active['anon']++;
}
else
{
$active['members']++;
}
}
}
}
$total = $active['anon'] + $active['guests'] + $active['members'];
$this->ipsclass->lang['usersviewing_prefix'] = sprintf( $this->ipsclass->lang['usersviewing_prefix'], $active['members'], $active['guests'], $active['anon'] );
$this->ipsclass->lang['usersviewing'] = sprintf( $this->ipsclass->lang['usersviewing'], $this->ipsclass->lang['usersviewing_prefix'], $total );
}
else
{
$this->ipsclass->lang['usersviewing_prefix'] = '';
$this->ipsclass->lang['usersviewing'] = '';
}
}
else
{
$this->ipsclass->lang['usersviewing_prefix'] = '';
$this->ipsclass->lang['usersviewing'] = '';
}
unset( $rows, $cached, $active );