• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/plugins/function.html_image.php

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

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2