2000-11-17 21:47:41 +00:00
|
|
|
<?
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Project: Smarty: the PHP compiled template engine
|
|
|
|
|
* File: Smarty.functions.php
|
|
|
|
|
* Author: Monte Ohrt <monte@ispi.net>
|
2000-11-20 22:31:38 +00:00
|
|
|
* Andrei Zmievski <andrei@ispi.net>
|
2000-11-17 21:47:41 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
2000-11-20 22:31:38 +00:00
|
|
|
Function: smarty_mod_escape
|
|
|
|
|
Purpose: Escape the string according to escapement type
|
2000-11-17 21:47:41 +00:00
|
|
|
\*======================================================================*/
|
2000-11-20 22:31:38 +00:00
|
|
|
function smarty_mod_escape($string, $esc_type = 'html')
|
2000-11-17 21:47:41 +00:00
|
|
|
{
|
2000-11-20 22:31:38 +00:00
|
|
|
switch ($esc_type) {
|
|
|
|
|
case 'html':
|
|
|
|
|
return htmlspecialchars($string);
|
2000-11-17 21:47:41 +00:00
|
|
|
|
2000-11-20 22:31:38 +00:00
|
|
|
case 'url':
|
|
|
|
|
return urlencode($string);
|
2000-11-17 21:47:41 +00:00
|
|
|
|
2000-11-20 22:31:38 +00:00
|
|
|
default:
|
|
|
|
|
return $string;
|
2000-11-17 21:47:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
2000-11-20 22:31:38 +00:00
|
|
|
Function: smarty_mod_truncate
|
|
|
|
|
Purpose: Truncate a string to a certain length if necessary,
|
|
|
|
|
optionally splitting in the middle of a word, and
|
|
|
|
|
appending the $etc string.
|
2000-11-17 21:47:41 +00:00
|
|
|
\*======================================================================*/
|
2000-11-20 22:31:38 +00:00
|
|
|
function smarty_mod_truncate($string, $length = 80, $etc = '...', $break_words = false)
|
2000-11-17 21:47:41 +00:00
|
|
|
{
|
2000-11-20 22:31:38 +00:00
|
|
|
if (strlen($string) > $length) {
|
|
|
|
|
$length -= strlen($etc);
|
|
|
|
|
$fragment = substr($string, 0, $length+1);
|
|
|
|
|
if ($break_words)
|
|
|
|
|
$fragment = substr($fragment, 0, -1);
|
|
|
|
|
else
|
|
|
|
|
$fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
|
|
|
|
|
return $fragment.$etc;
|
|
|
|
|
} else
|
|
|
|
|
return $string;
|
2000-11-17 21:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-20 22:31:38 +00:00
|
|
|
function smarty_mod_spacify($string, $spacify_char = ' ')
|
2000-11-17 21:47:41 +00:00
|
|
|
{
|
2000-11-20 22:31:38 +00:00
|
|
|
return implode($spacify_char, preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY));
|
2000-11-17 21:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|