| 1 |
|
<?php |
| 2 |
|
// $Id: graphstat_statistics.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_system_graphstat() { |
| 8 |
|
$graphs = array(); |
| 9 |
|
$graphs['history'] = array( |
| 10 |
|
'#title' => t('History'), |
| 11 |
|
'graph_nodes' => array( |
| 12 |
|
'#title' => t('Number of Nodes'), |
| 13 |
|
'#xlabel' => t('Date (MM/DD/YYYY)'), |
| 14 |
|
'#ylabel' => t('# Nodes') |
| 15 |
|
), |
| 16 |
|
'graph_users' => array( |
| 17 |
|
'#title' => t('Number of Users'), |
| 18 |
|
'#xlabel' => t('Date (MM/DD/YYYY)'), |
| 19 |
|
'#ylabel' => t('# Users') |
| 20 |
|
) |
| 21 |
|
); |
| 22 |
|
|
| 23 |
|
if (module_exists('comment')) { |
| 24 |
|
$graphs['history']['graph_comments'] = array( |
| 25 |
|
'#title' => t('Number of Comments'), |
| 26 |
|
'#xlabel' => t('Date (MM/DD/YYYY)'), |
| 27 |
|
'#ylabel' => t('# Comments') |
| 28 |
|
); |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
return $graphs; |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
/** |
| 35 |
|
* Implementation of hook_graphstat_data(). |
| 36 |
|
*/ |
| 37 |
|
function graphstat_system_graphstat_data() { |
| 38 |
|
$data = array(); |
| 39 |
|
$data['history']['graph_nodes'] = graphstat_statistics_tablehistory(); |
| 40 |
|
$data['history']['graph_users'] = graphstat_statistics_tablehistory('users', 'uid'); |
| 41 |
|
|
| 42 |
|
if (module_exists('comment')) { |
| 43 |
|
$data['history']['graph_comments'] = graphstat_statistics_tablehistory('comments', 'cid'); |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
return $data; |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
/** |
| 50 |
|
* Function graphstat_statistics_tablehistory(). |
| 51 |
|
*/ |
| 52 |
|
function graphstat_statistics_tablehistory($table = 'node', $id = 'nid', $fragment = '', $points = 0, $timestamp = 0) { |
| 53 |
|
$data = array(); |
| 54 |
|
|
| 55 |
|
$key = in_array($table, array('node', 'users')) ? 'created' : 'timestamp'; |
| 56 |
|
$timestamp = $timestamp ? $timestamp : db_result(db_query('SELECT MIN(%s) FROM {%s} WHERE %s != 0', $key, $table, $id)); |
| 57 |
|
if ($timestamp) { |
| 58 |
|
// One point per week (at least 15 points) |
| 59 |
|
if (!$points) { |
| 60 |
|
$points = max((time() - $timestamp) / (60*60*24*7), 15); |
| 61 |
|
while ($points > 30) { |
| 62 |
|
$points /= 2; |
| 63 |
|
} |
| 64 |
|
} |
| 65 |
|
$interval = round((time() - $timestamp) / ($points - 1), 0); |
| 66 |
|
$time = $timestamp; |
| 67 |
|
for ($i = 0; $i < $points; $i++) { |
| 68 |
|
$data[format_date($time, 'custom', 'm/d/Y')] = db_result(db_query('SELECT COUNT(DISTINCT(%s)) FROM {%s} WHERE %s <= %d AND %s <> 0 %s', $id, $table, $key, $time, $id, $fragment)); |
| 69 |
|
$time += $interval; |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
return $data; |
| 74 |
|
} |