| 1 |
<?php |
<?php |
| 2 |
// $Id: statistics_advanced.module,v 1.1.2.23 2009/03/20 06:01:50 davereid Exp $ |
// $Id: statistics_advanced.module,v 1.1.2.24 2009/04/17 02:27:44 davereid Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 146 |
// Ignore 404 and 403 node visits. |
// Ignore 404 and 403 node visits. |
| 147 |
_statistics_advanced_ignore('nodecounter', TRUE); |
_statistics_advanced_ignore('nodecounter', TRUE); |
| 148 |
} |
} |
| 149 |
elseif (user_access('exclude visits from counters')) { |
elseif (statistics_advanced_user_access('exclude visits from counters')) { |
| 150 |
_statistics_advanced_ignore('nodecounter', TRUE); |
_statistics_advanced_ignore('nodecounter', TRUE); |
| 151 |
} |
} |
| 152 |
/*else { |
/*else { |
| 161 |
} |
} |
| 162 |
|
|
| 163 |
// Check if user's access log entry should be ignored based on user role. |
// Check if user's access log entry should be ignored based on user role. |
| 164 |
drupal_load('module', 'user'); |
if (statistics_advanced_user_access('exclude visits from the access log')) { |
|
if (user_access('exclude visits from the access log')) { |
|
| 165 |
_statistics_advanced_ignore('accesslog', TRUE); |
_statistics_advanced_ignore('accesslog', TRUE); |
| 166 |
} |
} |
| 167 |
|
|
| 190 |
} |
} |
| 191 |
|
|
| 192 |
/** |
/** |
| 193 |
|
* A copy of user.module's user_access() function so we do not need to load |
| 194 |
|
* the entire user.module during cached visits. |
| 195 |
|
*/ |
| 196 |
|
function statistics_advanced_user_access($string, $account = NULL, $reset = FALSE) { |
| 197 |
|
// If user.module is loaded, use that function call since it most likely has |
| 198 |
|
// the permissions already cached. |
| 199 |
|
if (function_exists('user_access')) { |
| 200 |
|
return user_access($string, $account, $reset); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
global $user; |
| 204 |
|
static $perm = array(); |
| 205 |
|
|
| 206 |
|
if ($reset) { |
| 207 |
|
$perm = array(); |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
if (is_null($account)) { |
| 211 |
|
$account = $user; |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
// User #1 has all privileges: |
| 215 |
|
if ($account->uid == 1) { |
| 216 |
|
return TRUE; |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
// To reduce the number of SQL queries, we cache the user's permissions |
| 220 |
|
// in a static variable. |
| 221 |
|
if (!isset($perm[$account->uid])) { |
| 222 |
|
$result = db_query("SELECT p.perm FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (". db_placeholders($account->roles) .")", array_keys($account->roles)); |
| 223 |
|
|
| 224 |
|
$perms = array(); |
| 225 |
|
while ($row = db_fetch_object($result)) { |
| 226 |
|
$perms += array_flip(explode(', ', $row->perm)); |
| 227 |
|
} |
| 228 |
|
$perm[$account->uid] = $perms; |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
return isset($perm[$account->uid][$string]); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
/** |
| 235 |
* Internal function to track which records to ignore. |
* Internal function to track which records to ignore. |
| 236 |
*/ |
*/ |
| 237 |
function _statistics_advanced_ignore($type, $value = NULL) { |
function _statistics_advanced_ignore($type, $value = NULL) { |