From 543987415fa775c2015671c1314b3b3ba6367957 Mon Sep 17 00:00:00 2001 From: taggon Date: Thu, 22 Sep 2011 01:20:20 +0000 Subject: [PATCH] Remove unnecessary code git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9259 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/template/TemplateHandler.class.php | 262 +----------------- .../template/TemplateHandlerTest.class.php | 2 +- 2 files changed, 8 insertions(+), 256 deletions(-) diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php index 9827140f8..c38dc0f53 100644 --- a/classes/template/TemplateHandler.class.php +++ b/classes/template/TemplateHandler.class.php @@ -412,28 +412,29 @@ if($isRemoteFile || $cmd != 'load') return ''; // language file? if($pathinfo['basename'] == 'lang.xml' && substr($pathinfo['dirname'],-5) == '/lang') { - $result = ""; + $result = "Context::loadLang('{$relativeDir}');"; } else { - $result = "compile(); ?>"; + $result = "require_once('./classes/xml/XmlJsFilter.class.php');\$__xmlFilter = new XmlJsFilter('{$relativeDir}','{$pathinfo["basename"]}');\$__xmlFilter->compile();"; } break; case 'js': if($cmd == 'unload') { - $result = ""; + $result = " \$__tmp=array('{$attr['target']}','{$attr['media']}','{$attr['targetie']}','{$attr['index']}','{$attr['usecdn']}','{$attr['cdnprefix']}','{$attr['cdnversion']}');Context::loadFile(\$__tmp);unset(\$__tmp);"; } break; case 'css': if($cmd == 'unload') { - $result = ""; + $result = "\$__tmp=array('{$attr['target']}','{$attr['type']}','{$attr['targetie']}','{$attr['index']}','{$attr['usecdn']}','{$attr['cdnprefix']}','{$attr['cdnversion']}');Context::loadFile(\$__tmp);unset(\$__tmp);"; } break; } + $result = ""; if($metafile) $result = "".$result; return $result; @@ -498,112 +499,6 @@ return $path; } - /** - * @brief replace load tags - **/ - function _replaceLoad($matches) { - $output = $matches[0]; - if(!preg_match_all('/ ([^=]+)=\"([^\"]+)\"/is',$matches[0], $m)) return $matches[0]; - - $type = $matches[1]; - for($i=0,$c=count($m[1]);$i<$c;$i++) - { - if(!trim($m[1][$i])) continue; - $attrs[trim($m[1][$i])] = trim($m[2][$i]); - } - - if(!$attrs['target']) return $matches[0]; - - $web_path = $this->web_path; - $base_path = $this->path; - - $target = $attrs['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; - } - - if(!$attrs['index']) $attrs['index'] = 'null'; - if($attrs['type']!='body') $attrs['type'] = 'head'; - - // if target ends with lang, load language pack - if(substr($target, -4)=='lang') { - if(substr($target,0,2)=='./') $target = substr($target, 2); - $lang_dir = $base_path.$target; - if(is_dir($lang_dir)) $output = sprintf('', $lang_dir); - - // otherwise try to load xml, css, js file - } else { - if(substr($target,0,1)!='/') $source_filename = $base_path.$target; - else $source_filename = $target; - $source_filename = str_replace(array('/./','//'),'/',$source_filename); - - // get filename and path - $tmp_arr = explode("/",$source_filename); - $filename = array_pop($tmp_arr); - - //$base_path = implode("/",$tmp_arr)."/"; - - // get the ext - $tmp_arr = explode(".",$filename); - $ext = strtolower(array_pop($tmp_arr)); - - $output = ' $val) - { - $output .= '$_load_attrs[\''.$key.'\'] = \'' . preg_replace('/\{([^@^ ][^\{\}\n]+)\}/i', "'.\\1.'", $val) . '\';'; - } - $output .= '?>'; - - // according to ext., import the file - switch($ext) { - // xml js filter - case 'xml' : - if(preg_match('/^(http|https)/i',$source_filename)) return; - // create an instance of XmlJSFilter class, then create js and handle Context::addJsFile - $output .= sprintf( - 'compile();%s'. - '?>%s', - "\n", - "\n", - dirname($base_path . $attrs['target']).'/', - $filename, - "\n", - "\n", - "\n" - ); - break; - // css file - case 'css' : - if($type == 'unload') { - $output = sprintf("", $source_filename, $attrs['targetie'], $attrs['media']); - } else { - $meta_file = $source_filename; - $output .= ''; - } - break; - // js file - case 'js' : - if($type == 'unload') { - $output = sprintf("", $source_filename, $attrs['targetie']); - } else { - $meta_file = $source_filename; - $output .= ''; - } - break; - } - } - - if($meta_file) $output = ''.$output; - return $output; - } - /** * @brief replace PHP variables of $ character **/ @@ -611,148 +506,5 @@ if(!$php) return ''; return preg_replace('@(?$1', $php); } - - /** - * @brief replace xe specific code, "" with appropriate php code - * @param[in] $matches match - * @return Returns modified result or NULL in case of error - **/ - function _compileImportCode($matches) { - // find xml file - $base_path = $this->path; - $given_file = trim($matches[1]); - if(!$given_file) return; - if(isset($matches[3])) $optimized = strtolower(trim($matches[3])); - if(!$optimized) $optimized = 'true'; - if(isset($matches[5])) $media = trim($matches[5]); - if(!$media) $media = 'all'; - if(isset($matches[7])) $targetie = trim($matches[7]); - if(!$targetie) $targetie = ''; - else $optimized = 'false'; - - if(isset($matches[9])) $index = intval($matches[9]); - if(!$index) $index = 'null'; - if(isset($matches[11])) $type = strtolower(trim($matches[11])); - if($type!='body') $type = 'head'; - - // if given_file ends with lang, load language pack - if(substr($given_file, -4)=='lang') { - if(substr($given_file,0,2)=='./') $given_file = substr($given_file, 2); - $lang_dir = $base_path.$given_file; - if(is_dir($lang_dir)) $output = sprintf('', $lang_dir); - - // otherwise try to load xml, css, js file - } else { - if(preg_match('/^(http|https):/i',$given_file)) $source_filename = $given_file; - elseif(substr($given_file,0,1)!='/') $source_filename = sprintf("%s%s",$base_path, $given_file); - else $source_filename = $given_file; - - // get filename and path - $tmp_arr = explode("/",$source_filename); - $filename = array_pop($tmp_arr); - - $base_path = implode("/",$tmp_arr)."/"; - - // get the ext - $tmp_arr = explode(".",$filename); - $ext = strtolower(array_pop($tmp_arr)); - - // according to ext., import the file - switch($ext) { - // xml js filter - case 'xml' : - // create an instance of XmlJSFilter class, then create js and handle Context::addJsFile - $output = sprintf( - 'compile();%s'. - '?>%s', - "\n", - "\n", - $base_path, - $filename, - "\n", - "\n", - "\n" - ); - break; - // css file - case 'css' : - if(preg_match('/^(http|\/)/i',$source_filename)) { - $output = sprintf('', $source_filename, $media, $targetie, $index); - } else { - $meta_file = $base_path.$filename; - $output = sprintf('', $base_path, $filename, $media, $targetie, $index); - } - break; - // js file - case 'js' : - if(preg_match('/^(http|\/)/i',$source_filename)) { - $output = sprintf('', $source_filename, $type, $targetie, $index); - } else { - $meta_file = $base_path.$filename; - $output = sprintf('', $base_path, $filename, $type, $targetie, $index); - } - break; - } - } - - if($meta_file) $output = ''.$output; - return $output; - } - - /** - * @brief remove loading part of css/ js file - * @param[in] $matches match - * @return removed result - **/ - function _compileUnloadCode($matches) { - // find xml file - $base_path = $this->path; - $given_file = trim($matches[1]); - if(!$given_file) return; - if(isset($matches[3])) $optimized = strtolower(trim($matches[3])); - if(!$optimized) $optimized = 'true'; - if(isset($matches[5])) $media = trim($matches[5]); - if(!$media) $media = 'all'; - if(isset($matches[7])) $targetie = trim($matches[7]); - if(!$targetie) $targetie = ''; - else $optimized = 'false'; - - if(substr($given_file,0,1)!='/') $source_filename = sprintf("%s%s",$base_path, $given_file); - else $source_filename = $given_file; - - // get path and file nam - $tmp_arr = explode("/",$source_filename); - $filename = array_pop($tmp_arr); - - $base_path = implode("/",$tmp_arr)."/"; - - // get an ext. - $tmp_arr = explode(".",$filename); - $ext = strtolower(array_pop($tmp_arr)); - - switch($ext) { - // css file - case 'css' : - if(preg_match('/^(http|https|\/)/i',$source_filename)) { - $output = sprintf('', $source_filename, $targetie, $media); - } else { - $output = sprintf('', $base_path, $filename, $targetie, $media); - } - break; - // js file - case 'js' : - if(preg_match('/^(http|https|\/)/i',$source_filename)) { - $output = sprintf('', $source_filename, $targetie); - } else { - $output = sprintf('', $base_path, $filename, $targetie); - } - break; - } - - return $output; - } } ?> diff --git a/tests/classes/template/TemplateHandlerTest.class.php b/tests/classes/template/TemplateHandlerTest.class.php index 48259e086..77e3f2407 100644 --- a/tests/classes/template/TemplateHandlerTest.class.php +++ b/tests/classes/template/TemplateHandlerTest.class.php @@ -107,7 +107,7 @@ class TemplateHandlerTest extends PHPUnit_Framework_TestCase // array( '', - '' + '' ), ); }