From 0f320a6c48d63154bba45c2937adeee79165816c Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 8 Jul 2010 21:56:51 +0100 Subject: [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 | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions.php') 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; + static $timezones; + + if (!isset($timezones)) + { + $timezones = DateTimeZone::listIdentifiers(); + + sort($timezones); + } + $tz_select = ''; - foreach ($user->lang['tz_zones'] as $offset => $zone) + + foreach ($timezones as $timezone) { - if ($truncate) + 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; -- cgit v1.2.1 From 190b019fa28f59c018554916e33446d93efb7311 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 8 Jul 2010 22:09:24 +0100 Subject: [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(-) (limited to 'phpBB/includes/functions.php') 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) -- cgit v1.2.1 From bb461c8daa97358e8bcce923a21eba0abd6ea3dc Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 Mar 2011 19:14:53 -0500 Subject: [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/includes/functions.php | 71 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') 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 = ''; -- cgit v1.2.1 From 50936cb2eff3f80d99390c76ef6ac535e73f6cc3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 19:06:46 +0200 Subject: [feature/new-tz-handling] Fix selecting and validating of timezone in UCP PHPBB3-9558 --- phpBB/includes/functions.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions.php') 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; -- cgit v1.2.1 From 00b5e5345dc44c99340bba932522b6b05b48dab2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 19:19:34 +0200 Subject: [feature/new-tz-handling] Fix displaying of "All times are" string PHPBB3-9558 --- phpBB/includes/functions.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') 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, -- cgit v1.2.1 From 66f7d45603417df7619323977de62aebce0bf676 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 5 Jun 2012 21:44:44 +0200 Subject: [feature/new-tz-handling] Introduce 2 step timezone selection using javascript PHPBB3-9558 --- phpBB/includes/functions.php | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/functions.php') 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 .= ''; - return $tz_select; + if ($return_tzs_only) + { + return $tz_select; + } + + return array( + 'tz_select' => $tz_select, + 'tz_dates' => $tz_dates, + ); } // Functions handling topic/post tracking/marking -- cgit v1.2.1 From 9836efc13c73ddf2382a40cb8ce5a4181d5831ca Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Jun 2012 11:03:39 +0200 Subject: [feature/new-tz-handling] Inject $user to avoid the usage of global PHPBB3-9558 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9263833b4c..19e59f2ddb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1145,7 +1145,7 @@ function tz_select($default = '', $truncate = false, $return_tzs_only = true) foreach ($unsorted_timezones as $timezone) { $tz = new DateTimeZone($timezone); - $dt = new phpbb_datetime('now', $tz); + $dt = new phpbb_datetime('now', $tz, $user); $offset = $dt->getOffset(); $current_time = $dt->format($user->lang['DATETIME_FORMAT'], true); $offset_string = phpbb_format_timezone_offset($offset); @@ -4794,7 +4794,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } } - $dt = new phpbb_datetime('now', $user->tz); + $dt = new phpbb_datetime('now', $user->tz, $user); $timezone_offset = 'GMT' . phpbb_format_timezone_offset($dt->getOffset()); $timezone_name = $user->tz->getName(); if (isset($user->lang['timezones'][$timezone_name])) -- cgit v1.2.1 From 1716e2a2a57903464bf4a1b6843bca913c656695 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Jun 2012 11:28:23 +0200 Subject: [feature/new-tz-handling] Update doc blocks for the three timezone functions PHPBB3-9558 --- phpBB/includes/functions.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 19e59f2ddb..618af7ee00 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1068,6 +1068,13 @@ function style_select($default = '', $all = false) return $style_options; } +/** +* Format the timezone offset with hours and minutes +* +* @param int $tz_offset Timezone offset in seconds +* @return string Normalized offset string: -7200 => -02:00 +* 16200 => +04:30 +*/ function phpbb_format_timezone_offset($tz_offset) { $sign = ($tz_offset < 0) ? '-' : '+'; @@ -1081,9 +1088,11 @@ function phpbb_format_timezone_offset($tz_offset) 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. +/** +* 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]; @@ -1129,6 +1138,14 @@ function tz_select_compare($a, $b) /** * Pick a timezone +* +* @param string $default A timezone to select +* @param boolean $truncate Shall we truncate the options text +* @param boolean $return_tzs_only Shall we just return the options for the timezone selector, +* or also return the options for the time selector. +* +* @return string/array Returns either the options for timezone selector +* or an array, also containing the options for the time selector. */ function tz_select($default = '', $truncate = false, $return_tzs_only = true) { -- cgit v1.2.1 From c7d32a1b2d300618278cb8178f9dfefa93804167 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 19 Jun 2012 19:26:57 +0200 Subject: [feature/new-tz-handling] Prefix function with phpbb_ PHPBB3-9558 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 618af7ee00..53511291b5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1093,7 +1093,7 @@ function phpbb_format_timezone_offset($tz_offset) * Arranges them in increasing order by timezone offset. * Places UTC before other timezones in the same offset. */ -function tz_select_compare($a, $b) +function phpbb_tz_select_compare($a, $b) { $a_sign = $a[3]; $b_sign = $b[3]; @@ -1178,7 +1178,7 @@ function tz_select($default = '', $truncate = false, $return_tzs_only = true) } unset($unsorted_timezones); - uksort($timezones, 'tz_select_compare'); + uksort($timezones, 'phpbb_tz_select_compare'); } $tz_select = $tz_dates = $opt_group = ''; -- cgit v1.2.1 From 82e195ac683f6604aee9862233ffcb4f58af64b0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 14:34:35 +0200 Subject: [feature/new-tz-handling] Fix code and doc layout PHPBB3-9558 --- phpBB/includes/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 53511291b5..98a08ea4d3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1111,10 +1111,12 @@ function phpbb_tz_select_compare($a, $b) if ($a_name == $b_name) { return 0; - } else if ($a_name == 'UTC') + } + else if ($a_name == 'UTC') { return -1; - } else if ($b_name == 'UTC') + } + else if ($b_name == 'UTC') { return 1; } -- 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/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 98a08ea4d3..4fc2739f33 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1164,7 +1164,7 @@ function tz_select($default = '', $truncate = false, $return_tzs_only = true) foreach ($unsorted_timezones as $timezone) { $tz = new DateTimeZone($timezone); - $dt = new phpbb_datetime('now', $tz, $user); + $dt = new phpbb_datetime($user, 'now', $tz); $offset = $dt->getOffset(); $current_time = $dt->format($user->lang['DATETIME_FORMAT'], true); $offset_string = phpbb_format_timezone_offset($offset); @@ -4813,7 +4813,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } } - $dt = new phpbb_datetime('now', $user->tz, $user); + $dt = new phpbb_datetime($user, 'now', $user->tz); $timezone_offset = 'GMT' . phpbb_format_timezone_offset($dt->getOffset()); $timezone_name = $user->tz->getName(); if (isset($user->lang['timezones'][$timezone_name])) -- cgit v1.2.1 From 3637cd395e39c1fa5b7279222abe1da5d2abcd00 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 17 Jul 2012 16:09:05 +0200 Subject: [feature/new-tz-handling] Properly name new timezone selection function Marked the old one as deprecated and made it using the new function. PHPBB3-9558 --- phpBB/includes/functions.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4fc2739f33..3533a4ca00 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1143,13 +1143,26 @@ function phpbb_tz_select_compare($a, $b) * * @param string $default A timezone to select * @param boolean $truncate Shall we truncate the options text -* @param boolean $return_tzs_only Shall we just return the options for the timezone selector, -* or also return the options for the time selector. * -* @return string/array Returns either the options for timezone selector -* or an array, also containing the options for the time selector. +* @return string Returns the options for timezone selector only +* +* @deprecated +*/ +function tz_select($default = '', $truncate = false) +{ + $timezone_select = phpbb_timezone_select($default, $truncate); + return $timezone_select['tz_select']; +} + +/** +* Options to pick a timezone and date/time +* +* @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 tz_select($default = '', $truncate = false, $return_tzs_only = true) +function phpbb_timezone_select($default = '', $truncate = false) { global $user; @@ -1220,11 +1233,6 @@ function tz_select($default = '', $truncate = false, $return_tzs_only = true) } $tz_select .= ''; - if ($return_tzs_only) - { - return $tz_select; - } - return array( 'tz_select' => $tz_select, 'tz_dates' => $tz_dates, -- cgit v1.2.1 From 922147f05a75d5a0e00b34f0102bc014583df984 Mon Sep 17 00:00:00 2001 From: Drae Date: Wed, 4 Jul 2012 23:19:59 +0100 Subject: [ticket/10968] Render pagination within the template Since phpBB 2 pagination has been rendered mostly within the source. This limits just what designers can do with pagination. The current form is also questionable in terms of "best practice". The aim is to move rendering completely to the template via the use of a block element. Enabling S_ template vars also allows for control over specific aspects of the pagination output such as next, previous, active and ellipsis. Related to this - merging the capabilities of the topic_generate_pagination with generate_pagination removes an element of duplication. PHPBB3-10968 --- phpBB/includes/functions.php | 98 +++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 42 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e40df93194..b7b8ccda0f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1884,85 +1884,99 @@ function tracking_unserialize($string, $max_depth = 3) * Pagination routine, generates page number sequence * tpl_prefix is for using different pagination blocks at one page */ -function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = '') +function generate_pagination($base_url, $num_items, $per_page, $start_item = 1, $tpl_prefix = '', $reverse_count = false, $ignore_on_page = false, $block_var_name = '') { global $template, $user; // Make sure $per_page is a valid value $per_page = ($per_page <= 0) ? 1 : $per_page; - $separator = '' . $user->lang['COMMA_SEPARATOR'] . ''; $total_pages = ceil($num_items / $per_page); if ($total_pages == 1 || !$num_items) { - return false; + return; } $on_page = floor($start_item / $per_page) + 1; $url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&'); - - $page_string = ($on_page == 1) ? '1' : '1'; - - if ($total_pages > 5) + $block_var_name = ($block_var_name) ? $block_var_name . '.pagination' : 'pagination'; + + if ($reverse_count) { - $start_cnt = min(max(1, $on_page - 4), $total_pages - 5); - $end_cnt = max(min($total_pages, $on_page + 4), 6); - - $page_string .= ($start_cnt > 1) ? ' ... ' : $separator; - - for ($i = $start_cnt + 1; $i < $end_cnt; $i++) - { - $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . ''; - if ($i < $end_cnt - 1) - { - $page_string .= $separator; - } - } - - $page_string .= ($end_cnt < $total_pages) ? ' ... ' : $separator; + $start_cnt = ($total_pages > 5) ? $total_pages - 3 : 1; + $end_cnt = $total_pages; } else { - $page_string .= $separator; - - for ($i = 2; $i < $total_pages; $i++) - { - $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . ''; - if ($i < $total_pages) - { - $page_string .= $separator; - } - } + $start_cnt = ($total_pages > 5) ? min(max(1, $on_page - 4), $total_pages - 5) : 1; + $end_cnt = ($total_pages > 5) ? max(min($total_pages, $on_page + 4), 6) : $total_pages; } - $page_string .= ($on_page == $total_pages) ? '' . $total_pages . '' : '' . $total_pages . ''; - - if ($add_prevnext_text) + if ($on_page != $total_pages) + { + $template->assign_block_vars($block_var_name, array( + 'PAGE_NUMBER' => '', + 'PAGE_URL' => $base_url . "{$url_delim}start=" . ($on_page * $per_page), + 'S_IS_CURRENT' => false, + 'S_IS_PREV' => false, + 'S_IS_NEXT' => true, + 'S_IS_ELLIPSIS' => false, + )); + } + + $i = 1; + do { - if ($on_page != 1) + $page_url = $base_url . (($i == 1) ? '' : $url_delim . 'start=' . (($i - 1) * $per_page)); + + $template->assign_block_vars($block_var_name, array( + 'PAGE_NUMBER' => $i, + 'PAGE_URL' => $page_url, + 'S_IS_CURRENT' => (!$ignore_on_page && $i == $on_page) ? true : false, + 'S_IS_NEXT' => false, + 'S_IS_PREV' => false, + 'S_IS_ELLIPSIS' => ($i == 2 && $start_cnt > 1) || ($i == $total_pages - 1 && $end_cnt < $total_pages) ? true : false, + )); + + if ($i > 1 && $i < $start_cnt - 1) { - $page_string = '' . $user->lang['PREVIOUS'] . '  ' . $page_string; + $i = $start_cnt; } - - if ($on_page != $total_pages) + elseif ($i == $end_cnt && $end_cnt < $total_pages - 1) + { + $i = $total_pages - 1; + } + else { - $page_string .= '  ' . $user->lang['NEXT'] . ''; + $i++; } } + while ($i <= $total_pages); + if ($on_page != 1) + { + $template->assign_block_vars($block_var_name, array( + 'PAGE_NUMBER' => '', + 'PAGE_URL' => $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), + 'S_IS_CURRENT' => false, + 'S_IS_PREV' => true, + 'S_IS_NEXT' => false, + 'S_IS_ELLIPSIS' => false, + )); + } + $template->assign_vars(array( $tpl_prefix . 'BASE_URL' => $base_url, 'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url), $tpl_prefix . 'PER_PAGE' => $per_page, - $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), $tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . "{$url_delim}start=" . ($on_page * $per_page), $tpl_prefix . 'TOTAL_PAGES' => $total_pages, $tpl_prefix . 'CURRENT_PAGE' => $on_page, )); - return $page_string; + return; } /** -- cgit v1.2.1 From dc71c0629e60acccd39b59538f2e7f5b09b32509 Mon Sep 17 00:00:00 2001 From: Drae Date: Thu, 5 Jul 2012 18:56:14 +0100 Subject: [feature/pagination-as-list] Various fixes and improvements Extracted common template code for prosilver as per subsilver2. Various other fixups and oversight corrections, changed name of the "new" template function and re-introduced existing version. Altered on_page to compensate for removal of some templating vars from pagination routine. PHPBB3-10968 --- phpBB/includes/functions.php | 199 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 162 insertions(+), 37 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b7b8ccda0f..33b009307e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1882,15 +1882,115 @@ function tracking_unserialize($string, $max_depth = 3) /** * Pagination routine, generates page number sequence -* tpl_prefix is for using different pagination blocks at one page +* To generate pagination which is rendered fully within the template use generate_template_pagination +* +* @param string $base_url the base url is prepended to all links generated within the function +* @param int $num_items the total number of items, posts, topics, etc., used to determine the number of pages to produce +* @param int $per_page the number of items, posts, topics, etc. to display per page, used to determine the number of pages to produce +* @param int $start_item the item which should be considered currently active, used to determine the page we're on +* @param bool $add_prevnext_text appends and prepends next and previous links (true) or not (false) +* @param string $tpl_prefix is for using different pagination blocks at one page */ -function generate_pagination($base_url, $num_items, $per_page, $start_item = 1, $tpl_prefix = '', $reverse_count = false, $ignore_on_page = false, $block_var_name = '') +function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = '') { global $template, $user; // Make sure $per_page is a valid value $per_page = ($per_page <= 0) ? 1 : $per_page; + $separator = '' . $user->lang['COMMA_SEPARATOR'] . ''; + $total_pages = ceil($num_items / $per_page); + + if ($total_pages == 1 || !$num_items) + { + return false; + } + + $on_page = floor($start_item / $per_page) + 1; + $url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&'); + + $page_string = ($on_page == 1) ? '1' : '1'; + + if ($total_pages > 5) + { + $start_cnt = min(max(1, $on_page - 4), $total_pages - 5); + $end_cnt = max(min($total_pages, $on_page + 4), 6); + + $page_string .= ($start_cnt > 1) ? ' ... ' : $separator; + + for ($i = $start_cnt + 1; $i < $end_cnt; $i++) + { + $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . ''; + if ($i < $end_cnt - 1) + { + $page_string .= $separator; + } + } + + $page_string .= ($end_cnt < $total_pages) ? ' ... ' : $separator; + } + else + { + $page_string .= $separator; + + for ($i = 2; $i < $total_pages; $i++) + { + $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . ''; + if ($i < $total_pages) + { + $page_string .= $separator; + } + } + } + + $page_string .= ($on_page == $total_pages) ? '' . $total_pages . '' : '' . $total_pages . ''; + + if ($add_prevnext_text) + { + if ($on_page != 1) + { + $page_string = '' . $user->lang['PREVIOUS'] . '  ' . $page_string; + } + + if ($on_page != $total_pages) + { + $page_string .= '  ' . $user->lang['NEXT'] . ''; + } + } + + $template->assign_vars(array( + $tpl_prefix . 'BASE_URL' => $base_url, + 'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url), + $tpl_prefix . 'PER_PAGE' => $per_page, + + $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), + $tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . "{$url_delim}start=" . ($on_page * $per_page), + $tpl_prefix . 'TOTAL_PAGES' => $total_pages, + $tpl_prefix . 'CURRENT_PAGE' => $on_page, + )); + + return $page_string; +} + +/** +* Generate template rendered pagination +* Allows full control of rendering of pagination with the template +* +* @param string $base_url is url prepended to all links generated within the function +* @param string $block_var_name is the name assigned to the pagination data block within the template (example: ) +* @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce +* @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce +* @param int $start_item the item which should be considered currently active, used to determine the page we're on +* @param bool $reverse_count determines whether we weight display of the list towards the start (false) or end (true) of the list +* @param bool $ignore_on_page decides whether we enable an active (unlinked) item, used primarily for embedded lists +* +*/ +function generate_template_pagination($base_url, $block_var_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) +{ + global $template; + + // Make sure $per_page is a valid value + $per_page = ($per_page <= 0) ? 1 : $per_page; $total_pages = ceil($num_items / $per_page); if ($total_pages == 1 || !$num_items) @@ -1900,17 +2000,31 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item = 1, $on_page = floor($start_item / $per_page) + 1; $url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&'); - $block_var_name = ($block_var_name) ? $block_var_name . '.pagination' : 'pagination'; if ($reverse_count) { - $start_cnt = ($total_pages > 5) ? $total_pages - 3 : 1; - $end_cnt = $total_pages; + $start_page = ($total_pages > 5) ? $total_pages - 4 : 1; + $end_page = $total_pages; } else { - $start_cnt = ($total_pages > 5) ? min(max(1, $on_page - 4), $total_pages - 5) : 1; - $end_cnt = ($total_pages > 5) ? max(min($total_pages, $on_page + 4), 6) : $total_pages; + // What we're doing here is calculating what the "start" and "end" pages should be. We + // do this by assuming pagination is "centered" around the currently active page with + // the three previous and three next page links displayed. Anything more than that and + // we display the ellipsis, likewise anything less. + // + // $start_page is the page at which we start creating the list. When we have five or less + // pages we start at page 1 since there will be no ellipsis displayed. Anymore than that + // and we calculate the start based on the active page. This is the min/max calculation. + // First (max) would we end up starting on a page less than 1? Next (min) would we end + // up starting so close to the end that we'd not display our minimum number of pages. + // + // $end_page is the last page in the list to display. Like $start_page we use a min/max to + // determine this number. Again at most five pages? Then just display them all. More than + // five and we first (min) determine whether we'd end up listing more pages than exist. + // We then (max) ensure we're displaying the minimum number of pages. + $start_page = ($total_pages > 5) ? min(max(1, $on_page - 3), $total_pages - 4) : 1; + $end_page = ($total_pages > 5) ? max(min($total_pages, $on_page + 3), 5) : $total_pages; } if ($on_page != $total_pages) @@ -1924,35 +2038,48 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item = 1, 'S_IS_ELLIPSIS' => false, )); } - - $i = 1; + + // This do...while exists purely to negate the need for start and end assign_block_vars, i.e. + // to display the first and last page in the list plus any ellipsis. We use this loop to jump + // around a little within the list depending on where we're starting (and ending). + $at_page = 1; do { - $page_url = $base_url . (($i == 1) ? '' : $url_delim . 'start=' . (($i - 1) * $per_page)); - + $page_url = $base_url . (($at_page == 1) ? '' : $url_delim . 'start=' . (($at_page - 1) * $per_page)); + + // We decide whether to display the ellipsis during the loop. The ellipsis is always + // displayed as either the second or penultimate item in the list. So are we at either + // of those points and of course do we even need to display it, i.e. is the list starting + // on at least page 3 and ending three pages before the final item. $template->assign_block_vars($block_var_name, array( - 'PAGE_NUMBER' => $i, + 'PAGE_NUMBER' => $at_page, 'PAGE_URL' => $page_url, - 'S_IS_CURRENT' => (!$ignore_on_page && $i == $on_page) ? true : false, + 'S_IS_CURRENT' => (!$ignore_on_page && $at_page == $on_page), 'S_IS_NEXT' => false, 'S_IS_PREV' => false, - 'S_IS_ELLIPSIS' => ($i == 2 && $start_cnt > 1) || ($i == $total_pages - 1 && $end_cnt < $total_pages) ? true : false, + 'S_IS_ELLIPSIS' => ($at_page == 2 && $start_page > 2) || ($at_page == $total_pages - 1 && $end_page < $total_pages - 1), )); - - if ($i > 1 && $i < $start_cnt - 1) + + // We may need to jump around in the list depending on whether we have or need to display + // the ellipsis. Are we on page 2 and are we more than one page away from the start + // of the list? Yes? Then we jump to the start of the list. Likewise are we at the end of + // the list and are there more than two pages left in total? Yes? Then jump to the penultimate + // page (so we can display the ellipsis next pass). Else, increment the counter and keep + // going + if ($at_page == 2 && $at_page < $start_page - 1) { - $i = $start_cnt; + $at_page = $start_page; } - elseif ($i == $end_cnt && $end_cnt < $total_pages - 1) + else if ($at_page == $end_page && $end_page < $total_pages - 1) { - $i = $total_pages - 1; + $at_page = $total_pages - 1; } else { - $i++; + $at_page++; } } - while ($i <= $total_pages); + while ($at_page <= $total_pages); if ($on_page != 1) { @@ -1965,24 +2092,19 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item = 1, 'S_IS_ELLIPSIS' => false, )); } - - $template->assign_vars(array( - $tpl_prefix . 'BASE_URL' => $base_url, - 'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url), - $tpl_prefix . 'PER_PAGE' => $per_page, - $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), - $tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . "{$url_delim}start=" . ($on_page * $per_page), - $tpl_prefix . 'TOTAL_PAGES' => $total_pages, - $tpl_prefix . 'CURRENT_PAGE' => $on_page, - )); - - return; } /** -* Return current page (pagination) +* Return current page +* This function also sets certain specific template variables +* +* @param string $base_url the base url used to call this page, used by Javascript for popup jump to page +* @param int $num_items the total number of items, posts, topics, etc. +* @param int $per_page the number of items, posts, etc. per page +* @param int $start the item which should be considered currently active, used to determine the page we're on +* */ -function on_page($num_items, $per_page, $start) +function on_page($base_url, $num_items, $per_page, $start) { global $template, $user; @@ -1992,8 +2114,11 @@ function on_page($num_items, $per_page, $start) $on_page = floor($start / $per_page) + 1; $template->assign_vars(array( - 'ON_PAGE' => $on_page) - ); + 'PER_PAGE' => $per_page, + 'ON_PAGE' => $on_page, + + 'A_BASE_URL' => addslashes($base_url), + )); return sprintf($user->lang['PAGE_OF'], $on_page, max(ceil($num_items / $per_page), 1)); } -- cgit v1.2.1 From cf4d6e926dd83d61073ac355cdaf7778a18dcbf8 Mon Sep 17 00:00:00 2001 From: Drae Date: Fri, 6 Jul 2012 14:44:04 +0100 Subject: [feature/pagination-as-list] Rename and deprecate functions Returned and marked deprecated topic_generate_pagination. Rename new function in line with coding guidelines. PHPBB3-10968 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 33b009307e..91c2242d4f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1882,7 +1882,7 @@ function tracking_unserialize($string, $max_depth = 3) /** * Pagination routine, generates page number sequence -* To generate pagination which is rendered fully within the template use generate_template_pagination +* To generate pagination which is rendered fully within the template use phpbb_generate_template_pagination * * @param string $base_url the base url is prepended to all links generated within the function * @param int $num_items the total number of items, posts, topics, etc., used to determine the number of pages to produce @@ -1985,7 +1985,7 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add * @param bool $ignore_on_page decides whether we enable an active (unlinked) item, used primarily for embedded lists * */ -function generate_template_pagination($base_url, $block_var_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) +function phpbb_generate_template_pagination($base_url, $block_var_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) { global $template; -- cgit v1.2.1 From 27d8aef528460e87efc90bc4fffc82c0d1fa87d9 Mon Sep 17 00:00:00 2001 From: Drae Date: Sun, 8 Jul 2012 21:07:28 +0100 Subject: [feature/pagination-as-list] Updates for nils comments Re-remove deprecated functions, change on_page to phpbb_on_page, add null returns, remove globals and pass as params. PHPBB3-10968 --- phpBB/includes/functions.php | 107 +++---------------------------------------- 1 file changed, 7 insertions(+), 100 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 91c2242d4f..8c740edbfd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1880,102 +1880,11 @@ function tracking_unserialize($string, $max_depth = 3) // Pagination functions -/** -* Pagination routine, generates page number sequence -* To generate pagination which is rendered fully within the template use phpbb_generate_template_pagination -* -* @param string $base_url the base url is prepended to all links generated within the function -* @param int $num_items the total number of items, posts, topics, etc., used to determine the number of pages to produce -* @param int $per_page the number of items, posts, topics, etc. to display per page, used to determine the number of pages to produce -* @param int $start_item the item which should be considered currently active, used to determine the page we're on -* @param bool $add_prevnext_text appends and prepends next and previous links (true) or not (false) -* @param string $tpl_prefix is for using different pagination blocks at one page -*/ -function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = '') -{ - global $template, $user; - - // Make sure $per_page is a valid value - $per_page = ($per_page <= 0) ? 1 : $per_page; - - $separator = '' . $user->lang['COMMA_SEPARATOR'] . ''; - $total_pages = ceil($num_items / $per_page); - - if ($total_pages == 1 || !$num_items) - { - return false; - } - - $on_page = floor($start_item / $per_page) + 1; - $url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&'); - - $page_string = ($on_page == 1) ? '1' : '1'; - - if ($total_pages > 5) - { - $start_cnt = min(max(1, $on_page - 4), $total_pages - 5); - $end_cnt = max(min($total_pages, $on_page + 4), 6); - - $page_string .= ($start_cnt > 1) ? ' ... ' : $separator; - - for ($i = $start_cnt + 1; $i < $end_cnt; $i++) - { - $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . ''; - if ($i < $end_cnt - 1) - { - $page_string .= $separator; - } - } - - $page_string .= ($end_cnt < $total_pages) ? ' ... ' : $separator; - } - else - { - $page_string .= $separator; - - for ($i = 2; $i < $total_pages; $i++) - { - $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . ''; - if ($i < $total_pages) - { - $page_string .= $separator; - } - } - } - - $page_string .= ($on_page == $total_pages) ? '' . $total_pages . '' : '' . $total_pages . ''; - - if ($add_prevnext_text) - { - if ($on_page != 1) - { - $page_string = '' . $user->lang['PREVIOUS'] . '  ' . $page_string; - } - - if ($on_page != $total_pages) - { - $page_string .= '  ' . $user->lang['NEXT'] . ''; - } - } - - $template->assign_vars(array( - $tpl_prefix . 'BASE_URL' => $base_url, - 'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url), - $tpl_prefix . 'PER_PAGE' => $per_page, - - $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), - $tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . "{$url_delim}start=" . ($on_page * $per_page), - $tpl_prefix . 'TOTAL_PAGES' => $total_pages, - $tpl_prefix . 'CURRENT_PAGE' => $on_page, - )); - - return $page_string; -} - /** * Generate template rendered pagination * Allows full control of rendering of pagination with the template * +* @param object $template the template object * @param string $base_url is url prepended to all links generated within the function * @param string $block_var_name is the name assigned to the pagination data block within the template (example: ) * @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce @@ -1983,12 +1892,10 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add * @param int $start_item the item which should be considered currently active, used to determine the page we're on * @param bool $reverse_count determines whether we weight display of the list towards the start (false) or end (true) of the list * @param bool $ignore_on_page decides whether we enable an active (unlinked) item, used primarily for embedded lists -* +* @return null */ -function phpbb_generate_template_pagination($base_url, $block_var_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) +function phpbb_generate_template_pagination($template, $base_url, $block_var_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) { - global $template; - // Make sure $per_page is a valid value $per_page = ($per_page <= 0) ? 1 : $per_page; $total_pages = ceil($num_items / $per_page); @@ -2098,16 +2005,16 @@ function phpbb_generate_template_pagination($base_url, $block_var_name, $num_ite * Return current page * This function also sets certain specific template variables * +* @param object $template the template object +* @param object $user the user object * @param string $base_url the base url used to call this page, used by Javascript for popup jump to page * @param int $num_items the total number of items, posts, topics, etc. * @param int $per_page the number of items, posts, etc. per page * @param int $start the item which should be considered currently active, used to determine the page we're on -* +* @return null */ -function on_page($base_url, $num_items, $per_page, $start) +function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $start) { - global $template, $user; - // Make sure $per_page is a valid value $per_page = ($per_page <= 0) ? 1 : $per_page; -- cgit v1.2.1 From 584d49459d22ebf47239fc97ad8358a5404dacf4 Mon Sep 17 00:00:00 2001 From: Drae Date: Thu, 12 Jul 2012 02:36:00 +0100 Subject: [feature/pagination-as-list] New parameter for name of start var Add a new parameter to hold the name of the start variable. This fulfills ticket PHPBB3-8535. PHPBB3-10968 --- phpBB/includes/functions.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8c740edbfd..633ac3d307 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1887,6 +1887,7 @@ function tracking_unserialize($string, $max_depth = 3) * @param object $template the template object * @param string $base_url is url prepended to all links generated within the function * @param string $block_var_name is the name assigned to the pagination data block within the template (example: ) +* @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20) * @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce * @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce * @param int $start_item the item which should be considered currently active, used to determine the page we're on @@ -1894,7 +1895,7 @@ function tracking_unserialize($string, $max_depth = 3) * @param bool $ignore_on_page decides whether we enable an active (unlinked) item, used primarily for embedded lists * @return null */ -function phpbb_generate_template_pagination($template, $base_url, $block_var_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) +function phpbb_generate_template_pagination($template, $base_url, $block_var_name, $start_name, $num_items, $per_page, $start_item = 1, $reverse_count = false, $ignore_on_page = false) { // Make sure $per_page is a valid value $per_page = ($per_page <= 0) ? 1 : $per_page; @@ -1938,7 +1939,7 @@ function phpbb_generate_template_pagination($template, $base_url, $block_var_nam { $template->assign_block_vars($block_var_name, array( 'PAGE_NUMBER' => '', - 'PAGE_URL' => $base_url . "{$url_delim}start=" . ($on_page * $per_page), + 'PAGE_URL' => $base_url . $url_delim . $start_name . '=' . ($on_page * $per_page), 'S_IS_CURRENT' => false, 'S_IS_PREV' => false, 'S_IS_NEXT' => true, @@ -1952,7 +1953,7 @@ function phpbb_generate_template_pagination($template, $base_url, $block_var_nam $at_page = 1; do { - $page_url = $base_url . (($at_page == 1) ? '' : $url_delim . 'start=' . (($at_page - 1) * $per_page)); + $page_url = $base_url . (($at_page == 1) ? '' : $url_delim . $start_name . '=' . (($at_page - 1) * $per_page)); // We decide whether to display the ellipsis during the loop. The ellipsis is always // displayed as either the second or penultimate item in the list. So are we at either @@ -1992,7 +1993,7 @@ function phpbb_generate_template_pagination($template, $base_url, $block_var_nam { $template->assign_block_vars($block_var_name, array( 'PAGE_NUMBER' => '', - 'PAGE_URL' => $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), + 'PAGE_URL' => $base_url . $url_delim . $start_name . '=' . (($on_page - 2) * $per_page), 'S_IS_CURRENT' => false, 'S_IS_PREV' => true, 'S_IS_NEXT' => false, -- 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/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 22e456c7de..b5d164f7a3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4821,9 +4821,9 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } } - $dt = new phpbb_datetime($user, 'now', $user->tz); + $dt = new phpbb_datetime($user, 'now', $user->timezone); $timezone_offset = 'GMT' . phpbb_format_timezone_offset($dt->getOffset()); - $timezone_name = $user->tz->getName(); + $timezone_name = $user->timezone->getName(); if (isset($user->lang['timezones'][$timezone_name])) { $timezone_name = $user->lang['timezones'][$timezone_name]; -- cgit v1.2.1 From 248a52be2af2d450be0447b7a241727cb3d61844 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 Jul 2012 16:55:14 +0200 Subject: [feature/new-tz-handling] Delete old variable which is not used anymore PHPBB3-9558 --- phpBB/includes/functions.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b5d164f7a3..c6abcb27ef 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4796,9 +4796,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $board_url = generate_board_url() . '/'; $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $phpbb_root_path; - // Which timezone? - $tz = ($user->data['user_id'] != ANONYMOUS) ? strval(doubleval($user->data['user_timezone'])) : strval(doubleval($config['board_timezone'])); - // Send a proper content-language to the output $user_lang = $user->lang['USER_LANG']; if (strpos($user_lang, '-x-') !== false) -- cgit v1.2.1 From 81627e2888ac0987c941775276a720c2aa7fe142 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 Jul 2012 18:59:25 +0200 Subject: [feature/new-tz-handling] Remove additional marking of selected items PHPBB3-9558 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c6abcb27ef..6a4a67f9d7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1207,7 +1207,7 @@ function phpbb_timezone_select($default = '', $truncate = false) $opt_group = $timezone['offest']; $selected = ($default_offset == $timezone['offest']) ? ' selected="selected"' : ''; - $tz_dates .= ''; + $tz_dates .= ''; } if (isset($user->lang['timezones'][$timezone['tz']])) @@ -1229,7 +1229,7 @@ function phpbb_timezone_select($default = '', $truncate = false) } $selected = ($timezone['tz'] === $default) ? ' selected="selected"' : ''; - $tz_select .= ''; + $tz_select .= ''; } $tz_select .= ''; -- cgit v1.2.1 From d099ef8cade0194fa8056439d489b159d5890f29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Jul 2012 10:34:21 +0200 Subject: [feature/new-tz-handling] Display suggestion when a different value is selected PHPBB3-9558 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 6a4a67f9d7..c6abcb27ef 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1207,7 +1207,7 @@ function phpbb_timezone_select($default = '', $truncate = false) $opt_group = $timezone['offest']; $selected = ($default_offset == $timezone['offest']) ? ' selected="selected"' : ''; - $tz_dates .= ''; + $tz_dates .= ''; } if (isset($user->lang['timezones'][$timezone['tz']])) @@ -1229,7 +1229,7 @@ function phpbb_timezone_select($default = '', $truncate = false) } $selected = ($timezone['tz'] === $default) ? ' selected="selected"' : ''; - $tz_select .= ''; + $tz_select .= ''; } $tz_select .= ''; -- cgit v1.2.1 From 6de222065e737bdab4ecdd010773fb70c415fb3b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Jul 2012 14:36:20 +0200 Subject: [feature/new-tz-handling] Add previous selected value to validation if valid We also add the selected timezone if we can create an object with it. DateTimeZone::listIdentifiers seems to not add all identifiers to the list, because some are only kept for backward compatible reasons. If the user has a deprecated value, we add it here, so it can still be kept. Once the user changed his value, there is no way back to deprecated values. PHPBB3-9558 --- phpBB/includes/functions.php | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c6abcb27ef..98465ca462 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1138,6 +1138,40 @@ function phpbb_tz_select_compare($a, $b) } } +/** +* Return list of timezone identifiers +* We also add the selected timezone if we can create an object with it. +* DateTimeZone::listIdentifiers seems to not add all identifiers to the list, +* because some are only kept for backward compatible reasons. If the user has +* a deprecated value, we add it here, so it can still be kept. Once the user +* changed his value, there is no way back to deprecated values. +* +* @param string $selected_timezone Additional timezone that shall +* be added to the list of identiers +* @return array DateTimeZone::listIdentifiers and additional +* selected_timezone if it is a valid timezone. +*/ +function phpbb_get_timezone_identifiers($selected_timezone) +{ + $timezones = DateTimeZone::listIdentifiers(); + + if (!in_array($selected_timezone, $timezones)) + { + try + { + // Add valid timezones that are currently selected but not returned + // by DateTimeZone::listIdentifiers + $validate_timezone = new DateTimeZone($selected_timezone); + $timezones[] = $selected_timezone; + } + catch (Exception $e) + { + } + } + + return $timezones; +} + /** * Pick a timezone * @@ -1171,9 +1205,9 @@ function phpbb_timezone_select($default = '', $truncate = false) $default_offset = ''; if (!isset($timezones)) { - $unsorted_timezones = DateTimeZone::listIdentifiers(); - $timezones = array(); + $unsorted_timezones = phpbb_get_timezone_identifiers($default); + $timezones = array(); foreach ($unsorted_timezones as $timezone) { $tz = new DateTimeZone($timezone); @@ -1207,7 +1241,7 @@ function phpbb_timezone_select($default = '', $truncate = false) $opt_group = $timezone['offest']; $selected = ($default_offset == $timezone['offest']) ? ' selected="selected"' : ''; - $tz_dates .= ''; + $tz_dates .= ''; } if (isset($user->lang['timezones'][$timezone['tz']])) @@ -1229,7 +1263,7 @@ function phpbb_timezone_select($default = '', $truncate = false) } $selected = ($timezone['tz'] === $default) ? ' selected="selected"' : ''; - $tz_select .= ''; + $tz_select .= ''; } $tz_select .= ''; -- cgit v1.2.1 From 7df1c84447903ecc97a8418339ec6933bdfc9035 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Jul 2012 17:41:27 +0200 Subject: [feature/new-tz-handling] Don't use global user but make it a parameter PHPBB3-9558 --- phpBB/includes/functions.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions.php') 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 = ''; -- cgit v1.2.1