diff --git a/change_log.txt b/change_log.txt index 88584c03..79a12af5 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@  ===== 3.1.30-dev ===== (xx.xx.xx) 09.02.2016 - move some code from parser into compiler + - reformat all code for unique style 05.02.2016 - improvement internal compiler changes diff --git a/demo/index.php b/demo/index.php index 33f3035c..b67c217b 100644 --- a/demo/index.php +++ b/demo/index.php @@ -17,8 +17,8 @@ $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("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"))); diff --git a/demo/plugins/cacheresource.apc.php b/demo/plugins/cacheresource.apc.php index d7336f2b..ed55ec84 100644 --- a/demo/plugins/cacheresource.apc.php +++ b/demo/plugins/cacheresource.apc.php @@ -32,7 +32,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore $_res = array(); $res = apc_fetch($keys); foreach ($res as $k => $v) { - $_res[$k] = $v; + $_res[ $k ] = $v; } return $_res; diff --git a/demo/plugins/cacheresource.memcache.php b/demo/plugins/cacheresource.memcache.php index 15bb073b..945beb34 100644 --- a/demo/plugins/cacheresource.memcache.php +++ b/demo/plugins/cacheresource.memcache.php @@ -43,12 +43,12 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore foreach ($keys as $k) { $_k = sha1($k); $_keys[] = $_k; - $lookup[$_k] = $k; + $lookup[ $_k ] = $k; } $_res = array(); $res = $this->memcache->get($_keys); foreach ($res as $k => $v) { - $_res[$lookup[$k]] = $v; + $_res[ $lookup[ $k ] ] = $v; } return $_res; diff --git a/demo/plugins/cacheresource.mysql.php b/demo/plugins/cacheresource.mysql.php index d8d00ab2..027b9376 100644 --- a/demo/plugins/cacheresource.mysql.php +++ b/demo/plugins/cacheresource.mysql.php @@ -26,8 +26,11 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom { // PDO instance protected $db; + protected $fetch; + protected $fetchTimestamp; + protected $save; public function __construct() @@ -62,8 +65,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom $row = $this->fetch->fetch(); $this->fetch->closeCursor(); if ($row) { - $content = $row['content']; - $mtime = strtotime($row['modified']); + $content = $row[ 'content' ]; + $mtime = strtotime($row[ 'modified' ]); } else { $content = null; $mtime = null; @@ -105,13 +108,8 @@ 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, - )); + $this->save->execute(array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id, + 'content' => $content,)); return !!$this->save->rowCount(); } @@ -151,8 +149,8 @@ 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)); diff --git a/demo/plugins/cacheresource.pdo.php b/demo/plugins/cacheresource.pdo.php index 569193aa..d1e2d6ac 100644 --- a/demo/plugins/cacheresource.pdo.php +++ b/demo/plugins/cacheresource.pdo.php @@ -30,21 +30,21 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom { - protected $fetchStatements = Array('default' => 'SELECT %2$s + protected $fetchStatements = Array('default' => 'SELECT %2$s FROM %1$s WHERE 1 AND id = :id AND cache_id IS NULL AND compile_id IS NULL', - 'withCacheId' => 'SELECT %2$s + 'withCacheId' => 'SELECT %2$s FROM %1$s WHERE 1 AND id = :id AND cache_id = :cache_id AND compile_id IS NULL', - 'withCompileId' => 'SELECT %2$s + 'withCompileId' => 'SELECT %2$s FROM %1$s WHERE 1 AND id = :id @@ -57,6 +57,7 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom AND id = :id AND cache_id = :cache_id AND compile_id = :compile_id'); + protected $insertStatement = 'INSERT INTO %s SET id = :id, @@ -76,9 +77,11 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom 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; @@ -137,13 +140,15 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom { 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); @@ -174,13 +179,13 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom { $stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id); - $stmt ->execute(); + $stmt->execute(); $row = $stmt->fetch(); - $stmt ->closeCursor(); + $stmt->closeCursor(); if ($row) { - $content = $this->outputContent($row['content']); - $mtime = strtotime($row['modified']); + $content = $this->outputContent($row[ 'content' ]); + $mtime = strtotime($row[ 'modified' ]); } else { $content = null; $mtime = null; @@ -226,13 +231,13 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom $stmt = $this->pdo->prepare($this->insertStatement); - $stmt ->bindValue('id', $id); - $stmt ->bindValue('name', $name); - $stmt ->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); - $stmt ->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); - $stmt ->bindValue('expire', (int) $exp_time, PDO::PARAM_INT); - $stmt ->bindValue('content', $this->inputContent($content)); - $stmt ->execute(); + $stmt->bindValue('id', $id); + $stmt->bindValue('name', $name); + $stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); + $stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); + $stmt->bindValue('expire', (int) $exp_time, PDO::PARAM_INT); + $stmt->bindValue('content', $this->inputContent($content)); + $stmt->execute(); return !!$stmt->rowCount(); } @@ -289,8 +294,8 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom } // 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 if ($compile_id !== null) { diff --git a/demo/plugins/resource.mysql.php b/demo/plugins/resource.mysql.php index dfc9606b..619707e7 100644 --- a/demo/plugins/resource.mysql.php +++ b/demo/plugins/resource.mysql.php @@ -21,8 +21,10 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom { // PDO instance protected $db; + // prepared fetch() statement protected $fetch; + // prepared fetchTimestamp() statement protected $mtime; @@ -53,8 +55,8 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom $row = $this->fetch->fetch(); $this->fetch->closeCursor(); if ($row) { - $source = $row['source']; - $mtime = strtotime($row['modified']); + $source = $row[ 'source' ]; + $mtime = strtotime($row[ 'modified' ]); } else { $source = null; $mtime = null; diff --git a/demo/plugins/resource.mysqls.php b/demo/plugins/resource.mysqls.php index f694ddf1..d85aecf3 100644 --- a/demo/plugins/resource.mysqls.php +++ b/demo/plugins/resource.mysqls.php @@ -23,6 +23,7 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom { // PDO instance protected $db; + // prepared fetch() statement protected $fetch; @@ -52,8 +53,8 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom $row = $this->fetch->fetch(); $this->fetch->closeCursor(); if ($row) { - $source = $row['source']; - $mtime = strtotime($row['modified']); + $source = $row[ 'source' ]; + $mtime = strtotime($row[ 'modified' ]); } else { $source = null; $mtime = null; diff --git a/libs/Autoloader.php b/libs/Autoloader.php index 7d0c388a..c713ac61 100644 --- a/libs/Autoloader.php +++ b/libs/Autoloader.php @@ -57,7 +57,7 @@ class Smarty_Autoloader set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false ) { $registeredAutoLoadFunctions = spl_autoload_functions(); - if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { + if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) { spl_autoload_register(); } } else { @@ -103,11 +103,11 @@ class Smarty_Autoloader } if (preg_match('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/', $_class, $match)) { - if (!empty($match[3])) { + if (!empty($match[ 3 ])) { @include $file; return; - } elseif (!empty($match[9]) && isset(self::$rootClasses[$_class])) { - $file = self::$rootClasses[$_class]; + } elseif (!empty($match[ 9 ]) && isset(self::$rootClasses[ $_class ])) { + $file = self::$rootClasses[ $_class ]; require $file; return; } diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 73598d1c..f10d345a 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -684,8 +684,8 @@ class Smarty extends Smarty_Internal_TemplateBase * @var string[] */ private $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', - 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', - 'cache_dir' => 'CacheDir',); + 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', + 'cache_dir' => 'CacheDir',); /**#@-*/ @@ -1144,12 +1144,13 @@ class Smarty extends Smarty_Internal_TemplateBase if (strpos($path, $nds) !== false) { $path = str_replace($nds, DS, $path); } - preg_match('%^(?(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(?:[[:print:]]*))$%', $path, $parts); - $path = $parts['path']; - if ($parts['root'] == '\\') { - $parts['root'] = substr(getcwd(), 0, 2) . $parts['root']; + preg_match('%^(?(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(?:[[:print:]]*))$%', + $path, $parts); + $path = $parts[ 'path' ]; + if ($parts[ 'root' ] == '\\') { + $parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ]; } else { - if ($realpath !== null && !$parts['root']) { + if ($realpath !== null && !$parts[ 'root' ]) { $path = getcwd() . DS . $path; } } @@ -1159,15 +1160,16 @@ class Smarty extends Smarty_Internal_TemplateBase preg_replace('#([\\\\/][^\\\\/]+[\\\\/]([.]?[\\\\/])*[.][.][\\\\/]([.]?[\\\\/])*)+|([\\\\/]([.]?[\\\\/])+)#', DS, $path, - 1, $count); } - return $parts['root'] . $path; + return $parts[ 'root' ] . $path; } /** * Empty template objects cache */ - public function _clearTemplateCache() { - $this->_cache['isCached'] = array(); - $this->_cache['tplObjects'] = array(); + public function _clearTemplateCache() + { + $this->_cache[ 'isCached' ] = array(); + $this->_cache[ 'tplObjects' ] = array(); } /** @@ -1345,7 +1347,7 @@ class Smarty extends Smarty_Internal_TemplateBase if (isset($this->accessMap[ $name ])) { $method = 'set' . $this->accessMap[ $name ]; $this->{$method}($value); - } elseif (in_array($name, $this->obsoleteProperties)) { + } elseif (in_array($name, $this->obsoleteProperties)) { return; } else { if (is_object($value) && method_exists($value, $name)) { @@ -1399,7 +1401,7 @@ class Smarty extends Smarty_Internal_TemplateBase break; } } - // pass to next error handler if this error did not occur inside SMARTY_DIR + // pass to next error handler if this error did not occur inside SMARTY_DIR // or the error was within smarty but masked to be ignored if (!$_is_muted_directory || ($errno && $errno & error_reporting())) { if (Smarty::$_previous_error_handler) { diff --git a/libs/SmartyBC.class.php b/libs/SmartyBC.class.php index f50792ed..3955e4f2 100644 --- a/libs/SmartyBC.class.php +++ b/libs/SmartyBC.class.php @@ -128,7 +128,8 @@ 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, $block_methods = array()) + public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, + $block_methods = array()) { settype($allowed, 'array'); settype($smarty_args, 'boolean'); diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php index abf54493..e9f5fe2d 100644 --- a/libs/plugins/block.textformat.php +++ b/libs/plugins/block.textformat.php @@ -83,7 +83,9 @@ function smarty_block_textformat($params, $content, $template, &$repeat) continue; } // convert mult. spaces & special chars to single space - $_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph); + $_paragraph = + preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), + array(' ', ''), $_paragraph); // indent first line if ($indent_first > 0) { $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; diff --git a/libs/plugins/function.counter.php b/libs/plugins/function.counter.php index 4da85a14..bcc8f498 100644 --- a/libs/plugins/function.counter.php +++ b/libs/plugins/function.counter.php @@ -25,53 +25,48 @@ 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 - ); + $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]; + $counter =& $counters[ $name ]; - if (isset($params['start'])) { - $counter['start'] = $counter['count'] = (int) $params['start']; + if (isset($params[ 'start' ])) { + $counter[ 'start' ] = $counter[ 'count' ] = (int) $params[ 'start' ]; } - if (!empty($params['assign'])) { - $counter['assign'] = $params['assign']; + if (!empty($params[ 'assign' ])) { + $counter[ 'assign' ] = $params[ 'assign' ]; } - if (isset($counter['assign'])) { - $template->assign($counter['assign'], $counter['count']); + if (isset($counter[ 'assign' ])) { + $template->assign($counter[ 'assign' ], $counter[ 'count' ]); } - if (isset($params['print'])) { - $print = (bool) $params['print']; + if (isset($params[ 'print' ])) { + $print = (bool) $params[ 'print' ]; } else { - $print = empty($counter['assign']); + $print = empty($counter[ 'assign' ]); } if ($print) { - $retval = $counter['count']; + $retval = $counter[ 'count' ]; } else { $retval = null; } - if (isset($params['skip'])) { - $counter['skip'] = $params['skip']; + if (isset($params[ 'skip' ])) { + $counter[ 'skip' ] = $params[ 'skip' ]; } - if (isset($params['direction'])) { - $counter['direction'] = $params['direction']; + if (isset($params[ 'direction' ])) { + $counter[ 'direction' ] = $params[ 'direction' ]; } - if ($counter['direction'] == "down") { - $counter['count'] -= $counter['skip']; + if ($counter[ 'direction' ] == "down") { + $counter[ 'count' ] -= $counter[ 'skip' ]; } else { - $counter['count'] += $counter['skip']; + $counter[ 'count' ] += $counter[ 'skip' ]; } return $retval; diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php index 8dc5cd9d..a76d49ae 100644 --- a/libs/plugins/function.cycle.php +++ b/libs/plugins/function.cycle.php @@ -48,58 +48,56 @@ 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; + $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; - if (!isset($params['values'])) { - if (!isset($cycle_vars[$name]['values'])) { + if (!isset($params[ 'values' ])) { + if (!isset($cycle_vars[ $name ][ 'values' ])) { trigger_error("cycle: missing 'values' parameter"); return; } } else { - if (isset($cycle_vars[$name]['values']) - && $cycle_vars[$name]['values'] != $params['values'] - ) { - $cycle_vars[$name]['index'] = 0; + if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] != $params[ 'values' ]) { + $cycle_vars[ $name ][ 'index' ] = 0; } - $cycle_vars[$name]['values'] = $params['values']; + $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 (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']; + 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']); + $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($cycle_vars[ $name ][ 'index' ]) || $reset) { + $cycle_vars[ $name ][ 'index' ] = 0; } - if (isset($params['assign'])) { + if (isset($params[ 'assign' ])) { $print = false; - $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); + $template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]); } if ($print) { - $retval = $cycle_array[$cycle_vars[$name]['index']]; + $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; + if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) { + $cycle_vars[ $name ][ 'index' ] = 0; } else { - $cycle_vars[$name]['index'] ++; + $cycle_vars[ $name ][ 'index' ] ++; } } diff --git a/libs/plugins/function.fetch.php b/libs/plugins/function.fetch.php index 3506d4a8..cb60dd91 100644 --- a/libs/plugins/function.fetch.php +++ b/libs/plugins/function.fetch.php @@ -24,31 +24,31 @@ */ function smarty_function_fetch($params, $template) { - if (empty($params['file'])) { + if (empty($params[ 'file' ])) { trigger_error("[plugin] fetch parameter 'file' cannot be empty", E_USER_NOTICE); return; } // strip file protocol - if (stripos($params['file'], 'file://') === 0) { - $params['file'] = substr($params['file'], 7); + if (stripos($params[ 'file' ], 'file://') === 0) { + $params[ 'file' ] = substr($params[ 'file' ], 7); } - $protocol = strpos($params['file'], '://'); + $protocol = strpos($params[ 'file' ], '://'); if ($protocol !== false) { - $protocol = strtolower(substr($params['file'], 0, $protocol)); + $protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); } if (isset($template->smarty->security_policy)) { if ($protocol) { // remote resource (or php stream, …) - if (!$template->smarty->security_policy->isTrustedUri($params['file'])) { + if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) { return; } } else { // local file - if (!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { + if (!$template->smarty->security_policy->isTrustedResourceDir($params[ 'file' ])) { return; } } @@ -57,26 +57,26 @@ function smarty_function_fetch($params, $template) $content = ''; if ($protocol == 'http') { // http fetch - if ($uri_parts = parse_url($params['file'])) { + if ($uri_parts = parse_url($params[ 'file' ])) { // set defaults - $host = $server_name = $uri_parts['host']; + $host = $server_name = $uri_parts[ 'host' ]; $timeout = 30; $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; $agent = "Smarty Template Engine " . Smarty::SMARTY_VERSION; $referer = ""; - $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; - $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; + $uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/'; + $uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : ''; $_is_proxy = false; - if (empty($uri_parts['port'])) { + if (empty($uri_parts[ 'port' ])) { $port = 80; } else { - $port = $uri_parts['port']; + $port = $uri_parts[ 'port' ]; } - if (!empty($uri_parts['user'])) { - $user = $uri_parts['user']; + if (!empty($uri_parts[ 'user' ])) { + $user = $uri_parts[ 'user' ]; } - if (!empty($uri_parts['pass'])) { - $pass = $uri_parts['pass']; + if (!empty($uri_parts[ 'pass' ])) { + $pass = $uri_parts[ 'pass' ]; } // loop through parameters, setup headers foreach ($params as $param_key => $param_value) { @@ -163,7 +163,7 @@ function smarty_function_fetch($params, $template) return; } else { if ($_is_proxy) { - fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n"); + fputs($fp, 'GET ' . $params[ 'file' ] . " HTTP/1.0\r\n"); } else { fputs($fp, "GET $uri HTTP/1.0\r\n"); } @@ -195,10 +195,10 @@ function smarty_function_fetch($params, $template) fclose($fp); $csplit = preg_split("!\r\n\r\n!", $content, 2); - $content = $csplit[1]; + $content = $csplit[ 1 ]; - if (!empty($params['assign_headers'])) { - $template->assign($params['assign_headers'], preg_split("!\r\n!", $csplit[0])); + if (!empty($params[ 'assign_headers' ])) { + $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ])); } } } else { @@ -207,14 +207,14 @@ function smarty_function_fetch($params, $template) return; } } else { - $content = @file_get_contents($params['file']); + $content = @file_get_contents($params[ 'file' ]); if ($content === false) { - throw new SmartyException("{fetch} cannot read resource '" . $params['file'] . "'"); + throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); } } - if (!empty($params['assign'])) { - $template->assign($params['assign'], $content); + if (!empty($params[ 'assign' ])) { + $template->assign($params[ 'assign' ], $content); } else { return $content; } diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index d7868036..33f2efe1 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -90,19 +90,21 @@ function smarty_function_html_checkboxes($params, $template) if (method_exists($_sel, "__toString")) { $_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); } else { - trigger_error("html_checkboxes: selected attribute contains an object of class '" . get_class($_sel) . "' without __toString() method", E_USER_NOTICE); + trigger_error("html_checkboxes: selected attribute contains an object of class '" . + get_class($_sel) . "' without __toString() method", E_USER_NOTICE); continue; } } else { $_sel = smarty_function_escape_special_chars((string) $_sel); } - $selected[$_sel] = true; + $selected[ $_sel ] = true; } } elseif (is_object($_val)) { if (method_exists($_val, "__toString")) { $selected = smarty_function_escape_special_chars((string) $_val->__toString()); } else { - trigger_error("html_checkboxes: selected attribute is an object of class '" . get_class($_val) . "' without __toString() method", E_USER_NOTICE); + trigger_error("html_checkboxes: selected attribute is an object of class '" . get_class($_val) . + "' without __toString() method", E_USER_NOTICE); } } else { $selected = smarty_function_escape_special_chars((string) $_val); @@ -110,7 +112,8 @@ function smarty_function_html_checkboxes($params, $template) break; case 'checkboxes': - trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); + trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', + E_USER_WARNING); $options = (array) $_val; break; @@ -122,9 +125,10 @@ function smarty_function_html_checkboxes($params, $template) case 'disabled': case 'readonly': - if (!empty($params['strict'])) { + if (!empty($params[ 'strict' ])) { if (!is_scalar($_val)) { - trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE); + trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", + E_USER_NOTICE); } if ($_val === true || $_val === $_key) { @@ -153,23 +157,28 @@ function smarty_function_html_checkboxes($params, $template) if (isset($options)) { foreach ($options as $_key => $_val) { - $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); + $_html_result[] = + smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, + $label_ids, $escape); } } else { foreach ($values as $_i => $_key) { - $_val = isset($output[$_i]) ? $output[$_i] : ''; - $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); + $_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; + $_html_result[] = + smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, + $label_ids, $escape); } } - if (!empty($params['assign'])) { - $template->assign($params['assign'], $_html_result); + if (!empty($params[ 'assign' ])) { + $template->assign($params[ 'assign' ], $_html_result); } else { return implode("\n", $_html_result); } } -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 = ''; @@ -177,7 +186,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte if (method_exists($value, "__toString")) { $value = (string) $value->__toString(); } else { - trigger_error("html_options: value is an object of class '" . get_class($value) . "' without __toString() method", E_USER_NOTICE); + trigger_error("html_options: value is an object of class '" . get_class($value) . + "' without __toString() method", E_USER_NOTICE); return ''; } @@ -189,7 +199,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte if (method_exists($output, "__toString")) { $output = (string) $output->__toString(); } else { - trigger_error("html_options: output is an object of class '" . get_class($output) . "' without __toString() method", E_USER_NOTICE); + trigger_error("html_options: output is an object of class '" . get_class($output) . + "' without __toString() method", E_USER_NOTICE); return ''; } @@ -199,7 +210,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte if ($labels) { if ($label_ids) { - $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value)); + $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', + $name . '_' . $value)); $_output .= '