[1058] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 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; |
---|
[12831] | 33 | global $conf; |
---|
| 34 | if (!isset($conf['flip_file_ext'])) |
---|
| 35 | { |
---|
| 36 | $conf['flip_file_ext'] = array_flip($conf['file_ext']); |
---|
| 37 | } |
---|
| 38 | if (!isset($conf['flip_picture_ext'])) |
---|
| 39 | { |
---|
| 40 | $conf['flip_picture_ext'] = array_flip($conf['picture_ext']); |
---|
| 41 | } |
---|
[1058] | 42 | } |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * Is this local site ok ? |
---|
| 46 | * |
---|
| 47 | * @return true on success, false otherwise |
---|
| 48 | */ |
---|
| 49 | function open() |
---|
| 50 | { |
---|
| 51 | global $errors; |
---|
[1204] | 52 | |
---|
[1058] | 53 | if (!is_dir($this->site_url)) |
---|
| 54 | { |
---|
[1064] | 55 | array_push( |
---|
| 56 | $errors, |
---|
| 57 | array( |
---|
| 58 | 'path' => $this->site_url, |
---|
| 59 | 'type' => 'PWG-ERROR-NO-FS' |
---|
| 60 | ) |
---|
| 61 | ); |
---|
[1204] | 62 | |
---|
[1058] | 63 | return false; |
---|
| 64 | } |
---|
[1204] | 65 | |
---|
[1058] | 66 | return true; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | // retrieve file system sub-directories fulldirs |
---|
| 70 | function get_full_directories($basedir) |
---|
| 71 | { |
---|
| 72 | $fs_fulldirs = get_fs_directories($basedir); |
---|
| 73 | return $fs_fulldirs; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | * Returns an array with all file system files according to $conf['file_ext'] |
---|
| 78 | * and $conf['picture_ext'] |
---|
| 79 | * @param string $path recurse in this directory |
---|
[12831] | 80 | * @return array like "pic.jpg"=>array('representative_ext'=>'jpg' ... ) |
---|
[1058] | 81 | */ |
---|
| 82 | function get_elements($path) |
---|
| 83 | { |
---|
| 84 | global $conf; |
---|
| 85 | |
---|
| 86 | $subdirs = array(); |
---|
| 87 | $fs = array(); |
---|
| 88 | if (is_dir($path) && $contents = opendir($path) ) |
---|
| 89 | { |
---|
| 90 | while (($node = readdir($contents)) !== false) |
---|
| 91 | { |
---|
[12642] | 92 | if ($node == '.' or $node == '..') continue; |
---|
| 93 | |
---|
[1058] | 94 | if (is_file($path.'/'.$node)) |
---|
| 95 | { |
---|
| 96 | $extension = get_extension($node); |
---|
| 97 | $filename_wo_ext = get_filename_wo_extension($node); |
---|
| 98 | |
---|
[1204] | 99 | if ( isset($conf['flip_file_ext'][$extension]) ) |
---|
[1058] | 100 | { |
---|
[12831] | 101 | $representative_ext = null; |
---|
| 102 | if (! isset($conf['flip_picture_ext'][$extension]) ) |
---|
| 103 | { |
---|
| 104 | $representative_ext = $this->get_representative_ext($path, $filename_wo_ext); |
---|
| 105 | } |
---|
[1058] | 106 | $fs[ $path.'/'.$node ] = array( |
---|
[12831] | 107 | 'representative_ext' => $representative_ext, |
---|
[1058] | 108 | ); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | elseif (is_dir($path.'/'.$node) |
---|
| 112 | and $node != 'pwg_high' |
---|
| 113 | and $node != 'pwg_representative' |
---|
| 114 | and $node != 'thumbnail' ) |
---|
| 115 | { |
---|
| 116 | array_push($subdirs, $node); |
---|
| 117 | } |
---|
| 118 | } //end while readdir |
---|
| 119 | closedir($contents); |
---|
| 120 | |
---|
| 121 | foreach ($subdirs as $subdir) |
---|
| 122 | { |
---|
| 123 | $tmp_fs = $this->get_elements($path.'/'.$subdir); |
---|
| 124 | $fs = array_merge($fs, $tmp_fs); |
---|
| 125 | } |
---|
[5176] | 126 | ksort($fs); |
---|
[1058] | 127 | } //end if is_dir |
---|
| 128 | return $fs; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | // returns the name of the attributes that are supported for |
---|
[1204] | 132 | // files update/synchronization |
---|
[1058] | 133 | function get_update_attributes() |
---|
| 134 | { |
---|
[12831] | 135 | return array('representative_ext'); |
---|
[1204] | 136 | } |
---|
| 137 | |
---|
| 138 | function get_element_update_attributes($file) |
---|
| 139 | { |
---|
[1058] | 140 | global $conf; |
---|
[1204] | 141 | $data = array(); |
---|
| 142 | |
---|
| 143 | $filename = basename($file); |
---|
| 144 | $extension = get_extension($filename); |
---|
| 145 | |
---|
[12831] | 146 | $representative_ext = null; |
---|
| 147 | if (! isset($conf['flip_picture_ext'][$extension]) ) |
---|
[1204] | 148 | { |
---|
[12831] | 149 | $dirname = dirname($file); |
---|
| 150 | $filename_wo_ext = get_filename_wo_extension($filename); |
---|
| 151 | $representative_ext = $this->get_representative_ext($dirname, $filename_wo_ext); |
---|
[1204] | 152 | } |
---|
[12831] | 153 | |
---|
| 154 | $data['representative_ext'] = $representative_ext; |
---|
[1204] | 155 | return $data; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | // returns the name of the attributes that are supported for |
---|
| 159 | // metadata update/synchronization according to configuration |
---|
| 160 | function get_metadata_attributes() |
---|
| 161 | { |
---|
[12831] | 162 | return get_sync_metadata_attributes(); |
---|
[1058] | 163 | } |
---|
| 164 | |
---|
| 165 | // returns a hash of attributes (metadata+filesize+width,...) for file |
---|
[12831] | 166 | function get_element_metadata($infos) |
---|
[1058] | 167 | { |
---|
[12831] | 168 | return get_sync_metadata($infos); |
---|
[1058] | 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | //-------------------------------------------------- private functions -------- |
---|
| 173 | function get_representative_ext($path, $filename_wo_ext) |
---|
| 174 | { |
---|
| 175 | global $conf; |
---|
[1064] | 176 | $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.'; |
---|
[1058] | 177 | foreach ($conf['picture_ext'] as $ext) |
---|
| 178 | { |
---|
| 179 | $test = $base_test.$ext; |
---|
| 180 | if (is_file($test)) |
---|
| 181 | { |
---|
| 182 | return $ext; |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | return null; |
---|
| 186 | } |
---|
| 187 | |
---|
[1204] | 188 | |
---|
[1058] | 189 | } |
---|
[1029] | 190 | ?> |
---|