bestbuildpc: Forums
 

 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Show the number of visitors viewing a forum
 
 
Post new topic   Reply to topic    bestbuildpc Forum Index -> RavenNuke -> Mods and Hacks
View previous topic :: View next topic  
Author Message
bestbuildpc
Site Admin
Site Admin


Joined: Jun 30, 2012
Posts: 213
Location: NL

PostPosted: Tue May 28, 2013 23:59    Post subject: Show the number of visitors viewing a forum Reply with quote

This phpbb mod will show the number of visitors viewing a forum beside the name of each forum.
It is a cool mod and a must have for any forums
.

Code:
#################################################################

## Mod Title: Count user access to a box of forum
## PORTED TO PHP-NUKE
## Mod Version: 1.0.2
## Mod Time: 22/03/06
## Mod Description: This will help users see how many users are
##                  viewing into forums. Example "12 viewing"
##      
## Installation Level: Easy
## Installation Time: 15 Minutes
##
## Files To Edit: 3 (it is 4 if Easy Sub-Forums was installed)
##   modules/Forum/index.php
##   modules/Forum/viewforum.php (if Easy Sub-Forums was installed)
##   includes/session.php
##   templates/yourtemplate/index_body.tpl (themes/YOUR_THEME/forums/index_body.tpl)
##
## Included Files: (none)
##
## NOTE: it can have some non-acuracy, tell me if you have
##       a problem with it. See website http://vietshare.tk for the demo
##
#################################################################
## WHAT'S NEW IN THIS VERSION (1.0.2)?
## - fix code to show more correcly
## - make it can work with Easy Sub-Forums MOD v1.0.8
#################################################################
## THANKS TO
## Phuong < anhchang_pcit@yahoo.com > for report some error
##
#################################################################

#
#-----[ SQL Query ]----------------------------------------------
# If your phpbb table prefix is different, then change it to
# reflect the correct one.

ALTER TABLE `nuke_bbsessions` ADD `session_forum` INT( 15 ) NOT NULL DEFAULT '0';

#################################################################
#
#-----[ OPEN ]---------------------------------------------------
#
   modules/Forum/index.php
#
#-----[ FIND ]---------------------------------------------------
#

//
// Start page proper
//
$sql = "SELECT c.cat_id, c.cat_title, c.cat_order

#
#-----[ BEFORE, ADD ]--------------------------------------------
#

//
// BEGIN: number of user view forum
//
$sql = "SELECT s.session_forum, count(*) as numviewforum 
   FROM ".SESSIONS_TABLE." s
   WHERE (s.session_time >= ".( time() - 300 ) . ")
   GROUP BY s.session_forum";
if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain reg user/online information', '', __LINE__, __FILE__, $sql);
}

$session_forum_rows = array();

while( $row = $db->sql_fetchrow($result) )
{
   $session_forum_rows[] = $row;
}
$db->sql_freeresult($result);

function getIDsessionforum($n)
{
   global $session_forum_rows;
   for ($i=0; $i<count($session_forum_rows); $i++)
      if($session_forum_rows[$i]['session_forum']==$n) return $i;
   return -1;
}
//
// END: number of user view forum
//

#
#-----[ FIND ]---------------------------------------------------
#
   for($j = 0; $j < $total_forums; $j++)
   {
      if ( $forum_data[$j]['cat_id'] == $cat_id )
      {

#
#-----[ AFTER, ADD ]---------------------------------------------
#
   $nviewforum=0;
#
#-----[ FIND ]---------------------------------------------------
# it has just been used if Easy Sub-Forums MOD was installed

            $sub_forum_id = $value['forum_id'];
            if ($value['attached_forum_id']==$forum_id && $is_auth_ary[$sub_forum_id]['auth_view'])
            {

#
#-----[ AFTER, ADD ]---------------------------------------------
# it has just been used if Easy Sub-Forums MOD was installed

         $nviewforum+=$session_forum_rows[getIDsessionforum($sub_forum_id)]['numviewforum'];

#
#-----[ FIND ]---------------------------------------------------
#
   $template->assign_block_vars('catrow.forumrow',   array(
      'ROW_COLOR' => '#' . $row_color,
      'ROW_CLASS' => $row_class,
      'FORUM_FOLDER_IMG' => $folder_image,
      'FORUM_NAME' => $forum_data[$j]['forum_name'],

#
#-----[ BEFORE, ADD ]--------------------------------------------
#
   $nviewforum+=$session_forum_rows[getIDsessionforum($j+1)]['numviewforum'];
   
#
#-----[ AFTER, ADD ]---------------------------------------------
#
      'FORUM_VIEW' => ($nviewforum)?'('.$nviewforum.' viewing)':'',

#################################################################
#-----[ OPEN ]---------------------------------------------------
# it has just been used if Easy Sub-Forums MOD was installed

   modules/Forum/viewforum.php

#
#-----[ FIND ]---------------------------------------------------
# it has just been used if Easy Sub-Forums MOD was installed

   $attach_forum_link = append_sid('viewforum.php?f=' . $value['forum_id']);

#
#-----[ BEFORE, ADD ]--------------------------------------------
# it has just been used if Easy Sub-Forums MOD was installed

               $sql3 = "SELECT count(*) as numviewforum 
                  FROM ".SESSIONS_TABLE." s
                  WHERE (s.session_forum=".$value['forum_id'].") AND (s.session_time >= ".( time() - 300 ) . ")
                  GROUP BY s.session_forum LIMIT 1";
               if ( !($result3 = $db->sql_query($sql3)) )
               {
                  message_die(GENERAL_ERROR, 'Could not obtain reg user/online information', '', __LINE__, __FILE__, $sql3);
               }
               
               $snumusersforum = "";
               if ( $row3 = $db->sql_fetchrow($result3) )
               {
                  $snumusersforum = ($row3['numviewforum'])?'('.$row3['numviewforum'].' viewing)':'';
               }
               $db->sql_freeresult($result3);

#
#-----[ FIND ]---------------------------------------------------
# it has just been used if Easy Sub-Forums MOD was installed
   
   $attach_forum_name = '<a href="' . append_sid('viewforum.php?f=' . $value['forum_id']) . '">' . $value['forum_name'] . '</a>' ;

#
#-----[ REPLACE ]------------------------------------------------
# it has just been used if Easy Sub-Forums MOD was installed

   $attach_forum_name = '<a href="' . append_sid('viewforum.php?f=' . $value['forum_id']) . '">' . $value['forum_name'] . '</a> ' . $snumusersforum ;

#################################################################
#-----[ OPEN ]---------------------------------------------------
#
   includes/session.php

#
#-----[ FIND ]---------------------------------------------------
#
   //
   // Adds/updates a new session to the database for the given userid.
   // Returns the new session ID on success.
   //

#
#-----[ AFTER, ADD ]---------------------------------------------
#
   $myforum=(!empty($HTTP_GET_VARS['f']))?$HTTP_GET_VARS['f']:0;

#
#-----[ FIND ]---------------------------------------------------
#

function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_autologin = 0, $admin = 0)
{
   global $db, $board_config;

#
#-----[ AFTER, ADD ]---------------------------------------------
#
   global $myforum;

#
#-----[ FIND ]---------------------------------------------------
#
      $sql = "INSERT INTO " . SESSIONS_TABLE . "
         (session_id, session_user_id, session_start, session_time, session_ip, session_page, session_logged_in, session_admin)
         VALUES ('$session_id', $user_id, $current_time, $current_time, '$user_ip', $page_id, $login, $admin)";

#
#-----[ REPLACE ]------------------------------------------------
#
      $sql = "INSERT INTO " . SESSIONS_TABLE . "
         (session_id, session_user_id, session_start, session_time, session_ip, session_page, session_logged_in, session_admin, session_forum)
         VALUES ('$session_id', $user_id, $current_time, $current_time, '$user_ip', $page_id, $login, $admin, $myforum)";

#
#-----[ FIND ]---------------------------------------------------
#

function session_pagestart($user_ip, $thispage_id)
{
   global $db, $lang, $board_config;

#
#-----[ AFTER, ADD ]---------------------------------------------
#
   global $myforum;

#
#-----[ FIND ]---------------------------------------------------
#
            //
            // Only update session DB a minute or so after last update
            //
            if ( $current_time - $userdata['session_time'] > 60 )
            {
               // A little trick to reset session_admin on session re-usage
               $update_admin = (!defined('IN_ADMIN') && $current_time - $userdata['session_time'] > ($board_config['session_length']+60)) ? ', session_admin = 0' : '';

               $sql = "UPDATE " . SESSIONS_TABLE . "
                  SET session_time = $current_time, session_page = $thispage_id$update_admin
                  WHERE session_id = '" . $userdata['session_id'] . "'";

#
#-----[ REPLACE ]------------------------------------------------
#
            $sql = "UPDATE " . SESSIONS_TABLE . "
                  SET session_forum = $myforum
                  WHERE session_id = '" . $userdata['session_id'] . "'";
            if ( !$db->sql_query($sql) )
            {
               message_die(CRITICAL_ERROR, 'Error updating sessions table', '', __LINE__, __FILE__, $sql);
            }

            //
            // Only update session DB a minute or so after last update
            //
            if ( $current_time - $userdata['session_time'] > 60 )
            {
               // A little trick to reset session_admin on session re-usage
               $update_admin = (!defined('IN_ADMIN') && $current_time - $userdata['session_time'] > ($board_config['session_length']+60)) ? ', session_admin = 0' : '';

               $sql = "UPDATE " . SESSIONS_TABLE . "
                  SET session_time = $current_time, session_page = $thispage_id$update_admin, session_forum = $myforum
                  WHERE session_id = '" . $userdata['session_id'] . "'";


#################################################################
#-----[ OPEN ]---------------------------------------------------
#
   templates/yourtempate/index_body.tpl (themes/YOUR_THEME/forums/index_body.tpl)

#
#-----[ FIND ]---------------------------------------------------
#
   <a href="{catrow.forumrow.U_VIEWFORUM}" class="forumlink">{catrow.forumrow.FORUM_NAME}</a>

#
#-----[ AFTER, ADD ]---------------------------------------------
#
   </span><span class="gensmall">&nbsp;{catrow.forumrow.FORUM_VIEW}

#
#-----[ SAVE/CLOSE ALL FILES ]-----------------------------------
#
#EoM
  
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    bestbuildpc Forum Index -> RavenNuke -> Mods and Hacks All times are GMT + 2 Hours
 
 Page 1 of 1

 

Jump to:   
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001-2008 phpBB Group
 
Forums ©