mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 11:54:26 +02:00
*** empty log message ***
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
<?
|
<?
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Project: Smarty: the PHP compiled template engine
|
* Project: Smarty: the PHP compiled template engine
|
||||||
* File: Smarty.addons.php
|
* File: Smarty.addons.php
|
||||||
* Author: Monte Ohrt <monte@ispi.net>
|
* Author: Monte Ohrt <monte@ispi.net>
|
||||||
* Andrei Zmievski <andrei@ispi.net>
|
* Andrei Zmievski <andrei@ispi.net>
|
||||||
* Version: 1.2.3
|
* Version: 1.2.3
|
||||||
* Copyright: 2001 ispi of Lincoln, Inc.
|
* Copyright: 2001 ispi of Lincoln, Inc.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@@ -43,101 +43,101 @@
|
|||||||
|
|
||||||
function _smarty_mod_handler()
|
function _smarty_mod_handler()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
list($func_name, $map_array) = array_splice($args, 0, 2);
|
list($func_name, $map_array) = array_splice($args, 0, 2);
|
||||||
$var = $args[0];
|
$var = $args[0];
|
||||||
|
|
||||||
if ($map_array && is_array($var)) {
|
if ($map_array && is_array($var)) {
|
||||||
foreach ($var as $key => $val) {
|
foreach ($var as $key => $val) {
|
||||||
$args[0] = $val;
|
$args[0] = $val;
|
||||||
$var[$key] = call_user_func_array($func_name, $args);
|
$var[$key] = call_user_func_array($func_name, $args);
|
||||||
}
|
}
|
||||||
return $var;
|
return $var;
|
||||||
} else {
|
} else {
|
||||||
return call_user_func_array($func_name, $args);
|
return call_user_func_array($func_name, $args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: smarty_mod_escape
|
Function: smarty_mod_escape
|
||||||
Purpose: Escape the string according to escapement type
|
Purpose: Escape the string according to escapement type
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function smarty_mod_escape($string, $esc_type = 'html')
|
function smarty_mod_escape($string, $esc_type = 'html')
|
||||||
{
|
{
|
||||||
switch ($esc_type) {
|
switch ($esc_type) {
|
||||||
case 'html':
|
case 'html':
|
||||||
return htmlspecialchars($string);
|
return htmlspecialchars($string);
|
||||||
|
|
||||||
case 'url':
|
case 'url':
|
||||||
return urlencode($string);
|
return urlencode($string);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: smarty_mod_truncate
|
Function: smarty_mod_truncate
|
||||||
Purpose: Truncate a string to a certain length if necessary,
|
Purpose: Truncate a string to a certain length if necessary,
|
||||||
optionally splitting in the middle of a word, and
|
optionally splitting in the middle of a word, and
|
||||||
appending the $etc string.
|
appending the $etc string.
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function smarty_mod_truncate($string, $length = 80, $etc = '...', $break_words = false)
|
function smarty_mod_truncate($string, $length = 80, $etc = '...', $break_words = false)
|
||||||
{
|
{
|
||||||
if ($length == 0)
|
if ($length == 0)
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
if (strlen($string) > $length) {
|
if (strlen($string) > $length) {
|
||||||
$length -= strlen($etc);
|
$length -= strlen($etc);
|
||||||
$fragment = substr($string, 0, $length+1);
|
$fragment = substr($string, 0, $length+1);
|
||||||
if ($break_words)
|
if ($break_words)
|
||||||
$fragment = substr($fragment, 0, -1);
|
$fragment = substr($fragment, 0, -1);
|
||||||
else
|
else
|
||||||
$fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
|
$fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
|
||||||
return $fragment.$etc;
|
return $fragment.$etc;
|
||||||
} else
|
} else
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function smarty_mod_spacify($string, $spacify_char = ' ')
|
function smarty_mod_spacify($string, $spacify_char = ' ')
|
||||||
{
|
{
|
||||||
return implode($spacify_char, preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY));
|
return implode($spacify_char, preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function smarty_mod_date_format($string, $format="%b %e, %Y")
|
function smarty_mod_date_format($string, $format="%b %e, %Y")
|
||||||
{
|
{
|
||||||
return strftime($format, $string);
|
return strftime($format, $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function smarty_mod_string_format($string, $format)
|
function smarty_mod_string_format($string, $format)
|
||||||
{
|
{
|
||||||
return sprintf($format, $string);
|
return sprintf($format, $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_mod_replace($string, $search, $replace)
|
function smarty_mod_replace($string, $search, $replace)
|
||||||
{
|
{
|
||||||
return str_replace($search, $replace, $string);
|
return str_replace($search, $replace, $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_mod_strip_tags($string, $replace_with_space = true)
|
function smarty_mod_strip_tags($string, $replace_with_space = true)
|
||||||
{
|
{
|
||||||
if ($replace_with_space)
|
if ($replace_with_space)
|
||||||
return preg_replace('!<[^>]*?>!', ' ', $string);
|
return preg_replace('!<[^>]*?>!', ' ', $string);
|
||||||
else
|
else
|
||||||
return strip_tags($string);
|
return strip_tags($string);
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_mod_default($string, $default="")
|
function smarty_mod_default($string, $default="")
|
||||||
{
|
{
|
||||||
if(empty($string))
|
if(empty($string))
|
||||||
return $default;
|
return $default;
|
||||||
else
|
else
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*============================================*\
|
/*============================================*\
|
||||||
@@ -145,116 +145,118 @@ function smarty_mod_default($string, $default="")
|
|||||||
\*============================================*/
|
\*============================================*/
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: smarty_func_html_options
|
Function: smarty_func_html_options
|
||||||
Purpose: Prints the list of <option> tags generated from
|
Purpose: Prints the list of <option> tags generated from
|
||||||
the passed parameters
|
the passed parameters
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function smarty_func_html_options()
|
function smarty_func_html_options()
|
||||||
{
|
{
|
||||||
$print_result = true;
|
$print_result = true;
|
||||||
|
|
||||||
extract(func_get_arg(0));
|
extract(func_get_arg(0));
|
||||||
|
|
||||||
$html_result = "";
|
$html_result = "";
|
||||||
|
|
||||||
settype($selected, 'array');
|
settype($selected, 'array');
|
||||||
if (isset($options)) {
|
if (isset($options)) {
|
||||||
settype($options, 'array');
|
settype($options, 'array');
|
||||||
foreach ($options as $key => $value) {
|
foreach ($options as $key => $value) {
|
||||||
$html_result .= "<option value=\"$key\"";
|
$html_result .= "<option value=\"$key\"";
|
||||||
if (in_array($key, $selected))
|
if (in_array($key, $selected))
|
||||||
$html_result .= " selected";
|
$html_result .= " selected";
|
||||||
$html_result .= ">$value</option>\n";
|
$html_result .= ">$value</option>\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
settype($output, 'array');
|
settype($output, 'array');
|
||||||
settype($values, 'array');
|
settype($values, 'array');
|
||||||
for ($i = 0; $i < count($output); $i++) {
|
for ($i = 0; $i < count($output); $i++) {
|
||||||
/* By default, check value against $selected */
|
/* By default, check value against $selected */
|
||||||
$sel_check = $values[$i];
|
$sel_check = $values[$i];
|
||||||
$html_result .= "<option";
|
$html_result .= "<option";
|
||||||
if ($i < count($values))
|
if ($i < count($values))
|
||||||
$html_result .= " value=\"".$values[$i]."\"";
|
$html_result .= " value=\"".$values[$i]."\"";
|
||||||
else
|
else
|
||||||
$sel_check = $output[$i]; /* if more outputs than values, then
|
$sel_check = $output[$i]; /* if more outputs than values, then
|
||||||
check output against $selected */
|
check output against $selected */
|
||||||
if (in_array($sel_check, $selected))
|
if (in_array($sel_check, $selected))
|
||||||
$html_result .= " selected";
|
$html_result .= " selected";
|
||||||
$html_result .= ">".$output[$i]."</option>\n";
|
$html_result .= ">".$output[$i]."</option>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($print_result)
|
if ($print_result)
|
||||||
print $html_result;
|
print $html_result;
|
||||||
else
|
else
|
||||||
return $html_result;
|
return $html_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: smarty_func_html_select_date
|
Function: smarty_func_html_select_date
|
||||||
Purpose: Prints the dropdowns for date selection.
|
Purpose: Prints the dropdowns for date selection.
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function smarty_func_html_select_date()
|
function smarty_func_html_select_date()
|
||||||
{
|
{
|
||||||
/* Default values. */
|
/* Default values. */
|
||||||
$prefix = "Date_";
|
$prefix = "Date_";
|
||||||
$time = time();
|
$time = time();
|
||||||
$start_year = strftime("%Y");
|
$start_year = strftime("%Y");
|
||||||
$end_year = $start_year;
|
$end_year = $start_year;
|
||||||
$display_days = true;
|
$display_days = true;
|
||||||
$display_months = true;
|
$display_months = true;
|
||||||
$display_years = true;
|
$display_years = true;
|
||||||
$month_format = "%B";
|
$month_format = "%B";
|
||||||
$day_format = "%02d";
|
$day_format = "%02d";
|
||||||
$year_as_text = false;
|
$year_as_text = false;
|
||||||
|
|
||||||
extract(func_get_arg(0));
|
extract(func_get_arg(0));
|
||||||
|
|
||||||
$html_result = "";
|
$html_result = "";
|
||||||
|
|
||||||
if ($display_months) {
|
if ($display_months) {
|
||||||
$month_names = array();
|
$month_names = array();
|
||||||
|
|
||||||
for ($i = 1; $i <= 12; $i++)
|
for ($i = 1; $i <= 12; $i++)
|
||||||
$month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
|
$month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
|
||||||
|
|
||||||
$html_result .= '<select name="'.$prefix.'Month">'."\n";
|
$html_result .= '<select name="'.$prefix.'Month">'."\n";
|
||||||
$html_result .= smarty_func_html_options(array('output' => $month_names,
|
$html_result .= smarty_func_html_options(array('output' => $month_names,
|
||||||
'values' => range(1, 12),
|
'values' => range(1, 12),
|
||||||
'selected' => strftime("%m", $time),
|
'selected' => strftime("%m", $time),
|
||||||
'print_result' => false));
|
'print_result' => false));
|
||||||
$html_result .= "</select>\n";
|
$html_result .= "</select>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($display_days) {
|
if ($display_days) {
|
||||||
$days = range(1, 31);
|
$days = range(1, 31);
|
||||||
array_walk($days, create_function('&$x', '$x = sprintf("'.$day_format.'", $x);'));
|
array_walk($days, create_function('&$x', '$x = sprintf("'.$day_format.'", $x);'));
|
||||||
|
|
||||||
$html_result .= '<select name="'.$prefix.'Day">'."\n";
|
$html_result .= '<select name="'.$prefix.'Day">'."\n";
|
||||||
$html_result .= smarty_func_html_options(array('output' => $days,
|
$html_result .= smarty_func_html_options(array('output' => $days,
|
||||||
'values' => range(1, 31),
|
'values' => range(1, 31),
|
||||||
'selected' => strftime("%d", $time),
|
'selected' => strftime("%d", $time),
|
||||||
'print_result' => false));
|
'print_result' => false));
|
||||||
$html_result .= "</select>\n";
|
$html_result .= "</select>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($display_years) {
|
if ($display_years) {
|
||||||
if ($year_as_text) {
|
if ($year_as_text) {
|
||||||
$html_result .= '<input type="text" name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">';
|
$html_result .= '<input type="text" name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">';
|
||||||
} else {
|
} else {
|
||||||
$years = range($start_year, $end_year);
|
$years = range($start_year, $end_year);
|
||||||
|
|
||||||
$html_result .= '<select name="'.$prefix.'Year">'."\n";
|
$html_result .= '<select name="'.$prefix.'Year">'."\n";
|
||||||
$html_result .= smarty_func_html_options(array('output' => $years,
|
$html_result .= smarty_func_html_options(array('output' => $years,
|
||||||
'values' => $years,
|
'values' => $years,
|
||||||
'selected' => strftime("%Y", $time),
|
'selected' => strftime("%Y", $time),
|
||||||
'print_result' => false));
|
'print_result' => false));
|
||||||
$html_result .= "</select>\n";
|
$html_result .= "</select>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print $html_result;
|
print $html_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vim: set expandtab: */
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user