Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #11  
Old 11-07-2010, 02:16 PM
vbdarwin vbdarwin is offline
 
Join Date: Nov 2010
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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?
Reply With Quote
  #12  
Old 11-07-2010, 03:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Attached Files
File Type: php usercount.php (897 Bytes, 3 views)
File Type: xml product-usercount.xml (2.0 KB, 2 views)
Reply With Quote
  #13  
Old 11-07-2010, 04:27 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If they had Reputation here, I know I'd be repping kh99 for all his help!
Reply With Quote
  #14  
Old 11-08-2010, 05:23 AM
vbdarwin vbdarwin is offline
 
Join Date: Nov 2010
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

However, this WORK and THANK YOU

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

Found!

FROM_UNIXTIME(time)
Reply With Quote
  #15  
Old 11-08-2010, 06:06 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vbdarwin View Post
Found!

FROM_UNIXTIME(time)
I'm glad that worked out - we could change the column type for the time if you wanted to.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:47 PM.


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.03696 seconds
  • Memory Usage 2,237KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (2)postbit_attachment
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete