You are here

function l10n_update_requirements in Localization update 7.2

Same name and namespace in other branches
  1. 6 l10n_update.install \l10n_update_requirements()
  2. 7 l10n_update.install \l10n_update_requirements()

Implements hook_requirements().

File

./l10n_update.install, line 196
Install file for l10n remote updates.

Code

function l10n_update_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $available_updates = array();
    $untranslated = array();
    $languages = l10n_update_translatable_language_list();
    if ($languages) {

      // Determine the status of the translation updates per language.
      $status = l10n_update_get_status();
      if ($status) {
        foreach ($status as $project) {
          foreach ($project as $langcode => $project_info) {
            if (empty($project_info->type)) {
              $untranslated[$langcode] = $languages[$langcode];
            }
            elseif ($project_info->type == L10N_UPDATE_LOCAL || $project_info->type == L10N_UPDATE_REMOTE) {
              $available_updates[$langcode] = $languages[$langcode];
            }
          }
        }
        if ($available_updates || $untranslated) {
          if ($available_updates) {
            $requirements['l10n_update'] = array(
              'title' => 'Translation update status',
              'value' => l(t('Updates available'), 'admin/config/regional/translate/update'),
              'severity' => REQUIREMENT_WARNING,
              'description' => t('Updates available for: @languages. See the <a href="!updates">Translate interface update</a> page for more information.', array(
                '@languages' => implode(', ', $available_updates),
                '!updates' => url('admin/config/regional/translate/update'),
              )),
            );
          }
          else {
            $requirements['l10n_update'] = array(
              'title' => 'Translation update status',
              'value' => t('Missing translations'),
              'severity' => REQUIREMENT_INFO,
              'description' => t('Missing translations for: @languages. See the <a href="!updates">Translate interface update</a> page for more information.', array(
                '@languages' => implode(', ', $untranslated),
                '!updates' => url('admin/config/regional/translate/update'),
              )),
            );
          }
        }
        else {
          $requirements['l10n_update'] = array(
            'title' => 'Translation update status',
            'value' => t('Up to date'),
            'severity' => REQUIREMENT_OK,
          );
        }
      }
      else {
        $requirements['locale_translation'] = array(
          'title' => 'Translation update status',
          'value' => l(t('Can not determine status'), 'admin/config/regional/translate/update'),
          'severity' => REQUIREMENT_WARNING,
          'description' => t('No translation status is available. See the <a href="!updates">Translate interface update</a> page for more information.', array(
            '!updates' => url('admin/config/regional/translate/update'),
          )),
        );
      }
    }

    // Test the contents of the .htaccess file in the translations directory.
    l10n_update_ensure_htaccess();
    $htaccess_file = 'translations://.htaccess';
    $directory = variable_get('l10n_update_download_store', L10N_UPDATE_DEFAULT_TRANSLATION_PATH);

    // 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['l10n_update_htaccess'] = array(
        'title' => t('Translations directory'),
        'value' => t('Not fully protected'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('See <a href="@url">@url</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', array(
          '@url' => 'http://drupal.org/SA-CORE-2013-003',
          '%directory' => $directory,
        )),
      );
    }
  }
  if ($phase == 'update') {

    // Make sure the 'translations' stream wrapper class gets registered.
    // This is needed when upgrading to 7.x-2.x.
    if (!class_exists('TranslationsStreamWrapper')) {
      registry_rebuild();
    }
  }
  return $requirements;
}