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