mam plik templates.class.php:
<?
class Templates
{
var $unparsed = array ();
var $parsed = array ();
var $blocks = array();
var $last_loaded;
function load($plik)
{
if($plik == $last_loaded)
{
$this->unparsed[] = end($this->unparsed);
}
elseif(file_exists(F_TPL.$plik.'.tpl'))
{
$file = @fopen(F_TPL.$plik.'.tpl',r);
flock($file, 2);
$this -> unparsed[] = fread($file,filesize(F_TPL.$plik.'.tpl'));
flock($file, 3);
$this->last_loaded = $plik;
}
else
echo 'Plik ' .$plik. ' nie istnieje.';
} #end function load()
function parse()
{
$i=0;
foreach ($this->unparsed as $template)
{
$found = array();
if(preg_match_all("#\{(.+?)\}#is", $template, $found))
{
foreach($found[1] as $block)
{
$block_name = '{'.$block.'}';
$block_values = $this -> blocks[$i][$block];
$template = str_replace($block_name, $block_values, $template);
}
}
$this -> parsed[] = $template;
$i++;
}
} #end function parse()
function show_result($which="all",$to=0)
{
if($which >= 0 && $to >= 0 && $to <= count($this->parsed) && $which != 'all')
{
if($which < $to)
{
while($which <= $to)
{
echo $this->parsed[$which];
$which++;
}
}
else
{
while($which >= $to)
{
echo $this->parsed[$which];
$which--;
}
}
}
elseif($which != 'all')
{
echo $this->parsed[2];
}
else
{
foreach($this->parsed as $parsed)
{
echo $parsed;
}
}
} #end function show_result()
} #end class Templates
define('F_TPL','Templates/');
?>
Jak chce go wywołać to pisze:
<?
include('./templates.class.PHP');
$templates = new Templates;
$templates->load('panel');
$templates->blocks[] = array (
'LINK' => 'link.php');
$templates->parse();
$templates->show_result();
}
?>
Plik .tpl:
// Jakaś treść
<iframe align=center name="zdarzenie" SRC="{LINK}" width=205 height=84 scrolling=auto frameborder=no>
</IFRAME>
// Dalsza część treści
I teraz jest tak że ta strona link.php wygląda następująco:
<?
if(isset($_SESSION['COS'])){
print("OK");
}
?>
No i mam tak że w tym pliku link.php nie odnajduje sesji. W ogóle jej nie widzi. Pytanie jak mam umieścić w templates sesje (bo to chyba od tego zależy), by wszystko ładnie działało.
Bardzo prosze o pomoc.