public function generateJSFile() { if (!is_file(dirname(__FILE__) . '/cache/javascript.php')) { $js = $this->generateJS(); if (strlen($js) > 0) { include_once dirname(__FILE__) . '/classes/minify.php'; $minifyJS = new MinifyJS($js); $minifyJS->minify(dirname(__FILE__) . '/cache/javascript.php', $stripComments = true, $stripWhitespace = true); } else { $fhandle = fopen(dirname(__FILE__) . '/cache/javascript.php', "w"); fclose($fhandle); } } return DIR_WS_HTTP_CATALOG . DIR_WS_MODULES . 'checkout/cache/javascript.php'; }
/** * Minify a javascript-file * * @param string $file The file to be minified. * @return string */ private function minifyJS($file) { // create unique filename $fileName = md5($file) . '.js'; $finalURL = FRONTEND_CACHE_URL . '/minified_js/' . $fileName; $finalPath = FRONTEND_CACHE_PATH . '/minified_js/' . $fileName; // check that file does not yet exist or has been updated already if (!SpoonFile::exists($finalPath) || filemtime(PATH_WWW . $file) > filemtime($finalPath)) { // create directory if it does not exist if (!SpoonDirectory::exists(dirname($finalPath))) { SpoonDirectory::create(dirname($finalPath)); } // minify the file require_once PATH_LIBRARY . '/external/minify.php'; $js = new MinifyJS(PATH_WWW . $file); $js->minify($finalPath); } return $finalURL; }