PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.2.10
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.2.10
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / src / Scheduling / Timezone / TimezoneSelect.php
wp-all-export / src / Scheduling / Timezone Last commit date
TimezoneSelect.php 4 years ago
TimezoneSelect.php
93 lines
1 <?php
2
3 namespace Wpae\Scheduling\Timezone;
4
5
6 class TimezoneSelect
7 {
8
9 private $regions = array(
10 'Africa' => \DateTimeZone::AFRICA,
11 'America' => \DateTimeZone::AMERICA,
12 'Antarctica' => \DateTimeZone::ANTARCTICA,
13 'Arctic' => \DateTimeZone::ARCTIC,
14 'Asia' => \DateTimeZone::ASIA,
15 'Atlantic' => \DateTimeZone::ATLANTIC,
16 'Australia' => \DateTimeZone::AUSTRALIA,
17 'Europe' => \DateTimeZone::EUROPE,
18 'Indian' => \DateTimeZone::INDIAN,
19 'Pacific' => \DateTimeZone::PACIFIC
20 );
21
22 public function getTimezoneSelect($value = false)
23 {
24
25 $timezones = array();
26 foreach ($this->regions as $name => $mask) {
27 $zones = \DateTimeZone::listIdentifiers($mask);
28
29 foreach ($zones as $timezone) {
30
31 $timeZoneObject = new \DateTimeZone($timezone);
32
33 // Lets sample the time there right now
34 $time = new \DateTime('now', $timeZoneObject);
35
36 // Us dumb Americans can't handle millitary time
37 $ampm = $time->format('H') > 12 ? ' (' . $time->format('g:i a') . ')' : '';
38 $offset = $timeZoneObject->getOffset($time)/3600;
39
40 if($offset < 10 && $offset > 0 && is_int($offset)) {
41 $offsetName = '0'.$offset;
42 } else if($offset < 0 && $offset >-10 && is_int($offset)){
43 $offsetName = str_replace('- ','-0', $offset);
44 }
45 else{
46 $offsetName = str_replace('-','-', $offset);
47 }
48
49 if($offset > 0) {
50 $offsetName = "+".$offsetName;
51 $offset = "+".$offset;
52 }
53
54
55 $timezones[$name][$timezone]['offset'] = $offset;
56 $timezones[$name][$timezone]['timezoneAbbrev'] = $time->format('T');
57 // Remove region name and add a sample time
58 $timezones[$name][$timezone]['name'] = 'UTC ' . $offsetName.' - '.substr($timezone, strlen($name) + 1) . ' ('.$timezones[$name][$timezone]['timezoneAbbrev'].')';
59 }
60 }
61
62 $result = '';
63 $result .= '<select id="timezone" name="scheduling_timezone">';
64 foreach ($timezones as $region => $list) {
65 $result .= '<optgroup label="' . $region . '">' . "\n";
66 foreach ($list as $timezone => $data) {
67
68 $selected = '';
69
70 if($value) {
71 if($value == $timezone) {
72 $selected = ' selected="selected" ';
73 }
74 }
75
76 $keywords = array(
77 "UTC".$data['offset'],
78 "UTC ".$data['offset'],
79 $data['offset'],
80 str_replace("+","+ ", $data['offset']),
81 $data['timezoneAbbrev']
82 );
83
84 $keywords = implode(',', $keywords);
85 $result .= '<option value="' . $timezone . '" ' . $selected . ' data-keywords="'.$keywords.'" >' . str_replace("_"," ",$data['name']) .'</option>' . "\n";
86 }
87 $result .= '<optgroup>' . "\n";
88 }
89 $result .= '</select>';
90
91 return $result;
92 }
93 }