vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Posts Per Month (https://vborg.vbsupport.ru/showthread.php?t=287435)

grey_goose 09-04-2012 03:31 AM

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


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


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 


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:

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


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

Quote:

Originally Posted by Eosian (Post 2363372)
$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 ):

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 



All times are GMT. The time now is 12:12 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.01543 seconds
  • Memory Usage 1,745KB
  • 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
  • (2)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete