[1058] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1717] | 5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[1058] | 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | branch : BSF (Best So Far) |
---|
[1717] | 8 | // | file : $Id: site_reader_local.php 1900 2007-03-12 22:33:53Z rub $ |
---|
| 9 | // | last update : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $ |
---|
| 10 | // | last modifier : $Author: rub $ |
---|
| 11 | // | revision : $Revision: 1900 $ |
---|
[1058] | 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; |
---|
[1204] | 47 | |
---|
[1058] | 48 | if (!is_dir($this->site_url)) |
---|
| 49 | { |
---|
[1064] | 50 | array_push( |
---|
| 51 | $errors, |
---|
| 52 | array( |
---|
| 53 | 'path' => $this->site_url, |
---|
| 54 | 'type' => 'PWG-ERROR-NO-FS' |
---|
| 55 | ) |
---|
| 56 | ); |
---|
[1204] | 57 | |
---|
[1058] | 58 | return false; |
---|
| 59 | } |
---|
[1204] | 60 | |
---|
[1058] | 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_file_ext'])) |
---|
| 81 | { |
---|
| 82 | $conf['flip_file_ext'] = array_flip($conf['file_ext']); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | $subdirs = array(); |
---|
| 86 | $fs = array(); |
---|
| 87 | if (is_dir($path) && $contents = opendir($path) ) |
---|
| 88 | { |
---|
| 89 | while (($node = readdir($contents)) !== false) |
---|
| 90 | { |
---|
| 91 | if (is_file($path.'/'.$node)) |
---|
| 92 | { |
---|
| 93 | $extension = get_extension($node); |
---|
| 94 | $filename_wo_ext = get_filename_wo_extension($node); |
---|
| 95 | |
---|
[1204] | 96 | if ( isset($conf['flip_file_ext'][$extension]) ) |
---|
[1058] | 97 | { |
---|
[1204] | 98 | $tn_ext = $this->get_tn_ext($path, $filename_wo_ext); |
---|
[1058] | 99 | $fs[ $path.'/'.$node ] = array( |
---|
| 100 | 'tn_ext' => $tn_ext, |
---|
| 101 | ); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | elseif (is_dir($path.'/'.$node) |
---|
| 105 | and $node != '.' |
---|
| 106 | and $node != '..' |
---|
| 107 | and $node != 'pwg_high' |
---|
| 108 | and $node != 'pwg_representative' |
---|
| 109 | and $node != 'thumbnail' ) |
---|
| 110 | { |
---|
| 111 | array_push($subdirs, $node); |
---|
| 112 | } |
---|
| 113 | } //end while readdir |
---|
| 114 | closedir($contents); |
---|
| 115 | |
---|
| 116 | foreach ($subdirs as $subdir) |
---|
| 117 | { |
---|
| 118 | $tmp_fs = $this->get_elements($path.'/'.$subdir); |
---|
| 119 | $fs = array_merge($fs, $tmp_fs); |
---|
| 120 | } |
---|
| 121 | } //end if is_dir |
---|
| 122 | return $fs; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | // returns the name of the attributes that are supported for |
---|
[1204] | 126 | // files update/synchronization |
---|
[1058] | 127 | function get_update_attributes() |
---|
| 128 | { |
---|
[1204] | 129 | return array('tn_ext', 'has_high', 'representative_ext'); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | function get_element_update_attributes($file) |
---|
| 133 | { |
---|
[1058] | 134 | global $conf; |
---|
[1204] | 135 | $data = array(); |
---|
| 136 | |
---|
| 137 | $filename = basename($file); |
---|
| 138 | $dirname = dirname($file); |
---|
| 139 | $filename_wo_ext = get_filename_wo_extension($filename); |
---|
| 140 | $extension = get_extension($filename); |
---|
| 141 | |
---|
| 142 | $data['tn_ext'] = $this->get_tn_ext($dirname, $filename_wo_ext); |
---|
| 143 | $data['has_high'] = $this->get_has_high($dirname, $filename); |
---|
| 144 | |
---|
| 145 | if ( !isset($conf['flip_picture_ext'][$extension]) ) |
---|
| 146 | { |
---|
| 147 | $data['representative_ext'] = $this->get_representative_ext( |
---|
| 148 | $dirname, $filename_wo_ext |
---|
| 149 | ); |
---|
| 150 | } |
---|
| 151 | return $data; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | // returns the name of the attributes that are supported for |
---|
| 155 | // metadata update/synchronization according to configuration |
---|
| 156 | function get_metadata_attributes() |
---|
| 157 | { |
---|
| 158 | global $conf; |
---|
| 159 | |
---|
[1883] | 160 | $update_fields = array('filesize', 'width', 'height', 'high_filesize'); |
---|
[1204] | 161 | |
---|
[1058] | 162 | if ($conf['use_exif']) |
---|
| 163 | { |
---|
| 164 | $update_fields = |
---|
| 165 | array_merge( |
---|
| 166 | $update_fields, |
---|
| 167 | array_keys($conf['use_exif_mapping']) |
---|
| 168 | ); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | if ($conf['use_iptc']) |
---|
| 172 | { |
---|
| 173 | $update_fields = |
---|
| 174 | array_merge( |
---|
| 175 | $update_fields, |
---|
| 176 | array_keys($conf['use_iptc_mapping']) |
---|
| 177 | ); |
---|
| 178 | } |
---|
[1204] | 179 | |
---|
[1058] | 180 | return $update_fields; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | // returns a hash of attributes (metadata+filesize+width,...) for file |
---|
[1883] | 184 | function get_element_metadata($file, $has_high = false) |
---|
[1058] | 185 | { |
---|
| 186 | global $conf; |
---|
| 187 | if (!is_file($file)) |
---|
| 188 | { |
---|
| 189 | return null; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | $data = array(); |
---|
| 193 | |
---|
[1204] | 194 | $data['filesize'] = floor(filesize($file)/1024); |
---|
[1058] | 195 | |
---|
| 196 | if ($image_size = @getimagesize($file)) |
---|
| 197 | { |
---|
| 198 | $data['width'] = $image_size[0]; |
---|
| 199 | $data['height'] = $image_size[1]; |
---|
| 200 | } |
---|
| 201 | |
---|
[1883] | 202 | if ($has_high) |
---|
| 203 | { |
---|
| 204 | $high_file = dirname($file).'/pwg_high/'.basename($file); |
---|
| 205 | |
---|
| 206 | $data['high_filesize'] = floor(filesize($high_file)/1024); |
---|
| 207 | } |
---|
| 208 | |
---|
[1058] | 209 | if ($conf['use_exif']) |
---|
| 210 | { |
---|
[1717] | 211 | $data = array_merge($data, get_sync_exif_data($file) ); |
---|
[1058] | 212 | } |
---|
| 213 | |
---|
| 214 | if ($conf['use_iptc']) |
---|
| 215 | { |
---|
[1717] | 216 | $data = array_merge($data, get_sync_iptc_data($file) ); |
---|
[1058] | 217 | } |
---|
[1204] | 218 | |
---|
[1058] | 219 | return $data; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | //-------------------------------------------------- private functions -------- |
---|
| 224 | function get_representative_ext($path, $filename_wo_ext) |
---|
| 225 | { |
---|
| 226 | global $conf; |
---|
[1064] | 227 | $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.'; |
---|
[1058] | 228 | foreach ($conf['picture_ext'] as $ext) |
---|
| 229 | { |
---|
| 230 | $test = $base_test.$ext; |
---|
| 231 | if (is_file($test)) |
---|
| 232 | { |
---|
| 233 | return $ext; |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | return null; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | function get_tn_ext($path, $filename_wo_ext) |
---|
| 240 | { |
---|
| 241 | global $conf; |
---|
[1204] | 242 | |
---|
[1064] | 243 | $base_test = |
---|
| 244 | $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.'; |
---|
[1204] | 245 | |
---|
[1058] | 246 | foreach ($conf['picture_ext'] as $ext) |
---|
| 247 | { |
---|
| 248 | $test = $base_test.$ext; |
---|
| 249 | if (is_file($test)) |
---|
| 250 | { |
---|
| 251 | return $ext; |
---|
| 252 | } |
---|
| 253 | } |
---|
[1204] | 254 | |
---|
[1058] | 255 | return null; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | function get_has_high($path, $filename) |
---|
| 259 | { |
---|
| 260 | if (is_file($path.'/pwg_high/'.$filename)) |
---|
| 261 | { |
---|
| 262 | return 'true'; |
---|
| 263 | } |
---|
[1204] | 264 | |
---|
[1058] | 265 | return null; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | } |
---|
[1029] | 269 | ?> |
---|