diff options
author | emkael <emkael@tlen.pl> | 2018-10-18 02:40:38 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-10-18 02:40:38 +0200 |
commit | eab8a101e7a3fcbb41e01a574985e06c5a3775de (patch) | |
tree | 60f201da5984b0c3638d10da02bba42b61aa3177 /lib/smarty3/plugins/function.html_image.php | |
parent | 7f38be342c1495aeca418286c15c25c18ac9e142 (diff) |
Updating Smarty
Diffstat (limited to 'lib/smarty3/plugins/function.html_image.php')
-rw-r--r-- | lib/smarty3/plugins/function.html_image.php | 64 |
1 files changed, 29 insertions, 35 deletions
diff --git a/lib/smarty3/plugins/function.html_image.php b/lib/smarty3/plugins/function.html_image.php index 854af61..ad468e4 100644 --- a/lib/smarty3/plugins/function.html_image.php +++ b/lib/smarty3/plugins/function.html_image.php @@ -5,23 +5,21 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * 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"}<br> - * Output: <img src="/images/masthead.gif" width=400 height=23><br> + * Type: function + * Name: html_image + * Date: Feb 24, 2003 + * Purpose: format HTML tags for the image + * Examples: {html_image file="/images/masthead.gif"} + * Output: <img src="/images/masthead.gif" width=400 height=23> * Params: - * <pre> + * * - file - (required) - file (and path) of image * - height - (optional) - image height (default actual height) * - width - (optional) - image width (default actual width) * - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT * - path_prefix - prefix for path output (optional, default empty) - * </pre> * * @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image} * (Smarty online manual) @@ -36,10 +34,16 @@ * @return string * @uses smarty_function_escape_special_chars() */ -function smarty_function_html_image($params, $template) +function smarty_function_html_image($params, Smarty_Internal_Template $template) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - + $template->_checkPlugins( + array( + array( + 'function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' + ) + ) + ); $alt = ''; $file = ''; $height = ''; @@ -59,53 +63,50 @@ function smarty_function_html_image($params, $template) case 'basedir': $$_key = $_val; break; - case 'alt': if (!is_array($_val)) { $$_key = smarty_function_escape_special_chars($_val); } else { - throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + throw new SmartyException( + "html_image: extra attribute '{$_key}' cannot be an array", + E_USER_NOTICE + ); } 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 { - throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + throw new SmartyException( + "html_image: extra attribute '{$_key}' cannot be an array", + E_USER_NOTICE + ); } break; } } - if (empty($file)) { - trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); - + trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE); return; } - - if ($file[ 0 ] == '/') { + if ($file[ 0 ] === '/') { $_image_path = $basedir . $file; } else { $_image_path = $file; } - // strip file protocol if (stripos($params[ 'file' ], 'file://') === 0) { $params[ 'file' ] = substr($params[ 'file' ], 7); } - $protocol = strpos($params[ 'file' ], '://'); if ($protocol !== false) { $protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); } - if (isset($template->smarty->security_policy)) { if ($protocol) { // remote resource (or php stream, …) @@ -119,25 +120,20 @@ function smarty_function_html_image($params, $template) } } } - if (!isset($params[ 'width' ]) || !isset($params[ 'height' ])) { // FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader! if (!$_image_data = @getimagesize($_image_path)) { if (!file_exists($_image_path)) { - trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); - + trigger_error("html_image: unable to find '{$_image_path}'", E_USER_NOTICE); return; } elseif (!is_readable($_image_path)) { - trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); - + trigger_error("html_image: unable to read '{$_image_path}'", E_USER_NOTICE); return; } else { - trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); - + trigger_error("html_image: '{$_image_path}' is not a valid image file", E_USER_NOTICE); return; } } - if (!isset($params[ 'width' ])) { $width = $_image_data[ 0 ]; } @@ -145,7 +141,6 @@ function smarty_function_html_image($params, $template) $height = $_image_data[ 1 ]; } } - if (isset($params[ 'dpi' ])) { if (strstr($_SERVER[ 'HTTP_USER_AGENT' ], 'Mac')) { // FIXME: (rodneyrehm) wrong dpi assumption @@ -158,7 +153,6 @@ function smarty_function_html_image($params, $template) $width = round($width * $_resize); $height = round($height * $_resize); } - return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"' . $extra . ' />' . $suffix; } |