added fetch, unregister mod/fun, updated docs

This commit is contained in:
mohrt
2001-03-02 17:02:44 +00:00
parent ffaa3e20c4
commit 08d9cb8971
5 changed files with 169 additions and 4 deletions

4
NEWS
View File

@@ -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. - added ability to index looped variables by section properties, e.g.
$foo.index_prev/bar. (Andrei) $foo.index_prev/bar. (Andrei)
- added index_prev and index_next section properties. (Andrei) - added index_prev and index_next section properties. (Andrei)

View File

@@ -320,6 +320,17 @@ function smarty_func_math() {
eval("echo ".$equation.";"); 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: */ /* vim: set expandtab: */
?> ?>

View File

@@ -85,7 +85,8 @@ class Smarty
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options', var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
'html_select_date' => 'smarty_func_html_select_date', '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', var $custom_mods = array( 'lower' => 'strtolower',
@@ -189,6 +190,15 @@ class Smarty
$this->custom_funcs[$function] = $function_impl; $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 Function: register_modifier
@@ -199,6 +209,15 @@ class Smarty
$this->custom_mods[$modifier] = $modifier_impl; $this->custom_mods[$modifier] = $modifier_impl;
} }
/*======================================================================*\
Function: unregister_modifier
Purpose: Unregisters modifier
\*======================================================================*/
function unregister_modifier($modifier)
{
unset($this->custom_mods[$modifier]);
}
/*======================================================================*\ /*======================================================================*\
Function: clear_cache() Function: clear_cache()

112
docs.sgml
View File

@@ -580,6 +580,29 @@ function print_current_date ($params) {
// now you can use this in Smarty to print the current date: {date_now} // now you can use this in Smarty to print the current date: {date_now}
// or, {date_now format="%Y/%m/%d"} to format it. // or, {date_now format="%Y/%m/%d"} to format it.
</programlisting>
</example>
</sect2>
<sect2 id="api.unregister.function">
<title>unregister_function</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>unregister_function</function></funcdef>
<paramdef>string <parameter>funcname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Use this to dynamically unregister functions with Smarty. Pass in
the Smarty function name.
</para>
<example>
<title>unregister_function</title>
<programlisting>
// we don't want template designers to have access to system files
$smarty->unregister_modifier("fetch");
</programlisting> </programlisting>
</example> </example>
</sect2> </sect2>
@@ -607,6 +630,29 @@ $smarty->register_modifier("sslash","stripslashes");
// now you can use {$var|sslash} to strip slashes from variables // now you can use {$var|sslash} to strip slashes from variables
</programlisting>
</example>
</sect2>
<sect2 id="api.unregister.modifier">
<title>unregister_modifier</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>unregister_modifier</function></funcdef>
<paramdef>string <parameter>modname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Use this to dynamically unregister modifiers with Smarty. Pass in
the Smarty modifier name.
</para>
<example>
<title>unregister_modifier</title>
<programlisting>
// we don't want template designers to strip tags from elements
$smarty->unregister_modifier("strip_tags");
</programlisting> </programlisting>
</example> </example>
</sect2> </sect2>
@@ -1744,6 +1790,72 @@ OUTPUT:
Custom functions in Smarty work much the same as the built-in functions Custom functions in Smarty work much the same as the built-in functions
syntactically. syntactically.
</para> </para>
<sect2>
<title>fetch</title>
<informaltable frame=all>
<tgroup cols=3>
<colspec colname=param>
<colspec colname=type>
<colspec colname=required>
<colspec colname=default>
<colspec colname=desc>
<thead>
<row>
<entry>Attribute Name</entry>
<entry>Type</entry>
<entry>Required</entry>
<entry>Default</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>file</entry>
<entry>string</entry>
<entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>the file, http or ftp site to fetch</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
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.
</para>
<para>
TECHNICAL NOTE: This will not support http redirects, be sure to
include a trailing slash on your web page fetches where necessary.
</para>
<para>
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 <link
linkend="api.unregister.function">unregister</link> this function if
required.
</para>
<example>
<title>fetch</title>
<programlisting>
{* 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"}
</programlisting>
</example>
</sect2>
<sect2> <sect2>
<title>html_options</title> <title>html_options</title>
<informaltable frame=all> <informaltable frame=all>

View File

@@ -85,7 +85,8 @@ class Smarty
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options', var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
'html_select_date' => 'smarty_func_html_select_date', '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', var $custom_mods = array( 'lower' => 'strtolower',
@@ -189,6 +190,15 @@ class Smarty
$this->custom_funcs[$function] = $function_impl; $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 Function: register_modifier
@@ -199,6 +209,15 @@ class Smarty
$this->custom_mods[$modifier] = $modifier_impl; $this->custom_mods[$modifier] = $modifier_impl;
} }
/*======================================================================*\
Function: unregister_modifier
Purpose: Unregisters modifier
\*======================================================================*/
function unregister_modifier($modifier)
{
unset($this->custom_mods[$modifier]);
}
/*======================================================================*\ /*======================================================================*\
Function: clear_cache() Function: clear_cache()