function fetchPkgVersion($page, $files, $mode = 'js', $jsCompress = false, $cssCompress = false) { define('JSMIN_AS_LIB', true); // get file last modified dates $aLastModifieds = array(); foreach ($files as $sFile) { $aLastModifieds[] = filemtime($sFile); } // sort dates, newest first rsort($aLastModifieds); $iETag = $aLastModifieds[0]; // create a directory for storing current and archive versions if (!is_dir(ARCHIVE_FOLDER)) { mkdir(ARCHIVE_FOLDER); } $sMergedFilename = ARCHIVE_FOLDER . "/" . $page . "_" . $iETag . "." . $mode; // if it does not exist, we need to create a new merged package if (!file_exists($sMergedFilename)) { // get and merge code $sCode = ''; $aLastModifieds = array(); foreach ($files as $sFile) { $aLastModifieds[] = filemtime($sFile); $tempCode = file_get_contents($sFile); $tempCode = str_ireplace('{URL_BASE}', URL_BASE, $tempCode); if ($mode == 'css') { $tempCode = str_ireplace('{CLR_LINKS}', CLR_LINKS, $tempCode); $tempCode = str_ireplace('{CLR_BODY}', CLR_BODY, $tempCode); $tempCode = str_ireplace('{CLR_EDGES1}', CLR_EDGES1, $tempCode); $tempCode = str_ireplace('{CLR_EDGES2}', CLR_EDGES2, $tempCode); $tempCode = str_ireplace('{CLR_KEY1}', CLR_KEY1, $tempCode); $tempCode = str_ireplace('{CLR_KEY2}', CLR_KEY2, $tempCode); $tempCode = str_ireplace('{CLR_KEY3}', CLR_KEY3, $tempCode); $tempCode = str_ireplace('{CLR_UTILITY}', CLR_UTILITY, $tempCode); $tempCode = str_ireplace('{FONTS_MAIN}', FONTS_MAIN, $tempCode); } $sCode .= $tempCode; } // sort dates, newest first rsort($aLastModifieds); // reset iETag incase of late breaking file update $iETag = $aLastModifieds[0]; $sMergedFilename = ARCHIVE_FOLDER . "/" . $page . "_" . $iETag . "." . $mode; $this->pkgWrite($sMergedFilename, $sCode); if ($jsCompress) { require_once JSMIN_PATH . "/jsmin.php"; $jsMin = new JSMin(file_get_contents($sMergedFilename), false); $sCode = $jsMin->minify(); $this->pkgWrite($sMergedFilename, $sCode); } else { if ($cssCompress) { require_once JSMIN_PATH . "/cssMin.php"; $cssMin = new cssMin(); $sCode = $cssMin->minify(file_get_contents($sMergedFilename)); $this->pkgWrite($sMergedFilename, $sCode); } } } // return latest timestamp return $iETag; }
static function BuildCSS($minify = true) { $body = ''; foreach (self::$includeFiles as $filename) { if (!file_exists($filename)) { continue; } $contents = file_get_contents($filename); // convert relative url paths into absolute ones. $subDir = utopia::GetRelativePath(dirname($filename)); $contents = preg_replace('/url\\("?\'?([^"\']+)"?\'?\\)/Ui', 'url(' . $subDir . '/$1)', $contents); $body .= $contents . "\n\n"; } if ($minify) { $body = cssMin::minify($body); } return $body; }