2d3a630b |
1 | <?php |
2 | /** |
3 | * SquirrelMail Time zone functions |
4 | * |
5 | * Function load time zone array selected in SquirrelMail |
6 | * configuration. |
7 | * |
8 | * Time zone array must consist of key name that matches key in |
9 | * standard time zone array and 'NAME' and 'TZ' subkeys. 'NAME' |
10 | * key should store translatable key name. 'TZ' key should store |
11 | * time zone name that will be used in TZ environment variable. |
12 | * Both subkeys are optional. If they are not present, time zone |
13 | * key name is used. |
14 | * |
15 | * @package squirrelmail |
16 | * @subpackage timezone |
17 | */ |
18 | |
19 | /** |
20 | * Returns time zone array set in SquirrelMail configuration |
21 | * @return array time zone array |
22 | * @since 1.5.1 |
23 | */ |
24 | function sq_get_tz_array() { |
25 | global $time_zone_type; |
26 | |
27 | // variable is not set or empty |
28 | if (! isset($time_zone_type) || empty($time_zone_type)) { |
29 | $time_zone_type = 0; |
30 | } else { |
31 | // make sure that it is integer |
32 | $time_zone_type = (int) $time_zone_type; |
33 | } |
34 | |
35 | /** |
36 | * TODO: which one is better (global + include_once) or (include) |
37 | */ |
38 | switch ($time_zone_type) { |
39 | case '3': |
40 | case '2': |
41 | // custom time zone set |
42 | $aTimeZones = array(); |
43 | if (file_exists(SM_PATH . 'config/timezones.php')) { |
44 | include(SM_PATH . 'config/timezones.php'); |
45 | } |
46 | $aRet = $aTimeZones; |
47 | break; |
48 | case '1': |
49 | case '0': |
50 | default: |
51 | // standard (default) time zone set |
52 | include(SM_PATH . 'include/timezones/standard.php'); |
53 | $aRet = $aTimeZones; |
54 | } |
55 | // sort array |
56 | ksort($aRet); |
57 | return $aRet; |
58 | } |
59 | |
60 | /** |
61 | * @param string time zone string |
62 | * @return string time zone name used for TZ env |
63 | * (false, if timezone does not exists and server's TZ should be used) |
64 | * @since 1.5.1 |
65 | */ |
66 | function sq_get_tz_key($sTZ) { |
67 | $aTZs=sq_get_tz_array(); |
68 | |
69 | // get real time zone from link |
70 | if (isset($aTZs[$sTZ]['LINK'])) { |
71 | $sTZ = $aTZs[$sTZ]['LINK']; |
72 | } |
73 | |
74 | if (isset($aTZs[$sTZ])) { |
75 | if (isset($aTZs[$sTZ]['TZ'])) { |
76 | // get time zone |
77 | return $aTZs[$sTZ]['TZ']; |
78 | } else { |
79 | // array does not have TZ entry. bad thing |
80 | return $sTZ; |
81 | } |
82 | } else { |
83 | return false; |
84 | } |
85 | } |
86 | ?> |