Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43259
Total Topics: 7518
Most Online Today: 297
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 1
Guests: 290
Total: 291

Author Topic: Global who's online function that displays # of people in the gallery  (Read 7495 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
I'd like to display how many people are browsing the gallery in index.template.php. Could you create a function that calls all members in the who's online list that are currently in the gallery and display it as a number?



Another suggestion is to prevent keywords when less that 2 characters from being accepted. For example, if I choose this phrase as my keywords, it will only accept choose this phrase keyword.

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Global who's online function that displays # of people in the gallery
« Reply #1 on: September 03, 2014, 05:27:43 pm »
Global who's online
Code: [Select]
$context['can_moderate_forum'] = allowedTo('moderate_forum');

// SMF 1.1.x
// Taken from Display.php
// Start out with no one at all viewing it.
$context['view_members'] = array();
$context['view_members_list'] = array();
$context['view_num_hidden'] = 0;

$whoID = (string) $cat;
// Search for members who have this picture id set in their GET data.
$request = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
mg.onlineColor, mg.ID_GROUP, mg.groupName
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
WHERE INSTR(lo.url, 's:7:\"gallery\";s:3:\"cat\";s:" . strlen($whoID ) .":\"$cat\";') OR lo.session = '" . ($user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id()) . "'", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
if (empty($row['ID_MEMBER']))
continue;

if (!empty($row['onlineColor']))
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a>';
else
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';

$is_buddy = in_array($row['ID_MEMBER'], $user_info['buddies']);
if ($is_buddy)
$link = '<b>' . $link . '</b>';

// Add them both to the list and to the more detailed list.
if (!empty($row['showOnline']) || allowedTo('moderate_forum'))
$context['view_members_list'][$row['logTime'] . $row['memberName']] = empty($row['showOnline']) ? '<i>' . $link . '</i>' : $link;
$context['view_members'][$row['logTime'] . $row['memberName']] = array(
'id' => $row['ID_MEMBER'],
'username' => $row['memberName'],
'name' => $row['realName'],
'group' => $row['ID_GROUP'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => $link,
'is_buddy' => $is_buddy,
'hidden' => empty($row['showOnline']),
);

if (empty($row['showOnline']))
$context['view_num_hidden']++;
}

// The number of guests is equal to the rows minus the ones we actually used ;).
$context['view_num_guests'] = mysql_num_rows($request) - count($context['view_members']);
mysql_free_result($request);

// Sort the list.
krsort($context['view_members']);
krsort($context['view_members_list']);
               
                // Count
                echo 'Guests: ' .$context['view_num_guests'];
                echo 'Members: ' .  count($context['view_members']);
                echo 'Hidden: ' . $context['view_num_hidden'];
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Global who's online function that displays # of people in the gallery
« Reply #2 on: September 03, 2014, 05:42:56 pm »
Global who's online
Code: [Select]
$context['can_moderate_forum'] = allowedTo('moderate_forum');

// SMF 1.1.x
// Taken from Display.php
// Start out with no one at all viewing it.
$context['view_members'] = array();
$context['view_members_list'] = array();
$context['view_num_hidden'] = 0;

$whoID = (string) $cat;
// Search for members who have this picture id set in their GET data.
$request = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
mg.onlineColor, mg.ID_GROUP, mg.groupName
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
WHERE INSTR(lo.url, 's:7:\"gallery\";s:3:\"cat\";s:" . strlen($whoID ) .":\"$cat\";') OR lo.session = '" . ($user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id()) . "'", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
if (empty($row['ID_MEMBER']))
continue;

if (!empty($row['onlineColor']))
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a>';
else
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';

$is_buddy = in_array($row['ID_MEMBER'], $user_info['buddies']);
if ($is_buddy)
$link = '<b>' . $link . '</b>';

// Add them both to the list and to the more detailed list.
if (!empty($row['showOnline']) || allowedTo('moderate_forum'))
$context['view_members_list'][$row['logTime'] . $row['memberName']] = empty($row['showOnline']) ? '<i>' . $link . '</i>' : $link;
$context['view_members'][$row['logTime'] . $row['memberName']] = array(
'id' => $row['ID_MEMBER'],
'username' => $row['memberName'],
'name' => $row['realName'],
'group' => $row['ID_GROUP'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => $link,
'is_buddy' => $is_buddy,
'hidden' => empty($row['showOnline']),
);

if (empty($row['showOnline']))
$context['view_num_hidden']++;
}

// The number of guests is equal to the rows minus the ones we actually used ;).
$context['view_num_guests'] = mysql_num_rows($request) - count($context['view_members']);
mysql_free_result($request);

// Sort the list.
krsort($context['view_members']);
krsort($context['view_members_list']);
               
                // Count
                echo 'Guests: ' .$context['view_num_guests'];
                echo 'Members: ' .  count($context['view_members']);
                echo 'Hidden: ' . $context['view_num_hidden'];

Strangely, that shows the members, but not the guests.

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Global who's online function that displays # of people in the gallery
« Reply #3 on: September 03, 2014, 05:47:11 pm »
Just members the rest are blank?
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Global who's online function that displays # of people in the gallery
« Reply #4 on: September 03, 2014, 05:55:17 pm »
Just members the rest are blank?

It displays the number of members, but the number of guests are 0.

I tested it with 3+ guests in different browsers, still 0.

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Global who's online function that displays # of people in the gallery
« Reply #5 on: September 03, 2014, 06:03:28 pm »
Could it because you forgot to add:

echo 'Guests: ' .count($context['view_num_guests']); ?

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Global who's online function that displays # of people in the gallery
« Reply #6 on: September 03, 2014, 06:10:16 pm »
Found an issue change out the main query hopefully this should get everyone inside the gallery
Code: [Select]
$request = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
mg.onlineColor, mg.ID_GROUP, mg.groupName
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
WHERE  lo.url like '%s:7:\"gallery\"%' OR lo.session = '" . ($user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id()) . "'", __FILE__, __LINE__);

No because it is defined above... in the code
Code: [Select]
// The number of guests is equal to the rows minus the ones we actually used ;).
$context['view_num_guests'] = mysql_num_rows($request) - count($context['view_members']);
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Global who's online function that displays # of people in the gallery
« Reply #7 on: September 03, 2014, 06:52:31 pm »
I tried cleaning it up:

Quote
// Search for members who are in the gallery
   $request = db_query("
      SELECT lo.ID_MEMBER, lo.logTime
      FROM {$db_prefix}log_online AS lo
      LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
      WHERE  lo.url like '%s:7:\"gallery\"%' OR lo.session = '" . ($user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id()) . "'", __FILE__, __LINE__);
      
   while ($row = mysql_fetch_assoc($request))
   {
      if (empty($row['ID_MEMBER']))
         continue;
                     
      $context['view_members'][$row['logTime']] = array(
         'id' => $row['ID_MEMBER'],
      );
   }

   // The number of guests is equal to the rows minus the ones we actually used ;).
   $context['view_num_guests'] = mysql_num_rows($request) - count($context['view_members']);
   mysql_free_result($request);
     $gal_users = $context['view_num_guests'] + count($context['view_members']);

And I end up with this result:

Attached...

Is there anything else I can do to compact the query and increase speeds?

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Global who's online function that displays # of people in the gallery
« Reply #8 on: September 03, 2014, 07:10:44 pm »
Caching the query would help. So it is not called on each page load. if you have a caching system enabled

Code: [Select]
if (($gal_users = cache_get_data('gal_users', 15)) == null)
{
// Search for members who are in the gallery
   $request = db_query("
      SELECT lo.ID_MEMBER, lo.logTime
      FROM {$db_prefix}log_online AS lo
      LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
      WHERE  lo.url like '%s:7:\"gallery\"%' OR lo.session = '" . ($user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id()) . "'", __FILE__, __LINE__);
     
   while ($row = mysql_fetch_assoc($request))
   {
      if (empty($row['ID_MEMBER']))
         continue;
                     
      $context['view_members'][$row['logTime']] = array(
         'id' => $row['ID_MEMBER'],
      );
   }

   // The number of guests is equal to the rows minus the ones we actually used Wink.
   $context['view_num_guests'] = mysql_num_rows($request) - count($context['view_members']);
   mysql_free_result($request);
     $gal_users = $context['view_num_guests'] + count($context['view_members']);
   cache_put_data('gal_users', $gal_users, 15);
}
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Global who's online function that displays # of people in the gallery
« Reply #9 on: September 03, 2014, 07:18:48 pm »
I do have a caching system. It noticeably went quicker, though I keep getting these errors:

8: Undefined index: view_members
File: ***/public_html/Themes/default/index.template.php
Line: 513

8: Undefined index: view_members
File: ***/public_html/Themes/default/index.template.php
Line: 515

What's with that? It happens for guests only.

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Global who's online function that displays # of people in the gallery
« Reply #10 on: September 03, 2014, 07:25:40 pm »
I would change this
Code: [Select]
  while ($row = mysql_fetch_assoc($request))
   {
      if (empty($row['ID_MEMBER']))
         continue;
                     
      $context['view_members'][$row['logTime']] = array(
         'id' => $row['ID_MEMBER'],
      );
   }

   // The number of guests is equal to the rows minus the ones we actually used Wink.
   $context['view_num_guests'] = mysql_num_rows($request) - count($context['view_members']);
To
Code: [Select]
$context['view_members2'] = array();
  while ($row = mysql_fetch_assoc($request))
   {
      if (empty($row['ID_MEMBER']))
         continue;
                     
      $context['view_members2'][$row['logTime']] = array(
         'id' => $row['ID_MEMBER'],
      );
   }

   // The number of guests is equal to the rows minus the ones we actually used Wink.
   $context['view_num_guests2'] = mysql_num_rows($request) - count($context['view_members2']);
mysql_free_result($request);
     $gal_users = $context['view_num_guests2'] + count($context['view_members2']);
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Global who's online function that displays # of people in the gallery
« Reply #11 on: September 03, 2014, 07:32:25 pm »
That did it, thank you for your help. I bet someone down the road will be really happy to see this too.

Also, still on the line is:

Quote
Another suggestion is to prevent keywords when less that 2 characters from being accepted. For example, if I choose this phrase as my keywords, it will only accept choose this phrase keyword.

Examples where it is looks bad:

http://biology-forums.com/index.php?action=gallery;sa=view;id=422

http://biology-forums.com/index.php?action=gallery;sa=view;id=12290

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Global who's online function that displays # of people in the gallery
« Reply #12 on: September 03, 2014, 08:01:32 pm »
Take back the keyword  change Looks like they can separate by commas/ or spaces thought it was just commas.
I can change it back to just commas but not sure how that will affect some peoples galleries.
« Last Edit: September 03, 2014, 08:18:16 pm by SMFHacks »
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Global who's online function that displays # of people in the gallery
« Reply #13 on: September 03, 2014, 08:44:28 pm »
I think users should be able to use both commas or spaces, but the problem is, double spaces are being taken as separate keywords. That's why I suggested that anything will less that 2 characters be removed before entering the database.

Another question.

Is there a way I can amalgamate all of these queries into one neat one? I did one for the arcade, gallery, and blog. Seems too cluttered to go into the index.template.php.

Gallery Count

Code: [Select]
if (($gal_users = cache_get_data('gal_users', 15)) == null)
{
// Search for members who are in the gallery
   $request = db_query("
      SELECT lo.ID_MEMBER, lo.logTime
      FROM {$db_prefix}log_online AS lo
      LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
      WHERE  lo.url like '%s:7:\"gallery\"%'", __FILE__, __LINE__);
      
   $context['view_members2'] = array();
  while ($row = mysql_fetch_assoc($request))
   {
      if (empty($row['ID_MEMBER']))
         continue;
                    
      $context['view_members2'][$row['logTime']] = array(
         'id' => $row['ID_MEMBER'],
      );
   }

   // The number of guests is equal to the rows minus the ones we actually used Wink.
   $context['view_num_guests2'] = mysql_num_rows($request) - count($context['view_members2']);
mysql_free_result($request);
     $gal_users = $context['view_num_guests2'] + count($context['view_members2']);
   cache_put_data('gal_users', $gal_users, 15);
}

Blog Count

Code: [Select]
if (($blog_users = cache_get_data('blog_users', 15)) == null)
{
// Search for members who are in the gallery
   $request = db_query("
      SELECT lo.ID_MEMBER, lo.logTime
      FROM {$db_prefix}log_online AS lo
      LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
      WHERE lo.url like '%a:2:{s:4:\"blog\"%'", __FILE__, __LINE__);
      
   $context['view_members2'] = array();
  while ($row = mysql_fetch_assoc($request))
   {
      if (empty($row['ID_MEMBER']))
         continue;
                    
      $context['view_members2'][$row['logTime']] = array(
         'id' => $row['ID_MEMBER'],
      );
   }

   // The number of guests is equal to the rows minus the ones we actually used Wink.
   $context['view_num_guests2'] = mysql_num_rows($request) - count($context['view_members2']);
mysql_free_result($request);
     $blog_users = $context['view_num_guests2'] + count($context['view_members2']);
   cache_put_data('blog_users', $blog_users, 15);
}

Arcade Count

Code: [Select]
if (($arc_user = cache_get_data('arc_user', 15)) == null)
{
// Search for members who are in the gallery
   $request = db_query("
      SELECT lo.ID_MEMBER, lo.logTime
      FROM {$db_prefix}log_online AS lo
      LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
      WHERE  lo.url like '%s:6:\"arcade\"%' OR lo.session = '" . ($user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id()) . "'", __FILE__, __LINE__);
      
   $context['view_members2'] = array();
  while ($row = mysql_fetch_assoc($request))
   {
      if (empty($row['ID_MEMBER']))
         continue;
                    
      $context['view_members2'][$row['logTime']] = array(
         'id' => $row['ID_MEMBER'],
      );
   }

   // The number of guests is equal to the rows minus the ones we actually used Wink.
   $context['view_num_guests2'] = mysql_num_rows($request) - count($context['view_members2']);
mysql_free_result($request);
     $arc_user = $context['view_num_guests2'] + count($context['view_members2']);
   cache_put_data('arc_user', $arc_user, 15);
}

 

Related Topics

  Subject / Started by Replies Last post
4 Replies
5909 Views
Last post February 21, 2008, 07:49:29 pm
by SMFHacks
1 Replies
3872 Views
Last post June 15, 2008, 12:07:06 pm
by SMFHacks
1 Replies
4687 Views
Last post June 26, 2008, 03:51:01 pm
by rgsknr
0 Replies
3734 Views
Last post June 29, 2008, 12:16:25 pm
by razoraw701
4 Replies
5358 Views
Last post January 18, 2009, 03:44:17 pm
by SMFHacks

+- Recent Topics

No thumbnails on new uploads by SMFHacks
March 27, 2024, 02:10:41 pm

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

an idea for new mod (( content type with different display )) by SMFHacks
February 27, 2024, 01:36:27 pm

[Mod] RSS Feed Poster by SMFHacks
February 27, 2024, 11:57:18 am

find duplicate pictures by fvlog19
February 14, 2024, 02:22:40 pm

Error uploading video. by SMFHacks
February 08, 2024, 02:04:16 pm

Gallery icon as last added image by fvlog19
February 01, 2024, 01:04:56 pm

Powered by EzPortal