mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 10:41:40 +09:00
Merge branch 'develop' into refactor/functions
This commit is contained in:
commit
80289d2c41
103 changed files with 397 additions and 9706 deletions
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
class HTMLDisplayHandler
|
||||
{
|
||||
/**
|
||||
* Reserved scripts
|
||||
*/
|
||||
public static $reservedCSS = '@\bcommon/css/(?:xe|mobile)\.(?:min\.)?css$@';
|
||||
public static $reservedJS = '@\bcommon/js/(?:jquery(?:-[123]\.x)?|xe?|common|js_app|xml_handler|xml_js_filter)\.(?:min\.)?js$@';
|
||||
|
||||
/**
|
||||
* Produce HTML compliant content given a module object.\n
|
||||
|
|
@ -231,7 +236,7 @@ class HTMLDisplayHandler
|
|||
}
|
||||
else
|
||||
{
|
||||
$this->_loadJSCSS();
|
||||
$this->_loadDesktopJSCSS();
|
||||
$output = $oTemplate->compile('./common/tpl', 'common_layout');
|
||||
}
|
||||
|
||||
|
|
@ -385,56 +390,21 @@ class HTMLDisplayHandler
|
|||
* import basic .js files.
|
||||
* @return void
|
||||
*/
|
||||
function _loadJSCSS()
|
||||
function _loadDesktopJSCSS()
|
||||
{
|
||||
$oContext = Context::getInstance();
|
||||
$lang_type = Context::getLangType();
|
||||
|
||||
// add common JS/CSS files
|
||||
if(__DEBUG__ || !__XE_VERSION_STABLE__)
|
||||
{
|
||||
$oContext->loadFile(array('./common/js/jquery-1.x.js', 'head', 'lt IE 9', -111000), true);
|
||||
$oContext->loadFile(array('./common/js/jquery.js', 'head', 'gte IE 9', -110000), true);
|
||||
$oContext->loadFile(array('./common/js/modernizr.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/x.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/common.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/js_app.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/css/xe.css', '', '', -1000000), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oContext->loadFile(array('./common/js/jquery-1.x.min.js', 'head', 'lt IE 9', -111000), true);
|
||||
$oContext->loadFile(array('./common/js/jquery.min.js', 'head', 'gte IE 9', -110000), true);
|
||||
$oContext->loadFile(array('./common/js/x.min.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/xe.min.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/css/xe.min.css', '', '', -1000000), true);
|
||||
}
|
||||
|
||||
$this->_loadCommonJSCSS();
|
||||
|
||||
// for admin page, add admin css
|
||||
if(Context::get('module') == 'admin' || strpos(Context::get('act'), 'Admin') > 0)
|
||||
{
|
||||
if(__DEBUG__ || !__XE_VERSION_STABLE__)
|
||||
{
|
||||
$oContext->loadFile(array('./modules/admin/tpl/css/admin.css', '', '', 10), true);
|
||||
$oContext->loadFile(array("./modules/admin/tpl/css/admin_{$lang_type}.css", '', '', 10), true);
|
||||
$oContext->loadFile(array("./modules/admin/tpl/css/admin.iefix.css", '', 'ie', 10), true);
|
||||
$oContext->loadFile('./modules/admin/tpl/js/admin.js', true);
|
||||
$oContext->loadFile(array('./modules/admin/tpl/css/admin.bootstrap.css', '', '', 1), true);
|
||||
$oContext->loadFile(array('./modules/admin/tpl/js/jquery.tmpl.js', '', '', 1), true);
|
||||
$oContext->loadFile(array('./modules/admin/tpl/js/jquery.jstree.js', '', '', 1), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oContext->loadFile(array('./modules/admin/tpl/css/admin.min.css', '', '', 10), true);
|
||||
$oContext->loadFile(array("./modules/admin/tpl/css/admin_{$lang_type}.css", '', '', 10), true);
|
||||
$oContext->loadFile(array("./modules/admin/tpl/css/admin.iefix.css", '', 'ie', 10), true);
|
||||
$oContext->loadFile('./modules/admin/tpl/js/admin.min.js', true);
|
||||
$oContext->loadFile(array('./modules/admin/tpl/css/admin.bootstrap.min.css', '', '', 1), true);
|
||||
$oContext->loadFile(array('./modules/admin/tpl/js/jquery.tmpl.js', '', '', 1), true);
|
||||
$oContext->loadFile(array('./modules/admin/tpl/js/jquery.jstree.js', '', '', 1), true);
|
||||
}
|
||||
Context::loadFile(array('./modules/admin/tpl/css/admin.css', '', '', 10), true);
|
||||
Context::loadFile(array("./modules/admin/tpl/css/admin_{$lang_type}.css", '', '', 10), true);
|
||||
Context::loadFile(array("./modules/admin/tpl/css/admin.iefix.css", '', 'ie', 10), true);
|
||||
Context::loadFile('./modules/admin/tpl/js/admin.js', true);
|
||||
Context::loadFile(array('./modules/admin/tpl/css/admin.bootstrap.css', '', '', 1), true);
|
||||
Context::loadFile(array('./modules/admin/tpl/js/jquery.tmpl.js', '', '', 1), true);
|
||||
Context::loadFile(array('./modules/admin/tpl/js/jquery.jstree.js', '', '', 1), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -443,32 +413,56 @@ class HTMLDisplayHandler
|
|||
*/
|
||||
private function _loadMobileJSCSS()
|
||||
{
|
||||
$oContext = Context::getInstance();
|
||||
$lang_type = Context::getLangType();
|
||||
$this->_loadCommonJSCSS();
|
||||
Context::loadFile(array('./common/css/mobile.css', '', '', -1500000), true);
|
||||
}
|
||||
|
||||
// add common JS/CSS files
|
||||
if(__DEBUG__ || !__XE_VERSION_STABLE__)
|
||||
/**
|
||||
* import common .js and .css files for (both desktop and mobile)
|
||||
*/
|
||||
private function _loadCommonJSCSS()
|
||||
{
|
||||
Context::loadFile(array('./common/css/xe.css', '', '', -1600000), true);
|
||||
$original_file_list = array('x', 'common', 'js_app', 'xml_handler', 'xml_js_filter');
|
||||
|
||||
if(Context::getDBInfo()->minify_scripts === 'none')
|
||||
{
|
||||
$oContext->loadFile(array('./common/js/jquery.js', 'head', '', -110000), true);
|
||||
$oContext->loadFile(array('./common/js/modernizr.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/x.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/common.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/js_app.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/css/xe.css', '', '', -1000000), true);
|
||||
$oContext->loadFile(array('./common/css/mobile.css', '', '', -1000000), true);
|
||||
Context::loadFile(array('./common/js/jquery-1.x.js', 'head', 'lt IE 9', -1730000), true);
|
||||
Context::loadFile(array('./common/js/jquery.js', 'head', 'gte IE 9', -1720000), true);
|
||||
foreach($original_file_list as $filename)
|
||||
{
|
||||
Context::loadFile(array('./common/js/' . $filename . '.js', 'head', '', -1700000), true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$oContext->loadFile(array('./common/js/jquery.min.js', 'head', '', -110000), true);
|
||||
$oContext->loadFile(array('./common/js/x.min.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/js/xe.min.js', 'head', '', -100000), true);
|
||||
$oContext->loadFile(array('./common/css/xe.min.css', '', '', -1000000), true);
|
||||
$oContext->loadFile(array('./common/css/mobile.min.css', '', '', -1000000), true);
|
||||
Context::loadFile(array('./common/js/jquery-1.x.min.js', 'head', 'lt IE 9', -1730000), true);
|
||||
Context::loadFile(array('./common/js/jquery.min.js', 'head', 'gte IE 9', -1720000), true);
|
||||
|
||||
$concat_target_filename = 'files/cache/minify/xe.min.js';
|
||||
if(file_exists(_XE_PATH_ . $concat_target_filename))
|
||||
{
|
||||
$concat_target_mtime = filemtime(_XE_PATH_ . $concat_target_filename);
|
||||
$original_mtime = 0;
|
||||
foreach($original_file_list as $filename)
|
||||
{
|
||||
$original_mtime = max($original_mtime, filemtime(_XE_PATH_ . 'common/js/' . $filename . '.js'));
|
||||
}
|
||||
if($concat_target_mtime > $original_mtime)
|
||||
{
|
||||
Context::loadFile(array('./' . $concat_target_filename, 'head', '', -100000), true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$minifier = new MatthiasMullie\Minify\JS();
|
||||
foreach($original_file_list as $filename)
|
||||
{
|
||||
$minifier->add(_XE_PATH_ . 'common/js/' . $filename . '.js');
|
||||
}
|
||||
FileHandler::writeFile(_XE_PATH_ . $concat_target_filename, $minifier->execute());
|
||||
Context::loadFile(array('./' . $concat_target_filename, 'head', '', -100000), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file HTMLDisplayHandler.class.php */
|
||||
/* Location: ./classes/display/HTMLDisplayHandler.class.php */
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
class FrontEndFileHandler extends Handler
|
||||
{
|
||||
|
||||
static $isSSL = null;
|
||||
public static $isSSL = null;
|
||||
public static $minify = null;
|
||||
|
||||
/**
|
||||
* Map for css
|
||||
|
|
@ -92,7 +93,14 @@ class FrontEndFileHandler extends Handler
|
|||
{
|
||||
$args = array($args);
|
||||
}
|
||||
$file = $this->getFileInfo($args[0], $args[2], $args[1]);
|
||||
|
||||
$isCommon = preg_match(HTMLDisplayHandler::$reservedCSS, $args[0]) || preg_match(HTMLDisplayHandler::$reservedJS, $args[0]);
|
||||
if($args[3] > -1500000 && $isCommon)
|
||||
{
|
||||
return;
|
||||
}
|
||||
$file = $this->getFileInfo($args[0], $args[2], $args[1], $isCommon);
|
||||
$file->index = (int)$args[3];
|
||||
|
||||
$availableExtension = array('css' => 1, 'js' => 1);
|
||||
if(!isset($availableExtension[$file->fileExtension]))
|
||||
|
|
@ -100,8 +108,6 @@ class FrontEndFileHandler extends Handler
|
|||
return;
|
||||
}
|
||||
|
||||
$file->index = (int) $args[3];
|
||||
|
||||
if($file->fileExtension == 'css')
|
||||
{
|
||||
$map = &$this->cssMap;
|
||||
|
|
@ -123,7 +129,6 @@ class FrontEndFileHandler extends Handler
|
|||
}
|
||||
}
|
||||
|
||||
(is_null($file->index)) ? $file->index = 0 : $file->index = $file->index;
|
||||
if(!isset($mapIndex[$file->key]) || $mapIndex[$file->key] > $file->index)
|
||||
{
|
||||
$this->unloadFile($args[0], $args[2], $args[1]);
|
||||
|
|
@ -138,12 +143,18 @@ class FrontEndFileHandler extends Handler
|
|||
* @param string $fileName The file name
|
||||
* @param string $targetIe Target IE of file
|
||||
* @param string $media Media of file
|
||||
* @param bool $forceMinify Whether this file should be minified
|
||||
* @return stdClass The file information
|
||||
*/
|
||||
private function getFileInfo($fileName, $targetIe = '', $media = 'all')
|
||||
private function getFileInfo($fileName, $targetIe = '', $media = 'all', $forceMinify = false)
|
||||
{
|
||||
static $existsInfo = array();
|
||||
|
||||
if(self::$minify === null)
|
||||
{
|
||||
self::$minify = Context::getDBInfo()->minify_scripts ?: 'common';
|
||||
}
|
||||
|
||||
if(isset($existsInfo[$existsKey]))
|
||||
{
|
||||
return $existsInfo[$existsKey];
|
||||
|
|
@ -155,34 +166,82 @@ class FrontEndFileHandler extends Handler
|
|||
$file->filePath = $this->_getAbsFileUrl($pathInfo['dirname']);
|
||||
$file->fileRealPath = FileHandler::getRealPath($pathInfo['dirname']);
|
||||
$file->fileExtension = strtolower($pathInfo['extension']);
|
||||
$file->fileNameNoExt = preg_replace('/\.min$/', '', $pathInfo['filename']);
|
||||
$file->keyName = implode('.', array($file->fileNameNoExt, $file->fileExtension));
|
||||
$file->cdnPath = $this->_normalizeFilePath($pathInfo['dirname']);
|
||||
|
||||
if(strpos($file->filePath, '://') === FALSE)
|
||||
if(preg_match('/^(.+)\.min$/', $pathInfo['filename'], $matches))
|
||||
{
|
||||
if(!__DEBUG__ && __XE_VERSION_STABLE__)
|
||||
$file->fileNameNoExt = $matches[1];
|
||||
$file->isMinified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$file->fileNameNoExt = $pathInfo['filename'];
|
||||
$file->isMinified = false;
|
||||
}
|
||||
$file->isExternalURL = preg_match('@^(https?:)?//@i', $file->filePath) ? true : false;
|
||||
$file->isCachedScript = !$file->isExternalURL && strpos($file->filePath, 'files/cache/') !== false;
|
||||
$file->keyName = $file->fileNameNoExt . '.' . $file->fileExtension;
|
||||
$file->cdnPath = $this->_normalizeFilePath($pathInfo['dirname']);
|
||||
$originalFilePath = $file->fileRealPath . '/' . $pathInfo['basename'];
|
||||
|
||||
// Fix incorrectly minified URL
|
||||
if($file->isMinified && !$file->isExternalURL && (!file_exists($originalFilePath) || is_link($originalFilePath)))
|
||||
{
|
||||
if(file_exists($file->fileRealPath . '/' . $file->fileNameNoExt . '.' . $file->fileExtension))
|
||||
{
|
||||
// if no debug mode, load minifed file
|
||||
$minifiedFileName = implode('.', array($file->fileNameNoExt, 'min', $file->fileExtension));
|
||||
$minifiedRealPath = implode('/', array($file->fileRealPath, $minifiedFileName));
|
||||
if(file_exists($minifiedRealPath))
|
||||
{
|
||||
$file->fileName = $minifiedFileName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove .min
|
||||
if(file_exists(implode('/', array($file->fileRealPath, $file->keyName))))
|
||||
{
|
||||
$file->fileName = $file->keyName;
|
||||
}
|
||||
$file->fileName = $file->fileNameNoExt . '.' . $file->fileExtension;
|
||||
$file->isMinified = false;
|
||||
$originalFilePath = $file->fileRealPath . '/' . $file->fileNameNoExt . '.' . $file->fileExtension;
|
||||
}
|
||||
}
|
||||
|
||||
$file->targetIe = $targetIe;
|
||||
// Decide whether to minify this file
|
||||
if(self::$minify === 'all')
|
||||
{
|
||||
$minify_enabled = true;
|
||||
}
|
||||
elseif(self::$minify === 'none')
|
||||
{
|
||||
$minify_enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$minify_enabled = $forceMinify;
|
||||
}
|
||||
|
||||
// Minify file
|
||||
if($minify_enabled && !$file->isMinified && !$file->isExternalURL && !$file->isCachedScript && strpos($file->filePath, 'common/js/plugins') === false)
|
||||
{
|
||||
if(($file->fileExtension === 'css' || $file->fileExtension === 'js') && file_exists($originalFilePath))
|
||||
{
|
||||
$minifiedFileName = $file->fileNameNoExt . '.min.' . $file->fileExtension;
|
||||
$minifiedFileHash = ltrim(str_replace(array('/', '\\'), '.', $pathInfo['dirname']), '.');
|
||||
$minifiedFilePath = _XE_PATH_ . 'files/cache/minify/' . $minifiedFileHash . '.' . $minifiedFileName;
|
||||
|
||||
if(!file_exists($minifiedFilePath) || filemtime($minifiedFilePath) < filemtime($originalFilePath))
|
||||
{
|
||||
if($file->fileExtension === 'css')
|
||||
{
|
||||
$minifier = new MatthiasMullie\Minify\CSS($originalFilePath);
|
||||
$content = $minifier->execute($minifiedFilePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
$minifier = new MatthiasMullie\Minify\JS($originalFilePath);
|
||||
$content = $minifier->execute($minifiedFilePath);
|
||||
}
|
||||
FileHandler::writeFile($minifiedFilePath, $content);
|
||||
}
|
||||
|
||||
$file->fileName = $minifiedFileHash . '.' . $minifiedFileName;
|
||||
$file->filePath = $this->_getAbsFileUrl('./files/cache/minify');
|
||||
$file->fileRealPath = _XE_PATH_ . 'files/cache/minify';
|
||||
$file->keyName = $minifiedFileHash . '.' . $file->fileNameNoExt . '.' . $file->fileExtension;
|
||||
$file->cdnPath = $this->_normalizeFilePath('./files/cache/minify');
|
||||
$file->isMinified = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Process targetIe and media attributes
|
||||
$file->targetIe = $targetIe;
|
||||
if($file->fileExtension == 'css')
|
||||
{
|
||||
$file->media = $media;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue