From 57065095d570f0ff5976470ce81a4b216fe5f98e Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 3 Apr 2012 00:41:56 +0300 Subject: [ticket/10754] Changing $style to $phpbb_style Renaming global variable $style to $phpbb_style PHPBB3-10754 --- phpBB/includes/user.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index 1676f82ccb..ce9c804f23 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -72,7 +72,7 @@ class phpbb_user extends phpbb_session */ function setup($lang_set = false, $style_id = false) { - global $db, $style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; + global $db, $phpbb_style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; if ($this->data['user_id'] != ANONYMOUS) { @@ -206,7 +206,7 @@ class phpbb_user extends phpbb_session } } - $style->set_style(); + $phpbb_style->set_style(); $this->img_lang = $this->lang_name; -- cgit v1.2.1 From 33b72ec62bd8b6e6c890e4c474d28389f048632a Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 2 Apr 2012 11:45:26 +0300 Subject: [ticket/10743] Changing obtain_cfg_items Changing obtain_cfg_items to work only with style because other components no longer exist PHPBB3-10743 --- phpBB/includes/user.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index ce9c804f23..1db2364f76 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -188,9 +188,6 @@ class phpbb_user extends phpbb_session // Now parse the cfg file and cache it $parsed_items = $cache->obtain_cfg_items($this->theme); - // We are only interested in the theme configuration for now - $parsed_items = $parsed_items['theme']; - $check_for = array( 'pagination_sep' => (string) ', ' ); -- cgit v1.2.1 From 71ca9b4fe69dea8150a5d3c6f30dd177c488ff2b Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 2 Apr 2012 11:50:13 +0300 Subject: [ticket/10743] Renaming user->theme Renaming user->theme to user->style PHPBB3-10743 --- phpBB/includes/user.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index 1db2364f76..cf9e6b9994 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -27,7 +27,7 @@ class phpbb_user extends phpbb_session { var $lang = array(); var $help = array(); - var $theme = array(); + var $style = array(); var $date_format; var $timezone; var $dst; @@ -159,11 +159,11 @@ class phpbb_user extends phpbb_session FROM ' . STYLES_TABLE . " s WHERE s.style_id = $style_id"; $result = $db->sql_query($sql, 3600); - $this->theme = $db->sql_fetchrow($result); + $this->style = $db->sql_fetchrow($result); $db->sql_freeresult($result); // User has wrong style - if (!$this->theme && $style_id == $this->data['user_style']) + if (!$this->style && $style_id == $this->data['user_style']) { $style_id = $this->data['user_style'] = $config['default_style']; @@ -176,17 +176,17 @@ class phpbb_user extends phpbb_session FROM ' . STYLES_TABLE . " s WHERE s.style_id = $style_id"; $result = $db->sql_query($sql, 3600); - $this->theme = $db->sql_fetchrow($result); + $this->style = $db->sql_fetchrow($result); $db->sql_freeresult($result); } - if (!$this->theme) + if (!$this->style) { trigger_error('Could not get style data', E_USER_ERROR); } // Now parse the cfg file and cache it - $parsed_items = $cache->obtain_cfg_items($this->theme); + $parsed_items = $cache->obtain_cfg_items($this->style); $check_for = array( 'pagination_sep' => (string) ', ' @@ -194,12 +194,12 @@ class phpbb_user extends phpbb_session foreach ($check_for as $key => $default_value) { - $this->theme[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value; - settype($this->theme[$key], gettype($default_value)); + $this->style[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value; + settype($this->style[$key], gettype($default_value)); if (is_string($default_value)) { - $this->theme[$key] = htmlspecialchars($this->theme[$key]); + $this->style[$key] = htmlspecialchars($this->style[$key]); } } -- cgit v1.2.1 From 3c6272ff0475dc19cc67553f370ce227214d0613 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 23:28:48 +0200 Subject: [feature/new-tz-handling] Remove appearances of board_dst and user_dst PHPBB3-9558 --- phpBB/includes/user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/user.php') 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); -- cgit v1.2.1 From 3e3489195fb4d804e65a7a5438c33ac2fe0564b6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Jun 2012 14:32:09 +0200 Subject: [feature/new-tz-handling] Add a function to get the timestamp of a date The function uses the given timezone and returns the correct UNIX timestamp of it. PHPBB3-9558 --- phpBB/includes/user.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index a36d837fbd..0990cc601a 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -647,6 +647,21 @@ class phpbb_user extends phpbb_session return new phpbb_datetime($time, $timezone, $this); } + /** + * Get the UNIX timestamp for a datetime in the users timezone, so we can store it in the database. + * + * @param string $format Format of the entered date/time + * @param string $time Date/time with the timezone applied + * @param DateTimeZone $timezone Timezone of the date/time, falls back to timezone of current user + * @return int Returns the unix timestamp + */ + public function get_timestamp_from_format($format, $time, DateTimeZone $timezone = null) + { + $timezone = $timezone ?: $this->tz; + $date = DateTime::createFromFormat($format, $time, $timezone); + return ($date !== false) ? $date->format('U') : false; + } + /** * Get language id currently used by the user */ -- cgit v1.2.1 From a5628cbdc85a197f32bd14890938dabd23bb6ef6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 00:29:31 +0200 Subject: [feature/new-tz-handling] Fix docs in phpbb_user class PHPBB3-9558 --- phpBB/includes/user.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index 0990cc601a..df8f048c89 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -29,6 +29,10 @@ class phpbb_user extends phpbb_session var $help = array(); var $theme = array(); var $date_format; + + /** + * DateTimeZone object holding the timezone of the user + */ public $tz; var $lang_name = false; @@ -125,7 +129,7 @@ class phpbb_user extends phpbb_session if (is_numeric($this->tz)) { - // Might still be numeric by chance + // Might still be numeric $this->tz = sprintf('Etc/GMT%+d', $this->tz); } -- cgit v1.2.1 From f5bb145040a483a76fd734bb9d4025c54e7917a0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 16 Jul 2012 18:29:31 +0200 Subject: [feature/new-tz-handling] Require user argument on phpbb_datetime PHPBB3-9558 --- phpBB/includes/user.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index df8f048c89..cc50d2b98e 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -631,7 +631,7 @@ class phpbb_user extends phpbb_session $utc = new DateTimeZone('UTC'); } - $time = new phpbb_datetime("@$gmepoch", $utc, $this); + $time = new phpbb_datetime($this, "@$gmepoch", $utc); $time->setTimezone($this->tz); return $time->format($format, $forcedate); @@ -648,7 +648,7 @@ class phpbb_user extends phpbb_session public function create_datetime($time = 'now', DateTimeZone $timezone = null) { $timezone = $timezone ?: $this->tz; - return new phpbb_datetime($time, $timezone, $this); + return new phpbb_datetime($this, $time, $timezone); } /** -- cgit v1.2.1 From 48d3c68290b96c7d2a0e875ec3338f067a529b22 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 16 Jul 2012 18:44:13 +0200 Subject: [feature/new-tz-handling] Use tmp variable for user timezone PHPBB3-9558 --- phpBB/includes/user.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index cc50d2b98e..7dfb375a9b 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -82,13 +82,13 @@ class phpbb_user extends phpbb_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->tz = $this->data['user_timezone']; + $user_timezone = $this->data['user_timezone']; } else { $this->lang_name = basename($config['default_lang']); $this->date_format = $config['default_dateformat']; - $this->tz = $config['board_timezone']; + $user_timezone = $config['board_timezone']; /** * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language @@ -127,13 +127,13 @@ class phpbb_user extends phpbb_session */ } - if (is_numeric($this->tz)) + if (is_numeric($user_timezone)) { // Might still be numeric - $this->tz = sprintf('Etc/GMT%+d', $this->tz); + $user_timezone = sprintf('Etc/GMT%+d', $user_timezone); } - $this->tz = new DateTimeZone($this->tz); + $this->tz = new DateTimeZone($user_timezone); // We include common language file here to not load it every time a custom language file is included $lang = &$this->lang; -- cgit v1.2.1 From 515e1662a900526342b595692d73372f4fb7bbf9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 Jul 2012 14:56:42 +0200 Subject: [feature/new-tz-handling] Remove "timezone might be numeric" As we updated all of the used values, there really shouldn't be one anymore. PHPBB3-9558 --- phpBB/includes/user.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index fb6c1552e8..c3bdc71774 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -127,12 +127,6 @@ class phpbb_user extends phpbb_session */ } - if (is_numeric($user_timezone)) - { - // Might still be numeric - $user_timezone = sprintf('Etc/GMT%+d', $user_timezone); - } - $this->tz = new DateTimeZone($user_timezone); // We include common language file here to not load it every time a custom language file is included -- cgit v1.2.1 From a71e60cdbd3e47c62a565dd777a28aec6832fb88 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 Jul 2012 16:52:52 +0200 Subject: [feature/new-tz-handling] Rename $user->tz back to $user->timezone PHPBB3-9558 --- phpBB/includes/user.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index c3bdc71774..48c328214d 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -33,7 +33,7 @@ class phpbb_user extends phpbb_session /** * DateTimeZone object holding the timezone of the user */ - public $tz; + public $timezone; var $lang_name = false; var $lang_id = false; @@ -127,7 +127,7 @@ class phpbb_user extends phpbb_session */ } - $this->tz = new DateTimeZone($user_timezone); + $this->timezone = new DateTimeZone($user_timezone); // We include common language file here to not load it every time a custom language file is included $lang = &$this->lang; @@ -623,7 +623,7 @@ class phpbb_user extends phpbb_session } $time = new phpbb_datetime($this, "@$gmepoch", $utc); - $time->setTimezone($this->tz); + $time->setTimezone($this->timezone); return $time->format($format, $forcedate); } @@ -638,7 +638,7 @@ class phpbb_user extends phpbb_session */ public function create_datetime($time = 'now', DateTimeZone $timezone = null) { - $timezone = $timezone ?: $this->tz; + $timezone = $timezone ?: $this->timezone; return new phpbb_datetime($this, $time, $timezone); } @@ -652,7 +652,7 @@ class phpbb_user extends phpbb_session */ public function get_timestamp_from_format($format, $time, DateTimeZone $timezone = null) { - $timezone = $timezone ?: $this->tz; + $timezone = $timezone ?: $this->timezone; $date = DateTime::createFromFormat($format, $time, $timezone); return ($date !== false) ? $date->format('U') : false; } -- cgit v1.2.1 From 196e6343702e7d769d1b1668fd29682ad3bade4c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Jul 2012 15:46:12 +0200 Subject: [feature/new-tz-handling] Fall back to UTC, if the timezone is invalid This should avoid problems, when the board files are updated but database isn't. PHPBB3-9558 --- phpBB/includes/user.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/user.php') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index 48c328214d..fcbfaaddfa 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -127,7 +127,15 @@ class phpbb_user extends phpbb_session */ } - $this->timezone = new DateTimeZone($user_timezone); + try + { + $this->timezone = new DateTimeZone($user_timezone); + } + catch (Exception $e) + { + // If the timezone the user has selected is invalid, we fall back to UTC. + $this->timezone = new DateTimeZone('UTC'); + } // We include common language file here to not load it every time a custom language file is included $lang = &$this->lang; -- cgit v1.2.1