* Credits: Duda - wrote first image function * in repository, helped with lots of functionality * 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: * ------------------------------------------------------------- */ function smarty_function_html_image($params, &$smarty) { require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); $name = ''; $border = 0; $height = ''; $width = ''; $extra = ''; $prefix = ''; $suffix = ''; $basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']) ? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '/'; 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; case 'link': $prefix = ''; $suffix = ''; break; default: $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; break; } } 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(!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_ERROR); } else if(!is_readable($_image_path)) { $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_ERROR); } else { $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_ERROR); } } if(!$smarty->security && !$smarty->_is_secure('file', $_image_path)) { $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_ERROR); } if(!isset($params['width'])) { $width = $_image_data[1]; } if(!isset($params['height'])) { $height = $_image_data[2]; } } return $prefix . '' . $suffix; } /* vim: set expandtab: */ ?>