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