/[drupal]/contributions/modules/statistics_advanced/statistics_advanced.module
ViewVC logotype

Diff of /contributions/modules/statistics_advanced/statistics_advanced.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.19, Mon Dec 22 20:24:54 2008 UTC revision 1.1.2.20, Wed Jan 14 02:07:33 2009 UTC
# Line 53  function statistics_advanced_link_alter( Line 53  function statistics_advanced_link_alter(
53      }      }
54      drupal_set_message($message, 'error', FALSE);      drupal_set_message($message, 'error', FALSE);
55      watchdog('statistics_adv', $message, array(), WATCHDOG_ERROR);      watchdog('statistics_adv', $message, array(), WATCHDOG_ERROR);
56            return;      return;
57          }    }
58    
59    if (isset($links['statistics_counter'])) {    if (isset($links['statistics_counter'])) {
60      $counter_node_types = statistics_advanced_var('counter_node_types');      $counter_node_types = statistics_advanced_var('counter_node_types');
# Line 86  function statistics_advanced_boot() { Line 86  function statistics_advanced_boot() {
86      $uid = $user->uid;      $uid = $user->uid;
87    
88      if (!$uid && variable_get('statistics_enable_access_log', 0)) {      if (!$uid && variable_get('statistics_enable_access_log', 0)) {
89        $last_read_accesslog = db_fetch_object(db_query_range("SELECT uid, timestamp FROM {accesslog} WHERE (path = '%s' OR uid > 0) AND sid = '%s' ORDER BY timestamp DESC", array(':path' => $_GET['q'], ':sid' => session_id()), 0, 1));        $accesslog = db_fetch_object(db_query_range("SELECT uid, timestamp FROM {accesslog} WHERE (path = '%s' OR uid > 0) AND sid = '%s' ORDER BY timestamp DESC", array(':path' => $_GET['q'], ':sid' => session_id()), 0, 1));
90        if ($last_read_accesslog) {        if ($accesslog) {
91          if ($last_read_accesslog->uid) {          if ($accesslog->uid) {
92            $uid = $last_read_accesslog->uid;            $uid = $accesslog->uid;
93          }          }
94          else {          else {
95            _statistics_advanced_ignore('nodecounter', $last_read_accesslog->timestamp);            _statistics_advanced_ignore('nodecounter', $accesslog->timestamp);
96          }          }
97        }        }
98      }      }
99    
100      if ($uid) {      if ($uid) {
101        $last_read_history = db_result(db_query("SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d", array(':uid' => $uid, ':nid' => arg(1))));        $historylog = db_result(db_query("SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d", array(':uid' => $uid, ':nid' => arg(1))));
102        if ($last_read_history) {        if ($historylog) {
103          // Repeat user visit (same user id and node id in history table)          // Repeat user visit (same user id and node id in history table)
104          _statistics_advanced_ignore('nodecounter', $last_read_history);          _statistics_advanced_ignore('nodecounter', $historylog);
105        }        }
106      }      }
107    }    }
108  }  }
109    
110    function _statistics_advanced_is_403_or_404() {
111      global $base_root;
112      $headers = '';
113    
114      if (function_exists('headers_list')) {
115        $headers = implode("\n", headers_list());
116      }
117      elseif (function_exists('drupal_set_header')) {
118        $headers = drupal_set_header();
119      }
120      elseif (variable_get('cache', CACHE_DISABLED) == CACHE_NORMAL) {
121        $headers = db_result(db_query("SELECT headers FROM {cache_page} WHERE cid = :cid", array(':cid' => $base_root . request_uri())));
122      }
123    
124      return preg_match('/404 Not Found|403 Forbidden/i', $headers);
125    }
126    
127  /**  /**
128   * Implementation of hook_exit().   * Implementation of hook_exit().
129   *   *
# Line 118  function statistics_advanced_exit() { Line 135  function statistics_advanced_exit() {
135    $is_node_visit = (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0));    $is_node_visit = (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0));
136    
137    if ($is_node_visit) {    if ($is_node_visit) {
138      // Ignore 404 and 403 node visits.      if (_statistics_advanced_is_403_or_404()) {
139      if (preg_match('/404 Not Found|403 Forbidden/i', drupal_set_header())) {        // Ignore 404 and 403 node visits.
140        _statistics_advanced_ignore('nodecounter', TRUE);        _statistics_advanced_ignore('nodecounter', TRUE);
141      }      }
142        /*else {
     /*drupal_load('module', 'node');  
     $node = db_fetch_object(db_query("SELECT * FROM {node} WHERE nid = %d", array(':nid' => arg(1))));  
   
     if (!$node || !node_access('view', $node)) {  
       // Catch 404 and 403s from being added to the counter.  
       _statistics_advanced_ignore('nodecounter', TRUE);  
     }  
     else {  
143        // If the node has been previously read by the user and has changed since        // If the node has been previously read by the user and has changed since
144        // the last read, count it as a new read.        // the last read, count it as a new read.
145          $changed = db_result(db_query("SELECT changed FROM {node} WHERE nid = :nid", array(':nid' => arg(1))));
146        $last_read = _statistics_advanced_ignore('nodecounter');        $last_read = _statistics_advanced_ignore('nodecounter');
147        if ($last_read && $node->changed > $last_read) {        if ($last_read && $changed > $last_read) {
148          _statistics_advanced_ignore('nodecounter', FALSE);          _statistics_advanced_ignore('nodecounter', FALSE);
149        }        }
150      }*/      }*/
# Line 147  function statistics_advanced_exit() { Line 157  function statistics_advanced_exit() {
157    }    }
158    
159    // Check if the user's browser is a crawler.    // Check if the user's browser is a crawler.
160    if (!$user->uid && statistics_advanced_var('ignore_crawlers') && module_exists('browscap')) {    if (!$user->uid && statistics_advanced_var('ignore_crawlers') && module_exists('browscap') && function_exists('browscap_get_browser')) {
161      drupal_load('module', 'browscap');      drupal_load('module', 'browscap');
162      $browser = browscap_get_browser();      $browser = browscap_get_browser();
163      if (isset($browser['crawler']) && $browser['crawler']) {      if (!empty($browser['crawler'])) {
164        _statistics_advanced_ignore('accesslog', TRUE);        _statistics_advanced_ignore('accesslog', TRUE);
165        if ($is_node_visit) {        if ($is_node_visit) {
166          _statistics_advanced_ignore('nodecounter', TRUE);          _statistics_advanced_ignore('nodecounter', TRUE);
167        }        }
168        if (variable_get('browscap_monitor', 0)) {        if (variable_get('browscap_monitor', 0) && function_exists('browscap_unmonitor')) {
169          _statistics_advanced_ignore('browscap', TRUE);          browscap_unmonitor();
170        }        }
171      }      }
172    }    }
173    
   if (_statistics_advanced_ignore('browscap')) {  
     browscap_unmonitor();  
   }  
   
174    if (_statistics_advanced_ignore('nodecounter')) {    if (_statistics_advanced_ignore('nodecounter')) {
175      db_query("UPDATE {node_counter} SET daycount = daycount - 1, totalcount = totalcount - 1 WHERE nid = %d AND totalcount > 0 AND daycount > 0", array(':nid' => arg(1)));      db_query("UPDATE {node_counter} SET daycount = daycount - 1, totalcount = totalcount - 1 WHERE nid = %d AND totalcount > 0 AND daycount > 0", array(':nid' => arg(1)));
176    }    }

Legend:
Removed from v.1.1.2.19  
changed lines
  Added in v.1.1.2.20

  ViewVC Help
Powered by ViewVC 1.1.2