| 1 |
|
<?php |
| 2 |
|
// $Id: graphstat.user.inc,v 1.2.2.1 2009/01/25 14:32:28 profix898 Exp $ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* Implementation of hook_graphstat(). |
| 6 |
|
*/ |
| 7 |
|
function graphstat_user_graphstat() { |
| 8 |
|
$graphs = array(); |
| 9 |
|
|
| 10 |
|
// Most active users (page hits) |
| 11 |
|
if (variable_get('statistics_enable_access_log', 0)) { |
| 12 |
|
$top_users_hits_legend = array(); |
| 13 |
|
$result = db_query_range("SELECT uid, COUNT(DISTINCT(url)) AS hits FROM {accesslog} WHERE url <> '' GROUP BY uid ORDER BY hits DESC", $_SERVER['HTTP_HOST'], 0, 10); |
| 14 |
|
while ($object = db_fetch_object($result)) { |
| 15 |
|
$top_users_hits_legend[] = graphstat_statistics_uid2username($object->uid); |
| 16 |
|
} |
| 17 |
|
} |
| 18 |
|
|
| 19 |
|
// Most active users (number of nodes) |
| 20 |
|
$top_users_nodes_legend = array(); |
| 21 |
|
$result = db_query_range("SELECT uid, COUNT(nid) AS nodes FROM {node} WHERE nid <> 0 GROUP BY uid ORDER BY nodes DESC", $_SERVER['HTTP_HOST'], 0, 10); |
| 22 |
|
while ($object = db_fetch_object($result)) { |
| 23 |
|
$top_users_nodes_legend[] = graphstat_statistics_uid2username($object->uid); |
| 24 |
|
} |
| 25 |
|
|
| 26 |
|
$graphs['activity'] = array( |
| 27 |
|
'#title' => t('User Activity'), |
| 28 |
|
'graph_user_hits' => array( |
| 29 |
|
'#type' => 'pie', |
| 30 |
|
'#title' => t('Most active users (page hits)'), |
| 31 |
|
'#legend' => isset($top_users_hits_legend) ? $top_users_hits_legend : NULL |
| 32 |
|
), |
| 33 |
|
'graph_user_nodes' => array( |
| 34 |
|
'#type' => 'pie', |
| 35 |
|
'#title' => t('Most active users (number of nodes)'), |
| 36 |
|
'#legend' => $top_users_nodes_legend |
| 37 |
|
) |
| 38 |
|
); |
| 39 |
|
|
| 40 |
|
// Most active users (number of comments) |
| 41 |
|
if (module_exists('comment')) { |
| 42 |
|
$top_users_comments_legend = array(); |
| 43 |
|
$result = db_query_range("SELECT uid, COUNT(cid) AS comments FROM {comments} WHERE cid <> 0 GROUP BY uid ORDER BY comments DESC", $_SERVER['HTTP_HOST'], 0, 10); |
| 44 |
|
while ($object = db_fetch_object($result)) { |
| 45 |
|
$top_users_comments_legend[] = graphstat_statistics_uid2username($object->uid); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
$graphs['activity']['graph_user_comments'] = array( |
| 49 |
|
'#type' => 'pie', |
| 50 |
|
'#title' => t('Most active users (number of comments)'), |
| 51 |
|
'#legend' => $top_users_comments_legend |
| 52 |
|
); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
return $graphs; |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
/** |
| 59 |
|
* Implementation of hook_graphstat_data(). |
| 60 |
|
*/ |
| 61 |
|
function graphstat_user_graphstat_data() { |
| 62 |
|
$data = array(); |
| 63 |
|
|
| 64 |
|
// Most active users (page hits) |
| 65 |
|
if (variable_get('statistics_enable_access_log', 0)) { |
| 66 |
|
$top_users_hits = array(''); |
| 67 |
|
$result = db_query_range("SELECT uid, COUNT(DISTINCT(url)) AS hits FROM {accesslog} WHERE url <> '' GROUP BY uid ORDER BY hits DESC", $_SERVER['HTTP_HOST'], 0, 10); |
| 68 |
|
while ($object = db_fetch_object($result)) { |
| 69 |
|
$top_users_hits[] = $object->hits; |
| 70 |
|
} |
| 71 |
|
$total_hits = max(array_sum($top_users_hits), 1); |
| 72 |
|
$data['activity']['graph_user_hits'] = array(0 => array()); |
| 73 |
|
foreach ($top_users_hits as $pos => $hits) { |
| 74 |
|
$data['activity']['graph_user_hits'][0][$pos] = round($hits / $total_hits * 100, 1); |
| 75 |
|
} |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
// Most active users (number of nodes) |
| 79 |
|
$top_users_nodes = array(''); |
| 80 |
|
$result = db_query_range("SELECT uid, COUNT(nid) AS nodes FROM {node} WHERE nid <> 0 GROUP BY uid ORDER BY nodes DESC", $_SERVER['HTTP_HOST'], 0, 10); |
| 81 |
|
while ($object = db_fetch_object($result)) { |
| 82 |
|
$top_users_nodes[] = $object->nodes; |
| 83 |
|
} |
| 84 |
|
$total_nodes = max(array_sum($top_users_nodes), 1); |
| 85 |
|
$data['activity']['graph_user_nodes'] = array(0 => array()); |
| 86 |
|
foreach ($top_users_nodes as $pos => $nodes) { |
| 87 |
|
$data['activity']['graph_user_nodes'][0][$pos] = round($nodes / $total_nodes * 100, 1); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
// Most active users (number of comments) |
| 91 |
|
if (module_exists('comment')) { |
| 92 |
|
$top_users_comments = array(''); |
| 93 |
|
$result = db_query_range("SELECT uid, COUNT(cid) AS comments FROM {comments} WHERE cid <> 0 GROUP BY uid ORDER BY comments DESC", $_SERVER['HTTP_HOST'], 0, 10); |
| 94 |
|
while ($object = db_fetch_object($result)) { |
| 95 |
|
$top_users_comments[] = $object->comments; |
| 96 |
|
} |
| 97 |
|
$total_comments = max(array_sum($top_users_comments), 1); |
| 98 |
|
$data['activity']['graph_user_comments'] = array(0 => array()); |
| 99 |
|
foreach ($top_users_comments as $pos => $comments) { |
| 100 |
|
$data['activity']['graph_user_comments'][0][$pos] = round($comments / $total_comments * 100, 1); |
| 101 |
|
} |
| 102 |
|
if (count($data['activity']['graph_user_comments'][0][$pos]) < 2) { |
| 103 |
|
$data['activity']['graph_user_comments'] = NULL; |
| 104 |
|
} |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
return $data; |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
/** |
| 111 |
|
* Function graphstat_statistics_uid2username(). |
| 112 |
|
*/ |
| 113 |
|
function graphstat_statistics_uid2username($uid) { |
| 114 |
|
if ($uid) { |
| 115 |
|
$user = user_load(array('uid' => $uid)); |
| 116 |
|
return $user->name; |
| 117 |
|
} |
| 118 |
|
else { |
| 119 |
|
return variable_get('anonymous', t('anonymous')); |
| 120 |
|
} |
| 121 |
|
} |