* Name: from_to
* Date: 2008/09/07
* Input:
*
* - from (required) - string * - to (required) - string * - separator (optional) - string default " ~ ". ie "-", "~* Examples: *
". 常にエスケープせずに出力するので注意. * - escape (optional) - string default true. other false. エスケープするか否か。 *
* {html_radios from="-1" to="2"} → -1 ~ 2
* {html_radios from="B" to="a" separator="~
"} → B~
a
*
* @author Seasoft 塚田将久
* @param array
* @param Smarty
* @return string
* @uses smarty_function_escape_special_chars()
*/
function smarty_function_from_to($params, &$smarty) {
require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars');
$from = null;
$to = null;
$separator = ' ~ ';
$escape = true;
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'from':
case 'to':
case 'separator':
case 'escape':
$$_key = (string) $_val;
break;
default:
$smarty->trigger_error("from_to: extra attribute '$_key' is unknown.", E_USER_NOTICE);
break;
}
}
if ($escape) {
$from = smarty_function_escape_special_chars($from);
$to = smarty_function_escape_special_chars($to);
}
if ($from === $to) {
return $from;
} else {
return $from . $separator . $to;
}
}