2018-01-25 20:56:15 +03:00
|
|
|
<?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;
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
use OCP\Util;
|
2018-01-25 20:56:15 +03:00
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/**
|
|
|
|
* Class SimpleMenuAction
|
|
|
|
*
|
|
|
|
* @package OCP\AppFramework\Http\Template
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-02-09 11:20:11 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
class SimpleMenuAction implements IMenuAction {
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/** @var string */
|
2018-01-25 20:56:15 +03:00
|
|
|
private $id;
|
2018-02-09 11:20:11 +03:00
|
|
|
|
|
|
|
/** @var string */
|
2018-01-25 20:56:15 +03:00
|
|
|
private $label;
|
2018-02-09 11:20:11 +03:00
|
|
|
|
|
|
|
/** @var string */
|
2018-01-25 20:56:15 +03:00
|
|
|
private $icon;
|
2018-02-09 11:20:11 +03:00
|
|
|
|
|
|
|
/** @var string */
|
2018-01-25 20:56:15 +03:00
|
|
|
private $link;
|
2018-02-09 11:20:11 +03:00
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
private $priority;
|
|
|
|
|
|
|
|
/** @var string */
|
2018-01-25 20:56:15 +03:00
|
|
|
private $detail;
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/**
|
|
|
|
* SimpleMenuAction constructor.
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @param string $label
|
|
|
|
* @param string $icon
|
|
|
|
* @param string $link
|
|
|
|
* @param int $priority
|
|
|
|
* @param string $detail
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-02-09 11:20:11 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-02-09 11:20:11 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getId(): string {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-02-09 11:20:11 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getLabel(): string {
|
|
|
|
return $this->label;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-02-09 11:20:11 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getIcon(): string {
|
|
|
|
return $this->icon;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-02-09 11:20:11 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getLink(): string {
|
|
|
|
return $this->link;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/**
|
|
|
|
* @return int
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-02-09 11:20:11 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getPriority(): int {
|
|
|
|
return $this->priority;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:20:11 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-02-09 11:20:11 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function render(): string {
|
2018-02-09 11:20:11 +03:00
|
|
|
$detailContent = ($this->detail !== '') ? ' <span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
|
|
|
|
return sprintf(
|
2018-02-09 14:14:45 +03:00
|
|
|
'<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
|
2018-02-09 11:20:11 +03:00
|
|
|
);
|
2018-01-25 20:56:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|