function smart_ip_requirements in Smart IP 7
Same name and namespace in other branches
- 6.2 smart_ip.install \smart_ip_requirements()
- 6 smart_ip.install \smart_ip_requirements()
- 7.2 smart_ip.install \smart_ip_requirements()
Implements hook_requirements().
See also
File
- ./
smart_ip.install, line 13 - Installation callback for Smart IP.
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/config/people/smart_ip'),
)),
);
}
else {
$response = drupal_http_request(smart_ip_get_ipinfodb_url($ipinfodb_key, '127.0.0.1'));
if (isset($response->data)) {
$stat = drupal_json_decode($response->data);
if (isset($stat['Status']) && ($stat['Status'] == 'MISSING API KEY' || $stat['Status'] == 'INVALID API KEY') || isset($stat['statusCode']) && $stat['statusCode'] == 'ERROR') {
$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/config/people/smart_ip'),
)),
);
}
else {
variable_set('smart_ip_correct_ipinfodb_key', TRUE);
}
}
}
}
}
}
return $requirements;
}