vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Counting users online (https://vborg.vbsupport.ru/showthread.php?t=253203)

vbdarwin 11-07-2010 02:16 PM

Quote:

Originally Posted by kh99 (Post 2118697)
Here's an xml file you can import as a product if you want, it will create the scheduled task and plugin for you. You still need to make the changes to includes/cron/usercount.php yourself.

ETA: I don't know what else I can do, if someone else thinks they can improve on this or has a different solution feel free to jump in.

Hello all, and thank you again for the support.

The resulting code should be like this:

PHP Code:

<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db))
{
    exit;
}

// SQL for creating table, do once before starting task (add your table prefix to the table name
//CREATE TABLE usercounts (
//time INT UNSIGNED NOT NULL DEFAULT '0',
//users SMALLINT UNSIGNED NOT NULL DEFAULT '0',
//guests SMALLINT UNSIGNED NOT NULL DEFAULT '0')

$datecut TIMENOW $vbulletin->options['cookietimeout'];

$guests $vbulletin->db->query_first("
    SELECT COUNT(*) AS guests
    FROM " 
TABLE_PREFIX "session
    WHERE lastactivity > 
$datecut AND userid = 0
"
);

$users $vbulletin->db->query_first("
    SELECT COUNT(DISTINCT userid) AS users
    FROM " 
TABLE_PREFIX "session
    WHERE lastactivity > 
$datecut AND userid != 0
"
);

$vbulletin->db->query_write(
    
"UPDATE " TABLE_PREFIX "usercounts
            VALUES(" 
TIMENOW ", $users[users]$guests[guests])
"
);

build_datastore('usercount'serialize(array('users' => $users['users'], 'guests' => $guests['guests'])), 1);

$datastore_fetch[]="'usercount'";  

log_cron_action(''$nextitem1);

?>

Is it correct?

kh99 11-07-2010 03:17 PM

1 Attachment(s)
I apologize for making it confusing, so let's start over from the beginning.

1) Drop the table you created from the database (usercounts), delete includes/cron/usercount.php, and if you created a scheduled task or plugin, delete them.

2) Save the usercount.php attachment from this post and ftp it to includes/cron

3) Save the product-usercount.xml attachment and import it as a product. This will create the database table, the plugin, and the scheduled task.

4) To display the values put something like this code in a template:

Code:

<if condition="!empty($vbulletin->usercounts)">
{$vbulletin->usercounts[members]} Members, {$vbulletin->usercounts[guests]} Guests
</if>

Notes:
- The scheduled task is set to run every 15 minutes. If you want to run it at a different interval, you can use the Scheduled Task Manager to change it.
- I changed the database column "users" to "members" so it's not quite the same as the previous code.
- The counts will not display until the task runs at least once, so you can go to the "Scheduled Task Manager" and press the "Run Now" button to force it to run once if you want to.
- If you uninstall the product, it won't remove the database table.

Lynne 11-07-2010 04:27 PM

If they had Reputation here, I know I'd be repping kh99 for all his help! :)

vbdarwin 11-08-2010 05:23 AM

kh99, I have no words to thank you for the wonderful job! :up:

Only, I'm not able to format 'time' to a readable value. :confused:

However, this WORK and THANK YOU ;)

--------------- Added [DATE]1289205457[/DATE] at [TIME]1289205457[/TIME] ---------------

Found!

FROM_UNIXTIME(time)

kh99 11-08-2010 06:06 PM

Quote:

Originally Posted by vbdarwin (Post 2119363)
Found!

FROM_UNIXTIME(time)

I'm glad that worked out - we could change the column type for the time if you wanted to.


All times are GMT. The time now is 06:37 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01213 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete