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