You are here

function boost_stats_generate in Boost 6

Generate js/html for boost stat counter.

NOTE HTML code could be added to the $buffer directly. Would prevent 2x counts on first view. Would be hard to do though.

Parameters

$filename: Name of boost's statistics php file.

1 call to boost_stats_generate()
boost_block in ./boost.module
Implementation of hook_block().

File

./boost.module, line 2472
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function boost_stats_generate($filename) {
  global $base_path;

  // is node & node count enabled.
  if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0)) {
    $nid = arg(1);
  }
  else {
    $nid = 'NULL';
  }

  // access log enabled.
  if (variable_get('statistics_enable_access_log', 0) && module_invoke('throttle', 'status') == 0) {
    $title = drupal_urlencode(strip_tags(drupal_get_title()));
    $q = $_GET['q'];
  }
  else {
    $title = 'NULL';
    $q = 'NULL';
  }
  $page_js = array(
    'boost' => array(
      'nid' => $nid,
      'q' => $q,
      'title' => $title,
    ),
  );
  $site_js = <<<ETO
\$.getJSON(Drupal.settings.basePath + "{<span class="php-variable">$filename</span>}", {nocache: "1", js: "1", nid: Drupal.settings.boost.nid, qq: Drupal.settings.boost.q, title: Drupal.settings.boost.title, referer: document.referrer}, function(response) {
  \$.each(response, function(id, contents) {
    if (contents == 'NULL') {
      \$(id).parent().parent().hide();
    }
    else {
      \$(id).html(contents);
    }
  });
});
ETO;

  // page specific variables
  drupal_add_js($page_js, 'setting', 'header');

  // site-wide code
  drupal_add_js($site_js, 'inline', 'footer');

  // no script code
  $page_ns = '<noscript><div style="display:inline;"><img src="' . $base_path . $filename . '?nocache=1' . '&amp;nid=' . $nid . '&amp;title=' . $title . '&amp;qq=' . $q . '" alt="" /></div></noscript>';
  return $page_ns;
}