Hi,
i made an extension to the template class of phplib to support frames..
I have two concerns,
1). I am making temporary files using fopen($filename,'w'); to create a dynamic frame set. Interms of traffic on the site and performance... could this really slow things down.. ?
2). i made a method 'parse_frame($target,$varname)' i tried to copy the existing parse method so as to set up the $target as a VARKEY and the parsed template frame file becomes the VARVALUE.. in order to print the frame string i have i have to do
print $template->parse_frame ("frame",array("element","element2","etc")); instead of using $template->p("frame");
I have included the code.. please i would love feed back on the best way to keep navigational elements dynamic as well as content elements, and keeping duplicate code to a minimum..
$t = new templateX("C:/apache group/apache/phplib-7.4-pre1", "keep");
define variables named page and box, referencing files
define variables named page and box, referencing files
$t->set_file(array(
"frame" => "aboutusindexframe.tpl",
"history" => "history.tpl",
"nav" => "nav.tpl",
"side" => "side.tpl"));
define the variables TITLE and PAGETITLE
$t->set_var("IMGDIR","/images");
$t->set_web_path("/tempframes/");
$t->set_temp_dir($t->root . "/tempframes");
print $t->parse_frame("frame", array("history","nav","leftbottom","side"));
<?php
include("template.inc");
class templateX extends template {
var $temp_dir = "";
var $web_path = false;
var $temp_filename = false;
var $frame_file = "";
var $fullpath = "";
function templateX($root = ".",$unknowns = "remove"){
$this->set_root($root);
$this->set_unknowns($unknowns);
}
function set_temp_dir($temp_dir) {
if (!is_dir($temp_dir)) {
$this->halt("set_temp_dir: $temp_dir is not a directory.");
return false;
}
$this->temp_dir = $temp_dir;
return true;
}
function set_web_path($web_path){
$this->web_path = $web_path;
return true;
}
function parse_frame($target,$varname) {
if (!is_array($varname)) {
$str = $this->subst($varname);
//if ($append) {
// $this->set_var($target, $this->get_var($target) . $str);
// } else {
$this->write_temp_file($varname,$str);
if(!$this->temp_filename){
$this->halt("parse_frame: file not written");
return false;
}
if(!$this->web_path){
$this->halt("parse_frame : web path not set");
return false;
}
$this->set_var(strtoupper($varname),$this->web_path . $this->temp_filename);
$str = $this->subst($target);
} else {
reset($varname);
while(list($i, $v) = each($varname)){
$str = $this->subst($v);
$this->write_temp_file($v,$str);
if(!$this->temp_filename){
$this->halt("parse_frame: file not written");
return false;
}
if(!$this->web_path){
$this->halt("parse_frame : web path not set");
return false;
}
$this->set_var(strtoupper($v),$this->web_path . $this->temp_filename);
$str = $this->subst($target);
}
}
return $str;
}
// this->file var or an array having equvilent
function write_temp_file($varname,$str){
$this->temp_filename = $varname . "temp.html";
$this->fullpath = $this->temp_dir ."/" . $this->temp_filename;
$fp = fopen($this->fullpath,'w');
if(!$fp){
$this->halt("write_temp_file : could not open file $this->temp_filename");
return false;
}
fwrite($fp,$str);
fclose($fp);
return $this->temp_filename;
}
function rand_val() {
list($usec, $sec) = explode(' ', microtime());
$val = (float) $sec + ((float) $usec * 100000);
srand($val);
return rand();
}
}
?>
<pre>
<code>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset border="0" rows="210," cols="">
<frame src="{NAV}">
<frameset cols="10,350,350,100" rows="">
<frame src="{SIDE}">
<frame src="{LEFTBOTTOM}" frameborder="0" scrolling="No" noresize marginwidth="0" marginheight="0">
<frame src="{HISTORY}" frameborder="0" scrolling="Auto" noresize marginwidth="0" marginheight="0">
<frame src="{SIDE}">
</frameset>
</frameset>
<noframes>
<body bgcolor="#FFFFFF" text="#000000">
need frames able browser...............
</body>
</noframes>
</code></pre>