@@ -38,139 +38,139 @@ |
||
| 38 | 38 | use OCP\IRequest; |
| 39 | 39 | |
| 40 | 40 | class IconController extends Controller { |
| 41 | - /** @var ThemingDefaults */ |
|
| 42 | - private $themingDefaults; |
|
| 43 | - /** @var IconBuilder */ |
|
| 44 | - private $iconBuilder; |
|
| 45 | - /** @var ImageManager */ |
|
| 46 | - private $imageManager; |
|
| 47 | - /** @var FileAccessHelper */ |
|
| 48 | - private $fileAccessHelper; |
|
| 41 | + /** @var ThemingDefaults */ |
|
| 42 | + private $themingDefaults; |
|
| 43 | + /** @var IconBuilder */ |
|
| 44 | + private $iconBuilder; |
|
| 45 | + /** @var ImageManager */ |
|
| 46 | + private $imageManager; |
|
| 47 | + /** @var FileAccessHelper */ |
|
| 48 | + private $fileAccessHelper; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * IconController constructor. |
|
| 52 | - * |
|
| 53 | - * @param string $appName |
|
| 54 | - * @param IRequest $request |
|
| 55 | - * @param ThemingDefaults $themingDefaults |
|
| 56 | - * @param IconBuilder $iconBuilder |
|
| 57 | - * @param ImageManager $imageManager |
|
| 58 | - * @param FileAccessHelper $fileAccessHelper |
|
| 59 | - */ |
|
| 60 | - public function __construct( |
|
| 61 | - $appName, |
|
| 62 | - IRequest $request, |
|
| 63 | - ThemingDefaults $themingDefaults, |
|
| 64 | - IconBuilder $iconBuilder, |
|
| 65 | - ImageManager $imageManager, |
|
| 66 | - FileAccessHelper $fileAccessHelper |
|
| 67 | - ) { |
|
| 68 | - parent::__construct($appName, $request); |
|
| 50 | + /** |
|
| 51 | + * IconController constructor. |
|
| 52 | + * |
|
| 53 | + * @param string $appName |
|
| 54 | + * @param IRequest $request |
|
| 55 | + * @param ThemingDefaults $themingDefaults |
|
| 56 | + * @param IconBuilder $iconBuilder |
|
| 57 | + * @param ImageManager $imageManager |
|
| 58 | + * @param FileAccessHelper $fileAccessHelper |
|
| 59 | + */ |
|
| 60 | + public function __construct( |
|
| 61 | + $appName, |
|
| 62 | + IRequest $request, |
|
| 63 | + ThemingDefaults $themingDefaults, |
|
| 64 | + IconBuilder $iconBuilder, |
|
| 65 | + ImageManager $imageManager, |
|
| 66 | + FileAccessHelper $fileAccessHelper |
|
| 67 | + ) { |
|
| 68 | + parent::__construct($appName, $request); |
|
| 69 | 69 | |
| 70 | - $this->themingDefaults = $themingDefaults; |
|
| 71 | - $this->iconBuilder = $iconBuilder; |
|
| 72 | - $this->imageManager = $imageManager; |
|
| 73 | - $this->fileAccessHelper = $fileAccessHelper; |
|
| 74 | - } |
|
| 70 | + $this->themingDefaults = $themingDefaults; |
|
| 71 | + $this->iconBuilder = $iconBuilder; |
|
| 72 | + $this->imageManager = $imageManager; |
|
| 73 | + $this->fileAccessHelper = $fileAccessHelper; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @PublicPage |
|
| 78 | - * @NoCSRFRequired |
|
| 79 | - * |
|
| 80 | - * @param $app string app name |
|
| 81 | - * @param $image string image file name (svg required) |
|
| 82 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 83 | - * @throws \Exception |
|
| 84 | - */ |
|
| 85 | - public function getThemedIcon(string $app, string $image): Response { |
|
| 86 | - try { |
|
| 87 | - $iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image)); |
|
| 88 | - } catch (NotFoundException $exception) { |
|
| 89 | - $icon = $this->iconBuilder->colorSvg($app, $image); |
|
| 90 | - if ($icon === false || $icon === '') { |
|
| 91 | - return new NotFoundResponse(); |
|
| 92 | - } |
|
| 93 | - $iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon); |
|
| 94 | - } |
|
| 95 | - if ($iconFile !== false) { |
|
| 96 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
| 97 | - $response->cacheFor(86400); |
|
| 98 | - return $response; |
|
| 99 | - } |
|
| 76 | + /** |
|
| 77 | + * @PublicPage |
|
| 78 | + * @NoCSRFRequired |
|
| 79 | + * |
|
| 80 | + * @param $app string app name |
|
| 81 | + * @param $image string image file name (svg required) |
|
| 82 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 83 | + * @throws \Exception |
|
| 84 | + */ |
|
| 85 | + public function getThemedIcon(string $app, string $image): Response { |
|
| 86 | + try { |
|
| 87 | + $iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image)); |
|
| 88 | + } catch (NotFoundException $exception) { |
|
| 89 | + $icon = $this->iconBuilder->colorSvg($app, $image); |
|
| 90 | + if ($icon === false || $icon === '') { |
|
| 91 | + return new NotFoundResponse(); |
|
| 92 | + } |
|
| 93 | + $iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon); |
|
| 94 | + } |
|
| 95 | + if ($iconFile !== false) { |
|
| 96 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
| 97 | + $response->cacheFor(86400); |
|
| 98 | + return $response; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return new NotFoundResponse(); |
|
| 102 | - } |
|
| 101 | + return new NotFoundResponse(); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Return a 32x32 favicon as png |
|
| 106 | - * |
|
| 107 | - * @PublicPage |
|
| 108 | - * @NoCSRFRequired |
|
| 109 | - * |
|
| 110 | - * @param $app string app name |
|
| 111 | - * @return FileDisplayResponse|DataDisplayResponse |
|
| 112 | - * @throws \Exception |
|
| 113 | - */ |
|
| 114 | - public function getFavicon(string $app = 'core'): Response { |
|
| 115 | - $response = null; |
|
| 116 | - $iconFile = null; |
|
| 117 | - try { |
|
| 118 | - $iconFile = $this->imageManager->getImage('favicon'); |
|
| 119 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 120 | - } catch (NotFoundException $e) { |
|
| 121 | - } |
|
| 122 | - if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) { |
|
| 123 | - try { |
|
| 124 | - $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app); |
|
| 125 | - } catch (NotFoundException $exception) { |
|
| 126 | - $icon = $this->iconBuilder->getFavicon($app); |
|
| 127 | - $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon); |
|
| 128 | - } |
|
| 129 | - if ($iconFile !== false) { |
|
| 130 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if($response === null) { |
|
| 134 | - $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png'; |
|
| 135 | - $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 136 | - } |
|
| 137 | - $response->cacheFor(86400); |
|
| 138 | - return $response; |
|
| 139 | - } |
|
| 104 | + /** |
|
| 105 | + * Return a 32x32 favicon as png |
|
| 106 | + * |
|
| 107 | + * @PublicPage |
|
| 108 | + * @NoCSRFRequired |
|
| 109 | + * |
|
| 110 | + * @param $app string app name |
|
| 111 | + * @return FileDisplayResponse|DataDisplayResponse |
|
| 112 | + * @throws \Exception |
|
| 113 | + */ |
|
| 114 | + public function getFavicon(string $app = 'core'): Response { |
|
| 115 | + $response = null; |
|
| 116 | + $iconFile = null; |
|
| 117 | + try { |
|
| 118 | + $iconFile = $this->imageManager->getImage('favicon'); |
|
| 119 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 120 | + } catch (NotFoundException $e) { |
|
| 121 | + } |
|
| 122 | + if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) { |
|
| 123 | + try { |
|
| 124 | + $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app); |
|
| 125 | + } catch (NotFoundException $exception) { |
|
| 126 | + $icon = $this->iconBuilder->getFavicon($app); |
|
| 127 | + $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon); |
|
| 128 | + } |
|
| 129 | + if ($iconFile !== false) { |
|
| 130 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if($response === null) { |
|
| 134 | + $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png'; |
|
| 135 | + $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 136 | + } |
|
| 137 | + $response->cacheFor(86400); |
|
| 138 | + return $response; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Return a 512x512 icon for touch devices |
|
| 143 | - * |
|
| 144 | - * @PublicPage |
|
| 145 | - * @NoCSRFRequired |
|
| 146 | - * |
|
| 147 | - * @param $app string app name |
|
| 148 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 149 | - * @throws \Exception |
|
| 150 | - */ |
|
| 151 | - public function getTouchIcon(string $app = 'core'): Response { |
|
| 152 | - $response = null; |
|
| 153 | - try { |
|
| 154 | - $iconFile = $this->imageManager->getImage('favicon'); |
|
| 155 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 156 | - } catch (NotFoundException $e) { |
|
| 157 | - } |
|
| 158 | - if ($this->themingDefaults->shouldReplaceIcons()) { |
|
| 159 | - try { |
|
| 160 | - $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app); |
|
| 161 | - } catch (NotFoundException $exception) { |
|
| 162 | - $icon = $this->iconBuilder->getTouchIcon($app); |
|
| 163 | - $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon); |
|
| 164 | - } |
|
| 165 | - if ($iconFile !== false) { |
|
| 166 | - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - if($response === null) { |
|
| 170 | - $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png'; |
|
| 171 | - $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']); |
|
| 172 | - } |
|
| 173 | - $response->cacheFor(86400); |
|
| 174 | - return $response; |
|
| 175 | - } |
|
| 141 | + /** |
|
| 142 | + * Return a 512x512 icon for touch devices |
|
| 143 | + * |
|
| 144 | + * @PublicPage |
|
| 145 | + * @NoCSRFRequired |
|
| 146 | + * |
|
| 147 | + * @param $app string app name |
|
| 148 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 149 | + * @throws \Exception |
|
| 150 | + */ |
|
| 151 | + public function getTouchIcon(string $app = 'core'): Response { |
|
| 152 | + $response = null; |
|
| 153 | + try { |
|
| 154 | + $iconFile = $this->imageManager->getImage('favicon'); |
|
| 155 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); |
|
| 156 | + } catch (NotFoundException $e) { |
|
| 157 | + } |
|
| 158 | + if ($this->themingDefaults->shouldReplaceIcons()) { |
|
| 159 | + try { |
|
| 160 | + $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app); |
|
| 161 | + } catch (NotFoundException $exception) { |
|
| 162 | + $icon = $this->iconBuilder->getTouchIcon($app); |
|
| 163 | + $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon); |
|
| 164 | + } |
|
| 165 | + if ($iconFile !== false) { |
|
| 166 | + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + if($response === null) { |
|
| 170 | + $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png'; |
|
| 171 | + $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']); |
|
| 172 | + } |
|
| 173 | + $response->cacheFor(86400); |
|
| 174 | + return $response; |
|
| 175 | + } |
|
| 176 | 176 | } |