File: statistics.php

package info (click to toggle)
drupal7 7.52-2%2Bdeb9u11
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,756 kB
  • sloc: php: 44,022; pascal: 42,649; javascript: 31,405; sh: 1,685; xml: 466; makefile: 21; sql: 1
file content (33 lines) | stat: -rw-r--r-- 972 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?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)) {
  if (isset($_POST['nid'])) {
    $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();
    }
  }
}