You are here

function timeago_requirements in Timeago 7.2

Same name and namespace in other branches
  1. 6.2 timeago.install \timeago_requirements()

Implements hook_requirements().

File

./timeago.install, line 20
(Un)installs the Timeago module.

Code

function timeago_requirements($phase) {

  // Path to library
  if (module_exists('libraries') && function_exists('libraries_load') && ($path = libraries_get_path('timeago'))) {
    $path .= '/' . TIMEAGO_LIBRARY_FILENAME;
  }
  else {
    $path = drupal_get_path('module', 'timeago') . '/' . TIMEAGO_LIBRARY_FILENAME;
  }
  $t = get_t();
  $requirements = array(
    'timeago' => array(
      'title' => $t('Timeago library'),
    ),
  );

  // If file exists...
  if (file_exists($path)) {

    // Get version information
    $version = timeago_get_version($path);
    $requirements['timeago']['value'] = $version;

    // Check for updates, cache remote library file...
    if ($cache = cache_get('timeago_update_version')) {
      $update_version = $cache->data;
    }
    else {
      $update_version = timeago_get_version(TIMEAGO_LIBRARY_DOWNLOAD_URL);
      cache_set('timeago_update_version', $update_version, 'cache', REQUEST_TIME + 60 * 60 * 24 * 7);
    }

    // No update info
    if (!$update_version) {
      $requirements['timeago']['description'] = $t('The Timeago library exists but update information could not be found. If desired, you can manually check <a href="@library_download_url">@library_download_url</a> for a newer version of the library.', array(
        '@library_download_url' => TIMEAGO_LIBRARY_DOWNLOAD_URL,
      ));
      $requirements['timeago']['severity'] = REQUIREMENT_WARNING;
    }
    elseif (version_compare($version, $update_version, '<')) {
      $requirements['timeago']['description'] = $t('The Timeago library is installed, but a newer version is available. You may wish to download the latest version from <a href="@library_download_url">@library_download_url</a> and overwrite the current version located at %path.', array(
        '@library_download_url' => TIMEAGO_LIBRARY_DOWNLOAD_URL,
        '%path' => $path,
      ));
      $requirements['timeago']['severity'] = REQUIREMENT_WARNING;
    }
    else {
      $requirements['timeago']['description'] = $t('The Timeago library exists and is up to date.');
      $requirements['timeago']['severity'] = REQUIREMENT_OK;
    }
  }
  else {
    if (module_exists('libraries')) {

      // If libraries module exists, but timeago library is not yet installed, recommend default libraries directory for installation
      $path = 'sites/all/libraries/timeago/' . TIMEAGO_LIBRARY_FILENAME;
    }
    $requirements['timeago']['value'] = NULL;
    $requirements['timeago']['description'] = $t('The Timeago library is not installed. Please <a href="@library_download_url">download the library</a> and put it at %path.', array(
      '@library_download_url' => TIMEAGO_LIBRARY_DOWNLOAD_URL,
      '%path' => $path,
    ));
    $requirements['timeago']['severity'] = $phase == 'runtime' ? REQUIREMENT_ERROR : REQUIREMENT_WARNING;
  }
  return $requirements;
}