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

Annotation of /expose/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Wed Nov 5 14:21:33 2003 UTC (20 years, 6 months ago) by cam
Branch: MAIN
Changes since 1.2: +3 -2 lines
*** empty log message ***

1 cam 1.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 cam 1.3 $Id: index.php,v 1.2 2003/11/05 14:06:40 cam Exp $
24 cam 1.1 */
25    
26     $global_var['metadata']['author'] = "Carl Johan Schedvin <cjsc02@student.bth.se>";
27     $global_var['metadata']['keywords'] = "photos,gallery,album,digitalcamera,fuji,finepix";
28     $global_var['metadata']['description'] = "An photogallery written in PHP4";
29    
30    
31     $global_var['str_msg']['copyright'] = "all photos &copy; copyright Carl Johan Schedvin. all rights reserved.";
32    
33     $global_var['external']['magick'] = "/usr/bin/convert";
34    
35     $global_var['path']['thumb_dir'] = '.thumbs';
36     $global_var['path']['cache_dir'] = '.cache';
37    
38     $global_var['image_sz']['thumb'] = array (
39     'x' => 120,
40     'y' => 80,
41     'ql' => 70,
42     'wm' => ''
43     );
44    
45     $global_var['image_sz']['640'] = array (
46     'x' => 640,
47     'y' => 480,
48     'ql' => 88,
49     'wm' => ''
50     );
51     $global_var['image_sz']['800'] = array (
52     'x' => 800,
53     'y' => 600,
54     'ql' => 89,
55     'wm' => ''
56     );
57     $global_var['image_sz']['1024'] = array (
58     'x' => 1024,
59     'y' => 768,
60     'ql' => 90,
61     'wm' => ''
62     );
63    
64    
65    
66     if(isset($_SERVER['PHP_SELF'])) {
67     $php_self = $_SERVER['PHP_SELF'];
68     } else {
69     $php_self = $HTTP_SERVER_VARS['PHP_SELF'];
70     }
71    
72     if (isset($_GET)) {
73     $get_vars = $_GET;
74     } else {
75     $get_vars = $HTTP_GET_VARS;
76     }
77    
78    
79    
80     /**
81     * ! NOT IMPLEMENTED !
82     *
83     * Extracts the EXIF header of a JPG if available using
84     * built-in php function exif_read_data, this information
85     * is extracted upon request and not written to disk.
86     */
87     function extract_exif_data()
88     {
89     }
90    
91    
92    
93    
94     function create_thumbnail($src_image)
95     {
96     global $global_var, $pwd;
97     if(isset($global_var['external']['magick'])) {
98     if(file_exists($pwd.'/'.$src_image)) {
99     $src_image_sz = GetImageSize($pwd.'/'.$src_image);
100     $resize_aspect = round(($global_var['image_sz']['thumb']['y'] / $src_image_sz[1])*100, 2);
101     exec($global_var['external']['magick']
102     .' -geometry '.$resize_aspect.'%'
103     .' -quality '.$global_var['image_sz']['thumb']['ql']
104     .' '.$pwd.'/'.$src_image
105     .' '.$pwd.'/'.$global_var['path']['thumb_dir'].'/'.$src_image
106     );
107     }
108     }
109     }
110    
111    
112     function print_thumbnails()
113     {
114     global $global_var, $image_files, $pwd;
115    
116     // check if thumbnail directory exists, if not create it.
117     if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir']))
118     mkdir($pwd.'/'.$global_var['path']['thumb_dir'],0777);
119    
120     foreach($image_files as $image) {
121    
122     // check if a thumbnail for current image exists, if not create one.
123     if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir'].'/'.$image))
124     create_thumbnail($image);
125    
126     echo <<<EOT
127     <div class="thumbnail">\n
128     <a href="$php_self?dir=$pwd&img=$image">
129     <img src="$pwd/{$global_var[path][thumb_dir]}/$image" alt=""/>
130     </a>
131     </div>\n
132     EOT;
133     }
134     }
135    
136    
137    
138    
139     function show_image()
140     {
141     global $global_var, $get_vars, $pwd;
142    
143     if(file_exists($pwd.'/'.$get_vars['img'])) {
144     echo <<<EOT
145     <div id="image">\n
146     <img src="$pwd/{$get_vars[img]}" alt="">
147     </div>\n
148     EOT;
149     }
150     }
151    
152    
153    
154    
155     function resize_image()
156     {
157     }
158    
159    
160     /**
161     * Retirieves all filenames that are images exclude all
162     * other files. It's not recursive so it only examins the
163     * pwd and not sub directories if present.
164     *
165     * @param str $path, pwd
166     * @return @rray $images, list of all filenames
167     */
168     function &get_image_filenames($path)
169     {
170     global $global_var;
171     $images = array();
172    
173     if(is_dir($path)) {
174     $pwd_dd = opendir($path);
175     while(($file = readdir($pwd_dd)) !== false) {
176     if(is_file($path."/".$file)
177     && !eregi("^\.|^.*.php|^.*.css|^.*~",$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 cam 1.2 && !eregi("^\.|^\..|^CVS|^". $global_var['path']['thumb_dir']
200 cam 1.1 ."|^". $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 cam 1.3 {$global_var[str_msg][copyright]}<br />
300     <a href="">expose</a> <span style="font-style: italic;">cvs version: $Revision$</span>
301 cam 1.1 </div>
302     </div>
303     </body>
304     </html>
305     EOF;
306     }
307     ?>

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26