- Timestamp:
- Jun 17, 2013, 5:42:09 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/BatchDownloader/include/BatchDownloader.class.php
r23280 r23290 14 14 * @param: string set type ('album'|'tag'|'selection') 15 15 * @param: int set type id (for retrieving album infos for instance) 16 */ 17 function __construct($set_id, $images=array(), $type=null, $type_id=null) 16 * @param: string size to download 17 */ 18 function __construct($set_id, $images=array(), $type=null, $type_id=null, $size='original') 18 19 { 19 20 global $user, $conf; … … 26 27 'type' => null, 27 28 'type_id' => null, 29 'size' => 'original', 28 30 'nb_zip' => 0, 29 31 'last_zip' => 0, … … 39 41 { 40 42 $query = ' 41 SELECT 42 id, 43 user_id, 44 date_creation, 45 type, 46 type_id, 47 nb_zip, 48 last_zip, 49 nb_images, 50 total_size, 51 status 43 SELECT * 52 44 FROM '.BATCH_DOWNLOAD_TSETS.' 53 45 WHERE … … 95 87 else if ($set_id == 'new') 96 88 { 89 if ($size != 'original') 90 { 91 $type_map = array_keys(ImageStdParams::get_defined_type_map()); 92 if (!in_array($size, $type_map)) 93 { 94 throw new Exception(sprintf(l10n('Invalid size %s'), $size)); 95 } 96 } 97 97 98 $this->data['type'] = $type; 98 99 $this->data['type_id'] = $type_id; 100 $this->data['size'] = $size; 99 101 100 102 $query = ' … … 104 106 type, 105 107 type_id, 108 size, 106 109 nb_zip, 107 110 last_zip, … … 115 118 "'.$this->data['type'].'", 116 119 "'.$this->data['type_id'].'", 120 "'.$this->data['size'].'", 117 121 0, 118 122 0, … … 255 259 256 260 /** 261 * get missing derivatives files 262 * @return: array of i.php urls 263 */ 264 function getMissingDerivatives($update=false) 265 { 266 if ($this->data['size'] == 'original') 267 { 268 return array(); 269 } 270 271 global $conf; 272 273 $root_url = get_root_url(); 274 $uid = '&b='.time(); 275 276 $params = ImageStdParams::get_by_type($this->data['size']); 277 $last_mod_time = $params->last_mod_time; 278 279 $image_ids = array_keys($this->images); 280 $to_update = $urls = $inserts = array(); 281 282 $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; 283 $conf['derivative_url_style'] = 2; //script 284 285 // images which we need to update stats 286 if ($update) 287 { 288 $query = ' 289 SELECT image_id, filemtime FROM '.IMAGE_SIZES_TABLE.' 290 WHERE image_id IN('.implode(',', $image_ids).') 291 AND type = "'.$this->data['size'].'" 292 ;'; 293 $registered = array_from_query($query, 'image_id', 'filemtime'); 294 295 $to_update = array_filter($registered, create_function('$t', 'return $t<'.$last_mod_time.';')); 296 $to_update = array_merge($to_update, array_diff($image_ids, $registered)); 297 } 298 299 $query = ' 300 SELECT id, path, representative_ext, width, height, rotation 301 FROM '.IMAGES_TABLE.' 302 WHERE id IN('.implode(',', $image_ids).') 303 ORDER BY id DESC 304 ;'; 305 306 $result = pwg_query($query); 307 while ($row = pwg_db_fetch_assoc($result)) 308 { 309 $src_image = new SrcImage($row); 310 if ($src_image->is_mimetype()) continue; 311 312 $derivative = new DerivativeImage($this->data['size'], $src_image); 313 // if ($this->data['size'] != $derivative->get_type()) continue; 314 315 $filemtime = @filemtime($derivative->get_path()); 316 317 if ($filemtime===false || $filemtime<$last_mod_time) 318 { 319 $urls[] = $root_url.$derivative->get_url().$uid; 320 } 321 else if ($update && in_array($row['id'], $to_update)) 322 { 323 $imagesize = getimagesize($derivative->get_path()); 324 325 $inserts[ $row['id'] ] = array( 326 'image_id' => $row['id'], 327 'type' => $this->data['size'], 328 'width' => $imagesize[0], 329 'height' => $imagesize[1], 330 'filesize' => filesize($derivative->get_path())/1024, 331 'filemtime' => $filemtime, 332 ); 333 } 334 } 335 336 if (!empty($inserts)) 337 { 338 $query = ' 339 DELETE FROM '.IMAGE_SIZES_TABLE.' 340 WHERE image_id IN('.implode(',', array_keys($inserts)).') 341 ;'; 342 pwg_query($query); 343 344 mass_inserts( 345 IMAGE_SIZES_TABLE, 346 array('image_id','type','width','height','filesize'), 347 $inserts 348 ); 349 } 350 351 return $urls; 352 } 353 354 /** 257 355 * deleteLastArchive 258 356 */ … … 311 409 $query = ' 312 410 SELECT 313 id, 314 name, 315 file, 316 path, 317 filesize 411 id, name, file, path, 412 representative_ext, rotation, 413 filesize, width, height 318 414 FROM '.IMAGES_TABLE.' 319 415 WHERE id IN ('.implode(',', $images_to_add).') 320 416 ;'; 321 417 $images_to_add = hash_from_query($query, 'id'); 418 419 if ($this->data['size'] != 'original') 420 { 421 $query = ' 422 SELECT image_id, filesize 423 FROM '.IMAGE_SIZES_TABLE.' 424 WHERE image_id IN ('.implode(',', array_keys($images_to_add)).') 425 AND type = "'.$this->data['size'].'" 426 ;'; 427 $filesizes = simple_hash_from_query($query, 'image_id', 'filesize'); 428 } 322 429 323 430 // open zip … … 330 437 $total_size = 0; 331 438 foreach ($images_to_add as $row) 332 { 333 $zip->addFile(PHPWG_ROOT_PATH . $row['path'], $row['id'].'_'.stripslashes(get_filename_wo_extension($row['file'])).'.'.get_extension($row['path'])); 439 { 440 if ($this->data['size'] == 'original') 441 { 442 $zip->addFile(PHPWG_ROOT_PATH . $row['path'], $row['id'].'_'.stripslashes(get_filename_wo_extension($row['file'])).'.'.get_extension($row['path'])); 443 $total_size+= $row['filesize']; 444 } 445 else 446 { 447 $src_image = new SrcImage($row); 448 $derivative = new DerivativeImage($this->data['size'], $src_image); 449 $path = $derivative->get_path(); 450 451 $zip->addFile($path, $row['id'].'_'.stripslashes(get_filename_wo_extension(basename($path))).'.'.get_extension($path)); 452 $total_size+= $filesizes[ $row['id'] ]; 453 } 334 454 335 455 array_push($images_added, $row['id']); 336 456 $this->images[ $row['id'] ] = $this->data['last_zip']; 337 457 338 $total_size+= $row['filesize'];339 458 if ($total_size >= $this->conf['max_size']*1024 and !$force_one_archive) break; 340 459 } … … 370 489 371 490 // over estimed 372 if ( $this->data['status'] == 'done' and $this->data['last_zip'] < $this->data['nb_zip'])491 if ($this->data['status'] == 'done') 373 492 { 374 493 $this->updateParam('nb_zip', $this->data['last_zip']); 375 494 } 376 495 // under estimed 377 else if ( $this->data['last_zip'] == $this->data['nb_zip'] and $this->data['status'] != 'done')496 else if ($this->data['last_zip'] == $this->data['nb_zip']) 378 497 { 379 498 $this->updateParam('nb_zip', $this->data['last_zip']+1); … … 400 519 $image_ids = array_slice(array_keys($this->images), 0, $this->conf['max_elements']); 401 520 402 $query = ' 521 if ($this->data['size'] == 'original') 522 { 523 $query = ' 403 524 SELECT SUM(filesize) AS total 404 525 FROM '.IMAGES_TABLE.' 405 526 WHERE id IN ('.implode(',', $image_ids).') 406 527 ;'; 528 } 529 else 530 { 531 $query = ' 532 SELECT SUM(filesize) AS total 533 FROM '.IMAGE_SIZES_TABLE.' 534 WHERE image_id IN ('.implode(',', $image_ids).') 535 ;'; 536 } 537 407 538 list($total) = pwg_db_fetch_row(pwg_query($query)); 408 539 $this->data['estimated_total_size'] = $total; … … 416 547 function getEstimatedArchiveNumber() 417 548 { 418 $nb_zip = ceil( $this->getEstimatedTotalSize() / ($this->conf['max_size']*1024) );419 $this->updateParam('nb_zip', $nb_zip);420 return $nb_zip;549 if ($this->data['status'] == 'done') return $this->data['nb_zip']; 550 551 return ceil( $this->getEstimatedTotalSize() / ($this->conf['max_size']*1024) ); 421 552 } 422 553 … … 435 566 436 567 $out = ''; 437 for ($i=1; $i<=$this-> data['nb_zip']; $i++)568 for ($i=1; $i<=$this->getEstimatedArchiveNumber(); $i++) 438 569 { 439 570 $out.= '<li id="zip-'.$i.'">'; … … 482 613 $path.= $set['BASENAME'] . '_'; 483 614 $path.= $this->data['user_id'] . $this->data['id']; 484 $path.= $this-> data['nb_zip']!=1 ? '_part' . $i : null;615 $path.= $this->getEstimatedArchiveNumber()!=1 ? '_part' . $i : null; 485 616 $path.= '.zip'; 486 617 … … 680 811 $set = array( 681 812 'NB_IMAGES' => $this->data['nb_images'], 682 'NB_ARCHIVES' => $this->data[' nb_zip'],813 'NB_ARCHIVES' => $this->data['status']=='new' ? l10n('unknown') : $this->getEstimatedArchiveNumber(), 683 814 'STATUS' => $this->data['status'], 684 815 'LAST_ZIP' => $this->data['last_zip'], 685 'TOTAL_SIZE' => ceil($this->getEstimatedTotalSize()/1024),686 'LINKS' => $this->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'),816 'TOTAL_SIZE' => $this->data['status']=='new' ? l10n('unknown') : ceil($this->getEstimatedTotalSize()/1024), 817 // 'LINKS' => $this->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'), 687 818 'DATE_CREATION' => format_date($this->data['date_creation'], true), 819 'SIZE_ID' => $this->data['size'], 820 'SIZE' => l10n($this->data['size']), 688 821 ); 822 823 if ($this->data['size'] != 'original') 824 { 825 $params = ImageStdParams::get_by_type($this->data['size']); 826 $set['SIZE_INFO'] = $params->sizing->ideal_size[0].' x '.$params->sizing->ideal_size[1]; 827 } 689 828 690 829 return array_merge($set, $this->getNames());
Note: See TracChangeset
for help on using the changeset viewer.