Now all modules are in core modules folder

This commit is contained in:
Manuel Cillero 2017-08-08 12:14:45 +02:00
parent 5ba1cdfa0b
commit 05b6a91b0c
1907 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,12 @@
name = Date Timezone
description = Needed when using Date API. Overrides site and user timezone handling to set timezone names instead of offsets.
package = Date/Time
dependencies[] = date_api
core = 6.x
; Information added by Drupal.org packaging script on 2014-03-31
version = "6.x-2.10"
core = "6.x"
project = "date"
datestamp = "1396284252"

View file

@ -0,0 +1,606 @@
<?php
/**
* @file
* Install file for Date Timezone.
*/
function date_timezone_install() {
$ret = array();
module_enable(array('date_api'));
if (version_compare(PHP_VERSION, '5.2', '<')) {
module_enable(array('date_php4'));
}
return $ret;
}
function date_timezone_enable() {
module_enable(array('date_api'));
if (version_compare(PHP_VERSION, '5.2', '<')) {
module_enable(array('date_php4'));
}
}
function date_timezone_module_uninstall() {
$ret = array();
variable_del('date_default_timezone_name');
return $ret;
}
/**
* @file
* Installation file for Date Timezone
*/
/**
* Implementation of hook_requirements().
* Make sure a site timezone name has been selected.
*/
function date_timezone_requirements($phase) {
$requirements = array();
$t = get_t();
$error = FALSE;
$value = array();
switch ($phase) {
case 'runtime':
$tz_name = variable_get('date_default_timezone_name', NULL);
if ($tz_name === NULL) {
$error = TRUE;
$severity = REQUIREMENT_ERROR;
$value = $t('The Date Timezone module requires you to !link.', array('!link' => l($t('set the site timezone name'), 'admin/settings/date-time')));
}
elseif (function_exists('date_create')) {
$date = date_make_date('now', $tz_name);
if (date_offset_get($date) != variable_get('date_default_timezone', 0)) {
$error = TRUE;
$value = $t('The !link may not be correct.', array('!link' => l($t('site timezone name'), 'admin/settings/date-time')));
$severity = REQUIREMENT_WARNING;
}
}
}
if ($error) {
$requirements['date_default_timezone'] = array(
'title' => $t('Date Timezone requirements'),
'value' => $value,
'severity' => $severity,
);
}
return $requirements;
}
/**
* Get rid of deprecated timezone names.
*/
function date_timezone_update_5200() {
$ret = array();
$old = variable_get('date_default_timezone_name', NULL);
if (!empty($old)) {
$new = _date_timezone_replacement($old);
if (!empty($new) && $new != $old) {
variable_set('date_default_timezone_name', $new);
}
}
$results = db_query("SELECT DISTINCT timezone_name FROM {users} ORDER BY timezone_name");
while ($row = db_fetch_object($results)) {
if (!empty($row->timezone_name)) {
$new = _date_timezone_replacement($row->timezone_name);
if (!empty($new) && $new != $row->timezone_name) {
db_query("UPDATE {users} SET timezone_name = '%s' WHERE timezone_name = '%s'", $new, $row->timezone_name);
}
}
}
// Make sure the timezone name list gets updated.
cache_clear_all('date_timezone_identifiers_list', 'cache');
return $ret;
}
/**
* Create replacement values for deprecated timezone names.
*/
function _date_timezone_replacement($old) {
$replace = array(
'Brazil/Acre' => 'America/Rio_Branco',
'Brazil/DeNoronha' => 'America/Noronha',
'Brazil/East' => 'America/Recife',
'Brazil/West' => 'America/Manaus',
'Canada/Atlantic' => 'America/Halifax',
'Canada/Central' => 'America/Winnipeg',
'Canada/East-Saskatchewan' => 'America/Regina',
'Canada/Eastern' => 'America/Toronto',
'Canada/Mountain' => 'America/Edmonton',
'Canada/Newfoundland' => 'America/St_Johns',
'Canada/Pacific' => 'America/Vancouver',
'Canada/Saskatchewan' => 'America/Regina',
'Canada/Yukon' => 'America/Whitehorse',
'CET' => 'Europe/Berlin',
'Chile/Continental' => 'America/Santiago',
'Chile/EasterIsland' => 'Pacific/Easter',
'CST6CDT' => 'America/Chicago',
'Cuba' => 'America/Havana',
'EET' => 'Europe/Bucharest',
'Egypt' => 'Africa/Cairo',
'Eire' => 'Europe/Belfast',
'EST' => 'America/New_York',
'EST5EDT' => 'America/New_York',
'GB' => 'Europe/London',
'GB-Eire' => 'Europe/Belfast',
'Etc/GMT' => 'UTC',
'Etc/GMT+0' => 'UTC',
'Etc/GMT+1' => 'UTC',
'Etc/GMT+10' => 'UTC',
'Etc/GMT+11' => 'UTC',
'Etc/GMT+12' => 'UTC',
'Etc/GMT+2' => 'UTC',
'Etc/GMT+3' => 'UTC',
'Etc/GMT+4' => 'UTC',
'Etc/GMT+5' => 'UTC',
'Etc/GMT+6' => 'UTC',
'Etc/GMT+7' => 'UTC',
'Etc/GMT+8' => 'UTC',
'Etc/GMT+9' => 'UTC',
'Etc/GMT-0' => 'UTC',
'Etc/GMT-1' => 'UTC',
'Etc/GMT-10' => 'UTC',
'Etc/GMT-11' => 'UTC',
'Etc/GMT-12' => 'UTC',
'Etc/GMT-13' => 'UTC',
'Etc/GMT-14' => 'UTC',
'Etc/GMT-2' => 'UTC',
'Etc/GMT-3' => 'UTC',
'Etc/GMT-4' => 'UTC',
'Etc/GMT-5' => 'UTC',
'Etc/GMT-6' => 'UTC',
'Etc/GMT-7' => 'UTC',
'Etc/GMT-8' => 'UTC',
'Etc/GMT-9' => 'UTC',
'Etc/GMT0' => 'UTC',
'Etc/Greenwich' => 'UTC',
'Etc/UCT' => 'UTC',
'Etc/Universal' => 'UTC',
'Etc/UTC' => 'UTC',
'Etc/Zulu' => 'UTC',
'Factory' => 'UTC',
'GMT' => 'UTC',
'GMT+0' => 'UTC',
'GMT-0' => 'UTC',
'GMT0' => 'UTC',
'Hongkong' => 'Asia/Hong_Kong',
'HST' => 'Pacific/Honolulu',
'Iceland' => 'Atlantic/Reykjavik',
'Iran' => 'Asia/Tehran',
'Israel' => 'Asia/Tel_Aviv',
'Jamaica' => 'America/Jamaica',
'Japan' => 'Asia/Tokyo',
'Kwajalein' => 'Pacific/Kwajalein',
'Libya' => 'Africa/Tunis',
'MET' => 'Europe/Budapest',
'Mexico/BajaNorte' => 'America/Tijuana',
'Mexico/BajaSur' => 'America/Mazatlan',
'Mexico/General' => 'America/Mexico_City',
'MST' => 'America/Boise',
'MST7MDT' => 'America/Boise',
'Navajo' => 'America/Phoenix',
'NZ' => 'Pacific/Auckland',
'NZ-CHAT' => 'Pacific/Chatham',
'Poland' => 'Europe/Warsaw',
'Portugal' => 'Europe/Lisbon',
'PRC' => 'Asia/Chongqing',
'PST8PDT' => 'America/Los_Angeles',
'ROC' => 'Asia/Taipei',
'ROK' => 'Asia/Seoul',
'Singapore' => 'Asia/Singapore',
'Turkey' => 'Europe/Istanbul',
'US/Alaska' => 'America/Anchorage',
'US/Aleutian' => 'America/Adak',
'US/Arizona' => 'America/Phoenix',
'US/Central' => 'America/Chicago',
'US/East-Indiana' => 'America/Indianapolis',
'US/Eastern' => 'America/New_York',
'US/Hawaii' => 'Pacific/Honolulu',
'US/Indiana-Starke' => 'America/Indiana/Knox',
'US/Michigan' => 'America/Detroit',
'US/Mountain' => 'America/Boise',
'US/Pacific' => 'America/Los_Angeles',
'US/Pacific-New' => 'America/Los_Angeles',
'US/Samoa' => 'Pacific/Samoa',
'W-SU' => 'Europe/Moscow',
'WET' => 'Europe/Paris',
);
if (array_key_exists($old, $replace)) {
return $replace[$old];
}
else {
return $old;
}
}
/**
* These strings exist only for the extractor to pick them up and make them
* available for translation. Putting them here keeps them from being parsed
* on normal pages.
*
* Idea borrowed from Event module. Thanks killes!
*/
function date_timezone_translate() {
t('Africa/Algiers');
t('Africa/Asmera');
t('Africa/Bangui');
t('Africa/Blantyre');
t('Africa/Brazzaville');
t('Africa/Bujumbura');
t('Africa/Cairo');
t('Africa/Ceuta');
t('Africa/Dar_es_Salaam');
t('Africa/Djibouti');
t('Africa/Douala');
t('Africa/Gaborone');
t('Africa/Harare');
t('Africa/Johannesburg');
t('Africa/Kampala');
t('Africa/Khartoum');
t('Africa/Kigali');
t('Africa/Kinshasa');
t('Africa/Lagos');
t('Africa/Libreville');
t('Africa/Luanda');
t('Africa/Lubumbashi');
t('Africa/Lusaka');
t('Africa/Malabo');
t('Africa/Maputo');
t('Africa/Maseru');
t('Africa/Mbabane');
t('Africa/Mogadishu');
t('Africa/Nairobi');
t('Africa/Ndjamena');
t('Africa/Niamey');
t('Africa/Porto-Novo');
t('Africa/Tripoli');
t('Africa/Tunis');
t('Africa/Windhoek');
t('America/Adak');
t('America/Anchorage');
t('America/Anguilla');
t('America/Antigua');
t('America/Araguaina');
t('America/Aruba');
t('America/Asuncion');
t('America/Atka');
t('America/Barbados');
t('America/Belem');
t('America/Belize');
t('America/Boa_Vista');
t('America/Bogota');
t('America/Boise');
t('America/Buenos_Aires');
t('America/Cambridge_Bay');
t('America/Cancun');
t('America/Caracas');
t('America/Catamarca');
t('America/Cayenne');
t('America/Cayman');
t('America/Chicago');
t('America/Chihuahua');
t('America/Cordoba');
t('America/Costa_Rica');
t('America/Cuiaba');
t('America/Curacao');
t('America/Dawson');
t('America/Dawson_Creek');
t('America/Denver');
t('America/Detroit');
t('America/Dominica');
t('America/Edmonton');
t('America/Eirunepe');
t('America/El_Salvador');
t('America/Ensenada');
t('America/Fort_Wayne');
t('America/Fortaleza');
t('America/Glace_Bay');
t('America/Godthab');
t('America/Goose_Bay');
t('America/Grand_Turk');
t('America/Grenada');
t('America/Guadeloupe');
t('America/Guatemala');
t('America/Guayaquil');
t('America/Guyana');
t('America/Halifax');
t('America/Havana');
t('America/Hermosillo');
t('America/Indiana/Indianapolis');
t('America/Indiana/Knox');
t('America/Indiana/Marengo');
t('America/Indiana/Vevay');
t('America/Indianapolis');
t('America/Inuvik');
t('America/Iqaluit');
t('America/Jamaica');
t('America/Jujuy');
t('America/Juneau');
t('America/Kentucky/Louisville');
t('America/Kentucky/Monticello');
t('America/Knox_IN');
t('America/La_Paz');
t('America/Lima');
t('America/Los_Angeles');
t('America/Louisville');
t('America/Maceio');
t('America/Managua');
t('America/Manaus');
t('America/Martinique');
t('America/Mazatlan');
t('America/Mendoza');
t('America/Menominee');
t('America/Merida');
t('America/Mexico_City');
t('America/Miquelon');
t('America/Monterrey');
t('America/Montevideo');
t('America/Montreal');
t('America/Montserrat');
t('America/Nassau');
t('America/New_York');
t('America/Nipigon');
t('America/Nome');
t('America/Noronha');
t('America/Panama');
t('America/Pangnirtung');
t('America/Paramaribo');
t('America/Phoenix');
t('America/Port-au-Prince');
t('America/Port_of_Spain');
t('America/Porto_Acre');
t('America/Porto_Velho');
t('America/Puerto_Rico');
t('America/Rainy_River');
t('America/Rankin_Inlet');
t('America/Recife');
t('America/Regina');
t('America/Rio_Branco');
t('America/Rosario');
t('America/Santiago');
t('America/Santo_Domingo');
t('America/Sao_Paulo');
t('America/Scoresbysund');
t('America/Shiprock');
t('America/St_Johns');
t('America/St_Kitts');
t('America/St_Lucia');
t('America/St_Thomas');
t('America/St_Vincent');
t('America/Swift_Current');
t('America/Tegucigalpa');
t('America/Thule');
t('America/Thunder_Bay');
t('America/Tijuana');
t('America/Tortola');
t('America/Vancouver');
t('America/Virgin');
t('America/Whitehorse');
t('America/Winnipeg');
t('America/Yakutat');
t('America/Yellowknife');
t('Antarctica/Casey');
t('Antarctica/Davis');
t('Antarctica/DumontDUrville');
t('Antarctica/Mawson');
t('Antarctica/McMurdo');
t('Antarctica/Palmer');
t('Antarctica/South_Pole');
t('Antarctica/Syowa');
t('Antarctica/Vostok');
t('Arctic/Longyearbyen');
t('Asia/Aden');
t('Asia/Almaty');
t('Asia/Amman');
t('Asia/Anadyr');
t('Asia/Aqtau');
t('Asia/Aqtobe');
t('Asia/Ashgabat');
t('Asia/Ashkhabad');
t('Asia/Baghdad');
t('Asia/Bahrain');
t('Asia/Baku');
t('Asia/Bangkok');
t('Asia/Beirut');
t('Asia/Bishkek');
t('Asia/Brunei');
t('Asia/Calcutta');
t('Asia/Chungking');
t('Asia/Colombo');
t('Asia/Dacca');
t('Asia/Damascus');
t('Asia/Dhaka');
t('Asia/Dili');
t('Asia/Dubai');
t('Asia/Dushanbe');
t('Asia/Gaza');
t('Asia/Harbin');
t('Asia/Hong_Kong');
t('Asia/Hovd');
t('Asia/Irkutsk');
t('Asia/Istanbul');
t('Asia/Jakarta');
t('Asia/Jayapura');
t('Asia/Jerusalem');
t('Asia/Kabul');
t('Asia/Kamchatka');
t('Asia/Karachi');
t('Asia/Kashgar');
t('Asia/Katmandu');
t('Asia/Krasnoyarsk');
t('Asia/Kuala_Lumpur');
t('Asia/Kuching');
t('Asia/Kuwait');
t('Asia/Macao');
t('Asia/Magadan');
t('Asia/Manila');
t('Asia/Muscat');
t('Asia/Nicosia');
t('Asia/Novosibirsk');
t('Asia/Omsk');
t('Asia/Phnom_Penh');
t('Asia/Pyongyang');
t('Asia/Qatar');
t('Asia/Rangoon');
t('Asia/Riyadh');
t('Asia/Riyadh87');
t('Asia/Riyadh88');
t('Asia/Riyadh89');
t('Asia/Saigon');
t('Asia/Samarkand');
t('Asia/Seoul');
t('Asia/Shanghai');
t('Asia/Singapore');
t('Asia/Taipei');
t('Asia/Tashkent');
t('Asia/Tbilisi');
t('Asia/Tehran');
t('Asia/Tel_Aviv');
t('Asia/Thimbu');
t('Asia/Thimphu');
t('Asia/Tokyo');
t('Asia/Ujung_Pandang');
t('Asia/Ulaanbaatar');
t('Asia/Ulan_Bator');
t('Asia/Urumqi');
t('Asia/Vientiane');
t('Asia/Vladivostok');
t('Asia/Yakutsk');
t('Asia/Yekaterinburg');
t('Asia/Yerevan');
t('Atlantic/Azores');
t('Atlantic/Bermuda');
t('Atlantic/Canary');
t('Atlantic/Cape_Verde');
t('Atlantic/Faeroe');
t('Atlantic/Jan_Mayen');
t('Atlantic/Madeira');
t('Atlantic/South_Georgia');
t('Atlantic/Stanley');
t('Australia/ACT');
t('Australia/Adelaide');
t('Australia/Brisbane');
t('Australia/Broken_Hill');
t('Australia/Canberra');
t('Australia/Darwin');
t('Australia/Hobart');
t('Australia/LHI');
t('Australia/Lindeman');
t('Australia/Lord_Howe');
t('Australia/Melbourne');
t('Australia/NSW');
t('Australia/North');
t('Australia/Perth');
t('Australia/Queensland');
t('Australia/South');
t('Australia/Sydney');
t('Australia/Tasmania');
t('Australia/Victoria');
t('Australia/West');
t('Australia/Yancowinna');
t('Europe/Amsterdam');
t('Europe/Andorra');
t('Europe/Athens');
t('Europe/Belfast');
t('Europe/Belgrade');
t('Europe/Berlin');
t('Europe/Bratislava');
t('Europe/Brussels');
t('Europe/Bucharest');
t('Europe/Budapest');
t('Europe/Chisinau');
t('Europe/Copenhagen');
t('Europe/Dublin');
t('Europe/Gibraltar');
t('Europe/Helsinki');
t('Europe/Istanbul');
t('Europe/Kaliningrad');
t('Europe/Kiev');
t('Europe/Lisbon');
t('Europe/Ljubljana');
t('Europe/London');
t('Europe/Luxembourg');
t('Europe/Madrid');
t('Europe/Malta');
t('Europe/Minsk');
t('Europe/Monaco');
t('Europe/Moscow');
t('Europe/Nicosia');
t('Europe/Oslo');
t('Europe/Paris');
t('Europe/Prague');
t('Europe/Riga');
t('Europe/Rome');
t('Europe/Samara');
t('Europe/San_Marino');
t('Europe/Sarajevo');
t('Europe/Simferopol');
t('Europe/Skopje');
t('Europe/Sofia');
t('Europe/Stockholm');
t('Europe/Tallinn');
t('Europe/Tirane');
t('Europe/Tiraspol');
t('Europe/Uzhgorod');
t('Europe/Vaduz');
t('Europe/Vatican');
t('Europe/Vienna');
t('Europe/Vilnius');
t('Europe/Warsaw');
t('Europe/Zagreb');
t('Europe/Zaporozhye');
t('Europe/Zurich');
t('Indian/Antananarivo');
t('Indian/Chagos');
t('Indian/Christmas');
t('Indian/Cocos');
t('Indian/Comoro');
t('Indian/Kerguelen');
t('Indian/Mahe');
t('Indian/Maldives');
t('Indian/Mauritius');
t('Indian/Mayotte');
t('Indian/Reunion');
t('Pacific/Apia');
t('Pacific/Auckland');
t('Pacific/Chatham');
t('Pacific/Easter');
t('Pacific/Efate');
t('Pacific/Enderbury');
t('Pacific/Fakaofo');
t('Pacific/Fiji');
t('Pacific/Funafuti');
t('Pacific/Galapagos');
t('Pacific/Gambier');
t('Pacific/Guadalcanal');
t('Pacific/Guam');
t('Pacific/Honolulu');
t('Pacific/Johnston');
t('Pacific/Kiritimati');
t('Pacific/Kosrae');
t('Pacific/Kwajalein');
t('Pacific/Majuro');
t('Pacific/Marquesas');
t('Pacific/Midway');
t('Pacific/Nauru');
t('Pacific/Niue');
t('Pacific/Norfolk');
t('Pacific/Noumea');
t('Pacific/Pago_Pago');
t('Pacific/Palau');
t('Pacific/Pitcairn');
t('Pacific/Ponape');
t('Pacific/Port_Moresby');
t('Pacific/Rarotonga');
t('Pacific/Saipan');
t('Pacific/Samoa');
t('Pacific/Tahiti');
t('Pacific/Tarawa');
t('Pacific/Tongatapu');
t('Pacific/Truk');
t('Pacific/Wake');
t('Pacific/Wallis');
t('Pacific/Yap');
t('Pacific/French_Polynesia-Marquesas_Islands');
t('UTC');
}

View file

@ -0,0 +1,47 @@
/**
* Set the client's system time zone as default values of form fields.
*/
Drupal.setDefaultTimezone = function() {
var dateString = Date();
// In some client environments, date strings include a time zone
// abbreviation which can be interpreted by PHP.
var matches = Date().match(/\(([A-Z]{3,5})\)/);
var abbreviation = matches ? matches[1] : 0;
// For all other client environments, the abbreviation is set to "0"
// and the current offset from UTC and daylight saving time status are
// used to guess the time zone.
var dateNow = new Date();
var offsetNow = dateNow.getTimezoneOffset() * -60;
// Use January 1 and July 1 as test dates for determining daylight
// saving time status by comparing their offsets.
var dateJan = new Date(dateNow.getFullYear(), 0, 1, 12, 0, 0, 0);
var dateJul = new Date(dateNow.getFullYear(), 6, 1, 12, 0, 0, 0);
var offsetJan = dateJan.getTimezoneOffset() * -60;
var offsetJul = dateJul.getTimezoneOffset() * -60;
// If the offset from UTC is identical on January 1 and July 1,
// assume daylight saving time is not used in this time zone.
if (offsetJan == offsetJul) {
var isDaylightSavingTime = '';
}
// If the maximum annual offset is equivalent to the current offset,
// assume daylight saving time is in effect.
else if (Math.max(offsetJan, offsetJul) == offsetNow) {
var isDaylightSavingTime = 1;
}
// Otherwise, assume daylight saving time is not in effect.
else {
var isDaylightSavingTime = 0;
}
// Submit request to the user/timezone callback and set the form field
// to the response time zone.
var path = 'user/timezone/' + abbreviation + '/' + offsetNow + '/' + isDaylightSavingTime;
$.getJSON(Drupal.settings.basePath, { q: path, date: dateString }, function (data) {
if (data) {
$("#edit-date-default-timezone, #edit-user-register-timezone, #edit-timezone-name").val(data);
}
});
};

View file

@ -0,0 +1,289 @@
<?php
/**
* @file
* This module will make the alter the user and site timezone forms to
* select a timezone name instead of a timezone offset.
*
* This module won't be needed once core starts tracking timezone names
* instead of offsets.
*/
/**
* Implementation of hook_menu().
*/
function date_timezone_menu() {
$items = array();
$items['user/timezone'] = array(
'title' => 'User timezone',
'page callback' => 'user_timezone',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_form_alter().
*
* Override system handling of user and site timezone selection.
*/
function date_timezone_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'system_date_time_settings') {
date_timezone_site_form($form);
if (!isset($form['#after_build'])) {
$form['#after_build'] = array();
}
$form['#after_build'][] = 'date_timezone_site_form_after_build';
}
elseif ($form_id == 'user_profile_form' && variable_get('configurable_timezones', 1) && isset($form['timezone'])) {
date_timezone_user_form($form);
if (!isset($form['#after_build'])) {
$form['#after_build'] = array();
}
$form['#after_build'][] = 'date_timezone_user_form_after_build';
}
}
/**
* Create a form for the site timezone names.
* Display a list of timezone names instead of offsets.
*/
function date_timezone_site_form(&$form) {
drupal_add_js(drupal_get_path('module', 'date_timezone') .'/date_timezone.js');
$form['locale']['#element_validate'] = array('date_timezone_update_site');
$timezone = variable_get('date_default_timezone_name', NULL);
$form['locale']['date_default_timezone_name'] = array(
'#type' => 'select',
'#title' => t('Default time zone'),
'#default_value' => $timezone,
'#options' => date_timezone_names(FALSE, TRUE), // Force an update before setting a site default.
'#description' => t('Select the default site time zone. If in doubt, choose the timezone that is closest to your location which has the same rules for daylight saving time.'),
'#weight' => -10,
'#offset' => variable_get('date_default_timezone', 0),
);
// Add the JavaScript callback to automatically set the timezone.
if (empty($timezone)) {
drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
$(document).ready(function() {
Drupal.setDefaultTimezone();
});
}', 'inline');
}
return $form;
}
/**
* Hide the original form.
*
* We have to do this in after_build in case the Event module
* is enabled since the Event module will do its form_alter()
* after the Date module.
*/
function date_timezone_site_form_after_build(&$form) {
// Set the value, and make sure it's a legal value.
$value = $form['locale']['date_default_timezone']['#default_value'];
$options = $form['locale']['date_default_timezone']['#options'];
if (!array_key_exists($value, $options)) {
//$value = array_pop($options);
$value = NULL;
}
$form['locale']['date_default_timezone']['#type'] = 'hidden';
$form['locale']['date_default_timezone']['#value'] = $value;
return $form;
}
/**
* Create a form for the site timezone names.
* Display a list of timezone names instead of offsets.
*/
function date_timezone_user_form(&$form) {
drupal_add_js(drupal_get_path('module', 'date_timezone') .'/date_timezone.js');
$account = $form['_account']['#value'];
$form['timezone']['#uid'] = $account->uid;
$form['timezone']['#element_validate'] = array('date_timezone_update_user');
$timezone = $account->timezone_name ? $account->timezone_name : variable_get('date_default_timezone_name', NULL);
$form['timezone']['timezone_name'] = array(
'#type' => 'select',
'#title' => t('Default time zone'),
'#default_value' => $timezone,
'#options' => date_timezone_names(),
'#description' => t('Select your current local time. If in doubt, choose the timezone that is closest to your location which has the same rules for daylight saving time. Dates and times throughout this site will be displayed using this time zone.'),
);
// Add the JavaScript callback to automatically set the timezone.
if (empty($timezone)) {
drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
$(document).ready(function() {
Drupal.setDefaultTimezone();
});
}', 'inline');
}
return $form;
}
/**
* Hide the original form.
*
* We have to do this in after_build in case the Event module
* is enabled since the Event module will do its form_alter()
* after the Date module.
*/
function date_timezone_user_form_after_build($form) {
// Set the value, and make sure it's a legal value.
$value = $form['timezone']['timezone']['#default_value'];
$options = $form['timezone']['timezone']['#options'];
if (!array_key_exists($value, $options)) {
//$value = array_pop($options);
$value = NULL;
}
$form['timezone']['timezone']['#type'] = 'hidden';
$form['timezone']['timezone']['#value'] = $value;
return $form;
}
/**
* Callback from site timezone settings form to update site timezone info.
* When the timezone name is updated, update the offset as well.
*/
function date_timezone_update_site($element, &$form_state) {
$timezone = $element['date_default_timezone_name']['#value'];
if (empty($timezone)) {
$offset = $element['date_default_timezone_name']['#offset'];
}
else {
variable_set('date_default_timezone_name', $timezone);
$date = date_make_date('now', $timezone);
$offset = date_offset_get($date);
}
// Reset the original form to the expected value.
if (module_exists('event') && db_table_exists('event_timezones')) {
$event_zone = date_event_zonelist_by_name(str_replace('_', ' ', $timezone));
// The event module will update the timezone and zone id, using this value.
if (!empty($event_zone['timezone'])) {
form_set_value($element['date_default_timezone'], $event_zone['timezone'] .'|'. $offset, $form_state);
} else {
form_set_value($element['date_default_timezone'], $offset, $form_state);
}
}
else {
form_set_value($element['date_default_timezone'], $offset, $form_state);
}
}
/**
* Callback from user timezone settings form to update user timezone info.
* When the timezone name is updated, update the offset as well.
*/
function date_timezone_update_user($element, &$form_state) {
$timezone = $element['timezone_name']['#value'];
if (!empty($timezone)) {
$date = date_make_date('now', $timezone);
$offset = date_offset_get($date);
}
// Reset the original form to the expected value.
if (module_exists('event') && db_table_exists('event_timezones')) {
$event_zone = date_event_zonelist_by_name(str_replace('_', ' ', $timezone));
// The event module will update the timezone and zone id using this value.
if (!empty($event_zone['timezone'])) {
form_set_value($element['timezone'], $event_zone['timezone'] .'|'. $offset, $form_state);
} else {
form_set_value($element['timezone'], $offset, $form_state);
}
}
else {
form_set_value($element['timezone'], $offset, $form_state);
}
}
/**
* Update the site timezone offset when cron runs.
*
* This is to make sure that modules that rely on the timezone offset
* have current information to process.
*/
function date_timezone_cron() {
$date = date_now(variable_get('date_default_timezone_name', NULL));
$offset = date_offset_get($date);
if ($offset != variable_get('date_default_timezone', 0)) {
variable_set('date_default_timezone', $offset);
}
}
/**
* Update user timezone information at login.
*
* This is to make sure that modules that rely on the timezone offset
* have current information to process.
*/
function date_timezone_user($op, &$edit, &$account, $category = NULL) {
if (isset($account->uid) && $op == 'login' && variable_get('configurable_timezones', 1)) {
if (strlen($account->timezone_name)) {
$date = date_now($account->timezone_name);
$offset = date_offset_get($date);
if ($offset != $account->timezone) {
$account->timezone = $offset;
db_query("UPDATE {users} SET timezone='%s' WHERE uid = %d", $offset, $account->uid);
}
}
else {
// If the user doesn't already have a timezone name selected,
// default it to the site timezone name and offset.
$timezone = variable_get('date_default_timezone_name', NULL);
if (!empty($timezone)) {
$date = date_now($timezone);
$offset = date_offset_get($date);
db_query("UPDATE {users} SET timezone_name = '%s', timezone='%s' WHERE uid = %d", $timezone, $offset, $account->uid);
}
}
}
}
/**
* Menu callback; Retrieve a JSON object containing a suggested time
* zone name.
*/
function user_timezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL) {
// An abbreviation of "0" passed in the callback arguments should be
// interpreted as the empty string.
$abbreviation = $abbreviation ? $abbreviation : '';
$timezone = function_exists('timezone_name_from_abbr') ? timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time) : 'UTC';
// The client date is passed in for debugging purposes.
$date = isset($_GET['date']) ? $_GET['date'] : '';
// Log a debug message.
watchdog('timezone', 'Detected time zone: %timezone; client date: %date; abbreviation: %abbreviation; offset: %offset; daylight saving time: %is_daylight_saving_time.', array('%timezone' => $timezone, '%date' => $date, '%abbreviation' => $abbreviation, '%offset' => $offset, '%is_daylight_saving_time' => $is_daylight_saving_time));
drupal_json($timezone);
}
/**
* Create replacement values for deprecated timezone names.
*/
function date_timezone_replacement($old) {
('./'. drupal_get_path('module', 'date_timezone') .'/date_timezone.install');
return _date_timezone_replacement($old);
}
/**
* Helper function to update Event module timezone information.
*/
function date_event_zonelist_by_name($name) {
if (!module_exists('event') || !db_table_exists('event_timezones')) {
return array();
}
static $zone_names = array();
if (!isset($zone_names[$name])) {
$zone = db_fetch_array(db_query("SELECT * FROM {event_timezones} WHERE name = '%s'", $name));
$zone_names[$name] = $zone;
}
return $zone_names[$name];
}