continent.inc in GeoIP API 7.2
File
plugins/access/continent.inc
View source
<?php
$plugin = array(
'title' => t('GeoIP: Continent'),
'description' => t('Control access by continent a IP belongs to.'),
'callback' => 'geoip_ctools_plugin_region_ctools_access_check',
'settings form' => 'geoip_ctools_plugin_region_ctools_access_settings',
'summary' => 'geoip_ctools_plugin_region_ctools_access_summary',
'default' => array(
'continents' => array(),
),
);
function geoip_ctools_plugin_region_ctools_access_settings($form, &$form_state, $conf) {
$conf += array(
'continents' => array(),
);
$form['settings']['continents'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('continent'),
'#default_value' => $conf['continents'],
'#options' => geoip_continents_list(),
'#description' => t('The ip has to belong to one of the selected continents.'),
);
return $form;
}
function geoip_ctools_plugin_region_ctools_access_check($conf, $contexts) {
$conf += array(
'continents' => array(),
);
return in_array(geoip_continent_code(), $conf['continents']);
}
function geoip_ctools_plugin_region_ctools_access_summary($conf, $context) {
$continents = geoip_continents_list();
$continents = array_intersect_key($continents, $conf['continents']);
return t('User IP belongs to continent: @continents', array(
'@continents' => implode(' ' . t('or') . ' ', $continents),
));
}