* - width = image width (optional, default actual width)
* - basedir = base directory for absolute paths, default
* is environment variable DOCUMENT_ROOT
+ * - path_prefix = prefix for path output (optional, default empty)
*
- * Examples: {html_image file="images/masthead.gif"}
- * Output: <img src="images/masthead.gif" width=400 height=23>
+ * Examples: {html_image file="/images/masthead.gif"}
+ * Output: <img src="/images/masthead.gif" width=400 height=23>
* @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
function smarty_function_html_image($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
-
+
$alt = '';
$file = '';
$height = '';
$extra = '';
$prefix = '';
$suffix = '';
+ $path_prefix = '';
$server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
$basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
foreach($params as $_key => $_val) {
case 'height':
case 'width':
case 'dpi':
+ case 'path_prefix':
case 'basedir':
$$_key = $_val;
break;
} else {
$_image_path = $file;
}
-
+
if(!isset($params['width']) || !isset($params['height'])) {
- 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);
-
- } elseif (!$_image_data = @getimagesize($_image_path)) {
+ if(!$_image_data = @getimagesize($_image_path)) {
if(!file_exists($_image_path)) {
$smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
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'])) {
$width = $_image_data[0];
}
$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: */