[8734] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based photo gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008-2011 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 | |
---|
| 25 | if (isset($_GET['processed'])) |
---|
| 26 | { |
---|
| 27 | // echo '<pre>POST'."\n"; print_r($_POST); echo '</pre>'; |
---|
| 28 | // echo '<pre>FILES'."\n"; print_r($_FILES); echo '</pre>'; |
---|
| 29 | // echo '<pre>SESSION'."\n"; print_r($_SESSION); echo '</pre>'; |
---|
| 30 | // exit(); |
---|
| 31 | |
---|
| 32 | // sometimes, you have submitted the form but you have nothing in $_POST |
---|
| 33 | // and $_FILES. This may happen when you have an HTML upload and you |
---|
| 34 | // exceeded the post_max_size (but not the upload_max_size) |
---|
| 35 | if (!isset($_POST['submit_upload'])) |
---|
| 36 | { |
---|
| 37 | array_push( |
---|
| 38 | $page['errors'], |
---|
| 39 | sprintf( |
---|
| 40 | l10n('The uploaded files exceed the post_max_size directive in php.ini: %sB'), |
---|
| 41 | ini_get('post_max_size') |
---|
| 42 | ) |
---|
| 43 | ); |
---|
| 44 | } |
---|
| 45 | |
---|
[11962] | 46 | $category_id = $_POST['category']; |
---|
[8734] | 47 | |
---|
| 48 | $image_ids = array(); |
---|
| 49 | |
---|
| 50 | if (isset($_FILES) and !empty($_FILES['image_upload'])) |
---|
| 51 | { |
---|
| 52 | $starttime = get_moment(); |
---|
| 53 | |
---|
| 54 | foreach ($_FILES['image_upload']['error'] as $idx => $error) |
---|
| 55 | { |
---|
| 56 | if (UPLOAD_ERR_OK == $error) |
---|
| 57 | { |
---|
| 58 | $images_to_add = array(); |
---|
| 59 | |
---|
| 60 | $extension = pathinfo($_FILES['image_upload']['name'][$idx], PATHINFO_EXTENSION); |
---|
| 61 | if ('zip' == strtolower($extension)) |
---|
| 62 | { |
---|
| 63 | $upload_dir = $conf['upload_dir'].'/buffer'; |
---|
| 64 | prepare_directory($upload_dir); |
---|
| 65 | |
---|
| 66 | $temporary_archive_name = date('YmdHis').'-'.generate_key(10); |
---|
| 67 | $archive_path = $upload_dir.'/'.$temporary_archive_name.'.zip'; |
---|
| 68 | |
---|
| 69 | move_uploaded_file( |
---|
| 70 | $_FILES['image_upload']['tmp_name'][$idx], |
---|
| 71 | $archive_path |
---|
| 72 | ); |
---|
| 73 | |
---|
| 74 | define('PCLZIP_TEMPORARY_DIR', $upload_dir.'/'); |
---|
| 75 | include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); |
---|
| 76 | $zip = new PclZip($archive_path); |
---|
| 77 | if ($list = $zip->listContent()) |
---|
| 78 | { |
---|
| 79 | $indexes_to_extract = array(); |
---|
| 80 | |
---|
| 81 | foreach ($list as $node) |
---|
| 82 | { |
---|
| 83 | if (1 == $node['folder']) |
---|
| 84 | { |
---|
| 85 | continue; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if (is_valid_image_extension(pathinfo($node['filename'], PATHINFO_EXTENSION))) |
---|
| 89 | { |
---|
| 90 | array_push($indexes_to_extract, $node['index']); |
---|
| 91 | |
---|
| 92 | array_push( |
---|
| 93 | $images_to_add, |
---|
| 94 | array( |
---|
| 95 | 'source_filepath' => $upload_dir.'/'.$temporary_archive_name.'/'.$node['filename'], |
---|
| 96 | 'original_filename' => basename($node['filename']), |
---|
| 97 | ) |
---|
| 98 | ); |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | if (count($indexes_to_extract) > 0) |
---|
| 103 | { |
---|
| 104 | $zip->extract( |
---|
| 105 | PCLZIP_OPT_PATH, $upload_dir.'/'.$temporary_archive_name, |
---|
| 106 | PCLZIP_OPT_BY_INDEX, $indexes_to_extract, |
---|
| 107 | PCLZIP_OPT_ADD_TEMP_FILE_ON |
---|
| 108 | ); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | elseif (is_valid_image_extension($extension)) |
---|
| 113 | { |
---|
| 114 | array_push( |
---|
| 115 | $images_to_add, |
---|
| 116 | array( |
---|
| 117 | 'source_filepath' => $_FILES['image_upload']['tmp_name'][$idx], |
---|
| 118 | 'original_filename' => $_FILES['image_upload']['name'][$idx], |
---|
| 119 | ) |
---|
| 120 | ); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | foreach ($images_to_add as $image_to_add) |
---|
| 124 | { |
---|
| 125 | $image_id = add_uploaded_file( |
---|
| 126 | $image_to_add['source_filepath'], |
---|
| 127 | $image_to_add['original_filename'], |
---|
| 128 | array($category_id), |
---|
| 129 | $_POST['level'] |
---|
| 130 | ); |
---|
| 131 | |
---|
| 132 | array_push($image_ids, $image_id); |
---|
| 133 | |
---|
| 134 | // TODO: if $image_id is not an integer, something went wrong |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | else |
---|
| 138 | { |
---|
| 139 | $error_message = file_upload_error_message($error); |
---|
| 140 | |
---|
| 141 | array_push( |
---|
| 142 | $page['errors'], |
---|
| 143 | sprintf( |
---|
| 144 | l10n('Error on file "%s" : %s'), |
---|
| 145 | $_FILES['image_upload']['name'][$idx], |
---|
| 146 | $error_message |
---|
| 147 | ) |
---|
| 148 | ); |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | $endtime = get_moment(); |
---|
| 153 | $elapsed = ($endtime - $starttime) * 1000; |
---|
| 154 | // printf('%.2f ms', $elapsed); |
---|
| 155 | |
---|
| 156 | } // if (!empty($_FILES)) |
---|
| 157 | |
---|
| 158 | if (isset($_POST['upload_id'])) |
---|
| 159 | { |
---|
| 160 | // we're on a multiple upload, with uploadify and so on |
---|
| 161 | if (isset($_SESSION['uploads_error'][ $_POST['upload_id'] ])) |
---|
| 162 | { |
---|
| 163 | foreach ($_SESSION['uploads_error'][ $_POST['upload_id'] ] as $error) |
---|
| 164 | { |
---|
| 165 | array_push($page['errors'], $error); |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | if (isset($_SESSION['uploads'][ $_POST['upload_id'] ])) |
---|
| 170 | { |
---|
| 171 | $image_ids = $_SESSION['uploads'][ $_POST['upload_id'] ]; |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | $page['thumbnails'] = array(); |
---|
| 176 | foreach ($image_ids as $image_id) |
---|
| 177 | { |
---|
| 178 | // we could return the list of properties from the add_uploaded_file |
---|
| 179 | // function, but I like the "double check". And it costs nothing |
---|
| 180 | // compared to the upload process. |
---|
| 181 | $thumbnail = array(); |
---|
| 182 | |
---|
| 183 | $query = ' |
---|
| 184 | SELECT |
---|
| 185 | file, |
---|
| 186 | path, |
---|
| 187 | tn_ext |
---|
| 188 | FROM '.IMAGES_TABLE.' |
---|
| 189 | WHERE id = '.$image_id.' |
---|
| 190 | ;'; |
---|
| 191 | $image_infos = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 192 | |
---|
| 193 | $thumbnail['file'] = $image_infos['file']; |
---|
| 194 | |
---|
| 195 | $thumbnail['src'] = get_thumbnail_location( |
---|
| 196 | array( |
---|
| 197 | 'path' => $image_infos['path'], |
---|
| 198 | 'tn_ext' => $image_infos['tn_ext'], |
---|
| 199 | ) |
---|
| 200 | ); |
---|
| 201 | |
---|
| 202 | // TODO: when implementing this plugin in Piwigo core, we should have |
---|
| 203 | // a function get_image_name($name, $file) (if name is null, then |
---|
| 204 | // compute a temporary name from filename) that would be also used in |
---|
| 205 | // picture.php. UPDATE: in fact, "get_name_from_file($file)" already |
---|
| 206 | // exists and is used twice (batch_manager_unit + comments, but not in |
---|
| 207 | // picture.php I don't know why) with the same pattern if |
---|
| 208 | // (empty($name)) {$name = get_name_from_file($file)}, a clean |
---|
| 209 | // function get_image_name($name, $file) would be better |
---|
| 210 | $thumbnail['title'] = get_name_from_file($image_infos['file']); |
---|
| 211 | |
---|
| 212 | $thumbnail['link'] = PHPWG_ROOT_PATH.'admin.php?page=picture_modify' |
---|
| 213 | .'&image_id='.$image_id |
---|
| 214 | .'&cat_id='.$category_id |
---|
| 215 | ; |
---|
| 216 | |
---|
| 217 | array_push($page['thumbnails'], $thumbnail); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | if (!empty($page['thumbnails'])) |
---|
| 221 | { |
---|
| 222 | array_push( |
---|
| 223 | $page['infos'], |
---|
| 224 | sprintf( |
---|
| 225 | l10n('%d photos uploaded'), |
---|
| 226 | count($page['thumbnails']) |
---|
| 227 | ) |
---|
| 228 | ); |
---|
| 229 | |
---|
| 230 | if (0 != $_POST['level']) |
---|
| 231 | { |
---|
| 232 | array_push( |
---|
| 233 | $page['infos'], |
---|
| 234 | sprintf( |
---|
| 235 | l10n('Privacy level set to "%s"'), |
---|
| 236 | l10n( |
---|
| 237 | sprintf('Level %d', $_POST['level']) |
---|
| 238 | ) |
---|
| 239 | ) |
---|
| 240 | ); |
---|
| 241 | } |
---|
| 242 | |
---|
[11962] | 243 | $query = ' |
---|
[8734] | 244 | SELECT |
---|
| 245 | COUNT(*) |
---|
| 246 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 247 | WHERE category_id = '.$category_id.' |
---|
| 248 | ;'; |
---|
[11962] | 249 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
| 250 | $category_name = get_cat_display_name_from_id($category_id, 'admin.php?page=cat_modify&cat_id='); |
---|
| 251 | |
---|
| 252 | // information |
---|
| 253 | array_push( |
---|
| 254 | $page['infos'], |
---|
| 255 | sprintf( |
---|
| 256 | l10n('Album "%s" now contains %d photos'), |
---|
| 257 | '<em>'.$category_name.'</em>', |
---|
| 258 | $count |
---|
| 259 | ) |
---|
| 260 | ); |
---|
| 261 | |
---|
[8734] | 262 | $page['batch_link'] = PHOTOS_ADD_BASE_URL.'&batch='.implode(',', $image_ids); |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | ?> |
---|