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 30, 2023
1 parent ce7df18 commit 7efa53e
Show file tree
Hide file tree
Showing 5 changed files with 13 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

0 comments on commit 7efa53e

Please sign in to comment.