You are here

function ip_geoloc_requirements in IP Geolocation Views & Maps 7

Implements hook_requirements().

$phase typically is one of 'install', 'runtime', 'update'.

File

./ip_geoloc.install, line 24
Install and uninstall hooks for IP Geolocation Views & Maps.

Code

function ip_geoloc_requirements($phase) {
  $requirements = array();

  // Avoid 'undefined function: ip_geoloc_get_css_library_path' during 'install'
  // and some warnings not relevant while executing an 'update'.
  if ($phase != 'runtime') {
    return $requirements;
  }
  $t = get_t();
  $geolocation_methods = array();
  if (variable_get('ip_geoloc_google_to_reverse_geocode', FALSE)) {
    $geolocation_methods[] = $t('Google Maps reverse-geocode');
  }
  if (variable_get('ip_geoloc_smart_ip_as_backup', FALSE)) {
    if (module_exists('smart_ip')) {
      $geolocation_methods[] = 'Smart IP';
    }
    else {
      $requirements['ip_geoloc_lbs']['severity'] = REQUIREMENT_WARNING;
      $requirements['ip_geoloc_lbs']['description'] = $t('Smart IP is configured as a backup in case the Google Maps reverse-geocode fails. However the Smart IP module is not enabled.');
    }
  }
  elseif (module_exists('geoip')) {
    $geolocation_methods[] = 'GeoIP API';
  }
  $geolocation_methods = array_merge($geolocation_methods, module_implements('get_ip_geolocation_alter'));
  $requirements['ip_geoloc_lbs']['title'] = $t('IP Geolocation Views & Maps,<br/>data collection methods employed');
  $requirements['ip_geoloc_lbs']['value'] = implode(', ', $geolocation_methods);
  if (empty($geolocation_methods)) {
    $note = $t('You currently have no data collection methods enabled. Therefore no new address information can be added to the IP geolocation database.');
    if (empty($requirements['ip_geoloc']['description'])) {
      $requirements['ip_geoloc_lbs']['severity'] = REQUIREMENT_OK;
      $requirements['ip_geoloc_lbs']['description'] = $note;
    }
    else {
      $requirements['ip_geoloc_lbs']['description'] .= ' ' . $note;
    }
  }
  $library = drupal_get_library('leaflet_markercluster', 'leaflet_markercluster');
  if (isset($library['js'][0]['data'])) {
    $requirements['ip_geoloc_markercluster']['title'] = t('IP Geolocation Views & Maps; Leaflet MarkerCluster library');
    if (strpos($library['js'][0]['data'], IP_GEOLOC_LEAFLET_MARKERCLUSTER_REGIONBOUND_JS)) {
      $requirements['ip_geoloc_markercluster']['value'] = t('Installed with RegionBound extension');
      $requirements['ip_geoloc_markercluster']['severity'] = REQUIREMENT_OK;
    }
    else {
      $requirements['ip_geoloc_markercluster']['value'] = t('Using basic version');
      $requirements['ip_geoloc_markercluster']['severity'] = REQUIREMENT_INFO;
      $requirements['ip_geoloc_markercluster']['description'] = t('Leaflet MarkerCluster installed without region-aware extension. You are not making the most of your clustering. We suggest you obtain the <a href="http://regionbound.com">RegionBound</a> marker cluster .js file and drop it in %directory for superior clustering.', array(
        '%directory' => leaflet_markercluster_get_library_path(),
      ));
    }
  }
  $requirements['ip_geoloc_font_libs']['title'] = $t('IP Geolocation Views & Maps,<br/>font icon libraries');
  $requirements['ip_geoloc_font_libs']['severity'] = REQUIREMENT_OK;
  $requirements['ip_geoloc_font_libs']['description'] = $t('When using Leaflet you may superimpose font icons on your markers. <a target="fsymbols" href="!url_fsymbols">fsymbols</a> do not require any files to be downloaded. Other font icons like those from <a target="fontello" href="!url_fontello">Fontello</a> do. See the <a target="readme" href="!url_readme">README</a> for more details on font icon repositories.', array(
    '!url_fsymbols' => url('http://text-symbols.com'),
    '!url_fontello' => url('http://fontello.com'),
    '!url_readme' => url(drupal_get_path('module', 'ip_geoloc') . '/README.txt'),
  ));
  $requirements['ip_geoloc_font_libs']['value'] = '';
  $num_font_libs = 0;
  foreach (ip_geoloc_get_font_icon_libs() as $i => $css_file) {
    $css_file = trim($css_file);
    if (!empty($css_file)) {
      if (file_exists($css_file)) {
        $msg = $t('Font icon library #@i found at %css_file', array(
          '@i' => $i,
          '%css_file' => $css_file,
        ));
        $num_font_libs++;
      }
      else {
        $msg = $t('File %file was entered on the <a target="config" href="!url_config">configuration page</a> but not found.', array(
          '%file' => $css_file,
          '!url_config' => url('admin/config/system/ip_geoloc'),
        ));
        $requirements['ip_geoloc_font_libs']['severity'] = REQUIREMENT_WARNING;
      }
      $requirements['ip_geoloc_font_libs']['value'] .= $msg . '<br/>';
    }
  }
  if ($num_font_libs == 0) {
    $requirements['ip_geoloc_font_libs']['value'] .= $t('No font icon libraries found. However you can still copy and paste font icons from <a target="fsybmols" href="!url_fsymbols">fsymbols</a>.', array(
      '!url_fsymbols' => url('http://text-symbols.com'),
    ));
  }
  switch (variable_get('ip_geoloc_auth_method', 0)) {
    case 1:
      $key_provided = variable_get('ip_geoloc_apikey', FALSE);
      break;
    case 2:
      $key_provided = variable_get('ip_geoloc_client_id', FALSE);
      break;
    default:
  }
  if (empty($key_provided)) {
    $requirements['ip_geoloc_map'] = array(
      'title' => 'IP Geolocation Views & Maps',
      'severity' => REQUIREMENT_WARNING,
      'value' => t('No Google Maps API Key or Client ID. Keyless access to Google Maps is no longer supported and may impact rendering of maps. Obtain and enter an API Key or Client ID <a href="!url">here</a>.', array(
        '!url' => url('admin/config/system/ip_geoloc'),
      )),
    );
  }
  return $requirements;
}