Formatting.

This commit is contained in:
andrey
2001-04-12 20:14:30 +00:00
parent f5c945f7cc
commit 997469c2be
2 changed files with 160 additions and 192 deletions

View File

@@ -119,7 +119,7 @@ class Smarty
var $template_resource_handlers = array(); // where resource handlers are mapped
var $version = "1.3.2"; // Smarty version number
var $version = '1.3.2'; // Smarty version number
var $show_info_header = true; // display info header at top of page output
/**************************************************************************/
@@ -374,8 +374,6 @@ class Smarty
else
$info_header = "";
$this->_fetch_compile_path($tpl_file,$compile_path);
// if we just need to display the results, don't perform output
// buffering - for speed
if ($display && !$this->caching) {
@@ -413,6 +411,7 @@ class Smarty
{
// get path to where compiled template is (to be) saved
$this->_fetch_compile_path($tpl_file, $compile_path);
// test if template needs to be compiled
if (!$this->force_compile && $this->_compiled_template_exists($compile_path)) {
if (!$this->compile_check) {
@@ -489,41 +488,40 @@ class Smarty
function _fetch_template_source($tpl_path, &$template_source, &$template_timestamp)
{
// split tpl_path by the first colon
$tpl_path_parts = preg_split("/:/",$tpl_path,2);
$tpl_path_parts = explode(':', $tpl_path, 2);
if (count($tpl_path_parts) == 1) {
// no resource type, treat as type "file"
$resource_type = "file";
$filename = $tpl_path_parts[0];
$resource_type = 'file';
$resource_name = $tpl_path_parts[0];
} else {
$resource_type = $tpl_path_parts[0];
$filename = $tpl_path_parts[1];
$resource_name = $tpl_path_parts[1];
}
switch ($resource_type) {
case "file":
if(substr($filename,0,1) != "/") {
case 'file':
if ($resource_name{0} != '/') {
// relative pathname to $template_dir
$filename = $this->template_dir.'/'.$filename;
$resource_name = $this->template_dir.'/'.$resource_name;
}
if (file_exists($filename)) {
$template_source = $this->_read_file($filename);
$template_timestamp = filemtime($filename);
if (file_exists($resource_name)) {
$template_source = $this->_read_file($resource_name);
$template_timestamp = filemtime($resource_name);
return true;
} else {
$this->_set_error_msg("unable to read template resource: \"$tpl_path.\"");
$this->_trigger_error_msg();
$this->_trigger_error_msg("unable to read template resource: \"$tpl_path.\"");
return false;
}
break;
default:
$this->_set_error_msg("unknown resource type: \"$resource_type.\"");
$this->_trigger_error_msg();
return false;
break;
}
return true;
default:
$this->_trigger_error_msg("unknown resource type: \"$resource_type.\"");
return false;
break;
}
return true;
}
@@ -533,27 +531,26 @@ class Smarty
\*======================================================================*/
function _compile_template($tpl_file, $template_source, &$template_compiled)
{
include_once "Smarty_Compiler.class.php";
include_once("Smarty_Compiler.class.php");
$smarty_compiler = new Smarty_Compiler;
$smarty_compile = new Smarty_Compiler;
$smarty_compiler->template_dir = $this->template_dir;
$smarty_compiler->compile_dir = $this->compile_dir;
$smarty_compiler->config_dir = $this->config_dir;
$smarty_compiler->force_compile = $this->force_compile;
$smarty_compiler->caching = $this->caching;
$smarty_compiler->php_handling = $this->php_handling;
$smarty_compiler->left_delimiter = $this->left_delimiter;
$smarty_compiler->right_delimiter = $this->right_delimiter;
$smarty_compiler->custom_funcs = $this->custom_funcs;
$smarty_compiler->custom_mods = $this->custom_mods;
$smarty_compiler->version = $this->version;
$smarty_compile->template_dir = $this->template_dir;
$smarty_compile->compile_dir = $this->compile_dir;
$smarty_compile->config_dir = $this->config_dir;
$smarty_compile->force_compile = $this->force_compile;
$smarty_compile->caching = $this->caching;
$smarty_compile->php_handling = $this->php_handling;
$smarty_compile->left_delimiter = $this->left_delimiter;
$smarty_compile->right_delimiter = $this->right_delimiter;
$smarty_compile->custom_funcs = $this->custom_funcs;
$smarty_compile->custom_mods = $this->custom_mods;
$smarty_compile->version = $this->version;
if($smarty_compile->_compile_file($tpl_file,$template_source, $template_compiled))
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
return true;
else {
$this->_error_msg = $smarty_compile->_error_msg;
$this->_trigger_error_msg($smarty_compiler->_error_msg);
return false;
}
}
@@ -568,10 +565,8 @@ class Smarty
extract($_smarty_def_vars);
extract($_smarty_include_vars);
$this->_fetch_compile_path($_smarty_include_tpl_file,$compile_path);
$this->_process_template($_smarty_include_tpl_file, $compile_path);
include($compile_path);
}
/*======================================================================*\
@@ -622,8 +617,7 @@ class Smarty
{
if (!($fd = fopen($filename, 'r'))) {
$this->_set_error_msg("problem reading '$filename.'");
$this->_trigger_error_msg();
$this->_trigger_error_msg("problem reading '$filename.'");
return false;
}
flock($fd, LOCK_SH);
@@ -642,8 +636,7 @@ class Smarty
$this->_create_dir_structure(dirname($filename));
if (!($fd = fopen($filename, 'a'))) {
$this->_set_error_msg("problem writing '$filename.'");
$this->_trigger_error_msg();
$this->_trigger_error_msg("problem writing '$filename.'");
return false;
}
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
@@ -704,8 +697,7 @@ class Smarty
foreach ($dir_parts as $dir_part) {
$new_dir .= $dir_part;
if (!file_exists($new_dir) && !mkdir($new_dir, 0701)) {
$this->_set_error_msg("problem creating directory \"$dir\"");
$this->_trigger_error_msg();
$this->_trigger_error_msg("problem creating directory \"$dir\"");
return false;
}
$new_dir .= '/';
@@ -722,22 +714,14 @@ class Smarty
return preg_replace('![\\$]\d!', '\\\\\\0', $string);
}
/*======================================================================*\
Function: _set_error_msg()
Purpose: set the error message
\*======================================================================*/
function _set_error_msg($error_msg)
{
$this->_error_msg="Smarty error: $error_msg";
return true;
}
/*======================================================================*\
Function: _trigger_error_msg
Purpose: trigger Smarty error
\*======================================================================*/
function _trigger_error_msg($error_type = E_USER_ERROR)
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
{
trigger_error($this->_error_msg, $error_type);
trigger_error($error_msg, $error_type);
}
}

View File

@@ -119,7 +119,7 @@ class Smarty
var $template_resource_handlers = array(); // where resource handlers are mapped
var $version = "1.3.2"; // Smarty version number
var $version = '1.3.2'; // Smarty version number
var $show_info_header = true; // display info header at top of page output
/**************************************************************************/
@@ -374,8 +374,6 @@ class Smarty
else
$info_header = "";
$this->_fetch_compile_path($tpl_file,$compile_path);
// if we just need to display the results, don't perform output
// buffering - for speed
if ($display && !$this->caching) {
@@ -413,6 +411,7 @@ class Smarty
{
// get path to where compiled template is (to be) saved
$this->_fetch_compile_path($tpl_file, $compile_path);
// test if template needs to be compiled
if (!$this->force_compile && $this->_compiled_template_exists($compile_path)) {
if (!$this->compile_check) {
@@ -489,41 +488,40 @@ class Smarty
function _fetch_template_source($tpl_path, &$template_source, &$template_timestamp)
{
// split tpl_path by the first colon
$tpl_path_parts = preg_split("/:/",$tpl_path,2);
$tpl_path_parts = explode(':', $tpl_path, 2);
if (count($tpl_path_parts) == 1) {
// no resource type, treat as type "file"
$resource_type = "file";
$filename = $tpl_path_parts[0];
$resource_type = 'file';
$resource_name = $tpl_path_parts[0];
} else {
$resource_type = $tpl_path_parts[0];
$filename = $tpl_path_parts[1];
$resource_name = $tpl_path_parts[1];
}
switch ($resource_type) {
case "file":
if(substr($filename,0,1) != "/") {
case 'file':
if ($resource_name{0} != '/') {
// relative pathname to $template_dir
$filename = $this->template_dir.'/'.$filename;
$resource_name = $this->template_dir.'/'.$resource_name;
}
if (file_exists($filename)) {
$template_source = $this->_read_file($filename);
$template_timestamp = filemtime($filename);
if (file_exists($resource_name)) {
$template_source = $this->_read_file($resource_name);
$template_timestamp = filemtime($resource_name);
return true;
} else {
$this->_set_error_msg("unable to read template resource: \"$tpl_path.\"");
$this->_trigger_error_msg();
$this->_trigger_error_msg("unable to read template resource: \"$tpl_path.\"");
return false;
}
break;
default:
$this->_set_error_msg("unknown resource type: \"$resource_type.\"");
$this->_trigger_error_msg();
return false;
break;
}
return true;
default:
$this->_trigger_error_msg("unknown resource type: \"$resource_type.\"");
return false;
break;
}
return true;
}
@@ -533,27 +531,26 @@ class Smarty
\*======================================================================*/
function _compile_template($tpl_file, $template_source, &$template_compiled)
{
include_once "Smarty_Compiler.class.php";
include_once("Smarty_Compiler.class.php");
$smarty_compiler = new Smarty_Compiler;
$smarty_compile = new Smarty_Compiler;
$smarty_compiler->template_dir = $this->template_dir;
$smarty_compiler->compile_dir = $this->compile_dir;
$smarty_compiler->config_dir = $this->config_dir;
$smarty_compiler->force_compile = $this->force_compile;
$smarty_compiler->caching = $this->caching;
$smarty_compiler->php_handling = $this->php_handling;
$smarty_compiler->left_delimiter = $this->left_delimiter;
$smarty_compiler->right_delimiter = $this->right_delimiter;
$smarty_compiler->custom_funcs = $this->custom_funcs;
$smarty_compiler->custom_mods = $this->custom_mods;
$smarty_compiler->version = $this->version;
$smarty_compile->template_dir = $this->template_dir;
$smarty_compile->compile_dir = $this->compile_dir;
$smarty_compile->config_dir = $this->config_dir;
$smarty_compile->force_compile = $this->force_compile;
$smarty_compile->caching = $this->caching;
$smarty_compile->php_handling = $this->php_handling;
$smarty_compile->left_delimiter = $this->left_delimiter;
$smarty_compile->right_delimiter = $this->right_delimiter;
$smarty_compile->custom_funcs = $this->custom_funcs;
$smarty_compile->custom_mods = $this->custom_mods;
$smarty_compile->version = $this->version;
if($smarty_compile->_compile_file($tpl_file,$template_source, $template_compiled))
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
return true;
else {
$this->_error_msg = $smarty_compile->_error_msg;
$this->_trigger_error_msg($smarty_compiler->_error_msg);
return false;
}
}
@@ -568,10 +565,8 @@ class Smarty
extract($_smarty_def_vars);
extract($_smarty_include_vars);
$this->_fetch_compile_path($_smarty_include_tpl_file,$compile_path);
$this->_process_template($_smarty_include_tpl_file, $compile_path);
include($compile_path);
}
/*======================================================================*\
@@ -622,8 +617,7 @@ class Smarty
{
if (!($fd = fopen($filename, 'r'))) {
$this->_set_error_msg("problem reading '$filename.'");
$this->_trigger_error_msg();
$this->_trigger_error_msg("problem reading '$filename.'");
return false;
}
flock($fd, LOCK_SH);
@@ -642,8 +636,7 @@ class Smarty
$this->_create_dir_structure(dirname($filename));
if (!($fd = fopen($filename, 'a'))) {
$this->_set_error_msg("problem writing '$filename.'");
$this->_trigger_error_msg();
$this->_trigger_error_msg("problem writing '$filename.'");
return false;
}
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
@@ -704,8 +697,7 @@ class Smarty
foreach ($dir_parts as $dir_part) {
$new_dir .= $dir_part;
if (!file_exists($new_dir) && !mkdir($new_dir, 0701)) {
$this->_set_error_msg("problem creating directory \"$dir\"");
$this->_trigger_error_msg();
$this->_trigger_error_msg("problem creating directory \"$dir\"");
return false;
}
$new_dir .= '/';
@@ -722,22 +714,14 @@ class Smarty
return preg_replace('![\\$]\d!', '\\\\\\0', $string);
}
/*======================================================================*\
Function: _set_error_msg()
Purpose: set the error message
\*======================================================================*/
function _set_error_msg($error_msg)
{
$this->_error_msg="Smarty error: $error_msg";
return true;
}
/*======================================================================*\
Function: _trigger_error_msg
Purpose: trigger Smarty error
\*======================================================================*/
function _trigger_error_msg($error_type = E_USER_ERROR)
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
{
trigger_error($this->_error_msg, $error_type);
trigger_error($error_msg, $error_type);
}
}