/[cvs]/expose/index.php
ViewVC logotype

Contents of /expose/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Wed Nov 5 13:50:57 2003 UTC (20 years, 6 months ago) by cam
Branch: MAIN
Branch point for: expose
Initial revision

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 */
24
25 $global_var['metadata']['author'] = "Carl Johan Schedvin <cjsc02@student.bth.se>";
26 $global_var['metadata']['keywords'] = "photos,gallery,album,digitalcamera,fuji,finepix";
27 $global_var['metadata']['description'] = "An photogallery written in PHP4";
28
29
30 $global_var['str_msg']['copyright'] = "all photos &copy; copyright Carl Johan Schedvin. all rights reserved.";
31
32 $global_var['external']['magick'] = "/usr/bin/convert";
33
34 $global_var['path']['thumb_dir'] = '.thumbs';
35 $global_var['path']['cache_dir'] = '.cache';
36
37 $global_var['image_sz']['thumb'] = array (
38 'x' => 120,
39 'y' => 80,
40 'ql' => 70,
41 'wm' => ''
42 );
43
44 $global_var['image_sz']['640'] = array (
45 'x' => 640,
46 'y' => 480,
47 'ql' => 88,
48 'wm' => ''
49 );
50 $global_var['image_sz']['800'] = array (
51 'x' => 800,
52 'y' => 600,
53 'ql' => 89,
54 'wm' => ''
55 );
56 $global_var['image_sz']['1024'] = array (
57 'x' => 1024,
58 'y' => 768,
59 'ql' => 90,
60 'wm' => ''
61 );
62
63
64
65 if(isset($_SERVER['PHP_SELF'])) {
66 $php_self = $_SERVER['PHP_SELF'];
67 } else {
68 $php_self = $HTTP_SERVER_VARS['PHP_SELF'];
69 }
70
71 if (isset($_GET)) {
72 $get_vars = $_GET;
73 } else {
74 $get_vars = $HTTP_GET_VARS;
75 }
76
77
78
79 /**
80 * ! NOT IMPLEMENTED !
81 *
82 * Extracts the EXIF header of a JPG if available using
83 * built-in php function exif_read_data, this information
84 * is extracted upon request and not written to disk.
85 */
86 function extract_exif_data()
87 {
88 }
89
90
91
92
93 function create_thumbnail($src_image)
94 {
95 global $global_var, $pwd;
96 if(isset($global_var['external']['magick'])) {
97 if(file_exists($pwd.'/'.$src_image)) {
98 $src_image_sz = GetImageSize($pwd.'/'.$src_image);
99 $resize_aspect = round(($global_var['image_sz']['thumb']['y'] / $src_image_sz[1])*100, 2);
100 exec($global_var['external']['magick']
101 .' -geometry '.$resize_aspect.'%'
102 .' -quality '.$global_var['image_sz']['thumb']['ql']
103 .' '.$pwd.'/'.$src_image
104 .' '.$pwd.'/'.$global_var['path']['thumb_dir'].'/'.$src_image
105 );
106 }
107 }
108 }
109
110
111 function print_thumbnails()
112 {
113 global $global_var, $image_files, $pwd;
114
115 // check if thumbnail directory exists, if not create it.
116 if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir']))
117 mkdir($pwd.'/'.$global_var['path']['thumb_dir'],0777);
118
119 foreach($image_files as $image) {
120
121 // check if a thumbnail for current image exists, if not create one.
122 if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir'].'/'.$image))
123 create_thumbnail($image);
124
125 echo <<<EOT
126 <div class="thumbnail">\n
127 <a href="$php_self?dir=$pwd&img=$image">
128 <img src="$pwd/{$global_var[path][thumb_dir]}/$image" alt=""/>
129 </a>
130 </div>\n
131 EOT;
132 }
133 }
134
135
136
137
138 function show_image()
139 {
140 global $global_var, $get_vars, $pwd;
141
142 if(file_exists($pwd.'/'.$get_vars['img'])) {
143 echo <<<EOT
144 <div id="image">\n
145 <img src="$pwd/{$get_vars[img]}" alt="">
146 </div>\n
147 EOT;
148 }
149 }
150
151
152
153
154 function resize_image()
155 {
156 }
157
158
159 /**
160 * Retirieves all filenames that are images exclude all
161 * other files. It's not recursive so it only examins the
162 * pwd and not sub directories if present.
163 *
164 * @param str $path, pwd
165 * @return @rray $images, list of all filenames
166 */
167 function &get_image_filenames($path)
168 {
169 global $global_var;
170 $images = array();
171
172 if(is_dir($path)) {
173 $pwd_dd = opendir($path);
174 while(($file = readdir($pwd_dd)) !== false) {
175 if(is_file($path."/".$file)
176 && !eregi("^\.|^.*.php|^.*.css|^.*~",$file))
177 //&& $file != '.' && $file != '..')
178 array_push($images, $file);
179 }
180 }
181 return $images;
182 }
183
184
185
186 /**
187 * Retrieves all directory names present in $path. Using
188 * eregi we exclude names we don't want in the list.
189 */
190 function &get_directory_names($path)
191 {
192 global $global_var;
193 $dirs = array();
194
195 if(is_dir($path)) {
196 $pwd_dd = opendir($path);
197 while(($file = readdir($pwd_dd)) !== false) {
198 if(is_dir($path."/".$file)
199 && !eregi("^\.|^\..|^". $global_var['path']['thumb_dir']
200 ."|^". $global_var['path']['cache_dir'],$file))
201 array_push($dirs, $file);
202 }
203 }
204 return $dirs;
205 }
206
207
208
209 if (isset($get_vars['dir']) && is_dir(rawurldecode($get_vars['dir'])))
210 {
211 $pwd = rawurldecode($get_vars['dir']);
212 } else {
213 $pwd = './';
214 }
215
216 $image_files =& get_image_filenames($pwd);
217 $dir_files =& get_directory_names($pwd);
218
219
220 // print the html header before continuing processing.
221 html_template_header();
222
223
224 if(sizeof($image_files) <= 0) {
225 if(sizeof($dir_files) > 0) {
226 } else {
227 }
228 } else {
229 if(sizeof($dir_files) > 0) {
230 }
231 if(isset($get_vars['img'])) {
232 show_image();
233 } else {
234 print_thumbnails();
235 }
236 }
237
238 // print the html footer to make it nice and tidy.
239 html_template_footer();
240
241
242
243
244
245
246
247
248
249 /**
250 * Prints the html header, contains html document specific
251 * definitions and paths. Tags as <title> are set dynamically
252 * everytime the page is reloaded. The template is encapsulated
253 * in a function for structural reasons.
254 */
255 function html_template_header()
256 {
257 global $global_var;
258 echo <<<EOF
259 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
260 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
261 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
262
263 <head>
264
265 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
266 <meta name="author" content="{$global_var[metadata][author]}" />
267 <meta name="keywords" content="{$global_var[metadata][keywords]}" />
268 <meta name="description" content="{$global_var[metadata][description]}" />
269 <meta name="robots" content="all" />
270
271 <title></title>
272
273 <style type="text/css">
274 @import "/~ikea/style.css";
275 </style>
276
277 <link rel="Shortcut Icon" type="image/x-icon" href="/img/favicon.ico" />
278
279 </head>
280
281 <body>
282
283 <div id="container">\n
284 EOF;
285 }
286
287
288
289
290 /**
291 * Prints the html footer, this contains only closing
292 * tags for the html document and the copyright notice.
293 */
294 function html_template_footer()
295 {
296 global $global_var;
297 echo <<<EOF
298 <div id="copyright">\n
299 {$global_var[str_msg][copyright]}
300 </div>
301 </div>
302 </body>
303 </html>
304 EOF;
305 }
306 ?>

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26