[1058] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008 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 | // +-----------------------------------------------------------------------+ |
---|
[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 | } |
---|
| 117 | } //end if is_dir |
---|
| 118 | return $fs; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // returns the name of the attributes that are supported for |
---|
[1204] | 122 | // files update/synchronization |
---|
[1058] | 123 | function get_update_attributes() |
---|
| 124 | { |
---|
[1204] | 125 | return array('tn_ext', 'has_high', 'representative_ext'); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | function get_element_update_attributes($file) |
---|
| 129 | { |
---|
[1058] | 130 | global $conf; |
---|
[1204] | 131 | $data = array(); |
---|
| 132 | |
---|
| 133 | $filename = basename($file); |
---|
| 134 | $dirname = dirname($file); |
---|
| 135 | $filename_wo_ext = get_filename_wo_extension($filename); |
---|
| 136 | $extension = get_extension($filename); |
---|
| 137 | |
---|
| 138 | $data['tn_ext'] = $this->get_tn_ext($dirname, $filename_wo_ext); |
---|
| 139 | $data['has_high'] = $this->get_has_high($dirname, $filename); |
---|
| 140 | |
---|
| 141 | if ( !isset($conf['flip_picture_ext'][$extension]) ) |
---|
| 142 | { |
---|
| 143 | $data['representative_ext'] = $this->get_representative_ext( |
---|
| 144 | $dirname, $filename_wo_ext |
---|
| 145 | ); |
---|
| 146 | } |
---|
| 147 | return $data; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | // returns the name of the attributes that are supported for |
---|
| 151 | // metadata update/synchronization according to configuration |
---|
| 152 | function get_metadata_attributes() |
---|
| 153 | { |
---|
| 154 | global $conf; |
---|
| 155 | |
---|
[1883] | 156 | $update_fields = array('filesize', 'width', 'height', 'high_filesize'); |
---|
[1204] | 157 | |
---|
[1058] | 158 | if ($conf['use_exif']) |
---|
| 159 | { |
---|
| 160 | $update_fields = |
---|
| 161 | array_merge( |
---|
| 162 | $update_fields, |
---|
| 163 | array_keys($conf['use_exif_mapping']) |
---|
| 164 | ); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | if ($conf['use_iptc']) |
---|
| 168 | { |
---|
| 169 | $update_fields = |
---|
| 170 | array_merge( |
---|
| 171 | $update_fields, |
---|
| 172 | array_keys($conf['use_iptc_mapping']) |
---|
| 173 | ); |
---|
| 174 | } |
---|
[1204] | 175 | |
---|
[1058] | 176 | return $update_fields; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | // returns a hash of attributes (metadata+filesize+width,...) for file |
---|
[1883] | 180 | function get_element_metadata($file, $has_high = false) |
---|
[1058] | 181 | { |
---|
| 182 | global $conf; |
---|
| 183 | if (!is_file($file)) |
---|
| 184 | { |
---|
| 185 | return null; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | $data = array(); |
---|
| 189 | |
---|
[1204] | 190 | $data['filesize'] = floor(filesize($file)/1024); |
---|
[1058] | 191 | |
---|
| 192 | if ($image_size = @getimagesize($file)) |
---|
| 193 | { |
---|
| 194 | $data['width'] = $image_size[0]; |
---|
| 195 | $data['height'] = $image_size[1]; |
---|
| 196 | } |
---|
| 197 | |
---|
[1883] | 198 | if ($has_high) |
---|
| 199 | { |
---|
| 200 | $high_file = dirname($file).'/pwg_high/'.basename($file); |
---|
| 201 | |
---|
| 202 | $data['high_filesize'] = floor(filesize($high_file)/1024); |
---|
| 203 | } |
---|
| 204 | |
---|
[1058] | 205 | if ($conf['use_exif']) |
---|
| 206 | { |
---|
[1717] | 207 | $data = array_merge($data, get_sync_exif_data($file) ); |
---|
[1058] | 208 | } |
---|
| 209 | |
---|
| 210 | if ($conf['use_iptc']) |
---|
| 211 | { |
---|
[1717] | 212 | $data = array_merge($data, get_sync_iptc_data($file) ); |
---|
[1058] | 213 | } |
---|
[1204] | 214 | |
---|
[1058] | 215 | return $data; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | //-------------------------------------------------- private functions -------- |
---|
| 220 | function get_representative_ext($path, $filename_wo_ext) |
---|
| 221 | { |
---|
| 222 | global $conf; |
---|
[1064] | 223 | $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.'; |
---|
[1058] | 224 | foreach ($conf['picture_ext'] as $ext) |
---|
| 225 | { |
---|
| 226 | $test = $base_test.$ext; |
---|
| 227 | if (is_file($test)) |
---|
| 228 | { |
---|
| 229 | return $ext; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | return null; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | function get_tn_ext($path, $filename_wo_ext) |
---|
| 236 | { |
---|
| 237 | global $conf; |
---|
[1204] | 238 | |
---|
[1064] | 239 | $base_test = |
---|
| 240 | $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.'; |
---|
[1204] | 241 | |
---|
[1058] | 242 | foreach ($conf['picture_ext'] as $ext) |
---|
| 243 | { |
---|
| 244 | $test = $base_test.$ext; |
---|
| 245 | if (is_file($test)) |
---|
| 246 | { |
---|
| 247 | return $ext; |
---|
| 248 | } |
---|
| 249 | } |
---|
[1204] | 250 | |
---|
[1058] | 251 | return null; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | function get_has_high($path, $filename) |
---|
| 255 | { |
---|
| 256 | if (is_file($path.'/pwg_high/'.$filename)) |
---|
| 257 | { |
---|
| 258 | return 'true'; |
---|
| 259 | } |
---|
[1204] | 260 | |
---|
[1058] | 261 | return null; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | } |
---|
[1029] | 265 | ?> |
---|