Add forum statistics section
Mapi99 - June 4, 2008 - 18:21
| Project: | Advanced Forum |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Morbus Iff |
| Status: | closed |
Description
This will create a new block under the forums called "What's Going On?", it displays the number of members, posts, and topics your forum has, along with the online users and the latest member.
I am currently adding:
In advanced_forum.module add:
<?php
// $Id$
/************************* GENERAL FUNCTIONS *********************************/
// Count total amount of forum threads*
function advanced_statistics_topics() {
$topics = db_result(db_query('SELECT COUNT(vid) AS number FROM {forum}'));
return $topics;
}
// Count total amount of forum posts
function advanced_statistics_posts() {
$posts = db_result(db_query('SELECT COUNT(cid) AS number FROM {comments}'));
return $posts;
}
// Count total amount of members
function advanced_statistics_members() {
$members = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));
return $members;
}
// Display latest member
function advanced_statistics_latestmember() {
$l_member = db_result(db_query('SELECT name FROM {users} ORDER BY created DESC'));
return $l_member;
}
// Grab latest member uid
function advanced_statistics_latestmemberuid() {
$l_member_uid = db_result(db_query('SELECT uid FROM {users} ORDER BY created DESC'));
return $l_member_uid;
}
// Formatting the userlist
function advanced_statistics_onlineusers() {
if (user_access('access content')) {
$interval = time() - variable_get('user_block_seconds_online', 900);
$anonymous_count = sess_count($interval);
$authenticated_users = db_query('SELECT DISTINCT u.uid, u.name, s.timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid > 0 ORDER BY s.timestamp DESC', $interval);
$authenticated_count = 0;
$max_users = variable_get('user_block_max_list_count', 10);
$items = array();
while ($account = db_fetch_object($authenticated_users)) {
if ($max_users > 0) {
$items[] = $account;
$max_users--;
}
$authenticated_count++;
}
// Output the userlist.
$max_users = variable_get('user_block_max_list_count', 10);
if ($authenticated_count && $max_users) {
$list = array();
foreach ($items as $item) {
$list[] = l($item->name, 'user/' . $item->uid);
}
$output .= implode(', ', $list);
}
$online_users = $output;
}
return $online_users;
}
/** Commented out - Requires fix
// Most users ever online
function advanced_statistics_mostonline() {
$anonymous_count = sess_count($interval);
$authenticated_users = db_query('SELECT DISTINCT u.uid, u.name, s.timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid > 0 ORDER BY s.timestamp DESC', $interval);
$authenticated_count = 0;
$total_users_online = $authenticated_users;
if (variable_get('most_users_online_ever', '') < $total_users_online) {
variable_set('most_users_online_ever', $total_users_online);
variable_set('most_users_online_ever_time', time());
}
$output .= "Most users ever online was " . variable_get('most_users_online_ever', '');
$output .= " on " . format_date(variable_get('most_users_online_ever_time', ''), 'medium', '');
$mostonline = $output;
return $mostonline;
}
**/
// Currently online users
function advanced_statistics_curonline() {
$anonymous_count = sess_count($interval);
$authenticated_users = db_query('SELECT DISTINCT u.uid, u.name, s.timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid > 0 ORDER BY s.timestamp DESC', $interval);
$authenticated_count = 0;
// Format the output with proper grammar.
if ($anonymous_count == 1 && $authenticated_count == 1) {
$output = t('Currently active users: %total (%members and %visitors)', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
}
else {
$output = t('Currently active users: %total (%members and %visitors)', array ('%total' => format_plural($authenticated_count + $anonymous_count, '1', '@count'), '%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
}
$curonline = $output;
return $curonline;
}In advanced_forum/themes/advforum/advf-forum-list.tpl add:
<table id="forum">
<thead>
<tr>
<th><?php print t('What\'s Going On?'); ?></th>
</tr>
</thead>
<tbody>
<tr id="forum-list">
<td class="container"><?php print $curonline ?></td>
</tr>
<td><?php /** Req. Fix print $mostonline ?>
<br/> **/ ?>
<?php print $online_users ?>
</td>
<tr id="forum-list">
<td class="container"><?php print t('Statistics') ?></td>
</tr>
<td><?php print t('Topics: ') . $topics . t(',') ?>
<?php print t('Posts: ') . $posts . t(',') ?>
<?php print t('Members: ') . $members ?>
<br/>
<?php print t('Welcome to our latest member, ')?><a href="?q=user/<?php print $l_member_uid; ?>"><?php print $l_member; ?></a>
</td>
</tbody>
</table>In advanced_forum.module after
function advanced_forum_preprocess_forum_list(&$variables) {
$variables['template_files'][] = 'advf-forum-list';
// Add in a link to the last topic in each forum
$last_topics = advanced_forum_get_all_last_topics();
foreach ($variables['forums'] as $tid => $forum) {
// In the forum overview, we want to overwrite the last reply with our custom one
$variables['forums'][$tid]->last_reply = theme('forum_submitted', $last_topics[$tid]);
}Add after:
/ Advanced Statistics for Advanced Forum
if (module_exists('advanced_statistics')) {
$variables['topics'] = advanced_statistics_topics();
$variables['posts'] = advanced_statistics_posts();
$variables['members'] = advanced_statistics_members();
$variables['l_member'] = advanced_statistics_latestmember();
$variables['l_member_uid'] = advanced_statistics_latestmemberuid();
$variables['online_users'] = advanced_statistics_onlineusers();
/** Req. Fix $variables['mostonline'] = advanced_statistics_mostonline(); **/
$variables['curonline'] = advanced_statistics_curonline();All the features that are commented out or missing as of now, i am actively working on them and they will be fixed and reposted here in a matter of days.
Thanks,
Mapi

#1
Apoligies i have posted the last bit wrong, it should be:
// Advanced Statistics for Advanced Forumif (module_exists('advanced_statistics')) {
$variables['topics'] = advanced_statistics_topics();
$variables['posts'] = advanced_statistics_posts();
$variables['members'] = advanced_statistics_members();
$variables['l_member'] = advanced_statistics_latestmember();
$variables['l_member_uid'] = advanced_statistics_latestmemberuid();
$variables['online_users'] = advanced_statistics_onlineusers();
/** Req. Fix $variables['mostonline'] = advanced_statistics_mostonline(); **/
$variables['curonline'] = advanced_statistics_curonline();
Thanks,
Mapi
#2
Thanks for this. I mentioned it to you on IRC but for the benefit of any lurkers, I'll get this added ASAP.
Michelle
#3
Is this in yet?
#4
No, I haven't had time to work on my modules for quite some time.
Michelle
#5
subscribing.
#6
wonderful, great work. Subscribing.
#7
"All the features that are commented out or missing as of now, i am actively working on them and they will be fixed and reposted here in a matter of days."
Have you done any more work on this? I've been going thru and hitting the bug / support request issues and have cleaned up quite a bit. I'd like to get a couple features in the next alpha as well.
Thanks,
Michelle
#8
Adding to the to do list.
Michelle
#9
@Mapi99 - Are you planning on finishing this? I'd like to have it in the next alpha but don't have the b/w to put a lot of time into it. If you can get me something ready to go I'll add it. Otherwise it's not going to make this alpha.
Michelle
#10
Ill try in the weekend i'm totally swamped right now with work :/
It's about done tough, theres about two things that need to be fixed but i could use some help with them.
#11
Well, no hurry now. It's not going to make it into the alpha as I'm really pushing to release that ASAP so just winding up the last couple issues. Once the alpha is out, I will start looking at adding new features again and this will be top of the list. I'll be able to spare more time to figure it out since I won't be pushing for an alpha so hard.
Michelle
#12
Sounds good, that code was the best i could do at the time, its about 90% of what it should be i guess, i'm pretty swamped so i'm not sure when or if i'll be able to finish it.
It'll be good if you take a look at it
#13
Ok, here's a first stab at a rewrite against the D5 branch.
* I've only touched the 'naked' style until we agree this is awesomeeEEe.
* "Most online users" has been removed entirely; worry about it later.
* I think this will display at the bottom of every container; needs testing.
* Removes the table abuse and does it all in CSS (which means colors in the .css. frown.)
* Renames all functions, lots of cleanup, bug fixing, relogic.
* Standardizes on "User" not "Member" (vBulletin uses both interchangeably. frown!)
* Colors were set to a client site I was dev'ing this for. Needs Garland/default color love.
* Screenshot is attached.
#14
can someone please make this for D6
great idea by the way :)
#15
Babalu: Michelle will port this to D6 when she adds it. (She's keeping both D5 and D6 in tandem.)
#16
ok great. thx
#17
To prevent a warning, this patch needs the following addition to the first line of advanced_forum_statistics_online_users():
$list = array();#18
Ok, I used Morbus' patch, added it to all styles, fixed up the colors a bit to match the styles, split it up between the two CSS files, and committed the whole lot to both branches.
Thanks!
Michelle
#19
Automatically closed -- issue fixed for two weeks with no activity.
#20
Looks great guys, ive been out for a while unfortunately and im thrilled to see that my idea made it into the module
-Mapi
#21
Yep, thanks for getting us started, Mapi99 :)
Michelle
#22
Ive only noticed one problem with it so far, when you go to the forum on i.e two browsers it shows two users, so it shows Mapi twice.
#23
That's normal... As far as Drupal is concerned you are on there twice.
Michelle
#24
Alright, so there is no way to make it only show your user once?
Also, would there be a way to make it show what users are currently viewing a page?
#25
"Alright, so there is no way to make it only show your user once?"
Not that I know of. Maybe someone with better SQL skills than me can write a patch.
"Also, would there be a way to make it show what users are currently viewing a page?"
Probably, but that would be a 2.x feature and would need its own issue instead of piling on this already closed one. ;)
Michelle