OC.L10N.register( "files", { "Unknown error" : "Ukjend feil", "Unable to set upload directory." : "Klarte ikkje å endra opplastingsmappa.", "Invalid Token" : "Ugyldig token", "No file was uploaded. Unknown error" : "Ingen filer lasta opp. Ukjend feil", "There is no error, the file uploaded with success" : "Ingen feil, fila vart lasta opp", "The uploaded file exceeds the upload_max_filesize directive in php.ini: " : "Fila du lasta opp er større enn det «upload_max_filesize» i php.ini tillater: ", "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form" : "Den opplasta fila er større enn variabelen MAX_FILE_SIZE i HTML-skjemaet", "The uploaded file was only partially uploaded" : "Fila vart berre delvis lasta opp", "No file was uploaded" : "Ingen filer vart lasta opp", "Missing a temporary folder" : "Manglar ei mellombels mappe", "Failed to write to disk" : "Klarte ikkje skriva til disk", "Not enough storage available" : "Ikkje nok lagringsplass tilgjengeleg", "Upload failed. Could not find uploaded file" : "Feil ved opplasting. Klarte ikkje å finna opplasta fil.", "Upload failed. Could not get file info." : "Feil ved opplasting. Klarte ikkje å henta filinfo.", "Invalid directory." : "Ugyldig mappe.", "Files" : "Filer", "All files" : "Alle filer", "Home" : "Heime", "Close" : "Lukk", "Favorites" : "Favorittar", "Upload cancelled." : "Opplasting avbroten.", "Unable to upload {filename} as it is a directory or has 0 bytes" : "Klarte ikkje å lasta opp {filename} sidan det er ei mappe eller er 0 byte.", "Could not get result from server." : "Klarte ikkje å henta resultat frå tenaren.", "Uploading..." : "Lastar opp …", "File upload is in progress. Leaving the page now will cancel the upload." : "Fila lastar no opp. Viss du forlèt sida no vil opplastinga verta avbroten.", "Actions" : "Handlingar", "Download" : "Last ned", "Rename" : "Endra namn", "Delete" : "Slett", "Unshare" : "Udel", "Details" : "Detaljar", "Pending" : "Under vegs", "Name" : "Namn", "Size" : "Storleik", "Modified" : "Endra", "_%n folder_::_%n folders_" : ["%n mappe","%n mapper"], "_%n file_::_%n files_" : ["%n fil","%n filer"], "{dirs} and {files}" : "{dirs} og {files}", "_Uploading %n file_::_Uploading %n files_" : ["Lastar opp %n fil","Lastar opp %n filer"], "New" : "Ny", "File name cannot be empty." : "Filnamnet kan ikkje vera tomt.", "Your storage is full, files can not be updated or synced anymore!" : "Lagringa di er full, kan ikkje lenger oppdatera eller synkronisera!", "Your storage is almost full ({usedSpacePercent}%)" : "Lagringa di er nesten full ({usedSpacePercent} %)", "Favorite" : "Favoritt", "Folder" : "Mappe", "New folder" : "Ny mappe", "Upload" : "Last opp", "A new file or folder has been created" : "Ei ny fil eller mappe er oppretta", "A file or folder has been changed" : "Ei fil eller mappe er endra", "A file or folder has been deleted" : "Ei fil eller mappe er sletta", "You created %1$s" : "Du oppretta %1$s", "%2$s created %1$s" : "%2$s oppretta %1$s", "%1$s was created in a public folder" : "%1$s oppretta i ei offentleg mappe", "You changed %1$s" : "Du endra %1$s", "%2$s changed %1$s" : "%2$s endra %1$s", "You deleted %1$s" : "Du sletta %1$s", "%2$s deleted %1$s" : "%2$s sletta %1$s", "File handling" : "Filhandtering", "Maximum upload size" : "Maksimal opplastingsstorleik", "max. possible: " : "maks. moglege:", "Save" : "Lagre", "Settings" : "Innstillingar", "WebDAV" : "WebDAV", "Upload too large" : "For stor opplasting", "The files you are trying to upload exceed the maximum size for file uploads on this server." : "Filene du prøver å lasta opp er større enn maksgrensa til denne tenaren.", "Text file" : "Tekst fil" }, "nplurals=2; plural=(n != 1);"); stable29/48207'>artonge/backport/stable29/48207 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/core/Controller/NavigationController.php
blob: 62c4dd987567451aadbc2a030fbe3f69b4c6cdf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
 * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
 *
 * @author Julius Härtl <jus@bitgrid.net>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
namespace OC\Core\Controller;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IURLGenerator;

class NavigationController extends OCSController {
	public function __construct(
		string $appName,
		IRequest $request,
		private INavigationManager $navigationManager,
		private IURLGenerator $urlGenerator,
	) {
		parent::__construct($appName, $request);
	}

	/**
	 * @NoAdminRequired
	 * @NoCSRFRequired
	 */
	public function getAppsNavigation(bool $absolute = false): DataResponse {
		$navigation = $this->navigationManager->getAll();
		if ($absolute) {
			$navigation = $this->rewriteToAbsoluteUrls($navigation);
		}
		$navigation = array_values($navigation);
		$etag = $this->generateETag($navigation);
		if ($this->request->getHeader('If-None-Match') === $etag) {
			return new DataResponse([], Http::STATUS_NOT_MODIFIED);
		}
		$response = new DataResponse($navigation);
		$response->setETag($etag);
		return $response;
	}

	/**
	 * @NoAdminRequired
	 * @NoCSRFRequired
	 */
	public function getSettingsNavigation(bool $absolute = false): DataResponse {
		$navigation = $this->navigationManager->getAll('settings');
		if ($absolute) {
			$navigation = $this->rewriteToAbsoluteUrls($navigation);
		}
		$navigation = array_values($navigation);
		$etag = $this->generateETag($navigation);
		if ($this->request->getHeader('If-None-Match') === $etag) {
			return new DataResponse([], Http::STATUS_NOT_MODIFIED);
		}
		$response = new DataResponse($navigation);
		$response->setETag($etag);
		return $response;
	}

	/**
	 * Generate an ETag for a list of navigation entries
	 */
	private function generateETag(array $navigation): string {
		foreach ($navigation as &$nav) {
			if ($nav['id'] === 'logout') {
				$nav['href'] = 'logout';
			}
		}
		return md5(json_encode($navigation));
	}

	/**
	 * Rewrite href attribute of navigation entries to an absolute URL
	 */
	private function rewriteToAbsoluteUrls(array $navigation): array {
		foreach ($navigation as &$entry) {
			if (!str_starts_with($entry['href'], $this->urlGenerator->getBaseUrl())) {
				$entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
			}
			if (!str_starts_with($entry['icon'], $this->urlGenerator->getBaseUrl())) {
				$entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']);
			}
		}
		return $navigation;
	}
}