? browscap.filter-roles.patch Index: browscap.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/browscap/browscap.module,v retrieving revision 1.6.2.3.2.11 diff -u -p -r1.6.2.3.2.11 browscap.module --- browscap.module 30 Sep 2009 17:16:40 -0000 1.6.2.3.2.11 +++ browscap.module 1 Dec 2010 21:01:34 -0000 @@ -81,18 +81,21 @@ function browscap_menu() { function browscap_exit() { // If monitoring is enabled, record the browser if (variable_get('browscap_monitor', FALSE)) { - if ($browser = browscap_get_browser()) { - $browserstring = substr(trim($browser['parent']), 0, 255); - if ($browserstring == '' or $browserstring == 'Default Browser') { - $browserstring = trim($_SERVER['HTTP_USER_AGENT']); - } - db_query("UPDATE {browscap_statistics} SET counter = counter + 1, is_crawler=%d ". - "WHERE parent='%s'", $browser['crawler'], $browserstring); - // If we affected 0 rows, this is the first time we've seen this browser - if (!db_affected_rows()) { - // We must create a new row to store counters for the new browser. - db_query('INSERT INTO {browscap_statistics} (parent,counter,is_crawler) '. - "VALUES('%s', 1, %d)", $browserstring, $browser['crawler']); + // Check whether current user can be monitored + if (browscap_log_user()) { + if ($browser = browscap_get_browser()) { + $browserstring = substr(trim($browser['parent']), 0, 255); + if ($browserstring == '' or $browserstring == 'Default Browser') { + $browserstring = trim($_SERVER['HTTP_USER_AGENT']); + } + db_query("UPDATE {browscap_statistics} SET counter = counter + 1, is_crawler=%d ". + "WHERE parent='%s'", $browser['crawler'], $browserstring); + // If we affected 0 rows, this is the first time we've seen this browser + if (!db_affected_rows()) { + // We must create a new row to store counters for the new browser. + db_query('INSERT INTO {browscap_statistics} (parent,counter,is_crawler) '. + "VALUES('%s', 1, %d)", $browserstring, $browser['crawler']); + } } } } @@ -121,6 +124,10 @@ function browscap_cron() { * @return array */ function browscap_settings() { + + $roles_all = user_roles(); + $roles_monitored = variable_get('browscap_roles', array()); + $form['browscap_data_status'] = array( '#value' => t('

Browscap data current as of %fileversion. [Refresh now]

', array( @@ -138,6 +145,15 @@ function browscap_settings() { '!reports' => url('admin/reports/browscap'), )), ); + + $form['browscap_roles'] = array( + '#type' => 'checkboxes', + '#title' => t('Monitor Roles'), + '#default_value' => !empty($roles_monitored) ? array_values((array) $roles_monitored) : array(), + '#options' => $roles_all, + '#description' => t('Only monitor the selected roles. If no options are selected all roles are monitored by default.') + ); + return system_settings_form($form); } @@ -280,7 +296,7 @@ function browscap_get_browser($useragent } /** - * Determine whether the current visitor + * Determine whether the current visitor is a crawler * * @param string $useragent * Optional user agent string. @@ -399,6 +415,21 @@ function browscap_unmonitor() { } /** + * Check whether the current user role can be monitored + * + * @return bool + */ +function browscap_log_user() { + global $user; + $roles_orig = variable_get('browscap_roles', array()); + // removes roles without permission + $roles = array_filter($roles_orig); + // get intersection of user's roles and roles with permission + $intersect = array_intersect(array_keys($user->roles), array_keys($roles)); + return !empty($intersect); +} + +/** * Loads details about a given useragent. Also used as a menu object loader. * * @param $useragent