statspro.module in Statistics Pro 6
Same filename and directory in other branches
Main module of Statistcs pro module
File
statspro.moduleView source
<?php
/**
* @file
* Main module of Statistcs pro module
*
*/
/**
* Implementation of hook_theme().
*/
function statspro_theme() {
return array(
'graphstat_filter_form' => array(
'arguments' => array(
'form' => NULL,
),
),
'graphstat_graph' => array(
'arguments' => array(
'url' => NULL,
'title' => '',
'description' => '',
'attributes' => array(),
),
),
'statspro_content' => array(
'arguments' => array(
'title',
'data',
),
),
'statspro_log' => array(
'arguments' => array(
'title',
'data',
),
),
);
}
/**
* Implementation of hook_views_api().
*/
function statspro_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'statspro') . '/views',
);
}
/**
* Implementation of hook_menu().
*
* @return array
*/
function statspro_menu() {
$items = array();
$items['admin/reports/statspro'] = array(
'title' => 'Statistics Pro',
'description' => 'Content statistics',
'page callback' => 'statspro_overview',
'access arguments' => array(
'access statistics',
),
'file' => 'statspro.reports.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/reports/statspro/common'] = array(
'title' => 'Common',
'access arguments' => array(
'access statistics',
),
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'statspro.reports.inc',
'weight' => -10,
);
$items['admin/reports/statspro/tools'] = array(
'title' => 'Tools',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'statspro_tools',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'statspro.tools.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
return $items;
}
/**
* Implementation of hook_menu().
*/
function statspro_cron() {
require_once drupal_get_path('module', 'statspro') . '/statspro.inc';
$statspro = new statspro();
$last_run = variable_get('statspro_last_run', 0);
// force rebuild
//$last_run = 0;
$days = $statspro
->get_days_data($last_run);
if (count($days) > 0) {
foreach ($days as $date => $values) {
$statspro
->store_day($date, $values);
}
watchdog('statspro', 'New statistics available');
}
$term_rebuild = variable_get('statspro_term_rebuild', FALSE);
if ($term_rebuild) {
db_query('TRUNCATE TABLE {statspro_term}');
$statspro
->generate_term_stats();
variable_set('statspro_term_rebuild', FALSE);
}
// we always store last run
variable_set('statspro_last_run', mktime());
}
/**
* Implementation of hook_nodeapi().
*/
function statspro_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$term_rebuild = variable_get('statspro_term_rebuild', FALSE);
if (!$term_rebuild) {
switch ($op) {
case 'insert':
variable_set('statspro_term_rebuild', TRUE);
break;
case 'update':
variable_set('statspro_term_rebuild', TRUE);
break;
case 'delete':
variable_set('statspro_term_rebuild', TRUE);
break;
}
}
}
/**
* Get items for period selection
*
* @return array
*/
function statspro_get_period_items() {
return array(
'today' => t('Today'),
'yesterday' => t('Yesterday'),
'week_current' => t('Week, current'),
'week_last' => t('Week, last'),
'week_last2' => t('Week, before last'),
'month_current' => t('Month, current'),
'month_last' => t('Month, last'),
'month_last3' => t('Month, last 3'),
'month_last6' => t('Month, last 6'),
'quarter_current' => t('Quarter, current'),
'quarter_last' => t('Quarter, last'),
'year_current' => t('Year, current'),
'year_last' => t('Year, last'),
);
}
/**
* Form generating function for search_engine_referers settings
*/
function statspro_settings_form() {
$form = array();
$form['statspro_period'] = array(
'#type' => 'select',
'#title' => t('Time period'),
'#default_value' => variable_get('statspro_period', 'today'),
'#options' => statspro_get_period_items(),
);
return system_settings_form($form);
}
/**
* Reset Statistics Pro.
*
*/
function statspro_reset_stats() {
variable_set('statspro_last_run', 0);
db_query('TRUNCATE TABLE {statspro}');
drupal_set_message(t('You have to run cron to recreate statistics. !url', array(
'!url' => l('You can run cron manually.', 'admin/reports/status/run-cron'),
)));
}
Functions
Name | Description |
---|---|
statspro_cron | Implementation of hook_menu(). |
statspro_get_period_items | Get items for period selection |
statspro_menu | Implementation of hook_menu(). |
statspro_nodeapi | Implementation of hook_nodeapi(). |
statspro_reset_stats | Reset Statistics Pro. |
statspro_settings_form | Form generating function for search_engine_referers settings |
statspro_theme | Implementation of hook_theme(). |
statspro_views_api | Implementation of hook_views_api(). |