Re: [SMARTY-DEV] (fwd) Little Smarty improvement
| From: | messju mohr | Date: | Wed, 12 Nov 2003 21:20:18 +0000 |
| Subject: | Re: [SMARTY-DEV] (fwd) Little Smarty improvement | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-1924@lists.php.net to get a copy of this message | ||
hello benny,
i think realpath isn't used because it would mean a lot of unnecessary
hits to the filesystem (stat-calls).
in your example "index.tpl" and "products/index.tpl" are still unique
filenames if you don't change $smarty->template_dir. if you change
$smarty->template_dir, you also have to change $smarty->compile_dir,
though.
greetings
messju
On Wed, Nov 12, 2003 at 09:48:39AM -0800, Andrei Zmievski wrote:
>
> - Andrei
> Delivered-To: andrei@pair2.php.net
> Delivered-To: alias-scan-andrei@php.net
> Delivered-To: andrei@php.net
> Subject: Little Smarty improvement
> From: Benjamin Roth <benny@kwick.de>
> Reply-To: benny@kwick.de
> To: andrei@php.net
> Organization:
> X-Mailer: Ximian Evolution 1.2.2
> Date: 12 Nov 2003 12:02:11 +0100
> X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=ham
> version=2.60
> X-Spam-Level:
> X-Spam-Checker-Version: SpamAssassin 2.60 (1.212-2003-09-23-exp) on colo
>
> Hi Andrei,
>
> Why don't you use realpath() to get the exact location of the filename
> in _get_auto_filename() (Smarty.class.php).
>
> When we install a new Smarty Version we always have to fix this because
> we use always just a filename in the current directory in
> Smarty::display(). (e.g. $t->display('index.tpl')).
>
> If i run this in different Directories with different templates e.g.:
>
> /index.php
> /index.tpl
> /products/index.php
> /products/index.tpl
>
> This results in displaying always the same (first compiled) template for
> both (different) directories in this example.
> Because
> a) the file itself has always the same name
> b) we address the file relatively
>
> Using realpath() in the crc checksum circumvents this very easily.
>
> -------------------------------------------------------------------
> /**
> * get a concrete filename for automagically created content
> *
> * @param string $auto_base
> * @param string $auto_source
> * @param string $auto_id
> * @return string
> * @staticvar string|null
> * @staticvar string|null
> */
> function _get_auto_filename($auto_base, $auto_source = null,
> $auto_id = null)
> {
>
> .
> .
> .
>
> if(isset($auto_source)) {
> // make source name safe for filename
> $_filename = urlencode(basename($auto_source));
>
>
> // <-- I use basepath here to get the absolute pathname of $auto_source
>
> $_crc32 = crc32(realpath($auto_source)) . $_compile_dir_sep;
>
> // -->
>
> // prepend %% to avoid name conflicts with
> // with $params['auto_id'] names
> $_crc32 = '%%' . substr($_crc32,0,3) . $_compile_dir_sep .
> '%%' . $_crc32;
> $_return .= $_crc32 . $_filename;
> }
> return $_return;
> }
>
> --------------------------------------------------------------------------
>
> Hope this was useful to you.
>
> Greets
> Benny
>
> --
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php