web/wp-content/plugins/event-calendar/tz.php
branchwordpress
changeset 109 03b0d1493584
equal deleted inserted replaced
-1:000000000000 109:03b0d1493584
       
     1 <?php
       
     2 /*
       
     3 Copyright (c) 2006, Alex Tingle.  $Revision: 236 $
       
     4 
       
     5 This program is free software; you can redistribute it and/or
       
     6 modify it under the terms of the GNU General Public License
       
     7 as published by the Free Software Foundation; either version 2
       
     8 of the License, or (at your option) any later version.
       
     9 
       
    10 This program is distributed in the hope that it will be useful,
       
    11 but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 GNU General Public License for more details.
       
    14 
       
    15 You should have received a copy of the GNU General Public License
       
    16 along with this program; if not, write to the Free Software
       
    17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    18 */
       
    19 
       
    20 // Deal with timezones differently, depending upon what PHP has to offer.
       
    21 if(function_exists('date_default_timezone_get')):
       
    22 
       
    23   // PHP5
       
    24   function ec3_tz_push($tz)
       
    25   {
       
    26     $old_tz=date_default_timezone_get();
       
    27     date_default_timezone_set($tz);
       
    28     return $old_tz;
       
    29   }
       
    30   function ec3_tz_pop($tz)
       
    31   {
       
    32     date_default_timezone_set($tz);
       
    33   }
       
    34 
       
    35 elseif(ini_get('safe_mode')):
       
    36 
       
    37   // PHP4 safe mode.
       
    38   function ec3_tz_push($tz)
       
    39   {
       
    40     return $tz;
       
    41   }
       
    42   function ec3_tz_pop($tz)
       
    43   {
       
    44     // do nothing
       
    45   }
       
    46   $ec3->tz_disabled=true;
       
    47   $ec3->tz=getenv('TZ');
       
    48 
       
    49 else:
       
    50 
       
    51   // PHP4 safe mode OFF 
       
    52   function ec3_tz_push($tz)
       
    53   {
       
    54     $old_tz=getenv('TZ');
       
    55     putenv("TZ=$tz");
       
    56     return $old_tz;
       
    57   }
       
    58   function ec3_tz_pop($tz)
       
    59   {
       
    60     putenv("TZ=$tz");
       
    61   }
       
    62 
       
    63 endif;
       
    64 
       
    65 
       
    66 /** Converts a WordPress timestamp to Unix time. */
       
    67 function ec3_to_time($timestamp)
       
    68 {
       
    69   global $ec3;
       
    70   // Parse $timestamp and extract the Unix time.
       
    71   $old_tz=ec3_tz_push($ec3->tz);
       
    72   $unix_time = strtotime($timestamp);
       
    73   ec3_tz_pop($old_tz);
       
    74   // Unix time is seconds since the epoch (in UTC).
       
    75   return $unix_time;
       
    76 }
       
    77 
       
    78 /** Converts a WordPress timestamp to UTC. */
       
    79 function ec3_to_utc($timestamp,$fmt='%Y%m%dT%H%M00Z')
       
    80 {
       
    81   $result = gmstrftime($fmt,ec3_to_time($timestamp));
       
    82   return $result;
       
    83 }
       
    84 
       
    85 /** Formats a Unix time as a time in the current timezone. */
       
    86 function ec3_strftime($format,$unix_time=0)
       
    87 {
       
    88   global $ec3;
       
    89   if(!$unix_time)
       
    90       $unix_time=time();
       
    91   // Express the Unix time as a string for timezone $ec3->tz.
       
    92   $old_tz=ec3_tz_push($ec3->tz);
       
    93   $result = strftime($format,$unix_time);
       
    94   ec3_tz_pop($old_tz);
       
    95   return $result;
       
    96 }
       
    97 
       
    98 
       
    99 $ec3->today=ec3_strftime("%Y-%m-%d 00:00:00");
       
   100 
       
   101 
       
   102 /** Call from within a <select>. Echos grouped options for all timezones. */
       
   103 function ec3_get_tz_options($selected='')
       
   104 {
       
   105   /** All possible timezones, by group. */
       
   106   $groups = array(
       
   107     'Africa' => array(
       
   108       'Abidjan',
       
   109       'Accra',
       
   110       'Addis_Ababa',
       
   111       'Algiers',
       
   112       'Asmera',
       
   113       'Bamako',
       
   114       'Bangui',
       
   115       'Banjul',
       
   116       'Bissau',
       
   117       'Blantyre',
       
   118       'Brazzaville',
       
   119       'Bujumbura',
       
   120       'Cairo',
       
   121       'Casablanca',
       
   122       'Ceuta',
       
   123       'Conakry',
       
   124       'Dakar',
       
   125       'Dar_es_Salaam',
       
   126       'Djibouti',
       
   127       'Douala',
       
   128       'El_Aaiun',
       
   129       'Freetown',
       
   130       'Gaborone',
       
   131       'Harare',
       
   132       'Johannesburg',
       
   133       'Kampala',
       
   134       'Khartoum',
       
   135       'Kigali',
       
   136       'Kinshasa',
       
   137       'Lagos',
       
   138       'Libreville',
       
   139       'Lome',
       
   140       'Luanda',
       
   141       'Lubumbashi',
       
   142       'Lusaka',
       
   143       'Malabo',
       
   144       'Maputo',
       
   145       'Maseru',
       
   146       'Mbabane',
       
   147       'Mogadishu',
       
   148       'Monrovia',
       
   149       'Nairobi',
       
   150       'Ndjamena',
       
   151       'Niamey',
       
   152       'Nouakchott',
       
   153       'Ouagadougou',
       
   154       'Porto-Novo',
       
   155       'Sao_Tome',
       
   156       'Timbuktu',
       
   157       'Tripoli',
       
   158       'Tunis',
       
   159       'Windhoek'
       
   160     ),
       
   161     'America' => array(
       
   162       'Adak',
       
   163       'Anchorage',
       
   164       'Anguilla',
       
   165       'Antigua',
       
   166       'Araguaina',
       
   167       'Argentina/Buenos_Aires',
       
   168       'Argentina/Catamarca',
       
   169       'Argentina/ComodRivadavia',
       
   170       'Argentina/Cordoba',
       
   171       'Argentina/Jujuy',
       
   172       'Argentina/La_Rioja',
       
   173       'Argentina/Mendoza',
       
   174       'Argentina/Rio_Gallegos',
       
   175       'Argentina/San_Juan',
       
   176       'Argentina/Tucuman',
       
   177       'Argentina/Ushuaia',
       
   178       'Aruba',
       
   179       'Asuncion',
       
   180       'Atikokan',
       
   181       'Atka',
       
   182       'Bahia',
       
   183       'Barbados',
       
   184       'Belem',
       
   185       'Belize',
       
   186       'Blanc-Sablon',
       
   187       'Boa_Vista',
       
   188       'Bogota',
       
   189       'Boise',
       
   190       'Buenos_Aires',
       
   191       'Cambridge_Bay',
       
   192       'Campo_Grande',
       
   193       'Cancun',
       
   194       'Caracas',
       
   195       'Catamarca',
       
   196       'Cayenne',
       
   197       'Cayman',
       
   198       'Chicago',
       
   199       'Chihuahua',
       
   200       'Coral_Harbour',
       
   201       'Cordoba',
       
   202       'Costa_Rica',
       
   203       'Cuiaba',
       
   204       'Curacao',
       
   205       'Danmarkshavn',
       
   206       'Dawson',
       
   207       'Dawson_Creek',
       
   208       'Denver',
       
   209       'Detroit',
       
   210       'Dominica',
       
   211       'Edmonton',
       
   212       'Eirunepe',
       
   213       'El_Salvador',
       
   214       'Ensenada',
       
   215       'Fort_Wayne',
       
   216       'Fortaleza',
       
   217       'Glace_Bay',
       
   218       'Godthab',
       
   219       'Goose_Bay',
       
   220       'Grand_Turk',
       
   221       'Grenada',
       
   222       'Guadeloupe',
       
   223       'Guatemala',
       
   224       'Guayaquil',
       
   225       'Guyana',
       
   226       'Halifax',
       
   227       'Havana',
       
   228       'Hermosillo',
       
   229       'Indiana/Indianapolis',
       
   230       'Indiana/Knox',
       
   231       'Indiana/Marengo',
       
   232       'Indiana/Petersburg',
       
   233       'Indiana/Vevay',
       
   234       'Indiana/Vincennes',
       
   235       'Indianapolis',
       
   236       'Inuvik',
       
   237       'Iqaluit',
       
   238       'Jamaica',
       
   239       'Jujuy',
       
   240       'Juneau',
       
   241       'Kentucky/Louisville',
       
   242       'Kentucky/Monticello',
       
   243       'Knox_IN',
       
   244       'La_Paz',
       
   245       'Lima',
       
   246       'Los_Angeles',
       
   247       'Louisville',
       
   248       'Maceio',
       
   249       'Managua',
       
   250       'Manaus',
       
   251       'Martinique',
       
   252       'Mazatlan',
       
   253       'Mendoza',
       
   254       'Menominee',
       
   255       'Merida',
       
   256       'Mexico_City',
       
   257       'Miquelon',
       
   258       'Moncton',
       
   259       'Monterrey',
       
   260       'Montevideo',
       
   261       'Montreal',
       
   262       'Montserrat',
       
   263       'Nassau',
       
   264       'New_York',
       
   265       'Nipigon',
       
   266       'Nome',
       
   267       'Noronha',
       
   268       'North_Dakota/Center',
       
   269       'North_Dakota/New_Salem',
       
   270       'Panama',
       
   271       'Pangnirtung',
       
   272       'Paramaribo',
       
   273       'Phoenix',
       
   274       'Port-au-Prince',
       
   275       'Port_of_Spain',
       
   276       'Porto_Acre',
       
   277       'Porto_Velho',
       
   278       'Puerto_Rico',
       
   279       'Rainy_River',
       
   280       'Rankin_Inlet',
       
   281       'Recife',
       
   282       'Regina',
       
   283       'Rio_Branco',
       
   284       'Rosario',
       
   285       'Santiago',
       
   286       'Santo_Domingo',
       
   287       'Sao_Paulo',
       
   288       'Scoresbysund',
       
   289       'Shiprock',
       
   290       'St_Johns',
       
   291       'St_Kitts',
       
   292       'St_Lucia',
       
   293       'St_Thomas',
       
   294       'St_Vincent',
       
   295       'Swift_Current',
       
   296       'Tegucigalpa',
       
   297       'Thule',
       
   298       'Thunder_Bay',
       
   299       'Tijuana',
       
   300       'Toronto',
       
   301       'Tortola',
       
   302       'Vancouver',
       
   303       'Virgin',
       
   304       'Whitehorse',
       
   305       'Winnipeg',
       
   306       'Yakutat',
       
   307       'Yellowknife'
       
   308     ),
       
   309     'Antarctica' => array(
       
   310       'Casey',
       
   311       'Davis',
       
   312       'DumontDUrville',
       
   313       'Mawson',
       
   314       'McMurdo',
       
   315       'Palmer',
       
   316       'Rothera',
       
   317       'South_Pole',
       
   318       'Syowa',
       
   319       'Vostok'
       
   320     ),
       
   321     'Arctic' => array('Longyearbyen'),
       
   322     'Asia' => array(
       
   323       'Aden',
       
   324       'Almaty',
       
   325       'Amman',
       
   326       'Anadyr',
       
   327       'Aqtau',
       
   328       'Aqtobe',
       
   329       'Ashgabat',
       
   330       'Ashkhabad',
       
   331       'Baghdad',
       
   332       'Bahrain',
       
   333       'Baku',
       
   334       'Bangkok',
       
   335       'Beirut',
       
   336       'Bishkek',
       
   337       'Brunei',
       
   338       'Calcutta',
       
   339       'Choibalsan',
       
   340       'Chongqing',
       
   341       'Chungking',
       
   342       'Colombo',
       
   343       'Dacca',
       
   344       'Damascus',
       
   345       'Dhaka',
       
   346       'Dili',
       
   347       'Dubai',
       
   348       'Dushanbe',
       
   349       'Gaza',
       
   350       'Harbin',
       
   351       'Hong_Kong',
       
   352       'Hovd',
       
   353       'Irkutsk',
       
   354       'Istanbul',
       
   355       'Jakarta',
       
   356       'Jayapura',
       
   357       'Jerusalem',
       
   358       'Kabul',
       
   359       'Kamchatka',
       
   360       'Karachi',
       
   361       'Kashgar',
       
   362       'Katmandu',
       
   363       'Krasnoyarsk',
       
   364       'Kuala_Lumpur',
       
   365       'Kuching',
       
   366       'Kuwait',
       
   367       'Macao',
       
   368       'Macau',
       
   369       'Magadan',
       
   370       'Makassar',
       
   371       'Manila',
       
   372       'Muscat',
       
   373       'Nicosia',
       
   374       'Novosibirsk',
       
   375       'Omsk',
       
   376       'Oral',
       
   377       'Phnom_Penh',
       
   378       'Pontianak',
       
   379       'Pyongyang',
       
   380       'Qatar',
       
   381       'Qyzylorda',
       
   382       'Rangoon',
       
   383       'Riyadh',
       
   384       'Saigon',
       
   385       'Sakhalin',
       
   386       'Samarkand',
       
   387       'Seoul',
       
   388       'Shanghai',
       
   389       'Singapore',
       
   390       'Taipei',
       
   391       'Tashkent',
       
   392       'Tbilisi',
       
   393       'Tehran',
       
   394       'Tel_Aviv',
       
   395       'Thimbu',
       
   396       'Thimphu',
       
   397       'Tokyo',
       
   398       'Ujung_Pandang',
       
   399       'Ulaanbaatar',
       
   400       'Ulan_Bator',
       
   401       'Urumqi',
       
   402       'Vientiane',
       
   403       'Vladivostok',
       
   404       'Yakutsk',
       
   405       'Yekaterinburg',
       
   406       'Yerevan'
       
   407     ),
       
   408     'Atlantic' => array(
       
   409       'Azores',
       
   410       'Bermuda',
       
   411       'Canary',
       
   412       'Cape_Verde',
       
   413       'Faeroe',
       
   414       'Jan_Mayen',
       
   415       'Madeira',
       
   416       'Reykjavik',
       
   417       'South_Georgia',
       
   418       'St_Helena',
       
   419       'Stanley',
       
   420     ),
       
   421     'Australia' => array(
       
   422       'ACT',
       
   423       'Adelaide',
       
   424       'Brisbane',
       
   425       'Broken_Hill',
       
   426       'Canberra',
       
   427       'Currie',
       
   428       'Darwin',
       
   429       'Hobart',
       
   430       'LHI',
       
   431       'Lindeman',
       
   432       'Lord_Howe',
       
   433       'Melbourne',
       
   434       'North',
       
   435       'NSW',
       
   436       'Perth',
       
   437       'Queensland',
       
   438       'South',
       
   439       'Sydney',
       
   440       'Tasmania',
       
   441       'Victoria',
       
   442       'West',
       
   443       'Yancowinna'
       
   444     ),
       
   445     'Europe' => array(
       
   446       'Amsterdam',
       
   447       'Andorra',
       
   448       'Athens',
       
   449       'Belfast',
       
   450       'Belgrade',
       
   451       'Berlin',
       
   452       'Bratislava',
       
   453       'Brussels',
       
   454       'Bucharest',
       
   455       'Budapest',
       
   456       'Chisinau',
       
   457       'Copenhagen',
       
   458       'Dublin',
       
   459       'Gibraltar',
       
   460       'Guernsey',
       
   461       'Helsinki',
       
   462       'Isle_of_Man',
       
   463       'Istanbul',
       
   464       'Jersey',
       
   465       'Kaliningrad',
       
   466       'Kiev',
       
   467       'Lisbon',
       
   468       'Ljubljana',
       
   469       'London',
       
   470       'Luxembourg',
       
   471       'Madrid',
       
   472       'Malta',
       
   473       'Mariehamn',
       
   474       'Minsk',
       
   475       'Monaco',
       
   476       'Moscow',
       
   477       'Nicosia',
       
   478       'Oslo',
       
   479       'Paris',
       
   480       'Prague',
       
   481       'Riga',
       
   482       'Rome',
       
   483       'Samara',
       
   484       'San_Marino',
       
   485       'Sarajevo',
       
   486       'Simferopol',
       
   487       'Skopje',
       
   488       'Sofia',
       
   489       'Stockholm',
       
   490       'Tallinn',
       
   491       'Tirane',
       
   492       'Tiraspol',
       
   493       'Uzhgorod',
       
   494       'Vaduz',
       
   495       'Vatican',
       
   496       'Vienna',
       
   497       'Vilnius',
       
   498       'Volgograd',
       
   499       'Warsaw',
       
   500       'Zagreb',
       
   501       'Zaporozhye',
       
   502       'Zurich'
       
   503     ),
       
   504     'Indian' => array(
       
   505       'Antananarivo',
       
   506       'Chagos',
       
   507       'Christmas',
       
   508       'Cocos',
       
   509       'Comoro',
       
   510       'Kerguelen',
       
   511       'Mahe',
       
   512       'Maldives',
       
   513       'Mauritius',
       
   514       'Mayotte',
       
   515       'Reunion'
       
   516     ),
       
   517     'Pacific' => array(
       
   518       'Apia',
       
   519       'Auckland',
       
   520       'Chatham',
       
   521       'Easter',
       
   522       'Efate',
       
   523       'Enderbury',
       
   524       'Fakaofo',
       
   525       'Fiji',
       
   526       'Funafuti',
       
   527       'Galapagos',
       
   528       'Gambier',
       
   529       'Guadalcanal',
       
   530       'Guam',
       
   531       'Honolulu',
       
   532       'Johnston',
       
   533       'Kiritimati',
       
   534       'Kosrae',
       
   535       'Kwajalein',
       
   536       'Majuro',
       
   537       'Marquesas',
       
   538       'Midway',
       
   539       'Nauru',
       
   540       'Niue',
       
   541       'Norfolk',
       
   542       'Noumea',
       
   543       'Pago_Pago',
       
   544       'Palau',
       
   545       'Pitcairn',
       
   546       'Ponape',
       
   547       'Port_Moresby',
       
   548       'Rarotonga',
       
   549       'Saipan',
       
   550       'Samoa',
       
   551       'Tahiti',
       
   552       'Tarawa',
       
   553       'Tongatapu',
       
   554       'Truk',
       
   555       'Wake',
       
   556       'Wallis',
       
   557       'Yap'
       
   558     )
       
   559   );
       
   560 
       
   561   foreach($groups as $group => $zones)
       
   562   {
       
   563     echo "<optgroup label='$group'>\n";
       
   564     foreach($zones as $z)
       
   565     {
       
   566       echo "<option value='$group/$z'";
       
   567       if($selected=="$group/$z")
       
   568         echo ' selected="selected"';
       
   569       echo ">$z</option>\n";
       
   570     }
       
   571     echo '</optgroup>\n';
       
   572   }
       
   573 } // end function ec3_get_tz_options()
       
   574 
       
   575 ?>