*** empty log message ***

This commit is contained in:
andrey
2000-11-20 22:31:38 +00:00
parent 536b66a58c
commit f00e3f52e1
7 changed files with 73 additions and 172 deletions

View File

@@ -4,165 +4,54 @@
* Project: Smarty: the PHP compiled template engine
* File: Smarty.functions.php
* Author: Monte Ohrt <monte@ispi.net>
* Andrei Zmievski <andrei@ispi.net>
*
* This is the smarty custom function file.
* To add your own functions, name the function
* smarty_[funcname], then add the function name
* to the $registered_functions array in the
* smarty.class.php file. You may then call your
* function from a template file like so: {funcname [$var]...}
*/
/*======================================================================*\
Function: htmlesc
Purpose: html escape template vars
Function: smarty_mod_escape
Purpose: Escape the string according to escapement type
\*======================================================================*/
function smarty_htmlesc($var)
function smarty_mod_escape($string, $esc_type = 'html')
{
print htmlspecialchars($var);
}
switch ($esc_type) {
case 'html':
return htmlspecialchars($string);
/*======================================================================*\
Function: urlesc
Purpose: URL escape template vars
\*======================================================================*/
case 'url':
return urlencode($string);
function smarty_urlesc($var)
{
print urlencode($var);
}
/*======================================================================*\
Function: default
Purpose: display a default value for empty template vars
\*======================================================================*/
function smarty_default($var,$default_val)
{
if(empty($var))
print $default_val;
else
print $var;
}
/*======================================================================*\
Function: configload
Purpose: load vars from a config file
Notes: config files must be in this format:
key = "val"
key2 = "val2"
\*======================================================================*/
function smarty_configload($config_file)
{
global $_config_vars;
if(!is_array($_config_vars))
$_config_vars = array();
// only load in the config file
if(! ($fd = fopen($config_file,"r")))
{
print ("<!-- problem reading \"$config_file.\" -->");
return false;
default:
return $string;
}
$config_contents = fread($fd,filesize($config_file));
fclose($fd);
$contents_array = preg_split("/[\r\n]+/", $config_contents);
// read in the variables from the config file
foreach($contents_array as $current_line)
{
if (preg_match("/^\w+/",$current_line))
{
if(preg_match("/^([^\=]+)=(.*)/", $current_line, $preg_results))
{
$config_key = $preg_results[1];
$config_val = trim($preg_results[2]);
// remove tabs and spaces from key
$key = preg_replace("/[ \t]/", "", $config_key);
// is value surrounded by quotes?
if (!preg_match("/^['\"]/", $config_val))
{
$val = $config_val;
}
else
{
// Strip the leading and trailing quotes
$val = preg_replace("/^['\"]/","",$config_val);
$val = preg_replace("/['\"]$/","",$val);
}
// store the key and val in the config array
$_config_vars[$key] = $val;
}
}
}
return true;
}
/*======================================================================*\
Function: configclear
Purpose: clear config vars
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.
\*======================================================================*/
function smarty_configclear()
function smarty_mod_truncate($string, $length = 80, $etc = '...', $break_words = false)
{
global $_config_vars;
$_config_vars = array();
return true;
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;
}
/*======================================================================*\
Function: configprint
Purpose: print a var from config
\*======================================================================*/
function smarty_configprint($var)
function smarty_mod_spacify($string, $spacify_char = ' ')
{
global $_config_vars;
if (isset($_config_vars[$var]))
print $_config_vars[$var];
else
print "<!-- no value for $var in $config_file -->";
return true;
return implode($spacify_char, preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY));
}
/*======================================================================*\
Function: configset
Purpose: set a var from config
\*======================================================================*/
function smarty_configset($var,&$setvar)
{
global $_config_vars;
if (isset($_config_vars[$var]))
$setvar = $_config_vars[$var];
else
return false;
return true;
}
?>

View File

@@ -43,6 +43,7 @@ class Smarty
// registered template functions
// NOTE: leave off the "smarty_" prefix on the actual PHP function name
/*
var $registered_functions = array( "htmlesc",
"urlesc",
"default",
@@ -51,13 +52,18 @@ class Smarty
"configprint",
"configset"
);
*/
var $_modifiers = array( "lower" => "smarty_mod_lower",
"upper" => "smarty_mod_upper"
var $_modifiers = array( 'lower' => 'strtolower',
'upper' => 'strtoupper',
'capitalize' => 'ucwords',
'escape' => 'smarty_mod_escape',
'truncate' => 'smarty_mod_truncate',
'spacify' => 'smarty_mod_spacify'
);
// internal vars
var $errorMsg = false; // error messages
var $_error_msg = false; // error messages
var $_tpl_vars = array();
var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part
@@ -162,7 +168,7 @@ class Smarty
// exit if recursion depth is met
if($this->max_recursion_depth != 0 && $depth >= $this->max_recursion_depth)
{
$this->_set_errorMsg("recursion depth of $depth reached on $tpl_dir/$curr_file. exiting.");
$this->_set_error_msg("recursion depth of $depth reached on $tpl_dir/$curr_file. exiting.");
return false;
}
if(is_dir($tpl_dir))
@@ -198,7 +204,7 @@ class Smarty
else
{
// invalid file type, skipping
$this->_set_errorMsg("Invalid filetype for $filepath, skipping");
$this->_set_error_msg("Invalid filetype for $filepath, skipping");
continue;
}
}
@@ -206,7 +212,7 @@ class Smarty
}
else
{
$this->_set_errorMsg("Directory \"$tpl_dir\" does not exist or is not a directory.");
$this->_set_error_msg("Directory \"$tpl_dir\" does not exist or is not a directory.");
return false;
}
return true;
@@ -234,7 +240,7 @@ class Smarty
if(!file_exists($compile_dir))
if(!mkdir($compile_dir,0755))
{
$this->_set_errorMsg("problem creating directory \"$compile_dir\"");
$this->_set_error_msg("problem creating directory \"$compile_dir\"");
return false;
}
// compile the template file if none exists or has been modified
@@ -253,7 +259,7 @@ class Smarty
}
else
{
$this->_set_errorMsg("problem matching \"$filepath.\"");
$this->_set_error_msg("problem matching \"$filepath.\"");
return false;
}
return true;
@@ -772,7 +778,7 @@ class Smarty
{
if(! ($fd = fopen($filename,"r")))
{
$this->_set_errorMsg("problem reading \"$filename.\"");
$this->_set_error_msg("problem reading \"$filename.\"");
return false;
}
$contents = fread($fd,filesize($filename));
@@ -789,7 +795,7 @@ class Smarty
{
if(!($fd = fopen($filename,"w")))
{
$this->_set_errorMsg("problem writing \"$filename.\"");
$this->_set_error_msg("problem writing \"$filename.\"");
return false;
}
fwrite($fd,$contents);
@@ -798,13 +804,13 @@ class Smarty
}
/*======================================================================*\
Function: _set_errorMsg()
Function: _set_error_msg()
Purpose: set the error message
\*======================================================================*/
function _set_errorMsg($errorMsg)
function _set_error_msg($error_msg)
{
$this->errorMsg="smarty error: $errorMsg";
$this->_error_msg="smarty error: $error_msg";
return true;
}

View File

@@ -4,7 +4,7 @@ require("Smarty.class.php");
$smarty = new Smarty;
$smarty->assign("Name","Fred");
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),

View File

@@ -1,9 +1,9 @@
{config_load file=test.conf}
Title: {#title#}
Title: {#title#|capitalize}
{* A simple variable test *}
hello, my name is {$Name}.
hello, my name is {$Name}
My interests are:
{section name=outer loop=$FirstName}

View File

@@ -4,7 +4,7 @@ require("Smarty.class.php");
$smarty = new Smarty;
$smarty->assign("Name","Fred");
$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),

View File

@@ -43,6 +43,7 @@ class Smarty
// registered template functions
// NOTE: leave off the "smarty_" prefix on the actual PHP function name
/*
var $registered_functions = array( "htmlesc",
"urlesc",
"default",
@@ -51,13 +52,18 @@ class Smarty
"configprint",
"configset"
);
*/
var $_modifiers = array( "lower" => "smarty_mod_lower",
"upper" => "smarty_mod_upper"
var $_modifiers = array( 'lower' => 'strtolower',
'upper' => 'strtoupper',
'capitalize' => 'ucwords',
'escape' => 'smarty_mod_escape',
'truncate' => 'smarty_mod_truncate',
'spacify' => 'smarty_mod_spacify'
);
// internal vars
var $errorMsg = false; // error messages
var $_error_msg = false; // error messages
var $_tpl_vars = array();
var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part
@@ -162,7 +168,7 @@ class Smarty
// exit if recursion depth is met
if($this->max_recursion_depth != 0 && $depth >= $this->max_recursion_depth)
{
$this->_set_errorMsg("recursion depth of $depth reached on $tpl_dir/$curr_file. exiting.");
$this->_set_error_msg("recursion depth of $depth reached on $tpl_dir/$curr_file. exiting.");
return false;
}
if(is_dir($tpl_dir))
@@ -198,7 +204,7 @@ class Smarty
else
{
// invalid file type, skipping
$this->_set_errorMsg("Invalid filetype for $filepath, skipping");
$this->_set_error_msg("Invalid filetype for $filepath, skipping");
continue;
}
}
@@ -206,7 +212,7 @@ class Smarty
}
else
{
$this->_set_errorMsg("Directory \"$tpl_dir\" does not exist or is not a directory.");
$this->_set_error_msg("Directory \"$tpl_dir\" does not exist or is not a directory.");
return false;
}
return true;
@@ -234,7 +240,7 @@ class Smarty
if(!file_exists($compile_dir))
if(!mkdir($compile_dir,0755))
{
$this->_set_errorMsg("problem creating directory \"$compile_dir\"");
$this->_set_error_msg("problem creating directory \"$compile_dir\"");
return false;
}
// compile the template file if none exists or has been modified
@@ -253,7 +259,7 @@ class Smarty
}
else
{
$this->_set_errorMsg("problem matching \"$filepath.\"");
$this->_set_error_msg("problem matching \"$filepath.\"");
return false;
}
return true;
@@ -772,7 +778,7 @@ class Smarty
{
if(! ($fd = fopen($filename,"r")))
{
$this->_set_errorMsg("problem reading \"$filename.\"");
$this->_set_error_msg("problem reading \"$filename.\"");
return false;
}
$contents = fread($fd,filesize($filename));
@@ -789,7 +795,7 @@ class Smarty
{
if(!($fd = fopen($filename,"w")))
{
$this->_set_errorMsg("problem writing \"$filename.\"");
$this->_set_error_msg("problem writing \"$filename.\"");
return false;
}
fwrite($fd,$contents);
@@ -798,13 +804,13 @@ class Smarty
}
/*======================================================================*\
Function: _set_errorMsg()
Function: _set_error_msg()
Purpose: set the error message
\*======================================================================*/
function _set_errorMsg($errorMsg)
function _set_error_msg($error_msg)
{
$this->errorMsg="smarty error: $errorMsg";
$this->_error_msg="smarty error: $error_msg";
return true;
}

View File

@@ -1,9 +1,9 @@
{config_load file=test.conf}
Title: {#title#}
Title: {#title#|capitalize}
{* A simple variable test *}
hello, my name is {$Name}.
hello, my name is {$Name}
My interests are:
{section name=outer loop=$FirstName}