+++ /dev/null
-<?php\r
-/**\r
- * Smarty plugin\r
- * @package Smarty\r
- * @subpackage plugins\r
- */\r
-\r
-\r
-/**\r
- * Smarty {html_image} function plugin\r
- *\r
- * Type: function<br>\r
- * Name: html_image<br>\r
- * Date: Feb 24, 2003<br>\r
- * Purpose: format HTML tags for the image<br>\r
- * Input:<br>\r
- * - file = file (and path) of image (required)\r
- * - border = border width (optional, default 0)\r
- * - height = image height (optional, default actual height)\r
- * - image =image width (optional, default actual width)\r
- * - basedir = base directory for absolute paths, default\r
- * is environment variable DOCUMENT_ROOT\r
- *\r
- * Examples: {html_image file="images/masthead.gif"}\r
- * Output: <img src="images/masthead.gif" border=0 width=400 height=23>\r
- * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}\r
- * (Smarty online manual)\r
- * @author Monte Ohrt <monte@ispi.net>\r
- * @author credits to Duda <duda@big.hu> - wrote first image function\r
- * in repository, helped with lots of functionality\r
- * @version 1.0\r
- * @param array\r
- * @param Smarty\r
- * @return string\r
- * @uses smarty_function_escape_special_chars()\r
- */\r
-function smarty_function_html_image($params, &$smarty)\r
-{\r
- require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');\r
- \r
- $alt = '';\r
- $file = '';\r
- $border = 0;\r
- $height = '';\r
- $width = '';\r
- $extra = '';\r
- $prefix = '';\r
- $suffix = '';\r
- $basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])\r
- ? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '';\r
- if(strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) {\r
- $dpi_default = 72;\r
- } else {\r
- $dpi_default = 96;\r
- }\r
-\r
- foreach($params as $_key => $_val) {\r
- switch($_key) {\r
- case 'file':\r
- case 'border':\r
- case 'height':\r
- case 'width':\r
- case 'dpi':\r
- case 'basedir':\r
- $$_key = $_val;\r
- break;\r
-\r
- case 'alt':\r
- if(!is_array($_val)) {\r
- $$_key = smarty_function_escape_special_chars($_val);\r
- } else {\r
- $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);\r
- }\r
- break;\r
-\r
- case 'link':\r
- case 'href':\r
- $prefix = '<a href="' . $_val . '">';\r
- $suffix = '</a>';\r
- break;\r
-\r
- default:\r
- if(!is_array($_val)) {\r
- $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';\r
- } else {\r
- $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);\r
- }\r
- break;\r
- }\r
- }\r
-\r
- if (empty($file)) {\r
- $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);\r
- return;\r
- }\r
-\r
- if (substr($file,0,1) == '/') {\r
- $_image_path = $basedir . $file;\r
- } else {\r
- $_image_path = $file;\r
- }\r
-\r
- if(!isset($params['width']) || !isset($params['height'])) {\r
- if(!$_image_data = @getimagesize($_image_path)) {\r
- if(!file_exists($_image_path)) {\r
- $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);\r
- return;\r
- } else if(!is_readable($_image_path)) {\r
- $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);\r
- return;\r
- } else {\r
- $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);\r
- return;\r
- }\r
- }\r
- $_params = array('resource_type' => 'file', 'resource_name' => $_image_path);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php');\r
- if(!$smarty->security && !smarty_core_is_secure($_params, $smarty)) {\r
- $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);\r
- return;\r
- }\r
-\r
- if(!isset($params['width'])) {\r
- $width = $_image_data[0];\r
- }\r
- if(!isset($params['height'])) {\r
- $height = $_image_data[1];\r
- }\r
-\r
- }\r
-\r
- if(isset($params['dpi'])) {\r
- $_resize = $dpi_default/$params['dpi'];\r
- $width = round($width * $_resize);\r
- $height = round($height * $_resize);\r
- }\r
-\r
- return $prefix . '<img src="'.$file.'" alt="'.$alt.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;\r
-}\r
-\r
-/* vim: set expandtab: */\r
-\r
-?>\r