statistics.php 912 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * @file
  4. * Handles counts of node views via Ajax with minimal bootstrap.
  5. */
  6. /**
  7. * Root directory of Drupal installation.
  8. */
  9. define('DRUPAL_ROOT', substr($_SERVER['SCRIPT_FILENAME'], 0, strpos($_SERVER['SCRIPT_FILENAME'], '/modules/statistics/statistics.php')));
  10. // Change the directory to the Drupal root.
  11. chdir(DRUPAL_ROOT);
  12. include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  13. drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
  14. if (variable_get('statistics_count_content_views', 0) && variable_get('statistics_count_content_views_ajax', 0)) {
  15. $nid = $_POST['nid'];
  16. if (is_numeric($nid)) {
  17. db_merge('node_counter')
  18. ->key(array('nid' => $nid))
  19. ->fields(array(
  20. 'daycount' => 1,
  21. 'totalcount' => 1,
  22. 'timestamp' => REQUEST_TIME,
  23. ))
  24. ->expression('daycount', 'daycount + 1')
  25. ->expression('totalcount', 'totalcount + 1')
  26. ->execute();
  27. }
  28. }