aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-02-27 13:33:19 +0100
committerGitHub <noreply@github.com>2018-02-27 13:33:19 +0100
commit01f420c7ac38128c03975d7de7dd20190c4afcc1 (patch)
treeca9c599c93d8bd7c90237b9b90fe2fcb80808eae
parent017e1325f14d3cdbf8d16326f47d1aefa7eac4ea (diff)
parent36563d4a4b98cbd491b3832c29fee77e9f8b7118 (diff)
downloadnextcloud-server-01f420c7ac38128c03975d7de7dd20190c4afcc1.tar.gz
nextcloud-server-01f420c7ac38128c03975d7de7dd20190c4afcc1.zip
Merge pull request #8051 from nextcloud/public-template
Public page template response
-rw-r--r--apps/files_sharing/composer/composer/autoload_classmap.php2
-rw-r--r--apps/files_sharing/composer/composer/autoload_static.php2
-rw-r--r--apps/files_sharing/css/public.scss8
-rw-r--r--apps/files_sharing/lib/Controller/ShareController.php16
-rw-r--r--apps/files_sharing/lib/Template/ExternalShareMenuAction.php68
-rw-r--r--apps/files_sharing/lib/Template/LinkMenuAction.php54
-rw-r--r--apps/files_sharing/templates/public.php129
-rw-r--r--apps/files_sharing/tests/Controller/ShareControllerTest.php34
-rw-r--r--core/css/public.scss22
-rw-r--r--core/css/server.scss1
-rw-r--r--core/js/core.json1
-rw-r--r--core/js/public/publicpage.js29
-rw-r--r--core/templates/layout.public.php80
-rw-r--r--lib/composer/composer/autoload_classmap.php3
-rw-r--r--lib/composer/composer/autoload_static.php3
-rw-r--r--lib/private/Template/Base.php5
-rw-r--r--lib/private/TemplateLayout.php4
-rw-r--r--lib/private/legacy/template.php8
-rw-r--r--lib/public/AppFramework/Http/Template/IMenuAction.php64
-rw-r--r--lib/public/AppFramework/Http/Template/PublicTemplateResponse.php143
-rw-r--r--lib/public/AppFramework/Http/Template/SimpleMenuAction.php126
-rw-r--r--lib/public/AppFramework/Http/TemplateResponse.php2
-rw-r--r--tests/acceptance/features/bootstrap/FilesSharingAppContext.php2
-rw-r--r--tests/lib/AppFramework/Http/PublicTemplateResponseTest.php84
24 files changed, 781 insertions, 109 deletions
diff --git a/apps/files_sharing/composer/composer/autoload_classmap.php b/apps/files_sharing/composer/composer/autoload_classmap.php
index a68db3421b6..0388c7990ec 100644
--- a/apps/files_sharing/composer/composer/autoload_classmap.php
+++ b/apps/files_sharing/composer/composer/autoload_classmap.php
@@ -53,5 +53,7 @@ return array(
'OCA\\Files_Sharing\\ShareBackend\\Folder' => $baseDir . '/../lib/ShareBackend/Folder.php',
'OCA\\Files_Sharing\\SharedMount' => $baseDir . '/../lib/SharedMount.php',
'OCA\\Files_Sharing\\SharedStorage' => $baseDir . '/../lib/SharedStorage.php',
+ 'OCA\\Files_Sharing\\Template\\ExternalShareMenuAction' => $baseDir . '/../lib/Template/ExternalShareMenuAction.php',
+ 'OCA\\Files_Sharing\\Template\\LinkMenuAction' => $baseDir . '/../lib/Template/LinkMenuAction.php',
'OCA\\Files_Sharing\\Updater' => $baseDir . '/../lib/Updater.php',
);
diff --git a/apps/files_sharing/composer/composer/autoload_static.php b/apps/files_sharing/composer/composer/autoload_static.php
index 328d6aca01d..dd75dbaa18a 100644
--- a/apps/files_sharing/composer/composer/autoload_static.php
+++ b/apps/files_sharing/composer/composer/autoload_static.php
@@ -68,6 +68,8 @@ class ComposerStaticInitFiles_Sharing
'OCA\\Files_Sharing\\ShareBackend\\Folder' => __DIR__ . '/..' . '/../lib/ShareBackend/Folder.php',
'OCA\\Files_Sharing\\SharedMount' => __DIR__ . '/..' . '/../lib/SharedMount.php',
'OCA\\Files_Sharing\\SharedStorage' => __DIR__ . '/..' . '/../lib/SharedStorage.php',
+ 'OCA\\Files_Sharing\\Template\\ExternalShareMenuAction' => __DIR__ . '/..' . '/../lib/Template/ExternalShareMenuAction.php',
+ 'OCA\\Files_Sharing\\Template\\LinkMenuAction' => __DIR__ . '/..' . '/../lib/Template/LinkMenuAction.php',
'OCA\\Files_Sharing\\Updater' => __DIR__ . '/..' . '/../lib/Updater.php',
);
diff --git a/apps/files_sharing/css/public.scss b/apps/files_sharing/css/public.scss
index 5edc3f7eb90..1e9dec87fad 100644
--- a/apps/files_sharing/css/public.scss
+++ b/apps/files_sharing/css/public.scss
@@ -3,14 +3,6 @@
min-height: calc(100vh - 160px);
}
-#header .menutoggle {
- padding: 14px;
- padding-right: 40px;
- background-position: right 15px center;
- color: $color-primary-text;
- cursor: pointer;
-}
-
/* force layout to make sure the content element's height matches its contents' height */
.ie #content {
display: inline-block;
diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php
index 795d069c1b8..1f8864fc5f3 100644
--- a/apps/files_sharing/lib/Controller/ShareController.php
+++ b/apps/files_sharing/lib/Controller/ShareController.php
@@ -38,6 +38,10 @@ namespace OCA\Files_Sharing\Controller;
use OC_Files;
use OC_Util;
use OCA\FederatedFileSharing\FederatedShareProvider;
+use OCA\Files_Sharing\Template\ExternalShareMenuAction;
+use OCA\Files_Sharing\Template\LinkMenuAction;
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
+use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\Defaults;
use OCP\IL10N;
use OCP\Template;
@@ -435,7 +439,17 @@ class ShareController extends Controller {
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
- $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
+
+ $response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl);
+ $response->setHeaderTitle($shareTmpl['filename']);
+ $response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']]));
+ $response->setHeaderActions([
+ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $shareTmpl['downloadURL'], 0),
+ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']),
+ new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $shareTmpl['previewURL']),
+ new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $shareTmpl['owner'], $shareTmpl['displayName'], $shareTmpl['filename']),
+ ]);
+
$response->setContentSecurityPolicy($csp);
$this->emitAccessShareHook($share);
diff --git a/apps/files_sharing/lib/Template/ExternalShareMenuAction.php b/apps/files_sharing/lib/Template/ExternalShareMenuAction.php
new file mode 100644
index 00000000000..f548a3bc6f1
--- /dev/null
+++ b/apps/files_sharing/lib/Template/ExternalShareMenuAction.php
@@ -0,0 +1,68 @@
+<?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 OCA\Files_Sharing\Template;
+
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
+use OCP\Util;
+
+class ExternalShareMenuAction extends SimpleMenuAction {
+
+ /** @var string */
+ private $owner;
+
+ /** @var string */
+ private $displayname;
+
+ /** @var string */
+ private $shareName;
+
+ /**
+ * ExternalShareMenuAction constructor.
+ *
+ * @param string $label
+ * @param string $icon
+ * @param string $owner
+ * @param string $displayname
+ * @param string $shareName
+ */
+ public function __construct(string $label, string $icon, string $owner, string $displayname, string $shareName) {
+ parent::__construct('save', $label, $icon);
+ $this->owner = $owner;
+ $this->displayname = $displayname;
+ $this->shareName = $shareName;
+ }
+
+ public function render(): string {
+ return '<li>' .
+ '<a id="save" data-protected="false" data-owner-display-name="' . Util::sanitizeHTML($this->displayname) . '" data-owner="' . Util::sanitizeHTML($this->owner) . '" data-name="' . Util::sanitizeHTML($this->shareName) . '">' .
+ '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
+ '<span id="save-button">' . Util::sanitizeHTML($this->getLabel()) . '</span>' .
+ '<form class="save-form hidden" action="#">' .
+ '<input type="text" id="remote_address" placeholder="user@yourNextcloud.org">' .
+ '<button id="save-button-confirm" class="icon-confirm svg" disabled=""></button>' .
+ '</form>' .
+ '</a>' .
+ '</li>';
+ }
+} \ No newline at end of file
diff --git a/apps/files_sharing/lib/Template/LinkMenuAction.php b/apps/files_sharing/lib/Template/LinkMenuAction.php
new file mode 100644
index 00000000000..2fdf83e7026
--- /dev/null
+++ b/apps/files_sharing/lib/Template/LinkMenuAction.php
@@ -0,0 +1,54 @@
+<?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 OCA\Files_Sharing\Template;
+
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
+use OCP\Util;
+
+class LinkMenuAction extends SimpleMenuAction {
+
+ /**
+ * LinkMenuAction constructor.
+ *
+ * @param string $label
+ * @param string $icon
+ * @param string $link
+ */
+ public function __construct(string $label, string $icon, string $link) {
+ parent::__construct('directLink-container', $label, $icon, $link);
+ }
+
+ /**
+ * @return string
+ */
+ public function render(): string {
+ return '<li>' .
+ '<a id="directLink-container">' .
+ '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
+ '<label for="directLink">' . Util::sanitizeHTML($this->getLabel()) . '</label>' .
+ '<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' .
+ '</a>' .
+ '</li>';
+ }
+} \ No newline at end of file
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php
index 3c2bbe5fb59..698febd4c17 100644
--- a/apps/files_sharing/templates/public.php
+++ b/apps/files_sharing/templates/public.php
@@ -7,10 +7,6 @@
<link rel="image_src" href="<?php p($_['previewImage']); ?>" />
<?php endif; ?>
-<div id="notification-container">
- <div id="notification" style="display: none;"></div>
-</div>
-
<input type="hidden" id="sharingUserId" value="<?php p($_['owner']) ?>">
<input type="hidden" id="filesApp" name="filesApp" value="1">
<input type="hidden" id="isPublic" name="isPublic" value="1">
@@ -33,61 +29,9 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
<input type="hidden" name="filesize" value="<?php p($_['nonHumanFileSize']); ?>" id="filesize">
<?php endif; ?>
<input type="hidden" name="maxSizeAnimateGif" value="<?php p($_['maxSizeAnimateGif']); ?>" id="maxSizeAnimateGif">
-
-
-<header><div id="header" class="<?php p((isset($_['folder']) ? 'share-folder' : 'share-file')) ?>">
- <div class="header-left">
- <span id="nextcloud">
- <div class="logo logo-icon svg"></div>
- <h1 class="header-appname">
- <?php p($_['filename']); ?>
- </h1>
- <div class="header-shared-by">
- <?php echo p($l->t('shared by %s', [$_['displayName']])); ?>
- </div>
- </span>
- </div>
-
- <div class="header-right">
- <?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === false)) { ?>
- <a id="share-menutoggle" class="menutoggle icon-more-white"><span class="share-menutoggle-text"><?php p($l->t('Download')) ?></span></a>
- <div id="share-menu" class="popovermenu menu">
- <ul>
- <li>
- <a href="<?php p($_['downloadURL']); ?>" id="download">
- <span class="icon icon-download"></span>
- <?php p($l->t('Download'))?>&nbsp;<span class="download-size">(<?php p($_['fileSize']) ?>)</span>
- </a>
- </li>
- <li>
- <a id="directLink-container">
- <span class="icon icon-public"></span>
- <label for="directLink"><?php p($l->t('Direct link')) ?></label>
- <input id="directLink" type="text" readonly value="<?php p($_['previewURL']); ?>">
- </a>
- </li>
- <?php if ($_['server2serversharing']) { ?>
- <li>
- <a id="save" data-protected="<?php p($_['protected']) ?>"
- data-owner-display-name="<?php p($_['displayName']) ?>" data-owner="<?php p($_['owner']) ?>" data-name="<?php p($_['filename']) ?>">
- <span class="icon icon-external"></span>
- <span id="save-button"><?php p($l->t('Add to your Nextcloud')) ?></span>
- <form class="save-form hidden" action="#">
- <input type="text" id="remote_address" placeholder="user@yourNextcloud.org"/>
- <button id="save-button-confirm" class="icon-confirm svg" disabled></button>
- </form>
- </a>
- </li>
- <?php } ?>
- </ul>
- </div>
- <?php } ?>
- </div>
- </div></header>
-<div id="content-wrapper">
- <?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === false)) { ?>
+<?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] === false)) { ?>
<div id="content">
- <div id="preview">
+ <div id="preview">
<?php if (isset($_['folder'])): ?>
<?php print_unescaped($_['folder']); ?>
<?php else: ?>
@@ -102,46 +46,47 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
<div id="imgframe"></div>
<?php endif; ?>
<?php if ($_['previewURL'] === $_['downloadURL']): ?>
- <div class="directDownload">
- <a href="<?php p($_['downloadURL']); ?>" id="downloadFile" class="button">
- <span class="icon icon-download"></span>
- <?php p($l->t('Download %s', array($_['filename'])))?> (<?php p($_['fileSize']) ?>)
- </a>
- </div>
+ <div class="directDownload">
+ <a href="<?php p($_['downloadURL']); ?>" id="downloadFile" class="button">
+ <span class="icon icon-download"></span>
+ <?php p($l->t('Download %s', array($_['filename'])))?> (<?php p($_['fileSize']) ?>)
+ </a>
+ </div>
<?php endif; ?>
<?php endif; ?>
</div>
+ </div>
+<?php } else { ?>
+ <input type="hidden" id="upload-only-interface" value="1"/>
+ <div id="public-upload">
+ <div id="emptycontent" class="<?php if (!empty($_['disclaimer'])) { ?>has-disclaimer<?php } ?>">
+ <div id="displayavatar"><div class="avatardiv"></div></div>
+ <h2><?php p($l->t('Upload files to %s', [$_['shareOwner']])) ?></h2>
+ <p><span class="icon-folder"></span> <?php p($_['filename']) ?></p>
+ <?php if (!empty($_['disclaimer'])) { ?>
+ <p class="disclaimer"><?php p($_['disclaimer']); ?></p>
+ <?php } ?>
+ <input type="file" name="files[]" class="hidden" multiple>
+
+ <a href="#" class="button icon-upload"><?php p($l->t('Select or drop files')) ?></a>
+ <div id="drop-upload-progress-indicator" style="padding-top: 25px;" class="hidden"><?php p($l->t('Uploading files…')) ?></div>
+ <div id="drop-upload-done-indicator" style="padding-top: 25px;" class="hidden"><?php p($l->t('Uploaded files:')) ?></div>
+ <ul>
+ </ul>
</div>
- <?php } else { ?>
- <input type="hidden" id="upload-only-interface" value="1"/>
- <div id="public-upload">
- <div id="emptycontent" class="<?php if (!empty($_['disclaimer'])) { ?>has-disclaimer<?php } ?>">
- <div id="displayavatar"><div class="avatardiv"></div></div>
- <h2><?php p($l->t('Upload files to %s', [$_['shareOwner']])) ?></h2>
- <p><span class="icon-folder"></span> <?php p($_['filename']) ?></p>
- <?php if (!empty($_['disclaimer'])) { ?>
- <p class="disclaimer"><?php p($_['disclaimer']); ?></p>
- <?php } ?>
- <input type="file" name="files[]" class="hidden" multiple>
+ </div>
+<?php } ?>
- <a href="#" class="button icon-upload"><?php p($l->t('Select or drop files')) ?></a>
- <div id="drop-upload-progress-indicator" style="padding-top: 25px;" class="hidden"><?php p($l->t('Uploading files…')) ?></div>
- <div id="drop-upload-done-indicator" style="padding-top: 25px;" class="hidden"><?php p($l->t('Uploaded files:')) ?></div>
- <ul>
- </ul>
- </div>
- </div>
- <?php } ?>
<?php if (!isset($_['hideFileList']) || (isset($_['hideFileList']) && $_['hideFileList'] !== true)): ?>
<input type="hidden" name="dir" id="dir" value="" />
<div class="hiddenuploadfield">
- <input type="file" id="file_upload_start" class="hiddenuploadfield" name="files[]"
- data-url="<?php p(OCP\Util::linkTo('files', 'ajax/upload.php')); ?>" />
+ <input type="file" id="file_upload_start" class="hiddenuploadfield" name="files[]"
+ data-url="<?php p(OCP\Util::linkTo('files', 'ajax/upload.php')); ?>" />
</div>
- <?php endif; ?>
- <footer>
- <p class="info">
- <?php print_unescaped($theme->getLongFooter()); ?>
- </p>
- </footer>
-</div>
+<?php endif; ?>
+
+<footer>
+ <p class="info">
+ <?php print_unescaped($theme->getLongFooter()); ?>
+ </p>
+</footer>
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php
index 6062ff89065..6dc577a354c 100644
--- a/apps/files_sharing/tests/Controller/ShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php
@@ -34,7 +34,11 @@ namespace OCA\Files_Sharing\Tests\Controllers;
use OC\Files\Filesystem;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Sharing\Controller\ShareController;
+use OCA\Files_Sharing\Template\ExternalShareMenuAction;
+use OCA\Files_Sharing\Template\LinkMenuAction;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\Template\PublicTemplateResponse;
+use OCP\AppFramework\Http\Template\SimpleMenuAction;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
@@ -84,6 +88,8 @@ class ShareControllerTest extends \Test\TestCase {
private $federatedShareProvider;
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
private $eventDispatcher;
+ /** @var IL10N */
+ private $l10n;
protected function setUp() {
parent::setUp();
@@ -102,6 +108,7 @@ class ShareControllerTest extends \Test\TestCase {
$this->federatedShareProvider->expects($this->any())
->method('isIncomingServer2serverShareEnabled')->willReturn(true);
$this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->shareController = new \OCA\Files_Sharing\Controller\ShareController(
$this->appName,
@@ -117,7 +124,7 @@ class ShareControllerTest extends \Test\TestCase {
$this->getMockBuilder('\OCP\Files\IRootFolder')->getMock(),
$this->federatedShareProvider,
$this->eventDispatcher,
- $this->getMockBuilder(IL10N::class)->getMock(),
+ $this->l10n,
$this->getMockBuilder('\OCP\Defaults')->getMock()
);
@@ -348,6 +355,11 @@ class ShareControllerTest extends \Test\TestCase {
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
+ $this->urlGenerator->expects($this->at(0))
+ ->method('linkToRouteAbsolute')
+ ->with('files_sharing.sharecontroller.downloadShare', ['token' => 'token'])
+ ->willReturn('downloadURL');
+
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
$this->config->method('getSystemValue')
@@ -379,6 +391,12 @@ class ShareControllerTest extends \Test\TestCase {
->method('dispatch')
->with('OCA\Files_Sharing::loadAdditionalScripts');
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function($text, $parameters) {
+ return vsprintf($text, $parameters);
+ }));
+
$response = $this->shareController->showShare('token');
$sharedTmplParams = array(
'displayName' => 'ownerDisplay',
@@ -391,7 +409,7 @@ class ShareControllerTest extends \Test\TestCase {
'server2serversharing' => true,
'protected' => 'true',
'dir' => '',
- 'downloadURL' => null,
+ 'downloadURL' => 'downloadURL',
'fileSize' => '33 B',
'nonHumanFileSize' => 33,
'maxSizeAnimateGif' => 10,
@@ -404,13 +422,21 @@ class ShareControllerTest extends \Test\TestCase {
'disclaimer' => 'My disclaimer text',
'shareUrl' => null,
'previewImage' => null,
- 'previewURL' => null,
+ 'previewURL' => 'downloadURL',
);
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
- $expectedResponse = new TemplateResponse($this->appName, 'public', $sharedTmplParams, 'base');
+ $expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams);
$expectedResponse->setContentSecurityPolicy($csp);
+ $expectedResponse->setHeaderTitle($sharedTmplParams['filename']);
+ $expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']);
+ $expectedResponse->setHeaderActions([
+ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $sharedTmplParams['downloadURL'], 0),
+ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $sharedTmplParams['downloadURL'], 10, $sharedTmplParams['fileSize']),
+ new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $sharedTmplParams['previewURL']),
+ new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $sharedTmplParams['owner'], $sharedTmplParams['displayName'], $sharedTmplParams['filename']),
+ ]);
$this->assertEquals($expectedResponse, $response);
}
diff --git a/core/css/public.scss b/core/css/public.scss
new file mode 100644
index 00000000000..3651e701c34
--- /dev/null
+++ b/core/css/public.scss
@@ -0,0 +1,22 @@
+#body-public {
+ .header-right {
+
+ span:not(.popovermenu) a {
+ color: $color-primary-text;
+ }
+
+ .menutoggle,
+ #header-primary-action[class^='icon-'] {
+ padding: 14px;
+ padding-right: 40px;
+ background-position: right 15px center;
+ color: $color-primary-text;
+ cursor: pointer;
+ }
+
+ .menutoggle {
+ padding-right: 10px;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/core/css/server.scss b/core/css/server.scss
index 516220f2ad5..9b512038015 100644
--- a/core/css/server.scss
+++ b/core/css/server.scss
@@ -9,3 +9,4 @@
@import 'multiselect.scss';
@import 'mobile.scss';
@import 'tooltip.scss';
+@import 'public.scss'; \ No newline at end of file
diff --git a/core/js/core.json b/core/js/core.json
index 6cf6a2489ed..9da91a7f639 100644
--- a/core/js/core.json
+++ b/core/js/core.json
@@ -46,6 +46,7 @@
"config.js",
"public/appconfig.js",
"public/comments.js",
+ "public/publicpage.js",
"multiselect.js",
"oc-requesttoken.js",
"setupchecks.js",
diff --git a/core/js/public/publicpage.js b/core/js/public/publicpage.js
new file mode 100644
index 00000000000..31b862ba12a
--- /dev/null
+++ b/core/js/public/publicpage.js
@@ -0,0 +1,29 @@
+/*
+ * @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/>.
+ *
+ */
+
+$(document).ready(function () {
+
+ console.log('public');
+ $('#body-public .header-right .menutoggle').click(function() {
+ $(this).next('.popovermenu').toggleClass('open');
+ });
+});
diff --git a/core/templates/layout.public.php b/core/templates/layout.public.php
new file mode 100644
index 00000000000..b9451fe05a2
--- /dev/null
+++ b/core/templates/layout.public.php
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html class="ng-csp" data-placeholder-focus="false" lang="<?php p($_['language']); ?>" >
+<head data-user="<?php p($_['user_uid']); ?>" data-user-displayname="<?php p($_['user_displayname']); ?>" data-requesttoken="<?php p($_['requesttoken']); ?>">
+ <meta charset="utf-8">
+ <title>
+ <?php
+ p(!empty($_['application'])?$_['application'].' - ':'');
+ p($theme->getTitle());
+ ?>
+ </title>
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="referrer" content="never">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
+ <meta name="apple-itunes-app" content="app-id=<?php p($theme->getiTunesAppId()); ?>">
+ <meta name="apple-mobile-web-app-capable" content="yes">
+ <meta name="apple-mobile-web-app-status-bar-style" content="black">
+ <meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid']!='files')? $_['application']:$theme->getTitle()); ?>">
+ <meta name="mobile-web-app-capable" content="yes">
+ <meta name="theme-color" content="<?php p($theme->getColorPrimary()); ?>">
+ <link rel="icon" href="<?php print_unescaped(image_path($_['appid'], 'favicon.ico')); /* IE11+ supports png */ ?>">
+ <link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path($_['appid'], 'favicon-touch.png')); ?>">
+ <link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path($_['appid'], 'favicon-mask.svg')); ?>" color="<?php p($theme->getColorPrimary()); ?>">
+ <link rel="manifest" href="<?php print_unescaped(image_path($_['appid'], 'manifest.json')); ?>">
+ <?php emit_css_loading_tags($_); ?>
+ <?php emit_script_loading_tags($_); ?>
+ <?php print_unescaped($_['headers']); ?>
+</head>
+<body id="<?php p($_['bodyid']);?>">
+<?php include('layout.noscript.warning.php'); ?>
+<header>
+ <div id="header" class="<?php p($_['header-classes']); ?>">
+ <div class="header-left">
+ <span id="nextcloud">
+ <div class="logo logo-icon svg"></div>
+ <h1 class="header-appname">
+ <?php p($template->getHeaderTitle()); ?>
+ </h1>
+ <div class="header-shared-by">
+ <?php p($template->getHeaderDetails()) ?>
+ </div>
+ </span>
+ </div>
+
+ <?php
+ /** @var \OCP\AppFramework\Http\Template\PublicTemplateResponse $template */
+ if($template->getActionCount() !== 0) {
+ $primary = $template->getPrimaryAction();
+ $others = $template->getOtherActions();
+ ?>
+ <div class="header-right">
+ <span id="header-primary-action" class="<?php if($template->getActionCount() === 1) { p($primary->getIcon()); } ?>">
+ <a href="<?php p($primary->getLink()); ?>">
+ <span class="share-menutoggle-text"><?php p($primary->getLabel()) ?></span>
+ </a>
+ </span>
+ <?php if($template->getActionCount()>1) { ?>
+ <span id="header-actions-toggle" class="menutoggle icon-more-white"></span>
+ <div id="share-menu" class="popovermenu menu">
+ <ul>
+ <?php
+ /** @var \OCP\AppFramework\Http\Template\IMenuAction $action */
+ foreach($template->getOtherActions() as $action) {
+ print_unescaped($action->render());
+ }
+ ?>
+ </ul>
+ </div>
+ <?php } ?>
+ </div>
+ <?php } ?>
+ </div>
+</header>
+<div id="content-wrapper">
+ <div id="content" class="app-<?php p($_['appid']) ?>" role="main">
+ <?php print_unescaped($_['content']); ?>
+ </div>
+</div>
+
+</body>
+</html>
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index b3158ac7e04..68be5e2d595 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -40,6 +40,9 @@ return array(
'OCP\\AppFramework\\Http\\Response' => $baseDir . '/lib/public/AppFramework/Http/Response.php',
'OCP\\AppFramework\\Http\\StreamResponse' => $baseDir . '/lib/public/AppFramework/Http/StreamResponse.php',
'OCP\\AppFramework\\Http\\TemplateResponse' => $baseDir . '/lib/public/AppFramework/Http/TemplateResponse.php',
+ 'OCP\\AppFramework\\Http\\Template\\IMenuAction' => $baseDir . '/lib/public/AppFramework/Http/Template/IMenuAction.php',
+ 'OCP\\AppFramework\\Http\\Template\\PublicTemplateResponse' => $baseDir . '/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php',
+ 'OCP\\AppFramework\\Http\\Template\\SimpleMenuAction' => $baseDir . '/lib/public/AppFramework/Http/Template/SimpleMenuAction.php',
'OCP\\AppFramework\\IAppContainer' => $baseDir . '/lib/public/AppFramework/IAppContainer.php',
'OCP\\AppFramework\\Middleware' => $baseDir . '/lib/public/AppFramework/Middleware.php',
'OCP\\AppFramework\\OCSController' => $baseDir . '/lib/public/AppFramework/OCSController.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 65b36cc489e..81f21f31c21 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -70,6 +70,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\AppFramework\\Http\\Response' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Response.php',
'OCP\\AppFramework\\Http\\StreamResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/StreamResponse.php',
'OCP\\AppFramework\\Http\\TemplateResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/TemplateResponse.php',
+ 'OCP\\AppFramework\\Http\\Template\\IMenuAction' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Template/IMenuAction.php',
+ 'OCP\\AppFramework\\Http\\Template\\PublicTemplateResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php',
+ 'OCP\\AppFramework\\Http\\Template\\SimpleMenuAction' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Template/SimpleMenuAction.php',
'OCP\\AppFramework\\IAppContainer' => __DIR__ . '/../../..' . '/lib/public/AppFramework/IAppContainer.php',
'OCP\\AppFramework\\Middleware' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Middleware.php',
'OCP\\AppFramework\\OCSController' => __DIR__ . '/../../..' . '/lib/public/AppFramework/OCSController.php',
diff --git a/lib/private/Template/Base.php b/lib/private/Template/Base.php
index 18cf6324089..09be5ab7ddf 100644
--- a/lib/private/Template/Base.php
+++ b/lib/private/Template/Base.php
@@ -166,8 +166,11 @@ class Base {
$l = $this->l10n;
$theme = $this->theme;
- if( !is_null($additionalParams)) {
+ if(!is_null($additionalParams)) {
$_ = array_merge( $additionalParams, $this->vars );
+ foreach ($_ as $var => $value) {
+ ${$var} = $value;
+ }
}
// Include
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 8cc235bf818..eb8477ca9e9 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -123,6 +123,10 @@ class TemplateLayout extends \OC_Template {
} else if ($renderAs == 'guest') {
parent::__construct('core', 'layout.guest');
$this->assign('bodyid', 'body-login');
+ } else if ($renderAs == 'public') {
+ parent::__construct('core', 'layout.public');
+ $this->assign( 'appid', $appId );
+ $this->assign('bodyid', 'body-public');
} else {
parent::__construct('core', 'layout.base');
diff --git a/lib/private/legacy/template.php b/lib/private/legacy/template.php
index c5279bff6b8..a362b581fe2 100644
--- a/lib/private/legacy/template.php
+++ b/lib/private/legacy/template.php
@@ -206,6 +206,12 @@ class OC_Template extends \OC\Template\Base {
if( $this->renderAs ) {
$page = new TemplateLayout($this->renderAs, $this->app);
+ if(is_array($additionalParams)) {
+ foreach ($additionalParams as $key => $value) {
+ $page->assign($key, $value);
+ }
+ }
+
// Add custom headers
$headers = '';
foreach(OC_Util::$headers as $header) {
@@ -226,7 +232,7 @@ class OC_Template extends \OC\Template\Base {
$page->assign('headers', $headers);
$page->assign('content', $data);
- return $page->fetchPage();
+ return $page->fetchPage($additionalParams);
}
return $data;
diff --git a/lib/public/AppFramework/Http/Template/IMenuAction.php b/lib/public/AppFramework/Http/Template/IMenuAction.php
new file mode 100644
index 00000000000..e42d2057981
--- /dev/null
+++ b/lib/public/AppFramework/Http/Template/IMenuAction.php
@@ -0,0 +1,64 @@
+<?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 OCP\AppFramework\Http\Template;
+
+/**
+ * Interface IMenuAction
+ *
+ * @package OCP\AppFramework\Http\Template
+ * @since 14.0
+ */
+interface IMenuAction {
+
+ /**
+ * @since 14.0.0
+ * @return string
+ */
+ public function getId(): string;
+
+ /**
+ * @since 14.0.0
+ * @return string
+ */
+ public function getLabel(): string;
+
+ /**
+ * @since 14.0.0
+ * @return string
+ */
+ public function getLink(): string;
+
+ /**
+ * @since 14.0.0
+ * @return int
+ */
+ public function getPriority(): int;
+
+ /**
+ * @since 14.0.0
+ * @return string
+ */
+ public function render(): string;
+
+} \ No newline at end of file
diff --git a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
new file mode 100644
index 00000000000..3409d5aae53
--- /dev/null
+++ b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
@@ -0,0 +1,143 @@
+<?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 OCP\AppFramework\Http\Template;
+
+use InvalidArgumentException;
+use OCP\AppFramework\Http\TemplateResponse;
+
+/**
+ * Class PublicTemplateResponse
+ *
+ * @package OCP\AppFramework\Http\Template
+ * @since 14.0.0
+ */
+class PublicTemplateResponse extends TemplateResponse {
+
+ private $headerTitle = '';
+ private $headerDetails = '';
+ private $headerActions = [];
+
+ /**
+ * PublicTemplateResponse constructor.
+ *
+ * @param string $appName
+ * @param string $templateName
+ * @param array $params
+ * @since 14.0.0
+ */
+ public function __construct(string $appName, string $templateName, array $params = array()) {
+ parent::__construct($appName, $templateName, $params, 'public');
+ \OC_Util::addScript('core', 'public/publicpage');
+ }
+
+ /**
+ * @param string $title
+ * @since 14.0.0
+ */
+ public function setHeaderTitle(string $title) {
+ $this->headerTitle = $title;
+ }
+
+ /**
+ * @return string
+ * @since 14.0.0
+ */
+ public function getHeaderTitle(): string {
+ return $this->headerTitle;
+ }
+
+ /**
+ * @param string $details
+ * @since 14.0.0
+ */
+ public function setHeaderDetails(string $details) {
+ $this->headerDetails = $details;
+ }
+
+ /**
+ * @return string
+ * @since 14.0.0
+ */
+ public function getHeaderDetails(): string {
+ return $this->headerDetails;
+ }
+
+ /**
+ * @param array $actions
+ * @since 14.0.0
+ * @throws InvalidArgumentException
+ */
+ public function setHeaderActions(array $actions) {
+ foreach ($actions as $action) {
+ if ($actions instanceof IMenuAction) {
+ throw new InvalidArgumentException('Actions must be of type IMenuAction');
+ }
+ $this->headerActions[] = $action;
+ }
+ usort($this->headerActions, function(IMenuAction $a, IMenuAction $b) {
+ return $a->getPriority() > $b->getPriority();
+ });
+ }
+
+ /**
+ * @return IMenuAction
+ * @since 14.0.0
+ * @throws \Exception
+ */
+ public function getPrimaryAction(): IMenuAction {
+ if ($this->getActionCount() > 0) {
+ return $this->headerActions[0];
+ }
+ throw new \Exception('No header actions have been set');
+ }
+
+ /**
+ * @return int
+ * @since 14.0.0
+ */
+ public function getActionCount(): int {
+ return count($this->headerActions);
+ }
+
+ /**
+ * @return IMenuAction[]
+ * @since 14.0.0
+ */
+ public function getOtherActions(): array {
+ return array_slice($this->headerActions, 1);
+ }
+
+ /**
+ * @return string
+ * @since 14.0.0
+ */
+ public function render(): string {
+ $params = array_merge($this->getParams(), [
+ 'template' => $this,
+ ]);
+ $this->setParams($params);
+ return parent::render();
+ }
+
+} \ No newline at end of file
diff --git a/lib/public/AppFramework/Http/Template/SimpleMenuAction.php b/lib/public/AppFramework/Http/Template/SimpleMenuAction.php
new file mode 100644
index 00000000000..60bb268661c
--- /dev/null
+++ b/lib/public/AppFramework/Http/Template/SimpleMenuAction.php
@@ -0,0 +1,126 @@
+<?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 OCP\AppFramework\Http\Template;
+
+use OCP\Util;
+
+/**
+ * Class SimpleMenuAction
+ *
+ * @package OCP\AppFramework\Http\Template
+ * @since 14.0.0
+ */
+class SimpleMenuAction implements IMenuAction {
+
+ /** @var string */
+ private $id;
+
+ /** @var string */
+ private $label;
+
+ /** @var string */
+ private $icon;
+
+ /** @var string */
+ private $link;
+
+ /** @var int */
+ private $priority;
+
+ /** @var string */
+ private $detail;
+
+ /**
+ * SimpleMenuAction constructor.
+ *
+ * @param string $id
+ * @param string $label
+ * @param string $icon
+ * @param string $link
+ * @param int $priority
+ * @param string $detail
+ * @since 14.0.0
+ */
+ public function __construct(string $id, string $label, string $icon, string $link = '', int $priority = 100, string $detail = '') {
+ $this->id = $id;
+ $this->label = $label;
+ $this->icon = $icon;
+ $this->link = $link;
+ $this->priority = $priority;
+ $this->detail = $detail;
+ }
+
+ /**
+ * @return string
+ * @since 14.0.0
+ */
+ public function getId(): string {
+ return $this->id;
+ }
+
+ /**
+ * @return string
+ * @since 14.0.0
+ */
+ public function getLabel(): string {
+ return $this->label;
+ }
+
+ /**
+ * @return string
+ * @since 14.0.0
+ */
+ public function getIcon(): string {
+ return $this->icon;
+ }
+
+ /**
+ * @return string
+ * @since 14.0.0
+ */
+ public function getLink(): string {
+ return $this->link;
+ }
+
+ /**
+ * @return int
+ * @since 14.0.0
+ */
+ public function getPriority(): int {
+ return $this->priority;
+ }
+
+ /**
+ * @return string
+ * @since 14.0.0
+ */
+ public function render(): string {
+ $detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
+ return sprintf(
+ '<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
+ Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
+ );
+ }
+
+} \ No newline at end of file
diff --git a/lib/public/AppFramework/Http/TemplateResponse.php b/lib/public/AppFramework/Http/TemplateResponse.php
index ccb0c61bfd4..0e31f780d7a 100644
--- a/lib/public/AppFramework/Http/TemplateResponse.php
+++ b/lib/public/AppFramework/Http/TemplateResponse.php
@@ -154,7 +154,7 @@ class TemplateResponse extends Response {
$template->assign($key, $value);
}
- return $template->fetchPage();
+ return $template->fetchPage($this->params);
}
}
diff --git a/tests/acceptance/features/bootstrap/FilesSharingAppContext.php b/tests/acceptance/features/bootstrap/FilesSharingAppContext.php
index f3386b46db9..5c5d23887cd 100644
--- a/tests/acceptance/features/bootstrap/FilesSharingAppContext.php
+++ b/tests/acceptance/features/bootstrap/FilesSharingAppContext.php
@@ -55,7 +55,7 @@ class FilesSharingAppContext implements Context, ActorAwareInterface {
* @return Locator
*/
public static function shareMenuButton() {
- return Locator::forThe()->id("share-menutoggle")->
+ return Locator::forThe()->id("header-actions-toggle")->
describedAs("Share menu button in Shared file page");
}
diff --git a/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php b/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php
new file mode 100644
index 00000000000..8aaaec0733c
--- /dev/null
+++ b/tests/lib/AppFramework/Http/PublicTemplateResponseTest.php
@@ -0,0 +1,84 @@
+<?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 Test\AppFramework\Http;
+
+use OCP\AppFramework\Http\Template\PublicTemplateResponse;
+use OCP\AppFramework\Http;
+use Test\TestCase;
+
+class PublicTemplateResponseTest extends TestCase {
+
+ public function testSetParamsConstructor() {
+ $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
+ $this->assertContains('core/js/public/publicpage', \OC_Util::$scripts);
+ $this->assertEquals(['key' => 'value'], $template->getParams());
+ }
+
+ public function testAdditionalElements() {
+ $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
+ $template->setHeaderTitle('Header');
+ $template->setHeaderDetails('Details');
+ $this->assertEquals(['key' => 'value'], $template->getParams());
+ $this->assertEquals('Header', $template->getHeaderTitle());
+ $this->assertEquals('Details', $template->getHeaderDetails());
+ }
+
+ public function testActionSingle() {
+ $actions = [
+ new Http\Template\SimpleMenuAction('link', 'Download', 'download', 'downloadLink', 0)
+ ];
+ $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
+ $template->setHeaderActions($actions);
+ $this->assertEquals(['key' => 'value'], $template->getParams());
+ $this->assertEquals($actions[0], $template->getPrimaryAction());
+ $this->assertEquals(1, $template->getActionCount());
+ $this->assertEquals([], $template->getOtherActions());
+ }
+
+
+ public function testActionMultiple() {
+ $actions = [
+ new Http\Template\SimpleMenuAction('link1', 'Download1', 'download1', 'downloadLink1', 100),
+ new Http\Template\SimpleMenuAction('link2', 'Download2', 'download2', 'downloadLink2', 20),
+ new Http\Template\SimpleMenuAction('link3', 'Download3', 'download3', 'downloadLink3', 0)
+ ];
+ $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
+ $template->setHeaderActions($actions);
+ $this->assertEquals(['key' => 'value'], $template->getParams());
+ $this->assertEquals($actions[2], $template->getPrimaryAction());
+ $this->assertEquals(3, $template->getActionCount());
+ $this->assertEquals([$actions[1], $actions[0]], $template->getOtherActions());
+ }
+
+
+ public function testGetRenderAs() {
+ $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
+ $this->assertContains('core/js/public/publicpage', \OC_Util::$scripts);
+ $this->assertEquals(['key' => 'value'], $template->getParams());
+ $this->assertEquals('public', $template->getRenderAs());
+ }
+
+}