more module updates
This commit is contained in:
@@ -8,32 +8,31 @@
|
||||
* Implements hook_form().
|
||||
*/
|
||||
function browscap_settings_form($form, &$form_state) {
|
||||
// Check the local browscap data version number
|
||||
// Check the local browscap data version number.
|
||||
$version = variable_get('browscap_version', 0);
|
||||
|
||||
// If the version number is 0 then browscap data has never been fetched
|
||||
// If the version number is 0 then browscap data has never been fetched.
|
||||
if ($version == 0) {
|
||||
$version = t('Never fetched');
|
||||
}
|
||||
|
||||
$form['data'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('User agent detection settings'),
|
||||
);
|
||||
$form['data']['browscap_data_version'] = array(
|
||||
$form['browscap_data_version'] = array(
|
||||
'#markup' => '<p>' . t('Current browscap data version: %fileversion.', array('%fileversion' => $version)) . '</p>',
|
||||
);
|
||||
$form['data']['browscap_enable_automatic_updates'] = array(
|
||||
$form['browscap_enable_automatic_updates'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable automatic updates'),
|
||||
'#default_value' => variable_get('browscap_enable_automatic_updates', TRUE),
|
||||
'#description' => t('Automatically update the user agent detection information.'),
|
||||
);
|
||||
$form['data']['browscap_automatic_updates_timer'] = array(
|
||||
$form['browscap_automatic_updates_timer'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Check for new user agent detection information every'),
|
||||
'#default_value' => variable_get('browscap_automatic_updates_timer', 604800),
|
||||
'#options' => drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'),
|
||||
'#options' => drupal_map_assoc(array(
|
||||
3600, 10800, 21600, 32400, 43200, 86400, 172800,
|
||||
259200, 604800, 1209600, 2419200, 4838400, 9676800),
|
||||
'format_interval'),
|
||||
'#description' => t('Newer user agent detection information will be automatically downloaded and installed. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
@@ -55,9 +54,9 @@ function browscap_settings_form($form, &$form_state) {
|
||||
* Submit handler for the refresh browscap button.
|
||||
*/
|
||||
function browscap_refresh_submit($form, &$form_state) {
|
||||
// Update the browscap information
|
||||
// Update the browscap information.
|
||||
_browscap_import(FALSE);
|
||||
|
||||
// Record when the browscap information was updated
|
||||
// Record when the browscap information was updated.
|
||||
variable_set('browscap_imported', REQUEST_TIME);
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@ description = Provides a replacement for PHPs get_browser() function.
|
||||
core = 7.x
|
||||
configure = admin/config/system/browscap
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-22
|
||||
version = "7.x-2.0"
|
||||
; Information added by Drupal.org packaging script on 2014-07-09
|
||||
version = "7.x-2.2"
|
||||
core = "7.x"
|
||||
project = "browscap"
|
||||
datestamp = "1353586510"
|
||||
datestamp = "1404915228"
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function browscap_schema() {
|
||||
$schema['browscap'] = array(
|
||||
@@ -32,10 +32,10 @@ function browscap_schema() {
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function browscap_install() {
|
||||
// Update the browscap information
|
||||
// Update the browscap information.
|
||||
_browscap_import();
|
||||
|
||||
// Record when the browscap information was updated
|
||||
// Record when the browscap information was updated.
|
||||
variable_set('browscap_imported', REQUEST_TIME);
|
||||
}
|
||||
|
||||
@@ -48,3 +48,10 @@ function browscap_uninstall() {
|
||||
variable_del('browscap_enable_automatic_updates');
|
||||
variable_del('browscap_automatic_updates_timer');
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop the unused Browscap 1.x statistics table.
|
||||
*/
|
||||
function browscap_update_7200() {
|
||||
db_drop_table('browscap_statistics');
|
||||
}
|
||||
|
@@ -4,8 +4,8 @@
|
||||
* Replacement for PHP's get_browser() function.
|
||||
*/
|
||||
|
||||
// Include browscap data import and user agent recording functions
|
||||
include_once('import.inc');
|
||||
// Include browscap data import and user agent recording functions.
|
||||
include_once 'import.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
@@ -24,7 +24,7 @@ function browscap_permission() {
|
||||
function browscap_menu() {
|
||||
$items['admin/config/system/browscap'] = array(
|
||||
'title' => 'Browscap',
|
||||
'description' => 'Configure user agent monitoring and browscap information settings.',
|
||||
'description' => 'View the current browscap data version and configure automatic update settings.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('browscap_settings_form'),
|
||||
'access arguments' => array('administer browscap'),
|
||||
@@ -40,7 +40,7 @@ function browscap_menu() {
|
||||
function browscap_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/config/system/browscap':
|
||||
return '<p>' . t('Settings for user agent detection and the log that Browscap will keep about user agents that visit the site. See <a href="@statistics">user agent statistics</a> for the actual information.', array('@statistics' => url('admin/reports/browscap'))) . '</p>';
|
||||
return '<p>' . t('View the current browscap data version and configure automatic update settings.') . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,19 +49,19 @@ function browscap_help($path, $arg) {
|
||||
*/
|
||||
function browscap_cron() {
|
||||
if (variable_get('browscap_enable_automatic_updates', TRUE) == TRUE) {
|
||||
// Check the current update timer
|
||||
// Check the current update timer.
|
||||
$automatic_update_timer = variable_get('browscap_automatic_updates_timer', 604800);
|
||||
|
||||
// Check when the last update occurred
|
||||
// Check when the last update occurred.
|
||||
$last_imported = variable_get('browscap_imported', REQUEST_TIME);
|
||||
|
||||
// Update the browscap data if the amount of time specified by the update
|
||||
// timer has passed
|
||||
// timer has passed.
|
||||
if (($last_imported + $automatic_update_timer) < REQUEST_TIME) {
|
||||
// Update the browscap information
|
||||
// Update the browscap information.
|
||||
_browscap_import();
|
||||
|
||||
// Record when the browscap information was updated
|
||||
// Record when the browscap information was updated.
|
||||
variable_set('browscap_imported', REQUEST_TIME);
|
||||
}
|
||||
}
|
||||
@@ -71,12 +71,14 @@ function browscap_cron() {
|
||||
* Provide data about a user agent string or the current user agent.
|
||||
*
|
||||
* @param string $user_agent
|
||||
* Optional user agent string to test. If empty, use the value from the current request.
|
||||
* Optional user agent string to test. If empty, use the value from the
|
||||
* current request.
|
||||
*
|
||||
* @return array
|
||||
* An array of information about the user agent.
|
||||
*/
|
||||
function browscap_get_browser($user_agent = NULL) {
|
||||
// Determine the current user agent if a user agent was not specified
|
||||
// Determine the current user agent if a user agent was not specified.
|
||||
if ($user_agent != NULL) {
|
||||
$user_agent = check_plain(trim($user_agent));
|
||||
}
|
||||
@@ -87,40 +89,40 @@ function browscap_get_browser($user_agent = NULL) {
|
||||
$user_agent = 'Default Browser';
|
||||
}
|
||||
|
||||
// Check the cache for user agent data
|
||||
// Check the cache for user agent data.
|
||||
$cache = cache_get($user_agent, 'cache_browscap');
|
||||
|
||||
// Attempt to find a cached user agent
|
||||
// Otherwise store the user agent data in the cache
|
||||
// Attempt to find a cached user agent.
|
||||
// Otherwise store the user agent data in the cache.
|
||||
if (!empty($cache) && ($cache->created > REQUEST_TIME - 60 * 60 * 24)) {
|
||||
$user_agent_properties = $cache->data;
|
||||
}
|
||||
else {
|
||||
// Find the user agent's properties
|
||||
// Find the user agent's properties.
|
||||
// The useragent column contains the wildcarded pattern to match against our
|
||||
// full-length string while the ORDER BY chooses the most-specific matching
|
||||
// pattern
|
||||
// pattern.
|
||||
$user_agent_properties = db_query("SELECT * FROM {browscap} WHERE :useragent LIKE useragent ORDER BY LENGTH(useragent) DESC", array(':useragent' => $user_agent))
|
||||
->fetchObject();
|
||||
|
||||
// Store user agent data in the cache
|
||||
// Store user agent data in the cache.
|
||||
cache_set($user_agent, $user_agent_properties, 'cache_browscap');
|
||||
}
|
||||
|
||||
// Create an array to hold the user agent's properties
|
||||
// Create an array to hold the user agent's properties.
|
||||
$properties = array();
|
||||
|
||||
// Return an array of user agent properties
|
||||
// Return an array of user agent properties.
|
||||
if (isset($user_agent_properties) && isset($user_agent_properties->data)) {
|
||||
// Unserialize the user agent data found in the cache or the database
|
||||
// Unserialize the user agent data found in the cache or the database.
|
||||
$properties = unserialize($user_agent_properties->data);
|
||||
|
||||
// Set the user agent name and name pattern
|
||||
// Set the user agent name and name pattern.
|
||||
$properties['useragent'] = $user_agent;
|
||||
$properties['browser_name_pattern'] = strtr($user_agent_properties->useragent, '%_', '*?');
|
||||
}
|
||||
else {
|
||||
// Set the user agent name and name pattern to 'unrecognized'
|
||||
// Set the user agent name and name pattern to 'unrecognized'.
|
||||
$properties['useragent'] = 'unrecognized';
|
||||
$properties['browser_name_pattern'] = strtr('unrecognized', '%_', '*?');
|
||||
}
|
||||
|
@@ -7,22 +7,23 @@
|
||||
/**
|
||||
* Helper function to update the browscap data.
|
||||
*
|
||||
* @param boolean $cron
|
||||
* Optional import environment. If false, display status messages to the user in addition to logging information with the watchdog.
|
||||
* @param bool $cron
|
||||
* Optional import environment. If false, display status messages to the user
|
||||
* in addition to logging information with the watchdog.
|
||||
*/
|
||||
function _browscap_import($cron = TRUE) {
|
||||
// Check the local browscap data version number
|
||||
// Check the local browscap data version number.
|
||||
$local_version = variable_get('browscap_version', 0);
|
||||
|
||||
// Retrieve the current browscap data version number using HTTP
|
||||
$current_version = drupal_http_request('http://tempdownloads.browserscap.com/versions/version-number.php');
|
||||
// Retrieve the current browscap data version number using HTTP.
|
||||
$current_version = drupal_http_request('http://www.browscap.org/version-number');
|
||||
|
||||
// Log an error if the browscap version number could not be retrieved
|
||||
// Log an error if the browscap version number could not be retrieved.
|
||||
if (isset($current_version->error)) {
|
||||
// Log a message with the watchdog
|
||||
// Log a message with the watchdog.
|
||||
watchdog('browscap', "Couldn't check version: %error", array('%error' => $current_version->error), WATCHDOG_ERROR);
|
||||
|
||||
// Display a message to the user if the update process was triggered manually
|
||||
// Display a message to user if the update process was triggered manually.
|
||||
if ($cron == FALSE) {
|
||||
drupal_set_message(t("Couldn't check version: %error", array('%error' => $current_version->error)), 'error');
|
||||
}
|
||||
@@ -30,16 +31,16 @@ function _browscap_import($cron = TRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Sanitize the returned version number
|
||||
// Sanitize the returned version number.
|
||||
$current_version = check_plain(trim($current_version->data));
|
||||
|
||||
// Compare the current and local version numbers to determine if the browscap
|
||||
// data requires updating
|
||||
// data requires updating.
|
||||
if ($current_version == $local_version) {
|
||||
// Log a message with the watchdog
|
||||
// Log a message with the watchdog.
|
||||
watchdog('browscap', 'No new version of browscap to import');
|
||||
|
||||
// Display a message to the user if the update process was triggered manually
|
||||
// Display a message to user if the update process was triggered manually.
|
||||
if ($cron == FALSE) {
|
||||
drupal_set_message(t('No new version of browscap to import'));
|
||||
}
|
||||
@@ -47,15 +48,27 @@ function _browscap_import($cron = TRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve the browscap data using HTTP
|
||||
$browscap_data = drupal_http_request('http://tempdownloads.browserscap.com/stream.php?BrowsCapINI');
|
||||
// Set options for downloading data with or without compression.
|
||||
if (function_exists('gzdecode')) {
|
||||
$options = array(
|
||||
'headers' => array('Accept-Encoding' => 'gzip'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
// The download takes over ten times longer without gzip, and may exceed
|
||||
// the default timeout of 30 seconds, so we increase the timeout.
|
||||
$options = array('timeout' => 600);
|
||||
}
|
||||
|
||||
// Log an error if the browscap data could not be retrieved
|
||||
// Retrieve the browscap data using HTTP.
|
||||
$browscap_data = drupal_http_request('http://www.browscap.org/stream?q=PHP_BrowsCapINI', $options);
|
||||
|
||||
// Log an error if the browscap data could not be retrieved.
|
||||
if (isset($browscap_data->error) || empty($browscap_data)) {
|
||||
// Log a message with the watchdog
|
||||
// Log a message with the watchdog.
|
||||
watchdog('browscap', "Couldn't retrieve updated browscap: %error", array('%error' => $browscap_data->error), WATCHDOG_ERROR);
|
||||
|
||||
// Display a message to the user if the update process was triggered manually
|
||||
// Display a message to user if the update process was triggered manually.
|
||||
if ($cron == FALSE) {
|
||||
drupal_set_message(t("Couldn't retrieve updated browscap: %error", array('%error' => $browscap_data->error)), 'error');
|
||||
}
|
||||
@@ -63,83 +76,98 @@ function _browscap_import($cron = TRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the returned browscap data
|
||||
// The parse_ini_string function is preferred but only available in PHP 5.3.0
|
||||
// Decompress the downloaded data if it is compressed.
|
||||
if (function_exists('gzdecode')) {
|
||||
$browscap_data->data = gzdecode($browscap_data->data);
|
||||
}
|
||||
|
||||
// Parse the returned browscap data.
|
||||
// The parse_ini_string function is preferred but only available in PHP 5.3.0.
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
|
||||
// Retrieve the browscap data
|
||||
// Retrieve the browscap data.
|
||||
$browscap_data = $browscap_data->data;
|
||||
|
||||
// Replace 'true' and 'false' with '1' and '0'
|
||||
$browscap_data = strtr($browscap_data, array("=true\r" => "=1\r", "=false\r" => "=0\r"));
|
||||
$browscap_data = preg_replace(
|
||||
array(
|
||||
"/=\s*true\s*\n/",
|
||||
"/=\s*false\s*\n/",
|
||||
),
|
||||
array(
|
||||
"=1\n",
|
||||
"=0\n",
|
||||
),
|
||||
$browscap_data
|
||||
);
|
||||
|
||||
// Parse the browscap data as a string
|
||||
// Parse the browscap data as a string.
|
||||
$browscap_data = parse_ini_string($browscap_data, TRUE, INI_SCANNER_RAW);
|
||||
}
|
||||
else {
|
||||
// Create a path and filename
|
||||
// Create a path and filename.
|
||||
$server = $_SERVER['SERVER_NAME'];
|
||||
$path = variable_get('file_temporary_path', '/tmp');
|
||||
$file = "$path/browscap_$server.ini";
|
||||
|
||||
// Write the browscap data to a file
|
||||
// Write the browscap data to a file.
|
||||
$browscap_file = fopen($file, "w");
|
||||
fwrite($browscap_file, $browscap_data->data);
|
||||
fclose($browscap_file);
|
||||
|
||||
// Parse the browscap data as a file
|
||||
// Parse the browscap data as a file.
|
||||
$browscap_data = parse_ini_file($file, TRUE);
|
||||
}
|
||||
|
||||
if ($browscap_data) {
|
||||
// Find the version information
|
||||
// The version information is the first entry in the array
|
||||
// Find the version information.
|
||||
// The version information is the first entry in the array.
|
||||
$version = array_shift($browscap_data);
|
||||
|
||||
// Store the data available for each user agent
|
||||
// Store the data available for each user agent.
|
||||
foreach ($browscap_data as $key => $values) {
|
||||
// Store the current value
|
||||
// Store the current value.
|
||||
$e = $values;
|
||||
|
||||
// Create an array to hold the last parent
|
||||
// Create an array to hold the last parent.
|
||||
$last_parent = array();
|
||||
|
||||
// Recurse through the available user agent information
|
||||
// Recurse through the available user agent information.
|
||||
while (isset($values['Parent']) && $values['Parent'] !== $last_parent) {
|
||||
$values = isset($browscap_data[$values['Parent']]) ? $browscap_data[$values['Parent']] : array();
|
||||
$e = array_merge($values, $e);
|
||||
$last_parent = $values;
|
||||
}
|
||||
|
||||
// Replace '*?' with '%_'
|
||||
// Replace '*?' with '%_'.
|
||||
$user_agent = strtr($key, '*?', '%_');
|
||||
|
||||
// Change all array keys to lowercase
|
||||
// Change all array keys to lowercase.
|
||||
$e = array_change_key_case($e);
|
||||
|
||||
// Delete all data about the current user agent from the database
|
||||
// Delete all data about the current user agent from the database.
|
||||
db_delete('browscap')
|
||||
->condition('useragent', $user_agent)
|
||||
->execute();
|
||||
|
||||
// Insert all data about the current user agent into the database
|
||||
// Insert all data about the current user agent into the database.
|
||||
db_insert('browscap')
|
||||
->fields(array(
|
||||
'useragent' => $user_agent,
|
||||
'data' => serialize($e)
|
||||
'data' => serialize($e),
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
|
||||
// Clear the browscap data cache
|
||||
// Clear the browscap data cache.
|
||||
cache_clear_all('*', 'cache_browscap', TRUE);
|
||||
|
||||
// Update the browscap version
|
||||
// Update the browscap version.
|
||||
variable_set('browscap_version', $current_version);
|
||||
|
||||
// Log a message with the watchdog
|
||||
// Log a message with the watchdog.
|
||||
watchdog('browscap', 'New version of browscap imported: %version', array('%version' => $current_version));
|
||||
|
||||
// Display a message to the user if the update process was triggered manually
|
||||
// Display a message to user if the update process was triggered manually.
|
||||
if ($cron == FALSE) {
|
||||
drupal_set_message(t('New version of browscap imported: %version', array('%version' => $current_version)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user