From 4f7cd8f1b3e29b108d6eee28e912149f8d8ad893 Mon Sep 17 00:00:00 2001 From: uwetews Date: Fri, 31 Aug 2018 16:45:09 +0200 Subject: [PATCH] - reformating for PSR-2 coding standards https://github.com/smarty-php/smarty/pull/483 --- change_log.txt | 4 +- demo/index.php | 23 +- demo/plugins/cacheresource.apc.php | 3 - demo/plugins/cacheresource.memcache.php | 6 +- demo/plugins/cacheresource.mysql.php | 40 ++- demo/plugins/cacheresource.pdo.php | 160 +++++---- demo/plugins/cacheresource.pdo_gzip.php | 33 +- demo/plugins/resource.extendsall.php | 9 +- demo/plugins/resource.mysql.php | 29 +- demo/plugins/resource.mysqls.php | 19 +- libs/Autoloader.php | 2 +- libs/Smarty.class.php | 36 +- libs/SmartyBC.class.php | 12 +- libs/bootstrap.php | 5 +- libs/debug.tpl | 6 +- libs/plugins/block.textformat.php | 20 +- libs/plugins/function.counter.php | 15 +- libs/plugins/function.cycle.php | 20 +- libs/plugins/function.html_checkboxes.php | 31 +- libs/plugins/function.html_image.php | 20 +- libs/plugins/function.html_options.php | 9 +- libs/plugins/function.html_radios.php | 31 +- libs/plugins/function.html_select_date.php | 38 ++- libs/plugins/function.html_select_time.php | 42 ++- libs/plugins/function.mailto.php | 1 + libs/plugins/function.math.php | 45 +-- libs/plugins/modifier.capitalize.php | 31 +- libs/plugins/modifier.date_format.php | 34 +- libs/plugins/modifier.debug_print_var.php | 20 +- libs/plugins/modifier.escape.php | 76 +++-- libs/plugins/modifier.mb_wordwrap.php | 7 +- libs/plugins/modifier.regex_replace.php | 7 +- libs/plugins/modifier.replace.php | 4 +- libs/plugins/modifier.spacify.php | 3 +- libs/plugins/modifier.truncate.php | 14 +- libs/plugins/modifiercompiler.cat.php | 1 - .../modifiercompiler.count_characters.php | 4 +- .../modifiercompiler.count_paragraphs.php | 1 - .../modifiercompiler.count_sentences.php | 1 - libs/plugins/modifiercompiler.count_words.php | 1 - libs/plugins/modifiercompiler.default.php | 3 - libs/plugins/modifiercompiler.escape.php | 13 +- .../plugins/modifiercompiler.from_charset.php | 3 - libs/plugins/modifiercompiler.indent.php | 3 - libs/plugins/modifiercompiler.lower.php | 2 - libs/plugins/modifiercompiler.noprint.php | 1 - .../modifiercompiler.string_format.php | 1 - libs/plugins/modifiercompiler.strip.php | 3 - libs/plugins/modifiercompiler.strip_tags.php | 1 - libs/plugins/modifiercompiler.to_charset.php | 3 - libs/plugins/modifiercompiler.upper.php | 1 - libs/plugins/modifiercompiler.wordwrap.php | 2 +- libs/plugins/outputfilter.trimwhitespace.php | 32 +- libs/plugins/shared.escape_special_chars.php | 2 - .../plugins/shared.literal_compiler_param.php | 3 - libs/plugins/shared.make_timestamp.php | 20 +- libs/plugins/shared.mb_unicode.php | 9 +- .../variablefilter.htmlspecialchars.php | 2 +- libs/sysplugins/smarty_cacheresource.php | 12 +- .../smarty_cacheresource_custom.php | 39 ++- .../smarty_cacheresource_keyvaluestore.php | 79 +++-- libs/sysplugins/smarty_data.php | 4 +- .../smarty_internal_cacheresource_file.php | 30 +- .../smarty_internal_compile_assign.php | 10 +- .../smarty_internal_compile_block.php | 17 +- .../smarty_internal_compile_block_child.php | 2 +- .../smarty_internal_compile_block_parent.php | 2 +- .../smarty_internal_compile_break.php | 10 +- .../smarty_internal_compile_capture.php | 23 +- .../smarty_internal_compile_child.php | 8 +- .../smarty_internal_compile_config_load.php | 14 +- .../smarty_internal_compile_debug.php | 2 - .../smarty_internal_compile_eval.php | 5 +- .../smarty_internal_compile_extends.php | 15 +- .../smarty_internal_compile_for.php | 10 +- .../smarty_internal_compile_foreach.php | 17 +- .../smarty_internal_compile_function.php | 18 +- .../sysplugins/smarty_internal_compile_if.php | 20 +- .../smarty_internal_compile_include.php | 27 +- .../smarty_internal_compile_include_php.php | 5 +- .../smarty_internal_compile_insert.php | 2 + .../smarty_internal_compile_nocache.php | 2 - .../smarty_internal_compile_parent.php | 3 +- ..._internal_compile_private_block_plugin.php | 23 +- ...nternal_compile_private_foreachsection.php | 14 +- ...ternal_compile_private_function_plugin.php | 10 +- ..._compile_private_object_block_function.php | 2 +- ...ternal_compile_private_object_function.php | 3 +- .../smarty_internal_compile_private_php.php | 29 +- ...ernal_compile_private_print_expression.php | 36 +- ...ernal_compile_private_registered_block.php | 2 +- ...al_compile_private_registered_function.php | 13 +- ...ernal_compile_private_special_variable.php | 10 +- .../smarty_internal_compile_section.php | 55 ++-- .../smarty_internal_compile_setfilter.php | 2 - ...ty_internal_compile_shared_inheritance.php | 7 +- .../smarty_internal_compile_while.php | 10 +- .../smarty_internal_compilebase.php | 14 +- .../smarty_internal_config_file_compiler.php | 21 +- .../smarty_internal_configfilelexer.php | 82 +++-- .../smarty_internal_configfileparser.php | 69 ++-- libs/sysplugins/smarty_internal_data.php | 12 +- libs/sysplugins/smarty_internal_debug.php | 24 +- .../smarty_internal_errorhandler.php | 11 +- .../smarty_internal_extension_handler.php | 63 ++-- ...rty_internal_method_addautoloadfilters.php | 10 +- .../smarty_internal_method_append.php | 4 +- .../smarty_internal_method_appendbyref.php | 1 - .../smarty_internal_method_assignbyref.php | 6 +- .../smarty_internal_method_assignglobal.php | 3 +- .../smarty_internal_method_clearallassign.php | 1 - .../smarty_internal_method_clearassign.php | 1 - .../smarty_internal_method_clearcache.php | 7 +- ..._internal_method_clearcompiledtemplate.php | 33 +- ...marty_internal_method_compileallconfig.php | 7 +- ...ty_internal_method_compilealltemplates.php | 15 +- .../smarty_internal_method_configload.php | 11 +- ...arty_internal_method_getconfigvariable.php | 2 +- .../smarty_internal_method_getglobal.php | 2 +- ...arty_internal_method_getstreamvariable.php | 1 - ...smarty_internal_method_gettemplatevars.php | 18 +- .../smarty_internal_method_loadfilter.php | 2 +- .../smarty_internal_method_mustcompile.php | 1 - ..._internal_method_registercacheresource.php | 6 +- ..._method_registerdefaulttemplatehandler.php | 2 +- .../smarty_internal_method_registerfilter.php | 7 +- .../smarty_internal_method_registerobject.php | 15 +- .../smarty_internal_method_registerplugin.php | 10 +- ...rty_internal_method_setautoloadfilters.php | 6 +- ...ty_internal_method_setdefaultmodifiers.php | 2 +- .../smarty_internal_method_unloadfilter.php | 2 +- ...nternal_method_unregistercacheresource.php | 2 +- ...marty_internal_method_unregisterfilter.php | 4 +- .../smarty_internal_nocache_insert.php | 1 - libs/sysplugins/smarty_internal_parsetree.php | 4 - .../smarty_internal_parsetree_dq.php | 6 +- .../smarty_internal_parsetree_tag.php | 2 - .../smarty_internal_parsetree_template.php | 16 +- .../smarty_internal_resource_eval.php | 1 - .../smarty_internal_resource_extends.php | 2 - .../smarty_internal_resource_file.php | 182 +++++------ .../smarty_internal_resource_php.php | 14 +- .../smarty_internal_resource_registered.php | 4 +- .../smarty_internal_resource_stream.php | 1 - .../smarty_internal_resource_string.php | 2 - ...rty_internal_runtime_cacheresourcefile.php | 7 +- .../smarty_internal_runtime_capture.php | 31 +- .../smarty_internal_runtime_codeframe.php | 7 +- .../smarty_internal_runtime_filterhandler.php | 2 +- .../smarty_internal_runtime_foreach.php | 34 +- ...smarty_internal_runtime_getincludepath.php | 10 +- .../smarty_internal_runtime_inheritance.php | 16 +- .../smarty_internal_runtime_make_nocache.php | 3 +- .../smarty_internal_runtime_tplfunction.php | 20 +- .../smarty_internal_runtime_updatecache.php | 15 +- .../smarty_internal_runtime_updatescope.php | 14 +- .../smarty_internal_runtime_writefile.php | 1 + ...smarty_internal_smartytemplatecompiler.php | 17 +- libs/sysplugins/smarty_internal_template.php | 52 +-- .../smarty_internal_templatebase.php | 23 +- .../smarty_internal_templatecompilerbase.php | 279 ++++++++++------ .../smarty_internal_templatelexer.php | 37 ++- .../smarty_internal_templateparser.php | 95 ++++-- .../smarty_internal_testinstall.php | 308 +++++++++--------- libs/sysplugins/smarty_internal_undefined.php | 1 - libs/sysplugins/smarty_resource.php | 33 +- libs/sysplugins/smarty_resource_custom.php | 2 - .../sysplugins/smarty_resource_recompiled.php | 3 +- libs/sysplugins/smarty_security.php | 84 +++-- libs/sysplugins/smarty_template_cached.php | 10 +- libs/sysplugins/smarty_template_compiled.php | 7 +- libs/sysplugins/smarty_template_config.php | 6 +- .../smarty_template_resource_base.php | 5 +- libs/sysplugins/smarty_template_source.php | 4 +- libs/sysplugins/smarty_undefined_variable.php | 2 +- libs/sysplugins/smarty_variable.php | 3 +- utilities/BuildExpectedFiles.php | 1 - 177 files changed, 1905 insertions(+), 1498 deletions(-) diff --git a/change_log.txt b/change_log.txt index b7d7d6c6..7bdf5f05 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,5 +1,7 @@ -===== 3.1.33-dev-9 ===== +===== 3.1.33-dev-10 ===== 31.08.2018 + - reformating for PSR-2 coding standards https://github.com/smarty-php/smarty/pull/483 + - bugfix on Windows absolute filepathes did fail if the drive letter was followed by a linux DIRECTORY_SEPARATOR like C:/ at Smarty > 3.1.33-dev-5 https://github.com/smarty-php/smarty/issues/451 diff --git a/demo/index.php b/demo/index.php index 9db5ce03..3aed3716 100644 --- a/demo/index.php +++ b/demo/index.php @@ -4,31 +4,32 @@ * * @package Example-application */ - require '../libs/Smarty.class.php'; - $smarty = new Smarty; - //$smarty->force_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")) + "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")) + "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'); diff --git a/demo/plugins/cacheresource.apc.php b/demo/plugins/cacheresource.apc.php index dad9abaa..7867cc59 100644 --- a/demo/plugins/cacheresource.apc.php +++ b/demo/plugins/cacheresource.apc.php @@ -39,7 +39,6 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore foreach ($res as $k => $v) { $_res[ $k ] = $v; } - return $_res; } @@ -56,7 +55,6 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore foreach ($keys as $k => $v) { apc_store($k, $v, $expire); } - return true; } @@ -72,7 +70,6 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore foreach ($keys as $k) { apc_delete($k); } - return true; } diff --git a/demo/plugins/cacheresource.memcache.php b/demo/plugins/cacheresource.memcache.php index 4a4313ef..9c8855c3 100644 --- a/demo/plugins/cacheresource.memcache.php +++ b/demo/plugins/cacheresource.memcache.php @@ -19,6 +19,9 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore */ protected $memcache = null; + /** + * Smarty_CacheResource_Memcache constructor. + */ public function __construct() { if (class_exists('Memcached')) { @@ -50,7 +53,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore foreach ($res as $k => $v) { $_res[ $lookup[ $k ] ] = $v; } - return $_res; } @@ -68,7 +70,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore $k = sha1($k); $this->memcache->set($k, $v, 0, $expire); } - return true; } @@ -85,7 +86,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore $k = sha1($k); $this->memcache->delete($k); } - return true; } diff --git a/demo/plugins/cacheresource.mysql.php b/demo/plugins/cacheresource.mysql.php index 208ea435..c5037eb1 100644 --- a/demo/plugins/cacheresource.mysql.php +++ b/demo/plugins/cacheresource.mysql.php @@ -24,13 +24,24 @@ */ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom { - // PDO instance + /** + * @var \PDO + */ protected $db; + /** + * @var \PDOStatement + */ protected $fetch; + /** + * @var \PDOStatement + */ protected $fetchTimestamp; + /** + * @var \PDOStatement + */ protected $save; /** @@ -42,8 +53,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); - } - catch (PDOException $e) { + } 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'); @@ -83,7 +93,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom /** * 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. + * @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 @@ -97,7 +108,6 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom $this->fetchTimestamp->execute(array('id' => $id)); $mtime = strtotime($this->fetchTimestamp->fetchColumn()); $this->fetchTimestamp->closeCursor(); - return $mtime; } @@ -116,10 +126,12 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom 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,) + array('id' => $id, + 'name' => $name, + 'cache_id' => $cache_id, + 'compile_id' => $compile_id, + 'content' => $content,) ); - return !!$this->save->rowCount(); } @@ -139,8 +151,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom 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; + return -1; } // build the filter $where = array(); @@ -158,12 +169,15 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom } // 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 . '|%') . ')'; + $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(); } } diff --git a/demo/plugins/cacheresource.pdo.php b/demo/plugins/cacheresource.pdo.php index 58ffb557..a80cd698 100644 --- a/demo/plugins/cacheresource.pdo.php +++ b/demo/plugins/cacheresource.pdo.php @@ -29,7 +29,10 @@ */ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom { - protected $fetchStatements = Array('default' => 'SELECT %2$s + /** + * @var string[] + */ + protected $fetchStatements = array('default' => 'SELECT %2$s FROM %1$s WHERE 1 AND id = :id @@ -53,6 +56,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom AND id = :id AND cache_id = :cache_id AND compile_id = :compile_id'); + + /** + * @var string + */ protected $insertStatement = 'INSERT INTO %s SET id = :id, @@ -70,25 +77,48 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom modified = CURRENT_TIMESTAMP, expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND), content = :content'; - protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s'; - protected $truncateStatement = 'TRUNCATE TABLE %s'; - protected $fetchColumns = 'modified, content'; - protected $fetchTimestampColumns = 'modified'; - protected $pdo, $table, $database; - /* - * Constructor - * - * @param PDO $pdo PDO : active connection - * @param string $table : table (or view) name - * @param string $database : optional - if table is located in another db - */ /** - * Smarty_CacheResource_Pdo constructor. + * @var string + */ + protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s'; + + /** + * @var string + */ + protected $truncateStatement = 'TRUNCATE TABLE %s'; + + /** + * @var string + */ + protected $fetchColumns = 'modified, content'; + + /** + * @var string + */ + protected $fetchTimestampColumns = 'modified'; + + /** + * @var \PDO + */ + protected $pdo; + + /** + * @var + */ + protected $table; + + /** + * @var null + */ + protected $database; + + /** + * Constructor * - * @param \PDO $pdo - * @param $table - * @param null $database + * @param PDO $pdo PDO : active connection + * @param string $table : table (or view) name + * @param string $database : optional - if table is located in another db * * @throws \SmartyException */ @@ -103,15 +133,15 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom $this->fillStatementsWithTableName(); } - /* - * Fills the table name into the statements. - * - * @return Current Instance - * @access protected + /** + * Fills the table name into the statements. + * + * @return $this Current Instance + * @access protected */ protected function fillStatementsWithTableName() { - foreach ($this->fetchStatements AS &$statement) { + foreach ($this->fetchStatements as &$statement) { $statement = sprintf($statement, $this->getTableName(), '%s'); } $this->insertStatement = sprintf($this->insertStatement, $this->getTableName()); @@ -120,31 +150,34 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom return $this; } - /* - * Gets the fetch statement, depending on what you specify - * - * @param string $columns : the column(s) name(s) you want to retrieve from the database - * @param string $id unique cache content identifier - * @param string|null $cache_id cache id - * @param string|null $compile_id compile id - * @access protected + /** + * Gets the fetch statement, depending on what you specify + * + * @param string $columns : the column(s) name(s) you want to retrieve from the database + * @param string $id unique cache content identifier + * @param string|null $cache_id cache id + * @param string|null $compile_id compile id + * + * @access protected + * @return \PDOStatement */ protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null) { + $args = array(); if (!is_null($cache_id) && !is_null($compile_id)) { - $query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] AND - $args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id); + $query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] and + $args = array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id); } elseif (is_null($cache_id) && !is_null($compile_id)) { - $query = $this->fetchStatements[ 'withCompileId' ] AND - $args = Array('id' => $id, 'compile_id' => $compile_id); + $query = $this->fetchStatements[ 'withCompileId' ] and + $args = array('id' => $id, 'compile_id' => $compile_id); } elseif (!is_null($cache_id) && is_null($compile_id)) { - $query = $this->fetchStatements[ 'withCacheId' ] AND $args = Array('id' => $id, 'cache_id' => $cache_id); + $query = $this->fetchStatements[ 'withCacheId' ] and $args = array('id' => $id, 'cache_id' => $cache_id); } else { - $query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id); + $query = $this->fetchStatements[ 'default' ] and $args = array('id' => $id); } $query = sprintf($query, $columns); $stmt = $this->pdo->prepare($query); - foreach ($args AS $key => $value) { + foreach ($args as $key => $value) { $stmt->bindValue($key, $value); } return $stmt; @@ -224,24 +257,26 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom return !!$stmt->rowCount(); } - /* - * Encodes the content before saving to database - * - * @param string $content - * @return string $content - * @access protected + /** + * Encodes the content before saving to database + * + * @param string $content + * + * @return string $content + * @access protected */ protected function inputContent($content) { return $content; } - /* - * Decodes the content before saving to database - * - * @param string $content - * @return string $content - * @access protected + /** + * Decodes the content before saving to database + * + * @param string $content + * + * @return string $content + * @access protected */ protected function outputContent($content) { @@ -254,7 +289,7 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom * @param string|null $name template name * @param string|null $cache_id cache id * @param string|null $compile_id compile id - * @param integer|null|-1 $exp_time seconds till expiration or null + * @param integer|null|-1 $exp_time seconds till expiration or null * * @return integer number of deleted caches * @access protected @@ -263,33 +298,37 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom { // 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 + // returning the number of deleted caches would require a second query to count them $this->pdo->query($this->truncateStatement); return -1; } - // build the filter + // build the filter $where = array(); - // equal test name + // equal test name if ($name !== null) { $where[] = 'name = ' . $this->pdo->quote($name); } - // equal test cache_id and match sub-groups + // equal test cache_id and match sub-groups if ($cache_id !== null) { - $where[] = '(cache_id = ' . $this->pdo->quote($cache_id) . ' OR cache_id LIKE ' . - $this->pdo->quote($cache_id . '|%') . ')'; + $where[] = + '(cache_id = ' . + $this->pdo->quote($cache_id) . + ' OR cache_id LIKE ' . + $this->pdo->quote($cache_id . '|%') . + ')'; } - // equal test compile_id + // equal test compile_id if ($compile_id !== null) { $where[] = 'compile_id = ' . $this->pdo->quote($compile_id); } - // for clearing expired caches + // for clearing expired caches if ($exp_time === Smarty::CLEAR_EXPIRED) { $where[] = 'expire < CURRENT_TIMESTAMP'; } // range test expiration time elseif ($exp_time !== null) { $where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)'; } - // run delete query + // run delete query $query = $this->pdo->query(sprintf($this->deleteStatement, join(' AND ', $where))); return $query->rowCount(); } @@ -305,4 +344,3 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom return (is_null($this->database)) ? "`{$this->table}`" : "`{$this->database}`.`{$this->table}`"; } } - diff --git a/demo/plugins/cacheresource.pdo_gzip.php b/demo/plugins/cacheresource.pdo_gzip.php index 72427c4c..5560b9e3 100644 --- a/demo/plugins/cacheresource.pdo_gzip.php +++ b/demo/plugins/cacheresource.pdo_gzip.php @@ -1,4 +1,5 @@ uid ] = $s; $uid .= $s->filepath; $timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp; - } - catch (SmartyException $e) { + } catch (SmartyException $e) { } } if (!$sources) { $source->exists = false; return; } - $sources = array_reverse($sources, true); reset($sources); $s = current($sources); @@ -51,15 +49,14 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends $source->timestamp = $timestamp; } - /* + /** * Disable timestamp checks for extendsall resource. * The individual source components will be checked. * - * @return bool + * @return bool false */ public function checkTimestamps() { return false; } - } diff --git a/demo/plugins/resource.mysql.php b/demo/plugins/resource.mysql.php index 0c250b46..95a3c2ba 100644 --- a/demo/plugins/resource.mysql.php +++ b/demo/plugins/resource.mysql.php @@ -12,20 +12,34 @@ * 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}');
+ *
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 + /** + * PDO instance + * + * @var \PDO + */ protected $db; - // prepared fetch() statement + /** + * prepared fetch() statement + * + * @var \PDOStatement + */ protected $fetch; - // prepared fetchTimestamp() statement + /** + * prepared fetchTimestamp() statement + * + * @var \PDOStatement + */ protected $mtime; /** @@ -37,8 +51,7 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); - } - catch (PDOException $e) { + } catch (PDOException $e) { throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); } $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); @@ -71,7 +84,8 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom /** * 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. + * @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 * @@ -82,7 +96,6 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom $this->mtime->execute(array('name' => $name)); $mtime = $this->mtime->fetchColumn(); $this->mtime->closeCursor(); - return strtotime($mtime); } } diff --git a/demo/plugins/resource.mysqls.php b/demo/plugins/resource.mysqls.php index c15b9ecb..148a8dd6 100644 --- a/demo/plugins/resource.mysqls.php +++ b/demo/plugins/resource.mysqls.php @@ -14,17 +14,27 @@ * 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}');
+ *
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 + /** + * PDO instance + * + * @var \PDO + */ protected $db; - // prepared fetch() statement + /** + * prepared fetch() statement + * + * @var \PDOStatement + */ protected $fetch; /** @@ -36,8 +46,7 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom { try { $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); - } - catch (PDOException $e) { + } catch (PDOException $e) { throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); } $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); diff --git a/libs/Autoloader.php b/libs/Autoloader.php index c3186750..e4dc450f 100644 --- a/libs/Autoloader.php +++ b/libs/Autoloader.php @@ -54,7 +54,7 @@ class Smarty_Autoloader if (!defined('SMARTY_SPL_AUTOLOAD')) { define('SMARTY_SPL_AUTOLOAD', 0); } - if (SMARTY_SPL_AUTOLOAD + if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false ) { $registeredAutoLoadFunctions = spl_autoload_functions(); diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 137c9ca0..2b38e4ce 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.33-dev-9'; + const SMARTY_VERSION = '3.1.33-dev-10'; /** * define variable scopes */ @@ -650,18 +650,22 @@ class Smarty extends Smarty_Internal_TemplateBase * * @var string[] */ - protected $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security', - '_dir_perms', '_file_perms', 'plugin_search_order', - 'inheritance_merge_compiled_includes', 'resource_cache_mode',); + protected $obsoleteProperties = array( + 'resource_caching', 'template_resource_caching', 'direct_access_security', + '_dir_perms', '_file_perms', 'plugin_search_order', + 'inheritance_merge_compiled_includes', 'resource_cache_mode', + ); /** * List of private properties which will call getter/setter on a direct access * * @var string[] */ - protected $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', - 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', - 'cache_dir' => 'CacheDir',); + protected $accessMap = array( + 'template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', + 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', + 'cache_dir' => 'CacheDir', + ); /** * Initialize new Smarty object @@ -1074,13 +1078,13 @@ class Smarty extends Smarty_Internal_TemplateBase * @return string * @throws \SmartyException */ - public function _getTemplateId($template_name, - $cache_id = null, - $compile_id = null, - $caching = null, - Smarty_Internal_Template $template = null - ) - { + public function _getTemplateId( + $template_name, + $cache_id = null, + $compile_id = null, + $caching = null, + Smarty_Internal_Template $template = null + ) { $template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" : $template_name; $cache_id = $cache_id === null ? $this->cache_id : $cache_id; @@ -1129,8 +1133,8 @@ class Smarty extends Smarty_Internal_TemplateBase } } // normalize DIRECTORY_SEPARATOR - $path = str_replace($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR, $path); - $parts[ 'root' ] = str_replace($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR, $parts[ 'root' ]); + $path = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $path); + $parts[ 'root' ] = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $parts[ 'root' ]); do { $path = preg_replace( array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'), diff --git a/libs/SmartyBC.class.php b/libs/SmartyBC.class.php index 1141e488..836f9815 100644 --- a/libs/SmartyBC.class.php +++ b/libs/SmartyBC.class.php @@ -129,7 +129,11 @@ class SmartyBC extends Smarty * @throws SmartyException * @internal param array $block_functs list of methods that are block format */ - public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, + public function register_object( + $object, + $object_impl, + $allowed = array(), + $smarty_args = true, $block_methods = array() ) { settype($allowed, 'array'); @@ -150,8 +154,8 @@ class SmartyBC extends Smarty /** * Registers block function to be used in templates * - * @param string $block name of template block - * @param string $block_impl PHP function to register + * @param string $block name of template block + * @param string $block_impl PHP function to register * @param bool $cacheable * @param mixed $cache_attrs * @@ -352,7 +356,7 @@ class SmartyBC extends Smarty /** * test to see if valid cache exists for this template * - * @param string $tpl_file name of template file + * @param string $tpl_file name of template file * @param string $cache_id * @param string $compile_id * diff --git a/libs/bootstrap.php b/libs/bootstrap.php index 0b183bf9..2c830468 100644 --- a/libs/bootstrap.php +++ b/libs/bootstrap.php @@ -1,5 +1,5 @@ @@ -7,8 +7,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - -/* +/** * Load and register Smarty Autoloader */ if (!class_exists('Smarty_Autoloader')) { diff --git a/libs/debug.tpl b/libs/debug.tpl index 966376fc..edc7bef9 100644 --- a/libs/debug.tpl +++ b/libs/debug.tpl @@ -113,10 +113,10 @@
{foreach $template_data as $template} {$template.name} -
   +
   (compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}) -
+
{/foreach}
{/if} @@ -127,7 +127,7 @@ {foreach $assigned_vars as $vars}

${$vars@key}

- {if isset($vars['nocache'])}Nocache
{/if} + {if isset($vars['nocache'])}Nocache
{/if} {if isset($vars['scope'])}Origin: {$vars['scope']|debug_print_var nofilter}{/if}

Value

{$vars['value']|debug_print_var:10:80 nofilter} diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php index 93ae076f..5e494637 100644 --- a/libs/plugins/block.textformat.php +++ b/libs/plugins/block.textformat.php @@ -39,8 +39,12 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te } if (Smarty::$_MBSTRING) { $template->_checkPlugins( - array(array('function' => 'smarty_modifier_mb_wordwrap', - 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php')) + array( + array( + 'function' => 'smarty_modifier_mb_wordwrap', + 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php' + ) + ) ); } $style = null; @@ -83,10 +87,14 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te // convert mult. spaces & special chars to single space $_paragraph = preg_replace( - array('!\s+!' . Smarty::$_UTF8_MODIFIER, - '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), - array(' ', - ''), + array( + '!\s+!' . Smarty::$_UTF8_MODIFIER, + '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER + ), + array( + ' ', + '' + ), $_paragraph ); // indent first line diff --git a/libs/plugins/function.counter.php b/libs/plugins/function.counter.php index 9610362d..a4129e77 100644 --- a/libs/plugins/function.counter.php +++ b/libs/plugins/function.counter.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {counter} function plugin * Type: function @@ -24,50 +23,40 @@ function smarty_function_counter($params, $template) { static $counters = array(); - $name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default'; if (!isset($counters[ $name ])) { $counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1); } $counter =& $counters[ $name ]; - if (isset($params[ 'start' ])) { - $counter[ 'start' ] = $counter[ 'count' ] = (int) $params[ 'start' ]; + $counter[ 'start' ] = $counter[ 'count' ] = (int)$params[ 'start' ]; } - if (!empty($params[ 'assign' ])) { $counter[ 'assign' ] = $params[ 'assign' ]; } - if (isset($counter[ 'assign' ])) { $template->assign($counter[ 'assign' ], $counter[ 'count' ]); } - if (isset($params[ 'print' ])) { - $print = (bool) $params[ 'print' ]; + $print = (bool)$params[ 'print' ]; } else { $print = empty($counter[ 'assign' ]); } - if ($print) { $retval = $counter[ 'count' ]; } else { $retval = null; } - if (isset($params[ 'skip' ])) { $counter[ 'skip' ] = $params[ 'skip' ]; } - if (isset($params[ 'direction' ])) { $counter[ 'direction' ] = $params[ 'direction' ]; } - if ($counter[ 'direction' ] === 'down') { $counter[ 'count' ] -= $counter[ 'skip' ]; } else { $counter[ 'count' ] += $counter[ 'skip' ]; } - return $retval; } diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php index 692f7033..07ffcc5e 100644 --- a/libs/plugins/function.cycle.php +++ b/libs/plugins/function.cycle.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {cycle} function plugin * Type: function @@ -42,20 +41,16 @@ * * @return string|null */ - function smarty_function_cycle($params, $template) { static $cycle_vars; - $name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ]; - $print = (isset($params[ 'print' ])) ? (bool) $params[ 'print' ] : true; - $advance = (isset($params[ 'advance' ])) ? (bool) $params[ 'advance' ] : true; - $reset = (isset($params[ 'reset' ])) ? (bool) $params[ 'reset' ] : false; - + $print = (isset($params[ 'print' ])) ? (bool)$params[ 'print' ] : true; + $advance = (isset($params[ 'advance' ])) ? (bool)$params[ 'advance' ] : true; + $reset = (isset($params[ 'reset' ])) ? (bool)$params[ 'reset' ] : false; if (!isset($params[ 'values' ])) { if (!isset($cycle_vars[ $name ][ 'values' ])) { trigger_error('cycle: missing \'values\' parameter'); - return; } } else { @@ -64,41 +59,34 @@ function smarty_function_cycle($params, $template) } $cycle_vars[ $name ][ 'values' ] = $params[ 'values' ]; } - if (isset($params[ 'delimiter' ])) { $cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ]; } elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) { $cycle_vars[ $name ][ 'delimiter' ] = ','; } - if (is_array($cycle_vars[ $name ][ 'values' ])) { $cycle_array = $cycle_vars[ $name ][ 'values' ]; } else { $cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]); } - if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) { $cycle_vars[ $name ][ 'index' ] = 0; } - if (isset($params[ 'assign' ])) { $print = false; $template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]); } - if ($print) { $retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]; } else { $retval = null; } - if ($advance) { if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) { $cycle_vars[ $name ][ 'index' ] = 0; } else { - $cycle_vars[ $name ][ 'index' ] ++; + $cycle_vars[ $name ][ 'index' ]++; } } - return $retval; } diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index 9a1f9c89..302358ed 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -45,8 +45,12 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template) { $template->_checkPlugins( - array(array('function' => 'smarty_function_escape_special_chars', - 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) + array( + array( + 'function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' + ) + ) ); $name = 'checkbox'; $values = null; @@ -137,6 +141,7 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp break; } // omit break; to fall through! + // no break default: if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; @@ -202,17 +207,17 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp * * @return string */ -function smarty_function_html_checkboxes_output($name, - $value, - $output, - $selected, - $extra, - $separator, - $labels, - $label_ids, - $escape = true -) -{ +function smarty_function_html_checkboxes_output( + $name, + $value, + $output, + $selected, + $extra, + $separator, + $labels, + $label_ids, + $escape = true +) { $_output = ''; if (is_object($value)) { if (method_exists($value, '__toString')) { diff --git a/libs/plugins/function.html_image.php b/libs/plugins/function.html_image.php index af29a82d..ad468e4f 100644 --- a/libs/plugins/function.html_image.php +++ b/libs/plugins/function.html_image.php @@ -37,8 +37,12 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template) { $template->_checkPlugins( - array(array('function' => 'smarty_function_escape_special_chars', - 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) + array( + array( + 'function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' + ) + ) ); $alt = ''; $file = ''; @@ -63,8 +67,10 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template) if (!is_array($_val)) { $$_key = smarty_function_escape_special_chars($_val); } else { - throw new SmartyException("html_image: extra attribute '{$_key}' cannot be an array", - E_USER_NOTICE); + throw new SmartyException( + "html_image: extra attribute '{$_key}' cannot be an array", + E_USER_NOTICE + ); } break; case 'link': @@ -76,8 +82,10 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template) if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else { - throw new SmartyException("html_image: extra attribute '{$_key}' cannot be an array", - E_USER_NOTICE); + throw new SmartyException( + "html_image: extra attribute '{$_key}' cannot be an array", + E_USER_NOTICE + ); } break; } diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php index 53e82a24..6907e8ee 100644 --- a/libs/plugins/function.html_options.php +++ b/libs/plugins/function.html_options.php @@ -37,8 +37,12 @@ function smarty_function_html_options($params, Smarty_Internal_Template $template) { $template->_checkPlugins( - array(array('function' => 'smarty_function_escape_special_chars', - 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) + array( + array( + 'function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' + ) + ) ); $name = null; $values = null; @@ -113,6 +117,7 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat break; } // omit break; to fall through! + // no break default: if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; diff --git a/libs/plugins/function.html_radios.php b/libs/plugins/function.html_radios.php index 12c75bd6..5e834587 100644 --- a/libs/plugins/function.html_radios.php +++ b/libs/plugins/function.html_radios.php @@ -45,8 +45,12 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template) { $template->_checkPlugins( - array(array('function' => 'smarty_function_escape_special_chars', - 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) + array( + array( + 'function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' + ) + ) ); $name = 'radio'; $values = null; @@ -120,6 +124,7 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template break; } // omit break; to fall through! + // no break default: if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; @@ -186,17 +191,17 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template * * @return string */ -function smarty_function_html_radios_output($name, - $value, - $output, - $selected, - $extra, - $separator, - $labels, - $label_ids, - $escape -) -{ +function smarty_function_html_radios_output( + $name, + $value, + $output, + $selected, + $extra, + $separator, + $labels, + $label_ids, + $escape +) { $_output = ''; if (is_object($value)) { if (method_exists($value, '__toString')) { diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php index 87a9e8e6..86403e3d 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -45,8 +45,12 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $template) { $template->_checkPlugins( - array(array('function' => 'smarty_function_escape_special_chars', - 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) + array( + array( + 'function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' + ) + ) ); // generate timestamps used for month names only static $_month_timestamps = null; @@ -111,8 +115,12 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem case 'time': if (!is_array($_value) && $_value !== null) { $template->_checkPlugins( - array(array('function' => 'smarty_make_timestamp', - 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')) + array( + array( + 'function' => 'smarty_make_timestamp', + 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php' + ) + ) ); $time = smarty_make_timestamp($_value); } @@ -173,9 +181,11 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) { if (isset($params[ 'time' ][ $prefix . 'Year' ])) { // $_REQUEST[$field_array] given - foreach (array('Y' => 'Year', - 'm' => 'Month', - 'd' => 'Day') as $_elementKey => $_elementName) { + foreach (array( + 'Y' => 'Year', + 'm' => 'Month', + 'd' => 'Day' + ) as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); $$_variableName = isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] : @@ -183,9 +193,11 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem } } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) { // $_REQUEST given - foreach (array('Y' => 'Year', - 'm' => 'Month', - 'd' => 'Day') as $_elementKey => $_elementName) { + foreach (array( + 'Y' => 'Year', + 'm' => 'Month', + 'd' => 'Day' + ) as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey); @@ -205,8 +217,10 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem } // make syntax "+N" or "-N" work with $start_year and $end_year // Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr - foreach (array('start', - 'end') as $key) { + foreach (array( + 'start', + 'end' + ) as $key) { $key .= '_year'; $t = $$key; if ($t === null) { diff --git a/libs/plugins/function.html_select_time.php b/libs/plugins/function.html_select_time.php index 3fb6c31a..cb047bc0 100644 --- a/libs/plugins/function.html_select_time.php +++ b/libs/plugins/function.html_select_time.php @@ -27,8 +27,12 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $template) { $template->_checkPlugins( - array(array('function' => 'smarty_function_escape_special_chars', - 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) + array( + array( + 'function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' + ) + ) ); $prefix = 'Time_'; $field_array = null; @@ -73,8 +77,12 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem case 'time': if (!is_array($_value) && $_value !== null) { $template->_checkPlugins( - array(array('function' => 'smarty_make_timestamp', - 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')) + array( + array( + 'function' => 'smarty_make_timestamp', + 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php' + ) + ) ); $time = smarty_make_timestamp($_value); } @@ -133,9 +141,11 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) { if (isset($params[ 'time' ][ $prefix . 'Hour' ])) { // $_REQUEST[$field_array] given - foreach (array('H' => 'Hour', - 'i' => 'Minute', - 's' => 'Second') as $_elementKey => $_elementName) { + foreach (array( + 'H' => 'Hour', + 'i' => 'Minute', + 's' => 'Second' + ) as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); $$_variableName = isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] : @@ -148,9 +158,11 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) { // $_REQUEST given - foreach (array('H' => 'Hour', - 'i' => 'Minute', - 's' => 'Second') as $_elementKey => $_elementName) { + foreach (array( + 'H' => 'Hour', + 'i' => 'Minute', + 's' => 'Second' + ) as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey); @@ -325,10 +337,12 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem ''; } $_html = ''; - foreach (array('_html_hours', - '_html_minutes', - '_html_seconds', - '_html_meridian') as $k) { + foreach (array( + '_html_hours', + '_html_minutes', + '_html_seconds', + '_html_meridian' + ) as $k) { if (isset($$k)) { if ($_html) { $_html .= $field_separator; diff --git a/libs/plugins/function.mailto.php b/libs/plugins/function.mailto.php index 1b960846..27351df8 100644 --- a/libs/plugins/function.mailto.php +++ b/libs/plugins/function.mailto.php @@ -79,6 +79,7 @@ function smarty_function_mailto($params) case 'extra': case 'text': $$var = $value; + // no break default: } } diff --git a/libs/plugins/function.math.php b/libs/plugins/function.math.php index 111d5130..7348d964 100644 --- a/libs/plugins/function.math.php +++ b/libs/plugins/function.math.php @@ -6,7 +6,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {math} function plugin * Type: function @@ -25,66 +24,71 @@ 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); + 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; } - // disallow backticks if (strpos($equation, '`') !== false) { trigger_error("math: backtick character not allowed in equation", E_USER_WARNING); - return; } - // also disallow dollar signs if (strpos($equation, '$') !== false) { trigger_error("math: dollar signs not allowed in equation", 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; } } } - // match all vars in equation, make sure all are passed preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $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, or missing parameter '{$curr_var}'", E_USER_WARNING); - + trigger_error( + "math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", + E_USER_WARNING + ); return; } } - foreach ($params as $key => $val) { if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') { $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation); @@ -92,7 +96,6 @@ function smarty_function_math($params, $template) } $smarty_math_result = null; eval("\$smarty_math_result = " . $equation . ";"); - if (empty($params[ 'format' ])) { if (empty($params[ 'assign' ])) { return $smarty_math_result; diff --git a/libs/plugins/modifier.capitalize.php b/libs/plugins/modifier.capitalize.php index a26ff1fa..c5fc400a 100644 --- a/libs/plugins/modifier.capitalize.php +++ b/libs/plugins/modifier.capitalize.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifier */ - /** * Smarty capitalize modifier plugin * Type: modifier @@ -31,20 +30,25 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals // uppercase word breaks $upper_string = preg_replace_callback( "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, - 'smarty_mod_cap_mbconvert_cb', $string + 'smarty_mod_cap_mbconvert_cb', + $string ); } // check uc_digits case if (!$uc_digits) { if (preg_match_all( - "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, + "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, + $string, + $matches, PREG_OFFSET_CAPTURE ) ) { foreach ($matches[ 1 ] as $match) { $upper_string = substr_replace( - $upper_string, mb_strtolower($match[ 0 ], Smarty::$_CHARSET), $match[ 1 ], + $upper_string, + mb_strtolower($match[ 0 ], Smarty::$_CHARSET), + $match[ 1 ], strlen($match[ 0 ]) ); } @@ -52,12 +56,12 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals } $upper_string = preg_replace_callback( - "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb', + "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, + 'smarty_mod_cap_mbconvert2_cb', $upper_string ); return $upper_string; } - // lowercase first if ($lc_rest) { $string = strtolower($string); @@ -65,13 +69,16 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals // uppercase (including hyphenated words) $upper_string = preg_replace_callback( - "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb', + "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, + 'smarty_mod_cap_ucfirst_cb', $string ); // check uc_digits case if (!$uc_digits) { if (preg_match_all( - "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, + "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, + $string, + $matches, PREG_OFFSET_CAPTURE ) ) { @@ -82,13 +89,14 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals } } $upper_string = preg_replace_callback( - "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb', + "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, + 'smarty_mod_cap_ucfirst2_cb', $upper_string ); return $upper_string; } -/* +/** * * Bug: create_function() use exhausts memory when used in long loops * Fix: use declared functions for callbacks instead of using create_function() @@ -105,6 +113,7 @@ function smarty_mod_cap_mbconvert_cb($matches) { return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 2 ]), MB_CASE_UPPER, Smarty::$_CHARSET); } + /** * @param $matches * @@ -114,6 +123,7 @@ function smarty_mod_cap_mbconvert2_cb($matches) { return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 3 ]), MB_CASE_UPPER, Smarty::$_CHARSET); } + /** * @param $matches * @@ -123,6 +133,7 @@ function smarty_mod_cap_ucfirst_cb($matches) { return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ])); } + /** * @param $matches * diff --git a/libs/plugins/modifier.date_format.php b/libs/plugins/modifier.date_format.php index d38d8b08..23b69430 100644 --- a/libs/plugins/modifier.date_format.php +++ b/libs/plugins/modifier.date_format.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifier */ - /** * Smarty date_format modifier plugin * Type: modifier @@ -51,20 +50,24 @@ function smarty_modifier_date_format($string, $format = null, $default_date = '' } if ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) { if (Smarty::$_IS_WINDOWS) { - $_win_from = array('%D', - '%h', - '%n', - '%r', - '%R', - '%t', - '%T'); - $_win_to = array('%m/%d/%y', - '%b', - "\n", - '%I:%M:%S %p', - '%H:%M', - "\t", - '%H:%M:%S'); + $_win_from = array( + '%D', + '%h', + '%n', + '%r', + '%R', + '%t', + '%T' + ); + $_win_to = array( + '%m/%d/%y', + '%b', + "\n", + '%I:%M:%S %p', + '%H:%M', + "\t", + '%H:%M:%S' + ); if (strpos($format, '%e') !== false) { $_win_from[] = '%e'; $_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); @@ -75,7 +78,6 @@ function smarty_modifier_date_format($string, $format = null, $default_date = '' } $format = str_replace($_win_from, $_win_to, $format); } - return strftime($format, $timestamp); } else { return date($format, $timestamp); diff --git a/libs/plugins/modifier.debug_print_var.php b/libs/plugins/modifier.debug_print_var.php index 11d4eb12..78397d01 100644 --- a/libs/plugins/modifier.debug_print_var.php +++ b/libs/plugins/modifier.debug_print_var.php @@ -25,7 +25,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = { $_replace = array("\n" => '\n', "\r" => '\r', "\t" => '\t'); switch (gettype($var)) { - case 'array' : + case 'array': $results = 'Array (' . count($var) . ')'; if ($depth === $max) { break; @@ -37,7 +37,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = $depth--; } break; - case 'object' : + case 'object': $object_vars = get_object_vars($var); $results = '' . get_class($var) . ' Object (' . count($object_vars) . ')'; if (in_array($var, $objects)) { @@ -54,9 +54,9 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = $depth--; } break; - case 'boolean' : - case 'NULL' : - case 'resource' : + case 'boolean': + case 'NULL': + case 'resource': if (true === $var) { $results = 'true'; } elseif (false === $var) { @@ -68,11 +68,11 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = } $results = '' . $results . ''; break; - case 'integer' : - case 'float' : + case 'integer': + case 'float': $results = htmlspecialchars((string)$var); break; - case 'string' : + case 'string': $results = strtr($var, $_replace); if (Smarty::$_MBSTRING) { if (mb_strlen($var, Smarty::$_CHARSET) > $length) { @@ -85,8 +85,8 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = } $results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET); break; - case 'unknown type' : - default : + case 'unknown type': + default: $results = strtr((string)$var, $_replace); if (Smarty::$_MBSTRING) { if (mb_strlen($results, Smarty::$_CHARSET) > $length) { diff --git a/libs/plugins/modifier.escape.php b/libs/plugins/modifier.escape.php index 5d9586a1..150901c7 100644 --- a/libs/plugins/modifier.escape.php +++ b/libs/plugins/modifier.escape.php @@ -46,15 +46,20 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); $string = htmlspecialchars($string, ENT_QUOTES, $char_set); $string = str_replace( - array('%%%SMARTY_START%%%', - '%%%SMARTY_END%%%'), - array('&', - ';'), + array( + '%%%SMARTY_START%%%', + '%%%SMARTY_END%%%' + ), + array( + '&', + ';' + ), $string ); return $string; } } + // no break case 'htmlall': if (Smarty::$_MBSTRING) { // mb_convert_encoding ignores htmlspecialchars() @@ -71,10 +76,14 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ $string = htmlspecialchars($string, ENT_QUOTES, $char_set); $string = str_replace( - array('%%%SMARTY_START%%%', - '%%%SMARTY_END%%%'), - array('&', - ';'), + array( + '%%%SMARTY_START%%%', + '%%%SMARTY_END%%%' + ), + array( + '&', + ';' + ), $string ); return $string; @@ -93,15 +102,20 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); $string = htmlentities($string, ENT_QUOTES, $char_set); $string = str_replace( - array('%%%SMARTY_START%%%', - '%%%SMARTY_END%%%'), - array('&', - ';'), + array( + '%%%SMARTY_START%%%', + '%%%SMARTY_END%%%' + ), + array( + '&', + ';' + ), $string ); return $string; } } + // no break case 'url': return rawurlencode($string); case 'urlpathinfo': @@ -164,12 +178,14 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ // escape quotes and backslashes, newlines, etc. return strtr( $string, - array('\\' => '\\\\', - "'" => "\\'", - '"' => '\\"', - "\r" => '\\r', - "\n" => '\\n', - ' '<\/') + array( + '\\' => '\\\\', + "'" => "\\'", + '"' => '\\"', + "\r" => '\\r', + "\n" => '\\n', + ' '<\/' + ) ); case 'mail': if (Smarty::$_MBSTRING) { @@ -180,19 +196,27 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ $is_loaded_2 = true; } return smarty_mb_str_replace( - array('@', - '.'), - array(' [AT] ', - ' [DOT] '), + array( + '@', + '.' + ), + array( + ' [AT] ', + ' [DOT] ' + ), $string ); } // no MBString fallback return str_replace( - array('@', - '.'), - array(' [AT] ', - ' [DOT] '), + array( + '@', + '.' + ), + array( + ' [AT] ', + ' [DOT] ' + ), $string ); case 'nonstd': diff --git a/libs/plugins/modifier.mb_wordwrap.php b/libs/plugins/modifier.mb_wordwrap.php index b3dc6065..1cd625b6 100644 --- a/libs/plugins/modifier.mb_wordwrap.php +++ b/libs/plugins/modifier.mb_wordwrap.php @@ -11,7 +11,7 @@ * Name: mb_wordwrap * Purpose: Wrap a string to a given number of characters * - * @link http://php.net/manual/en/function.wordwrap.php for similarity + * @link http://php.net/manual/en/function.wordwrap.php for similarity * * @param string $str the string to wrap * @param int $width the width of the output @@ -29,7 +29,6 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa $t = ''; $_previous = false; $_space = false; - foreach ($tokens as $_token) { $token_length = mb_strlen($_token, Smarty::$_CHARSET); $_tokens = array($_token); @@ -43,18 +42,15 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa ); } } - foreach ($_tokens as $token) { $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token); $token_length = mb_strlen($token, Smarty::$_CHARSET); $length += $token_length; - if ($length > $width) { // remove space before inserted break if ($_previous) { $t = mb_substr($t, 0, -1, Smarty::$_CHARSET); } - if (!$_space) { // add the break before the token if (!empty($t)) { @@ -71,6 +67,5 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa $t .= $token; } } - return $t; } diff --git a/libs/plugins/modifier.regex_replace.php b/libs/plugins/modifier.regex_replace.php index 34d5b799..7eb55069 100644 --- a/libs/plugins/modifier.regex_replace.php +++ b/libs/plugins/modifier.regex_replace.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifier */ - /** * Smarty regex_replace modifier plugin * Type: modifier @@ -23,7 +22,7 @@ * * @return string */ -function smarty_modifier_regex_replace($string, $search, $replace, $limit = - 1) +function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1) { if (is_array($search)) { foreach ($search as $idx => $s) { @@ -32,7 +31,6 @@ function smarty_modifier_regex_replace($string, $search, $replace, $limit = - 1) } else { $search = _smarty_regex_replace_check($search); } - return preg_replace($search, $replace, $string, $limit); } @@ -51,8 +49,7 @@ function _smarty_regex_replace_check($search) } // remove eval-modifier from $search if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[ 1 ], 'e') !== false)) { - $search = substr($search, 0, - strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]); + $search = substr($search, 0, -strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]); } - return $search; } diff --git a/libs/plugins/modifier.replace.php b/libs/plugins/modifier.replace.php index a8f8f9b8..a98f5a4a 100644 --- a/libs/plugins/modifier.replace.php +++ b/libs/plugins/modifier.replace.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifier */ - /** * Smarty replace modifier plugin * Type: modifier @@ -32,8 +31,7 @@ function smarty_modifier_replace($string, $search, $replace) } $is_loaded = true; } - return smarty_mb_str_replace($search, $replace, $string); + return smarty_mb_str_replace($search, $replace, $string); } - return str_replace($search, $replace, $string); } diff --git a/libs/plugins/modifier.spacify.php b/libs/plugins/modifier.spacify.php index 1e29fd55..98efd4b3 100644 --- a/libs/plugins/modifier.spacify.php +++ b/libs/plugins/modifier.spacify.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifier */ - /** * Smarty spacify modifier plugin * Type: modifier @@ -23,5 +22,5 @@ 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)); + return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, -1, PREG_SPLIT_NO_EMPTY)); } diff --git a/libs/plugins/modifier.truncate.php b/libs/plugins/modifier.truncate.php index a020c716..bb881bf6 100644 --- a/libs/plugins/modifier.truncate.php +++ b/libs/plugins/modifier.truncate.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifier */ - /** * Smarty truncate modifier plugin * Type: modifier @@ -30,27 +29,24 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo if ($length === 0) { return ''; } - if (Smarty::$_MBSTRING) { if (mb_strlen($string, Smarty::$_CHARSET) > $length) { $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET)); if (!$break_words && !$middle) { $string = preg_replace( - '/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', + '/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, + '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET) ); } if (!$middle) { return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; } - return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . - mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET); + mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET); } - return $string; } - // no MBString fallback if (isset($string[ $length ])) { $length -= min($length, strlen($etc)); @@ -60,9 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo if (!$middle) { return substr($string, 0, $length) . $etc; } - - return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2); + return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); } - return $string; } diff --git a/libs/plugins/modifiercompiler.cat.php b/libs/plugins/modifiercompiler.cat.php index bb4c782f..21d0e662 100644 --- a/libs/plugins/modifiercompiler.cat.php +++ b/libs/plugins/modifiercompiler.cat.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty cat modifier plugin * Type: modifier diff --git a/libs/plugins/modifiercompiler.count_characters.php b/libs/plugins/modifiercompiler.count_characters.php index 8116aa32..6c44278a 100644 --- a/libs/plugins/modifiercompiler.count_characters.php +++ b/libs/plugins/modifiercompiler.count_characters.php @@ -5,14 +5,14 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty count_characters modifier plugin * Type: modifier * Name: count_characters * Purpose: count the number of characters in a text * - * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) + * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online + * manual) * @author Uwe Tews * * @param array $params parameters diff --git a/libs/plugins/modifiercompiler.count_paragraphs.php b/libs/plugins/modifiercompiler.count_paragraphs.php index 884d0d37..e214a56f 100644 --- a/libs/plugins/modifiercompiler.count_paragraphs.php +++ b/libs/plugins/modifiercompiler.count_paragraphs.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty count_paragraphs modifier plugin * Type: modifier diff --git a/libs/plugins/modifiercompiler.count_sentences.php b/libs/plugins/modifiercompiler.count_sentences.php index 015620e6..02774563 100644 --- a/libs/plugins/modifiercompiler.count_sentences.php +++ b/libs/plugins/modifiercompiler.count_sentences.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty count_sentences modifier plugin * Type: modifier diff --git a/libs/plugins/modifiercompiler.count_words.php b/libs/plugins/modifiercompiler.count_words.php index dc8500c7..6d889da5 100644 --- a/libs/plugins/modifiercompiler.count_words.php +++ b/libs/plugins/modifiercompiler.count_words.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty count_words modifier plugin * Type: modifier diff --git a/libs/plugins/modifiercompiler.default.php b/libs/plugins/modifiercompiler.default.php index 9fe5d4da..ae886c4b 100644 --- a/libs/plugins/modifiercompiler.default.php +++ b/libs/plugins/modifiercompiler.default.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty default modifier plugin * Type: modifier @@ -25,11 +24,9 @@ function smarty_modifiercompiler_default($params) if (!isset($params[ 1 ])) { $params[ 1 ] = "''"; } - array_shift($params); foreach ($params as $param) { $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; } - return $output; } diff --git a/libs/plugins/modifiercompiler.escape.php b/libs/plugins/modifiercompiler.escape.php index d5cadd48..e0763adc 100644 --- a/libs/plugins/modifiercompiler.escape.php +++ b/libs/plugins/modifiercompiler.escape.php @@ -25,8 +25,12 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile static $_double_encode = null; static $is_loaded = false; $compiler->template->_checkPlugins( - array(array('function' => 'smarty_literal_compiler_param', - 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php')) + array( + array( + 'function' => 'smarty_literal_compiler_param', + 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php' + ) + ) ); if ($_double_encode === null) { $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); @@ -48,6 +52,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile } else { // fall back to modifier.escape.php } + // no break case 'htmlall': if (Smarty::$_MBSTRING) { if ($_double_encode) { @@ -74,6 +79,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile } else { // fall back to modifier.escape.php } + // no break case 'url': return 'rawurlencode(' . $params[ 0 ] . ')'; case 'urlpathinfo': @@ -87,8 +93,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile $params[ 0 ] . ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", " "<\/" ))'; } - } - catch (SmartyException $e) { + } catch (SmartyException $e) { // pass through to regular plugin fallback } // could not optimize |escape call, so fallback to regular plugin diff --git a/libs/plugins/modifiercompiler.from_charset.php b/libs/plugins/modifiercompiler.from_charset.php index b5732db4..acce7784 100644 --- a/libs/plugins/modifiercompiler.from_charset.php +++ b/libs/plugins/modifiercompiler.from_charset.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty from_charset modifier plugin * Type: modifier @@ -24,10 +23,8 @@ function smarty_modifiercompiler_from_charset($params) // FIXME: (rodneyrehm) shouldn't this throw an error? return $params[ 0 ]; } - if (!isset($params[ 1 ])) { $params[ 1 ] = '"ISO-8859-1"'; } - return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')'; } diff --git a/libs/plugins/modifiercompiler.indent.php b/libs/plugins/modifiercompiler.indent.php index fede8aa7..2088ad6a 100644 --- a/libs/plugins/modifiercompiler.indent.php +++ b/libs/plugins/modifiercompiler.indent.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty indent modifier plugin * Type: modifier @@ -19,7 +18,6 @@ * * @return string with compiled code */ - function smarty_modifiercompiler_indent($params) { if (!isset($params[ 1 ])) { @@ -28,6 +26,5 @@ function smarty_modifiercompiler_indent($params) if (!isset($params[ 2 ])) { $params[ 2 ] = "' '"; } - return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')'; } diff --git a/libs/plugins/modifiercompiler.lower.php b/libs/plugins/modifiercompiler.lower.php index 8c6c26a8..0d899a00 100644 --- a/libs/plugins/modifiercompiler.lower.php +++ b/libs/plugins/modifiercompiler.lower.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty lower modifier plugin * Type: modifier @@ -20,7 +19,6 @@ * * @return string with compiled code */ - function smarty_modifiercompiler_lower($params) { if (Smarty::$_MBSTRING) { diff --git a/libs/plugins/modifiercompiler.noprint.php b/libs/plugins/modifiercompiler.noprint.php index d4b3304e..1275190e 100644 --- a/libs/plugins/modifiercompiler.noprint.php +++ b/libs/plugins/modifiercompiler.noprint.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty noprint modifier plugin * Type: modifier diff --git a/libs/plugins/modifiercompiler.string_format.php b/libs/plugins/modifiercompiler.string_format.php index 8d3bfa4e..66309431 100644 --- a/libs/plugins/modifiercompiler.string_format.php +++ b/libs/plugins/modifiercompiler.string_format.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty string_format modifier plugin * Type: modifier diff --git a/libs/plugins/modifiercompiler.strip.php b/libs/plugins/modifiercompiler.strip.php index 3b7ade5e..04ea332c 100644 --- a/libs/plugins/modifiercompiler.strip.php +++ b/libs/plugins/modifiercompiler.strip.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty strip modifier plugin * Type: modifier @@ -22,12 +21,10 @@ * * @return string with compiled code */ - function smarty_modifiercompiler_strip($params) { if (!isset($params[ 1 ])) { $params[ 1 ] = "' '"; } - return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; } diff --git a/libs/plugins/modifiercompiler.strip_tags.php b/libs/plugins/modifiercompiler.strip_tags.php index 5ddca7a9..1bca1a28 100644 --- a/libs/plugins/modifiercompiler.strip_tags.php +++ b/libs/plugins/modifiercompiler.strip_tags.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty strip_tags modifier plugin * Type: modifier diff --git a/libs/plugins/modifiercompiler.to_charset.php b/libs/plugins/modifiercompiler.to_charset.php index 88900571..d652eab1 100644 --- a/libs/plugins/modifiercompiler.to_charset.php +++ b/libs/plugins/modifiercompiler.to_charset.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty to_charset modifier plugin * Type: modifier @@ -24,10 +23,8 @@ function smarty_modifiercompiler_to_charset($params) // FIXME: (rodneyrehm) shouldn't this throw an error? return $params[ 0 ]; } - if (!isset($params[ 1 ])) { $params[ 1 ] = '"ISO-8859-1"'; } - return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(Smarty::$_CHARSET) . '")'; } diff --git a/libs/plugins/modifiercompiler.upper.php b/libs/plugins/modifiercompiler.upper.php index d0d5cc7c..ea4e95b7 100644 --- a/libs/plugins/modifiercompiler.upper.php +++ b/libs/plugins/modifiercompiler.upper.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty upper modifier plugin * Type: modifier diff --git a/libs/plugins/modifiercompiler.wordwrap.php b/libs/plugins/modifiercompiler.wordwrap.php index b08d2e05..8565f140 100644 --- a/libs/plugins/modifiercompiler.wordwrap.php +++ b/libs/plugins/modifiercompiler.wordwrap.php @@ -14,7 +14,7 @@ * @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual) * @author Uwe Tews * - * @param array $params parameters + * @param array $params parameters * @param \Smarty_Internal_TemplateCompilerBase $compiler * * @return string with compiled code diff --git a/libs/plugins/outputfilter.trimwhitespace.php b/libs/plugins/outputfilter.trimwhitespace.php index 9c8e7304..7e4503a1 100644 --- a/libs/plugins/outputfilter.trimwhitespace.php +++ b/libs/plugins/outputfilter.trimwhitespace.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFilter */ - /** * Smarty trimwhitespace outputfilter plugin * Trim unnecessary whitespace from HTML markup. @@ -22,13 +21,13 @@ function smarty_outputfilter_trimwhitespace($source) $store = array(); $_store = 0; $_offset = 0; - // Unify Line-Breaks to \n $source = preg_replace('/\015\012|\015|\012/', "\n", $source); - // capture Internet Explorer and KnockoutJS Conditional Comments if (preg_match_all( - '##is', $source, $matches, + '##is', + $source, + $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ) { @@ -37,21 +36,20 @@ function smarty_outputfilter_trimwhitespace($source) $_length = strlen($match[ 0 ][ 0 ]); $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); - $_offset += $_length - strlen($replace); - $_store ++; + $_store++; } } - // Strip all HTML-Comments // yes, even the ones in