1 | <?php |
||
35 | class ViewController extends Controller { |
||
36 | |||
37 | /** |
||
38 | * @var IConfig |
||
39 | */ |
||
40 | private $config; |
||
41 | |||
42 | /** |
||
43 | * @var IURLGenerator |
||
44 | */ |
||
45 | private $urlGenerator; |
||
46 | |||
47 | /** |
||
48 | * @var IUserSession |
||
49 | */ |
||
50 | private $userSession; |
||
51 | |||
52 | /** |
||
53 | * @param string $appName |
||
54 | * @param IRequest $request an instance of the request |
||
55 | * @param IUserSession $userSession |
||
56 | * @param IConfig $config |
||
57 | * @param IURLGenerator $urlGenerator |
||
58 | */ |
||
59 | 24 | public function __construct($appName, IRequest $request, IUserSession $userSession, |
|
60 | IConfig $config, IURLGenerator $urlGenerator) { |
||
61 | 24 | parent::__construct($appName, $request); |
|
62 | 24 | $this->config = $config; |
|
63 | 24 | $this->userSession = $userSession; |
|
64 | 24 | $this->urlGenerator = $urlGenerator; |
|
65 | 24 | } |
|
66 | |||
67 | /** |
||
68 | * @NoAdminRequired |
||
69 | * @NoCSRFRequired |
||
70 | * |
||
71 | * @return TemplateResponse |
||
72 | */ |
||
73 | 8 | public function index() { |
|
74 | 8 | if ($this->needsAssetPipelineWarning()) { |
|
75 | 1 | return new TemplateResponse('calendar', 'main-asset-pipeline-unsupported'); |
|
76 | } |
||
77 | |||
78 | 7 | $templateParameters = $this->getTemplateParams(); |
|
79 | |||
80 | 7 | $user = $this->userSession->getUser(); |
|
81 | 7 | $userId = $user->getUID(); |
|
82 | 7 | $emailAddress = $user->getEMailAddress(); |
|
83 | |||
84 | 7 | $initialView = $this->config->getUserValue($userId, $this->appName, 'currentView', null); |
|
85 | 7 | $skipPopover = $this->config->getUserValue($userId, $this->appName, 'skipPopover', 'no'); |
|
86 | 7 | $weekNumbers = $this->config->getUserValue($userId, $this->appName, 'showWeekNr', 'no'); |
|
87 | 7 | $firstRun = $this->config->getUserValue($userId, $this->appName, 'firstRun', null); |
|
88 | |||
89 | // the default view will be saved as soon as a user |
||
90 | // opens the calendar app, therefore this is a good |
||
91 | // indication if the calendar was used before |
||
92 | 7 | if ($firstRun === null) { |
|
93 | 2 | if ($initialView === null) { |
|
94 | 1 | $firstRun = 'yes'; |
|
95 | } else { |
||
96 | 1 | $this->config->setUserValue($userId, $this->appName, 'firstRun', 'no'); |
|
97 | 1 | $firstRun = 'no'; |
|
98 | } |
||
99 | } |
||
100 | |||
101 | 7 | if ($initialView === null) { |
|
102 | 1 | $initialView = 'month'; |
|
103 | } |
||
104 | |||
105 | 7 | return new TemplateResponse('calendar', 'main', array_merge($templateParameters, [ |
|
106 | 7 | 'initialView' => $initialView, |
|
107 | 7 | 'emailAddress' => $emailAddress, |
|
108 | 7 | 'skipPopover' => $skipPopover, |
|
109 | 7 | 'weekNumbers' => $weekNumbers, |
|
110 | 7 | 'firstRun' => $firstRun, |
|
111 | 'isPublic' => false, |
||
112 | 'isEmbedded' => false, |
||
113 | 7 | 'token' => '', |
|
114 | ])); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @PublicPage |
||
119 | * @NoCSRFRequired |
||
120 | * |
||
121 | * @param string $token |
||
122 | * |
||
123 | * @return TemplateResponse |
||
124 | */ |
||
125 | 8 | public function publicIndexWithBranding($token) { |
|
126 | 8 | if ($this->needsAssetPipelineWarning()) { |
|
127 | 1 | return new TemplateResponse('calendar', 'main-asset-pipeline-unsupported'); |
|
128 | } |
||
129 | |||
130 | 7 | $templateParameters = $this->getTemplateParams(); |
|
131 | 7 | $publicTemplateParameters = $this->getPublicTemplateParameters($token); |
|
132 | 7 | $params = array_merge($templateParameters, $publicTemplateParameters); |
|
133 | 7 | $params['isEmbedded'] = false; |
|
134 | |||
135 | 7 | return new TemplateResponse('calendar', 'public', $params, 'base'); |
|
136 | } |
||
137 | |||
138 | /** |
||
139 | * @PublicPage |
||
140 | * @NoCSRFRequired |
||
141 | * |
||
142 | * @param string $token |
||
143 | * |
||
144 | * @return TemplateResponse |
||
145 | */ |
||
146 | public function publicIndexWithBrandingAndFancyName($token) { |
||
147 | return $this->publicIndexWithBranding($token); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @PublicPage |
||
152 | * @NoCSRFRequired |
||
153 | * |
||
154 | * @param string $token |
||
155 | * |
||
156 | * @return TemplateResponse |
||
157 | */ |
||
158 | 8 | public function publicIndexForEmbedding($token) { |
|
177 | |||
178 | /** |
||
179 | * @PublicPage |
||
180 | * @NoCSRFRequired |
||
181 | * |
||
182 | * @param string $token |
||
183 | * |
||
184 | * @return TemplateResponse |
||
185 | */ |
||
186 | public function publicIndexForEmbeddingLegacy($token) { |
||
189 | |||
190 | /** |
||
191 | * get common parameters used for all three routes |
||
192 | * @return array |
||
193 | */ |
||
194 | 21 | private function getTemplateParams() { |
|
195 | 21 | $runningOn = $this->config->getSystemValue('version'); |
|
196 | 21 | $runningOnServer91OrLater = version_compare($runningOn, '9.1', '>='); |
|
197 | |||
198 | 21 | $supportsClass = $runningOnServer91OrLater; |
|
199 | |||
200 | 21 | $shareeCanEditShares = false; |
|
201 | 21 | $shareeCanEditCalendarProperties = false; |
|
202 | |||
203 | 21 | $appVersion = $this->config->getAppValue($this->appName, 'installed_version'); |
|
204 | 21 | $webCalWorkaround = $runningOnServer91OrLater ? 'no' : 'yes'; |
|
205 | 21 | $isIE = $this->request->isUserAgent([Request::USER_AGENT_IE]); |
|
206 | // $defaultColor = $this->config->getAppValue('theming', 'color', '#1d2d44'); |
||
207 | 21 | $canSharePublicLink = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
208 | |||
209 | return [ |
||
210 | 21 | 'appVersion' => $appVersion, |
|
211 | 21 | 'supportsClass' => $supportsClass, |
|
212 | 21 | 'isIE' => $isIE, |
|
213 | 21 | 'webCalWorkaround' => $webCalWorkaround, |
|
214 | 21 | 'defaultColor' => '#1d2d44', |
|
215 | 21 | 'shareeCanEditShares' => $shareeCanEditShares ? 'yes' : 'no', |
|
216 | 21 | 'shareeCanEditCalendarProperties' => $shareeCanEditCalendarProperties ? 'yes' : 'no', |
|
217 | 21 | 'canSharePublicLink' => $canSharePublicLink, |
|
218 | ]; |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * get common parameters for public sites |
||
223 | * @param string $token |
||
224 | * @return array |
||
225 | */ |
||
226 | 14 | private function getPublicTemplateParameters($token) { |
|
227 | 14 | $shareURL = $this->request->getServerProtocol() . '://'; |
|
228 | 14 | $shareURL .= $this->request->getServerHost(); |
|
229 | 14 | $shareURL .= $this->request->getRequestUri(); |
|
230 | |||
231 | 14 | $relativeImagePath = $this->urlGenerator->imagePath('core', 'favicon-touch.png'); |
|
232 | 14 | $previewImage = $this->urlGenerator->getAbsoluteURL($relativeImagePath); |
|
233 | |||
234 | 14 | $remoteBase = $this->urlGenerator->linkTo('', 'remote.php'); |
|
235 | 14 | $remoteBase .= '/dav/public-calendars/' . $token . '?export'; |
|
236 | |||
237 | 14 | $downloadUrl = $this->urlGenerator->getAbsoluteURL($remoteBase); |
|
238 | |||
239 | 14 | $protocolLength = strlen($this->request->getServerProtocol()) + 3; |
|
240 | 14 | $webcalUrl = 'webcal://' . substr($downloadUrl, $protocolLength); |
|
241 | |||
242 | return [ |
||
243 | 14 | 'initialView' => 'month', |
|
244 | 14 | 'emailAddress' => '', |
|
245 | 14 | 'skipPopover' => 'no', |
|
246 | 14 | 'weekNumbers' => 'no', |
|
247 | 14 | 'firstRun' => 'no', |
|
248 | 14 | 'webCalWorkaround' => 'no', |
|
249 | 'isPublic' => true, |
||
250 | 14 | 'shareURL' => $shareURL, |
|
251 | 14 | 'previewImage' => $previewImage, |
|
252 | 14 | 'webcalURL' => $webcalUrl, |
|
253 | 14 | 'downloadURL' => $downloadUrl, |
|
254 | 14 | 'token' => $token, |
|
255 | ]; |
||
256 | } |
||
257 | |||
258 | /** |
||
259 | * check if we need to show the asset pipeline warning |
||
260 | * @return bool |
||
261 | */ |
||
262 | 24 | private function needsAssetPipelineWarning() { |
|
269 | } |
||
270 |