PDA

View Full Version : phpinclude_start trouble - Forum Stats in Header


Neutral Singh
09-01-2005, 04:10 AM
Hi

There used to be smart little Forum stats hack which enabled me to show some important forum stats like no. of members, posts, threads etc in the header template to be shown on each forum page. In vB3.0.7, i could do it simply by putting the following code in the phpinclude_start template and then call the variables in header template.

Now with the advent of vB3.5, phpinclude_start has been removed and global_start hook has taken its place. I tried to create a plugin by using global_start hook and putting exactly the same code (below) in that plugin but as expected it resulted in an error.

How can use the plugin system to show the information in the header template? I believe some minor changes in the following code would do the trick but my expertise in PHP are pretty novice. Please guide me.

Thanks.


// forum stats start
$numbersmembers=$DB_site->query_first('SELECT COUNT(*) AS users,MAX(userid) AS max FROM user');
$numbermembers=number_format($numbersmembers['users']);
$countposts=$DB_site->query_first('SELECT COUNT(*) AS posts FROM post');
$totalposts=number_format($countposts['posts']);
$countthreads=$DB_site->query_first('SELECT COUNT(*) AS threads FROM thread');
$totalthreads=number_format($countthreads['threads']);
// forum stats end

// total online start
$datecut = TIMENOW - $vboptions['cookietimeout'];
$headerguests=$DB_site->query_first("SELECT COUNT(*) AS count FROM session WHERE userid=0 AND lastactivity>$datecut");
$headerusers=$DB_site->query_first("SELECT COUNT(DISTINCT(userid)) AS count FROM session WHERE session.userid>0 AND session.lastactivity>$datecut");
$headerguests=$headerguests[count];
$headerusers=$headerusers[count];
$totalonline=$headerguests+$headerusers;
// total online end

// get newest member name and userid start
$getnewestmember=$DB_site->query_first("SELECT userid, username FROM user WHERE userid=$numbersmembers[max]");
$newusername = $getnewestmember['username'];
$newuserid = $getnewestmember['userid'];
// get newest member name and userid end

Boofo
09-02-2005, 12:13 AM
First of all, this has changed:

$DB_site

Fix those and that will definately help. ;)

Andreas
09-02-2005, 12:31 AM
Try


// forum stats start
$numbersmembers = $db->query_first("SELECT COUNT(*) AS users,MAX(userid) AS max FROM user");
$numbermembers = number_format($numbersmembers['users']);
$counter = $db->query_first("SELECT COUNT(postid) AS posts, COUNT(threadid) AS threads FROM " . TABLE_PREFIX . "post");
$totalposts=number_format($counter['posts']);
$totalthreads=number_format($counter['threads']);
// forum stats end

// total online start
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$headerguests=$db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "session WHERE userid=0 AND lastactivity>$datecut");
$headerusers=$db->query_first("SELECT COUNT(DISTINCT(userid)) AS count FROM " . TABLE_PREFIX . "session WHERE session.userid>0 AND session.lastactivity>$datecut");
$headerguests=$headerguests[count];
$headerusers=$headerusers[count];
$totalonline=$headerguests+$headerusers;
// total online end

// get newest member name and userid start
$getnewestmember=$db->query_first("SELECT userid, username FROM " . TABLE_PREFIX . "user WHERE userid=$numbersmembers[max]");
$newusername = $getnewestmember['username'];
$newuserid = $getnewestmember['userid'];
// get newest member name and userid end


But this should still be optimized
- You can get rid of 2 Queries by using Datastore Item userstats (but this requires a File Edit)
- It might be possible to do the online stuff in 1 query

Neutral Singh
09-02-2005, 05:25 AM
woohooo!! it works flawlessly !! Thanks.