Date: 10/31/99
- Previous message: Kristian Koehntopp: "[PHPLIB-DEV] Re: [PHPLIB] Function nextid() with PostgreSql"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: kk
Date: Sun Oct 31 21:07:16 1999
Modified files:
php-lib/CHANGES
php-lib/doc/sgml/04-template.sgml
php-lib/php/db_pgsql.inc
php-lib/php/template.inc
Log message:
Changed Template so that there can be multiple directories for template files.
Index: php-lib/CHANGES
diff -u php-lib/CHANGES:1.129 php-lib/CHANGES:1.130
--- php-lib/CHANGES:1.129 Fri Oct 29 15:55:12 1999
+++ php-lib/CHANGES Sun Oct 31 21:06:45 1999
@@ -1,9 +1,13 @@
-$Id: CHANGES,v 1.129 1999/10/29 13:55:12 kk Exp $
+$Id: CHANGES,v 1.130 1999/10/31 20:06:45 kk Exp $
+31-Oct-1999 kk
+ - Template does understand search pathes as root directory now.
+
29-Oct-1999 negro
- Corrected a piece of example code in doc in order to use addslashes.
29-Oct-1999 kk
+ - nextid() to db_pgsql.inc
- Ok, Massimiliano, try this one. A complete Example_Auth class
featuring reg and log mode and transparent switching between
both.
Index: php-lib/doc/sgml/04-template.sgml
diff -u php-lib/doc/sgml/04-template.sgml:1.5 php-lib/doc/sgml/04-template.sgml:1.6
--- php-lib/doc/sgml/04-template.sgml:1.5 Tue Oct 26 20:12:16 1999
+++ php-lib/doc/sgml/04-template.sgml Sun Oct 31 21:06:45 1999
@@ -1,4 +1,4 @@
-<!-- $Id: 04-template.sgml,v 1.5 1999/10/26 18:12:16 kk Exp $ -->
+<!-- $Id: 04-template.sgml,v 1.6 1999/10/31 20:06:45 kk Exp $ -->
<sect1>Template
<p>
<em/Note:/ If you think that this is like FastTemplates, read
@@ -51,8 +51,8 @@
file<colsep>Hash of strings. A translation table which
translates variable names into filenames.<rowsep>
-root<colsep>String (Pathname). The base directory from which
-template files are being loaded.<rowsep>
+root<colsep>Array of pathnames. A list of base directories from
+which template files are being loaded.<rowsep>
varkeys<colsep>Hash of strings. A translation table which
translates variable names into regular expressions for
@@ -76,15 +76,15 @@
<tag>Template($root = ".", $unknowns = "remove")</tag>
<p>
Constructor. May be called with two optional parameters. The
-first parameter sets the template directory (see
+first parameter sets the template directories (see
<tt/set_root()/, the second parameter sets the policy
regarding handling of unknown variables.
<tag>set_root($root)</tag>
<p>
-The function checks that $root is a valid directory and sets
-this directory as the base directory where templates are being
-stored.
+The function checks that $root is an array of valid directory
+and sets these directories as the base directories where
+templates are being loaded from.
<tag>set_unknowns($unknowns = "remove")</tag>
<p>
@@ -190,10 +190,11 @@
<tag>filename($filename)</tag>
<p>
When called with a relative pathname, this function will return
-the pathname with $this->root prepended. Absolute pathnames are
-taken unchanged.
+the pathname with the appropriate directory from $this->root
+prepended. Absolute pathnames are taken unchanged.
-The resulting filename must exist, or an error is generated.
+The resulting filename must exist in any base directory, or an
+error is generated.
<tag>varname($varname)</tag>
<p>
Index: php-lib/php/db_pgsql.inc
diff -u php-lib/php/db_pgsql.inc:1.12 php-lib/php/db_pgsql.inc:1.13
--- php-lib/php/db_pgsql.inc:1.12 Wed Oct 27 15:17:34 1999
+++ php-lib/php/db_pgsql.inc Sun Oct 31 21:06:46 1999
@@ -5,7 +5,7 @@
* Copyright (c) 1998,1999 NetUSE GmbH
* Boris Erdmann, Kristian Koehntopp
*
- * $Id: db_pgsql.inc,v 1.12 1999/10/27 13:17:34 kk Exp $
+ * $Id: db_pgsql.inc,v 1.13 1999/10/31 20:06:46 kk Exp $
*
*/
@@ -144,6 +144,32 @@
function p($Name) {
print $this->Record[$Name];
+ }
+
+ ## contributed Saillard Luc <luc.saillard <email protected>>
+
+ function nextid($seq_name) {
+ $this->connect();
+
+ $q_id= <email protected>($this->Link_ID,"select nextval('$seq_name')");
+ if (!$q_id) {
+ if (! <email protected>($this->Link_ID,"create sequence $seq_name")) {
+ $this->halt("<BR> nextid() function - unable to create sequence");
+ return 0;
+ }
+ $q_id= <email protected>($this->Link_ID,"select nextval('$seq_name')");
+ if (!$q_id) {
+ $this->halt("<BR>pg_exec() failed:<BR>nextID function");
+ return 0;
+ }
+ }
+ $r= <email protected>($q_id, 0);
+ if ($r==false)
+ $nextid=0;
+ else
+ $nextid=$r[0];
+
+ return $nextid;
}
function halt($msg) {
Index: php-lib/php/template.inc
diff -u php-lib/php/template.inc:1.7 php-lib/php/template.inc:1.8
--- php-lib/php/template.inc:1.7 Tue Oct 26 20:40:44 1999
+++ php-lib/php/template.inc Sun Oct 31 21:06:46 1999
@@ -5,7 +5,7 @@
* (C) Copyright 1999 NetUSE GmbH
* Kristian Koehntopp
*
- * $Id: template.inc,v 1.7 1999/10/26 18:40:44 kk Exp $
+ * $Id: template.inc,v 1.8 1999/10/31 20:06:46 kk Exp $
*
*/
@@ -24,8 +24,8 @@
*/
var $block = array();
- /* relative filenames are relative to this pathname */
- var $root = "";
+ /* Template searches for files in one of these directories */
+ var $root = array( "." );
/* $varkeys[key] = "key"; $varvals[key] = "value"; */
var $varkeys = array();
@@ -53,15 +53,29 @@
}
/* public: setroot(pathname $root)
- * root: new template directory.
+ * root: array with template directories.
*/
function set_root($root) {
- if (!is_dir($root)) {
- $this->halt("set_root: $root is not a directory.");
- return false;
+ if (!is_array($root) {
+ if (!is_dir($root)) {
+ $this->halt("set_root (scalar): $root is not a directory.");
+ return false;
+ }
+
+ $this->root = array($root);
+
+ } else {
+ reset($root);
+ while(list($k, $v) = each($root)) {
+ if (!is_dir($v)) {
+ $this->halt("set_root (array): $v (entry $k of root) is not a directory.");
+ return false;
+ }
+
+ $this->root = $root;
+ }
}
-
- $this->root = $root;
+
return true;
}
@@ -305,14 +319,27 @@
* filename: name to be completed.
*/
function filename($filename) {
- if (substr($filename, 0, 1) != "/") {
- $filename = $this->root."/".$filename;
+ /* short path for absolute filenames */
+ if (substr($filename, 0, 1) == "/") {
+ if (file_exists($filename))
+ return $filename;
+ else {
+ $this->halt("filename (absolute): $filename does not exist.");
+ return false;
+ }
}
-
- if (!file_exists($filename))
- $this->halt("filename: file $filename does not exist.");
- return $filename;
+ /* search path for a matching file */
+ reset($this->root);
+ while(list($k, $v) = each($this->root)) {
+ $f = "$v/$filename";
+
+ if (file_exists($f))
+ return $f;
+ }
+
+ $this->halt("filename (relative): file $filename does not exist anywhere in " . implode(" ", $this->root));
+ return false;
}
/* private: varname($varname)
-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.
- Previous message: Kristian Koehntopp: "[PHPLIB-DEV] Re: [PHPLIB] Function nextid() with PostgreSql"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

