$controller->redirect(); return; } // Initialize files if (!empty($files)) { $files = base64_decode($files); $files = explode(',', $files); } $buffer = null; if (!empty($files)) { // Instantiate the helper $helper = new ScriptMergeHelper(); foreach ($files as $file) { // Basic security check if (!preg_match('/\\.(css|js)$/', $file)) { continue; } // CSS-code if ($type == 'css') { header('Content-Type: text/css'); $buffer .= $helper->getCssContent($file); // JS-code } else { header('Content-Type: application/javascript'); $buffer .= $helper->getJsContent($file); } } } echo $buffer; $application = JFactory::getApplication(); $application->close();
/** * Method to build the CSS / JavaScript cache * * @param string $type * @param array $matches * * @return string */ private function buildCacheUrl($type, $list = array()) { // Check for the cache-path $tmp_path = JPATH_SITE . '/cache/plg_scriptmerge/'; if (@is_dir($tmp_path) == false) { jimport('joomla.filesystem.folder'); JFolder::create($tmp_path); } if (!empty($list)) { $cacheId = $this->getHashFromList($list); $cacheFile = $cacheId . '.' . $type; $cachePath = $tmp_path . '/' . $cacheFile; $cacheExpireFile = $cachePath . '_expire'; $hasExpired = false; if (ScriptMergeHelper::hasExpired($cacheExpireFile, $cachePath)) { $hasExpired = true; } if (file_exists($cachePath)) { foreach ($list as $file) { if (file_exists($file['file']) == false) { $hasExpired = true; break; } if (filemtime($file['file'] > filemtime($cachePath))) { $hasExpired = true; break; } } } else { $hasExpired = true; } // Check the cache if ($hasExpired) { $buffer = null; foreach ($list as $file) { if (isset($file['file'])) { // CSS-code if ($type == 'css') { $buffer .= ScriptMergeHelper::getCssContent($file['file']); // JS-code } else { $buffer .= ScriptMergeHelper::getJsContent($file['file']); } } } // Clean up CSS-code if ($type == 'css') { $buffer = ScriptMergeHelper::cleanCssContent($buffer); // Clean up JS-code } else { $buffer = ScriptMergeHelper::cleanJsContent($buffer); } // Write this buffer to a file jimport('joomla.filesystem.file'); JFile::write($cachePath, $buffer); // Create a minified version of this file $this->createMinified($type, $cachePath); // Set the cache parameter $this->createCacheExpireFile($cacheExpireFile); } } // Construct the minified version if ($type == 'js') { $minifiedFile = preg_replace('/\\.js$/', '.min.js', $cacheFile); } else { $minifiedFile = preg_replace('/\\.css$/', '.min.css', $cacheFile); } // Return the minified version if it exists if (file_exists(JPATH_SITE . '/cache/plg_scriptmerge/' . $minifiedFile)) { $url = JURI::root() . 'cache/plg_scriptmerge/' . $minifiedFile; // Return the cache-file itself } else { $url = JURI::root() . 'cache/plg_scriptmerge/' . $cacheFile; } // Domainname sharding $domain = $type == 'js' ? $this->params->get('js_domain') : $this->params->get('css_domain'); $url = $this->replaceUrlDomain($url, $domain); // Protocol change if (JURI::getInstance()->isSSL()) { $url = str_replace('http://', 'https://', $url); } else { $url = str_replace('https://', 'http://', $url); } return $url; }