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

Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2012, 03:31 AM
grey_goose grey_goose is offline
 
Join Date: Jun 2009
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Posts Per Month

I'm looking for a plugin that will give the post count for the last 30 days... I found a couple for 3.x, but they don't work. Has anyone done one for 4.x -or- can anyone modify this one to work?

Code:
$jointime = (TIMENOW - $vbulletin->userinfo['joindate']) / 2419200; //its for a month if you can change to 604800 seconds for 1 week, 84600 for 1 day. 

if ($jointime < 1) // if they join time is less then 1 day 
{ 

    $postspermonth = vb_number_format($vbulletin->userinfo['posts']); put their current post 
} 
else 
{ 
    $postspermonth = vb_number_format($vbulletin->userinfo['posts'] / $jointime, 2); // more than 1 day.. 
} 

vB_Template::preRegister('memberinfo_block_statistics',array('postspermonth' => $postspermonth)); // puts variable into template hook
Reply With Quote
  #2  
Old 09-05-2012, 01:03 AM
Eosian Eosian is offline
 
Join Date: Feb 2009
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What you posted is 'average posts per month' not posts count for the past 30 days.

Hook: member_execute_start


PHP Code:
$posts $vbulletin->db->query_first'select count(*) as posts from post p where p.userid = '  $userinfo['userid'] . ' and p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -30 DAY))' );
vB_Template::preRegister('memberinfo_block_statistics',array('postspermonth' => $posts['posts'])); // puts variable into template hook 
Get fancier;

PHP Code:
$posts $vbulletin->db->query_first'select sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL 0 DAY)), 1, 0)) posts_0_day,sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -1 DAY)), 1, 0)) posts_1_day,sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -7 DAY)), 1, 0)) posts_7_day ,count(*) posts_30_day from post p where p.userid = '  $userinfo['userid'] . ' and p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -30 DAY))');
$newvars = array(
'poststoday' => $posts['posts_0_day']
,
'posts24hours' => $posts['posts_1_day']
,
'poststhisweek' => $posts['posts_7_day']
,
'postspermonth' => $posts['posts_30_day']
);
vB_Template::preRegister('memberinfo_block_statistics',$newvars); // puts variable into template hook 
Reply With Quote
  #3  
Old 09-07-2012, 02:39 PM
qpurser qpurser is offline
 
Join Date: Jul 2011
Posts: 275
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Was looking for something similar and thanks Eosian for trying to help.
I tried out you second suggestion "the fancier" once but got an error.

Database error in vBulletin 4.2.0:

Code:
Invalid SQL:
select sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL 0 DAY)), 1, 0)) posts_0_day,sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -1 DAY)), 1, 0)) posts_1_day,sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -7 DAY)), 1, 0)) posts_7_day ,count(*) posts_30_day from post p where p.userid =  and p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -30 DAY));

MySQL Error   : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -30 DAY))' at line 1
Error Number  : 1064
Reply With Quote
  #4  
Old 09-07-2012, 02:45 PM
Eosian Eosian is offline
 
Join Date: Feb 2009
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$userinfo['userid'] isn't populating from where you're calling it.

What hook did you set it on?
Reply With Quote
  #5  
Old 09-07-2012, 02:59 PM
qpurser qpurser is offline
 
Join Date: Jul 2011
Posts: 275
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Eosian View Post
$userinfo['userid'] isn't populating from where you're calling it.

What hook did you set it on?
I didn't wanted to put it in a template hook but using it in my postbit_legacy.
I did put the query in a module php file for vBadvanced (already have a stats.php module file) and just rendered the variables and used them in a template.

Guess being a novice that was the wrong way to do it or at least the query was not intended to be used in a php file.
Reply With Quote
  #6  
Old 09-07-2012, 03:14 PM
Eosian Eosian is offline
 
Join Date: Feb 2009
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In order to port the code somewhere else you have to supply it a way of identifying the user you want information about. The $userinfo['userid'] needs to be replaced with whatever local variable has the user id of the person your module is referring to.

If it's a page you can only see about yourself it's easy; $vbulletin->userinfo['userid'] is generally globally available as a reference to 'me'. But for any page about someone else you should have some identifier for that person you can use.

(Unrelated to fixing your issue, but none of what I posted was a template hook, that was a standard plugin that registers additional variables to an existing template before it renders by adding additional code to a specific event hook. A template hook is a somewhat different beast)

You could actually use it in your postbit legacy just by changing the hook used. ( showthread_postbit_create and $post['userid'] and register postbit_legacy as the modified template ):

PHP Code:
$posts $vbulletin->db->query_first'select sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL 0 DAY)), 1, 0)) posts_0_day,sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -1 DAY)), 1, 0)) posts_1_day,sum(if( p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -7 DAY)), 1, 0)) posts_7_day ,count(*) posts_30_day from post p where p.userid = '  $post['userid'] . ' and p.dateline >= UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL -30 DAY))'); 
$newvars = array( 
'poststoday' => $posts['posts_0_day'
,
'posts24hours' => $posts['posts_1_day'
,
'poststhisweek' => $posts['posts_7_day'
,
'postspermonth' => $posts['posts_30_day'
); 
vB_Template::preRegister('postbit_legacy',$newvars); // puts variable into template 
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 09:49 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.04450 seconds
  • Memory Usage 2,228KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete