@@ -62,347 +62,347 @@ discard block |
||
62 | 62 | * @package OCA\Theming\Controller |
63 | 63 | */ |
64 | 64 | class ThemingController extends Controller { |
65 | - /** @var ThemingDefaults */ |
|
66 | - private $themingDefaults; |
|
67 | - /** @var Util */ |
|
68 | - private $util; |
|
69 | - /** @var ITimeFactory */ |
|
70 | - private $timeFactory; |
|
71 | - /** @var IL10N */ |
|
72 | - private $l10n; |
|
73 | - /** @var IConfig */ |
|
74 | - private $config; |
|
75 | - /** @var ITempManager */ |
|
76 | - private $tempManager; |
|
77 | - /** @var IAppData */ |
|
78 | - private $appData; |
|
79 | - /** @var SCSSCacher */ |
|
80 | - private $scssCacher; |
|
81 | - /** @var IURLGenerator */ |
|
82 | - private $urlGenerator; |
|
83 | - /** @var IAppManager */ |
|
84 | - private $appManager; |
|
85 | - /** @var ImageManager */ |
|
86 | - private $imageManager; |
|
65 | + /** @var ThemingDefaults */ |
|
66 | + private $themingDefaults; |
|
67 | + /** @var Util */ |
|
68 | + private $util; |
|
69 | + /** @var ITimeFactory */ |
|
70 | + private $timeFactory; |
|
71 | + /** @var IL10N */ |
|
72 | + private $l10n; |
|
73 | + /** @var IConfig */ |
|
74 | + private $config; |
|
75 | + /** @var ITempManager */ |
|
76 | + private $tempManager; |
|
77 | + /** @var IAppData */ |
|
78 | + private $appData; |
|
79 | + /** @var SCSSCacher */ |
|
80 | + private $scssCacher; |
|
81 | + /** @var IURLGenerator */ |
|
82 | + private $urlGenerator; |
|
83 | + /** @var IAppManager */ |
|
84 | + private $appManager; |
|
85 | + /** @var ImageManager */ |
|
86 | + private $imageManager; |
|
87 | 87 | |
88 | - /** |
|
89 | - * ThemingController constructor. |
|
90 | - * |
|
91 | - * @param string $appName |
|
92 | - * @param IRequest $request |
|
93 | - * @param IConfig $config |
|
94 | - * @param ThemingDefaults $themingDefaults |
|
95 | - * @param Util $util |
|
96 | - * @param ITimeFactory $timeFactory |
|
97 | - * @param IL10N $l |
|
98 | - * @param ITempManager $tempManager |
|
99 | - * @param IAppData $appData |
|
100 | - * @param SCSSCacher $scssCacher |
|
101 | - * @param IURLGenerator $urlGenerator |
|
102 | - * @param IAppManager $appManager |
|
103 | - * @param ImageManager $imageManager |
|
104 | - */ |
|
105 | - public function __construct( |
|
106 | - $appName, |
|
107 | - IRequest $request, |
|
108 | - IConfig $config, |
|
109 | - ThemingDefaults $themingDefaults, |
|
110 | - Util $util, |
|
111 | - ITimeFactory $timeFactory, |
|
112 | - IL10N $l, |
|
113 | - ITempManager $tempManager, |
|
114 | - IAppData $appData, |
|
115 | - SCSSCacher $scssCacher, |
|
116 | - IURLGenerator $urlGenerator, |
|
117 | - IAppManager $appManager, |
|
118 | - ImageManager $imageManager |
|
119 | - ) { |
|
120 | - parent::__construct($appName, $request); |
|
88 | + /** |
|
89 | + * ThemingController constructor. |
|
90 | + * |
|
91 | + * @param string $appName |
|
92 | + * @param IRequest $request |
|
93 | + * @param IConfig $config |
|
94 | + * @param ThemingDefaults $themingDefaults |
|
95 | + * @param Util $util |
|
96 | + * @param ITimeFactory $timeFactory |
|
97 | + * @param IL10N $l |
|
98 | + * @param ITempManager $tempManager |
|
99 | + * @param IAppData $appData |
|
100 | + * @param SCSSCacher $scssCacher |
|
101 | + * @param IURLGenerator $urlGenerator |
|
102 | + * @param IAppManager $appManager |
|
103 | + * @param ImageManager $imageManager |
|
104 | + */ |
|
105 | + public function __construct( |
|
106 | + $appName, |
|
107 | + IRequest $request, |
|
108 | + IConfig $config, |
|
109 | + ThemingDefaults $themingDefaults, |
|
110 | + Util $util, |
|
111 | + ITimeFactory $timeFactory, |
|
112 | + IL10N $l, |
|
113 | + ITempManager $tempManager, |
|
114 | + IAppData $appData, |
|
115 | + SCSSCacher $scssCacher, |
|
116 | + IURLGenerator $urlGenerator, |
|
117 | + IAppManager $appManager, |
|
118 | + ImageManager $imageManager |
|
119 | + ) { |
|
120 | + parent::__construct($appName, $request); |
|
121 | 121 | |
122 | - $this->themingDefaults = $themingDefaults; |
|
123 | - $this->util = $util; |
|
124 | - $this->timeFactory = $timeFactory; |
|
125 | - $this->l10n = $l; |
|
126 | - $this->config = $config; |
|
127 | - $this->tempManager = $tempManager; |
|
128 | - $this->appData = $appData; |
|
129 | - $this->scssCacher = $scssCacher; |
|
130 | - $this->urlGenerator = $urlGenerator; |
|
131 | - $this->appManager = $appManager; |
|
132 | - $this->imageManager = $imageManager; |
|
133 | - } |
|
122 | + $this->themingDefaults = $themingDefaults; |
|
123 | + $this->util = $util; |
|
124 | + $this->timeFactory = $timeFactory; |
|
125 | + $this->l10n = $l; |
|
126 | + $this->config = $config; |
|
127 | + $this->tempManager = $tempManager; |
|
128 | + $this->appData = $appData; |
|
129 | + $this->scssCacher = $scssCacher; |
|
130 | + $this->urlGenerator = $urlGenerator; |
|
131 | + $this->appManager = $appManager; |
|
132 | + $this->imageManager = $imageManager; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param string $setting |
|
137 | - * @param string $value |
|
138 | - * @return DataResponse |
|
139 | - * @throws NotPermittedException |
|
140 | - */ |
|
141 | - public function updateStylesheet($setting, $value) { |
|
142 | - $value = trim($value); |
|
143 | - switch ($setting) { |
|
144 | - case 'name': |
|
145 | - if (strlen($value) > 250) { |
|
146 | - return new DataResponse([ |
|
147 | - 'data' => [ |
|
148 | - 'message' => $this->l10n->t('The given name is too long'), |
|
149 | - ], |
|
150 | - 'status' => 'error' |
|
151 | - ]); |
|
152 | - } |
|
153 | - break; |
|
154 | - case 'url': |
|
155 | - if (strlen($value) > 500) { |
|
156 | - return new DataResponse([ |
|
157 | - 'data' => [ |
|
158 | - 'message' => $this->l10n->t('The given web address is too long'), |
|
159 | - ], |
|
160 | - 'status' => 'error' |
|
161 | - ]); |
|
162 | - } |
|
163 | - break; |
|
164 | - case 'slogan': |
|
165 | - if (strlen($value) > 500) { |
|
166 | - return new DataResponse([ |
|
167 | - 'data' => [ |
|
168 | - 'message' => $this->l10n->t('The given slogan is too long'), |
|
169 | - ], |
|
170 | - 'status' => 'error' |
|
171 | - ]); |
|
172 | - } |
|
173 | - break; |
|
174 | - case 'color': |
|
175 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
176 | - return new DataResponse([ |
|
177 | - 'data' => [ |
|
178 | - 'message' => $this->l10n->t('The given color is invalid'), |
|
179 | - ], |
|
180 | - 'status' => 'error' |
|
181 | - ]); |
|
182 | - } |
|
183 | - break; |
|
184 | - } |
|
135 | + /** |
|
136 | + * @param string $setting |
|
137 | + * @param string $value |
|
138 | + * @return DataResponse |
|
139 | + * @throws NotPermittedException |
|
140 | + */ |
|
141 | + public function updateStylesheet($setting, $value) { |
|
142 | + $value = trim($value); |
|
143 | + switch ($setting) { |
|
144 | + case 'name': |
|
145 | + if (strlen($value) > 250) { |
|
146 | + return new DataResponse([ |
|
147 | + 'data' => [ |
|
148 | + 'message' => $this->l10n->t('The given name is too long'), |
|
149 | + ], |
|
150 | + 'status' => 'error' |
|
151 | + ]); |
|
152 | + } |
|
153 | + break; |
|
154 | + case 'url': |
|
155 | + if (strlen($value) > 500) { |
|
156 | + return new DataResponse([ |
|
157 | + 'data' => [ |
|
158 | + 'message' => $this->l10n->t('The given web address is too long'), |
|
159 | + ], |
|
160 | + 'status' => 'error' |
|
161 | + ]); |
|
162 | + } |
|
163 | + break; |
|
164 | + case 'slogan': |
|
165 | + if (strlen($value) > 500) { |
|
166 | + return new DataResponse([ |
|
167 | + 'data' => [ |
|
168 | + 'message' => $this->l10n->t('The given slogan is too long'), |
|
169 | + ], |
|
170 | + 'status' => 'error' |
|
171 | + ]); |
|
172 | + } |
|
173 | + break; |
|
174 | + case 'color': |
|
175 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
176 | + return new DataResponse([ |
|
177 | + 'data' => [ |
|
178 | + 'message' => $this->l10n->t('The given color is invalid'), |
|
179 | + ], |
|
180 | + 'status' => 'error' |
|
181 | + ]); |
|
182 | + } |
|
183 | + break; |
|
184 | + } |
|
185 | 185 | |
186 | - $this->themingDefaults->set($setting, $value); |
|
186 | + $this->themingDefaults->set($setting, $value); |
|
187 | 187 | |
188 | - // reprocess server scss for preview |
|
189 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
188 | + // reprocess server scss for preview |
|
189 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
190 | 190 | |
191 | - return new DataResponse( |
|
192 | - [ |
|
193 | - 'data' => |
|
194 | - [ |
|
195 | - 'message' => $this->l10n->t('Saved'), |
|
196 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
197 | - ], |
|
198 | - 'status' => 'success' |
|
199 | - ] |
|
200 | - ); |
|
201 | - } |
|
191 | + return new DataResponse( |
|
192 | + [ |
|
193 | + 'data' => |
|
194 | + [ |
|
195 | + 'message' => $this->l10n->t('Saved'), |
|
196 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
197 | + ], |
|
198 | + 'status' => 'success' |
|
199 | + ] |
|
200 | + ); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @return DataResponse |
|
205 | - * @throws NotPermittedException |
|
206 | - */ |
|
207 | - public function uploadImage(): DataResponse { |
|
208 | - // logo / background |
|
209 | - // new: favicon logo-header |
|
210 | - // |
|
211 | - $key = $this->request->getParam('key'); |
|
212 | - $image = $this->request->getUploadedFile('image'); |
|
213 | - $error = null; |
|
214 | - $phpFileUploadErrors = [ |
|
215 | - UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
216 | - UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
217 | - UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
218 | - UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
219 | - UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
220 | - UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
221 | - UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
222 | - UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
223 | - ]; |
|
224 | - if (empty($image)) { |
|
225 | - $error = $this->l10n->t('No file uploaded'); |
|
226 | - } |
|
227 | - if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { |
|
228 | - $error = $phpFileUploadErrors[$image['error']]; |
|
229 | - } |
|
203 | + /** |
|
204 | + * @return DataResponse |
|
205 | + * @throws NotPermittedException |
|
206 | + */ |
|
207 | + public function uploadImage(): DataResponse { |
|
208 | + // logo / background |
|
209 | + // new: favicon logo-header |
|
210 | + // |
|
211 | + $key = $this->request->getParam('key'); |
|
212 | + $image = $this->request->getUploadedFile('image'); |
|
213 | + $error = null; |
|
214 | + $phpFileUploadErrors = [ |
|
215 | + UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
216 | + UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
217 | + UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
218 | + UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
219 | + UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
220 | + UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
221 | + UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
222 | + UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
223 | + ]; |
|
224 | + if (empty($image)) { |
|
225 | + $error = $this->l10n->t('No file uploaded'); |
|
226 | + } |
|
227 | + if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { |
|
228 | + $error = $phpFileUploadErrors[$image['error']]; |
|
229 | + } |
|
230 | 230 | |
231 | - if ($error !== null) { |
|
232 | - return new DataResponse( |
|
233 | - [ |
|
234 | - 'data' => [ |
|
235 | - 'message' => $error |
|
236 | - ], |
|
237 | - 'status' => 'failure', |
|
238 | - ], |
|
239 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
240 | - ); |
|
241 | - } |
|
231 | + if ($error !== null) { |
|
232 | + return new DataResponse( |
|
233 | + [ |
|
234 | + 'data' => [ |
|
235 | + 'message' => $error |
|
236 | + ], |
|
237 | + 'status' => 'failure', |
|
238 | + ], |
|
239 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
240 | + ); |
|
241 | + } |
|
242 | 242 | |
243 | - $name = ''; |
|
244 | - try { |
|
245 | - $folder = $this->appData->getFolder('images'); |
|
246 | - } catch (NotFoundException $e) { |
|
247 | - $folder = $this->appData->newFolder('images'); |
|
248 | - } |
|
243 | + $name = ''; |
|
244 | + try { |
|
245 | + $folder = $this->appData->getFolder('images'); |
|
246 | + } catch (NotFoundException $e) { |
|
247 | + $folder = $this->appData->newFolder('images'); |
|
248 | + } |
|
249 | 249 | |
250 | - $target = $folder->newFile($key); |
|
251 | - $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/svg']; |
|
252 | - $detectedMimeType = mime_content_type($image['tmp_name']); |
|
253 | - if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) { |
|
254 | - return new DataResponse( |
|
255 | - [ |
|
256 | - 'data' => [ |
|
257 | - 'message' => $this->l10n->t('Unsupported image type'), |
|
258 | - ], |
|
259 | - 'status' => 'failure', |
|
260 | - ], |
|
261 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
262 | - ); |
|
263 | - } |
|
250 | + $target = $folder->newFile($key); |
|
251 | + $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/svg']; |
|
252 | + $detectedMimeType = mime_content_type($image['tmp_name']); |
|
253 | + if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) { |
|
254 | + return new DataResponse( |
|
255 | + [ |
|
256 | + 'data' => [ |
|
257 | + 'message' => $this->l10n->t('Unsupported image type'), |
|
258 | + ], |
|
259 | + 'status' => 'failure', |
|
260 | + ], |
|
261 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
262 | + ); |
|
263 | + } |
|
264 | 264 | |
265 | - $resizeKeys = ['background']; |
|
266 | - if (in_array($key, $resizeKeys, true)) { |
|
267 | - // Optimize the image since some people may upload images that will be |
|
268 | - // either to big or are not progressive rendering. |
|
269 | - $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r')); |
|
265 | + $resizeKeys = ['background']; |
|
266 | + if (in_array($key, $resizeKeys, true)) { |
|
267 | + // Optimize the image since some people may upload images that will be |
|
268 | + // either to big or are not progressive rendering. |
|
269 | + $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r')); |
|
270 | 270 | |
271 | - $tmpFile = $this->tempManager->getTemporaryFile(); |
|
272 | - $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096; |
|
273 | - $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth); |
|
274 | - $outputImage = imagescale($newImage, $newWidth, $newHeight); |
|
271 | + $tmpFile = $this->tempManager->getTemporaryFile(); |
|
272 | + $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096; |
|
273 | + $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth); |
|
274 | + $outputImage = imagescale($newImage, $newWidth, $newHeight); |
|
275 | 275 | |
276 | - imageinterlace($outputImage, 1); |
|
277 | - imagejpeg($outputImage, $tmpFile, 75); |
|
278 | - imagedestroy($outputImage); |
|
276 | + imageinterlace($outputImage, 1); |
|
277 | + imagejpeg($outputImage, $tmpFile, 75); |
|
278 | + imagedestroy($outputImage); |
|
279 | 279 | |
280 | - $target->putContent(file_get_contents($tmpFile, 'r')); |
|
281 | - } else { |
|
282 | - $target->putContent(file_get_contents($image['tmp_name'], 'r')); |
|
283 | - } |
|
284 | - $name = $image['name']; |
|
280 | + $target->putContent(file_get_contents($tmpFile, 'r')); |
|
281 | + } else { |
|
282 | + $target->putContent(file_get_contents($image['tmp_name'], 'r')); |
|
283 | + } |
|
284 | + $name = $image['name']; |
|
285 | 285 | |
286 | - $this->themingDefaults->set($key.'Mime', $image['type']); |
|
286 | + $this->themingDefaults->set($key.'Mime', $image['type']); |
|
287 | 287 | |
288 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
288 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
289 | 289 | |
290 | - return new DataResponse( |
|
291 | - [ |
|
292 | - 'data' => |
|
293 | - [ |
|
294 | - 'name' => $name, |
|
295 | - 'url' => $this->imageManager->getImageUrl($key), |
|
296 | - 'message' => $this->l10n->t('Saved'), |
|
297 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
298 | - ], |
|
299 | - 'status' => 'success' |
|
300 | - ] |
|
301 | - ); |
|
302 | - } |
|
290 | + return new DataResponse( |
|
291 | + [ |
|
292 | + 'data' => |
|
293 | + [ |
|
294 | + 'name' => $name, |
|
295 | + 'url' => $this->imageManager->getImageUrl($key), |
|
296 | + 'message' => $this->l10n->t('Saved'), |
|
297 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
298 | + ], |
|
299 | + 'status' => 'success' |
|
300 | + ] |
|
301 | + ); |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * Revert setting to default value |
|
306 | - * |
|
307 | - * @param string $setting setting which should be reverted |
|
308 | - * @return DataResponse |
|
309 | - * @throws NotPermittedException |
|
310 | - */ |
|
311 | - public function undo(string $setting): DataResponse { |
|
312 | - $value = $this->themingDefaults->undo($setting); |
|
313 | - // reprocess server scss for preview |
|
314 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
304 | + /** |
|
305 | + * Revert setting to default value |
|
306 | + * |
|
307 | + * @param string $setting setting which should be reverted |
|
308 | + * @return DataResponse |
|
309 | + * @throws NotPermittedException |
|
310 | + */ |
|
311 | + public function undo(string $setting): DataResponse { |
|
312 | + $value = $this->themingDefaults->undo($setting); |
|
313 | + // reprocess server scss for preview |
|
314 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
315 | 315 | |
316 | - if (strpos($setting, 'Mime') !== -1) { |
|
317 | - $imageKey = str_replace('Mime', '', $setting); |
|
318 | - $this->imageManager->delete($imageKey); |
|
319 | - } |
|
316 | + if (strpos($setting, 'Mime') !== -1) { |
|
317 | + $imageKey = str_replace('Mime', '', $setting); |
|
318 | + $this->imageManager->delete($imageKey); |
|
319 | + } |
|
320 | 320 | |
321 | - return new DataResponse( |
|
322 | - [ |
|
323 | - 'data' => |
|
324 | - [ |
|
325 | - 'value' => $value, |
|
326 | - 'message' => $this->l10n->t('Saved'), |
|
327 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
328 | - ], |
|
329 | - 'status' => 'success' |
|
330 | - ] |
|
331 | - ); |
|
332 | - } |
|
321 | + return new DataResponse( |
|
322 | + [ |
|
323 | + 'data' => |
|
324 | + [ |
|
325 | + 'value' => $value, |
|
326 | + 'message' => $this->l10n->t('Saved'), |
|
327 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
328 | + ], |
|
329 | + 'status' => 'success' |
|
330 | + ] |
|
331 | + ); |
|
332 | + } |
|
333 | 333 | |
334 | - /** |
|
335 | - * @PublicPage |
|
336 | - * @NoCSRFRequired |
|
337 | - * |
|
338 | - * @param string $key |
|
339 | - * @return FileDisplayResponse|NotFoundResponse |
|
340 | - * @throws \Exception |
|
341 | - */ |
|
342 | - public function getImage(string $key) { |
|
343 | - try { |
|
344 | - $file = $this->imageManager->getImage($key); |
|
345 | - } catch (NotFoundException $e) { |
|
346 | - return new NotFoundResponse(); |
|
347 | - } |
|
334 | + /** |
|
335 | + * @PublicPage |
|
336 | + * @NoCSRFRequired |
|
337 | + * |
|
338 | + * @param string $key |
|
339 | + * @return FileDisplayResponse|NotFoundResponse |
|
340 | + * @throws \Exception |
|
341 | + */ |
|
342 | + public function getImage(string $key) { |
|
343 | + try { |
|
344 | + $file = $this->imageManager->getImage($key); |
|
345 | + } catch (NotFoundException $e) { |
|
346 | + return new NotFoundResponse(); |
|
347 | + } |
|
348 | 348 | |
349 | - $response = new FileDisplayResponse($file); |
|
350 | - $response->cacheFor(3600); |
|
351 | - $expires = new \DateTime(); |
|
352 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
353 | - $expires->add(new \DateInterval('PT24H')); |
|
354 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
355 | - $response->addHeader('Pragma', 'cache'); |
|
356 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
357 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
358 | - return $response; |
|
359 | - } |
|
349 | + $response = new FileDisplayResponse($file); |
|
350 | + $response->cacheFor(3600); |
|
351 | + $expires = new \DateTime(); |
|
352 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
353 | + $expires->add(new \DateInterval('PT24H')); |
|
354 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
355 | + $response->addHeader('Pragma', 'cache'); |
|
356 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
357 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
358 | + return $response; |
|
359 | + } |
|
360 | 360 | |
361 | - /** |
|
362 | - * @NoCSRFRequired |
|
363 | - * @PublicPage |
|
364 | - * |
|
365 | - * @return FileDisplayResponse|NotFoundResponse |
|
366 | - * @throws NotPermittedException |
|
367 | - * @throws \Exception |
|
368 | - * @throws \OCP\App\AppPathNotFoundException |
|
369 | - */ |
|
370 | - public function getStylesheet() { |
|
371 | - $appPath = $this->appManager->getAppPath('theming'); |
|
361 | + /** |
|
362 | + * @NoCSRFRequired |
|
363 | + * @PublicPage |
|
364 | + * |
|
365 | + * @return FileDisplayResponse|NotFoundResponse |
|
366 | + * @throws NotPermittedException |
|
367 | + * @throws \Exception |
|
368 | + * @throws \OCP\App\AppPathNotFoundException |
|
369 | + */ |
|
370 | + public function getStylesheet() { |
|
371 | + $appPath = $this->appManager->getAppPath('theming'); |
|
372 | 372 | |
373 | - /* SCSSCacher is required here |
|
373 | + /* SCSSCacher is required here |
|
374 | 374 | * We cannot rely on automatic caching done by \OC_Util::addStyle, |
375 | 375 | * since we need to add the cacheBuster value to the url |
376 | 376 | */ |
377 | - $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
|
378 | - if(!$cssCached) { |
|
379 | - return new NotFoundResponse(); |
|
380 | - } |
|
377 | + $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
|
378 | + if(!$cssCached) { |
|
379 | + return new NotFoundResponse(); |
|
380 | + } |
|
381 | 381 | |
382 | - try { |
|
383 | - $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
384 | - $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
385 | - $response->cacheFor(86400); |
|
386 | - $expires = new \DateTime(); |
|
387 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
388 | - $expires->add(new \DateInterval('PT24H')); |
|
389 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
390 | - $response->addHeader('Pragma', 'cache'); |
|
391 | - return $response; |
|
392 | - } catch (NotFoundException $e) { |
|
393 | - return new NotFoundResponse(); |
|
394 | - } |
|
395 | - } |
|
382 | + try { |
|
383 | + $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
384 | + $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
385 | + $response->cacheFor(86400); |
|
386 | + $expires = new \DateTime(); |
|
387 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
388 | + $expires->add(new \DateInterval('PT24H')); |
|
389 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
390 | + $response->addHeader('Pragma', 'cache'); |
|
391 | + return $response; |
|
392 | + } catch (NotFoundException $e) { |
|
393 | + return new NotFoundResponse(); |
|
394 | + } |
|
395 | + } |
|
396 | 396 | |
397 | - /** |
|
398 | - * @NoCSRFRequired |
|
399 | - * @PublicPage |
|
400 | - * |
|
401 | - * @return DataDownloadResponse |
|
402 | - */ |
|
403 | - public function getJavascript() { |
|
404 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
405 | - $responseJS = '(function() { |
|
397 | + /** |
|
398 | + * @NoCSRFRequired |
|
399 | + * @PublicPage |
|
400 | + * |
|
401 | + * @return DataDownloadResponse |
|
402 | + */ |
|
403 | + public function getJavascript() { |
|
404 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
405 | + $responseJS = '(function() { |
|
406 | 406 | OCA.Theming = { |
407 | 407 | name: ' . json_encode($this->themingDefaults->getName()) . ', |
408 | 408 | url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
@@ -412,45 +412,45 @@ discard block |
||
412 | 412 | cacheBuster: ' . json_encode($cacheBusterValue) . ' |
413 | 413 | }; |
414 | 414 | })();'; |
415 | - $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
416 | - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
417 | - $response->addHeader('Pragma', 'cache'); |
|
418 | - $response->cacheFor(3600); |
|
419 | - return $response; |
|
420 | - } |
|
415 | + $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
416 | + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
417 | + $response->addHeader('Pragma', 'cache'); |
|
418 | + $response->cacheFor(3600); |
|
419 | + return $response; |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
423 | - * @NoCSRFRequired |
|
424 | - * @PublicPage |
|
425 | - * |
|
426 | - * @return Http\JSONResponse |
|
427 | - */ |
|
428 | - public function getManifest($app) { |
|
429 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
430 | - $responseJS = [ |
|
431 | - 'name' => $this->themingDefaults->getName(), |
|
432 | - 'start_url' => $this->urlGenerator->getBaseUrl(), |
|
433 | - 'icons' => |
|
434 | - [ |
|
435 | - [ |
|
436 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
437 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
438 | - 'type'=> 'image/png', |
|
439 | - 'sizes'=> '128x128' |
|
440 | - ], |
|
441 | - [ |
|
442 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
443 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
444 | - 'type' => 'image/svg+xml', |
|
445 | - 'sizes' => '16x16' |
|
446 | - ] |
|
447 | - ], |
|
448 | - 'display' => 'standalone' |
|
449 | - ]; |
|
450 | - $response = new Http\JSONResponse($responseJS); |
|
451 | - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
452 | - $response->addHeader('Pragma', 'cache'); |
|
453 | - $response->cacheFor(3600); |
|
454 | - return $response; |
|
455 | - } |
|
422 | + /** |
|
423 | + * @NoCSRFRequired |
|
424 | + * @PublicPage |
|
425 | + * |
|
426 | + * @return Http\JSONResponse |
|
427 | + */ |
|
428 | + public function getManifest($app) { |
|
429 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
430 | + $responseJS = [ |
|
431 | + 'name' => $this->themingDefaults->getName(), |
|
432 | + 'start_url' => $this->urlGenerator->getBaseUrl(), |
|
433 | + 'icons' => |
|
434 | + [ |
|
435 | + [ |
|
436 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
437 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
438 | + 'type'=> 'image/png', |
|
439 | + 'sizes'=> '128x128' |
|
440 | + ], |
|
441 | + [ |
|
442 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
443 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
444 | + 'type' => 'image/svg+xml', |
|
445 | + 'sizes' => '16x16' |
|
446 | + ] |
|
447 | + ], |
|
448 | + 'display' => 'standalone' |
|
449 | + ]; |
|
450 | + $response = new Http\JSONResponse($responseJS); |
|
451 | + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
452 | + $response->addHeader('Pragma', 'cache'); |
|
453 | + $response->cacheFor(3600); |
|
454 | + return $response; |
|
455 | + } |
|
456 | 456 | } |
@@ -353,8 +353,8 @@ discard block |
||
353 | 353 | $expires->add(new \DateInterval('PT24H')); |
354 | 354 | $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
355 | 355 | $response->addHeader('Pragma', 'cache'); |
356 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
357 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
356 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key.'Mime', '')); |
|
357 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.$key.'"'); |
|
358 | 358 | return $response; |
359 | 359 | } |
360 | 360 | |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * since we need to add the cacheBuster value to the url |
376 | 376 | */ |
377 | 377 | $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
378 | - if(!$cssCached) { |
|
378 | + if (!$cssCached) { |
|
379 | 379 | return new NotFoundResponse(); |
380 | 380 | } |
381 | 381 | |
@@ -404,12 +404,12 @@ discard block |
||
404 | 404 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
405 | 405 | $responseJS = '(function() { |
406 | 406 | OCA.Theming = { |
407 | - name: ' . json_encode($this->themingDefaults->getName()) . ', |
|
408 | - url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
|
409 | - slogan: ' . json_encode($this->themingDefaults->getSlogan()) . ', |
|
410 | - color: ' . json_encode($this->themingDefaults->getColorPrimary()) . ', |
|
411 | - inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())) . ', |
|
412 | - cacheBuster: ' . json_encode($cacheBusterValue) . ' |
|
407 | + name: ' . json_encode($this->themingDefaults->getName()).', |
|
408 | + url: ' . json_encode($this->themingDefaults->getBaseUrl()).', |
|
409 | + slogan: ' . json_encode($this->themingDefaults->getSlogan()).', |
|
410 | + color: ' . json_encode($this->themingDefaults->getColorPrimary()).', |
|
411 | + inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())).', |
|
412 | + cacheBuster: ' . json_encode($cacheBusterValue).' |
|
413 | 413 | }; |
414 | 414 | })();'; |
415 | 415 | $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
@@ -434,13 +434,13 @@ discard block |
||
434 | 434 | [ |
435 | 435 | [ |
436 | 436 | 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
437 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
437 | + ['app' => $app]).'?v='.$cacheBusterValue, |
|
438 | 438 | 'type'=> 'image/png', |
439 | 439 | 'sizes'=> '128x128' |
440 | 440 | ], |
441 | 441 | [ |
442 | 442 | 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
443 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
443 | + ['app' => $app]).'?v='.$cacheBusterValue, |
|
444 | 444 | 'type' => 'image/svg+xml', |
445 | 445 | 'sizes' => '16x16' |
446 | 446 | ] |