00001 <?php 00037 function smarty_function_html_image($params, &$smarty) 00038 { 00039 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); 00040 00041 $alt = ''; 00042 $file = ''; 00043 $height = ''; 00044 $width = ''; 00045 $extra = ''; 00046 $prefix = ''; 00047 $suffix = ''; 00048 $path_prefix = ''; 00049 $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; 00050 $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : ''; 00051 foreach($params as $_key => $_val) { 00052 switch($_key) { 00053 case 'file': 00054 case 'height': 00055 case 'width': 00056 case 'dpi': 00057 case 'path_prefix': 00058 case 'basedir': 00059 $$_key = $_val; 00060 break; 00061 00062 case 'alt': 00063 if(!is_array($_val)) { 00064 $$_key = smarty_function_escape_special_chars($_val); 00065 } else { 00066 $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 00067 } 00068 break; 00069 00070 case 'link': 00071 case 'href': 00072 $prefix = '<a href="' . $_val . '">'; 00073 $suffix = '</a>'; 00074 break; 00075 00076 default: 00077 if(!is_array($_val)) { 00078 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; 00079 } else { 00080 $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 00081 } 00082 break; 00083 } 00084 } 00085 00086 if (empty($file)) { 00087 $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); 00088 return; 00089 } 00090 00091 if (substr($file,0,1) == '/') { 00092 $_image_path = $basedir . $file; 00093 } else { 00094 $_image_path = $file; 00095 } 00096 00097 if(!isset($params['width']) || !isset($params['height'])) { 00098 if(!$_image_data = @getimagesize($_image_path)) { 00099 if(!file_exists($_image_path)) { 00100 $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); 00101 return; 00102 } else if(!is_readable($_image_path)) { 00103 $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); 00104 return; 00105 } else { 00106 $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); 00107 return; 00108 } 00109 } 00110 if ($smarty->security && 00111 ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) && 00112 (require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) && 00113 (!smarty_core_is_secure($_params, $smarty)) ) { 00114 $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE); 00115 } 00116 00117 if(!isset($params['width'])) { 00118 $width = $_image_data[0]; 00119 } 00120 if(!isset($params['height'])) { 00121 $height = $_image_data[1]; 00122 } 00123 00124 } 00125 00126 if(isset($params['dpi'])) { 00127 if(strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) { 00128 $dpi_default = 72; 00129 } else { 00130 $dpi_default = 96; 00131 } 00132 $_resize = $dpi_default/$params['dpi']; 00133 $width = round($width * $_resize); 00134 $height = round($height * $_resize); 00135 } 00136 00137 return $prefix . '<img src="'.$path_prefix.$file.'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix; 00138 } 00139 00140 /* vim: set expandtab: */ 00141 00142 ?>
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
