5 * @subpackage plugins
\r
10 * Smarty {html_image} function plugin
\r
12 * Type: function<br>
\r
13 * Name: html_image<br>
\r
14 * Date: Feb 24, 2003<br>
\r
15 * Purpose: format HTML tags for the image<br>
\r
17 * - file = file (and path) of image (required)
\r
18 * - border = border width (optional, default 0)
\r
19 * - height = image height (optional, default actual height)
\r
20 * - image =image width (optional, default actual width)
\r
21 * - basedir = base directory for absolute paths, default
\r
22 * is environment variable DOCUMENT_ROOT
\r
24 * Examples: {html_image file="images/masthead.gif"}
\r
25 * Output: <img src="images/masthead.gif" border=0 width=400 height=23>
\r
26 * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
\r
27 * (Smarty online manual)
\r
28 * @author Monte Ohrt <monte@ispi.net>
\r
29 * @author credits to Duda <duda@big.hu> - wrote first image function
\r
30 * in repository, helped with lots of functionality
\r
35 * @uses smarty_function_escape_special_chars()
\r
37 function smarty_function_html_image($params, &$smarty)
\r
39 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
\r
49 $basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])
\r
50 ? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '';
\r
51 if(strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) {
\r
57 foreach($params as $_key => $_val) {
\r
69 if(!is_array($_val)) {
\r
70 $$_key = smarty_function_escape_special_chars($_val);
\r
72 $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
\r
78 $prefix = '<a href="' . $_val . '">';
\r
83 if(!is_array($_val)) {
\r
84 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
\r
86 $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
\r
93 $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
\r
97 if (substr($file,0,1) == '/') {
\r
98 $_image_path = $basedir . $file;
\r
100 $_image_path = $file;
\r
103 if(!isset($params['width']) || !isset($params['height'])) {
\r
104 if(!$_image_data = @getimagesize($_image_path)) {
\r
105 if(!file_exists($_image_path)) {
\r
106 $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
\r
108 } else if(!is_readable($_image_path)) {
\r
109 $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
\r
112 $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
\r
116 $_params = array('resource_type' => 'file', 'resource_name' => $_image_path);
\r
117 require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php');
\r
118 if(!$smarty->security && !smarty_core_is_secure($_params, $smarty)) {
\r
119 $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
\r
123 if(!isset($params['width'])) {
\r
124 $width = $_image_data[0];
\r
126 if(!isset($params['height'])) {
\r
127 $height = $_image_data[1];
\r
132 if(isset($params['dpi'])) {
\r
133 $_resize = $dpi_default/$params['dpi'];
\r
134 $width = round($width * $_resize);
\r
135 $height = round($height * $_resize);
\r
138 return $prefix . '<img src="'.$file.'" alt="'.$alt.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
\r
141 /* vim: set expandtab: */
\r