Visual Console Refactor: moved the client resources loading to a function

Former-commit-id: 78af6fc129b9e44f3807127df9c05ad284624a7e
This commit is contained in:
Alejandro Gallardo Escobar 2019-04-12 12:43:23 +02:00
parent 7ddc4a70f1
commit f7d856f064
1 changed files with 40 additions and 0 deletions

View File

@ -4525,3 +4525,43 @@ function visual_map_get_color_cloud_element($data)
<?php
return ob_get_clean();
}
/**
* Load the Visual Console Client files (js & css).
*
* @return void
*/
function visual_map_load_client_resources()
{
global $config;
$baseUrl = ui_get_full_url(false, false, false, false);
$vcClientPath = 'include/visual-console-client';
$dir = $config['homedir'].'/'.$vcClientPath;
if (is_dir($dir)) {
$dh = opendir($dir);
if ($dh) {
while (($file = readdir($dh)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
preg_match('/.*.js$/', $file, $match, PREG_OFFSET_CAPTURE);
if (empty($match) === false) {
$url = $baseUrl.$vcClientPath.'/'.$match[0][0];
echo '<script type="text/javascript" src="'.$url.'"></script>';
continue;
}
preg_match('/.*.css$/', $file, $match, PREG_OFFSET_CAPTURE);
if (empty($match) === false) {
$url = $baseUrl.$vcClientPath.'/'.$match[0][0];
echo '<link type="text/css" rel="stylesheet" href="'.$url.'" />';
}
}
closedir($dh);
}
}
}