X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FTimeZone.php;h=c1869ef87e1d0b96b105c792d8dc902c15ca5246;hb=a3f83c15f4296530d3ceb70adde7c1cfb3f6312e;hp=e363d90a789207b821493a98a65270ba63b1ae97;hpb=afd7b77b4c79a0450a6ef0489ca383c156111173;p=github%2Fshaarli%2FShaarli.git
diff --git a/application/TimeZone.php b/application/TimeZone.php
index e363d90a..c1869ef8 100644
--- a/application/TimeZone.php
+++ b/application/TimeZone.php
@@ -1,23 +1,42 @@
'Europe',
+ * ],
+ * [
+ * ['continent' => 'America', 'city' => 'Toronto'],
+ * ['continent' => 'Europe', 'city' => 'Paris'],
+ * 'selected' => 'Paris',
+ * ],
+ * ];
*
- * @param string $preselected_timezone preselected timezone (optional)
+ * 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
*
- * @return an array containing the generated HTML form and Javascript code
+ * @param array $installedTimeZones List of installed timezones as string
+ * @param string $preselectedTimezone preselected timezone (optional)
+ *
+ * @return array[] continents and cities
**/
-function generateTimeZoneForm($preselectedTimezone='')
+function generateTimeZoneData($installedTimeZones, $preselectedTimezone = '')
{
- // Select the server timezone
- if ($preselectedTimezone == '') {
- $preselectedTimezone = date_default_timezone_get();
- }
-
if ($preselectedTimezone == 'UTC') {
$pcity = $pcontinent = 'UTC';
} else {
@@ -27,66 +46,30 @@ function generateTimeZoneForm($preselectedTimezone='')
$pcity = substr($preselectedTimezone, $spos+1);
}
- // Display config form:
- $timezoneForm = '';
- $timezoneJs = '';
-
- // 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] .= '