Skip to content

Commit

Permalink
code cleanup and optimizations 3.1.32-dev-34
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Nov 6, 2017
1 parent 3799714 commit 3fc8abe
Show file tree
Hide file tree
Showing 99 changed files with 600 additions and 621 deletions.
366 changes: 183 additions & 183 deletions change_log.txt

Large diffs are not rendered by default.

30 changes: 4 additions & 26 deletions libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.32-dev-32';
const SMARTY_VERSION = '3.1.32-dev-34';
/**
* define variable scopes
*/
Expand Down Expand Up @@ -166,14 +166,6 @@ class Smarty extends Smarty_Internal_TemplateBase
const PLUGIN_COMPILER = 'compiler';
const PLUGIN_MODIFIER = 'modifier';
const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler';
/**
* Resource caching modes
* (not used since 3.1.30)
*/
const RESOURCE_CACHE_OFF = 0;
const RESOURCE_CACHE_AUTOMATIC = 1; // cache template objects by rules
const RESOURCE_CACHE_TEMPLATE = 2; // cache all template objects
const RESOURCE_CACHE_ON = 4; // cache source and compiled resources
/**
* assigned global tpl vars
*/
Expand Down Expand Up @@ -283,13 +275,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var boolean
*/
public $force_compile = false;
/**
* check template for modifications?
*
* @var boolean
*/
public $compile_check = true;
/**
/**
* use sub dirs for compiled/cached files?
*
* @var boolean
Expand Down Expand Up @@ -980,10 +966,10 @@ public function createTemplate($template, $cache_id = null, $compile_id = null,
$tpl->tpl_vars[ $_key ] = new Smarty_Variable($_val);
}
}
if ($this->debugging || $this->debugging_ctrl == 'URL') {
if ($this->debugging || $this->debugging_ctrl === 'URL') {
$tpl->smarty->_debug = new Smarty_Internal_Debug();
// check URL debugging control
if (!$this->debugging && $this->debugging_ctrl == 'URL') {
if (!$this->debugging && $this->debugging_ctrl === 'URL') {
$tpl->smarty->_debug->debugUrl($tpl->smarty);
}
}
Expand Down Expand Up @@ -1100,14 +1086,6 @@ public function _clearTemplateCache()
Smarty_Internal_Template::$tplObjCache = array();
}

/**
* @param boolean $compile_check
*/
public function setCompileCheck($compile_check)
{
$this->compile_check = $compile_check;
}

/**
* @param boolean $use_sub_dirs
*/
Expand Down
4 changes: 2 additions & 2 deletions libs/plugins/block.textformat.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
break;

default:
trigger_error("textformat: unknown attribute '$_key'");
trigger_error("textformat: unknown attribute '{$_key}'");
}
}

if ($style == 'email') {
if ($style === 'email') {
$wrap = 72;
}
// split into paragraphs
Expand Down
2 changes: 1 addition & 1 deletion libs/plugins/function.counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function smarty_function_counter($params, $template)
$counter[ 'direction' ] = $params[ 'direction' ];
}

if ($counter[ 'direction' ] == "down") {
if ($counter[ 'direction' ] === 'down') {
$counter[ 'count' ] -= $counter[ 'skip' ];
} else {
$counter[ 'count' ] += $counter[ 'skip' ];
Expand Down
4 changes: 2 additions & 2 deletions libs/plugins/function.cycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ function smarty_function_cycle($params, $template)

if (!isset($params[ 'values' ])) {
if (!isset($cycle_vars[ $name ][ 'values' ])) {
trigger_error("cycle: missing 'values' parameter");
trigger_error('cycle: missing \'values\' parameter');

return;
}
} else {
if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] != $params[ 'values' ]) {
if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] !== $params[ 'values' ]) {
$cycle_vars[ $name ][ 'index' ] = 0;
}
$cycle_vars[ $name ][ 'values' ] = $params[ 'values' ];
Expand Down
44 changes: 22 additions & 22 deletions libs/plugins/function.fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
function smarty_function_fetch($params, $template)
{
if (empty($params[ 'file' ])) {
trigger_error("[plugin] fetch parameter 'file' cannot be empty", E_USER_NOTICE);
trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE);

return;
}
Expand Down Expand Up @@ -55,15 +55,15 @@ function smarty_function_fetch($params, $template)
}

$content = '';
if ($protocol == 'http') {
if ($protocol === 'http') {
// http fetch
if ($uri_parts = parse_url($params[ 'file' ])) {
// set defaults
$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 = "";
$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' ] : '';
$_is_proxy = false;
Expand All @@ -81,71 +81,71 @@ function smarty_function_fetch($params, $template)
// loop through parameters, setup headers
foreach ($params as $param_key => $param_value) {
switch ($param_key) {
case "file":
case "assign":
case "assign_headers":
case 'file':
case 'assign':
case 'assign_headers':
break;
case "user":
case 'user':
if (!empty($param_value)) {
$user = $param_value;
}
break;
case "pass":
case 'pass':
if (!empty($param_value)) {
$pass = $param_value;
}
break;
case "accept":
case 'accept':
if (!empty($param_value)) {
$accept = $param_value;
}
break;
case "header":
case 'header':
if (!empty($param_value)) {
if (!preg_match('![\w\d-]+: .+!', $param_value)) {
trigger_error("[plugin] invalid header format '" . $param_value . "'", E_USER_NOTICE);
trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE);

return;
} else {
$extra_headers[] = $param_value;
}
}
break;
case "proxy_host":
case 'proxy_host':
if (!empty($param_value)) {
$proxy_host = $param_value;
}
break;
case "proxy_port":
case 'proxy_port':
if (!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value;
} else {
trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE);
trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE);

return;
}
break;
case "agent":
case 'agent':
if (!empty($param_value)) {
$agent = $param_value;
}
break;
case "referer":
case 'referer':
if (!empty($param_value)) {
$referer = $param_value;
}
break;
case "timeout":
case 'timeout':
if (!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value;
} else {
trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE);
trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);

return;
}
break;
default:
trigger_error("[plugin] unrecognized attribute '" . $param_key . "'", E_USER_NOTICE);
trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);

return;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ function smarty_function_fetch($params, $template)
}
}
if (!empty($user) && !empty($pass)) {
fputs($fp, "Authorization: BASIC " . base64_encode("$user:$pass") . "\r\n");
fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n");
}

fputs($fp, "\r\n");
Expand Down
28 changes: 14 additions & 14 deletions libs/plugins/function.html_checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ function smarty_function_html_checkboxes($params, $template)
$selected = array();
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, "__toString")) {
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 {
Expand All @@ -103,11 +103,11 @@ function smarty_function_html_checkboxes($params, $template)
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, "__toString")) {
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);
Expand All @@ -130,7 +130,7 @@ function smarty_function_html_checkboxes($params, $template)
case 'readonly':
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",
trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE);
}

Expand All @@ -146,7 +146,7 @@ function smarty_function_html_checkboxes($params, $template)
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
trigger_error("html_checkboxes: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
Expand Down Expand Up @@ -198,11 +198,11 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
$_output = '';

if (is_object($value)) {
if (method_exists($value, "__toString")) {
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 '';
}
Expand All @@ -211,11 +211,11 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
}

if (is_object($output)) {
if (method_exists($output, "__toString")) {
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 '';
}
Expand Down
14 changes: 7 additions & 7 deletions libs/plugins/function.html_image.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function smarty_function_html_image($params, $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;

Expand All @@ -81,19 +81,19 @@ function smarty_function_html_image($params, $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;
}
}

if (empty($file)) {
trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE);

return;
}

if ($file[ 0 ] == '/') {
if ($file[ 0 ] === '/') {
$_image_path = $basedir . $file;
} else {
$_image_path = $file;
Expand Down Expand Up @@ -127,15 +127,15 @@ function smarty_function_html_image($params, $template)
// FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader!
if (!$_image_data = @getimagesize($_image_path)) {
if (!file_exists($_image_path)) {
trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
trigger_error("html_image: unable to find '{$_image_path}'", E_USER_NOTICE);

return;
} elseif (!is_readable($_image_path)) {
trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
trigger_error("html_image: unable to read '{$_image_path}'", E_USER_NOTICE);

return;
} else {
trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
trigger_error("html_image: '{$_image_path}' is not a valid image file", E_USER_NOTICE);

return;
}
Expand Down
Loading

0 comments on commit 3fc8abe

Please sign in to comment.