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

@@ -20,7 +20,7 @@
* - image =image width (optional, default actual width) * - image =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
* *
* Examples: {image file="images/masthead.gif"} * Examples: {image file="images/masthead.gif"}
* Output: <img src="images/masthead.gif" border=0 width=400 height=23> * Output: <img src="images/masthead.gif" border=0 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}
@@ -35,100 +35,104 @@
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
*/ */
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');
$alt = '';
$file = '';
$border = 0;
$height = '';
$width = '';
$extra = '';
$prefix = '';
$suffix = '';
$basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])
? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '/';
if(strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) {
$dpi_default = 72;
} else {
$dpi_default = 96;
}
$file = ''; foreach($params as $_key => $_val) {
$border = 0; switch($_key) {
$height = ''; case 'file':
$width = ''; case 'border':
$extra = ''; case 'height':
$prefix = ''; case 'width':
$suffix = ''; case 'dpi':
$basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']) $$_key = $_val;
? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '/'; break;
if(strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) {
$dpi_default = 72; case 'alt':
} else { if(!is_array($_val)) {
$dpi_default = 96; $$_key = smarty_function_escape_special_chars($_val);
} } else {
$smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
foreach($params as $_key => $_val) { }
switch($_key) { break;
case 'file':
$file = $_val; case 'link':
break; case 'href':
case 'border': $prefix = '<a href="' . $_val . '">';
$border = $_val; $suffix = '</a>';
break; break;
case 'height':
$height = $_val; default:
break; if(!is_array($_val)) {
case 'width': $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
$width = $_val; } else {
break; $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
case 'link': }
$prefix = '<a href="' . $_val . '">'; break;
$suffix = '</a>'; }
break; }
case 'dpi':
$dpi = $_val;
break;
default:
if(!is_array($_val)) {
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} 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(!$_image_data = @getimagesize($_image_path)) {
if(!file_exists($_image_path)) {
$smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
return;
} else if(!is_readable($_image_path)) {
$smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
return;
} else {
$smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
return;
}
}
if(!$smarty->security && !$smarty->_is_secure('file', $_image_path)) {
$smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
return;
}
if(!isset($params['width'])) {
$width = $_image_data[0];
}
if(!isset($params['height'])) {
$height = $_image_data[1];
}
}
if(isset($params['dpi'])) { if(!isset($params['width']) || !isset($params['height'])) {
$_resize = $dpi_default/$params['dpi']; if(!$_image_data = @getimagesize($_image_path)) {
$width = round($width * $_resize); if(!file_exists($_image_path)) {
$height = round($height * $_resize); $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
} return;
} else if(!is_readable($_image_path)) {
return $prefix . '<img src="'.$file.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix; $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
return;
} else {
$smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
return;
}
}
if(!$smarty->security && !$smarty->_is_secure('file', $_image_path)) {
$smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
return;
}
if(!isset($params['width'])) {
$width = $_image_data[0];
}
if(!isset($params['height'])) {
$height = $_image_data[1];
}
}
if(isset($params['dpi'])) {
$_resize = $dpi_default/$params['dpi'];
$width = round($width * $_resize);
$height = round($height * $_resize);
}
return $prefix . '<img src="'.$file.'" alt="'.$alt.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */