From e56056e95038e4d1fcc9c9e4ae7a76feae8588ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20R=C3=BCll?= Date: Tue, 28 Jan 2014 09:58:07 +0100 Subject: [PATCH] makro resolver add view helper "this->makroresolver()" to replace makros. refs #4490 --- .../views/helpers/MakroResolver.php | 110 ++++++++++++++++++ .../views/scripts/list/hosts.phtml | 4 + 2 files changed, 114 insertions(+) create mode 100644 modules/monitoring/application/views/helpers/MakroResolver.php diff --git a/modules/monitoring/application/views/helpers/MakroResolver.php b/modules/monitoring/application/views/helpers/MakroResolver.php new file mode 100644 index 000000000..238f1587c --- /dev/null +++ b/modules/monitoring/application/views/helpers/MakroResolver.php @@ -0,0 +1,110 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + * + */ +// {{{ICINGA_LICENSE_HEADER}}} + +class Zend_View_Helper_MakroResolver extends Zend_View_Helper_Abstract +{ + + private $mapping = array ( + 'HOSTADDRESS' => 'host_address', + 'HOSTNAME' => 'host_name', + 'SERVICEDESC' => 'service_description' + ); + + private $costumPrefix = array ( + '_HOST' => 'host_', + '_Service' => 'service_', + '_CONTACT' => 'contact_' + ); + + private $object; + private $escape; + + public function makroResolver($string, $object, $escape = true) + { + $this->object = $object; + $this->object->host_macaddress = "123.123.123.123"; + $this->escape = $escape; + $values = explode('$', $string); + + foreach ($values as $value){ + $resolved[] = $this->replace($value); + } + $string = implode('', $resolved); + + die(var_dump($object)); + + return $string."
"; + } + + + private function replace($piece) + { + if($piece == 'COSTUM'){ + $piece = $this->mapping["$piece"]; + } + if(array_key_exists($piece, $this->mapping)) + { + $var = $this->mapping["$piece"]; + $piece = $this->object->$var; + } else { + $piece = $this->checkCostumVars($piece); + } + ($this->escape) ? $piece = $this->escapeString($piece) : '' ; + + + //echo $this->object; + return $piece; + } + + private function checkCostumVars($value) + { + if($value != '') { + foreach ($this->costumPrefix as $prefix => $val) { + if(strstr($value, $prefix)){ + $costumVar = $val.strtolower(str_replace($prefix, '', $value)); + if(array_key_exists($costumVar, $this->object)) { + $value = $this->object->$costumVar; + } + } + } + } + + return $value; + } + + private function escapeString($string) + { + return htmlspecialchars($string); + } +} + + +// @codingStandardsIgnoreStop \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml index 2383db43c..91cff3b22 100644 --- a/modules/monitoring/application/views/scripts/list/hosts.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts.phtml @@ -33,7 +33,10 @@ $viewHelper = $this->getHelper('MonitoringState'); + + action_url = 'http://$HOSTNAME$/$HOSTADDRESS$/BANA/$HOSTNAME$/$_HOSTMACADDRESS$' : $host->action_url = "test"; ($i == 1) ? $i++ : $i = $i + 1;?> + util()->getHostStateName($host->host_state)); ?> href('monitoring/show/host', array('host' => $host->host_name)); ?> @@ -119,6 +122,7 @@ $viewHelper = $this->getHelper('MonitoringState');
+ makroResolver($host->action_url, $host, false); ?> host_icon_image) : ?>