Smarty-3.1.21/0000775000000000000000000000000012420527714011561 5ustar rootrootSmarty-3.1.21/demo/0000755000000000000000000000000012420527746012510 5ustar rootrootSmarty-3.1.21/demo/templates_c/0000755000000000000000000000000012420527746015010 5ustar rootrootSmarty-3.1.21/demo/index.php0000664000000000000000000000210312420527634014322 0ustar rootrootforce_compile = true; $smarty->debugging = true; $smarty->caching = true; $smarty->cache_lifetime = 120; $smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true); $smarty->assign("FirstName", array("John", "Mary", "James", "Henry")); $smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case")); $smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"), array("M", "N", "O", "P"))); $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))); $smarty->assign("option_values", array("NY", "NE", "KS", "IA", "OK", "TX")); $smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas")); $smarty->assign("option_selected", "NE"); $smarty->display('index.tpl'); Smarty-3.1.21/demo/plugins/0000755000000000000000000000000012420527746014171 5ustar rootrootSmarty-3.1.21/demo/plugins/resource.mysqls.php0000664000000000000000000000374712420527634020071 0ustar rootrootCREATE TABLE IF NOT EXISTS `templates` ( * `name` varchar(100) NOT NULL, * `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, * `source` text, * PRIMARY KEY (`name`) * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; * Demo data: *
INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');
* * @package Resource-examples * @author Rodney Rehm */ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom { // PDO instance protected $db; // prepared fetch() statement protected $fetch; public function __construct() { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); } catch (PDOException $e) { throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); } $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); } /** * Fetch a template and its modification time from database * * @param string $name template name * @param string $source template source * @param integer $mtime template modification timestamp (epoch) * * @return void */ protected function fetch($name, &$source, &$mtime) { $this->fetch->execute(array('name' => $name)); $row = $this->fetch->fetch(); $this->fetch->closeCursor(); if ($row) { $source = $row['source']; $mtime = strtotime($row['modified']); } else { $source = null; $mtime = null; } } } Smarty-3.1.21/demo/plugins/cacheresource.mysql.php0000664000000000000000000001345212420527634020664 0ustar rootrootCREATE TABLE IF NOT EXISTS `output_cache` ( * `id` CHAR(40) NOT NULL COMMENT 'sha1 hash', * `name` VARCHAR(250) NOT NULL, * `cache_id` VARCHAR(250) NULL DEFAULT NULL, * `compile_id` VARCHAR(250) NULL DEFAULT NULL, * `modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, * `content` LONGTEXT NOT NULL, * PRIMARY KEY (`id`), * INDEX(`name`), * INDEX(`cache_id`), * INDEX(`compile_id`), * INDEX(`modified`) * ) ENGINE = InnoDB; * * @package CacheResource-examples * @author Rodney Rehm */ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom { // PDO instance protected $db; protected $fetch; protected $fetchTimestamp; protected $save; public function __construct() { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); } catch (PDOException $e) { throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); } $this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); $this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id'); $this->save = $this->db->prepare('REPLACE INTO output_cache (id, name, cache_id, compile_id, content) VALUES (:id, :name, :cache_id, :compile_id, :content)'); } /** * fetch cached content and its modification time from data source * * @param string $id unique cache content identifier * @param string $name template name * @param string $cache_id cache id * @param string $compile_id compile id * @param string $content cached content * @param integer $mtime cache modification timestamp (epoch) * * @return void */ protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime) { $this->fetch->execute(array('id' => $id)); $row = $this->fetch->fetch(); $this->fetch->closeCursor(); if ($row) { $content = $row['content']; $mtime = strtotime($row['modified']); } else { $content = null; $mtime = null; } } /** * Fetch cached content's modification timestamp from data source * * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content. * * @param string $id unique cache content identifier * @param string $name template name * @param string $cache_id cache id * @param string $compile_id compile id * * @return integer|boolean timestamp (epoch) the template was modified, or false if not found */ protected function fetchTimestamp($id, $name, $cache_id, $compile_id) { $this->fetchTimestamp->execute(array('id' => $id)); $mtime = strtotime($this->fetchTimestamp->fetchColumn()); $this->fetchTimestamp->closeCursor(); return $mtime; } /** * Save content to cache * * @param string $id unique cache content identifier * @param string $name template name * @param string $cache_id cache id * @param string $compile_id compile id * @param integer|null $exp_time seconds till expiration time in seconds or null * @param string $content content to cache * * @return boolean success */ protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content) { $this->save->execute(array( 'id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id, 'content' => $content, )); return !!$this->save->rowCount(); } /** * Delete content from cache * * @param string $name template name * @param string $cache_id cache id * @param string $compile_id compile id * @param integer|null $exp_time seconds till expiration or null * * @return integer number of deleted caches */ protected function delete($name, $cache_id, $compile_id, $exp_time) { // delete the whole cache if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) { // returning the number of deleted caches would require a second query to count them $query = $this->db->query('TRUNCATE TABLE output_cache'); return - 1; } // build the filter $where = array(); // equal test name if ($name !== null) { $where[] = 'name = ' . $this->db->quote($name); } // equal test compile_id if ($compile_id !== null) { $where[] = 'compile_id = ' . $this->db->quote($compile_id); } // range test expiration time if ($exp_time !== null) { $where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)'; } // equal test cache_id and match sub-groups if ($cache_id !== null) { $where[] = '(cache_id = ' . $this->db->quote($cache_id) . ' OR cache_id LIKE ' . $this->db->quote($cache_id . '|%') . ')'; } // run delete query $query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where)); return $query->rowCount(); } } Smarty-3.1.21/demo/plugins/cacheresource.memcache.php0000664000000000000000000000450212420527634021255 0ustar rootrootmemcache = new Memcache(); $this->memcache->addServer('127.0.0.1', 11211); } /** * Read values for a set of keys from cache * * @param array $keys list of keys to fetch * * @return array list of values with the given keys used as indexes * @return boolean true on success, false on failure */ protected function read(array $keys) { $_keys = $lookup = array(); foreach ($keys as $k) { $_k = sha1($k); $_keys[] = $_k; $lookup[$_k] = $k; } $_res = array(); $res = $this->memcache->get($_keys); foreach ($res as $k => $v) { $_res[$lookup[$k]] = $v; } return $_res; } /** * Save values for a set of keys to cache * * @param array $keys list of values to save * @param int $expire expiration time * * @return boolean true on success, false on failure */ protected function write(array $keys, $expire = null) { foreach ($keys as $k => $v) { $k = sha1($k); $this->memcache->set($k, $v, 0, $expire); } return true; } /** * Remove values from cache * * @param array $keys list of keys to delete * * @return boolean true on success, false on failure */ protected function delete(array $keys) { foreach ($keys as $k) { $k = sha1($k); $this->memcache->delete($k); } return true; } /** * Remove *all* values from cache * * @return boolean true on success, false on failure */ protected function purge() { $this->memcache->flush(); } } Smarty-3.1.21/demo/plugins/cacheresource.apc.php0000664000000000000000000000362012420527634020256 0ustar rootroot $v) { $_res[$k] = $v; } return $_res; } /** * Save values for a set of keys to cache * * @param array $keys list of values to save * @param int $expire expiration time * * @return boolean true on success, false on failure */ protected function write(array $keys, $expire = null) { foreach ($keys as $k => $v) { apc_store($k, $v, $expire); } return true; } /** * Remove values from cache * * @param array $keys list of keys to delete * * @return boolean true on success, false on failure */ protected function delete(array $keys) { foreach ($keys as $k) { apc_delete($k); } return true; } /** * Remove *all* values from cache * * @return boolean true on success, false on failure */ protected function purge() { return apc_clear_cache('user'); } } Smarty-3.1.21/demo/plugins/resource.mysql.php0000664000000000000000000000506712420527634017703 0ustar rootrootCREATE TABLE IF NOT EXISTS `templates` ( * `name` varchar(100) NOT NULL, * `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, * `source` text, * PRIMARY KEY (`name`) * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; * Demo data: *
INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');
* * @package Resource-examples * @author Rodney Rehm */ class Smarty_Resource_Mysql extends Smarty_Resource_Custom { // PDO instance protected $db; // prepared fetch() statement protected $fetch; // prepared fetchTimestamp() statement protected $mtime; public function __construct() { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); } catch (PDOException $e) { throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); } $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); } /** * Fetch a template and its modification time from database * * @param string $name template name * @param string $source template source * @param integer $mtime template modification timestamp (epoch) * * @return void */ protected function fetch($name, &$source, &$mtime) { $this->fetch->execute(array('name' => $name)); $row = $this->fetch->fetch(); $this->fetch->closeCursor(); if ($row) { $source = $row['source']; $mtime = strtotime($row['modified']); } else { $source = null; $mtime = null; } } /** * Fetch a template's modification time from database * * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source. * * @param string $name template name * * @return integer timestamp (epoch) the template was modified */ protected function fetchTimestamp($name) { $this->mtime->execute(array('name' => $name)); $mtime = $this->mtime->fetchColumn(); $this->mtime->closeCursor(); return strtotime($mtime); } } Smarty-3.1.21/demo/plugins/resource.extendsall.php0000664000000000000000000000337212420527634020676 0ustar rootrootsmarty->getTemplateDir() as $key => $directory) { try { $s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name); if (!$s->exists) { continue; } $sources[$s->uid] = $s; $uid .= $s->filepath; } catch (SmartyException $e) { } } if (!$sources) { $source->exists = false; $source->template = $_template; return; } $sources = array_reverse($sources, true); reset($sources); $s = current($sources); $source->components = $sources; $source->filepath = $s->filepath; $source->uid = sha1($uid); $source->exists = $exists; if ($_template && $_template->smarty->compile_check) { $source->timestamp = $s->timestamp; } // need the template at getContent() $source->template = $_template; } } Smarty-3.1.21/demo/configs/0000755000000000000000000000000012420527746014140 5ustar rootrootSmarty-3.1.21/demo/configs/test.conf0000644000000000000000000000010112420527634015752 0ustar rootroottitle = Welcome to Smarty! cutoff_size = 40 [setup] bold = true Smarty-3.1.21/demo/templates/0000755000000000000000000000000012420527746014506 5ustar rootrootSmarty-3.1.21/demo/templates/footer.tpl0000644000000000000000000000002012420527634016511 0ustar rootroot Smarty-3.1.21/demo/templates/header.tpl0000664000000000000000000000012512420527634016453 0ustar rootroot {$title} - {$Name} Smarty-3.1.21/demo/templates/index.tpl0000664000000000000000000000400012420527634016326 0ustar rootroot{config_load file="test.conf" section="setup"} {include file="header.tpl" title=foo}

{* bold and title are read from the config file *}
    {if #bold#}{/if}
        {* capitalize the first letters of each word of the title *}
        Title: {#title#|capitalize}
        {if #bold#}{/if}

    The current date and time is {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}

    The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}

    Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}

    The value of {ldelim}$Name{rdelim} is {$Name}

variable modifier example of {ldelim}$Name|upper{rdelim}

{$Name|upper}


An example of a section loop:

    {section name=outer
    loop=$FirstName}
        {if $smarty.section.outer.index is odd by 2}
            {$smarty.section.outer.rownum} . {$FirstName[outer]} {$LastName[outer]}
        {else}
            {$smarty.section.outer.rownum} * {$FirstName[outer]} {$LastName[outer]}
        {/if}
        {sectionelse}
        none
    {/section}

    An example of section looped key values:

    {section name=sec1 loop=$contacts}
        phone: {$contacts[sec1].phone}
        
fax: {$contacts[sec1].fax}
cell: {$contacts[sec1].cell}
{/section}

testing strip tags {strip}
This is a test
{/strip}

This is an example of the html_select_date function:
{html_select_date start_year=1998 end_year=2010}
This is an example of the html_select_time function:
{html_select_time use_24_hours=false}
This is an example of the html_options function:
{include file="footer.tpl"} Smarty-3.1.21/demo/cache/0000755000000000000000000000000012420527746013553 5ustar rootrootSmarty-3.1.21/README0000644000000000000000000005046312420527642012447 0ustar rootrootSmarty 3.1.21 Author: Monte Ohrt Author: Uwe Tews AN INTRODUCTION TO SMARTY 3 NOTICE FOR 3.1 release: Please see the SMARTY_3.1_NOTES.txt file that comes with the distribution. NOTICE for 3.0.5 release: Smarty now follows the PHP error_reporting level by default. If PHP does not mask E_NOTICE and you try to access an unset template variable, you will now get an E_NOTICE warning. To revert to the old behavior: $smarty->error_reporting = E_ALL & ~E_NOTICE; NOTICE for 3.0 release: IMPORTANT: Some API adjustments have been made between the RC4 and 3.0 release. We felt it is better to make these now instead of after a 3.0 release, then have to immediately deprecate APIs in 3.1. Online documentation has been updated to reflect these changes. Specifically: ---- API CHANGES RC4 -> 3.0 ---- $smarty->register->* $smarty->unregister->* $smarty->utility->* $samrty->cache->* Have all been changed to local method calls such as: $smarty->clearAllCache() $smarty->registerFoo() $smarty->unregisterFoo() $smarty->testInstall() etc. Registration of function, block, compiler, and modifier plugins have been consolidated under two API calls: $smarty->registerPlugin(...) $smarty->unregisterPlugin(...) Registration of pre, post, output and variable filters have been consolidated under two API calls: $smarty->registerFilter(...) $smarty->unregisterFilter(...) Please refer to the online documentation for all specific changes: http://www.smarty.net/documentation ---- The Smarty 3 API has been refactored to a syntax geared for consistency and modularity. The Smarty 2 API syntax is still supported, but will throw a deprecation notice. You can disable the notices, but it is highly recommended to adjust your syntax to Smarty 3, as the Smarty 2 syntax must run through an extra rerouting wrapper. Basically, all Smarty methods now follow the "fooBarBaz" camel case syntax. Also, all Smarty properties now have getters and setters. So for example, the property $smarty->cache_dir can be set with $smarty->setCacheDir('foo/') and can be retrieved with $smarty->getCacheDir(). Some of the Smarty 3 APIs have been revoked such as the "is*" methods that were just duplicate functions of the now available "get*" methods. Here is a rundown of the Smarty 3 API: $smarty->fetch($template, $cache_id = null, $compile_id = null, $parent = null) $smarty->display($template, $cache_id = null, $compile_id = null, $parent = null) $smarty->isCached($template, $cache_id = null, $compile_id = null) $smarty->createData($parent = null) $smarty->createTemplate($template, $cache_id = null, $compile_id = null, $parent = null) $smarty->enableSecurity() $smarty->disableSecurity() $smarty->setTemplateDir($template_dir) $smarty->addTemplateDir($template_dir) $smarty->templateExists($resource_name) $smarty->loadPlugin($plugin_name, $check = true) $smarty->loadFilter($type, $name) $smarty->setExceptionHandler($handler) $smarty->addPluginsDir($plugins_dir) $smarty->getGlobal($varname = null) $smarty->getRegisteredObject($name) $smarty->getDebugTemplate() $smarty->setDebugTemplate($tpl_name) $smarty->assign($tpl_var, $value = null, $nocache = false) $smarty->assignGlobal($varname, $value = null, $nocache = false) $smarty->assignByRef($tpl_var, &$value, $nocache = false) $smarty->append($tpl_var, $value = null, $merge = false, $nocache = false) $smarty->appendByRef($tpl_var, &$value, $merge = false) $smarty->clearAssign($tpl_var) $smarty->clearAllAssign() $smarty->configLoad($config_file, $sections = null) $smarty->getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true) $smarty->getConfigVariable($variable) $smarty->getStreamVariable($variable) $smarty->getConfigVars($varname = null) $smarty->clearConfig($varname = null) $smarty->getTemplateVars($varname = null, $_ptr = null, $search_parents = true) $smarty->clearAllCache($exp_time = null, $type = null) $smarty->clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) $smarty->registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = array()) $smarty->registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) $smarty->registerFilter($type, $function_name) $smarty->registerResource($resource_type, $function_names) $smarty->registerDefaultPluginHandler($function_name) $smarty->registerDefaultTemplateHandler($function_name) $smarty->unregisterPlugin($type, $tag) $smarty->unregisterObject($object_name) $smarty->unregisterFilter($type, $function_name) $smarty->unregisterResource($resource_type) $smarty->compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) $smarty->clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) $smarty->testInstall() // then all the getters/setters, available for all properties. Here are a few: $caching = $smarty->getCaching(); // get $smarty->caching $smarty->setCaching(true); // set $smarty->caching $smarty->setDeprecationNotices(false); // set $smarty->deprecation_notices $smarty->setCacheId($id); // set $smarty->cache_id $debugging = $smarty->getDebugging(); // get $smarty->debugging FILE STRUCTURE The Smarty 3 file structure is similar to Smarty 2: /libs/ Smarty.class.php /libs/sysplugins/ internal.* /libs/plugins/ function.mailto.php modifier.escape.php ... A lot of Smarty 3 core functionality lies in the sysplugins directory; you do not need to change any files here. The /libs/plugins/ folder is where Smarty plugins are located. You can add your own here, or create a separate plugin directory, just the same as Smarty 2. You will still need to create your own /cache/, /templates/, /templates_c/, /configs/ folders. Be sure /cache/ and /templates_c/ are writable. The typical way to use Smarty 3 should also look familiar: require('Smarty.class.php'); $smarty = new Smarty; $smarty->assign('foo','bar'); $smarty->display('index.tpl'); However, Smarty 3 works completely different on the inside. Smarty 3 is mostly backward compatible with Smarty 2, except for the following items: *) Smarty 3 is PHP 5 only. It will not work with PHP 4. *) The {php} tag is disabled by default. Enable with $smarty->allow_php_tag=true. *) Delimiters surrounded by whitespace are no longer treated as Smarty tags. Therefore, { foo } will not compile as a tag, you must use {foo}. This change Makes Javascript/CSS easier to work with, eliminating the need for {literal}. This can be disabled by setting $smarty->auto_literal = false; *) The Smarty 3 API is a bit different. Many Smarty 2 API calls are deprecated but still work. You will want to update your calls to Smarty 3 for maximum efficiency. There are many things that are new to Smarty 3. Here are the notable items: LEXER/PARSER ============ Smarty 3 now uses a lexing tokenizer for its parser/compiler. Basically, this means Smarty has some syntax additions that make life easier such as in-template math, shorter/intuitive function parameter options, infinite function recursion, more accurate error handling, etc. WHAT IS NEW IN SMARTY TEMPLATE SYNTAX ===================================== Smarty 3 allows expressions almost anywhere. Expressions can include PHP functions as long as they are not disabled by the security policy, object methods and properties, etc. The {math} plugin is no longer necessary but is still supported for BC. Examples: {$x+$y} will output the sum of x and y. {$foo = strlen($bar)} function in assignment {assign var=foo value= $x+$y} in attributes {$foo = myfunct( ($x+$y)*3 )} as function parameter {$foo[$x+3]} as array index Smarty tags can be used as values within other tags. Example: {$foo={counter}+3} Smarty tags can also be used inside double quoted strings. Example: {$foo="this is message {counter}"} You can define arrays within templates. Examples: {assign var=foo value=[1,2,3]} {assign var=foo value=['y'=>'yellow','b'=>'blue']} Arrays can be nested. {assign var=foo value=[1,[9,8],3]} There is a new short syntax supported for assigning variables. Example: {$foo=$bar+2} You can assign a value to a specific array element. If the variable exists but is not an array, it is converted to an array before the new values are assigned. Examples: {$foo['bar']=1} {$foo['bar']['blar']=1} You can append values to an array. If the variable exists but is not an array, it is converted to an array before the new values are assigned. Example: {$foo[]=1} You can use a PHP-like syntax for accessing array elements, as well as the original "dot" notation. Examples: {$foo[1]} normal access {$foo['bar']} {$foo['bar'][1]} {$foo[$x+$x]} index may contain any expression {$foo[$bar[1]]} nested index {$foo[section_name]} smarty section access, not array access! The original "dot" notation stays, and with improvements. Examples: {$foo.a.b.c} => $foo['a']['b']['c'] {$foo.a.$b.c} => $foo['a'][$b]['c'] with variable index {$foo.a.{$b+4}.c} => $foo['a'][$b+4]['c'] with expression as index {$foo.a.{$b.c}} => $foo['a'][$b['c']] with nested index note that { and } are used to address ambiguties when nesting the dot syntax. Variable names themselves can be variable and contain expressions. Examples: $foo normal variable $foo_{$bar} variable name containing other variable $foo_{$x+$y} variable name containing expressions $foo_{$bar}_buh_{$blar} variable name with multiple segments {$foo_{$x}} will output the variable $foo_1 if $x has a value of 1. Object method chaining is implemented. Example: {$object->method1($x)->method2($y)} {for} tag added for looping (replacement for {section} tag): {for $x=0, $y=count($foo); $x<$y; $x++} .... {/for} Any number of statements can be used separated by comma as the first inital expression at {for}. {for $x = $start to $end step $step} ... {/for}is in the SVN now . You can use also {for $x = $start to $end} ... {/for} In this case the step value will be automaticall 1 or -1 depending on the start and end values. Instead of $start and $end you can use any valid expression. Inside the loop the following special vars can be accessed: $x@iteration = number of iteration $x@total = total number of iterations $x@first = true on first iteration $x@last = true on last iteration The Smarty 2 {section} syntax is still supported. New shorter {foreach} syntax to loop over an array. Example: {foreach $myarray as $var}...{/foreach} Within the foreach loop, properties are access via: $var@key foreach $var array key $var@iteration foreach current iteration count (1,2,3...) $var@index foreach current index count (0,1,2...) $var@total foreach $var array total $var@first true on first iteration $var@last true on last iteration The Smarty 2 {foreach} tag syntax is still supported. NOTE: {$bar[foo]} still indicates a variable inside of a {section} named foo. If you want to access an array element with index foo, you must use quotes such as {$bar['foo']}, or use the dot syntax {$bar.foo}. while block tag is now implemented: {while $foo}...{/while} {while $x lt 10}...{/while} Direct access to PHP functions: Just as you can use PHP functions as modifiers directly, you can now access PHP functions directly, provided they are permitted by security settings: {time()} There is a new {function}...{/function} block tag to implement a template function. This enables reuse of code sequences like a plugin function. It can call itself recursively. Template function must be called with the new {call name=foo...} tag. Example: Template file: {function name=menu level=0} {/function} {$menu = ['item1','item2','item3' => ['item3-1','item3-2','item3-3' => ['item3-3-1','item3-3-2']],'item4']} {call name=menu data=$menu} Generated output: * item1 * item2 * item3 o item3-1 o item3-2 o item3-3 + item3-3-1 + item3-3-2 * item4 The function tag itself must have the "name" attribute. This name is the tag name when calling the function. The function tag may have any number of additional attributes. These will be default settings for local variables. New {nocache} block function: {nocache}...{/nocache} will declare a section of the template to be non-cached when template caching is enabled. New nocache attribute: You can declare variable/function output as non-cached with the nocache attribute. Examples: {$foo nocache=true} {$foo nocache} /* same */ {foo bar="baz" nocache=true} {foo bar="baz" nocache} /* same */ {time() nocache=true} {time() nocache} /* same */ Or you can also assign the variable in your script as nocache: $smarty->assign('foo',$something,true); // third param is nocache setting {$foo} /* non-cached */ $smarty.current_dir returns the directory name of the current template. You can use strings directly as templates with the "string" resource type. Examples: $smarty->display('string:This is my template, {$foo}!'); // php {include file="string:This is my template, {$foo}!"} // template VARIABLE SCOPE / VARIABLE STORAGE ================================= In Smarty 2, all assigned variables were stored within the Smarty object. Therefore, all variables assigned in PHP were accessible by all subsequent fetch and display template calls. In Smarty 3, we have the choice to assign variables to the main Smarty object, to user-created data objects, and to user-created template objects. These objects can be chained. The object at the end of a chain can access all variables belonging to that template and all variables within the parent objects. The Smarty object can only be the root of a chain, but a chain can be isolated from the Smarty object. All known Smarty assignment interfaces will work on the data and template objects. Besides the above mentioned objects, there is also a special storage area for global variables. A Smarty data object can be created as follows: $data = $smarty->createData(); // create root data object $data->assign('foo','bar'); // assign variables as usual $data->config_load('my.conf'); // load config file $data= $smarty->createData($smarty); // create data object having a parent link to the Smarty object $data2= $smarty->createData($data); // create data object having a parent link to the $data data object A template object can be created by using the createTemplate method. It has the same parameter assignments as the fetch() or display() method. Function definition: function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null) The first parameter can be a template name, a smarty object or a data object. Examples: $tpl = $smarty->createTemplate('mytpl.tpl'); // create template object not linked to any parent $tpl->assign('foo','bar'); // directly assign variables $tpl->config_load('my.conf'); // load config file $tpl = $smarty->createTemplate('mytpl.tpl',$smarty); // create template having a parent link to the Smarty object $tpl = $smarty->createTemplate('mytpl.tpl',$data); // create template having a parent link to the $data object The standard fetch() and display() methods will implicitly create a template object. If the $parent parameter is not specified in these method calls, the template object is will link back to the Smarty object as it's parent. If a template is called by an {include...} tag from another template, the subtemplate links back to the calling template as it's parent. All variables assigned locally or from a parent template are accessible. If the template creates or modifies a variable by using the {assign var=foo...} or {$foo=...} tags, these new values are only known locally (local scope). When the template exits, none of the new variables or modifications can be seen in the parent template(s). This is same behavior as in Smarty 2. With Smarty 3, we can assign variables with a scope attribute which allows the availablility of these new variables or modifications globally (ie in the parent templates.) Possible scopes are local, parent, root and global. Examples: {assign var=foo value='bar'} // no scope is specified, the default 'local' {$foo='bar'} // same, local scope {assign var=foo value='bar' scope='local'} // same, local scope {assign var=foo value='bar' scope='parent'} // Values will be available to the parent object {$foo='bar' scope='parent'} // (normally the calling template) {assign var=foo value='bar' scope='root'} // Values will be exported up to the root object, so they can {$foo='bar' scope='root'} // be seen from all templates using the same root. {assign var=foo value='bar' scope='global'} // Values will be exported to global variable storage, {$foo='bar' scope='global'} // they are available to any and all templates. The scope attribute can also be attached to the {include...} tag. In this case, the specified scope will be the default scope for all assignments within the included template. PLUGINS ======= Smarty3 are following the same coding rules as in Smarty2. The only difference is that the template object is passed as additional third parameter. smarty_plugintype_name (array $params, object $smarty, object $template) The Smarty 2 plugins are still compatible as long as they do not make use of specific Smarty2 internals. TEMPLATE INHERITANCE: ===================== With template inheritance you can define blocks, which are areas that can be overriden by child templates, so your templates could look like this: parent.tpl: {block name='title'}My site name{/block}

{block name='page-title'}Default page title{/block}

{block name='content'} Default content {/block}
child.tpl: {extends file='parent.tpl'} {block name='title'} Child title {/block} grandchild.tpl: {extends file='child.tpl'} {block name='title'}Home - {$smarty.block.parent}{/block} {block name='page-title'}My home{/block} {block name='content'} {foreach $images as $img} {$img.description} {/foreach} {/block} We redefined all the blocks here, however in the title block we used {$smarty.block.parent}, which tells Smarty to insert the default content from the parent template in its place. The content block was overriden to display the image files, and page-title has also be overriden to display a completely different title. If we render grandchild.tpl we will get this: Home - Child title

My home

image image image
NOTE: In the child templates everything outside the {extends} or {block} tag sections is ignored. The inheritance tree can be as big as you want (meaning you can extend a file that extends another one that extends another one and so on..), but be aware that all files have to be checked for modifications at runtime so the more inheritance the more overhead you add. Instead of defining the parent/child relationships with the {extends} tag in the child template you can use the resource as follow: $smarty->display('extends:parent.tpl|child.tpl|grandchild.tpl'); Child {block} tags may optionally have a append or prepend attribute. In this case the parent block content is appended or prepended to the child block content. {block name='title' append} My title {/block} PHP STREAMS: ============ (see online documentation) VARIBLE FILTERS: ================ (see online documentation) STATIC CLASS ACCESS AND NAMESPACE SUPPORT ========================================= You can register a class with optional namespace for the use in the template like: $smarty->register->templateClass('foo','name\name2\myclass'); In the template you can use it like this: {foo::method()} etc. ======================= Please look through it and send any questions/suggestions/etc to the forums. http://www.phpinsider.com/smarty-forum/viewtopic.php?t=14168 Monte and Uwe Smarty-3.1.21/SMARTY_3.1_NOTES.txt0000644000000000000000000002652312420527634014701 0ustar rootrootSmarty 3.1 Notes ================ Smarty 3.1 is a departure from 2.0 compatibility. Most notably, all backward compatibility has been moved to a separate class file named SmartyBC.class.php. If you require compatibility with 2.0, you will need to use this class. Some differences from 3.0 are also present. 3.1 begins the journey of requiring setters/getters for property access. So far this is only implemented on the five directory properties: template_dir, plugins_dir, configs_dir, compile_dir and cache_dir. These properties are now protected, it is required to use the setters/getters instead. That said, direct property access will still work, however slightly slower since they will now fall through __set() and __get() and in turn passed through the setter/getter methods. 3.2 will exhibit a full list of setter/getter methods for all (currently) public properties, so code-completion in your IDE will work as expected. There is absolutely no PHP allowed in templates any more. All deprecated features of Smarty 2.0 are gone. Again, use the SmartyBC class if you need any backward compatibility. Internal Changes Full UTF-8 Compatibility The plugins shipped with Smarty 3.1 have been rewritten to fully support UTF-8 strings if Multibyte String is available. Without MBString UTF-8 cannot be handled properly. For those rare cases where templates themselves have to juggle encodings, the new modifiers to_charset and from_charset may come in handy. Plugin API and Performance All Plugins (modifiers, functions, blocks, resources, default_template_handlers, etc) are now receiving the Smarty_Internal_Template instance, where they were supplied with the Smarty instance in Smarty 3.0. *. As The Smarty_Internal_Template mimics the behavior of Smarty, this API simplification should not require any changes to custom plugins. The plugins shipped with Smarty 3.1 have been rewritten for better performance. Most notably {html_select_date} and {html_select_time} have been improved vastly. Performance aside, plugins have also been reviewed and generalized in their API. {html_select_date} and {html_select_time} now share almost all available options. The escape modifier now knows the $double_encode option, which will prevent entities from being encoded again. The capitalize modifier now know the $lc_rest option, which makes sure all letters following a captial letter are lower-cased. The count_sentences modifier now accepts (.?!) as legitimate endings of a sentence - previously only (.) was accepted The new unescape modifier is there to reverse the effects of the escape modifier. This applies to the escape formats html, htmlall and entity. default_template_handler_func The invocation of $smarty->$default_template_handler_func had to be altered. Instead of a Smarty_Internal_Template, the fifth argument is now provided with the Smarty instance. New footprint: /** * Default Template Handler * * called when Smarty's file: resource is unable to load a requested file * * @param string $type resource type (e.g. "file", "string", "eval", "resource") * @param string $name resource name (e.g. "foo/bar.tpl") * @param string &$content template's content * @param integer &$modified template's modification time * @param Smarty $smarty Smarty instance * @return string|boolean path to file or boolean true if $content and $modified * have been filled, boolean false if no default template * could be loaded */ function default_template_handler_func($type, $name, &$content, &$modified, Smarty $smarty) { if (false) { // return corrected filepath return "/tmp/some/foobar.tpl"; } elseif (false) { // return a template directly $content = "the template source"; $modified = time(); return true; } else { // tell smarty that we failed return false; } } Stuff done to the compiler Many performance improvements have happened internally. One notable improvement is that all compiled templates are now handled as PHP functions. This speeds up repeated templates tremendously, as each one calls an (in-memory) PHP function instead of performing another file include/scan. New Features Template syntax {block}..{/block} The {block} tag has a new hide option flag. It does suppress the block content if no corresponding child block exists. EXAMPLE: parent.tpl {block name=body hide} child content "{$smarty.block.child}" was inserted {block} In the above example the whole block will be suppressed if no child block "body" is existing. {setfilter}..{/setfilter} The new {setfilter} block tag allows the definition of filters which run on variable output. SYNTAX: {setfilter filter1|filter2|filter3....} Smarty3 will lookup up matching filters in the following search order: 1. varibale filter plugin in plugins_dir. 2. a valid modifier. A modifier specification will also accept additional parameter like filter2:'foo' 3. a PHP function {/setfilter} will turn previous filter setting off again. {setfilter} tags can be nested. EXAMPLE: {setfilter filter1} {$foo} {setfilter filter2} {$bar} {/setfilter} {$buh} {/setfilter} {$blar} In the above example filter1 will run on the output of $foo, filter2 on $bar, filter1 again on $buh and no filter on $blar. NOTES: - {$foo nofilter} will suppress the filters - These filters will run in addition to filters defined by registerFilter('variable',...), autoLoadFilter('variable',...) and defined default modifier. - {setfilter} will effect only the current template, not included subtemplates. Resource API Smarty 3.1 features a new approach to resource management. The Smarty_Resource API allows simple, yet powerful integration of custom resources for templates and configuration files. It offers simple functions for loading data from a custom resource (e.g. database) as well as define new template types adhering to the special non-compiling (e,g, plain php) and non-compile-caching (e.g. eval: resource type) resources. See demo/plugins/resource.mysql.php for an example custom database resource. Note that old-fashioned registration of callbacks for resource management has been deprecated but is still possible with SmartyBC. CacheResource API In line with the Resource API, the CacheResource API offers a more comfortable handling of output-cache data. With the Smarty_CacheResource_Custom accessing databases is made simple. With the introduction of Smarty_CacheResource_KeyValueStore the implementation of resources like memcache or APC became a no-brainer; simple hash-based storage systems are now supporting hierarchical output-caches. See demo/plugins/cacheresource.mysql.php for an example custom database CacheResource. See demo/plugins/cacheresource.memcache.php for an example custom memcache CacheResource using the KeyValueStore helper. Note that old-fashioned registration of $cache_handler is not possible anymore. As the functionality had not been ported to Smarty 3.0.x properly, it has been dropped from 3.1 completely. Locking facilities have been implemented to avoid concurrent cache generation. Enable cache locking by setting $smarty->cache_locking = true; Relative Paths in Templates (File-Resource) As of Smarty 3.1 {include file="../foo.tpl"} and {include file="./foo.tpl"} will resolve relative to the template they're in. Relative paths are available with {include file="..."} and {extends file="..."}. As $smarty->fetch('../foo.tpl') and $smarty->fetch('./foo.tpl') cannot be relative to a template, an exception is thrown. Addressing a specific $template_dir Smarty 3.1 introduces the $template_dir index notation. $smarty->fetch('[foo]bar.tpl') and {include file="[foo]bar.tpl"} require the template bar.tpl to be loaded from $template_dir['foo']; Smarty::setTemplateDir() and Smarty::addTemplateDir() offer ways to define indexes along with the actual directories. Mixing Resources in extends-Resource Taking the php extends: template resource one step further, it is now possible to mix resources within an extends: call like $smarty->fetch("extends:file:foo.tpl|db:bar.tpl"); To make eval: and string: resources available to the inheritance chain, eval:base64:TPL_STRING and eval:urlencode:TPL_STRING have been introduced. Supplying the base64 or urlencode flags will trigger decoding the TPL_STRING in with either base64_decode() or urldecode(). extends-Resource in template inheritance Template based inheritance may now inherit from php's extends: resource like {extends file="extends:foo.tpl|db:bar.tpl"}. New Smarty property escape_html $smarty->escape_html = true will autoescape all template variable output by calling htmlspecialchars({$output}, ENT_QUOTES, SMARTY_RESOURCE_CHAR_SET). NOTE: This is a compile time option. If you change the setting you must make sure that the templates get recompiled. New option at Smarty property compile_check The automatic recompilation of modified templates can now be controlled by the following settings: $smarty->compile_check = COMPILECHECK_OFF (false) - template files will not be checked $smarty->compile_check = COMPILECHECK_ON (true) - template files will always be checked $smarty->compile_check = COMPILECHECK_CACHEMISS - template files will be checked if caching is enabled and there is no existing cache file or it has expired Automatic recompilation on Smarty version change Templates will now be automatically recompiled on Smarty version changes to avoide incompatibillities in the compiled code. Compiled template checked against the current setting of the SMARTY_VERSION constant. default_config_handler_func() Analogous to the default_template_handler_func() default_config_handler_func() has been introduced. default_plugin_handler_func() An optional default_plugin_handler_func() can be defined which gets called by the compiler on tags which can't be resolved internally or by plugins. The default_plugin_handler() can map tags to plugins on the fly. New getters/setters The following setters/getters will be part of the official documentation, and will be strongly recommended. Direct property access will still work for the foreseeable future... it will be transparently routed through the setters/getters, and consequently a bit slower. array|string getTemplateDir( [string $index] ) replaces $smarty->template_dir; and $smarty->template_dir[$index]; Smarty setTemplateDir( array|string $path ) replaces $smarty->template_dir = "foo"; and $smarty->template_dir = array("foo", "bar"); Smarty addTemplateDir( array|string $path, [string $index]) replaces $smarty->template_dir[] = "bar"; and $smarty->template_dir[$index] = "bar"; array|string getConfigDir( [string $index] ) replaces $smarty->config_dir; and $smarty->config_dir[$index]; Smarty setConfigDir( array|string $path ) replaces $smarty->config_dir = "foo"; and $smarty->config_dir = array("foo", "bar"); Smarty addConfigDir( array|string $path, [string $index]) replaces $smarty->config_dir[] = "bar"; and $smarty->config_dir[$index] = "bar"; array getPluginsDir() replaces $smarty->plugins_dir; Smarty setPluginsDir( array|string $path ) replaces $smarty->plugins_dir = "foo"; Smarty addPluginsDir( array|string $path ) replaces $smarty->plugins_dir[] = "bar"; string getCompileDir() replaces $smarty->compile_dir; Smarty setCompileDir( string $path ) replaces $smarty->compile_dir = "foo"; string getCacheDir() replaces $smarty->cache_dir; Smarty setCacheDir( string $path ) replaces $smarty->cache_dir; Smarty-3.1.21/COPYING.lib0000644000000000000000000001674212420527634013372 0ustar rootroot GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.Smarty-3.1.21/change_log.txt0000664000000000000000000025403312420527712014415 0ustar rootroot ===== 3.1.22-dev ===== (xx.xx.2014) ===== 3.1.21 ===== (18.10.2014) 18.10.2014 - composer moved to github - add COMPOSER_RELEASE_NOTES 17.10.2014 - bugfix on $php_handling security and optimization of smarty_internal_parsetree (Thue Kristensen) 16.10.2014 - bugfix composer.json update 15.10.2014 - bugfix calling a new created cache file with fetch() and Smarty::CACHING_LIFETIME_SAVED multiple times did fail (forum 22350) 14.10.2014 - bugfix any tag placed within "'; } elseif ($encode == 'javascript_charcode') { $string = '' . $text . ''; for ($x = 0, $y = strlen($string); $x < $y; $x ++) { $ord[] = ord($string[$x]); } $_ret = "\n"; return $_ret; } elseif ($encode == 'hex') { preg_match('!^(.*)(\?.*)$!', $address, $match); if (!empty($match[2])) { trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING); return; } $address_encode = ''; for ($x = 0, $_length = strlen($address); $x < $_length; $x ++) { if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[$x])) { $address_encode .= '%' . bin2hex($address[$x]); } else { $address_encode .= $address[$x]; } } $text_encode = ''; for ($x = 0, $_length = strlen($text); $x < $_length; $x ++) { $text_encode .= '&#x' . bin2hex($text[$x]) . ';'; } $mailto = "mailto:"; return '' . $text_encode . ''; } else { // no encoding return '' . $text . ''; } } Smarty-3.1.21/libs/plugins/modifier.spacify.php0000664000000000000000000000137612420527634020147 0ustar rootroot * Name: spacify
* Purpose: add spaces between characters in a string * * @link http://smarty.php.net/manual/en/language.modifier.spacify.php spacify (Smarty online manual) * @author Monte Ohrt * * @param string $string input string * @param string $spacify_char string to insert between characters. * * @return string */ function smarty_modifier_spacify($string, $spacify_char = ' ') { // well… what about charsets besides latin and UTF-8? return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, - 1, PREG_SPLIT_NO_EMPTY)); } Smarty-3.1.21/libs/plugins/modifiercompiler.lower.php0000664000000000000000000000133212420527634021364 0ustar rootroot * Name: lower
* Purpose: convert string to lowercase * * @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual) * @author Monte Ohrt * @author Uwe Tews * * @param array $params parameters * * @return string with compiled code */ function smarty_modifiercompiler_lower($params) { if (Smarty::$_MBSTRING) { return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; } // no MBString fallback return 'strtolower(' . $params[0] . ')'; } Smarty-3.1.21/libs/plugins/function.math.php0000664000000000000000000000557312420527634017474 0ustar rootroot * Name: math
* Purpose: handle math computations in template * * @link http://www.smarty.net/manual/en/language.function.math.php {math} * (Smarty online manual) * @author Monte Ohrt * * @param array $params parameters * @param Smarty_Internal_Template $template template object * * @return string|null */ function smarty_function_math($params, $template) { static $_allowed_funcs = array( 'int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true, 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true, 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true ); // be sure equation parameter is present if (empty($params['equation'])) { trigger_error("math: missing equation parameter", E_USER_WARNING); return; } $equation = $params['equation']; // make sure parenthesis are balanced if (substr_count($equation, "(") != substr_count($equation, ")")) { trigger_error("math: unbalanced parenthesis", E_USER_WARNING); return; } // match all vars in equation, make sure all are passed preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match); foreach ($match[1] as $curr_var) { if ($curr_var && !isset($params[$curr_var]) && !isset($_allowed_funcs[$curr_var])) { trigger_error("math: function call $curr_var not allowed", E_USER_WARNING); return; } } foreach ($params as $key => $val) { if ($key != "equation" && $key != "format" && $key != "assign") { // make sure value is not empty if (strlen($val) == 0) { trigger_error("math: parameter $key is empty", E_USER_WARNING); return; } if (!is_numeric($val)) { trigger_error("math: parameter $key: is not numeric", E_USER_WARNING); return; } $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation); } } $smarty_math_result = null; eval("\$smarty_math_result = " . $equation . ";"); if (empty($params['format'])) { if (empty($params['assign'])) { return $smarty_math_result; } else { $template->assign($params['assign'], $smarty_math_result); } } else { if (empty($params['assign'])) { printf($params['format'], $smarty_math_result); } else { $template->assign($params['assign'], sprintf($params['format'], $smarty_math_result)); } } } Smarty-3.1.21/libs/plugins/shared.mb_str_replace.php0000664000000000000000000000334312420527634021136 0ustar rootroot * Name: noprint
* Purpose: return an empty string * * @author Uwe Tews * @return string with compiled code */ function smarty_modifiercompiler_noprint() { return "''"; } Smarty-3.1.21/libs/plugins/function.html_options.php0000664000000000000000000001575212420527634021262 0ustar rootroot * Name: html_options
* Purpose: Prints the list of