You are here

function locationmap_page in Location Map 7.2

Same name and namespace in other branches
  1. 8.2 locationmap.module \locationmap_page()
  2. 7 locationmap.module \locationmap_page()

Menu callback; generate a page with the location map.

1 string reference to 'locationmap_page'
locationmap_menu in ./locationmap.module
Implements hook_menu().

File

./locationmap.module, line 261

Code

function locationmap_page() {
  $defaults = array(
    'value' => '',
    'format' => filter_default_format(),
  );
  $locationmap_info_defaults = array(
    'value' => 'Fiordland, New Zealand',
    'format' => filter_default_format(),
  );
  $locationmap_title = variable_get('locationmap_title', t('Our Location'));
  $locationmap_info = variable_get('locationmap_info', $locationmap_info_defaults);
  $locationmap_body = variable_get('locationmap_body', $defaults);
  $locationmap_footer = variable_get('locationmap_footer', $defaults);
  $path = drupal_get_path('module', 'locationmap');
  $locationmap_api_key = variable_get('locationmap_api_key', '');
  if ($locationmap_api_key) {
    drupal_add_js('//maps.google.com/maps/api/js?v=3&key=' . $locationmap_api_key, array(
      'type' => 'external',
      'weight' => 5,
    ));
  }
  else {
    drupal_add_js('//maps.google.com/maps/api/js?v=3', array(
      'type' => 'external',
      'weight' => 5,
    ));
    if (user_access('administer locationmap')) {
      $msg = l(t('Location Map Configuration Page'), 'admin/config/content/locationmap');
      $google_map_key_msg = l(t('Google API Console'), 'https://developers.google.com/maps/documentation/javascript/get-api-key');
      drupal_set_message(t("Please set Google Map API Key at {$msg}. You can get Google Map API key from {$google_map_key_msg}"), 'warning', FALSE);
    }
  }
  drupal_add_js($path . '/locationmap.js', array(
    'type' => 'file',
    'weight' => 6,
    'scope' => 'footer',
  ));
  $locationmap_css_options = array(
    'preprocess' => FALSE,
  );
  drupal_add_css($path . '/locationmap.css', $locationmap_css_options);
  $locationmap_settings = array(
    'address' => variable_get('locationmap_address', 'Fiordland, New Zealand'),
    'info' => check_markup($locationmap_info['value'], $locationmap_info['format']),
    'popinfo' => variable_get('locationmap_popinfo', false),
    'lat' => variable_get('locationmap_lat', '-46.0868686'),
    'lng' => variable_get('locationmap_lng', '166.6822074'),
    'zoom' => variable_get('locationmap_zoom', 10),
    'type' => variable_get('locationmap_type', 'google.maps.MapTypeId.ROADMAP'),
    'admin' => user_access('administer locationmap'),
    'scroll' => variable_get('locationmap_scroll', 1),
  );
  if (!$locationmap_settings['info']) {
    $locationmap_settings['info'] = $locationmap_settings['address'];
  }
  drupal_add_js(array(
    'locationmap' => $locationmap_settings,
  ), 'setting');
  $output = '<div id="locationmap_body">' . check_markup($locationmap_body['value'], $locationmap_body['format']) . '</div>';
  $output .= theme('locationmap_map');
  $output .= '<div id="locationmap_footer">' . check_markup($locationmap_footer['value'], $locationmap_footer['format']) . '</div>';
  if (user_access('administer locationmap')) {

    // TODO: Remove drupal_render and update to D7 desired behaviour. See http://drupal.org/update/modules/6/7#unrendered
    $form = drupal_get_form('locationmap_in_place_edit_form');
    $output .= drupal_render($form);
  }
  drupal_set_title($locationmap_title);
  return $output;
}