vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Total Posts under user statistics (https://vborg.vbsupport.ru/showthread.php?t=282562)

postchan 05-07-2012 11:13 AM

Total Posts under user statistics
 
On the user profile page, Total Posts under user statistics shows both the replies he made or the threads he started as one total count. Is there a way I can split this count into Threads and Posts and display it?

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

I forgot to mention I have vB 3.8.x

kh99 05-07-2012 01:13 PM

If you create a plugin using hook location userprofile_create and this code:

Code:

if ($threads = $registry->db->query_first("SELECT COUNT(*) AS threads FROM " . TABLE_PREFIX . "thread WHERE postuserid = $userinfo[userid] AND open=1 AND visible=1"))
{
    $this->prepared['threads'] = $threads['threads'];
    $this->prepared['replys'] = $userinfo['posts'] - $threads['threads'];
}


then you can edit any of the block templates and insert $prepared[threads] and $prepared[replys].

postchan 05-07-2012 02:52 PM

Thanks so much! It worked like a charm!

kh99 05-07-2012 03:33 PM

Now that I look at it again, you might want to take out "AND open=1" from the query, because that will cause it not to count closed threads which probably isn't what you want.

postchan 05-08-2012 01:58 PM

Hi kh99,

Thanks. I need another bit of info. Can I use the same code to create another plugin for displaying this count in each post. I presume you need the postbit_display_complete hook. Please help.

kh99 05-08-2012 02:04 PM

You could - I haven't tested it but this might work.

Code:

if ($threads = $vbulletin->db->query_first("SELECT COUNT(*) AS threads FROM " . TABLE_PREFIX . "thread WHERE postuserid = $post[userid] AND visible=1"))
{
    $post['threads'] = $threads['threads'];
    $post['replys'] = $post['posts'] - $threads['threads'];
}


But this adds one db query per displayed post. It would be better to do something like add a threads column to the user table and manage the value the same way the user post count is managed, but of course that would be more complicated.

postchan 05-08-2012 02:13 PM

I tried as you said but it gives me the following fatal error:

Fatal error: Call to a member function query_first() on a non-object in /public_html/forums/includes/class_postbit.php(294) : eval()'d code on line 56

kh99 05-08-2012 02:15 PM

Oh yeah...you need to add

Code:

global $vbulletin;

as the first line of the plugin code.

postchan 05-08-2012 02:23 PM

I added the first line but the error persists. I added $post[threads] and $post[replys] in my template. Is that a prob?

kh99 05-08-2012 02:31 PM

OK, I tested this code and it seems to work:

Code:

global $vbulletin;

if ($threads = $vbulletin->db->query_first("SELECT COUNT(*) AS threads FROM " . TABLE_PREFIX . "thread WHERE postuserid = $post[userid] AND visible=1"))
{
    $post['threads'] = $threads['threads'];
    $post['replys'] = $post['posts'] - $threads['threads'];
}


Yes, adding $posts[threads] and $posts[replys] is what you want to do.

(I guess that should really have been "replies" :) ).


All times are GMT. The time now is 05:03 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.01161 seconds
  • Memory Usage 1,727KB
  • 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
  • (4)bbcode_code_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
  • (10)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