You are here

function statistics_block in Drupal 4

Same name and namespace in other branches
  1. 5 modules/statistics/statistics.module \statistics_block()
  2. 6 modules/statistics/statistics.module \statistics_block()

Implementation of hook_block().

File

modules/statistics.module, line 416
Logs access statistics for your site.

Code

function statistics_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      if (variable_get('statistics_count_content_views', 0)) {
        $blocks[0]['info'] = t('Popular content');
      }
      return $blocks;
    case 'configure':

      // Popular content block settings
      $numbers = array(
        '0' => t('Disabled'),
      ) + drupal_map_assoc(array(
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        15,
        20,
        25,
        30,
        40,
      ));
      $form['statistics_block_top_day_num'] = array(
        '#type' => 'select',
        '#title' => t("Number of day's top views to display"),
        '#default_value' => variable_get('statistics_block_top_day_num', 0),
        '#options' => $numbers,
        '#description' => t('How many content items to display in "day" list.'),
      );
      $form['statistics_block_top_all_num'] = array(
        '#type' => 'select',
        '#title' => t('Number of all time views to display'),
        '#default_value' => variable_get('statistics_block_top_all_num', 0),
        '#options' => $numbers,
        '#description' => t('How many content items to display in "all time" list.'),
      );
      $form['statistics_block_top_last_num'] = array(
        '#type' => 'select',
        '#title' => t('Number of most recent views to display'),
        '#default_value' => variable_get('statistics_block_top_last_num', 0),
        '#options' => $numbers,
        '#description' => t('How many content items to display in "recently viewed" list.'),
      );
      return $form;
    case 'save':
      variable_set('statistics_block_top_day_num', $edit['statistics_block_top_day_num']);
      variable_set('statistics_block_top_all_num', $edit['statistics_block_top_all_num']);
      variable_set('statistics_block_top_last_num', $edit['statistics_block_top_last_num']);
      break;
    case 'view':
      if (user_access('access content')) {
        $content = array();
        $daytop = variable_get('statistics_block_top_day_num', 0);
        if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && db_num_rows($result)) {
          $content[] = node_title_list($result, t("Today's:"));
        }
        $alltimetop = variable_get('statistics_block_top_all_num', 0);
        if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && db_num_rows($result)) {
          $content[] = node_title_list($result, t('All time:'));
        }
        $lasttop = variable_get('statistics_block_top_last_num', 0);
        if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && db_num_rows($result)) {
          $content[] = node_title_list($result, t('Last viewed:'));
        }
        if (count($content)) {
          $block['content'] = implode('<br />', $content);
          $block['subject'] = t('Popular content');
          return $block;
        }
      }
  }
}