Skip to content

Commit

Permalink
feat: add url path segments to iframe
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Stückler <[email protected]>
  • Loading branch information
pReya committed Oct 31, 2023
1 parent ce7df18 commit 45a599d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
return [
'routes' => [
['name' => 'site#showDefaultPage', 'url' => '/', 'verb' => 'GET'],
['name' => 'site#showPage', 'url' => '/{id}', 'verb' => 'GET'],
['name' => 'icon#uploadIcon', 'url' => '/icons', 'verb' => 'POST'],
['name' => 'icon#showIcon', 'url' => '/icons/{icon}', 'verb' => 'GET'],
['name' => 'icon#deleteIcon', 'url' => '/icons/{icon}', 'verb' => 'DELETE'],
['name' => 'site#showPage', 'url' => '/{id}/{path}', 'verb' => 'GET', 'requirements' => ['path' => '.*']],
],
'ocs' => [
['name' => 'API#get', 'url' => '/api/{apiVersion}', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']],
Expand Down
2 changes: 1 addition & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function registerSites(

$href = $site['url'];
if (!$site['redirect']) {
$href = $url->linkToRoute('external.site.showPage', ['id' => $site['id']]);
$href = $url->linkToRoute('external.site.showPage', ['id' => $site['id'], 'path' => '']);
}

return [
Expand Down
2 changes: 1 addition & 1 deletion lib/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function generateImageLink(array $site): string {

protected function getHref(array $site): string {
if (!$site['redirect']) {
return $this->urlGenerator->linkToRoute('external.site.showPage', ['id' => $site['id']]);
return $this->urlGenerator->linkToRoute('external.site.showPage', ['id' => $site['id'], 'path' => '']);
}

return $site['url'];
Expand Down
13 changes: 9 additions & 4 deletions lib/Controller/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public function __construct(string $appName,
*
* @return TemplateResponse|RedirectResponse
*/
public function showPage(int $id) {
public function showPage(int $id, string $path) {
try {
$site = $this->sitesManager->getSiteById($id);
return $this->createResponse($id, $site);
return $this->createResponse($id, $site, $path);
} catch (SiteNotFoundException $e) {
return new RedirectResponse($this->url->linkToDefaultPageUrl());
}
Expand Down Expand Up @@ -100,11 +100,16 @@ public function showDefaultPage() {
return new RedirectResponse($this->url->getAbsoluteURL('/index.php/apps/files/'));
}

protected function createResponse(int $id, array $site): TemplateResponse {
protected function createResponse(int $id, array $site, string $path = ''): TemplateResponse {
$this->navigationManager->setActiveEntry('external_index' . $id);

if ($path !== '') {
// Check whether we need to suffix the site URL with a slash, or not.
$path = $site['url'][-1] == '/' ? $path : '/' . $path;
}

$response = new TemplateResponse('external', 'frame', [
'url' => $site['url'],
'url' => $site['url'] . $path,
'name' => $site['name'],
], 'user');

Expand Down
2 changes: 1 addition & 1 deletion lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getForm() {

$url = $quotaLink['url'];
if (!$quotaLink['redirect']) {
$url = $this->url->linkToRoute('external.site.showPage', ['id' => $quotaLink['id']]);
$url = $this->url->linkToRoute('external.site.showPage', ['id' => $quotaLink['id'], 'path' => '']);
}

return new TemplateResponse('external', 'quota', [
Expand Down
1 change: 1 addition & 0 deletions templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<h2><?php p($l->t('External sites'));?></h2>
<p class="settings-hint"><?php p($l->t('Add a website directly to the app list in the top bar. This will be visible for all users and is useful to quickly reach other internally used web apps or important sites.')); ?></p>
<p class="settings-hint"><?php p($l->t('The placeholders {email}, {uid} and {displayname} can be used and are filled with the user´s values to customize the links.')); ?></p>
<p class="settings-hint"><?php p($l->t("When accessing the external site through the Nextcloud link, path parameters will be forwarded to the external site. So you can also create deep links (e.g. 'mycloud.com/external/1/pageA' will lead to Nextcloud with the iframe pointed at 'externalsite.com/pageA').")); ?></p>
<p class="settings-hint"><?php print_unescaped(str_replace(
['{linkstart}', '{linkend}'],
['<a target="_blank" class="external" href="https://github.com/nextcloud/external/blob/master/docs/jwt-sample.php" rel="noreferrer nofollow">', ' ↗</a>'],
Expand Down

0 comments on commit 45a599d

Please sign in to comment.