mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 03:44:26 +02:00
add path_prefix to html_image, fix incorrect secure_dir error when image file is missing
This commit is contained in:
3
NEWS
3
NEWS
@@ -1,3 +1,6 @@
|
|||||||
|
- plugin html_image: fix incorrect secure_dir error when
|
||||||
|
file doesn't exist (monte)
|
||||||
|
- plugin html_image: add path_prefix param (monte)
|
||||||
- add char_set parameter to escape modifier (Loading, monte)
|
- add char_set parameter to escape modifier (Loading, monte)
|
||||||
- fix notice in debug security check (Drakla, monte)
|
- fix notice in debug security check (Drakla, monte)
|
||||||
- return valid reference in get_template_vars() when given var is
|
- return valid reference in get_template_vars() when given var is
|
||||||
|
@@ -19,9 +19,10 @@
|
|||||||
* - width = image width (optional, default actual width)
|
* - width = image width (optional, default actual width)
|
||||||
* - basedir = base directory for absolute paths, default
|
* - basedir = base directory for absolute paths, default
|
||||||
* is environment variable DOCUMENT_ROOT
|
* is environment variable DOCUMENT_ROOT
|
||||||
|
* - path_prefix = prefix for path output (optional, default empty)
|
||||||
*
|
*
|
||||||
* Examples: {html_image file="images/masthead.gif"}
|
* Examples: {html_image file="/images/masthead.gif"}
|
||||||
* Output: <img src="images/masthead.gif" width=400 height=23>
|
* Output: <img src="/images/masthead.gif" width=400 height=23>
|
||||||
* @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
|
* @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
|
||||||
* (Smarty online manual)
|
* (Smarty online manual)
|
||||||
* @author Monte Ohrt <monte at ohrt dot com>
|
* @author Monte Ohrt <monte at ohrt dot com>
|
||||||
@@ -44,6 +45,7 @@ function smarty_function_html_image($params, &$smarty)
|
|||||||
$extra = '';
|
$extra = '';
|
||||||
$prefix = '';
|
$prefix = '';
|
||||||
$suffix = '';
|
$suffix = '';
|
||||||
|
$path_prefix = '';
|
||||||
$server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
|
$server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
|
||||||
$basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
|
$basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
|
||||||
foreach($params as $_key => $_val) {
|
foreach($params as $_key => $_val) {
|
||||||
@@ -52,6 +54,7 @@ function smarty_function_html_image($params, &$smarty)
|
|||||||
case 'height':
|
case 'height':
|
||||||
case 'width':
|
case 'width':
|
||||||
case 'dpi':
|
case 'dpi':
|
||||||
|
case 'path_prefix':
|
||||||
case 'basedir':
|
case 'basedir':
|
||||||
$$_key = $_val;
|
$$_key = $_val;
|
||||||
break;
|
break;
|
||||||
@@ -90,15 +93,9 @@ function smarty_function_html_image($params, &$smarty)
|
|||||||
} else {
|
} else {
|
||||||
$_image_path = $file;
|
$_image_path = $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($params['width']) || !isset($params['height'])) {
|
if(!isset($params['width']) || !isset($params['height'])) {
|
||||||
if ($smarty->security &&
|
if(!$_image_data = @getimagesize($_image_path)) {
|
||||||
($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) &&
|
|
||||||
(require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) &&
|
|
||||||
(!smarty_core_is_secure($_params, $smarty)) ) {
|
|
||||||
$smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
|
|
||||||
|
|
||||||
} elseif (!$_image_data = @getimagesize($_image_path)) {
|
|
||||||
if(!file_exists($_image_path)) {
|
if(!file_exists($_image_path)) {
|
||||||
$smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
|
$smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
|
||||||
return;
|
return;
|
||||||
@@ -110,7 +107,13 @@ function smarty_function_html_image($params, &$smarty)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($smarty->security &&
|
||||||
|
($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) &&
|
||||||
|
(require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) &&
|
||||||
|
(!smarty_core_is_secure($_params, $smarty)) ) {
|
||||||
|
$smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
|
||||||
|
}
|
||||||
|
|
||||||
if(!isset($params['width'])) {
|
if(!isset($params['width'])) {
|
||||||
$width = $_image_data[0];
|
$width = $_image_data[0];
|
||||||
}
|
}
|
||||||
@@ -131,7 +134,7 @@ function smarty_function_html_image($params, &$smarty)
|
|||||||
$height = round($height * $_resize);
|
$height = round($height * $_resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $prefix . '<img src="'.$file.'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
|
return $prefix . '<img src="'.$path_prefix.$file.'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
/* vim: set expandtab: */
|
||||||
|
Reference in New Issue
Block a user