@@ -57,330 +57,330 @@ discard block |
||
| 57 | 57 | * @package OCA\Theming\Controller |
| 58 | 58 | */ |
| 59 | 59 | class ThemingController extends Controller { |
| 60 | - /** @var ThemingDefaults */ |
|
| 61 | - private $themingDefaults; |
|
| 62 | - /** @var Util */ |
|
| 63 | - private $util; |
|
| 64 | - /** @var ITimeFactory */ |
|
| 65 | - private $timeFactory; |
|
| 66 | - /** @var IL10N */ |
|
| 67 | - private $l10n; |
|
| 68 | - /** @var IConfig */ |
|
| 69 | - private $config; |
|
| 70 | - /** @var ITempManager */ |
|
| 71 | - private $tempManager; |
|
| 72 | - /** @var IAppData */ |
|
| 73 | - private $appData; |
|
| 74 | - /** @var SCSSCacher */ |
|
| 75 | - private $scssCacher; |
|
| 60 | + /** @var ThemingDefaults */ |
|
| 61 | + private $themingDefaults; |
|
| 62 | + /** @var Util */ |
|
| 63 | + private $util; |
|
| 64 | + /** @var ITimeFactory */ |
|
| 65 | + private $timeFactory; |
|
| 66 | + /** @var IL10N */ |
|
| 67 | + private $l10n; |
|
| 68 | + /** @var IConfig */ |
|
| 69 | + private $config; |
|
| 70 | + /** @var ITempManager */ |
|
| 71 | + private $tempManager; |
|
| 72 | + /** @var IAppData */ |
|
| 73 | + private $appData; |
|
| 74 | + /** @var SCSSCacher */ |
|
| 75 | + private $scssCacher; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * ThemingController constructor. |
|
| 79 | - * |
|
| 80 | - * @param string $appName |
|
| 81 | - * @param IRequest $request |
|
| 82 | - * @param IConfig $config |
|
| 83 | - * @param ThemingDefaults $themingDefaults |
|
| 84 | - * @param Util $util |
|
| 85 | - * @param ITimeFactory $timeFactory |
|
| 86 | - * @param IL10N $l |
|
| 87 | - * @param ITempManager $tempManager |
|
| 88 | - * @param IAppData $appData |
|
| 89 | - * @param SCSSCacher $scssCacher |
|
| 90 | - */ |
|
| 91 | - public function __construct( |
|
| 92 | - $appName, |
|
| 93 | - IRequest $request, |
|
| 94 | - IConfig $config, |
|
| 95 | - ThemingDefaults $themingDefaults, |
|
| 96 | - Util $util, |
|
| 97 | - ITimeFactory $timeFactory, |
|
| 98 | - IL10N $l, |
|
| 99 | - ITempManager $tempManager, |
|
| 100 | - IAppData $appData, |
|
| 101 | - SCSSCacher $scssCacher |
|
| 102 | - ) { |
|
| 103 | - parent::__construct($appName, $request); |
|
| 77 | + /** |
|
| 78 | + * ThemingController constructor. |
|
| 79 | + * |
|
| 80 | + * @param string $appName |
|
| 81 | + * @param IRequest $request |
|
| 82 | + * @param IConfig $config |
|
| 83 | + * @param ThemingDefaults $themingDefaults |
|
| 84 | + * @param Util $util |
|
| 85 | + * @param ITimeFactory $timeFactory |
|
| 86 | + * @param IL10N $l |
|
| 87 | + * @param ITempManager $tempManager |
|
| 88 | + * @param IAppData $appData |
|
| 89 | + * @param SCSSCacher $scssCacher |
|
| 90 | + */ |
|
| 91 | + public function __construct( |
|
| 92 | + $appName, |
|
| 93 | + IRequest $request, |
|
| 94 | + IConfig $config, |
|
| 95 | + ThemingDefaults $themingDefaults, |
|
| 96 | + Util $util, |
|
| 97 | + ITimeFactory $timeFactory, |
|
| 98 | + IL10N $l, |
|
| 99 | + ITempManager $tempManager, |
|
| 100 | + IAppData $appData, |
|
| 101 | + SCSSCacher $scssCacher |
|
| 102 | + ) { |
|
| 103 | + parent::__construct($appName, $request); |
|
| 104 | 104 | |
| 105 | - $this->themingDefaults = $themingDefaults; |
|
| 106 | - $this->util = $util; |
|
| 107 | - $this->timeFactory = $timeFactory; |
|
| 108 | - $this->l10n = $l; |
|
| 109 | - $this->config = $config; |
|
| 110 | - $this->tempManager = $tempManager; |
|
| 111 | - $this->appData = $appData; |
|
| 112 | - $this->scssCacher = $scssCacher; |
|
| 113 | - } |
|
| 105 | + $this->themingDefaults = $themingDefaults; |
|
| 106 | + $this->util = $util; |
|
| 107 | + $this->timeFactory = $timeFactory; |
|
| 108 | + $this->l10n = $l; |
|
| 109 | + $this->config = $config; |
|
| 110 | + $this->tempManager = $tempManager; |
|
| 111 | + $this->appData = $appData; |
|
| 112 | + $this->scssCacher = $scssCacher; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * @param string $setting |
|
| 117 | - * @param string $value |
|
| 118 | - * @return DataResponse |
|
| 119 | - * @internal param string $color |
|
| 120 | - */ |
|
| 121 | - public function updateStylesheet($setting, $value) { |
|
| 122 | - $value = trim($value); |
|
| 123 | - switch ($setting) { |
|
| 124 | - case 'name': |
|
| 125 | - if (strlen($value) > 250) { |
|
| 126 | - return new DataResponse([ |
|
| 127 | - 'data' => [ |
|
| 128 | - 'message' => $this->l10n->t('The given name is too long'), |
|
| 129 | - ], |
|
| 130 | - 'status' => 'error' |
|
| 131 | - ]); |
|
| 132 | - } |
|
| 133 | - break; |
|
| 134 | - case 'url': |
|
| 135 | - if (strlen($value) > 500) { |
|
| 136 | - return new DataResponse([ |
|
| 137 | - 'data' => [ |
|
| 138 | - 'message' => $this->l10n->t('The given web address is too long'), |
|
| 139 | - ], |
|
| 140 | - 'status' => 'error' |
|
| 141 | - ]); |
|
| 142 | - } |
|
| 143 | - break; |
|
| 144 | - case 'slogan': |
|
| 145 | - if (strlen($value) > 500) { |
|
| 146 | - return new DataResponse([ |
|
| 147 | - 'data' => [ |
|
| 148 | - 'message' => $this->l10n->t('The given slogan is too long'), |
|
| 149 | - ], |
|
| 150 | - 'status' => 'error' |
|
| 151 | - ]); |
|
| 152 | - } |
|
| 153 | - break; |
|
| 154 | - case 'color': |
|
| 155 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 156 | - return new DataResponse([ |
|
| 157 | - 'data' => [ |
|
| 158 | - 'message' => $this->l10n->t('The given color is invalid'), |
|
| 159 | - ], |
|
| 160 | - 'status' => 'error' |
|
| 161 | - ]); |
|
| 162 | - } |
|
| 163 | - break; |
|
| 164 | - } |
|
| 115 | + /** |
|
| 116 | + * @param string $setting |
|
| 117 | + * @param string $value |
|
| 118 | + * @return DataResponse |
|
| 119 | + * @internal param string $color |
|
| 120 | + */ |
|
| 121 | + public function updateStylesheet($setting, $value) { |
|
| 122 | + $value = trim($value); |
|
| 123 | + switch ($setting) { |
|
| 124 | + case 'name': |
|
| 125 | + if (strlen($value) > 250) { |
|
| 126 | + return new DataResponse([ |
|
| 127 | + 'data' => [ |
|
| 128 | + 'message' => $this->l10n->t('The given name is too long'), |
|
| 129 | + ], |
|
| 130 | + 'status' => 'error' |
|
| 131 | + ]); |
|
| 132 | + } |
|
| 133 | + break; |
|
| 134 | + case 'url': |
|
| 135 | + if (strlen($value) > 500) { |
|
| 136 | + return new DataResponse([ |
|
| 137 | + 'data' => [ |
|
| 138 | + 'message' => $this->l10n->t('The given web address is too long'), |
|
| 139 | + ], |
|
| 140 | + 'status' => 'error' |
|
| 141 | + ]); |
|
| 142 | + } |
|
| 143 | + break; |
|
| 144 | + case 'slogan': |
|
| 145 | + if (strlen($value) > 500) { |
|
| 146 | + return new DataResponse([ |
|
| 147 | + 'data' => [ |
|
| 148 | + 'message' => $this->l10n->t('The given slogan is too long'), |
|
| 149 | + ], |
|
| 150 | + 'status' => 'error' |
|
| 151 | + ]); |
|
| 152 | + } |
|
| 153 | + break; |
|
| 154 | + case 'color': |
|
| 155 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 156 | + return new DataResponse([ |
|
| 157 | + 'data' => [ |
|
| 158 | + 'message' => $this->l10n->t('The given color is invalid'), |
|
| 159 | + ], |
|
| 160 | + 'status' => 'error' |
|
| 161 | + ]); |
|
| 162 | + } |
|
| 163 | + break; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - $this->themingDefaults->set($setting, $value); |
|
| 167 | - return new DataResponse( |
|
| 168 | - [ |
|
| 169 | - 'data' => |
|
| 170 | - [ |
|
| 171 | - 'message' => $this->l10n->t('Saved') |
|
| 172 | - ], |
|
| 173 | - 'status' => 'success' |
|
| 174 | - ] |
|
| 175 | - ); |
|
| 176 | - } |
|
| 166 | + $this->themingDefaults->set($setting, $value); |
|
| 167 | + return new DataResponse( |
|
| 168 | + [ |
|
| 169 | + 'data' => |
|
| 170 | + [ |
|
| 171 | + 'message' => $this->l10n->t('Saved') |
|
| 172 | + ], |
|
| 173 | + 'status' => 'success' |
|
| 174 | + ] |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Update the logos and background image |
|
| 180 | - * |
|
| 181 | - * @return DataResponse |
|
| 182 | - */ |
|
| 183 | - public function updateLogo() { |
|
| 184 | - $newLogo = $this->request->getUploadedFile('uploadlogo'); |
|
| 185 | - $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background'); |
|
| 186 | - if (empty($newLogo) && empty($newBackgroundLogo)) { |
|
| 187 | - return new DataResponse( |
|
| 188 | - [ |
|
| 189 | - 'data' => [ |
|
| 190 | - 'message' => $this->l10n->t('No file uploaded') |
|
| 191 | - ] |
|
| 192 | - ], |
|
| 193 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 194 | - ); |
|
| 195 | - } |
|
| 178 | + /** |
|
| 179 | + * Update the logos and background image |
|
| 180 | + * |
|
| 181 | + * @return DataResponse |
|
| 182 | + */ |
|
| 183 | + public function updateLogo() { |
|
| 184 | + $newLogo = $this->request->getUploadedFile('uploadlogo'); |
|
| 185 | + $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background'); |
|
| 186 | + if (empty($newLogo) && empty($newBackgroundLogo)) { |
|
| 187 | + return new DataResponse( |
|
| 188 | + [ |
|
| 189 | + 'data' => [ |
|
| 190 | + 'message' => $this->l10n->t('No file uploaded') |
|
| 191 | + ] |
|
| 192 | + ], |
|
| 193 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 194 | + ); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - $name = ''; |
|
| 198 | - try { |
|
| 199 | - $folder = $this->appData->getFolder('images'); |
|
| 200 | - } catch (NotFoundException $e) { |
|
| 201 | - $folder = $this->appData->newFolder('images'); |
|
| 202 | - } |
|
| 197 | + $name = ''; |
|
| 198 | + try { |
|
| 199 | + $folder = $this->appData->getFolder('images'); |
|
| 200 | + } catch (NotFoundException $e) { |
|
| 201 | + $folder = $this->appData->newFolder('images'); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - if (!empty($newLogo)) { |
|
| 205 | - $target = $folder->newFile('logo'); |
|
| 206 | - $target->putContent(file_get_contents($newLogo['tmp_name'], 'r')); |
|
| 207 | - $this->themingDefaults->set('logoMime', $newLogo['type']); |
|
| 208 | - $name = $newLogo['name']; |
|
| 209 | - } |
|
| 210 | - if (!empty($newBackgroundLogo)) { |
|
| 211 | - $target = $folder->newFile('background'); |
|
| 212 | - $image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r')); |
|
| 213 | - if ($image === false) { |
|
| 214 | - return new DataResponse( |
|
| 215 | - [ |
|
| 216 | - 'data' => [ |
|
| 217 | - 'message' => $this->l10n->t('Unsupported image type'), |
|
| 218 | - ], |
|
| 219 | - 'status' => 'failure', |
|
| 220 | - ], |
|
| 221 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 222 | - ); |
|
| 223 | - } |
|
| 204 | + if (!empty($newLogo)) { |
|
| 205 | + $target = $folder->newFile('logo'); |
|
| 206 | + $target->putContent(file_get_contents($newLogo['tmp_name'], 'r')); |
|
| 207 | + $this->themingDefaults->set('logoMime', $newLogo['type']); |
|
| 208 | + $name = $newLogo['name']; |
|
| 209 | + } |
|
| 210 | + if (!empty($newBackgroundLogo)) { |
|
| 211 | + $target = $folder->newFile('background'); |
|
| 212 | + $image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r')); |
|
| 213 | + if ($image === false) { |
|
| 214 | + return new DataResponse( |
|
| 215 | + [ |
|
| 216 | + 'data' => [ |
|
| 217 | + 'message' => $this->l10n->t('Unsupported image type'), |
|
| 218 | + ], |
|
| 219 | + 'status' => 'failure', |
|
| 220 | + ], |
|
| 221 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 222 | + ); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // Optimize the image since some people may upload images that will be |
|
| 226 | - // either to big or are not progressive rendering. |
|
| 227 | - $tmpFile = $this->tempManager->getTemporaryFile(); |
|
| 228 | - if (function_exists('imagescale')) { |
|
| 229 | - // FIXME: Once PHP 5.5.0 is a requirement the above check can be removed |
|
| 230 | - // Workaround for https://bugs.php.net/bug.php?id=65171 |
|
| 231 | - $newHeight = imagesy($image) / (imagesx($image) / 1920); |
|
| 232 | - $image = imagescale($image, 1920, $newHeight); |
|
| 233 | - } |
|
| 234 | - imageinterlace($image, 1); |
|
| 235 | - imagejpeg($image, $tmpFile, 75); |
|
| 236 | - imagedestroy($image); |
|
| 225 | + // Optimize the image since some people may upload images that will be |
|
| 226 | + // either to big or are not progressive rendering. |
|
| 227 | + $tmpFile = $this->tempManager->getTemporaryFile(); |
|
| 228 | + if (function_exists('imagescale')) { |
|
| 229 | + // FIXME: Once PHP 5.5.0 is a requirement the above check can be removed |
|
| 230 | + // Workaround for https://bugs.php.net/bug.php?id=65171 |
|
| 231 | + $newHeight = imagesy($image) / (imagesx($image) / 1920); |
|
| 232 | + $image = imagescale($image, 1920, $newHeight); |
|
| 233 | + } |
|
| 234 | + imageinterlace($image, 1); |
|
| 235 | + imagejpeg($image, $tmpFile, 75); |
|
| 236 | + imagedestroy($image); |
|
| 237 | 237 | |
| 238 | - $target->putContent(file_get_contents($tmpFile, 'r')); |
|
| 239 | - $this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']); |
|
| 240 | - $name = $newBackgroundLogo['name']; |
|
| 241 | - } |
|
| 238 | + $target->putContent(file_get_contents($tmpFile, 'r')); |
|
| 239 | + $this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']); |
|
| 240 | + $name = $newBackgroundLogo['name']; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - return new DataResponse( |
|
| 244 | - [ |
|
| 245 | - 'data' => |
|
| 246 | - [ |
|
| 247 | - 'name' => $name, |
|
| 248 | - 'message' => $this->l10n->t('Saved') |
|
| 249 | - ], |
|
| 250 | - 'status' => 'success' |
|
| 251 | - ] |
|
| 252 | - ); |
|
| 253 | - } |
|
| 243 | + return new DataResponse( |
|
| 244 | + [ |
|
| 245 | + 'data' => |
|
| 246 | + [ |
|
| 247 | + 'name' => $name, |
|
| 248 | + 'message' => $this->l10n->t('Saved') |
|
| 249 | + ], |
|
| 250 | + 'status' => 'success' |
|
| 251 | + ] |
|
| 252 | + ); |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Revert setting to default value |
|
| 257 | - * |
|
| 258 | - * @param string $setting setting which should be reverted |
|
| 259 | - * @return DataResponse |
|
| 260 | - */ |
|
| 261 | - public function undo($setting) { |
|
| 262 | - $value = $this->themingDefaults->undo($setting); |
|
| 255 | + /** |
|
| 256 | + * Revert setting to default value |
|
| 257 | + * |
|
| 258 | + * @param string $setting setting which should be reverted |
|
| 259 | + * @return DataResponse |
|
| 260 | + */ |
|
| 261 | + public function undo($setting) { |
|
| 262 | + $value = $this->themingDefaults->undo($setting); |
|
| 263 | 263 | |
| 264 | - if($setting === 'logoMime') { |
|
| 265 | - try { |
|
| 266 | - $file = $this->appData->getFolder('images')->getFile('logo'); |
|
| 267 | - $file->delete(); |
|
| 268 | - } catch (NotFoundException $e) { |
|
| 269 | - } catch (NotPermittedException $e) { |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - if($setting === 'backgroundMime') { |
|
| 273 | - try { |
|
| 274 | - $file = $this->appData->getFolder('images')->getFile('background'); |
|
| 275 | - $file->delete(); |
|
| 276 | - } catch (NotFoundException $e) { |
|
| 277 | - } catch (NotPermittedException $e) { |
|
| 278 | - } |
|
| 279 | - } |
|
| 264 | + if($setting === 'logoMime') { |
|
| 265 | + try { |
|
| 266 | + $file = $this->appData->getFolder('images')->getFile('logo'); |
|
| 267 | + $file->delete(); |
|
| 268 | + } catch (NotFoundException $e) { |
|
| 269 | + } catch (NotPermittedException $e) { |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + if($setting === 'backgroundMime') { |
|
| 273 | + try { |
|
| 274 | + $file = $this->appData->getFolder('images')->getFile('background'); |
|
| 275 | + $file->delete(); |
|
| 276 | + } catch (NotFoundException $e) { |
|
| 277 | + } catch (NotPermittedException $e) { |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - return new DataResponse( |
|
| 282 | - [ |
|
| 283 | - 'data' => |
|
| 284 | - [ |
|
| 285 | - 'value' => $value, |
|
| 286 | - 'message' => $this->l10n->t('Saved') |
|
| 287 | - ], |
|
| 288 | - 'status' => 'success' |
|
| 289 | - ] |
|
| 290 | - ); |
|
| 291 | - } |
|
| 281 | + return new DataResponse( |
|
| 282 | + [ |
|
| 283 | + 'data' => |
|
| 284 | + [ |
|
| 285 | + 'value' => $value, |
|
| 286 | + 'message' => $this->l10n->t('Saved') |
|
| 287 | + ], |
|
| 288 | + 'status' => 'success' |
|
| 289 | + ] |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * @PublicPage |
|
| 295 | - * @NoCSRFRequired |
|
| 296 | - * |
|
| 297 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 298 | - */ |
|
| 299 | - public function getLogo() { |
|
| 300 | - try { |
|
| 301 | - /** @var File $file */ |
|
| 302 | - $file = $this->appData->getFolder('images')->getFile('logo'); |
|
| 303 | - } catch (NotFoundException $e) { |
|
| 304 | - return new NotFoundResponse(); |
|
| 305 | - } |
|
| 293 | + /** |
|
| 294 | + * @PublicPage |
|
| 295 | + * @NoCSRFRequired |
|
| 296 | + * |
|
| 297 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 298 | + */ |
|
| 299 | + public function getLogo() { |
|
| 300 | + try { |
|
| 301 | + /** @var File $file */ |
|
| 302 | + $file = $this->appData->getFolder('images')->getFile('logo'); |
|
| 303 | + } catch (NotFoundException $e) { |
|
| 304 | + return new NotFoundResponse(); |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - $response = new FileDisplayResponse($file); |
|
| 308 | - $response->cacheFor(3600); |
|
| 309 | - $expires = new \DateTime(); |
|
| 310 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 311 | - $expires->add(new \DateInterval('PT24H')); |
|
| 312 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 313 | - $response->addHeader('Pragma', 'cache'); |
|
| 314 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', '')); |
|
| 315 | - return $response; |
|
| 316 | - } |
|
| 307 | + $response = new FileDisplayResponse($file); |
|
| 308 | + $response->cacheFor(3600); |
|
| 309 | + $expires = new \DateTime(); |
|
| 310 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 311 | + $expires->add(new \DateInterval('PT24H')); |
|
| 312 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 313 | + $response->addHeader('Pragma', 'cache'); |
|
| 314 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', '')); |
|
| 315 | + return $response; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * @PublicPage |
|
| 320 | - * @NoCSRFRequired |
|
| 321 | - * |
|
| 322 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 323 | - */ |
|
| 324 | - public function getLoginBackground() { |
|
| 325 | - try { |
|
| 326 | - /** @var File $file */ |
|
| 327 | - $file = $this->appData->getFolder('images')->getFile('background'); |
|
| 328 | - } catch (NotFoundException $e) { |
|
| 329 | - return new NotFoundResponse(); |
|
| 330 | - } |
|
| 318 | + /** |
|
| 319 | + * @PublicPage |
|
| 320 | + * @NoCSRFRequired |
|
| 321 | + * |
|
| 322 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 323 | + */ |
|
| 324 | + public function getLoginBackground() { |
|
| 325 | + try { |
|
| 326 | + /** @var File $file */ |
|
| 327 | + $file = $this->appData->getFolder('images')->getFile('background'); |
|
| 328 | + } catch (NotFoundException $e) { |
|
| 329 | + return new NotFoundResponse(); |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - $response = new FileDisplayResponse($file); |
|
| 333 | - $response->cacheFor(3600); |
|
| 334 | - $expires = new \DateTime(); |
|
| 335 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 336 | - $expires->add(new \DateInterval('PT24H')); |
|
| 337 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 338 | - $response->addHeader('Pragma', 'cache'); |
|
| 339 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', '')); |
|
| 340 | - return $response; |
|
| 341 | - } |
|
| 332 | + $response = new FileDisplayResponse($file); |
|
| 333 | + $response->cacheFor(3600); |
|
| 334 | + $expires = new \DateTime(); |
|
| 335 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 336 | + $expires->add(new \DateInterval('PT24H')); |
|
| 337 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 338 | + $response->addHeader('Pragma', 'cache'); |
|
| 339 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', '')); |
|
| 340 | + return $response; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * @NoCSRFRequired |
|
| 345 | - * @PublicPage |
|
| 346 | - * |
|
| 347 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 348 | - */ |
|
| 349 | - public function getStylesheet() { |
|
| 350 | - $appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1); |
|
| 351 | - /* SCSSCacher is required here |
|
| 343 | + /** |
|
| 344 | + * @NoCSRFRequired |
|
| 345 | + * @PublicPage |
|
| 346 | + * |
|
| 347 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 348 | + */ |
|
| 349 | + public function getStylesheet() { |
|
| 350 | + $appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1); |
|
| 351 | + /* SCSSCacher is required here |
|
| 352 | 352 | * We cannot rely on automatic caching done by \OC_Util::addStyle, |
| 353 | 353 | * since we need to add the cacheBuster value to the url |
| 354 | 354 | */ |
| 355 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming'); |
|
| 356 | - if(!$cssCached) { |
|
| 357 | - return new NotFoundResponse(); |
|
| 358 | - } |
|
| 355 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming'); |
|
| 356 | + if(!$cssCached) { |
|
| 357 | + return new NotFoundResponse(); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - try { |
|
| 361 | - $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
| 362 | - $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 363 | - $response->cacheFor(86400); |
|
| 364 | - $expires = new \DateTime(); |
|
| 365 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 366 | - $expires->add(new \DateInterval('PT24H')); |
|
| 367 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 368 | - $response->addHeader('Pragma', 'cache'); |
|
| 369 | - return $response; |
|
| 370 | - } catch (NotFoundException $e) { |
|
| 371 | - return new NotFoundResponse(); |
|
| 372 | - } |
|
| 373 | - } |
|
| 360 | + try { |
|
| 361 | + $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
| 362 | + $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 363 | + $response->cacheFor(86400); |
|
| 364 | + $expires = new \DateTime(); |
|
| 365 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 366 | + $expires->add(new \DateInterval('PT24H')); |
|
| 367 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 368 | + $response->addHeader('Pragma', 'cache'); |
|
| 369 | + return $response; |
|
| 370 | + } catch (NotFoundException $e) { |
|
| 371 | + return new NotFoundResponse(); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * @NoCSRFRequired |
|
| 377 | - * @PublicPage |
|
| 378 | - * |
|
| 379 | - * @return DataDownloadResponse |
|
| 380 | - */ |
|
| 381 | - public function getJavascript() { |
|
| 382 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 383 | - $responseJS = '(function() { |
|
| 375 | + /** |
|
| 376 | + * @NoCSRFRequired |
|
| 377 | + * @PublicPage |
|
| 378 | + * |
|
| 379 | + * @return DataDownloadResponse |
|
| 380 | + */ |
|
| 381 | + public function getJavascript() { |
|
| 382 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 383 | + $responseJS = '(function() { |
|
| 384 | 384 | OCA.Theming = { |
| 385 | 385 | name: ' . json_encode($this->themingDefaults->getName()) . ', |
| 386 | 386 | url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
@@ -390,10 +390,10 @@ discard block |
||
| 390 | 390 | cacheBuster: ' . json_encode($cacheBusterValue) . ' |
| 391 | 391 | }; |
| 392 | 392 | })();'; |
| 393 | - $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
| 394 | - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
| 395 | - $response->addHeader('Pragma', 'cache'); |
|
| 396 | - $response->cacheFor(3600); |
|
| 397 | - return $response; |
|
| 398 | - } |
|
| 393 | + $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
| 394 | + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
| 395 | + $response->addHeader('Pragma', 'cache'); |
|
| 396 | + $response->cacheFor(3600); |
|
| 397 | + return $response; |
|
| 398 | + } |
|
| 399 | 399 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | public function undo($setting) { |
| 262 | 262 | $value = $this->themingDefaults->undo($setting); |
| 263 | 263 | |
| 264 | - if($setting === 'logoMime') { |
|
| 264 | + if ($setting === 'logoMime') { |
|
| 265 | 265 | try { |
| 266 | 266 | $file = $this->appData->getFolder('images')->getFile('logo'); |
| 267 | 267 | $file->delete(); |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | } catch (NotPermittedException $e) { |
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | - if($setting === 'backgroundMime') { |
|
| 272 | + if ($setting === 'backgroundMime') { |
|
| 273 | 273 | try { |
| 274 | 274 | $file = $this->appData->getFolder('images')->getFile('background'); |
| 275 | 275 | $file->delete(); |
@@ -352,8 +352,8 @@ discard block |
||
| 352 | 352 | * We cannot rely on automatic caching done by \OC_Util::addStyle, |
| 353 | 353 | * since we need to add the cacheBuster value to the url |
| 354 | 354 | */ |
| 355 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming'); |
|
| 356 | - if(!$cssCached) { |
|
| 355 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath.'/css/theming.scss', 'theming'); |
|
| 356 | + if (!$cssCached) { |
|
| 357 | 357 | return new NotFoundResponse(); |
| 358 | 358 | } |
| 359 | 359 | |
@@ -382,12 +382,12 @@ discard block |
||
| 382 | 382 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
| 383 | 383 | $responseJS = '(function() { |
| 384 | 384 | OCA.Theming = { |
| 385 | - name: ' . json_encode($this->themingDefaults->getName()) . ', |
|
| 386 | - url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
|
| 387 | - slogan: ' . json_encode($this->themingDefaults->getSlogan()) . ', |
|
| 388 | - color: ' . json_encode($this->themingDefaults->getColorPrimary()) . ', |
|
| 389 | - inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())) . ', |
|
| 390 | - cacheBuster: ' . json_encode($cacheBusterValue) . ' |
|
| 385 | + name: ' . json_encode($this->themingDefaults->getName()).', |
|
| 386 | + url: ' . json_encode($this->themingDefaults->getBaseUrl()).', |
|
| 387 | + slogan: ' . json_encode($this->themingDefaults->getSlogan()).', |
|
| 388 | + color: ' . json_encode($this->themingDefaults->getColorPrimary()).', |
|
| 389 | + inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())).', |
|
| 390 | + cacheBuster: ' . json_encode($cacheBusterValue).' |
|
| 391 | 391 | }; |
| 392 | 392 | })();'; |
| 393 | 393 | $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |