2 Commits

Author SHA1 Message Date
9d038e4fe6 Smarty v4 update to v4.3.4 2023-10-18 10:02:18 +09:00
c61abb4b56 Update Readme file 2023-02-20 15:41:14 +09:00
16 changed files with 67 additions and 58 deletions

View File

@@ -11,45 +11,36 @@ For local install only
## Setup from central composer ## Setup from central composer
| Host | Location | Type | Setup from gitea internal servers
| - | - | - |
| composer.tokyo.tequila.jp | soba-local | Local test |
| composer-local.tokyo.tequila.jp | udon-local | Local Live, no https |
| composer.egplusww.jp | udon | General Live (use this) |
composer.json: ```sh
composer config repositories.git.egplusww.jp.Composer composer https://git.egplusww.jp/api/packages/Composer/composer
For Local test, note that secure-http has to be turned off:
```json
{
"repositories": [
{
"type": "composer",
"url": "http://composer.tokyo.tequila.jp"
}
],
"require": {
"egrajp/smarty-extended": "@dev"
},
"config": {
"secure-http": false
}
}
``` ```
For live settings Alternative setup composer local zip file repot:
`composer config repositories.composer.egplusww.jp composer http://composer.egplusww.jp`
```json ## Install package
{
"repositories": [ `composer require egrajp/smarty-extended:^4.3`
{
"type": "composer", ## How to update
"url": "https://composer.egplusww.jp"
} 1) update the original composer for ^4.3
], 2) copy over the src/sysplugins and all base files in src/
"require": { 3) check either function.html_checkboxes.php and function.html_options.php have changed
"egrajp/smarty-extended": "@dev" 4) copy src/plugins except the above two files, be sure to keep the block.t.php and function_popup*.php
} 5) Create new release version as official relase number
}
``` ## Updated files (different from master)
### New
`src/plugins/block.t.php`
`src/plugins/function_popup.php`
`src/plugins/function_popup.init.php`
### Changed
`src/plugins/function.html_checkboxes.php`
`src/plugins/function.html_options.php`

View File

@@ -167,9 +167,7 @@
</html> </html>
{/capture} {/capture}
<script type="text/javascript"> <script type="text/javascript">
{$id = '__Smarty__'} _smarty_console = window.open("", "console{$targetWindow}", "width=1024,height=600,left={$offset},top={$offset},resizable,scrollbars=yes");
{if $display_mode}{$id = "$offset$template_name"|md5}{/if}
_smarty_console = window.open("", "console{$id}", "width=1024,height=600,left={$offset},top={$offset},resizable,scrollbars=yes");
_smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}"); _smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}");
_smarty_console.document.close(); _smarty_console.document.close();
</script> </script>

View File

@@ -67,7 +67,7 @@ function smarty_function_math($params, $template)
$equation = preg_replace('/\s+/', '', $equation); $equation = preg_replace('/\s+/', '', $equation);
// Adapted from https://www.php.net/manual/en/function.eval.php#107377 // Adapted from https://www.php.net/manual/en/function.eval.php#107377
$number = '(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number $number = '-?(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number
$functionsOrVars = '((?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))'; $functionsOrVars = '((?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))';
$operators = '[,+\/*\^%-]'; // Allowed math operators $operators = '[,+\/*\^%-]'; // Allowed math operators
$regexp = '/^(('.$number.'|'.$functionsOrVars.'|('.$functionsOrVars.'\s*\((?1)*\)|\((?1)*\)))(?:'.$operators.'(?1))?)+$/'; $regexp = '/^(('.$number.'|'.$functionsOrVars.'|('.$functionsOrVars.'\s*\((?1)*\)|\((?1)*\)))(?:'.$operators.'(?1))?)+$/';

View File

@@ -115,7 +115,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements // see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
'<!--' => '<\!--', '<!--' => '<\!--',
'<s' => '<\s', '<s' => '<\s',
'<S' => '<\S' '<S' => '<\S',
"`" => "\\\\`",
"\${" => "\\\\\\$\\{"
) )
); );
case 'mail': case 'mail':

View File

@@ -26,7 +26,7 @@
*/ */
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{ {
if ($length === 0) { if ($length === 0 || $string === null) {
return ''; return '';
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {

View File

@@ -25,8 +25,8 @@ function smarty_modifiercompiler_count_characters($params)
return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)'; return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)';
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strlen(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strlen((string) ' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strlen(' . $params[ 0 ] . ')'; return 'strlen((string) ' . $params[ 0 ] . ')';
} }

View File

@@ -27,5 +27,5 @@ function smarty_modifiercompiler_count_words($params)
$params[ 0 ] . ', $tmp)'; $params[ 0 ] . ', $tmp)';
} }
// no MBString fallback // no MBString fallback
return 'str_word_count(' . $params[ 0 ] . ')'; return 'str_word_count((string) ' . $params[ 0 ] . ')';
} }

View File

@@ -64,7 +64,9 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements // see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
return 'strtr((string)' . return 'strtr((string)' .
$params[ 0 ] . $params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))'; ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r",
"\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S",
"`" => "\\\\`", "\${" => "\\\\\\$\\{"))';
} }
} catch (SmartyException $e) { } catch (SmartyException $e) {
// pass through to regular plugin fallback // pass through to regular plugin fallback

View File

@@ -25,5 +25,5 @@ function smarty_modifiercompiler_lower($params)
return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strtolower(' . $params[ 0 ] . ')'; return 'strtolower((string) ' . $params[ 0 ] . ')';
} }

View File

@@ -21,7 +21,7 @@
function smarty_modifiercompiler_strip_tags($params) function smarty_modifiercompiler_strip_tags($params)
{ {
if (!isset($params[ 1 ]) || $params[ 1 ] === true || trim($params[ 1 ], '"') === 'true') { if (!isset($params[ 1 ]) || $params[ 1 ] === true || trim($params[ 1 ], '"') === 'true') {
return "preg_replace('!<[^>]*?>!', ' ', {$params[0]} ?: '')"; return "preg_replace('!<[^>]*?>!', ' ', (string) {$params[0]})";
} else { } else {
return 'strip_tags((string) ' . $params[ 0 ] . ')'; return 'strip_tags((string) ' . $params[ 0 ] . ')';
} }

View File

@@ -21,8 +21,8 @@
function smarty_modifiercompiler_upper($params) function smarty_modifiercompiler_upper($params)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strtoupper(' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strtoupper((string) ' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strtoupper(' . $params[ 0 ] . ' ?? \'\')'; return 'strtoupper((string) ' . $params[ 0 ] . ' ?? \'\')';
} }

View File

@@ -62,7 +62,7 @@ function smarty_outputfilter_trimwhitespace($source)
} }
} }
$expressions = array(// replace multiple spaces between tags by a single space $expressions = array(// replace multiple spaces between tags by a single space
// can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements // can't remove them entirely, because that might break poorly implemented CSS display:inline-block elements
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2', '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
// remove spaces between attributes (but not in attribute values!) // remove spaces between attributes (but not in attribute values!)
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',

View File

@@ -15,5 +15,5 @@
*/ */
function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template) function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template)
{ {
return htmlspecialchars($source, ENT_QUOTES, Smarty::$_CHARSET); return htmlspecialchars((string) $source, ENT_QUOTES, Smarty::$_CHARSET);
} }

View File

@@ -238,9 +238,12 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$_config_vars = $ptr->config_vars; $_config_vars = $ptr->config_vars;
ksort($_config_vars); ksort($_config_vars);
$debugging = $smarty->debugging; $debugging = $smarty->debugging;
$templateName = $obj->source->type . ':' . $obj->source->name;
$displayMode = $debugging === 2 || !$full;
$offset = $this->offset * 50;
$_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj); $_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj);
if ($obj->_isTplObj()) { if ($obj->_isTplObj()) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name); $_template->assign('template_name', $templateName);
} }
if ($obj->_objType === 1 || $full) { if ($obj->_objType === 1 || $full) {
$_template->assign('template_data', $this->template_data[ $this->index ]); $_template->assign('template_data', $this->template_data[ $this->index ]);
@@ -250,8 +253,8 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$_template->assign('assigned_vars', $_assigned_vars); $_template->assign('assigned_vars', $_assigned_vars);
$_template->assign('config_vars', $_config_vars); $_template->assign('config_vars', $_config_vars);
$_template->assign('execution_time', microtime(true) - $smarty->start_time); $_template->assign('execution_time', microtime(true) - $smarty->start_time);
$_template->assign('display_mode', $debugging === 2 || !$full); $_template->assign('targetWindow', $displayMode ? md5("$offset$templateName") : '__Smarty__');
$_template->assign('offset', $this->offset * 50); $_template->assign('offset', $offset);
echo $_template->fetch(); echo $_template->fetch();
if (isset($full)) { if (isset($full)) {
$this->index--; $this->index--;

View File

@@ -17,6 +17,12 @@ class Smarty_Internal_ErrorHandler
*/ */
public $allowUndefinedVars = true; public $allowUndefinedVars = true;
/**
* Allows {$foo->propName} where propName is undefined.
* @var bool
*/
public $allowUndefinedProperties = true;
/** /**
* Allows {$foo.bar} where bar is unset and {$foo.bar1.bar2} where either bar1 or bar2 is unset. * Allows {$foo.bar} where bar is unset and {$foo.bar1.bar2} where either bar1 or bar2 is unset.
* @var bool * @var bool
@@ -80,6 +86,13 @@ class Smarty_Internal_ErrorHandler
return; // suppresses this error return; // suppresses this error
} }
if ($this->allowUndefinedProperties && preg_match(
'/^(Undefined property)/',
$errstr
)) {
return; // suppresses this error
}
if ($this->allowUndefinedArrayKeys && preg_match( if ($this->allowUndefinedArrayKeys && preg_match(
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type)/', '/^(Undefined index|Undefined array key|Trying to access array offset on value of type)/',
$errstr $errstr

View File

@@ -85,7 +85,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
* *
* @param Smarty_Internal_Template $_template * @param Smarty_Internal_Template $_template
* *
* @return string * @return void
* @throws Exception * @throws Exception
*/ */
public function render(Smarty_Internal_Template $_template) public function render(Smarty_Internal_Template $_template)