Commit 0c5a5b26 authored by mikeytown2's avatar mikeytown2

#422620 : Improved stat image code, valid xhtml output, smarter boost_stats.php file.

parent 3608a461
......@@ -12,23 +12,13 @@ something implemented right now, please contact the developers to see if
they're available for contract work, or if perhaps a modest donation could
speed things along.)
TODO: IN THE WORKS
------------------
* Add a 'Delete cached page' button to the Boost cache status block.
* Test interaction with other modules that also make use of ob_start().
TODO: FUTURE IDEAS
------------------
* An administrative interface for pre-generating static files for all pages
on the Drupal site in one go using the Batch API.
* Add a node-specific cache lifetime setting.
* Add admin-visible block for updating the cached copy of the current page.
* An administrative interface to set specific cache lifetime settings.
* Add a cache current page button to block.
* Other web servers than Apache are not supported at the moment. This is due
to the way the cache dispatch is implemented using Apache mod_rewrite
directives in the .htaccess file. Lighttpd support would be desirable but
is not a high priority for the developer at present.
* User-specific static page cache. Could conceivably be implemented based
on the existing user-cookie mechanism, though security would be a concern.
* Don't delete the entire file system cache when Boost is disabled; just
rename the site's cache directory with the suffix `.disabled', speeding up
cache regeneration once the module is re-enabled?
is not a high priority for the developer at present.
\ No newline at end of file
......@@ -125,12 +125,16 @@ function boost_preprocess_page(&$variables) {
/**
* Implementation of hook_footer().
*
* Place boost image into pages footer.
* Place boost stat counter image into pages footer.
*
* NOTE HTML code could be added to the $buffer directly, right before </body>,
* inside _boost_ob_handler() function. Would prevent 2x counts on first view.
*/
function boost_footer() {
Global $base_url;
Global $base_path, $user;
$filename = 'boost_stats.php';
if (!( strpos($_SERVER['SCRIPT_FILENAME'], 'index.php') === FALSE
if ( strpos($_SERVER['SCRIPT_FILENAME'], 'index.php') === FALSE
|| variable_get('site_offline', 0)
|| $_SERVER['REQUEST_METHOD'] != 'GET'
|| $_SERVER['SERVER_SOFTWARE'] === 'PHP CLI'
......@@ -139,24 +143,28 @@ function boost_footer() {
|| !boost_is_cacheable($GLOBALS['_boost_path'])
|| !empty($user->uid)
|| !file_exists($filename)
)) {
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0)) {
$nid = arg(1);
}
if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
$title = drupal_urlencode(strip_tags(drupal_get_title()));
$q = $_GET['q'];
}
) {
return;
}
if (isset($nid) & !isset($title)) {
return '<img src="'. $base_url . '/' . $filename . '?nid=' . $nid . '" />';
}
elseif (isset($nid) & isset($title)) {
return '<img src="'. $base_url . '/' . $filename . '?nid=' . $nid . '&q=' . $q . '&title=' . $title . '" />';
}
elseif (!isset($nid) & isset($title)) {
return '<img src="'. $base_url . '/' . $filename . '?q=' . $q . '&title=' . $title . '" />';
}
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0)) {
$nid = arg(1);
}
if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
$title = drupal_urlencode(strip_tags(drupal_get_title()));
$q = $_GET['q'];
}
$start = '<div><img src="' . $base_path . $filename;
$end = '" alt="" /></div>';
if (isset($nid) & !isset($title)) {
return $start . '?nid=' . $nid . $end;
}
elseif (isset($nid) & isset($title)) {
return $start . '?nid=' . $nid . '&q=' . $q . '&title=' . $title . $end;
}
elseif (!isset($nid) & isset($title)) {
return $start . '?q=' . $q . '&title=' . $title . $end;
}
}
......
<?php
// $Id$
//Script should take under 1mb of memory to work.
//prime php for background operations
// Script should take under 1mb of memory to work.
// Prime php for background operations
ob_end_clean();
header("Connection: close");
ignore_user_abort();
// output of 1 pixel transparent gif
// Output of 1 pixel transparent gif
ob_start();
header("Content-type: image/gif");
header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
header("Cache-Control: no-cache");
header("Cache-Control: must-revalidate");
header("Content-Length: 45");
header("Content-Length: 43");
header("Connection: close");
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
ob_end_flush();
flush();
// Image returned, so time taken below should not effect page load times.
// Do background processing here - Connect to DB and set stats.
// Image returned and connection closed.
// Do background processing. Time taken below should not effect page load times.
// Exit script if nothing was passed to it.
if ( !isset($_GET['nid'])
&& !isset($_GET['title'])
&& !isset($_GET['q'])
&& !isset($_GET['referer'])
) {
exit;
}
// Set variables passed via GET.
$nid = isset($_GET['nid']) ? $_GET['nid'] : NULL;
$title = isset($_GET['title']) ? urldecode($_GET['title']) : NULL;
$q = isset($_GET['q']) ? $_GET['q'] : NULL;
$referer = isset($_GET['referer']) ? $_GET['referer'] : NULL;
// Connect to DB.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
// Get stat settings.
$count_views = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'statistics_count_content_views', 0, 1));
$count_views = unserialize($count_views['value']);
$access_log = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'statistics_enable_access_log', 0, 1));
$access_log = unserialize($access_log['value']);
// Set node counter.
if ($count_views) {
// We are counting content views.
if (isset($_GET['nid']) && is_numeric($_GET['nid'])) {
if (isset($nid) && is_numeric($nid)) {
// A node has been viewed, so update the node's counters.
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $_GET['nid']);
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $nid);
// If we affected 0 rows, this is the first time viewing the node.
if (!db_affected_rows()) {
// We must create a new row to store counters for the new node.
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $_GET['nid'], time());
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $nid, time());
}
}
}
if ($access_log && isset($_GET['title']) && isset($_GET['q'])) {
// Log this page access.
// Set access log.
if ($access_log && isset($title) && isset($q)) {
$session_id = session_id();
if (empty($session_id)) {
$session_id = $_COOKIE[session_name()];
if (empty($session_id)) {
$session_id = 'boost ' . ip_address();
// This only goes in the access log; only used for stats, not creds.
$session_id = md5($_SERVER['HTTP_USER_AGENT'] . ip_address());
}
}
$referer = isset($GET['referer']) ? $GET['referer'] : '';
$uid = 0;
db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", urldecode($_GET['title']), $_GET['q'], $referer, ip_address(), $uid, $session_id, timer_read('page'), time());
db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", $title, $q, $referer, ip_address(), $uid, $session_id, timer_read('page'), time());
}
exit;
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment