View Full Version : Posts Per Month
grey_goose
09-04-2012, 03:31 AM
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?
$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_statist ics',array('postspermonth' => $postspermonth)); // puts variable into template hook
Eosian
09-05-2012, 01:03 AM
What you posted is 'average posts per month' not posts count for the past 30 days.
Hook: member_execute_start
$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_statist ics',array('postspermonth' => $posts['posts'])); // puts variable into template hook
Get fancier;
$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_statist ics',$newvars); // puts variable into template hook
qpurser
09-07-2012, 02:39 PM
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:
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
Eosian
09-07-2012, 02:45 PM
$userinfo['userid'] isn't populating from where you're calling it.
What hook did you set it on?
qpurser
09-07-2012, 02:59 PM
$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.
Eosian
09-07-2012, 03:14 PM
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 ):
$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
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.