#19278316 remove optimizer

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7861 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ngleader 2010-11-22 01:02:35 +00:00
parent 4e4f9a9943
commit 298a0465e5
8 changed files with 33 additions and 443 deletions

View file

@ -218,8 +218,6 @@
if(file_exists($db_config_file)) @include($db_config_file);
if(!$db_info->time_zone) $db_info->time_zone = date("O");
if(!$db_info->use_optimizer || $db_info->use_optimizer != 'N') $db_info->use_optimizer = 'Y';
else $db_info->use_optimizer = 'N';
if(!$db_info->qmail_compatibility || $db_info->qmail_compatibility != 'Y') $db_info->qmail_compatibility = 'N';
else $db_info->qmail_compatibility = 'Y';
if(!$db_info->use_ssl) $db_info->use_ssl = 'none';
@ -1160,15 +1158,15 @@
/**
* @brief js file을 추가
**/
function addJsFile($file, $optimized = true, $targetie = '',$index=null) {
function addJsFile($file, $optimized = false, $targetie = '',$index=null) {
$oContext = &Context::getInstance();
return $oContext->_addJsFile($file, $optimized, $targetie,$index);
return $oContext->_addJsFile($file, $targetie,$index);
}
/**
* @brief js file을 추가
**/
function _addJsFile($file, $optimized = true, $targetie = '',$index=null) {
function _addJsFile($file, $targetie = '',$index=null) {
if(strpos($file,'://')===false && $file{0}!='/' && $file{0}!='.') $file = './'.$file;
$file = preg_replace('@/\./|(?<!:)\/\/@', '/', $file);
while(strpos($file,'/../')) $file = preg_replace('/\/([^\/]+)\/\.\.\//s','/',$file,1);
@ -1177,23 +1175,23 @@
if(is_null($index)) $index=count($this->js_files);
for($i=$index;array_key_exists($i,$this->js_files);$i++);
$this->js_files[$i] = array('file' => $file, 'optimized' => $optimized, 'targetie' => $targetie);
$this->js_files[$i] = array('file' => $file, 'targetie' => $targetie);
}
/**
* @brief js file을 제거
**/
function unloadJsFile($file, $optimized = true, $targetie = '') {
function unloadJsFile($file, $optimized = false, $targetie = '') {
$oContext = &Context::getInstance();
return $oContext->_unloadJsFile($file, $optimized, $targetie);
return $oContext->_unloadJsFile($file, $targetie);
}
/**
* @brief js file을 제거
**/
function _unloadJsFile($file, $optimized, $targetie) {
function _unloadJsFile($file, $targetie) {
foreach($this->js_files as $key => $val) {
if(realpath($val['file'])==realpath($file) && $val['optimized'] == $optimized && $val['targetie'] == $targetie) {
if(realpath($val['file'])==realpath($file) && $val['targetie'] == $targetie) {
unset($this->js_files[$key]);
return;
}
@ -1250,23 +1248,22 @@
* @brief js file 목록을 return
**/
function _getJsFile() {
require_once(_XE_PATH_."classes/optimizer/Optimizer.class.php");
$oOptimizer = new Optimizer();
return $oOptimizer->getOptimizedFiles($this->_getUniqueFileList($this->js_files), "js");
$files = $this->_getUniqueFileList($this->js_files);
return $files;
}
/**
* @brief CSS file 추가
**/
function addCSSFile($file, $optimized = true, $media = 'all', $targetie = '',$index = null) {
function addCSSFile($file, $optimized = false, $media = 'all', $targetie = '',$index = null) {
$oContext = &Context::getInstance();
return $oContext->_addCSSFile($file, $optimized, $media, $targetie,$index);
return $oContext->_addCSSFile($file, $media, $targetie,$index);
}
/**
* @brief CSS file 추가
**/
function _addCSSFile($file, $optimized = true, $media = 'all', $targetie = '', $index = null) {
function _addCSSFile($file, $media = 'all', $targetie = '', $index = null) {
if(strpos($file,'://')===false && substr($file,0,1)!='/' && substr($file,0,1)!='.') $file = './'.$file;
$file = str_replace(array('/./','//'),'/',$file);
while(strpos($file,'/../')) $file = preg_replace('/\/([^\/]+)\/\.\.\//s','/',$file,1);
@ -1277,23 +1274,23 @@
for($i=$index;array_key_exists($i,$this->css_files);$i++);
//if(preg_match('/^http:\/\//i',$file)) $file = str_replace(realpath("."), ".", realpath($file));
$this->css_files[$i] = array('file' => $file, 'optimized' => $optimized, 'media' => $media, 'targetie' => $targetie);
$this->css_files[$i] = array('file' => $file, 'media' => $media, 'targetie' => $targetie);
}
/**
* @brief css file을 제거
**/
function unloadCSSFile($file, $optimized = true, $media = 'all', $targetie = '') {
function unloadCSSFile($file, $optimized = false, $media = 'all', $targetie = '') {
$oContext = &Context::getInstance();
return $oContext->_unloadCSSFile($file, $optimized, $media, $targetie);
return $oContext->_unloadCSSFile($file, $media, $targetie);
}
/**
* @brief css file을 제거
**/
function _unloadCSSFile($file, $optimized, $media, $targetie) {
function _unloadCSSFile($file, $media, $targetie) {
foreach($this->css_files as $key => $val) {
if(realpath($val['file'])==realpath($file) && $val['optimized'] == $optimized && $val['media'] == $media && $val['targetie'] == $targetie) {
if(realpath($val['file'])==realpath($file) && $val['media'] == $media && $val['targetie'] == $targetie) {
unset($this->css_files[$key]);
return;
}
@ -1324,9 +1321,8 @@
* @brief CSS file 목록 return
**/
function _getCSSFile() {
require_once(_XE_PATH_."classes/optimizer/Optimizer.class.php");
$oOptimizer = new Optimizer();
return $oOptimizer->getOptimizedFiles($this->_getUniqueFileList($this->css_files), "css");
$files = $this->_getUniqueFileList($this->css_files);
return $files;
}
/**
@ -1354,8 +1350,8 @@
$filename = trim($list[$i]);
if(!$filename) continue;
if(substr($filename,0,2)=='./') $filename = substr($filename,2);
if(preg_match('/\.js$/i',$filename)) $this->_addJsFile($plugin_path.$filename, true, '', null);
elseif(preg_match('/\.css$/i',$filename)) $this->_addCSSFile($plugin_path.$filename, true, 'all','', null);
if(preg_match('/\.js$/i',$filename)) $this->_addJsFile($plugin_path.$filename, '', null);
elseif(preg_match('/\.css$/i',$filename)) $this->_addCSSFile($plugin_path.$filename, 'all','', null);
}
if(is_dir($plugin_path.'lang')) $this->_loadLang($plugin_path.'lang');

View file

@ -136,21 +136,21 @@ class HTMLDisplayHandler {
{
$oContext =& Context::getInstance();
// add common JS/CSS files
$oContext->_addJsFile("./common/js/jquery.js", true, '', -100000);
$oContext->_addJsFile("./common/js/jquery.js", '', -100000);
//$oContext->_addJsFile("./common/js/jquery-1.4.2-full.js", true, '', -100000);
$oContext->_addJsFile("./common/js/x.js", true, '', -100000);
$oContext->_addJsFile("./common/js/common.js", true, '', -100000);
$oContext->_addJsFile("./common/js/js_app.js", true, '', -100000);
$oContext->_addJsFile("./common/js/xml_handler.js", true, '', -100000);
$oContext->_addJsFile("./common/js/xml_js_filter.js", true, '', -100000);
$oContext->_addCSSFile("./common/css/default.css", true, 'all', '', -100000);
$oContext->_addCSSFile("./common/css/button.css", true, 'all', '', -100000);
$oContext->_addJsFile("./common/js/x.js", '', -100000);
$oContext->_addJsFile("./common/js/common.js", '', -100000);
$oContext->_addJsFile("./common/js/js_app.js", '', -100000);
$oContext->_addJsFile("./common/js/xml_handler.js", '', -100000);
$oContext->_addJsFile("./common/js/xml_js_filter.js", '', -100000);
$oContext->_addCSSFile("./common/css/default.css", 'all', '', -100000);
$oContext->_addCSSFile("./common/css/button.css", 'all', '', -100000);
// for admin page, add admin css
if(Context::get('module')=='admin' || strpos(Context::get('act'),'Admin')>0){
$oContext->_addCSSFile("./modules/admin/tpl/css/font.css", true, 'all', '',10000);
$oContext->_addCSSFile("./modules/admin/tpl/css/pagination.css", true, 'all', '', 100001);
$oContext->_addCSSFile("./modules/admin/tpl/css/admin.css", true, 'all', '', 100002);
$oContext->_addCSSFile("./modules/admin/tpl/css/font.css", 'all', '',10000);
$oContext->_addCSSFile("./modules/admin/tpl/css/pagination.css", 'all', '', 100001);
$oContext->_addCSSFile("./modules/admin/tpl/css/admin.css", 'all', '', 100002);
}
}
}

View file

@ -1,109 +0,0 @@
<?php
/**
* @class Optimizer
* @author NHN (developers@xpressengine.com)
* @brief class designed to be used to merge mutiple JS/CSS files into one file to shorten time taken for transmission.
*
**/
class Optimizer {
var $cache_path = "./files/cache/optimized/";
var $script_file = "./common/script.php?l=%s&amp;t=.%s";
/**
* @brief Constructor which check if a directory, 'optimized' exists in designated path. If not create a new one
**/
function Optimizer() {
if(!is_dir($this->cache_path)) {
FileHandler::makeDir($this->cache_path);
}
}
/**
* @brief file that removes 'optimized' in a given array
* @param[in] $files an array to be modified
**/
function _getOptimizedRemoved($files) {
foreach($files as $key => $val) unset($files[$key]['optimized']);
return $files;
}
/**
* @brief method that optimizes a given file and returns a resultant file
* @param[in] source_files an array of source files to be optimized
* @param[in] type a type of source file, either js or css.
* @return Returns a optimized file
**/
function getOptimizedFiles($source_files, $type = "js") {
if(!is_array($source_files) || !count($source_files)) return;
// 관리자 설정시 설정이 되어 있지 않으면 패스
// 캐시 디렉토리가 없으면 실행하지 않음
$db_info = Context::getDBInfo();
if($db_info->use_optimizer == 'N' || !is_dir($this->cache_path)) return $this->_getOptimizedRemoved($source_files);
if(!count($source_files)) return;
$files = array();
$hash = "";
foreach($source_files as $key => $file) {
if($file['file'][0] == '/'){
if(!file_exists($file['file'])){
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $file['file'])){
if($file['optimized']) $source_files[$key]['file'] = $file['file'] = $_SERVER['DOCUMENT_ROOT'].$file['file'];
}else{
continue;
}
}
} else if(!$file || !$file['file'] || !file_exists($file['file'])) continue;
$file['file'] = $source_files[$key]['file'] = str_replace("\\","/",$file['file']);
if(empty($file['optimized']) || preg_match('/^https?:\/\//i', $file['file']) ) $files[] = $file;
else{
$targets[] = $file;
$hash .= $file['file'];
}
}
if(!count($targets)) return $this->_getOptimizedRemoved($files);
$list_file_hash = md5($hash);
$oCacheHandler = &CacheHandler::getInstance('template');
if($oCacheHandler->isSupport()){
if(!$oCacheHandler->isValid($list_file_hash)){
$buff = array();
foreach($targets as $file) $buff[] = $file['file'];
$oCacheHandler->put($list_file_hash, $buff);
}
}else{
$list_file = FileHandler::getRealPath($this->cache_path . $list_file_hash . '.info.php');
if(!file_exists($list_file)){
$str = '<?php $f=array();';
foreach($targets as $file) $str .= '$f[]="'. $file['file'] . '";';
$str .= ' return $f; ?>';
FileHandler::writeFile($list_file, $str);
}
}
array_unshift($files, array('file' => sprintf($this->script_file, $list_file_hash, $type) , 'media' => 'all'));
$files = $this->_getOptimizedRemoved($files);
if(!count($files)) return $files;
$url_info = parse_url(Context::getRequestUri());
$abpath = $url_info['path'];
foreach($files as $key => $val) {
$file = $val['file'];
if($file{0} == '/' || strpos($file,'://')!==false) continue;
if(substr($file,0,2)=='./') $file = substr($file,2);
$file = $abpath.$file;
while(strpos($file,'/../')!==false) {
$file = preg_replace('/\/([^\/]+)\/\.\.\//','/',$file);
}
$files[$key]['file'] = $file;
}
return $files;
}
}
?>