From 6f7d095e3f4b09847c5963646b2f4a817d68ba39 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 18 Apr 2010 22:11:04 +0100 Subject: [PATCH 01/75] [feature/new-tz-handling] Wrapper around DateTime for new date time handling. Wrapped PHP's DateTime with some extensions for supporting phpBB's relative date formats and provided the DateTime::getTimestamp() method to PHP < 5.3. PHPBB3-9558 --- phpBB/includes/datetime.php | 160 ++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 phpBB/includes/datetime.php diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php new file mode 100644 index 0000000000..b1e95e58a3 --- /dev/null +++ b/phpBB/includes/datetime.php @@ -0,0 +1,160 @@ +_user = $user ? $user : $GLOBALS['user']; + + $timezone = (!$timezone && $this->_user->tz instanceof DateTimeZone) ? $this->_user->tz : $timezone; + + parent::__construct($time, $timezone); + } + + /** + * Returns a UNIX timestamp representation of the date time. + * + * @return int UNIX timestamp + */ + public function getTimestamp() + { + static $compat; + + if (!isset($compat)) + { + $compat = !method_exists('DateTime', 'getTimestamp'); + } + + return !$compat ? parent::getTimestamp() : (int) parent::format('U'); + } + + /** + * Formats the current date time into the specified format + * + * @param string $format Optional format to use for output, defaults to users chosen format + * @param boolean $force_absolute Force output of a non relative date + * @return string Formatted date time + */ + public function format($format = '', $force_absolute = false) + { + $format = $format ? $format : $this->_user->date_format; + $relative = (strpos($format, self::RELATIVE_WRAPPER) !== false && !$force_absolute); + $now = new self('now', $this->_user->tz, $this->_user); + $delta = $now->getTimestamp() - $this->getTimestamp(); + + if ($relative) + { + if ($delta <= 3600 && ($delta >= -5 || (($now->getTimestamp() / 60) % 60) == (($this->getTimestamp() / 60) % 60)) && isset($this->_user->lang['datetime']['AGO'])) + { + return $this->_user->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); + } + else + { + $midnight = clone $now; + $midnight->setTime(0, 0, 0); + + $midnight = $midnight->getTimestamp(); + $gmepoch = $this->getTimestamp(); + + if (!($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) + { + $day = false; + + if ($gmepoch > $midnight + 86400) + { + $day = 'TOMORROW'; + } + else if ($gmepoch > $midnight) + { + $day = 'TODAY'; + } + else if ($gmepoch > $midnight - 86400) + { + $day = 'YESTERDAY'; + } + + if ($day !== false) + { + $format = self::_format_cache($format, $this->_user); + + return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->_user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang'])); + } + } + } + } + + $format = self::_format_cache($format, $this->_user); + + return strtr(parent::format($format['format_long']), $format['lang']); + } + + /** + * Pre-processes the specified date format + * + * @param string $format Output format + * @param user $user User object to use for localisation + * @return array Processed date format + */ + static protected function _format_cache($format, $user) + { + $lang = $user->lang_name; + + if (!isset(self::$format_cache[$lang])) + { + self::$format_cache[$lang] = array(); + + if (!isset(self::$format_cache[$lang][$format])) + { + // Is the user requesting a friendly date format (i.e. 'Today 12:42')? + self::$format_cache[$lang][$format] = array( + 'is_short' => strpos($format, self::RELATIVE_WRAPPER) !== false, + 'format_short' => substr($format, 0, strpos($format, self::RELATIVE_WRAPPER)) . self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER . substr(strrchr($format, self::RELATIVE_WRAPPER), 1), + 'format_long' => str_replace(self::RELATIVE_WRAPPER, '', $format), + 'lang' => $user->lang['datetime'], + ); + + // Short representation of month in format? Some languages use different terms for the long and short format of May + if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) + { + self::$format_cache[$lang][$format]['lang']['May'] = $user->lang['datetime']['May_short']; + } + } + } + + return self::$format_cache[$lang][$format]; + } +} From e8b60fc3d8b483fda50c715e59b73861cd3ced9e Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 18 Apr 2010 22:26:33 +0100 Subject: [PATCH 02/75] [feature/new-tz-handling] Use phpbb_datetime rather than phpbb_DateTime. PHPBB3-9558 --- phpBB/includes/datetime.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index b1e95e58a3..d14693faa3 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -11,7 +11,7 @@ * phpBB custom extensions to the PHP DateTime class * This handles the relative formats phpBB employs */ -class phpbb_DateTime extends DateTime +class phpbb_datetime extends DateTime { /** * String used to wrap the date segment which should be replaced by today/tomorrow/yesterday @@ -29,7 +29,7 @@ class phpbb_DateTime extends DateTime static protected $format_cache = array(); /** - * Constructs a new instance of phpbb_DateTime, expanded to include an argument to inject + * Constructs a new instance of phpbb_datetime, expanded to include an argument to inject * the user context and modify the timezone to the users selected timezone if one is not set. * * @param string $time String in a format accepted by strtotime(). From a5c3ff376911f2f25595f1a540c7a16395dac67d Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Apr 2010 19:30:05 +0100 Subject: [PATCH 03/75] [feature/new-tz-handling] Renamed old variables and removed extra conditional. PHPBB3-9558 --- phpBB/includes/datetime.php | 39 ++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index d14693faa3..92aef88599 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -87,32 +87,27 @@ class phpbb_datetime extends DateTime $midnight = clone $now; $midnight->setTime(0, 0, 0); - $midnight = $midnight->getTimestamp(); - $gmepoch = $this->getTimestamp(); + $midnight = $midnight->getTimestamp(); + $timestamp = $this->getTimestamp(); - if (!($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) + if ($timestamp > $midnight + 86400) { - $day = false; + $day = 'TOMORROW'; + } + else if ($timestamp > $midnight) + { + $day = 'TODAY'; + } + else if ($timestamp > $midnight - 86400) + { + $day = 'YESTERDAY'; + } - if ($gmepoch > $midnight + 86400) - { - $day = 'TOMORROW'; - } - else if ($gmepoch > $midnight) - { - $day = 'TODAY'; - } - else if ($gmepoch > $midnight - 86400) - { - $day = 'YESTERDAY'; - } + if ($day !== false) + { + $format = self::_format_cache($format, $this->_user); - if ($day !== false) - { - $format = self::_format_cache($format, $this->_user); - - return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->_user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang'])); - } + return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->_user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang'])); } } } From 3559d2062480d5c3a0e94dae7388f9f1e5918ea7 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Apr 2010 19:43:49 +0100 Subject: [PATCH 04/75] [feature/new-tz-handling] Update user methods to use new date processing class. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit user::setup() now stores a DateTimeZone object in user::$timezone representing the users timezone. For backwards compatibility a numeric value in user/board_timezone will be converted into one of the legacy Etc/GMT±X timezones. This will be used until the user updates his/her timezone in the UCP. user::format_date() is now basically a legacy wrapper that transforms a UTC UNIX timestamp into a formatted localised date using phpbb_datetime::format(). PHPBB3-9558 --- phpBB/includes/session.php | 87 +++++++++++--------------------------- 1 file changed, 24 insertions(+), 63 deletions(-) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 497aaf1141..ba9136b568 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1574,20 +1574,26 @@ class user extends session { global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; + // @todo Move this to a better location + if (!class_exists('phpbb_datetime')) + { + global $phpbb_root_path, $phpEx; + + require "{$phpbb_root_path}includes/datetime.$phpEx"; + } + if ($this->data['user_id'] != ANONYMOUS) { $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']); $this->date_format = $this->data['user_dateformat']; - $this->timezone = $this->data['user_timezone'] * 3600; - $this->dst = $this->data['user_dst'] * 3600; + $this->timezone = $this->data['user_timezone']; } else { $this->lang_name = basename($config['default_lang']); $this->date_format = $config['default_dateformat']; - $this->timezone = $config['board_timezone'] * 3600; - $this->dst = $config['board_dst'] * 3600; + $this->timezone = $config['board_timezone']; /** * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language @@ -1626,6 +1632,14 @@ class user extends session */ } + if (is_numeric($this->timezone)) + { + // Might still be numeric by chance + $this->timezone = sprintf('Etc/GMT%+d', ($this->timezone + ($this->data['user_id'] != ANONYMOUS ? $this->data['user_dst'] : $config['board_dst']))); + } + + $this->timezone = new DateTimeZone($this->timezone); + // We include common language file here to not load it every time a custom language file is included $lang = &$this->lang; @@ -2072,70 +2086,17 @@ class user extends session */ function format_date($gmepoch, $format = false, $forcedate = false) { - static $midnight; - static $date_cache; + static $utc; - $format = (!$format) ? $this->date_format : $format; - $now = time(); - $delta = $now - $gmepoch; - - if (!isset($date_cache[$format])) + if (!isset($utc)) { - // Is the user requesting a friendly date format (i.e. 'Today 12:42')? - $date_cache[$format] = array( - 'is_short' => strpos($format, '|'), - 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), - 'format_long' => str_replace('|', '', $format), - 'lang' => $this->lang['datetime'], - ); - - // Short representation of month in format? Some languages use different terms for the long and short format of May - if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) - { - $date_cache[$format]['lang']['May'] = $this->lang['datetime']['May_short']; - } + $utc = new DateTimeZone('UTC'); } - // Zone offset - $zone_offset = $this->timezone + $this->dst; + $time = new phpbb_DateTime("@$gmepoch", $utc, $this); + $time->setTimezone($this->tz); - // Show date <= 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future - // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago' - if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO'])) - { - return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); - } - - if (!$midnight) - { - list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset)); - $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset; - } - - if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) - { - $day = false; - - if ($gmepoch > $midnight + 86400) - { - $day = 'TOMORROW'; - } - else if ($gmepoch > $midnight) - { - $day = 'TODAY'; - } - else if ($gmepoch > $midnight - 86400) - { - $day = 'YESTERDAY'; - } - - if ($day !== false) - { - return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang'])); - } - } - - return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']); + return $time->format($format, $forcedate); } /** From b2a812e36bc90d01f21da469823f4e759294b770 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Apr 2010 21:01:20 +0100 Subject: [PATCH 05/75] [feature/new-tz-handling] Correct capitalisation of phpbb_datetime. PHPBB3-9558 --- phpBB/includes/session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index ba9136b568..d8204e41f6 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -2093,7 +2093,7 @@ class user extends session $utc = new DateTimeZone('UTC'); } - $time = new phpbb_DateTime("@$gmepoch", $utc, $this); + $time = new phpbb_datetime("@$gmepoch", $utc, $this); $time->setTimezone($this->tz); return $time->format($format, $forcedate); From 9e1812a0ca728aee69df9ec5b86ea21756d3b1cc Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 21:31:41 +0100 Subject: [PATCH 06/75] [feature/new-tz-handling] Remove old user::$dst property PHPBB3-9558 --- phpBB/includes/session.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index d8204e41f6..fe690a1a9a 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1529,7 +1529,6 @@ class user extends session var $theme = array(); var $date_format; var $timezone; - var $dst; var $lang_name = false; var $lang_id = false; From 6a783b843b596c46738d76f2db5d539d8f68a815 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:17:40 +0100 Subject: [PATCH 07/75] [feature/new-tz-handling] Replace user::$timezone with user::$tz. user::$tz will store the new DateTimeZone object representing the users timezone instead of the existing user::$timezone and user::$dst combination. PHPBB3-9558 --- phpBB/includes/session.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index fe690a1a9a..2352e6394a 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1528,7 +1528,14 @@ class user extends session var $help = array(); var $theme = array(); var $date_format; - var $timezone; + + /** + * Users current timezone + * + * @var DateTimeZone Timezone of the user + * @since 3.1 + */ + public $tz; var $lang_name = false; var $lang_id = false; @@ -1586,13 +1593,13 @@ class user extends session $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']); $this->date_format = $this->data['user_dateformat']; - $this->timezone = $this->data['user_timezone']; + $this->tz = $this->data['user_timezone']; } else { $this->lang_name = basename($config['default_lang']); $this->date_format = $config['default_dateformat']; - $this->timezone = $config['board_timezone']; + $this->tz = $config['board_timezone']; /** * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language @@ -1631,13 +1638,13 @@ class user extends session */ } - if (is_numeric($this->timezone)) + if (is_numeric($this->tz)) { // Might still be numeric by chance - $this->timezone = sprintf('Etc/GMT%+d', ($this->timezone + ($this->data['user_id'] != ANONYMOUS ? $this->data['user_dst'] : $config['board_dst']))); + $this->tz = sprintf('Etc/GMT%+d', ($this->tz + ($this->data['user_id'] != ANONYMOUS ? $this->data['user_dst'] : $config['board_dst']))); } - $this->timezone = new DateTimeZone($this->timezone); + $this->tz = new DateTimeZone($this->tz); // We include common language file here to not load it every time a custom language file is included $lang = &$this->lang; From 74be23a098ec222cf3f3d14d6b6df236c58e8c01 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:20:08 +0100 Subject: [PATCH 08/75] [feature/new-tz-handling] Added a user::create_datetime() method. New method which handles instantiating new phpbb_datetime objects in the context of the current user. PHPBB3-9558 --- phpBB/includes/session.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 2352e6394a..e91606878a 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -2105,6 +2105,21 @@ class user extends session return $time->format($format, $forcedate); } + /** + * Create a phpbb_datetime object in the context of the current user + * + * @since 3.1 + * @param string $time String in a format accepted by strtotime(). + * @param DateTimeZone $timezone Time zone of the time. + * @return phpbb_datetime Date time object linked to the current users locale + */ + public function create_datetime($time, DateTimeZone $timezone = null) + { + $timezone = $timezone ? $timezone : $this->tz; + + return new phpbb_datetime($time, $timezone, $this); + } + /** * Get language id currently used by the user */ From 2e7d9ec805a8f2088ceebf22dbc97b89a72f76d0 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 23:46:20 +0100 Subject: [PATCH 09/75] [feature/new-tz-handling] Fixed bug with signature of user::create_datetime(). First argument to user::create_datetime() should be optional. PHPBB3-9558 --- phpBB/includes/session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index e91606878a..cf2efd2960 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -2113,7 +2113,7 @@ class user extends session * @param DateTimeZone $timezone Time zone of the time. * @return phpbb_datetime Date time object linked to the current users locale */ - public function create_datetime($time, DateTimeZone $timezone = null) + public function create_datetime($time = 'now', DateTimeZone $timezone = null) { $timezone = $timezone ? $timezone : $this->tz; From 522f65d079c61e9ea7f718b67e37a9e58968b0f0 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:21:40 +0100 Subject: [PATCH 10/75] [feature/new-tz-handling] Correct typo in member comment. PHPBB3-9558 --- phpBB/includes/datetime.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index 92aef88599..3a7fc04105 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -24,7 +24,7 @@ class phpbb_datetime extends DateTime protected $_user; /** - * @var array Date formats are preprocessed by phpBB, to save constact recalculation they are cached. + * @var array Date formats are preprocessed by phpBB, to save constant recalculation they are cached. */ static protected $format_cache = array(); From c521ef1591022e69fe952ec23e6614ae36dee2e2 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:22:38 +0100 Subject: [PATCH 11/75] [feature/new-tz-handling] Comment and optimise phpbb_datetime::format(). - Added comments explaining the complex time computations for rendering relative date times. - Replaced some repeated method invokations with variables. PHPBB3-9558 --- phpBB/includes/datetime.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index 3a7fc04105..577081e40b 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -74,11 +74,18 @@ class phpbb_datetime extends DateTime $format = $format ? $format : $this->_user->date_format; $relative = (strpos($format, self::RELATIVE_WRAPPER) !== false && !$force_absolute); $now = new self('now', $this->_user->tz, $this->_user); - $delta = $now->getTimestamp() - $this->getTimestamp(); + + $timestamp = $this->getTimestamp(); + $now_ts = $now->getTimeStamp(); + + $delta = $now_ts - $timestamp; if ($relative) { - if ($delta <= 3600 && ($delta >= -5 || (($now->getTimestamp() / 60) % 60) == (($this->getTimestamp() / 60) % 60)) && isset($this->_user->lang['datetime']['AGO'])) + // Check the delta is less than or equal to 1 hour + // and the delta is either greater than -5 seconds or timestamp and current time are of the same minute (they must be in the same hour already) + // finally check that relative dates are supported by the language pack + if ($delta <= 3600 && ($delta >= -5 || (($now_ts / 60) % 60) == (($timestamp / 60) % 60)) && isset($this->_user->lang['datetime']['AGO'])) { return $this->_user->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); } @@ -88,7 +95,6 @@ class phpbb_datetime extends DateTime $midnight->setTime(0, 0, 0); $midnight = $midnight->getTimestamp(); - $timestamp = $this->getTimestamp(); if ($timestamp > $midnight + 86400) { @@ -107,6 +113,7 @@ class phpbb_datetime extends DateTime { $format = self::_format_cache($format, $this->_user); + // Format using the short formatting and finally swap out the relative token placeholder with the correct value return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->_user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang'])); } } From dba89a534120d48d0ba901aedd69f962536bf36d Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:24:43 +0100 Subject: [PATCH 12/75] [feature/new-tz-handling] Added phpbb_datetime::__toString(). New phpbb_datetime::__toString() magic method that formats the datetime according to the users default settings. PHPBB3-9558 --- phpBB/includes/datetime.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index 577081e40b..8763697c78 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -124,6 +124,16 @@ class phpbb_datetime extends DateTime return strtr(parent::format($format['format_long']), $format['lang']); } + /** + * Magic method to convert DateTime object to string + * + * @return Formatted date time, according to the users default settings. + */ + public function __toString() + { + return $this->format(); + } + /** * Pre-processes the specified date format * From f085735ef812a57790699a6d789cbab22f882328 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:25:52 +0100 Subject: [PATCH 13/75] [feature/new-tz-handling] Explained name of phpbb_datetime::getTimestamp() phpbb_datetime::getTimestamp() exists purely to support PHP 5.2 which does not implement the method. PHPBB3-9558 --- phpBB/includes/datetime.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index 8763697c78..12d04d5ca6 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -48,6 +48,7 @@ class phpbb_datetime extends DateTime /** * Returns a UNIX timestamp representation of the date time. * + * @internal This method is for backwards compatibility with 5.2, hence why it doesn't use our method naming standards. * @return int UNIX timestamp */ public function getTimestamp() From 8fe46175aff1d9275b7337a8ced8060ff850d153 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:29:36 +0100 Subject: [PATCH 14/75] [feature/new-tz-handling] Fix undefined variable. PHPBB3-9558 --- phpBB/includes/datetime.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index 12d04d5ca6..25da6401d7 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -97,6 +97,8 @@ class phpbb_datetime extends DateTime $midnight = $midnight->getTimestamp(); + $day = false; + if ($timestamp > $midnight + 86400) { $day = 'TOMORROW'; From 5dd7916c496b76ab2e1e28b804069dde63f7dbf0 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:47:34 +0100 Subject: [PATCH 15/75] [feature/new-tz-handling] Check the is_short flag stored inside the format array. Reuse the existing check store in the format array to determine if the date time format supports relative formatting. PHPBB3-9558 --- phpBB/includes/datetime.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index 25da6401d7..ecb3dfcf17 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -73,7 +73,8 @@ class phpbb_datetime extends DateTime public function format($format = '', $force_absolute = false) { $format = $format ? $format : $this->_user->date_format; - $relative = (strpos($format, self::RELATIVE_WRAPPER) !== false && !$force_absolute); + $format = self::_format_cache($format, $this->_user); + $relative = ($format['is_short'] && !$force_absolute); $now = new self('now', $this->_user->tz, $this->_user); $timestamp = $this->getTimestamp(); @@ -114,8 +115,6 @@ class phpbb_datetime extends DateTime if ($day !== false) { - $format = self::_format_cache($format, $this->_user); - // Format using the short formatting and finally swap out the relative token placeholder with the correct value return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->_user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang'])); } From e9fe9ea5185679e9950e330c949cc2577bfea21d Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:52:04 +0100 Subject: [PATCH 16/75] [feature/new-tz-handling] Fix bug from 3.0 formatting future dates. Future dates can get formatted as 'less than a minute ago' if they occur in the future on the same minute as the current minute. PHPBB3-9558 PHPBB3-9712 --- phpBB/includes/datetime.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index ecb3dfcf17..2276d36413 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -85,9 +85,10 @@ class phpbb_datetime extends DateTime if ($relative) { // Check the delta is less than or equal to 1 hour + // and the delta not more than a minute in the past // and the delta is either greater than -5 seconds or timestamp and current time are of the same minute (they must be in the same hour already) // finally check that relative dates are supported by the language pack - if ($delta <= 3600 && ($delta >= -5 || (($now_ts / 60) % 60) == (($timestamp / 60) % 60)) && isset($this->_user->lang['datetime']['AGO'])) + if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now_ts / 60) % 60) == (($timestamp / 60) % 60)) && isset($this->_user->lang['datetime']['AGO'])) { return $this->_user->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); } From 6e1278655ff3f250b4f1e09aa8674bae8d86287a Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 22:57:43 +0100 Subject: [PATCH 17/75] [feature/new-tz-handling] Removed line that was missed in cc312d8. PHPBB3-9558 --- phpBB/includes/datetime.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index 2276d36413..22b7f871fd 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -122,8 +122,6 @@ class phpbb_datetime extends DateTime } } - $format = self::_format_cache($format, $this->_user); - return strtr(parent::format($format['format_long']), $format['lang']); } From af789040b8880f908df0a26d5239d07d77c34124 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 23:23:11 +0100 Subject: [PATCH 18/75] [feature/new-tz-handling] Modify database schemas. - Dropped the user_dst column which is no longer required. - Modified the user_timezone column to take a string, max length 100. PHPBB3-9558 --- phpBB/develop/create_schema_files.php | 3 +-- phpBB/install/schemas/firebird_schema.sql | 3 +-- phpBB/install/schemas/mssql_schema.sql | 3 +-- phpBB/install/schemas/mysql_40_schema.sql | 3 +-- phpBB/install/schemas/mysql_41_schema.sql | 3 +-- phpBB/install/schemas/oracle_schema.sql | 3 +-- phpBB/install/schemas/postgres_schema.sql | 3 +-- phpBB/install/schemas/sqlite_schema.sql | 3 +-- 8 files changed, 8 insertions(+), 16 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 1735bffef5..f16675385b 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1823,8 +1823,7 @@ function get_schema_struct() 'user_inactive_time' => array('TIMESTAMP', 0), 'user_posts' => array('UINT', 0), 'user_lang' => array('VCHAR:30', ''), - 'user_timezone' => array('DECIMAL', 0), - 'user_dst' => array('BOOL', 0), + 'user_timezone' => array('VCHAR:100', 'UTC'), 'user_dateformat' => array('VCHAR_UNI:30', 'd M Y H:i'), 'user_style' => array('UINT', 0), 'user_rank' => array('UINT', 0), diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index daeba45864..f4b1c624d7 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -1290,8 +1290,7 @@ CREATE TABLE phpbb_users ( user_inactive_time INTEGER DEFAULT 0 NOT NULL, user_posts INTEGER DEFAULT 0 NOT NULL, user_lang VARCHAR(30) CHARACTER SET NONE DEFAULT '' NOT NULL, - user_timezone DOUBLE PRECISION DEFAULT 0 NOT NULL, - user_dst INTEGER DEFAULT 0 NOT NULL, + user_timezone VARCHAR(100) CHARACTER SET NONE DEFAULT 'UTC' NOT NULL, user_dateformat VARCHAR(30) CHARACTER SET UTF8 DEFAULT 'd M Y H:i' NOT NULL COLLATE UNICODE, user_style INTEGER DEFAULT 0 NOT NULL, user_rank INTEGER DEFAULT 0 NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 736917fdcb..fc1afcbbff 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -1576,8 +1576,7 @@ CREATE TABLE [phpbb_users] ( [user_inactive_time] [int] DEFAULT (0) NOT NULL , [user_posts] [int] DEFAULT (0) NOT NULL , [user_lang] [varchar] (30) DEFAULT ('') NOT NULL , - [user_timezone] [float] DEFAULT (0) NOT NULL , - [user_dst] [int] DEFAULT (0) NOT NULL , + [user_timezone] [varchar] (100) DEFAULT ('UTC') NOT NULL , [user_dateformat] [varchar] (30) DEFAULT ('d M Y H:i') NOT NULL , [user_style] [int] DEFAULT (0) NOT NULL , [user_rank] [int] DEFAULT (0) NOT NULL , diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 97c378621b..76b9294987 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -914,8 +914,7 @@ CREATE TABLE phpbb_users ( user_inactive_time int(11) UNSIGNED DEFAULT '0' NOT NULL, user_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, user_lang varbinary(30) DEFAULT '' NOT NULL, - user_timezone decimal(5,2) DEFAULT '0' NOT NULL, - user_dst tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, + user_timezone varbinary(100) DEFAULT 'UTC' NOT NULL, user_dateformat varbinary(90) DEFAULT 'd M Y H:i' NOT NULL, user_style mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, user_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 9615905625..30fb7a8623 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -914,8 +914,7 @@ CREATE TABLE phpbb_users ( user_inactive_time int(11) UNSIGNED DEFAULT '0' NOT NULL, user_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, user_lang varchar(30) DEFAULT '' NOT NULL, - user_timezone decimal(5,2) DEFAULT '0' NOT NULL, - user_dst tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, + user_timezone varchar(100) DEFAULT 'UTC' NOT NULL, user_dateformat varchar(30) DEFAULT 'd M Y H:i' NOT NULL, user_style mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, user_rank mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 5d60d2a19e..a4b8686948 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -1702,8 +1702,7 @@ CREATE TABLE phpbb_users ( user_inactive_time number(11) DEFAULT '0' NOT NULL, user_posts number(8) DEFAULT '0' NOT NULL, user_lang varchar2(30) DEFAULT '' , - user_timezone number(5, 2) DEFAULT '0' NOT NULL, - user_dst number(1) DEFAULT '0' NOT NULL, + user_timezone varchar2(100) DEFAULT 'UTC' NOT NULL, user_dateformat varchar2(90) DEFAULT 'd M Y H:i' NOT NULL, user_style number(8) DEFAULT '0' NOT NULL, user_rank number(8) DEFAULT '0' NOT NULL, diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index d7377ac2e6..7138c818ff 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -1172,8 +1172,7 @@ CREATE TABLE phpbb_users ( user_inactive_time INT4 DEFAULT '0' NOT NULL CHECK (user_inactive_time >= 0), user_posts INT4 DEFAULT '0' NOT NULL CHECK (user_posts >= 0), user_lang varchar(30) DEFAULT '' NOT NULL, - user_timezone decimal(5,2) DEFAULT '0' NOT NULL, - user_dst INT2 DEFAULT '0' NOT NULL CHECK (user_dst >= 0), + user_timezone varchar(100) DEFAULT 'UTC' NOT NULL, user_dateformat varchar(30) DEFAULT 'd M Y H:i' NOT NULL, user_style INT4 DEFAULT '0' NOT NULL CHECK (user_style >= 0), user_rank INT4 DEFAULT '0' NOT NULL CHECK (user_rank >= 0), diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 257937275c..5066ac97df 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -886,8 +886,7 @@ CREATE TABLE phpbb_users ( user_inactive_time INTEGER UNSIGNED NOT NULL DEFAULT '0', user_posts INTEGER UNSIGNED NOT NULL DEFAULT '0', user_lang varchar(30) NOT NULL DEFAULT '', - user_timezone decimal(5,2) NOT NULL DEFAULT '0', - user_dst INTEGER UNSIGNED NOT NULL DEFAULT '0', + user_timezone varchar(100) NOT NULL DEFAULT 'UTC', user_dateformat varchar(30) NOT NULL DEFAULT 'd M Y H:i', user_style INTEGER UNSIGNED NOT NULL DEFAULT '0', user_rank INTEGER UNSIGNED NOT NULL DEFAULT '0', From 1665434853fb09e70337d23955e1c9a5f3f0d19d Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 7 Jul 2010 23:42:54 +0100 Subject: [PATCH 19/75] [feature/new-tz-handling] Remove code using legacy timezone properties. Code accessing the legacy user::$timezone and user::$dst properties has been removed and replaced with code utilising user::create_datetime(). Changed by Oleg: in viewtopic, memberlist and index use getTimestamp() + getOffset(). We show members that have birthdays on the specified date. getTimestamp() returns the current date in UTC. We add getOffset() to obtain the current local time in the viewing user's timezone. Then we find members having birthday on this date. Changed by Oleg again: Take leap year status out of the datetime object we have, this seems like it should work as one would expect. PHPBB3-9558 --- phpBB/feed.php | 2 +- phpBB/includes/functions_profile_fields.php | 9 ++++++--- phpBB/index.php | 5 +++-- phpBB/memberlist.php | 3 ++- phpBB/viewtopic.php | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/phpBB/feed.php b/phpBB/feed.php index b8c0c370f9..d7092d6758 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -255,7 +255,7 @@ function feed_format_date($time) { global $user; - $zone_offset = (int) $user->timezone + (int) $user->dst; + $zone_offset = $user->create_datetime()->getOffset(); $sign = ($zone_offset < 0) ? '-' : '+'; $time_offset = abs($zone_offset); diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index ec29a1732d..aacfa82c54 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -555,9 +555,12 @@ class custom_profile else if ($day && $month && $year) { global $user; - // Date should display as the same date for every user regardless of timezone, so remove offset - // to compensate for the offset added by user::format_date() - return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) - ($user->timezone + $user->dst), $user->lang['DATE_FORMAT'], true); + // Date should display as the same date for every user regardless of timezone + + return $user->create_datetime() + ->setDate($year, $month, $day) + ->setTime(0, 0, 0) + ->format($user->lang['DATE_FORMAT'], true); } return $value; diff --git a/phpBB/index.php b/phpBB/index.php index 182efbc7e0..ccefd9833c 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -84,11 +84,12 @@ $legend = implode(', ', $legend); $birthday_list = array(); if ($config['load_birthdays'] && $config['allow_birthdays'] && $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')) { - $now = phpbb_gmgetdate(time() + $user->timezone + $user->dst); + $time = $user->create_datetime(); + $now = phpbb_gmgetdate($time->getTimestamp() + $time->getOffset()); // Display birthdays of 29th february on 28th february in non-leap-years $leap_year_birthdays = ''; - if ($now['mday'] == 28 && $now['mon'] == 2 && !$user->format_date(time(), 'L')) + if ($now['mday'] == 28 && $now['mon'] == 2 && !$time->format('L')) { $leap_year_birthdays = " OR user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', 29, 2)) . "%'"; } diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 556db2fa5d..ea8a6fc44b 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1684,7 +1684,8 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f if ($bday_year) { - $now = phpbb_gmgetdate(time() + $user->timezone + $user->dst); + $now = $user->create_datetime(); + $now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset()); $diff = $now['mon'] - $bday_month; if ($diff == 0) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index e78ba73cd7..782f02fd4b 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -965,7 +965,8 @@ $sql_ary = array( $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); -$now = phpbb_gmgetdate(time() + $user->timezone + $user->dst); +$now = $user->create_datetime(); +$now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset()); // Posts are stored in the $rowset array while $attach_list, $user_cache // and the global bbcode_bitfield are built From 0f320a6c48d63154bba45c2937adeee79165816c Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 8 Jul 2010 21:56:51 +0100 Subject: [PATCH 20/75] [feature/new-tz-handling] Update tz_select() to use the PHP timezone database. tz_select() now uses the PHP timezone database to generate the timezone selection box, it tries to use a translated language string otherwise falls back to a label produced from the timezone identifier. I've done this so new timezones are available immediately without a new language pack. PHPBB3-9558 --- phpBB/includes/functions.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9e2e57dd5e..fb8ea93e32 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1071,28 +1071,45 @@ function style_select($default = '', $all = false) /** * Pick a timezone +* @todo Possible HTML escaping */ function tz_select($default = '', $truncate = false) { global $user; - $tz_select = ''; - foreach ($user->lang['tz_zones'] as $offset => $zone) + static $timezones; + + if (!isset($timezones)) { - if ($truncate) + $timezones = DateTimeZone::listIdentifiers(); + + sort($timezones); + } + + $tz_select = ''; + + foreach ($timezones as $timezone) + { + if (isset($user->lang['timezones'][$timezone])) { - $zone_trunc = truncate_string($zone, 50, 255, false, '...'); + $title = $label = $user->lang['timezones'][$timezone]; } else { - $zone_trunc = $zone; + // No label, we'll figure one out + // @todo rtl languages? + $bits = explode('/', strtolower(str_replace('_', ' ', $timezone))); + + $title = $label = ucwords(implode(' - ', $bits)); } - if (is_numeric($offset)) + if ($truncate) { - $selected = ($offset == $default) ? ' selected="selected"' : ''; - $tz_select .= ''; + $label = truncate_string($label, 50, 255, false, '...'); } + + $selected = ($timezone === $default) ? ' selected="selected"' : ''; + $tz_select .= ''; } return $tz_select; From 190b019fa28f59c018554916e33446d93efb7311 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 8 Jul 2010 22:09:24 +0100 Subject: [PATCH 21/75] [feature/new-tz-handling] Remove case mangling, the identifiers are correct. PHPBB3-9558 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index fb8ea93e32..69bfe3e090 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1098,9 +1098,9 @@ function tz_select($default = '', $truncate = false) { // No label, we'll figure one out // @todo rtl languages? - $bits = explode('/', strtolower(str_replace('_', ' ', $timezone))); + $bits = explode('/', str_replace('_', ' ', $timezone)); - $title = $label = ucwords(implode(' - ', $bits)); + $title = $label = implode(' - ', $bits); } if ($truncate) From f17664a00c9fa3b80a887bde2cdb2424a5d5567a Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 9 Jul 2010 20:39:30 +0100 Subject: [PATCH 22/75] [feature/new-tz-handling] Correct a bug preventing multiple formats working. PHPBB3-9558 --- phpBB/includes/datetime.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/phpBB/includes/datetime.php b/phpBB/includes/datetime.php index 22b7f871fd..15e3c8b0b7 100644 --- a/phpBB/includes/datetime.php +++ b/phpBB/includes/datetime.php @@ -149,22 +149,22 @@ class phpbb_datetime extends DateTime if (!isset(self::$format_cache[$lang])) { self::$format_cache[$lang] = array(); + } - if (!isset(self::$format_cache[$lang][$format])) + if (!isset(self::$format_cache[$lang][$format])) + { + // Is the user requesting a friendly date format (i.e. 'Today 12:42')? + self::$format_cache[$lang][$format] = array( + 'is_short' => strpos($format, self::RELATIVE_WRAPPER) !== false, + 'format_short' => substr($format, 0, strpos($format, self::RELATIVE_WRAPPER)) . self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER . substr(strrchr($format, self::RELATIVE_WRAPPER), 1), + 'format_long' => str_replace(self::RELATIVE_WRAPPER, '', $format), + 'lang' => $user->lang['datetime'], + ); + + // Short representation of month in format? Some languages use different terms for the long and short format of May + if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) { - // Is the user requesting a friendly date format (i.e. 'Today 12:42')? - self::$format_cache[$lang][$format] = array( - 'is_short' => strpos($format, self::RELATIVE_WRAPPER) !== false, - 'format_short' => substr($format, 0, strpos($format, self::RELATIVE_WRAPPER)) . self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER . substr(strrchr($format, self::RELATIVE_WRAPPER), 1), - 'format_long' => str_replace(self::RELATIVE_WRAPPER, '', $format), - 'lang' => $user->lang['datetime'], - ); - - // Short representation of month in format? Some languages use different terms for the long and short format of May - if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) - { - self::$format_cache[$lang][$format]['lang']['May'] = $user->lang['datetime']['May_short']; - } + self::$format_cache[$lang][$format]['lang']['May'] = $user->lang['datetime']['May_short']; } } From bb461c8daa97358e8bcce923a21eba0abd6ea3dc Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 Mar 2011 19:14:53 -0500 Subject: [PATCH 23/75] [feature/new-tz-handling] Sort timezones in selector by offset. Since the list of timezones is very long, and users are likely to know their current offset but not necessarily which city that is nearby is in the timezone database, sort the list of timezones by offset. UTC is specially handled to show up before other GMT+0 timezones. PHPBB3-9558 --- phpBB/feed.php | 10 +---- phpBB/includes/functions.php | 71 +++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/phpBB/feed.php b/phpBB/feed.php index d7092d6758..025904e682 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -256,15 +256,7 @@ function feed_format_date($time) global $user; $zone_offset = $user->create_datetime()->getOffset(); - - $sign = ($zone_offset < 0) ? '-' : '+'; - $time_offset = abs($zone_offset); - - $offset_seconds = $time_offset % 3600; - $offset_minutes = $offset_seconds / 60; - $offset_hours = ($time_offset - $offset_seconds) / 3600; - - $offset_string = sprintf("%s%02d:%02d", $sign, $offset_hours, $offset_minutes); + $offset_string = phpbb_format_timezone_offset($zone_offset); } return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 69bfe3e090..31a191b513 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1069,6 +1069,65 @@ function style_select($default = '', $all = false) return $style_options; } +function phpbb_format_timezone_offset($tz_offset) +{ + $sign = ($tz_offset < 0) ? '-' : '+'; + $time_offset = abs($tz_offset); + + $offset_seconds = $time_offset % 3600; + $offset_minutes = $offset_seconds / 60; + $offset_hours = ($time_offset - $offset_seconds) / 3600; + + $offset_string = sprintf("%s%02d:%02d", $sign, $offset_hours, $offset_minutes); + return $offset_string; +} + +// Compares two time zone labels. +// Arranges them in increasing order by timezone offset. +// Places UTC before other timezones in the same offset. +function tz_select_compare($a, $b) +{ + $a_sign = $a[3]; + $b_sign = $b[3]; + if ($a_sign != $b_sign) + { + return $a_sign == '-' ? -1 : 1; + } + + $a_offset = substr($a, 4, 5); + $b_offset = substr($b, 4, 5); + if ($a_offset == $b_offset) + { + $a_name = substr($a, 12); + $b_name = substr($b, 12); + if ($a_name == $b_name) + { + return 0; + } else if ($a_name == 'UTC') + { + return -1; + } else if ($b_name == 'UTC') + { + return 1; + } + else + { + return $a_name < $b_name ? -1 : 1; + } + } + else + { + if ($a_sign == '-') + { + return $a_offset > $b_offset ? -1 : 1; + } + else + { + return $a_offset < $b_offset ? -1 : 1; + } + } +} + /** * Pick a timezone * @todo Possible HTML escaping @@ -1083,7 +1142,17 @@ function tz_select($default = '', $truncate = false) { $timezones = DateTimeZone::listIdentifiers(); - sort($timezones); + foreach ($timezones as &$timezone) + { + $tz = new DateTimeZone($timezone); + $dt = new phpbb_datetime('now', $tz); + $offset = $dt->getOffset(); + $offset_string = phpbb_format_timezone_offset($offset); + $timezone = 'GMT' . $offset_string . ' - ' . $timezone; + } + unset($timezone); + + usort($timezones, 'tz_select_compare'); } $tz_select = ''; From da8009603d05acdccaff15cd610353d85c365220 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Mar 2011 07:45:43 -0400 Subject: [PATCH 24/75] [feature/new-tz-handling] Preselect a timezone in registration. Use Javascript to obtain client's timezone offset and select the first timezone in our list with that offset. Changes for prosilver only. The javascript file should be shared between styles. PHPBB3-9558 --- phpBB/language/en/ucp.php | 1 + phpBB/styles/prosilver/template/timezone.js | 54 +++++++++++++++++++ .../template/ucp_prefs_personal.html | 10 +++- .../prosilver/template/ucp_register.html | 10 +++- 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 phpBB/styles/prosilver/template/timezone.js diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index c8ffbf31c0..9cbca4b740 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -399,6 +399,7 @@ $lang = array_merge($lang, array( 'SIGNATURE_EXPLAIN' => 'This is a block of text that can be added to posts you make. There is a %d character limit.', 'SIGNATURE_PREVIEW' => 'Your signature will appear like this in posts', 'SIGNATURE_TOO_LONG' => 'Your signature is too long.', + 'SELECT_TIMEZONE' => 'Select timezone', 'SORT' => 'Sort', 'SORT_COMMENT' => 'File comment', 'SORT_DOWNLOADS' => 'Downloads', diff --git a/phpBB/styles/prosilver/template/timezone.js b/phpBB/styles/prosilver/template/timezone.js new file mode 100644 index 0000000000..5d07b1d3ad --- /dev/null +++ b/phpBB/styles/prosilver/template/timezone.js @@ -0,0 +1,54 @@ +function phpbb_preselect_tz_select() +{ + var selector = document.getElementsByClassName('tz_select')[0]; + if (selector.value) + { + return; + } + // The offset returned here is in minutes and negated. + // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp + var offset = (new Date()).getTimezoneOffset(); + if (offset < 0) + { + var sign = '+'; + offset = -offset; + } + else + { + var sign = '-'; + } + var minutes = offset % 60; + var hours = (offset - minutes) / 60; + if (hours < 10) + { + hours = '0' + hours.toString(); + } + else + { + hours = hours.toString(); + } + if (minutes < 10) + { + minutes = '0' + minutes.toString(); + } + else + { + minutes = minutes.toString(); + } + var prefix = 'GMT' + sign + hours + ':' + minutes; + var prefix_length = prefix.length; + for (var i = 0; i < selector.options.length; ++i) + { + var option = selector.options[i]; + if (option.value.substring(0, prefix_length) == prefix) + { + // Firefox scrolls the selector only to put the option into view; + // for negative-offset timezones, this means the first timezone + // of a particular offset will be the bottom one, and selected, + // with all other timezones not visible. Not much can be done + // about that here unfortunately. + option.selected = true; + break; + } + } +} diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 635f321469..eae37b8021 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -75,7 +75,12 @@
-
+
+ +
@@ -141,4 +146,7 @@ // ]]> + + + diff --git a/phpBB/styles/prosilver/template/ucp_register.html b/phpBB/styles/prosilver/template/ucp_register.html index dd0e5ad02a..542a860f23 100644 --- a/phpBB/styles/prosilver/template/ucp_register.html +++ b/phpBB/styles/prosilver/template/ucp_register.html @@ -59,7 +59,12 @@
-
+
+ +
@@ -110,4 +115,7 @@ + + + From 56a7038aa57a1ec473196e01f68b7c8a1d0a89b6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Mar 2011 07:56:21 -0400 Subject: [PATCH 25/75] [feature/new-tz-handling] Removed DST options from templates. PHPBB3-9558 --- phpBB/adm/style/acp_users_prefs.html | 5 ----- phpBB/styles/prosilver/template/ucp_prefs_personal.html | 7 ------- phpBB/styles/subsilver2/template/ucp_prefs_personal.html | 4 ---- 3 files changed, 16 deletions(-) diff --git a/phpBB/adm/style/acp_users_prefs.html b/phpBB/adm/style/acp_users_prefs.html index a519447b2f..90db62984e 100644 --- a/phpBB/adm/style/acp_users_prefs.html +++ b/phpBB/adm/style/acp_users_prefs.html @@ -56,11 +56,6 @@
-
-
-
-
-

{L_BOARD_DATE_FORMAT_EXPLAIN}
diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index eae37b8021..267a3b8c2f 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -82,13 +82,6 @@
-
-
-
- - -
-

{L_BOARD_DATE_FORMAT_EXPLAIN}
diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index 8e4b04fc10..357e1fe100 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -77,10 +77,6 @@ - - {L_BOARD_DST}: - checked="checked" /> {L_YES}   checked="checked" /> {L_NO} - {L_BOARD_DATE_FORMAT}:
{L_BOARD_DATE_FORMAT_EXPLAIN} From e8e5d2b2c000e8a91897b4044c6a3005f60b86ab Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Mar 2011 17:37:15 -0400 Subject: [PATCH 26/75] [feature/new-tz-handling] Removed DST and numeric timezone-related language. PHPBB3-9558 --- phpBB/language/en/acp/board.php | 1 - phpBB/language/en/common.php | 87 --------------------------------- phpBB/language/en/help_faq.php | 2 +- phpBB/language/en/ucp.php | 1 - 4 files changed, 1 insertion(+), 90 deletions(-) diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index ff516a8146..0be4c0df6d 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -49,7 +49,6 @@ $lang = array_merge($lang, array( 'OVERRIDE_STYLE_EXPLAIN' => 'Replaces user’s style with the default.', 'SITE_DESC' => 'Site description', 'SITE_NAME' => 'Site name', - 'SYSTEM_DST' => 'Enable Summer Time/DST', 'SYSTEM_TIMEZONE' => 'Guest timezone', 'SYSTEM_TIMEZONE_EXPLAIN' => 'Timezone to use for displaying times to users who are not logged in (guests, bots). Logged in users set their timezone during registration and can change it in their user control panel.', 'WARNINGS_EXPIRE' => 'Warning duration', diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 44a63a6acb..bcb08a8b73 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -786,93 +786,6 @@ $lang = array_merge($lang, array( 'Dec' => 'Dec', ), - 'tz' => array( - '-12' => 'UTC - 12 hours', - '-11' => 'UTC - 11 hours', - '-10' => 'UTC - 10 hours', - '-9.5' => 'UTC - 9:30 hours', - '-9' => 'UTC - 9 hours', - '-8' => 'UTC - 8 hours', - '-7' => 'UTC - 7 hours', - '-6' => 'UTC - 6 hours', - '-5' => 'UTC - 5 hours', - '-4.5' => 'UTC - 4:30 hours', - '-4' => 'UTC - 4 hours', - '-3.5' => 'UTC - 3:30 hours', - '-3' => 'UTC - 3 hours', - '-2' => 'UTC - 2 hours', - '-1' => 'UTC - 1 hour', - '0' => 'UTC', - '1' => 'UTC + 1 hour', - '2' => 'UTC + 2 hours', - '3' => 'UTC + 3 hours', - '3.5' => 'UTC + 3:30 hours', - '4' => 'UTC + 4 hours', - '4.5' => 'UTC + 4:30 hours', - '5' => 'UTC + 5 hours', - '5.5' => 'UTC + 5:30 hours', - '5.75' => 'UTC + 5:45 hours', - '6' => 'UTC + 6 hours', - '6.5' => 'UTC + 6:30 hours', - '7' => 'UTC + 7 hours', - '8' => 'UTC + 8 hours', - '8.75' => 'UTC + 8:45 hours', - '9' => 'UTC + 9 hours', - '9.5' => 'UTC + 9:30 hours', - '10' => 'UTC + 10 hours', - '10.5' => 'UTC + 10:30 hours', - '11' => 'UTC + 11 hours', - '11.5' => 'UTC + 11:30 hours', - '12' => 'UTC + 12 hours', - '12.75' => 'UTC + 12:45 hours', - '13' => 'UTC + 13 hours', - '14' => 'UTC + 14 hours', - 'dst' => '[ DST ]', - ), - - 'tz_zones' => array( - '-12' => '[UTC - 12] Baker Island Time', - '-11' => '[UTC - 11] Niue Time, Samoa Standard Time', - '-10' => '[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time', - '-9.5' => '[UTC - 9:30] Marquesas Islands Time', - '-9' => '[UTC - 9] Alaska Standard Time, Gambier Island Time', - '-8' => '[UTC - 8] Pacific Standard Time', - '-7' => '[UTC - 7] Mountain Standard Time', - '-6' => '[UTC - 6] Central Standard Time', - '-5' => '[UTC - 5] Eastern Standard Time', - '-4.5' => '[UTC - 4:30] Venezuelan Standard Time', - '-4' => '[UTC - 4] Atlantic Standard Time', - '-3.5' => '[UTC - 3:30] Newfoundland Standard Time', - '-3' => '[UTC - 3] Amazon Standard Time, Central Greenland Time', - '-2' => '[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time', - '-1' => '[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time', - '0' => '[UTC] Western European Time, Greenwich Mean Time', - '1' => '[UTC + 1] Central European Time, West African Time', - '2' => '[UTC + 2] Eastern European Time, Central African Time', - '3' => '[UTC + 3] Moscow Standard Time, Eastern African Time', - '3.5' => '[UTC + 3:30] Iran Standard Time', - '4' => '[UTC + 4] Gulf Standard Time, Samara Standard Time', - '4.5' => '[UTC + 4:30] Afghanistan Time', - '5' => '[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time', - '5.5' => '[UTC + 5:30] Indian Standard Time, Sri Lanka Time', - '5.75' => '[UTC + 5:45] Nepal Time', - '6' => '[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time', - '6.5' => '[UTC + 6:30] Cocos Islands Time, Myanmar Time', - '7' => '[UTC + 7] Indochina Time, Krasnoyarsk Standard Time', - '8' => '[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time', - '8.75' => '[UTC + 8:45] Southeastern Western Australia Standard Time', - '9' => '[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time', - '9.5' => '[UTC + 9:30] Australian Central Standard Time', - '10' => '[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time', - '10.5' => '[UTC + 10:30] Lord Howe Standard Time', - '11' => '[UTC + 11] Solomon Island Time, Magadan Standard Time', - '11.5' => '[UTC + 11:30] Norfolk Island Time', - '12' => '[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time', - '12.75' => '[UTC + 12:45] Chatham Islands Time', - '13' => '[UTC + 13] Tonga Time, Phoenix Islands Time', - '14' => '[UTC + 14] Line Island Time', - ), - // The value is only an example and will get replaced by the current time on view 'dateformats' => array( 'd M Y, H:i' => '01 Jan 2007, 13:37', diff --git a/phpBB/language/en/help_faq.php b/phpBB/language/en/help_faq.php index 6ca9589913..5f9af2d721 100644 --- a/phpBB/language/en/help_faq.php +++ b/phpBB/language/en/help_faq.php @@ -88,7 +88,7 @@ $help = array( ), array( 0 => 'I changed the timezone and the time is still wrong!', - 1 => 'If you are sure you have set the timezone and Summer Time/DST correctly and the time is still incorrect, then the time stored on the server clock is incorrect. Please notify an administrator to correct the problem.' + 1 => 'If you are sure you have set the timezone correctly and the time is still incorrect, then the time stored on the server clock is incorrect. Please notify an administrator to correct the problem.' ), array( 0 => 'My language is not in the list!', diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 9cbca4b740..3925005968 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -103,7 +103,6 @@ $lang = array_merge($lang, array( 'BIRTHDAY_EXPLAIN' => 'Setting a year will list your age when it is your birthday.', 'BOARD_DATE_FORMAT' => 'My date format', 'BOARD_DATE_FORMAT_EXPLAIN' => 'The syntax used is identical to the PHP date() function.', - 'BOARD_DST' => 'Summer Time/DST is in effect', 'BOARD_LANGUAGE' => 'My language', 'BOARD_STYLE' => 'My board style', 'BOARD_TIMEZONE' => 'My timezone', From b672fc7ae113c0e01f1d7ce4ffae3eb26e57b586 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 26 Apr 2011 22:11:45 -0400 Subject: [PATCH 27/75] [feature/new-tz-handling] Started on database updater changes. The changes are tricky since we need to drop user_dst column from users table, but we need it during the data migration process to properly calculate effective timezones for all users. The change here converts user_timezone to vchar and computes timezone identifiers from the offsets. It uses database-specific functions for building SQL conditionals and concatenations which need to be implemented, probably in a separate ticket. As a result the current code is not functional. PHPBB3-9558 --- phpBB/install/database_update.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index fa0fba9dc7..9d550cf938 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1090,6 +1090,9 @@ function database_update_info() GROUPS_TABLE => array( 'group_legend' => array('UINT', 0), ), + USERS_TABLE => array( + 'user_timezone' => array('VCHAR:100', ''), + ), ), 'drop_columns' => array( STYLES_TABLE => array( @@ -2352,6 +2355,25 @@ function change_database_data(&$no_updates, $version) set_config('teampage_memberships', '1'); } + // Update timezones + // user_dst is 0 if not in dst and 1 if in dst; + // this happens to be exactly the correction that should be added to the timezone offset + // to obtain dst offset. + // Parenthesize here because we operate on this value later. + $active_offset = '(user_timezone + user_dst)'; + // Now we have a tricky problem of forcing the plus sign into the expression. + // Build it via a conditional since there cannot be a portable printf equivalent in databases. + // Note that active offset is not an absolute value here - it is an expression that will + // be evaluated by the database during query execution. + // We don't print - here because it will come from active offset. + $sign = $db->conditional_sql("$active_offset < 0", '', '+'); + // Use database-specific escaping because strings are quoted differently by different databases. + $new_value = $db->concatenate_sql($db->sql_escape('GMT'), $sign, $active_offset); + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_timezone = ' . $new_value; + _sql($sql, $errored, $error_ary); + // After we have calculated the timezones we can delete user_dst column from user table. + $no_updates = false; break; } From 50936cb2eff3f80d99390c76ef6ac535e73f6cc3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 19:06:46 +0200 Subject: [PATCH 28/75] [feature/new-tz-handling] Fix selecting and validating of timezone in UCP PHPBB3-9558 --- phpBB/includes/functions.php | 24 ++++++++++++++---------- phpBB/includes/functions_user.php | 16 ++++++++++++++++ phpBB/includes/ucp/ucp_prefs.php | 4 ++-- phpBB/language/en/ucp.php | 1 + 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3ec4b76091..55f7f0531c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1139,34 +1139,38 @@ function tz_select($default = '', $truncate = false) if (!isset($timezones)) { - $timezones = DateTimeZone::listIdentifiers(); + $unsorted_timezones = DateTimeZone::listIdentifiers(); + $timezones = array(); - foreach ($timezones as &$timezone) + foreach ($unsorted_timezones as $timezone) { $tz = new DateTimeZone($timezone); $dt = new phpbb_datetime('now', $tz); $offset = $dt->getOffset(); $offset_string = phpbb_format_timezone_offset($offset); - $timezone = 'GMT' . $offset_string . ' - ' . $timezone; + $timezones['GMT' . $offset_string . ' - ' . $timezone] = array( + 'tz' => $timezone, + 'label' => 'GMT' . $offset_string . ' - ' . $timezone, + ); } - unset($timezone); + unset($unsorted_timezones); - usort($timezones, 'tz_select_compare'); + uksort($timezones, 'tz_select_compare'); } $tz_select = ''; foreach ($timezones as $timezone) { - if (isset($user->lang['timezones'][$timezone])) + if (isset($user->lang['timezones'][$timezone['tz']])) { - $title = $label = $user->lang['timezones'][$timezone]; + $title = $label = $user->lang['timezones'][$timezone['tz']]; } else { // No label, we'll figure one out // @todo rtl languages? - $bits = explode('/', str_replace('_', ' ', $timezone)); + $bits = explode('/', str_replace('_', ' ', $timezone['label'])); $title = $label = implode(' - ', $bits); } @@ -1176,8 +1180,8 @@ function tz_select($default = '', $truncate = false) $label = truncate_string($label, 50, 255, false, '...'); } - $selected = ($timezone === $default) ? ' selected="selected"' : ''; - $tz_select .= ''; + $selected = ($timezone['tz'] === $default) ? ' selected="selected"' : ''; + $tz_select .= ''; } return $tz_select; diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9b102b7387..3a77407c20 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1395,6 +1395,22 @@ function validate_language_iso_name($lang_iso) return ($lang_id) ? false : 'WRONG_DATA'; } +/** +* Validate Timezone Name +* +* Tests whether a timezone name is valid +* +* @param string $timezone The timezone string to test +* +* @return bool|string Either false if validation succeeded or +* a string which will be used as the error message +* (with the variable name appended) +*/ +function validate_timezone($timezone) +{ + return (in_array($timezone, DateTimeZone::listIdentifiers())) ? false : 'TIMEZONE_INVALID'; +} + /** * Check to see if the username has been taken, or if it is disallowed. * Also checks if it includes the " character, which we don't allow in usernames. diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 0c9f20f266..45e3bb8951 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -41,7 +41,7 @@ class ucp_prefs 'dateformat' => request_var('dateformat', $user->data['user_dateformat'], true), 'lang' => basename(request_var('lang', $user->data['user_lang'])), 'style' => request_var('style', (int) $user->data['user_style']), - 'tz' => request_var('tz', (float) $user->data['user_timezone']), + 'tz' => request_var('tz', $user->data['user_timezone']), 'dst' => request_var('dst', (bool) $user->data['user_dst']), 'viewemail' => request_var('viewemail', (bool) $user->data['user_allow_viewemail']), @@ -72,7 +72,7 @@ class ucp_prefs $error = validate_data($data, array( 'dateformat' => array('string', false, 1, 30), 'lang' => array('language_iso_name'), - 'tz' => array('num', false, -14, 14), + 'tz' => array('timezone'), )); if (!check_form_key('ucp_prefs_personal')) diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index a80862890a..f9558bc6d3 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -422,6 +422,7 @@ $lang = array_merge($lang, array( 'SORT_SIZE' => 'File size', 'TIMEZONE' => 'Timezone', + 'TIMEZONE_INVALID' => 'The timezone you selected is invalid.', 'TO' => 'To', 'TOO_MANY_RECIPIENTS' => 'You tried to send a private message to too many recipients.', 'TOO_MANY_REGISTERS' => 'You have exceeded the maximum number of registration attempts for this session. Please try again later.', From 00b5e5345dc44c99340bba932522b6b05b48dab2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 19:19:34 +0200 Subject: [PATCH 29/75] [feature/new-tz-handling] Fix displaying of "All times are" string PHPBB3-9558 --- phpBB/includes/functions.php | 10 +++++++++- phpBB/language/en/common.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 55f7f0531c..44346c7795 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4769,6 +4769,14 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } } + $dt = new phpbb_datetime('now', $user->tz); + $timezone_offset = 'GMT' . phpbb_format_timezone_offset($dt->getOffset()); + $timezone_name = $user->tz->getName(); + if (isset($user->lang['timezones'][$timezone_name])) + { + $timezone_name = $user->lang['timezones'][$timezone_name]; + } + // The following assigns all _common_ variables that may be used at any point in a template. $template->assign_vars(array( 'SITENAME' => $config['sitename'], @@ -4836,7 +4844,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right', 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left', 'S_CONTENT_ENCODING' => 'UTF-8', - 'S_TIMEZONE' => ($user->data['user_dst'] || ($user->data['user_id'] == ANONYMOUS && $config['board_dst'])) ? sprintf($user->lang['ALL_TIMES'], $user->lang['tz'][$tz], $user->lang['tz']['dst']) : sprintf($user->lang['ALL_TIMES'], $user->lang['tz'][$tz], ''), + 'S_TIMEZONE' => sprintf($user->lang['ALL_TIMES'], $timezone_offset, $timezone_name), 'S_DISPLAY_ONLINE_LIST' => ($l_online_time) ? 1 : 0, 'S_DISPLAY_SEARCH' => (!$config['load_search']) ? 0 : (isset($auth) ? ($auth->acl_get('u_search') && $auth->acl_getf_global('f_search')) : 1), 'S_DISPLAY_PM' => ($config['allow_privmsg'] && !empty($user->data['is_registered']) && ($auth->acl_get('u_readpm') || $auth->acl_get('u_sendpm'))) ? true : false, diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 023ee2c89f..bbafb54108 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -74,7 +74,7 @@ $lang = array_merge($lang, array( 'ALL_FORUMS' => 'All forums', 'ALL_MESSAGES' => 'All messages', 'ALL_POSTS' => 'All posts', - 'ALL_TIMES' => 'All times are %1$s %2$s', + 'ALL_TIMES' => 'All times are %1$s', 'ALL_TOPICS' => 'All Topics', 'AND' => 'And', 'ARE_WATCHING_FORUM' => 'You have subscribed to be notified of new posts in this forum.', From 09499fb128802bd19cee1550bf6e9af80a9388e2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 22:33:03 +0200 Subject: [PATCH 30/75] [feature/new-tz-handling] Fix handling of timezone and dst in dateformat_select PHPBB3-9558 --- phpBB/includes/acp/acp_board.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index d537885ef1..ce2ddc3b0b 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -906,11 +906,13 @@ class acp_board global $user, $config; // Let the format_date function operate with the acp values - $old_tz = $user->timezone; - $old_dst = $user->dst; - - $user->timezone = $config['board_timezone'] * 3600; - $user->dst = $config['board_dst'] * 3600; + $old_tz = $user->tz; + if (is_numeric($config['board_timezone'])) + { + // Might still be numeric by chance + $config['board_timezone'] = sprintf('Etc/GMT%+d', $config['board_timezone']); + } + $user->tz = new DateTimeZone($config['board_timezone']); $dateformat_options = ''; @@ -929,8 +931,7 @@ class acp_board $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . ''; // Reset users date options - $user->timezone = $old_tz; - $user->dst = $old_dst; + $user->tz = $old_tz; return " "; From 66ae9ee2ea8b65ddb4c39b4bc9add8d2aca2e73d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 22:39:35 +0200 Subject: [PATCH 31/75] [feature/new-tz-handling] Fix timezone selection on registration page PHPBB3-9558 --- phpBB/includes/ucp/ucp_register.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 5d85029e62..aee55711b2 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -100,7 +100,7 @@ class ucp_register 'username' => utf8_normalize_nfc(request_var('username', '', true)), 'email' => strtolower(request_var('email', '')), 'lang' => $user->lang_name, - 'tz' => request_var('tz', (float) $config['board_timezone']), + 'tz' => request_var('tz', $config['board_timezone']), )); } @@ -172,7 +172,7 @@ class ucp_register 'password_confirm' => request_var('password_confirm', '', true), 'email' => strtolower(request_var('email', '')), 'lang' => basename(request_var('lang', $user->lang_name)), - 'tz' => request_var('tz', (float) $timezone), + 'tz' => request_var('tz', $timezone), ); // Check and initialize some variables if needed @@ -189,7 +189,7 @@ class ucp_register 'email' => array( array('string', false, 6, 60), array('email')), - 'tz' => array('num', false, -14, 14), + 'tz' => array('timezone'), 'lang' => array('language_iso_name'), )); @@ -279,7 +279,7 @@ class ucp_register 'user_password' => phpbb_hash($data['new_password']), 'user_email' => $data['email'], 'group_id' => (int) $group_id, - 'user_timezone' => (float) $data['tz'], + 'user_timezone' => $data['tz'], 'user_dst' => $is_dst, 'user_lang' => $data['lang'], 'user_type' => $user_type, @@ -453,7 +453,7 @@ class ucp_register 'L_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])), 'S_LANG_OPTIONS' => language_select($data['lang']), - 'S_TZ_OPTIONS' => tz_select($data['tz']), + 'S_TZ_OPTIONS' => tz_select($data['tz'], true), 'S_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false, 'S_REGISTRATION' => true, 'S_COPPA' => $coppa, From f9bc8252641ec69983acfc6d392770934b7a37a4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 22:40:09 +0200 Subject: [PATCH 32/75] [feature/new-tz-handling] Fix timezone validation in ACP user section PHPBB3-9558 --- phpBB/includes/acp/acp_users.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 17687b05c7..825bba514f 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1458,7 +1458,7 @@ class acp_users $data = array( 'dateformat' => utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)), 'lang' => basename(request_var('lang', $user_row['user_lang'])), - 'tz' => request_var('tz', (float) $user_row['user_timezone']), + 'tz' => request_var('tz', $user_row['user_timezone']), 'style' => request_var('style', $user_row['user_style']), 'dst' => request_var('dst', $user_row['user_dst']), 'viewemail' => request_var('viewemail', $user_row['user_allow_viewemail']), @@ -1495,7 +1495,7 @@ class acp_users $error = validate_data($data, array( 'dateformat' => array('string', false, 1, 30), 'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'), - 'tz' => array('num', false, -14, 14), + 'tz' => array('timezone'), 'topic_sk' => array('string', false, 1, 1), 'topic_sd' => array('string', false, 1, 1), From 963d4afc2cf5fb2903ed02ada20cdbf0188d57db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 23:14:41 +0200 Subject: [PATCH 33/75] [feature/new-tz-handling] Replace gmmktime() and mktime() with phpbb_datetime PHPBB3-9558 --- phpBB/includes/functions_user.php | 7 ++++--- phpBB/includes/ucp/ucp_register.php | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3a77407c20..f235b2be55 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -197,7 +197,6 @@ function user_add($user_row, $cp_data = false) 'user_lastpost_time' => 0, 'user_lastpage' => '', 'user_posts' => 0, - 'user_dst' => (int) $config['board_dst'], 'user_colour' => '', 'user_occ' => '', 'user_interests' => '', @@ -677,8 +676,10 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas if (sizeof($ban_other) == 3 && ((int)$ban_other[0] < 9999) && (strlen($ban_other[0]) == 4) && (strlen($ban_other[1]) == 2) && (strlen($ban_other[2]) == 2)) { - $time_offset = (isset($user->timezone) && isset($user->dst)) ? (int) $user->timezone + (int) $user->dst : 0; - $ban_end = max($current_time, gmmktime(0, 0, 0, (int)$ban_other[1], (int)$ban_other[2], (int)$ban_other[0]) - $time_offset); + $ban_end = max($current_time, $user->create_datetime() + ->setDate((int) $ban_other[0], (int) $ban_other[1], (int) $ban_other[2]) + ->setTime(0, 0, 0) + ->getTimestamp() + $user->tz->getOffset(new DateTime('UTC'))); } else { diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index aee55711b2..ac002a26c2 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -120,7 +120,10 @@ class ucp_register if ($coppa === false && $config['coppa_enable']) { $now = getdate(); - $coppa_birthday = $user->format_date(mktime($now['hours'] + $user->data['user_dst'], $now['minutes'], $now['seconds'], $now['mon'], $now['mday'] - 1, $now['year'] - 13), $user->lang['DATE_FORMAT']); + $coppa_birthday = $user->create_datetime() + ->setDate($now['year'] - 13, $now['mon'], $now['mday'] - 1) + ->setTime(0, 0, 0) + ->format($user->lang['DATE_FORMAT'], true); unset($now); $template->assign_vars(array( @@ -163,7 +166,6 @@ class ucp_register $captcha->init(CONFIRM_REG); } - $is_dst = $config['board_dst']; $timezone = $config['board_timezone']; $data = array( @@ -280,7 +282,6 @@ class ucp_register 'user_email' => $data['email'], 'group_id' => (int) $group_id, 'user_timezone' => $data['tz'], - 'user_dst' => $is_dst, 'user_lang' => $data['lang'], 'user_type' => $user_type, 'user_actkey' => $user_actkey, From 3c6272ff0475dc19cc67553f370ce227214d0613 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 23:28:48 +0200 Subject: [PATCH 34/75] [feature/new-tz-handling] Remove appearances of board_dst and user_dst PHPBB3-9558 --- phpBB/develop/mysql_upgrader.php | 3 +-- phpBB/develop/repair_bots.php | 2 +- phpBB/includes/acp/acp_board.php | 1 - phpBB/includes/acp/acp_users.php | 3 --- phpBB/includes/functions_convert.php | 2 +- phpBB/includes/questionnaire/questionnaire.php | 1 - phpBB/includes/ucp/ucp_prefs.php | 3 --- phpBB/includes/user.php | 2 +- phpBB/install/database_update.php | 2 +- phpBB/install/install_install.php | 2 +- phpBB/install/schemas/schema_data.sql | 3 +-- 11 files changed, 7 insertions(+), 17 deletions(-) diff --git a/phpBB/develop/mysql_upgrader.php b/phpBB/develop/mysql_upgrader.php index 0498f826ab..7f82ebfeab 100644 --- a/phpBB/develop/mysql_upgrader.php +++ b/phpBB/develop/mysql_upgrader.php @@ -1229,8 +1229,7 @@ function get_schema_struct() 'user_inactive_time' => array('TIMESTAMP', 0), 'user_posts' => array('UINT', 0), 'user_lang' => array('VCHAR:30', ''), - 'user_timezone' => array('DECIMAL', 0), - 'user_dst' => array('BOOL', 0), + 'user_timezone' => array('VCHAR:100', 'UTC'), 'user_dateformat' => array('VCHAR_UNI:30', 'd M Y H:i'), 'user_style' => array('UINT', 0), 'user_rank' => array('UINT', 0), diff --git a/phpBB/develop/repair_bots.php b/phpBB/develop/repair_bots.php index 790d3d9f2f..2c6e9ce091 100644 --- a/phpBB/develop/repair_bots.php +++ b/phpBB/develop/repair_bots.php @@ -128,7 +128,7 @@ function add_bots($bots) 'user_email' => '', 'user_lang' => $config['default_lang'], 'user_style' => 1, - 'user_timezone' => 0, + 'user_timezone' => 'UTC', 'user_allow_massemail' => 0, ); diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index ce2ddc3b0b..e018655407 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -58,7 +58,6 @@ class acp_board 'default_lang' => array('lang' => 'DEFAULT_LANGUAGE', 'validate' => 'lang', 'type' => 'select', 'function' => 'language_select', 'params' => array('{CONFIG_VALUE}'), 'explain' => false), 'default_dateformat' => array('lang' => 'DEFAULT_DATE_FORMAT', 'validate' => 'string', 'type' => 'custom', 'method' => 'dateformat_select', 'explain' => true), 'board_timezone' => array('lang' => 'SYSTEM_TIMEZONE', 'validate' => 'string', 'type' => 'select', 'function' => 'tz_select', 'params' => array('{CONFIG_VALUE}', 1), 'explain' => true), - 'board_dst' => array('lang' => 'SYSTEM_DST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'default_style' => array('lang' => 'DEFAULT_STYLE', 'validate' => 'int', 'type' => 'select', 'function' => 'style_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => false), 'override_user_style' => array('lang' => 'OVERRIDE_STYLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 825bba514f..b863a9ed80 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1460,7 +1460,6 @@ class acp_users 'lang' => basename(request_var('lang', $user_row['user_lang'])), 'tz' => request_var('tz', $user_row['user_timezone']), 'style' => request_var('style', $user_row['user_style']), - 'dst' => request_var('dst', $user_row['user_dst']), 'viewemail' => request_var('viewemail', $user_row['user_allow_viewemail']), 'massemail' => request_var('massemail', $user_row['user_allow_massemail']), 'hideonline' => request_var('hideonline', !$user_row['user_allow_viewonline']), @@ -1531,7 +1530,6 @@ class acp_users 'user_notify_type' => $data['notifymethod'], 'user_notify_pm' => $data['notifypm'], - 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], @@ -1654,7 +1652,6 @@ class acp_users 'NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false, 'NOTIFY_PM' => $data['notifypm'], 'POPUP_PM' => $data['popuppm'], - 'DST' => $data['dst'], 'BBCODE' => $data['bbcode'], 'SMILIES' => $data['smilies'], 'ATTACH_SIG' => $data['sig'], diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index e9ec153c50..ac791e0d9b 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -1884,7 +1884,7 @@ function add_bots() 'user_email' => '', 'user_lang' => $config['default_lang'], 'user_style' => 1, - 'user_timezone' => 0, + 'user_timezone' => 'UTC', 'user_allow_massemail' => 0, ); diff --git a/phpBB/includes/questionnaire/questionnaire.php b/phpBB/includes/questionnaire/questionnaire.php index 46a743d7e9..5cb441d536 100644 --- a/phpBB/includes/questionnaire/questionnaire.php +++ b/phpBB/includes/questionnaire/questionnaire.php @@ -304,7 +304,6 @@ class phpbb_questionnaire_phpbb_data_provider 'avatar_max_width' => true, 'avatar_min_height' => true, 'avatar_min_width' => true, - 'board_dst' => true, 'board_email_form' => true, 'board_hide_emails' => true, 'board_timezone' => true, diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 45e3bb8951..3f5f573389 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -43,7 +43,6 @@ class ucp_prefs 'style' => request_var('style', (int) $user->data['user_style']), 'tz' => request_var('tz', $user->data['user_timezone']), - 'dst' => request_var('dst', (bool) $user->data['user_dst']), 'viewemail' => request_var('viewemail', (bool) $user->data['user_allow_viewemail']), 'massemail' => request_var('massemail', (bool) $user->data['user_allow_massemail']), 'hideonline' => request_var('hideonline', (bool) !$user->data['user_allow_viewonline']), @@ -93,7 +92,6 @@ class ucp_prefs 'user_notify_pm' => $data['notifypm'], 'user_options' => $user->data['user_options'], - 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], @@ -145,7 +143,6 @@ class ucp_prefs 'S_HIDE_ONLINE' => $data['hideonline'], 'S_NOTIFY_PM' => $data['notifypm'], 'S_POPUP_PM' => $data['popuppm'], - 'S_DST' => $data['dst'], 'DATE_FORMAT' => $data['dateformat'], 'A_DATE_FORMAT' => addslashes($data['dateformat']), diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index 4c62dd93d7..a36d837fbd 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -126,7 +126,7 @@ class phpbb_user extends phpbb_session if (is_numeric($this->tz)) { // Might still be numeric by chance - $this->tz = sprintf('Etc/GMT%+d', ($this->tz + ($this->data['user_id'] != ANONYMOUS ? $this->data['user_dst'] : $config['board_dst']))); + $this->tz = sprintf('Etc/GMT%+d', $this->tz); } $this->tz = new DateTimeZone($this->tz); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 9758ad3b2b..b6f7f82785 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1971,7 +1971,7 @@ function change_database_data(&$no_updates, $version) 'user_email' => '', 'user_lang' => $config['default_lang'], 'user_style' => $config['default_style'], - 'user_timezone' => 0, + 'user_timezone' => 'UTC', 'user_dateformat' => $config['default_dateformat'], 'user_allow_massemail' => 0, ); diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index ef384edb78..bafcefe3f5 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1795,7 +1795,7 @@ class install_install extends module 'user_email' => '', 'user_lang' => $data['default_lang'], 'user_style' => 1, - 'user_timezone' => 0, + 'user_timezone' => 'UTC', 'user_dateformat' => $lang['default_dateformat'], 'user_allow_massemail' => 0, ); diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 5489fd4e3d..307864825c 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -54,12 +54,11 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('avatar_salt', 'php INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_contact', 'contact@yourdomain.tld'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_disable', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_disable_msg', ''); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_dst', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email', 'address@yourdomain.tld'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email_form', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email_sig', '{L_CONFIG_BOARD_EMAIL_SIG}'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_hide_emails', '1'); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_timezone', '0'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_timezone', 'UTC'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('browser_check', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('bump_interval', '10'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('bump_type', 'd'); From 66f7d45603417df7619323977de62aebce0bf676 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 5 Jun 2012 21:44:44 +0200 Subject: [PATCH 35/75] [feature/new-tz-handling] Introduce 2 step timezone selection using javascript PHPBB3-9558 --- phpBB/includes/functions.php | 43 ++++++++++--- phpBB/includes/ucp/ucp_prefs.php | 4 +- phpBB/language/en/common.php | 1 + phpBB/language/en/ucp.php | 3 + phpBB/styles/prosilver/template/timezone.js | 63 +++++++++++++++---- .../template/ucp_prefs_personal.html | 10 ++- phpBB/styles/prosilver/theme/forms.css | 5 ++ 7 files changed, 107 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 44346c7795..9263833b4c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1129,14 +1129,14 @@ function tz_select_compare($a, $b) /** * Pick a timezone -* @todo Possible HTML escaping */ -function tz_select($default = '', $truncate = false) +function tz_select($default = '', $truncate = false, $return_tzs_only = true) { global $user; static $timezones; + $default_offset = ''; if (!isset($timezones)) { $unsorted_timezones = DateTimeZone::listIdentifiers(); @@ -1147,21 +1147,37 @@ function tz_select($default = '', $truncate = false) $tz = new DateTimeZone($timezone); $dt = new phpbb_datetime('now', $tz); $offset = $dt->getOffset(); + $current_time = $dt->format($user->lang['DATETIME_FORMAT'], true); $offset_string = phpbb_format_timezone_offset($offset); $timezones['GMT' . $offset_string . ' - ' . $timezone] = array( 'tz' => $timezone, - 'label' => 'GMT' . $offset_string . ' - ' . $timezone, + 'offest' => 'GMT' . $offset_string, + 'current' => $current_time, ); + if ($timezone === $default) + { + $default_offset = 'GMT' . $offset_string; + } } unset($unsorted_timezones); uksort($timezones, 'tz_select_compare'); } - $tz_select = ''; + $tz_select = $tz_dates = $opt_group = ''; foreach ($timezones as $timezone) { + if ($opt_group != $timezone['offest']) + { + $tz_select .= ($opt_group) ? '' : ''; + $tz_select .= ''; + $opt_group = $timezone['offest']; + + $selected = ($default_offset == $timezone['offest']) ? ' selected="selected"' : ''; + $tz_dates .= ''; + } + if (isset($user->lang['timezones'][$timezone['tz']])) { $title = $label = $user->lang['timezones'][$timezone['tz']]; @@ -1169,10 +1185,10 @@ function tz_select($default = '', $truncate = false) else { // No label, we'll figure one out - // @todo rtl languages? - $bits = explode('/', str_replace('_', ' ', $timezone['label'])); + $bits = explode('/', str_replace('_', ' ', $timezone['tz'])); - $title = $label = implode(' - ', $bits); + $label = implode(' - ', $bits); + $title = $timezone['offest'] . ' - ' . $label; } if ($truncate) @@ -1181,10 +1197,19 @@ function tz_select($default = '', $truncate = false) } $selected = ($timezone['tz'] === $default) ? ' selected="selected"' : ''; - $tz_select .= ''; + $tz_select .= ''; + } + $tz_select .= ''; + + if ($return_tzs_only) + { + return $tz_select; } - return $tz_select; + return array( + 'tz_select' => $tz_select, + 'tz_dates' => $tz_dates, + ); } // Functions handling topic/post tracking/marking diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 3f5f573389..4239afc96e 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -131,6 +131,7 @@ class ucp_prefs } $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . ''; + $tz_select = tz_select($data['tz'], true, false); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', @@ -153,7 +154,8 @@ class ucp_prefs 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['style']), - 'S_TZ_OPTIONS' => tz_select($data['tz'], true), + 'S_TZ_OPTIONS' => $tz_select['tz_select'], + 'S_TZ_DATE_OPTIONS' => $tz_select['tz_dates'], 'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false, 'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false) ); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index bbafb54108..d0afb846b4 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -42,6 +42,7 @@ $lang = array_merge($lang, array( 'TRANSLATION_INFO' => '', 'DIRECTION' => 'ltr', 'DATE_FORMAT' => '|d M Y|', // 01 Jan 2007 (with Relative days enabled) + 'DATETIME_FORMAT' => '|d M Y, H:i|', // 01 Jan 2007, 13:37 (with Relative days enabled) 'USER_LANG' => 'en-gb', // You can define different rules for the determination of plural forms here. diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index f9558bc6d3..64a434d89c 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -412,6 +412,7 @@ $lang = array_merge($lang, array( 'SIGNATURE_EXPLAIN' => 'This is a block of text that can be added to posts you make. There is a %d character limit.', 'SIGNATURE_PREVIEW' => 'Your signature will appear like this in posts', 'SIGNATURE_TOO_LONG' => 'Your signature is too long.', + 'SELECT_CURRENT_TIME' => 'Select current time', 'SELECT_TIMEZONE' => 'Select timezone', 'SORT' => 'Sort', 'SORT_COMMENT' => 'File comment', @@ -422,7 +423,9 @@ $lang = array_merge($lang, array( 'SORT_SIZE' => 'File size', 'TIMEZONE' => 'Timezone', + 'TIMEZONE_DATE_SUGGESTION' => 'Suggestion: %s', 'TIMEZONE_INVALID' => 'The timezone you selected is invalid.', + 'TIMEZONE_SELECTED' => '(currently selected)', 'TO' => 'To', 'TOO_MANY_RECIPIENTS' => 'You tried to send a private message to too many recipients.', 'TOO_MANY_REGISTERS' => 'You have exceeded the maximum number of registration attempts for this session. Please try again later.', diff --git a/phpBB/styles/prosilver/template/timezone.js b/phpBB/styles/prosilver/template/timezone.js index 5d07b1d3ad..deebbf36a8 100644 --- a/phpBB/styles/prosilver/template/timezone.js +++ b/phpBB/styles/prosilver/template/timezone.js @@ -1,10 +1,37 @@ -function phpbb_preselect_tz_select() +function phpbb_switch_tz_date(keep_selection) { - var selector = document.getElementsByClassName('tz_select')[0]; - if (selector.value) - { - return; + var timezone_groups = document.getElementById("timezone"); + for (var i = 0; i < timezone_groups.childElementCount; i++) { + if (timezone_groups.children[i].tagName == "OPTGROUP" && + timezone_groups.children[i].label != document.getElementById("tz_date").value) + { + timezone_groups.children[i].style.display = "none"; + } + else if (timezone_groups.children[i].tagName == "OPTGROUP") + { + // Display other options + timezone_groups.children[i].style.display = "block"; + } } + if (typeof keep_selection !== 'undefined') + { + if (!keep_selection) + { + timezone_groups.children[0].selected = true; + } + } +} + +function phpbb_enable_tz_dates() +{ + var tz_select_date = document.getElementById("tz_select_date"); + tz_select_date.style.display = "block"; +} + +function phpbb_preselect_tz_select(force_selector, l_suggestion) +{ + + var selector = document.getElementById('tz_date'); // The offset returned here is in minutes and negated. // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp var offset = (new Date()).getTimezoneOffset(); @@ -42,12 +69,26 @@ function phpbb_preselect_tz_select() var option = selector.options[i]; if (option.value.substring(0, prefix_length) == prefix) { - // Firefox scrolls the selector only to put the option into view; - // for negative-offset timezones, this means the first timezone - // of a particular offset will be the bottom one, and selected, - // with all other timezones not visible. Not much can be done - // about that here unfortunately. - option.selected = true; + if (selector.value && selector.value != option.value && !force_selector) + { + // We do not select the option for the user, but notify him, + // that we would suggest a different setting. + document.getElementById("tz_select_date_suggest").style.display = "inline"; + document.getElementById("tz_select_date_suggest").title = l_suggestion.replace("%s", option.innerHTML); + document.getElementById("tz_select_date_suggest").innerHTML = l_suggestion.replace("%s", option.innerHTML.substring(0, 9)); + phpbb_switch_tz_date(true); + } + else + { + // Firefox scrolls the selector only to put the option into view; + // for negative-offset timezones, this means the first timezone + // of a particular offset will be the bottom one, and selected, + // with all other timezones not visible. Not much can be done + // about that here unfortunately. + option.selected = true; + phpbb_switch_tz_date(!force_selector); + document.getElementById("tz_select_date_suggest").style.display = "none"; + } break; } } diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index b09e7b1591..c798b1a1f2 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -75,6 +75,13 @@
+
+ + {S_TZ_DATE_OPTIONS} + + +
+ +
+ + + + + +
+
diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index c798b1a1f2..29c01e03b9 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -73,22 +73,7 @@
-
-
- -
- -
-
+

{L_BOARD_DATE_FORMAT_EXPLAIN}
@@ -146,8 +131,4 @@ // ]]> - - - - diff --git a/phpBB/styles/prosilver/template/ucp_register.html b/phpBB/styles/prosilver/template/ucp_register.html index 95e125fdea..994356efe6 100644 --- a/phpBB/styles/prosilver/template/ucp_register.html +++ b/phpBB/styles/prosilver/template/ucp_register.html @@ -53,15 +53,8 @@
-
-
-
- -
-
+ +
{L_ITEMS_REQUIRED}
From a6bace039ab18ce5138a7f6ffa6d74c543bd6222 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 12 Jun 2012 19:51:55 +0200 Subject: [PATCH 37/75] [feature/new-tz-handling] Fix timezone selection in subsilver2 PHPBB3-9558 --- phpBB/styles/subsilver2/template/timezone.js | 95 +++++++++++++++++++ .../subsilver2/template/timezone_option.html | 22 +++++ .../template/ucp_prefs_personal.html | 7 +- .../subsilver2/template/ucp_register.html | 7 +- 4 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 phpBB/styles/subsilver2/template/timezone.js create mode 100644 phpBB/styles/subsilver2/template/timezone_option.html diff --git a/phpBB/styles/subsilver2/template/timezone.js b/phpBB/styles/subsilver2/template/timezone.js new file mode 100644 index 0000000000..deebbf36a8 --- /dev/null +++ b/phpBB/styles/subsilver2/template/timezone.js @@ -0,0 +1,95 @@ +function phpbb_switch_tz_date(keep_selection) +{ + var timezone_groups = document.getElementById("timezone"); + for (var i = 0; i < timezone_groups.childElementCount; i++) { + if (timezone_groups.children[i].tagName == "OPTGROUP" && + timezone_groups.children[i].label != document.getElementById("tz_date").value) + { + timezone_groups.children[i].style.display = "none"; + } + else if (timezone_groups.children[i].tagName == "OPTGROUP") + { + // Display other options + timezone_groups.children[i].style.display = "block"; + } + } + if (typeof keep_selection !== 'undefined') + { + if (!keep_selection) + { + timezone_groups.children[0].selected = true; + } + } +} + +function phpbb_enable_tz_dates() +{ + var tz_select_date = document.getElementById("tz_select_date"); + tz_select_date.style.display = "block"; +} + +function phpbb_preselect_tz_select(force_selector, l_suggestion) +{ + + var selector = document.getElementById('tz_date'); + // The offset returned here is in minutes and negated. + // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp + var offset = (new Date()).getTimezoneOffset(); + if (offset < 0) + { + var sign = '+'; + offset = -offset; + } + else + { + var sign = '-'; + } + var minutes = offset % 60; + var hours = (offset - minutes) / 60; + if (hours < 10) + { + hours = '0' + hours.toString(); + } + else + { + hours = hours.toString(); + } + if (minutes < 10) + { + minutes = '0' + minutes.toString(); + } + else + { + minutes = minutes.toString(); + } + var prefix = 'GMT' + sign + hours + ':' + minutes; + var prefix_length = prefix.length; + for (var i = 0; i < selector.options.length; ++i) + { + var option = selector.options[i]; + if (option.value.substring(0, prefix_length) == prefix) + { + if (selector.value && selector.value != option.value && !force_selector) + { + // We do not select the option for the user, but notify him, + // that we would suggest a different setting. + document.getElementById("tz_select_date_suggest").style.display = "inline"; + document.getElementById("tz_select_date_suggest").title = l_suggestion.replace("%s", option.innerHTML); + document.getElementById("tz_select_date_suggest").innerHTML = l_suggestion.replace("%s", option.innerHTML.substring(0, 9)); + phpbb_switch_tz_date(true); + } + else + { + // Firefox scrolls the selector only to put the option into view; + // for negative-offset timezones, this means the first timezone + // of a particular offset will be the bottom one, and selected, + // with all other timezones not visible. Not much can be done + // about that here unfortunately. + option.selected = true; + phpbb_switch_tz_date(!force_selector); + document.getElementById("tz_select_date_suggest").style.display = "none"; + } + break; + } + } +} diff --git a/phpBB/styles/subsilver2/template/timezone_option.html b/phpBB/styles/subsilver2/template/timezone_option.html new file mode 100644 index 0000000000..184722ef7e --- /dev/null +++ b/phpBB/styles/subsilver2/template/timezone_option.html @@ -0,0 +1,22 @@ + + {L_BOARD_TIMEZONE}: + + + + + + + + + + + diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index 357e1fe100..bf0e67d68b 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -71,12 +71,7 @@ - - {L_BOARD_TIMEZONE}: - - - - + {L_BOARD_DATE_FORMAT}:
{L_BOARD_DATE_FORMAT_EXPLAIN} diff --git a/phpBB/styles/subsilver2/template/ucp_register.html b/phpBB/styles/subsilver2/template/ucp_register.html index 0c3533292d..095c97ed49 100644 --- a/phpBB/styles/subsilver2/template/ucp_register.html +++ b/phpBB/styles/subsilver2/template/ucp_register.html @@ -53,10 +53,9 @@ {L_LANGUAGE}: - - {L_TIMEZONE}: - - + + + {L_ITEMS_REQUIRED} From 435573a9cb82060ddae673aa1e1572bd78c7741d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 12 Jun 2012 19:52:33 +0200 Subject: [PATCH 38/75] [feature/new-tz-handling] Fix Timezone selection on registration page PHPBB3-9558 --- phpBB/includes/ucp/ucp_register.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index ac002a26c2..804bd2e0e2 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -442,6 +442,7 @@ class ucp_register break; } + $tz_select = tz_select($data['tz'], true, false); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', 'USERNAME' => $data['username'], @@ -454,7 +455,8 @@ class ucp_register 'L_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])), 'S_LANG_OPTIONS' => language_select($data['lang']), - 'S_TZ_OPTIONS' => tz_select($data['tz'], true), + 'S_TZ_OPTIONS' => $tz_select['tz_select'], + 'S_TZ_DATE_OPTIONS' => $tz_select['tz_dates'], 'S_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false, 'S_REGISTRATION' => true, 'S_COPPA' => $coppa, From 5f96e5d374d1702d3d81591b7c69ede1cafebfa7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 12 Jun 2012 19:54:26 +0200 Subject: [PATCH 39/75] [feature/new-tz-handling] Fix timezone option when editing a user in the ACP PHPBB3-9558 --- phpBB/adm/style/acp_users_prefs.html | 5 +---- phpBB/adm/style/timezone.js | 29 ++++++++++++++++++++++++++++ phpBB/adm/style/timezone_option.html | 20 +++++++++++++++++++ phpBB/includes/acp/acp_users.php | 4 +++- phpBB/language/en/acp/common.php | 2 ++ 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 phpBB/adm/style/timezone.js create mode 100644 phpBB/adm/style/timezone_option.html diff --git a/phpBB/adm/style/acp_users_prefs.html b/phpBB/adm/style/acp_users_prefs.html index 90db62984e..9439f0cf03 100644 --- a/phpBB/adm/style/acp_users_prefs.html +++ b/phpBB/adm/style/acp_users_prefs.html @@ -52,10 +52,7 @@
-
-
-
-
+

{L_BOARD_DATE_FORMAT_EXPLAIN}
diff --git a/phpBB/adm/style/timezone.js b/phpBB/adm/style/timezone.js new file mode 100644 index 0000000000..d02c965ab5 --- /dev/null +++ b/phpBB/adm/style/timezone.js @@ -0,0 +1,29 @@ +function phpbb_switch_tz_date(keep_selection) +{ + var timezone_groups = document.getElementById("timezone"); + for (var i = 0; i < timezone_groups.childElementCount; i++) { + if (timezone_groups.children[i].tagName == "OPTGROUP" && + timezone_groups.children[i].label != document.getElementById("tz_date").value) + { + timezone_groups.children[i].style.display = "none"; + } + else if (timezone_groups.children[i].tagName == "OPTGROUP") + { + // Display other options + timezone_groups.children[i].style.display = "block"; + } + } + if (typeof keep_selection !== 'undefined') + { + if (!keep_selection) + { + timezone_groups.children[0].selected = true; + } + } +} + +function phpbb_enable_tz_dates() +{ + var tz_select_date = document.getElementById("tz_select_date"); + tz_select_date.style.display = "block"; +} diff --git a/phpBB/adm/style/timezone_option.html b/phpBB/adm/style/timezone_option.html new file mode 100644 index 0000000000..12e6e3700a --- /dev/null +++ b/phpBB/adm/style/timezone_option.html @@ -0,0 +1,20 @@ +
+
+ + + +
+ + + + +
+
diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index b863a9ed80..949109abaf 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1639,6 +1639,7 @@ class acp_users ${'s_sort_' . $sort_option . '_dir'} .= ''; } + $tz_select = tz_select($data['tz'], true, false); $template->assign_vars(array( 'S_PREFS' => true, 'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true, @@ -1678,7 +1679,8 @@ class acp_users 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => style_select($data['style']), - 'S_TZ_OPTIONS' => tz_select($data['tz'], true), + 'S_TZ_OPTIONS' => $tz_select['tz_select'], + 'S_TZ_DATE_OPTIONS' => $tz_select['tz_dates'], ) ); diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index dc35969955..5cebcc89d7 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -401,6 +401,8 @@ $lang = array_merge($lang, array( 'STATISTIC' => 'Statistic', 'STATISTIC_RESYNC_OPTIONS' => 'Resynchronise or reset statistics', + 'TIMEZONE_INVALID' => 'The timezone you selected is invalid.', + 'TIMEZONE_SELECTED' => '(currently selected)', 'TOPICS_PER_DAY' => 'Topics per day', 'UPLOAD_DIR_SIZE' => 'Size of posted attachments', From 5441ee1ee489ef9ad1727f110c440dde5417cc1f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 17 Jun 2012 16:54:12 +0200 Subject: [PATCH 40/75] [feature/new-tz-handling] Use jQuery and INCLUDEJS for javascript PHPBB3-9558 --- phpBB/adm/style/timezone.js | 28 +++++------ phpBB/adm/style/timezone_option.html | 3 +- phpBB/styles/prosilver/template/timezone.js | 47 ++++++++++--------- .../prosilver/template/timezone_option.html | 8 ++-- phpBB/styles/subsilver2/template/timezone.js | 47 ++++++++++--------- .../subsilver2/template/timezone_option.html | 8 ++-- 6 files changed, 72 insertions(+), 69 deletions(-) diff --git a/phpBB/adm/style/timezone.js b/phpBB/adm/style/timezone.js index d02c965ab5..a1ffeb17c5 100644 --- a/phpBB/adm/style/timezone.js +++ b/phpBB/adm/style/timezone.js @@ -1,29 +1,27 @@ function phpbb_switch_tz_date(keep_selection) { - var timezone_groups = document.getElementById("timezone"); - for (var i = 0; i < timezone_groups.childElementCount; i++) { - if (timezone_groups.children[i].tagName == "OPTGROUP" && - timezone_groups.children[i].label != document.getElementById("tz_date").value) - { - timezone_groups.children[i].style.display = "none"; - } - else if (timezone_groups.children[i].tagName == "OPTGROUP") - { - // Display other options - timezone_groups.children[i].style.display = "block"; - } + $('#timezone > optgroup').css("display", "none"); + $("#timezone > optgroup[label='" + $('#tz_date').val() + "']").css("display", "block"); + + if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) + { + // If there is only one timezone for the selected date, we just select that automatically. + $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr("selected", true); + keep_selection = true; } + if (typeof keep_selection !== 'undefined') { if (!keep_selection) { - timezone_groups.children[0].selected = true; + $('#timezone > option:first').attr("selected", true); } } } function phpbb_enable_tz_dates() { - var tz_select_date = document.getElementById("tz_select_date"); - tz_select_date.style.display = "block"; + $('#tz_select_date').css("display", "block"); } + +phpbb_enable_tz_dates(); diff --git a/phpBB/adm/style/timezone_option.html b/phpBB/adm/style/timezone_option.html index 12e6e3700a..e12219b1c0 100644 --- a/phpBB/adm/style/timezone_option.html +++ b/phpBB/adm/style/timezone_option.html @@ -14,7 +14,6 @@ {S_TZ_OPTIONS} - - +
diff --git a/phpBB/styles/prosilver/template/timezone.js b/phpBB/styles/prosilver/template/timezone.js index deebbf36a8..f73a82a063 100644 --- a/phpBB/styles/prosilver/template/timezone.js +++ b/phpBB/styles/prosilver/template/timezone.js @@ -1,37 +1,32 @@ function phpbb_switch_tz_date(keep_selection) { - var timezone_groups = document.getElementById("timezone"); - for (var i = 0; i < timezone_groups.childElementCount; i++) { - if (timezone_groups.children[i].tagName == "OPTGROUP" && - timezone_groups.children[i].label != document.getElementById("tz_date").value) - { - timezone_groups.children[i].style.display = "none"; - } - else if (timezone_groups.children[i].tagName == "OPTGROUP") - { - // Display other options - timezone_groups.children[i].style.display = "block"; - } + $('#timezone > optgroup').css("display", "none"); + $("#timezone > optgroup[label='" + $('#tz_date').val() + "']").css("display", "block"); + + if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) + { + // If there is only one timezone for the selected date, we just select that automatically. + $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr("selected", true); + keep_selection = true; } + if (typeof keep_selection !== 'undefined') { if (!keep_selection) { - timezone_groups.children[0].selected = true; + $('#timezone > option:first').attr("selected", true); } } } function phpbb_enable_tz_dates() { - var tz_select_date = document.getElementById("tz_select_date"); - tz_select_date.style.display = "block"; + $('#tz_select_date').css("display", "block"); } function phpbb_preselect_tz_select(force_selector, l_suggestion) { - var selector = document.getElementById('tz_date'); // The offset returned here is in minutes and negated. // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp var offset = (new Date()).getTimezoneOffset(); @@ -62,20 +57,23 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) { minutes = minutes.toString(); } + var prefix = 'GMT' + sign + hours + ':' + minutes; var prefix_length = prefix.length; - for (var i = 0; i < selector.options.length; ++i) + + var selector_options = $('#tz_date > option'); + for (var i = 0; i < selector_options.length; ++i) { - var option = selector.options[i]; + var option = selector_options[i]; if (option.value.substring(0, prefix_length) == prefix) { - if (selector.value && selector.value != option.value && !force_selector) + if ($('#tz_date').val() != option.value && !force_selector) { // We do not select the option for the user, but notify him, // that we would suggest a different setting. - document.getElementById("tz_select_date_suggest").style.display = "inline"; - document.getElementById("tz_select_date_suggest").title = l_suggestion.replace("%s", option.innerHTML); - document.getElementById("tz_select_date_suggest").innerHTML = l_suggestion.replace("%s", option.innerHTML.substring(0, 9)); + $('#tz_select_date_suggest').css("display", "inline"); + $('#tz_select_date_suggest').attr("title", l_suggestion.replace("%s", option.innerHTML)); + $('#tz_select_date_suggest').html(l_suggestion.replace("%s", option.innerHTML.substring(0, 9))); phpbb_switch_tz_date(true); } else @@ -87,9 +85,12 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) // about that here unfortunately. option.selected = true; phpbb_switch_tz_date(!force_selector); - document.getElementById("tz_select_date_suggest").style.display = "none"; + $('#tz_select_date_suggest').css("display", "none"); } break; } } } + +phpbb_enable_tz_dates(); +phpbb_preselect_tz_select(is_registration, l_timezone_date_suggestion); diff --git a/phpBB/styles/prosilver/template/timezone_option.html b/phpBB/styles/prosilver/template/timezone_option.html index 6a6a937977..3a08de1a46 100644 --- a/phpBB/styles/prosilver/template/timezone_option.html +++ b/phpBB/styles/prosilver/template/timezone_option.html @@ -15,8 +15,10 @@ {S_TZ_OPTIONS} - - - + + diff --git a/phpBB/styles/subsilver2/template/timezone.js b/phpBB/styles/subsilver2/template/timezone.js index deebbf36a8..f73a82a063 100644 --- a/phpBB/styles/subsilver2/template/timezone.js +++ b/phpBB/styles/subsilver2/template/timezone.js @@ -1,37 +1,32 @@ function phpbb_switch_tz_date(keep_selection) { - var timezone_groups = document.getElementById("timezone"); - for (var i = 0; i < timezone_groups.childElementCount; i++) { - if (timezone_groups.children[i].tagName == "OPTGROUP" && - timezone_groups.children[i].label != document.getElementById("tz_date").value) - { - timezone_groups.children[i].style.display = "none"; - } - else if (timezone_groups.children[i].tagName == "OPTGROUP") - { - // Display other options - timezone_groups.children[i].style.display = "block"; - } + $('#timezone > optgroup').css("display", "none"); + $("#timezone > optgroup[label='" + $('#tz_date').val() + "']").css("display", "block"); + + if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) + { + // If there is only one timezone for the selected date, we just select that automatically. + $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr("selected", true); + keep_selection = true; } + if (typeof keep_selection !== 'undefined') { if (!keep_selection) { - timezone_groups.children[0].selected = true; + $('#timezone > option:first').attr("selected", true); } } } function phpbb_enable_tz_dates() { - var tz_select_date = document.getElementById("tz_select_date"); - tz_select_date.style.display = "block"; + $('#tz_select_date').css("display", "block"); } function phpbb_preselect_tz_select(force_selector, l_suggestion) { - var selector = document.getElementById('tz_date'); // The offset returned here is in minutes and negated. // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp var offset = (new Date()).getTimezoneOffset(); @@ -62,20 +57,23 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) { minutes = minutes.toString(); } + var prefix = 'GMT' + sign + hours + ':' + minutes; var prefix_length = prefix.length; - for (var i = 0; i < selector.options.length; ++i) + + var selector_options = $('#tz_date > option'); + for (var i = 0; i < selector_options.length; ++i) { - var option = selector.options[i]; + var option = selector_options[i]; if (option.value.substring(0, prefix_length) == prefix) { - if (selector.value && selector.value != option.value && !force_selector) + if ($('#tz_date').val() != option.value && !force_selector) { // We do not select the option for the user, but notify him, // that we would suggest a different setting. - document.getElementById("tz_select_date_suggest").style.display = "inline"; - document.getElementById("tz_select_date_suggest").title = l_suggestion.replace("%s", option.innerHTML); - document.getElementById("tz_select_date_suggest").innerHTML = l_suggestion.replace("%s", option.innerHTML.substring(0, 9)); + $('#tz_select_date_suggest').css("display", "inline"); + $('#tz_select_date_suggest').attr("title", l_suggestion.replace("%s", option.innerHTML)); + $('#tz_select_date_suggest').html(l_suggestion.replace("%s", option.innerHTML.substring(0, 9))); phpbb_switch_tz_date(true); } else @@ -87,9 +85,12 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) // about that here unfortunately. option.selected = true; phpbb_switch_tz_date(!force_selector); - document.getElementById("tz_select_date_suggest").style.display = "none"; + $('#tz_select_date_suggest').css("display", "none"); } break; } } } + +phpbb_enable_tz_dates(); +phpbb_preselect_tz_select(is_registration, l_timezone_date_suggestion); diff --git a/phpBB/styles/subsilver2/template/timezone_option.html b/phpBB/styles/subsilver2/template/timezone_option.html index 184722ef7e..0806186c9c 100644 --- a/phpBB/styles/subsilver2/template/timezone_option.html +++ b/phpBB/styles/subsilver2/template/timezone_option.html @@ -15,8 +15,10 @@ {S_TZ_OPTIONS} - - - + + From 8d65f1f7d263d9f6e76cbac2765da02a0877c87f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Jun 2012 10:20:15 +0200 Subject: [PATCH 41/75] [feature/new-tz-handling] Add doc blocks to js functions PHPBB3-9558 --- phpBB/adm/style/timezone.js | 8 ++++++++ phpBB/styles/prosilver/template/timezone.js | 19 ++++++++++++++----- phpBB/styles/subsilver2/template/timezone.js | 19 ++++++++++++++----- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/phpBB/adm/style/timezone.js b/phpBB/adm/style/timezone.js index a1ffeb17c5..d1667699da 100644 --- a/phpBB/adm/style/timezone.js +++ b/phpBB/adm/style/timezone.js @@ -1,3 +1,8 @@ +/** +* Hide the optgroups that are not the selected timezone +* +* @param bool keep_selection Shall we keep the value selected, or shall the user be forced to repick one. +*/ function phpbb_switch_tz_date(keep_selection) { $('#timezone > optgroup').css("display", "none"); @@ -19,6 +24,9 @@ function phpbb_switch_tz_date(keep_selection) } } +/** +* Display the date/time select +*/ function phpbb_enable_tz_dates() { $('#tz_select_date').css("display", "block"); diff --git a/phpBB/styles/prosilver/template/timezone.js b/phpBB/styles/prosilver/template/timezone.js index f73a82a063..b91aae6244 100644 --- a/phpBB/styles/prosilver/template/timezone.js +++ b/phpBB/styles/prosilver/template/timezone.js @@ -1,3 +1,8 @@ +/** +* Hide the optgroups that are not the selected timezone +* +* @param bool keep_selection Shall we keep the value selected, or shall the user be forced to repick one. +*/ function phpbb_switch_tz_date(keep_selection) { $('#timezone > optgroup').css("display", "none"); @@ -19,11 +24,20 @@ function phpbb_switch_tz_date(keep_selection) } } +/** +* Display the date/time select +*/ function phpbb_enable_tz_dates() { $('#tz_select_date').css("display", "block"); } +/** +* Preselect a date/time or suggest one, if it is not picked. +* +* @param bool force_selector Shall we select the suggestion? +* @param string l_suggestion The language string which we use, to display the selection +*/ function phpbb_preselect_tz_select(force_selector, l_suggestion) { @@ -78,11 +92,6 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) } else { - // Firefox scrolls the selector only to put the option into view; - // for negative-offset timezones, this means the first timezone - // of a particular offset will be the bottom one, and selected, - // with all other timezones not visible. Not much can be done - // about that here unfortunately. option.selected = true; phpbb_switch_tz_date(!force_selector); $('#tz_select_date_suggest').css("display", "none"); diff --git a/phpBB/styles/subsilver2/template/timezone.js b/phpBB/styles/subsilver2/template/timezone.js index f73a82a063..b91aae6244 100644 --- a/phpBB/styles/subsilver2/template/timezone.js +++ b/phpBB/styles/subsilver2/template/timezone.js @@ -1,3 +1,8 @@ +/** +* Hide the optgroups that are not the selected timezone +* +* @param bool keep_selection Shall we keep the value selected, or shall the user be forced to repick one. +*/ function phpbb_switch_tz_date(keep_selection) { $('#timezone > optgroup').css("display", "none"); @@ -19,11 +24,20 @@ function phpbb_switch_tz_date(keep_selection) } } +/** +* Display the date/time select +*/ function phpbb_enable_tz_dates() { $('#tz_select_date').css("display", "block"); } +/** +* Preselect a date/time or suggest one, if it is not picked. +* +* @param bool force_selector Shall we select the suggestion? +* @param string l_suggestion The language string which we use, to display the selection +*/ function phpbb_preselect_tz_select(force_selector, l_suggestion) { @@ -78,11 +92,6 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) } else { - // Firefox scrolls the selector only to put the option into view; - // for negative-offset timezones, this means the first timezone - // of a particular offset will be the bottom one, and selected, - // with all other timezones not visible. Not much can be done - // about that here unfortunately. option.selected = true; phpbb_switch_tz_date(!force_selector); $('#tz_select_date_suggest').css("display", "none"); From c21275fa951bd4d8608cc335a5c39d9a05bc4904 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Jun 2012 10:53:47 +0200 Subject: [PATCH 42/75] [feature/new-tz-handling] Use js and data attributes to create the events PHPBB3-9558 --- phpBB/styles/prosilver/template/timezone.js | 13 ++++++++----- .../styles/prosilver/template/timezone_option.html | 6 +----- phpBB/styles/subsilver2/template/timezone.js | 13 ++++++++----- .../styles/subsilver2/template/timezone_option.html | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/phpBB/styles/prosilver/template/timezone.js b/phpBB/styles/prosilver/template/timezone.js index b91aae6244..b8d3c2f152 100644 --- a/phpBB/styles/prosilver/template/timezone.js +++ b/phpBB/styles/prosilver/template/timezone.js @@ -36,9 +36,8 @@ function phpbb_enable_tz_dates() * Preselect a date/time or suggest one, if it is not picked. * * @param bool force_selector Shall we select the suggestion? -* @param string l_suggestion The language string which we use, to display the selection */ -function phpbb_preselect_tz_select(force_selector, l_suggestion) +function phpbb_preselect_tz_select(force_selector) { // The offset returned here is in minutes and negated. @@ -86,8 +85,8 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) // We do not select the option for the user, but notify him, // that we would suggest a different setting. $('#tz_select_date_suggest').css("display", "inline"); - $('#tz_select_date_suggest').attr("title", l_suggestion.replace("%s", option.innerHTML)); - $('#tz_select_date_suggest').html(l_suggestion.replace("%s", option.innerHTML.substring(0, 9))); + $('#tz_select_date_suggest').attr("title", $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML)); + $('#tz_select_date_suggest').attr("value", $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML.substring(0, 9))); phpbb_switch_tz_date(true); } else @@ -101,5 +100,9 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) } } +$('#tz_select_date_suggest').click(function(){ + phpbb_preselect_tz_select(true, ''); +}); + phpbb_enable_tz_dates(); -phpbb_preselect_tz_select(is_registration, l_timezone_date_suggestion); +phpbb_preselect_tz_select($('#tz_select_date_suggest').attr('data-is-registration') == "true"); diff --git a/phpBB/styles/prosilver/template/timezone_option.html b/phpBB/styles/prosilver/template/timezone_option.html index 3a08de1a46..8840e9e5e8 100644 --- a/phpBB/styles/prosilver/template/timezone_option.html +++ b/phpBB/styles/prosilver/template/timezone_option.html @@ -6,7 +6,7 @@ {S_TZ_DATE_OPTIONS} - +
@@ -15,10 +15,6 @@ {S_TZ_OPTIONS} -
diff --git a/phpBB/styles/subsilver2/template/timezone.js b/phpBB/styles/subsilver2/template/timezone.js index b91aae6244..b8d3c2f152 100644 --- a/phpBB/styles/subsilver2/template/timezone.js +++ b/phpBB/styles/subsilver2/template/timezone.js @@ -36,9 +36,8 @@ function phpbb_enable_tz_dates() * Preselect a date/time or suggest one, if it is not picked. * * @param bool force_selector Shall we select the suggestion? -* @param string l_suggestion The language string which we use, to display the selection */ -function phpbb_preselect_tz_select(force_selector, l_suggestion) +function phpbb_preselect_tz_select(force_selector) { // The offset returned here is in minutes and negated. @@ -86,8 +85,8 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) // We do not select the option for the user, but notify him, // that we would suggest a different setting. $('#tz_select_date_suggest').css("display", "inline"); - $('#tz_select_date_suggest').attr("title", l_suggestion.replace("%s", option.innerHTML)); - $('#tz_select_date_suggest').html(l_suggestion.replace("%s", option.innerHTML.substring(0, 9))); + $('#tz_select_date_suggest').attr("title", $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML)); + $('#tz_select_date_suggest').attr("value", $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML.substring(0, 9))); phpbb_switch_tz_date(true); } else @@ -101,5 +100,9 @@ function phpbb_preselect_tz_select(force_selector, l_suggestion) } } +$('#tz_select_date_suggest').click(function(){ + phpbb_preselect_tz_select(true, ''); +}); + phpbb_enable_tz_dates(); -phpbb_preselect_tz_select(is_registration, l_timezone_date_suggestion); +phpbb_preselect_tz_select($('#tz_select_date_suggest').attr('data-is-registration') == "true"); diff --git a/phpBB/styles/subsilver2/template/timezone_option.html b/phpBB/styles/subsilver2/template/timezone_option.html index 0806186c9c..affeee91ac 100644 --- a/phpBB/styles/subsilver2/template/timezone_option.html +++ b/phpBB/styles/subsilver2/template/timezone_option.html @@ -7,7 +7,7 @@ {S_TZ_DATE_OPTIONS}
-
+ + From 7b4f9765f8ab515c19d360818d7e57e5d6e47bd3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 19 Jun 2012 18:57:20 +0200 Subject: [PATCH 51/75] [feature/new-tz-handling] Move js functions into assets core.js PHPBB3-9558 --- phpBB/assets/javascript/core.js | 85 ++++++++++++++++++++ phpBB/styles/prosilver/template/timezone.js | 89 +-------------------- 2 files changed, 87 insertions(+), 87 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 958b6c9ff6..ab1aaa8505 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -411,6 +411,91 @@ phpbb.ajaxify = function(options) { return this; } +/** +* Hide the optgroups that are not the selected timezone +* +* @param bool keep_selection Shall we keep the value selected, or shall the user be forced to repick one. +*/ +phpbb.timezone_switch_date = function(keep_selection) { + $('#timezone > optgroup').css('display', 'none'); + $("#timezone > optgroup[label='" + $('#tz_date').val() + "']").css('display', 'block'); + + if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) { + // If there is only one timezone for the selected date, we just select that automatically. + $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr('selected', true); + keep_selection = true; + } + + if (typeof keep_selection !== 'undefined' && !keep_selection) { + $('#timezone > option:first').attr('selected', true); + } +} + +/** +* Display the date/time select +*/ +phpbb.timezone_enable_date_selection = function() { + $('#tz_select_date').css('display', 'block'); +} + +/** +* Preselect a date/time or suggest one, if it is not picked. +* +* @param bool force_selector Shall we select the suggestion? +*/ +phpbb.timezone_preselect_select = function(force_selector) { + + // The offset returned here is in minutes and negated. + // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp + var offset = (new Date()).getTimezoneOffset(); + + if (offset < 0) { + var sign = '+'; + offset = -offset; + } else { + var sign = '-'; + } + + var minutes = offset % 60; + var hours = (offset - minutes) / 60; + + if (hours < 10) { + hours = '0' + hours.toString(); + } else { + hours = hours.toString(); + } + + if (minutes < 10) { + minutes = '0' + minutes.toString(); + } else { + minutes = minutes.toString(); + } + + var prefix = 'GMT' + sign + hours + ':' + minutes; + var prefix_length = prefix.length; + var selector_options = $('#tz_date > option'); + + for (var i = 0; i < selector_options.length; ++i) { + var option = selector_options[i]; + + if (option.value.substring(0, prefix_length) == prefix) { + if ($('#tz_date').val() != option.value && !force_selector) { + // We do not select the option for the user, but notify him, + // that we would suggest a different setting. + $('#tz_select_date_suggest').css('display', 'inline'); + $('#tz_select_date_suggest').attr('title', $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML)); + $('#tz_select_date_suggest').attr('value', $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML.substring(0, 9))); + phpbb.timezone_switch_date(true); + } else { + option.selected = true; + phpbb.timezone_switch_date(!force_selector); + $('#tz_select_date_suggest').css('display', 'none'); + } + break; + } + } +} + phpbb.ajax_callbacks = {}; /** diff --git a/phpBB/styles/prosilver/template/timezone.js b/phpBB/styles/prosilver/template/timezone.js index 30f4b87425..da0a2b0bfd 100644 --- a/phpBB/styles/prosilver/template/timezone.js +++ b/phpBB/styles/prosilver/template/timezone.js @@ -1,92 +1,5 @@ (function($) { // Avoid conflicts with other libraries -/** -* Hide the optgroups that are not the selected timezone -* -* @param bool keep_selection Shall we keep the value selected, or shall the user be forced to repick one. -*/ -phpbb.timezone_switch_date = function(keep_selection) { - $('#timezone > optgroup').css('display', 'none'); - $("#timezone > optgroup[label='" + $('#tz_date').val() + "']").css('display', 'block'); - - if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) { - // If there is only one timezone for the selected date, we just select that automatically. - $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr('selected', true); - keep_selection = true; - } - - if (typeof keep_selection !== 'undefined' && !keep_selection) { - $('#timezone > option:first').attr('selected', true); - } -} - -/** -* Display the date/time select -*/ -phpbb.timezone_enable_date_selection = function() { - $('#tz_select_date').css('display', 'block'); -} - -/** -* Preselect a date/time or suggest one, if it is not picked. -* -* @param bool force_selector Shall we select the suggestion? -*/ -phpbb.timezone_preselect_select = function(force_selector) { - - // The offset returned here is in minutes and negated. - // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp - var offset = (new Date()).getTimezoneOffset(); - - if (offset < 0) { - var sign = '+'; - offset = -offset; - } else { - var sign = '-'; - } - - var minutes = offset % 60; - var hours = (offset - minutes) / 60; - - if (hours < 10) { - hours = '0' + hours.toString(); - } else { - hours = hours.toString(); - } - - if (minutes < 10) { - minutes = '0' + minutes.toString(); - } else { - minutes = minutes.toString(); - } - - var prefix = 'GMT' + sign + hours + ':' + minutes; - var prefix_length = prefix.length; - var selector_options = $('#tz_date > option'); - - for (var i = 0; i < selector_options.length; ++i) { - var option = selector_options[i]; - - if (option.value.substring(0, prefix_length) == prefix) { - if ($('#tz_date').val() != option.value && !force_selector) { - // We do not select the option for the user, but notify him, - // that we would suggest a different setting. - $('#tz_select_date_suggest').css('display', 'inline'); - $('#tz_select_date_suggest').attr('title', $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML)); - $('#tz_select_date_suggest').attr('value', $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML.substring(0, 9))); - phpbb.timezone_switch_date(true); - } else { - option.selected = true; - phpbb.timezone_switch_date(!force_selector); - $('#tz_select_date_suggest').css('display', 'none'); - } - break; - } - } -} - -})(jQuery); // Avoid conflicts with other libraries - $('#tz_date').change(function() { phpbb.timezone_switch_date(false); }); @@ -102,3 +15,5 @@ $(document).ready( $(document).ready( phpbb.timezone_preselect_select($('#tz_select_date_suggest').attr('data-is-registration') == 'true') ); + +})(jQuery); // Avoid conflicts with other libraries From dcd7d962960ade175400cbb9b8e00575e8735a22 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 19 Jun 2012 19:08:53 +0200 Subject: [PATCH 52/75] [feature/new-tz-handling] Use asset in acp and subsilver2 and remove duplicates PHPBB3-9558 --- phpBB/adm/style/timezone.js | 40 ++---- phpBB/adm/style/timezone_option.html | 2 +- phpBB/styles/subsilver2/template/timezone.js | 121 +++--------------- .../subsilver2/template/timezone_option.html | 6 +- 4 files changed, 26 insertions(+), 143 deletions(-) diff --git a/phpBB/adm/style/timezone.js b/phpBB/adm/style/timezone.js index d1667699da..4556ea5f94 100644 --- a/phpBB/adm/style/timezone.js +++ b/phpBB/adm/style/timezone.js @@ -1,35 +1,11 @@ -/** -* Hide the optgroups that are not the selected timezone -* -* @param bool keep_selection Shall we keep the value selected, or shall the user be forced to repick one. -*/ -function phpbb_switch_tz_date(keep_selection) -{ - $('#timezone > optgroup').css("display", "none"); - $("#timezone > optgroup[label='" + $('#tz_date').val() + "']").css("display", "block"); +(function($) { // Avoid conflicts with other libraries - if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) - { - // If there is only one timezone for the selected date, we just select that automatically. - $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr("selected", true); - keep_selection = true; - } +$('#tz_date').change(function() { + phpbb.timezone_switch_date(false); +}); - if (typeof keep_selection !== 'undefined') - { - if (!keep_selection) - { - $('#timezone > option:first').attr("selected", true); - } - } -} +$(document).ready( + phpbb.timezone_enable_date_selection +); -/** -* Display the date/time select -*/ -function phpbb_enable_tz_dates() -{ - $('#tz_select_date').css("display", "block"); -} - -phpbb_enable_tz_dates(); +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/adm/style/timezone_option.html b/phpBB/adm/style/timezone_option.html index e12219b1c0..23c0ee19e9 100644 --- a/phpBB/adm/style/timezone_option.html +++ b/phpBB/adm/style/timezone_option.html @@ -2,7 +2,7 @@
From 7df1c84447903ecc97a8418339ec6933bdfc9035 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Jul 2012 17:41:27 +0200 Subject: [PATCH 75/75] [feature/new-tz-handling] Don't use global user but make it a parameter PHPBB3-9558 --- phpBB/includes/acp/acp_board.php | 4 +++- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/functions.php | 9 +++++---- phpBB/includes/ucp/ucp_prefs.php | 2 +- phpBB/includes/ucp/ucp_register.php | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 937d9e926f..575d05933f 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -901,7 +901,9 @@ class acp_board */ function timezone_select($value, $key) { - $timezone_select = phpbb_timezone_select($value, true); + global $user; + + $timezone_select = phpbb_timezone_select($user, $value, true); $timezone_select['tz_select']; return ''; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index a228e07c22..3f05f216d9 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1639,7 +1639,7 @@ class acp_users ${'s_sort_' . $sort_option . '_dir'} .= ''; } - $timezone_selects = phpbb_timezone_select($data['tz'], true, false); + $timezone_selects = phpbb_timezone_select($user, $data['tz'], true); $template->assign_vars(array( 'S_PREFS' => true, 'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true, diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 98465ca462..0b71ea3484 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1184,22 +1184,23 @@ function phpbb_get_timezone_identifiers($selected_timezone) */ function tz_select($default = '', $truncate = false) { - $timezone_select = phpbb_timezone_select($default, $truncate); + global $user; + + $timezone_select = phpbb_timezone_select($user, $default, $truncate); return $timezone_select['tz_select']; } /** * Options to pick a timezone and date/time * +* @param phpbb_user $user Object of the current user * @param string $default A timezone to select * @param boolean $truncate Shall we truncate the options text * * @return array Returns an array, also containing the options for the time selector. */ -function phpbb_timezone_select($default = '', $truncate = false) +function phpbb_timezone_select($user, $default = '', $truncate = false) { - global $user; - static $timezones; $default_offset = ''; diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index f63758c52d..2228bc7931 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -131,7 +131,7 @@ class ucp_prefs } $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . ''; - $timezone_selects = phpbb_timezone_select($data['tz'], true, false); + $timezone_selects = phpbb_timezone_select($user, $data['tz'], true); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 705000d7a8..6ce53a79ab 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -442,7 +442,7 @@ class ucp_register break; } - $timezone_selects = phpbb_timezone_select($data['tz'], true, false); + $timezone_selects = phpbb_timezone_select($user, $data['tz'], true); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', 'USERNAME' => $data['username'],