Smarty v5 update test, initial code setup

This commit is contained in:
2024-08-09 17:28:32 +09:00
parent b2c8fe2e1f
commit 2fc2807a6b
382 changed files with 30655 additions and 28498 deletions

206
test/plugins/block.t.php Normal file
View File

@@ -0,0 +1,206 @@
<?php
/**
* smarty-gettext.php - Gettext support for smarty
*
* To register as a smarty block function named 't', use:
* $smarty->register_block('t', 'smarty_translate');
*
* NOTE: native php support for conext sensitive does not exist
* Those jumps are disabled
*
* @package smarty-gettext
* @version $Id: block.t.php 4738 2022-05-06 01:28:48Z clemens $
* @link http://smarty-gettext.sf.net/
* @author Sagi Bashari <sagi@boom.org.il>
* @copyright 2004 Sagi Bashari
* @copyright Elan Ruusamäe
* @copyright 2024 Clemens Schwaighofer
*/
/**
* Replaces arguments in a string with their values.
* Arguments are represented by % followed by their number.
*
* @param string $str Source string
* @param mixed mixed Arguments, can be passed in an array or through single variables.
* @return string Modified string
*/
function smarty_gettext_strarg($str/*, $varargs... */)
{
$tr = [];
$p = 0;
$nargs = func_num_args();
for ($i = 1; $i < $nargs; $i++) {
$arg = func_get_arg($i);
if (is_array($arg)) {
foreach ($arg as $aarg) {
$tr['%' . ++$p] = $aarg;
}
} else {
$tr['%' . ++$p] = $arg;
}
}
return strtr($str, $tr);
}
/**
* Smarty block function, provides gettext support for smarty.
*
* The block content is the text that should be translated.
*
* Any parameter that is sent to the function will be represented as %n in the translation text,
* where n is 1 for the first parameter. The following parameters are reserved:
* - escape - sets escape mode:
* - 'html' for HTML escaping, this is the default.
* - 'js' for javascript escaping.
* - 'url' for url escaping.
* - 'no'/'off'/0 - turns off escaping
* - plural - The plural version of the text (2nd parameter of ngettext())
* - count - The item count for plural mode (3rd parameter of ngettext())
* - domain - Textdomain to be used, default if skipped (dgettext() instead of gettext())
* - context - gettext context. reserved for future use.
*
*/
// cs modified: __ calls instead of direct gettext calls
function smarty_block_t($params, $text)
{
if (!isset($text)) {
return $text;
}
$escape = 'html';
$plural = null;
$count = null;
$domain = null;
$context = null;
foreach ($params as $_key => $_value) {
switch ($_key) {
// set escape mode, default html escape
case 'escape':
$escape = (string)$_value;
break;
// set plural parameters 'plural' and 'count'.
case 'plural':
$plural = $_value;
break;
// set count, only for plural, else ignored
case 'count':
$count = $_value;
break;
// get domain param
case 'domain':
$domain = (string)$_value;
break;
// get context param
case 'context':
$context = (string)$_value;
break;
}
}
// use plural if required parameters are set
if (isset($count) && isset($plural)) {
if (isset($domain) && isset($context)) {
if (is_callable('_dnpgettext')) {
$text = _dnpgettext($domain, $context, $text, $plural, $count);
}/* elseif (is_callable('dnpgettext')) {
$text = dnpgettext($domain, $context, $text, $plural, $count);
} */
} elseif (isset($domain)) {
if (is_callable('_dngettext')) {
$text = _dngettext($domain, $text, $plural, $count);
} elseif (is_callable('dngettext')) {
$text = dngettext($domain, $text, $plural, $count);
}
} elseif (isset($context)) {
if (is_callable('_npgettext')) {
$text = _npgettext($context, $text, $plural, $count);
}/* elseif (is_callable('npgettext')) {
$text = npgettext($context, $text, $plural, $count);
} */
} else {
if (is_callable('_ngettext')) {
$text = _ngettext($text, $plural, $count);
} elseif (is_callable('ngettext')) {
$text = ngettext($text, $plural, $count);
}
}
} else { // use normal
if (isset($domain) && isset($context)) {
if (is_callable('_dpgettext')) {
$text = _dpgettext($domain, $context, $text);
}/* elseif (is_callable('dpgettext')) {
$text = dpgettext($domain, $context, $text);
} */
} elseif (isset($domain)) {
if (is_callable('_dgettext')) {
$text = _dgettext($domain, $text);
} elseif (is_callable('dpgettext')) {
$text = dgettext($domain, $text);
}
} elseif (isset($context)) {
if (is_callable('_pgettext')) {
$text = _pgettext($context, $text);
}/* elseif (is_callable('pgettext')) {
$text = pgettext($context, $text);
} */
} else {
if (is_callable('_gettext')) {
$text = _gettext($text);
} elseif (is_callable('gettext')) {
$text = gettext($text);
}
}
}
// run strarg if there are parameters
if (count($params)) {
$text = smarty_gettext_strarg($text, $params);
}
switch ($escape) {
case 'html':
// default
$text = nl2br(htmlspecialchars($text));
break;
case 'javascript':
case 'js':
// javascript escape
$text = strtr(
$text,
[
'\\' => '\\\\',
"'" => "\\'",
'"' => '\\"',
"\r" => '\\r',
"\n" => '\\n',
'</' => '<\/'
]
);
break;
case 'url':
// url escape
$text = urlencode($text);
break;
// below is a list for explicit OFF
case 'no':
case 'off':
case 'false':
case '0':
case 0:
// explicit OFF
default:
break;
}
return $text;
}
// __END__

View File

@@ -0,0 +1,124 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {popup} function plugin
*
* Type: function<br>
* Name: popup<br>
* Purpose: make text pop up in windows via overlib
* @author Monte Ohrt <monte at ohrt dot com>
* @author 2024 Clemens Schwaighofer <gullevek at gullevek dot org>
* @param array
* @param Smarty
* @return string
*/
function smarty_function_popup($params, &$smarty)
{
$append = '';
foreach ($params as $_key => $_value) {
switch ($_key) {
case 'text':
case 'trigger':
case 'function':
case 'inarray':
$$_key = (string)$_value;
if ($_key == 'function' || $_key == 'inarray') {
$append .= ',' . strtoupper($_key) . ",'$_value'";
}
break;
case 'caption':
case 'closetext':
case 'status':
$append .= ',' . strtoupper($_key) . ",'" . str_replace("'", "\'", $_value) . "'";
break;
case 'fgcolor':
case 'bgcolor':
case 'textcolor':
case 'capcolor':
case 'closecolor':
case 'textfont':
case 'captionfont':
case 'closefont':
case 'fgbackground':
case 'bgbackground':
case 'caparray':
case 'capicon':
case 'background':
case 'frame':
$append .= ',' . strtoupper($_key) . ",'$_value'";
break;
case 'textsize':
case 'captionsize':
case 'closesize':
case 'width':
case 'height':
case 'border':
case 'offsetx':
case 'offsety':
case 'snapx':
case 'snapy':
case 'fixx':
case 'fixy':
case 'padx':
case 'pady':
case 'timeout':
case 'delay':
$append .= ',' . strtoupper($_key) . ",$_value";
break;
case 'sticky':
case 'left':
case 'right':
case 'center':
case 'above':
case 'below':
case 'noclose':
case 'autostatus':
case 'autostatuscap':
case 'fullhtml':
case 'hauto':
case 'vauto':
case 'mouseoff':
case 'followmouse':
case 'closeclick':
if ($_value) {
$append .= ',' . strtoupper($_key);
}
break;
default:
$smarty->trigger_error("[popup] unknown parameter $_key", E_USER_WARNING);
}
}
if (empty($text) && !isset($inarray) && empty($function)) {
$smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required");
return false;
}
if (empty($trigger)) {
$trigger = "onmouseover";
}
$retval = $trigger
. '="return overlib(\'' . preg_replace(array("!'!", "![\r\n]!"), array("\'", '\r'), $text) . '\'';
$retval .= $append . ');"';
if ($trigger == 'onmouseover') {
$retval .= ' onmouseout="nd();"';
}
return $retval;
}
// __END__

View File

@@ -0,0 +1,44 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {popup_init} function plugin
*
* Type: function<br>
* Name: popup_init<br>
* Purpose: initialize overlib
* @author Monte Ohrt <monte at ohrt dot com>
* @author 2024 Clemens Schwaighofer <gullevek at gullevek dot org>
* @param array
* @param Smarty
* @return string
*/
function smarty_function_popup_init($params, &$smarty)
{
/* $zindex = 1000;
if (!empty($params['zindex'])) {
$zindex = $params['zindex'];
} */
if (!empty($params['src'])) {
return str_replace(
[/*"{ZINDEX}", */"{SCRIPT_SOURCE}"],
[/*$zindex, */$params['src']],
// <!-- <div id="overDiv" style="position:absolute; visibility:hidden; z-index:{ZINDEX};"></div> -->
<<<HTML
<script type="text/javascript" language="JavaScript" src="{SCRIPT_SOURCE}"></script>
HTML
);
} else {
$smarty->trigger_error("popup_init: missing src parameter");
}
}
// __END__