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