You are here

function apachesolr_stats_block in Apache Solr Statistics 6.3

Same name and namespace in other branches
  1. 6 apachesolr_stats.module \apachesolr_stats_block()

Implementation of hook_block().

File

./apachesolr_stats.module, line 923
Keeps and reports statistics about Apache Solr usage and performance.

Code

function apachesolr_stats_block($op = 'list', $delta = 0) {
  $search_pages = apachesolr_search_load_all_search_pages();
  $enabled_search_pages = variable_get('apachesolr_stats_enabled', array());
  $blocks = array();
  switch ($op) {
    case 'list':

      // Default block settings.
      foreach ($enabled_search_pages as $page_id) {
        if ($page_id) {
          $blocks[$page_id] = array(
            'info' => t('Apache Solr Statistics: popular searches for @page_id page', array(
              '@page_id' => $search_pages[$page_id]['label'],
            )),
            // Start out disabled
            'status' => 0,
            'region' => 'right',
            // Should be cached equally across paths and roles.
            'cache' => BLOCK_CACHE_GLOBAL,
          );
        }
      }
      return $blocks;
    case 'view':
      if (!$enabled_search_pages[$delta]) {
        return array(
          'subject' => '',
          'content' => '',
        );
      }
      $links = apachesolr_stats_block_frequent_keywords($delta);
      if ($links) {

        // Return a block array.
        $block = array(
          'subject' => t('Popular searches for @page_name', array(
            '@page_name' => $search_pages[$delta]['label'],
          )),
          'content' => theme('apachesolr_stats_block', $links),
        );
        return $block;
      }
  }
}