Changeset 4829 for extensions
- Timestamp:
- Feb 2, 2010, 9:07:50 PM (15 years ago)
- Location:
- extensions/upload_form
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/upload_form/include/functions_upload.inc.php
r4807 r4829 250 250 ); 251 251 } 252 253 function is_valid_image_extension($extension) 254 { 255 return in_array(strtolower($extension), array('jpg', 'jpeg', 'png')); 256 } 252 257 ?> -
extensions/upload_form/language/en_UK/plugin.lang.php
r4811 r4829 36 36 $lang['Category "%s" now contains %d photos'] = 'Category "%s" now contains %d photos'; 37 37 $lang['Manage this set of %d photos'] = 'Manage this set of %d photos'; 38 $lang['Select files'] = 'Select files'; 39 $lang['JPEG files or ZIP archives with JPEG files inside please.'] = 'JPEG files or ZIP archives with JPEG files inside please.'; 38 40 ?> -
extensions/upload_form/language/fr_FR/plugin.lang.php
r4811 r4829 36 36 $lang['Category "%s" now contains %d photos'] = 'La catégorie "%s" contient désormais %d photos'; 37 37 $lang['Manage this set of %d photos'] = 'Gérer ce lot de %d photos'; 38 $lang['Select files'] = 'Choisir des fichiers'; 39 $lang['JPEG files or ZIP archives with JPEG files inside please.'] = 'Fichiers JPEG ou archives ZIP avec des fichiers JPEG dedans s\'il vous plaît.'; 38 40 ?> -
extensions/upload_form/upload.php
r4811 r4829 120 120 if (UPLOAD_ERR_OK == $error) 121 121 { 122 $source_filepath = $_FILES['image_upload']['tmp_name'][$idx]; 123 $original_filename = $_FILES['image_upload']['name'][$idx]; 124 125 $image_id = add_uploaded_file( 126 $source_filepath, 127 $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 // we could return the list of properties from the add_uploaded_file 137 // function, but I like the "double check". And it costs nothing 138 // compared to the upload process. 139 $thumbnail = array(); 140 141 $query = ' 122 $images_to_add = array(); 123 124 $extension = pathinfo($_FILES['image_upload']['name'][$idx], PATHINFO_EXTENSION); 125 if ('zip' == strtolower($extension)) 126 { 127 $upload_dir = PHPWG_ROOT_PATH.'upload/buffer'; 128 prepare_directory($upload_dir); 129 130 $temporary_archive_name = date('YmdHis').'-'.generate_key(10); 131 $archive_path = $upload_dir.'/'.$temporary_archive_name.'.zip'; 132 133 move_uploaded_file( 134 $_FILES['image_upload']['tmp_name'][$idx], 135 $archive_path 136 ); 137 138 define('PCLZIP_TEMPORARY_DIR', $upload_dir.'/'); 139 include(UPLOAD_FORM_PATH.'include/pclzip.lib.php'); 140 $zip = new PclZip($archive_path); 141 if ($list = $zip->listContent()) 142 { 143 $indexes_to_extract = array(); 144 145 foreach ($list as $node) 146 { 147 if (1 == $node['folder']) 148 { 149 continue; 150 } 151 152 if (is_valid_image_extension(pathinfo($node['filename'], PATHINFO_EXTENSION))) 153 { 154 array_push($indexes_to_extract, $node['index']); 155 156 array_push( 157 $images_to_add, 158 array( 159 'source_filepath' => $upload_dir.'/'.$temporary_archive_name.'/'.$node['filename'], 160 'original_filename' => basename($node['filename']), 161 ) 162 ); 163 } 164 } 165 166 if (count($indexes_to_extract) > 0) 167 { 168 $zip->extract( 169 PCLZIP_OPT_PATH, $upload_dir.'/'.$temporary_archive_name, 170 PCLZIP_OPT_BY_INDEX, $indexes_to_extract, 171 PCLZIP_OPT_ADD_TEMP_FILE_ON 172 ); 173 } 174 } 175 } 176 elseif (is_valid_image_extension($extension)) 177 { 178 array_push( 179 $images_to_add, 180 array( 181 'source_filepath' => $_FILES['image_upload']['tmp_name'][$idx], 182 'original_filename' => $_FILES['image_upload']['name'][$idx], 183 ) 184 ); 185 } 186 187 foreach ($images_to_add as $image_to_add) 188 { 189 $image_id = add_uploaded_file( 190 $image_to_add['source_filepath'], 191 $image_to_add['original_filename'], 192 array($category_id), 193 $_POST['level'] 194 ); 195 196 array_push($image_ids, $image_id); 197 198 // TODO: if $image_id is not an integer, something went wrong 199 200 // we could return the list of properties from the add_uploaded_file 201 // function, but I like the "double check". And it costs nothing 202 // compared to the upload process. 203 $thumbnail = array(); 204 205 $query = ' 142 206 SELECT 143 207 file, … … 147 211 WHERE id = '.$image_id.' 148 212 ;'; 149 $image_infos = mysql_fetch_assoc(pwg_query($query)); 150 151 $thumbnail['file'] = $image_infos['file']; 152 153 $thumbnail['src'] = get_thumbnail_location( 154 array( 155 'path' => $image_infos['path'], 156 'tn_ext' => $image_infos['tn_ext'], 157 ) 158 ); 159 160 // TODO: when implementing this plugin in Piwigo core, we should have 161 // a function get_image_name($name, $file) (if name is null, then 162 // compute a temporary name from filename) that would be also used in 163 // picture.php. UPDATE: in fact, "get_name_from_file($file)" already 164 // exists and is used twice (element_set_unit + comments, but not in 165 // picture.php I don't know why) with the same pattern if 166 // (empty($name)) {$name = get_name_from_file($file)}, a clean 167 // function get_image_name($name, $file) would be better 168 $thumbnail['title'] = get_name_from_file($image_infos['file']); 169 170 $thumbnail['link'] = PHPWG_ROOT_PATH.'admin.php?page=picture_modify' 171 .'&image_id='.$image_id 172 .'&cat_id='.$category_id 173 ; 174 175 array_push($page['thumbnails'], $thumbnail); 213 $image_infos = mysql_fetch_assoc(pwg_query($query)); 214 215 $thumbnail['file'] = $image_infos['file']; 216 217 $thumbnail['src'] = get_thumbnail_location( 218 array( 219 'path' => $image_infos['path'], 220 'tn_ext' => $image_infos['tn_ext'], 221 ) 222 ); 223 224 // TODO: when implementing this plugin in Piwigo core, we should have 225 // a function get_image_name($name, $file) (if name is null, then 226 // compute a temporary name from filename) that would be also used in 227 // picture.php. UPDATE: in fact, "get_name_from_file($file)" already 228 // exists and is used twice (element_set_unit + comments, but not in 229 // picture.php I don't know why) with the same pattern if 230 // (empty($name)) {$name = get_name_from_file($file)}, a clean 231 // function get_image_name($name, $file) would be better 232 $thumbnail['title'] = get_name_from_file($image_infos['file']); 233 234 $thumbnail['link'] = PHPWG_ROOT_PATH.'admin.php?page=picture_modify' 235 .'&image_id='.$image_id 236 .'&cat_id='.$category_id 237 ; 238 239 array_push($page['thumbnails'], $thumbnail); 240 } 176 241 } 177 242 } -
extensions/upload_form/upload.tpl
r4811 r4829 110 110 <tr> 111 111 <td colspan="2"> 112 <strong>{'Select files'|@translate}</strong> 113 <p>{'JPEG files or ZIP archives with JPEG files inside please.'|@translate}</p> 112 114 <div id="uploadBoxes"> 113 115 <p><input class="file" type="file" size="70" name="image_upload[]" /></p>
Note: See TracChangeset
for help on using the changeset viewer.