update Smarty version numbers

This commit is contained in:
mohrt
2003-02-02 08:07:57 +00:00
parent d6e0917b9b
commit 66c1110fea
12 changed files with 285 additions and 30 deletions

View File

@@ -3,7 +3,7 @@
/** /**
* Config_File class. * Config_File class.
* *
* @version 2.3.1 * @version 2.4.0
* @author Andrei Zmievski <andrei@php.net> * @author Andrei Zmievski <andrei@php.net>
* @access public * @access public
* *

4
NEWS
View File

@@ -1,3 +1,6 @@
Version 2.4.0
-------------
- fix known problems with php tag handling in templates - fix known problems with php tag handling in templates
(recursion, echoing <?xml tags) (Monte) (recursion, echoing <?xml tags) (Monte)
- add support for object registration (Monte) - add support for object registration (Monte)
@@ -27,6 +30,7 @@
- fix popup function to allow newlines in text (Monte) - fix popup function to allow newlines in text (Monte)
- escape html entities in html_options (Monte) - escape html entities in html_options (Monte)
- fixed bug with label for html_options (Monte) - fixed bug with label for html_options (Monte)
- added config_load API function (Monte)
- added caching to config file loading (Monte) - added caching to config file loading (Monte)
- added "extra" parameter to mailto function (Monte, - added "extra" parameter to mailto function (Monte,
Massimiliano Perantoni) Massimiliano Perantoni)

2
README
View File

@@ -2,7 +2,7 @@ NAME:
Smarty - the PHP compiling template engine Smarty - the PHP compiling template engine
VERSION: 2.3.1 VERSION: 2.4.0
AUTHORS: AUTHORS:

View File

@@ -1,3 +1,10 @@
2.4.0
-----
Smarty now supports the ability to access objects within the templates. Two methods are available, one which closely follows Smartys conventions, and another that follows more traditional object syntax for those familiar with PHP.
The internal compiling engine has also undergone some major work. The regex parsing was rewritten to be much more strict, more secure and more maintainable. Config files are now compiled, which can speed up pages quite a bit that use config files extensively. Assigned variables are no longer extracted to PHP namespace, saving an extract call for every template. There is now support for applying modifiers to static values and functions. You can now access constants with $smarty.const.VAR. See the NEWS file for complete changes.
2.3.1 2.3.1
----- -----

View File

@@ -5,7 +5,7 @@
* Author: Monte Ohrt <monte@ispi.net> * Author: Monte Ohrt <monte@ispi.net>
* Andrei Zmievski <andrei@php.net> * Andrei Zmievski <andrei@php.net>
* *
* Version: 2.3.1 * Version: 2.4.0
* Copyright: 2001,2002 ispi of Lincoln, Inc. * Copyright: 2001,2002 ispi of Lincoln, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@@ -1734,22 +1734,22 @@ class Smarty
$_compile_file = $this->_get_auto_filename($this->compile_dir, $file); $_compile_file = $this->_get_auto_filename($this->compile_dir, $file);
} }
// need to generate cache? // need to compile config file?
if($this->force_compile || !file_exists($_compile_file) || if($this->force_compile || !file_exists($_compile_file) ||
($this->compile_check && ($this->compile_check &&
file_exists($_file_path) && file_exists($_file_path) &&
( filemtime($_compile_file) != filemtime($_file_path) ))) { ( filemtime($_compile_file) != filemtime($_file_path) ))) {
$_generate_cache = true; $_compile_config = true;
} else { } else {
include($_compile_file); include($_compile_file);
if(!empty($_config_vars)) { if(!empty($_config_vars)) {
$_generate_cache = true; $_compile_config = true;
} else { } else {
$_generate_cache = false; $_compile_config = false;
} }
} }
if($_generate_cache) { if($_compile_config) {
if(!is_object($this->_conf_obj)) { if(!is_object($this->_conf_obj)) {
require_once SMARTY_DIR . $this->config_class . '.class.php'; require_once SMARTY_DIR . $this->config_class . '.class.php';
$this->_conf_obj = new Config_File($_config_dir); $this->_conf_obj = new Config_File($_config_dir);

View File

@@ -6,7 +6,7 @@
* Author: Monte Ohrt <monte@ispi.net> * Author: Monte Ohrt <monte@ispi.net>
* Andrei Zmievski <andrei@php.net> * Andrei Zmievski <andrei@php.net>
* *
* Version: 2.3.1 * Version: 2.4.0
* Copyright: 2001,2002 ispi of Lincoln, Inc. * Copyright: 2001,2002 ispi of Lincoln, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or

View File

@@ -362,9 +362,7 @@ Stock Name: {$ticker_name} Stock Price: {$ticker_price}</programlisting>
lists? One way spammers collect E-mail addresses is from web pages. To lists? One way spammers collect E-mail addresses is from web pages. To
help combat this problem, you can make your E-mail address show up in help combat this problem, you can make your E-mail address show up in
scrambled javascript in the HTML source, yet it it will look and work scrambled javascript in the HTML source, yet it it will look and work
correctly in the browser. This is done with the mailto plugin, correctly in the browser. This is done with the mailto plugin.
available from the plugin repository on the Smarty website. Download
the plugin and drop it into the plugins directory.
</para> </para>
<example> <example>
<title>Example of Obfuscating an E-mail Address</title> <title>Example of Obfuscating an E-mail Address</title>

View File

@@ -359,6 +359,18 @@ OUTPUT:
<programlisting> <programlisting>
{* use the date_format modifier to show current date and time *} {* use the date_format modifier to show current date and time *}
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}</programlisting> {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}</programlisting>
</example>
</sect2>
<sect2 id="language.variables.smarty.const">
<title>{$smarty.const}</title>
<para>
You can access PHP constant values directly.
</para>
<example>
<title>using {$smarty.const}</title>
<programlisting>
{$smarty.const._MY_CONST_VAL}</programlisting>
</example> </example>
</sect2> </sect2>
@@ -395,8 +407,8 @@ OUTPUT:
<chapter id="language.modifiers"> <chapter id="language.modifiers">
<title>Variable Modifiers</title> <title>Variable Modifiers</title>
<para> <para>
Variable modifiers can be applied to any variable to alter its contents. To Variable modifiers can be applied to variables, custom functions or strings. To
apply a modifier, specify the variable followed by the <literal>|</literal> apply a modifier, specify the value followed by the <literal>|</literal>
(pipe) and the modifier name. A modifier may accept additional parameters (pipe) and the modifier name. A modifier may accept additional parameters
that affect its behavior. These parameters follow the modifer name and are that affect its behavior. These parameters follow the modifer name and are
separated by <literal>:</literal> (colon). separated by <literal>:</literal> (colon).
@@ -408,7 +420,13 @@ OUTPUT:
&lt;h2&gt;{$title|upper}&lt;/h2&gt; &lt;h2&gt;{$title|upper}&lt;/h2&gt;
{* Truncate the topic to 40 characters use ... at the end *} {* Truncate the topic to 40 characters use ... at the end *}
Topic: {$topic|truncate:40:"..."}</programlisting> Topic: {$topic|truncate:40:"..."}
{* format a literal string *}
{"now"|date_format:"%Y/%m/%d"}
{* apply modifier to a custom function *}
{mailto|upper address="me@domain.dom"}</programlisting>
</example> </example>
<para> <para>
If you apply a modifier to an array variable instead of a single value variable, If you apply a modifier to an array variable instead of a single value variable,
@@ -787,7 +805,7 @@ no title</programlisting>
<entry>1</entry> <entry>1</entry>
<entry>string</entry> <entry>string</entry>
<entry>No</entry> <entry>No</entry>
<entry>html,htmlall,url,quotes,hex,hexentity</entry> <entry>html,htmlall,url,quotes,hex,hexentity,javascript</entry>
<entry>html</entry> <entry>html</entry>
<entry>This is the escape format to use.</entry> <entry>This is the escape format to use.</entry>
</row> </row>
@@ -796,10 +814,8 @@ no title</programlisting>
</informaltable> </informaltable>
<para> <para>
This is used to html escape, url escape, escape single quotes on a This is used to html escape, url escape, escape single quotes on a
variable not already escaped, hex escape or hexentity escape. hex variable not already escaped, hex escape, hexentity or javascript escape.
and hexentity escape can be used in conjunction to hide "mailto:" By default, the variable is html
links on a page from web spiders (spam collectors) and yet keep
them readable and linkable. By default, the variable is html
escaped. escaped.
</para> </para>
<example> <example>
@@ -4128,6 +4144,138 @@ OUTPUT:
OUTPUT: OUTPUT:
9.44</programlisting> 9.44</programlisting>
</example>
</sect1>
<sect1 id="language.function.mailto">
<title>mailto</title>
<informaltable frame=all>
<tgroup cols=5>
<colspec colname=param align=center>
<colspec colname=type align=center>
<colspec colname=required align=center>
<colspec colname=default align=center>
<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>address</entry>
<entry>string</entry>
<entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>the e-mail address</entry>
</row>
<row>
<entry>text</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>the text to display, default is
the e-mail address</entry>
</row>
<row>
<entry>encode</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>none</emphasis></entry>
<entry>How to encode the e-mail.
Can be one of none,
hex or javascript.</entry>
</row>
<row>
<entry>cc</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>e-mail addresses to carbon copy.
Separate entries by a comma.</entry>
</row>
<row>
<entry>bcc</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>e-mail addresses to blind carbon copy.
Separate entries by a comma.</entry>
</row>
<row>
<entry>subject</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>e-mail subject.</entry>
</row>
<row>
<entry>newsgroups</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>newsgroups to post to.
Separate entries by a comma.</entry>
</row>
<row>
<entry>followupto</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>addresses to follow up to.
Separate entries by a comma.</entry>
</row>
<row>
<entry>extra</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>any extra information you
want passed to the link, such
as style sheet classes</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
mailto automates the creation of mailto links and optionally
encodes them. Encoding e-mails makes it more difficult for
web spiders to pick up e-mail addresses off of your site.
</para>
<note>
<title>Technical Note</title>
<para>
javascript is probably the most thorough form of
encoding, although you can use hex encoding too.
</para>
</note>
<example>
<title>mailto</title>
<programlisting>
{mailto address="me@domain.com"}
{mailto address="me@domain.com" text="send me some mail"}
{mailto address="me@domain.com" encode="javascript"}
{mailto address="me@domain.com" encode="hex"}
{mailto address="me@domain.com" subject="Hello to you!"}
{mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
{mailto address="me@domain.com" extra='class="email"'}
OUTPUT:
&lt;a href="mailto:me@domain.com" &gt;me@domain.com&lt;/a&gt;
&lt;a href="mailto:me@domain.com" &gt;send me some mail&lt;/a&gt;
&lt;SCRIPT language="javascript"&gt;eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%6
9%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%
61%69%6e%2e%63%6f%6d%22%20%3e%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%3c%2f%61%3e
%27%29%3b'))&lt;/SCRIPT&gt;
&lt;a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" &gt;&amp;#x6d;&amp;#x65;&amp;#x40;&amp;#x64;&amp;
#x6f;&amp;#x6d;&amp;#x61;&amp;#x69;&amp;#x6e;&amp;#x2e;&amp;#x63;&amp;#x6f;&amp;#x6d;&lt;/a&gt;
&lt;a href="mailto:me@domain.com?subject=Hello%20to%20you%21" &gt;me@domain.com&lt;/a&gt;
&lt;a href="mailto:me@domain.com?cc=you@domain.com%2Cthey@domain.com" &gt;me@domain.com&lt;/a&gt;
&lt;a href="mailto:me@domain.com" class="email"&gt;me@domain.com&lt;/a&gt;</programlisting>
</example> </example>
</sect1> </sect1>
<sect1 id="language.function.popup.init"> <sect1 id="language.function.popup.init">

View File

@@ -1125,6 +1125,23 @@ $smarty->register_modifier("sslash","stripslashes");
// now you can use {$var|sslash} to strip slashes from variables</programlisting> // now you can use {$var|sslash} to strip slashes from variables</programlisting>
</example> </example>
</sect1>
<sect1 id="api.register.object">
<title>register_object</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>register_object</function></funcdef>
<paramdef>string <parameter>object_name</parameter></paramdef>
<paramdef>object <parameter>$object</parameter></paramdef>
<paramdef>array <parameter>allowed methods/properties</parameter></paramdef>
<paramdef>boolean <parameter>format</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This is to register an object for use in the templates. See the
<link linkend="advanced.features.objects">object section</link>
of the manual for examples.
</para>
</sect1> </sect1>
<sect1 id="api.register.outputfilter"> <sect1 id="api.register.outputfilter">
<title>register_outputfilter</title> <title>register_outputfilter</title>
@@ -1295,6 +1312,18 @@ $smarty->unregister_function("fetch");</programlisting>
$smarty->unregister_modifier("strip_tags");</programlisting> $smarty->unregister_modifier("strip_tags");</programlisting>
</example> </example>
</sect1> </sect1>
<sect1 id="api.unregister.object">
<title>unregister_object</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>unregister_object</function></funcdef>
<paramdef>string <parameter>object_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Use this to unregister an object.
</para>
</sect1>
<sect1 id="api.unregister.outputfilter"> <sect1 id="api.unregister.outputfilter">
<title>unregister_outputfilter</title> <title>unregister_outputfilter</title>
<funcsynopsis> <funcsynopsis>
@@ -1639,6 +1668,75 @@ $smarty->display('index.tpl',"sports|basketball");</programlisting>
<chapter id="advanced.features"> <chapter id="advanced.features">
<title>Advanced Features</title> <title>Advanced Features</title>
<sect1 id="advanced.features.objects">
<title>Objects</title>
<para>
Smarty allows access to PHP objects through the templates. There are
two ways to access them. One way is to register objects to the template,
then use access them via syntax similar to custom functions. The other way
is to assign objects to the templates and access them much like any other
assigned variable. The first method has a much nicer template syntax. It
is also more secure, as a registered object can be restricted to certain
methods or properties. However, a registered object cannot be looped over
or assigned in arrays of objects, etc. The method you choose will be
determined by your needs, but use the first method whenever possible to
keep template syntax to a minimum.
</para>
<para>
If security is enabled, no private methods or functions can be accessed
(begininning with "_"). If a method and property of the same name exist,
the method will be used.
</para>
<para>
You can restrict the methods and properties that can be accessed by
listing them in an array as the third registration parameter.
</para>
<para>
By default, parameters passed to objects through the templates are passed
the same way custom functions get them. An associative array is passed
as the first parameter, and the smarty object as the second. If you want
the parameters passed one at a time for each argument like traditional
object parameter passing, set the fourth registration parameter to false.
</para>
<example>
<title>using a registered or assigned object</title>
<programlisting>
&lt;?php
// the object
class My_Object() {
function meth1($params, &$smarty_obj) {
return "this is my meth1";
}
}
$myobj = new My_Object;
// registering the object (will be by reference)
$smarty->register_object("foobar",$myobj);
// if we want to restrict access to certain methods or properties, list them
$smarty->register_object("foobar",$myobj,array('meth1','meth2','prop1'));
// if you want to use the traditional object parameter format, pass a boolean of false
$smarty->register_object("foobar",$myobj,null,false);
// We can also assign objects. Assign by ref when possible.
$smarty->assign_by_ref("myobj", $myobj);
$smarty->display("index.tpl");
?&gt;
TEMPLATE:
{* access our registered object *}
{foobar->meth1 p1="foo" p2=$bar}
{* you can also assign the output *}
{foobar->meth1 p1="foo" p2=$bar assign="output"}
the output was {$output)
{* access our assigned object *}
{$myobj->meth1("foo",$bar)}</programlisting>
</example>
</sect1>
<sect1 id="advanced.features.prefilters"> <sect1 id="advanced.features.prefilters">
<title>Prefilters</title> <title>Prefilters</title>
<para> <para>
@@ -2219,7 +2317,7 @@ require_once SMARTY_DIR . 'plugins/function.html_options.php';</programlisting>
table. table.
</para> </para>
<para> <para>
The output of the function will be substituted in place of the The output (return value) of the function will be substituted in place of the
function tag in the template (<function>fetch</function> function, for function tag in the template (<function>fetch</function> function, for
example). Alternatively, the function can simply perform some other example). Alternatively, the function can simply perform some other
task without any output (<function>assign</function> function). task without any output (<function>assign</function> function).
@@ -2258,7 +2356,7 @@ function smarty_function_eightball($params, &amp;$smarty)
'Maybe in your reality'); 'Maybe in your reality');
$result = array_rand($answers); $result = array_rand($answers);
echo $answers[$result]; return $answers[$result];
} }
?&gt;</programlisting> ?&gt;</programlisting>
</example> </example>

View File

@@ -3,7 +3,7 @@
/** /**
* Config_File class. * Config_File class.
* *
* @version 2.3.1 * @version 2.4.0
* @author Andrei Zmievski <andrei@php.net> * @author Andrei Zmievski <andrei@php.net>
* @access public * @access public
* *

View File

@@ -5,7 +5,7 @@
* Author: Monte Ohrt <monte@ispi.net> * Author: Monte Ohrt <monte@ispi.net>
* Andrei Zmievski <andrei@php.net> * Andrei Zmievski <andrei@php.net>
* *
* Version: 2.3.1 * Version: 2.4.0
* Copyright: 2001,2002 ispi of Lincoln, Inc. * Copyright: 2001,2002 ispi of Lincoln, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@@ -1734,22 +1734,22 @@ class Smarty
$_compile_file = $this->_get_auto_filename($this->compile_dir, $file); $_compile_file = $this->_get_auto_filename($this->compile_dir, $file);
} }
// need to generate cache? // need to compile config file?
if($this->force_compile || !file_exists($_compile_file) || if($this->force_compile || !file_exists($_compile_file) ||
($this->compile_check && ($this->compile_check &&
file_exists($_file_path) && file_exists($_file_path) &&
( filemtime($_compile_file) != filemtime($_file_path) ))) { ( filemtime($_compile_file) != filemtime($_file_path) ))) {
$_generate_cache = true; $_compile_config = true;
} else { } else {
include($_compile_file); include($_compile_file);
if(!empty($_config_vars)) { if(!empty($_config_vars)) {
$_generate_cache = true; $_compile_config = true;
} else { } else {
$_generate_cache = false; $_compile_config = false;
} }
} }
if($_generate_cache) { if($_compile_config) {
if(!is_object($this->_conf_obj)) { if(!is_object($this->_conf_obj)) {
require_once SMARTY_DIR . $this->config_class . '.class.php'; require_once SMARTY_DIR . $this->config_class . '.class.php';
$this->_conf_obj = new Config_File($_config_dir); $this->_conf_obj = new Config_File($_config_dir);

View File

@@ -6,7 +6,7 @@
* Author: Monte Ohrt <monte@ispi.net> * Author: Monte Ohrt <monte@ispi.net>
* Andrei Zmievski <andrei@php.net> * Andrei Zmievski <andrei@php.net>
* *
* Version: 2.3.1 * Version: 2.4.0
* Copyright: 2001,2002 ispi of Lincoln, Inc. * Copyright: 2001,2002 ispi of Lincoln, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or