Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/chaty/admin
File: chaty-timezone.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* List of functions to get timezone lists
[2] Fix | Delete
*
[3] Fix | Delete
* @author : Premio <contact@premio.io>
[4] Fix | Delete
* @license : GPL2
[5] Fix | Delete
* */
[6] Fix | Delete
[7] Fix | Delete
if (defined('ABSPATH') === false) {
[8] Fix | Delete
exit;
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
if (!function_exists('chaty_timezone_choice')) {
[12] Fix | Delete
/**
[13] Fix | Delete
* Generates the HTML structure for selecting a timezone.
[14] Fix | Delete
*
[15] Fix | Delete
* @param string $selectedZone The selected timezone value.
[16] Fix | Delete
* @param bool $utc Whether to include UTC offsets or not.
[17] Fix | Delete
*
[18] Fix | Delete
* @return string The HTML structure for the timezone selection.
[19] Fix | Delete
*/
[20] Fix | Delete
function chaty_timezone_choice($selectedZone='', $utc=true)
[21] Fix | Delete
{
[22] Fix | Delete
$countryName = json_decode(chaty_country_city_name(), true);
[23] Fix | Delete
$continents = [
[24] Fix | Delete
'Africa',
[25] Fix | Delete
'America',
[26] Fix | Delete
'Antarctica',
[27] Fix | Delete
'Arctic',
[28] Fix | Delete
'Asia',
[29] Fix | Delete
'Atlantic',
[30] Fix | Delete
'Australia',
[31] Fix | Delete
'Europe',
[32] Fix | Delete
'Indian',
[33] Fix | Delete
'Pacific',
[34] Fix | Delete
];
[35] Fix | Delete
[36] Fix | Delete
$zonen = [];
[37] Fix | Delete
[38] Fix | Delete
foreach (timezone_identifiers_list() as $zone) {
[39] Fix | Delete
$zone = explode('/', $zone);
[40] Fix | Delete
if (! in_array($zone[0], $continents, true)) {
[41] Fix | Delete
continue;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later.
[45] Fix | Delete
$exists = [
[46] Fix | Delete
0 => ( isset($zone[0]) && $zone[0] ),
[47] Fix | Delete
1 => ( isset($zone[1]) && $zone[1] ),
[48] Fix | Delete
2 => ( isset($zone[2]) && $zone[2] ),
[49] Fix | Delete
];
[50] Fix | Delete
$exists[3] = ( $exists[0] && 'Etc' !== $zone[0] );
[51] Fix | Delete
$exists[4] = ( $exists[1] && $exists[3] );
[52] Fix | Delete
$exists[5] = ( $exists[2] && $exists[3] );
[53] Fix | Delete
[54] Fix | Delete
// phpcs:disable WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
[55] Fix | Delete
$zonen[] = [
[56] Fix | Delete
'continent' => ( $exists[0] ? $zone[0] : '' ),
[57] Fix | Delete
'city' => ( $exists[1] ? $zone[1] : '' ),
[58] Fix | Delete
'subcity' => ( $exists[2] ? $zone[2] : '' ),
[59] Fix | Delete
't_continent' => ( $exists[3] ? str_replace('_', ' ', $zone[0]) : '' ),
[60] Fix | Delete
't_city' => ( $exists[4] ? str_replace('_', ' ', $zone[1]) : '' ),
[61] Fix | Delete
't_subcity' => ( $exists[5] ? str_replace('_', ' ', $zone[2]) : '' ),
[62] Fix | Delete
];
[63] Fix | Delete
// phpcs:enable
[64] Fix | Delete
}//end foreach
[65] Fix | Delete
[66] Fix | Delete
usort($zonen, '_chaty_timezone_sort');
[67] Fix | Delete
[68] Fix | Delete
$structure = [];
[69] Fix | Delete
[70] Fix | Delete
if (empty($selectedZone)) {
[71] Fix | Delete
$structure[] = '<option selected="selected" value="">Select a city or country</option>';
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
foreach ($zonen as $key => $zone) {
[75] Fix | Delete
// Build value in an array to join later.
[76] Fix | Delete
$value = [ $zone['continent'] ];
[77] Fix | Delete
$display = '';
[78] Fix | Delete
[79] Fix | Delete
if (isset($countryName[$zone['city']]) && $countryName[$zone['city']] != '') {
[80] Fix | Delete
$display .= $countryName[$zone['city']]."/";
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if (empty($zone['city'])) {
[84] Fix | Delete
// It's at the continent level (generally won't happen).
[85] Fix | Delete
$display .= $zone['t_continent'];
[86] Fix | Delete
} else {
[87] Fix | Delete
// It's inside a continent group.
[88] Fix | Delete
// Continent optgroup.
[89] Fix | Delete
if (! isset($zonen[($key - 1)]) || $zonen[($key - 1)]['continent'] !== $zone['continent']) {
[90] Fix | Delete
$label = $zone['t_continent'];
[91] Fix | Delete
$structure[] = '<optgroup label="'.$label.'">';
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
// Add the city to the value.
[95] Fix | Delete
$value[] = $zone['city'];
[96] Fix | Delete
[97] Fix | Delete
$display .= $zone['t_city'];
[98] Fix | Delete
if (! empty($zone['subcity'])) {
[99] Fix | Delete
// Add the subcity to the value.
[100] Fix | Delete
$value[] = $zone['subcity'];
[101] Fix | Delete
$display .= ' - '.$zone['t_subcity'];
[102] Fix | Delete
}
[103] Fix | Delete
}//end if
[104] Fix | Delete
[105] Fix | Delete
// Build the value.
[106] Fix | Delete
$value = join('/', $value);
[107] Fix | Delete
$selected = '';
[108] Fix | Delete
if ($value === $selectedZone) {
[109] Fix | Delete
$selected = 'selected="selected" ';
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
$structure[] = '<option '.$selected.'value="'.$value.'">'.$display.'</option>';
[113] Fix | Delete
[114] Fix | Delete
// Close continent optgroup.
[115] Fix | Delete
if (! empty($zone['city']) && ( ! isset($zonen[($key + 1)]) || ( isset($zonen[($key + 1)]) && $zonen[($key + 1)]['continent'] !== $zone['continent'] ) )) {
[116] Fix | Delete
$structure[] = '</optgroup>';
[117] Fix | Delete
}
[118] Fix | Delete
}//end foreach
[119] Fix | Delete
[120] Fix | Delete
// Do UTC.
[121] Fix | Delete
$structure[] = '<optgroup label="UTC">';
[122] Fix | Delete
$selected = '';
[123] Fix | Delete
if ('UTC' === $selectedZone) {
[124] Fix | Delete
$selected = 'selected="selected" ';
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
$structure[] = '<option '.$selected.'value="UTC">UTC</option>';
[128] Fix | Delete
$structure[] = '</optgroup>';
[129] Fix | Delete
[130] Fix | Delete
// Do manual UTC offsets.
[131] Fix | Delete
$structure[] = '<optgroup label="Manual Offsets">';
[132] Fix | Delete
$offsetRange = [
[133] Fix | Delete
-12,
[134] Fix | Delete
-11.5,
[135] Fix | Delete
-11,
[136] Fix | Delete
-10.5,
[137] Fix | Delete
-10,
[138] Fix | Delete
-9.5,
[139] Fix | Delete
-9,
[140] Fix | Delete
-8.5,
[141] Fix | Delete
-8,
[142] Fix | Delete
-7.5,
[143] Fix | Delete
-7,
[144] Fix | Delete
-6.5,
[145] Fix | Delete
-6,
[146] Fix | Delete
-5.5,
[147] Fix | Delete
-5,
[148] Fix | Delete
-4.5,
[149] Fix | Delete
-4,
[150] Fix | Delete
-3.5,
[151] Fix | Delete
-3,
[152] Fix | Delete
-2.5,
[153] Fix | Delete
-2,
[154] Fix | Delete
-1.5,
[155] Fix | Delete
-1,
[156] Fix | Delete
-0.5,
[157] Fix | Delete
0,
[158] Fix | Delete
0.5,
[159] Fix | Delete
1,
[160] Fix | Delete
1.5,
[161] Fix | Delete
2,
[162] Fix | Delete
2.5,
[163] Fix | Delete
3,
[164] Fix | Delete
3.5,
[165] Fix | Delete
4,
[166] Fix | Delete
4.5,
[167] Fix | Delete
5,
[168] Fix | Delete
5.5,
[169] Fix | Delete
5.75,
[170] Fix | Delete
6,
[171] Fix | Delete
6.5,
[172] Fix | Delete
7,
[173] Fix | Delete
7.5,
[174] Fix | Delete
8,
[175] Fix | Delete
8.5,
[176] Fix | Delete
8.75,
[177] Fix | Delete
9,
[178] Fix | Delete
9.5,
[179] Fix | Delete
10,
[180] Fix | Delete
10.5,
[181] Fix | Delete
11,
[182] Fix | Delete
11.5,
[183] Fix | Delete
12,
[184] Fix | Delete
12.75,
[185] Fix | Delete
13,
[186] Fix | Delete
13.75,
[187] Fix | Delete
14,
[188] Fix | Delete
];
[189] Fix | Delete
foreach ($offsetRange as $offset) {
[190] Fix | Delete
if (0 <= $offset) {
[191] Fix | Delete
$offsetName = ($utc ) ? '+'.$offset : $offset;
[192] Fix | Delete
} else {
[193] Fix | Delete
$offsetName = (string) $offset;
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
$offsetValue = $offsetName;
[197] Fix | Delete
$offsetName = str_replace([ '.25', '.5', '.75' ], [ ':15', ':30', ':45' ], $offsetName);
[198] Fix | Delete
if ($offset >= 0 && !$utc) {
[199] Fix | Delete
$offsetName = 'UTC+'.$offsetName;
[200] Fix | Delete
} else {
[201] Fix | Delete
$offsetName = 'UTC'.$offsetName;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
$offsetValue = ($utc ) ? 'UTC'.$offsetValue : $offsetValue ;
[205] Fix | Delete
$selected = '';
[206] Fix | Delete
if ($offsetValue === $selectedZone) {
[207] Fix | Delete
$selected = 'selected="selected" ';
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
$structure[] = '<option '.$selected.'value="'.$offsetValue.'">'.$offsetName.'</option>';
[211] Fix | Delete
}//end foreach
[212] Fix | Delete
[213] Fix | Delete
$structure[] = '</optgroup>';
[214] Fix | Delete
[215] Fix | Delete
return join("\n", $structure);
[216] Fix | Delete
[217] Fix | Delete
}//end chaty_timezone_choice()
[218] Fix | Delete
}//end if
[219] Fix | Delete
[220] Fix | Delete
if (!function_exists('_chaty_timezone_sort')) {
[221] Fix | Delete
/**
[222] Fix | Delete
* Sorts timezones based on specific criteria.
[223] Fix | Delete
*
[224] Fix | Delete
* @param array $a The first timezone to compare.
[225] Fix | Delete
* @param array $b The second timezone to compare.
[226] Fix | Delete
* @return int Returns a negative value if $a should be sorted before $b,
[227] Fix | Delete
* a positive value if $a should be sorted after $b,
[228] Fix | Delete
* or 0 if $a and $b are equal in terms of sorting.
[229] Fix | Delete
*/
[230] Fix | Delete
function _chaty_timezone_sort($a, $b)
[231] Fix | Delete
{
[232] Fix | Delete
// Don't use translated versions of Etc.
[233] Fix | Delete
if ($a['continent'] === 'Etc' && $b['continent'] === 'Etc') {
[234] Fix | Delete
// Make the order of these more like the old dropdown.
[235] Fix | Delete
if (substr($a['city'] === 'GMT+', 0, 4) && substr($b['city'] === 'GMT+', 0, 4)) {
[236] Fix | Delete
return (-1 * ( strnatcasecmp($a['city'], $b['city']) ));
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
if ($a['city'] === 'UTC') {
[240] Fix | Delete
if (substr($b['city'], 0, 4) === 'GMT+') {
[241] Fix | Delete
return 1;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
return -1;
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
if ($b['city'] === 'UTC') {
[248] Fix | Delete
if (substr($a['city'], 0, 4) === 'GMT+') {
[249] Fix | Delete
return -1;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
return 1;
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
return strnatcasecmp($a['city'], $b['city']);
[256] Fix | Delete
}//end if
[257] Fix | Delete
[258] Fix | Delete
if ($a['t_continent'] == $b['t_continent']) {
[259] Fix | Delete
if ($a['t_city'] == $b['t_city']) {
[260] Fix | Delete
return strnatcasecmp($a['t_subcity'], $b['t_subcity']);
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
return strnatcasecmp($a['t_city'], $b['t_city']);
[264] Fix | Delete
} else {
[265] Fix | Delete
// Force Etc to the bottom of the list.
[266] Fix | Delete
if ($a['continent'] === 'Etc') {
[267] Fix | Delete
return 1;
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
if ($b['continent'] === 'Etc') {
[271] Fix | Delete
return -1;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
return strnatcasecmp($a['t_continent'], $b['t_continent']);
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
}//end _chaty_timezone_sort()
[278] Fix | Delete
}//end if
[279] Fix | Delete
[280] Fix | Delete
[281] Fix | Delete
if (!function_exists('chaty_country_city_name')) {
[282] Fix | Delete
/**
[283] Fix | Delete
* Returns a JSON string representing an array of country-city pairs.
[284] Fix | Delete
*
[285] Fix | Delete
* @return string Returns a JSON string containing country-city pairs. The keys of the array are city names, and the values are country names.
[286] Fix | Delete
*/
[287] Fix | Delete
function chaty_country_city_name()
[288] Fix | Delete
{
[289] Fix | Delete
return '{"Abidjan":"Ivory Coast","Accra":"Ghana","Addis Ababa":"Ethiopia","Algiers":"Algeria","Asmara":"Eritrea","Bamako":"Mali","Bangui":"Central African Republic","Banjul":"Gambia","Bissau":"Guinea-Bissau","Blantyre":"Malawi","Brazzaville":"Republic of the Congo","Bujumbura":"Burundi","Cairo":"Egypt","Casablanca":"Morocco","Ceuta":"Spain","Conakry":"Guinea","Dakar":"Senegal","Dar es Salaam":"Tanzania","Djibouti":"Djibouti","Douala":"Cameroon","Freetown":"Sierra Leone","Gaborone":"Botswana","Harare":"Zimbabwe","Johannesburg":"South Africa","Juba":"South Sudan","Kampala":"Uganda","Khartoum":"Sudan","Kigali":"Rwanda","Kinshasa":"Congo","Lagos":"Nigeria","Libreville":"Gabon","Lome":"Togo","Luanda":"Angola","Lubumbashi":"Congo","Lusaka":"Zambia","Malabo":"Equatorial Guinea","Maputo":"Mozambique","Maseru":"Lesotho","Mbabane":"Swaziland","Mogadishu":"Somalia","Monrovia":"Liberia","Nairobi":"Kenya","Niamey":"Niger","Nouakchott":"Mauritania","Ouagadougou":"Burkina Faso","Sao Tome":"Brazil","Tripoli":"Libya","Tunis":"Tunisia","Windhoek":"Namibia","Adak":"United States","Anchorage":"United States","Anguilla":"United States","Antigua":"Spain","Asuncion":"Paraguay","Atikokan":"Canada","Belem":"Brazil","Boa Vista":"Brazil","Bogota":"United States","Boise":"United States","Cambridge Bay":"Canada","Campo Grande":"Brazil","Caracas":"Venezuela","Chicago":"Mexico","Chihuahua":"Mexico","Creston":"Canada","Cuiaba":"Brazil","Dawson":"Australia","Dawson Creek":"Canada","Denver":"United States","Detroit":"United States","Dominica":"Dominican Republic","Edmonton":"Canada","El Salvador":"Guatemala","Fort Nelson":"Canada","Fortaleza":"Brazil","Glace Bay":"Canada","Grenada":"United States","Guayaquil":"Ecuador","Halifax":"Canada","Havana":"Cuba","Hermosillo":"Mexico","Indiana":"United States","Inuvik":"Canada","Iqaluit":"Canada","Jamaica":"United States","Juneau":"United States","Kralendijk":"Bonaire","La Paz":"Uruguay","Lima":"Argentina","Los Angeles":"Panama","Managua":"Nicaragua","Manaus":"Brazil","Marigot":"Dominica","Mazatlan":"Mexico","Menominee":"United States","Metlakatla":"United States","Mexico City":"Mexico","Moncton":"Canada","Monterrey":"Mexico","Montevideo":"Uruguay","Montserrat":"Argentina","Nassau":"Bahamas","New York":"United States","Nipigon":"Canada","Nome":"United States","Ojinaga":"Mexico","Panama":"United States","Paramaribo":"Suriname","Phoenix":"South Africa","Port-au-Prince":"Haiti","Port of Spain":"Trinidad and Tobago","Porto Velho":"Brazil","Puerto Rico":"Argentina","Punta Arenas":"Chile","Rankin Inlet":"Canada","Recife":"Brazil","Regina":"Canada","Rio Branco":"Brazil","Santiago":"Peru","Santo Domingo":"Costa Rica","Sao Paulo":"Brazil","Sitka":"United States","Swift Current":"Canada","Tegucigalpa":"Honduras","Thunder Bay":"Canada","Tijuana":"Mexico","Toronto":"Canada","Tortola":"British Virgin Islands","Vancouver":"Canada","Whitehorse":"Canada","Winnipeg":"Canada","Yellowknife":"Canada","Casey":"United States","Davis":"United States","Palmer":"Puerto Rico","Vostok":"Kazakhstan","Longyearbyen":"Svalbard and Jan Mayen","Aden":"Yemen","Almaty":"Kazakhstan","Amman":"Hashemite Kingdom of Jordan","Aqtau":"Kazakhstan","Ashgabat":"Turkmenistan","Atyrau":"Kazakhstan","Baghdad":"Iraq","Baku":"Azerbaijan","Bangkok":"Thailand","Barnaul":"Russia","Beirut":"Lebanon","Bishkek":"Kyrgyzstan","Chita":"Russia","Colombo":"Sri Lanka","Damascus":"Syria","Dhaka":"Bangladesh","Dili":"East Timor","Dubai":"United Arab Emirates","Dushanbe":"Tajikistan","Famagusta":"Cyprus","Gaza":"Palestine","Hebron":"Palestine","Hong Kong":"Hong Kong","Irkutsk":"Russia","Jakarta":"Indonesia","Jayapura":"Indonesia","Jerusalem":"Israel","Kabul":"Afghanistan","Kamchatka":"Russia","Karachi":"Pakistan","Kathmandu":"Nepal","Kolkata":"India","Krasnoyarsk":"Russia","Kuala Lumpur":"Malaysia","Kuching":"Malaysia","Macau":"Brazil","Magadan":"Russia","Makassar":"Indonesia","Manila":"Philippines","Muscat":"Oman","Nicosia":"Cyprus","Novokuznetsk":"Russia","Novosibirsk":"Russia","Omsk":"Russia","Oral":"Kazakhstan","Phnom Penh":"Cambodia","Pontianak":"Indonesia","Pyongyang":"North Korea","Riyadh":"Saudi Arabia","Seoul":"Republic of Korea","Shanghai":"China","Singapore":"Singapore","Taipei":"Taiwan","Tashkent":"Uzbekistan","Tbilisi":"Georgia","Thimphu":"Bhutan","Tokyo":"Japan","Tomsk":"Russia","Vientiane":"Laos","Vladivostok":"Russia","Yakutsk":"Russia","Yangon":"Myanmar [Burma]","Yekaterinburg":"Russia","Yerevan":"Armenia","Madeira":"Portugal","Reykjavik":"Iceland","Stanley":"Falkland Islands","Adelaide":"Australia","Brisbane":"Australia","Broken Hill":"Australia","Currie":"United Kingdom","Darwin":"Australia","Hobart":"Australia","Melbourne":"United Kingdom","Perth":"Canada","Sydney":"Canada","Amsterdam":"Netherlands","Andorra":"Spain","Astrakhan":"Russia","Athens":"Canada","Belgrade":"Serbia","Berlin":"Germany","Bratislava":"Slovakia","Brussels":"Belgium","Bucharest":"Romania","Budapest":"Hungary","Copenhagen":"Denmark","Dublin":"Ireland","Gibraltar":"Gibraltar","Guernsey":"United States","Helsinki":"Finland","Istanbul":"Turkey","Jersey":"United States","Kaliningrad":"Russia","Kiev":"Ukraine","Kirov":"Russia","Lisbon":"Portugal","Ljubljana":"Slovenia","London":"South Africa","Luxembourg":"Luxembourg","Madrid":"Colombia","Malta":"Latvia","Mariehamn":"\u00c5land","Minsk":"Belarus","Monaco":"Monaco","Moscow":"Russia","Oslo":"Norway","Paris":"Canada","Podgorica":"Montenegro","Prague":"Czech Republic","Riga":"Latvia","Rome":"Italy","Samara":"Russia","San Marino":"San Marino","Sarajevo":"Bosnia and Herzegovina","Saratov":"Russia","Simferopol":"Ukraine","Skopje":"Macedonia","Sofia":"Bulgaria","Stockholm":"Sweden","Tallinn":"Estonia","Ulyanovsk":"Russia","Vaduz":"Liechtenstein","Vienna":"Austria","Vilnius":"Republic of Lithuania","Volgograd":"Russia","Warsaw":"Poland","Zagreb":"Croatia","Zurich":"Switzerland","Antananarivo":"Madagascar","Christmas":"United States","Cocos":"Brazil","Apia":"Samoa","Auckland":"New Zealand","Chatham":"Canada","Funafuti":"Tuvalu","Galapagos":"Spain","Gambier":"United States","Honolulu":"United States","Majuro":"Marshall Islands","Midway":"United States","Norfolk":"United States","Noumea":"New Caledonia","Pago Pago":"American Samoa","Palau":"Spain","Pitcairn":"United States","Port Moresby":"Papua New Guinea","Saipan":"Northern Mariana Islands","Wake":"United States","Wallis":"United States"}';
[290] Fix | Delete
[291] Fix | Delete
}//end chaty_country_city_name()
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function