PHPLib Template! am I stupit or is it a bug?

From: Date: Sat, 08 Feb 2003 18:58:16 +0000
Subject: PHPLib Template! am I stupit or is it a bug?
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3657@lists.php.net to get a copy of this message
Hy everybody! I'm using Template_PHPLib that released some days ago. After changing the method-names in my old scripts, it worked like expected, and no problem occured. I know that class very well from PHPLib itself, and had no problem with it until today. So today I started a new project, and had a typical structure like that .index.php /template /include so i started within index.php like that: $TMPL = new Template_PHPLIB( './template/' ); $TMPL -> setFile( array("MAINTMPL"=>"main.html","TOPICTMPL"=>'album.html') ); but I became an error implode() [function.implode.html]: Bad arguments. in E:\httpd\pear\HTML\Template\PHPLIB.php on line 248 // I stipped the comments in my version so linenumbers may differ. The error occurs in the method _loadFile also all the other possibilitys of writing the template-dir-path, even a absolute path were leading to an error. The only way was to call the Template was from within a subdirectory like the include-dir. When I print out the path that is loaded in the _loadFile- method (that causes the error), it shows something like that: ../template/../template/album.html so it seams, that there's a bug, or am I completely wrong? How is it with a path like this? Does this effect the performance of the file() method? Or is this a symlink, that might be denied from the apache-conf? As I can see, this error is produced, because the if clause in _filename() is not greedy enough and secondly not realy OS-indipendent, so that a second root-path is added. Does this also happen under Linux? But instead of fixing that if clause, the solution for this error might rather be solved, be editing the setFile() Method to function setFile( $handle, $filename = "" ) { if ( !is_array( $handle ) ) { if ( $filename == "" ) { $this -> halt( "setFile: For handle $handle filename is empty." ); return false; } $this -> file[$handle] = $filename; // <= stripped _filename() } else { reset( $handle ); while ( list( $h, $f ) = each( $handle ) ) { $this -> file[$h] = $f; // <= stripped _filename() } } } By the way! I found a solution, to strip untouched blocks, when parsing out the Template with p(); You just have to add following lines: class Template_PHPLIB { $removeUntouched = true; ......... function p( $varname ) { $str = $this -> finish( $this -> getVar( $varname ) ); if($removeUntouched){ $str = preg_replace( '/<!--\s+BEGIN ([a-zA-Z0-9-_]*)\s+-->.*<!--\s+END \\1\s+-->/sm', "", $str ); } print $str; } This little update would give this template-class much more flexibility whithout increasing the performance to much. In my Tests there was no realizeable performancebreak. Your Till Dawn

« previous php.pear.general (#3657) next »