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 01-22-2013, 05:51 PM
eviljoker7075 eviljoker7075 is offline
 
Join Date: Dec 2008
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Displaying VB Variables in external page - particularly forum stats

Hi all, I am attempting to create a php file that displays my forum stats, to use as an include in a wordpress themplate.

So far I have the following code, saved as a file in my forum root directory:

Code:
<?php 

require_once('./global.php');

echo {vb:raw numbermembers};

?>
I know it's the echo line that's causing a problem, the thing is I'm new to php so don't really know how this should be formatted.


Can anyone help?
Reply With Quote
  #2  
Old 01-22-2013, 05:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The {vb:raw numbermembers} is something that can only be used in vbulletin templates. You could do something like echo $numbermembers, but you need to calculate $numbermembers first. If you look in forum.php and search for "BOARD STATISTICS" you can find the section that calculates it.

Also, for that code to work you would need to get the 'userstats' loaded from the datastore, so you'd need
Code:
$specialtemplates = array('userstats');

before you include global.php.

Edit: now that I look at it more, there isn't much of a calculation for numbermembers, it just formats the number.
Reply With Quote
Благодарность от:
eviljoker7075
  #3  
Old 01-22-2013, 06:19 PM
eviljoker7075 eviljoker7075 is offline
 
Join Date: Dec 2008
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What an incredibly helpful answer, thanks you! So I have the following working code, that gives me the total number of members:

Code:
<?php 
$specialtemplates = array('userstats');
require_once('./global.php');


$numbermembers = vb_number_format($vbulletin->userstats['numbermembers']);
echo $numbermembers;


?>

However, I also want to add in the total number of posts and threads, so I tried the below:

Code:
<?php 
$specialtemplates = array('userstats');
$specialtemplates = array('forumcache');
require_once('./global.php');


$numbermembers = vb_number_format($vbulletin->userstats['numbermembers']);
echo $numbermembers;




$totalthreads = 0;
$totalposts = 0;

if (is_array($vbulletin->forumcache)){
	foreach ($vbulletin->forumcache AS $forum)
	
	{
		$totalthreads += $forum['threadcount'];
		$totalposts += $forum['replycount'];
	}
}

$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);

echo $totalthreads;
echo $totalposts;



?>
This doesn't work, and gives me '0' for each of the echos. I'm guessing the issue is that I'm not calling in the specialtemplates correctly now that there's more than one - how should these be formatted?

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

The forum info always gets loaded, so you don't have to include that in $specialtemplates (in fact you really want to remove that second $specialtemplates line because it's overwriting what the first one does). But the forumcache doesn't include the thread and post count info. There's another function that adds that info, called cache_ordered_forums(). So if you add a call to that function like:
Code:
cache_ordered_forums(1, 1);

after global.php is included and before you do the calculations, then it should work.
Reply With Quote
  #5  
Old 01-23-2013, 06:09 AM
eviljoker7075 eviljoker7075 is offline
 
Join Date: Dec 2008
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Perfect! Thank you very much. For anyone also wishing to do the same,

HERE IS THE FINAL WORKING CODE:

File: 'forumStats.php' - saved in the root directory of my forum
Code:
<?php 
$specialtemplates = array('userstats');
require_once('./global.php');
cache_ordered_forums(1, 1);


$numbermembers = vb_number_format($vbulletin->userstats['numbermembers']);
echo 'Members: ';
echo $numbermembers;


$totalthreads = 0;
$totalposts = 0;

if (is_array($vbulletin->forumcache)){
	foreach ($vbulletin->forumcache AS $forum)
	
	{
		$totalthreads += $forum['threadcount'];
		$totalposts += $forum['replycount'];
	}
}

$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);

echo ' Thread: ';
echo $totalthreads;

echo ' Posts: ';
echo $totalposts;

?>

However (there's always a but, right), when I add this as an include on my website homepage (running wordpress) I get an error. I have placed the following line into my template:
PHP Code:
<?php include('./forum/forumStats.php'); ?>
And on the page I get this error:
Quote:
Warning: require_once(./global.php) [function.require-once]: failed to open stream: No such file or directory in /home/sitedir/public_html/forum/forumStats.php on line 3
I am assuming that it's looking for global.php in the root of my site, rather than in the forum directory - but is there a way round this?
Reply With Quote
  #6  
Old 01-23-2013, 12:32 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're right. Try this for the beginning of the code:

Code:
<?php 
$specialtemplates = array('userstats');
chdir('./forum');
require_once('./global.php');
cache_ordered_forums(1, 1);

If you wanted you could chdir() to the absolute path instead. And also you could save the current directory and chdir back after including gobal.php, but if that's the entire code then it doesn't look like it's necessary.
Reply With Quote
  #7  
Old 01-23-2013, 04:51 PM
eviljoker7075 eviljoker7075 is offline
 
Join Date: Dec 2008
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That did the trick nicely! Thank you so much for your help, I've learnt a lot.
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 07:45 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.07139 seconds
  • Memory Usage 2,229KB
  • 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
  • (7)bbcode_code
  • (1)bbcode_php
  • (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
  • (1)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete