@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * @since 6.0.0 - return value was added in 7.0.0 |
| 97 | 97 | */ |
| 98 | 98 | public function cacheFor(int $cacheSeconds) { |
| 99 | - if($cacheSeconds > 0) { |
|
| 100 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
| 99 | + if ($cacheSeconds > 0) { |
|
| 100 | + $this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate'); |
|
| 101 | 101 | |
| 102 | 102 | // Old scool prama caching |
| 103 | 103 | $this->addHeader('Pragma', 'public'); |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @since 8.0.0 |
| 162 | 162 | */ |
| 163 | 163 | public function invalidateCookies(array $cookieNames) { |
| 164 | - foreach($cookieNames as $cookieName) { |
|
| 164 | + foreach ($cookieNames as $cookieName) { |
|
| 165 | 165 | $this->invalidateCookie($cookieName); |
| 166 | 166 | } |
| 167 | 167 | return $this; |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | * @since 6.0.0 - return value was added in 7.0.0 |
| 186 | 186 | */ |
| 187 | 187 | public function addHeader($name, $value) { |
| 188 | - $name = trim($name); // always remove leading and trailing whitespace |
|
| 188 | + $name = trim($name); // always remove leading and trailing whitespace |
|
| 189 | 189 | // to be able to reliably check for security |
| 190 | 190 | // headers |
| 191 | 191 | |
| 192 | - if(is_null($value)) { |
|
| 192 | + if (is_null($value)) { |
|
| 193 | 193 | unset($this->headers[$name]); |
| 194 | 194 | } else { |
| 195 | 195 | $this->headers[$name] = $value; |
@@ -220,19 +220,19 @@ discard block |
||
| 220 | 220 | public function getHeaders() { |
| 221 | 221 | $mergeWith = []; |
| 222 | 222 | |
| 223 | - if($this->lastModified) { |
|
| 223 | + if ($this->lastModified) { |
|
| 224 | 224 | $mergeWith['Last-Modified'] = |
| 225 | 225 | $this->lastModified->format(\DateTime::RFC2822); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // Build Content-Security-Policy and use default if none has been specified |
| 229 | - if(is_null($this->contentSecurityPolicy)) { |
|
| 229 | + if (is_null($this->contentSecurityPolicy)) { |
|
| 230 | 230 | $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
| 231 | 231 | } |
| 232 | 232 | $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
| 233 | 233 | |
| 234 | - if($this->ETag) { |
|
| 235 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
| 234 | + if ($this->ETag) { |
|
| 235 | + $mergeWith['ETag'] = '"'.$this->ETag.'"'; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | return array_merge($mergeWith, $this->headers); |
@@ -45,329 +45,329 @@ |
||
| 45 | 45 | */ |
| 46 | 46 | class Response { |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - private $headers = array( |
|
| 53 | - 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Cookies that will be need to be constructed as header |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - private $cookies = array(); |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * HTTP status code - defaults to STATUS OK |
|
| 66 | - * @var int |
|
| 67 | - */ |
|
| 68 | - private $status = Http::STATUS_OK; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Last modified date |
|
| 73 | - * @var \DateTime |
|
| 74 | - */ |
|
| 75 | - private $lastModified; |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * ETag |
|
| 80 | - * @var string |
|
| 81 | - */ |
|
| 82 | - private $ETag; |
|
| 83 | - |
|
| 84 | - /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
| 85 | - private $contentSecurityPolicy = null; |
|
| 86 | - |
|
| 87 | - /** @var bool */ |
|
| 88 | - private $throttled = false; |
|
| 89 | - /** @var array */ |
|
| 90 | - private $throttleMetadata = []; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Caches the response |
|
| 94 | - * @param int $cacheSeconds the amount of seconds that should be cached |
|
| 95 | - * if 0 then caching will be disabled |
|
| 96 | - * @return $this |
|
| 97 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 98 | - */ |
|
| 99 | - public function cacheFor(int $cacheSeconds) { |
|
| 100 | - if($cacheSeconds > 0) { |
|
| 101 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
| 102 | - |
|
| 103 | - // Old scool prama caching |
|
| 104 | - $this->addHeader('Pragma', 'public'); |
|
| 105 | - |
|
| 106 | - // Set expires header |
|
| 107 | - $expires = new \DateTime(); |
|
| 108 | - /** @var ITimeFactory $time */ |
|
| 109 | - $time = \OC::$server->query(ITimeFactory::class); |
|
| 110 | - $expires->setTimestamp($time->getTime()); |
|
| 111 | - $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); |
|
| 112 | - $this->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 113 | - } else { |
|
| 114 | - $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
| 115 | - unset($this->headers['Expires'], $this->headers['Pragma']); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return $this; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Adds a new cookie to the response |
|
| 123 | - * @param string $name The name of the cookie |
|
| 124 | - * @param string $value The value of the cookie |
|
| 125 | - * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
| 126 | - * to null cookie will be considered as session |
|
| 127 | - * cookie. |
|
| 128 | - * @return $this |
|
| 129 | - * @since 8.0.0 |
|
| 130 | - */ |
|
| 131 | - public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
| 132 | - $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
| 133 | - return $this; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Set the specified cookies |
|
| 139 | - * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
| 140 | - * @return $this |
|
| 141 | - * @since 8.0.0 |
|
| 142 | - */ |
|
| 143 | - public function setCookies(array $cookies) { |
|
| 144 | - $this->cookies = $cookies; |
|
| 145 | - return $this; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Invalidates the specified cookie |
|
| 151 | - * @param string $name |
|
| 152 | - * @return $this |
|
| 153 | - * @since 8.0.0 |
|
| 154 | - */ |
|
| 155 | - public function invalidateCookie($name) { |
|
| 156 | - $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
| 157 | - return $this; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Invalidates the specified cookies |
|
| 162 | - * @param array $cookieNames array('foo', 'bar') |
|
| 163 | - * @return $this |
|
| 164 | - * @since 8.0.0 |
|
| 165 | - */ |
|
| 166 | - public function invalidateCookies(array $cookieNames) { |
|
| 167 | - foreach($cookieNames as $cookieName) { |
|
| 168 | - $this->invalidateCookie($cookieName); |
|
| 169 | - } |
|
| 170 | - return $this; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Returns the cookies |
|
| 175 | - * @return array |
|
| 176 | - * @since 8.0.0 |
|
| 177 | - */ |
|
| 178 | - public function getCookies() { |
|
| 179 | - return $this->cookies; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Adds a new header to the response that will be called before the render |
|
| 184 | - * function |
|
| 185 | - * @param string $name The name of the HTTP header |
|
| 186 | - * @param string $value The value, null will delete it |
|
| 187 | - * @return $this |
|
| 188 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 189 | - */ |
|
| 190 | - public function addHeader($name, $value) { |
|
| 191 | - $name = trim($name); // always remove leading and trailing whitespace |
|
| 192 | - // to be able to reliably check for security |
|
| 193 | - // headers |
|
| 194 | - |
|
| 195 | - if(is_null($value)) { |
|
| 196 | - unset($this->headers[$name]); |
|
| 197 | - } else { |
|
| 198 | - $this->headers[$name] = $value; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $this; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Set the headers |
|
| 207 | - * @param array $headers value header pairs |
|
| 208 | - * @return $this |
|
| 209 | - * @since 8.0.0 |
|
| 210 | - */ |
|
| 211 | - public function setHeaders(array $headers) { |
|
| 212 | - $this->headers = $headers; |
|
| 213 | - |
|
| 214 | - return $this; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Returns the set headers |
|
| 220 | - * @return array the headers |
|
| 221 | - * @since 6.0.0 |
|
| 222 | - */ |
|
| 223 | - public function getHeaders() { |
|
| 224 | - $mergeWith = []; |
|
| 225 | - |
|
| 226 | - if($this->lastModified) { |
|
| 227 | - $mergeWith['Last-Modified'] = |
|
| 228 | - $this->lastModified->format(\DateTime::RFC2822); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Build Content-Security-Policy and use default if none has been specified |
|
| 232 | - if(is_null($this->contentSecurityPolicy)) { |
|
| 233 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
| 234 | - } |
|
| 235 | - $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
| 236 | - |
|
| 237 | - if($this->ETag) { |
|
| 238 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - return array_merge($mergeWith, $this->headers); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * By default renders no output |
|
| 247 | - * @return string |
|
| 248 | - * @since 6.0.0 |
|
| 249 | - */ |
|
| 250 | - public function render() { |
|
| 251 | - return ''; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Set response status |
|
| 257 | - * @param int $status a HTTP status code, see also the STATUS constants |
|
| 258 | - * @return Response Reference to this object |
|
| 259 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 260 | - */ |
|
| 261 | - public function setStatus($status) { |
|
| 262 | - $this->status = $status; |
|
| 263 | - |
|
| 264 | - return $this; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Set a Content-Security-Policy |
|
| 269 | - * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
| 270 | - * @return $this |
|
| 271 | - * @since 8.1.0 |
|
| 272 | - */ |
|
| 273 | - public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
| 274 | - $this->contentSecurityPolicy = $csp; |
|
| 275 | - return $this; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Get the currently used Content-Security-Policy |
|
| 280 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
| 281 | - * none specified. |
|
| 282 | - * @since 8.1.0 |
|
| 283 | - */ |
|
| 284 | - public function getContentSecurityPolicy() { |
|
| 285 | - return $this->contentSecurityPolicy; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Get response status |
|
| 291 | - * @since 6.0.0 |
|
| 292 | - */ |
|
| 293 | - public function getStatus() { |
|
| 294 | - return $this->status; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Get the ETag |
|
| 300 | - * @return string the etag |
|
| 301 | - * @since 6.0.0 |
|
| 302 | - */ |
|
| 303 | - public function getETag() { |
|
| 304 | - return $this->ETag; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Get "last modified" date |
|
| 310 | - * @return \DateTime RFC2822 formatted last modified date |
|
| 311 | - * @since 6.0.0 |
|
| 312 | - */ |
|
| 313 | - public function getLastModified() { |
|
| 314 | - return $this->lastModified; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Set the ETag |
|
| 320 | - * @param string $ETag |
|
| 321 | - * @return Response Reference to this object |
|
| 322 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 323 | - */ |
|
| 324 | - public function setETag($ETag) { |
|
| 325 | - $this->ETag = $ETag; |
|
| 326 | - |
|
| 327 | - return $this; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Set "last modified" date |
|
| 333 | - * @param \DateTime $lastModified |
|
| 334 | - * @return Response Reference to this object |
|
| 335 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 336 | - */ |
|
| 337 | - public function setLastModified($lastModified) { |
|
| 338 | - $this->lastModified = $lastModified; |
|
| 339 | - |
|
| 340 | - return $this; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Marks the response as to throttle. Will be throttled when the |
|
| 345 | - * @BruteForceProtection annotation is added. |
|
| 346 | - * |
|
| 347 | - * @param array $metadata |
|
| 348 | - * @since 12.0.0 |
|
| 349 | - */ |
|
| 350 | - public function throttle(array $metadata = []) { |
|
| 351 | - $this->throttled = true; |
|
| 352 | - $this->throttleMetadata = $metadata; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Returns the throttle metadata, defaults to empty array |
|
| 357 | - * |
|
| 358 | - * @return array |
|
| 359 | - * @since 13.0.0 |
|
| 360 | - */ |
|
| 361 | - public function getThrottleMetadata() { |
|
| 362 | - return $this->throttleMetadata; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Whether the current response is throttled. |
|
| 367 | - * |
|
| 368 | - * @since 12.0.0 |
|
| 369 | - */ |
|
| 370 | - public function isThrottled() { |
|
| 371 | - return $this->throttled; |
|
| 372 | - } |
|
| 48 | + /** |
|
| 49 | + * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + private $headers = array( |
|
| 53 | + 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Cookies that will be need to be constructed as header |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + private $cookies = array(); |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * HTTP status code - defaults to STATUS OK |
|
| 66 | + * @var int |
|
| 67 | + */ |
|
| 68 | + private $status = Http::STATUS_OK; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Last modified date |
|
| 73 | + * @var \DateTime |
|
| 74 | + */ |
|
| 75 | + private $lastModified; |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * ETag |
|
| 80 | + * @var string |
|
| 81 | + */ |
|
| 82 | + private $ETag; |
|
| 83 | + |
|
| 84 | + /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
| 85 | + private $contentSecurityPolicy = null; |
|
| 86 | + |
|
| 87 | + /** @var bool */ |
|
| 88 | + private $throttled = false; |
|
| 89 | + /** @var array */ |
|
| 90 | + private $throttleMetadata = []; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Caches the response |
|
| 94 | + * @param int $cacheSeconds the amount of seconds that should be cached |
|
| 95 | + * if 0 then caching will be disabled |
|
| 96 | + * @return $this |
|
| 97 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 98 | + */ |
|
| 99 | + public function cacheFor(int $cacheSeconds) { |
|
| 100 | + if($cacheSeconds > 0) { |
|
| 101 | + $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
| 102 | + |
|
| 103 | + // Old scool prama caching |
|
| 104 | + $this->addHeader('Pragma', 'public'); |
|
| 105 | + |
|
| 106 | + // Set expires header |
|
| 107 | + $expires = new \DateTime(); |
|
| 108 | + /** @var ITimeFactory $time */ |
|
| 109 | + $time = \OC::$server->query(ITimeFactory::class); |
|
| 110 | + $expires->setTimestamp($time->getTime()); |
|
| 111 | + $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); |
|
| 112 | + $this->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 113 | + } else { |
|
| 114 | + $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
| 115 | + unset($this->headers['Expires'], $this->headers['Pragma']); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return $this; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Adds a new cookie to the response |
|
| 123 | + * @param string $name The name of the cookie |
|
| 124 | + * @param string $value The value of the cookie |
|
| 125 | + * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
| 126 | + * to null cookie will be considered as session |
|
| 127 | + * cookie. |
|
| 128 | + * @return $this |
|
| 129 | + * @since 8.0.0 |
|
| 130 | + */ |
|
| 131 | + public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
| 132 | + $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
| 133 | + return $this; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Set the specified cookies |
|
| 139 | + * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
| 140 | + * @return $this |
|
| 141 | + * @since 8.0.0 |
|
| 142 | + */ |
|
| 143 | + public function setCookies(array $cookies) { |
|
| 144 | + $this->cookies = $cookies; |
|
| 145 | + return $this; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Invalidates the specified cookie |
|
| 151 | + * @param string $name |
|
| 152 | + * @return $this |
|
| 153 | + * @since 8.0.0 |
|
| 154 | + */ |
|
| 155 | + public function invalidateCookie($name) { |
|
| 156 | + $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
| 157 | + return $this; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Invalidates the specified cookies |
|
| 162 | + * @param array $cookieNames array('foo', 'bar') |
|
| 163 | + * @return $this |
|
| 164 | + * @since 8.0.0 |
|
| 165 | + */ |
|
| 166 | + public function invalidateCookies(array $cookieNames) { |
|
| 167 | + foreach($cookieNames as $cookieName) { |
|
| 168 | + $this->invalidateCookie($cookieName); |
|
| 169 | + } |
|
| 170 | + return $this; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Returns the cookies |
|
| 175 | + * @return array |
|
| 176 | + * @since 8.0.0 |
|
| 177 | + */ |
|
| 178 | + public function getCookies() { |
|
| 179 | + return $this->cookies; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Adds a new header to the response that will be called before the render |
|
| 184 | + * function |
|
| 185 | + * @param string $name The name of the HTTP header |
|
| 186 | + * @param string $value The value, null will delete it |
|
| 187 | + * @return $this |
|
| 188 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 189 | + */ |
|
| 190 | + public function addHeader($name, $value) { |
|
| 191 | + $name = trim($name); // always remove leading and trailing whitespace |
|
| 192 | + // to be able to reliably check for security |
|
| 193 | + // headers |
|
| 194 | + |
|
| 195 | + if(is_null($value)) { |
|
| 196 | + unset($this->headers[$name]); |
|
| 197 | + } else { |
|
| 198 | + $this->headers[$name] = $value; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $this; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Set the headers |
|
| 207 | + * @param array $headers value header pairs |
|
| 208 | + * @return $this |
|
| 209 | + * @since 8.0.0 |
|
| 210 | + */ |
|
| 211 | + public function setHeaders(array $headers) { |
|
| 212 | + $this->headers = $headers; |
|
| 213 | + |
|
| 214 | + return $this; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Returns the set headers |
|
| 220 | + * @return array the headers |
|
| 221 | + * @since 6.0.0 |
|
| 222 | + */ |
|
| 223 | + public function getHeaders() { |
|
| 224 | + $mergeWith = []; |
|
| 225 | + |
|
| 226 | + if($this->lastModified) { |
|
| 227 | + $mergeWith['Last-Modified'] = |
|
| 228 | + $this->lastModified->format(\DateTime::RFC2822); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Build Content-Security-Policy and use default if none has been specified |
|
| 232 | + if(is_null($this->contentSecurityPolicy)) { |
|
| 233 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
| 234 | + } |
|
| 235 | + $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
| 236 | + |
|
| 237 | + if($this->ETag) { |
|
| 238 | + $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + return array_merge($mergeWith, $this->headers); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * By default renders no output |
|
| 247 | + * @return string |
|
| 248 | + * @since 6.0.0 |
|
| 249 | + */ |
|
| 250 | + public function render() { |
|
| 251 | + return ''; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Set response status |
|
| 257 | + * @param int $status a HTTP status code, see also the STATUS constants |
|
| 258 | + * @return Response Reference to this object |
|
| 259 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 260 | + */ |
|
| 261 | + public function setStatus($status) { |
|
| 262 | + $this->status = $status; |
|
| 263 | + |
|
| 264 | + return $this; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Set a Content-Security-Policy |
|
| 269 | + * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
| 270 | + * @return $this |
|
| 271 | + * @since 8.1.0 |
|
| 272 | + */ |
|
| 273 | + public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
| 274 | + $this->contentSecurityPolicy = $csp; |
|
| 275 | + return $this; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Get the currently used Content-Security-Policy |
|
| 280 | + * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
| 281 | + * none specified. |
|
| 282 | + * @since 8.1.0 |
|
| 283 | + */ |
|
| 284 | + public function getContentSecurityPolicy() { |
|
| 285 | + return $this->contentSecurityPolicy; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Get response status |
|
| 291 | + * @since 6.0.0 |
|
| 292 | + */ |
|
| 293 | + public function getStatus() { |
|
| 294 | + return $this->status; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Get the ETag |
|
| 300 | + * @return string the etag |
|
| 301 | + * @since 6.0.0 |
|
| 302 | + */ |
|
| 303 | + public function getETag() { |
|
| 304 | + return $this->ETag; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Get "last modified" date |
|
| 310 | + * @return \DateTime RFC2822 formatted last modified date |
|
| 311 | + * @since 6.0.0 |
|
| 312 | + */ |
|
| 313 | + public function getLastModified() { |
|
| 314 | + return $this->lastModified; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Set the ETag |
|
| 320 | + * @param string $ETag |
|
| 321 | + * @return Response Reference to this object |
|
| 322 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 323 | + */ |
|
| 324 | + public function setETag($ETag) { |
|
| 325 | + $this->ETag = $ETag; |
|
| 326 | + |
|
| 327 | + return $this; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Set "last modified" date |
|
| 333 | + * @param \DateTime $lastModified |
|
| 334 | + * @return Response Reference to this object |
|
| 335 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 336 | + */ |
|
| 337 | + public function setLastModified($lastModified) { |
|
| 338 | + $this->lastModified = $lastModified; |
|
| 339 | + |
|
| 340 | + return $this; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Marks the response as to throttle. Will be throttled when the |
|
| 345 | + * @BruteForceProtection annotation is added. |
|
| 346 | + * |
|
| 347 | + * @param array $metadata |
|
| 348 | + * @since 12.0.0 |
|
| 349 | + */ |
|
| 350 | + public function throttle(array $metadata = []) { |
|
| 351 | + $this->throttled = true; |
|
| 352 | + $this->throttleMetadata = $metadata; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Returns the throttle metadata, defaults to empty array |
|
| 357 | + * |
|
| 358 | + * @return array |
|
| 359 | + * @since 13.0.0 |
|
| 360 | + */ |
|
| 361 | + public function getThrottleMetadata() { |
|
| 362 | + return $this->throttleMetadata; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Whether the current response is throttled. |
|
| 367 | + * |
|
| 368 | + * @since 12.0.0 |
|
| 369 | + */ |
|
| 370 | + public function isThrottled() { |
|
| 371 | + return $this->throttled; |
|
| 372 | + } |
|
| 373 | 373 | } |
@@ -49,286 +49,286 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | class AvatarController extends Controller { |
| 51 | 51 | |
| 52 | - /** @var IAvatarManager */ |
|
| 53 | - protected $avatarManager; |
|
| 54 | - |
|
| 55 | - /** @var ICache */ |
|
| 56 | - protected $cache; |
|
| 57 | - |
|
| 58 | - /** @var IL10N */ |
|
| 59 | - protected $l; |
|
| 60 | - |
|
| 61 | - /** @var IUserManager */ |
|
| 62 | - protected $userManager; |
|
| 63 | - |
|
| 64 | - /** @var IUserSession */ |
|
| 65 | - protected $userSession; |
|
| 66 | - |
|
| 67 | - /** @var IRootFolder */ |
|
| 68 | - protected $rootFolder; |
|
| 69 | - |
|
| 70 | - /** @var ILogger */ |
|
| 71 | - protected $logger; |
|
| 72 | - |
|
| 73 | - /** @var string */ |
|
| 74 | - protected $userId; |
|
| 75 | - |
|
| 76 | - /** @var TimeFactory */ |
|
| 77 | - protected $timeFactory; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param string $appName |
|
| 81 | - * @param IRequest $request |
|
| 82 | - * @param IAvatarManager $avatarManager |
|
| 83 | - * @param ICache $cache |
|
| 84 | - * @param IL10N $l10n |
|
| 85 | - * @param IUserManager $userManager |
|
| 86 | - * @param IRootFolder $rootFolder |
|
| 87 | - * @param ILogger $logger |
|
| 88 | - * @param string $userId |
|
| 89 | - * @param TimeFactory $timeFactory |
|
| 90 | - */ |
|
| 91 | - public function __construct($appName, |
|
| 92 | - IRequest $request, |
|
| 93 | - IAvatarManager $avatarManager, |
|
| 94 | - ICache $cache, |
|
| 95 | - IL10N $l10n, |
|
| 96 | - IUserManager $userManager, |
|
| 97 | - IRootFolder $rootFolder, |
|
| 98 | - ILogger $logger, |
|
| 99 | - $userId, |
|
| 100 | - TimeFactory $timeFactory) { |
|
| 101 | - parent::__construct($appName, $request); |
|
| 102 | - |
|
| 103 | - $this->avatarManager = $avatarManager; |
|
| 104 | - $this->cache = $cache; |
|
| 105 | - $this->l = $l10n; |
|
| 106 | - $this->userManager = $userManager; |
|
| 107 | - $this->rootFolder = $rootFolder; |
|
| 108 | - $this->logger = $logger; |
|
| 109 | - $this->userId = $userId; |
|
| 110 | - $this->timeFactory = $timeFactory; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @NoAdminRequired |
|
| 118 | - * @NoCSRFRequired |
|
| 119 | - * @NoSameSiteCookieRequired |
|
| 120 | - * @PublicPage |
|
| 121 | - * |
|
| 122 | - * @param string $userId |
|
| 123 | - * @param int $size |
|
| 124 | - * @return JSONResponse|FileDisplayResponse |
|
| 125 | - */ |
|
| 126 | - public function getAvatar($userId, $size) { |
|
| 127 | - if ($size > 2048) { |
|
| 128 | - $size = 2048; |
|
| 129 | - } elseif ($size <= 0) { |
|
| 130 | - $size = 64; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - try { |
|
| 134 | - $avatar = $this->avatarManager->getAvatar($userId)->getFile($size); |
|
| 135 | - $resp = new FileDisplayResponse($avatar, |
|
| 136 | - Http::STATUS_OK, |
|
| 137 | - ['Content-Type' => $avatar->getMimeType()]); |
|
| 138 | - } catch (\Exception $e) { |
|
| 139 | - $resp = new Http\Response(); |
|
| 140 | - $resp->setStatus(Http::STATUS_NOT_FOUND); |
|
| 141 | - return $resp; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // Cache for 30 minutes |
|
| 145 | - $resp->cacheFor(1800); |
|
| 146 | - return $resp; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @NoAdminRequired |
|
| 151 | - * |
|
| 152 | - * @param string $path |
|
| 153 | - * @return JSONResponse |
|
| 154 | - */ |
|
| 155 | - public function postAvatar($path) { |
|
| 156 | - $files = $this->request->getUploadedFile('files'); |
|
| 157 | - |
|
| 158 | - if (isset($path)) { |
|
| 159 | - $path = stripslashes($path); |
|
| 160 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 161 | - /** @var File $node */ |
|
| 162 | - $node = $userFolder->get($path); |
|
| 163 | - if (!($node instanceof File)) { |
|
| 164 | - return new JSONResponse(['data' => ['message' => $this->l->t('Please select a file.')]]); |
|
| 165 | - } |
|
| 166 | - if ($node->getSize() > 20*1024*1024) { |
|
| 167 | - return new JSONResponse( |
|
| 168 | - ['data' => ['message' => $this->l->t('File is too big')]], |
|
| 169 | - Http::STATUS_BAD_REQUEST |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if ($node->getMimeType() !== 'image/jpeg' && $node->getMimeType() !== 'image/png') { |
|
| 174 | - return new JSONResponse( |
|
| 175 | - ['data' => ['message' => $this->l->t('The selected file is not an image.')]], |
|
| 176 | - Http::STATUS_BAD_REQUEST |
|
| 177 | - ); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - try { |
|
| 181 | - $content = $node->getContent(); |
|
| 182 | - } catch (\OCP\Files\NotPermittedException $e) { |
|
| 183 | - return new JSONResponse( |
|
| 184 | - ['data' => ['message' => $this->l->t('The selected file cannot be read.')]], |
|
| 185 | - Http::STATUS_BAD_REQUEST |
|
| 186 | - ); |
|
| 187 | - } |
|
| 188 | - } elseif (!is_null($files)) { |
|
| 189 | - if ( |
|
| 190 | - $files['error'][0] === 0 && |
|
| 191 | - is_uploaded_file($files['tmp_name'][0]) && |
|
| 192 | - !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0]) |
|
| 193 | - ) { |
|
| 194 | - if ($files['size'][0] > 20*1024*1024) { |
|
| 195 | - return new JSONResponse( |
|
| 196 | - ['data' => ['message' => $this->l->t('File is too big')]], |
|
| 197 | - Http::STATUS_BAD_REQUEST |
|
| 198 | - ); |
|
| 199 | - } |
|
| 200 | - $this->cache->set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200); |
|
| 201 | - $content = $this->cache->get('avatar_upload'); |
|
| 202 | - unlink($files['tmp_name'][0]); |
|
| 203 | - } else { |
|
| 204 | - return new JSONResponse( |
|
| 205 | - ['data' => ['message' => $this->l->t('Invalid file provided')]], |
|
| 206 | - Http::STATUS_BAD_REQUEST |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - } else { |
|
| 210 | - //Add imgfile |
|
| 211 | - return new JSONResponse( |
|
| 212 | - ['data' => ['message' => $this->l->t('No image or file provided')]], |
|
| 213 | - Http::STATUS_BAD_REQUEST |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - try { |
|
| 218 | - $image = new \OC_Image(); |
|
| 219 | - $image->loadFromData($content); |
|
| 220 | - $image->readExif($content); |
|
| 221 | - $image->fixOrientation(); |
|
| 222 | - |
|
| 223 | - if ($image->valid()) { |
|
| 224 | - $mimeType = $image->mimeType(); |
|
| 225 | - if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') { |
|
| 226 | - return new JSONResponse( |
|
| 227 | - ['data' => ['message' => $this->l->t('Unknown filetype')]], |
|
| 228 | - Http::STATUS_OK |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - $this->cache->set('tmpAvatar', $image->data(), 7200); |
|
| 233 | - return new JSONResponse( |
|
| 234 | - ['data' => 'notsquare'], |
|
| 235 | - Http::STATUS_OK |
|
| 236 | - ); |
|
| 237 | - } else { |
|
| 238 | - return new JSONResponse( |
|
| 239 | - ['data' => ['message' => $this->l->t('Invalid image')]], |
|
| 240 | - Http::STATUS_OK |
|
| 241 | - ); |
|
| 242 | - } |
|
| 243 | - } catch (\Exception $e) { |
|
| 244 | - $this->logger->logException($e, ['app' => 'core']); |
|
| 245 | - return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_OK); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @NoAdminRequired |
|
| 52 | + /** @var IAvatarManager */ |
|
| 53 | + protected $avatarManager; |
|
| 54 | + |
|
| 55 | + /** @var ICache */ |
|
| 56 | + protected $cache; |
|
| 57 | + |
|
| 58 | + /** @var IL10N */ |
|
| 59 | + protected $l; |
|
| 60 | + |
|
| 61 | + /** @var IUserManager */ |
|
| 62 | + protected $userManager; |
|
| 63 | + |
|
| 64 | + /** @var IUserSession */ |
|
| 65 | + protected $userSession; |
|
| 66 | + |
|
| 67 | + /** @var IRootFolder */ |
|
| 68 | + protected $rootFolder; |
|
| 69 | + |
|
| 70 | + /** @var ILogger */ |
|
| 71 | + protected $logger; |
|
| 72 | + |
|
| 73 | + /** @var string */ |
|
| 74 | + protected $userId; |
|
| 75 | + |
|
| 76 | + /** @var TimeFactory */ |
|
| 77 | + protected $timeFactory; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param string $appName |
|
| 81 | + * @param IRequest $request |
|
| 82 | + * @param IAvatarManager $avatarManager |
|
| 83 | + * @param ICache $cache |
|
| 84 | + * @param IL10N $l10n |
|
| 85 | + * @param IUserManager $userManager |
|
| 86 | + * @param IRootFolder $rootFolder |
|
| 87 | + * @param ILogger $logger |
|
| 88 | + * @param string $userId |
|
| 89 | + * @param TimeFactory $timeFactory |
|
| 90 | + */ |
|
| 91 | + public function __construct($appName, |
|
| 92 | + IRequest $request, |
|
| 93 | + IAvatarManager $avatarManager, |
|
| 94 | + ICache $cache, |
|
| 95 | + IL10N $l10n, |
|
| 96 | + IUserManager $userManager, |
|
| 97 | + IRootFolder $rootFolder, |
|
| 98 | + ILogger $logger, |
|
| 99 | + $userId, |
|
| 100 | + TimeFactory $timeFactory) { |
|
| 101 | + parent::__construct($appName, $request); |
|
| 102 | + |
|
| 103 | + $this->avatarManager = $avatarManager; |
|
| 104 | + $this->cache = $cache; |
|
| 105 | + $this->l = $l10n; |
|
| 106 | + $this->userManager = $userManager; |
|
| 107 | + $this->rootFolder = $rootFolder; |
|
| 108 | + $this->logger = $logger; |
|
| 109 | + $this->userId = $userId; |
|
| 110 | + $this->timeFactory = $timeFactory; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @NoAdminRequired |
|
| 118 | + * @NoCSRFRequired |
|
| 119 | + * @NoSameSiteCookieRequired |
|
| 120 | + * @PublicPage |
|
| 251 | 121 | * |
| 252 | - * @return JSONResponse |
|
| 253 | - */ |
|
| 254 | - public function deleteAvatar() { |
|
| 255 | - try { |
|
| 256 | - $avatar = $this->avatarManager->getAvatar($this->userId); |
|
| 257 | - $avatar->remove(); |
|
| 258 | - return new JSONResponse(); |
|
| 259 | - } catch (\Exception $e) { |
|
| 260 | - $this->logger->logException($e, ['app' => 'core']); |
|
| 261 | - return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @NoAdminRequired |
|
| 267 | - * |
|
| 268 | - * @return JSONResponse|DataDisplayResponse |
|
| 269 | - */ |
|
| 270 | - public function getTmpAvatar() { |
|
| 271 | - $tmpAvatar = $this->cache->get('tmpAvatar'); |
|
| 272 | - if (is_null($tmpAvatar)) { |
|
| 273 | - return new JSONResponse(['data' => [ |
|
| 274 | - 'message' => $this->l->t("No temporary profile picture available, try again") |
|
| 275 | - ]], |
|
| 276 | - Http::STATUS_NOT_FOUND); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $image = new \OC_Image(); |
|
| 280 | - $image->loadFromData($tmpAvatar); |
|
| 281 | - |
|
| 282 | - $resp = new DataDisplayResponse($image->data(), |
|
| 283 | - Http::STATUS_OK, |
|
| 284 | - ['Content-Type' => $image->mimeType()]); |
|
| 285 | - |
|
| 286 | - $resp->setETag((string)crc32($image->data())); |
|
| 287 | - $resp->cacheFor(0); |
|
| 288 | - $resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT'))); |
|
| 289 | - return $resp; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @NoAdminRequired |
|
| 294 | - * |
|
| 295 | - * @param array $crop |
|
| 296 | - * @return JSONResponse |
|
| 297 | - */ |
|
| 298 | - public function postCroppedAvatar($crop) { |
|
| 299 | - if (is_null($crop)) { |
|
| 300 | - return new JSONResponse(['data' => ['message' => $this->l->t("No crop data provided")]], |
|
| 301 | - Http::STATUS_BAD_REQUEST); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if (!isset($crop['x'], $crop['y'], $crop['w'], $crop['h'])) { |
|
| 305 | - return new JSONResponse(['data' => ['message' => $this->l->t("No valid crop data provided")]], |
|
| 306 | - Http::STATUS_BAD_REQUEST); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $tmpAvatar = $this->cache->get('tmpAvatar'); |
|
| 310 | - if (is_null($tmpAvatar)) { |
|
| 311 | - return new JSONResponse(['data' => [ |
|
| 312 | - 'message' => $this->l->t("No temporary profile picture available, try again") |
|
| 313 | - ]], |
|
| 314 | - Http::STATUS_BAD_REQUEST); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - $image = new \OC_Image(); |
|
| 318 | - $image->loadFromData($tmpAvatar); |
|
| 319 | - $image->crop($crop['x'], $crop['y'], (int)round($crop['w']), (int)round($crop['h'])); |
|
| 320 | - try { |
|
| 321 | - $avatar = $this->avatarManager->getAvatar($this->userId); |
|
| 322 | - $avatar->set($image); |
|
| 323 | - // Clean up |
|
| 324 | - $this->cache->remove('tmpAvatar'); |
|
| 325 | - return new JSONResponse(['status' => 'success']); |
|
| 326 | - } catch (\OC\NotSquareException $e) { |
|
| 327 | - return new JSONResponse(['data' => ['message' => $this->l->t('Crop is not square')]], |
|
| 328 | - Http::STATUS_BAD_REQUEST); |
|
| 329 | - } catch (\Exception $e) { |
|
| 330 | - $this->logger->logException($e, ['app' => 'core']); |
|
| 331 | - return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
| 332 | - } |
|
| 333 | - } |
|
| 122 | + * @param string $userId |
|
| 123 | + * @param int $size |
|
| 124 | + * @return JSONResponse|FileDisplayResponse |
|
| 125 | + */ |
|
| 126 | + public function getAvatar($userId, $size) { |
|
| 127 | + if ($size > 2048) { |
|
| 128 | + $size = 2048; |
|
| 129 | + } elseif ($size <= 0) { |
|
| 130 | + $size = 64; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + try { |
|
| 134 | + $avatar = $this->avatarManager->getAvatar($userId)->getFile($size); |
|
| 135 | + $resp = new FileDisplayResponse($avatar, |
|
| 136 | + Http::STATUS_OK, |
|
| 137 | + ['Content-Type' => $avatar->getMimeType()]); |
|
| 138 | + } catch (\Exception $e) { |
|
| 139 | + $resp = new Http\Response(); |
|
| 140 | + $resp->setStatus(Http::STATUS_NOT_FOUND); |
|
| 141 | + return $resp; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // Cache for 30 minutes |
|
| 145 | + $resp->cacheFor(1800); |
|
| 146 | + return $resp; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @NoAdminRequired |
|
| 151 | + * |
|
| 152 | + * @param string $path |
|
| 153 | + * @return JSONResponse |
|
| 154 | + */ |
|
| 155 | + public function postAvatar($path) { |
|
| 156 | + $files = $this->request->getUploadedFile('files'); |
|
| 157 | + |
|
| 158 | + if (isset($path)) { |
|
| 159 | + $path = stripslashes($path); |
|
| 160 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 161 | + /** @var File $node */ |
|
| 162 | + $node = $userFolder->get($path); |
|
| 163 | + if (!($node instanceof File)) { |
|
| 164 | + return new JSONResponse(['data' => ['message' => $this->l->t('Please select a file.')]]); |
|
| 165 | + } |
|
| 166 | + if ($node->getSize() > 20*1024*1024) { |
|
| 167 | + return new JSONResponse( |
|
| 168 | + ['data' => ['message' => $this->l->t('File is too big')]], |
|
| 169 | + Http::STATUS_BAD_REQUEST |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if ($node->getMimeType() !== 'image/jpeg' && $node->getMimeType() !== 'image/png') { |
|
| 174 | + return new JSONResponse( |
|
| 175 | + ['data' => ['message' => $this->l->t('The selected file is not an image.')]], |
|
| 176 | + Http::STATUS_BAD_REQUEST |
|
| 177 | + ); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + try { |
|
| 181 | + $content = $node->getContent(); |
|
| 182 | + } catch (\OCP\Files\NotPermittedException $e) { |
|
| 183 | + return new JSONResponse( |
|
| 184 | + ['data' => ['message' => $this->l->t('The selected file cannot be read.')]], |
|
| 185 | + Http::STATUS_BAD_REQUEST |
|
| 186 | + ); |
|
| 187 | + } |
|
| 188 | + } elseif (!is_null($files)) { |
|
| 189 | + if ( |
|
| 190 | + $files['error'][0] === 0 && |
|
| 191 | + is_uploaded_file($files['tmp_name'][0]) && |
|
| 192 | + !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0]) |
|
| 193 | + ) { |
|
| 194 | + if ($files['size'][0] > 20*1024*1024) { |
|
| 195 | + return new JSONResponse( |
|
| 196 | + ['data' => ['message' => $this->l->t('File is too big')]], |
|
| 197 | + Http::STATUS_BAD_REQUEST |
|
| 198 | + ); |
|
| 199 | + } |
|
| 200 | + $this->cache->set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200); |
|
| 201 | + $content = $this->cache->get('avatar_upload'); |
|
| 202 | + unlink($files['tmp_name'][0]); |
|
| 203 | + } else { |
|
| 204 | + return new JSONResponse( |
|
| 205 | + ['data' => ['message' => $this->l->t('Invalid file provided')]], |
|
| 206 | + Http::STATUS_BAD_REQUEST |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + } else { |
|
| 210 | + //Add imgfile |
|
| 211 | + return new JSONResponse( |
|
| 212 | + ['data' => ['message' => $this->l->t('No image or file provided')]], |
|
| 213 | + Http::STATUS_BAD_REQUEST |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + try { |
|
| 218 | + $image = new \OC_Image(); |
|
| 219 | + $image->loadFromData($content); |
|
| 220 | + $image->readExif($content); |
|
| 221 | + $image->fixOrientation(); |
|
| 222 | + |
|
| 223 | + if ($image->valid()) { |
|
| 224 | + $mimeType = $image->mimeType(); |
|
| 225 | + if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') { |
|
| 226 | + return new JSONResponse( |
|
| 227 | + ['data' => ['message' => $this->l->t('Unknown filetype')]], |
|
| 228 | + Http::STATUS_OK |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + $this->cache->set('tmpAvatar', $image->data(), 7200); |
|
| 233 | + return new JSONResponse( |
|
| 234 | + ['data' => 'notsquare'], |
|
| 235 | + Http::STATUS_OK |
|
| 236 | + ); |
|
| 237 | + } else { |
|
| 238 | + return new JSONResponse( |
|
| 239 | + ['data' => ['message' => $this->l->t('Invalid image')]], |
|
| 240 | + Http::STATUS_OK |
|
| 241 | + ); |
|
| 242 | + } |
|
| 243 | + } catch (\Exception $e) { |
|
| 244 | + $this->logger->logException($e, ['app' => 'core']); |
|
| 245 | + return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_OK); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @NoAdminRequired |
|
| 251 | + * |
|
| 252 | + * @return JSONResponse |
|
| 253 | + */ |
|
| 254 | + public function deleteAvatar() { |
|
| 255 | + try { |
|
| 256 | + $avatar = $this->avatarManager->getAvatar($this->userId); |
|
| 257 | + $avatar->remove(); |
|
| 258 | + return new JSONResponse(); |
|
| 259 | + } catch (\Exception $e) { |
|
| 260 | + $this->logger->logException($e, ['app' => 'core']); |
|
| 261 | + return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @NoAdminRequired |
|
| 267 | + * |
|
| 268 | + * @return JSONResponse|DataDisplayResponse |
|
| 269 | + */ |
|
| 270 | + public function getTmpAvatar() { |
|
| 271 | + $tmpAvatar = $this->cache->get('tmpAvatar'); |
|
| 272 | + if (is_null($tmpAvatar)) { |
|
| 273 | + return new JSONResponse(['data' => [ |
|
| 274 | + 'message' => $this->l->t("No temporary profile picture available, try again") |
|
| 275 | + ]], |
|
| 276 | + Http::STATUS_NOT_FOUND); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $image = new \OC_Image(); |
|
| 280 | + $image->loadFromData($tmpAvatar); |
|
| 281 | + |
|
| 282 | + $resp = new DataDisplayResponse($image->data(), |
|
| 283 | + Http::STATUS_OK, |
|
| 284 | + ['Content-Type' => $image->mimeType()]); |
|
| 285 | + |
|
| 286 | + $resp->setETag((string)crc32($image->data())); |
|
| 287 | + $resp->cacheFor(0); |
|
| 288 | + $resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT'))); |
|
| 289 | + return $resp; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @NoAdminRequired |
|
| 294 | + * |
|
| 295 | + * @param array $crop |
|
| 296 | + * @return JSONResponse |
|
| 297 | + */ |
|
| 298 | + public function postCroppedAvatar($crop) { |
|
| 299 | + if (is_null($crop)) { |
|
| 300 | + return new JSONResponse(['data' => ['message' => $this->l->t("No crop data provided")]], |
|
| 301 | + Http::STATUS_BAD_REQUEST); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if (!isset($crop['x'], $crop['y'], $crop['w'], $crop['h'])) { |
|
| 305 | + return new JSONResponse(['data' => ['message' => $this->l->t("No valid crop data provided")]], |
|
| 306 | + Http::STATUS_BAD_REQUEST); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $tmpAvatar = $this->cache->get('tmpAvatar'); |
|
| 310 | + if (is_null($tmpAvatar)) { |
|
| 311 | + return new JSONResponse(['data' => [ |
|
| 312 | + 'message' => $this->l->t("No temporary profile picture available, try again") |
|
| 313 | + ]], |
|
| 314 | + Http::STATUS_BAD_REQUEST); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + $image = new \OC_Image(); |
|
| 318 | + $image->loadFromData($tmpAvatar); |
|
| 319 | + $image->crop($crop['x'], $crop['y'], (int)round($crop['w']), (int)round($crop['h'])); |
|
| 320 | + try { |
|
| 321 | + $avatar = $this->avatarManager->getAvatar($this->userId); |
|
| 322 | + $avatar->set($image); |
|
| 323 | + // Clean up |
|
| 324 | + $this->cache->remove('tmpAvatar'); |
|
| 325 | + return new JSONResponse(['status' => 'success']); |
|
| 326 | + } catch (\OC\NotSquareException $e) { |
|
| 327 | + return new JSONResponse(['data' => ['message' => $this->l->t('Crop is not square')]], |
|
| 328 | + Http::STATUS_BAD_REQUEST); |
|
| 329 | + } catch (\Exception $e) { |
|
| 330 | + $this->logger->logException($e, ['app' => 'core']); |
|
| 331 | + return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | 334 | } |
@@ -39,148 +39,148 @@ |
||
| 39 | 39 | |
| 40 | 40 | class PreviewController extends Controller { |
| 41 | 41 | |
| 42 | - /** @var string */ |
|
| 43 | - private $userId; |
|
| 44 | - |
|
| 45 | - /** @var IRootFolder */ |
|
| 46 | - private $root; |
|
| 47 | - |
|
| 48 | - /** @var IPreview */ |
|
| 49 | - private $preview; |
|
| 50 | - |
|
| 51 | - /** @var ITimeFactory */ |
|
| 52 | - private $timeFactory; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * PreviewController constructor. |
|
| 56 | - * |
|
| 57 | - * @param string $appName |
|
| 58 | - * @param IRequest $request |
|
| 59 | - * @param IPreview $preview |
|
| 60 | - * @param IRootFolder $root |
|
| 61 | - * @param string $userId |
|
| 62 | - * @param ITimeFactory $timeFactory |
|
| 63 | - */ |
|
| 64 | - public function __construct(string $appName, |
|
| 65 | - IRequest $request, |
|
| 66 | - IPreview $preview, |
|
| 67 | - IRootFolder $root, |
|
| 68 | - string $userId, |
|
| 69 | - ITimeFactory $timeFactory |
|
| 70 | - ) { |
|
| 71 | - parent::__construct($appName, $request); |
|
| 72 | - |
|
| 73 | - $this->preview = $preview; |
|
| 74 | - $this->root = $root; |
|
| 75 | - $this->userId = $userId; |
|
| 76 | - $this->timeFactory = $timeFactory; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @NoAdminRequired |
|
| 81 | - * @NoCSRFRequired |
|
| 82 | - * |
|
| 83 | - * @param string $file |
|
| 84 | - * @param int $x |
|
| 85 | - * @param int $y |
|
| 86 | - * @param bool $a |
|
| 87 | - * @param bool $forceIcon |
|
| 88 | - * @param string $mode |
|
| 89 | - * @return DataResponse|FileDisplayResponse |
|
| 90 | - */ |
|
| 91 | - public function getPreview ( |
|
| 92 | - string $file = '', |
|
| 93 | - int $x = 32, |
|
| 94 | - int $y = 32, |
|
| 95 | - bool $a = false, |
|
| 96 | - bool $forceIcon = true, |
|
| 97 | - string $mode = 'fill'): Http\Response { |
|
| 98 | - |
|
| 99 | - if ($file === '' || $x === 0 || $y === 0) { |
|
| 100 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - try { |
|
| 104 | - $userFolder = $this->root->getUserFolder($this->userId); |
|
| 105 | - $node = $userFolder->get($file); |
|
| 106 | - } catch (NotFoundException $e) { |
|
| 107 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @NoAdminRequired |
|
| 115 | - * @NoCSRFRequired |
|
| 116 | - * |
|
| 117 | - * @param int $fileId |
|
| 118 | - * @param int $x |
|
| 119 | - * @param int $y |
|
| 120 | - * @param bool $a |
|
| 121 | - * @param bool $forceIcon |
|
| 122 | - * @param string $mode |
|
| 123 | - * |
|
| 124 | - * @return DataResponse|FileDisplayResponse |
|
| 125 | - */ |
|
| 126 | - public function getPreviewByFileId( |
|
| 127 | - int $fileId = -1, |
|
| 128 | - int $x = 32, |
|
| 129 | - int $y = 32, |
|
| 130 | - bool $a = false, |
|
| 131 | - bool $forceIcon = true, |
|
| 132 | - string $mode = 'fill') { |
|
| 133 | - |
|
| 134 | - if ($fileId === -1 || $x === 0 || $y === 0) { |
|
| 135 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $userFolder = $this->root->getUserFolder($this->userId); |
|
| 139 | - $nodes = $userFolder->getById($fileId); |
|
| 140 | - |
|
| 141 | - if (\count($nodes) === 0) { |
|
| 142 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $node = array_pop($nodes); |
|
| 146 | - |
|
| 147 | - return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param Node $node |
|
| 152 | - * @param int $x |
|
| 153 | - * @param int $y |
|
| 154 | - * @param bool $a |
|
| 155 | - * @param bool $forceIcon |
|
| 156 | - * @param string $mode |
|
| 157 | - * @return DataResponse|FileDisplayResponse |
|
| 158 | - */ |
|
| 159 | - private function fetchPreview( |
|
| 160 | - Node $node, |
|
| 161 | - int $x, |
|
| 162 | - int $y, |
|
| 163 | - bool $a = false, |
|
| 164 | - bool $forceIcon = true, |
|
| 165 | - string $mode) : Http\Response { |
|
| 166 | - |
|
| 167 | - if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) { |
|
| 168 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 169 | - } |
|
| 170 | - if (!$node->isReadable()) { |
|
| 171 | - return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - try { |
|
| 175 | - $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); |
|
| 176 | - $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
| 177 | - $response->cacheFor(3600 * 24); |
|
| 178 | - return $response; |
|
| 179 | - } catch (NotFoundException $e) { |
|
| 180 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 181 | - } catch (\InvalidArgumentException $e) { |
|
| 182 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - } |
|
| 42 | + /** @var string */ |
|
| 43 | + private $userId; |
|
| 44 | + |
|
| 45 | + /** @var IRootFolder */ |
|
| 46 | + private $root; |
|
| 47 | + |
|
| 48 | + /** @var IPreview */ |
|
| 49 | + private $preview; |
|
| 50 | + |
|
| 51 | + /** @var ITimeFactory */ |
|
| 52 | + private $timeFactory; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * PreviewController constructor. |
|
| 56 | + * |
|
| 57 | + * @param string $appName |
|
| 58 | + * @param IRequest $request |
|
| 59 | + * @param IPreview $preview |
|
| 60 | + * @param IRootFolder $root |
|
| 61 | + * @param string $userId |
|
| 62 | + * @param ITimeFactory $timeFactory |
|
| 63 | + */ |
|
| 64 | + public function __construct(string $appName, |
|
| 65 | + IRequest $request, |
|
| 66 | + IPreview $preview, |
|
| 67 | + IRootFolder $root, |
|
| 68 | + string $userId, |
|
| 69 | + ITimeFactory $timeFactory |
|
| 70 | + ) { |
|
| 71 | + parent::__construct($appName, $request); |
|
| 72 | + |
|
| 73 | + $this->preview = $preview; |
|
| 74 | + $this->root = $root; |
|
| 75 | + $this->userId = $userId; |
|
| 76 | + $this->timeFactory = $timeFactory; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @NoAdminRequired |
|
| 81 | + * @NoCSRFRequired |
|
| 82 | + * |
|
| 83 | + * @param string $file |
|
| 84 | + * @param int $x |
|
| 85 | + * @param int $y |
|
| 86 | + * @param bool $a |
|
| 87 | + * @param bool $forceIcon |
|
| 88 | + * @param string $mode |
|
| 89 | + * @return DataResponse|FileDisplayResponse |
|
| 90 | + */ |
|
| 91 | + public function getPreview ( |
|
| 92 | + string $file = '', |
|
| 93 | + int $x = 32, |
|
| 94 | + int $y = 32, |
|
| 95 | + bool $a = false, |
|
| 96 | + bool $forceIcon = true, |
|
| 97 | + string $mode = 'fill'): Http\Response { |
|
| 98 | + |
|
| 99 | + if ($file === '' || $x === 0 || $y === 0) { |
|
| 100 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + try { |
|
| 104 | + $userFolder = $this->root->getUserFolder($this->userId); |
|
| 105 | + $node = $userFolder->get($file); |
|
| 106 | + } catch (NotFoundException $e) { |
|
| 107 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @NoAdminRequired |
|
| 115 | + * @NoCSRFRequired |
|
| 116 | + * |
|
| 117 | + * @param int $fileId |
|
| 118 | + * @param int $x |
|
| 119 | + * @param int $y |
|
| 120 | + * @param bool $a |
|
| 121 | + * @param bool $forceIcon |
|
| 122 | + * @param string $mode |
|
| 123 | + * |
|
| 124 | + * @return DataResponse|FileDisplayResponse |
|
| 125 | + */ |
|
| 126 | + public function getPreviewByFileId( |
|
| 127 | + int $fileId = -1, |
|
| 128 | + int $x = 32, |
|
| 129 | + int $y = 32, |
|
| 130 | + bool $a = false, |
|
| 131 | + bool $forceIcon = true, |
|
| 132 | + string $mode = 'fill') { |
|
| 133 | + |
|
| 134 | + if ($fileId === -1 || $x === 0 || $y === 0) { |
|
| 135 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $userFolder = $this->root->getUserFolder($this->userId); |
|
| 139 | + $nodes = $userFolder->getById($fileId); |
|
| 140 | + |
|
| 141 | + if (\count($nodes) === 0) { |
|
| 142 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $node = array_pop($nodes); |
|
| 146 | + |
|
| 147 | + return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param Node $node |
|
| 152 | + * @param int $x |
|
| 153 | + * @param int $y |
|
| 154 | + * @param bool $a |
|
| 155 | + * @param bool $forceIcon |
|
| 156 | + * @param string $mode |
|
| 157 | + * @return DataResponse|FileDisplayResponse |
|
| 158 | + */ |
|
| 159 | + private function fetchPreview( |
|
| 160 | + Node $node, |
|
| 161 | + int $x, |
|
| 162 | + int $y, |
|
| 163 | + bool $a = false, |
|
| 164 | + bool $forceIcon = true, |
|
| 165 | + string $mode) : Http\Response { |
|
| 166 | + |
|
| 167 | + if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) { |
|
| 168 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 169 | + } |
|
| 170 | + if (!$node->isReadable()) { |
|
| 171 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + try { |
|
| 175 | + $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); |
|
| 176 | + $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
| 177 | + $response->cacheFor(3600 * 24); |
|
| 178 | + return $response; |
|
| 179 | + } catch (NotFoundException $e) { |
|
| 180 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 181 | + } catch (\InvalidArgumentException $e) { |
|
| 182 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + } |
|
| 186 | 186 | } |
@@ -39,144 +39,144 @@ |
||
| 39 | 39 | use OCP\IRequest; |
| 40 | 40 | |
| 41 | 41 | class IconController extends Controller { |
| 42 | - /** @var ThemingDefaults */ |
|
| 43 | - private $themingDefaults; |
|
| 44 | - /** @var ITimeFactory */ |
|
| 45 | - private $timeFactory; |
|
| 46 | - /** @var IconBuilder */ |
|
| 47 | - private $iconBuilder; |
|
| 48 | - /** @var ImageManager */ |
|
| 49 | - private $imageManager; |
|
| 50 | - /** @var FileAccessHelper */ |
|
| 51 | - private $fileAccessHelper; |
|
| 42 | + /** @var ThemingDefaults */ |
|
| 43 | + private $themingDefaults; |
|
| 44 | + /** @var ITimeFactory */ |
|
| 45 | + private $timeFactory; |
|
| 46 | + /** @var IconBuilder */ |
|
| 47 | + private $iconBuilder; |
|
| 48 | + /** @var ImageManager */ |
|
| 49 | + private $imageManager; |
|
| 50 | + /** @var FileAccessHelper */ |
|
| 51 | + private $fileAccessHelper; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * IconController constructor. |
|
| 55 | - * |
|
| 56 | - * @param string $appName |
|
| 57 | - * @param IRequest $request |
|
| 58 | - * @param ThemingDefaults $themingDefaults |
|
| 59 | - * @param ITimeFactory $timeFactory |
|
| 60 | - * @param IconBuilder $iconBuilder |
|
| 61 | - * @param ImageManager $imageManager |
|
| 62 | - * @param FileAccessHelper $fileAccessHelper |
|
| 63 | - */ |
|
| 64 | - public function __construct( |
|
| 65 | - $appName, |
|
| 66 | - IRequest $request, |
|
| 67 | - ThemingDefaults $themingDefaults, |
|
| 68 | - ITimeFactory $timeFactory, |
|
| 69 | - IconBuilder $iconBuilder, |
|
| 70 | - ImageManager $imageManager, |
|
| 71 | - FileAccessHelper $fileAccessHelper |
|
| 72 | - ) { |
|
| 73 | - parent::__construct($appName, $request); |
|
| 53 | + /** |
|
| 54 | + * IconController constructor. |
|
| 55 | + * |
|
| 56 | + * @param string $appName |
|
| 57 | + * @param IRequest $request |
|
| 58 | + * @param ThemingDefaults $themingDefaults |
|
| 59 | + * @param ITimeFactory $timeFactory |
|
| 60 | + * @param IconBuilder $iconBuilder |
|
| 61 | + * @param ImageManager $imageManager |
|
| 62 | + * @param FileAccessHelper $fileAccessHelper |
|
| 63 | + */ |
|
| 64 | + public function __construct( |
|
| 65 | + $appName, |
|
| 66 | + IRequest $request, |
|
| 67 | + ThemingDefaults $themingDefaults, |
|
| 68 | + ITimeFactory $timeFactory, |
|
| 69 | + IconBuilder $iconBuilder, |
|
| 70 | + ImageManager $imageManager, |
|
| 71 | + FileAccessHelper $fileAccessHelper |
|
| 72 | + ) { |
|
| 73 | + parent::__construct($appName, $request); |
|
| 74 | 74 | |
| 75 | - $this->themingDefaults = $themingDefaults; |
|
| 76 | - $this->timeFactory = $timeFactory; |
|
| 77 | - $this->iconBuilder = $iconBuilder; |
|
| 78 | - $this->imageManager = $imageManager; |
|
| 79 | - $this->fileAccessHelper = $fileAccessHelper; |
|
| 80 | - } |
|
| 75 | + $this->themingDefaults = $themingDefaults; |
|
| 76 | + $this->timeFactory = $timeFactory; |
|
| 77 | + $this->iconBuilder = $iconBuilder; |
|
| 78 | + $this->imageManager = $imageManager; |
|
| 79 | + $this->fileAccessHelper = $fileAccessHelper; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @PublicPage |
|
| 84 | - * @NoCSRFRequired |
|
| 85 | - * |
|
| 86 | - * @param $app string app name |
|
| 87 | - * @param $image string image file name (svg required) |
|
| 88 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 89 | - * @throws \Exception |
|
| 90 | - */ |
|
| 91 | - public function getThemedIcon(string $app, string $image): Response { |
|
| 92 | - try { |
|
| 93 | - $iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image)); |
|
| 94 | - } catch (NotFoundException $exception) { |
|
| 95 | - $icon = $this->iconBuilder->colorSvg($app, $image); |
|
| 96 | - if ($icon === false || $icon === '') { |
|
| 97 | - return new NotFoundResponse(); |
|
| 98 | - } |
|
| 99 | - $iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon); |
|
| 100 | - } |
|
| 101 | - if ($iconFile !== false) { |
|
| 102 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
| 103 | - $response->cacheFor(86400); |
|
| 104 | - return $response; |
|
| 105 | - } |
|
| 82 | + /** |
|
| 83 | + * @PublicPage |
|
| 84 | + * @NoCSRFRequired |
|
| 85 | + * |
|
| 86 | + * @param $app string app name |
|
| 87 | + * @param $image string image file name (svg required) |
|
| 88 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 89 | + * @throws \Exception |
|
| 90 | + */ |
|
| 91 | + public function getThemedIcon(string $app, string $image): Response { |
|
| 92 | + try { |
|
| 93 | + $iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image)); |
|
| 94 | + } catch (NotFoundException $exception) { |
|
| 95 | + $icon = $this->iconBuilder->colorSvg($app, $image); |
|
| 96 | + if ($icon === false || $icon === '') { |
|
| 97 | + return new NotFoundResponse(); |
|
| 98 | + } |
|
| 99 | + $iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon); |
|
| 100 | + } |
|
| 101 | + if ($iconFile !== false) { |
|
| 102 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
| 103 | + $response->cacheFor(86400); |
|
| 104 | + return $response; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return new NotFoundResponse(); |
|
| 108 | - } |
|
| 107 | + return new NotFoundResponse(); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Return a 32x32 favicon as png |
|
| 112 | - * |
|
| 113 | - * @PublicPage |
|
| 114 | - * @NoCSRFRequired |
|
| 115 | - * |
|
| 116 | - * @param $app string app name |
|
| 117 | - * @return FileDisplayResponse|DataDisplayResponse |
|
| 118 | - * @throws \Exception |
|
| 119 | - */ |
|
| 120 | - public function getFavicon(string $app = 'core'): Response { |
|
| 121 | - $response = null; |
|
| 122 | - $iconFile = null; |
|
| 123 | - try { |
|
| 124 | - $iconFile = $this->imageManager->getImage('favicon'); |
|
| 125 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 126 | - } catch (NotFoundException $e) { |
|
| 127 | - } |
|
| 128 | - if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) { |
|
| 129 | - try { |
|
| 130 | - $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app); |
|
| 131 | - } catch (NotFoundException $exception) { |
|
| 132 | - $icon = $this->iconBuilder->getFavicon($app); |
|
| 133 | - $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon); |
|
| 134 | - } |
|
| 135 | - if ($iconFile !== false) { |
|
| 136 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - if($response === null) { |
|
| 140 | - $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png'; |
|
| 141 | - $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 142 | - } |
|
| 143 | - $response->cacheFor(86400); |
|
| 144 | - return $response; |
|
| 145 | - } |
|
| 110 | + /** |
|
| 111 | + * Return a 32x32 favicon as png |
|
| 112 | + * |
|
| 113 | + * @PublicPage |
|
| 114 | + * @NoCSRFRequired |
|
| 115 | + * |
|
| 116 | + * @param $app string app name |
|
| 117 | + * @return FileDisplayResponse|DataDisplayResponse |
|
| 118 | + * @throws \Exception |
|
| 119 | + */ |
|
| 120 | + public function getFavicon(string $app = 'core'): Response { |
|
| 121 | + $response = null; |
|
| 122 | + $iconFile = null; |
|
| 123 | + try { |
|
| 124 | + $iconFile = $this->imageManager->getImage('favicon'); |
|
| 125 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 126 | + } catch (NotFoundException $e) { |
|
| 127 | + } |
|
| 128 | + if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) { |
|
| 129 | + try { |
|
| 130 | + $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app); |
|
| 131 | + } catch (NotFoundException $exception) { |
|
| 132 | + $icon = $this->iconBuilder->getFavicon($app); |
|
| 133 | + $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon); |
|
| 134 | + } |
|
| 135 | + if ($iconFile !== false) { |
|
| 136 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + if($response === null) { |
|
| 140 | + $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png'; |
|
| 141 | + $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 142 | + } |
|
| 143 | + $response->cacheFor(86400); |
|
| 144 | + return $response; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Return a 512x512 icon for touch devices |
|
| 149 | - * |
|
| 150 | - * @PublicPage |
|
| 151 | - * @NoCSRFRequired |
|
| 152 | - * |
|
| 153 | - * @param $app string app name |
|
| 154 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 155 | - * @throws \Exception |
|
| 156 | - */ |
|
| 157 | - public function getTouchIcon(string $app = 'core'): Response { |
|
| 158 | - $response = null; |
|
| 159 | - try { |
|
| 160 | - $iconFile = $this->imageManager->getImage('favicon'); |
|
| 161 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 162 | - } catch (NotFoundException $e) { |
|
| 163 | - } |
|
| 164 | - if ($this->themingDefaults->shouldReplaceIcons()) { |
|
| 165 | - try { |
|
| 166 | - $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app); |
|
| 167 | - } catch (NotFoundException $exception) { |
|
| 168 | - $icon = $this->iconBuilder->getTouchIcon($app); |
|
| 169 | - $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon); |
|
| 170 | - } |
|
| 171 | - if ($iconFile !== false) { |
|
| 172 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - if($response === null) { |
|
| 176 | - $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png'; |
|
| 177 | - $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']); |
|
| 178 | - } |
|
| 179 | - $response->cacheFor(86400); |
|
| 180 | - return $response; |
|
| 181 | - } |
|
| 147 | + /** |
|
| 148 | + * Return a 512x512 icon for touch devices |
|
| 149 | + * |
|
| 150 | + * @PublicPage |
|
| 151 | + * @NoCSRFRequired |
|
| 152 | + * |
|
| 153 | + * @param $app string app name |
|
| 154 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 155 | + * @throws \Exception |
|
| 156 | + */ |
|
| 157 | + public function getTouchIcon(string $app = 'core'): Response { |
|
| 158 | + $response = null; |
|
| 159 | + try { |
|
| 160 | + $iconFile = $this->imageManager->getImage('favicon'); |
|
| 161 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 162 | + } catch (NotFoundException $e) { |
|
| 163 | + } |
|
| 164 | + if ($this->themingDefaults->shouldReplaceIcons()) { |
|
| 165 | + try { |
|
| 166 | + $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app); |
|
| 167 | + } catch (NotFoundException $exception) { |
|
| 168 | + $icon = $this->iconBuilder->getTouchIcon($app); |
|
| 169 | + $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon); |
|
| 170 | + } |
|
| 171 | + if ($iconFile !== false) { |
|
| 172 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + if($response === null) { |
|
| 176 | + $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png'; |
|
| 177 | + $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']); |
|
| 178 | + } |
|
| 179 | + $response->cacheFor(86400); |
|
| 180 | + return $response; |
|
| 181 | + } |
|
| 182 | 182 | } |
@@ -62,357 +62,357 @@ discard block |
||
| 62 | 62 | * @package OCA\Theming\Controller |
| 63 | 63 | */ |
| 64 | 64 | class ThemingController extends Controller { |
| 65 | - /** @var ThemingDefaults */ |
|
| 66 | - private $themingDefaults; |
|
| 67 | - /** @var Util */ |
|
| 68 | - private $util; |
|
| 69 | - /** @var ITimeFactory */ |
|
| 70 | - private $timeFactory; |
|
| 71 | - /** @var IL10N */ |
|
| 72 | - private $l10n; |
|
| 73 | - /** @var IConfig */ |
|
| 74 | - private $config; |
|
| 75 | - /** @var ITempManager */ |
|
| 76 | - private $tempManager; |
|
| 77 | - /** @var IAppData */ |
|
| 78 | - private $appData; |
|
| 79 | - /** @var SCSSCacher */ |
|
| 80 | - private $scssCacher; |
|
| 81 | - /** @var IURLGenerator */ |
|
| 82 | - private $urlGenerator; |
|
| 83 | - /** @var IAppManager */ |
|
| 84 | - private $appManager; |
|
| 85 | - /** @var ImageManager */ |
|
| 86 | - private $imageManager; |
|
| 65 | + /** @var ThemingDefaults */ |
|
| 66 | + private $themingDefaults; |
|
| 67 | + /** @var Util */ |
|
| 68 | + private $util; |
|
| 69 | + /** @var ITimeFactory */ |
|
| 70 | + private $timeFactory; |
|
| 71 | + /** @var IL10N */ |
|
| 72 | + private $l10n; |
|
| 73 | + /** @var IConfig */ |
|
| 74 | + private $config; |
|
| 75 | + /** @var ITempManager */ |
|
| 76 | + private $tempManager; |
|
| 77 | + /** @var IAppData */ |
|
| 78 | + private $appData; |
|
| 79 | + /** @var SCSSCacher */ |
|
| 80 | + private $scssCacher; |
|
| 81 | + /** @var IURLGenerator */ |
|
| 82 | + private $urlGenerator; |
|
| 83 | + /** @var IAppManager */ |
|
| 84 | + private $appManager; |
|
| 85 | + /** @var ImageManager */ |
|
| 86 | + private $imageManager; |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * ThemingController constructor. |
|
| 90 | - * |
|
| 91 | - * @param string $appName |
|
| 92 | - * @param IRequest $request |
|
| 93 | - * @param IConfig $config |
|
| 94 | - * @param ThemingDefaults $themingDefaults |
|
| 95 | - * @param Util $util |
|
| 96 | - * @param ITimeFactory $timeFactory |
|
| 97 | - * @param IL10N $l |
|
| 98 | - * @param ITempManager $tempManager |
|
| 99 | - * @param IAppData $appData |
|
| 100 | - * @param SCSSCacher $scssCacher |
|
| 101 | - * @param IURLGenerator $urlGenerator |
|
| 102 | - * @param IAppManager $appManager |
|
| 103 | - * @param ImageManager $imageManager |
|
| 104 | - */ |
|
| 105 | - public function __construct( |
|
| 106 | - $appName, |
|
| 107 | - IRequest $request, |
|
| 108 | - IConfig $config, |
|
| 109 | - ThemingDefaults $themingDefaults, |
|
| 110 | - Util $util, |
|
| 111 | - ITimeFactory $timeFactory, |
|
| 112 | - IL10N $l, |
|
| 113 | - ITempManager $tempManager, |
|
| 114 | - IAppData $appData, |
|
| 115 | - SCSSCacher $scssCacher, |
|
| 116 | - IURLGenerator $urlGenerator, |
|
| 117 | - IAppManager $appManager, |
|
| 118 | - ImageManager $imageManager |
|
| 119 | - ) { |
|
| 120 | - parent::__construct($appName, $request); |
|
| 88 | + /** |
|
| 89 | + * ThemingController constructor. |
|
| 90 | + * |
|
| 91 | + * @param string $appName |
|
| 92 | + * @param IRequest $request |
|
| 93 | + * @param IConfig $config |
|
| 94 | + * @param ThemingDefaults $themingDefaults |
|
| 95 | + * @param Util $util |
|
| 96 | + * @param ITimeFactory $timeFactory |
|
| 97 | + * @param IL10N $l |
|
| 98 | + * @param ITempManager $tempManager |
|
| 99 | + * @param IAppData $appData |
|
| 100 | + * @param SCSSCacher $scssCacher |
|
| 101 | + * @param IURLGenerator $urlGenerator |
|
| 102 | + * @param IAppManager $appManager |
|
| 103 | + * @param ImageManager $imageManager |
|
| 104 | + */ |
|
| 105 | + public function __construct( |
|
| 106 | + $appName, |
|
| 107 | + IRequest $request, |
|
| 108 | + IConfig $config, |
|
| 109 | + ThemingDefaults $themingDefaults, |
|
| 110 | + Util $util, |
|
| 111 | + ITimeFactory $timeFactory, |
|
| 112 | + IL10N $l, |
|
| 113 | + ITempManager $tempManager, |
|
| 114 | + IAppData $appData, |
|
| 115 | + SCSSCacher $scssCacher, |
|
| 116 | + IURLGenerator $urlGenerator, |
|
| 117 | + IAppManager $appManager, |
|
| 118 | + ImageManager $imageManager |
|
| 119 | + ) { |
|
| 120 | + parent::__construct($appName, $request); |
|
| 121 | 121 | |
| 122 | - $this->themingDefaults = $themingDefaults; |
|
| 123 | - $this->util = $util; |
|
| 124 | - $this->timeFactory = $timeFactory; |
|
| 125 | - $this->l10n = $l; |
|
| 126 | - $this->config = $config; |
|
| 127 | - $this->tempManager = $tempManager; |
|
| 128 | - $this->appData = $appData; |
|
| 129 | - $this->scssCacher = $scssCacher; |
|
| 130 | - $this->urlGenerator = $urlGenerator; |
|
| 131 | - $this->appManager = $appManager; |
|
| 132 | - $this->imageManager = $imageManager; |
|
| 133 | - } |
|
| 122 | + $this->themingDefaults = $themingDefaults; |
|
| 123 | + $this->util = $util; |
|
| 124 | + $this->timeFactory = $timeFactory; |
|
| 125 | + $this->l10n = $l; |
|
| 126 | + $this->config = $config; |
|
| 127 | + $this->tempManager = $tempManager; |
|
| 128 | + $this->appData = $appData; |
|
| 129 | + $this->scssCacher = $scssCacher; |
|
| 130 | + $this->urlGenerator = $urlGenerator; |
|
| 131 | + $this->appManager = $appManager; |
|
| 132 | + $this->imageManager = $imageManager; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * @param string $setting |
|
| 137 | - * @param string $value |
|
| 138 | - * @return DataResponse |
|
| 139 | - * @throws NotPermittedException |
|
| 140 | - */ |
|
| 141 | - public function updateStylesheet($setting, $value) { |
|
| 142 | - $value = trim($value); |
|
| 143 | - switch ($setting) { |
|
| 144 | - case 'name': |
|
| 145 | - if (strlen($value) > 250) { |
|
| 146 | - return new DataResponse([ |
|
| 147 | - 'data' => [ |
|
| 148 | - 'message' => $this->l10n->t('The given name is too long'), |
|
| 149 | - ], |
|
| 150 | - 'status' => 'error' |
|
| 151 | - ]); |
|
| 152 | - } |
|
| 153 | - break; |
|
| 154 | - case 'url': |
|
| 155 | - if (strlen($value) > 500) { |
|
| 156 | - return new DataResponse([ |
|
| 157 | - 'data' => [ |
|
| 158 | - 'message' => $this->l10n->t('The given web address is too long'), |
|
| 159 | - ], |
|
| 160 | - 'status' => 'error' |
|
| 161 | - ]); |
|
| 162 | - } |
|
| 163 | - break; |
|
| 164 | - case 'imprintUrl': |
|
| 165 | - if (strlen($value) > 500) { |
|
| 166 | - return new DataResponse([ |
|
| 167 | - 'data' => [ |
|
| 168 | - 'message' => $this->l10n->t('The given legal notice address is too long'), |
|
| 169 | - ], |
|
| 170 | - 'status' => 'error' |
|
| 171 | - ]); |
|
| 172 | - } |
|
| 173 | - break; |
|
| 174 | - case 'privacyUrl': |
|
| 175 | - if (strlen($value) > 500) { |
|
| 176 | - return new DataResponse([ |
|
| 177 | - 'data' => [ |
|
| 178 | - 'message' => $this->l10n->t('The given privacy policy address is too long'), |
|
| 179 | - ], |
|
| 180 | - 'status' => 'error' |
|
| 181 | - ]); |
|
| 182 | - } |
|
| 183 | - break; |
|
| 184 | - case 'slogan': |
|
| 185 | - if (strlen($value) > 500) { |
|
| 186 | - return new DataResponse([ |
|
| 187 | - 'data' => [ |
|
| 188 | - 'message' => $this->l10n->t('The given slogan is too long'), |
|
| 189 | - ], |
|
| 190 | - 'status' => 'error' |
|
| 191 | - ]); |
|
| 192 | - } |
|
| 193 | - break; |
|
| 194 | - case 'color': |
|
| 195 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 196 | - return new DataResponse([ |
|
| 197 | - 'data' => [ |
|
| 198 | - 'message' => $this->l10n->t('The given color is invalid'), |
|
| 199 | - ], |
|
| 200 | - 'status' => 'error' |
|
| 201 | - ]); |
|
| 202 | - } |
|
| 203 | - break; |
|
| 204 | - } |
|
| 135 | + /** |
|
| 136 | + * @param string $setting |
|
| 137 | + * @param string $value |
|
| 138 | + * @return DataResponse |
|
| 139 | + * @throws NotPermittedException |
|
| 140 | + */ |
|
| 141 | + public function updateStylesheet($setting, $value) { |
|
| 142 | + $value = trim($value); |
|
| 143 | + switch ($setting) { |
|
| 144 | + case 'name': |
|
| 145 | + if (strlen($value) > 250) { |
|
| 146 | + return new DataResponse([ |
|
| 147 | + 'data' => [ |
|
| 148 | + 'message' => $this->l10n->t('The given name is too long'), |
|
| 149 | + ], |
|
| 150 | + 'status' => 'error' |
|
| 151 | + ]); |
|
| 152 | + } |
|
| 153 | + break; |
|
| 154 | + case 'url': |
|
| 155 | + if (strlen($value) > 500) { |
|
| 156 | + return new DataResponse([ |
|
| 157 | + 'data' => [ |
|
| 158 | + 'message' => $this->l10n->t('The given web address is too long'), |
|
| 159 | + ], |
|
| 160 | + 'status' => 'error' |
|
| 161 | + ]); |
|
| 162 | + } |
|
| 163 | + break; |
|
| 164 | + case 'imprintUrl': |
|
| 165 | + if (strlen($value) > 500) { |
|
| 166 | + return new DataResponse([ |
|
| 167 | + 'data' => [ |
|
| 168 | + 'message' => $this->l10n->t('The given legal notice address is too long'), |
|
| 169 | + ], |
|
| 170 | + 'status' => 'error' |
|
| 171 | + ]); |
|
| 172 | + } |
|
| 173 | + break; |
|
| 174 | + case 'privacyUrl': |
|
| 175 | + if (strlen($value) > 500) { |
|
| 176 | + return new DataResponse([ |
|
| 177 | + 'data' => [ |
|
| 178 | + 'message' => $this->l10n->t('The given privacy policy address is too long'), |
|
| 179 | + ], |
|
| 180 | + 'status' => 'error' |
|
| 181 | + ]); |
|
| 182 | + } |
|
| 183 | + break; |
|
| 184 | + case 'slogan': |
|
| 185 | + if (strlen($value) > 500) { |
|
| 186 | + return new DataResponse([ |
|
| 187 | + 'data' => [ |
|
| 188 | + 'message' => $this->l10n->t('The given slogan is too long'), |
|
| 189 | + ], |
|
| 190 | + 'status' => 'error' |
|
| 191 | + ]); |
|
| 192 | + } |
|
| 193 | + break; |
|
| 194 | + case 'color': |
|
| 195 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 196 | + return new DataResponse([ |
|
| 197 | + 'data' => [ |
|
| 198 | + 'message' => $this->l10n->t('The given color is invalid'), |
|
| 199 | + ], |
|
| 200 | + 'status' => 'error' |
|
| 201 | + ]); |
|
| 202 | + } |
|
| 203 | + break; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - $this->themingDefaults->set($setting, $value); |
|
| 206 | + $this->themingDefaults->set($setting, $value); |
|
| 207 | 207 | |
| 208 | - // reprocess server scss for preview |
|
| 209 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
| 208 | + // reprocess server scss for preview |
|
| 209 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
| 210 | 210 | |
| 211 | - return new DataResponse( |
|
| 212 | - [ |
|
| 213 | - 'data' => |
|
| 214 | - [ |
|
| 215 | - 'message' => $this->l10n->t('Saved'), |
|
| 216 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 217 | - ], |
|
| 218 | - 'status' => 'success' |
|
| 219 | - ] |
|
| 220 | - ); |
|
| 221 | - } |
|
| 211 | + return new DataResponse( |
|
| 212 | + [ |
|
| 213 | + 'data' => |
|
| 214 | + [ |
|
| 215 | + 'message' => $this->l10n->t('Saved'), |
|
| 216 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 217 | + ], |
|
| 218 | + 'status' => 'success' |
|
| 219 | + ] |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * @return DataResponse |
|
| 225 | - * @throws NotPermittedException |
|
| 226 | - */ |
|
| 227 | - public function uploadImage(): DataResponse { |
|
| 228 | - // logo / background |
|
| 229 | - // new: favicon logo-header |
|
| 230 | - // |
|
| 231 | - $key = $this->request->getParam('key'); |
|
| 232 | - $image = $this->request->getUploadedFile('image'); |
|
| 233 | - $error = null; |
|
| 234 | - $phpFileUploadErrors = [ |
|
| 235 | - UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
| 236 | - UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
| 237 | - UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
| 238 | - UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
| 239 | - UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
| 240 | - UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
| 241 | - UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
| 242 | - UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
| 243 | - ]; |
|
| 244 | - if (empty($image)) { |
|
| 245 | - $error = $this->l10n->t('No file uploaded'); |
|
| 246 | - } |
|
| 247 | - if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { |
|
| 248 | - $error = $phpFileUploadErrors[$image['error']]; |
|
| 249 | - } |
|
| 223 | + /** |
|
| 224 | + * @return DataResponse |
|
| 225 | + * @throws NotPermittedException |
|
| 226 | + */ |
|
| 227 | + public function uploadImage(): DataResponse { |
|
| 228 | + // logo / background |
|
| 229 | + // new: favicon logo-header |
|
| 230 | + // |
|
| 231 | + $key = $this->request->getParam('key'); |
|
| 232 | + $image = $this->request->getUploadedFile('image'); |
|
| 233 | + $error = null; |
|
| 234 | + $phpFileUploadErrors = [ |
|
| 235 | + UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
| 236 | + UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
| 237 | + UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
| 238 | + UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
| 239 | + UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
| 240 | + UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
| 241 | + UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
| 242 | + UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
| 243 | + ]; |
|
| 244 | + if (empty($image)) { |
|
| 245 | + $error = $this->l10n->t('No file uploaded'); |
|
| 246 | + } |
|
| 247 | + if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { |
|
| 248 | + $error = $phpFileUploadErrors[$image['error']]; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - if ($error !== null) { |
|
| 252 | - return new DataResponse( |
|
| 253 | - [ |
|
| 254 | - 'data' => [ |
|
| 255 | - 'message' => $error |
|
| 256 | - ], |
|
| 257 | - 'status' => 'failure', |
|
| 258 | - ], |
|
| 259 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 260 | - ); |
|
| 261 | - } |
|
| 251 | + if ($error !== null) { |
|
| 252 | + return new DataResponse( |
|
| 253 | + [ |
|
| 254 | + 'data' => [ |
|
| 255 | + 'message' => $error |
|
| 256 | + ], |
|
| 257 | + 'status' => 'failure', |
|
| 258 | + ], |
|
| 259 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 260 | + ); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - $name = ''; |
|
| 264 | - try { |
|
| 265 | - $folder = $this->appData->getFolder('images'); |
|
| 266 | - } catch (NotFoundException $e) { |
|
| 267 | - $folder = $this->appData->newFolder('images'); |
|
| 268 | - } |
|
| 263 | + $name = ''; |
|
| 264 | + try { |
|
| 265 | + $folder = $this->appData->getFolder('images'); |
|
| 266 | + } catch (NotFoundException $e) { |
|
| 267 | + $folder = $this->appData->newFolder('images'); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - $target = $folder->newFile($key); |
|
| 271 | - $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/svg']; |
|
| 272 | - $detectedMimeType = mime_content_type($image['tmp_name']); |
|
| 273 | - if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) { |
|
| 274 | - return new DataResponse( |
|
| 275 | - [ |
|
| 276 | - 'data' => [ |
|
| 277 | - 'message' => $this->l10n->t('Unsupported image type'), |
|
| 278 | - ], |
|
| 279 | - 'status' => 'failure', |
|
| 280 | - ], |
|
| 281 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 282 | - ); |
|
| 283 | - } |
|
| 270 | + $target = $folder->newFile($key); |
|
| 271 | + $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/svg']; |
|
| 272 | + $detectedMimeType = mime_content_type($image['tmp_name']); |
|
| 273 | + if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) { |
|
| 274 | + return new DataResponse( |
|
| 275 | + [ |
|
| 276 | + 'data' => [ |
|
| 277 | + 'message' => $this->l10n->t('Unsupported image type'), |
|
| 278 | + ], |
|
| 279 | + 'status' => 'failure', |
|
| 280 | + ], |
|
| 281 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - $resizeKeys = ['background']; |
|
| 286 | - if (in_array($key, $resizeKeys, true)) { |
|
| 287 | - // Optimize the image since some people may upload images that will be |
|
| 288 | - // either to big or are not progressive rendering. |
|
| 289 | - $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r')); |
|
| 285 | + $resizeKeys = ['background']; |
|
| 286 | + if (in_array($key, $resizeKeys, true)) { |
|
| 287 | + // Optimize the image since some people may upload images that will be |
|
| 288 | + // either to big or are not progressive rendering. |
|
| 289 | + $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r')); |
|
| 290 | 290 | |
| 291 | - $tmpFile = $this->tempManager->getTemporaryFile(); |
|
| 292 | - $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096; |
|
| 293 | - $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth); |
|
| 294 | - $outputImage = imagescale($newImage, $newWidth, $newHeight); |
|
| 291 | + $tmpFile = $this->tempManager->getTemporaryFile(); |
|
| 292 | + $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096; |
|
| 293 | + $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth); |
|
| 294 | + $outputImage = imagescale($newImage, $newWidth, $newHeight); |
|
| 295 | 295 | |
| 296 | - imageinterlace($outputImage, 1); |
|
| 297 | - imagejpeg($outputImage, $tmpFile, 75); |
|
| 298 | - imagedestroy($outputImage); |
|
| 296 | + imageinterlace($outputImage, 1); |
|
| 297 | + imagejpeg($outputImage, $tmpFile, 75); |
|
| 298 | + imagedestroy($outputImage); |
|
| 299 | 299 | |
| 300 | - $target->putContent(file_get_contents($tmpFile, 'r')); |
|
| 301 | - } else { |
|
| 302 | - $target->putContent(file_get_contents($image['tmp_name'], 'r')); |
|
| 303 | - } |
|
| 304 | - $name = $image['name']; |
|
| 300 | + $target->putContent(file_get_contents($tmpFile, 'r')); |
|
| 301 | + } else { |
|
| 302 | + $target->putContent(file_get_contents($image['tmp_name'], 'r')); |
|
| 303 | + } |
|
| 304 | + $name = $image['name']; |
|
| 305 | 305 | |
| 306 | - $this->themingDefaults->set($key.'Mime', $image['type']); |
|
| 306 | + $this->themingDefaults->set($key.'Mime', $image['type']); |
|
| 307 | 307 | |
| 308 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
| 308 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
| 309 | 309 | |
| 310 | - return new DataResponse( |
|
| 311 | - [ |
|
| 312 | - 'data' => |
|
| 313 | - [ |
|
| 314 | - 'name' => $name, |
|
| 315 | - 'url' => $this->imageManager->getImageUrl($key), |
|
| 316 | - 'message' => $this->l10n->t('Saved'), |
|
| 317 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 318 | - ], |
|
| 319 | - 'status' => 'success' |
|
| 320 | - ] |
|
| 321 | - ); |
|
| 322 | - } |
|
| 310 | + return new DataResponse( |
|
| 311 | + [ |
|
| 312 | + 'data' => |
|
| 313 | + [ |
|
| 314 | + 'name' => $name, |
|
| 315 | + 'url' => $this->imageManager->getImageUrl($key), |
|
| 316 | + 'message' => $this->l10n->t('Saved'), |
|
| 317 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 318 | + ], |
|
| 319 | + 'status' => 'success' |
|
| 320 | + ] |
|
| 321 | + ); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Revert setting to default value |
|
| 326 | - * |
|
| 327 | - * @param string $setting setting which should be reverted |
|
| 328 | - * @return DataResponse |
|
| 329 | - * @throws NotPermittedException |
|
| 330 | - */ |
|
| 331 | - public function undo(string $setting): DataResponse { |
|
| 332 | - $value = $this->themingDefaults->undo($setting); |
|
| 333 | - // reprocess server scss for preview |
|
| 334 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
| 324 | + /** |
|
| 325 | + * Revert setting to default value |
|
| 326 | + * |
|
| 327 | + * @param string $setting setting which should be reverted |
|
| 328 | + * @return DataResponse |
|
| 329 | + * @throws NotPermittedException |
|
| 330 | + */ |
|
| 331 | + public function undo(string $setting): DataResponse { |
|
| 332 | + $value = $this->themingDefaults->undo($setting); |
|
| 333 | + // reprocess server scss for preview |
|
| 334 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
| 335 | 335 | |
| 336 | - if (strpos($setting, 'Mime') !== -1) { |
|
| 337 | - $imageKey = str_replace('Mime', '', $setting); |
|
| 338 | - $this->imageManager->delete($imageKey); |
|
| 339 | - } |
|
| 336 | + if (strpos($setting, 'Mime') !== -1) { |
|
| 337 | + $imageKey = str_replace('Mime', '', $setting); |
|
| 338 | + $this->imageManager->delete($imageKey); |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - return new DataResponse( |
|
| 342 | - [ |
|
| 343 | - 'data' => |
|
| 344 | - [ |
|
| 345 | - 'value' => $value, |
|
| 346 | - 'message' => $this->l10n->t('Saved'), |
|
| 347 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 348 | - ], |
|
| 349 | - 'status' => 'success' |
|
| 350 | - ] |
|
| 351 | - ); |
|
| 352 | - } |
|
| 341 | + return new DataResponse( |
|
| 342 | + [ |
|
| 343 | + 'data' => |
|
| 344 | + [ |
|
| 345 | + 'value' => $value, |
|
| 346 | + 'message' => $this->l10n->t('Saved'), |
|
| 347 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 348 | + ], |
|
| 349 | + 'status' => 'success' |
|
| 350 | + ] |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | - /** |
|
| 355 | - * @PublicPage |
|
| 356 | - * @NoCSRFRequired |
|
| 357 | - * |
|
| 358 | - * @param string $key |
|
| 359 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 360 | - * @throws \Exception |
|
| 361 | - */ |
|
| 362 | - public function getImage(string $key) { |
|
| 363 | - try { |
|
| 364 | - $file = $this->imageManager->getImage($key); |
|
| 365 | - } catch (NotFoundException $e) { |
|
| 366 | - return new NotFoundResponse(); |
|
| 367 | - } |
|
| 354 | + /** |
|
| 355 | + * @PublicPage |
|
| 356 | + * @NoCSRFRequired |
|
| 357 | + * |
|
| 358 | + * @param string $key |
|
| 359 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 360 | + * @throws \Exception |
|
| 361 | + */ |
|
| 362 | + public function getImage(string $key) { |
|
| 363 | + try { |
|
| 364 | + $file = $this->imageManager->getImage($key); |
|
| 365 | + } catch (NotFoundException $e) { |
|
| 366 | + return new NotFoundResponse(); |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | - $response = new FileDisplayResponse($file); |
|
| 370 | - $response->cacheFor(3600); |
|
| 371 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
| 372 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
| 373 | - return $response; |
|
| 374 | - } |
|
| 369 | + $response = new FileDisplayResponse($file); |
|
| 370 | + $response->cacheFor(3600); |
|
| 371 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
| 372 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
| 373 | + return $response; |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - /** |
|
| 377 | - * @NoCSRFRequired |
|
| 378 | - * @PublicPage |
|
| 379 | - * |
|
| 380 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 381 | - * @throws NotPermittedException |
|
| 382 | - * @throws \Exception |
|
| 383 | - * @throws \OCP\App\AppPathNotFoundException |
|
| 384 | - */ |
|
| 385 | - public function getStylesheet() { |
|
| 386 | - $appPath = $this->appManager->getAppPath('theming'); |
|
| 376 | + /** |
|
| 377 | + * @NoCSRFRequired |
|
| 378 | + * @PublicPage |
|
| 379 | + * |
|
| 380 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 381 | + * @throws NotPermittedException |
|
| 382 | + * @throws \Exception |
|
| 383 | + * @throws \OCP\App\AppPathNotFoundException |
|
| 384 | + */ |
|
| 385 | + public function getStylesheet() { |
|
| 386 | + $appPath = $this->appManager->getAppPath('theming'); |
|
| 387 | 387 | |
| 388 | - /* SCSSCacher is required here |
|
| 388 | + /* SCSSCacher is required here |
|
| 389 | 389 | * We cannot rely on automatic caching done by \OC_Util::addStyle, |
| 390 | 390 | * since we need to add the cacheBuster value to the url |
| 391 | 391 | */ |
| 392 | - $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
|
| 393 | - if(!$cssCached) { |
|
| 394 | - return new NotFoundResponse(); |
|
| 395 | - } |
|
| 392 | + $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
|
| 393 | + if(!$cssCached) { |
|
| 394 | + return new NotFoundResponse(); |
|
| 395 | + } |
|
| 396 | 396 | |
| 397 | - try { |
|
| 398 | - $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
| 399 | - $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 400 | - $response->cacheFor(86400); |
|
| 401 | - return $response; |
|
| 402 | - } catch (NotFoundException $e) { |
|
| 403 | - return new NotFoundResponse(); |
|
| 404 | - } |
|
| 405 | - } |
|
| 397 | + try { |
|
| 398 | + $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
| 399 | + $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 400 | + $response->cacheFor(86400); |
|
| 401 | + return $response; |
|
| 402 | + } catch (NotFoundException $e) { |
|
| 403 | + return new NotFoundResponse(); |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | 406 | |
| 407 | - /** |
|
| 408 | - * @NoCSRFRequired |
|
| 409 | - * @PublicPage |
|
| 410 | - * |
|
| 411 | - * @return DataDownloadResponse |
|
| 412 | - */ |
|
| 413 | - public function getJavascript() { |
|
| 414 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 415 | - $responseJS = '(function() { |
|
| 407 | + /** |
|
| 408 | + * @NoCSRFRequired |
|
| 409 | + * @PublicPage |
|
| 410 | + * |
|
| 411 | + * @return DataDownloadResponse |
|
| 412 | + */ |
|
| 413 | + public function getJavascript() { |
|
| 414 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 415 | + $responseJS = '(function() { |
|
| 416 | 416 | OCA.Theming = { |
| 417 | 417 | name: ' . json_encode($this->themingDefaults->getName()) . ', |
| 418 | 418 | url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
@@ -424,41 +424,41 @@ discard block |
||
| 424 | 424 | cacheBuster: ' . json_encode($cacheBusterValue) . ' |
| 425 | 425 | }; |
| 426 | 426 | })();'; |
| 427 | - $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
| 428 | - $response->cacheFor(3600); |
|
| 429 | - return $response; |
|
| 430 | - } |
|
| 427 | + $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
| 428 | + $response->cacheFor(3600); |
|
| 429 | + return $response; |
|
| 430 | + } |
|
| 431 | 431 | |
| 432 | - /** |
|
| 433 | - * @NoCSRFRequired |
|
| 434 | - * @PublicPage |
|
| 435 | - * |
|
| 436 | - * @return Http\JSONResponse |
|
| 437 | - */ |
|
| 438 | - public function getManifest($app) { |
|
| 439 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 440 | - $responseJS = [ |
|
| 441 | - 'name' => $this->themingDefaults->getName(), |
|
| 442 | - 'start_url' => $this->urlGenerator->getBaseUrl(), |
|
| 443 | - 'icons' => |
|
| 444 | - [ |
|
| 445 | - [ |
|
| 446 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
| 447 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 448 | - 'type'=> 'image/png', |
|
| 449 | - 'sizes'=> '128x128' |
|
| 450 | - ], |
|
| 451 | - [ |
|
| 452 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
| 453 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 454 | - 'type' => 'image/svg+xml', |
|
| 455 | - 'sizes' => '16x16' |
|
| 456 | - ] |
|
| 457 | - ], |
|
| 458 | - 'display' => 'standalone' |
|
| 459 | - ]; |
|
| 460 | - $response = new Http\JSONResponse($responseJS); |
|
| 461 | - $response->cacheFor(3600); |
|
| 462 | - return $response; |
|
| 463 | - } |
|
| 432 | + /** |
|
| 433 | + * @NoCSRFRequired |
|
| 434 | + * @PublicPage |
|
| 435 | + * |
|
| 436 | + * @return Http\JSONResponse |
|
| 437 | + */ |
|
| 438 | + public function getManifest($app) { |
|
| 439 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 440 | + $responseJS = [ |
|
| 441 | + 'name' => $this->themingDefaults->getName(), |
|
| 442 | + 'start_url' => $this->urlGenerator->getBaseUrl(), |
|
| 443 | + 'icons' => |
|
| 444 | + [ |
|
| 445 | + [ |
|
| 446 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
| 447 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 448 | + 'type'=> 'image/png', |
|
| 449 | + 'sizes'=> '128x128' |
|
| 450 | + ], |
|
| 451 | + [ |
|
| 452 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
| 453 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 454 | + 'type' => 'image/svg+xml', |
|
| 455 | + 'sizes' => '16x16' |
|
| 456 | + ] |
|
| 457 | + ], |
|
| 458 | + 'display' => 'standalone' |
|
| 459 | + ]; |
|
| 460 | + $response = new Http\JSONResponse($responseJS); |
|
| 461 | + $response->cacheFor(3600); |
|
| 462 | + return $response; |
|
| 463 | + } |
|
| 464 | 464 | } |
@@ -368,8 +368,8 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | $response = new FileDisplayResponse($file); |
| 370 | 370 | $response->cacheFor(3600); |
| 371 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
| 372 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
| 371 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key.'Mime', '')); |
|
| 372 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.$key.'"'); |
|
| 373 | 373 | return $response; |
| 374 | 374 | } |
| 375 | 375 | |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * since we need to add the cacheBuster value to the url |
| 391 | 391 | */ |
| 392 | 392 | $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
| 393 | - if(!$cssCached) { |
|
| 393 | + if (!$cssCached) { |
|
| 394 | 394 | return new NotFoundResponse(); |
| 395 | 395 | } |
| 396 | 396 | |
@@ -414,14 +414,14 @@ discard block |
||
| 414 | 414 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
| 415 | 415 | $responseJS = '(function() { |
| 416 | 416 | OCA.Theming = { |
| 417 | - name: ' . json_encode($this->themingDefaults->getName()) . ', |
|
| 418 | - url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
|
| 419 | - slogan: ' . json_encode($this->themingDefaults->getSlogan()) . ', |
|
| 420 | - color: ' . json_encode($this->themingDefaults->getColorPrimary()) . ', |
|
| 421 | - imprintUrl: ' . json_encode($this->themingDefaults->getImprintUrl()) . ', |
|
| 422 | - privacyUrl: ' . json_encode($this->themingDefaults->getPrivacyUrl()) . ', |
|
| 423 | - inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())) . ', |
|
| 424 | - cacheBuster: ' . json_encode($cacheBusterValue) . ' |
|
| 417 | + name: ' . json_encode($this->themingDefaults->getName()).', |
|
| 418 | + url: ' . json_encode($this->themingDefaults->getBaseUrl()).', |
|
| 419 | + slogan: ' . json_encode($this->themingDefaults->getSlogan()).', |
|
| 420 | + color: ' . json_encode($this->themingDefaults->getColorPrimary()).', |
|
| 421 | + imprintUrl: ' . json_encode($this->themingDefaults->getImprintUrl()).', |
|
| 422 | + privacyUrl: ' . json_encode($this->themingDefaults->getPrivacyUrl()).', |
|
| 423 | + inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())).', |
|
| 424 | + cacheBuster: ' . json_encode($cacheBusterValue).' |
|
| 425 | 425 | }; |
| 426 | 426 | })();'; |
| 427 | 427 | $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
@@ -444,13 +444,13 @@ discard block |
||
| 444 | 444 | [ |
| 445 | 445 | [ |
| 446 | 446 | 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
| 447 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 447 | + ['app' => $app]).'?v='.$cacheBusterValue, |
|
| 448 | 448 | 'type'=> 'image/png', |
| 449 | 449 | 'sizes'=> '128x128' |
| 450 | 450 | ], |
| 451 | 451 | [ |
| 452 | 452 | 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
| 453 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 453 | + ['app' => $app]).'?v='.$cacheBusterValue, |
|
| 454 | 454 | 'type' => 'image/svg+xml', |
| 455 | 455 | 'sizes' => '16x16' |
| 456 | 456 | ] |