/[cvs]/nfo/php/libs/net.php.smarty/plugins/function.html_image.php
ViewVC logotype

Annotation of /nfo/php/libs/net.php.smarty/plugins/function.html_image.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Wed Jun 16 21:58:16 2004 UTC (20 years, 2 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
updated to smarty-2.6.3

1 joko 1.1 <?php
2     /**
3     * Smarty plugin
4     * @package Smarty
5     * @subpackage plugins
6     */
7    
8    
9     /**
10     * Smarty {html_image} function plugin
11     *
12     * Type: function<br>
13     * Name: html_image<br>
14     * Date: Feb 24, 2003<br>
15     * Purpose: format HTML tags for the image<br>
16     * Input:<br>
17     * - file = file (and path) of image (required)
18     * - border = border width (optional, default 0)
19     * - height = image height (optional, default actual height)
20     * - image =image width (optional, default actual width)
21     * - basedir = base directory for absolute paths, default
22     * is environment variable DOCUMENT_ROOT
23     *
24     * Examples: {html_image file="images/masthead.gif"}
25     * Output: <img src="images/masthead.gif" border=0 width=400 height=23>
26     * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
27     * (Smarty online manual)
28     * @author Monte Ohrt <monte@ispi.net>
29     * @author credits to Duda <duda@big.hu> - wrote first image function
30     * in repository, helped with lots of functionality
31     * @version 1.0
32     * @param array
33     * @param Smarty
34     * @return string
35     * @uses smarty_function_escape_special_chars()
36     */
37     function smarty_function_html_image($params, &$smarty)
38     {
39     require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
40    
41     $alt = '';
42     $file = '';
43     $border = 0;
44     $height = '';
45     $width = '';
46     $extra = '';
47     $prefix = '';
48     $suffix = '';
49     $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
50     $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
51     foreach($params as $_key => $_val) {
52     switch($_key) {
53     case 'file':
54     case 'border':
55     case 'height':
56     case 'width':
57     case 'dpi':
58     case 'basedir':
59     $$_key = $_val;
60     break;
61    
62     case 'alt':
63     if(!is_array($_val)) {
64     $$_key = smarty_function_escape_special_chars($_val);
65     } else {
66     $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
67     }
68     break;
69    
70     case 'link':
71     case 'href':
72     $prefix = '<a href="' . $_val . '">';
73     $suffix = '</a>';
74     break;
75    
76     default:
77     if(!is_array($_val)) {
78     $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
79     } else {
80     $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
81     }
82     break;
83     }
84     }
85    
86     if (empty($file)) {
87     $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
88     return;
89     }
90    
91     if (substr($file,0,1) == '/') {
92     $_image_path = $basedir . $file;
93     } else {
94     $_image_path = $file;
95     }
96    
97     if(!isset($params['width']) || !isset($params['height'])) {
98     if ($smarty->security &&
99     ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) &&
100     (require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php')) &&
101     (!smarty_core_is_secure($_params, $smarty)) ) {
102     $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
103    
104     } elseif (!$_image_data = @getimagesize($_image_path)) {
105     if(!file_exists($_image_path)) {
106     $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
107     return;
108     } else if(!is_readable($_image_path)) {
109     $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
110     return;
111     } else {
112     $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
113     return;
114     }
115     }
116    
117     if(!isset($params['width'])) {
118     $width = $_image_data[0];
119     }
120     if(!isset($params['height'])) {
121     $height = $_image_data[1];
122     }
123    
124     }
125    
126     if(isset($params['dpi'])) {
127     if(strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) {
128     $dpi_default = 72;
129     } else {
130     $dpi_default = 96;
131     }
132     $_resize = $dpi_default/$params['dpi'];
133     $width = round($width * $_resize);
134     $height = round($height * $_resize);
135     }
136    
137     return $prefix . '<img src="'.$file.'" alt="'.$alt.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
138     }
139    
140     /* vim: set expandtab: */
141    
142     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed