1
0
Prechádzať zdrojové kódy

Allow echoing raw data instead of htmlentities

Nathaniel van Diepen 7 rokov pred
rodič
commit
cc1878f3c7
1 zmenil súbory, kde vykonal 18 pridanie a 2 odobranie
  1. 18 2
      Data/template.class.php

+ 18 - 2
Data/template.class.php

@@ -32,6 +32,8 @@
 		private static $regex = [
 			'match'=>'/\{([^#\/?_][^}\n]*?)\}/i',
 			'parentmatch'=>'/\{\.\.\/([^#\/?_][^}\n]*?)\}/i',
+			'rawmatch'=>'/\{@([^#\/?_][^}\n]*?)\}/i',
+			'rawparentmatch'=>'/\{@\.\.\/([^#\/?_][^}\n]*?)\}/i',
 			'each'=>'/\{#each ([^}]*)\}([\S\s]*)\{\/each \1\}/i',
 			'exist'=>'/\{#exist ([^}]*)\}([\S\s]*)\{\/exist \1\}/i',
 			'existelse'=>'/\{#exist ([^}]*)\}([\S\s]*)\{#else \1\}([\S\s]*)\{\/exist \1\}/i',
@@ -152,14 +154,24 @@
 							return "<?php {$matches[1]}; ?>";
 						}, $output);
 					},
+					'rawmatch'=>function(&$output){
+						$output = preg_replace_callback(static::$regex['rawmatch'], function($matches){
+							return "<?=(\$data[".var_export($matches[1], true)."] ?? '');?>";
+						}, $output);
+					},
+					'rawparentmatch'=>function(&$output){
+						$output = preg_replace_callback(static::$regex['rawparentmatch'], function($matches){
+							return "<?=(\$parent[count(\$parent)-1][".var_export($matches[1], true)."] ?? '');?>";
+						}, $output);
+					},
 					'match'=>function(&$output){
 						$output = preg_replace_callback(static::$regex['match'], function($matches){
-							return "<?=htmlentities(\$data[".var_export($matches[1], true)."] ?? ''); ?>";
+							return "<?=htmlentities(\$data[".var_export($matches[1], true)."] ?? '');?>";
 						}, $output);
 					},
 					'parentmatch'=>function(&$output){
 						$output = preg_replace_callback(static::$regex['parentmatch'], function($matches){
-							return "<?=htmlentities(\$parent[count(\$parent)-1][".var_export($matches[1], true)."] ?? ''); ?>";
+							return "<?=htmlentities(\$parent[count(\$parent)-1][".var_export($matches[1], true)."] ?? '');?>";
 						}, $output);
 					},
 					'ignored'=>function(&$output, $ignored){
@@ -244,6 +256,10 @@
 			static::$parsers['echo']($output);
 			// Handle {? expression ?}
 			static::$parsers['eval']($output);
+			// Handle {@../name}
+			static::$parsers['rawparentmatch']($output);
+			// Handle {@name}
+			static::$parsers['rawmatch']($output);
 			// Handle {../name}
 			static::$parsers['parentmatch']($output);
 			// Handle {name}