timezone_detect.install in Timezone Detect 7
Same filename and directory in other branches
(Un)installs the Timezone Detect module.
File
timezone_detect.installView source
<?php
/**
* @file
* (Un)installs the Timezone Detect module.
*/
/**
* Load constants.
*/
require_once 'timezone_detect.constants.inc';
/**
* Implements hook_enable().
*/
function timezone_detect_enable() {
drupal_set_message(t('The Timezone Detect module was successfully enabled.'), 'status');
// Set default user timezone to "none." Otherwise this module will not do
// anything in its default configuration ("set user timezone only if it
// is not set").
$user_default_timezone = variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT);
if ($user_default_timezone != DRUPAL_USER_TIMEZONE_EMPTY) {
variable_set('user_default_timezone', DRUPAL_USER_TIMEZONE_EMPTY);
drupal_set_message(t('Default user timezone set to "empty timezone" for best results with Timezone Detect.'), 'status');
}
// Disable "remind users at login if their time zone is not set." Otherwise
// users may be asked to set their timezone on first login even when this
// module has already set it via ajax callback.
$empty_timezone_message = variable_get('empty_timezone_message', 0);
if ($empty_timezone_message != 0) {
variable_set('empty_timezone_message', 0);
drupal_set_message(t('"Remind users at login if their time zone is not set" set to FALSE for best results with Timezone Detect.'), 'status');
}
}
/**
* Implements hook_requirements().
*/
function timezone_detect_requirements($phase) {
$requirements = array();
$t = get_t();
// Check that default user timezone is set to "empty timezone", or that
// Timezone Detect is configured to update user timezone on every login
// (otherwise automatic timezone detection will not work).
$default_timezone_okay = FALSE;
$user_default_timezone = variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT);
$timezone_update_mode = variable_get('timezone_detect_mode');
if ($timezone_update_mode != TIMEZONE_DETECT_MODE_DEFAULT || $user_default_timezone == DRUPAL_USER_TIMEZONE_EMPTY) {
$default_timezone_okay = TRUE;
}
switch ($phase) {
case 'runtime':
if (!$default_timezone_okay) {
$requirements['timezone_detect'] = array(
'title' => $t('Timezone Detect'),
'value' => $t('Incompatible default user timezone'),
'description' => $t('For automatic timezone detection to work correctly, please change default user timezone to "empty timezone" on your site\'s !regional_settings_url.', array(
'!regional_settings_url' => l($t('regional settings page'), 'admin/config/regional/settings'),
)),
'severity' => REQUIREMENT_ERROR,
);
}
break;
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function timezone_detect_uninstall() {
variable_del('timezone_detect_mode');
}
/**
* Migrate variable used for saving timezone detection mode.
*/
function timezone_detect_update_7100() {
$current_mode = variable_get('timezone_detect_update_timezone_every_login', TIMEZONE_DETECT_MODE_DEFAULT);
variable_set('timezone_detect_mode', $current_mode);
variable_del('timezone_detect_update_timezone_every_login');
}
Functions
Name | Description |
---|---|
timezone_detect_enable | Implements hook_enable(). |
timezone_detect_requirements | Implements hook_requirements(). |
timezone_detect_uninstall | Implements hook_uninstall(). |
timezone_detect_update_7100 | Migrate variable used for saving timezone detection mode. |