39 require_once(SMARTY_PLUGINS_DIR .
'shared.escape_special_chars.php');
49 $basedir = isset($_SERVER[
'DOCUMENT_ROOT']) ? $_SERVER[
'DOCUMENT_ROOT'] :
'';
50 foreach($params as $_key => $_val) {
62 if (!is_array($_val)) {
63 $$_key = smarty_function_escape_special_chars($_val);
65 throw new SmartyException (
"html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
71 $prefix =
'<a href="' . $_val .
'">';
76 if (!is_array($_val)) {
77 $extra .=
' ' . $_key .
'="' . smarty_function_escape_special_chars($_val) .
'"';
79 throw new SmartyException (
"html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
86 trigger_error(
"html_image: missing 'file' parameter", E_USER_NOTICE);
90 if ($file[0] ==
'/') {
91 $_image_path = $basedir . $file;
97 if (stripos($params[
'file'],
'file://') === 0) {
98 $params[
'file'] = substr($params[
'file'], 7);
101 $protocol = strpos($params[
'file'],
'://');
102 if ($protocol !==
false) {
103 $protocol = strtolower(substr($params[
'file'], 0, $protocol));
106 if (isset($template->smarty->security_policy)) {
109 if(!$template->smarty->security_policy->isTrustedUri($params[
'file'])) {
114 if(!$template->smarty->security_policy->isTrustedResourceDir($params[
'file'])) {
120 if (!isset($params[
'width']) || !isset($params[
'height'])) {
122 if (!$_image_data = @getimagesize($_image_path)) {
123 if (!file_exists($_image_path)) {
124 trigger_error(
"html_image: unable to find '$_image_path'", E_USER_NOTICE);
126 }
else if (!is_readable($_image_path)) {
127 trigger_error(
"html_image: unable to read '$_image_path'", E_USER_NOTICE);
130 trigger_error(
"html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
135 if (!isset($params[
'width'])) {
136 $width = $_image_data[0];
138 if (!isset($params[
'height'])) {
139 $height = $_image_data[1];
143 if (isset($params[
'dpi'])) {
144 if (strstr($_SERVER[
'HTTP_USER_AGENT'],
'Mac')) {
151 $_resize = $dpi_default / $params[
'dpi'];
152 $width = round($width * $_resize);
153 $height = round($height * $_resize);
156 return $prefix .
'<img src="' . $path_prefix . $file .
'" alt="' . $alt .
'" width="' . $width .
'" height="' . $height .
'"' . $extra .
' />' . $suffix;
smarty_function_html_image($params, $template)
Smarty {html_image} function plugin.