Deduplicate url-attribute parsing code
Use function to fetch all host links in MonitoredObject instead.
This commit is contained in:
parent
cba36ec017
commit
6c44f6a11a
|
@ -1,29 +1,21 @@
|
|||
<?php
|
||||
|
||||
$links = array();
|
||||
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'));
|
||||
|
||||
$linkText = '<a href="%s" target="_blank">%s ' . $newTabInfo . '</a>';
|
||||
$localLinkText = '<a href="%s">%s</a>';
|
||||
|
||||
if ($object->action_url) {
|
||||
if (strpos($object->action_url, "' ") === false) {
|
||||
$links[] = sprintf($linkText, $this->resolveMacros($object->action_url, $object), 'Action');
|
||||
} else {
|
||||
// TODO: We should find out document what's going on here. Looks strange :p
|
||||
foreach(explode("' ", $object->action_url) as $url) {
|
||||
$url = strpos($url, "'") === 0 ? substr($url, 1) : $url;
|
||||
$url = strrpos($url, "'") === strlen($url) - 1 ? substr($url, 0, strlen($url) - 1) : $url;
|
||||
$links[] = sprintf($linkText, $this->resolveMacros($url, $object), 'Action');
|
||||
}
|
||||
}
|
||||
$links = MonitoredObject::parseAttributeUrls($object->action_url);
|
||||
foreach ($links as $i => $link) {
|
||||
$links[$i] = sprintf(
|
||||
'<a href="%s" target="_blank">%s ' . $newTabInfo . '</a>',
|
||||
$this->resolveMacros($object->action_url, $object),
|
||||
'Action'
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->actions)) {
|
||||
foreach ($this->actions as $id => $action) {
|
||||
$links[] = sprintf($localLinkText, $action, $id);
|
||||
$links[] = sprintf('<a href="%s">%s</a>', $action, $id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -578,9 +578,22 @@ abstract class MonitoredObject implements Filterable
|
|||
*/
|
||||
public function getNotesUrls() {}
|
||||
|
||||
/**
|
||||
* Get all action urls configured for this monitored object
|
||||
*
|
||||
* @return array All note urls as a string
|
||||
*/
|
||||
public function getActionUrls()
|
||||
{
|
||||
return MonitoredObject::parseAttributeUrls($this->action_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the content of the action_url or notes_url attributes
|
||||
*
|
||||
* Find all occurences of http links, separated by whitespaces and quoted
|
||||
* by single or double-ticks.
|
||||
*
|
||||
* @link http://docs.icinga.org/latest/de/objectdefinitions.html
|
||||
*
|
||||
* @param string $urlString A string containing one or more urls
|
||||
|
|
Loading…
Reference in New Issue