- bugfix error handling at stream resources

This commit is contained in:
uwe.tews@googlemail.com
2011-05-14 11:11:52 +00:00
parent 86586e5af4
commit 7c0e3c89c1
3 changed files with 110 additions and 110 deletions

View File

@@ -1,6 +1,6 @@
===== SVN trunk ===== ===== SVN trunk =====
14/05/2011 14/05/2011
- bugfix fopen() error handling at stream resources - bugfix error handling at stream resources
13/05/2011 13/05/2011
- bugfix condition starting with "-" did fail at {if} and {while} tags - bugfix condition starting with "-" did fail at {if} and {while} tags

View File

@@ -2,12 +2,12 @@
/** /**
* Smarty Internal Plugin Data * Smarty Internal Plugin Data
* *
* This file contains the basic classes and methodes for template and variable creation * This file contains the basic classes and methodes for template and variable creation
* *
* @package Smarty * @package Smarty
* @subpackage Templates * @subpackage Templates
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
@@ -19,7 +19,7 @@ class Smarty_Internal_Data {
/** /**
* assigns a Smarty variable * assigns a Smarty variable
* *
* @param array $ |string $tpl_var the template variable name(s) * @param array $ |string $tpl_var the template variable name(s)
* @param mixed $value the value to assign * @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @param boolean $nocache if true any output of this variable will be not cached
@@ -31,17 +31,17 @@ class Smarty_Internal_Data {
foreach ($tpl_var as $_key => $_val) { foreach ($tpl_var as $_key => $_val) {
if ($_key != '') { if ($_key != '') {
$this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache); $this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache);
} }
} }
} else { } else {
if ($tpl_var != '') { if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache); $this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache);
} }
} }
} }
/** /**
* assigns a global Smarty variable * assigns a global Smarty variable
* *
* @param string $varname the global variable name * @param string $varname the global variable name
* @param mixed $value the value to assign * @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @param boolean $nocache if true any output of this variable will be not cached
@@ -50,11 +50,11 @@ class Smarty_Internal_Data {
{ {
if ($varname != '') { if ($varname != '') {
Smarty::$global_tpl_vars[$varname] = new Smarty_variable($value, $nocache); Smarty::$global_tpl_vars[$varname] = new Smarty_variable($value, $nocache);
} }
} }
/** /**
* assigns values to template variables by reference * assigns values to template variables by reference
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to assign * @param mixed $ &$value the referenced value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @param boolean $nocache if true any output of this variable will be not cached
@@ -64,12 +64,12 @@ class Smarty_Internal_Data {
if ($tpl_var != '') { if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache); $this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache);
$this->tpl_vars[$tpl_var]->value = &$value; $this->tpl_vars[$tpl_var]->value = &$value;
} }
} }
/** /**
* wrapper function for Smarty 2 BC * wrapper function for Smarty 2 BC
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to assign * @param mixed $ &$value the referenced value to assign
*/ */
@@ -78,10 +78,10 @@ class Smarty_Internal_Data {
if($this->smarty->deprecation_notices) if($this->smarty->deprecation_notices)
trigger_error("function call 'assign_by_ref' is unknown or deprecated, use 'assignByRef'", E_USER_NOTICE); trigger_error("function call 'assign_by_ref' is unknown or deprecated, use 'assignByRef'", E_USER_NOTICE);
$this->assignByRef($tpl_var, $value); $this->assignByRef($tpl_var, $value);
} }
/** /**
* appends values to template variables * appends values to template variables
* *
* @param array $ |string $tpl_var the template variable name(s) * @param array $ |string $tpl_var the template variable name(s)
* @param mixed $value the value to append * @param mixed $value the value to append
* @param boolean $merge flag if array elements shall be merged * @param boolean $merge flag if array elements shall be merged
@@ -99,20 +99,20 @@ class Smarty_Internal_Data {
$this->tpl_vars[$_key] = new Smarty_variable(null, $nocache); $this->tpl_vars[$_key] = new Smarty_variable(null, $nocache);
} else { } else {
$this->tpl_vars[$_key] = clone $tpl_var_inst; $this->tpl_vars[$_key] = clone $tpl_var_inst;
} }
} }
if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) { if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) {
settype($this->tpl_vars[$_key]->value, 'array'); settype($this->tpl_vars[$_key]->value, 'array');
} }
if ($merge && is_array($_val)) { if ($merge && is_array($_val)) {
foreach($_val as $_mkey => $_mval) { foreach($_val as $_mkey => $_mval) {
$this->tpl_vars[$_key]->value[$_mkey] = $_mval; $this->tpl_vars[$_key]->value[$_mkey] = $_mval;
} }
} else { } else {
$this->tpl_vars[$_key]->value[] = $_val; $this->tpl_vars[$_key]->value[] = $_val;
} }
} }
} }
} else { } else {
if ($tpl_var != '' && isset($value)) { if ($tpl_var != '' && isset($value)) {
if (!isset($this->tpl_vars[$tpl_var])) { if (!isset($this->tpl_vars[$tpl_var])) {
@@ -121,25 +121,25 @@ class Smarty_Internal_Data {
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache); $this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache);
} else { } else {
$this->tpl_vars[$tpl_var] = clone $tpl_var_inst; $this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
} }
} }
if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) { if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
settype($this->tpl_vars[$tpl_var]->value, 'array'); settype($this->tpl_vars[$tpl_var]->value, 'array');
} }
if ($merge && is_array($value)) { if ($merge && is_array($value)) {
foreach($value as $_mkey => $_mval) { foreach($value as $_mkey => $_mval) {
$this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; $this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval;
} }
} else { } else {
$this->tpl_vars[$tpl_var]->value[] = $value; $this->tpl_vars[$tpl_var]->value[] = $value;
} }
} }
} }
} }
/** /**
* appends values to template variables by reference * appends values to template variables by reference
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to append * @param mixed $ &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged * @param boolean $merge flag if array elements shall be merged
@@ -149,22 +149,22 @@ class Smarty_Internal_Data {
if ($tpl_var != '' && isset($value)) { if ($tpl_var != '' && isset($value)) {
if (!isset($this->tpl_vars[$tpl_var])) { if (!isset($this->tpl_vars[$tpl_var])) {
$this->tpl_vars[$tpl_var] = new Smarty_variable(); $this->tpl_vars[$tpl_var] = new Smarty_variable();
} }
if (!@is_array($this->tpl_vars[$tpl_var]->value)) { if (!@is_array($this->tpl_vars[$tpl_var]->value)) {
settype($this->tpl_vars[$tpl_var]->value, 'array'); settype($this->tpl_vars[$tpl_var]->value, 'array');
} }
if ($merge && is_array($value)) { if ($merge && is_array($value)) {
foreach($value as $_key => $_val) { foreach($value as $_key => $_val) {
$this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key]; $this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key];
} }
} else { } else {
$this->tpl_vars[$tpl_var]->value[] = &$value; $this->tpl_vars[$tpl_var]->value[] = &$value;
} }
} }
} }
/** /**
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to append * @param mixed $ &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged * @param boolean $merge flag if array elements shall be merged
@@ -174,10 +174,10 @@ class Smarty_Internal_Data {
if($this->smarty->deprecation_notices) if($this->smarty->deprecation_notices)
trigger_error("function call 'append_by_ref' is unknown or deprecated, use 'appendByRef'", E_USER_NOTICE); trigger_error("function call 'append_by_ref' is unknown or deprecated, use 'appendByRef'", E_USER_NOTICE);
$this->appendByRef($tpl_var, $value, $merge); $this->appendByRef($tpl_var, $value, $merge);
} }
/** /**
* Returns a single or all template variables * Returns a single or all template variables
* *
* @param string $varname variable name or null * @param string $varname variable name or null
* @return string variable value or or array of variables * @return string variable value or or array of variables
*/ */
@@ -189,7 +189,7 @@ class Smarty_Internal_Data {
return $_var->value; return $_var->value;
} else { } else {
return null; return null;
} }
} else { } else {
$_result = array(); $_result = array();
if ($_ptr === null) { if ($_ptr === null) {
@@ -199,28 +199,28 @@ class Smarty_Internal_Data {
if (!array_key_exists($key, $_result)) { if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value; $_result[$key] = $var->value;
} }
} }
// not found, try at parent // not found, try at parent
if ($search_parents) { if ($search_parents) {
$_ptr = $_ptr->parent; $_ptr = $_ptr->parent;
} else { } else {
$_ptr = null; $_ptr = null;
} }
} }
if ($search_parents && isset(Smarty::$global_tpl_vars)) { if ($search_parents && isset(Smarty::$global_tpl_vars)) {
foreach (Smarty::$global_tpl_vars AS $key => $var) { foreach (Smarty::$global_tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) { if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value; $_result[$key] = $var->value;
} }
} }
} }
return $_result; return $_result;
} }
} }
/** /**
* clear the given assigned template variable. * clear the given assigned template variable.
* *
* @param string $ |array $tpl_var the template variable(s) to clear * @param string $ |array $tpl_var the template variable(s) to clear
*/ */
public function clearAssign($tpl_var) public function clearAssign($tpl_var)
@@ -228,11 +228,11 @@ class Smarty_Internal_Data {
if (is_array($tpl_var)) { if (is_array($tpl_var)) {
foreach ($tpl_var as $curr_var) { foreach ($tpl_var as $curr_var) {
unset($this->tpl_vars[$curr_var]); unset($this->tpl_vars[$curr_var]);
} }
} else { } else {
unset($this->tpl_vars[$tpl_var]); unset($this->tpl_vars[$tpl_var]);
} }
} }
/** /**
* clear all the assigned template variables. * clear all the assigned template variables.
@@ -240,24 +240,24 @@ class Smarty_Internal_Data {
public function clearAllAssign() public function clearAllAssign()
{ {
$this->tpl_vars = array(); $this->tpl_vars = array();
} }
/** /**
* load a config file, optionally load just selected sections * load a config file, optionally load just selected sections
* *
* @param string $config_file filename * @param string $config_file filename
* @param mixed $sections array of section names, single section or null * @param mixed $sections array of section names, single section or null
*/ */
public function configLoad($config_file, $sections = null) public function configLoad($config_file, $sections = null)
{ {
// load Config class // load Config class
$config = new Smarty_Internal_Config($config_file, $this->smarty, $this); $config = new Smarty_Internal_Config($config_file, $this->smarty, $this);
$config->loadConfigVars($sections); $config->loadConfigVars($sections);
} }
/** /**
* gets the object of a Smarty variable * gets the object of a Smarty variable
* *
* @param string $variable the name of the Smarty variable * @param string $variable the name of the Smarty variable
* @param object $_ptr optional pointer to data object * @param object $_ptr optional pointer to data object
* @param boolean $search_parents search also in parent data * @param boolean $search_parents search also in parent data
@@ -271,18 +271,18 @@ class Smarty_Internal_Data {
if (isset($_ptr->tpl_vars[$_variable])) { if (isset($_ptr->tpl_vars[$_variable])) {
// found it, return it // found it, return it
return $_ptr->tpl_vars[$_variable]; return $_ptr->tpl_vars[$_variable];
} }
// not found, try at parent // not found, try at parent
if ($search_parents) { if ($search_parents) {
$_ptr = $_ptr->parent; $_ptr = $_ptr->parent;
} else { } else {
$_ptr = null; $_ptr = null;
} }
} }
if (isset(Smarty::$global_tpl_vars[$_variable])) { if (isset(Smarty::$global_tpl_vars[$_variable])) {
// found it, return it // found it, return it
return Smarty::$global_tpl_vars[$_variable]; return Smarty::$global_tpl_vars[$_variable];
} }
if ($this->smarty->error_unassigned && $error_enable) { if ($this->smarty->error_unassigned && $error_enable) {
throw new SmartyException('Undefined Smarty variable "' . $_variable . '"'); throw new SmartyException('Undefined Smarty variable "' . $_variable . '"');
} else { } else {
@@ -291,11 +291,11 @@ class Smarty_Internal_Data {
$x = $$_variable; $x = $$_variable;
} }
return new Undefined_Smarty_Variable; return new Undefined_Smarty_Variable;
} }
} }
/** /**
* gets a config variable * gets a config variable
* *
* @param string $variable the name of the config variable * @param string $variable the name of the config variable
* @return mixed the value of the config variable * @return mixed the value of the config variable
*/ */
@@ -306,22 +306,22 @@ class Smarty_Internal_Data {
if (isset($_ptr->config_vars[$_variable])) { if (isset($_ptr->config_vars[$_variable])) {
// found it, return it // found it, return it
return $_ptr->config_vars[$_variable]; return $_ptr->config_vars[$_variable];
} }
// not found, try at parent // not found, try at parent
$_ptr = $_ptr->parent; $_ptr = $_ptr->parent;
} }
if ($this->smarty->error_unassigned) { if ($this->smarty->error_unassigned) {
throw new SmartyException('Undefined config variable "' . $_variable . '"'); throw new SmartyException('Undefined config variable "' . $_variable . '"');
} else { } else {
// force a notice // force a notice
$x = $$_variable; $x = $$_variable;
return null; return null;
} }
} }
/** /**
* gets a stream variable * gets a stream variable
* *
* @param string $variable the stream of the variable * @param string $variable the stream of the variable
* @return mixed the value of the stream variable * @return mixed the value of the stream variable
*/ */
@@ -329,23 +329,23 @@ class Smarty_Internal_Data {
{ {
$_result = ''; $_result = '';
if ($fp = fopen($variable, 'r+')) { if ($fp = fopen($variable, 'r+')) {
while (!feof($fp)) { while (!feof($fp) && ($current_line = fgets($fp)) !== false ) {
$_result .= fgets($fp); $_result .= $current_line;
} }
fclose($fp); fclose($fp);
return $_result; return $_result;
} }
if ($this->smarty->error_unassigned) { if ($this->smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"'); throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else { } else {
return null; return null;
} }
} }
/** /**
* Returns a single or all config variables * Returns a single or all config variables
* *
* @param string $varname variable name or null * @param string $varname variable name or null
* @return string variable value or or array of variables * @return string variable value or or array of variables
*/ */
@@ -361,24 +361,24 @@ class Smarty_Internal_Data {
} }
} else { } else {
$var_array = array_merge($_ptr->config_vars, $var_array); $var_array = array_merge($_ptr->config_vars, $var_array);
} }
// not found, try at parent // not found, try at parent
if ($search_parents) { if ($search_parents) {
$_ptr = $_ptr->parent; $_ptr = $_ptr->parent;
} else { } else {
$_ptr = null; $_ptr = null;
} }
} }
if (isset($varname)) { if (isset($varname)) {
return ''; return '';
} else { } else {
return $var_array; return $var_array;
} }
} }
/** /**
* Deassigns a single or all config variables * Deassigns a single or all config variables
* *
* @param string $varname variable name or null * @param string $varname variable name or null
*/ */
function clearConfig($varname = null) function clearConfig($varname = null)
@@ -389,25 +389,25 @@ class Smarty_Internal_Data {
} else { } else {
$this->config_vars = array(); $this->config_vars = array();
return; return;
} }
} }
} }
/** /**
* class for the Smarty data object * class for the Smarty data object
* *
* The Smarty data object will hold Smarty variables in the current scope * The Smarty data object will hold Smarty variables in the current scope
* *
* @param object $parent tpl_vars next higher level of Smarty variables * @param object $parent tpl_vars next higher level of Smarty variables
*/ */
class Smarty_Data extends Smarty_Internal_Data { class Smarty_Data extends Smarty_Internal_Data {
// array of variable objects // array of variable objects
public $tpl_vars = array(); public $tpl_vars = array();
// back pointer to parent object // back pointer to parent object
public $parent = null; public $parent = null;
// config vars // config vars
public $config_vars = array(); public $config_vars = array();
// Smarty object // Smarty object
public $smarty = null; public $smarty = null;
/** /**
@@ -423,15 +423,15 @@ class Smarty_Data extends Smarty_Internal_Data {
// set up variable values // set up variable values
foreach ($_parent as $_key => $_val) { foreach ($_parent as $_key => $_val) {
$this->tpl_vars[$_key] = new Smarty_variable($_val); $this->tpl_vars[$_key] = new Smarty_variable($_val);
} }
} elseif ($_parent != null) { } elseif ($_parent != null) {
throw new SmartyException("Wrong type for template variables"); throw new SmartyException("Wrong type for template variables");
} }
} }
} }
/** /**
* class for the Smarty variable object * class for the Smarty variable object
* *
* This class defines the Smarty variable object * This class defines the Smarty variable object
*/ */
class Smarty_Variable { class Smarty_Variable {
@@ -441,7 +441,7 @@ class Smarty_Variable {
public $scope; public $scope;
/** /**
* create Smarty variable object * create Smarty variable object
* *
* @param mixed $value the value to assign * @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @param boolean $nocache if true any output of this variable will be not cached
* @param boolean $scope the scope the variable will have (local,parent or root) * @param boolean $scope the scope the variable will have (local,parent or root)
@@ -451,17 +451,17 @@ class Smarty_Variable {
$this->value = $value; $this->value = $value;
$this->nocache = $nocache; $this->nocache = $nocache;
$this->scope = $scope; $this->scope = $scope;
} }
public function __toString () public function __toString ()
{ {
return $this->value; return $this->value;
} }
} }
/** /**
* class for undefined variable object * class for undefined variable object
* *
* This class defines an object for undefined variable handling * This class defines an object for undefined variable handling
*/ */
class Undefined_Smarty_Variable { class Undefined_Smarty_Variable {
@@ -472,8 +472,8 @@ class Undefined_Smarty_Variable {
return false; return false;
} else { } else {
return null; return null;
} }
} }
} }
?> ?>

View File

@@ -75,8 +75,8 @@ class Smarty_Internal_Resource_Stream {
// return template string // return template string
$_template->template_source = ''; $_template->template_source = '';
if ($fp = fopen(str_replace(':', '://', $_template->template_resource),'r+')) { if ($fp = fopen(str_replace(':', '://', $_template->template_resource),'r+')) {
while (!feof($fp)) { while (!feof($fp) && ($current_line = fgets($fp)) !== false ) {
$_template->template_source .= fgets($fp); $_template->template_source .= $current_line;
} }
fclose($fp); fclose($fp);
return true; return true;