private function _cssFiles() { if (Sobi::Cfg('cache.include_css_files', false) && !defined('SOBIPRO_ADM')) { if (count($this->_cache['css'])) { /* * create the right checksum */ $check = array('section' => Sobi::Section()); foreach ($this->_cache['css'] as $file) { if (file_exists($file)) { $check[$file] = filemtime($file); } } $check = md5(serialize($check)); if (!SPFs::exists(SOBI_PATH . "/var/css/{$check}.css")) { $cssContent = "\n/* Created at: " . date(SPFactory::config()->key('date.log_format', 'D M j G:i:s T Y')) . " */\n"; foreach ($this->_cache['css'] as $file) { $fName = str_replace(Sobi::FixPath(SOBI_ROOT), null, $file); $cssContent .= "\n/** \n========\nFile: {$fName}\n========\n*/\n"; $fc = SPFs::read($file); preg_match_all('/[^\\(]*url\\(([^\\)]*)/', $fc, $matches); // we have to replace url relative path $fPath = str_replace(Sobi::FixPath(SOBI_ROOT . '/'), SPFactory::config()->get('live_site'), $file); $fPath = str_replace('\\', '/', $fPath); $fPath = explode('/', $fPath); if (count($matches[1])) { foreach ($matches[1] as $url) { // if it is already absolute - skip or from root if (preg_match('|http(s)?://|', $url) || preg_match('|url\\(["\\s]*/|', $url)) { continue; } elseif (strpos($url, '/') === 0) { continue; } $c = preg_match_all('|\\.\\./|', $url, $c) + 1; $tempFile = array_reverse($fPath); for ($i = 0; $i < $c; $i++) { unset($tempFile[$i]); } $rPath = Sobi::FixPath(implode('/', array_reverse($tempFile))); if ($c > 1) { //WHY?!! //$realUrl = Sobi::FixPath( str_replace( '..', $rPath, $url ) ); $realUrl = Sobi::FixPath($rPath . '/' . str_replace('../', null, $url)); } else { $realUrl = Sobi::FixPath($rPath . '/' . $url); } $realUrl = str_replace(array('"', "'", ' '), null, $realUrl); $fc = str_replace($url, $realUrl, $fc); } } // and add to content $cssContent .= $fc; } SPFs::write(SOBI_PATH . "/var/css/{$check}.css", $cssContent); } $cfile = SPLoader::CssFile('front.var.css.' . $check, false, true, true); $this->cssFiles[++$this->count] = "<link rel=\"stylesheet\" href=\"{$cfile}\" type=\"text/css\" />"; } } return $this->cssFiles; }