[textpattern commit] r3233 - * Option: define('NO_TIMEZONE_SUPPORT') to disable timezone support even on capable serve...

0 views
Skip to first unread message

codesite...@google.com

unread,
Jun 24, 2009, 9:06:44 PM6/24/09
to txp...@googlegroups.com
Author: r.wetzlmayr
Date: Wed Jun 24 05:08:00 2009
New Revision: 3233

Modified:
development/4.x/textpattern/include/txp_prefs.php
development/4.x/textpattern/lib/txplib_misc.php
development/4.x/textpattern/update/_to_4.2.0.php

Log:
* Option: define('NO_TIMEZONE_SUPPORT') to disable timezone support even on
capable servers.
* Built-in fallback to GMT-offsets in timezone::selectInput().

Modified: development/4.x/textpattern/include/txp_prefs.php
==============================================================================
--- development/4.x/textpattern/include/txp_prefs.php (original)
+++ development/4.x/textpattern/include/txp_prefs.php Wed Jun 24 05:08:00
2009
@@ -45,7 +45,7 @@
$post = doSlash(stripPost());

// Forge $gmtoffset and $is_dst from $timezone_key if present
- if (isset($post['timezone_key']) && timezone::is_supported())
+ if (isset($post['timezone_key']))
{
$key = $post['timezone_key'];
$tz = new timezone;
@@ -55,7 +55,6 @@
global $prefs, $gmtoffset, $is_dst, $timezone_key;
$prefs['timezone_key'] = $timezone_key = $key;
$post['gmtoffset'] = $prefs['gmtoffset'] = $gmtoffset =
$tzd[$key]['offset'];
-
if (gps('auto_dst'))
{
$post['is_dst'] = $prefs['is_dst'] = $is_dst =
timezone::is_dst(time(), $key);
@@ -247,32 +246,8 @@
{
// Fetch *hidden* pref
$key = safe_field('val', 'txp_prefs', "name='timezone_key'");
- // Try geographic timezone UI
$tz = new timezone;
$ui = $tz->selectInput('timezone_key', $key,
true, '', 'gmtoffset');
- // Fall back to GMT offset UI
- if (!$ui)
- {
- // Standard time zones as compiled by H.M. Nautical Almanac
Office, June 2004
- // http://aa.usno.navy.mil/faq/docs/world_tzones.html
- $tz = array(
- -12, -11, -10, -9.5, -9, -8.5, -8, -7, -6, -5, -4, -3.5,
-3, -2, -1,
- 0,
- +1, +2, +3, +3.5, +4, +4.5, +5, +5.5, +6, +6.5, +7, +8,
+9, +9.5, +10, +10.5, +11, +11.5, +12, +13, +14,
- );
-
- $vals = array();
-
- foreach ($tz as $z)
- {
- $sign = ($z >= 0 ? '+' : '');
- $label = sprintf("GMT %s%02d:%02d", $sign, $z, abs($z -
(int)$z) * 60);
-
- $vals[sprintf("%s%d", $sign, $z * 3600)] = $label;
- }
- $ui = selectInput($name, $vals, $val, '', '', $name);
- }
-
return pluggable_ui('prefs_ui', 'gmtoffset', $ui, $name, $val);
}


Modified: development/4.x/textpattern/lib/txplib_misc.php
==============================================================================
--- development/4.x/textpattern/lib/txplib_misc.php (original)
+++ development/4.x/textpattern/lib/txplib_misc.php Wed Jun 24 05:08:00 2009
@@ -2354,37 +2354,55 @@
*/
function timezone()
{
- // bail out when we find ourselves riding a dinosaur
+ // are we riding a dinosaur?
if (!timezone::is_supported())
- {
- $this->_details = array();
- $this->_offsets = array();
- return;
- }
-
- $continents = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia',
- 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific', 'Etc');
+ {
+ // Standard time zones as compiled by H.M. Nautical Almanac
Office, June 2004
+ // http://aa.usno.navy.mil/faq/docs/world_tzones.html
+ $timezones = array(
+ -12, -11, -10, -9.5, -9, -8.5, -8, -7, -6, -5, -4, -3.5,
-3, -2, -1,
+ 0,
+ +1, +2, +3, +3.5, +4, +4.5, +5, +5.5, +6, +6.5, +7, +8,
+9, +9.5, +10, +10.5, +11, +11.5, +12, +13, +14,
+ );
+
+ foreach ($timezones as $tz)
+ {
+ // Fake timezone id
+ $timezone_id = 'GMT'.sprintf('%+05.1f', $tz);
+ $sign = ($tz >= 0 ? '+' : '');
+ $label = sprintf("GMT %s%02d:%02d", $sign, $tz, abs($tz -
(int)$tz) * 60);
+ $this->_details[$timezone_id]['continent'] =
gTxt('timezone_gmt');
+ $this->_details[$timezone_id]['city'] = $label;
+ $this->_details[$timezone_id]['offset'] = $tz * 3600;
+ $this->_offsets[$tz * 3600] = $timezone_id;
+ }
+ }
+ else
+ {
+ $continents =
array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia',
+ 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');

- $tzlist = DateTimeZone::listAbbreviations();
- foreach ($tzlist as $abbr => $timezones)
- {
- foreach ($timezones as $tz)
+ $tzlist = timezone_abbreviations_list();
+ foreach ($tzlist as $abbr => $timezones)
{
- $timezone_id = $tz['timezone_id'];
- if ($timezone_id)
+ foreach ($timezones as $tz)
{
- $parts = explode('/', $timezone_id);
- if (in_array($parts[0], $continents))
+ $timezone_id = $tz['timezone_id'];
+ if ($timezone_id)
{
- $this->_details[$timezone_id]['continent'] = $parts[0];
- $this->_details[$timezone_id]['city'] = (isset($parts[1])) ?
$parts[1] : '';
- $this->_details[$timezone_id]['subcity'] = (isset($parts[2])) ?
$parts[2] : '';
- $this->_details[$timezone_id]['offset'] = $tz['offset'];
- $this->_details[$timezone_id]['dst'] = $tz['dst'];
- $this->_details[$timezone_id]['abbr'] = strtoupper($abbr);
-
- // Guesstimate a timezone key for a given GMT offset
- $this->_offsets[$tz['offset']] = $timezone_id;
+ $parts = explode('/', $timezone_id);
+ if (in_array($parts[0], $continents))
+ {
+ $this->_details[$timezone_id]['continent'] = $parts[0];
+ $this->_details[$timezone_id]['city'] = (isset($parts[1])) ?
$parts[1] : '';
+ $this->_details[$timezone_id]['subcity'] = (isset($parts[2])) ?
$parts[2] : '';
+ $this->_details[$timezone_id]['offset'] = $tz['offset'];
+ $this->_details[$timezone_id]['dst'] = $tz['dst'];
+ $this->_details[$timezone_id]['abbr'] = strtoupper($abbr);
+
+ // Guesstimate a timezone key for a given GMT offset
+ $this->_offsets[$tz['offset']] = $timezone_id;
+ }
}
}
}
@@ -2453,7 +2471,7 @@
*/
function key($gmtoffset)
{
- return isset($this->_keys[$gmtoffset]) ? $this->_keys[$gmtoffset] : '';
+ return isset($this->_offsets[$gmtoffset]) ?
$this->_offsets[$gmtoffset] : '';
}

/**
@@ -2490,7 +2508,7 @@
*/
function is_supported()
{
- return function_exists('date_default_timezone_set') &&
method_exists('DateTimeZone', 'listAbbreviations');
+ return is_callable('date_default_timezone_set') &&
is_callable('timezone_abbreviations_list')
&& !defined('NO_TIMEZONE_SUPPORT');
}
}
?>

Modified: development/4.x/textpattern/update/_to_4.2.0.php
==============================================================================
--- development/4.x/textpattern/update/_to_4.2.0.php (original)
+++ development/4.x/textpattern/update/_to_4.2.0.php Wed Jun 24 05:08:00
2009
@@ -37,17 +37,8 @@
}
if (!safe_field('name', 'txp_prefs', "name = 'timezone_key'"))
{
- $tz = '';
- if (timezone::is_supported())
- {
- $tz = new timezone;
- $tz = $tz->key($gmtoffset);
- }
- if (empty($tz))
- {
- $sign = ($gmtoffset >= 0 ? '+' : '');
- $tz = sprintf("Etc/GMT%s%d", $sign, $gmtoffset / 3600);
- }
+ $tz = new timezone;
+ $tz = $tz->key($gmtoffset);
safe_insert('txp_prefs', "prefs_id = 1, name = 'timezone_key', val
= '$tz', type = '2', event = 'publish', html = 'textinput', position
= '0'");
}

Reply all
Reply to author
Forward
0 new messages