function statistics_advanced_user_access in Statistics Advanced 6
A copy of user.module's user_access() function so we do not need to load the entire user.module during cached visits.
1 call to statistics_advanced_user_access()
- statistics_advanced_exit in ./
statistics_advanced.module - Implementation of hook_exit().
File
- ./
statistics_advanced.module, line 209 - Adds advanced settings and features for the core Statistics module.
Code
function statistics_advanced_user_access($string, $account = NULL) {
// If user.module is loaded, use that function call since it most likely has
// the permissions already cached.
if (function_exists('user_access')) {
return user_access($string, $account);
}
static $perm = array();
if (!isset($account)) {
global $user;
$account = $user;
}
// User #1 has all privileges:
if ($account->uid == 1) {
return TRUE;
}
// To reduce the number of SQL queries, we cache the user's permissions
// in a static variable.
if (!isset($perm[$account->uid])) {
$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));
$perms = array();
while ($row = db_fetch_object($result)) {
$perms += array_flip(explode(', ', $row->perm));
}
$perm[$account->uid] = $perms;
}
return isset($perm[$account->uid][$string]);
}