summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-01-29 12:52:40 +0100
committerJulius Härtl <jus@bitgrid.net>2018-02-12 17:22:32 +0100
commit8ecac5654323e5d335386874f01b15d680d0febb (patch)
treeca25c200b0e5eb42cc9de1a00e10b3bb55817a27 /core
parent6211d18dc103dac3bea6e7cf1c05dca6a8ccf774 (diff)
downloadnextcloud-server-8ecac5654323e5d335386874f01b15d680d0febb.tar.gz
nextcloud-server-8ecac5654323e5d335386874f01b15d680d0febb.zip
Allow requesting absolute URLs
They might be useful when requesting the navigation from the clients Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'core')
-rw-r--r--core/Controller/NavigationController.php38
1 files changed, 33 insertions, 5 deletions
diff --git a/core/Controller/NavigationController.php b/core/Controller/NavigationController.php
index 5850025f450..98744171198 100644
--- a/core/Controller/NavigationController.php
+++ b/core/Controller/NavigationController.php
@@ -26,34 +26,62 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\INavigationManager;
use OCP\IRequest;
+use OCP\IURLGenerator;
class NavigationController extends Controller {
/** @var INavigationManager */
private $navigationManager;
- public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager) {
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
+ public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager, IURLGenerator $urlGenerator) {
parent::__construct($appName, $request);
$this->navigationManager = $navigationManager;
+ $this->urlGenerator = $urlGenerator;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
+ * @param bool $absolute
* @return JSONResponse
*/
- public function getAppsNavigation($absolute = false) {
- return new JSONResponse($this->navigationManager->getAll('link', $absolute));
+ public function getAppsNavigation(bool $absolute = false) {
+ $navigation = $this->navigationManager->getAll('link');
+ if ($absolute) {
+ $this->rewriteToAbsoluteUrls($navigation);
+ }
+ return new JSONResponse($navigation);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
+ * @param bool $absolute
* @return JSONResponse
*/
- public function getSettingsNavigation($absolute = false) {
- return new JSONResponse($this->navigationManager->getAll('settings', $absolute));
+ public function getSettingsNavigation(bool $absolute = false) {
+ $navigation = $this->navigationManager->getAll('settings');
+ if ($absolute) {
+ $this->rewriteToAbsoluteUrls($navigation);
+ }
+ return new JSONResponse($navigation);
+ }
+
+ /**
+ * Rewrite href attribute of navigation entries to an absolute URL
+ *
+ * @param array $navigation
+ */
+ private function rewriteToAbsoluteUrls(array &$navigation) {
+ foreach ($navigation as &$entry) {
+ if (substr($entry['href'], 0, strlen($this->urlGenerator->getBaseUrl())) !== $this->urlGenerator->getBaseUrl()) {
+ $entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
+ }
+ }
}
}