@@ -31,92 +31,92 @@ |
||
| 31 | 31 | |
| 32 | 32 | class NavigationController extends OCSController { |
| 33 | 33 | |
| 34 | - /** @var INavigationManager */ |
|
| 35 | - private $navigationManager; |
|
| 34 | + /** @var INavigationManager */ |
|
| 35 | + private $navigationManager; |
|
| 36 | 36 | |
| 37 | - /** @var IURLGenerator */ |
|
| 38 | - private $urlGenerator; |
|
| 37 | + /** @var IURLGenerator */ |
|
| 38 | + private $urlGenerator; |
|
| 39 | 39 | |
| 40 | - public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager, IURLGenerator $urlGenerator) { |
|
| 41 | - parent::__construct($appName, $request); |
|
| 42 | - $this->navigationManager = $navigationManager; |
|
| 43 | - $this->urlGenerator = $urlGenerator; |
|
| 44 | - } |
|
| 40 | + public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager, IURLGenerator $urlGenerator) { |
|
| 41 | + parent::__construct($appName, $request); |
|
| 42 | + $this->navigationManager = $navigationManager; |
|
| 43 | + $this->urlGenerator = $urlGenerator; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @NoAdminRequired |
|
| 48 | - * @NoCSRFRequired |
|
| 49 | - * |
|
| 50 | - * @param bool $absolute |
|
| 51 | - * @return DataResponse |
|
| 52 | - */ |
|
| 53 | - public function getAppsNavigation(bool $absolute = false): DataResponse { |
|
| 54 | - $navigation = $this->navigationManager->getAll(); |
|
| 55 | - if ($absolute) { |
|
| 56 | - $navigation = $this->rewriteToAbsoluteUrls($navigation); |
|
| 57 | - } |
|
| 58 | - $navigation = array_values($navigation); |
|
| 59 | - $etag = $this->generateETag($navigation); |
|
| 60 | - if ($this->request->getHeader('If-None-Match') === $etag) { |
|
| 61 | - return new DataResponse([], Http::STATUS_NOT_MODIFIED); |
|
| 62 | - } |
|
| 63 | - $response = new DataResponse($navigation); |
|
| 64 | - $response->setETag($etag); |
|
| 65 | - return $response; |
|
| 66 | - } |
|
| 46 | + /** |
|
| 47 | + * @NoAdminRequired |
|
| 48 | + * @NoCSRFRequired |
|
| 49 | + * |
|
| 50 | + * @param bool $absolute |
|
| 51 | + * @return DataResponse |
|
| 52 | + */ |
|
| 53 | + public function getAppsNavigation(bool $absolute = false): DataResponse { |
|
| 54 | + $navigation = $this->navigationManager->getAll(); |
|
| 55 | + if ($absolute) { |
|
| 56 | + $navigation = $this->rewriteToAbsoluteUrls($navigation); |
|
| 57 | + } |
|
| 58 | + $navigation = array_values($navigation); |
|
| 59 | + $etag = $this->generateETag($navigation); |
|
| 60 | + if ($this->request->getHeader('If-None-Match') === $etag) { |
|
| 61 | + return new DataResponse([], Http::STATUS_NOT_MODIFIED); |
|
| 62 | + } |
|
| 63 | + $response = new DataResponse($navigation); |
|
| 64 | + $response->setETag($etag); |
|
| 65 | + return $response; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @NoAdminRequired |
|
| 70 | - * @NoCSRFRequired |
|
| 71 | - * |
|
| 72 | - * @param bool $absolute |
|
| 73 | - * @return DataResponse |
|
| 74 | - */ |
|
| 75 | - public function getSettingsNavigation(bool $absolute = false): DataResponse { |
|
| 76 | - $navigation = $this->navigationManager->getAll('settings'); |
|
| 77 | - if ($absolute) { |
|
| 78 | - $navigation = $this->rewriteToAbsoluteUrls($navigation); |
|
| 79 | - } |
|
| 80 | - $navigation = array_values($navigation); |
|
| 81 | - $etag = $this->generateETag($navigation); |
|
| 82 | - if ($this->request->getHeader('If-None-Match') === $etag) { |
|
| 83 | - return new DataResponse([], Http::STATUS_NOT_MODIFIED); |
|
| 84 | - } |
|
| 85 | - $response = new DataResponse($navigation); |
|
| 86 | - $response->setETag($etag); |
|
| 87 | - return $response; |
|
| 88 | - } |
|
| 68 | + /** |
|
| 69 | + * @NoAdminRequired |
|
| 70 | + * @NoCSRFRequired |
|
| 71 | + * |
|
| 72 | + * @param bool $absolute |
|
| 73 | + * @return DataResponse |
|
| 74 | + */ |
|
| 75 | + public function getSettingsNavigation(bool $absolute = false): DataResponse { |
|
| 76 | + $navigation = $this->navigationManager->getAll('settings'); |
|
| 77 | + if ($absolute) { |
|
| 78 | + $navigation = $this->rewriteToAbsoluteUrls($navigation); |
|
| 79 | + } |
|
| 80 | + $navigation = array_values($navigation); |
|
| 81 | + $etag = $this->generateETag($navigation); |
|
| 82 | + if ($this->request->getHeader('If-None-Match') === $etag) { |
|
| 83 | + return new DataResponse([], Http::STATUS_NOT_MODIFIED); |
|
| 84 | + } |
|
| 85 | + $response = new DataResponse($navigation); |
|
| 86 | + $response->setETag($etag); |
|
| 87 | + return $response; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Generate an ETag for a list of navigation entries |
|
| 92 | - * |
|
| 93 | - * @param array $navigation |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - private function generateETag(array $navigation): string { |
|
| 97 | - foreach ($navigation as &$nav) { |
|
| 98 | - if ($nav['id'] === 'logout') { |
|
| 99 | - $nav['href'] = 'logout'; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - return md5(json_encode($navigation)); |
|
| 103 | - } |
|
| 90 | + /** |
|
| 91 | + * Generate an ETag for a list of navigation entries |
|
| 92 | + * |
|
| 93 | + * @param array $navigation |
|
| 94 | + * @return string |
|
| 95 | + */ |
|
| 96 | + private function generateETag(array $navigation): string { |
|
| 97 | + foreach ($navigation as &$nav) { |
|
| 98 | + if ($nav['id'] === 'logout') { |
|
| 99 | + $nav['href'] = 'logout'; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + return md5(json_encode($navigation)); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Rewrite href attribute of navigation entries to an absolute URL |
|
| 107 | - * |
|
| 108 | - * @param array $navigation |
|
| 109 | - * @return array |
|
| 110 | - */ |
|
| 111 | - private function rewriteToAbsoluteUrls(array $navigation): array { |
|
| 112 | - foreach ($navigation as &$entry) { |
|
| 113 | - if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) { |
|
| 114 | - $entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']); |
|
| 115 | - } |
|
| 116 | - if (0 !== strpos($entry['icon'], $this->urlGenerator->getBaseUrl())) { |
|
| 117 | - $entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - return $navigation; |
|
| 121 | - } |
|
| 105 | + /** |
|
| 106 | + * Rewrite href attribute of navigation entries to an absolute URL |
|
| 107 | + * |
|
| 108 | + * @param array $navigation |
|
| 109 | + * @return array |
|
| 110 | + */ |
|
| 111 | + private function rewriteToAbsoluteUrls(array $navigation): array { |
|
| 112 | + foreach ($navigation as &$entry) { |
|
| 113 | + if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) { |
|
| 114 | + $entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']); |
|
| 115 | + } |
|
| 116 | + if (0 !== strpos($entry['icon'], $this->urlGenerator->getBaseUrl())) { |
|
| 117 | + $entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + return $navigation; |
|
| 121 | + } |
|
| 122 | 122 | } |