@@ -233,7 +233,7 @@ public function newTemplate($tmplfile)
233233 public function setVar ($ k , $ v = null , $ encode = false )
234234 {
235235 global $ app ;
236-
236+
237237 if (is_array ($ k )) {
238238 foreach ($ k as $ key => $ value ){
239239 $ key = ($ this ->OPTIONS ['CASELESS ' ]) ? strtolower (trim ($ key )) : trim ($ key );
@@ -1079,12 +1079,12 @@ private function _parseIf($varname, $value = null, $op = null, $namespace = null
10791079 private function _parseHook ($ name )
10801080 {
10811081 global $ app ;
1082-
1082+
10831083 if (!$ name ) return false ;
1084-
1084+
10851085 $ module = isset ($ _SESSION ['s ' ]['module ' ]['name ' ]) ? $ _SESSION ['s ' ]['module ' ]['name ' ] : '' ;
10861086 $ form = isset ($ app ->tform ->formDef ['name ' ]) ? $ app ->tform ->formDef ['name ' ] : '' ;
1087-
1087+
10881088 $ events = array ();
10891089 if ($ module ) {
10901090 $ events [] = $ module . ': ' . ($ form ? $ form : '' ) . ': ' . $ name ;
@@ -1093,9 +1093,9 @@ private function _parseHook ($name)
10931093 $ events [] = $ name ;
10941094 $ events [] = 'on_template_content ' ;
10951095 }
1096-
1096+
10971097 $ events = array_unique ($ events );
1098-
1098+
10991099 for ($ e = 0 ; $ e < count ($ events ); $ e ++) {
11001100 $ tmpresult = $ app ->plugin ->raiseEvent ($ events [$ e ], array (
11011101 'name ' => $ name ,
@@ -1104,10 +1104,10 @@ private function _parseHook ($name)
11041104 ), true );
11051105 if (!$ tmpresult ) $ tmpresult = '' ;
11061106 else $ tmpresult = $ this ->_getData ($ tmpresult , false , true );
1107-
1107+
11081108 $ result .= $ tmpresult ;
11091109 }
1110-
1110+
11111111 return $ result ;
11121112 }
11131113
@@ -1121,17 +1121,12 @@ private function _parseLoop ($varname)
11211121 {
11221122 array_push ($ this ->_namespace , $ varname );
11231123 $ tempvar = count ($ this ->_namespace ) - 1 ;
1124- $ retstr = "for ( \$_ " .$ tempvar ."=0 ; \$_ " .$ tempvar ." < (isset( \$this->_arrvars " ;
1125- for ($ i =0 ; $ i < count ($ this ->_namespace ); $ i ++) {
1126- $ retstr .= "[' " .$ this ->_namespace [$ i ]."'] " ;
1127- if ($ this ->_namespace [$ i ] != $ varname ) $ retstr .= "[ \$_ " .$ i ."] " ;
1128- }
1129- $ retstr .= ") ? count( \$this->_arrvars " ;
1124+ $ retstr = "for ( \$_ " .$ tempvar ."=0 ; \$_ " .$ tempvar ." < \$this->_tpl_count( \$this->_arrvars " ;
11301125 for ($ i =0 ; $ i < count ($ this ->_namespace ); $ i ++) {
11311126 $ retstr .= "[' " .$ this ->_namespace [$ i ]."'] " ;
11321127 if ($ this ->_namespace [$ i ] != $ varname ) $ retstr .= "[ \$_ " .$ i ."] " ;
11331128 }
1134- return $ retstr .") : 0) ; \$_ " .$ tempvar ."++) { " ;
1129+ return $ retstr ."); \$_ " .$ tempvar ."++) { " ;
11351130 }
11361131
11371132 /**
@@ -1230,7 +1225,7 @@ private function _parseTag ($args)
12301225 $ wholetag = $ args [0 ];
12311226 $ openclose = $ args [1 ];
12321227 $ tag = strtolower ($ args [2 ]);
1233-
1228+
12341229 if ($ tag == 'else ' ) return '<?php } else { ?> ' ;
12351230 if ($ tag == 'tmpl_include ' ) return $ wholetag ; // ignore tmpl_include tags
12361231
@@ -1308,10 +1303,10 @@ private function _parseTag ($args)
13081303 if ($ this ->OPTIONS ['ENABLE_PHPINCLUDE ' ]) {
13091304 return '<?php include( \'' .$ file .'\'); ?> ' ;
13101305 }
1311-
1306+
13121307 case 'hook ' :
13131308 return $ this ->_parseHook (@$ var );
1314-
1309+
13151310 case 'include ' :
13161311 return '<?php $this->_getData($this->_fileSearch( \'' .$ file .'\'), 1); ?> ' ;
13171312
@@ -1466,6 +1461,27 @@ private function _escape_hex($str = '', $entity = false) {
14661461 return $ return ;
14671462 }
14681463
1464+ /**
1465+ * Used during in evaled code to replace PHP count function for PHP 8 compatibility
1466+ * @var variable to be counted
1467+ */
1468+ private function _tpl_count ($ var )
1469+ {
1470+ $ retvar = 0 ;
1471+ if (isset ($ var )) {
1472+ if (is_array ($ var )) {
1473+ $ retvar = count ($ var );
1474+ } elseif (is_null ($ var )) {
1475+ $ retvar = 0 ;
1476+ } else {
1477+ $ retvar = 1 ;
1478+ }
1479+ } else {
1480+ $ retvar = 0 ;
1481+ }
1482+ return $ retvar ;
1483+ }
1484+
14691485 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14701486 The following functions have no use and are included just so that if the user
14711487 is making use of vlibTemplateCache functions, this doesn't crash when changed to
0 commit comments