RE: [SMARTY] Bugfixes and some other stuff...

From: Date: Sun, 14 Jul 2002 18:22:19 +0000
Subject: RE: [SMARTY] Bugfixes and some other stuff...
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5304@lists.php.net to get a copy of this message
On a tangent, I sorta think that the template/compile/config dirs should use SMARTY_DIR. I can understand why people would want them in the various dirs. I put them all in a sub dir of smarty. The permissions of templates_c need to be set properly, and it's easier to keep track of a single dir, reduces clutter. Plus, for sub dirs I often need to insert their templates into the templates of parent dirs (the only ways to do this is have the template dirs in your include path, or use the 'file:' resource). It'd be nice to have those dirs use SMARTY_DIR (maybe a true/false var). Maybe allow arrays for the dir variables. 2c ;) Gerard > -----Original Message----- > From: Monte Ohrt [mailto:monte@ispi.net] > Sent: Sunday, July 14, 2002 10:32 AM > To: .SMK. > Cc: smarty-general@lists.php.net > Subject: Re: [SMARTY] Bugfixes and some other stuff... > > > Do you think Smarty should attempt to create the top level directory for > $compile_dir or $cache_dir? IMHO, Smarty shouldn't be responsible for > creating these. Normally user "nobody" would not have permission to > create them anyways, they must be setup before hand. Smarty _does_ > create sub-directories, but only in an established directory. This > sounds better to me, this way Smarty isn't blindly trying to create a > new directory somewhere. If you don't have that directory created > already, you don't have Smarty installed properly (or if you do > something dynamic, your application should be responsible for > creating it.) > > Thoughts on this? > > Monte > > > .SMK. wrote: > > >Warning: Failed opening '\N117\N1172603085\index.tpl.php' for inclusion > >(include_path='.;e:/httpd/php/pear') in > >path\to\Smarty-2.2.0-CVS\Smarty.class.php on line 656 > > > >... comes from missing templates_c directory in _get_auto_filename(). > >_get_include_path() already returns FALSE in case it couldn't find the > >file, so I suppose lines 1446 ff. in Smarty.class.php should be changed > >to something like this: > > > >// auto_base not found, try include_path > >if(!$this->_get_include_path($auto_base,$_include_path)) { > > //still not found, create it > > mkdir($auto_base, 0700); > > $res = $auto_base . DIR_SEP; > >} else { > > $res = $_include_path . DIR_SEP; > >} > > > >*** > > > >Fatal error: Call to undefined function: () in > >path\to\Smarty-2.2.0-CVS\Smarty.class.php on line 1004 > > > >... is a Windows bug: debug.tpl is prepended with SMARTY_DIR in class > >constructor, but absolute paths need a resource type. Line 216 should > >look like this: > > > >$this->debug_tpl = 'file:'.SMARTY_DIR.'debug.tpl'; > > > >*** > > > >Some performance hints... > > > >Double-quoted strings containing variables: > > > >Writing something like: > >$arg_list[] = "'$arg_name' => $arg_value"; > >instead of separating string and variables: > >$arg_list[] = "'".$arg_name."' => ".$arg_value; > >is 25% slower. > > > > > >SWITCH constructs using literal strings: > > > >Instead of writing: > >switch ($tag_command) { > > case 'include': > > return $this->_compile_include_tag($tag_args); > > case 'include_php': > > return $this->_compile_include_php_tag($tag_args); > > ... > > > >why not using PHP's fast hashing algorithm using a lookup table: > > > >$_TAGS = array( > > 'include' => 1, > > 'include_php' => 2, > > 'if' => 3, > > ... > >); > > > >switch ($_TAGS[$tag_command]) { > > case 1: > > return $this->_compile_include_tag($tag_args); > > case 2: > > return $this->_compile_include_php_tag($tag_args); > > case 3: > > return $this->_compile_if_tag($tag_args); > > ... > > > >With only two test CASEs, the code is 5% faster (almost nothing), but > >with 4 CASEs, the code executes about 30% faster. > > > >*** > > > >>From the TODO list: > >Idea to correctly capture nested php tag syntax in templates: > > <?php echo "<?php exit(); ?>"; ?> > > > >I use some code to strip all literal strings (both double- and > >single-quoted) from a string containing executable logic: > >First I replace all literal strings in non-escaped quotes with control > >codes 0x01 and 0x02, resp. > >Then I perform all my work on the 'cleaned' string, and last I inject > >the stripped literal strings again. > > > >function save_literal( &$expr ) > >{ > > $stack = array(); > > preg_match_all( > > >>"/(?<!\\\\)\"(?:(?<=\\\\)(?:\\\\\\\\)+\"|(?<=(?<!\\\\)\\\\)\"|[^\"])*\"/ > >", $expr, $reg ); > > $expr = str_replace( $stack[] = $reg[0], "\x01", $expr ); > > preg_match_all( > > >>"/(?<!\\\\)'(?:(?<=\\\\)(?:\\\\\\\\)+'|(?<=(?<!\\\\)\\\\)'|[^'])*'/", > >$expr, $reg ); > > $expr = str_replace( $stack[] = $reg[0], "\x02", $expr ); > > return $stack; > >} > > > >function restore_literal( $expr, $stack ) > >{ > > $expr = vsprintf( str_replace("\x02", "%s", $expr), array_pop($stack) > >); > > return vsprintf( str_replace("\x01", "%s", $expr), array_pop($stack) > > ); > >} > > > >//assume $expr = "<?php echo \"<?php exit(); ?>\"; ?>"; > >//modify $expr, save the returned stack > >$stack = save_literal( $expr ); > >//do something with $expr > >... > >//inject saved literal strings in (modified) $expr again > >$expr = restore_literal( $expr, $stack ); > > > >*** > > > >Ok, enough said for today > > > >.SMK. > > > > > > > > > > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.smarty.general (#5304) next »