| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty plugin | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * @package Smarty | 
					
						
							|  |  |  |  * @subpackage PluginsFunction | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * 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> | 
					
						
							|  |  |  |  * Examples: {html_image file="/images/masthead.gif"} | 
					
						
							|  |  |  |  * Output:   <img src="/images/masthead.gif" width=400 height=23> | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image} | 
					
						
							|  |  |  |  *      (Smarty online manual) | 
					
						
							|  |  |  |  * @author Monte Ohrt <monte at ohrt dot com>  | 
					
						
							|  |  |  |  * @author credits to Duda <duda@big.hu>  | 
					
						
							|  |  |  |  * @version 1.0 | 
					
						
							|  |  |  |  * @param array $params parameters | 
					
						
							|  |  |  |  * Input:<br> | 
					
						
							|  |  |  |  *          - file = file (and path) of image (required) | 
					
						
							|  |  |  |  *          - height = image height (optional, default actual height) | 
					
						
							|  |  |  |  *          - width = image width (optional, default actual width) | 
					
						
							|  |  |  |  *          - basedir = base directory for absolute paths, default | 
					
						
							|  |  |  |  *                      is environment variable DOCUMENT_ROOT | 
					
						
							|  |  |  |  *          - path_prefix = prefix for path output (optional, default empty) | 
					
						
							|  |  |  |  * @param object $template template object | 
					
						
							|  |  |  |  * @return string  | 
					
						
							|  |  |  |  * @uses smarty_function_escape_special_chars() | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-11-12 23:42:32 +00:00
										 |  |  | function smarty_function_html_image($params, $template) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |     require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); | 
					
						
							| 
									
										
										
										
											2010-11-13 04:10:52 +00:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     $alt = ''; | 
					
						
							|  |  |  |     $file = ''; | 
					
						
							|  |  |  |     $height = ''; | 
					
						
							|  |  |  |     $width = ''; | 
					
						
							|  |  |  |     $extra = ''; | 
					
						
							|  |  |  |     $prefix = ''; | 
					
						
							|  |  |  |     $suffix = ''; | 
					
						
							|  |  |  |     $path_prefix = ''; | 
					
						
							| 
									
										
										
										
											2010-11-14 15:08:44 +00:00
										 |  |  |     $server_vars = $_SERVER; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : ''; | 
					
						
							|  |  |  |     foreach($params as $_key => $_val) { | 
					
						
							|  |  |  |         switch ($_key) { | 
					
						
							|  |  |  |             case 'file': | 
					
						
							|  |  |  |             case 'height': | 
					
						
							|  |  |  |             case 'width': | 
					
						
							|  |  |  |             case 'dpi': | 
					
						
							|  |  |  |             case 'path_prefix': | 
					
						
							|  |  |  |             case 'basedir': | 
					
						
							|  |  |  |                 $$_key = $_val; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'alt': | 
					
						
							|  |  |  |                 if (!is_array($_val)) { | 
					
						
							|  |  |  |                     $$_key = smarty_function_escape_special_chars($_val); | 
					
						
							|  |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2010-08-13 10:39:51 +00:00
										 |  |  |                     throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 }  | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             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 { | 
					
						
							| 
									
										
										
										
											2010-08-13 10:39:51 +00:00
										 |  |  |                     throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 }  | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (empty($file)) { | 
					
						
							| 
									
										
										
										
											2009-12-01 20:34:32 +00:00
										 |  |  |         trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         return; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (substr($file, 0, 1) == '/') { | 
					
						
							|  |  |  |         $_image_path = $basedir . $file; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $_image_path = $file; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!isset($params['width']) || !isset($params['height'])) { | 
					
						
							|  |  |  |         if (!$_image_data = @getimagesize($_image_path)) { | 
					
						
							|  |  |  |             if (!file_exists($_image_path)) { | 
					
						
							| 
									
										
										
										
											2009-12-01 20:34:32 +00:00
										 |  |  |                 trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             } else if (!is_readable($_image_path)) { | 
					
						
							| 
									
										
										
										
											2009-12-01 20:34:32 +00:00
										 |  |  |                 trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2009-12-01 20:34:32 +00:00
										 |  |  |                 trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2010-11-12 23:42:32 +00:00
										 |  |  |         if (isset($template->security_policy)) { | 
					
						
							|  |  |  |             if (!$template->security_policy->isTrustedResourceDir($_image_path)) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!isset($params['width'])) { | 
					
						
							|  |  |  |             $width = $_image_data[0]; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         if (!isset($params['height'])) { | 
					
						
							|  |  |  |             $height = $_image_data[1]; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isset($params['dpi'])) { | 
					
						
							|  |  |  |         if (strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) { | 
					
						
							|  |  |  |             $dpi_default = 72; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $dpi_default = 96; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         $_resize = $dpi_default / $params['dpi']; | 
					
						
							|  |  |  |         $width = round($width * $_resize); | 
					
						
							|  |  |  |         $height = round($height * $_resize); | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"' . $extra . ' />' . $suffix; | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-13 10:39:51 +00:00
										 |  |  | ?>
 |