thank ya. you correctly understand how the widget requests work.
for my current project (and my first with php), i'm converting a 1,000 page static .html site that lives in a directory structure over to 1 php script (web.php3), 2 template (one for ie/win, one for others), and 1 MySQL db (subdivided into tables based on content; about,links,main,magazine,members,etc.).
I currently only need the template feature of phplib. I plan to incorporate the other elements once I complete this basic phase. The template has empty slots for CSS sizes, meta-tags, and page content, along with a few slots to turn page elements 'on' or 'off' with comment tags.
The page works with search-engine and novice-computer-user friendly URLs. In other words, instead of www.website.org/web.php3?table=about&page=index, the page reference would be www.website.org/web/about/index.html.
My search function is called like any other page. There's a little search window in my template that appears on every page, and the submit button has an action of www.website.org/web/search/results.html.
below is the template section of my web.php3 script. The part that does the eval() is at the very bottom (named $magicfairy). I left all of my comments in just in case they might be helpful to anyone...
/
$vars de-cloaks the necessary page assembly variables hidden in the URL.
It basically says $vars=whatever is in the URL after 'web', from the 2nd to 6th from last character.
This removes the '/' and '.html' from whatever is after 'web'
www.website.org/web/main/index.html is stripped down to 'main/index'
/
$vars = substr($PATH_INFO, 1, -5);
/ This splits the de-cloaked variables into 2 parts of an array
/$slash = "/";
$var_array = split($slash, $vars);
/ This assigns $table and $page the proper values /
$table = $var_array[0];
$page= $var_array[1];
/ Database connection stuff. "server", "username", "password" /
$db = mysql_connect("foo", "bar", "foobar");
/ Database name - note: Database name and Username are the same for us /
mysql_select_db("foo", $db);
/ This selects the proper page info from the MySQL Database /
$result = mysql_query("SELECT * FROM $table where page=\"$page\"", $db);
/ This includes the code for the template engine /
include "/templates/template.inc";
/ Here we assign each of the necessary variables their values from MySQL
some variables, such as the CSS vars and the $template var are already defined
in the CSS GENERATION section above/
$title = mysql_result($result,$page,"title");
$expires = mysql_result($result,$page,"expires");
$robots = mysql_result($result,$page,"robots");
$description = mysql_result($result,$page,"description");
$keywords = mysql_result($result,$page,"keywords");
$ad_zone = mysql_result($result,$page,"ad_zone");
$location = "- MBI > $table > $page -";
$content = mysql_result($result,$page,"content");
/ This line creates a new temporary file for use with the template engine /
$t = new Template("/home/cust2/usr2049/templates/");
/ Choose template file. /
$t->set_file("website",$template);
/ Determine if banner ad cell at top of template is on or off /
if ($ad_zone == "z") {
$t->set_var("onoroff1","<!--");
$t->set_var("onoroff2","-->");
} else {
$t->set_var("onoroff1"," ");
$t->set_var("onoroff2"," ");
}
/ This lets the template engine know how our variable names are referred to in the template file.
For examplpe, we let the template engine know that when it finds the phrase "page_title" in curly
brackets it is to replace the phrase with the value of $title /
$t->set_var("page_title",$title);
$t->set_var("page_expires",$expires);
$t->set_var("page_robots",$robots);
$t->set_var("page_description",$description);
$t->set_var("page_keywords",$keywords);
$t->set_var("ad_zone",$ad_zone);
$t->set_var("your_location",$location);
$t->set_var("page_content",$content);
$t->set_var("font_size",$font_size);
$t->set_var("font_smaller",$font_smaller);
$t->set_var("font_smallest",$font_smallest);
$t->set_var("site_fonts",$site_fonts);
/ This is where the final parsing takes place. By default, only the line:
'$t->parse("weboutput","website");' would be used by the engine. I had to
create the $magicfairy in order to be able to place PHP code like the search function
directly in the database. This way, the file gets parsed, Content gets inserted, then
The MagicFairy runs back through the file and executes any PHP code it finds /
$t->parse("weboutput","website");
$magicfairy = $t->parse("weboutput","website");
eval ("?>".$magicfairy);
?>
The above code works great for all pages that don't contain php code pulled from the database.
Thank you for help!
-dolphinsnot