icingaweb2-module-director/application/views/scripts/config/file.phtml

67 lines
1.7 KiB
PHTML
Raw Normal View History

<div class="controls">
<?= $this->tabs ?>
<h1><?= $title ?></h1>
<span class="action-links" data-base-target="_self">
2016-03-23 01:31:33 +01:00
<?= $this->addLink ?>
</span>
</div>
2016-07-28 09:11:09 +02:00
<?php
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
$decode = function($str) { return htmlspecialchars_decode($str, ENT_COMPAT | ENT_SUBSTITUTE | ENT_HTML5); };
} else {
$decode = function($str) { return htmlspecialchars_decode($str, ENT_COMPAT | ENT_IGNORE); };
}
$view = $this;
$linkObject = function ($match) use ($view, $decode) {
if ($match[2] === 'Service') {
return $match[0];
}
if ($match[2] === 'CheckCommand') {
$match[2] = 'command';
}
2016-07-28 09:11:09 +02:00
$name = $decode($match[3]);
return sprintf(
'%s %s &quot;%s&quot; {',
$match[1],
$match[2],
$view->qlink(
$name,
'director/' . $match[2],
array('name' => $name),
array('data-base-target' => '_next')
)
);
};
function linkObjects($config, $linkCallback) {
$pattern = '/^(object|template)\s([A-Z][A-Za-z]*?)\s&quot;(.+?)&quot;\s{/m';
return preg_replace_callback(
$pattern,
$linkCallback,
$config
);
}
function highlight($what, $line, $severity) {
$lines = explode("\n", $what);
$lines[$line - 1] = '<span class="highlight ' . $severity . '">' . $lines[$line - 1] . '</span>';
return implode("\n", $lines);
}
?>
<div class="content">
2016-07-28 09:11:09 +02:00
<pre class="generated-config">
<?php if ($this->highlight): ?>
<?= highlight(linkObjects($this->escape($file->getContent()), $linkObject), $highlight, $highlightSeverity) ?>
<?php else: ?>
<?= linkObjects($this->escape($file->getContent()), $linkObject) ?>
<?php endif ?>
</pre>
</div>