You are here

function search_log_block in Search Log 6

Implementation of hook_block().

1 string reference to 'search_log_block'
search_log.module in ./search_log.module
Replaces default report of top search phrases.

File

./search_log.module, line 211
Replaces default report of top search phrases.

Code

function search_log_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[SEARCH_LOG_BLOCK]['info'] = t('Top Searches');
      return $blocks;
    case 'view':
      switch ($delta) {
        case SEARCH_LOG_BLOCK:
          if ($items = _search_log_items()) {
            $block['subject'] = t("Top Searches");
            $block['content'] = theme('search_log_block', $items);
          }
          break;
      }
      return $block;
    case 'configure':
      $form['search_log_block_max'] = array(
        '#type' => 'textfield',
        '#title' => t('Maximum number of search terms'),
        '#size' => 4,
        '#default_value' => variable_get('search_log_block_max', 10),
      );
      $form['search_log_block_count'] = array(
        '#type' => 'radios',
        '#title' => t('Display search count for terms?'),
        '#options' => array(
          t('No'),
          t('Yes'),
        ),
        '#default_value' => variable_get('search_log_block_count', 0),
      );
      $form['search_log_block_days'] = array(
        '#type' => 'textfield',
        '#title' => t('Number of days for search terms'),
        '#description' => t('Enter number of days for terms in Top Searches block. Enter 0 for all days.'),
        '#size' => 4,
        '#default_value' => variable_get('search_log_block_days', 0),
      );
      foreach (module_list() as $name) {
        if (module_hook($name, 'search') && ($title = module_invoke($name, 'search', 'name'))) {
          $module_options[$name] = $name;
        }
      }
      $form['search_log_block_modules'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Modules'),
        '#description' => t('Select modules to include in Top Searches block. If no modules are checked, all modules will be included.'),
        '#options' => $module_options,
        '#default_value' => variable_get('search_log_block_modules', array()),
      );
      $form['search_log_block_manual'] = array(
        '#type' => 'textarea',
        '#title' => t('Manually included terms'),
        '#description' => t('Enter term|module|count to be included in Top Searches block. For example, apple ipod|node|100 would link to search/node/apple+ipod.'),
        '#rows' => 5,
        '#default_value' => variable_get('search_log_block_manual', NULL),
      );
      return $form;
    case 'save':
      variable_set('search_log_block_max', $edit['search_log_block_max']);
      variable_set('search_log_block_count', $edit['search_log_block_count']);
      variable_set('search_log_block_days', $edit['search_log_block_days']);
      variable_set('search_log_block_modules', $edit['search_log_block_modules']);
      variable_set('search_log_block_manual', $edit['search_log_block_manual']);
      cache_clear_all(SEARCH_LOG_BLOCK_CACHE, 'cache', TRUE);
      break;
  }
}