2013-07-12 14:33:17 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
2013-07-12 14:33:17 +02:00
|
|
|
|
|
|
|
namespace Icinga\Web;
|
|
|
|
|
2015-01-23 09:36:45 +01:00
|
|
|
use Closure;
|
2019-07-17 10:00:34 +02:00
|
|
|
use Icinga\Application\Icinga;
|
2021-05-20 09:34:50 +02:00
|
|
|
use ipl\I18n\Translation;
|
2015-01-23 09:36:45 +01:00
|
|
|
use Zend_View_Abstract;
|
2015-07-28 17:08:55 +02:00
|
|
|
use Icinga\Authentication\Auth;
|
2014-03-17 17:14:16 +01:00
|
|
|
use Icinga\Exception\ProgrammingError;
|
2013-07-12 14:33:17 +02:00
|
|
|
|
2013-08-20 19:26:44 +02:00
|
|
|
/**
|
|
|
|
* Icinga view
|
2017-09-07 11:22:46 +02:00
|
|
|
*
|
|
|
|
* @method Url href($path = null, $params = null) {
|
2017-09-29 12:08:14 +02:00
|
|
|
* @param Url|string|null $path
|
|
|
|
* @param string[]|null $params
|
2017-09-07 11:22:46 +02:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @method Url url($path = null, $params = null) {
|
2017-09-29 12:08:14 +02:00
|
|
|
* @param Url|string|null $path
|
|
|
|
* @param string[]|null $params
|
2017-09-07 11:22:46 +02:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @method Url qlink($title, $url, $params = null, $properties = null, $escape = true) {
|
2017-09-29 12:08:14 +02:00
|
|
|
* @param string $title
|
|
|
|
* @param Url|string|null $url
|
|
|
|
* @param string[]|null $params
|
|
|
|
* @param string[]|null $properties
|
|
|
|
* @param bool $escape
|
2017-09-07 11:22:46 +02:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @method string img($url, $params = null, array $properties = array()) {
|
2017-09-29 12:08:14 +02:00
|
|
|
* @param Url|string|null $url
|
|
|
|
* @param string[]|null $params
|
|
|
|
* @param string[] $properties
|
2017-09-07 11:22:46 +02:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @method string icon($img, $title = null, array $properties = array()) {
|
2017-09-29 12:08:14 +02:00
|
|
|
* @param string $img
|
|
|
|
* @param string|null $title
|
|
|
|
* @param string[] $properties
|
2017-09-07 11:22:46 +02:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @method string propertiesToString($properties) {
|
2017-09-29 12:08:14 +02:00
|
|
|
* @param string[] $properties
|
2017-09-07 11:22:46 +02:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @method string attributeToString($key, $value) {
|
|
|
|
* @param string $key
|
|
|
|
* @param string $value
|
|
|
|
* }
|
2013-08-20 19:26:44 +02:00
|
|
|
*/
|
|
|
|
class View extends Zend_View_Abstract
|
2013-07-12 14:33:17 +02:00
|
|
|
{
|
2021-05-20 09:34:50 +02:00
|
|
|
use Translation;
|
|
|
|
|
2014-03-17 17:14:16 +01:00
|
|
|
/**
|
|
|
|
* Charset to be used - we only support UTF-8
|
|
|
|
*/
|
|
|
|
const CHARSET = 'UTF-8';
|
|
|
|
|
2024-10-10 09:38:15 +02:00
|
|
|
/**
|
|
|
|
* Legacy icons provided by our old fontello font
|
|
|
|
*
|
|
|
|
* @var array<string, bool>
|
|
|
|
*/
|
|
|
|
private const LEGACY_ICONS = [
|
|
|
|
//<editor-fold desc="Icon names">
|
|
|
|
'dashboard' => true,
|
|
|
|
'user' => true,
|
|
|
|
'users' => true,
|
|
|
|
'ok' => true,
|
|
|
|
'cancel' => true,
|
|
|
|
'plus' => true,
|
|
|
|
'minus' => true,
|
|
|
|
'folder-empty' => true,
|
|
|
|
'download' => true,
|
|
|
|
'upload' => true,
|
|
|
|
'git' => true,
|
|
|
|
'cubes' => true,
|
|
|
|
'database' => true,
|
|
|
|
'gauge' => true,
|
|
|
|
'sitemap' => true,
|
|
|
|
'sort-name-up' => true,
|
|
|
|
'sort-name-down' => true,
|
|
|
|
'megaphone' => true,
|
|
|
|
'bug' => true,
|
|
|
|
'tasks' => true,
|
|
|
|
'filter' => true,
|
|
|
|
'off' => true,
|
|
|
|
'book' => true,
|
|
|
|
'paste' => true,
|
|
|
|
'scissors' => true,
|
|
|
|
'globe' => true,
|
|
|
|
'cloud' => true,
|
|
|
|
'flash' => true,
|
|
|
|
'barchart' => true,
|
|
|
|
'down-dir' => true,
|
|
|
|
'up-dir' => true,
|
|
|
|
'left-dir' => true,
|
|
|
|
'right-dir' => true,
|
|
|
|
'down-open' => true,
|
|
|
|
'right-open' => true,
|
|
|
|
'up-open' => true,
|
|
|
|
'left-open' => true,
|
|
|
|
'up-big' => true,
|
|
|
|
'right-big' => true,
|
|
|
|
'left-big' => true,
|
|
|
|
'down-big' => true,
|
|
|
|
'resize-full-alt' => true,
|
|
|
|
'resize-full' => true,
|
|
|
|
'resize-small' => true,
|
|
|
|
'move' => true,
|
|
|
|
'resize-horizontal' => true,
|
|
|
|
'resize-vertical' => true,
|
|
|
|
'zoom-in' => true,
|
|
|
|
'block' => true,
|
|
|
|
'zoom-out' => true,
|
|
|
|
'lightbulb' => true,
|
|
|
|
'clock' => true,
|
|
|
|
'volume-up' => true,
|
|
|
|
'volume-down' => true,
|
|
|
|
'volume-off' => true,
|
|
|
|
'mute' => true,
|
|
|
|
'mic' => true,
|
|
|
|
'endtime' => true,
|
|
|
|
'starttime' => true,
|
|
|
|
'calendar-empty' => true,
|
|
|
|
'calendar' => true,
|
|
|
|
'wrench' => true,
|
|
|
|
'sliders' => true,
|
|
|
|
'services' => true,
|
|
|
|
'service' => true,
|
|
|
|
'phone' => true,
|
|
|
|
'file-pdf' => true,
|
|
|
|
'file-word' => true,
|
|
|
|
'file-excel' => true,
|
|
|
|
'doc-text' => true,
|
|
|
|
'trash' => true,
|
|
|
|
'comment-empty' => true,
|
|
|
|
'comment' => true,
|
|
|
|
'chat' => true,
|
|
|
|
'chat-empty' => true,
|
|
|
|
'bell' => true,
|
|
|
|
'bell-alt' => true,
|
|
|
|
'attention-alt' => true,
|
|
|
|
'print' => true,
|
|
|
|
'edit' => true,
|
|
|
|
'forward' => true,
|
|
|
|
'reply' => true,
|
|
|
|
'reply-all' => true,
|
|
|
|
'eye' => true,
|
|
|
|
'tag' => true,
|
|
|
|
'tags' => true,
|
|
|
|
'lock-open-alt' => true,
|
|
|
|
'lock-open' => true,
|
|
|
|
'lock' => true,
|
|
|
|
'home' => true,
|
|
|
|
'info' => true,
|
|
|
|
'help' => true,
|
|
|
|
'search' => true,
|
|
|
|
'flapping' => true,
|
|
|
|
'rewind' => true,
|
|
|
|
'chart-line' => true,
|
|
|
|
'bell-off' => true,
|
|
|
|
'bell-off-empty' => true,
|
|
|
|
'plug' => true,
|
|
|
|
'eye-off' => true,
|
|
|
|
'arrows-cw' => true,
|
|
|
|
'cw' => true,
|
|
|
|
'host' => true,
|
|
|
|
'thumbs-up' => true,
|
|
|
|
'thumbs-down' => true,
|
|
|
|
'spinner' => true,
|
|
|
|
'attach' => true,
|
|
|
|
'keyboard' => true,
|
|
|
|
'menu' => true,
|
|
|
|
'wifi' => true,
|
|
|
|
'moon' => true,
|
|
|
|
'chart-pie' => true,
|
|
|
|
'chart-area' => true,
|
|
|
|
'chart-bar' => true,
|
|
|
|
'beaker' => true,
|
|
|
|
'magic' => true,
|
|
|
|
'spin6' => true,
|
|
|
|
'down-small' => true,
|
|
|
|
'left-small' => true,
|
|
|
|
'right-small' => true,
|
|
|
|
'up-small' => true,
|
|
|
|
'pin' => true,
|
|
|
|
'angle-double-left' => true,
|
|
|
|
'angle-double-right' => true,
|
|
|
|
'circle' => true,
|
|
|
|
'info-circled' => true,
|
|
|
|
'twitter' => true,
|
|
|
|
'facebook-squared' => true,
|
|
|
|
'gplus-squared' => true,
|
|
|
|
'attention-circled' => true,
|
|
|
|
'check' => true,
|
|
|
|
'reschedule' => true,
|
|
|
|
'warning-empty' => true,
|
|
|
|
'th-list' => true,
|
|
|
|
'th-thumb-empty' => true,
|
|
|
|
'github-circled' => true,
|
|
|
|
'history' => true,
|
2024-11-28 16:55:59 +01:00
|
|
|
'binoculars' => true,
|
|
|
|
'letter' => true
|
2024-10-10 09:38:15 +02:00
|
|
|
//</editor-fold>
|
|
|
|
];
|
|
|
|
|
2014-03-17 17:14:16 +01:00
|
|
|
/**
|
|
|
|
* Registered helper functions
|
|
|
|
*/
|
|
|
|
private $helperFunctions = array();
|
|
|
|
|
2015-01-23 09:36:45 +01:00
|
|
|
/**
|
|
|
|
* Authentication manager
|
|
|
|
*
|
2015-07-28 17:08:55 +02:00
|
|
|
* @var Auth|null
|
2015-01-23 09:36:45 +01:00
|
|
|
*/
|
|
|
|
private $auth;
|
|
|
|
|
2013-08-20 19:26:44 +02:00
|
|
|
/**
|
|
|
|
* Create a new view object
|
|
|
|
*
|
|
|
|
* @param array $config
|
|
|
|
* @see Zend_View_Abstract::__construct
|
|
|
|
*/
|
2013-07-12 14:33:17 +02:00
|
|
|
public function __construct($config = array())
|
|
|
|
{
|
2019-07-17 10:00:34 +02:00
|
|
|
$config['helperPath']['Icinga\\Web\\View\\Helper\\'] = Icinga::app()->getLibraryDir('Icinga/Web/View/Helper');
|
|
|
|
|
2013-07-12 14:33:17 +02:00
|
|
|
parent::__construct($config);
|
|
|
|
}
|
|
|
|
|
2013-08-20 19:26:44 +02:00
|
|
|
/**
|
|
|
|
* Initialize the view
|
|
|
|
*
|
|
|
|
* @see Zend_View_Abstract::init
|
|
|
|
*/
|
2013-07-12 14:33:17 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->loadGlobalHelpers();
|
|
|
|
}
|
|
|
|
|
2014-03-17 17:14:16 +01:00
|
|
|
/**
|
|
|
|
* Escape the given value top be safely used in view scripts
|
|
|
|
*
|
2023-08-15 08:04:56 +02:00
|
|
|
* @param ?string $var The output to be escaped
|
2014-03-17 17:14:16 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2023-07-04 09:57:52 +02:00
|
|
|
public function escape($var)
|
2014-03-31 18:37:21 +02:00
|
|
|
{
|
2023-07-04 09:57:52 +02:00
|
|
|
return htmlspecialchars($var ?? '', ENT_COMPAT | ENT_SUBSTITUTE | ENT_HTML5, self::CHARSET, true);
|
2014-03-17 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether a specific helper (closure) has been registered
|
|
|
|
*
|
|
|
|
* @param string $name The desired function name
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function hasHelperFunction($name)
|
|
|
|
{
|
|
|
|
return array_key_exists($name, $this->helperFunctions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new helper function
|
|
|
|
*
|
|
|
|
* @param string $name The desired function name
|
|
|
|
* @param Closure $function An anonymous function
|
2015-04-07 14:23:26 +02:00
|
|
|
* @return $this
|
2014-03-17 17:14:16 +01:00
|
|
|
*/
|
|
|
|
public function addHelperFunction($name, Closure $function)
|
|
|
|
{
|
|
|
|
if ($this->hasHelperFunction($name)) {
|
|
|
|
throw new ProgrammingError(
|
2014-08-26 11:15:19 +02:00
|
|
|
'Cannot assign the same helper function twice: "%s"',
|
|
|
|
$name
|
2014-03-31 18:37:21 +02:00
|
|
|
);
|
2014-03-17 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->helperFunctions[$name] = $function;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-07-11 09:07:01 +02:00
|
|
|
/**
|
|
|
|
* Set or overwrite a helper function
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param Closure $function
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setHelperFunction($name, Closure $function)
|
|
|
|
{
|
|
|
|
$this->helperFunctions[$name] = $function;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drop a helper function
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function dropHelperFunction($name)
|
|
|
|
{
|
|
|
|
unset($this->helperFunctions[$name]);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-03-17 17:14:16 +01:00
|
|
|
/**
|
|
|
|
* Call a helper function
|
|
|
|
*
|
|
|
|
* @param string $name The desired function name
|
|
|
|
* @param Array $args Function arguments
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function callHelperFunction($name, $args)
|
|
|
|
{
|
|
|
|
return call_user_func_array(
|
|
|
|
$this->helperFunctions[$name],
|
|
|
|
$args
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-08-20 19:26:44 +02:00
|
|
|
/**
|
|
|
|
* Load helpers
|
|
|
|
*/
|
|
|
|
private function loadGlobalHelpers()
|
2013-07-12 14:33:17 +02:00
|
|
|
{
|
|
|
|
$pattern = dirname(__FILE__) . '/View/helpers/*.php';
|
|
|
|
$files = glob($pattern);
|
|
|
|
foreach ($files as $file) {
|
|
|
|
require_once $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-23 09:36:45 +01:00
|
|
|
/**
|
|
|
|
* Get the authentication manager
|
|
|
|
*
|
2015-07-28 17:08:55 +02:00
|
|
|
* @return Auth
|
2015-01-23 09:36:45 +01:00
|
|
|
*/
|
|
|
|
public function Auth()
|
|
|
|
{
|
|
|
|
if ($this->auth === null) {
|
2015-07-28 17:08:55 +02:00
|
|
|
$this->auth = Auth::getInstance();
|
2015-01-23 09:36:45 +01:00
|
|
|
}
|
|
|
|
return $this->auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the current user has the given permission
|
|
|
|
*
|
|
|
|
* @param string $permission Name of the permission
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasPermission($permission)
|
|
|
|
{
|
|
|
|
return $this->Auth()->hasPermission($permission);
|
|
|
|
}
|
|
|
|
|
2013-08-20 19:26:44 +02:00
|
|
|
/**
|
|
|
|
* Use to include the view script in a scope that only allows public
|
|
|
|
* members.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*
|
|
|
|
* @see Zend_View_Abstract::run
|
|
|
|
*/
|
2013-07-12 14:33:17 +02:00
|
|
|
protected function _run()
|
|
|
|
{
|
|
|
|
foreach ($this->getVars() as $k => $v) {
|
|
|
|
// Exporting global variables to view scripts:
|
|
|
|
$$k = $v;
|
|
|
|
}
|
2019-12-04 09:35:24 +01:00
|
|
|
|
|
|
|
include func_get_arg(0);
|
2013-07-12 14:33:17 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 19:26:44 +02:00
|
|
|
/**
|
|
|
|
* Accesses a helper object from within a script
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param array $args
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-07-12 14:33:17 +02:00
|
|
|
public function __call($name, $args)
|
|
|
|
{
|
2014-03-17 17:14:16 +01:00
|
|
|
if ($this->hasHelperFunction($name)) {
|
|
|
|
return $this->callHelperFunction($name, $args);
|
2013-07-12 14:33:17 +02:00
|
|
|
} else {
|
|
|
|
return parent::__call($name, $args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|