diff --git a/FAQ b/FAQ index 1f0e63b8..484018da 100644 --- a/FAQ +++ b/FAQ @@ -66,7 +66,7 @@ A: Most other template engines for PHP provide basic variable substitution and functionality as easy as possible to use for both programmers and template designers. Smarty also compiles the templates into PHP scripts, eliminating the need to parse the templates on every invocation, making Smarty extremely - scalable and managable for large application needs. + scalable and manageable for large application needs. Q: What do you mean "Compiled PHP Scripts" ? A: Smarty reads the template files and creates PHP scripts from them. Once diff --git a/NEWS b/NEWS index 91e9a52a..35a5e6ab 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ - added nl2br modifier to distribution (Monte) - added html_image to distribution (Monte) - added cat modifier to distribution (Monte) + - added html_table to distribution (Monte) - added << >> <> support to if statments (SMK, Monte) - fix _assign_smarty_interface to not overwrite keys other than 'request' (Jerome Poudevigne, Monte) @@ -9,7 +10,8 @@ - fixed string_format modifier args (wrong order) (Paul Lockaby, Monte) - use tmp file for file writes, avoid file lock race (Monte) - - handle embedded "$smarty.config.foo.tpl" correctly (Monte) + - support syntax "$`smarty.config.foo`.tpl" for embedded + vars in quotes, and allow full dollar var syntax (Monte) - add $smarty.config.varname variable for accessing config vars (Paul Lockaby, Monte) - silence PHP warnings in function.fetch.php (Eduardo, diff --git a/README b/README index 70665c4b..47145209 100644 --- a/README +++ b/README @@ -52,7 +52,7 @@ DESCRIPTION: use for both programmers and template designers. Smarty also converts the templates into PHP scripts, eliminating the need to parse the templates on every invocation. This makes Smarty extremely scalable and - managable for large application needs. + manageable for large application needs. Some of Smarty's features: diff --git a/docs/designers.sgml b/docs/designers.sgml index 080c864e..e62577ed 100644 --- a/docs/designers.sgml +++ b/docs/designers.sgml @@ -515,6 +515,56 @@ OUTPUT: Cold Wave Linked to Temperatures. 32 + + + + cat + + + + + + + + + + Parameter Position + Type + Required + cat + Description + + + + + 1 + string + No + empty + This value to catentate to the given variable. + + + + + + This value is catenated to the given variable. + + +cat + +index.php: + +$smarty = new Smarty; +$smarty->assign('articleTitle', 'Psychics predict world didn't end'); +$smarty->display('index.tpl'); + +index.tpl: + +{$articleTitle|cat:" yesterday."} + +OUTPUT: + +Psychics predict world didn't end yesterday. @@ -984,6 +1034,30 @@ OUTPUT: Two Convicts Evade Noose, Jury Hung. two convicts evade noose, jury hung. + + + + nl2br + + All linebreaks will be converted to <br /> tags in the given + variable. This is equivalent to the PHP nl2br() function. + + +nl2br + +index.php: + +$smarty = new Smarty; +$smarty->assign('articleTitle', "Sun or rain expected\ntoday, dark tonight"); +$smarty->display('index.tpl'); + +index.tpl: + +{$articleTitle|nl2br} + +OUTPUT: + +Sun or rain expected<br />today, dark tonight @@ -2840,7 +2914,7 @@ e-mail: jane@mydomain.com<p> carriage returns affect the output of the rendered HTML (browser "features"), so you must run all your tags together in the template to get the desired results. This usually ends up in unreadable or - unmanagable templates. + unmanageable templates. Anything within {strip}{/strip} tags in Smarty are stripped of the @@ -3374,6 +3448,219 @@ You must supply a <b>state</b>. {if $weather ne ""} <b>{$weather}</b> {/if} + + + + html_checkboxes + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + name + string + No + checkbox + name of checkbox list + + + values + array + Yes, unless using checkboxes attribute + n/a + an array of values for checkbox buttons + + + output + array + Yes, unless using checkboxes attribute + n/a + an array of output for checkbox buttons + + + checked + string + No + empty + the checked checkbox element + + + checkboxes + associative array + Yes, unless using values and output + n/a + an associative array of values and output + + + separator + string + No + empty + string of text to separate each checkbox item + + + + + + html_checkboxes is a custom function that creates an html checkbox + group with provided data. It takes care of which item(s) are + selected by default as well. Required attributes are values and + output, unless you use checkboxes instead. All output is XHTML + compatible. + + +html_checkboxes + +index.php: + +require('Smarty.php.class'); +$smarty = new Smarty; +$smarty->assign('cust_ids', array(1000,1001,1002,1003)); +$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane +Johnson','CHarlie Brown')); +$smarty->assign('customer_id', 1001); +$smarty->display('index.tpl'); + + +index.tpl: + +{html_checkboxes values=$cust_ids checked=$customer_id output=$cust_names separator="<br />"} + + +index.php: + +require('Smarty.php.class'); +$smarty = new Smarty; +$smarty->assign('cust_checkboxes', array( + 1001 => 'Joe Schmoe', + 1002 => 'Jack Smith', + 1003 => 'Jane Johnson','Carlie Brown')); +$smarty->assign('customer_id', 1001); +$smarty->display('index.tpl'); + +index.tpl: + +{html_checkboxes name="id" checkboxes=$cust_checkboxes checked=$customer_id separator="<br />"} + + +OUTPUT: (both examples) + +<input type="checkbox" name="id[]" value="1000">Joe Schmoe<br /> +<input type="checkbox" name="id[]" value="1001" checked="checked"><br /> +<input type="checkbox" name="id[]" value="1002">Jane Johnson<br /> +<input type="checkbox" name="id[]" value="1003">Charlie Brown<br /> + + + + html_image + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + name + string + Yes + n/a + name/path to image + + + border + string + No + 0 + size of border around image + + + height + string + No + actual image height + height to display image + + + width + string + No + actual image width + width to display image + + + basedir + string + no + web server doc root + directory to base relative paths from + + + + + + html_image is a custom function that generates an HTML tag for an + image. The height and width are automatically calculated from the + image file if none are supplied. + + + basedir is the base directory that relative image paths are based + from. If not given, the web server document root (env variable + DOCUMENT_ROOT) is used as the base. If security is enabled, the + path to the image must be within a secure directory. + + + Technical Note + + html_image requires a hit to the disk to read the image and + calculate the height and width. If you don't use template + caching, it is generally better to avoid html_image and leave + image tags static for optimal performance. + + + +html_image + +index.php: + +require('Smarty.php.class'); +$smarty = new Smarty; +$smarty->display('index.tpl'); + +index.tpl: + +{image file="pumpkin.jpg"} +{image file="/path/from/docroot/pumpkin.jpg"} +{image file="../path/relative/to/currdir/pumpkin.jpg"} + +OUTPUT: (possible) + +<img src="pumpkin.jpg" border="0" width="44" height="68"> +<img src="/path/under/docroot/pumpkin.jpg" border="0" width="44" height="68"> +<img src="../path/relative/to/currdir/pumpkin.jpg" border="0" width="44" height="68"> @@ -3414,7 +3701,7 @@ You must supply a <b>state</b>. string/array No empty - the selected array element(s) + the selected option element(s) options @@ -3423,44 +3710,194 @@ You must supply a <b>state</b>. n/a an associative array of values and output + + name + string + No + empty + name of select group + - html_options is a custom function that creates html option lists - with provided data. It takes care of which item is selected by + html_options is a custom function that creates html option group + with provided data. It takes care of which item(s) are selected by default as well. Required attributes are values and output, unless - you use options instead. If a given value is an array, it will - treat it as an html OPTGROUP, and display the groups. Recursion is - supported with OPTGROUP. All output is xhtml compatible. + you use options instead. + + + If a given value is an array, it will treat it as an html OPTGROUP, + and display the groups. Recursion is supported with OPTGROUP. All + output is XHTML compatible. + + + If the optional name attribute is given, the + <select name="groupname"></select> tags will enclose + the option list. Otherwise only the option list is generated. html_options -{* assume that $cust_ids, and $cust_names are arrays of values, - and $customer_id may or may not be set to a value *} +index.php: + +require('Smarty.php.class'); +$smarty = new Smarty; +$smarty->assign('cust_ids', array(1000,1001,1002,1003)); +$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane +Johnson','Carlie Brown')); +$smarty->assign('customer_id', 1001); +$smarty->display('index.tpl'); + +index.tpl: <select name=customer_id> {html_options values=$cust_ids selected=$customer_id output=$cust_names} </select> -{* an alternative method is to pass the values & output as an associative array into - options. $customer_options is an associative array in this example. *} +index.php: + +require('Smarty.php.class'); +$smarty = new Smarty; +$smarty->assign('cust_options', array( + 1001 => 'Joe Schmoe', + 1002 => 'Jack Smith', + 1003 => 'Jane Johnson', + 1004 => 'Charlie Brown')); +$smarty->assign('customer_id', 1001); +$smarty->display('index.tpl'); + +index.tpl: <select name=customer_id> - {html_options options=$customer_options selected=$customer_id} + {html_options options=$cust_options selected=$customer_id} </select> -OUTPUT: +OUTPUT: (both examples) <select name=customer_id> - <option value="1000">Joe Schmoe</option> - <option value="1001" selected="selected">Jack Smith</option> - <option value="1002">Jane Johnson</option> - <option value="1003">Charlie Brown</option> + <option value="1000">Joe Schmoe</option> + <option value="1001" selected="selected">Jack Smith</option> + <option value="1002">Jane Johnson</option> + <option value="1003">Charlie Brown</option> </select> + + + + html_radios + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + name + string + No + radio + name of radio list + + + values + array + Yes, unless using radios attribute + n/a + an array of values for radio buttons + + + output + array + Yes, unless using radios attribute + n/a + an array of output for radio buttons + + + checked + string + No + empty + the checked radio element + + + radios + associative array + Yes, unless using values and output + n/a + an associative array of values and output + + + separator + string + No + empty + string of text to separate each radio item + + + + + + html_radios is a custom function that creates html radio button + group with provided data. It takes care of which item is selected + by default as well. Required attributes are values and output, + unless you use radios instead. All output is XHTML compatible. + + +html_radios + +index.php: + +require('Smarty.php.class'); +$smarty = new Smarty; +$smarty->assign('cust_ids', array(1000,1001,1002,1003)); +$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane +Johnson','Carlie Brown')); +$smarty->assign('customer_id', 1001); +$smarty->display('index.tpl'); + + +index.tpl: + +{html_radios values=$cust_ids checked=$customer_id output=$cust_names separator="<br />"} + + +index.php: + +require('Smarty.php.class'); +$smarty = new Smarty; +$smarty->assign('cust_radios', array( + 1001 => 'Joe Schmoe', + 1002 => 'Jack Smith', + 1003 => 'Jane Johnson', + 1004 => 'Charlie Brown')); +$smarty->assign('customer_id', 1001); +$smarty->display('index.tpl'); + + +index.tpl: + +{html_radios name="id" radios=$cust_radios checked=$customer_id separator="<br />"} + + +OUTPUT: (both examples) + +<input type="radio" name="id[]" value="1000">Joe Schmoe<br /> +<input type="radio" name="id[]" value="1001" checked="checked"><br /> +<input type="radio" name="id[]" value="1002">Jane Johnson<br /> +<input type="radio" name="id[]" value="1003">Charlie Brown<br /> @@ -4056,6 +4493,118 @@ OUTPUT: <option value="am" selected>AM</option> <option value="pm">PM</option> </select> + + + + html_table + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + loop + array + Yes + n/a + array of data to loop through + + + cols + integer + No + 3 + number of columns in the table + + + table_attr + string + No + border="1" + attributes for table tag + + + tr_attr + string + No + empty + attributes for tr tag (arrays are cycled) + + + td_attr + string + No + empty + attributes for td tag (arrays are cycled) + + + trailpad + string + No + &nbsp; + value to pad the trailing cells on last row with + (if any) + + + + + + html_table is a custom function that dumps an + array of data into an HTML table. The cols + attribute determines how many columns will be in the table. The + table_attr, tr_attr and + td_attr values determine the attributes given + to the table, tr and td tags. If tr_attr or + td_attr are arrays, they will be cycled through. + trailpad is the value put into the trailing + cells on the last table row if there are any present. + + +html_table + +index.php: + +require('Smarty.php.class'); +$smarty = new Smarty; +$smarty->assign('data',array(1,2,3,4,5,6,7,8,9)); +$smarty->assign('tr',array('bgcolor="#eeeeee"','bgcolor="#dddddd"')); +$smarty->display('index.tpl'); + +index.tpl: + +{html_table loop=$data} +{html_table loop=$data cols=4 table_attrs='border="0"'} +{html_table loop=$data cols=4 tr_attrs=$tr} + +OUTPUT: + +<table border="1"> +<tr><td>1</td><td>2</td><td>3</td></tr> +<tr><td>4</td><td>5</td><td>6</td></tr> +<tr><td>7</td><td>8</td><td>9</td></tr> +</table> +<table border="0"> +<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr> +<tr><td>5</td><td>6</td><td>7</td><td>8</td></tr> +<tr><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> +</table> +<table border="1"> +<tr bgcolor="#eeeeee"><td>1</td><td>2</td><td>3</td><td>4</td></tr> +<tr bgcolor="#dddddd"><td>5</td><td>6</td><td>7</td><td>8</td></tr> +<tr bgcolor="#eeeeee"><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> +</table> diff --git a/docs/getting-started.sgml b/docs/getting-started.sgml index c650fdf5..ea9579a2 100644 --- a/docs/getting-started.sgml +++ b/docs/getting-started.sgml @@ -5,7 +5,7 @@ What is Smarty? Smarty is a template engine for PHP. More specifically, it facilitates a - managable way to separate application logic and content from its + manageable way to separate application logic and content from its presentation. This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person. For example, let's say you are creating a web page @@ -30,7 +30,7 @@ logic in your templates under the condition that this logic is strictly for presentation. A word of advice: keep application logic out of the templates, and presentation logic out of the application. This will most - definately keep things managable and scalable for the foreseeable future. + definately keep things manageable and scalable for the foreseeable future. One of the unique aspects about Smarty is the template compling. This means @@ -81,39 +81,14 @@ Basic Installation - - Technical Note - This installation guide makes the assumption that you are familiar with - your web server setup, your PHP setup, and your operating system directory - naming conventions. In these examples we use a Unix filesystem, so be sure - you make the appropriate adjustments for your environment. - - - The following examples assume that "/php/includes" is in your PHP - include_path. See the PHP manual for information on setting this up. - - - - First install the Smarty library files. These are the PHP files that you DO - NOT edit. They are shared among all applications and they only get updated - when you upgrade to a new version of Smarty. - - - Technical Note - - We recommend that you do not edit the Smarty library files. This makes - upgrades much easier for you. You DO NOT need to edit these files to - configure your applications! Use an instance of the Smarty class, which - we'll get to in the sample setup below. - - - - - This is a list of the required library files that come with Smarty: + Install the Smarty library files which are in the /libs/ directory of + the distribution. These are the PHP files that you SHOULD NOT edit. They + are shared among all applications and they only get updated when you + upgrade to a new version of Smarty. - Smarty library files list + Smarty library files Smarty.class.php Smarty_Compiler.class.php @@ -123,32 +98,52 @@ debug.tpl - You can either place these library files within your PHP include_path, or - in any directory as long as you define that with the SMARTY_DIR constant. We'll show an - example of both. + Smarty uses a PHP constant named SMARTY_DIR which is the system + filepath Smarty library directory. Basically, if your application can find + the Smarty.class.php file, you do not need to set + SMARTY_DIR, Smarty will figure it out on its own. Therefore, if + Smarty.class.php is not in your include_path, or you + do not supply an absolute path to it in your application, then you must + define SMARTY_DIR manually. SMARTY_DIR must include a + trailing slash. Here is how you create an instance of Smarty in your PHP scripts: - Create Smarty instance from include_path + Create Smarty instance of Smarty require('Smarty.class.php'); $smarty = new Smarty; - If the library files are outside of your PHP include_path, you must define - the absolute path with the SMARTY_DIR constant. SMARTY_DIR must - end with a slash. Lets say we place our Smarty library files in - "/usr/local/lib/php/Smarty/". + Try running the above script. If you get an error saying the + Smarty.class.php file could not be found, you have to + do one of the following: - Create Smarty instance from SMARTY_DIR + Supply absolute path to library directory + +require('/usr/local/lib/php/Smarty/Smarty.class.php'); +$smarty = new Smarty; + + + + Add library directory to php_include path + +// Edit your php.ini file, add the Smarty library +// directory to the include_path and restart web server. +// Then the following should work: +require('Smarty.class.php'); +$smarty = new Smarty; + + + + Set SMARTY_DIR constant manually define('SMARTY_DIR','/usr/local/lib/php/Smarty/'); require(SMARTY_DIR.'Smarty.class.php'); @@ -156,53 +151,44 @@ $smarty = new Smarty; - Now the library files are in place, it's time to setup the Smarty - directories. + Now that the library files are in place, it's time to setup the Smarty + directories for your application. Smarty requires four directories which + are (by default) named tempalates, + templates_c, configs and + cache. Each of these are definable by the Smarty class + properties $template_dir, + $compile_dir, $config_dir, and + $cache_dir respectively. It is highly recommended + that you setup a separate set of these directories for each application + that will use Smarty. + + + Be sure you know the location of your web server document root. In our + example, the document root is "/web/www.mydomain.com/docs/". The Smarty + directories are only accessed by the Smarty library and never accessed + directly by the web browser. Therefore to avoid any security concerns, it + is recommended to place these directories in a directory + off the document root. For our installation example, we will be setting up the Smarty environment for a guest book application. We picked an application only for the purpose of a directory naming convention. You can use the same environment for any - application, just replace "guestbook" with the name of your app. - - - Be sure you know the location of your web server document root. In our - example, the document root is "/web/www.mydomain.com/docs/". - - - The Smarty directories are defined in the class variables $template_dir, - $compile_dir, $config_dir and $cache_dir, which default to the values - "templates", "templates_c", "configs" and "cache" respectively. In our - example, we'll place all of these directories under + application, just replace "guestbook" with the name of your app. We'll + place our Smarty directories under "/web/www.mydomain.com/smarty/guestbook/". - - - Technical Note - - As a rule of thumb, none of these directories should be under the document - root of your web server. This is recommended to avoid any possible direct - access. You may, for example, have config files with sensitive data. - - - You will need as least one file under your document root, and that is the script accessed by the web browser. We will call our script "index.php", - and place it in a subdirectory under the document root called "/guestbook/". - - - - Technical Note - - It is convenient to setup the web server so that "index.php" can be - identified as the default directory index, so if you access + and place it in a subdirectory under the document root called + "/guestbook/". It is convenient to setup the web server so that "index.php" + can be identified as the default directory index, so if you access "http://www.mydomain.com/guestbook/", the index.php script will be executed without "index.php" in the URL. In Apache you can set this up by adding "index.php" onto the end of your DirectoryIndex setting (separate each entry with a space.) - - + Lets take a look at the file structure so far: @@ -225,21 +211,13 @@ $smarty = new Smarty; /web/www.mydomain.com/docs/guestbook/index.php - - Technical Note - - The $config_dir and $cache_dir are not absolutely necessary if you do not - plan on using config files or template caching. It is probably a good idea - to set them up anyways, in the case you decide to use them later. - - - - Smarty will need write access to the $compile_dir and $cache_dir, so be sure - the web server user can write to them. This is usually user "nobody" and - group "nobody". For OS X users, the default is user "web" and group "web". - If you are using Apache, you can look in your httpd.conf file (usually in - "/usr/local/apache/conf/") to see what user and group are being used. + Smarty will need write access to the $compile_dir and + $cache_dir, so be sure the web server user can write + to them. This is usually user "nobody" and group "nobody". For OS X users, + the default is user "web" and group "web". If you are using Apache, you can + look in your httpd.conf file (usually in "/usr/local/apache/conf/") to see + what user and group are being used. @@ -291,15 +269,16 @@ Hello, {$name}! Now lets edit index.php. We'll create an instance of Smarty, assign a - template variable and display the index.tpl file. + template variable and display the index.tpl file. In our example + environment, "/usr/local/lib/php/Smarty" is in our include_path. Be sure you + do the same, or use absolute paths. Editing /web/www.mydomain.com/docs/guestbook/index.php - -define('SMARTY_DIR','/usr/local/lib/php/Smarty/'); -require(SMARTY_DIR.'Smarty.class.php'); +// load Smarty library +require(Smarty.class.php'); $smarty = new Smarty; @@ -345,19 +324,21 @@ $smarty->display('index.tpl'); A slightly more flexible way to setup Smarty is to extend the class and initialize your Smarty environment. So instead of repeatedly setting directory paths, assigning the same vars, etc., we can do that in one place. - Lets create a new directory "/php/includes/guestbook/" and make a new file called - "setup.php". + Lets create a new directory "/php/includes/guestbook/" and make a new file + called "setup.php". In our example environment, "/php/includes" is in our + include_path. Be sure you set this up too, or use absolute file paths. Editing /php/includes/guestbook/setup.php -// load Smarty library files -define('SMARTY_DIR','/usr/local/lib/php/Smarty/'); -require(SMARTY_DIR.'Smarty.class.php'); +// load Smarty library +require(Smarty.class.php'); -// a good place to load application library files, example: +// The setup.php file is a good place to load +// required application library files, and you +// can do that right here. An example: // require('guestbook/guestbook.lib.php'); class Smarty_GuestBook extends Smarty { @@ -380,18 +361,6 @@ class Smarty_GuestBook extends Smarty { } - - Technical Note - - In our example, we keep application libraries (not intended for direct - browser access) in a separate directory outside of the document root. These - files may contain sensitive data that we don't want any direct access to. - We keep all library files for the guest book application under - "/php/includes/guestbook/" and load them in the setup script, as you see in - the above example. - - - Now lets alter the index.php file to use setup.php: diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 3c38dfc8..d44f4a74 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -1449,16 +1449,20 @@ class Smarty_Compiler extends Smarty { function _expand_quoted_text($var_expr) { // if contains unescaped $, expand it - if(preg_match_all('%(?_var_bracket_regexp . ')*)\`?%', $var_expr, $match)) { - rsort($match[0]); - reset($match[0]); - foreach($match[0] as $var) { - $var_expr = str_replace ($var, '".' . $this->_parse_var(str_replace('`','',$var)) . '."', $var_expr); + if(preg_match_all('%(?_dvar_guts_regexp . '\`?%', $var_expr, $_match)) { + $_match = $_match[0]; + rsort($_match); + reset($_match); + foreach($_match as $_var) { + $var_expr = str_replace ($_var, '".' . $this->_parse_var(str_replace('`','',$_var)) . '."', $var_expr); } - return preg_replace('!\.""|""\.!', '', $var_expr); + $_return = preg_replace('!\.""|""\.!', '', $var_expr); } else { - return $var_expr; + $_return = $var_expr; } + // replace double quoted string with single quotes + $_return = preg_replace('!"([^\$\']+)"!',"'\\1'",$_return); + return $_return; } /** @@ -1468,9 +1472,8 @@ class Smarty_Compiler extends Smarty { */ function _parse_var($var_expr) { - preg_match('!(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . ')(' . $this->_mod_regexp . '*)$!', $var_expr, $match); - + $var_ref = substr($match[1],1); $modifiers = $match[2]; @@ -1481,7 +1484,7 @@ class Smarty_Compiler extends Smarty { // get [foo] and .foo and ->foo and (...) pieces preg_match_all('!(?:^\w+)|' . $this->_obj_params_regexp . '|(?:' . $this->_var_bracket_regexp . ')|->\w+|\.\$?\w+|\S+!', $var_ref, $match); - + $indexes = $match[0]; $var_name = array_shift($indexes); @@ -1534,11 +1537,6 @@ class Smarty_Compiler extends Smarty { $output .= $index; } } - - // look for variables imbedded in quoted strings, replace them - if(preg_match('|(?_expand_quoted_text($match[0]), $output); - } $this->_parse_modifiers($output, $modifiers); @@ -1749,7 +1747,7 @@ class Smarty_Compiler extends Smarty { case 'const': array_shift($indexes); $_val = $this->_parse_var_props(substr($indexes[0],1)); - $compiled_ref = "(defined($_val) ? $_val : null)"; + $compiled_ref = '(defined(' . $_val . ') ? ' . $this->_dequote($_val) . ' : null)'; $_max_index = 1; break; diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index 40329025..0c06ef5e 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -11,6 +11,7 @@ * Purpose: Prints out a list of checkbox input types * Input: name (optional) - string default "checkbox" * values (required) - array + * checkboxes (optional) - associative array * checked (optional) - array default not set * separator (optional) - ie
or   * output (optional) - without this one the buttons don't have names @@ -21,9 +22,10 @@ * {html_checkboxes values=$ids checked=$checked separator='
' output=$names} * ------------------------------------------------------------- */ -require_once $this->_get_plugin_filepath('shared','escape_special_chars'); function smarty_function_html_checkboxes($params, &$smarty) { + require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); + extract($params); $_html_result = ''; diff --git a/libs/plugins/function.html_image.php b/libs/plugins/function.html_image.php index 938e386b..a3b8a1ab 100644 --- a/libs/plugins/function.html_image.php +++ b/libs/plugins/function.html_image.php @@ -15,8 +15,8 @@ * border = border width (optional, default 0) * height = image height (optional, default actual height) * image =image width (optional, default actual width) - * basedir= base directory for absolute paths, default - * is environment variable DOCUMENT_ROOT + * basedir = base directory for absolute paths, default + * is environment variable DOCUMENT_ROOT * * Examples: {image name="images/masthead.gif"} * Output: @@ -80,8 +80,8 @@ function smarty_function_html_image($params, &$smarty) $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_ERROR); } } - if(!$smarty->security && substr($_image_path,0,strlen($basedir)) != $basedir) { - $smarty->trigger_error("html_image: (secure) '$_image_path' not within basedir ($basedir)", E_USER_ERROR); + if(!$smarty->security && !$smarty->_is_secure('file', $_image_path)) { + $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_ERROR); } if(!isset($params['width'])) { diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php index 7a85e489..aada4bbc 100644 --- a/libs/plugins/function.html_options.php +++ b/libs/plugins/function.html_options.php @@ -1,7 +1,5 @@ _get_plugin_filepath('shared','escape_special_chars'); + extract($params); $html_result = ''; @@ -35,6 +35,9 @@ function smarty_function_html_options($params, &$smarty) } } + if(!empty($name)) { + $html_result = '' . "\n"; + } return $html_result; } diff --git a/libs/plugins/function.html_radios.php b/libs/plugins/function.html_radios.php index 92a9d0f0..ea7c47ca 100644 --- a/libs/plugins/function.html_radios.php +++ b/libs/plugins/function.html_radios.php @@ -11,6 +11,7 @@ * Purpose: Prints out a list of radio input types * Input: name (optional) - string default "radio" * values (required) - array + * radios (optional) - associative array * checked (optional) - array default not set * separator (optional) - ie
or   * output (optional) - without this one the buttons don't have names diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php index c50083bd..ca17b5c7 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -19,10 +19,10 @@ * day values (Marcus Bointon) * ------------------------------------------------------------- */ -require_once $this->_get_plugin_filepath('shared','make_timestamp'); -require_once $this->_get_plugin_filepath('function','html_options'); function smarty_function_html_select_date($params, &$smarty) { + require_once $smarty->_get_plugin_filepath('shared','make_timestamp'); + require_once $smarty->_get_plugin_filepath('function','html_options'); /* Default values. */ $prefix = "Date_"; $start_year = strftime("%Y"); diff --git a/libs/plugins/function.html_select_time.php b/libs/plugins/function.html_select_time.php index 06bd7787..818ae6eb 100644 --- a/libs/plugins/function.html_select_time.php +++ b/libs/plugins/function.html_select_time.php @@ -8,10 +8,10 @@ * Purpose: Prints the dropdowns for time selection * ------------------------------------------------------------- */ -require_once $this->_get_plugin_filepath('shared','make_timestamp'); -require_once $this->_get_plugin_filepath('function','html_options'); function smarty_function_html_select_time($params, &$smarty) { + require_once $smarty->_get_plugin_filepath('shared','make_timestamp'); + require_once $smarty->_get_plugin_filepath('function','html_options'); /* Default values. */ $prefix = "Time_"; $time = time(); diff --git a/libs/plugins/function.html_table.php b/libs/plugins/function.html_table.php index b24da486..b66cb0c5 100644 --- a/libs/plugins/function.html_table.php +++ b/libs/plugins/function.html_table.php @@ -14,7 +14,7 @@ * table_attr = table attributes * tr_attr = table row attributes (arrays are cycled) * td_attr = table cell attributes (arrays are cycled) - * cellpad = value to pad trailing cells with + * trailpad = value to pad trailing cells with * * Examples: {table loop=$data} * {$table loop=$data cols=4 tr_attr='"bgcolor=red"'} @@ -23,11 +23,11 @@ */ function smarty_function_html_table($params, &$smarty) { - $table_attr = 'border=1'; + $table_attr = 'border="1"'; $tr_attr = ''; $td_attr = ''; $cols = 3; - $cellpad = ' '; + $trailpad = ' '; extract($params); @@ -50,7 +50,7 @@ function smarty_function_html_table($params, &$smarty) $cells = $cols - $y % $cols; if($cells != $cols) { for($padloop = 0; $padloop < $cells; $padloop++) { - $output .= "$cellpad\n"; + $output .= "$trailpad\n"; } } $output .= "\n";