Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2013, 10:25 PM
WorldCraft WorldCraft is offline
 
Join Date: Jun 2010
Posts: 240
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Displaying forumstats in a sidebar block

Hello. I'm trying to move the Forum Statistics from What's Going On into a forum block. I read that it was possible to put the code in a template, and then just register the template in a PHP block. I'm there, but how to I access the variables in the template?

Here's my code

Created new template called 'forumhome_forumstats'
Code:
<dl>
	<dt>{vb:rawphrase threads}</dt>
		<dd>{vb:raw totalthreads}</dd><br />
	<dt>{vb:rawphrase posts}</dt>
		<dd>{vb:raw totalposts}</dd><br />
	<dt>{vb:rawphrase members}</dt>
		<dd>{vb:raw numbermembers}</dd><br />
	<vb:if condition="$show['activemembers']">
		<dt>{vb:rawphrase active_members}</dt>
		<dd>{vb:raw activemembers}</dd>
	</vb:if>
</dl>
Created new PHP block
Code:
$templater = vB_Template::create('forumhome_forumstats');

$output = $templater->render();
return $output;
As expected it will display the HTML properly, but not the template variables. How can I access them? I'm new to using the $templater and am a bit stuck.

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

Your php code need to include code to get and/or calculate whatever values you display. If you look at the file forum.php, you can find the code that calculates the values. I believe it depends on having 'userstats' in the $specialtemps array (near the top of the file). You would probably need to have something in your code to fetch it if it doesn't exist, so maybe something like:
Code:
global $vbulletin;

if (empty($vbulletin->userstats))
{
   $vbulletin->datastore->fetch(array('userstats'));
}

// continue with code that uses userstats to calculate statistics
Reply With Quote
  #3  
Old 08-03-2013, 07:29 PM
WorldCraft WorldCraft is offline
 
Join Date: Jun 2010
Posts: 240
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

For some reason that code above breaks, and forumhome is just a white page.
Reply With Quote
  #4  
Old 08-05-2013, 01:00 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Then check your error_logs (if you don't know where they are, ask your host) and see what is there. But, you can't just use that code - you have to write a whole bunch of your own to go with it if you want the stats to display.
Reply With Quote
  #5  
Old 08-05-2013, 03:24 AM
WorldCraft WorldCraft is offline
 
Join Date: Jun 2010
Posts: 240
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
Then check your error_logs (if you don't know where they are, ask your host) and see what is there. But, you can't just use that code - you have to write a whole bunch of your own to go with it if you want the stats to display.
I realize I don't use just that code...it's just that everything breaks when I use what was given above. I'll see if anything of use comes up in the error log.

Edit: Just wanted to point out that $vbulletin->datastore->fetch(array('name')) breaks on two boards I work with (when using it in forum blocks).
Reply With Quote
  #6  
Old 08-05-2013, 07:58 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry about that, I hadn't tried that code at all, and there was a missing close paren which I've fixed, and it also needed a "global".

But thinking about it a little more, the forum block only appears on the home page which already loads the userstats, so you probably don't really need that code (unless you use a mod that puts the sidebar on other pages). You would need to declare $vbulletin as global (as in the first line of code I added above).
Reply With Quote
  #7  
Old 08-05-2013, 10:41 PM
WorldCraft WorldCraft is offline
 
Join Date: Jun 2010
Posts: 240
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Got it working. All I was missing was the global. I had implied that was included automatically. Sorry about that...but thank you for the help!
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 01:23 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03789 seconds
  • Memory Usage 2,214KB
  • Queries Executed 11 (?)
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
  • (3)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete