diff --git a/Config_File.class.php b/Config_File.class.php index 01c248fb..975da8a7 100644 --- a/Config_File.class.php +++ b/Config_File.class.php @@ -3,7 +3,7 @@ /** * Config_File class. * - * @version 2.3.1 + * @version 2.4.0 * @author Andrei Zmievski * @access public * diff --git a/NEWS b/NEWS index eb228d4c..b3625fa6 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +Version 2.4.0 +------------- + - fix known problems with php tag handling in templates (recursion, echoing * Andrei Zmievski * - * Version: 2.3.1 + * Version: 2.4.0 * Copyright: 2001,2002 ispi of Lincoln, Inc. * * 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); } - // need to generate cache? + // need to compile config file? if($this->force_compile || !file_exists($_compile_file) || ($this->compile_check && file_exists($_file_path) && ( filemtime($_compile_file) != filemtime($_file_path) ))) { - $_generate_cache = true; + $_compile_config = true; } else { include($_compile_file); if(!empty($_config_vars)) { - $_generate_cache = true; + $_compile_config = true; } else { - $_generate_cache = false; + $_compile_config = false; } } - if($_generate_cache) { + if($_compile_config) { if(!is_object($this->_conf_obj)) { require_once SMARTY_DIR . $this->config_class . '.class.php'; $this->_conf_obj = new Config_File($_config_dir); diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index bddd22a8..5a7884c5 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -6,7 +6,7 @@ * Author: Monte Ohrt * Andrei Zmievski * - * Version: 2.3.1 + * Version: 2.4.0 * Copyright: 2001,2002 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or diff --git a/docs/appendixes.sgml b/docs/appendixes.sgml index 19de45b2..7ce174a1 100644 --- a/docs/appendixes.sgml +++ b/docs/appendixes.sgml @@ -362,9 +362,7 @@ Stock Name: {$ticker_name} Stock Price: {$ticker_price} 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 scrambled javascript in the HTML source, yet it it will look and work - 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. + correctly in the browser. This is done with the mailto plugin. Example of Obfuscating an E-mail Address diff --git a/docs/designers.sgml b/docs/designers.sgml index 00bf29bc..6a307039 100644 --- a/docs/designers.sgml +++ b/docs/designers.sgml @@ -359,6 +359,18 @@ OUTPUT: {* use the date_format modifier to show current date and time *} {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"} + + + + {$smarty.const} + + You can access PHP constant values directly. + + + +using {$smarty.const} + +{$smarty.const._MY_CONST_VAL} @@ -395,8 +407,8 @@ OUTPUT: Variable Modifiers - Variable modifiers can be applied to any variable to alter its contents. To - apply a modifier, specify the variable followed by the | + Variable modifiers can be applied to variables, custom functions or strings. To + apply a modifier, specify the value followed by the | (pipe) and the modifier name. A modifier may accept additional parameters that affect its behavior. These parameters follow the modifer name and are separated by : (colon). @@ -408,7 +420,13 @@ OUTPUT: <h2>{$title|upper}</h2> {* Truncate the topic to 40 characters use ... at the end *} -Topic: {$topic|truncate:40:"..."} +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"} If you apply a modifier to an array variable instead of a single value variable, @@ -787,7 +805,7 @@ no title 1 string No - html,htmlall,url,quotes,hex,hexentity + html,htmlall,url,quotes,hex,hexentity,javascript html This is the escape format to use. @@ -796,10 +814,8 @@ no title This is used to html escape, url escape, escape single quotes on a - variable not already escaped, hex escape or hexentity escape. hex - and hexentity escape can be used in conjunction to hide "mailto:" - links on a page from web spiders (spam collectors) and yet keep - them readable and linkable. By default, the variable is html + variable not already escaped, hex escape, hexentity or javascript escape. + By default, the variable is html escaped. @@ -4128,6 +4144,138 @@ OUTPUT: OUTPUT: 9.44 + + + + mailto + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + address + string + Yes + n/a + the e-mail address + + + text + string + No + n/a + the text to display, default is + the e-mail address + + + encode + string + No + none + How to encode the e-mail. + Can be one of none, + hex or javascript. + + + cc + string + No + n/a + e-mail addresses to carbon copy. + Separate entries by a comma. + + + bcc + string + No + n/a + e-mail addresses to blind carbon copy. + Separate entries by a comma. + + + subject + string + No + n/a + e-mail subject. + + + newsgroups + string + No + n/a + newsgroups to post to. + Separate entries by a comma. + + + followupto + string + No + n/a + addresses to follow up to. + Separate entries by a comma. + + + extra + string + No + n/a + any extra information you + want passed to the link, such + as style sheet classes + + + + + + 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. + + + Technical Note + + javascript is probably the most thorough form of + encoding, although you can use hex encoding too. + + + +mailto + +{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: + +<a href="mailto:me@domain.com" >me@domain.com</a> +<a href="mailto:me@domain.com" >send me some mail</a> +<SCRIPT language="javascript">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'))</SCRIPT> +<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" >&#x6d;&#x65;&#x40;&#x64;& +#x6f;&#x6d;&#x61;&#x69;&#x6e;&#x2e;&#x63;&#x6f;&#x6d;</a> +<a href="mailto:me@domain.com?subject=Hello%20to%20you%21" >me@domain.com</a> +<a href="mailto:me@domain.com?cc=you@domain.com%2Cthey@domain.com" >me@domain.com</a> +<a href="mailto:me@domain.com" class="email">me@domain.com</a> diff --git a/docs/programmers.sgml b/docs/programmers.sgml index 1b3ba3ce..61ec5839 100644 --- a/docs/programmers.sgml +++ b/docs/programmers.sgml @@ -1125,6 +1125,23 @@ $smarty->register_modifier("sslash","stripslashes"); // now you can use {$var|sslash} to strip slashes from variables + + + register_object + + + void register_object + string object_name + object $object + array allowed methods/properties + boolean format + + + + This is to register an object for use in the templates. See the + object section + of the manual for examples. + register_outputfilter @@ -1295,6 +1312,18 @@ $smarty->unregister_function("fetch"); $smarty->unregister_modifier("strip_tags"); + + unregister_object + + + void unregister_object + string object_name + + + + Use this to unregister an object. + + unregister_outputfilter @@ -1639,6 +1668,75 @@ $smarty->display('index.tpl',"sports|basketball"); Advanced Features + + Objects + + 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. + + + 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. + + + You can restrict the methods and properties that can be accessed by + listing them in an array as the third registration parameter. + + + 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. + + + using a registered or assigned object + +<?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"); +?> + +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)} + + Prefilters @@ -2219,7 +2317,7 @@ require_once SMARTY_DIR . 'plugins/function.html_options.php'; table. - 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 (fetch function, for example). Alternatively, the function can simply perform some other task without any output (assign function). @@ -2258,7 +2356,7 @@ function smarty_function_eightball($params, &$smarty) 'Maybe in your reality'); $result = array_rand($answers); - echo $answers[$result]; + return $answers[$result]; } ?> diff --git a/libs/Config_File.class.php b/libs/Config_File.class.php index 01c248fb..975da8a7 100644 --- a/libs/Config_File.class.php +++ b/libs/Config_File.class.php @@ -3,7 +3,7 @@ /** * Config_File class. * - * @version 2.3.1 + * @version 2.4.0 * @author Andrei Zmievski * @access public * diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 125d4a9d..a6c1c488 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -5,7 +5,7 @@ * Author: Monte Ohrt * Andrei Zmievski * - * Version: 2.3.1 + * Version: 2.4.0 * Copyright: 2001,2002 ispi of Lincoln, Inc. * * 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); } - // need to generate cache? + // need to compile config file? if($this->force_compile || !file_exists($_compile_file) || ($this->compile_check && file_exists($_file_path) && ( filemtime($_compile_file) != filemtime($_file_path) ))) { - $_generate_cache = true; + $_compile_config = true; } else { include($_compile_file); if(!empty($_config_vars)) { - $_generate_cache = true; + $_compile_config = true; } else { - $_generate_cache = false; + $_compile_config = false; } } - if($_generate_cache) { + if($_compile_config) { if(!is_object($this->_conf_obj)) { require_once SMARTY_DIR . $this->config_class . '.class.php'; $this->_conf_obj = new Config_File($_config_dir); diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index bddd22a8..5a7884c5 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -6,7 +6,7 @@ * Author: Monte Ohrt * Andrei Zmievski * - * Version: 2.3.1 + * Version: 2.4.0 * Copyright: 2001,2002 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or