[geeklog-cvs] geeklog: Modernized the "timezone hack", made the config option ...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Nov 1 04:05:49 EST 2009
changeset 7428:df55886043f2
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/df55886043f2
user: Dirk Haun <dirk at haun-online.de>
date: Sun Sep 20 11:00:03 2009 +0200
description:
Modernized the "timezone hack", made the config option a dropdown, and moved all timezone-related code into a new TimeZoneConfig class
diffstat:
public_html/admin/configuration.php | 17 ++-
public_html/admin/install/config-install.php | 2 +-
public_html/docs/history | 2 +
public_html/lib-common.php | 13 +-
public_html/usersettings.php | 33 +---
sql/updates/mssql_1.6.0_to_1.6.1.php | 4 +
sql/updates/mysql_1.6.0_to_1.6.1.php | 4 +
system/classes/timezoneconfig.class.php | 260 ++++++++++++++++++++++++++++++++
8 files changed, 300 insertions(+), 35 deletions(-)
diffs (truncated from 426 to 300 lines):
diff -r 30e040149cbe -r df55886043f2 public_html/admin/configuration.php
--- a/public_html/admin/configuration.php Sun Sep 20 10:41:17 2009 +0200
+++ b/public_html/admin/configuration.php Sun Sep 20 11:00:03 2009 +0200
@@ -8,7 +8,7 @@
// | |
// | Loads the administration UI and sends input to config.class |
// +---------------------------------------------------------------------------+
-// | Copyright (C) 2007-2008 by the following authors: |
+// | Copyright (C) 2007-2009 by the following authors: |
// | |
// | Authors: Aaron Blankstein - kantai AT gmail DOT com |
// +---------------------------------------------------------------------------+
@@ -84,6 +84,21 @@
return $themes;
}
+/**
+* Helper function: Provide timezone dropdown
+*
+* @return array Array of (timezone-long-name, timezone-short-name) pairs
+*
+*/
+function configmanager_select_timezone_helper()
+{
+ global $_CONF;
+
+ require_once $_CONF['path_system'] . 'classes/timezoneconfig.class.php';
+
+ return array_flip(TimeZoneConfig::listAvailableTimeZones());
+}
+
// MAIN
$display = '';
diff -r 30e040149cbe -r df55886043f2 public_html/admin/install/config-install.php
--- a/public_html/admin/install/config-install.php Sun Sep 20 10:41:17 2009 +0200
+++ b/public_html/admin/install/config-install.php Sun Sep 20 11:00:03 2009 +0200
@@ -291,7 +291,7 @@
$c->add('thousand_separator',",",'text',6,29,NULL,440,TRUE);
$c->add('decimal_separator',".",'text',6,29,NULL,450,TRUE);
$c->add('decimal_count',"2",'text',6,29,NULL,460,TRUE);
- $c->add('timezone','Etc/GMT-6','text',6,29,NULL,490,FALSE);
+ $c->add('timezone','UTC','select',6,29,NULL,490,FALSE);
// Subgroup: Miscellaneous
$c->add('sg_misc', NULL, 'subgroup', 7, 0, NULL, 0, TRUE);
diff -r 30e040149cbe -r df55886043f2 public_html/docs/history
--- a/public_html/docs/history Sun Sep 20 10:41:17 2009 +0200
+++ b/public_html/docs/history Sun Sep 20 11:00:03 2009 +0200
@@ -3,6 +3,8 @@
Oct ??, 2009 (1.6.1)
------------
+- Modernized the "timezone hack", made the config option a dropdown, and moved
+ all timezone-related code into a new TimeZoneConfig class [Dirk]
- Changing the Post Mode in Advanced Editor mode selected the wrong tab
(bug #0000980, patch provided by dengen)
- Made the former $cc parameter for COM_mail an optional array of additional
diff -r 30e040149cbe -r df55886043f2 public_html/lib-common.php
--- a/public_html/lib-common.php Sun Sep 20 10:41:17 2009 +0200
+++ b/public_html/lib-common.php Sun Sep 20 11:00:03 2009 +0200
@@ -130,12 +130,6 @@
exit;
}
-// timezone hack - set the webserver's timezone
-if( !empty( $_CONF['timezone'] ) && !ini_get( 'safe_mode' ) &&
- function_exists( 'putenv' )) {
- putenv( 'TZ=' . $_CONF['timezone'] );
-}
-
// +---------------------------------------------------------------------------+
// | Library Includes: You shouldn't have to touch anything below here |
@@ -160,6 +154,13 @@
}
/**
+* Set the webserver's timezone
+*/
+
+require_once $_CONF['path_system'] . 'classes/timezoneconfig.class.php';
+TimeZoneConfig::setSystemTimeZone();
+
+/**
* Include plugin class.
* This is a poorly implemented class that was not very well thought out.
* Still very necessary
diff -r 30e040149cbe -r df55886043f2 public_html/usersettings.php
--- a/public_html/usersettings.php Sun Sep 20 10:41:17 2009 +0200
+++ b/public_html/usersettings.php Sun Sep 20 11:00:03 2009 +0200
@@ -518,36 +518,15 @@
$preferences->set_var ('theme_selection', '');
}
- require_once ('Date/TimeZone.php');
// Timezone
- if (empty($_USER['tzid']) && isset($_CONF['timezone'])) {
- $timezone = $_CONF['timezone'];
- } else if (!empty($_USER['tzid'])) {
- $timezone = $_USER['tzid'];
- } else {
- $tz_obj = Date_TimeZone::getDefault();
- $timezone = $tz_obj->id;
- }
- $selection = '<select id="tzid" name="tzid">' . LB;
+ require_once $_CONF['path_system'] . 'classes/timezoneconfig.class.php';
- $T = $GLOBALS['_DATE_TIMEZONE_DATA'];
+ $timezone = TimeZoneConfig::getUserTimeZone();
+ $selection = TimeZoneConfig::getTimeZoneDropDown($timezone,
+ array('id' => 'tzid', 'name' => 'tzid'));
- foreach ($T as $tzid => $tDetails) {
- $tzcode = str_replace('_', ' ', $tzid);
- $tzcode = htmlspecialchars($tzcode);
- $selection .= '<option value="' . $tzcode . '"';
- if ($timezone == $tzcode) {
- $selection .= ' selected="selected"';
- }
- $hours = $tDetails['offset'] / (3600 * 1000);
- if ($hours > 0) {
- $hours = "+$hours";
- }
- $selection .= ">$hours, {$tDetails['shortname']} ($tzcode)</option>" . LB;
- }
- $selection .= '</select>';
- $preferences->set_var ('timezone_selector', $selection);
- $preferences->set_var ('lang_timezone', $LANG04[158]);
+ $preferences->set_var('timezone_selector', $selection);
+ $preferences->set_var('lang_timezone', $LANG04[158]);
if ($A['noicons'] == '1') {
$preferences->set_var ('noicons_checked', 'checked="checked"');
diff -r 30e040149cbe -r df55886043f2 sql/updates/mssql_1.6.0_to_1.6.1.php
--- a/sql/updates/mssql_1.6.0_to_1.6.1.php Sun Sep 20 10:41:17 2009 +0200
+++ b/sql/updates/mssql_1.6.0_to_1.6.1.php Sun Sep 20 11:00:03 2009 +0200
@@ -23,6 +23,10 @@
$c->add('meta_description','Geeklog, the open source content management system designed with security in mind.','text',0,0,NULL,2010,TRUE);
$c->add('meta_keywords','Geeklog, Blog, Content Management System, CMS, Open Source, Security','text',0,0,NULL,2020,TRUE);
+ // the timezone config option is a dropdown now
+ $utc = addslashes(serialize('UTC')); // change default timezone to UTC
+ DB_query("UPDATE {$_TABLES['conf_values']} SET type = 'select', selectionArray = -1, default_value = '$utc' WHERE name = 'timezone' AND group_name = 'Core'");
+
return true;
}
diff -r 30e040149cbe -r df55886043f2 sql/updates/mysql_1.6.0_to_1.6.1.php
--- a/sql/updates/mysql_1.6.0_to_1.6.1.php Sun Sep 20 10:41:17 2009 +0200
+++ b/sql/updates/mysql_1.6.0_to_1.6.1.php Sun Sep 20 11:00:03 2009 +0200
@@ -24,6 +24,10 @@
$c->add('meta_description','Geeklog, the open source content management system designed with security in mind.','text',0,0,NULL,2010,TRUE);
$c->add('meta_keywords','Geeklog, Blog, Content Management System, CMS, Open Source, Security','text',0,0,NULL,2020,TRUE);
+ // the timezone config option is a dropdown now
+ $utc = addslashes(serialize('UTC')); // change default timezone to UTC
+ DB_query("UPDATE {$_TABLES['conf_values']} SET type = 'select', selectionArray = -1, default_value = '$utc' WHERE name = 'timezone' AND group_name = 'Core'");
+
return true;
}
diff -r 30e040149cbe -r df55886043f2 system/classes/timezoneconfig.class.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/system/classes/timezoneconfig.class.php Sun Sep 20 11:00:03 2009 +0200
@@ -0,0 +1,260 @@
+<?php
+
+/* Reminder: always indent with 4 spaces (no tabs). */
+// +---------------------------------------------------------------------------+
+// | Geeklog 1.6 |
+// +---------------------------------------------------------------------------+
+// | timezoneconfig.class.php |
+// | |
+// | Helper class for time zone handling |
+// +---------------------------------------------------------------------------+
+// | Copyright (C) 2009 by the following authors: |
+// | |
+// | Authors: Dirk Haun - dirk AT haun-online DOT de |
+// | based on earlier work by Oliver Spiesshofer, Yew Loong, and others |
+// +---------------------------------------------------------------------------+
+// | |
+// | This program is free software; you can redistribute it and/or |
+// | modify it under the terms of the GNU General Public License |
+// | as published by the Free Software Foundation; either version 2 |
+// | of the License, or (at your option) any later version. |
+// | |
+// | This program is distributed in the hope that it will be useful, |
+// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+// | GNU General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software Foundation, |
+// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
+// | |
+// +---------------------------------------------------------------------------+
+
+/**
+* Geeklog Time Zone Config class
+*
+* A collection of static (for now) methods dealing with time zone handling.
+*
+* For the original "Timezone Hack" discussion, see
+* @link http://www.geeklog.net/forum/viewtopic.php?showtopic=21232
+*
+* @author Dirk Haun, dirk AT haun-online DOT de
+*
+*/
+class TimeZoneConfig {
+
+ /**
+ * Set the system's timezone
+ *
+ * @param string $tz timezone to set; use $_CONF['timezone'] if empty
+ * @return void
+ * @static
+ *
+ */
+ function setSystemTimeZone($tz = '')
+ {
+ global $_CONF;
+
+ if (empty($tz) && !empty($_CONF['timezone'])) {
+ $tz = $_CONF['timezone'];
+ }
+
+ if (! empty($tz)) {
+ if (function_exists('date_default_timezone_set')) {
+ if (! @date_default_timezone_set($tz)) {
+ date_default_timezone_set('UTC');
+ COM_errorLog("Timezone '$tz' not valid - using 'UTC' instead", 1);
+ }
+ } elseif (!ini_get('safe_mode') && function_exists('putenv')) {
+ // aka "Timezone Hack"
+ putenv('TZ=' . $tz);
+ }
+ } elseif (function_exists('date_default_timezone_get')) {
+ // this is not ideal but will stop PHP 5.3.0ff from complaining ...
+ date_default_timezone_set(@date_default_timezone_get());
+ }
+ }
+
+ /**
+ * Get the user's preferred timezone
+ *
+ * @return string name of the timezone
+ * @static
+ *
+ */
+ function getUserTimeZone()
+ {
+ global $_CONF, $_USER;
+
+ if (! empty($_USER['tzid'])) {
+ $timezone = $_USER['tzid'];
+ } elseif (! empty($_CONF['timezone'])) {
+ $timezone = $_CONF['timezone'];
+ } else {
+ require_once 'Date/TimeZone.php';
+
+ $tz_obj = Date_TimeZone::getDefault();
+ $timezone = $tz_obj->id;
+ }
+
+ return $timezone;
+ }
+
+ /**
+ * Provide a dropdown menu of the available timezones
+ *
+ * @return string HTML for the dropdown
+ * @static
+ *
+ */
+ function getTimeZoneDropDown($selected = '', $attributes = array())
+ {
+ $timezones = TimeZoneConfig::listAvailableTimeZones();
+
+ $selection = '<select';
+ foreach ($attributes as $name => $value) {
+ $selection .= sprintf(' %s="%s"', $name, $value);
+ }
+ $selection .= '>' . LB;
+
+ foreach ($timezones as $tzid => $tzdisplay) {
+ $selection .= '<option value="' . $tzid . '"';
+ if (!empty($selected) && ($selected == $tzid)) {
+ $selection .= ' selected="selected"';
+ }
+ $selection .= ">$tzdisplay</option>" . LB;
+ }
+ $selection .= '</select>';
+
+ return $selection;
+ }
+
+ /**
+ * Provide a list of available timezones
+ *
More information about the geeklog-cvs
mailing list