--- C:/Documents/Web/drupal-5.1/modules/statistics/statistics.module.old Wed Jan 10 10:17:51 2007 +++ C:/Documents/Web/drupal-5.1/modules/statistics/statistics.module Tue Apr 24 10:57:16 2007 @@ -57,12 +57,17 @@ if (variable_get('statistics_count_content_views', 0)) { // We are counting content views. if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') { - // 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(), arg(1)); - // 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)', arg(1), time()); + // If we want only unique views, check to see if the user has seen this node already + // Previous visits for authenticed users is in the history table + // For anonymous users, we check the session id in the access_log table + if (!variable_get('statistics_count_unique_views', 0) || !($user->uid ? db_num_rows(db_query("SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d", $user->uid, arg(1))) : db_num_rows(db_query("SELECT aid FROM {accesslog} WHERE uid = 0 AND sid = '%s' AND path = '%s'", $_GET['q'], session_id())))) { + // 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(), arg(1)); + // 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)', arg(1), time()); + } } } } @@ -389,6 +394,11 @@ '#default_value' => variable_get('statistics_count_content_views', 0), '#options' => $options, '#description' => t('Increment a counter each time content is viewed.')); + $form['content']['statistics_count_unique_views'] = array( + '#type' => 'checkbox', + '#title' => t('Only count unique views'), + '#default_value' => variable_get('statistics_count_unique_views', 0), + '#description' => t('Only count one view for each registered user and each anonymous user session.')); return system_settings_form($form); }