1 |
<?php |
2 |
/* vim: set ts=4: |
3 |
+----------------------------------------------------------------------+ |
4 |
| expose, a simple image gallery written in php4. |
5 |
+----------------------------------------------------------------------+ |
6 |
| Copyright 2003 Carl Johan Schedvin |
7 |
| This program is distributed under the terms of the |
8 |
| GNU General Public License, Version 2 |
9 |
| |
10 |
| This program is free software; you can redistribute it and/or modify |
11 |
| it under the terms of the GNU General Public License, Version 2 as |
12 |
| published by the Free Software Foundation. |
13 |
| |
14 |
| This program is distributed in the hope that it will be useful, |
15 |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
| GNU General Public License for more details. |
18 |
| |
19 |
| You should have received a copy of the GNU General Public License, |
20 |
| Version 2 along with this program; if not, visit GNU's Home Page |
21 |
| http://www.gnu.org/ |
22 |
+----------------------------------------------------------------------+ |
23 |
$Id: index.php,v 1.5 2003/11/06 11:47:12 cam Exp $ |
24 |
|
25 |
|
26 |
|
27 |
// CODE FOR EMBEDDING AVI/MPEG/MOV FILES IN HTML |
28 |
|
29 |
<embed src="filename" autostart="false" width="320" height="240" align="left" oncursor="play" hspace="20"> |
30 |
<noembed> |
31 |
<a href="filename">click to view</a> |
32 |
<img dynsrc="filename" start="mouseover" align="left" controls width="320" height="240" hspace="25"> |
33 |
</a> |
34 |
</noembed> |
35 |
*/ |
36 |
|
37 |
$global_var['metadata']['author'] = "Carl Johan Schedvin <cjsc02@student.bth.se>"; |
38 |
$global_var['metadata']['keywords'] = "photos,gallery,album,digitalcamera,fuji,finepix"; |
39 |
$global_var['metadata']['description'] = "An photogallery written in PHP4"; |
40 |
|
41 |
|
42 |
$global_var['str_msg']['copyright'] = "all photos © copyright Carl Johan Schedvin. all rights reserved."; |
43 |
|
44 |
$global_var['external']['magick'] = "/usr/bin/convert"; |
45 |
|
46 |
$global_var['path']['thumb_dir'] = '.thumbs'; |
47 |
$global_var['path']['cache_dir'] = '.cache'; |
48 |
|
49 |
$global_var['image_sz']['thumb'] = array ( |
50 |
'x' => 120, |
51 |
'y' => 80, |
52 |
'ql' => 70, |
53 |
'wm' => '' |
54 |
); |
55 |
$global_var['image_sz']['640'] = array ( |
56 |
'x' => 640, |
57 |
'y' => 480, |
58 |
'ql' => 88, |
59 |
'wm' => '' |
60 |
); |
61 |
$global_var['image_sz']['800'] = array ( |
62 |
'x' => 800, |
63 |
'y' => 600, |
64 |
'ql' => 89, |
65 |
'wm' => '' |
66 |
); |
67 |
$global_var['image_sz']['1024'] = array ( |
68 |
'x' => 1024, |
69 |
'y' => 768, |
70 |
'ql' => 90, |
71 |
'wm' => '' |
72 |
); |
73 |
|
74 |
$global_var['image_sz']['default'] =& $global_var['image_sz']['640']; |
75 |
|
76 |
$global_var['exif'] = array ( |
77 |
'Make', |
78 |
'ApertureFNumber', |
79 |
'FocalLength', |
80 |
'DateTime', |
81 |
'FlashMode' |
82 |
); |
83 |
$exif_headers = array (); |
84 |
|
85 |
|
86 |
if(isset($_SERVER['PHP_SELF'])) { |
87 |
$php_self = $_SERVER['PHP_SELF']; |
88 |
} else { |
89 |
$php_self = $HTTP_SERVER_VARS['PHP_SELF']; |
90 |
} |
91 |
|
92 |
if (isset($_GET)) { |
93 |
$get_vars = $_GET; |
94 |
} else { |
95 |
$get_vars = $HTTP_GET_VARS; |
96 |
} |
97 |
|
98 |
|
99 |
|
100 |
/** |
101 |
* ! NOT IMPLEMENTED ! |
102 |
* |
103 |
* Extracts the EXIF header of a JPG if available using |
104 |
* built-in php function exif_read_data, this information |
105 |
* is extracted upon request and not written to disk. |
106 |
*/ |
107 |
function extract_exif_data() |
108 |
{ |
109 |
global $global_var, $pwd, $get_vars, $exif_headers; |
110 |
|
111 |
$src_image = $get_vars['img']; |
112 |
$exif_data = @exif_read_data($pwd.'/'.$src_image,0,true); |
113 |
|
114 |
if($exif_data) { |
115 |
|
116 |
foreach($exif_data as $exif_section_key => $exif_section) { |
117 |
foreach($exif_section as $exif_key => $exif_value) { |
118 |
|
119 |
if(array_search($exif_key, $global_var['exif'])) { |
120 |
|
121 |
switch($exif_key) { |
122 |
case 'Make': |
123 |
array_push($exif_headers, 'Model: '.$exif_value); |
124 |
break; |
125 |
|
126 |
case 'ApertureFNumber': |
127 |
array_push($exif_headers, 'Aperture: '. $exif_value); |
128 |
break; |
129 |
|
130 |
case 'FocalLength': |
131 |
$factor = 6.49122807; |
132 |
$vars = split("/",$exif_value); |
133 |
$focal_length = round(($vars[0]/$vars[1])*$factor); |
134 |
array_push($exif_headers, 'Focal Length: '. $focal_length .'mm'); |
135 |
break; |
136 |
|
137 |
case 'DateTime': |
138 |
array_push($exif_headers, 'Date: '.$exif_value); |
139 |
break; |
140 |
|
141 |
case 'FlashMode': |
142 |
switch($exif_value) { |
143 |
case '0': |
144 |
array_push($exif_headers, 'Flash: Off'); |
145 |
break; |
146 |
case '1': |
147 |
array_push($exif_headers, 'Flash: On'); |
148 |
break; |
149 |
} |
150 |
break; |
151 |
|
152 |
default: |
153 |
break; |
154 |
} |
155 |
} |
156 |
} |
157 |
} |
158 |
if(sizeof($exif_headers)>0) { |
159 |
ksort($exif_headers); |
160 |
reset($exif_headers); |
161 |
} |
162 |
} |
163 |
} |
164 |
|
165 |
|
166 |
|
167 |
|
168 |
function create_thumbnail($src_image) |
169 |
{ |
170 |
global $global_var, $pwd; |
171 |
if(isset($global_var['external']['magick'])) { |
172 |
if(file_exists($pwd.'/'.$src_image)) { |
173 |
$src_image_sz = GetImageSize($pwd.'/'.$src_image); |
174 |
$resize_aspect = round(($global_var['image_sz']['thumb']['y'] / $src_image_sz[1])*100, 2); |
175 |
exec($global_var['external']['magick'] |
176 |
.' -geometry '.$resize_aspect.'%' |
177 |
.' -quality '.$global_var['image_sz']['thumb']['ql'] |
178 |
.' '.$pwd.'/'.$src_image |
179 |
.' '.$pwd.'/'.$global_var['path']['thumb_dir'].'/'.$src_image |
180 |
); |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
|
186 |
function print_thumbnails() |
187 |
{ |
188 |
global $global_var, $image_files, $pwd; |
189 |
|
190 |
// check if thumbnail directory exists, if not create it. |
191 |
if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir'])) |
192 |
mkdir($pwd.'/'.$global_var['path']['thumb_dir'],0777); |
193 |
|
194 |
echo <<<EOT |
195 |
<div id="thumbnails_container">\n |
196 |
|
197 |
EOT; |
198 |
|
199 |
foreach($image_files as $image) { |
200 |
|
201 |
$thumb_image = $pwd.'/'.$global_var['path']['thumb_dir'].'/'.$image; |
202 |
|
203 |
// check if a thumbnail for current image exists, if not create one. |
204 |
if(!file_exists($thumb_image)) |
205 |
create_thumbnail($image); |
206 |
|
207 |
$thumb_sz = GetImageSize($thumb_image); |
208 |
|
209 |
echo <<<EOT |
210 |
<div class="thumbnail" style="width: {$thumb_sz[0]}px; height: {$thumb_sz[1]}px;">\n |
211 |
<a href="$php_self?dir=$pwd&img=$image"> |
212 |
<img src="$thumb_image" alt=""/> |
213 |
</a> |
214 |
</div>\n |
215 |
EOT; |
216 |
} |
217 |
|
218 |
echo <<<EOT |
219 |
</div>\n |
220 |
<div style="clear: both;"><br/></div>\n |
221 |
EOT; |
222 |
} |
223 |
|
224 |
|
225 |
|
226 |
|
227 |
function show_image() |
228 |
{ |
229 |
global $global_var, $get_vars, $pwd, $exif_headers; |
230 |
|
231 |
$image = $pwd.'/'.$get_vars['img']; |
232 |
|
233 |
$cached_image = $pwd.'/'.$global_var['path']['cache_dir']; |
234 |
|
235 |
if(file_exists($image)) { |
236 |
|
237 |
$image_size = GetImageSize($image); |
238 |
|
239 |
if(isset($get_var['width'])) { |
240 |
if($get_var['width'] >= $image_size[0]) |
241 |
$cache_image = $image; |
242 |
} else { |
243 |
if(!file_exists($cached_image.'/default_'.$get_vars['img'])) { |
244 |
resize_image('default_'); |
245 |
} |
246 |
$cached_image = $cached_image.'/default_'.$get_vars['img']; |
247 |
} |
248 |
|
249 |
$image_size = GetImageSize($cached_image); |
250 |
|
251 |
extract_exif_data(); |
252 |
|
253 |
if(sizeof($exif_headers) > 0) { |
254 |
|
255 |
$exif_str .= sprintf("<span style=\"font-weight: bold; color:#333;\">EXIF</span> "); |
256 |
|
257 |
foreach($exif_headers as $exif_tag) { |
258 |
$exif_str .= sprintf("| %s ", $exif_tag); |
259 |
} |
260 |
|
261 |
echo <<<EOT |
262 |
<div id="exif_headers">\n |
263 |
<span>$exif_str</span>\n |
264 |
</div>\n |
265 |
EOT; |
266 |
|
267 |
} |
268 |
|
269 |
|
270 |
echo <<<EOT |
271 |
<div id="image" style="width: {$image_size[0]}px; height: {$image_size[1]}px;">\n |
272 |
<a href="$image" target="_blank"><img src="$cached_image" alt=""></a> |
273 |
</div>\n |
274 |
EOT; |
275 |
|
276 |
$image_index = get_image_index(); |
277 |
$next = get_next_image($image_index); |
278 |
$prev = get_prev_image($image_index); |
279 |
|
280 |
echo <<<EOT |
281 |
<a href="$php_self?dir=$pwd&img=$prev">prev</a> |
282 |
<a href="$php_self?dir=$pwd&img=$next">next</a> |
283 |
EOT; |
284 |
|
285 |
} |
286 |
} |
287 |
|
288 |
|
289 |
|
290 |
|
291 |
function resize_image($prefix) |
292 |
{ |
293 |
global $global_var, $get_vars, $pwd; |
294 |
$src_image = $get_vars['img']; |
295 |
$cache_dir = $pwd.'/'.$global_var['path']['cache_dir']; |
296 |
|
297 |
if(isset($global_var['external']['magick'])) { |
298 |
if(file_exists($pwd.'/'.$src_image)) { |
299 |
$src_image_sz = GetImageSize($pwd.'/'.$src_image); |
300 |
$resize_aspect = round(($global_var['image_sz']['default']['y'] / $src_image_sz[1])*100, 2); |
301 |
|
302 |
// DEBUG: print "Quality: ".$global_var['image_sz']['default']['ql'] ." Resize Aspect: ". $resize_aspect ."%"; |
303 |
if(!file_exists($cache_dir)) |
304 |
mkdir($cache_dir,0777); |
305 |
|
306 |
exec($global_var['external']['magick'] |
307 |
.' -geometry '.$resize_aspect.'%' |
308 |
.' -quality '.$global_var['image_sz']['default']['ql'] |
309 |
.' '.$pwd.'/'.$src_image |
310 |
.' '.$pwd.'/'.$global_var['path']['cache_dir'].'/'.$prefix.$src_image |
311 |
); |
312 |
} |
313 |
} |
314 |
} |
315 |
|
316 |
|
317 |
|
318 |
|
319 |
function get_image_index() |
320 |
{ |
321 |
global $get_vars, $image_files; |
322 |
|
323 |
return array_search($get_vars['img'], $image_files); |
324 |
} |
325 |
|
326 |
function get_next_image($pos) |
327 |
{ |
328 |
global $get_vars, $image_files; |
329 |
|
330 |
$next = $pos + 1; |
331 |
|
332 |
if($next >= sizeof($image_files)) |
333 |
$next = 0; |
334 |
|
335 |
return $image_files[$next]; |
336 |
} |
337 |
|
338 |
function get_prev_image($pos) |
339 |
{ |
340 |
global $get_vars, $image_files; |
341 |
|
342 |
$prev = $pos - 1; |
343 |
|
344 |
if($prev < 0) |
345 |
$prev = sizeof($image_files) - 1; |
346 |
|
347 |
return $image_files[$prev]; |
348 |
} |
349 |
|
350 |
|
351 |
function get_split_path() |
352 |
{ |
353 |
global $pwd; |
354 |
|
355 |
$split_path = split('/', $pwd); |
356 |
|
357 |
return $split_path; |
358 |
} |
359 |
/** |
360 |
* Retirieves all filenames that are images exclude all |
361 |
* other files. It's not recursive so it only examins the |
362 |
* pwd and not sub directories if present. |
363 |
* |
364 |
* @param str $path, pwd |
365 |
* @return @rray $images, list of all filenames |
366 |
*/ |
367 |
function &get_image_filenames($path) |
368 |
{ |
369 |
global $global_var; |
370 |
$images = array(); |
371 |
|
372 |
if(is_dir($path)) { |
373 |
$pwd_dd = opendir($path); |
374 |
while(($file = readdir($pwd_dd)) !== false) { |
375 |
if(is_file($path."/".$file) |
376 |
&& !eregi("^\.|^.*.php|^.*.css|^.*~|^.txt",$file)) |
377 |
array_push($images, $file); |
378 |
} |
379 |
} |
380 |
return $images; |
381 |
} |
382 |
|
383 |
|
384 |
|
385 |
|
386 |
/** |
387 |
* Retrieves all directory names present in $path. Using |
388 |
* eregi we exclude names we don't want in the list. |
389 |
*/ |
390 |
function &get_directory_names($path) |
391 |
{ |
392 |
global $global_var; |
393 |
$dirs = array(); |
394 |
|
395 |
if(is_dir($path)) { |
396 |
$pwd_dd = opendir($path); |
397 |
while(($file = readdir($pwd_dd)) !== false) { |
398 |
if(is_dir($path."/".$file) |
399 |
&& !eregi("^\.|^\..|^CVS|^". $global_var['path']['thumb_dir'] |
400 |
."|^". $global_var['path']['cache_dir'],$file)) |
401 |
array_push($dirs, $file); |
402 |
} |
403 |
} |
404 |
return $dirs; |
405 |
} |
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
if (isset($get_vars['dir']) && is_dir(rawurldecode($get_vars['dir']))) |
414 |
{ |
415 |
$pwd = rawurldecode($get_vars['dir']); |
416 |
} else { |
417 |
$pwd = './'; |
418 |
} |
419 |
|
420 |
$image_files =& get_image_filenames($pwd); |
421 |
$dir_files =& get_directory_names($pwd); |
422 |
|
423 |
|
424 |
// print the html header before continuing processing. |
425 |
html_template_header(); |
426 |
|
427 |
//if($global_var['navigation_bar']) |
428 |
html_template_navbar(); |
429 |
|
430 |
if(sizeof($image_files) <= 0) { |
431 |
if(sizeof($dir_files) > 0) { |
432 |
} else { |
433 |
} |
434 |
} else { |
435 |
if(sizeof($dir_files) > 0) { |
436 |
} |
437 |
if(isset($get_vars['img'])) { |
438 |
show_image(); |
439 |
} else { |
440 |
print_thumbnails(); |
441 |
} |
442 |
} |
443 |
|
444 |
// print the html footer to make it nice and tidy. |
445 |
html_template_footer(); |
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
/** |
456 |
* Prints the html header, contains html document specific |
457 |
* definitions and paths. Tags as <title> are set dynamically |
458 |
* everytime the page is reloaded. The template is encapsulated |
459 |
* in a function for structural reasons. |
460 |
*/ |
461 |
function html_template_header() |
462 |
{ |
463 |
global $global_var; |
464 |
echo <<<EOF |
465 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
466 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
467 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > |
468 |
|
469 |
<head> |
470 |
|
471 |
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> |
472 |
<meta name="author" content="{$global_var[metadata][author]}" /> |
473 |
<meta name="keywords" content="{$global_var[metadata][keywords]}" /> |
474 |
<meta name="description" content="{$global_var[metadata][description]}" /> |
475 |
<meta name="robots" content="all" /> |
476 |
|
477 |
<title>expose: </title> |
478 |
|
479 |
<style type="text/css"> |
480 |
@import "./style.css"; |
481 |
</style> |
482 |
|
483 |
<link rel="Shortcut Icon" type="image/x-icon" href="/img/favicon.ico" /> |
484 |
|
485 |
</head> |
486 |
|
487 |
<body> |
488 |
<div id="header">\n |
489 |
<h1>expose:</h1> |
490 |
<span style="font-style: italic;"></span> |
491 |
</div>\n |
492 |
<div id="container">\n |
493 |
EOF; |
494 |
} |
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
/** |
503 |
* Prints the html footer, this contains only closing |
504 |
* tags for the html document and the copyright notice. |
505 |
*/ |
506 |
function html_template_footer() |
507 |
{ |
508 |
global $global_var; |
509 |
echo <<<EOF |
510 |
<div id="copyright">\n |
511 |
{$global_var[str_msg][copyright]}<br />\n |
512 |
<a href="">expose</a>\n <span style="font-style: italic;">\$Revision: 1.5 $</span>\n |
513 |
</div>\n\n |
514 |
</div>\n |
515 |
</body>\n |
516 |
</html>\n |
517 |
EOF; |
518 |
} |
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
function html_template_navbar() |
526 |
{ |
527 |
global $get_vars; |
528 |
$split_path = get_split_path(); |
529 |
|
530 |
if(sizeof($split_path) > 0) { |
531 |
|
532 |
foreach($split_path as $dir) { |
533 |
if($dir!='') { |
534 |
$path .= $dir.'/'; |
535 |
echo <<<EOT |
536 |
<a style="text-decoration: none;" href="$php_self?dir=$path"> |
537 |
EOT; |
538 |
if($dir == '.') |
539 |
$dir = 'expose'; |
540 |
|
541 |
echo <<<EOT |
542 |
$dir</a> > \n |
543 |
EOT; |
544 |
} |
545 |
} |
546 |
if(isset($get_vars['img'])) { |
547 |
echo <<<EOT |
548 |
{$get_vars[img]} |
549 |
EOT; |
550 |
} |
551 |
} |
552 |
} |
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
function html_template_alt_resolutions() |
561 |
{ |
562 |
} |
563 |
?> |