6  * @subpackage PluginsFunction
 
  10  * Smarty {html_image} function plugin
 
  13  * Name:     html_image<br>
 
  14  * Date:     Feb 24, 2003<br>
 
  15  * Purpose:  format HTML tags for the image<br>
 
  16  * Examples: {html_image file="/images/masthead.gif"}
 
  17  * Output:   <img src="/images/masthead.gif" width=400 height=23>
 
  19  * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
 
  20  *      (Smarty online manual)
 
  21  * @author Monte Ohrt <monte at ohrt dot com> 
 
  22  * @author credits to Duda <duda@big.hu> 
 
  24  * @param array $params parameters
 
  26  *          - file = file (and path) of image (required)
 
  27  *          - height = image height (optional, default actual height)
 
  28  *          - width = image width (optional, default actual width)
 
  29  *          - basedir = base directory for absolute paths, default
 
  30  *                      is environment variable DOCUMENT_ROOT
 
  31  *          - path_prefix = prefix for path output (optional, default empty)
 
  32  * @param object $template template object
 
  34  * @uses smarty_function_escape_special_chars()
 
  36 function smarty_function_html_image($params, $template)
 
  38     require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
 
  48     $server_vars = $_SERVER;
 
  49     $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
 
  50     foreach($params as $_key => $_val) {
 
  62                 if (!is_array($_val)) {
 
  63                     $$_key = smarty_function_escape_special_chars($_val);
 
  65                     throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
 
  71                 $prefix = '<a href="' . $_val . '">';
 
  76                 if (!is_array($_val)) {
 
  77                     $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
 
  79                     throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
 
  86         trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
 
  90     if (substr($file, 0, 1) == '/') {
 
  91         $_image_path = $basedir . $file;
 
  96     if (!isset($params['width']) || !isset($params['height'])) {
 
  97         if (!$_image_data = @getimagesize($_image_path)) {
 
  98             if (!file_exists($_image_path)) {
 
  99                 trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
 
 101             } else if (!is_readable($_image_path)) {
 
 102                 trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
 
 105                 trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
 
 109         if (isset($template->security_policy)) {
 
 110             if (!$template->security_policy->isTrustedResourceDir($_image_path)) {
 
 115         if (!isset($params['width'])) {
 
 116             $width = $_image_data[0];
 
 118         if (!isset($params['height'])) {
 
 119             $height = $_image_data[1];
 
 123     if (isset($params['dpi'])) {
 
 124         if (strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) {
 
 129         $_resize = $dpi_default / $params['dpi'];
 
 130         $width = round($width * $_resize);
 
 131         $height = round($height * $_resize);
 
 134     return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"' . $extra . ' />' . $suffix;