View source
<?php
define('BRB_TITLE', t('Your browser is not supported on this site'));
define('BRB_BODY_DEFAULT', '<h2>' . t('Sorry but it seems like your browser is a little bit old.') . '</h2>' . '<h4>' . t('We strongly recommend you to upgrade it or download one of the following:') . '</h4>');
define('BRB_IE_CONDITIONAL_DEFAULT', 'lte IE 7');
function brb_help($path, $arg) {
$output = '';
switch ($path) {
case "admin/help#brb":
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Browser Bouncer (BrB) module displays a message to users informing them that their browser is not supported. For more information, see the online handbook entry for <a href="@brb">Browser Bouncer (BrB)</a>.', array(
'@brb' => 'http://drupal.org/handbook/modules/brb',
)) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Prompting users to upgrade their browser') . '</dt>';
$output .= '<dd>' . t('When the module is enabled, anyone using a browser that is included in the "not supported" list will see a warning message on the site.') . '</dd>';
$output .= '<dt>' . t('Administering the module') . '</dt>';
$output .= '<dd>' . t('The <a href="@settings">settings page</a> allows you to change: the blocked browsers, displayed text, overlay, and the list of alternative browsers.', array(
'@settings' => url('admin/config/brb'),
)) . '</dd>';
$output .= '<dt>' . t('User permissions') . '</dt>';
$output .= '<dd>' . t('The Browser Bouncer (BrB) module makes a number of permissions available for administration and browsing without the warning message, which can be set by role on the <a href="@permissions">permissions page</a>.', array(
'@permissions' => url('admin/settings/permissions'),
)) . '</dd>';
$output .= '</dl>';
}
return $output;
}
function brb_permission() {
return array(
'browse without warning' => array(
'title' => t('Browse without warning'),
'description' => t('If selected the warning message will not be displayed.'),
),
'administer brb' => array(
'title' => t('Administer BrB'),
'description' => t('Perform administration tasks for Browser Bouncer (BrB)'),
),
);
}
function brb_menu() {
$items = array();
$items['admin/config/brb'] = array(
'title' => 'Browser Bouncer',
'description' => 'Modify this settings for a better fit with your design. Remember you can also style the module by CSS.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'brb_admin_settings',
),
'access arguments' => array(
'administer brb',
),
'file' => 'brb.admin.inc',
);
return $items;
}
function brb_theme() {
$items = array();
$items['brb_widget'] = array(
'variables' => array(
'body' => NULL,
'browsers' => NULL,
),
'template' => 'brb-widget',
);
$items['brb_admin_settings'] = array(
'render element' => 'form',
);
return $items;
}
function brb_preprocess_page(&$variables) {
global $user;
if (user_access('browse without warning', $user) == FALSE) {
drupal_add_library('system', 'ui.dialog');
$module_path = drupal_get_path('module', 'brb');
drupal_add_css($module_path . '/brb.css', array(
'type' => 'file',
'weight' => CSS_DEFAULT,
'browsers' => array(
'IE' => variable_get('brb_ie_conditional', BRB_IE_CONDITIONAL_DEFAULT),
'!IE' => FALSE,
),
));
}
}
function brb_init() {
drupal_add_js(array(
'brb' => NULL,
), 'setting');
}
function brb_process_html(&$variables) {
global $user;
if (user_access('browse without warning', $user) == FALSE) {
$module_path = drupal_get_path('module', 'brb');
$clean_widget = str_replace(array(
"\r\n",
"\n",
"\r",
'"',
), array(
"",
"",
"",
'\\"',
), brb_widget());
global $base_path;
$variables['scripts'] .= '
<!--[if ' . variable_get('brb_ie_conditional', BRB_IE_CONDITIONAL_DEFAULT) . ']>
<script type="text/javascript">
var brb = {
overlay: ' . strtolower(variable_get('brb_overlay', TRUE)) . ',
title: "' . variable_get('brb_title', BRB_TITLE) . '",
widget: "' . $clean_widget . '"
};
</script>
<script type="text/javascript" src="' . $base_path . $module_path . '/brb.js"></script>
<![endif]-->
';
}
}
function brb_widget() {
$body = variable_get('brb_body', 'Sorry but your browser is not supported.');
$browsers = variable_get('brb_browsers', array());
uasort($browsers, 'brb_cmp');
$ok_browsers = array();
foreach ($browsers as $browser) {
if (!$browser->exclude) {
$ok_browsers[] = array(
"id" => 'brb-' . drupal_strtolower(str_replace(' ', '-', $browser->name)),
"name" => $browser->name,
'url' => $browser->url,
"attributes" => array(
'class' => 'brb-browser',
'title' => $browser->name,
),
);
}
}
return theme('brb_widget', array(
'body' => $body,
'browsers' => $ok_browsers,
));
}
function brb_cmp($a, $b) {
if ($a->weight == $b->weight) {
return 0;
}
return $a->weight < $b->weight ? -1 : 1;
}