2003-02-24 17:47:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Smarty plugin
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
* Type: function
|
|
|
|
* Name: html_image
|
|
|
|
* Version: 1.0
|
|
|
|
* Date: Feb 24, 2003
|
|
|
|
* Author: Monte Ohrt <monte@ispi.net>
|
|
|
|
* Purpose: format HTML tags for the image
|
|
|
|
* Input: name = name of image (required)
|
|
|
|
* border = border width (optional, default 0)
|
|
|
|
* height = image height (optional, default actual height)
|
|
|
|
* image =image width (optional, default actual width)
|
|
|
|
* basedir= base directory for absolute paths, default
|
|
|
|
* is environment variable DOCUMENT_ROOT
|
|
|
|
*
|
|
|
|
* Examples: {image name="images/masthead.gif"}
|
|
|
|
* Output: <img src="images/masthead.gif" border=0 width=400 height=23>
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
*/
|
2003-02-24 21:45:19 +00:00
|
|
|
require_once $this->_get_plugin_filepath('shared','escape_special_chars');
|
2003-02-24 17:47:05 +00:00
|
|
|
function smarty_function_html_image($params, &$smarty)
|
|
|
|
{
|
|
|
|
$name = '';
|
|
|
|
$border = 0;
|
2003-02-24 23:28:20 +00:00
|
|
|
$height = '';
|
|
|
|
$width = '';
|
2003-02-24 21:45:19 +00:00
|
|
|
$extra = '';
|
2003-02-24 17:47:05 +00:00
|
|
|
$basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])
|
2003-02-24 23:28:20 +00:00
|
|
|
? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '/';
|
2003-02-24 17:47:05 +00:00
|
|
|
|
2003-02-24 21:45:19 +00:00
|
|
|
foreach($params as $_key => $_val) {
|
|
|
|
switch($_key) {
|
|
|
|
case 'name':
|
|
|
|
$name = $_val;
|
|
|
|
break;
|
|
|
|
case 'border':
|
|
|
|
$border = $_val;
|
|
|
|
break;
|
|
|
|
case 'height':
|
|
|
|
$height = $_val;
|
|
|
|
break;
|
|
|
|
case 'width':
|
|
|
|
$width = $_val;
|
|
|
|
break;
|
|
|
|
default:
|
2003-02-24 23:28:20 +00:00
|
|
|
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
|
|
|
|
break;
|
2003-02-24 21:45:19 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-24 17:47:05 +00:00
|
|
|
|
|
|
|
if (empty($name)) {
|
|
|
|
$smarty->trigger_error("html_image: missing 'name' parameter", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(substr($name,0,1) == DIR_SEP) {
|
|
|
|
$_image_path = $basedir . DIR_SEP . $name;
|
|
|
|
} else {
|
|
|
|
$_image_path = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!file_exists($_image_path)) {
|
|
|
|
$smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!is_readable($_image_path)) {
|
|
|
|
$smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_ERROR);
|
|
|
|
}
|
2003-02-24 21:45:19 +00:00
|
|
|
|
|
|
|
if(!$smarty->security && substr($_image_path,0,strlen($basedir)) != $basedir) {
|
|
|
|
$smarty->trigger_error("html_image: (secure) '$_image_path' not within basedir ($basedir)", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
2003-02-24 17:47:05 +00:00
|
|
|
if(!$_image_data = getimagesize($_image_path)) {
|
|
|
|
$smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
2003-02-24 21:45:19 +00:00
|
|
|
return "<img src=\"$name\" border=\"$border\" ".$_image_data[3]."$extra>";
|
2003-02-24 17:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set expandtab: */
|
|
|
|
|
|
|
|
?>
|