getBootstrapDirectory(); $js = $out = ''; $min = $minified ? '.min' : ''; // Prepare vendor file list $vendorFiles = array(); foreach (self::$vendorFiles as $file) { $vendorFiles[] = $basedir . '/' . $file . $min . '.js'; } // Prepare Icinga JS file list $jsFiles = array(); foreach (self::$jsFiles as $file) { $jsFiles[] = $basedir . '/' . $file; } foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) { if ($module->hasJs()) { foreach ($module->getJsFiles() as $path) { if (file_exists($path)) { $jsFiles[] = $path; } } } } $files = array_merge($vendorFiles, $jsFiles); $request = Icinga::app()->getRequest(); $noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache'; header('Cache-Control: public'); if (! $noCache && FileCache::etagMatchesFiles($files)) { header("HTTP/1.1 304 Not Modified"); return; } else { $etag = FileCache::etagForFiles($files); } header('ETag: "' . $etag . '"'); header('Content-Type: application/javascript'); $cacheFile = 'icinga-' . $etag . $min . '.js'; $cache = FileCache::instance(); if (! $noCache && $cache->has($cacheFile)) { $cache->send($cacheFile); return; } // We do not minify vendor files foreach ($vendorFiles as $file) { $out .= ';' . ltrim(trim(file_get_contents($file)), ';') . "\n"; } foreach ($jsFiles as $file) { $js .= file_get_contents($file) . "\n\n\n"; } if ($minified) { require_once 'JShrink/Minifier.php'; $out .= Minifier::minify($js, array('flaggedComments' => false)); } else { $out .= $js; } $cache->store($cacheFile, $out); echo $out; } }