function html_callback($buffer)
|
{
|
global $config;
|
global $cache_html; // Do not disclose version to unauthorized requests
|
$version_param = $_SESSION['authenticated'] ? '?v=' . OBSERVIUM_VERSION : ''; // Define template strings for registered CSS/JS links and other elements
|
$templates = [
|
'css' => ' <link href="%%STRING%%' . $version_param . '" rel="stylesheet" type="text/css" />' . PHP_EOL,
|
'style' => ' <style type="text/css">' . PHP_EOL . '%%STRING%%' . PHP_EOL . ' </style>' . PHP_EOL,
|
'js' => ' <script type="text/javascript" src="%%STRING%%' . $version_param . '"></script>' . PHP_EOL,
|
'script' => ' <script type="text/javascript">' . PHP_EOL .
|
' <!-- Begin' . PHP_EOL . '%%STRING%%' . PHP_EOL .
|
' // End -->' . PHP_EOL . ' </script>' . PHP_EOL,
|
// key-value
|
'meta-equiv' => ' <meta http-equiv="%%STRING_name%%" content="%%STRING_content%%" />' . PHP_EOL,
|
'meta' => ' <meta name="%%STRING_name%%" content="%%STRING_content%%" />' . PHP_EOL,
|
]; // Process and replace resources in the buffer
|
foreach ($templates as $type => $template) {
|
$uppercase_type = strtoupper($type);
|
//if (isset($GLOBALS['cache_html']['resources'][$type])) {
|
if (isset($GLOBALS['cache_html']['resources'][$type]) && is_array($GLOBALS['cache_html']['resources'][$type])) {
|
$resource_string = '<!-- ' . $uppercase_type . ' BEGIN -->' . PHP_EOL;
|
if ($type === 'meta-equiv' || $type === 'meta') {
|
foreach ($GLOBALS['cache_html']['resources'][$type] as $name => $content) {
|
//bdump($content);
|
$resource_string .= str_replace([ '%%STRING_name%%', '%%STRING_content%%' ], [ $name, $content ], $template);
|
}
|
} else {
|
foreach (array_unique($GLOBALS['cache_html']['resources'][$type]) as $content) {
|
$resource_string .= str_replace('%%STRING%%', $content, $template);
|
}
|
}
|
$resource_string .= ' <!-- ' . $uppercase_type . ' END -->' . PHP_EOL;
|
if (strpos($buffer, '<!-- ##' . $uppercase_type . '_CACHE## -->') !== false) {
|
$buffer = str_replace('<!-- ##' . $uppercase_type . '_CACHE## -->' . PHP_EOL, $resource_string, $buffer);
|
}
|
} else {
|
// Clean template string
|
if (strpos($buffer, '<!-- ##' . $uppercase_type . '_CACHE## -->') !== false) {
|
$tmp = $buffer;
|
$buffer = str_replace('<!-- ##' . $uppercase_type . '_CACHE## -->', '', $tmp);
|
}
|
}
|
} // Replace placeholders in the buffer with actual values
|
$replacements = [
|
'##TITLE##' => html_callback_build_title(),
|
'##PAGE_PANEL##' => $GLOBALS['cache_html']['page_panel'],
|
'##UI_ALERTS##' => implode(PHP_EOL, (array)$GLOBALS['cache_html']['ui_alerts']),
|
]; // Return the modified HTML page source
|
return array_str_replace($replacements, $buffer, TRUE);
|
}
|
Observium initially recommend to use minimum 512M php memory for web ui.