psr12 fixes for new PHP_CodeSniffer (#4795)
[openemr.git] / portal / patient / fwk / libs / savant / Savant3 / resources / Savant3_Plugin_image.php
blob63f03d82d82f09ea8b30a46cb8d98efc4cc6f1ac
1 <?php
3 /**
5 * Plugin to generate an <img ... /> tag.
7 * @package Savant3
9 * @author Paul M. Jones <pmjones@ciaweb.net>
11 * @license http://www.gnu.org/copyleft/lesser.html LGPL
13 * @version $Id: Savant3_Plugin_image.php,v 1.7 2005/08/12 14:34:09 pmjones Exp $
17 /**
19 * Plugin to generate an <img ... /> tag.
21 * Support for alpha transparency of PNG files in Microsoft IE added by
22 * Edward Ritter; thanks, Edward.
24 * @package Savant3
26 * @author Paul M. Jones <pmjones@ciaweb.net>
30 class Savant3_Plugin_image extends Savant3_Plugin
32 /**
34 * The document root.
36 * @access public
38 * @var string
41 protected $documentRoot = null;
43 /**
45 * The base directory for images within the document root.
47 * @access public
49 * @var string
52 protected $imageDir = null;
54 /**
56 * Outputs an <img ... /> tag.
58 * Microsoft IE alpha PNG support added by Edward Ritter.
60 * @access public
62 * @param string $file
63 * The path to the image on the local file system
64 * relative to $this->imageDir.
66 * @param string $alt
67 * Alternative descriptive text for the image;
68 * defaults to the filename of the image.
70 * @param int $border
71 * The border width for the image; defaults to zero.
73 * @param int $width
74 * The displayed image width in pixels; defaults to
75 * the width of the image.
77 * @param int $height
78 * The displayed image height in pixels; defaults to
79 * the height of the image.
81 * @return string An <img ... /> tag.
84 public function image($file, $alt = null, $height = null, $width = null, $attr = null)
86 // is the document root set?
87 if (is_null($this->documentRoot) && isset($_SERVER ['DOCUMENT_ROOT'])) {
88 // no, so set it
89 $this->documentRoot = $_SERVER ['DOCUMENT_ROOT'];
92 // make sure there's a DIRECTORY_SEPARATOR between the docroot
93 // and the image dir
94 if (substr($this->documentRoot, - 1) != DIRECTORY_SEPARATOR && substr($this->imageDir, 0, 1) != DIRECTORY_SEPARATOR) {
95 $this->documentRoot .= DIRECTORY_SEPARATOR;
98 // make sure there's a separator between the imageDir and the
99 // file name
100 if (substr($this->imageDir, - 1) != DIRECTORY_SEPARATOR && substr($file, 0, 1) != DIRECTORY_SEPARATOR) {
101 $this->imageDir .= DIRECTORY_SEPARATOR;
104 // the image file type code (PNG = 3)
105 $type = null;
107 // get the file information
108 $info = false;
110 if (strpos($file, '://') === false) {
111 // no "://" in the file, so it's local
112 $file = $this->imageDir . $file;
113 $tmp = $this->documentRoot . $file;
114 $info = @getimagesize($tmp);
115 } else {
116 // don't attempt to get file info from streams, it takes
117 // way too long.
118 $info = false;
121 // did we find the file info?
122 if (is_array($info)) {
123 // capture type info regardless
124 $type = $info [2];
126 // capture size info where both not specified
127 if (is_null($width) && is_null($height)) {
128 $width = $info [0];
129 $height = $info [1];
133 // clean up
134 unset($info);
136 // is the file a PNG? if so, check user agent, we will need to
137 // make special allowances for Microsoft IE.
138 if (stristr($_SERVER ['HTTP_USER_AGENT'], 'MSIE') && $type === 3) {
139 // support alpha transparency for PNG files in MSIE
140 $html = '<span style="position: relative;';
142 if ($height) {
143 $html .= ' height: ' . $height . 'px;';
146 if ($width) {
147 $html .= ' width: ' . $width . 'px;';
150 $html .= ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
151 $html .= "(src='" . htmlspecialchars($file) . "',sizingMethod='scale');\"";
152 $html .= ' title="' . htmlspecialchars($alt) . '"';
154 $html .= $this->Savant->htmlAttribs($attr);
156 // done
157 $html .= '></span>';
158 } else {
159 // not IE, so build a normal image tag.
160 $html = '<img';
161 $html .= ' src="' . htmlspecialchars($file) . '"';
163 // add the alt attribute
164 if (is_null($alt)) {
165 $alt = basename($file);
168 $html .= ' alt="' . htmlspecialchars($alt) . '"';
170 // add the height attribute
171 if ($height) {
172 $html .= ' height="' . htmlspecialchars($height) . '"';
175 // add the width attribute
176 if ($width) {
177 $html .= ' width="' . htmlspecialchars($width) . '"';
180 $html .= $this->Savant->htmlAttribs($attr);
182 // done
183 $html .= ' />';
186 // done!
187 return $html;