1 system.install system_requirements($phase)

Implements hook_requirements().

File

core/modules/system/system.install, line 10
Install, update and uninstall functions for the system module.

Code

function system_requirements($phase) {
  global $base_url;
  $requirements = array();
  // Ensure translations don't break during installation.
  $t = get_t();

  // Report Backdrop version
  if ($phase == 'runtime') {
    $requirements['backdrop'] = array(
      'title' => $t('Backdrop CMS'),
      'value' => BACKDROP_VERSION,
      'severity' => REQUIREMENT_INFO,
      'weight' => -10,
    );

    // Display the currently active installation profile, if the site
    // is not running the default installation profile.
    $profile = backdrop_get_profile();
    if ($profile != 'standard') {
      $info = system_get_info('module', $profile);
      $requirements['install_profile'] = array(
        'title' => $t('Install profile'),
        'value' => $t('%profile_name (%profile-%version)', array(
          '%profile_name' => $info['name'],
          '%profile' => $profile,
          '%version' => $info['version']
        )),
        'severity' => REQUIREMENT_INFO,
        'weight' => -9
      );
    }
  }

  // Web server information.
  $software = $_SERVER['SERVER_SOFTWARE'];
  $requirements['webserver'] = array(
    'title' => $t('Web server'),
    'value' => check_plain($software),
    'severity' => REQUIREMENT_INFO,
  );

  // Test PHP version and show link to phpinfo() if it's available
  $phpversion = phpversion();
  if (function_exists('phpinfo')) {
    if ($phase == 'runtime') {
      $php_value = $t('Version: !version (<a href="!infourl">PHP information</a>)', array('!version' => $phpversion, '!infourl' => url('admin/reports/status/php')));
    }
    else {
      $php_value = $t('Version: !version', array('!version' => $phpversion));
    }
    $requirements['php'] = array(
      'title' => $t('PHP'),
      'value' => $php_value,
      'severity' => REQUIREMENT_INFO,
    );
  }
  else {
    $requirements['php'] = array(
      'title' => $t('PHP'),
      'value' => $phpversion,
      'description' => $t('The phpinfo() function has been disabled for security reasons. To see your server\'s phpinfo() information, change your PHP settings or contact your server administrator. For more information, <a href="@phpinfo">Enabling and disabling phpinfo()</a> handbook page.', array('@phpinfo' => 'http://drupal.org/node/243993')),
      'severity' => REQUIREMENT_INFO,
    );
  }

  if (version_compare($phpversion, BACKDROP_MINIMUM_PHP) < 0) {
    $requirements['php']['description'] = $t('Your PHP installation is too old. Backdrop requires at least PHP %version.', array('%version' => BACKDROP_MINIMUM_PHP));
    $requirements['php']['severity'] = REQUIREMENT_ERROR;
    // If PHP is old, it's not safe to continue with the requirements check.
    return $requirements;
  }

  // Test PHP register_globals setting.
  $requirements['php_register_globals'] = array(
    'title' => $t('PHP register globals'),
  );
  $register_globals = trim(ini_get('register_globals'));
  // Unfortunately, ini_get() may return many different values, and we can't
  // be certain which values mean 'on', so we instead check for 'not off'
  // since we never want to tell the user that their site is secure
  // (register_globals off), when it is in fact on. We can only guarantee
  // register_globals is off if the value returned is 'off', '', or 0.
  if (!empty($register_globals) && strtolower($register_globals) != 'off') {
    $requirements['php_register_globals']['description'] = $t('<em>register_globals</em> is enabled. Backdrop requires this configuration directive to be disabled. Your site may not be secure when <em>register_globals</em> is enabled. The PHP manual has instructions for <a href="http://php.net/configuration.changes">how to change configuration settings</a>.');
    $requirements['php_register_globals']['severity'] = REQUIREMENT_ERROR;
    $requirements['php_register_globals']['value'] = $t("Enabled ('@value')", array('@value' => $register_globals));
  }
  else {
    $requirements['php_register_globals']['value'] = $t('Disabled');
  }

  // Test for PHP extensions.
  $requirements['php_extensions'] = array(
    'title' => $t('PHP extensions'),
  );

  $missing_extensions = array();
  $required_extensions = array(
    'date',
    'dom',
    'filter',
    'gd',
    'hash',
    'json',
    'pcre',
    'pdo',
    'session',
    'SimpleXML',
    'SPL',
    'xml',
  );
  foreach ($required_extensions as $extension) {
    if (!extension_loaded($extension)) {
      $missing_extensions[] = $extension;
    }
  }

  if (!empty($missing_extensions)) {
    $description = $t('Backdrop requires you to enable the PHP extensions in the following list (see the <a href="@system_requirements" target="_blank">system requirements page</a> for more information):', array(
      '@system_requirements' => 'https://backdropcms.org/requirements',
    ));

    $description .= theme('item_list', array('items' => $missing_extensions));

    $requirements['php_extensions']['value'] = $t('Disabled');
    $requirements['php_extensions']['severity'] = REQUIREMENT_ERROR;
    $requirements['php_extensions']['description'] = $description;
  }
  else {
    $description = $t('Enabled: !extensions', array('!extensions' => implode(', ', $required_extensions)));
    $requirements['php_extensions']['value'] = $description;
  }

  if ($phase == 'install' || $phase == 'update') {
    // Test for PDO (database).
    $requirements['database_extensions'] = array(
      'title' => $t('Database support'),
    );

    // Make sure PDO is available.
    if (!extension_loaded('pdo')) {
      $pdo_message = $t('Your web server does not appear to support PDO (PHP Data Objects). Ask your hosting provider if they support the native PDO extension.');
    }
    else {
      // Make sure the native PDO extension is available, not the older PEAR
      // version. (See install_verify_pdo() for details.)
      if (!defined('PDO::ATTR_DEFAULT_FETCH_MODE')) {
        $pdo_message = $t('Your web server seems to have the wrong version of PDO installed. Backdrop CMS requires the PDO extension from PHP core. This system has the older PECL version. See the <a href="@link" target="_blank">System Requirements</a> page for more information.');
      }
    }

    if (isset($pdo_message)) {
      $pdo_more_info = $t('See the <a href="@link" target="_blank">System Requirements</a> page for more information.', array('@link' => 'https://backdropcms.org/requirements'));
      $requirements['database_extensions']['value'] = $t('Disabled');
      $requirements['database_extensions']['severity'] = REQUIREMENT_ERROR;
      $requirements['database_extensions']['description'] = $pdo_message . ' ' . $pdo_more_info;
    }
    else {
      $requirements['database_extensions']['value'] = $t('Enabled');
    }
  }
  else {
    // Database information.
    $class = 'DatabaseTasks_' . Database::getConnection()->driver();
    /* @var DatabaseTasks $tasks */
    $tasks = new $class();
    $dbinfo = $t('!system version !version', array('!system' => $tasks->name(), '!version' => Database::getConnection()->version()));
    $requirements['database_system'] = array(
      'title' => $t('MySQL Database'),
      'severity' => REQUIREMENT_INFO,
      'value' => $dbinfo,
    );
  }

  // Test database-specific multi-byte UTF-8 related requirements.
  $charset_requirements = _system_check_db_utf8mb4_requirements($phase);
  if (!empty($charset_requirements)) {
    $requirements['database_charset'] = $charset_requirements;
  }

  // Report jQuery and jQuery UI versions.
  if ($phase == 'runtime') {
    $jquery = backdrop_get_library('system', 'jquery');
    $jquery_ui = backdrop_get_library('system', 'ui');
    $requirements['jquery'] = array(
      'title' => $t('jQuery'),
      'severity' => REQUIREMENT_OK,
      'value' => $t('jQuery version !jqv / jQuery UI version !jquiv', array('!jqv' => $jquery['version'], '!jquiv' => $jquery_ui['version'])),
    );
  }

  // Test PHP memory_limit
  $memory_limit = ini_get('memory_limit');
  $requirements['php_memory_limit'] = array(
    'title' => $t('PHP memory limit'),
    'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
  );

  if (!backdrop_check_memory_limit(BACKDROP_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
    $description = '';
    if ($phase == 'install') {
      $description = $t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', array('%memory_minimum_limit' => BACKDROP_MINIMUM_PHP_MEMORY_LIMIT));
    }
    elseif ($phase == 'update') {
      $description = $t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', array('%memory_minimum_limit' => BACKDROP_MINIMUM_PHP_MEMORY_LIMIT));
    }
    elseif ($phase == 'runtime') {
      $description = $t('Depending on your configuration, Backdrop can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', array('%memory_limit' => $memory_limit, '%memory_minimum_limit' => BACKDROP_MINIMUM_PHP_MEMORY_LIMIT));
    }

    if (!empty($description)) {
      if ($php_ini_path = get_cfg_var('cfg_file_path')) {
        $description .= ' ' . $t('Increase the memory limit by editing the memory_limit parameter in the file %configuration-file and then restart your web server (or contact your system administrator or hosting provider for assistance).', array('%configuration-file' => $php_ini_path));
      }
      else {
        $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
      }

      $requirements['php_memory_limit']['description'] = $description . ' ' . $t('See the <a href="@url" target="_blank">Backdrop requirements</a> for more information.', array('@url' => 'https://backdropcms.org/requirements'));
      $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
    }
  }

  // Test the contents of the .htaccess files.
  if ($phase == 'runtime' && backdrop_is_apache()) {

    // Check/create .htaccess files for active and staging config directories.
    foreach (array('active', 'staging') as $type) {
      $config_directory = config_get_config_directory($type);
      file_save_htaccess($config_directory);

      $htaccess_files[$config_directory . '/.htaccess'] = array(
        'title' => $t('%type config directory', array('%type' => backdrop_ucfirst($type))),
        'directory' => $config_directory,
      );
    }

    // Try to write the .htaccess files first, to prevent false alarms in case
    // (for example) the /tmp directory was wiped.
    file_ensure_htaccess();

    $htaccess_files['public://.htaccess'] = array(
      'title' => $t('Public files directory'),
      'directory' => config_get('system.core', 'file_public_path'),
    );
    if ($private_files_directory = config_get('system.core', 'file_private_path')) {
      $htaccess_files['private://.htaccess'] = array(
        'title' => $t('Private files directory'),
        'directory' => $private_files_directory,
      );
    }
    $htaccess_files['temporary://.htaccess'] = array(
      'title' => $t('Temporary files directory'),
      'directory' => file_directory_temp(),
    );

    foreach ($htaccess_files as $htaccess_file => $info) {
      // Check for the string which was added to the recommended .htaccess file
      // in the latest security update.
      if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
        $requirements[$htaccess_file] = array(
          'title' => $info['title'],
          'value' => $t('Not fully protected'),
          'severity' => REQUIREMENT_ERROR,
          'description' => $t('See <a href="@url" target="_blank">@url</a> for information about the recommended <code>.htaccess</code> file which should be added to the <code>%directory</code> directory to help protect against arbitrary code execution.', array('@url' => 'http://drupal.org/SA-CORE-2013-003', '%directory' => $info['directory'])),
        );
      }
    }
  }

  // Report cron status.
  if ($phase == 'runtime') {
    $config = config('system.core');
    // Cron warning threshold defaults to two days.
    $threshold_warning = $config->get('cron_threshold_warning');
    // Cron error threshold defaults to two weeks.
    $threshold_error = $config->get('cron_threshold_error');
    // Cron configuration help text.
    $help = $t('For more information, see the online handbook entry for <a href="@cron-handbook" target="_blank">configuring cron jobs</a>.', array('@cron-handbook' => 'https://backdropcms.org/cron'));

    // Determine when cron last ran.
    $cron_last = state_get('cron_last');
    if (!is_numeric($cron_last)) {
      $cron_last = state_get('install_time', 0);
    }

    // Determine severity based on time since cron last ran.
    $severity = REQUIREMENT_OK;
    if (REQUEST_TIME - $cron_last > $threshold_error) {
      $severity = REQUIREMENT_ERROR;
    }
    elseif (REQUEST_TIME - $cron_last > $threshold_warning) {
      $severity = REQUIREMENT_WARNING;
    }

    // Set summary and description based on values determined above.
    $summary = $t('Last run !time ago (<a href="@url">Run cron manually</a>)', array(
      '!time' => format_interval(REQUEST_TIME - $cron_last),
      '@url' => url('admin/reports/status/run-cron')
    ));
    $description = '';
    if ($severity != REQUIREMENT_OK) {
      $description = $t('Cron has not run recently.') . ' ' . $help;
    }

    $description .= $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url($base_url . '/core/cron.php', array('external' => TRUE, 'query' => array('cron_key' => state_get('cron_key'))))));

    $requirements['cron'] = array(
      'title' => $t('Cron maintenance tasks'),
      'severity' => $severity,
      'value' => $summary,
      'description' => $description,
    );
  }

  // Test files directories.
  $directories = array();
  if ($phase == 'runtime') {
    $directories[] = config_get('system.core', 'file_public_path');
    $directories[] = config_get('system.core', 'file_private_path');
    $directories[] = file_directory_temp();
  }
  else {
    $directories[] = conf_path() . '/files';
  }

  $requirements['file system'] = array(
    'title' => $t('File system'),
  );

  $error = '';
  // For installer, create the directories if possible.
  foreach ($directories as $directory) {
    if (!$directory) {
      continue;
    }
    $prepared = file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
    $is_writable = is_writable($directory);
    $is_directory = is_dir($directory);
    if (!$prepared || !$is_writable || !$is_directory) {
      $description = '';
      $requirements['file system']['value'] = $t('Not writable');
      if (!$is_directory) {
        $error .= $t('The directory %directory does not exist.', array('%directory' => $directory)) . ' ';
      }
      else {
        $error .= $t('The directory %directory is not writable.', array('%directory' => $directory)) . ' ';
      }
      // The files directory requirement check is done only during install and runtime.
      if ($phase == 'runtime') {
        $description = $error . $t('You may need to set the correct directory at the <a href="@admin-file-system">file system settings page</a> or change the current directory\'s permissions so that it is writable.', array('@admin-file-system' => url('admin/config/media/file-system')));
      }
      elseif ($phase == 'install') {
        // For the installer UI, we need different wording. 'value' will
        // be treated as version, so provide none there.
        if ($is_directory && !$is_writable) {
          $description = $error . ' ' . $t('To proceed with installation, you must modify the permissions of this directory to make it writable by the web server.');
        }
        else {
          $description = $error . ' ' . $t('An automated attempt to create this directory failed. To proceed with the installation, either create the directory and modify its permissions to make it writable or adjust the permissions on the parent directory to allow the installer to create it automatically.');
        }
        $description .= ' ' . $t('If you are unsure how to do this, see the <a href="@handbook_url" target="_blank">Installation Instructions</a> page.', array('@handbook_url' => 'https://backdropcms.org/installation'));
        $requirements['file system']['value'] = '';
      }
      if (!empty($description)) {
        $requirements['file system']['description'] = $description;
        $requirements['file system']['severity'] = REQUIREMENT_ERROR;
      }
    }
    else {
      if (file_default_scheme() == 'public') {
        $requirements['file system']['value'] = $t('Writable (<em>public</em> download method)');
      }
      else {
        $requirements['file system']['value'] = $t('Writable (<em>private</em> download method)');
      }
    }
  }

  // See if updates are available in update.php.
  if ($phase == 'runtime') {
    $requirements['update'] = array(
      'title' => $t('Database updates'),
      'severity' => REQUIREMENT_OK,
      'value' => $t('Up to date'),
    );

    // Check installed modules.
    foreach (module_list() as $module) {
      $updates = backdrop_get_schema_versions($module);
      if ($updates !== FALSE) {
        $current_schema = backdrop_get_installed_schema_version($module);
        $latest_schema = end($updates);
        if ($current_schema < $latest_schema) {
          $requirements['update']['severity'] = REQUIREMENT_ERROR;
          $requirements['update']['value'] = $t('Out of date') . ' (' . l(t('Run database updates'), 'core/update.php') . ')';
          $requirements['update']['description'] = $t('Some modules have database schema updates to install. You should run the <a href="@update">database update script</a> immediately.', array('@update' => base_path() . 'core/update.php'));
          break;
        }
      }
    }
  }

  // Verify the update.php access setting
  if ($phase == 'runtime') {
    if (!empty($GLOBALS['settings']['update_free_access'])) {
      $requirements['update access'] = array(
        'value' => $t('Not protected'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('The <code>update.php</code> script is accessible to everyone without authentication check, which is a security risk. You must change the <code>update_free_access</code> value in your <code>settings.php</code> back to <code>FALSE</code>.'),
      );
    }
    else {
      $requirements['update access'] = array(
        'value' => $t('Protected'),
      );
    }
    $requirements['update access']['title'] = $t('Access to update.php');
  }

  // Display an error if a newly introduced dependency in a module is not resolved.
  if ($phase == 'update') {
    $profile = backdrop_get_profile();
    $files = system_rebuild_module_data();
    foreach ($files as $module => $file) {
      // Ignore disabled modules and installation profiles.
      if (!$file->status || $module == $profile) {
        continue;
      }
      // Check the module's PHP version.
      $name = $file->info['name'];
      $php = $file->info['php'];
      if (version_compare($php, PHP_VERSION, '>')) {
        $requirements['php']['description'] .= $t('@name requires at least PHP @version.', array('@name' => $name, '@version' => $php));
        $requirements['php']['severity'] = REQUIREMENT_ERROR;
      }
      // Check the module's required modules.
      foreach ($file->requires as $requirement) {
        $required_module = $requirement['name'];
        // Check if the module exists.
        if (!isset($files[$required_module])) {
          $requirements["$module-$required_module"] = array(
            'title' => $t('Unresolved dependency'),
            'description' => $t('@name requires this module.', array('@name' => $name)),
            'value' => t('@required_name (Missing)', array('@required_name' => $required_module)),
            'severity' => REQUIREMENT_ERROR,
          );
          continue;
        }
        // Check for an incompatible version.
        $required_file = $files[$required_module];
        $required_name = $required_file->info['name'];
        $version = preg_replace('/^' . preg_quote(BACKDROP_CORE_COMPATIBILITY, '/') . '-/', '', $required_file->info['version']);
        $compatibility = backdrop_check_incompatibility($requirement, $version);
        if ($compatibility) {
          $compatibility = rtrim(substr($compatibility, 2), ')');
          $requirements["$module-$required_module"] = array(
            'title' => $t('Unresolved dependency'),
            'description' => $t('@name requires this module and version. Currently using @required_name version @version', array('@name' => $name, '@required_name' => $required_name, '@version' => $version)),
            'value' => t('@required_name (Version @compatibility required)', array('@required_name' => $required_name, '@compatibility' => $compatibility)),
            'severity' => REQUIREMENT_ERROR,
          );
          continue;
        }
      }
    }
  }

  // Test Unicode library
  include_once BACKDROP_ROOT . '/core/includes/unicode.inc';
  $requirements = array_merge($requirements, unicode_requirements());

  if ($phase == 'runtime') {
    // Check for update status module.
    if (!module_exists('update')) {
      $requirements['update status'] = array(
        'value' => $t('Not enabled'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('Update notifications are not enabled. It is <strong>highly recommended</strong> that you enable the Update Manager module from the <a href="@module">module administration page</a> in order to stay up-to-date on new releases. For more information, <a href="@update" target="_blank">Update status handbook page</a>.', array('@update' => 'http://drupal.org/handbook/modules/update', '@module' => url('admin/modules'))),
      );
    }
    else {
      $requirements['update status'] = array(
        'value' => $t('Enabled'),
      );
    }
    $requirements['update status']['title'] = $t('Backdrop CMS update notifications');
  }

  if ($phase == 'runtime') {
    // Check for various token definition problems.
    $token_problems = token_get_token_problems();
    // Format and display each token problem.
    foreach ($token_problems as $problem_key => $problem) {
      if (!empty($problem['problems'])) {
        $problems = array_unique($problem['problems']);
        $problems = array_map('check_plain', $problems);
        $token_problems[$problem_key] = $problem['label'] . theme('item_list', array('items' => $problems));
      }
      else {
        unset($token_problems[$problem_key]);
      }
    }
    if (!empty($token_problems)) {
      $requirements['token_problems'] = array(
        'title' => $t('Tokens'),
        'value' => $t('Problems detected'),
        'severity' => REQUIREMENT_WARNING,
        'description' => '<p>' . implode('</p><p>', $token_problems) . '</p>',
      );
    }
  }

  if ($phase == 'runtime') {
    // Check for a duplicate CKEditor project.
    $path = backdrop_get_path('module', 'ckeditor');
    if ($path && strpos($path, 'core/modules/ckeditor') === FALSE) {
      $requirements['ckeditor_replaced'] = array(
        'title' => $t('CKEditor'),
        'value' => $t('Duplicate module detected'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('Backdrop core now provides a bundled CKEditor module. A different copy of CKEditor module has been located at %path. To use the new CKEditor module, disable and then uninstall the current module, remove it from your installation, and then enable the new CKEditor module from the modules page. For more information see the <a href="https://api.backdropcms.org/node/42827" target="_blank">CKEditor change notice</a>.', array('%path' => BACKDROP_ROOT . '/' . $path)),
      );
    }

    // Check for a duplicate Email project.
    $path = backdrop_get_path('module', 'email');
    if ($path && strpos($path, 'core/modules/email') === FALSE) {
      $requirements['email_replaced'] = array(
        'title' => $t('Email'),
        'value' => $t('Duplicate module detected'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('Backdrop core now provides a bundled Email module. A different copy of Email module has been located at %path. Remove this module from your installation to use the core Email module. For more information see the <a href="https://api.backdropcms.org/node/42928" target="_blank">Email module change notice</a>.', array('%path' => BACKDROP_ROOT . '/' . $path)),
      );
    }

    // Check for a duplicate Link project.
    $path = backdrop_get_path('module', 'link');
    if ($path && strpos($path, 'core/modules/link') === FALSE) {
      $requirements['link_replaced'] = array(
        'title' => $t('Link'),
        'value' => $t('Duplicate module detected'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('Backdrop core now provides a bundled Link module. A different copy of Link module has been located at %path. Remove this module from your installation to use the new Link module. For more information see the <a href="https://api.backdropcms.org/node/42930" target="_blank">Link change notice</a>.', array('%path' => BACKDROP_ROOT . '/' . $path)),
      );
    }

    // Check for a duplicate Date project.
    $path = backdrop_get_path('module', 'date');
    if ($path && strpos($path, 'core/modules/date') === FALSE) {
      $requirements['date_replaced'] = array(
        'title' => $t('Date'),
        'value' => $t('Duplicate module detected'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('Backdrop core now provides a bundled Date module. A different copy of Date module has been located at %path. Remove this module from your installation to use new Date module. For more information see the <a href="https://api.backdropcms.org/node/43066" target="_blank">Date change notice</a>.', array('%path' => BACKDROP_ROOT . '/' . $path)),
      );
    }

    // Check for a duplicate redirect project.
    $path = backdrop_get_path('module', 'redirect');
    if ($path && strpos($path, 'core/modules/redirect') === FALSE) {
      $requirements['redirect_replaced'] = array(
        'title' => $t('Redirect'),
        'value' => $t('Duplicate module detected'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('Backdrop core now provides a bundled Redirect module. A different copy of Redirect module has been located at %path. Remove this module from your installation to use the new Redirect module. For more information see the <a href="https://api.backdropcms.org/node/43994" target="_blank">Redirect change notice</a>.', array('%path' => BACKDROP_ROOT . '/' . $path)),
      );
    }
  }

  if ($phase == 'runtime') {
    // Inform user about status of display error messages.
    $error_level = config_get('system.core', 'error_level');
    $description = $t('Backdrop CMS provides the ability to display error messages, which can be useful while a site is in development.');
    $logging_url = url('admin/config/development/logging');
    if ($error_level != ERROR_REPORTING_HIDE) {
      $value = $t('Enabled');
      $severity = REQUIREMENT_WARNING;
      $description .= ' ' . $t('Do not forget to <a href="@url">disable the display of errors</a> when you have finished testing and this site goes live.', array('@url' => $logging_url));
    }
    else {
      $value = $t('Disabled');
      $severity = REQUIREMENT_OK;
      $description .= ' ' . $t('If your site is in development, you might want to <a href="@url">enable the display of errors</a>.', array('@url' => $logging_url));
    }

    $requirements['error_level'] = array(
      'title' => $t('Display error messages'),
      'value' => $value,
      'severity' => $severity,
      'description' => $description,
    );
  }

  if ($phase == 'runtime') {
    // Inform the user if theme_debug is enabled.
    $theme_debug_enabled = config_get('system.core', 'theme_debug');
    if ($theme_debug_enabled) {
      $requirements['theme_debug'] = array(
        'title' => $t('Theme debug'),
        'value' => $t('Enabled'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('Theme debugging is currently enabled, and should be disabled on a live site. This setting can be changed using the <a href="!url">Devel module</a>.', array('!url' => module_exists('devel') ? url('admin/config/development/devel') : 'https://backdropcms.org/project/devel')),
      );
    }
  }

  // Warn the user if trusted hostnames have not been configured.
  if ($phase == 'runtime') {
    $trusted_host_patterns = settings_get('trusted_host_patterns', array());
    $more_info = $t('See <a href="@url" target="_blank">Protecting against HTTP HOST Header attacks</a> for more information.', array('@url' => 'https://api.backdropcms.org/documentation/trusted-host-settings'));
    // @todo: upgrade this to an error when we provide a way to configure
    // $trusted_host_patterns via the admin UI.
    if (empty($trusted_host_patterns)) {
      $requirements['trusted_host_patterns'] = array(
        'title' => $t('Trusted Host Setting'),
        'value' => $t('Not configured'),
        'description' => $t('The <code>trusted_host_patterns</code> setting is not configured in <code>settings.php</code>. It is highly recommended that you configure this to protect your site.') . ' ' . $more_info,
        'severity' => $trusted_host_patterns === FALSE ? REQUIREMENT_INFO : REQUIREMENT_WARNING,
      );
    }
    else {
      $description = format_plural(count($trusted_host_patterns), 'Configured to allow the following pattern:', 'Configured to allow the following patterns:');
      // Wrap each pattern in <code> tags for when they are rendered later.
      foreach ($trusted_host_patterns as $key => $trusted_host_pattern) {
        $trusted_host_patterns[$key] = '<code>' . $trusted_host_pattern . '</code>';
      }
      // If only one trusted host pattern, render as is...
      if (count($trusted_host_patterns) == 1) {
        $description .= ' ' . $trusted_host_patterns[0] . '<br>';
      }
      // ...otherwise, render the patterns as a list.
      else {
        $description .= theme('item_list', array('items' => $trusted_host_patterns));
      }
      $description .= $t('You can change this by editing the <code>trusted_host_patterns</code> setting in <code>settings.php</code>.') . ' ' . $more_info;
      $requirements['trusted_host_patterns'] = array(
        'title' => $t('Trusted Host Settings'),
        'value' => $t('Current hostname is trusted'),
        'description' => $description,
      );
    }
  }

  return $requirements;
}