| 1 |
<?php |
<?php |
| 2 |
// $Id: graphstat.user.inc,v 1.2.2.1 2009/01/25 14:32:28 profix898 Exp $ |
// $Id: graphstat.user.inc,v 1.1.2.1 2009/01/25 21:08:34 profix898 Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_graphstat(). |
* Implementation of hook_graphstat(). |
| 6 |
*/ |
*/ |
| 7 |
function graphstat_user_graphstat() { |
function graphstat_user_graphstat() { |
| 8 |
$graphs = array(); |
$graphs = array(); |
|
|
|
|
// Most active users (page hits) |
|
|
if (variable_get('statistics_enable_access_log', 0)) { |
|
|
$top_users_hits_legend = array(); |
|
|
$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); |
|
|
while ($object = db_fetch_object($result)) { |
|
|
$top_users_hits_legend[] = graphstat_statistics_uid2username($object->uid); |
|
|
} |
|
|
} |
|
|
|
|
|
// Most active users (number of nodes) |
|
|
$top_users_nodes_legend = array(); |
|
|
$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); |
|
|
while ($object = db_fetch_object($result)) { |
|
|
$top_users_nodes_legend[] = graphstat_statistics_uid2username($object->uid); |
|
|
} |
|
| 9 |
|
|
| 10 |
$graphs['activity'] = array( |
$graphs['users'] = array( |
| 11 |
'#title' => t('User Activity'), |
'#title' => t('Users'), |
| 12 |
|
'graph_user_roles' => array( |
| 13 |
|
'#type' => 'bars', |
| 14 |
|
'#title' => t('Users per role') |
| 15 |
|
), |
| 16 |
'graph_user_hits' => array( |
'graph_user_hits' => array( |
| 17 |
'#type' => 'pie', |
'#type' => 'pie', |
| 18 |
'#title' => t('Most active users (page hits)'), |
'#title' => t('Most active users (page hits)') |
|
'#legend' => isset($top_users_hits_legend) ? $top_users_hits_legend : NULL |
|
| 19 |
), |
), |
| 20 |
'graph_user_nodes' => array( |
'graph_user_nodes' => array( |
| 21 |
'#type' => 'pie', |
'#type' => 'pie', |
| 22 |
'#title' => t('Most active users (number of nodes)'), |
'#title' => t('Most active users (number of nodes)') |
|
'#legend' => $top_users_nodes_legend |
|
| 23 |
) |
) |
| 24 |
); |
); |
| 25 |
|
|
| 26 |
// Most active users (number of comments) |
// Most active users (number of comments) |
| 27 |
if (module_exists('comment')) { |
if (module_exists('comment')) { |
| 28 |
$top_users_comments_legend = array(); |
$graphs['users']['graph_user_comments'] = array( |
|
$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); |
|
|
while ($object = db_fetch_object($result)) { |
|
|
$top_users_comments_legend[] = graphstat_statistics_uid2username($object->uid); |
|
|
} |
|
|
|
|
|
$graphs['activity']['graph_user_comments'] = array( |
|
| 29 |
'#type' => 'pie', |
'#type' => 'pie', |
| 30 |
'#title' => t('Most active users (number of comments)'), |
'#title' => t('Most active users (number of comments)') |
|
'#legend' => $top_users_comments_legend |
|
| 31 |
); |
); |
| 32 |
} |
} |
| 33 |
|
|
| 40 |
function graphstat_user_graphstat_data() { |
function graphstat_user_graphstat_data() { |
| 41 |
$data = array(); |
$data = array(); |
| 42 |
|
|
| 43 |
|
// Users per role |
| 44 |
|
$data['users']['graph_user_roles'] = array(0 => array(0 => '')); |
| 45 |
|
foreach (user_roles(TRUE) as $rid => $role_name) { |
| 46 |
|
if ($rid != DRUPAL_AUTHENTICATED_RID) { |
| 47 |
|
$data['users']['graph_user_roles'][0][] = db_result(db_query('SELECT COUNT(uid) FROM {users_roles} WHERE rid = %d', $rid)); |
| 48 |
|
$data['users']['graph_user_roles']['#legend'][] = $role_name; |
| 49 |
|
} |
| 50 |
|
} |
| 51 |
|
|
| 52 |
// Most active users (page hits) |
// Most active users (page hits) |
| 53 |
if (variable_get('statistics_enable_access_log', 0)) { |
if (variable_get('statistics_enable_access_log', 0)) { |
| 54 |
$top_users_hits = array(''); |
$top_users_hits = array(''); |
| 55 |
|
$top_users_hits_legend = array(); |
| 56 |
$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); |
$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); |
| 57 |
while ($object = db_fetch_object($result)) { |
while ($object = db_fetch_object($result)) { |
| 58 |
$top_users_hits[] = $object->hits; |
$top_users_hits[] = $object->hits; |
| 59 |
|
$top_users_hits_legend[] = graphstat_statistics_uid2username($object->uid); |
| 60 |
} |
} |
| 61 |
$total_hits = max(array_sum($top_users_hits), 1); |
$total_hits = max(array_sum($top_users_hits), 1); |
| 62 |
$data['activity']['graph_user_hits'] = array(0 => array()); |
$data['users']['graph_user_hits'] = array(0 => array()); |
| 63 |
foreach ($top_users_hits as $pos => $hits) { |
foreach ($top_users_hits as $pos => $hits) { |
| 64 |
$data['activity']['graph_user_hits'][0][$pos] = round($hits / $total_hits * 100, 1); |
$data['users']['graph_user_hits'][0][$pos] = round($hits / $total_hits * 100, 1); |
| 65 |
} |
} |
| 66 |
|
$data['users']['graph_user_hits']['#legend'] = $top_users_hits_legend; |
| 67 |
} |
} |
| 68 |
|
|
| 69 |
// Most active users (number of nodes) |
// Most active users (number of nodes) |
| 70 |
$top_users_nodes = array(''); |
$top_users_nodes = array(''); |
| 71 |
|
$top_users_nodes_legend = array(); |
| 72 |
$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); |
$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); |
| 73 |
while ($object = db_fetch_object($result)) { |
while ($object = db_fetch_object($result)) { |
| 74 |
$top_users_nodes[] = $object->nodes; |
$top_users_nodes[] = $object->nodes; |
| 75 |
|
$top_users_nodes_legend[] = graphstat_statistics_uid2username($object->uid); |
| 76 |
} |
} |
| 77 |
$total_nodes = max(array_sum($top_users_nodes), 1); |
$total_nodes = max(array_sum($top_users_nodes), 1); |
| 78 |
$data['activity']['graph_user_nodes'] = array(0 => array()); |
$data['users']['graph_user_nodes'] = array(0 => array()); |
| 79 |
foreach ($top_users_nodes as $pos => $nodes) { |
foreach ($top_users_nodes as $pos => $nodes) { |
| 80 |
$data['activity']['graph_user_nodes'][0][$pos] = round($nodes / $total_nodes * 100, 1); |
$data['users']['graph_user_nodes'][0][$pos] = round($nodes / $total_nodes * 100, 1); |
| 81 |
} |
} |
| 82 |
|
$data['users']['graph_user_nodes']['#legend'] = $top_users_nodes_legend; |
| 83 |
|
|
| 84 |
// Most active users (number of comments) |
// Most active users (number of comments) |
| 85 |
if (module_exists('comment')) { |
if (module_exists('comment')) { |
| 86 |
$top_users_comments = array(''); |
$top_users_comments = array(''); |
| 87 |
|
$top_users_comments_legend = array(); |
| 88 |
$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); |
$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); |
| 89 |
while ($object = db_fetch_object($result)) { |
while ($object = db_fetch_object($result)) { |
| 90 |
$top_users_comments[] = $object->comments; |
$top_users_comments[] = $object->comments; |
| 91 |
|
$top_users_comments_legend[] = graphstat_statistics_uid2username($object->uid); |
| 92 |
} |
} |
| 93 |
$total_comments = max(array_sum($top_users_comments), 1); |
$total_comments = max(array_sum($top_users_comments), 1); |
| 94 |
$data['activity']['graph_user_comments'] = array(0 => array()); |
$data['users']['graph_user_comments'] = array(0 => array()); |
| 95 |
foreach ($top_users_comments as $pos => $comments) { |
foreach ($top_users_comments as $pos => $comments) { |
| 96 |
$data['activity']['graph_user_comments'][0][$pos] = round($comments / $total_comments * 100, 1); |
$data['users']['graph_user_comments'][0][$pos] = round($comments / $total_comments * 100, 1); |
| 97 |
} |
} |
| 98 |
if (count($data['activity']['graph_user_comments'][0][$pos]) < 2) { |
$data['users']['graph_user_comments']['#legend'] = $top_users_nodes_legend; |
| 99 |
$data['activity']['graph_user_comments'] = NULL; |
if (count($data['users']['graph_user_comments'][0][$pos]) < 2) { |
| 100 |
|
$data['users']['graph_user_comments'] = NULL; |
| 101 |
} |
} |
| 102 |
} |
} |
| 103 |
|
|
| 108 |
* Function graphstat_statistics_uid2username(). |
* Function graphstat_statistics_uid2username(). |
| 109 |
*/ |
*/ |
| 110 |
function graphstat_statistics_uid2username($uid) { |
function graphstat_statistics_uid2username($uid) { |
| 111 |
if ($uid) { |
if ($uid && $user = user_load(array('uid' => $uid))) { |
|
$user = user_load(array('uid' => $uid)); |
|
| 112 |
return $user->name; |
return $user->name; |
| 113 |
} |
} |
| 114 |
else { |
|
| 115 |
return variable_get('anonymous', t('anonymous')); |
return variable_get('anonymous', t('anonymous')); |
|
} |
|
| 116 |
} |
} |