Parser...
<?php class templates { var $template_name; var $template_content; var $varible; var $section; var $templates_dir = "templates"; var $cache_dir = "cache/templates"; function assign ($varible_name, $varible_value) { $this -> varible[$varible_name] = $varible_value; $this -> section[$varible_name] = $varible_value; } function display ($template_name) { $this -> template_name = $template_name; $this -> template_content = "<?php /* File compiled from '" .$this -> template_name. "' to '" .$this -> template_name. ".php' on (date) */ ?>nn"; echo "<font face='verdana' size='1'>Nie można otworzyc pliku <b>" .$this -> template_name. "</b>.<br></font>"; } else { } $this -> template_content = preg_replace ('/{$([a-zA-Z0-9_]+)}/', '<?php echo $this -> varible['$1']; ?>', $this -> template_content); } /* if (preg_match ('/{section[$([a-zA-Z0-9_]+)]}/', $this -> template_content)) { $this -> template_content = preg_replace ('/{section[$([a-zA-Z0-9_]+)]}/', '<?php while ($row[$this -> section['$1']] = mysql_fetch_array ($this -> section['$1'])) { ?>', $this -> template_content); } */ $this -> template_content = preg_replace ('/{section[$([a-zA-Z0-9_]+)]}/', '<?php for ($this -> section['$1']['start'] = 0; $this -> section['$1']['start'] <= count ($this -> section['$1'])-2; $this -> section['$1']['start']++) { ?>', $this -> template_content); } /* if (preg_match ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', $this -> template_content)) { $this -> template_content = preg_replace ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', '<?php echo $row[$this -> section['$1']]['$2']; ?>', $this -> template_content); } */ $this -> template_content = preg_replace ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', '<?php echo $this -> section['$1'][$this -> section['$1']['start']]['$2']; ?>', $this -> template_content); } } $this -> template_content = preg_replace ('/{iteration[$([a-zA-Z0-9_]+)]}/', '<?php echo $this -> section['$1']['start']+1; ?>', $this -> template_content); } $this -> template_content = preg_replace ('/{include=$([a-zA-Z0-9_]+)}/', '<?php include ($this -> varible['$1']); ?>', $this -> template_content); } echo "<font face='verdana' size='1'>Nie można utworzyć pliku wykonywalnego dla systemu szablonów: <b>" .$this -> template_name. ".php</b>.<br></font>"; } echo "<font face='verdana' size='1'>Błąd zapisu do pliku: <b>" .$this -> template_name. "</b>.<br></font>"; } echo "<font face='verdana' size='1'>Błąd przy zamykaniu pliku: <b>" .$this -> template_name. "</b>.<br></font>"; } if (!@include ($this -> cache_dir. "/" .$this -> template_name. ".php")) { echo "<font face='verdana' size='1'>Błąd dołączenia sparsowanego pliku: <b>" .$this -> template_name. "</b>.<br></font>"; } } } ?>
To jest troche chaotycznie pisane wiec nie patrzcie na kod.
{section[$dane]} pole z bazy: {section[$dane].nazwa_pola_z_bazy} {/section}
Uzycie klasy tak jak w smarty
