X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FTimeZone.php;h=a420eb9674242b48ea1414aaf7438fc9639798c6;hb=8f423eb11c6642d96b5144f56e4698652591ad6b;hp=ccbef918b3f6f9c6db91c50c17df5c7b8ce7a7af;hpb=96db105e4c0833324f7168edb5673278de8ccd54;p=github%2Fshaarli%2FShaarli.git
diff --git a/application/TimeZone.php b/application/TimeZone.php
index ccbef918..a420eb96 100644
--- a/application/TimeZone.php
+++ b/application/TimeZone.php
@@ -1,89 +1,76 @@
'Europe',
+ * ],
+ * [
+ * ['continent' => 'America', 'city' => 'Toronto'],
+ * ['continent' => 'Europe', 'city' => 'Paris'],
+ * 'selected' => 'Paris',
+ * ],
+ * ];
*
- * Example: preselect Europe/Paris
- * list($htmlform, $js) = templateTZform('Europe/Paris');
+ * Notes:
+ * - 'UTC/UTC' is mapped to 'UTC' to form a valid option
+ * - a few timezone cities includes the country/state, such as Argentina/Buenos_Aires
+ * - these arrays are designed to build timezone selects in template files with any HTML structure
*
- * @param string $preselected_timezone preselected timezone (optional)
+ * @param array $installedTimeZones List of installed timezones as string
+ * @param string $preselectedTimezone preselected timezone (optional)
*
- * @return an array containing the generated HTML form and Javascript code
+ * @return array[] continents and cities
**/
-function generateTimeZoneForm($preselected_timezone='')
+function generateTimeZoneData($installedTimeZones, $preselectedTimezone = '')
{
- // Select the first available timezone if no preselected value is passed
- if ($preselected_timezone == '') {
- $l = timezone_identifiers_list();
- $preselected_timezone = $l[0];
+ if ($preselectedTimezone == 'UTC') {
+ $pcity = $pcontinent = 'UTC';
+ } else {
+ // Try to split the provided timezone
+ $spos = strpos($preselectedTimezone, '/');
+ $pcontinent = substr($preselectedTimezone, 0, $spos);
+ $pcity = substr($preselectedTimezone, $spos + 1);
}
- // Try to split the provided timezone
- $spos = strpos($preselected_timezone, '/');
- $pcontinent = substr($preselected_timezone, 0, $spos);
- $pcity = substr($preselected_timezone, $spos+1);
-
- // Display config form:
- $timezone_form = '';
- $timezone_js = '';
-
- // The list is in the form 'Europe/Paris', 'America/Argentina/Buenos_Aires'...
- // We split the list in continents/cities.
- $continents = array();
- $cities = array();
-
- // TODO: use a template to generate the HTML/Javascript form
-
- foreach (timezone_identifiers_list() as $tz) {
+ $continents = [];
+ $cities = [];
+ foreach ($installedTimeZones as $tz) {
if ($tz == 'UTC') {
$tz = 'UTC/UTC';
}
$spos = strpos($tz, '/');
- if ($spos !== false) {
- $continent = substr($tz, 0, $spos);
- $city = substr($tz, $spos+1);
- $continents[$continent] = 1;
-
- if (!isset($cities[$continent])) {
- $cities[$continent] = '';
- }
- $cities[$continent] .= '