Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
width: 20%;
}

.site-redirect-box {
padding: 8px 0;
}

#external .icon-more {
width: 16px;
height: 16px;
Expand All @@ -24,7 +28,8 @@
}

#external ul.external_sites li {
padding: 5px 0 10px;
margin-left: -5px;
padding: 5px 0 10px 5px;
}

#external ul.external_sites li.saving {
Expand Down
3 changes: 2 additions & 1 deletion js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
e.preventDefault();

var $el = $(self._compiledTemplate({
id: 'undefined',
id: 'new-' + Date.now(),
name: t('external', 'New site'),
icon: 'external.svg',
type: 'link',
Expand Down Expand Up @@ -183,6 +183,7 @@
lang: $site.find('.site-lang').val(),
type: $site.find('.site-type').val(),
device: $site.find('.site-device').val(),
redirect: $site.find('.site-redirect').prop("checked") ? 1 : 0,
icon: $site.find('.site-icon').val()
};

Expand Down
14 changes: 12 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ public function registerNavigationEntries(IServerContainer $server, array $sites
} catch (\RuntimeException $e) {
$image = $url->imagePath('external', 'external.svg');
}

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

return [
'id' => 'external_index' . $site['id'],
'order' => 80 + $site['id'],
'href' => $url->linkToRoute('external.site.showPage', ['id'=> $site['id']]),
'href' => $href,
'icon' => $image,
'type' => $site['type'],
'name' => $site['name'],
Expand All @@ -88,7 +94,11 @@ public function registerPersonalPage(IServerContainer $server, array $sites) {
$url = $server->getURLGenerator();

$hiddenFields = $event->getArgument('hiddenFields');
$hiddenFields['external_quota_link'] = $url->linkToRoute('external.site.showPage', ['id'=> $site['id']]);

$hiddenFields['external_quota_link'] = $site['url'];
if (!$site['redirect']) {
$hiddenFields['external_quota_link'] = $url->linkToRoute('external.site.showPage', ['id'=> $site['id']]);
}
$hiddenFields['external_quota_name'] = $site['name'];
$event->setArgument('hiddenFields', $hiddenFields);

Expand Down
10 changes: 6 additions & 4 deletions lib/Controller/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ public function getAdmin() {
* @param string $type
* @param string $device
* @param string $icon
* @param int $redirect
* @return DataResponse
*/
public function add($name, $url, $lang, $type, $device, $icon) {
public function add($name, $url, $lang, $type, $device, $icon, $redirect) {
try {
return new DataResponse($this->sitesManager->addSite($name, $url, $lang, $type, $device, $icon));
return new DataResponse($this->sitesManager->addSite($name, $url, $lang, $type, $device, $icon, (bool) $redirect));
} catch (InvalidNameException $e) {
return new DataResponse(['error' => $this->l->t('The given label is invalid'), 'field' => 'name'], Http::STATUS_BAD_REQUEST);
} catch (InvalidURLException $e) {
Expand All @@ -157,11 +158,12 @@ public function add($name, $url, $lang, $type, $device, $icon) {
* @param string $type
* @param string $device
* @param string $icon
* @param int $redirect
* @return DataResponse
*/
public function update($id, $name, $url, $lang, $type, $device, $icon) {
public function update($id, $name, $url, $lang, $type, $device, $icon, $redirect) {
try {
return new DataResponse($this->sitesManager->updateSite($id, $name, $url, $lang, $type, $device, $icon));
return new DataResponse($this->sitesManager->updateSite($id, $name, $url, $lang, $type, $device, $icon, (bool) $redirect));
} catch (SiteNotFoundException $e) {
return new DataResponse(['error' => $this->l->t('The site does not exist'), 'field' => 'site'], Http::STATUS_NOT_FOUND);
} catch (InvalidNameException $e) {
Expand Down
7 changes: 6 additions & 1 deletion lib/Controller/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ public function renderQuotaLink() {
}
}

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

return new TemplateResponse('external', 'quota', [
'quotaLink' => $this->url->linkToRoute('external.site.showPage', ['id'=> $quotaLink['id']]),
'quotaLink' => $url,
'quotaName' => $quotaLink['name'],
], '');
}
Expand Down
9 changes: 7 additions & 2 deletions lib/SitesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ protected function fillSiteArray(array $site) {
'lang' => '',
'type' => self::TYPE_LINK,
'device' => self::DEVICE_ALL,
'redirect' => false,
],
$site
);
Expand All @@ -147,6 +148,7 @@ protected function fillSiteArray(array $site) {
* @param string $type
* @param string $device
* @param string $icon
* @param bool $redirect
* @return array
* @throws InvalidNameException
* @throws InvalidURLException
Expand All @@ -155,7 +157,7 @@ protected function fillSiteArray(array $site) {
* @throws InvalidDeviceException
* @throws IconNotFoundException
*/
public function addSite($name, $url, $lang, $type, $device, $icon) {
public function addSite($name, $url, $lang, $type, $device, $icon, $redirect) {
$id = 1 + (int) $this->config->getAppValue('external', 'max_site', 0);

if ($name === '') {
Expand Down Expand Up @@ -206,6 +208,7 @@ public function addSite($name, $url, $lang, $type, $device, $icon) {
'type' => $type,
'device' => $device,
'icon' => $icon,
'redirect' => $redirect,
];
$this->config->setAppValue('external', 'sites', json_encode($sites));
$this->config->setAppValue('external', 'max_site', $id);
Expand All @@ -221,6 +224,7 @@ public function addSite($name, $url, $lang, $type, $device, $icon) {
* @param string $type
* @param string $device
* @param string $icon
* @param bool $redirect
* @return array
* @throws SiteNotFoundException
* @throws InvalidNameException
Expand All @@ -230,7 +234,7 @@ public function addSite($name, $url, $lang, $type, $device, $icon) {
* @throws InvalidDeviceException
* @throws IconNotFoundException
*/
public function updateSite($id, $name, $url, $lang, $type, $device, $icon) {
public function updateSite($id, $name, $url, $lang, $type, $device, $icon, $redirect) {
$sites = $this->getSites();
if (!isset($sites[$id])) {
throw new SiteNotFoundException();
Expand Down Expand Up @@ -283,6 +287,7 @@ public function updateSite($id, $name, $url, $lang, $type, $device, $icon) {
'type' => $type,
'device' => $device,
'icon' => $icon,
'redirect' => $redirect,
];
$this->config->setAppValue('external', 'sites', json_encode($sites));

Expand Down
9 changes: 9 additions & 0 deletions templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
</label>
</div>

<div class="site-redirect-box">
<label>
<span><?php p($l->t('Redirect')) ?></span>
<input type="checkbox" id="site_redirect_{{id}}" name="site_redirect_{{id}}"
value="1" class="site-redirect checkbox trigger-save" {{#if redirect}} checked="checked"{{/if}} />
<label for="site_redirect_{{id}}"><?php p($l->t('This site does not allow embeding')) ?></label>
</label>
</div>

<div class="button delete-button"><?php p($l->t('Remove site')); ?></div>
</div>
</li>
Expand Down