You are here

function openlayers_include in Openlayers 7.2

Same name and namespace in other branches
  1. 6.2 openlayers.module \openlayers_include()

Include necessary CSS and JS for rendering maps

4 calls to openlayers_include()
openlayers_build_map in ./openlayers.module
Prepare a map for rendering.
openlayers_maps_ui::edit_form in modules/openlayers_ui/plugins/export_ui/openlayers_maps_ui.class.php
Provide the actual editing form.
openlayers_ui_init in modules/openlayers_ui/openlayers_ui.module
Implements hook_init().
openlayers_ui_style_preview in modules/openlayers_ui/openlayers_ui.module
Create Style Preview

File

./openlayers.module, line 100
Main OpenLayers API File

Code

function openlayers_include() {

  // Get the page language for string translation.
  global $language;
  $lang = $language->language;
  if ('internal' == variable_get('openlayers_source_type', 'external')) {
    $variant = variable_get('openlayers_source_internal_variant', NULL);
    if ($variant == 'original') {
      $variant = NULL;
    }
    libraries_load('openlayers', $variant);
    if ($lang != 'en') {
      $main_locale = libraries_get_path('openlayers') . '/lib/OpenLayers/Lang.js';
      if (file_exists($main_locale)) {
        drupal_add_js($main_locale, 'file');
      }
      $language_locale = libraries_get_path('openlayers') . '/lib/OpenLayers/Lang/' . $lang . '.js';
      if (file_exists($language_locale)) {
        drupal_add_js($language_locale, 'file');
      }
      else {
        $country_code = variable_get('site_default_country', '');
        $language_locale = libraries_get_path('openlayers') . '/lib/OpenLayers/Lang/' . $lang . '-' . $country_code . '.js';
        if (file_exists($language_locale)) {
          drupal_add_js($language_locale, 'file');
        }
      }
    }
  }
  else {

    // Use a static variable to prevent running URL check code repeatedly.
    static $once;
    if (!isset($once)) {
      $once = TRUE;
      $path = check_plain(variable_get('openlayers_source_external', OPENLAYERS_DEFAULT_LIBRARY));

      // Correctly handle URLs beginning with a double backslash, see RFC 1808 Section 4
      if (substr($path, 0, 2) == '//') {
        $http_protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
        $path = $http_protocol . ':' . $path;
      }

      // Check for full URL and include it manually if external.
      if (valid_url($path, TRUE)) {
        drupal_add_js($path, 'external');
      }
      else {
        drupal_add_js($path);
      }
      if ($lang != 'en') {
        $main_locale = libraries_get_path('openlayers') . '/lib/OpenLayers/Lang.js';
        if (file_exists($main_locale)) {
          drupal_add_js($main_locale, 'file');
        }
        $language_locale = libraries_get_path('openlayers') . '/lib/OpenLayers/Lang/' . $lang . '.js';
        if (file_exists($language_locale)) {
          drupal_add_js($language_locale, 'file');
        }
        else {
          $country_code = variable_get('site_default_country', '');
          $language_locale = libraries_get_path('openlayers') . '/lib/OpenLayers/Lang/' . $lang . '-' . $country_code . '.js';
          if (file_exists($language_locale)) {
            drupal_add_js($language_locale, 'file');
          }
        }
      }
      drupal_add_css(drupal_get_path('module', 'openlayers') . '/css/openlayers.css', 'file');
      drupal_add_js(drupal_get_path('module', 'openlayers') . '/js/openlayers.js', 'file');
    }
  }
}