summaryrefslogtreecommitdiffstats
path: root/lib/public
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 /lib/public
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
Diffstat (limited to 'lib/public')
-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
4 files changed, 334 insertions, 1 deletions
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);
}
}