去除文件里面的换行和注释
$dir = DISCUZ_ROOT.'./template/default/common/';
$dh = opendir($dir);
$data['staticurl'] = STATICURL;
while(($entry = readdir($dh)) !== false) {
if(fileext($entry) == 'css') {
$cssfile = DISCUZ_ROOT.'./'.$data['tpldir'].'/common/'.$entry;
!file_exists($cssfile) && $cssfile = $dir.$entry;
$cssdata = @implode('', file($cssfile));
if(file_exists($cssfile = DISCUZ_ROOT.'./'.$data['tpldir'].'/common/extend_'.$entry)) {
$cssdata .= @implode('', file($cssfile));
}
if(is_array($_G['setting']['plugins']['available']) && $_G['setting']['plugins']['available']) {
foreach($_G['setting']['plugins']['available'] as $plugin) {
if(file_exists($cssfile = DISCUZ_ROOT.'./source/plugin/'.$plugin.'/template/extend_'.$entry)) {
$cssdata .= @implode('', file($cssfile));
}
}
}
$cssdata = preg_replace("/\{([A-Z0-9]+)\}/e", '\$data[strtolower(\'\1\')]', $cssdata);
$cssdata = preg_replace("/<\?.+?\?>\s*/", '', $cssdata);
$cssdata = !preg_match('/^http:\/\//i', $data['styleimgdir']) ? preg_replace("/url\(([\"'])?".preg_quote($data['styleimgdir'], '/')."/i", "url(\\1$_G[siteurl]$data[styleimgdir]", $cssdata) : $cssdata;
$cssdata = !preg_match('/^http:\/\//i', $data['imgdir']) ? preg_replace("/url\(([\"'])?".preg_quote($data['imgdir'], '/')."/i", "url(\\1$_G[siteurl]$data[imgdir]", $cssdata) : $cssdata;
$cssdata = !preg_match('/^http:\/\//i', $data['staticurl']) ? preg_replace("/url\(([\"'])?".preg_quote($data['staticurl'], '/')."/i", "url(\\1$_G[siteurl]$data[staticurl]", $cssdata) : $cssdata;
if($entry == 'module.css') {
$cssdata = preg_replace('/\/\*\*\s*(.+?)\s*\*\*\//', '[\\1]', $cssdata);
}
$cssdata = preg_replace(array('/\s*([,;:\{\}])\s*/', '/[\t\n\r]/', '/\/\*.+?\*\//'), array('\\1', '',''), $cssdata);
if(@$fp = fopen(DISCUZ_ROOT.'./data/cache/style_'.$data['styleid'].'_'.$entry, 'w')) {
fwrite($fp, $cssdata);
fclose($fp);
} else {
exit('Can not write to cache files, please check directory ./data/ and ./data/cache/ .');
}
}
}
$dh = opendir($dir);
$data['staticurl'] = STATICURL;
while(($entry = readdir($dh)) !== false) {
if(fileext($entry) == 'css') {
$cssfile = DISCUZ_ROOT.'./'.$data['tpldir'].'/common/'.$entry;
!file_exists($cssfile) && $cssfile = $dir.$entry;
$cssdata = @implode('', file($cssfile));
if(file_exists($cssfile = DISCUZ_ROOT.'./'.$data['tpldir'].'/common/extend_'.$entry)) {
$cssdata .= @implode('', file($cssfile));
}
if(is_array($_G['setting']['plugins']['available']) && $_G['setting']['plugins']['available']) {
foreach($_G['setting']['plugins']['available'] as $plugin) {
if(file_exists($cssfile = DISCUZ_ROOT.'./source/plugin/'.$plugin.'/template/extend_'.$entry)) {
$cssdata .= @implode('', file($cssfile));
}
}
}
$cssdata = preg_replace("/\{([A-Z0-9]+)\}/e", '\$data[strtolower(\'\1\')]', $cssdata);
$cssdata = preg_replace("/<\?.+?\?>\s*/", '', $cssdata);
$cssdata = !preg_match('/^http:\/\//i', $data['styleimgdir']) ? preg_replace("/url\(([\"'])?".preg_quote($data['styleimgdir'], '/')."/i", "url(\\1$_G[siteurl]$data[styleimgdir]", $cssdata) : $cssdata;
$cssdata = !preg_match('/^http:\/\//i', $data['imgdir']) ? preg_replace("/url\(([\"'])?".preg_quote($data['imgdir'], '/')."/i", "url(\\1$_G[siteurl]$data[imgdir]", $cssdata) : $cssdata;
$cssdata = !preg_match('/^http:\/\//i', $data['staticurl']) ? preg_replace("/url\(([\"'])?".preg_quote($data['staticurl'], '/')."/i", "url(\\1$_G[siteurl]$data[staticurl]", $cssdata) : $cssdata;
if($entry == 'module.css') {
$cssdata = preg_replace('/\/\*\*\s*(.+?)\s*\*\*\//', '[\\1]', $cssdata);
}
$cssdata = preg_replace(array('/\s*([,;:\{\}])\s*/', '/[\t\n\r]/', '/\/\*.+?\*\//'), array('\\1', '',''), $cssdata);
if(@$fp = fopen(DISCUZ_ROOT.'./data/cache/style_'.$data['styleid'].'_'.$entry, 'w')) {
fwrite($fp, $cssdata);
fclose($fp);
} else {
exit('Can not write to cache files, please check directory ./data/ and ./data/cache/ .');
}
}
}