You are here

function boost_stats_ajax_callback in Boost 6

AJAX Menu Callback.

1 string reference to 'boost_stats_ajax_callback'
boost_menu in ./boost.module
Implementation of hook_menu().

File

stats/boost_stats.ajax.inc, line 11
Boost & core stats logic

Code

function boost_stats_ajax_callback() {

  // Exit if nothing was passed to this.
  if (!isset($_GET['nid']) && !isset($_GET['title']) && !isset($_GET['qq']) && !isset($_GET['referer'])) {
    return drupal_not_found();
  }
  if (!isset($_GET['js'])) {

    // stats not called via JS, send image out & close connection.
    boost_async_opp("", TRUE, 'image/gif', 43);
  }

  // Set variables passed via GET.
  $nid = isset($_GET['nid']) && is_numeric($_GET['nid']) ? $_GET['nid'] : NULL;
  $title = isset($_GET['title']) && $_GET['title'] != 'NULL' ? urldecode($_GET['title']) : NULL;
  $q = isset($_GET['qq']) && $_GET['qq'] != 'NULL' ? $_GET['qq'] : NULL;
  $referer = isset($_GET['referer']) ? $_GET['referer'] : NULL;

  // $session_id only goes in the access log; only used for stats, not creds.
  $session_id = session_id();
  if (empty($session_id)) {
    if (empty($_COOKIE[session_name()])) {
      if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $session_id = md5(ip_address());
      }
      else {
        $session_id = md5($_SERVER['HTTP_USER_AGENT'] . ip_address());
      }
    }
    else {
      $session_id = $_COOKIE[session_name()];
    }
  }

  // Anonymous users always get a User ID of 0.
  $uid = 0;

  // Set node counter.
  if (variable_get('statistics_count_content_views', FALSE)) {
    boost_stats_update_node_counter($nid);
  }

  // Set access log.
  if (variable_get('statistics_enable_access_log', FALSE)) {
    boost_stats_add_access_log($title, $q, $referer, $session_id, $uid);
  }

  // Return Data
  if (isset($_GET['js'])) {
    if ($_GET['js'] == 1) {
      $json = array();

      // Get stats block html.
      $json = array_merge($json, boost_stats_output_stats_block());

      // Send JSON Back
      if (!empty($json)) {
        drupal_json($json);
      }
    }
    elseif ($_GET['js'] == 2) {
      echo array_pop(boost_stats_output_stats_block());
    }
  }
}