diff options
author | David Rothstein <drothstein@gmail.com> | 2013-12-27 14:15:52 -0500 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2013-12-27 14:15:52 -0500 |
commit | 1bcc0e36ad00c534eeff22fd23e405b18ce0a2e9 (patch) | |
tree | face7a8d10a8502aedfd7b4348877b5fee1d53cf /modules/statistics/statistics.php | |
parent | cc200167b4c2113f027d1da3d16c1fa97619991e (diff) | |
download | brdo-1bcc0e36ad00c534eeff22fd23e405b18ce0a2e9.tar.gz brdo-1bcc0e36ad00c534eeff22fd23e405b18ce0a2e9.tar.bz2 |
Issue #1209532 by timmillwood, lucascaro, wiifm, iamEAP, sdrycroft, mikeytown2 | slashrsm: Count node views via AJAX in the statistics module.
Diffstat (limited to 'modules/statistics/statistics.php')
-rw-r--r-- | modules/statistics/statistics.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/statistics/statistics.php b/modules/statistics/statistics.php new file mode 100644 index 000000000..f00e03976 --- /dev/null +++ b/modules/statistics/statistics.php @@ -0,0 +1,31 @@ +<?php + +/** + * @file + * Handles counts of node views via Ajax with minimal bootstrap. + */ + +/** +* Root directory of Drupal installation. +*/ +define('DRUPAL_ROOT', substr($_SERVER['SCRIPT_FILENAME'], 0, strpos($_SERVER['SCRIPT_FILENAME'], '/modules/statistics/statistics.php'))); +// Change the directory to the Drupal root. +chdir(DRUPAL_ROOT); + +include_once DRUPAL_ROOT . '/includes/bootstrap.inc'; +drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); +if (variable_get('statistics_count_content_views', 0) && variable_get('statistics_count_content_views_ajax', 0)) { + $nid = $_POST['nid']; + if (is_numeric($nid)) { + db_merge('node_counter') + ->key(array('nid' => $nid)) + ->fields(array( + 'daycount' => 1, + 'totalcount' => 1, + 'timestamp' => REQUEST_TIME, + )) + ->expression('daycount', 'daycount + 1') + ->expression('totalcount', 'totalcount + 1') + ->execute(); + } +} |