changed "link" to "href" in html_image. "link" is still working but deprecated

html_image always renders an alt-tag now (default alt="")
cleaned up indentiation of function.html_image.php
This commit is contained in:
messju
2003-05-04 11:32:54 +00:00
parent f40c0f0b53
commit 2bc360d3c3
2 changed files with 94 additions and 87 deletions

3
NEWS
View File

@@ -1,3 +1,6 @@
- changed "link" to "href" in html_image. "link" is still working
but deprecated (messju)
- html_image always renders an alt-tag now (default alt="") (messju)
- fixed assign attribute for multiple counters (messju) - fixed assign attribute for multiple counters (messju)
- added simple math operators to variables (Monte) - added simple math operators to variables (Monte)
- reverted patch for case-insensitive tag-names (messju) - reverted patch for case-insensitive tag-names (messju)

View File

@@ -36,99 +36,103 @@
*/ */
function smarty_function_html_image($params, &$smarty) function smarty_function_html_image($params, &$smarty)
{ {
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
$file = ''; $alt = '';
$border = 0; $file = '';
$height = ''; $border = 0;
$width = ''; $height = '';
$extra = ''; $width = '';
$prefix = ''; $extra = '';
$suffix = ''; $prefix = '';
$basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']) $suffix = '';
? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '/'; $basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])
if(strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) { ? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '/';
$dpi_default = 72; if(strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) {
} else { $dpi_default = 72;
$dpi_default = 96; } else {
} $dpi_default = 96;
}
foreach($params as $_key => $_val) { foreach($params as $_key => $_val) {
switch($_key) { switch($_key) {
case 'file': case 'file':
$file = $_val; case 'border':
break; case 'height':
case 'border': case 'width':
$border = $_val; case 'dpi':
break; $$_key = $_val;
case 'height': break;
$height = $_val;
break; case 'alt':
case 'width': if(!is_array($_val)) {
$width = $_val; $$_key = smarty_function_escape_special_chars($_val);
break; } else {
case 'link': $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
$prefix = '<a href="' . $_val . '">'; }
$suffix = '</a>'; break;
break;
case 'dpi': case 'link':
$dpi = $_val; case 'href':
break; $prefix = '<a href="' . $_val . '">';
default: $suffix = '</a>';
if(!is_array($_val)) { break;
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} else { default:
$smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); if(!is_array($_val)) {
} $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
break; } else {
} $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
} }
break;
}
}
if (empty($file)) { if (empty($file)) {
$smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
return; return;
} }
if(substr($file,0,1) == DIR_SEP) { if(substr($file,0,1) == DIR_SEP) {
$_image_path = $basedir . $file; $_image_path = $basedir . $file;
} else { } else {
$_image_path = $file; $_image_path = $file;
} }
if(!isset($params['width']) || !isset($params['height'])) { if(!isset($params['width']) || !isset($params['height'])) {
if(!$_image_data = @getimagesize($_image_path)) { if(!$_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;
} else if(!is_readable($_image_path)) { } else if(!is_readable($_image_path)) {
$smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
return; return;
} else { } else {
$smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
return; return;
} }
} }
if(!$smarty->security && !$smarty->_is_secure('file', $_image_path)) { if(!$smarty->security && !$smarty->_is_secure('file', $_image_path)) {
$smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE); $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
return; return;
} }
if(!isset($params['width'])) { if(!isset($params['width'])) {
$width = $_image_data[0]; $width = $_image_data[0];
} }
if(!isset($params['height'])) { if(!isset($params['height'])) {
$height = $_image_data[1]; $height = $_image_data[1];
} }
} }
if(isset($params['dpi'])) { if(isset($params['dpi'])) {
$_resize = $dpi_default/$params['dpi']; $_resize = $dpi_default/$params['dpi'];
$width = round($width * $_resize); $width = round($width * $_resize);
$height = round($height * $_resize); $height = round($height * $_resize);
} }
return $prefix . '<img src="'.$file.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix; return $prefix . '<img src="'.$file.'" alt="'.$alt.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */