diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2018-02-27 13:33:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-27 13:33:19 +0100 |
commit | 01f420c7ac38128c03975d7de7dd20190c4afcc1 (patch) | |
tree | ca9c599c93d8bd7c90237b9b90fe2fcb80808eae /lib | |
parent | 017e1325f14d3cdbf8d16326f47d1aefa7eac4ea (diff) | |
parent | 36563d4a4b98cbd491b3832c29fee77e9f8b7118 (diff) | |
download | nextcloud-server-01f420c7ac38128c03975d7de7dd20190c4afcc1.tar.gz nextcloud-server-01f420c7ac38128c03975d7de7dd20190c4afcc1.zip |
Merge pull request #8051 from nextcloud/public-template
Public page template response
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 3 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 3 | ||||
-rw-r--r-- | lib/private/Template/Base.php | 5 | ||||
-rw-r--r-- | lib/private/TemplateLayout.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/template.php | 8 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/Template/IMenuAction.php | 64 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/Template/PublicTemplateResponse.php | 143 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/Template/SimpleMenuAction.php | 126 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/TemplateResponse.php | 2 |
9 files changed, 355 insertions, 3 deletions
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 !== '') ? ' <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); } } |