| 1 |
<?php
|
| 2 |
// $Id: top_users.module,v 1.3 2005/05/24 05:37:14 frjo Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Author: Fredrik Jonsson <fredrik at combonet dot se>
|
| 7 |
* Enables admins to display a block with the top users,
|
| 8 |
* the ones that has posted most comments.
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implementation of hook_help().
|
| 13 |
*/
|
| 14 |
function top_users_help($section = 'admin/help#top_users') {
|
| 15 |
switch ($section) {
|
| 16 |
case 'admin/modules#description':
|
| 17 |
$output = t('Block that display the top users, the ones that has posted most comments.');
|
| 18 |
break;
|
| 19 |
}
|
| 20 |
return $output;
|
| 21 |
}
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Implementation of hook_block().
|
| 25 |
*
|
| 26 |
* Generates a block with the top users,
|
| 27 |
* the ones that has posted most comments/nodes.
|
| 28 |
* $nlimit sets the number of top users to display
|
| 29 |
*/
|
| 30 |
|
| 31 |
function top_users_block($op = 'list', $delta = 0) {
|
| 32 |
if ($op == 'list') {
|
| 33 |
$blocks[0]['info'] = t('Top Users');
|
| 34 |
return $blocks;
|
| 35 |
}
|
| 36 |
else if ($op == 'view') {
|
| 37 |
if (user_access('access content')) {
|
| 38 |
$nlimit = 5;
|
| 39 |
|
| 40 |
$result = db_query_range('SELECT COUNT(c.cid) AS count, u.uid, u.name
|
| 41 |
FROM {comments} c
|
| 42 |
LEFT JOIN {users} u ON c.uid = u.uid
|
| 43 |
WHERE c.uid != 0
|
| 44 |
GROUP BY uid
|
| 45 |
ORDER BY count DESC', 0, $nlimit);
|
| 46 |
$items = array();
|
| 47 |
while ($user = db_fetch_object($result)) {
|
| 48 |
$items[] = format_name($user) .' - '. l(t('%count comments', array('%count' => $user->count)),'tracker/'. $user->uid);
|
| 49 |
}
|
| 50 |
|
| 51 |
$result2 = db_query_range('SELECT COUNT(n.nid) AS count, u.uid, u.name
|
| 52 |
FROM {node} n
|
| 53 |
LEFT JOIN {users} u ON n.uid = u.uid
|
| 54 |
WHERE n.uid != 0
|
| 55 |
GROUP BY uid
|
| 56 |
ORDER BY count DESC', 0, $nlimit);
|
| 57 |
$items2 = array();
|
| 58 |
while ($user = db_fetch_object($result2)) {
|
| 59 |
$items2[] = format_name($user) .' - '. l(t('%count nodes', array('%count' => $user->count)),'tracker/'. $user->uid);
|
| 60 |
}
|
| 61 |
|
| 62 |
$block['subject'] = t('Top Users');
|
| 63 |
if ($items) {
|
| 64 |
$block['content'] = theme('item_list', $items, t('Comments'));
|
| 65 |
}
|
| 66 |
if ($items2) {
|
| 67 |
$block['content'] .= theme('item_list', $items2, t('Nodes'));
|
| 68 |
}
|
| 69 |
}
|
| 70 |
return $block;
|
| 71 |
}
|
| 72 |
}
|
| 73 |
?>
|