228 |
kaklik |
1 |
<?php |
|
|
2 |
|
|
|
3 |
/** |
|
|
4 |
* Image class. |
|
|
5 |
* |
|
|
6 |
* @author Tamlyn Rhodes <tam at zenology dot co dot uk> |
|
|
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License |
|
|
8 |
* @copyright (c)2003-2005 Tamlyn Rhodes |
|
|
9 |
* @version $Id: image.class.php,v 1.22 2006/08/06 13:50:20 thepavian Exp $ |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
//include the base class |
|
|
13 |
require_once dirname(__FILE__)."/item.class.php"; |
|
|
14 |
|
|
|
15 |
/** |
|
|
16 |
* Data-only class used to store image data. |
|
|
17 |
* @package singapore |
|
|
18 |
* @author Tamlyn Rhodes <tam at zenology dot co dot uk> |
|
|
19 |
* @copyright (c)2003-2005 Tamlyn Rhodes |
|
|
20 |
*/ |
|
|
21 |
class sgImage extends sgItem |
|
|
22 |
{ |
|
|
23 |
/** |
|
|
24 |
* Width in pixels of the image |
|
|
25 |
* @var int |
|
|
26 |
*/ |
|
|
27 |
var $width = 0; |
|
|
28 |
|
|
|
29 |
/** |
|
|
30 |
* Height in pixels of the image |
|
|
31 |
* @var int |
|
|
32 |
*/ |
|
|
33 |
var $height = 0; |
|
|
34 |
|
|
|
35 |
/** |
|
|
36 |
* Image file format flag as returned by GetImageSize() |
|
|
37 |
* @var int |
|
|
38 |
*/ |
|
|
39 |
var $type; |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
/** |
|
|
43 |
* Configurable field |
|
|
44 |
*/ |
|
|
45 |
var $camera = ""; |
|
|
46 |
var $lens = ""; |
|
|
47 |
var $film = ""; |
|
|
48 |
var $darkroom = ""; |
|
|
49 |
var $digital = ""; |
|
|
50 |
|
|
|
51 |
/** |
|
|
52 |
* Constructor |
|
|
53 |
* @param string image id |
|
|
54 |
* @param sgGallery reference to the parent gallery |
|
|
55 |
*/ |
|
|
56 |
function sgImage($id, &$parent) |
|
|
57 |
{ |
|
|
58 |
$this->id = $id; |
|
|
59 |
$this->parent =& $parent; |
|
|
60 |
$this->config =& sgConfig::getInstance(); |
|
|
61 |
$this->translator =& Translator::getInstance(); |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
/** |
|
|
65 |
* Over-rides the method in the item class |
|
|
66 |
* @return true returns true |
|
|
67 |
*/ |
|
|
68 |
function isImage() { return true; } |
|
|
69 |
|
|
|
70 |
|
|
|
71 |
/** |
|
|
72 |
* @return bool true if image height is greater than width |
|
|
73 |
*/ |
|
|
74 |
function isPortrait() |
|
|
75 |
{ |
|
|
76 |
return $this->width()/$this->height() > 1; |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
/** |
|
|
80 |
* @return bool true if image height is greater than width |
|
|
81 |
*/ |
|
|
82 |
function isLandscape() |
|
|
83 |
{ |
|
|
84 |
return $this->width()/$this->height() < 1; |
|
|
85 |
} |
|
|
86 |
|
|
|
87 |
function hasPrev() |
|
|
88 |
{ |
|
|
89 |
return (bool) $this->index(); |
|
|
90 |
} |
|
|
91 |
|
|
|
92 |
function hasNext() |
|
|
93 |
{ |
|
|
94 |
$index = $this->index(); |
|
|
95 |
return $index !== false && $index < $this->parent->imageCount()-1; |
|
|
96 |
} |
|
|
97 |
|
|
|
98 |
function &firstImage() |
|
|
99 |
{ |
|
|
100 |
return $this->parent->images[0]; |
|
|
101 |
} |
|
|
102 |
|
|
|
103 |
function &prevImage() |
|
|
104 |
{ |
|
|
105 |
return $this->parent->images[$this->index()-1]; |
|
|
106 |
} |
|
|
107 |
|
|
|
108 |
function &nextImage() |
|
|
109 |
{ |
|
|
110 |
return $this->parent->images[$this->index()+1]; |
|
|
111 |
} |
|
|
112 |
|
|
|
113 |
function &lastImage() |
|
|
114 |
{ |
|
|
115 |
return $this->parent->images[count($this->parent->images)-1]; |
|
|
116 |
} |
|
|
117 |
|
|
|
118 |
function firstLink($action = null) |
|
|
119 |
{ |
|
|
120 |
if(!$this->hasPrev()) |
|
|
121 |
return ""; |
|
|
122 |
|
|
|
123 |
$tmp =& $this->firstImage(); |
|
|
124 |
return '<a href="'.$tmp->URL(null, $action).'">'.$this->firstText().'</a>'; |
|
|
125 |
} |
|
|
126 |
|
|
|
127 |
function prevLink($action = null) |
|
|
128 |
{ |
|
|
129 |
if(!$this->hasPrev()) |
|
|
130 |
return ""; |
|
|
131 |
|
|
|
132 |
return '<a href="'.$this->prevURL($action).'">'.$this->prevText().'</a>'; |
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
function nextLink($action = null) |
|
|
136 |
{ |
|
|
137 |
if(!$this->hasNext()) |
|
|
138 |
return ""; |
|
|
139 |
|
|
|
140 |
return '<a href="'.$this->nextURL($action).'">'.$this->nextText().'</a>'; |
|
|
141 |
} |
|
|
142 |
|
|
|
143 |
function lastLink($action = null) |
|
|
144 |
{ |
|
|
145 |
if(!$this->hasNext()) |
|
|
146 |
return ""; |
|
|
147 |
|
|
|
148 |
$tmp =& $this->lastImage(); |
|
|
149 |
return '<a href="'.$tmp->URL(null, $action).'">'.$this->lastText().'</a>'; |
|
|
150 |
} |
|
|
151 |
|
|
|
152 |
function prevURL($action = null) |
|
|
153 |
{ |
|
|
154 |
$tmp =& $this->prevImage(); |
|
|
155 |
return $tmp->URL(null, $action); |
|
|
156 |
} |
|
|
157 |
|
|
|
158 |
function nextURL($action = null) |
|
|
159 |
{ |
|
|
160 |
$tmp =& $this->nextImage(); |
|
|
161 |
return $tmp->URL(null, $action); |
|
|
162 |
} |
|
|
163 |
|
|
|
164 |
function firstText() { return $this->translator->_g("image|First"); } |
|
|
165 |
function prevText() { return $this->translator->_g("image|Previous"); } |
|
|
166 |
function nextText() { return $this->translator->_g("image|Next"); } |
|
|
167 |
function lastText() { return $this->translator->_g("image|Last"); } |
|
|
168 |
function parentText() { return $this->translator->_g("image|Thumbnails"); } |
|
|
169 |
|
|
|
170 |
function imageURL() |
|
|
171 |
{ |
|
|
172 |
if($this->config->full_image_resize) { |
|
|
173 |
$img = $this->thumbnail("image"); |
|
|
174 |
return $img->URL(); |
|
|
175 |
} else |
|
|
176 |
return $this->realURL(); |
|
|
177 |
} |
|
|
178 |
|
|
|
179 |
function realURL() |
|
|
180 |
{ |
|
|
181 |
if($this->isRemote()) |
|
|
182 |
return $this->id; |
|
|
183 |
else |
|
|
184 |
return $this->config->base_url.$this->config->pathto_galleries.$this->parent->idEncoded()."/".$this->idEncoded(); |
|
|
185 |
} |
|
|
186 |
|
|
|
187 |
function imageHTML($class = "sgImage") |
|
|
188 |
{ |
|
|
189 |
$ret = "<img src=\"".$this->imageURL().'" '; |
|
|
190 |
$ret .= 'class="'.$class.'" '; |
|
|
191 |
$ret .= 'width="'.$this->width().'" height="'.$this->height().'" '; |
|
|
192 |
if($this->config->imagemap_navigation) $ret .= 'usemap="#sgNavMap" border="0" '; |
|
|
193 |
$ret .= 'alt="'.$this->name().$this->byArtistText().'" />'; |
|
|
194 |
|
|
|
195 |
return $ret; |
|
|
196 |
} |
|
|
197 |
|
|
|
198 |
function thumbnailURL($type = "album") |
|
|
199 |
{ |
|
|
200 |
$thumb = $this->thumbnail($type); |
|
|
201 |
return $thumb->URL(); |
|
|
202 |
} |
|
|
203 |
|
|
|
204 |
function thumbnailHTML($class = "sgThumbnailAlbum", $type = "album") |
|
|
205 |
{ |
|
|
206 |
$thumb = $this->thumbnail($type); |
|
|
207 |
$ret = "<img src=\"".$thumb->URL().'" '; |
|
|
208 |
$ret .= 'class="'.$class.'" '; |
|
|
209 |
$ret .= 'width="'.$thumb->width().'" height="'.$thumb->height().'" '; |
|
|
210 |
$ret .= 'alt="'.$this->name().$this->byArtistText().'" />'; |
|
|
211 |
return $ret; |
|
|
212 |
} |
|
|
213 |
|
|
|
214 |
function thumbnailLink($class = "sgThumbnailAlbum", $type = "album") |
|
|
215 |
{ |
|
|
216 |
return '<a href="'.$this->URL().'">'.$this->thumbnailHTML($class, $type).'</a>'; |
|
|
217 |
} |
|
|
218 |
|
|
|
219 |
function thumbnailPopupLink($class = "sgThumbnailAlbum", $type = "album") |
|
|
220 |
{ |
|
|
221 |
$ret = '<a href="'.$this->URL().'" onclick="'; |
|
|
222 |
$ret .= "window.open('".$this->imageURL()."','','toolbar=0,resizable=1,"; |
|
|
223 |
$ret .= "width=".($this->width()+20).","; |
|
|
224 |
$ret .= "height=".($this->height()+20)."');"; |
|
|
225 |
$ret .= "return false;\">".$this->thumbnailHTML($class, $type)."</a>"; |
|
|
226 |
return $ret; |
|
|
227 |
} |
|
|
228 |
|
|
|
229 |
function nameForce() |
|
|
230 |
{ |
|
|
231 |
if($this->name) |
|
|
232 |
return $this->name; |
|
|
233 |
elseif($this->isRemote()) |
|
|
234 |
return substr($this->id, strrpos($this->id,'/') + 1, strrpos($this->id,'.') - strrpos($this->id,'/') - 1); |
|
|
235 |
else |
|
|
236 |
return substr($this->id, 0, strrpos($this->id,'.')); |
|
|
237 |
} |
|
|
238 |
|
|
|
239 |
/** |
|
|
240 |
* checks if image is remote (filename starts with 'http://') |
|
|
241 |
*/ |
|
|
242 |
function isRemote($image = null) |
|
|
243 |
{ |
|
|
244 |
if($image == null) $image = $this->id; |
|
|
245 |
return substr($image, 0, 7) == "http://"; |
|
|
246 |
} |
|
|
247 |
|
|
|
248 |
/** |
|
|
249 |
* @return string the absolute, canonical system path to the image |
|
|
250 |
*/ |
|
|
251 |
function realPath() |
|
|
252 |
{ |
|
|
253 |
if($this->isRemote()) |
|
|
254 |
return $this->id; |
|
|
255 |
else |
|
|
256 |
return realpath($this->config->base_path.$this->config->pathto_galleries.$this->parent->id."/".$this->id); |
|
|
257 |
} |
|
|
258 |
|
|
|
259 |
/** |
|
|
260 |
* @return string the rawurlencoded version of the image id |
|
|
261 |
*/ |
|
|
262 |
function idEncoded() |
|
|
263 |
{ |
|
|
264 |
return rawurlencode($this->id); |
|
|
265 |
} |
|
|
266 |
|
|
|
267 |
function width() |
|
|
268 |
{ |
|
|
269 |
if($this->config->full_image_resize) { |
|
|
270 |
$img = $this->thumbnail("image"); |
|
|
271 |
return $img->width(); |
|
|
272 |
} else |
|
|
273 |
return $this->realWidth(); |
|
|
274 |
} |
|
|
275 |
|
|
|
276 |
function height() |
|
|
277 |
{ |
|
|
278 |
if($this->config->full_image_resize) { |
|
|
279 |
$img = $this->thumbnail("image"); |
|
|
280 |
return $img->height(); |
|
|
281 |
} else |
|
|
282 |
return $this->realHeight(); |
|
|
283 |
} |
|
|
284 |
|
|
|
285 |
/** |
|
|
286 |
* finds position of current image in parent array |
|
|
287 |
*/ |
|
|
288 |
function index() |
|
|
289 |
{ |
|
|
290 |
foreach($this->parent->images as $key => $img) |
|
|
291 |
if($this->id == $img->id) |
|
|
292 |
return $key; |
|
|
293 |
|
|
|
294 |
return false; |
|
|
295 |
} |
|
|
296 |
|
|
|
297 |
function realWidth() |
|
|
298 |
{ |
|
|
299 |
//try to load image dimensions if not already loaded |
|
|
300 |
if($this->width == 0) { |
|
|
301 |
$size = @GetImageSize($this->realPath()); |
|
|
302 |
if($size) |
|
|
303 |
list($this->width, $this->height, $this->type) = $size; |
|
|
304 |
else |
|
|
305 |
return $this->config->thumb_width_image; |
|
|
306 |
} |
|
|
307 |
return $this->width; |
|
|
308 |
} |
|
|
309 |
|
|
|
310 |
function realHeight() |
|
|
311 |
{ |
|
|
312 |
//try to load image dimensions if not already loaded |
|
|
313 |
if($this->height == 0) { |
|
|
314 |
$size = @GetImageSize($this->realPath()); |
|
|
315 |
if($size) |
|
|
316 |
list($this->width, $this->height, $this->type) = $size; |
|
|
317 |
else |
|
|
318 |
return $this->config->thumb_height_image; |
|
|
319 |
} |
|
|
320 |
return $this->height; |
|
|
321 |
} |
|
|
322 |
|
|
|
323 |
/** Accessor methods */ |
|
|
324 |
function type() { return $this->type; } |
|
|
325 |
|
|
|
326 |
|
|
|
327 |
/* Private methods */ |
|
|
328 |
|
|
|
329 |
function &thumbnail($type) |
|
|
330 |
{ |
|
|
331 |
//only create thumbnail if it doesn't already exist |
|
|
332 |
if(!isset($this->thumbnails[$type])) |
|
|
333 |
$this->thumbnails[$type] =& new sgThumbnail($this, $type); |
|
|
334 |
|
|
|
335 |
return $this->thumbnails[$type]; |
|
|
336 |
} |
|
|
337 |
} |
|
|
338 |
|
|
|
339 |
?> |