You are here

function location_geocoding_options_form in Location 5

Same name and namespace in other branches
  1. 5.3 location.admin.inc \location_geocoding_options_form()
  2. 6.3 location.admin.inc \location_geocoding_options_form()
  3. 7.5 location.admin.inc \location_geocoding_options_form()
  4. 7.3 location.admin.inc \location_geocoding_options_form()
  5. 7.4 location.admin.inc \location_geocoding_options_form()
2 string references to 'location_geocoding_options_form'
location_form_alter in ./location.module
location_geocoding_options_page in ./location.module

File

./location.module, line 388

Code

function location_geocoding_options_form() {
  $form = array();
  $form['countries'] = array();

  // First, we build two arrays to help us figure out on the fly whether a specific country is covered by a multi-country geocoder,
  // and what the details of the multi-country geocoder are
  // (1) Get list of geocoders
  $general_geocoders_list = location_get_general_geocoder_list();

  // (2) get data about each geocoder and the list of coutnries covered by each geocoder
  $general_geocoders_data = array();
  $general_geocoders_countries = array();
  foreach ($general_geocoders_list as $geocoder_name) {
    include_once LOCATION_PATH . '/geocoding/' . $geocoder_name . '.inc';
    $info_function = $geocoder_name . '_geocode_info';
    if (function_exists($info_function)) {
      $general_geocoders_data[$geocoder_name] = $info_function();
    }
    $countries_function = $geocoder_name . '_geocode_country_list';
    if (function_exists($countries_function)) {
      $general_geocoders_countries[$geocoder_name] = $countries_function();
    }
  }
  foreach (location_configured_countries() as $country_iso => $country_name) {
    $geocoding_options = array();
    $form['countries'][$country_iso] = array(
      '#type' => 'markup',
      '#value' => '',
    );
    $form['countries'][$country_iso]['label_' . $country_iso] = array(
      '#type' => 'markup',
      '#value' => '<div id="' . $country_iso . '">' . $country_name . '</div>',
    );

    // Next, we look for options presented by country specific providers
    $country_specific_provider_function = 'location_geocode_' . $country_iso . '_providers';
    if (function_exists($country_specific_provider_function)) {
      foreach ($country_specific_provider_function() as $name => $details) {
        $geocoding_options[$name . '|' . $country_iso] = '<a href="' . $details['url'] . '">' . $details['name'] . '</a> (<a href="' . $details['tos'] . '">Terms of Use</a>)';
      }
    }
    foreach ($general_geocoders_list as $geocoder_name) {
      if (in_array($country_iso, $general_geocoders_countries[$geocoder_name])) {
        $geocoding_options[$geocoder_name] = '<a href="' . $general_geocoders_data[$geocoder_name]['url'] . '">' . $general_geocoders_data[$geocoder_name]['name'] . '</a> (<a href="' . $general_geocoder_data[$geocoder_name]['tos'] . '">Terms of Use</a>)';
      }
    }
    if (count($geocoding_options)) {
      $geocoding_options = array_merge(array(
        'none' => t('None'),
      ), $geocoding_options);
      $form['countries'][$country_iso]['location_geocode_' . $country_iso] = array(
        '#type' => 'radios',
        '#default_value' => variable_get('location_geocode_' . $country_iso, 'none'),
        '#options' => $geocoding_options,
      );
    }
    else {
      $form['countries'][$country_iso]['location_geocode_' . $country_iso] = array(
        '#type' => 'markup',
        '#value' => t('None supported.'),
      );
    }
    $current_value = variable_get('location_geocode_' . $country_iso, 'none');
    if ($current_value == 'none') {
      $form['countries'][$country_iso]['location_geocode_config_link_' . $country_iso] = array(
        '#type' => 'markup',
        '#value' => t('No service selected for country.'),
      );
    }
    else {
      $current_val_chopped = substr($current_value, 0, strpos($current_value, '|'));
      $geocode_settings_form_function_specific = 'location_geocode_' . $country_iso . '_' . $current_val_chopped . '_settings';
      $geocode_settings_form_function_general = $current_value . '_geocode_settings';
      if (function_exists($geocode_settings_form_function_specific)) {
        $form['countries'][$country_iso]['location_geocode_config_link_' . $country_iso] = array(
          '#type' => 'markup',
          '#value' => l(t('Configure parameters'), 'admin/settings/location/geocoding/' . $country_iso . '/' . $current_val_chopped),
        );
      }
      elseif (function_exists($geocode_settings_form_function_general)) {
        $form['countries'][$country_iso]['location_geocode_config_link_' . $country_iso] = array(
          '#type' => 'markup',
          '#value' => l(t('Configure parameters'), 'admin/settings/location/geocoding/' . $country_iso . '/' . $current_value),
        );
      }
      else {
        $form['countries'][$country_iso]['location_geocode_config_link_' . $country_iso] = array(
          '#type' => 'markup',
          '#value' => t('No configuration necessary for selected service.'),
        );
      }
    }
  }
  $form['#theme'] = 'location_geocoding_options';
  return system_settings_form($form);
}