aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/AppFramework/Http/Template
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/AppFramework/Http/Template')
-rw-r--r--lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php41
-rw-r--r--lib/public/AppFramework/Http/Template/IMenuAction.php8
-rw-r--r--lib/public/AppFramework/Http/Template/LinkMenuAction.php23
-rw-r--r--lib/public/AppFramework/Http/Template/PublicTemplateResponse.php43
-rw-r--r--lib/public/AppFramework/Http/Template/SimpleMenuAction.php29
5 files changed, 76 insertions, 68 deletions
diff --git a/lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php b/lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php
index cddf5d19171..281bb559a10 100644
--- a/lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php
+++ b/lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php
@@ -1,58 +1,29 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\AppFramework\Http\Template;
-use OCP\Util;
-
/**
* Class LinkMenuAction
*
* @since 14.0.0
*/
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
+ * @param string $label Translated label
+ * @param string $icon Icon CSS class
+ * @param string $owner Owner user ID (unused)
+ * @param string $displayname Display name of the owner (unused)
+ * @param string $shareName Name of the share (unused)
* @since 14.0.0
*/
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;
- }
-
- /**
- * @since 14.0.0
- */
- public function render(): string {
- return '<li>' .
- ' <button id="save-external-share" class="icon ' . Util::sanitizeHTML($this->getIcon()) . '" data-protected="false" data-owner-display-name="' . Util::sanitizeHTML($this->displayname) . '" data-owner="' . Util::sanitizeHTML($this->owner) . '" data-name="' . Util::sanitizeHTML($this->shareName) . '">' . Util::sanitizeHTML($this->getLabel()) . '</button>' .
- '</li>' .
- '<li id="external-share-menu-item" class="hidden">' .
- ' <span class="menuitem">' .
- ' <form class="save-form" action="#">' .
- ' <input type="text" id="remote_address" placeholder="user@yourNextcloud.org">' .
- ' <input type="submit" value=" " id="save-button-confirm" class="icon-confirm" disabled="disabled"></button>' .
- ' </form>' .
- ' </span>' .
- '</li>';
}
}
diff --git a/lib/public/AppFramework/Http/Template/IMenuAction.php b/lib/public/AppFramework/Http/Template/IMenuAction.php
index d3962300923..124e95fe019 100644
--- a/lib/public/AppFramework/Http/Template/IMenuAction.php
+++ b/lib/public/AppFramework/Http/Template/IMenuAction.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -18,12 +19,16 @@ interface IMenuAction {
public function getId(): string;
/**
+ * The translated label of the menu item.
+ *
* @since 14.0.0
* @return string
*/
public function getLabel(): string;
/**
+ * The link this menu item points to.
+ *
* @since 14.0.0
* @return string
*/
@@ -36,6 +41,9 @@ interface IMenuAction {
public function getPriority(): int;
/**
+ * Custom render function.
+ * The returned HTML will be wrapped within a listitem element (`<li>...</li>`).
+ *
* @since 14.0.0
* @return string
*/
diff --git a/lib/public/AppFramework/Http/Template/LinkMenuAction.php b/lib/public/AppFramework/Http/Template/LinkMenuAction.php
index 69e835f6b82..391802a1dce 100644
--- a/lib/public/AppFramework/Http/Template/LinkMenuAction.php
+++ b/lib/public/AppFramework/Http/Template/LinkMenuAction.php
@@ -1,12 +1,11 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\AppFramework\Http\Template;
-use OCP\Util;
-
/**
* Class LinkMenuAction
*
@@ -22,24 +21,6 @@ class LinkMenuAction extends SimpleMenuAction {
* @since 14.0.0
*/
public function __construct(string $label, string $icon, string $link) {
- parent::__construct('directLink-container', $label, $icon, $link);
- }
-
- /**
- * @return string
- * @since 14.0.0
- */
- 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>' .
- '</a>' .
- '</li>' .
- '<li>' .
- '<span class="menuitem">' .
- '<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' .
- '</span>' .
- '</li>';
+ parent::__construct('directLink', $label, $icon, $link);
}
}
diff --git a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
index c12cf087755..4c156cdecea 100644
--- a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
+++ b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -8,18 +9,20 @@ namespace OCP\AppFramework\Http\Template;
use InvalidArgumentException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IInitialStateService;
/**
* Class PublicTemplateResponse
*
* @since 14.0.0
* @template H of array<string, mixed>
- * @template S of int
- * @template-extends TemplateResponse<int, array<string, mixed>>
+ * @template S of Http::STATUS_*
+ * @template-extends TemplateResponse<Http::STATUS_*, array<string, mixed>>
*/
class PublicTemplateResponse extends TemplateResponse {
private $headerTitle = '';
private $headerDetails = '';
+ /** @var IMenuAction[] */
private $headerActions = [];
private $footerVisible = true;
@@ -33,9 +36,39 @@ class PublicTemplateResponse extends TemplateResponse {
* @param H $headers
* @since 14.0.0
*/
- public function __construct(string $appName, string $templateName, array $params = [], $status = Http::STATUS_OK, array $headers = []) {
+ public function __construct(
+ string $appName,
+ string $templateName,
+ array $params = [],
+ $status = Http::STATUS_OK,
+ array $headers = [],
+ ) {
parent::__construct($appName, $templateName, $params, 'public', $status, $headers);
- \OC_Util::addScript('core', 'public/publicpage');
+ \OCP\Util::addScript('core', 'public-page-menu');
+ \OCP\Util::addScript('core', 'public-page-user-menu');
+
+ $state = \OCP\Server::get(IInitialStateService::class);
+ $state->provideLazyInitialState('core', 'public-page-menu', function () {
+ $response = [];
+ foreach ($this->headerActions as $action) {
+ // First try in it is a custom action that provides rendered HTML
+ $rendered = $action->render();
+ if ($rendered === '') {
+ // If simple action, add the response data
+ if ($action instanceof SimpleMenuAction) {
+ $response[] = $action->getData();
+ }
+ } else {
+ // custom action so add the rendered output
+ $response[] = [
+ 'id' => $action->getId(),
+ 'label' => $action->getLabel(),
+ 'html' => $rendered,
+ ];
+ }
+ }
+ return $response;
+ });
}
/**
@@ -138,6 +171,6 @@ class PublicTemplateResponse extends TemplateResponse {
'template' => $this,
]);
$this->setParams($params);
- return parent::render();
+ return parent::render();
}
}
diff --git a/lib/public/AppFramework/Http/Template/SimpleMenuAction.php b/lib/public/AppFramework/Http/Template/SimpleMenuAction.php
index 2bb60975f26..03cb9b4c7ea 100644
--- a/lib/public/AppFramework/Http/Template/SimpleMenuAction.php
+++ b/lib/public/AppFramework/Http/Template/SimpleMenuAction.php
@@ -1,12 +1,11 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\AppFramework\Http\Template;
-use OCP\Util;
-
/**
* Class SimpleMenuAction
*
@@ -68,6 +67,8 @@ class SimpleMenuAction implements IMenuAction {
}
/**
+ * The icon CSS class to use.
+ *
* @return string
* @since 14.0.0
*/
@@ -92,14 +93,28 @@ class SimpleMenuAction implements IMenuAction {
}
/**
+ * Custom render function.
+ * The returned HTML must be wrapped within a listitem (`<li>...</li>`).
+ * * If an empty string is returned, the default design is used (based on the label and link specified).
* @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
- );
+ return '';
+ }
+
+ /**
+ * Return JSON data to let the frontend render the menu entry.
+ * @return array{id: string, label: string, href: string, icon: string, details: string|null}
+ * @since 31.0.0
+ */
+ public function getData(): array {
+ return [
+ 'id' => $this->id,
+ 'label' => $this->label,
+ 'href' => $this->link,
+ 'icon' => $this->icon,
+ 'details' => $this->detail,
+ ];
}
}