PDA

View Full Version : Widget - Stats help


IR15H
01-02-2010, 08:38 PM
Hi,

I'm trying convert "Forum Statistics", displayed at the bottom of forum.php into a widget by following Cellarius' Rendering templates and registering variables guide (https://vborg.vbsupport.ru/showthread.php?t=228078) and by cross referencing with Lynne's "Who's Online" mod (https://vborg.vbsupport.ru/showthread.php?t=230428), but I'm not having much joy. Below are the steps I took;


Create a new template

Admin CP > Styles & Templates > Style Manager > Add New Template
Title
vbcms_widget_execphp_stats
Template
<div class="cms_widget">
<div class="block">
<div class="cms_widget_header">
<h3><img src="{vb:stylevar imgdir_misc}/forum_stats.png" title="{vb:raw widget_title}" alt="" /> {vb:raw widget_title}</h3>
</div>
<div class="cms_widget_content">
<div>
<dl>
<dt>{vb:rawphrase threads}</dt>
<dd>{vb:raw totalthreads}</dd>
<dt>{vb:rawphrase posts}</dt>
<dd>{vb:raw totalposts}</dd>
<dt>{vb:rawphrase members}</dt>
<dd>{vb:raw numbermembers}</dd>
<vb:if condition="$show['activemembers']">
<dt>{vb:rawphrase active_members}</dt>
<dd>{vb:raw activemembers}</dd>
</vb:if>
</dl>
<p>{vb:rawphrase welcome_to_our_newest_member_x, {vb:link member, {vb:raw newuserinfo}}, {vb:raw newuserinfo.username}}</p>
</div>
</div>
</div>
</div>
Create a widget

ADMIN CP > vBulletin CMS > Widgets > Create New Widget

Widget Type: PHP Direct Execution
Title: Statistics
Description: Site Statistics.

Configure widget

Enter PHP Direct (taken from forum.php);

// get total threads & posts from the forumcache
$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);

// get total members and newest member from template
$numbermembers = vb_number_format($vbulletin->userstats['numbermembers']);
$newuserinfo = array(
'userid' => $vbulletin->userstats['newuserid'],
'username' => $vbulletin->userstats['newusername']
);
$activemembers = vb_number_format($vbulletin->userstats['activemembers']);
$show['activemembers'] = ($vbulletin->options['activememberdays'] > 0 AND ($vbulletin->options['activememberoptions'] & 2)) ? true : false;


$stats = array('totalthreads' => $totalthreads,
'totalposts' => $totalposts,
'numbermembers' => $numbermembers,
'activemembers' => $activemembers,
'newuserinfo' => $newuserinfo,
);

vB_Template::preRegister('vbcms_widget_execphp_sta ts', $stats);

Template Name
vbcms_widget_execphp_stats



From looking at the guide, I (incorrectly?) thought I defined the array I wanted to use, which includes all my variables, and then registered it for use in my pre-existing template. However, something is wrong as my outcome is;
http://img682.imageshack.us/img682/759/23310562.png

The only difference in methodology I can find is the inclusion of "require_once(DIR . '/includes/functions_bigthree.php'); " at the start of the PHP in Lynne's mod. I don't really understand it, but I think it's basically needed because something required for the mod to work is defined within functions_bigthree.php? As my threads is currently displaying 0, I'm guessing that "threadcount" (amongst others) hasn't been defined properly, as it's not adding this value onto 0.

I did a search for "functions" files containing"threadcount" and discovered it contained within the following files;


includes/functions.php
includes/functions_databuild.php
includes/functions_forumdisplay.php
includes/functions_forumlist.php


I then tried adding these to top of the widget PHP via require_once(DIR . '/includes/functions_filename.php');, but to no avail. I'm now at a dead end as to what to try next to get it to work so any help would be appreciated.

IR15H
01-07-2010, 03:40 PM
Anyone? I've hit a brick wall in terms of trying to get this to work on my own.

kevinchappell
02-11-2010, 11:04 PM
Did you ever figure this out?

IR15H
02-20-2010, 03:12 PM
Did you ever figure this out?

Hi, sorry for the late reply. No I didn't, however, someone else managed to get it to work and released it - https://vborg.vbsupport.ru/showthread.php?t=236403 :).