statistics.php 972 B

123456789101112131415161718192021222324252627282930313233
  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. if (isset($_POST['nid'])) {
  16. $nid = $_POST['nid'];
  17. if (is_numeric($nid)) {
  18. db_merge('node_counter')
  19. ->key(array('nid' => $nid))
  20. ->fields(array(
  21. 'daycount' => 1,
  22. 'totalcount' => 1,
  23. 'timestamp' => REQUEST_TIME,
  24. ))
  25. ->expression('daycount', 'daycount + 1')
  26. ->expression('totalcount', 'totalcount + 1')
  27. ->execute();
  28. }
  29. }
  30. }