issue 106 Add support for CDN

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8764 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2011-08-12 09:24:54 +00:00
parent 52b3ae8d4f
commit e6eb7a75d2
19 changed files with 412 additions and 163 deletions

View file

@ -24,8 +24,7 @@ class Context {
var $ftp_info = NULL; ///< FTP info.
var $ssl_actions = array(); ///< list of actions to be sent via ssl (it is used by javascript xml handler for ajax)
var $js_files_map = array(); ///< hash map of javascript files. The file name is used as a key
var $css_files_map = array(); ///< hash map of css files. The file name is used as a key
var $oFrontEndFileHandler;
var $html_header = NULL; ///< script codes in <head>..</head>
var $body_class = array(); ///< classnames of <body>
@ -57,6 +56,14 @@ class Context {
return $theInstance;
}
/**
* @brief cunstructor
**/
function Context()
{
$this->oFrontEndFileHandler = new FrontEndFileHandler();
}
/**
* @brief initialization, it sets DB information, request arguments and so on.
* @return none
@ -987,6 +994,7 @@ class Context {
/**
* @brief normalize file path
* @return normalized file path
* @deprecated
*/
function normalizeFilePath($file) {
if(strpos($file,'://')===false && $file{0}!='/' && $file{0}!='.') $file = './'.$file;
@ -996,6 +1004,9 @@ class Context {
return $file;
}
/**
* @deprecated
**/
function getAbsFileUrl($file) {
$file = Context::normalizeFilePath($file);
if(strpos($file,'./')===0) $file = dirname($_SERVER['SCRIPT_NAME']).'/'.substr($file,2);
@ -1004,37 +1015,54 @@ class Context {
return $file;
}
/**
* @brief load front end file
* @params $args array
* case js
* $args[0]: file name
* $args[1]: type (head | body)
* $args[2]: target IE
* $args[3]: index
* case css
* $args[0]: file name
* $args[1]: media
* $args[2]: target IE
* $args[3]: index
**/
function loadFile($args, $cdnPath = '')
{
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$self->oFrontEndFileHandler->loadFile($args, $cdnPath);
}
function unloadFile($file, $targetIe = '', $media = 'all')
{
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$self->oFrontEndFileHandler->unloadFile($file, $targetIe, $media);
}
function unloadAllFiles($type = 'all')
{
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$self->oFrontEndFileHandler->unloadAllFiles($type);
}
/**
* @brief Add the js file
* @deprecated
**/
function addJsFile($file, $optimized = false, $targetie = '',$index=0, $type='head') {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$avail_types = array('head', 'body');
if(!in_array($type, $avail_types)) $type = $avail_types[0];
$key = Context::getAbsFileUrl($file)."\t".$targetie;
$map = &$self->js_files_map;
// Is this file already registered?
if (!is_array($map[$type])) $map[$type] = array();
if (!isset($map[$type][$key]) || (int)$map[$type][$key] > (int)$index) $map[$type][$key] = (int)$index+count($map[$type])/1000-1;
$self->oFrontEndFileHandler->loadFile(array($file, $type, $targetie, $index));
}
/**
* @brief Remove the js file
* @deprecated
**/
function unloadJsFile($file, $optimized = false, $targetie = '') {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$remove_key = Context::getAbsFileUrl($file)."\t$targetie";
foreach($self->js_files_map as $key=>$val) {
if($key === $remove_key) {
unset($self->js_files_map[$key]);
return;
}
}
$self->oFrontEndFileHandler->unloadFile($file, $targetie);
}
/**
@ -1042,7 +1070,7 @@ class Context {
**/
function unloadAllJsFiles() {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$self->js_files_map = array();
$self->oFrontEndFileHandler->unloadAllJsFiles();
}
/**
@ -1075,50 +1103,25 @@ class Context {
**/
function getJsFile($type='head') {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
if(!is_array($self->js_files_map[$type])) $self->js_files_map[$type] = array();
$ret = array();
$map = &$self->js_files_map[$type];
asort($self->js_files_map[$type]);
foreach($map as $key=>$val) {
list($file, $targetie) = explode("\t", $key);
$ret[] = array('file'=>$file, 'targetie'=>$targetie);
}
return $ret;
return $self->oFrontEndFileHandler->getJsFileList($type);
}
/**
* @brief Add CSS file
* @deprecated
**/
function addCSSFile($file, $optimized=false, $media='all', $targetie='',$index=0) {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
if(!$media) $media = 'all';
$key = Context::getAbsFileUrl($file)."\t$targetie\t$media";
$map = &$self->css_files_map;
if (!isset($map[$key]) || (int)$map[$key] > (int)$index) $map[$key] = (int)$index+count($map)/100-1;
$self->oFrontEndFileHandler->loadFile(array($file, $media, $targetie, $index));
}
/**
* @brief Remove css file
* @deprecated
**/
function unloadCSSFile($file, $optimized = false, $media = 'all', $targetie = '') {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$remove_key = Context::getAbsFileUrl($file)."\t$targetie\t$media";
foreach($self->css_files_map as $key => $val) {
if($key === $remove_key) {
unset($self->css_files_map[$key]);
return;
}
}
$self->oFrontEndFileHandler->unloadFile($file, $targetie, $media);
}
/**
@ -1126,7 +1129,7 @@ class Context {
**/
function unloadAllCSSFiles() {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$self->css_files_map = array();
$self->oFrontEndFileHandler->unloadAllCssFiles();
}
/**
@ -1134,16 +1137,7 @@ class Context {
**/
function getCSSFile() {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
asort($self->css_files_map);
$ret = array();
foreach($self->css_files_map as $key=>$val) {
list($_file, $_targetie, $_media) = explode("\t", $key);
$ret[] = array('file'=>$_file, 'media'=>$_media, 'targetie'=>$_targetie);
}
return $ret;
return $self->oFrontEndFileHandler->getCssFileList();
}
/**
@ -1168,8 +1162,8 @@ class Context {
if(!$filename) continue;
if(substr($filename,0,2)=='./') $filename = substr($filename,2);
if(preg_match('/\.js$/i', $filename)) $self->addJsFile($plugin_path.$filename, false, '', 0, 'body');
elseif(preg_match('/\.css$/i', $filename)) $self->addCSSFile($plugin_path.$filename, false, 'all', '', 0);
if(preg_match('/\.js$/i', $filename)) $self->loadFile(array($plugin_path.$filename, 'body', '', 0));
elseif(preg_match('/\.css$/i', $filename)) $self->loadFile(array($plugin_path.$filename, 'all', '', 0));
}
if(is_dir($plugin_path.'lang')) $self->loadLang($plugin_path.'lang');

View file

@ -5,7 +5,7 @@ class HTMLDisplayHandler {
* @brief Produce HTML compliant content given a module object.\n
* @param[in] $oModule the module object
**/
function toDoc(&$oModule)
function toDoc(&$oModule)
{
$oTemplate = &TemplateHandler::getInstance();
@ -14,7 +14,7 @@ class HTMLDisplayHandler {
$skin = $oModule->origin_module_info->skin;
else
$skin = $oModule->module_config->skin;
if ($skin){
$theme_skin = explode('.', $skin);
if (count($theme_skin) == 2)
@ -58,7 +58,7 @@ class HTMLDisplayHandler {
// search if the changes CSS exists in the admin layout edit window
$edited_layout_css = $oLayoutModel->getUserLayoutCss($layout_srl);
if(file_exists($edited_layout_css)) Context::addCSSFile($edited_layout_css,true,'all','',100);
if(file_exists($edited_layout_css)) Context::loadFile(array($edited_layout_css,'all','',100));
}
if(!$layout_path) $layout_path = "./common/tpl";
if(!$layout_file) $layout_file = "default_layout";
@ -76,7 +76,7 @@ class HTMLDisplayHandler {
function prepareToPrint(&$output) {
if(Context::getResponseMethod() != 'HTML') return;
if(__DEBUG__==3) $start = getMicroTime();
// move <style ..></style> in body to the header
@ -146,13 +146,12 @@ class HTMLDisplayHandler {
}
/**
* @brief add given .css or .js file names in widget code to Context
* @brief add given .css or .js file names in widget code to Context
* @param[in] $oModule the module object
**/
function _transMeta($matches) {
if($matches[1]) return '';
if(substr($matches[2],'-4')=='.css') Context::addCSSFile($matches[2]);
elseif(substr($matches[2],'-3')=='.js') Context::addJSFile($matches[2]);
Context::loadFile($matches[2]);
}
function _loadJSCSS()
@ -162,31 +161,31 @@ class HTMLDisplayHandler {
// add common JS/CSS files
if(__DEBUG__) {
$oContext->addJsFile('./common/js/jquery.js', false, '', -100000);
$oContext->addJsFile('./common/js/x.js', false, '', -100000);
$oContext->addJsFile('./common/js/common.js', false, '', -100000);
$oContext->addJsFile('./common/js/js_app.js', false, '', -100000);
$oContext->addJsFile('./common/js/xml_handler.js', false, '', -100000);
$oContext->addJsFile('./common/js/xml_js_filter.js', false, '', -100000);
$oContext->addCSSFile('./common/css/default.css', false, 'all', '', -100000);
$oContext->addCSSFile('./common/css/button.css', false, 'all', '', -100000);
$oContext->loadFile(array('./common/js/jquery.js', 'head', '', -100000));
$oContext->loadFile(array('./common/js/x.js', 'head', '', -100000));
$oContext->loadFile(array('./common/js/common.js', 'head', '', -100000));
$oContext->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
$oContext->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000));
$oContext->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000));
$oContext->loadFile(array('./common/css/default.css', 'all', '', -100000));
$oContext->loadFile(array('./common/css/button.css', 'all', '', -100000));
} else {
$oContext->addJsFile('./common/js/jquery.min.js', false, '', -100000);
$oContext->addJsFile('./common/js/x.min.js', false, '', -100000);
$oContext->addJsFile('./common/js/xe.min.js', false, '', -100000);
$oContext->addCSSFile('./common/css/xe.min.css', false, 'all', '', -100000);
$oContext->loadFile(array('./common/js/jquery.min.js', 'head', '', -100000));
$oContext->loadFile(array('./common/js/x.min.js', 'head', '', -100000));
$oContext->loadFile(array('./common/js/xe.min.js', 'head', '', -100000));
$oContext->loadFile(array('./common/css/xe.min.css', 'all', '', -100000));
}
// for admin page, add admin css
if(Context::get('module')=='admin' || strpos(Context::get('act'),'Admin')>0){
if(__DEBUG__) {
$oContext->addCSSFile('./modules/admin/tpl/css/admin.css', false, 'all', '', 100000);
$oContext->addCSSFile("./modules/admin/tpl/css/admin_{$lang_type}.css", false, 'all', '', 100000);
$oContext->addJsFile('./modules/admin/tpl/js/admin.js');
$oContext->loadFile(array('./modules/admin/tpl/css/admin.css', 'all', '', 100000));
$oContext->loadFile(array("./modules/admin/tpl/css/admin_{$lang_type}.css", 'all', '', 100000));
$oContext->loadFile('./modules/admin/tpl/js/admin.js');
} else {
$oContext->addCSSFile('./modules/admin/tpl/css/admin.min.css', false, 'all', '', 100000);
$oContext->addCSSFile("./modules/admin/tpl/css/admin_{$lang_type}.min.css", false, 'all', '',10000);
$oContext->addJsFile('./modules/admin/tpl/js/admin.js');
$oContext->loadFile(array('./modules/admin/tpl/css/admin.min.css', 'all', '', 100000));
$oContext->loadFile(array("./modules/admin/tpl/css/admin_{$lang_type}.min.css", 'all', '',10000));
$oContext->loadFile('./modules/admin/tpl/js/admin.js');
}
}
}

View file

@ -0,0 +1,224 @@
<?php
/**
* @class FrontEndFileHandler
* @author NHN (developer@xpressengine.com)
**/
class FrontEndFileHandler extends Handler
{
var $cssMap = array();
var $jsHeadMap = array();
var $jsBodyMap = array();
var $cssMapIndex = array();
var $jsHeadMapIndex = array();
var $jsBodyMapIndex = array();
/**
* @brief load front end file
* @params $args array
* case js
* $args[0]: file name
* $args[1]: type (head | body)
* $args[2]: target IE
* $args[3]: index
* case css
* $args[0]: file name
* $args[1]: media
* $args[2]: target IE
* $args[3]: index
**/
function loadFile($args, $cdnPath = '')
{
if (!is_array($args)) $args = array($args);
$pathInfo = pathinfo($args[0]);
$file->fileName = $pathInfo['basename'];
$file->filePath = $this->_getAbsFileUrl($pathInfo['dirname']);
$file->fileExtension = strtolower($pathInfo['extension']);
$file->cdnPath = $cdnPath;
$availableExtension = array('css', 'js');
if (!in_array($file->fileExtension, $availableExtension)) return;
$file->targetIe = $args[2];
$file->index = (int)$args[3];
if ($file->fileExtension == 'css')
{
$file->media = $args[1];
$map = &$this->cssMap;
$mapIndex = &$this->cssMapIndex;
$key = $file->filePath . $file->fileName . "\t" . $file->targetIe . "\t" . $file->media;
}
else if ($file->fileExtension == 'js')
{
$type = $args[1];
if ($type == 'body')
{
$map = &$this->jsBodyMap;
$mapIndex = &$this->jsBodyMapIndex;
}
else
{
$map = &$this->jsHeadMap;
$mapIndex = &$this->jsHeadMapIndex;
}
$key = $file->filePath . $file->fileName . "\t" . $file->targetIe;
}
if (!isset($map[$key]) || $map[$key]->index > $file->index)
{
$file->index = ((int)$file->index + count($map));
$map[$key] = $file;
$mapIndex[$key] = $file->index;
}
debugPrint($file);
}
function unloadFile($fileName, $targetIe = '', $media = 'all')
{
$pathInfo = pathinfo($fileName);
$fileName = $pathInfo['basename'];
$filePath = $this->_getAbsFileUrl($pathInfo['dirname']);
$fileExtension = strtolower($pathInfo['extension']);
$key = $filePath . $fileName . "\t" . $targetIe;
if ($fileExtension == 'css')
{
$key .= "\t" . $media;
unset($this->cssMap[$key]);
unset($this->cssMapIndex[$key]);
}
else
{
unset($this->jsHeadMap[$key]);
unset($this->jsBodyMap[$key]);
unset($this->jsHeadMapIndex[$key]);
unset($this->jsBodyMapIndex[$key]);
}
}
function unloadAllFiles($type = 'all')
{
if ($type == 'css' || $type == 'all')
{
$cssMap = array();
$cssMapIndex = array();
}
if ($type == 'js' || $type == 'all')
{
$jsHeadMap = array();
$jsBodyMap = array();
$jsHeadMapIndex = array();
$jsBodyMapIndex = array();
}
}
function getCssFileList()
{
$map = &$this->cssMap;
$mapIndex = &$this->cssMapIndex;
$this->_sortMap($map, $mapIndex);
$dbInfo = Context::get('db_info');
$useCdn = $dbInfo->use_cdn;
$result = array();
foreach($map as $file)
{
if ($useCdn == 'Y' && $file->cdnPath)
{
$fullFilePath = __XE_CDN__ . $file->cdnPath . '/' . $file->fileName;
}
else
{
$fullFilePath = $file->filePath . '/' . $file->fileName;
}
$result[] = array('file' => $fullFilePath, 'media' => $file->media, 'targetie' => $file->targetIe);
}
return $result;
}
function getJsFileList($type = 'head')
{
if ($type == 'head')
{
$map = &$this->jsHeadMap;
$mapIndex = &$this->jsHeadMapIndex;
}
else
{
$map = &$this->jsBodyMap;
$mapIndex = &$this->jsBodyMapIndex;
}
$this->_sortMap($map, $mapIndex);
$dbInfo = Context::get('db_info');
$useCdn = $dbInfo->use_cdn;
$result = array();
foreach($map as $file)
{
if ($useCdn == 'Y' && $file->cdnPath)
{
$fullFilePath = __XE_CDN__ . $file->cdnPath . '/' . $file->fileName;
}
else
{
$fullFilePath = $file->filePath . '/' . $file->fileName;
}
$result[] = array('file' => $fullFilePath, 'targetie' => $file->targetIe);
}
return $result;
}
function _sortMap(&$map, &$index)
{
asort($index);
$sortedMap = array();
foreach($index as $key => $val)
{
$sortedMap[$key] = $map[$key];
}
$map = $sortedMap;
}
function _normalizeFilePath($path)
{
if (strpos($path, '://') === false && $path{0} != '/' && $path{0} != '.')
{
$path = './' . $path;
}
$path = preg_replace('@/\./|(?<!:)\/\/@', '/', $path);
while(strpos($path, '/../'))
{
$path = preg_replace('/\/([^\/]+)\/\.\.\//s', '/', $path, 1);
}
return $path;
}
function _getAbsFileUrl($path)
{
$path = $this->_normalizeFilePath($path);
if(strpos($path, './') === 0)
{
$path = dirname($_SERVER['SCRIPT_NAME']) . '/' . substr($path, 2);
}
else if(strpos($file, '../') === 0)
{
$file = $this->_normalizeFilePath(dirname($_SERVER['SCRIPT_NAME']) . "/{$path}");
}
return $path;
}
}

View file

@ -2,19 +2,19 @@
/**
* @class TemplateHandler
* @author NHN (developers@xpressengine.com)
* @brief template compiler
* @brief template compiler
* @version 0.1
* @remarks It compiles template file by using regular expression into php
* code, and XE caches compiled code for further uses
* @remarks It compiles template file by using regular expression into php
* code, and XE caches compiled code for further uses
**/
class TemplateHandler extends Handler {
var $compiled_path = './files/cache/template_compiled/'; ///< path of compiled caches files
var $path = null; ///< target directory
var $path = null; ///< target directory
var $filename = null; ///< target filename
var $file = null; ///< target file (fullpath)
var $file = null; ///< target file (fullpath)
var $xe_path = null; ///< XpressEngine base path
var $web_path = null; ///< tpl file web path
var $compiled_file = null; ///< tpl file web path
@ -42,11 +42,11 @@
* @brief set variables for template compile
**/
function init($tpl_path, $tpl_filename, $tpl_file) {
// verify arguments
// verify arguments
if(substr($tpl_path,-1)!='/') $tpl_path .= '/';
if(!file_exists($tpl_path.$tpl_filename)&&file_exists($tpl_path.$tpl_filename.'.html')) $tpl_filename .= '.html';
// create tpl_file variable
// create tpl_file variable
if(!$tpl_file) $tpl_file = $tpl_path.$tpl_filename;
// set template file infos.
@ -69,11 +69,11 @@
}
/**
* @brief compiles specified tpl file and execution result in Context into resultant content
* @brief compiles specified tpl file and execution result in Context into resultant content
* @param[in] $tpl_path path of the directory containing target template file
* @param[in] $tpl_filename target template file's name
* @param[in] $tpl_file if specified use it as template file's full path
* @return Returns compiled result in case of success, NULL otherwise
* @param[in] $tpl_file if specified use it as template file's full path
* @return Returns compiled result in case of success, NULL otherwise
*/
function compile($tpl_path, $tpl_filename, $tpl_file = '') {
// store the starting time for debug information
@ -136,16 +136,16 @@
}
/**
* @brief compile a template file specified in $tpl_file and
* @brief compile a template file specified in $tpl_file and
* @pre files specified by $tpl_file exists.
* @param[in] $tpl_file path of tpl file
* @param[in] $compiled_tpl_file if specified, write compiled result into the file
* @return compiled result in case of success or NULL in case of error
* @return compiled result in case of success or NULL in case of error
**/
function parse() {
if(!file_exists($this->file)) return;
// read tpl file
// read tpl file
$buff = FileHandler::readFile($this->file);
// replace value of src in img/input/script tag
@ -172,10 +172,10 @@
// replace include <!--#include($filename)-->
$buff = preg_replace_callback('!<\!--#include\(([^\)]*?)\)-->!is', array($this, '_compileIncludeToCode'), $buff);
// replace <!--@, -->
// replace <!--@, -->
$buff = preg_replace_callback('!<\!--@(.*?)-->!is', array($this, '_compileFuncToCode'), $buff);
// remove comments <!--// ~ -->
// remove comments <!--// ~ -->
$buff = preg_replace('!(\n?)( *?)<\!--//(.*?)-->!is', '', $buff);
// import xml filter/ css/ js/ files <!--%import("filename"[,optimized=true|false][,media="media"][,targetie="lt IE 6|IE 7|gte IE 8|..."])--> (media is applied to only css)
@ -245,7 +245,7 @@
}
/**
* @brief fetch using ob_* function
* @brief fetch using ob_* function
* @param[in] $compiled_tpl_file path of compiled template file
* @param[in] $buff if buff is not null, eval it instead of including compiled template file
* @param[in] $tpl_path set context's tpl path
@ -271,7 +271,7 @@
* @param[in] $matches match
* @return changed result
**/
function _replacePath($matches)
function _replacePath($matches)
{
preg_match_all('/src="([^"]*?)"/is', $matches[0], $m);
for($i=0,$c=count($m[0]);$i<$c;$i++) {
@ -279,7 +279,7 @@
if(substr($path,0,1)=='/' || substr($path,0,1)=='{' || strpos($path,'://')!==false) continue;
if(substr($path,0,2)=='./') $path = substr($path,2);
$target = $this->web_path.$path;
while(strpos($target,'/../')!==false)
while(strpos($target,'/../')!==false)
{
$target = preg_replace('/\/([^\/]+)\/\.\.\//','/',$target);
}
@ -358,7 +358,7 @@
}
}
if(substr(trim($tag),-2)!='/>')
if(substr(trim($tag),-2)!='/>')
{
while(false !== $close_pos = strpos($next, '</'.$tag_name))
{
@ -375,7 +375,7 @@
}
/**
* @brief replace pipe cond and |cond=
* @brief replace pipe cond and |cond=
**/
function _replacePipeCond($matches)
{
@ -425,7 +425,7 @@
$tag_head .= '<?php if('.$m[1][$i].') { ?>';
$tag_tail .= '<?php } ?>';
}
}
}
if(!preg_match('/ cond="([^"]+)"/is',$tag)) {
print "<strong>Invalid XpressEngine Template Syntax</strong><br/>";
@ -435,11 +435,11 @@
}
$tag = preg_replace('/ cond="([^"]+)"/is','', $tag);
if(substr(trim($tag),-2)=='/>')
if(substr(trim($tag),-2)=='/>')
{
$buff = $pre.$tag_head.$tag.$tag_tail.$next;
}
else
}
else
{
while(false !== $close_pos = strpos($next, '</'.$tag_name))
{
@ -452,14 +452,14 @@
$buff = $pre.$tag_head.$tag.$tag_tail.$next;
}
}
return $buff;
}
/**
* @brief replace include tags which include other template files
**/
function _replaceInclude($matches)
function _replaceInclude($matches)
{
if(!preg_match('/target=\"([^\"]+)\"/is',$matches[0], $m)) {
print '"target" attribute missing in "'.htmlspecialchars($matches[0]);
@ -512,7 +512,7 @@
$base_path = $this->path;
$target = $attrs['target'];
if(!preg_match('/^(http|https)/i',$target))
if(!preg_match('/^(http|https)/i',$target))
{
if(substr($target,0,2)=='./') $target = substr($target,2);
if(substr($target,0,1)!='/') $target = $web_path.$target;
@ -567,19 +567,19 @@
// css file
case 'css' :
if($type == 'unload') {
$output = '<?php Context::unloadCSSFile("'.$source_filename.'"); ?>';
$output = '<?php Context::unloadFile("'.$source_filename.'","'.$attrs['targetie'].'","'.$attrs['media'].'"); ?>';
} else {
$meta_file = $source_filename;
$output = '<?php Context::addCSSFile("'.$source_filename.'",false,"'.$attrs['media'].'","'.$attrs['targetie'].'",'.$attrs['index'].'); ?>';
$output = '<?php Context::loadFile(array("'.$source_filename.'","'.$attrs['media'].'","'.$attrs['targetie'].'","'.$attrs['index'].'"), "'.$attrs['cdn'].'"); ?>';
}
break;
// js file
case 'js' :
if($type == 'unload') {
$output = '<?php Context::unloadJsFile("'.$source_filename.'"); ?>';
$output = '<?php Context::unloadFile("'.$source_filename.'","'.$attrs['targetie'].'","'.$attrs['media'].'"); ?>';
} else {
$meta_file = $source_filename;
$output = '<?php Context::addJsFile("'.$source_filename.'",false,"'.$attrs['targetie'].'",'.$attrs['index'].',"'.$attrs['type'].'"); ?>';
$output = '<?php Context::loadFile(array("'.$source_filename.'","'.$attrs['type'].'","'.$attrs['targetie'].'","'.$attrs['index'].'"), "'.$attrs['cdn'].'"); ?>';
}
break;
}
@ -658,7 +658,7 @@
$filename = array_pop($tmp_arr);
$path = implode('/', $tmp_arr).'/';
// try to include
// try to include
$output = sprintf(
'<?php%s'.
'$oTemplate = &TemplateHandler::getInstance();%s'.
@ -674,8 +674,8 @@
}
/**
* @brief replace $... variables in { } with Context::get(...)
* @param[in] $matches match
* @brief replace $... variables in { } with Context::get(...)
* @param[in] $matches match
* @return replaced result in case of success or NULL in case of error
**/
function _compileVarToContext($matches) {
@ -779,7 +779,7 @@
/**
* @brief replace xe specific code, "<!--%filename-->" with appropriate php code
* @brief replace xe specific code, "<!--%filename-->" with appropriate php code
* @param[in] $matches match
* @return Returns modified result or NULL in case of error
**/
@ -846,19 +846,19 @@
// css file
case 'css' :
if(preg_match('/^(http|\/)/i',$source_filename)) {
$output = sprintf('<?php Context::addCSSFile("%s", %s, "%s", "%s", %s); ?>', $source_filename, 'false', $media, $targetie, $index);
$output = sprintf('<?php Context::loadFile(array("%s", "%s", "%s", "%s")); ?>', $source_filename, $media, $targetie, $index);
} else {
$meta_file = $base_path.$filename;
$output = sprintf('<?php Context::addCSSFile("%s%s", %s, "%s", "%s", %s); ?>', $base_path, $filename, $optimized, $media, $targetie, $index);
$output = sprintf('<?php Context::loadFile(array("%s%s", "%s", "%s", "%s")); ?>', $base_path, $filename, $media, $targetie, $index);
}
break;
// js file
case 'js' :
if(preg_match('/^(http|\/)/i',$source_filename)) {
$output = sprintf('<?php Context::addJsFile("%s", %s, "%s", %s,"%s"); ?>', $source_filename, 'false', $targetie, $index, $type);
$output = sprintf('<?php Context::loadFile(array("%s", "%s", "%s","%s")); ?>', $source_filename, $type, $targetie, $index);
} else {
$meta_file = $base_path.$filename;
$output = sprintf('<?php Context::addJsFile("%s%s", %s, "%s", %s, "%s"); ?>', $base_path, $filename, $optimized, $targetie, $index, $type);
$output = sprintf('<?php Context::loadFile(array("%s%s", "%s", "%s", "%s")); ?>', $base_path, $filename, $type, $targetie, $index);
}
break;
}
@ -869,7 +869,7 @@
}
/**
* @brief import javascript plugin
* @brief import javascript plugin
* @param[in] $matches match
* @return result loading the plugin
* @remarks javascript plugin works as optimized = false
@ -881,12 +881,12 @@
}
/**
* @brief remove loading part of css/ js file
* @brief remove loading part of css/ js file
* @param[in] $matches match
* @return removed result
**/
function _compileUnloadCode($matches) {
// find xml file
// find xml file
$base_path = $this->path;
$given_file = trim($matches[1]);
if(!$given_file) return;
@ -915,17 +915,17 @@
// css file
case 'css' :
if(preg_match('/^(http|https|\/)/i',$source_filename)) {
$output = sprintf('<?php Context::unloadCSSFile("%s", %s, "%s", "%s"); ?>', $source_filename, 'false', $media, $targetie);
$output = sprintf('<?php Context::unloadFile("%s", "%s", "%s"); ?>', $source_filename, $targetie, $media);
} else {
$output = sprintf('<?php Context::unloadCSSFile("%s%s", %s, "%s", "%s"); ?>', $base_path, $filename, $optimized, $media, $targetie);
$output = sprintf('<?php Context::unloadFile("%s%s", "%s", "%s"); ?>', $base_path, $filename, $targetie, $media);
}
break;
// js file
case 'js' :
if(preg_match('/^(http|https|\/)/i',$source_filename)) {
$output = sprintf('<?php Context::unloadJsFile("%s", %s, "%s"); ?>', $source_filename, 'false', $targetie);
$output = sprintf('<?php Context::unloadFile("%s", "%s"); ?>', $source_filename, $targetie);
} else {
$output = sprintf('<?php Context::unloadJsFile("%s%s", %s, "%s"); ?>', $base_path, $filename, $optimized, $targetie);
$output = sprintf('<?php Context::unloadFile("%s%s", "%s"); ?>', $base_path, $filename, $targetie);
}
break;
}

View file

@ -6,8 +6,8 @@
* @version 0.2
*
* it convert xml code into js file and save the result as a cache file
* @code
* {
* @code
* {
* <filter name="name of javascript funcion" act="action name" confirm_msg_code="message string to be prompted when submitting the form" >
* <form> <-- code to validate data in the form
* <node target="name" required="true" minlength="1" maxlength="5" filter="email,userid,alpha,number" equalto="target" />
@ -42,7 +42,7 @@
* tag = key : name of variable that will contain the result of the execution
* }
**/
class XmlJsFilter extends XmlParser {
var $version = '0.2.5';
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
@ -66,7 +66,7 @@
if(!file_exists($this->xml_file)) return;
if(!file_exists($this->js_file)) $this->_compile();
else if(filemtime($this->xml_file)>filemtime($this->js_file)) $this->_compile();
Context::addJsFile($this->js_file, false, '',null,'body');
Context::loadFile(array($this->js_file, 'body', '',null));
}
/**
@ -90,7 +90,7 @@
$module = $attrs->module;
$act = $attrs->act;
$extend_filter = $attrs->extend_filter;
$field_node = $xml_obj->filter->form->node;
if($field_node && !is_array($field_node)) $field_node = array($field_node);
@ -181,7 +181,7 @@
// Check extend_filter_item
$rule_types = array('homepage'=>'homepage', 'email_address'=>'email');
for($i=0;$i<$extend_filter_count;$i++) {
$filter_item = $extend_filter_list[$i];
$target = trim($filter_item->name);
@ -265,7 +265,7 @@
$confirm_msg = '';
if ($confirm_msg_code) $confirm_msg = $lang->{$confirm_msg_code};
$jsdoc = array();
$jsdoc[] = "function {$filter_name}(form){ return legacy_filter('{$filter_name}', form, '{$module}', '{$act}', {$callback_func}, [".implode(',', $responses)."], '".addslashes($confirm_msg)."', {".implode(',', $rename_params)."}) };";
$jsdoc[] = '(function($){';