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