diff --git a/NEWS b/NEWS
index 9d69a138..31d31623 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+ - added unregister_modifier, documented (Monte)
+ - added unregister_function, documented (Monte)
+ - added fetch function, documented (Monte)
+ - added math function, documented (Monte)
- added ability to index looped variables by section properties, e.g.
$foo.index_prev/bar. (Andrei)
- added index_prev and index_next section properties. (Andrei)
diff --git a/Smarty.addons.php b/Smarty.addons.php
index 2b93dc28..98e303f8 100644
--- a/Smarty.addons.php
+++ b/Smarty.addons.php
@@ -320,6 +320,17 @@ function smarty_func_math() {
eval("echo ".$equation.";");
}
+function smarty_func_fetch() {
+ extract(func_get_arg(0));
+
+ if(empty($file)) {
+ trigger_error("parameter 'file' cannot be empty");
+ return;
+ }
+ readfile($file);
+}
+
+
/* vim: set expandtab: */
?>
diff --git a/Smarty.class.php b/Smarty.class.php
index 3f77b4aa..f5f0d5c0 100644
--- a/Smarty.class.php
+++ b/Smarty.class.php
@@ -85,7 +85,8 @@ class Smarty
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
'html_select_date' => 'smarty_func_html_select_date',
- 'math' => 'smarty_func_math'
+ 'math' => 'smarty_func_math',
+ 'fetch' => 'smarty_func_fetch'
);
var $custom_mods = array( 'lower' => 'strtolower',
@@ -189,7 +190,16 @@ class Smarty
$this->custom_funcs[$function] = $function_impl;
}
-
+/*======================================================================*\
+ Function: unregister_function
+ Purpose: Unregisters custom function
+\*======================================================================*/
+ function unregister_function($function)
+ {
+ unset($this->custom_funcs[$function]);
+ }
+
+
/*======================================================================*\
Function: register_modifier
Purpose: Registers modifier to be used in templates
@@ -199,6 +209,15 @@ class Smarty
$this->custom_mods[$modifier] = $modifier_impl;
}
+/*======================================================================*\
+ Function: unregister_modifier
+ Purpose: Unregisters modifier
+\*======================================================================*/
+ function unregister_modifier($modifier)
+ {
+ unset($this->custom_mods[$modifier]);
+ }
+
/*======================================================================*\
Function: clear_cache()
diff --git a/docs.sgml b/docs.sgml
index a037adb2..b75a1410 100644
--- a/docs.sgml
+++ b/docs.sgml
@@ -580,6 +580,29 @@ function print_current_date ($params) {
// now you can use this in Smarty to print the current date: {date_now}
// or, {date_now format="%Y/%m/%d"} to format it.
+
+
+
+
+ unregister_function
+
+
+ void unregister_function
+ string funcname
+
+
+
+ Use this to dynamically unregister functions with Smarty. Pass in
+ the Smarty function name.
+
+
+unregister_function
+
+
+// we don't want template designers to have access to system files
+
+$smarty->unregister_modifier("fetch");
+
@@ -607,6 +630,29 @@ $smarty->register_modifier("sslash","stripslashes");
// now you can use {$var|sslash} to strip slashes from variables
+
+
+
+
+ unregister_modifier
+
+
+ void unregister_modifier
+ string modname
+
+
+
+ Use this to dynamically unregister modifiers with Smarty. Pass in
+ the Smarty modifier name.
+
+
+unregister_modifier
+
+
+// we don't want template designers to strip tags from elements
+
+$smarty->unregister_modifier("strip_tags");
+
@@ -1744,6 +1790,72 @@ OUTPUT:
Custom functions in Smarty work much the same as the built-in functions
syntactically.
+
+ fetch
+
+
+
+
+
+
+
+
+
+ Attribute Name
+ Type
+ Required
+ Default
+ Description
+
+
+
+
+ file
+ string
+ Yes
+ n/a
+ the file, http or ftp site to fetch
+
+
+
+
+
+ fetch allows the template designer to fetch files from the local
+ file system, ftp, or http, and display the contents. If the file
+ name begins with "http://", the web site page will be fetched and
+ displayed. If the file name begins with "ftp://", the file will be
+ fetched from the ftp server and displayed. For local files, the full
+ system file path must be given, or a path relative to the executed
+ php script.
+
+
+ TECHNICAL NOTE: This will not support http redirects, be sure to
+ include a trailing slash on your web page fetches where necessary.
+
+
+ TECHNICAL NOTE: This function may be a security concern if you are
+ allowing third parties to modify templates. i.e., they can access
+ arbitrary files on your system. Be sure to unregister this function if
+ required.
+
+
+fetch
+
+
+{* include some javascript in your template *}
+{fetch file="/export/httpd/www.domain.com/docs/navbar.js"}
+
+{* imbed some weather text in your template from another web site *}
+{fetch file="http://www.myweather.com/cgi-bin/getweather?zipcode=68502"}
+
+{* fetch a news headline file via ftp *}
+{fetch file="ftp://user:password@ftp.domain.com/path/to/currentheadlines.txt"}
+
+
+
+
+ html_options
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 3f77b4aa..f5f0d5c0 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -85,7 +85,8 @@ class Smarty
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
'html_select_date' => 'smarty_func_html_select_date',
- 'math' => 'smarty_func_math'
+ 'math' => 'smarty_func_math',
+ 'fetch' => 'smarty_func_fetch'
);
var $custom_mods = array( 'lower' => 'strtolower',
@@ -189,7 +190,16 @@ class Smarty
$this->custom_funcs[$function] = $function_impl;
}
-
+/*======================================================================*\
+ Function: unregister_function
+ Purpose: Unregisters custom function
+\*======================================================================*/
+ function unregister_function($function)
+ {
+ unset($this->custom_funcs[$function]);
+ }
+
+
/*======================================================================*\
Function: register_modifier
Purpose: Registers modifier to be used in templates
@@ -199,6 +209,15 @@ class Smarty
$this->custom_mods[$modifier] = $modifier_impl;
}
+/*======================================================================*\
+ Function: unregister_modifier
+ Purpose: Unregisters modifier
+\*======================================================================*/
+ function unregister_modifier($modifier)
+ {
+ unset($this->custom_mods[$modifier]);
+ }
+
/*======================================================================*\
Function: clear_cache()