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 | 15 | public function __construct($appName, IRequest $request, IUserSession $userSession, |
|
66 | |||
67 | /** |
||
68 | * @NoAdminRequired |
||
69 | * @NoCSRFRequired |
||
70 | * |
||
71 | * @return TemplateResponse |
||
72 | */ |
||
73 | 7 | public function index() { |
|
74 | 7 | $templateParameters = $this->getTemplateParams(); |
|
75 | |||
76 | 7 | $user = $this->userSession->getUser(); |
|
77 | 7 | $userId = $user->getUID(); |
|
78 | 7 | $emailAddress = $user->getEMailAddress(); |
|
79 | |||
80 | 7 | $initialView = $this->config->getUserValue($userId, $this->appName, 'currentView', null); |
|
81 | 7 | $skipPopover = $this->config->getUserValue($userId, $this->appName, 'skipPopover', 'no'); |
|
82 | 7 | $weekNumbers = $this->config->getUserValue($userId, $this->appName, 'showWeekNr', 'no'); |
|
83 | 7 | $firstRun = $this->config->getUserValue($userId, $this->appName, 'firstRun', null); |
|
84 | |||
85 | // the default view will be saved as soon as a user |
||
86 | // opens the calendar app, therefore this is a good |
||
87 | // indication if the calendar was used before |
||
88 | 7 | if ($firstRun === null) { |
|
89 | 2 | if ($initialView === null) { |
|
90 | 1 | $firstRun = 'yes'; |
|
91 | } else { |
||
92 | 1 | $this->config->setUserValue($userId, $this->appName, 'firstRun', 'no'); |
|
93 | 1 | $firstRun = 'no'; |
|
94 | } |
||
95 | } |
||
96 | |||
97 | 7 | if ($initialView === null) { |
|
98 | 2 | $initialView = 'month'; |
|
99 | } |
||
100 | |||
101 | 7 | return new TemplateResponse('calendar', 'main', array_merge($templateParameters, [ |
|
102 | 7 | 'initialView' => $initialView, |
|
103 | 7 | 'emailAddress' => $emailAddress, |
|
104 | 7 | 'skipPopover' => $skipPopover, |
|
105 | 7 | 'weekNumbers' => $weekNumbers, |
|
106 | 7 | 'firstRun' => $firstRun, |
|
107 | 'isPublic' => false, |
||
108 | 'isEmbedded' => false, |
||
109 | 7 | 'token' => '', |
|
110 | ])); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @PublicPage |
||
115 | * @NoCSRFRequired |
||
116 | * |
||
117 | * @param string $token |
||
118 | * |
||
119 | * @return TemplateResponse |
||
120 | */ |
||
121 | 4 | public function publicIndexWithBranding($token) { |
|
122 | 4 | $templateParameters = $this->getTemplateParams(); |
|
123 | 4 | $publicTemplateParameters = $this->getPublicTemplateParameters($token); |
|
124 | 4 | $params = array_merge($templateParameters, $publicTemplateParameters); |
|
125 | 4 | $params['isEmbedded'] = false; |
|
126 | |||
127 | 4 | return new TemplateResponse('calendar', 'public', $params, 'base'); |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * @PublicPage |
||
132 | * @NoCSRFRequired |
||
133 | * |
||
134 | * @param string $token |
||
135 | * |
||
136 | * @return TemplateResponse |
||
137 | */ |
||
138 | public function publicIndexWithBrandingAndFancyName($token) { |
||
139 | return $this->publicIndexWithBranding($token); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @PublicPage |
||
144 | * @NoCSRFRequired |
||
145 | * |
||
146 | * @param string $token |
||
147 | * |
||
148 | * @return TemplateResponse |
||
149 | */ |
||
150 | 4 | public function publicIndexForEmbedding($token) { |
|
151 | 4 | $templateParameters = $this->getTemplateParams(); |
|
152 | 4 | $publicTemplateParameters = $this->getPublicTemplateParameters($token); |
|
153 | 4 | $params = array_merge($templateParameters, $publicTemplateParameters); |
|
154 | 4 | $params['isEmbedded'] = true; |
|
155 | |||
156 | 4 | $response = new TemplateResponse('calendar', 'main', $params, 'public'); |
|
157 | |||
158 | 4 | $response->addHeader('X-Frame-Options', 'ALLOW'); |
|
159 | 4 | $csp = new ContentSecurityPolicy(); |
|
160 | 4 | $csp->addAllowedScriptDomain('*'); |
|
161 | 4 | $response->setContentSecurityPolicy($csp); |
|
162 | |||
163 | 4 | return $response; |
|
164 | } |
||
165 | |||
166 | /** |
||
167 | * @PublicPage |
||
168 | * @NoCSRFRequired |
||
169 | * |
||
170 | * @param string $token |
||
171 | * |
||
172 | * @return TemplateResponse |
||
173 | */ |
||
174 | public function publicIndexForEmbeddingLegacy($token) { |
||
177 | |||
178 | /** |
||
179 | * get common parameters used for all three routes |
||
180 | * @return array |
||
181 | */ |
||
182 | 15 | private function getTemplateParams() { |
|
183 | 15 | $runningOn = $this->config->getSystemValue('version'); |
|
184 | 15 | $runningOnNextcloud12OrLater = version_compare($runningOn, '12', '>='); |
|
185 | |||
186 | 15 | $shareeCanEditShares = !$runningOnNextcloud12OrLater; |
|
187 | 15 | $shareeCanEditCalendarProperties = $runningOnNextcloud12OrLater; |
|
188 | |||
189 | 15 | $appVersion = $this->config->getAppValue($this->appName, 'installed_version'); |
|
190 | 15 | $isIE = $this->request->isUserAgent([Request::USER_AGENT_IE]); |
|
191 | 15 | $defaultColor = $this->config->getAppValue('theming', 'color', '#0082C9'); |
|
192 | 15 | $canSharePublicLink = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
193 | |||
194 | return [ |
||
195 | 15 | 'appVersion' => $appVersion, |
|
196 | 15 | 'isIE' => $isIE, |
|
197 | 15 | 'defaultColor' => $defaultColor, |
|
198 | 15 | 'shareeCanEditShares' => $shareeCanEditShares ? 'yes' : 'no', |
|
199 | 15 | 'shareeCanEditCalendarProperties' => $shareeCanEditCalendarProperties ? 'yes' : 'no', |
|
200 | 15 | 'canSharePublicLink' => $canSharePublicLink, |
|
201 | ]; |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * get common parameters for public sites |
||
206 | * @param string $token |
||
207 | * @return array |
||
208 | */ |
||
209 | 8 | private function getPublicTemplateParameters($token) { |
|
239 | } |
||
240 |