@@ -864,7 +864,7 @@ private function _getData ($tmplfile, $do_eval=false)
864864
865865 $ regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s* ' ;
866866 $ regex .= 'tmpl_([\w]+)\s* ' ;
867- $ regex .= '(?: ' ;
867+ $ regex .= '((?:( ?: ' ;
868868 $ regex .= '(?: ' ;
869869 $ regex .= '(name|format|escape|op|value|file) ' ;
870870 $ regex .= '\s*=\s* ' ;
@@ -873,30 +873,10 @@ private function _getData ($tmplfile, $do_eval=false)
873873 $ regex .= '((?<=[\" \']) ' ;
874874 $ regex .= '[^\" \']*|[a-z0-9_\.]*) ' ;
875875 $ regex .= '[\" \']? ' ;
876- $ regex .= ')?\s* ' ;
877- $ regex .= '(?: ' ;
878- $ regex .= '(?: ' ;
879- $ regex .= '(name|format|escape|op|value) ' ;
880- $ regex .= '\s*=\s* ' ;
881- $ regex .= ') ' ;
882- $ regex .= '(?:[\" \'])? ' ;
883- $ regex .= '((?<=[\" \']) ' ;
884- $ regex .= '[^\" \']*|[a-z0-9_\.]*) ' ;
885- $ regex .= '[\" \']? ' ;
886- $ regex .= ')?\s* ' ;
887- $ regex .= '(?: ' ;
888- $ regex .= '(?: ' ;
889- $ regex .= '(name|format|escape|op|value) ' ;
890- $ regex .= '\s*=\s* ' ;
891- $ regex .= ') ' ;
892- $ regex .= '(?:[\" \'])? ' ;
893- $ regex .= '((?<=[\" \']) ' ;
894- $ regex .= '[^\" \']*|[a-z0-9_\.]*) ' ;
895- $ regex .= '[\" \']? ' ;
896- $ regex .= ')?\s* ' ;
876+ $ regex .= ')?\s*)*?) ' ;
897877 $ regex .= '(?:>|\/>|}|-->){1} ' ;
898- $ regex .= '([\r\n|\n|\r])? /i ' ;
899- $ data = preg_replace_callback ($ regex , array ($ this , _parseTag), $ data );
878+ $ regex .= '/i ' ;
879+ $ data = preg_replace_callback ($ regex , array ($ this , ' _parseTag ' ), $ data );
900880
901881 if ($ this ->_cache ) { // add cache if need be
902882 $ this ->_createCache ($ data );
@@ -1026,8 +1006,7 @@ private function _arrayBuild($arr)
10261006 * @access private
10271007 * @return string used for eval'ing
10281008 */
1029- private function _parseIf ($ varname , $ value = null , $ op = null , $ namespace = null )
1030- {
1009+ function _parseIf ($ varname , $ value =null , $ op =null , $ namespace =null , $ format =null ) {
10311010 if (isset ($ namespace )) $ namespace = substr ($ namespace , 0 , -1 );
10321011 $ comp_str = '' ; // used for extended if statements
10331012
@@ -1065,9 +1044,19 @@ private function _parseIf($varname, $value = null, $op = null, $namespace = null
10651044 }
10661045 }
10671046 if ($ this ->OPTIONS ['GLOBAL_VARS ' ] && empty ($ namespace )) {
1068- return '(( ' .$ retstr .'[ \'' .$ varname .'\'] !== null) ? ' .$ retstr .'[ \'' .$ varname .'\'] : $this->_vars[ \'' .$ varname .'\']) ' .$ comp_str ;
1069- } else {
1070- return $ retstr ."[' " .$ varname ."'] " .$ comp_str ;
1047+ $ retstr = '(( ' .$ retstr .'[ \'' .$ varname .'\'] !== null) ? ' .$ retstr .'[ \'' .$ varname .'\'] : $this->_vars[ \'' .$ varname .'\']) ' ;
1048+ if (isset ($ format ) && isset ($ value ) && $ format == 'version ' ) {
1049+ return 'version_compare( ' . $ retstr . ', \'' . $ value . '\', ' . (!empty ($ op ) ? $ op : '== ' ) . ') ' ;
1050+ } else {
1051+ return $ retstr .$ comp_str ;
1052+ }
1053+ }
1054+ else {
1055+ if (isset ($ format ) && isset ($ value ) && $ format == 'version ' ) {
1056+ return 'version_compare( ' . $ retstr ."[' " .$ varname ."'] " . ', \'' . $ value . '\', ' . (!empty ($ op ) ? $ op : '== ' ) . ') ' ;
1057+ } else {
1058+ return $ retstr ."[' " .$ varname ."'] " .$ comp_str ;
1059+ }
10711060 }
10721061 }
10731062
@@ -1186,28 +1175,38 @@ private function _parseTag ($args)
11861175 $ wholetag = $ args [0 ];
11871176 $ openclose = $ args [1 ];
11881177 $ tag = strtolower ($ args [2 ]);
1189- $ newline = $ args [9 ];
1190-
1191- if ($ tag == 'else ' ) return '<?php } else { ?> ' .$ newline ;
1178+
1179+ if ($ tag == 'else ' ) return '<?php } else { ?> ' ;
11921180 if ($ tag == 'tmpl_include ' ) return $ wholetag ; // ignore tmpl_include tags
11931181
11941182 if (preg_match ("/^<\/|{\/|<!--\/$/s " , $ openclose ) || preg_match ("/^end[if|loop|unless|comment]$/ " , $ tag )) {
11951183 if ($ tag == 'loop ' || $ tag == 'endloop ' ) array_pop ($ this ->_namespace );
11961184 if ($ tag == 'comment ' || $ tag == 'endcomment ' ) {
1197- return '<?php */ ?> ' .$ newline ;
1198- } else {
1199- return '<?php } ?> ' .$ newline ;
1185+ return '<?php */ ?> ' ;
1186+ }
1187+ else {
1188+ return '<?php } ?> ' ;
12001189 }
12011190 }
12021191
1203- //* arrange attributes
1204- for ($ i =3 ; $ i < 8 ; $ i =($ i +2 )) {
1205- if (empty ($ args [$ i ]) && empty ($ args [($ i +1 )])) break ;
1206- $ key = (empty ($ args [$ i ])) ? 'name ' : strtolower ($ args [$ i ]);
1207- if ($ key == 'name ' && preg_match ('/^(php)?include$/ ' , $ tag )) $ key = 'file ' ;
1208- $ $ key = $ args [($ i +1 )];
1192+ // arrange attributes
1193+ $ tmp_atts = $ args [3 ];
1194+ $ atts = preg_split ('/\s+/ ' , $ tmp_atts );
1195+ foreach ($ atts as $ att ) {
1196+ $ regex = '/(?: ' ;
1197+ $ regex .= '(name|format|escape|op|value|file) ' ;
1198+ $ regex .= '\s*=\s* ' ;
1199+ $ regex .= ')? ' ;
1200+ $ regex .= '(?:[\" \'])? ' ;
1201+ $ regex .= '((?<=[\" \']) ' ;
1202+ $ regex .= '[^\" \']*|[a-z0-9_\.]*) ' ;
1203+ $ regex .= '[\" \']?/ ' ;
1204+ if (preg_match ($ regex , $ att , $ match )) {
1205+ $ key = (empty ($ match [1 ])) ? 'name ' : strtolower ($ match [1 ]);
1206+ if ($ key == 'name ' && preg_match ('/^(php)?include$/ ' , $ tag )) $ key = 'file ' ;
1207+ $ $ key = $ match [2 ];
1208+ }
12091209 }
1210-
12111210 $ var = ($ this ->OPTIONS ['CASELESS ' ]) ? strtolower ($ name ) : $ name ;
12121211
12131212 if ($ this ->_debug && !empty ($ var )) {
@@ -1229,37 +1228,47 @@ private function _parseTag ($args)
12291228 if (empty ($ escape ) && (!empty ($ this ->OPTIONS ['DEFAULT_ESCAPE ' ]) && strtolower ($ this ->OPTIONS ['DEFAULT_ESCAPE ' ]) != 'none ' )) {
12301229 $ escape = strtolower ($ this ->OPTIONS ['DEFAULT_ESCAPE ' ]);
12311230 }
1232- return '<?php ' .$ this ->_parseVar ($ wholetag , $ tag , $ var , @$ escape , @$ format , @$ namespace )." ?> $ newline " ;
1231+ return '<?php ' .$ this ->_parseVar ($ wholetag , $ tag , $ var , @$ escape , @$ format , @$ namespace ).' ?> ' ."\n" ;
1232+ break ;
12331233
12341234 case 'if ' :
1235- return '<?php if ( ' . $ this ->_parseIf ($ var , @$ value , @$ op , @$ namespace ) .') { ?> ' .$ newline ;
1235+ return '<?php if ( ' . $ this ->_parseIf ($ var , @$ value , @$ op , @$ namespace , @$ format ) .') { ?> ' ;
1236+ break ;
12361237
12371238 case 'unless ' :
1238- return '<?php if (! ' . $ this ->_parseIf ($ var , @$ value , @$ op , @$ namespace ) .') { ?> ' .$ newline ;
1239+ return '<?php if (! ' . $ this ->_parseIf ($ var , @$ value , @$ op , @$ namespace , @$ format ) .') { ?> ' ;
1240+ break ;
12391241
12401242 case 'elseif ' :
1241- return '<?php } elseif ( ' . $ this ->_parseIf ($ var , @$ value , @$ op , @$ namespace ) .') { ?> ' .$ newline ;
1243+ return '<?php } elseif ( ' . $ this ->_parseIf ($ var , @$ value , @$ op , @$ namespace , @$ format ) .') { ?> ' ;
1244+ break ;
12421245
12431246 case 'loop ' :
1244- return '<?php ' . $ this ->_parseLoop ($ var ) .'?> ' .$ newline ;
1247+ return '<?php ' . $ this ->_parseLoop ($ var ) .'?> ' ;
1248+ break ;
12451249
12461250 case 'comment ' :
12471251 if (empty ($ var )) { // full open/close style comment
1248- return '<?php /* ?> ' .$ newline ;
1249- } else { // just ignore tag if it was a one line comment
1252+ return '<?php /* ?> ' ;
1253+ }
1254+ else { // just ignore tag if it was a one line comment
12501255 return ;
12511256 }
1257+ break ;
12521258
12531259 case 'phpinclude ' :
12541260 if ($ this ->OPTIONS ['ENABLE_PHPINCLUDE ' ]) {
1255- return '<?php include( \'' .$ file .'\'); ?> ' . $ newline ;
1261+ return '<?php include( \'' .$ file .'\'); ?> ' ;
12561262 }
1263+ break ;
12571264
12581265 case 'include ' :
12591266 return '<?php $this->_getData($this->_fileSearch( \'' .$ file .'\'), 1); ?> ' ;
1267+ break ;
12601268
12611269 case 'dyninclude ' :
12621270 return '<?php $this->_getData($this->_fileSearch($this->_dyninclude[ \'' .$ name .'\']), 1); ?> ' ;
1271+ break ;
12631272
12641273 default :
12651274 if ($ this ->OPTIONS ['STRICT ' ]) vlibTemplateError::raiseError ('VT_ERROR_INVALID_TAG ' , KILL , htmlspecialchars ($ wholetag , ENT_QUOTES ));
0 commit comments