boost.admin.modules.inc 3.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
<?php

/**
 * @file
 * Displays compatible modules for boost, descriptions of functionality and
 * links if not installed.
 */

/**
 * Returns a table listing of the status of recommended modules.
 */
function boost_compatible_output() {
  $modules_enabled = array();
  $modules_disabled = array();

  // Query from the database in case modules are already installed but not enabled
  $result = db_query("SELECT name, status FROM {system} WHERE type = 'module' ORDER BY weight ASC, name ASC");
  foreach ($result as $record) {
    if ($record->status == 1) {
      $modules_enabled[] = $record->name;
    }
    else {
      $modules_disabled[] = $record->name;
    }
  }

  // list of compatible modules
  $recommended = array(
    'boost_crawler' => array(
      'title' => 'Boost Crawler',
      'link' => 'http://drupal.org/project/boost' ,
32
      'description' => t('Minimal crawler - expires and regenerates pages only when content is edited and on next cron run. If this module is disabled, the content will be regenerated by the next visitor (who may have a slow page load). Only recommended for sites with low traffic, since the page cache will probably have been regenerated by the time the crawler accesses it. This is a Boost sub-module.'),
33 34 35 36
    ),
    'fast_404' => array(
      'title' => 'Fast 404',
      'link' => 'http://drupal.org/project/fast_404' ,
37
      'description' => t('Produces a faster "page not found" (404) page, reducing server load. Boost does not cache 404 pages since it would increase the size of the cache for pages which should not be accessed anyway. However, the default 404 mechanism of Drupal can be expensive in terms of performance. If you have a large amount of 404, consider adding a redirection for them in your .htaccess file.'),
38 39 40 41
    ),
    'globalredirect' => array(
      'title' => 'Global Redirect',
      'link' => 'http://drupal.org/project/globalredirect',
42
      'description' => t('Redirects pages to their canonical URL. Avoids caching two pages for the same content.'),
43 44 45 46
    ),
    'httprl' => array(
      'title' => 'HTTP Parallel Request & Threading Library',
      'link' =>  'http://drupal.org/project/httprl',
47
      'description' => t('Required by Boost crawler, performs HTTP requests to regenerate expired pages.'),
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    ),
    'expire' => array(
      'title' => 'Cache Expiration',
      'link' => 'http://drupal.org/project/expire',
      'description' => t('Expire specific pages of the cache immediately when content is added or modified. Also required by the Boost crawler, to crawl expired content after expiration.'),
    ),
  );

  ksort($recommended);

  // uses array_intersect as array_intersect_key only came in PHP > 5.1
  $installed = array_intersect($modules_enabled, array_keys($recommended));
  $disabled = array_intersect($modules_disabled, array_keys($recommended));
  $not_installed = array_diff( array_diff( array_keys($recommended), $installed), $disabled );

  // prepare the table
64
  $header = array(t('Module'), t('Status'), t('Description'));
65 66 67 68

  $rows = array();

  foreach ($recommended as $module => $data) {
69
    $status = in_array($module, $not_installed) ? t('Not Installed') : (in_array($module, $disabled) ? t('Disabled') : t('Enabled'));
70
    $trclass = in_array($module, $not_installed) ? 'info' : (in_array($module, $disabled) ? 'warning' : 'ok' ) ;
71
    $module_link = l($data['title'], $data['link']);
72 73 74

    $rows[] = array(
      'data' => array(
75
        $module_link,
76
        $status,
77
        $data['description'],
78 79 80 81 82 83
      ),
      'class' => array($trclass),
      'no_striping' => TRUE,
    );
  }

84 85 86
  $output = '<p class="boost-listmodules-intro">' . t("The following modules can be useful for most common use cases. For more information, please read and contribute to the <a href='!url'>Boost handbook</a>.", array('!url' => 'http://drupal.org/node/1434362')) . '</p>';

  $output .= theme('table', array('attributes' => array('class' => array('system-status-report')), 'header' => $header, 'rows' => $rows));
87 88 89 90 91 92 93 94

  return array(
   'my_page' => array(
      '#markup' => $output,
    ),
  );
}