You are here

statspro.module in Statistics Pro 6.2

Same filename and directory in other branches
  1. 6 statspro.module

Main module of Statistcs pro module

File

statspro.module
View 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',
      ),
    ),
    'statspro_path_aggregator_list_form' => array(
      'arguments' => array(
        'form' => NULL,
      ),
    ),
  );
}

/**
 * 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 pro reports',
    ),
    'file' => 'statspro_overview.inc',
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/reports/statspro/overview'] = array(
    'title' => 'Overview',
    'access arguments' => array(
      'access statistics pro reports',
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'file' => 'statspro_overview.inc',
    'weight' => -10,
  );
  $items['admin/reports/statspro/comment'] = array(
    'title' => 'Comments',
    'page callback' => 'statspro_comment',
    'access arguments' => array(
      'access statistics pro reports',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'statspro_comment.inc',
  );
  $items['admin/reports/statspro/log'] = array(
    'title' => 'Logs',
    'page callback' => 'statspro_log',
    'access arguments' => array(
      'access statistics pro reports',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'statspro_log.inc',
  );
  $items['admin/reports/statspro/node'] = array(
    'title' => 'Nodes',
    'page callback' => 'statspro_node',
    'access arguments' => array(
      'access statistics pro reports',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'statspro_node.inc',
  );
  $items['admin/reports/statspro/pi'] = array(
    'title' => 'PIs',
    'page callback' => 'statspro_pi',
    'access arguments' => array(
      'access statistics pro reports',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'statspro_pi.inc',
  );
  $items['admin/reports/statspro/user'] = array(
    'title' => 'Users',
    'page callback' => 'statspro_user',
    'access arguments' => array(
      'access statistics pro reports',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'statspro_user.inc',
  );
  $items['admin/reports/statspro/path_aggregated'] = array(
    'title' => 'Path aggregated',
    'description' => 'Statistics report with path aggregated access data.',
    'page callback' => 'statspro_path_aggregated',
    'file' => 'statspro_path_aggregated.inc',
    'access arguments' => array(
      'access statistics pro reports',
    ),
    'type' => MENU_LOCAL_TASK,
  );
  $items['admin/settings/statspro'] = array(
    'title' => 'Statistics Pro',
    'description' => 'Statistics Pro settings.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'statspro_main_admin_settings_form',
    ),
    'access arguments' => array(
      'administer statistics pro settings',
    ),
    'file' => 'statspro_admin_settings.inc',
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/settings/statspro/main'] = array(
    'title' => 'Main',
    'description' => 'Define the default period for the reports.',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['admin/settings/statspro/tools'] = array(
    'title' => 'Tools',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'statspro_tools',
    ),
    'access arguments' => array(
      'administer statistics pro settings',
    ),
    'file' => 'statspro_tools.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => -5,
  );
  $items['admin/settings/statspro/path_aggregator/list'] = array(
    'title' => 'Path aggregators list',
    'description' => 'List of all path aggregators.',
    'page callback' => 'statspro_path_aggregator_list',
    'access arguments' => array(
      'administer statistics pro settings',
    ),
    'file' => 'statspro_path_aggregated.inc',
    'type' => MENU_LOCAL_TASK,
  );
  $items['admin/settings/statspro/path_aggregator/add'] = array(
    'title' => 'Add path aggregator',
    'description' => 'Add new path aggregator.',
    'page callback' => 'statspro_path_aggregator_add',
    'access arguments' => array(
      'administer statistics pro settings',
    ),
    'file' => 'statspro_path_aggregated.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 10,
  );
  $items['admin/settings/statspro/path_aggregator/edit'] = array(
    'title' => 'Edit path aggregator',
    'description' => 'Edit existing path aggregator.',
    'page callback' => 'statspro_path_aggregator_edit',
    'page arguments' => array(
      5,
    ),
    'access arguments' => array(
      'administer statistics pro settings',
    ),
    'file' => 'statspro_path_aggregated.inc',
    'type' => MENU_CALLBACK,
  );
  $items['admin/settings/statspro/path_aggregator/delete'] = array(
    'title' => 'Delete path aggregator',
    'description' => 'Delete existing path aggregator.',
    'page callback' => 'statspro_path_aggregator_delete',
    'page arguments' => array(
      5,
    ),
    'access arguments' => array(
      'administer statistics pro settings',
    ),
    'file' => 'statspro_path_aggregated.inc',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implementation of hook_perm().
 */
function statspro_perm() {
  $permissions = array(
    'access statistics pro reports',
    'administer statistics pro settings',
  );
  return $permissions;
}

/**
 * Implementation of hook_cron().
 */
function statspro_cron() {
  require_once drupal_get_path('module', 'statspro') . '/statspro.inc';
  $statspro = new StatsPro();
  $last_run = variable_get('statspro_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_help().
 */
function statspro_help($path, $arg) {
  switch ($path) {
    case 'admin/help#statspro':
      return '<p>' . t('The Statistics Pro module produces several new site statistic reports.') . '</p>';
      break;
  }
}

/**
 * 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'),
    'custom_days' => t('Custom number of days'),
  );
}

/**
 * Reset Statistics Pro statistics.
 *
 */
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

Namesort descending Description
statspro_cron Implementation of hook_cron().
statspro_get_period_items Get items for period selection.
statspro_help Implementation of hook_help().
statspro_menu Implementation of hook_menu().
statspro_nodeapi Implementation of hook_nodeapi().
statspro_perm Implementation of hook_perm().
statspro_reset_stats Reset Statistics Pro statistics.
statspro_theme Implementation of hook_theme().
statspro_views_api Implementation of hook_views_api().