m7v
3/31/2014 - 2:27 PM

CTool Access Plugin is_ajax

CTool Access Plugin is_ajax

$plugin = array(
  'title' => t('Ajax'),
  'description' => t('Is page loaded by ajax.'),
  'callback' => 'spaint_track_ajax_access_callback',
);

/**
* Callback.
*/
function spaint_track_ajax_access_callback($conf, $context) {
  return spaint_track_ajax();
}

/**
* Check if current request is AJAX.
*
* @return boolean
* TRUE if request is ajax, and FALSE if it is't.
*/
function spaint_track_ajax() {
  $http_request = isset($_SERVER['HTTP_X_REQUESTED_WITH'])
  && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
  
  // Check ajax in IE.
  $request_uri = isset($_SERVER['REQUEST_URI'])
  && strtolower($_SERVER['REQUEST_URI']) == '/system/ajax';
  
  return $http_request || $request_uri || !empty($_GET['ajax']);
}