You are here

function extlink_extra_page_build in External Links Extra 7

Implementation of hook_page_build().

File

./extlink_extra.module, line 11
This module adds some extra functionality to the External Links module.

Code

function extlink_extra_page_build() {
  $path = drupal_get_path('module', 'extlink_extra');

  // Add our JS in the footer so it will execute after extlink.js.
  drupal_add_js($path . '/extlink_extra.js', array(
    'every_page' => TRUE,
    'scope' => 'footer',
  ));

  // If we're using colorbox, we'll add js=1 to the url string of the alert page - this causes a premature exit
  // which saves execution time and doesn't render the rest of the page.
  $aQuery = array();
  if (variable_get('extlink_alert_type', 'colorbox') == 'colorbox') {
    $aQuery = array(
      'js' => 1,
    );
  }

  // Get url params if they exist.
  $url_params['external_url'] = isset($_GET['external_url']) ? valid_url($_GET['external_url'], $absolute = TRUE) ? drupal_strip_dangerous_protocols($_GET['external_url']) : NULL : NULL;
  $url_params['back_url'] = isset($_GET['back_url']) ? valid_url($_GET['back_url'], $absolute = TRUE) ? drupal_strip_dangerous_protocols($_GET['back_url']) : NULL : NULL;

  // Expose settings from our settings page to javascript.
  drupal_add_js(array(
    'extlink_extra' => array(
      'extlink_alert_type' => variable_get('extlink_alert_type', 'colorbox'),
      'extlink_alert_timer' => variable_get('extlink_alert_timer', 0),
      'extlink_alert_url' => url('now-leaving', array(
        'query' => $aQuery,
      )),
      'extlink_cache_fix' => variable_get('extlink_cache_fix', 0),
      'extlink_exclude_warning' => variable_get('extlink_exclude_warning', ''),
      'extlink_508_fix' => variable_get('extlink_508_fix', 0),
      'extlink_508_text' => variable_get('extlink_508_text', EXTLINK_EXTRA_508_TEXT),
      'extlink_url_override' => variable_get('extlink_url_override', 0),
      'extlink_url_params' => $url_params,
    ),
  ), 'setting');

  // Add an extra CSS file if our 508 fix option is on.
  if (variable_get('extlink_508_fix', 0)) {
    drupal_add_css($path . '/extlink_extra.508.css');
  }

  // extlink_extra relies on the jquery.cookie for passing around information.
  // This also helps us overcome aggressive caching, since the client side code
  // has access to information from the last page load.
  drupal_add_library('system', 'jquery.cookie', TRUE);
}