kiedys napisalem funkcje do obslugi szablonow... duzo jej do doskonalosci, ale moze sam ja skonczysz, oto kod
<?php
class TemplateManager {
var $TemplateName;
var $TemplateContent;
var $Varible;
var $Section;
var $TemplatesDir = "templates/default";
var $CacheDir = "cache/templates";
function AssignVarible ($VaribleName, $VaribleValue) {
$this -> Varible[$VaribleName] = $VaribleValue;
$this -> Section[$VaribleName] = $VaribleValue;
}
function TemplateDisplay ($TemplateName) {
$this -> TemplateName = $TemplateName;
$this -> TemplateContent = "<?php /* File compiled from '" .$this -> TemplateName. "' to '" .$this -> TemplateName. ".php' on (date) */ ?>nn";
if (!@implode ("", file ($this -> TemplatesDir
. "/" .$this -> TemplateName
))) {
echo "<font face='verdana' size='1'>Nie można otworzyc pliku <b>" .$this -> TemplateName
. "</b>.<br></font>";
} else {
$this -> TemplateContent
.= @implode ("", file ($this -> TemplatesDir
. "/" .$this -> TemplateName
)); }
if (preg_match ('/{$([a-zA-Z0-9_]+)}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{$([a-zA-Z0-9_]+)}/', '<?php echo $this -> Varible['$
1']; ?>', $this -> TemplateContent
); }
if (preg_match ('/{Section[$([a-zA-Z0-9_]+)]}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{Section[$([a-zA-Z0-9_]+)]}/', '<?php for ($this -> Section['start
'] = 0; $this -> Section['start
'] <= count ($this -> Section['$
1'])-1; $this -> Section['start
']++) { ?>', $this -> TemplateContent
); }
if (preg_match ('/{Section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{Section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', '<?php echo $this -> Varible['$
1'][$this -> Section['start
']]['$
2']; ?>', $this -> TemplateContent
); }
if (preg_match ('/{/Section}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{/Section}/', '<?php } ?>', $this -> TemplateContent
); }
if (preg_match ('/{iteration[$([a-zA-Z0-9_]+)]}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{iteration[$([a-zA-Z0-9_]+)]}/', '<?php echo $this -> Section['start
']+1; ?>', $this -> TemplateContent
); }
if (preg_match ('/{include=$([a-zA-Z0-9_]+)}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{include=$([a-zA-Z0-9_]+)}/', '<?php include ($this -> Varible['$
1']); ?>', $this -> TemplateContent
); }
if (preg_match ('/{if $([a-zA-Z0-9_]+) (.*?) "([a-zA-Z0-9_]+)"}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{if $([a-zA-Z0-9_]+) (.*?) "([a-zA-Z0-9_]+)"}/', '<?php if ($this -> Varible['$
1'] $2 "$3") { ?>', $this -> TemplateContent
); }
#
if (preg_match ('/{if $([a-zA-Z0-9_]+) == "empty"}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{if $([a-zA-Z0-9_]+) == "empty"}/', '<?php if (empty ($this -> Varible['$
1'])) { ?>', $this -> TemplateContent
); }
#
if (preg_match ('/{if Section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+) (.*?) "([a-zA-Z0-9_]+)"}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{if Section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+) (.*?) "([a-zA-Z0-9_]+)"}/', '<?php if ($this -> Varible['$
1'][$this -> Section['start
']]['$
2'] $3 "$4") { ?>', $this -> TemplateContent
); }
if (preg_match ('/{else}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{else}/', '<?php } else { ?>', $this -> TemplateContent
); }
if (preg_match ('/{/if}/', $this -> TemplateContent
)) {
$this -> TemplateContent
= preg_replace ('/{/if}/', '<?php } ?>', $this -> TemplateContent
); }
if (!$file_open = @fopen ($this -> CacheDir
. "/" .$this -> TemplateName
. ".php", 'w')) {
echo "<font face='verdana' size='1'>Nie można utworzyć pliku wykonywalnego dla systemu szablonów: <b>" .$this -> TemplateName
. ".php</b>.<br></font>"; }
if (!@fputs ($file_open, $this -> TemplateContent
)) {
echo "<font face='verdana' size='1'>Błąd zapisu do pliku: <b>" .$this -> TemplateName
. "</b>.<br></font>"; }
echo "<font face='verdana' size='1'>Błąd przy zamykaniu pliku: <b>" .$this -> TemplateName
. "</b>.<br></font>"; }
if (!include ($this -> CacheDir. "/" .$this -> TemplateName. ".php")) {
echo "<font face='verdana' size='1'>Błąd dołączenia sparsowanego pliku: <b>" .$this -> TemplateName
. "</b>.<br></font>"; }
}
}
?>