Date: 04/26/00
- Next message: Kristian Köhntopp: "[phplib] Hmm, Silence?"
- Previous message: Michael Chaney: "Re: [PHPLIB] how facilitate sessions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi.
Recently I started using Template class from PHPLIB and noticed that it
completely lacks session management support. Since I'm stuck with PHP3
which does not yet support transparent session ids appended to URLs I
added some basic support for that in Template class. This patch requires
the programmer to always print filled template out with Template::p()
method. Also, the <A> tag href attribute's targets must be enclosed in
quotes. But anyway everyone uses xml or xhtml these days which requires
you to make use of quotes. ;-)
Also I fixed unused variable removal in Template::finish(). Now it leaves
JavaScript untouched... The bottom line is that {variables} must only
comprise of letters, digits and an underscore and must not start with a
digit - just as in any decent programming language. :-/
Here's the diff file:
<<EOF
--- /home/luke/HTML/phplib-7.2b/php/template.inc Thu Mar 23 12:28:52 2000
+++ template.inc Wed Apr 26 16:53:45 2000
@@ -248,16 +248,25 @@
* str: string to finish.
*/
function finish($str) {
+ global $sess;
+ /* First substitute all URLs which contain question marks (in this case session id
+ * is appended after an ampersand (&). With the next pass substitute URLs not containing
+ * question marks - this time use `?' as a separator.
+ */
+ if (isset($sess) && $sess->mode == "get") {
+ $str = preg_replace('/<[aA]( +[^>]*)[hH][rR][eE][fF]="(([^"]+)\?([^"]*))"/', '<a\1href="\2&'.$sess->cookiename.'='.$sess->id.'"', $str);
+ $str = preg_replace('/<[aA]( +[^>]*)[hH][rR][eE][fF]="([^"?]+)"/', '<a\1href="\2?'.$sess->cookiename.'='.$sess->id.'"', $str);
+ }
switch ($this->unknowns) {
case "keep":
break;
case "remove":
- $str = preg_replace("/\{[^}]+\}/", "", $str);
+ $str = preg_replace("/\{[A-Za-z_][A-Za-z0-9_]*\}/", "", $str);
break;
case "comment":
- $str = preg_replace("/\{([^}]+)\}/", "<!-- Template $handle: Variable \\1 undefined -->", $str);
+ $str = preg_replace("/\{([A-Za-z_][A-Za-z0-9_]*)\}/", "<!-- Template $handle: Variable \\1 undefined -->", $str);
break;
}
EOF
-- £ukasz Kowalczyk
- Next message: Kristian Köhntopp: "[phplib] Hmm, Silence?"
- Previous message: Michael Chaney: "Re: [PHPLIB] how facilitate sessions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

