diff --git a/FAQ b/FAQ
index d160e569..7e3eb331 100644
--- a/FAQ
+++ b/FAQ
@@ -139,4 +139,4 @@ Q: My ISP did not setup the PEAR repository, nor will they set it up. How do I
A: The easiest thing to do is grab all of PEAR and install it locally for your
own use. There's nothing that says PEAR must be installed in its default
directory. There won't be a version of Smarty that runs without PEAR, as it
- quite dependant on it, especially with database support.
+ quite dependant on it.
diff --git a/NEWS b/NEWS
index 8590629f..87abb5a6 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
Version 1.4.0
-------------
+ - added "componentized templates" tip into documentation (Monte)
+ - added {php}{/php} tags for embedding php code into templates (Monte)
+ - changed default value of $show_info_header to false (Monte)
- implemented '->' syntax for accessing properties of objects passed to the
template. (Andrei)
- allowed custom functions to receive Smarty object as the second
@@ -25,7 +28,7 @@ Version 1.4.0
- changed Smarty to compile templates at runtime, allowing for arbitrary
template resources. (Monte)
- added fix for LOCK_EX under Windows and changed a couple of file
- permissions for security. (Monte)
+ permissions for security. (Monte, Fernando Nunes)
- allow arbitrary date strings to date_format, html_select_date and
html_select_time (Monte)
diff --git a/QUICKSTART b/QUICKSTART
index f013eaa7..f7c4f950 100644
--- a/QUICKSTART
+++ b/QUICKSTART
@@ -62,7 +62,7 @@ drwxrwxrwx 2 user group 512 Jan 18 14:18 templates_c/
Now we need to create two files, index.php and templates/index.tpl. index.php
is the file that we will be calling from our web browser. index.tpl is the file
-that Smarty will use as it's template file. (.tpl files are never called
+that Smarty will use as its template file. (.tpl files are never called
directly from the browser, only Smarty calls them.)
@@ -178,7 +178,7 @@ $smarty->display("index.tpl");
--------- templates/header.tpl --------
-
{$title}
+{$title|default:"no title"}
--------- templates/footer.tpl --------
@@ -191,7 +191,7 @@ You can pass as many variables as you want. The included file inherits all the
current template vars, plus any that are passed to it. The passed variables are
only available within the scope of the included file. Also notice the way the
$title variable is printed to the template. It uses a variable modifier called
-"default". Printing {$title} means that if the value of
+"default". Printing {$title|default:"no title"} means that if the value of
$title is empty, the text "no title" will be printed instead of nothing.
IF/ELSEIF/ELSE
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 7f8cc1af..a84e90fe 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -41,7 +41,12 @@ problems when displaying content other than HTML, so now you must explicitly
set this flag to true to show the header information (or change the default in
your copy of Smarty.)
-CHANGES/ENHANCEMENTS
+Documentation is written in docbook format. I updated the docbook -> HTML
+generating software & style-sheets, and consequently the examples are no longer
+in a different background color. If anyone wants to contribute a better
+stylesheet or help with documentation, drop me a line.
+
+CHANGES/ENHANCEMENTS/UPDATES
date_format, html_select_date and html_select_time used to require a unix
timestamp as the format of the date passed into the template. Smarty is now a
@@ -64,9 +69,20 @@ The run-time custom functions are now passed Smarty object as the second
parameter. This can be used, for example, to assign or clear template variables
from inside the custom function.
+clear_compile_dir() was added for clearing out compiled versions of your
+templates. Not something normally needed, but you may have a need for this if
+you have $compile_check set to false and you periodically update templates via
+some automated process. As of 1.4.0, uncompiled templates _always_ get
+compiled, regardless of $compile_check setting, although they won't be checked
+for recompile if $compile_check is set to false.
+
You can now refer to properties of objects assigned from PHP by using the '->'
symbol and specifying the property name after it, e.g. $foo->bar.
+{php}{/php} tags were added to embed php into the templates. Not normally
+needed, but some circumstances may call for it. Check out the "componentized
+templates" tip in the documentation for an example of needed usage.
+
UPGRADE NOTES
The format of the files created in the $compile_dir are now a bit different.
diff --git a/Smarty.class.php b/Smarty.class.php
index 8dad13ad..af6ea1b4 100644
--- a/Smarty.class.php
+++ b/Smarty.class.php
@@ -136,7 +136,7 @@ class Smarty
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
// Smarty to compile templates
var $resource_funcs = array(); // what functions resource handlers are mapped to
- var $filter_funcs = array(); // what functions templates are filtered through
+ var $prefilter_funcs = array(); // what functions templates are prefiltered through
// before being compiled
/**************************************************************************/
@@ -304,28 +304,28 @@ class Smarty
}
/*======================================================================*\
- Function: register_filter
- Purpose: Registers a filter function to apply
+ Function: register_prefilter
+ Purpose: Registers a prefilter function to apply
to a template before compiling
\*======================================================================*/
- function register_filter($function_name)
+ function register_prefilter($function_name)
{
- $this->filter_funcs[] = $function_name;
+ $this->prefilter_funcs[] = $function_name;
}
/*======================================================================*\
- Function: unregister_filter
- Purpose: Unregisters a filter
+ Function: unregister_prefilter
+ Purpose: Unregisters a prefilter
\*======================================================================*/
- function unregister_filter($function_name)
+ function unregister_prefilter($function_name)
{
$tmp_array = array();
- foreach($this->filter_funcs as $curr_func) {
+ foreach($this->prefilter_funcs as $curr_func) {
if($curr_func != $function_name) {
$tmp_array[] = $curr_func;
}
}
- $this->filter_funcs = $tmp_array;
+ $this->prefilter_funcs = $tmp_array;
}
/*======================================================================*\
@@ -407,6 +407,37 @@ class Smarty
$this->_tpl_vars = array();
}
+/*======================================================================*\
+ Function: clear_compile_dir()
+ Purpose: clears compiled version of specified template resource,
+ or all compiled template files if one is not specified.
+ This function is for advanced use only, not normally needed.
+\*======================================================================*/
+ function clear_compile_dir($tpl_file=null)
+ {
+ if (!is_dir($this->compile_dir))
+ return false;
+
+ if($tpl_file) {
+ // remove compiled template file if it exists
+ $tpl_file = urlencode($tpl_file).'.php';
+ if(file_exists($this->compile_dir.'/'.$tpl_file)) {
+ unlink($this->compile_dir.'/'.$tpl_file);
+ }
+ } else {
+ // remove everything in $compile_dir
+ $dir_handle = opendir($this->compile_dir);
+ while ($curr_file = readdir($dir_handle)) {
+ if ($curr_file == '.' || $curr_dir == '..' ||
+ !is_file($this->compile_dir.'/'.$curr_file))
+ { continue; }
+ unlink($this->compile_dir.'/'.$curr_file);
+ }
+ closedir($dir_handle);
+ }
+
+ return true;
+ }
/*======================================================================*\
Function: get_template_vars
@@ -649,7 +680,7 @@ class Smarty
$smarty_compiler->custom_funcs = $this->custom_funcs;
$smarty_compiler->custom_mods = $this->custom_mods;
$smarty_compiler->version = $this->version;
- $smarty_compiler->filter_funcs = $this->filter_funcs;
+ $smarty_compiler->prefilter_funcs = $this->prefilter_funcs;
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php
index 0f3bd7c2..fbf71b81 100644
--- a/Smarty_Compiler.class.php
+++ b/Smarty_Compiler.class.php
@@ -43,6 +43,7 @@ class Smarty_Compiler extends Smarty {
// internal vars
var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part
var $_literal_blocks = array(); // keeps literal template blocks
+ var $_php_blocks = array(); // keeps php code blocks
var $_current_file = null; // the current template being compiled
var $_current_line_no = 1; // line number for error messages
@@ -54,13 +55,13 @@ class Smarty_Compiler extends Smarty {
function _compile_file($tpl_file, $template_source, &$template_compiled)
{
- // run template source through functions registered in filter_funcs
- if(is_array($this->filter_funcs) && count($this->filter_funcs) > 0) {
- foreach($this->filter_funcs as $curr_func) {
+ // run template source through functions registered in prefilter_funcs
+ if(is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) {
+ foreach($this->prefilter_funcs as $curr_func) {
if(function_exists($curr_func)) {
$template_source = $curr_func($template_source);
} else {
- $this->_trigger_error_msg("filter function $curr_func does not exist.");
+ $this->_trigger_error_msg("prefilter function $curr_func does not exist.");
}
}
}
@@ -74,8 +75,14 @@ class Smarty_Compiler extends Smarty {
preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_source, $match);
$this->_literal_blocks = $match[1];
$template_source = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s",
- $this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_source);
+ $this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_source);
+ /* Pull out the php code blocks. */
+ preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $template_source, $match);
+ $this->_php_blocks = $match[1];
+ $template_source = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s",
+ $this->quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $template_source);
+
/* Gather all template tags. */
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_source, $match);
$template_tags = $match[1];
@@ -226,6 +233,11 @@ class Smarty_Compiler extends Smarty {
$this->_current_line_no += substr_count($literal_block, "\n");
return "\n";
+ case 'php':
+ list (,$php_block) = each($this->_php_blocks);
+ $this->_current_line_no += substr_count($php_block, "\n");
+ return '';
+
case 'insert':
return $this->_compile_insert_tag($tag_args);
diff --git a/docs.sgml b/docs.sgml
index e99f45d7..2fa4af06 100644
--- a/docs.sgml
+++ b/docs.sgml
@@ -134,16 +134,16 @@
Caching
- Smarty can cache the output of your generated templates. By default
- this is disabled. If you enable
- caching, Smarty will store a copy of the generated template
- output, and use this until the copy expires, regenerating a new
- one. The default cache expire time can be configured from the
- class. The exception to the rule is the insert tag. Anything generated by
- the insert tag is not cached, but run dynamically on every
- invocation, even within cached content.
+ Smarty can cache the output of your generated templates. By default
+ this is disabled. If you enable
+ caching, Smarty will store a copy of the generated template
+ output, and use this until the copy expires, regenerating a new
+ one. The default cache expire time can be configured from the
+ class. The exception to the rule is the insert tag. Anything
+ generated by the insert tag is not cached, but run dynamically on
+ every invocation, even within cached content.
TECHNICAL NOTE: Any time you change a template, change values in
@@ -289,33 +289,44 @@ chmod 700 cache
$global_assign
- This is a list of variables that are always implicitly assigned
- to the template engine. This is handy for making global
- variables or server variables available to all templates
- without having to manually assign them. $SCRIPT_NAME is
- globally assigned by default.
+ This is a list of variables that are always implicitly assigned
+ to the template engine. This is handy for making global
+ variables or server variables available to all templates
+ without having to manually assign them. $SCRIPT_NAME is
+ globally assigned by default.
+
+
+
+ $undefined
+
+ This sets the value of $undefined for Smarty, default is null.
+ Currently this is only used to set undefined variables in
+ $global_assign to a default value.
$compile_check
- Upon each invocation of the PHP application, Smarty tests to
- see if the current template has changed (later time stamp)
- since the last time it was compiled. If it has changed, it
- recompiles that template. By default this variable is set to
- true. Once an application is put into production and all
- templates are initially compiled, the compile_check step is no
- longer needed. Be sure to set $compile_check to "false" to
- improve performance! Note that if you change this to "false"
- and a template file is changed, you will *not* see the change
- since the template will not get recompiled. See $force_compile
+ Upon each invocation of the PHP application, Smarty tests to
+ see if the current template has changed (later time stamp)
+ since the last time it was compiled. If it has changed, it
+ recompiles that template. As of 1.4.0, if the template has not
+ been compiled, it will compile regardless of this setting. By
+ default this variable is set to true. Once an application is
+ put into production (templates won't be changing), the
+ compile_check step is no longer needed. Be sure to set
+ $compile_check to "false" to improve performance! Note that if
+ you change this to "false" and a template file is changed, you
+ will *not* see the change since the template will not get
+ recompiled. See $force_compile or clear_compile_dir.
$force_compile
- This forces Smarty to (re)compile each template on every
+ This forces Smarty to (re)compile templates on every
invocation. This setting overrides $compile_check. By default
this is disabled. This is handy for development and debugging.
It should never be used in a production environment.
@@ -364,10 +375,10 @@ chmod 700 cache
$insert_tag_check
- If you have $caching enabled and you do not use the insert tag anywhere in your
- templates, set this to false. This saves the insert tag search,
- speeding up cached page fetches.
+ If you have $caching enabled and you do not use the insert tag anywhere in
+ your templates, set this to false. This saves the insert tag
+ search, speeding up cached page fetches.
@@ -400,9 +411,11 @@ chmod 700 cache
$php_handling
- This tells Smarty how to handle PHP code embedded in the
- tempalates. There are four possible settings, default being
- SMARTY_PHP_PASSTHRU.
+ This tells Smarty how to handle PHP code embedded in the
+ tempalates. There are four possible settings, default being
+ SMARTY_PHP_PASSTHRU. Note that this does NOT affect php code
+ within {php}{/php}
+ tags in the template.
SMARTY_PHP_PASSTHRU - Smarty echos tags as-is.
@@ -647,6 +660,33 @@ $smarty->clear_cache("index.tpl","CACHEID");
$smarty->clear_all_cache();
+
+
+
+
+ clear_compile_dir
+
+
+ void clear_all_cache
+ string tpl_file
+
+
+
+ This clears the compiled version of the specified template
+ resource, or all compiled template files if one is not specified.
+ This function is for advanced use only, not normally needed.
+
+
+clear_compile_dir
+
+
+// clear a specific template resource
+$smarty->clear_compile_dir("index.tpl");
+
+// clear entire compile directory
+$smarty->clear_compile_dir();
+
+
@@ -801,45 +841,45 @@ $smarty->unregister_resource("db");
-
- register_filter
+
+ register_prefilter
- void register_filter
+ void register_prefilterstring function_name
- Use this to dynamically register filters to run templates
+ Use this to dynamically register prefilters to run templates
through before they are compiled. See template filters for
- more information on how to setup a filtering function.
+ linkend="section.template.prefilters">template prefilters for
+ more information on how to setup a prefiltering function.
-register_filter
+register_prefilter
-$smarty->register_filter("remove_dw_comments");
+$smarty->register_prefilter("remove_dw_comments");
-
- unregister_filter
+
+ unregister_prefilter
- void unregister_filter
+ void unregister_prefilterstring function_name
- Use this to dynamically unregister a filter.
+ Use this to dynamically unregister a prefilter.
-unregister_filter
+unregister_prefilter
-$smarty->unregister_filter("imbed_asp_jokes");
+$smarty->unregister_prefilter("imbed_asp_jokes");
@@ -1180,26 +1220,26 @@ $smarty->display("db:index.tpl");
-
- Template Filters
+
+ Template Preilters
- Template filters are PHP functions that your templates are ran through
+ Template prefilters are PHP functions that your templates are ran through
before they are compiled. This is good for preprocessing your templates
to remove unwanted comments, keeping an eye on what people are putting
- in their templates, etc. Filters are processed in the order they are
- registered.
+ in their templates, etc. Prefilters are processed in the order they are
+ registered.
- Example of a Template Filter
+ Example of a Template Prefilter
Create a function in your application that Smarty will use as a
- template filter. Smarty will pass the template source code as the
+ template prefilter. Smarty will pass the template source code as the
first argument, an expect the function to return the resulting
template source code.
-using a template filter
+using a template prefilter
// put this in your application, or in Smarty.addons.php
@@ -1207,12 +1247,12 @@ function remove_dw_comments($tpl_source) {
return preg_replace("/<!--#.*-->/U","",$tpl_source);
}
-// register the filter
-$smarty->register_filter("remove_dw_comments");
+// register the prefilter
+$smarty->register_prefilter("remove_dw_comments");
$smarty->display("index.tpl");
{* from within Smarty template *}
-<!--# this line will get removed by the filter -->
+<!--# this line will get removed by the prefilter -->
@@ -1617,7 +1657,7 @@ Intro = """This is a value that spans more
-
+ include
@@ -1691,7 +1731,7 @@ Intro = """This is a value that spans more
-
+ insert
@@ -1878,7 +1918,7 @@ OUTPUT:
-
+ literal
Literal tags allow a block of data to be taken literally,
@@ -1909,6 +1949,28 @@ OUTPUT:
</script>
{/literal}
+
+
+
+
+ php
+
+ php tags allow php to be imbedded directly into the template. They
+ will not be escaped, regardless of the $php_handling setting. This
+ is for advanced users only, not normally needed. This was added to
+ 1.4.0.
+
+
+php tags
+
+
+{php}
+ // including a php script directly
+ // from the template.
+ include("/path/to/display_weather.php");
+{/php}
+
@@ -2498,7 +2560,7 @@ OUTPUT:
-
+ html_options
@@ -2587,7 +2649,7 @@ OUTPUT:
-
+ html_select_date
@@ -2783,7 +2845,7 @@ OUTPUT:
-
+ html_select_time
@@ -3040,7 +3102,7 @@ OUTPUT:
-
+ math
@@ -3975,6 +4037,10 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
linkend="date.format">date_format for full control over date
formatting, and also makes it easy to compare dates if necessary.
+
+ NOTE: As of Smarty 1.4.0, you can pass dates to Smarty as unix
+ timestamps, mysql timestamps, or any date parsable by strtotime().
+ using date_format
@@ -4083,9 +4149,59 @@ Pretty easy isn't it?
+
+ Componentized Templates
+
+ This tip is a bit of a hack, but still a neat idea. Use at your own
+ risk. ;-)
+
+
+ Traditionally, programming templates into your applications goes as
+ follows: First, you accumulate your variables within your PHP
+ application, (maybe with database queries.) Then, you instantiate your
+ Smarty object, assign the variables and display the template. So lets
+ say for example we have a stock ticker on our template. We would
+ collect the stock data in our application, then assign these variables
+ in the template and display it. Now wouldn't it be nice if you could
+ add this stock ticker to any application by merely including the
+ template, and not worry about fetching the data up front?
+
+
+ As of Smarty 1.4.0, you can embed php into your templates with the
+ {php}{/php} tags. With this, you can setup self contained templates
+ with their own data structures for assigning their own variables. With
+ the logic embedded like this, you can keep the template & logic
+ together. This way no matter where the template source is coming from,
+ it is always together as one component.
+
+
+componentized template
+
+{* Smarty *}
+{php}
+ // setup our function for fetching stock data
+ function fetch_ticker($symbol,&$ticker_name,&$ticker_price) {
+ // put logic here that fetches $ticker_name
+ // and $ticker_price from some resource
+ }
+
+ // call the function
+ fetch_ticker("YHOO",$ticker_name,$ticker_price);
+
+ // assign template variables
+ $this->assign("ticker_name",$ticker_name);
+ $this->assign("ticker_price",$ticker_price);
+
+{/php}
+
+Stock Name: {$ticker_name} Stock Price: {$ticker_price}
+
+
+
+ Resources
@@ -4093,7 +4209,7 @@ Pretty easy isn't it?
Smarty's homepage is located at http://www.phpinsider.com/php/code/Smarty/.
You can join the mailing list by sending an e-mail to
subscribe-smarty@lists.ispi.net. An archive of the mailing list can be
- viewed at http://marc.theaimsgroup.com/ under www/smarty.
+ viewed at http://marc.theaimsgroup.com/?l=smarty&r=1&w=2
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 8dad13ad..af6ea1b4 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -136,7 +136,7 @@ class Smarty
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
// Smarty to compile templates
var $resource_funcs = array(); // what functions resource handlers are mapped to
- var $filter_funcs = array(); // what functions templates are filtered through
+ var $prefilter_funcs = array(); // what functions templates are prefiltered through
// before being compiled
/**************************************************************************/
@@ -304,28 +304,28 @@ class Smarty
}
/*======================================================================*\
- Function: register_filter
- Purpose: Registers a filter function to apply
+ Function: register_prefilter
+ Purpose: Registers a prefilter function to apply
to a template before compiling
\*======================================================================*/
- function register_filter($function_name)
+ function register_prefilter($function_name)
{
- $this->filter_funcs[] = $function_name;
+ $this->prefilter_funcs[] = $function_name;
}
/*======================================================================*\
- Function: unregister_filter
- Purpose: Unregisters a filter
+ Function: unregister_prefilter
+ Purpose: Unregisters a prefilter
\*======================================================================*/
- function unregister_filter($function_name)
+ function unregister_prefilter($function_name)
{
$tmp_array = array();
- foreach($this->filter_funcs as $curr_func) {
+ foreach($this->prefilter_funcs as $curr_func) {
if($curr_func != $function_name) {
$tmp_array[] = $curr_func;
}
}
- $this->filter_funcs = $tmp_array;
+ $this->prefilter_funcs = $tmp_array;
}
/*======================================================================*\
@@ -407,6 +407,37 @@ class Smarty
$this->_tpl_vars = array();
}
+/*======================================================================*\
+ Function: clear_compile_dir()
+ Purpose: clears compiled version of specified template resource,
+ or all compiled template files if one is not specified.
+ This function is for advanced use only, not normally needed.
+\*======================================================================*/
+ function clear_compile_dir($tpl_file=null)
+ {
+ if (!is_dir($this->compile_dir))
+ return false;
+
+ if($tpl_file) {
+ // remove compiled template file if it exists
+ $tpl_file = urlencode($tpl_file).'.php';
+ if(file_exists($this->compile_dir.'/'.$tpl_file)) {
+ unlink($this->compile_dir.'/'.$tpl_file);
+ }
+ } else {
+ // remove everything in $compile_dir
+ $dir_handle = opendir($this->compile_dir);
+ while ($curr_file = readdir($dir_handle)) {
+ if ($curr_file == '.' || $curr_dir == '..' ||
+ !is_file($this->compile_dir.'/'.$curr_file))
+ { continue; }
+ unlink($this->compile_dir.'/'.$curr_file);
+ }
+ closedir($dir_handle);
+ }
+
+ return true;
+ }
/*======================================================================*\
Function: get_template_vars
@@ -649,7 +680,7 @@ class Smarty
$smarty_compiler->custom_funcs = $this->custom_funcs;
$smarty_compiler->custom_mods = $this->custom_mods;
$smarty_compiler->version = $this->version;
- $smarty_compiler->filter_funcs = $this->filter_funcs;
+ $smarty_compiler->prefilter_funcs = $this->prefilter_funcs;
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php
index 0f3bd7c2..fbf71b81 100644
--- a/libs/Smarty_Compiler.class.php
+++ b/libs/Smarty_Compiler.class.php
@@ -43,6 +43,7 @@ class Smarty_Compiler extends Smarty {
// internal vars
var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part
var $_literal_blocks = array(); // keeps literal template blocks
+ var $_php_blocks = array(); // keeps php code blocks
var $_current_file = null; // the current template being compiled
var $_current_line_no = 1; // line number for error messages
@@ -54,13 +55,13 @@ class Smarty_Compiler extends Smarty {
function _compile_file($tpl_file, $template_source, &$template_compiled)
{
- // run template source through functions registered in filter_funcs
- if(is_array($this->filter_funcs) && count($this->filter_funcs) > 0) {
- foreach($this->filter_funcs as $curr_func) {
+ // run template source through functions registered in prefilter_funcs
+ if(is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) {
+ foreach($this->prefilter_funcs as $curr_func) {
if(function_exists($curr_func)) {
$template_source = $curr_func($template_source);
} else {
- $this->_trigger_error_msg("filter function $curr_func does not exist.");
+ $this->_trigger_error_msg("prefilter function $curr_func does not exist.");
}
}
}
@@ -74,8 +75,14 @@ class Smarty_Compiler extends Smarty {
preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_source, $match);
$this->_literal_blocks = $match[1];
$template_source = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s",
- $this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_source);
+ $this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_source);
+ /* Pull out the php code blocks. */
+ preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $template_source, $match);
+ $this->_php_blocks = $match[1];
+ $template_source = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s",
+ $this->quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $template_source);
+
/* Gather all template tags. */
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_source, $match);
$template_tags = $match[1];
@@ -226,6 +233,11 @@ class Smarty_Compiler extends Smarty {
$this->_current_line_no += substr_count($literal_block, "\n");
return "\n";
+ case 'php':
+ list (,$php_block) = each($this->_php_blocks);
+ $this->_current_line_no += substr_count($php_block, "\n");
+ return '';
+
case 'insert':
return $this->_compile_insert_tag($tag_args);