Skip to content
Snippets Groups Projects

Issue #3087315: Filter/filter config anonymous users & paths

Merged Steven Ayers requested to merge issue/visitors-3087315:3087315-filter-config-path into 7.x-1.x
7 files
+ 455
50
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 124
47
@@ -12,35 +12,10 @@
* The form.
*/
function visitors_admin_settings() {
$roles = [];
foreach (user_roles() as $role) {
$roles[$role] = $role;
}
$form = array();
// Statistics settings.
$form['visitors_statistics'] = array(
'#type' => 'fieldset',
'#title' => t('Visitors statistics'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => t('Visitors statistics settings'),
);
$form['visitors_statistics']['visitors_exclude_user1'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude user1 from statistics'),
'#default_value' => variable_get('visitors_exclude_user1', 0),
'#description' => t('Exclude hits of user1 from statistics.'),
);
$form['visitors_statistics']['visitors_excluded_roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Excluded Roles'),
'#options' => $roles,
'#default_value' => variable_get('visitors_excluded_roles', []),
);
$form = array();
$form['visitors_statistics']['visitors_lines_per_page'] = array(
$form['visitors_lines_per_page'] = array(
'#type' => 'select',
'#title' => 'Lines per page',
'#default_value' => variable_get('visitors_lines_per_page', 10),
@@ -79,7 +54,7 @@ function visitors_admin_settings() {
);
$period[0] = t('Never');
$form['visitors_statistics']['visitors_flush_log_timer'] = array(
$form['visitors_flush_log_timer'] = array(
'#type' => 'select',
'#title' => t('Discard visitors logs older than'),
'#default_value' => variable_get('visitors_flush_log_timer', 0),
@@ -90,44 +65,146 @@ function visitors_admin_settings() {
),
);
$installed = array_filter(list_themes(), function ($obj) {
return $obj->status;
});
$themes = array('_admin' => t('admin'), '_default' => t('default')) + array_map(function ($value) {
return $value->name;
}, $installed);
$form['visitors_theme'] = array(
'#title' => t('Theme'),
'#description' => t('Select a theme for the Visitors reports.'),
'#type' => 'select',
'#options' => $themes,
'#default_value' => variable_get('visitors_theme', '_admin'),
);
$default_role_options = [];
foreach (user_roles() as $role) {
$default_role_options[$role] = ucwords($role);
}
$form['visibility_title'] = array(
'#type' => 'item',
'#title' => t('Logging settings'),
);
$form['logging'] = array(
'#type' => 'vertical_tabs',
'#weight' => 20,
'#attached' => array(
'js' => array(drupal_get_path('module', 'visitors') . '/form.js'),
),
);
// Per-path visibility.
$form['logging']['path'] = array(
'#type' => 'fieldset',
'#title' => t('Pages'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'visibility',
'#weight' => 0,
);
$access = user_access('use PHP for settings');
if (isset($block->visibility) && $block->visibility == VISITORS_VISIBILITY_PHP && !$access) {
$form['logging']['path']['visitors_visibility_pages'] = array(
'#type' => 'value',
'#value' => VISITORS_VISIBILITY_PHP,
);
$form['logging']['path']['visitors_excluded_pages'] = array(
'#type' => 'value',
'#value' => isset($block->pages) ? $block->pages : '',
);
}
else {
$options = array(
VISITORS_VISIBILITY_NOTLISTED => t('All pages except those listed'),
VISITORS_VISIBILITY_LISTED => t('Only the listed pages'),
);
$description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
if (module_exists('php') && $access) {
$options += array(VISITORS_VISIBILITY_PHP => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'));
$title = t('Pages or PHP code');
$description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '<?php ?>'));
}
else {
$title = t('Pages');
}
$form['logging']['path']['visitors_visibility_pages'] = array(
'#type' => 'radios',
'#title' => t('Log visits on specific pages'),
'#options' => $options,
'#default_value' => variable_get('visitors_visibility_pages', VISITORS_VISIBILITY_NOTLISTED),
);
$form['logging']['path']['visitors_excluded_pages'] = array(
'#type' => 'textarea',
'#title' => '<span class="element-invisible">' . $title . '</span>',
'#default_value' => variable_get('visitors_excluded_pages', ''),
'#description' => $description,
);
}
$role_options = array_map('check_plain', user_roles());
$form['logging']['role'] = array(
'#type' => 'fieldset',
'#title' => t('Roles'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'visibility',
'#weight' => 10,
);
$form['logging']['role']['visitors_excluded_roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Show block for specific roles'),
'#default_value' => variable_get('visitors_excluded_roles', []),
'#options' => $default_role_options,
'#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
);
// Per-user visibility.
$form['logging']['user'] = array(
'#type' => 'fieldset',
'#title' => t('Users'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'visibility',
'#weight' => 20,
);
$form['logging']['user']['visitors_exclude_user1'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude user1 from statistics'),
'#default_value' => variable_get('visitors_exclude_user1', 0),
'#description' => t('Exclude hits of user1 from statistics.'),
);
// Chart settings.
$form['visitors_chart_settings'] = array(
$form['chart'] = array(
'#type' => 'fieldset',
'#title' => t('Chart settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'visibility',
'#weight' => 30,
'#description' => t('Visitors chart settings'),
);
$form['visitors_chart_settings']['visitors_chart_width'] = array(
$form['chart']['visitors_chart_width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => variable_get('visitors_chart_width', 700),
'#description' => t('Chart width.'),
);
$form['visitors_chart_settings']['visitors_chart_height'] = array(
$form['chart']['visitors_chart_height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => variable_get('visitors_chart_height', 430),
'#description' => t('Chart height.'),
);
$installed = array_filter(list_themes(), function ($obj) {
return $obj->status;
});
$themes = array('_admin' => t('admin'), '_default' => t('default')) + array_map(function ($value) {
return $value->name;
}, $installed);
$form['visitors_theme'] = array(
'#title' => t('Theme'),
'#description' => t('Select a theme for the Visitors reports.'),
'#type' => 'select',
'#options' => $themes,
'#default_value' => variable_get('visitors_theme', '_admin'),
);
return system_settings_form($form);
}
Loading