1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2005-12-03 17:03:58 -0500 (Sat, 03 Dec 2005) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 967 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | // provides data for site synchronization from the local file system |
---|
29 | class LocalSiteReader |
---|
30 | { |
---|
31 | |
---|
32 | var $site_url; |
---|
33 | |
---|
34 | function LocalSiteReader($url) |
---|
35 | { |
---|
36 | $this->site_url = $url; |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * Is this local site ok ? |
---|
41 | * |
---|
42 | * @return true on success, false otherwise |
---|
43 | */ |
---|
44 | function open() |
---|
45 | { |
---|
46 | global $errors; |
---|
47 | |
---|
48 | if (!is_dir($this->site_url)) |
---|
49 | { |
---|
50 | array_push( |
---|
51 | $errors, |
---|
52 | array( |
---|
53 | 'path' => $this->site_url, |
---|
54 | 'type' => 'PWG-ERROR-NO-FS' |
---|
55 | ) |
---|
56 | ); |
---|
57 | |
---|
58 | return false; |
---|
59 | } |
---|
60 | |
---|
61 | return true; |
---|
62 | } |
---|
63 | |
---|
64 | // retrieve file system sub-directories fulldirs |
---|
65 | function get_full_directories($basedir) |
---|
66 | { |
---|
67 | $fs_fulldirs = get_fs_directories($basedir); |
---|
68 | return $fs_fulldirs; |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * Returns an array with all file system files according to $conf['file_ext'] |
---|
73 | * and $conf['picture_ext'] |
---|
74 | * @param string $path recurse in this directory |
---|
75 | * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... ) |
---|
76 | */ |
---|
77 | function get_elements($path) |
---|
78 | { |
---|
79 | global $conf; |
---|
80 | if (!isset($conf['flip_picture_ext'])) |
---|
81 | { |
---|
82 | $conf['flip_picture_ext'] = array_flip($conf['picture_ext']); |
---|
83 | } |
---|
84 | if (!isset($conf['flip_file_ext'])) |
---|
85 | { |
---|
86 | $conf['flip_file_ext'] = array_flip($conf['file_ext']); |
---|
87 | } |
---|
88 | |
---|
89 | $subdirs = array(); |
---|
90 | $fs = array(); |
---|
91 | if (is_dir($path) && $contents = opendir($path) ) |
---|
92 | { |
---|
93 | while (($node = readdir($contents)) !== false) |
---|
94 | { |
---|
95 | if (is_file($path.'/'.$node)) |
---|
96 | { |
---|
97 | $extension = get_extension($node); |
---|
98 | $filename_wo_ext = get_filename_wo_extension($node); |
---|
99 | |
---|
100 | // searching the thumbnail |
---|
101 | $tn_ext = $this->get_tn_ext($path, $filename_wo_ext); |
---|
102 | |
---|
103 | if (isset($conf['flip_picture_ext'][$extension])) |
---|
104 | { |
---|
105 | $fs[ $path.'/'.$node ] = array( |
---|
106 | 'tn_ext' => $tn_ext, |
---|
107 | 'has_high' => $this->get_has_high($path, $node) |
---|
108 | ); |
---|
109 | } |
---|
110 | else if (isset($conf['flip_file_ext'][$extension])) |
---|
111 | { // file not a picture |
---|
112 | $representative_ext = $this->get_representative_ext($path, $filename_wo_ext); |
---|
113 | |
---|
114 | $fs[ $path.'/'.$node ] = array( |
---|
115 | 'tn_ext' => $tn_ext, |
---|
116 | 'representative_ext' => $representative_ext |
---|
117 | ); |
---|
118 | } |
---|
119 | |
---|
120 | } |
---|
121 | elseif (is_dir($path.'/'.$node) |
---|
122 | and $node != '.' |
---|
123 | and $node != '..' |
---|
124 | and $node != 'pwg_high' |
---|
125 | and $node != 'pwg_representative' |
---|
126 | and $node != 'thumbnail' ) |
---|
127 | { |
---|
128 | array_push($subdirs, $node); |
---|
129 | } |
---|
130 | } //end while readdir |
---|
131 | closedir($contents); |
---|
132 | |
---|
133 | foreach ($subdirs as $subdir) |
---|
134 | { |
---|
135 | $tmp_fs = $this->get_elements($path.'/'.$subdir); |
---|
136 | $fs = array_merge($fs, $tmp_fs); |
---|
137 | } |
---|
138 | } //end if is_dir |
---|
139 | return $fs; |
---|
140 | } |
---|
141 | |
---|
142 | // returns the name of the attributes that are supported for |
---|
143 | // update/synchronization according to configuration |
---|
144 | function get_update_attributes() |
---|
145 | { |
---|
146 | global $conf; |
---|
147 | |
---|
148 | $update_fields = array( |
---|
149 | 'has_high', 'representative_ext', 'filesize', 'width', 'height' |
---|
150 | ); |
---|
151 | |
---|
152 | if ($conf['use_exif']) |
---|
153 | { |
---|
154 | $update_fields = |
---|
155 | array_merge( |
---|
156 | $update_fields, |
---|
157 | array_keys($conf['use_exif_mapping']) |
---|
158 | ); |
---|
159 | } |
---|
160 | |
---|
161 | if ($conf['use_iptc']) |
---|
162 | { |
---|
163 | $update_fields = |
---|
164 | array_merge( |
---|
165 | $update_fields, |
---|
166 | array_keys($conf['use_iptc_mapping']) |
---|
167 | ); |
---|
168 | } |
---|
169 | |
---|
170 | return $update_fields; |
---|
171 | } |
---|
172 | |
---|
173 | // returns a hash of attributes (metadata+filesize+width,...) for file |
---|
174 | function get_element_update_attributes($file) |
---|
175 | { |
---|
176 | global $conf; |
---|
177 | if (!is_file($file)) |
---|
178 | { |
---|
179 | return null; |
---|
180 | } |
---|
181 | |
---|
182 | $data = array(); |
---|
183 | |
---|
184 | $filename = basename($file); |
---|
185 | |
---|
186 | $data['has_high'] = $this->get_has_high(dirname($file), $filename); |
---|
187 | |
---|
188 | $data['representative_ext'] = $this->get_representative_ext( |
---|
189 | dirname($file), |
---|
190 | get_filename_wo_extension($filename) |
---|
191 | ); |
---|
192 | |
---|
193 | $data['filesize'] = floor(filesize($file)/1024); |
---|
194 | if ($image_size = @getimagesize($file)) |
---|
195 | { |
---|
196 | $data['width'] = $image_size[0]; |
---|
197 | $data['height'] = $image_size[1]; |
---|
198 | } |
---|
199 | |
---|
200 | if ($conf['use_exif']) |
---|
201 | { |
---|
202 | $exif = get_sync_exif_data($file); |
---|
203 | |
---|
204 | if (count($exif) > 0) |
---|
205 | { |
---|
206 | foreach (array_keys($exif) as $key) |
---|
207 | { |
---|
208 | $data[$key] = addslashes($exif[$key]); |
---|
209 | } |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | if ($conf['use_iptc']) |
---|
214 | { |
---|
215 | $iptc = get_sync_iptc_data($file); |
---|
216 | if (count($iptc) > 0) |
---|
217 | { |
---|
218 | foreach (array_keys($iptc) as $key) |
---|
219 | { |
---|
220 | $data[$key] = addslashes($iptc[$key]); |
---|
221 | } |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | return $data; |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | //-------------------------------------------------- private functions -------- |
---|
230 | function get_representative_ext($path, $filename_wo_ext) |
---|
231 | { |
---|
232 | global $conf; |
---|
233 | $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.'; |
---|
234 | foreach ($conf['picture_ext'] as $ext) |
---|
235 | { |
---|
236 | $test = $base_test.$ext; |
---|
237 | if (is_file($test)) |
---|
238 | { |
---|
239 | return $ext; |
---|
240 | } |
---|
241 | } |
---|
242 | return null; |
---|
243 | } |
---|
244 | |
---|
245 | function get_tn_ext($path, $filename_wo_ext) |
---|
246 | { |
---|
247 | global $conf; |
---|
248 | |
---|
249 | $base_test = |
---|
250 | $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.'; |
---|
251 | |
---|
252 | foreach ($conf['picture_ext'] as $ext) |
---|
253 | { |
---|
254 | $test = $base_test.$ext; |
---|
255 | if (is_file($test)) |
---|
256 | { |
---|
257 | return $ext; |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | return null; |
---|
262 | } |
---|
263 | |
---|
264 | function get_has_high($path, $filename) |
---|
265 | { |
---|
266 | if (is_file($path.'/pwg_high/'.$filename)) |
---|
267 | { |
---|
268 | return 'true'; |
---|
269 | } |
---|
270 | |
---|
271 | return null; |
---|
272 | } |
---|
273 | |
---|
274 | } |
---|
275 | ?> |
---|