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