|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Calendar App |
|
4
|
|
|
* |
|
5
|
|
|
* @author Georg Ehrke |
|
6
|
|
|
* @copyright 2017 Georg Ehrke <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This library is free software; you can redistribute it and/or |
|
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
10
|
|
|
* License as published by the Free Software Foundation; either |
|
11
|
|
|
* version 3 of the License, or any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This library is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public |
|
19
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
namespace OCA\Calendar\Controller; |
|
23
|
|
|
|
|
24
|
|
|
use OCP\AppFramework\Controller; |
|
25
|
|
|
use OCP\AppFramework\Http; |
|
26
|
|
|
use OCP\AppFramework\Http\DataDisplayResponse; |
|
27
|
|
|
use OCP\AppFramework\Http\NotFoundResponse; |
|
28
|
|
|
|
|
29
|
|
|
class TimezoneController extends Controller { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @NoAdminRequired |
|
33
|
|
|
* |
|
34
|
|
|
* @param string $id |
|
35
|
|
|
* @return NotFoundResponse|DataDisplayResponse |
|
36
|
|
|
*/ |
|
37
|
4 |
|
public function getTimezone($id) { |
|
38
|
4 |
|
if (!in_array($id, $this->getTimezoneList())) { |
|
39
|
2 |
|
return new NotFoundResponse(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
$tzData = file_get_contents(__DIR__ . '/../timezones/' . $id); |
|
43
|
|
|
|
|
44
|
2 |
|
return new DataDisplayResponse($tzData, Http::STATUS_OK, [ |
|
45
|
2 |
|
'content-type' => 'text/calendar', |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @NoAdminRequired |
|
51
|
|
|
* @NoCSRFRequired |
|
52
|
|
|
* @PublicPage |
|
53
|
|
|
* |
|
54
|
|
|
* @param $region |
|
55
|
|
|
* @param $city |
|
56
|
|
|
* @return DataDisplayResponse |
|
57
|
|
|
*/ |
|
58
|
2 |
|
public function getTimezoneWithRegion($region, $city) { |
|
59
|
2 |
|
return $this->getTimezone($region . '-' . $city); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @NoAdminRequired |
|
64
|
|
|
* @NoCSRFRequired |
|
65
|
|
|
* @PublicPage |
|
66
|
|
|
* |
|
67
|
|
|
* @param $region |
|
68
|
|
|
* @param $subRegion |
|
69
|
|
|
* @param $city |
|
70
|
|
|
* @return DataDisplayResponse |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getTimezoneWithSubRegion($region, $subRegion, $city) { |
|
73
|
|
|
return $this->getTimezone($region . '-' . $subRegion . '-' . $city); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* get a list of default timezones |
|
78
|
|
|
* |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
4 |
|
private function getTimezoneList() { |
|
82
|
4 |
|
$allFiles = scandir(__DIR__ . '/../timezones/'); |
|
83
|
|
|
|
|
84
|
4 |
|
return array_values(array_filter($allFiles, function($file) { |
|
85
|
4 |
|
return (substr($file, -4) === '.ics'); |
|
86
|
4 |
|
})); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|