You are here

function smart_ip_requirements in Smart IP 6

Same name and namespace in other branches
  1. 6.2 smart_ip.install \smart_ip_requirements()
  2. 7.2 smart_ip.install \smart_ip_requirements()
  3. 7 smart_ip.install \smart_ip_requirements()

Implements hook_requirements().

See also

smart_ip_admin_settings()

File

./smart_ip.install, line 8

Code

function smart_ip_requirements($phase = 'runtime') {
  $requirements = array();
  if ($phase == 'runtime') {
    $correct_key = variable_set('smart_ip_correct_ipinfodb_key', FALSE);
    if (!$correct_key) {
      $smart_ip_source = variable_get('smart_ip_source', 'ipinfodb_service');
      if ($smart_ip_source == 'ipinfodb_service') {

        // Generate an appropriate error message:
        // Missing API keys.
        $ipinfodb_key = variable_get('smart_ip_ipinfodb_key', '');
        if (empty($ipinfodb_key)) {
          $requirements['smart_ip'] = array(
            'title' => 'IPInfoDB API key',
            'severity' => REQUIREMENT_ERROR,
            'value' => t('Not configured'),
            'description' => t('The IPInfoDB API key is not configured yet. Visit Smart IP settings !page.', array(
              '!page' => l(t('page'), 'admin/settings/smart_ip'),
            )),
          );
        }
        else {
          $response = drupal_http_request(smart_ip_get_ipinfodb_url($ipinfodb_key, '127.0.0.1'));
          $stat = (array) json_decode($response->data);
          if ($stat['Status'] == 'MISSING API KEY' || $stat['Status'] == 'INVALID API KEY') {
            $requirements['smart_ip'] = array(
              'title' => 'IPInfoDB API key',
              'severity' => REQUIREMENT_ERROR,
              'value' => t('Invalid'),
              'description' => t('The IPInfoDB API key is invalid. Visit Smart IP settings !page.', array(
                '!page' => l(t('page'), 'admin/settings/smart_ip'),
              )),
            );
          }
          else {
            variable_set('smart_ip_correct_ipinfodb_key', TRUE);
          }
        }
      }
    }
  }
  return $requirements;
}