'admin/logs/monitor',
'title' => t('stats monitor'),
'description' => t('Monitor important stats of your site'),
'callback' => 'monitor_dashboard',
'access' => user_access('access monitor'),
'type' => MENU_NORMAL_ITEM);
return $items;
}
/**
* Veiw the dashboard.
*/
function monitor_dashboard() {
drupal_set_title('Stats Monitor');
return(monitor_search_terms().
'
'.
monitor_page_most_viewed().
'
'.
monitor_page_most_commented());
}
function monitor_search_terms() {
$sql = 'SELECT message, link, COUNT(message) AS count FROM {watchdog} WHERE type = '.
"'search'".' AND uid = 0 GROUP BY message ORDER BY count DESC LIMIT 10';
$result = db_query($sql);
$rows = array();
$header = array(t('Search Term'), t('Link'), t('Count'));
while ($s = db_fetch_object($result)) {
preg_match('!(.*?)!', $s->message, $matches);
$rows[] = array($matches[1], $s->link, $s->count);
}
if ($rows)
$output .= theme_table($header, $rows, array('width' => '100%'), t('Most Searched Terms by Anonymous Users'));
$rows = array();
$sql = 'SELECT message, link, COUNT(message) AS count FROM {watchdog} WHERE type = '.
"'search'".' AND uid != 0 GROUP BY message ORDER BY count DESC LIMIT 10';
$result = db_query($sql);
while ($s = db_fetch_object($result)) {
preg_match('!(.*?)!', $s->message, $matches);
$rows[] = array($matches[1], $s->link, $s->count);
}
if ($rows)
$output .= theme_table($header, $rows, array('width' => '100%'), t('Most Searched Terms by Authenticated Users'));
return $output;
}
function monitor_page_most_viewed() {
$sql = 'SELECT title, path, COUNT(path) AS count FROM {accesslog} WHERE path != '.
"'node'".' GROUP BY path ORDER BY count DESC LIMIT 10';
$result = db_query($sql);
$rows = array();
$header = array(t('Page Title'), t('Path'), t('Views Count'));
while ($s = db_fetch_object($result)) {
$rows[] = array($s->title, $s->path, $s->count);
}
if ($rows)
$output .= theme_table($header, $rows, array('width' => '100%'), t('Most Viewed Pages'));
return $output;
}
function monitor_page_most_commented() {
$sql = 'SELECT n.nid, n.title, COUNT(c.subject) AS count from {comments} c'.
' INNER JOIN {node} n ON n.nid = c.nid GROUP BY nid ORDER BY count LIMIT 10';
$result = db_query($sql);
$rows = array();
$header = array(t('Page Title'), t('Path'), t('Comments Count'));
while ($s = db_fetch_object($result)) {
$rows[] = array($s->title, 'node/'.$s->nid, $s->count);
}
if ($rows)
$output .= theme_table($header, $rows, array('width' => '100%'), t('Most Commented Pages'));
return $output;
}