Resolve macros when accessing getters on MonitoredObjects

refs #6392
This commit is contained in:
Matthias Jentsch 2015-05-28 14:58:16 +02:00
parent 37f58e55d8
commit a66949162b
5 changed files with 29 additions and 17 deletions

View File

@ -1,16 +1,11 @@
<?php
use Icinga\Module\Monitoring\Object\MonitoredObject;
// add warning to links that open in new tabs to improve accessibility, as recommended by WCAG20 G201
$newTabInfo = sprintf('<span class="info-box display-on-hover"> %s </span>', $this->translate('opens in new window'));
$links = MonitoredObject::parseAttributeUrls($object->action_url);
$links = $object->getActionUrls();
foreach ($links as $i => $link) {
$links[$i] = sprintf(
'<a href="%s" target="_blank">%s ' . $newTabInfo . '</a>',
$this->resolveMacros($object->action_url, $object),
'Action'
);
$links[$i] = sprintf('<a href="%s" target="_blank">%s ' . $newTabInfo . '</a>', $link, 'Action');
}
if (isset($this->actions)) {

View File

@ -1,15 +1,13 @@
<?php
$notes = trim($object->getNotes());
$links = $object->getNotesUrls();
?>
<?php if (! empty($links) || ! empty($notes)): ?>
if (! empty($links) || ! empty($notes)): ?>
<tr>
<th><?= $this->translate('Notes') ?></th>
<td>
<?php
if (! empty($notes)) {
$notes = $this->resolveMacros($notes, $object);
echo $notes . '<br>';
}
// add warning to links that open in new tabs to improve accessibility, as recommended by WCAG20 G201
@ -19,8 +17,7 @@ $links = $object->getNotesUrls();
);
$linkText = '<a href="%s" target="_blank">%s ' . $newTabInfo . '</a>';
foreach ($links as $i => $link) {
$resolved = $this->resolveMacros($link, $object);
$links[$i] = sprintf($linkText, $this->escape($resolved), $this->escape($resolved));
$links[$i] = sprintf($linkText, $this->escape($link), $this->escape($link));
}
echo implode('<br>', $links);
?>

View File

@ -192,7 +192,9 @@ class Host extends MonitoredObject
public function getNotesUrls()
{
return MonitoredObject::parseAttributeUrls($this->host_notes_url);
return $this->resolveAllStrings(
MonitoredObject::parseAttributeUrls($this->host_notes_url)
);
}
public function getNotes()

View File

@ -569,14 +569,14 @@ abstract class MonitoredObject implements Filterable
*
* @return string The notes as a string
*/
public function getNotes() {}
public abstract function getNotes();
/**
* Get all note urls configured for this monitored object
*
* @return array All note urls as a string
*/
public function getNotesUrls() {}
public abstract function getNotesUrls();
/**
* Get all action urls configured for this monitored object
@ -585,7 +585,23 @@ abstract class MonitoredObject implements Filterable
*/
public function getActionUrls()
{
return MonitoredObject::parseAttributeUrls($this->action_url);
return $this->resolveAllStrings(
MonitoredObject::parseAttributeUrls($this->action_url)
);
}
/**
* Resolve macros in all given strings in the current object context
*
* @param array $strs An array of urls as string
* @return type
*/
protected function resolveAllStrings(array $strs)
{
foreach ($strs as $i => $str) {
$strs[$i] = Macro::resolveMacros($str, $this);
}
return $strs;
}
/**

View File

@ -202,7 +202,9 @@ class Service extends MonitoredObject
public function getNotesUrls()
{
return MonitoredObject::parseAttributeUrls($this->service_notes_url);
return $this->resolveAllStrings(
MonitoredObject::parseAttributeUrls($this->service_notes_url)
);
}
public function getNotes()