<div class="controls">
<?= $this->tabs ?>
<h1><?= $title ?></h1>
<span class="action-links" data-base-target="_self">
<?= $this->addLink ?>
</span>
</div>
<?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';
    }

    $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">
<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>
