1 | <?php |
||
41 | class ViewController extends Controller { |
||
42 | |||
43 | /** |
||
44 | * @var IURLGenerator |
||
45 | */ |
||
46 | private $urlGenerator; |
||
47 | |||
48 | /** |
||
49 | * @var IConfig |
||
50 | */ |
||
51 | private $config; |
||
52 | |||
53 | /** |
||
54 | * @var IUserSession |
||
55 | */ |
||
56 | private $userSession; |
||
57 | |||
58 | /** |
||
59 | * @var IMailer |
||
60 | */ |
||
61 | private $mailer; |
||
62 | |||
63 | /** |
||
64 | * @var L10N |
||
65 | */ |
||
66 | private $l10n; |
||
67 | |||
68 | /** |
||
69 | * @var Defaults |
||
70 | */ |
||
71 | private $defaults; |
||
72 | |||
73 | /** |
||
74 | * @param string $appName |
||
75 | * @param IRequest $request an instance of the request |
||
76 | * @param IUserSession $userSession |
||
77 | * @param IConfig $config |
||
78 | * @param IMailer $mailer |
||
79 | * @param L10N $l10N |
||
80 | * @param Defaults $defaults |
||
81 | * @param IURLGenerator $urlGenerator |
||
82 | */ |
||
83 | 14 | public function __construct($appName, IRequest $request, |
|
84 | IUserSession $userSession, IConfig $config, IMailer $mailer, L10N $l10N, Defaults $defaults, IURLGenerator $urlGenerator) { |
||
85 | 14 | parent::__construct($appName, $request); |
|
86 | 14 | $this->config = $config; |
|
87 | 14 | $this->userSession = $userSession; |
|
88 | 14 | $this->mailer = $mailer; |
|
89 | 14 | $this->l10n = $l10N; |
|
90 | 14 | $this->defaults = $defaults; |
|
91 | 14 | $this->urlGenerator = $urlGenerator; |
|
92 | 14 | } |
|
93 | |||
94 | /** |
||
95 | * @NoAdminRequired |
||
96 | * @NoCSRFRequired |
||
97 | * |
||
98 | * @return TemplateResponse |
||
99 | */ |
||
100 | 5 | public function index() { |
|
101 | 5 | $runningOn = $this->config->getSystemValue('version'); |
|
102 | 5 | $runningOnServer91OrLater = version_compare($runningOn, '9.1', '>='); |
|
103 | |||
104 | 5 | $supportsClass = $runningOnServer91OrLater; |
|
105 | 5 | $assetPipelineBroken = !$runningOnServer91OrLater; |
|
106 | |||
107 | 5 | $isAssetPipelineEnabled = $this->config->getSystemValue('asset-pipeline.enabled', false); |
|
108 | 5 | if ($isAssetPipelineEnabled && $assetPipelineBroken) { |
|
109 | 2 | return new TemplateResponse('calendar', 'main-asset-pipeline-unsupported'); |
|
110 | } |
||
111 | |||
112 | 3 | $user = $this->userSession->getUser(); |
|
113 | 3 | $userId = $user->getUID(); |
|
114 | 3 | $emailAddress = $user->getEMailAddress(); |
|
115 | |||
116 | 3 | $appVersion = $this->config->getAppValue($this->appName, 'installed_version'); |
|
117 | 3 | $defaultView = $this->config->getUserValue($userId, $this->appName, 'currentView', 'month'); |
|
118 | 3 | $skipPopover = $this->config->getUserValue($userId, $this->appName, 'skipPopover', 'no'); |
|
119 | 3 | $weekNumbers = $this->config->getUserValue($userId, $this->appName, 'showWeekNr', 'no'); |
|
120 | 3 | $defaultColor = $this->config->getAppValue('theming', 'color', '#0082C9'); |
|
121 | |||
122 | 3 | $webCalWorkaround = $runningOnServer91OrLater ? 'no' : 'yes'; |
|
123 | |||
124 | 3 | return new TemplateResponse('calendar', 'main', [ |
|
125 | 3 | 'appVersion' => $appVersion, |
|
126 | 3 | 'defaultView' => $defaultView, |
|
127 | 3 | 'emailAddress' => $emailAddress, |
|
128 | 3 | 'skipPopover' => $skipPopover, |
|
129 | 3 | 'weekNumbers' => $weekNumbers, |
|
130 | 3 | 'supportsClass' => $supportsClass, |
|
131 | 3 | 'defaultColor' => $defaultColor, |
|
132 | 3 | 'webCalWorkaround' => $webCalWorkaround, |
|
133 | 'isPublic' => false, |
||
134 | ]); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @PublicPage |
||
139 | * @NoCSRFRequired |
||
140 | * |
||
141 | * @return TemplateResponse |
||
142 | */ |
||
143 | 3 | public function publicIndex() { |
|
144 | 3 | $runningOn = $this->config->getSystemValue('version'); |
|
145 | 3 | $runningOnServer91OrLater = version_compare($runningOn, '9.1', '>='); |
|
146 | |||
147 | 3 | $supportsClass = $runningOnServer91OrLater; |
|
148 | 3 | $assetPipelineBroken = !$runningOnServer91OrLater; |
|
149 | |||
150 | 3 | $isAssetPipelineEnabled = $this->config->getSystemValue('asset-pipeline.enabled', false); |
|
151 | 3 | if ($isAssetPipelineEnabled && $assetPipelineBroken) { |
|
152 | return new TemplateResponse('calendar', 'main-asset-pipeline-unsupported'); |
||
153 | } |
||
154 | |||
155 | 3 | $appVersion = $this->config->getAppValue($this->appName, 'installed_version'); |
|
156 | |||
157 | 3 | $response = new TemplateResponse('calendar', 'main', [ |
|
158 | 3 | 'appVersion' => $appVersion, |
|
159 | 3 | 'defaultView' => 'month', |
|
160 | 3 | 'emailAddress' => '', |
|
161 | 3 | 'supportsClass' => $supportsClass, |
|
162 | 'isPublic' => true, |
||
163 | 3 | 'shareURL' => $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . $this->request->getRequestUri(), |
|
164 | 3 | 'previewImage' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-touch.png')), |
|
165 | 3 | ], 'public'); |
|
166 | 3 | $response->addHeader('X-Frame-Options', 'ALLOW'); |
|
167 | 3 | $csp = new ContentSecurityPolicy(); |
|
168 | 3 | $csp->addAllowedScriptDomain('*'); |
|
169 | 3 | $response->setContentSecurityPolicy($csp); |
|
170 | |||
171 | 3 | return $response; |
|
172 | } |
||
173 | |||
174 | /** |
||
175 | * @NoAdminRequired |
||
176 | * |
||
177 | * @param string $id |
||
178 | * @return NotFoundResponse|DataDisplayResponse |
||
179 | */ |
||
180 | 4 | public function getTimezone($id) { |
|
181 | 4 | if (!in_array($id, $this->getTimezoneList())) { |
|
182 | 2 | return new NotFoundResponse(); |
|
183 | } |
||
184 | |||
185 | 2 | $tzData = file_get_contents(__DIR__ . '/../timezones/' . $id); |
|
186 | |||
187 | 2 | return new DataDisplayResponse($tzData, HTTP::STATUS_OK, [ |
|
188 | 2 | 'content-type' => 'text/calendar', |
|
189 | ]); |
||
190 | } |
||
191 | |||
192 | |||
193 | /** |
||
194 | * @NoAdminRequired |
||
195 | * @NoCSRFRequired |
||
196 | * @PublicPage |
||
197 | * |
||
198 | * @param $region |
||
199 | * @param $city |
||
200 | * @return DataDisplayResponse |
||
201 | */ |
||
202 | 2 | public function getTimezoneWithRegion($region, $city) { |
|
203 | 2 | return $this->getTimezone($region . '-' . $city); |
|
|
|||
204 | } |
||
205 | |||
206 | |||
207 | /** |
||
208 | * @NoAdminRequired |
||
209 | * @PublicPage |
||
210 | * @NoCSRFRequired |
||
211 | * |
||
212 | * @param $region |
||
213 | * @param $subregion |
||
214 | * @param $city |
||
215 | * @return DataDisplayResponse |
||
216 | */ |
||
217 | public function getTimezoneWithSubRegion($region, $subregion, $city) { |
||
220 | |||
221 | |||
222 | /** |
||
223 | * get a list of default timezones |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | 4 | private function getTimezoneList() { |
|
234 | |||
235 | /** |
||
236 | * @param string $to |
||
237 | * @param string $url |
||
238 | * @param string $name |
||
239 | * @return JSONResponse |
||
240 | * @NoAdminRequired |
||
241 | */ |
||
242 | 2 | public function sendEmailPublicLink($to, $url, $name) { |
|
258 | |||
259 | /** |
||
260 | * @param string $target |
||
261 | * @param string $subject |
||
262 | * @param string $body |
||
263 | * @param string $textBody |
||
264 | * @return int |
||
265 | */ |
||
266 | 2 | private function sendEmail($target, $subject, $body, $textBody) { |
|
285 | } |
||
286 |