<?php

/**
 * @file
 * Handles Advanced Aggregation installation and upgrade tasks.
 */

/**
 * Implements hook_requirements().
 */
function advagg_css_cdn_requirements($phase) {
  $requirements = array();
  // Ensure translations don't break at install time.
  $t = get_t();

  // If not at runtime, return here.
  if ($phase !== 'runtime') {
    return $requirements;
  }

  if (module_exists('jquery_update')) {
    $jquery_cdn = variable_get('jquery_update_jquery_cdn', 'none');
    if ($jquery_cdn === 'none') {
      $jquery_description = $t('The jquery update module has support for CDNs. Go to the <a href="@settings">jquery update settings page</a> and select a CDN instead of using this module.', array(
        '@settings' => url('admin/config/development/jquery_update', array(
          'fragment' => 'edit-jquery-update-jquery-cdn',
        )),
      ));
    }
    else {
      $jquery_description = $t('The jquery update module is already configured to use the external CDN "@cdn".', array('@cdn' => $jquery_cdn));
    }

    $requirements['advagg_css_cdn_jquery_update'] = array(
      'title' => $t('Adv CSS CDN - jquery update'),
      'severity' => REQUIREMENT_WARNING,
      'value' => $t('Duplicate Functionality: Use jquery update instead of the advagg_css_cdn sub module.'),
      'description' => $jquery_description . ' ' . $t('You should go to the <a href="@modules">modules page</a> and disable the "AdvAgg CDN CSS" module.', array(
        '@modules' => url('admin/modules', array(
          'fragment' => 'edit-modules-advanced-cssjs-aggregation',
        )),
      )),
    );
  }

  if (empty($requirements)) {
    $requirements['advagg_css_cdn'] = array(
      'title' => $t('Adv CSS CDN'),
      'severity' => REQUIREMENT_OK,
      'value' => $t('OK'),
      'description' => $t('jQuery UI CSS should be coming from a CDN.'),
    );
  }

  return $requirements;
}
