[1058] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1058] | 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; |
---|
[1204] | 43 | |
---|
[1058] | 44 | if (!is_dir($this->site_url)) |
---|
| 45 | { |
---|
[1064] | 46 | array_push( |
---|
| 47 | $errors, |
---|
| 48 | array( |
---|
| 49 | 'path' => $this->site_url, |
---|
| 50 | 'type' => 'PWG-ERROR-NO-FS' |
---|
| 51 | ) |
---|
| 52 | ); |
---|
[1204] | 53 | |
---|
[1058] | 54 | return false; |
---|
| 55 | } |
---|
[1204] | 56 | |
---|
[1058] | 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 | |
---|
[1204] | 92 | if ( isset($conf['flip_file_ext'][$extension]) ) |
---|
[1058] | 93 | { |
---|
[1204] | 94 | $tn_ext = $this->get_tn_ext($path, $filename_wo_ext); |
---|
[1058] | 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 | } |
---|
[5176] | 117 | ksort($fs); |
---|
[1058] | 118 | } //end if is_dir |
---|
| 119 | return $fs; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | // returns the name of the attributes that are supported for |
---|
[1204] | 123 | // files update/synchronization |
---|
[1058] | 124 | function get_update_attributes() |
---|
| 125 | { |
---|
[1204] | 126 | return array('tn_ext', 'has_high', 'representative_ext'); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | function get_element_update_attributes($file) |
---|
| 130 | { |
---|
[1058] | 131 | global $conf; |
---|
[1204] | 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 | |
---|
[1883] | 157 | $update_fields = array('filesize', 'width', 'height', 'high_filesize'); |
---|
[1204] | 158 | |
---|
[1058] | 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 | } |
---|
[1204] | 176 | |
---|
[1058] | 177 | return $update_fields; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | // returns a hash of attributes (metadata+filesize+width,...) for file |
---|
[1883] | 181 | function get_element_metadata($file, $has_high = false) |
---|
[1058] | 182 | { |
---|
| 183 | global $conf; |
---|
| 184 | if (!is_file($file)) |
---|
| 185 | { |
---|
| 186 | return null; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | $data = array(); |
---|
| 190 | |
---|
[1204] | 191 | $data['filesize'] = floor(filesize($file)/1024); |
---|
[1058] | 192 | |
---|
| 193 | if ($image_size = @getimagesize($file)) |
---|
| 194 | { |
---|
| 195 | $data['width'] = $image_size[0]; |
---|
| 196 | $data['height'] = $image_size[1]; |
---|
| 197 | } |
---|
| 198 | |
---|
[1883] | 199 | if ($has_high) |
---|
| 200 | { |
---|
| 201 | $high_file = dirname($file).'/pwg_high/'.basename($file); |
---|
[5176] | 202 | |
---|
[1883] | 203 | $data['high_filesize'] = floor(filesize($high_file)/1024); |
---|
| 204 | } |
---|
[5176] | 205 | |
---|
[1058] | 206 | if ($conf['use_exif']) |
---|
| 207 | { |
---|
[6076] | 208 | $exif = get_sync_exif_data($file); |
---|
| 209 | if (count($exif) == 0 and isset($data['high_filesize'])) |
---|
| 210 | { |
---|
| 211 | $exif = get_sync_exif_data($high_file); |
---|
| 212 | } |
---|
| 213 | $data = array_merge($data, $exif); |
---|
[1058] | 214 | } |
---|
| 215 | |
---|
| 216 | if ($conf['use_iptc']) |
---|
| 217 | { |
---|
[6076] | 218 | $iptc = get_sync_iptc_data($file); |
---|
| 219 | if (count($iptc) == 0 and isset($data['high_filesize'])) |
---|
| 220 | { |
---|
| 221 | $iptc = get_sync_iptc_data($high_file); |
---|
| 222 | } |
---|
| 223 | $data = array_merge($data, $iptc); |
---|
[1058] | 224 | } |
---|
[1204] | 225 | |
---|
[1058] | 226 | return $data; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | //-------------------------------------------------- private functions -------- |
---|
| 231 | function get_representative_ext($path, $filename_wo_ext) |
---|
| 232 | { |
---|
| 233 | global $conf; |
---|
[1064] | 234 | $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.'; |
---|
[1058] | 235 | foreach ($conf['picture_ext'] as $ext) |
---|
| 236 | { |
---|
| 237 | $test = $base_test.$ext; |
---|
| 238 | if (is_file($test)) |
---|
| 239 | { |
---|
| 240 | return $ext; |
---|
| 241 | } |
---|
| 242 | } |
---|
| 243 | return null; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | function get_tn_ext($path, $filename_wo_ext) |
---|
| 247 | { |
---|
| 248 | global $conf; |
---|
[1204] | 249 | |
---|
[1064] | 250 | $base_test = |
---|
| 251 | $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.'; |
---|
[1204] | 252 | |
---|
[1058] | 253 | foreach ($conf['picture_ext'] as $ext) |
---|
| 254 | { |
---|
| 255 | $test = $base_test.$ext; |
---|
| 256 | if (is_file($test)) |
---|
| 257 | { |
---|
| 258 | return $ext; |
---|
| 259 | } |
---|
| 260 | } |
---|
[1204] | 261 | |
---|
[1058] | 262 | return null; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | function get_has_high($path, $filename) |
---|
| 266 | { |
---|
| 267 | if (is_file($path.'/pwg_high/'.$filename)) |
---|
| 268 | { |
---|
| 269 | return 'true'; |
---|
| 270 | } |
---|
[1204] | 271 | |
---|
[1058] | 272 | return null; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | } |
---|
[1029] | 276 | ?> |
---|